11import type { Runtime } from "@/runtime/Runtime" ;
22import type { RuntimeConfig } from "./runtime" ;
33import type { RpcTarget } from "capnweb" ;
4+ import type {
5+ BashToolArgs ,
6+ BashToolResult ,
7+ FileReadToolArgs ,
8+ FileReadToolResult ,
9+ FileEditReplaceStringToolArgs ,
10+ FileEditReplaceStringToolResult ,
11+ FileEditReplaceLinesToolArgs ,
12+ FileEditReplaceLinesToolResult ,
13+ FileEditInsertToolArgs ,
14+ FileEditInsertToolResult ,
15+ ProposePlanToolArgs ,
16+ ProposePlanToolResult ,
17+ TodoWriteToolArgs ,
18+ TodoWriteToolResult ,
19+ StatusSetToolArgs ,
20+ StatusSetToolResult ,
21+ } from "./tools" ;
422
523/**
624 * Extension manifest structure (manifest.json)
@@ -10,17 +28,90 @@ export interface ExtensionManifest {
1028}
1129
1230/**
13- * Hook payload for post- tool-use hook
31+ * Tool execution payload - discriminated union by tool name
1432 */
15- export interface PostToolUseHookPayload {
16- toolName : string ;
17- toolCallId : string ;
18- args : unknown ;
19- result : unknown ;
20- workspaceId : string ;
21- timestamp : number ;
33+ export type ToolUsePayload =
34+ | {
35+ toolName : "bash" ;
36+ toolCallId : string ;
37+ args : BashToolArgs ;
38+ result : BashToolResult ;
39+ workspaceId : string ;
40+ timestamp : number ;
41+ }
42+ | {
43+ toolName : "file_read" ;
44+ toolCallId : string ;
45+ args : FileReadToolArgs ;
46+ result : FileReadToolResult ;
47+ workspaceId : string ;
48+ timestamp : number ;
49+ }
50+ | {
51+ toolName : "file_edit_replace_string" ;
52+ toolCallId : string ;
53+ args : FileEditReplaceStringToolArgs ;
54+ result : FileEditReplaceStringToolResult ;
55+ workspaceId : string ;
56+ timestamp : number ;
57+ }
58+ | {
59+ toolName : "file_edit_replace_lines" ;
60+ toolCallId : string ;
61+ args : FileEditReplaceLinesToolArgs ;
62+ result : FileEditReplaceLinesToolResult ;
63+ workspaceId : string ;
64+ timestamp : number ;
65+ }
66+ | {
67+ toolName : "file_edit_insert" ;
68+ toolCallId : string ;
69+ args : FileEditInsertToolArgs ;
70+ result : FileEditInsertToolResult ;
71+ workspaceId : string ;
72+ timestamp : number ;
73+ }
74+ | {
75+ toolName : "propose_plan" ;
76+ toolCallId : string ;
77+ args : ProposePlanToolArgs ;
78+ result : ProposePlanToolResult ;
79+ workspaceId : string ;
80+ timestamp : number ;
81+ }
82+ | {
83+ toolName : "todo_write" ;
84+ toolCallId : string ;
85+ args : TodoWriteToolArgs ;
86+ result : TodoWriteToolResult ;
87+ workspaceId : string ;
88+ timestamp : number ;
89+ }
90+ | {
91+ toolName : "status_set" ;
92+ toolCallId : string ;
93+ args : StatusSetToolArgs ;
94+ result : StatusSetToolResult ;
95+ workspaceId : string ;
96+ timestamp : number ;
97+ }
98+ | {
99+ // Catch-all for unknown tools
100+ toolName : string ;
101+ toolCallId : string ;
102+ args : unknown ;
103+ result : unknown ;
104+ workspaceId : string ;
105+ timestamp : number ;
106+ } ;
107+
108+ /**
109+ * Hook payload for post-tool-use hook with Runtime access
110+ * This adds the runtime field to each variant of ToolUsePayload
111+ */
112+ export type PostToolUseHookPayload = ToolUsePayload & {
22113 runtime : Runtime ; // Extensions get full workspace access via Runtime
23- }
114+ } ;
24115
25116/**
26117 * Extension export interface - what extensions must export as default
@@ -31,7 +122,7 @@ export interface Extension {
31122 * Extensions can monitor, log, or modify the tool result.
32123 *
33124 * @param payload - Tool execution context with full Runtime access
34- * @returns The tool result (can be modified) or undefined to leave unchanged
125+ * @returns The tool result (modified or unmodified). Return undefined to leave unchanged.
35126 */
36127 onPostToolUse ?: ( payload : PostToolUseHookPayload ) => Promise < unknown > | unknown ;
37128}
@@ -81,7 +172,7 @@ export interface ExtensionHostApi extends RpcTarget {
81172 * @param payload Hook payload (runtime will be added by host)
82173 * @returns The (possibly modified) tool result, or undefined if unchanged
83174 */
84- onPostToolUse ( payload : Omit < PostToolUseHookPayload , "runtime" > ) : Promise < unknown > ;
175+ onPostToolUse ( payload : ToolUsePayload ) : Promise < unknown > ;
85176
86177 /**
87178 * Gracefully shutdown the extension host
0 commit comments