@@ -28,6 +28,7 @@ import { toDisplayPath, markdownEscape } from './utils.js'
2828
2929// ── ToolUseCache ──────────────────────────────────────────────────
3030
31+ /** Maps tool_use_id → tool metadata for tracked inflight tool calls. */
3132export type ToolUseCache = {
3233 [ key : string ] : {
3334 type : 'tool_use' | 'server_tool_use' | 'mcp_tool_use'
@@ -39,20 +40,23 @@ export type ToolUseCache = {
3940
4041// ── Session usage tracking ────────────────────────────────────────
4142
43+ /** Accumulated token usage across a session, updated per result message. */
4244export type SessionUsage = {
4345 inputTokens : number
4446 outputTokens : number
4547 cachedReadTokens : number
4648 cachedWriteTokens : number
4749}
4850
51+ /** Token usage reported in SDK result messages. */
4952type BridgeUsage = {
5053 input_tokens ?: number
5154 output_tokens ?: number
5255 cache_read_input_tokens ?: number
5356 cache_creation_input_tokens ?: number
5457}
5558
59+ /** system-init, compact_boundary, status, api_retry, local_command_output messages. */
5660type BridgeSystemMessage = {
5761 type : 'system'
5862 subtype ?: string
@@ -66,6 +70,7 @@ type BridgeSystemMessage = {
6670 [ key : string ] : unknown
6771}
6872
73+ /** Turn completion message: success with usage, or error with stop_reason. */
6974type BridgeResultMessage = {
7075 type : 'result'
7176 subtype ?: string
@@ -84,6 +89,7 @@ type BridgeResultMessage = {
8489 [ key : string ] : unknown
8590}
8691
92+ /** Full assistant response message after the turn completes. */
8793type BridgeAssistantMessage = {
8894 type : 'assistant'
8995 message ?: {
@@ -102,6 +108,7 @@ type BridgeAssistantMessage = {
102108 [ key : string ] : unknown
103109}
104110
111+ /** Real-time streaming event (aka partial_assistant in the SDK schema). */
105112type BridgeStreamEventMessage = {
106113 type : 'stream_event'
107114 event ?: { type ?: string ; [ key : string ] : unknown }
@@ -112,6 +119,7 @@ type BridgeStreamEventMessage = {
112119 [ key : string ] : unknown
113120}
114121
122+ /** User prompt message (may include tool_use_result from prior turns). */
115123type BridgeUserMessage = {
116124 type : 'user'
117125 message ?: Record < string , unknown >
@@ -122,6 +130,7 @@ type BridgeUserMessage = {
122130 [ key : string ] : unknown
123131}
124132
133+ /** Subagent or hook progress notification (internal, not an SDK message member). */
125134type BridgeProgressMessage = {
126135 type : 'progress'
127136 data ?: {
@@ -132,6 +141,7 @@ type BridgeProgressMessage = {
132141 [ key : string ] : unknown
133142}
134143
144+ /** Summary of tool calls made during a turn. */
135145type BridgeToolUseSummaryMessage = {
136146 type : 'tool_use_summary'
137147 summary ?: string
@@ -141,17 +151,20 @@ type BridgeToolUseSummaryMessage = {
141151 [ key : string ] : unknown
142152}
143153
154+ /** File attachment metadata (internal, not an SDK message member). */
144155type BridgeAttachmentMessage = {
145156 type : 'attachment'
146157 [ key : string ] : unknown
147158}
148159
160+ /** Compaction boundary marker (type is 'compact_boundary', not 'system'). */
149161type BridgeCompactBoundaryMessage = {
150162 type : 'compact_boundary'
151163 compact_metadata ?: Record < string , unknown >
152164 [ key : string ] : unknown
153165}
154166
167+ /** ACP bridge local discriminated union — covers all message shapes consumed by the forwarding loop. */
155168type BridgeSDKMessage =
156169 | BridgeSystemMessage
157170 | BridgeResultMessage
@@ -167,6 +180,7 @@ const logger: { debug: (...args: unknown[]) => void } = console
167180
168181// ── Tool info conversion ──────────────────────────────────────────
169182
183+ /** Sanitised tool metadata sent to ACP client for tool_call notifications. */
170184interface ToolInfo {
171185 title : string
172186 kind : ToolKind
@@ -638,6 +652,7 @@ function toAcpContentBlock(
638652
639653// ── Edit tool response → diff ──────────────────────────────────────
640654
655+ /** Context lines and diff metadata for one hunk of an Edit tool response. */
641656interface EditToolResponseHunk {
642657 oldStart : number
643658 oldLines : number
@@ -646,6 +661,7 @@ interface EditToolResponseHunk {
646661 lines : string [ ]
647662}
648663
664+ /** Result block for Edit/Write tool responses containing hunks and optional file stats. */
649665interface EditToolResponse {
650666 filePath ?: string
651667 structuredPatch ?: EditToolResponseHunk [ ]
0 commit comments