@namzu/sdk 74.1.0 → 76.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/bridge/acp/server.d.ts +2 -0
  3. package/dist/bridge/acp/server.d.ts.map +1 -1
  4. package/dist/bridge/acp/server.js +13 -2
  5. package/dist/bridge/acp/server.js.map +1 -1
  6. package/dist/bridge/acp/update.d.ts.map +1 -1
  7. package/dist/bridge/acp/update.js +22 -2
  8. package/dist/bridge/acp/update.js.map +1 -1
  9. package/dist/connector/mcp/adapter.d.ts +1 -1
  10. package/dist/connector/mcp/adapter.d.ts.map +1 -1
  11. package/dist/connector/mcp/adapter.js +3 -2
  12. package/dist/connector/mcp/adapter.js.map +1 -1
  13. package/dist/connector/mcp/client.d.ts +4 -25
  14. package/dist/connector/mcp/client.d.ts.map +1 -1
  15. package/dist/connector/mcp/client.js +32 -32
  16. package/dist/connector/mcp/client.js.map +1 -1
  17. package/dist/peers/record.d.ts +3 -3
  18. package/dist/provider/errors.d.ts.map +1 -1
  19. package/dist/provider/errors.js +13 -18
  20. package/dist/provider/errors.js.map +1 -1
  21. package/dist/provider/stream-request-timeout.d.ts +9 -0
  22. package/dist/provider/stream-request-timeout.d.ts.map +1 -0
  23. package/dist/provider/stream-request-timeout.js +34 -0
  24. package/dist/provider/stream-request-timeout.js.map +1 -0
  25. package/dist/public-runtime.d.ts +3 -2
  26. package/dist/public-runtime.d.ts.map +1 -1
  27. package/dist/public-runtime.js +2 -1
  28. package/dist/public-runtime.js.map +1 -1
  29. package/dist/public-tools.d.ts +1 -1
  30. package/dist/public-tools.d.ts.map +1 -1
  31. package/dist/public-tools.js +1 -1
  32. package/dist/public-tools.js.map +1 -1
  33. package/dist/runtime/query/executor.d.ts +3 -0
  34. package/dist/runtime/query/executor.d.ts.map +1 -1
  35. package/dist/runtime/query/executor.js +25 -4
  36. package/dist/runtime/query/executor.js.map +1 -1
  37. package/dist/runtime/query/file-evidence-replay.d.ts +1 -0
  38. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  39. package/dist/runtime/query/file-evidence-replay.js +64 -21
  40. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  41. package/dist/runtime/query/file-evidence-seed.d.ts +7 -0
  42. package/dist/runtime/query/file-evidence-seed.d.ts.map +1 -1
  43. package/dist/runtime/query/file-evidence-seed.js +12 -1
  44. package/dist/runtime/query/file-evidence-seed.js.map +1 -1
  45. package/dist/runtime/query/index.d.ts +2 -0
  46. package/dist/runtime/query/index.d.ts.map +1 -1
  47. package/dist/runtime/query/index.js +5 -2
  48. package/dist/runtime/query/index.js.map +1 -1
  49. package/dist/runtime/query/path-escalation.d.ts.map +1 -1
  50. package/dist/runtime/query/path-escalation.js +4 -3
  51. package/dist/runtime/query/path-escalation.js.map +1 -1
  52. package/dist/runtime/query/tooling.d.ts +2 -0
  53. package/dist/runtime/query/tooling.d.ts.map +1 -1
  54. package/dist/runtime/query/tooling.js +1 -0
  55. package/dist/runtime/query/tooling.js.map +1 -1
  56. package/dist/sandbox/provider/local.d.ts.map +1 -1
  57. package/dist/sandbox/provider/local.js +45 -18
  58. package/dist/sandbox/provider/local.js.map +1 -1
  59. package/dist/schedules/cron.js +1 -1
  60. package/dist/schedules/cron.js.map +1 -1
  61. package/dist/schedules/describe.js +1 -1
  62. package/dist/schedules/describe.js.map +1 -1
  63. package/dist/schedules/next-fire.d.ts +2 -2
  64. package/dist/schedules/next-fire.d.ts.map +1 -1
  65. package/dist/schedules/next-fire.js +7 -4
  66. package/dist/schedules/next-fire.js.map +1 -1
  67. package/dist/schedules/spec.d.ts.map +1 -1
  68. package/dist/schedules/spec.js +23 -7
  69. package/dist/schedules/spec.js.map +1 -1
  70. package/dist/schedules/types.d.ts +2 -0
  71. package/dist/schedules/types.d.ts.map +1 -1
  72. package/dist/session/workspace/git-worktree.d.ts +18 -0
  73. package/dist/session/workspace/git-worktree.d.ts.map +1 -1
  74. package/dist/session/workspace/git-worktree.js +100 -1
  75. package/dist/session/workspace/git-worktree.js.map +1 -1
  76. package/dist/session/workspace/index.d.ts +1 -1
  77. package/dist/session/workspace/index.d.ts.map +1 -1
  78. package/dist/session/workspace/index.js +1 -1
  79. package/dist/session/workspace/index.js.map +1 -1
  80. package/dist/store/checkpoint/contract.d.ts.map +1 -1
  81. package/dist/store/checkpoint/contract.js +5 -2
  82. package/dist/store/checkpoint/contract.js.map +1 -1
  83. package/dist/store/session-index/sqlite.d.ts.map +1 -1
  84. package/dist/store/session-index/sqlite.js +7 -3
  85. package/dist/store/session-index/sqlite.js.map +1 -1
  86. package/dist/store/session-log/core.d.ts.map +1 -1
  87. package/dist/store/session-log/core.js +118 -25
  88. package/dist/store/session-log/core.js.map +1 -1
  89. package/dist/store/session-log/disk.js +1 -1
  90. package/dist/store/session-log/disk.js.map +1 -1
  91. package/dist/tools/admit-facts.d.ts.map +1 -1
  92. package/dist/tools/admit-facts.js +19 -0
  93. package/dist/tools/admit-facts.js.map +1 -1
  94. package/dist/tools/builtins/bash.d.ts +1 -1
  95. package/dist/tools/builtins/bash.d.ts.map +1 -1
  96. package/dist/tools/builtins/bash.js +9 -7
  97. package/dist/tools/builtins/bash.js.map +1 -1
  98. package/dist/tools/builtins/browser.d.ts +2 -2
  99. package/dist/tools/builtins/browser.d.ts.map +1 -1
  100. package/dist/tools/builtins/browser.js +15 -3
  101. package/dist/tools/builtins/browser.js.map +1 -1
  102. package/dist/tools/builtins/code-analysis.d.ts.map +1 -1
  103. package/dist/tools/builtins/code-analysis.js +4 -1
  104. package/dist/tools/builtins/code-analysis.js.map +1 -1
  105. package/dist/tools/builtins/computer-use.d.ts +19 -3
  106. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  107. package/dist/tools/builtins/computer-use.js +150 -50
  108. package/dist/tools/builtins/computer-use.js.map +1 -1
  109. package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
  110. package/dist/tools/builtins/edit-apply.js +24 -10
  111. package/dist/tools/builtins/edit-apply.js.map +1 -1
  112. package/dist/tools/builtins/edit.d.ts.map +1 -1
  113. package/dist/tools/builtins/edit.js +31 -15
  114. package/dist/tools/builtins/edit.js.map +1 -1
  115. package/dist/tools/builtins/file-text.d.ts +3 -0
  116. package/dist/tools/builtins/file-text.d.ts.map +1 -0
  117. package/dist/tools/builtins/file-text.js +14 -0
  118. package/dist/tools/builtins/file-text.js.map +1 -0
  119. package/dist/tools/builtins/glob.d.ts.map +1 -1
  120. package/dist/tools/builtins/glob.js +7 -2
  121. package/dist/tools/builtins/glob.js.map +1 -1
  122. package/dist/tools/builtins/grep.d.ts.map +1 -1
  123. package/dist/tools/builtins/grep.js +8 -5
  124. package/dist/tools/builtins/grep.js.map +1 -1
  125. package/dist/tools/builtins/ls.d.ts.map +1 -1
  126. package/dist/tools/builtins/ls.js +2 -1
  127. package/dist/tools/builtins/ls.js.map +1 -1
  128. package/dist/tools/builtins/notebook-edit.d.ts.map +1 -1
  129. package/dist/tools/builtins/notebook-edit.js +19 -10
  130. package/dist/tools/builtins/notebook-edit.js.map +1 -1
  131. package/dist/tools/builtins/read-file.d.ts.map +1 -1
  132. package/dist/tools/builtins/read-file.js +48 -24
  133. package/dist/tools/builtins/read-file.js.map +1 -1
  134. package/dist/tools/builtins/read-regular-file.d.ts +5 -0
  135. package/dist/tools/builtins/read-regular-file.d.ts.map +1 -0
  136. package/dist/tools/builtins/read-regular-file.js +23 -0
  137. package/dist/tools/builtins/read-regular-file.js.map +1 -0
  138. package/dist/tools/builtins/search-support.d.ts +2 -0
  139. package/dist/tools/builtins/search-support.d.ts.map +1 -1
  140. package/dist/tools/builtins/search-support.js +14 -0
  141. package/dist/tools/builtins/search-support.js.map +1 -1
  142. package/dist/tools/builtins/stale-before-review.d.ts.map +1 -1
  143. package/dist/tools/builtins/stale-before-review.js +8 -5
  144. package/dist/tools/builtins/stale-before-review.js.map +1 -1
  145. package/dist/tools/builtins/write-file.d.ts.map +1 -1
  146. package/dist/tools/builtins/write-file.js +17 -13
  147. package/dist/tools/builtins/write-file.js.map +1 -1
  148. package/dist/tools/coordinator/agent.d.ts.map +1 -1
  149. package/dist/tools/coordinator/agent.js +6 -0
  150. package/dist/tools/coordinator/agent.js.map +1 -1
  151. package/dist/tools/coordinator/index.d.ts.map +1 -1
  152. package/dist/tools/coordinator/index.js +6 -0
  153. package/dist/tools/coordinator/index.js.map +1 -1
  154. package/dist/tools/coordinator/progress.d.ts +9 -0
  155. package/dist/tools/coordinator/progress.d.ts.map +1 -0
  156. package/dist/tools/coordinator/progress.js +30 -0
  157. package/dist/tools/coordinator/progress.js.map +1 -0
  158. package/dist/tools/paths.d.ts +9 -0
  159. package/dist/tools/paths.d.ts.map +1 -1
  160. package/dist/tools/paths.js +39 -9
  161. package/dist/tools/paths.js.map +1 -1
  162. package/dist/tools/posix-path.d.ts +2 -14
  163. package/dist/tools/posix-path.d.ts.map +1 -1
  164. package/dist/tools/posix-path.js +7 -0
  165. package/dist/tools/posix-path.js.map +1 -1
  166. package/dist/tools/shell-output-window.d.ts +12 -0
  167. package/dist/tools/shell-output-window.d.ts.map +1 -0
  168. package/dist/tools/shell-output-window.js +92 -0
  169. package/dist/tools/shell-output-window.js.map +1 -0
  170. package/dist/types/acp/index.d.ts +3 -0
  171. package/dist/types/acp/index.d.ts.map +1 -1
  172. package/dist/types/browser/index.d.ts +4 -0
  173. package/dist/types/browser/index.d.ts.map +1 -1
  174. package/dist/types/code-analysis/index.d.ts +1 -1
  175. package/dist/types/code-analysis/index.d.ts.map +1 -1
  176. package/dist/types/computer-use/index.d.ts +4 -0
  177. package/dist/types/computer-use/index.d.ts.map +1 -1
  178. package/dist/types/provider/errors.d.ts.map +1 -1
  179. package/dist/types/provider/errors.js +3 -5
  180. package/dist/types/provider/errors.js.map +1 -1
  181. package/dist/types/session/checkpoint.d.ts +13 -0
  182. package/dist/types/session/checkpoint.d.ts.map +1 -1
  183. package/dist/types/session/checkpoint.js +33 -0
  184. package/dist/types/session/checkpoint.js.map +1 -1
  185. package/dist/types/session/events.d.ts +3 -0
  186. package/dist/types/session/events.d.ts.map +1 -1
  187. package/dist/types/session/events.js.map +1 -1
  188. package/dist/types/tool/index.d.ts +17 -0
  189. package/dist/types/tool/index.d.ts.map +1 -1
  190. package/dist/types/tool/index.js.map +1 -1
  191. package/dist/types/tool/presentation.d.ts +8 -0
  192. package/dist/types/tool/presentation.d.ts.map +1 -1
  193. package/package.json +1 -1
  194. package/src/bridge/acp/server.ts +22 -8
  195. package/src/bridge/acp/update.ts +23 -2
  196. package/src/connector/mcp/adapter.ts +4 -3
  197. package/src/connector/mcp/client.ts +33 -32
  198. package/src/provider/errors.ts +12 -19
  199. package/src/provider/stream-request-timeout.ts +34 -0
  200. package/src/public-runtime.ts +3 -0
  201. package/src/public-tools.ts +1 -0
  202. package/src/runtime/query/executor.ts +41 -6
  203. package/src/runtime/query/file-evidence-replay.ts +73 -19
  204. package/src/runtime/query/file-evidence-seed.ts +16 -0
  205. package/src/runtime/query/index.ts +9 -1
  206. package/src/runtime/query/path-escalation.ts +4 -3
  207. package/src/runtime/query/tooling.ts +3 -0
  208. package/src/sandbox/provider/local.ts +53 -25
  209. package/src/schedules/cron.ts +1 -1
  210. package/src/schedules/describe.ts +1 -1
  211. package/src/schedules/next-fire.ts +7 -4
  212. package/src/schedules/spec.ts +36 -7
  213. package/src/schedules/types.ts +2 -0
  214. package/src/session/workspace/git-worktree.ts +115 -1
  215. package/src/session/workspace/index.ts +6 -1
  216. package/src/store/checkpoint/contract.ts +9 -2
  217. package/src/store/session-index/sqlite.ts +8 -4
  218. package/src/store/session-log/core.ts +130 -26
  219. package/src/store/session-log/disk.ts +1 -1
  220. package/src/tools/admit-facts.ts +20 -0
  221. package/src/tools/builtins/bash.ts +11 -12
  222. package/src/tools/builtins/browser.ts +16 -3
  223. package/src/tools/builtins/code-analysis.ts +6 -1
  224. package/src/tools/builtins/computer-use.ts +188 -44
  225. package/src/tools/builtins/edit-apply.ts +25 -10
  226. package/src/tools/builtins/edit.ts +31 -15
  227. package/src/tools/builtins/file-text.ts +14 -0
  228. package/src/tools/builtins/glob.ts +6 -1
  229. package/src/tools/builtins/grep.ts +7 -5
  230. package/src/tools/builtins/ls.ts +2 -1
  231. package/src/tools/builtins/notebook-edit.ts +18 -11
  232. package/src/tools/builtins/read-file.ts +52 -27
  233. package/src/tools/builtins/read-regular-file.ts +25 -0
  234. package/src/tools/builtins/search-support.ts +13 -0
  235. package/src/tools/builtins/stale-before-review.ts +8 -6
  236. package/src/tools/builtins/write-file.ts +18 -12
  237. package/src/tools/coordinator/agent.ts +6 -0
  238. package/src/tools/coordinator/index.ts +6 -0
  239. package/src/tools/coordinator/progress.ts +40 -0
  240. package/src/tools/paths.ts +49 -7
  241. package/src/tools/posix-path.ts +9 -0
  242. package/src/tools/shell-output-window.ts +97 -0
  243. package/src/types/acp/index.ts +3 -0
  244. package/src/types/browser/index.ts +2 -0
  245. package/src/types/code-analysis/index.ts +1 -1
  246. package/src/types/computer-use/index.ts +17 -0
  247. package/src/types/provider/errors.ts +3 -5
  248. package/src/types/session/checkpoint.ts +37 -0
  249. package/src/types/session/events.ts +3 -0
  250. package/src/types/tool/index.ts +12 -0
  251. package/src/types/tool/presentation.ts +12 -1
