@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
@@ -1008,16 +1008,9 @@ export class MCPClient {
1008
1008
  /**
1009
1009
  * Every tool this server publishes that this client is willing to expose.
1010
1010
  *
1011
- * Two clauses refuse, and both refuse ONE entry rather than the listing.
1012
- * An entry that is not an object at all is dropped by
1013
- * {@link admitToolEntries}, with its position logged — `tools/list` is
1014
- * the server's own JSON, and a single `null` used to reach the schema
1015
- * adapter and throw there, costing every other tool the server offered.
1016
- * A tool whose `inputSchema` carries an invalid `x-mcp-header` annotation
1017
- * is dropped by {@link admitToolHeaderAnnotations}, with the tool name
1018
- * and the reason logged — the spec's requirement, and the reason it is a
1019
- * requirement is that the annotation names a header this client would
1020
- * otherwise write from a value it cannot vouch for.
1011
+ * Malformed and duplicate tool entries are skipped individually by
1012
+ * {@link admitToolEntries}. On HTTP, {@link admitToolHeaderAnnotations}
1013
+ * also drops tools with invalid `x-mcp-header` annotations.
1021
1014
  *
1022
1015
  * It lives HERE rather than in `MCPToolDiscovery` or the tool adapter
1023
1016
  * because the shipping CLI calls `listTools()` directly and never
@@ -1032,33 +1025,41 @@ export class MCPClient {
1032
1025
  return this.era?.kind === 'modern' ? sortedByName(admitted) : admitted
1033
1026
  }
1034
1027
 
1035
- /**
1036
- * Drop entries that are not tool definitions at all, and keep the rest.
1037
- *
1038
- * `tools/list` is parsed JSON from a server this client does not trust,
1039
- * and the array was taken exactly as sent: one `null`, string, number or
1040
- * array among fifty well-formed entries travelled as far as the schema
1041
- * adapter, where reading `.inputSchema` off it threw and took the whole
1042
- * listing down — every tool that server offered, and in a headless run
1043
- * the session with it. One bad entry costs one tool.
1044
- *
1045
- * The warning names the position rather than the tool, because an entry
1046
- * this malformed has no name to be named by. The position is its index
1047
- * in the flattened listing, across pages, so it points at what the server
1048
- * sent.
1049
- */
1028
+ /** Keep the first usable definition for each name in the flattened listing. */
1050
1029
  private admitToolEntries(tools: readonly MCPToolDefinition[]): MCPToolDefinition[] {
1051
1030
  const admitted: MCPToolDefinition[] = []
1031
+ const names = new Set<string>()
1052
1032
  for (const [index, entry] of tools.entries()) {
1053
- if (typeof entry === 'object' && entry !== null && !Array.isArray(entry)) {
1054
- admitted.push(entry)
1033
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
1034
+ this.log.warn('Skipped a malformed entry in the MCP tool list', {
1035
+ 'namzu.connector.server': this.config.serverName,
1036
+ 'namzu.connector.index': index,
1037
+ 'namzu.connector.entry_type': describeToolEntry(entry),
1038
+ })
1055
1039
  continue
1056
1040
  }
1057
- this.log.warn('Skipped a malformed entry in the MCP tool list', {
1058
- 'namzu.connector.server': this.config.serverName,
1059
- 'namzu.connector.index': index,
1060
- 'namzu.connector.entry_type': describeToolEntry(entry),
1061
- })
1041
+ const name = typeof entry.name === 'string' ? entry.name : ''
1042
+ const schema = entry.inputSchema
1043
+ const reason =
1044
+ name.trim() === ''
1045
+ ? 'missing or invalid name'
1046
+ : schema !== undefined &&
1047
+ (typeof schema !== 'object' || schema === null || Array.isArray(schema))
1048
+ ? 'invalid inputSchema'
1049
+ : names.has(name)
1050
+ ? 'duplicate tool name'
1051
+ : undefined
1052
+ if (reason !== undefined) {
1053
+ this.log.warn('Skipped a malformed entry in the MCP tool list', {
1054
+ 'namzu.connector.server': this.config.serverName,
1055
+ 'namzu.connector.index': index,
1056
+ ...(name ? { 'namzu.mcp.tool': name } : {}),
1057
+ 'namzu.mcp.reason': reason,
1058
+ })
1059
+ continue
1060
+ }
1061
+ names.add(name)
1062
+ admitted.push(entry)
1062
1063
  }
1063
1064
  return admitted
1064
1065
  }
@@ -135,25 +135,18 @@ function providerCode(value: unknown): string | undefined {
135
135
  }
136
136
 
137
137
  /**
138
- * A vendor can name a spent allowance in `type` instead of `code`
139
- * (`{"error":{"type":"usage_limit_reached"}}`, `{"error":{"type":"billing_error"}}`).
140
- * Only those identifiers are lifted to a provider code; any other `type` is a
141
- * category and stays where it was.
138
+ * A vendor can report an allowance failure in `type` or in the error's
139
+ * `details.error_code`. Lift known allowance identifiers to a provider code.
142
140
  */
143
- function usageLimitTypeOf(error: unknown): string | undefined {
144
- if (typeof error !== 'object' || error === null) return undefined
145
- const outer = error as { type?: unknown; error?: unknown }
146
- const inner =
147
- typeof outer.error === 'object' && outer.error !== null
148
- ? (outer.error as { type?: unknown; error?: unknown })
149
- : undefined
150
- const innermost =
151
- typeof inner?.error === 'object' && inner.error !== null
152
- ? (inner.error as { type?: unknown })
153
- : undefined
154
- for (const candidate of [outer.type, inner?.type, innermost?.type]) {
155
- if (typeof candidate === 'string' && isUsageLimitSignal(candidate, undefined)) {
156
- return safeProviderCode(candidate)
141
+ function usageLimitCodeOf(error: unknown): string | undefined {
142
+ const outer = parsedBody(error)
143
+ const inner = parsedBody(outer?.error)
144
+ const innermost = parsedBody(inner?.error)
145
+ for (const record of [outer, inner, innermost]) {
146
+ const details = parsedBody(record?.details)
147
+ for (const value of [details?.error_code, record?.error_code, record?.type]) {
148
+ const code = safeProviderCode(value)
149
+ if (code !== undefined && isUsageLimitSignal(code, undefined)) return code
157
150
  }
158
151
  }
159
152
  return undefined
@@ -581,7 +574,7 @@ export function providerVendorError(input: {
581
574
  }): ProviderRequestError {
582
575
  const { error } = input
583
576
  const status = vendorErrorStatus(error)
584
- const exactProviderCode = providerCode(error) ?? usageLimitTypeOf(error)
577
+ const exactProviderCode = providerCode(error) ?? usageLimitCodeOf(error)
585
578
  const name = error instanceof Error ? error.name : ''
586
579
  const message = error instanceof Error ? error.message : ''
587
580
 
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Give each network operation in a streaming request a fresh timeout, using
3
+ * one signal for fetch and its body. Run the setup and each body read in
4
+ * sequence so time spent processing or yielding chunks uses no timer.
5
+ */
6
+ export function createStreamRequestTimeout(timeoutMs: number, caller?: AbortSignal) {
7
+ if (!Number.isInteger(timeoutMs) || timeoutMs < 0 || timeoutMs > 0xffff_ffff) {
8
+ throw new RangeError('Stream timeout must be an unsigned 32-bit integer in milliseconds')
9
+ }
10
+ const controller = new AbortController()
11
+ const signal = caller ? AbortSignal.any([caller, controller.signal]) : controller.signal
12
+
13
+ return {
14
+ async run<T>(operation: (signal: AbortSignal) => Promise<T>): Promise<T> {
15
+ signal.throwIfAborted()
16
+ const timer = setTimeout(() => {
17
+ controller.abort(
18
+ new DOMException('The operation was aborted due to timeout', 'TimeoutError'),
19
+ )
20
+ }, timeoutMs)
21
+ timer.unref()
22
+ try {
23
+ const result = await operation(signal)
24
+ signal.throwIfAborted()
25
+ return result
26
+ } catch (error) {
27
+ signal.throwIfAborted()
28
+ throw error
29
+ } finally {
30
+ clearTimeout(timer)
31
+ }
32
+ },
33
+ }
34
+ }
@@ -1014,6 +1014,7 @@ export {
1014
1014
 
1015
1015
  // ─── providers, sandbox, vault ───────────────────────────────────────────
1016
1016
 
1017
+ export { createStreamRequestTimeout } from './provider/stream-request-timeout.js'
1017
1018
  export {
1018
1019
  classifyProviderError,
1019
1020
  DEFAULT_PROVIDER_RETRY,
@@ -1458,6 +1459,7 @@ export {
1458
1459
  GitWorktreeDriver,
1459
1460
  DiskWorkspaceHoldStore,
1460
1461
  WorkspaceInUseError,
1462
+ LinkedCheckoutError,
1461
1463
  defaultWorkspaceHoldsDir,
1462
1464
  defaultWorktreesDir,
1463
1465
  HookedWorkspaceDriver,
@@ -2091,6 +2093,7 @@ export type {
2091
2093
  ComputerUseObservation,
2092
2094
  ComputerUseTool,
2093
2095
  ComputerUseToolOptions,
2096
+ ComputerUseTimingRecord,
2094
2097
  ImageSize,
2095
2098
  ScreenshotLimits,
2096
2099
  } from './tools/builtins/computer-use.js'
@@ -335,6 +335,7 @@ export type { LedgerReplayReport } from './runtime/query/file-evidence-replay.js
335
335
  */
336
336
  export {
337
337
  type ObservationSeedContext,
338
+ replayFileComparisonBodies,
338
339
  seedObservationLedger,
339
340
  } from './runtime/query/file-evidence-seed.js'
340
341
 
@@ -22,10 +22,18 @@ import {
22
22
  } from '../../tools/builtins/bash-cwd.js'
23
23
  import { BashTool } from '../../tools/builtins/bash.js'
24
24
  import { fingerprintContent } from '../../tools/builtins/content-fingerprint.js'
25
+ import { EditTool } from '../../tools/builtins/edit.js'
26
+ import { ReadFileTool } from '../../tools/builtins/read-file.js'
27
+ import { WriteFileTool } from '../../tools/builtins/write-file.js'
25
28
  import { sandboxShellSpawn, withoutBashStartup } from '../../tools/command-shell.js'
26
29
  import { isAlwaysDestructive } from '../../tools/defineTool.js'
27
30
  import { createFileReadTracker } from '../../tools/file-read-tracker.js'
28
- import { pathOutsideRoots, resolveWithinAnyReal, toolRoots } from '../../tools/paths.js'
31
+ import {
32
+ isAllowedFile,
33
+ pathOutsideRoots,
34
+ resolveWithinAnyReal,
35
+ toolRoots,
36
+ } from '../../tools/paths.js'
29
37
  import { resolveRetainedOutput } from '../../tools/retained-output.js'
30
38
  import { isTrustedReadOnly } from '../../tools/trusted-read-only.js'
31
39
  import type { ToolManager } from '../../toolsets/manager.js'
@@ -292,7 +300,7 @@ function boundedToolProgress(message: string): string {
292
300
  */
293
301
  class ToolProgressPublisher {
294
302
  private pending:
295
- | { readonly message: string; readonly fraction?: number; readonly outputLines?: number }
303
+ | (ToolProgressDetails & { readonly message: string; readonly fraction?: number })
296
304
  | undefined
297
305
  private draining: Promise<void> | null = null
298
306
  private accepting = true
@@ -301,7 +309,7 @@ class ToolProgressPublisher {
301
309
  private readonly emitEvent: EmitEvent,
302
310
  private readonly base: Omit<
303
311
  Extract<SessionEventDraft, { type: 'tool_progress' }>,
304
- 'message' | 'fraction' | 'outputLines'
312
+ 'message' | 'fraction' | 'outputLines' | 'output'
305
313
  >,
306
314
  ) {}
307
315
 
@@ -309,6 +317,9 @@ class ToolProgressPublisher {
309
317
  if (!this.accepting) return
310
318
  this.pending = {
311
319
  message,
320
+ childSessionId: details?.childSessionId,
321
+ childStatus: details?.childStatus,
322
+ ...(details?.output ? { output: details.output } : {}),
312
323
  ...(fraction !== undefined ? { fraction: Math.min(1, Math.max(0, fraction)) } : {}),
313
324
  ...(details?.outputLines !== undefined && Number.isFinite(details.outputLines)
314
325
  ? { outputLines: Math.max(0, Math.floor(details.outputLines)) }
@@ -346,6 +357,9 @@ class ToolProgressPublisher {
346
357
  await this.emitEvent({
347
358
  ...this.base,
348
359
  message: boundedToolProgress(update.message),
360
+ ...(update.childSessionId ? { childSessionId: update.childSessionId } : {}),
361
+ ...(update.childStatus ? { childStatus: update.childStatus } : {}),
362
+ ...(update.output ? { output: update.output } : {}),
349
363
  ...(update.fraction !== undefined ? { fraction: update.fraction } : {}),
350
364
  ...(update.outputLines !== undefined ? { outputLines: update.outputLines } : {}),
351
365
  }).catch(() => {})
@@ -402,6 +416,8 @@ export interface ToolExecutorConfig {
402
416
  workingDirectory: string
403
417
  /** See `ToolContext.additionalDirectories`. */
404
418
  additionalDirectories?: readonly string[]
419
+ /** Host-owned absolute file paths available to read, write and edit, including in a sandbox. */
420
+ allowedFiles?: readonly string[]
405
421
  /**
406
422
  * Where this session's own scratch folder is. It becomes a root of the file
407
423
  * tools once it has been made and checked, a write inside it needs no review,
@@ -1475,6 +1491,18 @@ export class ToolExecutor {
1475
1491
  return this.publishPreparedBatch(calls, escalations, scratchpadWrites)
1476
1492
  }
1477
1493
 
1494
+ private isAllowedToolFile(tool: ToolDefinition, path: string): boolean {
1495
+ return (
1496
+ (tool.execute === ReadFileTool.execute ||
1497
+ tool.execute === WriteFileTool.execute ||
1498
+ tool.execute === EditTool.execute) &&
1499
+ isAllowedFile(
1500
+ { workingDirectory: this.config.workingDirectory, allowedFiles: this.config.allowedFiles },
1501
+ path,
1502
+ )
1503
+ )
1504
+ }
1505
+
1478
1506
  /**
1479
1507
  * A file tool's path outside the roots, refused with the host's own words
1480
1508
  * (`QueryParams.outsideRootRefusal`) instead of the tool's generic one.
@@ -1498,7 +1526,7 @@ export class ToolExecutor {
1498
1526
  try {
1499
1527
  const retained =
1500
1528
  tool.name === 'read' && (await resolveRetainedOutput(this.outputDirectory(), value))
1501
- if (retained) return call
1529
+ if (retained || this.isAllowedToolFile(tool, value)) return call
1502
1530
  const outside = await pathOutsideRoots(this.rootsNow(), value)
1503
1531
  if (outside === undefined) return call
1504
1532
  return {
@@ -1624,7 +1652,10 @@ export class ToolExecutor {
1624
1652
  // result that was cut told the model to look.
1625
1653
  const retained =
1626
1654
  tool.name === 'read' && (await resolveRetainedOutput(this.outputDirectory(), value))
1627
- const outside = retained ? undefined : await pathOutsideRoots(this.rootsNow(), value)
1655
+ const outside =
1656
+ retained || this.isAllowedToolFile(tool, value)
1657
+ ? undefined
1658
+ : await pathOutsideRoots(this.rootsNow(), value)
1628
1659
  if (outside !== undefined) outsidePaths = [outside]
1629
1660
  }
1630
1661
  }
@@ -2762,7 +2793,10 @@ export class ToolExecutor {
2762
2793
  )
2763
2794
  return saved ? { savedPresentation: saved } : {}
2764
2795
  }
2765
- if (savedOnly || view?.kind !== 'diff') {
2796
+ // A terminal view that carries a pane fallback is drawn live too: the host shows a
2797
+ // notice beside the call, and the generic result view has no field for it.
2798
+ const liveView = view?.kind === 'diff' || (view?.kind === 'terminal' && view.paneFallback)
2799
+ if (savedOnly || !liveView) {
2766
2800
  // Journal-only: the live event keeps drawing the real result.
2767
2801
  const tool = this.config.tools.get(name)
2768
2802
  const saved = savedPresentation(input, tool?.presentCall?.(input), view)
@@ -2791,6 +2825,7 @@ export class ToolExecutor {
2791
2825
  ...(this.additionalDirectoriesNow()?.length
2792
2826
  ? { additionalDirectories: this.additionalDirectoriesNow() }
2793
2827
  : {}),
2828
+ ...(this.config.allowedFiles?.length ? { allowedFiles: this.config.allowedFiles } : {}),
2794
2829
  ...(this.config.authorizationGate
2795
2830
  ? {
2796
2831
  readDenied: (absolutePath: string) =>
@@ -6,6 +6,7 @@ import { ReadFileTool } from '../../tools/builtins/read-file.js'
6
6
  import {
7
7
  LINE_NUMBER_WIDTH,
8
8
  type ReadWindowRequest,
9
+ linePrefix,
9
10
  renderNumberedRead,
10
11
  resolveReadWindow,
11
12
  } from '../../tools/builtins/read-render.js'
@@ -498,6 +499,29 @@ export function replayObservationLedger(
498
499
  keyOf: FileKeyResolver,
499
500
  attributions: PathAttributions = createPathAttributions(),
500
501
  ): LedgerReplayReport {
502
+ const { claims, budget } = replayClaims(messages, keyOf, attributions, false)
503
+ return commit(tracker, claims, budget)
504
+ }
505
+
506
+ export function replayComparisonClaims(
507
+ messages: readonly Message[],
508
+ keyOf: FileKeyResolver,
509
+ attributions: PathAttributions,
510
+ ): ReadonlyMap<string, string> {
511
+ const { claims } = replayClaims(messages, keyOf, attributions, true)
512
+ const bodies = new Map<string, string>()
513
+ for (const [key, claim] of claims) {
514
+ if (claim.kind === 'content') bodies.set(key, claim.body)
515
+ }
516
+ return bodies
517
+ }
518
+
519
+ function replayClaims(
520
+ messages: readonly Message[],
521
+ keyOf: FileKeyResolver,
522
+ attributions: PathAttributions,
523
+ compareReads: boolean,
524
+ ): { claims: Map<string, Claim>; budget: ReplayBudget } {
501
525
  const history = indexVisibleHistory(messages, keyOf)
502
526
  const budget = createReplayBudget()
503
527
  const claims = new Map<string, Claim>()
@@ -517,14 +541,15 @@ export function replayObservationLedger(
517
541
  // be the one showing a body this walk is holding to be something else,
518
542
  // and skipping the read past would keep a claim that very observation
519
543
  // withdrew. Both get the same answer.
520
- if (receipt === null) return commit(tracker, new Map(), budget)
544
+ if (receipt === null) return { claims: new Map(), budget }
521
545
  const answered = receipt !== undefined && receipt.role === 'tool' && !receipt.isError
522
546
  if (name === 'read') {
523
547
  // A read that never came back, or came back refused, saw no body: it
524
548
  // can neither confirm what this pass holds nor contradict it. And a
525
549
  // read changes no file, so a claim left standing across one is still a
526
550
  // claim about the same bytes.
527
- if (answered) observeRead(history, call, claims, withBody, budget)
551
+ if (answered) observeRead(history, call, claims, withBody, budget, compareReads)
552
+ limitBodies(claims, withBody)
528
553
  continue
529
554
  }
530
555
  // One id claimed by two calls hides which of them ran. On a path this
@@ -532,7 +557,7 @@ export function replayObservationLedger(
532
557
  // have replaced a body claimed somewhere else in this walk, and there
533
558
  // is no way to tell where — so the pass establishes nothing at all
534
559
  // rather than carry a body something unseen may have moved past.
535
- if (history.calls.get(call.id) === null) return commit(tracker, new Map(), budget)
560
+ if (history.calls.get(call.id) === null) return { claims: new Map(), budget }
536
561
  // Attribution before outcome, for every mutation the walk reaches. A call
537
562
  // the transcript never answered — the unknown-outcome result the kernel's
538
563
  // own repair writes for one included — is precisely the call whose effect
@@ -546,28 +571,26 @@ export function replayObservationLedger(
546
571
  // is still the one thing that stops the pass, because then there is no
547
572
  // path to withdraw.
548
573
  const key = mutatedKey(history, call, attributions)
549
- if (key === undefined) return commit(tracker, new Map(), budget)
574
+ if (key === undefined) return { claims: new Map(), budget }
550
575
  const claim: Claim = answered
551
576
  ? mutate(history, call, name, key, claims.get(key), budget)
552
577
  : { kind: 'seen' }
553
578
  claims.set(key, claim)
554
579
  withBody.delete(key)
555
580
  if (claim.kind === 'content') withBody.add(key)
556
- // Oldest body first, matching what the projection keeps. An evicted
557
- // path is one this pass stops vouching for: it was mutated here, and
558
- // what it holds is past what the pass can carry, so it reaches the
559
- // ledger as the nothing every unrebuilt path reaches it as.
560
- if (withBody.size > MAX_WITNESSED_PATHS) {
561
- const oldest = withBody.values().next().value as string
562
- withBody.delete(oldest)
563
- // Setting an existing key leaves it where it is, so the order the
564
- // ledger is written in stays the order the calls arrived in.
565
- claims.set(oldest, { kind: 'seen' })
566
- }
581
+ limitBodies(claims, withBody)
567
582
  }
568
583
  }
569
584
 
570
- return commit(tracker, claims, budget)
585
+ return { claims, budget }
586
+ }
587
+
588
+ /** Evict the oldest body while retaining its path attribution. */
589
+ function limitBodies(claims: Map<string, Claim>, withBody: Set<string>): void {
590
+ if (withBody.size <= MAX_WITNESSED_PATHS) return
591
+ const oldest = withBody.values().next().value as string
592
+ withBody.delete(oldest)
593
+ claims.set(oldest, { kind: 'seen' })
571
594
  }
572
595
 
573
596
  /** Apply a walk's surviving claims to the ledger, in the order they were made. */
@@ -673,28 +696,40 @@ function observeRead(
673
696
  claims: Map<string, Claim>,
674
697
  withBody: Set<string>,
675
698
  budget: ReplayBudget,
699
+ compareReads: boolean,
676
700
  ): void {
677
701
  const read = readWindow(history, call)
678
702
  if (!read) return
679
703
  const claim = claims.get(read.key)
680
- if (!claim || claim.kind !== 'content') return
704
+ if (!compareReads && (!claim || claim.kind !== 'content')) return
681
705
  const shown = history.results.get(call.id)?.content
682
706
  if (visibleCall(history, call.id, 'read') && typeof shown === 'string') {
683
707
  // A whole-file rendering is the body plus a number on every line, so one
684
708
  // shorter than the body it would render cannot be equal to it. The cheap
685
709
  // half of the comparison, taken before anything is measured.
686
710
  const units =
687
- shown.length < claim.body.length ? undefined : wholeFileRenderUnits(claim.body, read.window)
711
+ claim?.kind === 'content' && shown.length >= claim.body.length
712
+ ? wholeFileRenderUnits(claim.body, read.window)
713
+ : undefined
688
714
  // The rendering is content this pass materialises, so it is charged like
689
715
  // every other body — and charged for what it will actually come to,
690
716
  // worked out from the body and the window while the string does not exist
691
717
  // yet. Charging the RECEIPT's length was charging one number and building
692
718
  // another: a receipt that had been rewritten short could have the pass
693
719
  // build a rendering the ceiling had never been asked about.
694
- if (units !== undefined && spend(budget, units)) {
720
+ if (claim?.kind === 'content' && units !== undefined && spend(budget, units)) {
695
721
  const rendered = renderNumberedRead(claim.body, read.window)
696
722
  if (!rendered.partial && rendered.output === shown) return
697
723
  }
724
+ if (compareReads && spend(budget, shown.length)) {
725
+ const body = comparisonReadBody(shown, read.window)
726
+ if (body !== undefined) {
727
+ claims.set(read.key, { kind: 'content', body, steps: [] })
728
+ withBody.delete(read.key)
729
+ withBody.add(read.key)
730
+ return
731
+ }
732
+ }
698
733
  }
699
734
  claims.set(read.key, { kind: 'seen' })
700
735
  // Off the held list as well as out of the claim. A withdrawn path is one
@@ -705,6 +740,25 @@ function observeRead(
705
740
  withBody.delete(read.key)
706
741
  }
707
742
 
743
+ /**
744
+ * Recover a comparison baseline from a complete, unmodified numbered receipt.
745
+ * Numbered reads omit the final newline. This approximation is only used to
746
+ * request a fresh read and must never establish a mutation witness.
747
+ */
748
+ function comparisonReadBody(shown: string, window: ReadWindowRequest): string | undefined {
749
+ if (shown === 'Warning: the file exists but is empty.') return ''
750
+ const rows = shown.split('\n')
751
+ const lines: string[] = []
752
+ for (const [index, row] of rows.entries()) {
753
+ const prefix = linePrefix(index + 1)
754
+ if (!row.startsWith(prefix)) return undefined
755
+ lines.push(row.slice(prefix.length))
756
+ }
757
+ const body = `${lines.join('\n')}\n`
758
+ const rendered = renderNumberedRead(body, window)
759
+ return !rendered.partial && rendered.output === shown ? body : undefined
760
+ }
761
+
708
762
  /**
709
763
  * What `read` would return for this whole body, in UTF-16 units, without
710
764
  * building it — and `undefined` for a window that would leave a line out.
@@ -7,6 +7,7 @@ import {
7
7
  type PathAttributions,
8
8
  collectObservedPaths,
9
9
  createPathAttributions,
10
+ replayComparisonClaims,
10
11
  replayObservationLedger,
11
12
  } from './file-evidence-replay.js'
12
13
 
@@ -92,6 +93,21 @@ export async function seedObservationLedger(
92
93
  return keyOf ? replayObservationLedger(messages, tracker, keyOf, attributions) : NOTHING
93
94
  }
94
95
 
96
+ /**
97
+ * Recover bounded file bodies for change notices when a conversation is reopened.
98
+ * Includes complete numbered reads and edits replayed over them. Bodies recovered
99
+ * from reads have an ambiguous final newline and are suitable only for comparison.
100
+ * No file content is read from disk and no mutation witness is established.
101
+ */
102
+ export async function replayFileComparisonBodies(
103
+ messages: readonly Message[],
104
+ context: ObservationSeedContext,
105
+ ): Promise<ReadonlyMap<string, string>> {
106
+ const attributions = createPathAttributions()
107
+ const keyOf = await resolveObservedFileKeys(messages, context, attributions)
108
+ return keyOf ? replayComparisonClaims(messages, keyOf, attributions) : new Map()
109
+ }
110
+
95
111
  /**
96
112
  * The tools' key for every path this history names, or `undefined` when the
97
113
  * pass should not run at all.
@@ -46,6 +46,7 @@ import { createStructuredOutputTool } from '../../tools/builtins/structuredOutpu
46
46
  import {
47
47
  HAND_BACK_GUIDANCE,
48
48
  HAND_BACK_GUIDANCE_CONTRIBUTION_ID,
49
+ HAND_BACK_TOOL_NAME,
49
50
  buildHandBackTool,
50
51
  } from '../../tools/hand-back/index.js'
51
52
  import { buildTaskTools } from '../../tools/task/index.js'
@@ -620,6 +621,8 @@ export interface QueryParams {
620
621
  * `ToolContext.additionalDirectories`.
621
622
  */
622
623
  additionalDirectories?: readonly string[]
624
+ /** Host-owned absolute file paths available to read, write and edit, including in a sandbox. */
625
+ allowedFiles?: readonly string[]
623
626
  /**
624
627
  * What a file tool's path outside `workingDirectory` and
625
628
  * `additionalDirectories` becomes, on a turn with no sandbox.
@@ -1715,6 +1718,7 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1715
1718
  ...(params.additionalDirectories?.length
1716
1719
  ? { additionalDirectories: params.additionalDirectories }
1717
1720
  : {}),
1721
+ ...(params.allowedFiles?.length ? { allowedFiles: params.allowedFiles } : {}),
1718
1722
  ...(scratchpadDirectory ? { scratchpadDirectory } : {}),
1719
1723
  ...(params.outsideRootAccess ? { outsideRootAccess: params.outsideRootAccess } : {}),
1720
1724
  ...(params.outsideRootRefusal ? { outsideRootRefusal: params.outsideRootRefusal } : {}),
@@ -1930,7 +1934,11 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1930
1934
  // The turn's own registry when the host passed none, so a hook's
1931
1935
  // annotation has somewhere to land.
1932
1936
  const promptContributions = params.promptContributions ?? new PromptContributionRegistry()
1933
- if (turnConfig.handBack === true) {
1937
+ if (
1938
+ turnConfig.handBack === true &&
1939
+ runtimeToolOverrides?.[HAND_BACK_TOOL_NAME] !== 'disabled' &&
1940
+ (effectiveAllowedTools?.includes(HAND_BACK_TOOL_NAME) ?? true)
1941
+ ) {
1934
1942
  promptContributions.replace({
1935
1943
  id: HAND_BACK_GUIDANCE_CONTRIBUTION_ID,
1936
1944
  placement: 'static',
@@ -31,7 +31,7 @@ import {
31
31
  topLevelEntryChange,
32
32
  } from '../../authorization/top-level-entries.js'
33
33
  import { resolveNamzuHome } from '../../session/home.js'
34
- import { canonicalize, pathOutsideRoots } from '../../tools/paths.js'
34
+ import { canonicalize, expandHomePath, pathOutsideRoots } from '../../tools/paths.js'
35
35
 
36
36
  /** What the escalation records carry. */
37
37
  export interface PathEscalations {
@@ -274,8 +274,9 @@ export async function declaredWriteEscalation(
274
274
  ): Promise<string | undefined> {
275
275
  const [first] = roots
276
276
  if (first === undefined || value === '') return undefined
277
- const absolute = resolve(resolve(first), value)
278
- if (await isProtectedWrite(value, absolute, roots)) return absolute
277
+ const spelled = expandHomePath(value)
278
+ const absolute = resolve(first, spelled)
279
+ if (await isProtectedWrite(spelled, absolute, roots)) return absolute
279
280
  return topLevel ? topLevelEntryChange(absolute, 'write', homedir()) : undefined
280
281
  }
281
282
 
@@ -33,6 +33,8 @@ export interface ToolingBootstrapConfig {
33
33
  workingDirectory: string
34
34
  /** See `QueryParams.additionalDirectories`. */
35
35
  additionalDirectories?: readonly string[]
36
+ /** Host-owned absolute file paths available to read, write and edit, including in a sandbox. */
37
+ allowedFiles?: readonly string[]
36
38
  /** See `ToolExecutorConfig.scratchpadDirectory`. */
37
39
  scratchpadDirectory?: string
38
40
  /** See `QueryParams.outsideRootAccess`. */
@@ -119,6 +121,7 @@ export class ToolingBootstrap {
119
121
  ...(config.additionalDirectories?.length
120
122
  ? { additionalDirectories: config.additionalDirectories }
121
123
  : {}),
124
+ ...(config.allowedFiles?.length ? { allowedFiles: config.allowedFiles } : {}),
122
125
  ...(config.scratchpadDirectory ? { scratchpadDirectory: config.scratchpadDirectory } : {}),
123
126
  ...(config.outsideRootAccess ? { outsideRootAccess: config.outsideRootAccess } : {}),
124
127
  ...(config.outsideRootRefusal ? { outsideRootRefusal: config.outsideRootRefusal } : {}),