@@ -0,0 +1,97 @@
1
+ import type { ToolOutputWindow } from '../types/tool/index.js'
2
+ import { plainTerminalText } from '../utils/plain-terminal-text.js'
3
+
4
+ const MAX_LINES = 200
5
+ const MAX_BYTES = 32 * 1024
6
+
7
+ export function limitOutputLines(lines: readonly string[], omitted: number) {
8
+ const kept: string[] = []
9
+ let bytes = 0
10
+ for (let index = lines.length - 1; index >= Math.max(0, lines.length - MAX_LINES); index--) {
11
+ const line = lines[index] ?? ''
12
+ const size = Buffer.byteLength(line) + 1
13
+ if (bytes + size > MAX_BYTES) break
14
+ bytes += size
15
+ kept.push(line)
16
+ }
17
+ return { lines: kept.reverse(), omitted: omitted + lines.length - kept.length }
18
+ }
19
+
20
+ export function limitOutputWindow(output: ToolOutputWindow): ToolOutputWindow {
21
+ return {
22
+ sequence: output.sequence,
23
+ stdout: limitOutputLines(output.stdout.lines, output.stdout.omitted),
24
+ stderr: limitOutputLines(output.stderr.lines, output.stderr.omitted),
25
+ }
26
+ }
27
+
28
+ class StreamWindow {
29
+ private partial = ''
30
+ private oversized = false
31
+ private completed: { line: string; bytes: number }[] = []
32
+ private bytes = 0
33
+ private omitted = 0
34
+
35
+ append(data: string) {
36
+ let start = 0
37
+ for (let end = data.indexOf('\n'); end >= 0; end = data.indexOf('\n', start)) {
38
+ this.appendPartial(data.slice(start, end))
39
+ this.completeLine()
40
+ this.partial = ''
41
+ this.oversized = false
42
+ start = end + 1
43
+ }
44
+ this.appendPartial(data.slice(start))
45
+ }
46
+
47
+ private completeLine() {
48
+ const line = this.oversized ? '' : plainTerminalText(this.partial.replace(/\r$/, ''))
49
+ const bytes = this.oversized ? MAX_BYTES + 1 : Buffer.byteLength(line) + 1
50
+ if (bytes > MAX_BYTES) {
51
+ this.omitted += this.completed.length + 1
52
+ this.completed = []
53
+ this.bytes = 0
54
+ return
55
+ }
56
+ while (this.completed.length >= MAX_LINES || this.bytes + bytes > MAX_BYTES) {
57
+ const oldest = this.completed.shift()
58
+ if (!oldest) break
59
+ this.bytes -= oldest.bytes
60
+ this.omitted++
61
+ }
62
+ this.completed.push({ line, bytes })
63
+ this.bytes += bytes
64
+ }
65
+
66
+ private appendPartial(text: string) {
67
+ if (this.oversized) return
68
+ if (this.partial.length + text.length > MAX_BYTES) {
69
+ this.partial = ''
70
+ this.oversized = true
71
+ return
72
+ }
73
+ this.partial += text
74
+ }
75
+
76
+ snapshot(): ToolOutputWindow['stdout'] {
77
+ if (this.oversized) return { lines: [], omitted: this.omitted + this.completed.length + 1 }
78
+ const lines = this.completed.map(({ line }) => line)
79
+ const partial = plainTerminalText(this.partial)
80
+ if (partial) return limitOutputLines([...lines, partial], this.omitted)
81
+ return { lines, omitted: this.omitted }
82
+ }
83
+ }
84
+
85
+ export class ShellOutputWindow {
86
+ private streams = { stdout: new StreamWindow(), stderr: new StreamWindow() }
87
+ private sequence = 0
88
+
89
+ append(stream: 'stdout' | 'stderr', data: string): ToolOutputWindow {
90
+ this.streams[stream].append(data)
91
+ return {
92
+ sequence: ++this.sequence,
93
+ stdout: this.streams.stdout.snapshot(),
94
+ stderr: this.streams.stderr.snapshot(),
95
+ }
96
+ }
97
+ }
@@ -301,6 +301,8 @@ export type AcpSessionUpdate =
301
301
  */
302
302
  | {
303
303
  readonly kind: 'tool_call'
304
+ readonly childSessionId?: string
305
+ readonly childStatus?: import('../agent/task.js').AgentTaskState
304
306
  readonly toolCallId: string
305
307
  readonly title: string
306
308
  readonly status: 'pending' | 'completed' | 'failed'
@@ -317,6 +319,7 @@ export type AcpSessionUpdate =
317
319
  readonly progress?: {
318
320
  readonly message: string
319
321
  readonly fraction?: number
322
+ readonly output?: import('../tool/index.js').ToolOutputWindow
320
323
  }
321
324
  }
322
325
  /**
@@ -302,6 +302,8 @@ export interface BrowserValue {
302
302
  * the tool renders whichever are present.
303
303
  */
304
304
  export interface BrowserResult {
305
+ /** The preferred pane failed to open and this result came from the host's own browser. */
306
+ readonly paneFallback?: { readonly reason: string }
305
307
  /** The page after the action. */
306
308
  readonly page?: BrowserPageInfo
307
309
  /**
@@ -206,7 +206,7 @@ export interface FindLiteralRequest extends AnalysisPaging {
206
206
  readonly text: string
207
207
  /** Absolute file or directory to restrict the search to. */
208
208
  readonly path?: string
209
- /** Default `true`. */
209
+ /** Default `true`. Set to `false` for Unicode simple case folding without locale tailoring. */
210
210
  readonly caseSensitive?: boolean
211
211
  }
212
212
 
@@ -487,7 +487,24 @@ export interface ComputerUseOutcomeUnknown {
487
487
  // Implementations live outside @namzu/sdk (e.g. @namzu/computer-use).
488
488
  // ---------------------------------------------------------------------------
489
489
 
490
+ export type ComputerUseTimingStage =
491
+ | 'list_windows'
492
+ | 'ui_snapshot'
493
+ | 'capture_encode'
494
+ | 'input_delivery'
495
+ | 'verify_reads'
496
+ | 'settle_wait'
497
+ | 'foreground_gate'
498
+
499
+ export type ComputerUseStageTimes = Partial<Record<ComputerUseTimingStage, number>>
500
+
490
501
  export interface ComputerUseHost {
502
+ /** Collect stage durations for the asynchronous work of one tool call. */
503
+ withTiming?<T>(
504
+ record: (stage: ComputerUseTimingStage, ms: number) => void,
505
+ run: () => Promise<T>,
506
+ ): Promise<T>
507
+
491
508
  readonly id: string
492
509
  readonly capabilities: ComputerUseCapabilities
493
510
 
@@ -497,6 +497,7 @@ const STRUCTURAL_CODES: Readonly<Record<string, ProviderErrorCode>> = {
497
497
  usage_limit_reached: 'usage_limit',
498
498
  usage_limit_exceeded: 'usage_limit',
499
499
  billing_error: 'usage_limit',
500
+ credits_required: 'usage_limit',
500
501
  overloaded_error: 'overloaded',
501
502
  content_filter: 'content_filter',
502
503
  content_policy_violation: 'content_filter',
@@ -507,14 +508,11 @@ const STRUCTURAL_CODES: Readonly<Record<string, ProviderErrorCode>> = {
507
508
  }
508
509
 
509
510
  /**
510
- * Is this exact provider code, or the provider's own complaint, a spent
511
- * allowance? The codes are the vendors' identifiers (`insufficient_quota`,
512
- * `usage_limit_reached`, `usage_limit_exceeded`, `billing_error`); the
513
- * sentences are the two vendors that word it only in prose: an exhausted
514
- * prepaid balance and an exhausted plan allowance.
511
+ * Provider wording for exhausted allowances and required credits.
515
512
  */
516
513
  const USAGE_LIMIT_DETAIL: readonly RegExp[] = [
517
514
  /credit balance is too low/i,
515
+ /credits are required/i,
518
516
  /exceeded your current quota/i,
519
517
  /usage limit (?:has been )?(?:reached|exceeded)/i,
520
518
  ]
@@ -88,6 +88,43 @@ export const TokenUsageSchema = z
88
88
  })
89
89
  .strict()
90
90
 
91
+ /** The usage a checkpoint or a session record keeps, as {@link TokenUsageSchema} reads it. */
92
+ export type PersistedTokenUsage = z.infer<typeof TokenUsageSchema>
93
+
94
+ /**
95
+ * The part of a usage total that a checkpoint or a session record keeps: the keys
96
+ * {@link TokenUsageSchema} names. A usage total gained summed fields (hosted web search
97
+ * requests, a cost the provider reported) after that shape shipped, and every reader
98
+ * validates it strictly, so writing them would make each such checkpoint and record
99
+ * unreadable to an older Desktop app or CLI sharing the session folder (and was refused
100
+ * by this release's own check, which ended every web-search turn without a checkpoint or
101
+ * a closing record). They are left out of what is written instead; the turn's cost is
102
+ * kept in its own field.
103
+ */
104
+ export function persistedTokenUsage(usage: TokenUsage): PersistedTokenUsage {
105
+ const ttl = usage.cacheWriteTtlTokens
106
+ return {
107
+ promptTokens: usage.promptTokens,
108
+ completionTokens: usage.completionTokens,
109
+ totalTokens: usage.totalTokens,
110
+ cachedTokens: usage.cachedTokens,
111
+ cacheWriteTokens: usage.cacheWriteTokens,
112
+ ...(usage.cacheTokensInPrompt !== undefined
113
+ ? { cacheTokensInPrompt: usage.cacheTokensInPrompt }
114
+ : {}),
115
+ ...(usage.reasoningTokens !== undefined ? { reasoningTokens: usage.reasoningTokens } : {}),
116
+ ...(usage.cacheTtlMs !== undefined ? { cacheTtlMs: usage.cacheTtlMs } : {}),
117
+ ...(ttl
118
+ ? {
119
+ cacheWriteTtlTokens: {
120
+ ...(ttl.fiveMin !== undefined ? { fiveMin: ttl.fiveMin } : {}),
121
+ ...(ttl.oneHour !== undefined ? { oneHour: ttl.oneHour } : {}),
122
+ },
123
+ }
124
+ : {}),
125
+ }
126
+ }
127
+
91
128
  export const CostInfoSchema = z
92
129
  .object({
93
130
  inputCostPer1M: z.number().nonnegative().optional(),
@@ -487,6 +487,9 @@ type CoreSessionEvent =
487
487
  fraction?: number
488
488
  /** Lines of output the call has produced so far, when the tool counts them (a shell command). Cumulative: the newest report wins. */
489
489
  outputLines?: number
490
+ readonly childSessionId?: string
491
+ readonly childStatus?: import('../agent/task.js').AgentTaskState
492
+ output?: import('../tool/index.js').ToolOutputWindow
490
493
  }
491
494
  /** Provider-executed activity, retained as evidence rather than a local tool request. */
492
495
  | {
@@ -692,6 +692,8 @@ export interface ToolContext {
692
692
  * directory; an absolute path inside any of these is accepted.
693
693
  */
694
694
  additionalDirectories?: readonly string[]
695
+ /** Host-owned absolute file paths available to read, write and edit, including in a sandbox. */
696
+ allowedFiles?: readonly string[]
695
697
  /**
696
698
  * Whether the session's read rules deny an absolute path. The search tools
697
699
  * (`grep`, `glob`) call it for every file they would list or open and skip
@@ -1098,10 +1100,20 @@ export interface ToolContext {
1098
1100
  report?: (message: string, fraction?: number, details?: ToolProgressDetails) => void
1099
1101
  }
1100
1102
 
1103
+ /** A bounded snapshot of a running command's recent plain-text output. */
1104
+ export interface ToolOutputWindow {
1105
+ readonly sequence: number
1106
+ readonly stdout: { readonly lines: readonly string[]; readonly omitted: number }
1107
+ readonly stderr: { readonly lines: readonly string[]; readonly omitted: number }
1108
+ }
1109
+
1101
1110
  /** Facts a tool can attach to a progress report besides its words. */
1102
1111
  export interface ToolProgressDetails {
1112
+ readonly childSessionId?: string
1113
+ readonly childStatus?: import('../agent/task.js').AgentTaskState
1103
1114
  /** Lines of output the call has produced so far, counted by the tool itself (never by a renderer from what it was shown). */
1104
1115
  readonly outputLines?: number
1116
+ readonly output?: ToolOutputWindow
1105
1117
  }
1106
1118
 
1107
1119
  export interface ToolResult {
@@ -62,7 +62,12 @@ export type ToolCallView =
62
62
  readonly after: string
63
63
  }
64
64
  /** A command and what it printed. */
65
- | { readonly kind: 'terminal'; readonly command?: string; readonly output: string }
65
+ | {
66
+ readonly kind: 'terminal'
67
+ readonly command?: string
68
+ readonly output: string
69
+ readonly paneFallback?: { readonly reason: string }
70
+ }
66
71
 
67
72
  /**
68
73
  * A bounded window onto a block of text: the first lines, the last lines, and
@@ -131,6 +136,12 @@ export type ToolFailureReason =
131
136
  * Paths are as the tool resolved them; a host shortens them for display.
132
137
  */
133
138
  export type ToolFacts =
139
+ | {
140
+ readonly kind: 'delegate'
141
+ readonly description?: string
142
+ readonly childSessionId?: string
143
+ readonly childStatus?: import('../agent/task.js').AgentTaskState
144
+ }
134
145
  | {
135
146
  readonly kind: 'command'
136
147
  /** The command line, on the call. */