@namzu/sdk 68.0.1 → 69.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 (281) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/bridge/acp/server.d.ts +12 -0
  3. package/dist/bridge/acp/server.d.ts.map +1 -1
  4. package/dist/bridge/acp/server.js +20 -0
  5. package/dist/bridge/acp/server.js.map +1 -1
  6. package/dist/compaction/context-window.d.ts +8 -0
  7. package/dist/compaction/context-window.d.ts.map +1 -1
  8. package/dist/compaction/context-window.js +14 -0
  9. package/dist/compaction/context-window.js.map +1 -1
  10. package/dist/compaction/loaded-skills.d.ts +10 -0
  11. package/dist/compaction/loaded-skills.d.ts.map +1 -1
  12. package/dist/compaction/loaded-skills.js +45 -1
  13. package/dist/compaction/loaded-skills.js.map +1 -1
  14. package/dist/compaction/manager.d.ts +8 -0
  15. package/dist/compaction/manager.d.ts.map +1 -1
  16. package/dist/compaction/manager.js +31 -0
  17. package/dist/compaction/manager.js.map +1 -1
  18. package/dist/compaction/manual.d.ts.map +1 -1
  19. package/dist/compaction/manual.js +7 -1
  20. package/dist/compaction/manual.js.map +1 -1
  21. package/dist/compaction/model-summary.js +2 -2
  22. package/dist/compaction/model-summary.js.map +1 -1
  23. package/dist/compaction/restore.d.ts +8 -0
  24. package/dist/compaction/restore.d.ts.map +1 -1
  25. package/dist/compaction/restore.js +65 -0
  26. package/dist/compaction/restore.js.map +1 -1
  27. package/dist/compaction/salience/working-set.d.ts.map +1 -1
  28. package/dist/compaction/salience/working-set.js +2 -2
  29. package/dist/compaction/salience/working-set.js.map +1 -1
  30. package/dist/compaction/tool-result-editing.d.ts +6 -0
  31. package/dist/compaction/tool-result-editing.d.ts.map +1 -1
  32. package/dist/compaction/tool-result-editing.js +7 -1
  33. package/dist/compaction/tool-result-editing.js.map +1 -1
  34. package/dist/compaction/types.d.ts +2 -0
  35. package/dist/compaction/types.d.ts.map +1 -1
  36. package/dist/compaction/wire.d.ts.map +1 -1
  37. package/dist/compaction/wire.js +4 -0
  38. package/dist/compaction/wire.js.map +1 -1
  39. package/dist/manager/session/turn-recorder.d.ts.map +1 -1
  40. package/dist/manager/session/turn-recorder.js +23 -1
  41. package/dist/manager/session/turn-recorder.js.map +1 -1
  42. package/dist/network/join.d.ts +10 -0
  43. package/dist/network/join.d.ts.map +1 -1
  44. package/dist/network/join.js +15 -0
  45. package/dist/network/join.js.map +1 -1
  46. package/dist/network/service.d.ts.map +1 -1
  47. package/dist/network/service.js +166 -12
  48. package/dist/network/service.js.map +1 -1
  49. package/dist/network/store.d.ts +23 -1
  50. package/dist/network/store.d.ts.map +1 -1
  51. package/dist/network/store.js +23 -1
  52. package/dist/network/store.js.map +1 -1
  53. package/dist/network/transport.d.ts +1 -1
  54. package/dist/network/transport.js +1 -1
  55. package/dist/network/wire.d.ts +12 -0
  56. package/dist/network/wire.d.ts.map +1 -1
  57. package/dist/network/wire.js +12 -1
  58. package/dist/network/wire.js.map +1 -1
  59. package/dist/prompt/coding-agent-doctrine.d.ts +4 -4
  60. package/dist/prompt/coding-agent-doctrine.d.ts.map +1 -1
  61. package/dist/prompt/coding-agent-doctrine.js +7 -2
  62. package/dist/prompt/coding-agent-doctrine.js.map +1 -1
  63. package/dist/provider/fallback.d.ts.map +1 -1
  64. package/dist/provider/fallback.js +5 -0
  65. package/dist/provider/fallback.js.map +1 -1
  66. package/dist/provider/idle-timeout.d.ts.map +1 -1
  67. package/dist/provider/idle-timeout.js +5 -0
  68. package/dist/provider/idle-timeout.js.map +1 -1
  69. package/dist/provider/instrumentation.d.ts.map +1 -1
  70. package/dist/provider/instrumentation.js +10 -0
  71. package/dist/provider/instrumentation.js.map +1 -1
  72. package/dist/provider/model-window-suffix.d.ts.map +1 -1
  73. package/dist/provider/model-window-suffix.js +1 -0
  74. package/dist/provider/model-window-suffix.js.map +1 -1
  75. package/dist/provider/retry.d.ts.map +1 -1
  76. package/dist/provider/retry.js +5 -0
  77. package/dist/provider/retry.js.map +1 -1
  78. package/dist/public-runtime.d.ts +1 -1
  79. package/dist/public-runtime.d.ts.map +1 -1
  80. package/dist/public-runtime.js +1 -1
  81. package/dist/public-runtime.js.map +1 -1
  82. package/dist/public-tools.d.ts +2 -0
  83. package/dist/public-tools.d.ts.map +1 -1
  84. package/dist/public-tools.js +4 -0
  85. package/dist/public-tools.js.map +1 -1
  86. package/dist/public-types.d.ts +1 -0
  87. package/dist/public-types.d.ts.map +1 -1
  88. package/dist/registry/tool/presentation.d.ts +8 -1
  89. package/dist/registry/tool/presentation.d.ts.map +1 -1
  90. package/dist/registry/tool/presentation.js +14 -5
  91. package/dist/registry/tool/presentation.js.map +1 -1
  92. package/dist/runtime/jobs/registry.d.ts.map +1 -1
  93. package/dist/runtime/jobs/registry.js +2 -1
  94. package/dist/runtime/jobs/registry.js.map +1 -1
  95. package/dist/runtime/query/auto-review/classifier.d.ts.map +1 -1
  96. package/dist/runtime/query/auto-review/classifier.js +19 -3
  97. package/dist/runtime/query/auto-review/classifier.js.map +1 -1
  98. package/dist/runtime/query/auto-review/failure.d.ts +12 -0
  99. package/dist/runtime/query/auto-review/failure.d.ts.map +1 -0
  100. package/dist/runtime/query/auto-review/failure.js +46 -0
  101. package/dist/runtime/query/auto-review/failure.js.map +1 -0
  102. package/dist/runtime/query/auto-review/index.d.ts +1 -0
  103. package/dist/runtime/query/auto-review/index.d.ts.map +1 -1
  104. package/dist/runtime/query/auto-review/index.js +1 -0
  105. package/dist/runtime/query/auto-review/index.js.map +1 -1
  106. package/dist/runtime/query/file-evidence-replay.d.ts.map +1 -1
  107. package/dist/runtime/query/file-evidence-replay.js +6 -6
  108. package/dist/runtime/query/file-evidence-replay.js.map +1 -1
  109. package/dist/runtime/query/index.d.ts.map +1 -1
  110. package/dist/runtime/query/index.js +8 -1
  111. package/dist/runtime/query/index.js.map +1 -1
  112. package/dist/runtime/query/iteration/index.d.ts.map +1 -1
  113. package/dist/runtime/query/iteration/index.js +2 -0
  114. package/dist/runtime/query/iteration/index.js.map +1 -1
  115. package/dist/runtime/query/iteration/phases/compaction.d.ts.map +1 -1
  116. package/dist/runtime/query/iteration/phases/compaction.js +21 -3
  117. package/dist/runtime/query/iteration/phases/compaction.js.map +1 -1
  118. package/dist/runtime/query/iteration/phases/context.d.ts +4 -0
  119. package/dist/runtime/query/iteration/phases/context.d.ts.map +1 -1
  120. package/dist/runtime/query/iteration/phases/context.js.map +1 -1
  121. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +6 -2
  122. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  123. package/dist/runtime/query/iteration/phases/per-call-review.js +24 -9
  124. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  125. package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
  126. package/dist/runtime/query/iteration/step-shaping.js +4 -0
  127. package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
  128. package/dist/runtime/query/prepare-turn.d.ts +5 -1
  129. package/dist/runtime/query/prepare-turn.d.ts.map +1 -1
  130. package/dist/runtime/query/prepare-turn.js +13 -3
  131. package/dist/runtime/query/prepare-turn.js.map +1 -1
  132. package/dist/runtime/query/review-policy.d.ts +13 -2
  133. package/dist/runtime/query/review-policy.d.ts.map +1 -1
  134. package/dist/runtime/query/review-policy.js +13 -2
  135. package/dist/runtime/query/review-policy.js.map +1 -1
  136. package/dist/runtime/query/turn/outcome-ledger.d.ts +4 -0
  137. package/dist/runtime/query/turn/outcome-ledger.d.ts.map +1 -1
  138. package/dist/runtime/query/turn/outcome-ledger.js +36 -1
  139. package/dist/runtime/query/turn/outcome-ledger.js.map +1 -1
  140. package/dist/sandbox/provider/local.d.ts.map +1 -1
  141. package/dist/sandbox/provider/local.js +3 -1
  142. package/dist/sandbox/provider/local.js.map +1 -1
  143. package/dist/tools/admit-facts.d.ts.map +1 -1
  144. package/dist/tools/admit-facts.js +20 -0
  145. package/dist/tools/admit-facts.js.map +1 -1
  146. package/dist/tools/builtins/bash.d.ts.map +1 -1
  147. package/dist/tools/builtins/bash.js +5 -2
  148. package/dist/tools/builtins/bash.js.map +1 -1
  149. package/dist/tools/builtins/browser.js +1 -1
  150. package/dist/tools/builtins/browser.js.map +1 -1
  151. package/dist/tools/builtins/computer-use.d.ts +4 -0
  152. package/dist/tools/builtins/computer-use.d.ts.map +1 -1
  153. package/dist/tools/builtins/computer-use.js +106 -5
  154. package/dist/tools/builtins/computer-use.js.map +1 -1
  155. package/dist/tools/builtins/content-fingerprint.d.ts.map +1 -1
  156. package/dist/tools/builtins/content-fingerprint.js +2 -1
  157. package/dist/tools/builtins/content-fingerprint.js.map +1 -1
  158. package/dist/tools/builtins/edit-apply.d.ts +1 -0
  159. package/dist/tools/builtins/edit-apply.d.ts.map +1 -1
  160. package/dist/tools/builtins/edit-apply.js +108 -21
  161. package/dist/tools/builtins/edit-apply.js.map +1 -1
  162. package/dist/tools/builtins/edit-match.d.ts +37 -0
  163. package/dist/tools/builtins/edit-match.d.ts.map +1 -1
  164. package/dist/tools/builtins/edit-match.js +193 -0
  165. package/dist/tools/builtins/edit-match.js.map +1 -1
  166. package/dist/tools/builtins/edit.d.ts.map +1 -1
  167. package/dist/tools/builtins/edit.js +14 -7
  168. package/dist/tools/builtins/edit.js.map +1 -1
  169. package/dist/tools/builtins/exit-semantics.d.ts +8 -0
  170. package/dist/tools/builtins/exit-semantics.d.ts.map +1 -1
  171. package/dist/tools/builtins/exit-semantics.js +19 -0
  172. package/dist/tools/builtins/exit-semantics.js.map +1 -1
  173. package/dist/tools/builtins/index.d.ts +2 -0
  174. package/dist/tools/builtins/index.d.ts.map +1 -1
  175. package/dist/tools/builtins/index.js +1 -0
  176. package/dist/tools/builtins/index.js.map +1 -1
  177. package/dist/tools/builtins/present-file.d.ts +24 -0
  178. package/dist/tools/builtins/present-file.d.ts.map +1 -0
  179. package/dist/tools/builtins/present-file.js +116 -0
  180. package/dist/tools/builtins/present-file.js.map +1 -0
  181. package/dist/tools/builtins/read-file.js +1 -1
  182. package/dist/tools/builtins/read-file.js.map +1 -1
  183. package/dist/tools/builtins/read-render.d.ts +12 -1
  184. package/dist/tools/builtins/read-render.d.ts.map +1 -1
  185. package/dist/tools/builtins/read-render.js +16 -3
  186. package/dist/tools/builtins/read-render.js.map +1 -1
  187. package/dist/tools/builtins/search-tools.d.ts +10 -0
  188. package/dist/tools/builtins/search-tools.d.ts.map +1 -1
  189. package/dist/tools/builtins/search-tools.js +36 -2
  190. package/dist/tools/builtins/search-tools.js.map +1 -1
  191. package/dist/tools/builtins/wait-for-job.d.ts.map +1 -1
  192. package/dist/tools/builtins/wait-for-job.js +5 -0
  193. package/dist/tools/builtins/wait-for-job.js.map +1 -1
  194. package/dist/tools/builtins/web.d.ts.map +1 -1
  195. package/dist/tools/builtins/web.js +13 -2
  196. package/dist/tools/builtins/web.js.map +1 -1
  197. package/dist/tools/task/create.js +2 -2
  198. package/dist/tools/task/create.js.map +1 -1
  199. package/dist/tools/task/update.js +1 -1
  200. package/dist/tools/task/update.js.map +1 -1
  201. package/dist/types/provider/chat.d.ts +8 -0
  202. package/dist/types/provider/chat.d.ts.map +1 -1
  203. package/dist/types/provider/interface.d.ts +10 -0
  204. package/dist/types/provider/interface.d.ts.map +1 -1
  205. package/dist/types/provider/model.d.ts +6 -0
  206. package/dist/types/provider/model.d.ts.map +1 -1
  207. package/dist/types/provider/stream.d.ts +2 -0
  208. package/dist/types/provider/stream.d.ts.map +1 -1
  209. package/dist/types/tool/presentation.d.ts +11 -0
  210. package/dist/types/tool/presentation.d.ts.map +1 -1
  211. package/dist/utils/node-on-path.d.ts +27 -0
  212. package/dist/utils/node-on-path.d.ts.map +1 -0
  213. package/dist/utils/node-on-path.js +70 -0
  214. package/dist/utils/node-on-path.js.map +1 -0
  215. package/package.json +1 -1
  216. package/src/bridge/acp/server.ts +25 -0
  217. package/src/compaction/context-window.ts +18 -0
  218. package/src/compaction/loaded-skills.ts +42 -1
  219. package/src/compaction/manager.ts +28 -0
  220. package/src/compaction/manual.ts +9 -1
  221. package/src/compaction/model-summary.ts +2 -2
  222. package/src/compaction/restore.ts +69 -0
  223. package/src/compaction/salience/working-set.ts +6 -2
  224. package/src/compaction/tool-result-editing.ts +8 -1
  225. package/src/compaction/types.ts +2 -0
  226. package/src/compaction/wire.ts +4 -0
  227. package/src/manager/session/turn-recorder.ts +24 -1
  228. package/src/network/join.ts +17 -0
  229. package/src/network/service.ts +185 -12
  230. package/src/network/store.ts +28 -1
  231. package/src/network/transport.ts +1 -1
  232. package/src/network/wire.ts +13 -1
  233. package/src/prompt/coding-agent-doctrine.ts +7 -2
  234. package/src/provider/fallback.ts +6 -0
  235. package/src/provider/idle-timeout.ts +6 -0
  236. package/src/provider/instrumentation.ts +12 -0
  237. package/src/provider/model-window-suffix.ts +1 -0
  238. package/src/provider/retry.ts +6 -0
  239. package/src/public-runtime.ts +1 -0
  240. package/src/public-tools.ts +9 -0
  241. package/src/public-types.ts +1 -0
  242. package/src/registry/tool/presentation.ts +14 -4
  243. package/src/runtime/jobs/registry.ts +2 -1
  244. package/src/runtime/query/auto-review/classifier.ts +19 -3
  245. package/src/runtime/query/auto-review/failure.ts +50 -0
  246. package/src/runtime/query/auto-review/index.ts +1 -0
  247. package/src/runtime/query/file-evidence-replay.ts +6 -5
  248. package/src/runtime/query/index.ts +19 -0
  249. package/src/runtime/query/iteration/index.ts +2 -0
  250. package/src/runtime/query/iteration/phases/compaction.ts +25 -2
  251. package/src/runtime/query/iteration/phases/context.ts +4 -0
  252. package/src/runtime/query/iteration/phases/per-call-review.ts +24 -7
  253. package/src/runtime/query/iteration/step-shaping.ts +4 -0
  254. package/src/runtime/query/prepare-turn.ts +20 -2
  255. package/src/runtime/query/review-policy.ts +24 -4
  256. package/src/runtime/query/turn/outcome-ledger.ts +45 -1
  257. package/src/sandbox/provider/local.ts +3 -1
  258. package/src/tools/admit-facts.ts +18 -0
  259. package/src/tools/builtins/bash.ts +5 -2
  260. package/src/tools/builtins/browser.ts +1 -1
  261. package/src/tools/builtins/computer-use.ts +123 -4
  262. package/src/tools/builtins/content-fingerprint.ts +2 -1
  263. package/src/tools/builtins/edit-apply.ts +124 -24
  264. package/src/tools/builtins/edit-match.ts +200 -0
  265. package/src/tools/builtins/edit.ts +16 -7
  266. package/src/tools/builtins/exit-semantics.ts +23 -0
  267. package/src/tools/builtins/index.ts +2 -0
  268. package/src/tools/builtins/present-file.ts +127 -0
  269. package/src/tools/builtins/read-file.ts +1 -1
  270. package/src/tools/builtins/read-render.ts +18 -3
  271. package/src/tools/builtins/search-tools.ts +36 -2
  272. package/src/tools/builtins/wait-for-job.ts +5 -0
  273. package/src/tools/builtins/web.ts +15 -2
  274. package/src/tools/task/create.ts +2 -2
  275. package/src/tools/task/update.ts +1 -1
  276. package/src/types/provider/chat.ts +9 -0
  277. package/src/types/provider/interface.ts +11 -0
  278. package/src/types/provider/model.ts +6 -0
  279. package/src/types/provider/stream.ts +2 -0
  280. package/src/types/tool/presentation.ts +12 -0
  281. package/src/utils/node-on-path.ts +81 -0
@@ -13,6 +13,7 @@ import type {
13
13
  } from '../../types/job/index.js'
14
14
  import type { MonitorWebSocketTarget } from '../../types/tool/index.js'
15
15
  import { subscribeToAbort } from '../../utils/abort.js'
16
+ import { withNodeOnPath } from '../../utils/node-on-path.js'
16
17
  import { oneMetadataLine } from '../system-events.js'
17
18
  import { stopAtHostExit } from './host-exit-finalizer.js'
18
19
  import { createBackgroundJobId } from './job-id.js'
@@ -731,7 +732,7 @@ export class BackgroundJobRegistry {
731
732
  : {
732
733
  child: spawnHostShell(params.command, {
733
734
  cwd: params.workingDirectory,
734
- env: { ...inherited.env, ...params.env },
735
+ env: withNodeOnPath({ ...inherited.env, ...params.env }),
735
736
  // `detached` makes the child the leader of its own process group
736
737
  // off Windows, which is what `killTree` needs to reach the command
737
738
  // and everything it forks rather than only the wrapping shell. See
@@ -45,6 +45,7 @@ import {
45
45
  import { SCOPE_ATTRIBUTE } from '../../../utils/log/types.js'
46
46
  import { type Logger, resolveLogger } from '../../../utils/logger.js'
47
47
  import { chatStreamWithSamplingRepair } from '../iteration/side-call.js'
48
+ import { describeCheckFailure } from './failure.js'
48
49
  import { renderGitStatus } from './git-status.js'
49
50
  import {
50
51
  STAGE_ONE_INSTRUCTION,
@@ -303,7 +304,10 @@ export function createAutoReviewClassifier(
303
304
  ): AutoReviewDecision {
304
305
  let limitReached: 'consecutive' | 'total' | undefined
305
306
  let noVerdictLimitReached = false
306
- if (cause !== 'aborted') {
307
+ // A check that could not be completed says nothing about the action, so it
308
+ // does not count toward the blocks that take auto mode away; the no-verdict
309
+ // counter below is its own limit.
310
+ if (cause !== 'aborted' && cause !== 'unavailable' && cause !== 'unreadable') {
307
311
  consecutive += 1
308
312
  total += 1
309
313
  if (consecutive >= limits.consecutive) limitReached = 'consecutive'
@@ -426,11 +430,17 @@ export function createAutoReviewClassifier(
426
430
  if (request.signal?.aborted) {
427
431
  return blocked(started, 0, 'aborted', 'the review was cancelled before it finished')
428
432
  }
433
+ const why = describeCheckFailure(error, options.quickDeadlineMs ?? 60_000)
434
+ log.warn('auto review could not complete', {
435
+ 'namzu.auto_review.stage': 1,
436
+ 'namzu.auto_review.failure': why,
437
+ 'namzu.auto_review.error': error instanceof Error ? error.message : String(error),
438
+ })
429
439
  return blocked(
430
440
  started,
431
441
  0,
432
442
  'unavailable',
433
- 'the safety check could not be completed, so the action was not run',
443
+ `the safety check could not be completed (${why}), so the action was not run`,
434
444
  )
435
445
  }
436
446
  const first = parseVerdict(quick)
@@ -447,11 +457,17 @@ export function createAutoReviewClassifier(
447
457
  if (request.signal?.aborted) {
448
458
  return blocked(started, 1, 'aborted', 'the review was cancelled before it finished')
449
459
  }
460
+ const why = describeCheckFailure(error, options.reasonedDeadlineMs ?? 120_000)
461
+ log.warn('auto review could not complete', {
462
+ 'namzu.auto_review.stage': 2,
463
+ 'namzu.auto_review.failure': why,
464
+ 'namzu.auto_review.error': error instanceof Error ? error.message : String(error),
465
+ })
450
466
  return blocked(
451
467
  started,
452
468
  1,
453
469
  'unavailable',
454
- 'a first look flagged this action and the closer look could not be completed',
470
+ `a first look flagged this action and the closer look could not be completed (${why})`,
455
471
  )
456
472
  }
457
473
  const second = parseVerdict(careful)
@@ -0,0 +1,50 @@
1
+ import { classifyProviderError } from '../../../types/provider/errors.js'
2
+
3
+ /**
4
+ * The class of a failure to complete the safety check, in a few plain words:
5
+ * `no credential for the check model`, `provider returned 400`,
6
+ * `timed out after 60 s`. It is a class, never the provider's own text: that
7
+ * text can carry a request body or a key fragment, so it goes to the log, not
8
+ * to the person or the model.
9
+ *
10
+ * `deadlineMs` is the deadline the pass ran under, when the failure was the
11
+ * deadline expiring.
12
+ */
13
+ export function describeCheckFailure(error: unknown, deadlineMs?: number): string {
14
+ if (error instanceof Error && error.name === 'DeadlineError') {
15
+ return deadlineMs !== undefined
16
+ ? `timed out after ${Math.round(deadlineMs / 1000)} s`
17
+ : 'timed out'
18
+ }
19
+ const classified = classifyProviderError(error)
20
+ // An HTTP status names the failure better than any word in the message: a
21
+ // 401 that says "invalid credentials" is a refused credential, not a missing one.
22
+ // The words are read only when there is no status.
23
+ if (classified.status === undefined) {
24
+ const message = error instanceof Error ? error.message : String(error)
25
+ if (
26
+ /no (api )?(key|credential)s?|missing (api )?(key|credential)s?|credentials? (is |are )?(not (set|configured|found)|missing)|not signed in|not logged in|api key (is )?(required|missing|not set)/i.test(
27
+ message,
28
+ )
29
+ ) {
30
+ return 'no credential for the check model'
31
+ }
32
+ }
33
+ const status = classified.status
34
+ switch (classified.code) {
35
+ case 'auth':
36
+ return status !== undefined
37
+ ? `provider returned ${status}: the credential was refused`
38
+ : 'the credential was refused'
39
+ case 'rate_limit':
40
+ return 'provider rate limit'
41
+ case 'usage_limit':
42
+ return 'provider usage limit reached'
43
+ case 'network':
44
+ return 'could not reach the provider'
45
+ case 'not_found':
46
+ return 'the check model was not found'
47
+ default:
48
+ return status !== undefined ? `provider returned ${status}` : 'provider error'
49
+ }
50
+ }
@@ -16,6 +16,7 @@ export type {
16
16
  AutoReviewRequest,
17
17
  AutoReviewStage,
18
18
  } from './classifier.js'
19
+ export { describeCheckFailure } from './failure.js'
19
20
  export {
20
21
  AUTO_REVIEW_DEFAULTS_MARKER,
21
22
  DEFAULT_ALLOW,
@@ -4,6 +4,7 @@ import { replayEditCallWithin } from '../../tools/builtins/edit-apply.js'
4
4
  import { EditTool } from '../../tools/builtins/edit.js'
5
5
  import { ReadFileTool } from '../../tools/builtins/read-file.js'
6
6
  import {
7
+ LINE_NUMBER_WIDTH,
7
8
  type ReadWindowRequest,
8
9
  renderNumberedRead,
9
10
  resolveReadWindow,
@@ -659,7 +660,7 @@ function mutate(
659
660
  * compared whole.
660
661
  *
661
662
  * Equality is conclusive because of the numbering. Every line of a rendering
662
- * goes out behind its own `${n}\t`, so one rendering belongs to exactly one
663
+ * goes out behind its own `linePrefix(n)`, so one rendering belongs to exactly one
663
664
  * body and window; and the partial-view notice carries no such prefix on its
664
665
  * lines, so a rendering that covers a whole file cannot be equal to one that
665
666
  * was cut short. A read this cannot match leaves the path known and its body
@@ -708,9 +709,9 @@ function observeRead(
708
709
  * What `read` would return for this whole body, in UTF-16 units, without
709
710
  * building it — and `undefined` for a window that would leave a line out.
710
711
  *
711
- * The rendering puts `${n}\t` in front of every line and joins them back with
712
- * the newlines the body already carries, so its length is the body's, plus one
713
- * tab per line, plus the digits of the numbers `1..lines`. A windowed read
712
+ * The rendering puts `linePrefix(n)` in front of every line and joins them back with
713
+ * the newlines the body already carries, so its length is the body's, plus the
714
+ * prefix of every line: the arrow and the number padded to its column. A windowed read
714
715
  * renumbers from its offset and carries the PARTIAL notice, and can never equal
715
716
  * a whole body's rendering — so it is refused here rather than built and
716
717
  * compared, which is also what makes the figure above exact.
@@ -736,7 +737,7 @@ function countLines(body: string): number {
736
737
  function lineNumberUnits(lines: number): number {
737
738
  let units = 0
738
739
  for (let width = 1, first = 1; first <= lines; width++, first *= 10)
739
- units += (Math.min(lines, first * 10 - 1) - first + 1) * width
740
+ units += (Math.min(lines, first * 10 - 1) - first + 1) * Math.max(width, LINE_NUMBER_WIDTH)
740
741
  return units
741
742
  }
742
743
 
@@ -1173,7 +1173,9 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
1173
1173
  resilientProvider,
1174
1174
  serving,
1175
1175
  providerContextWindow,
1176
+ providerAutoCompactLimit,
1176
1177
  modelContextWindows,
1178
+ modelAutoCompactLimits,
1177
1179
  approvalPolicy,
1178
1180
  eventTranslator,
1179
1181
  executeUserInterruptHooks,
@@ -2063,6 +2065,23 @@ export async function* query(params: QueryParams): AsyncGenerator<SessionEvent,
2063
2065
  ? { compactionSummaryRoute: params.compactionSummaryRoute }
2064
2066
  : {}),
2065
2067
  ...(providerContextWindow !== undefined ? { providerContextWindow } : {}),
2068
+ ...(providerAutoCompactLimit !== undefined ? { providerAutoCompactLimit } : {}),
2069
+ resolveModelAutoCompactLimit: async (model) => {
2070
+ if (!modelAutoCompactLimits.has(model)) {
2071
+ modelAutoCompactLimits.set(
2072
+ model,
2073
+ await resolveProviderContextWindow(
2074
+ resilientProvider,
2075
+ model,
2076
+ ctx.abortController.signal,
2077
+ turnConfig.timeoutMs,
2078
+ log,
2079
+ 'resolveAutoCompactLimit',
2080
+ ),
2081
+ )
2082
+ }
2083
+ return modelAutoCompactLimits.get(model)
2084
+ },
2066
2085
  resolveModelContextWindow: async (model) => {
2067
2086
  if (!modelContextWindows.has(model)) {
2068
2087
  modelContextWindows.set(
@@ -1335,6 +1335,7 @@ export class IterationOrchestrator {
1335
1335
  maxTokens:
1336
1336
  outputCapOverride ?? step.maxResponseTokens ?? turnConfig.maxResponseTokens,
1337
1337
  cacheControl: { type: 'auto' },
1338
+ cacheKey: recorder.sessionId,
1338
1339
  ...(turnConfig.thinking ? { thinking: turnConfig.thinking } : {}),
1339
1340
  ...(stepEffort ? { effort: stepEffort } : {}),
1340
1341
  ...(turnConfig.speed ? { speed: turnConfig.speed } : {}),
@@ -3866,6 +3867,7 @@ export class IterationOrchestrator {
3866
3867
  temperature: this.ctx.turnConfig.temperature,
3867
3868
  maxTokens: this.ctx.turnConfig.maxResponseTokens,
3868
3869
  cacheControl: { type: 'auto' },
3870
+ cacheKey: this.ctx.recorder.sessionId,
3869
3871
  ...(this.ctx.turnConfig.thinking ? { thinking: this.ctx.turnConfig.thinking } : {}),
3870
3872
  // This turn is a hand-maintained duplicate of the one above, which
3871
3873
  // is exactly the shape a field goes missing from — so it is tested
@@ -1,4 +1,5 @@
1
1
  import {
2
+ providerTriggerFraction,
2
3
  resolveContextWindow,
3
4
  resolveTriggerThreshold,
4
5
  } from '../../../../compaction/context-window.js'
@@ -21,7 +22,7 @@ import {
21
22
  } from '../../../../compaction/plan.js'
22
23
  import type { ContextReducer, ContextReduction } from '../../../../compaction/reducer.js'
23
24
  import { createSlidingWindowReducer } from '../../../../compaction/reducer.js'
24
- import { renderRestoredContext } from '../../../../compaction/restore.js'
25
+ import { carriedWorkingCommands, renderRestoredContext } from '../../../../compaction/restore.js'
25
26
  import { findRetainedIndices } from '../../../../compaction/retention.js'
26
27
  import { serializeState } from '../../../../compaction/serializer.js'
27
28
  import {
@@ -188,6 +189,10 @@ async function emitToolResultClear(
188
189
  */
189
190
  function adoptLoadedSkills(ctx: IterationContext): void {
190
191
  ctx.workingStateManager?.adoptSkillBodies(adoptableSkills(ctx.recorder.messages))
192
+ for (const message of ctx.recorder.messages) {
193
+ if (message.role === 'system' && typeof message.content === 'string')
194
+ ctx.workingStateManager?.adoptWorkingCommands(carriedWorkingCommands(message.content))
195
+ }
191
196
  }
192
197
 
193
198
  /**
@@ -836,7 +841,7 @@ async function runCompactionCheckInner(
836
841
  const configured = ctx.compactionConfig
837
842
  if (!configured) return
838
843
  if (configured.strategy === 'disabled') return
839
- const config = options?.deeper ? deepenConfig(configured, ctx.recorder.messages) : configured
844
+ const deepened = options?.deeper ? deepenConfig(configured, ctx.recorder.messages) : configured
840
845
 
841
846
  const measured = measureContext(ctx)
842
847
  const estimatedTokens = measured.tokens
@@ -851,6 +856,24 @@ async function runCompactionCheckInner(
851
856
  const window = activeContextWindow(ctx)
852
857
  const budget = window.tokens
853
858
 
859
+ // The provider's own compaction limit, when its service stated one, is the trigger:
860
+ // min(limit, 90% of the window). A host that set a threshold or an auto-compact window
861
+ // keeps what it set. Folding it into the config means the planners below read the same
862
+ // trigger this pass does.
863
+ const model = ctx.contextModel ?? ctx.turnConfig.model
864
+ const providerLimit =
865
+ model === ctx.turnConfig.model
866
+ ? ctx.providerAutoCompactLimit
867
+ : ctx.activeProviderAutoCompactLimit
868
+ const providerFraction =
869
+ deepened.triggerThreshold === undefined &&
870
+ deepened.autoCompactWindowTokens === undefined &&
871
+ window.source !== 'config'
872
+ ? providerTriggerFraction(providerLimit, budget)
873
+ : undefined
874
+ const config =
875
+ providerFraction !== undefined ? { ...deepened, triggerThreshold: providerFraction } : deepened
876
+
854
877
  const usage = estimatedTokens / budget
855
878
 
856
879
  // A forced pass skips the threshold: it runs because the provider
@@ -242,6 +242,10 @@ export interface IterationContext {
242
242
  * through to the table.
243
243
  */
244
244
  readonly providerContextWindow?: number
245
+ /** What the driver's service says compaction starts at, in tokens; asked once at the start of the turn. */
246
+ readonly providerAutoCompactLimit?: number
247
+ activeProviderAutoCompactLimit?: number
248
+ readonly resolveModelAutoCompactLimit?: (model: string) => Promise<number | undefined>
245
249
  /** Selected request model; its window must not reuse another model's metadata. */
246
250
  contextModel?: string
247
251
  activeProviderContextWindow?: number
@@ -81,6 +81,8 @@ interface Interpreted {
81
81
  readonly verdicts: Map<string, Verdict>
82
82
  /** The calls were refused and the refusal ends the turn. */
83
83
  readonly endsTurn: boolean
84
+ /** The refusal was a person's own No, not the safety check's. */
85
+ readonly byPerson?: boolean
84
86
  /** The decision was the host stopping the turn outright. */
85
87
  readonly cancelled: boolean
86
88
  /** The decision was a request to wait: the park it recorded must not stay open. */
@@ -135,8 +137,12 @@ export interface PerCallReviewDeps {
135
137
  * - An answer that grants something (a remembered approval, a changed rule or
136
138
  * mode on the host's side) re-checks the questions still open, and any call
137
139
  * the new state covers is let through unasked. A re-check never refuses.
138
- * - A plain refusal ends the turn: the questions still open close, calls not
139
- * yet started are refused without being asked, calls in flight are cancelled.
140
+ * - A refusal that ends the turn closes the questions still open and refuses,
141
+ * without asking, the calls that would have needed one. When the safety
142
+ * check refused, calls that need no review (a read, a search, a call a rule
143
+ * already allowed) still run and calls already running finish: the refusal
144
+ * is about the call it answered. A person's own No, and the host stopping
145
+ * the turn (`cancelled`), cancel what is running and start nothing more.
140
146
  * - Every refusal and every call that could not be matched to a reviewed
141
147
  * summary is a refusal. Nothing is approved by the absence of an answer.
142
148
  */
@@ -266,6 +272,10 @@ export class PerCallReview implements ReviewedExecution {
266
272
  })
267
273
  return { run: true }
268
274
  }
275
+ // A refusal ended the turn while this call waited its turn: nobody is asked
276
+ // about it any more. It is refused here; a call that needed no question was
277
+ // let through above.
278
+ if (this.#endsTurn) return { run: false, reason: REFUSED_WITH_THE_TURN }
269
279
  const interpreted = await this.#ask([summary], leave)
270
280
  this.#noteEnd(interpreted)
271
281
  const verdict = interpreted.verdicts.get(summary.id) ?? {
@@ -361,10 +371,10 @@ export class PerCallReview implements ReviewedExecution {
361
371
 
362
372
  #noteEnd(interpreted: Interpreted): void {
363
373
  if (!interpreted.endsTurn && !interpreted.cancelled) return
364
- this.#end(interpreted.cancelled)
374
+ this.#end(interpreted.cancelled, interpreted.byPerson === true)
365
375
  }
366
376
 
367
- #end(cancelled: boolean): void {
377
+ #end(cancelled: boolean, byPerson = false): void {
368
378
  if (this.#endsTurn) return
369
379
  this.#endsTurn = true
370
380
  this.#cancelled = cancelled
@@ -372,7 +382,10 @@ export class PerCallReview implements ReviewedExecution {
372
382
  ask.closedBy ??= 'ended'
373
383
  ask.controller.abort()
374
384
  }
375
- this.#endController.abort(new Error('the user stopped the turn'))
385
+ // A person's No, and the host stopping the turn, cancel what is running
386
+ // and start nothing more. A refusal by the safety check is about the call
387
+ // it answered: what is running and what needs no review carries on.
388
+ if (cancelled || byPerson) this.#endController.abort(new Error('the user stopped the turn'))
376
389
  }
377
390
 
378
391
  /** One request to the handler about `calls`, and what its answer means for each. */
@@ -481,6 +494,7 @@ export class PerCallReview implements ReviewedExecution {
481
494
  interpreted.endsTurn,
482
495
  interpreted.cancelled,
483
496
  interpreted.paused,
497
+ interpreted.byPerson === true,
484
498
  )
485
499
  }
486
500
 
@@ -492,6 +506,7 @@ export class PerCallReview implements ReviewedExecution {
492
506
  endsTurn: boolean,
493
507
  cancelled: boolean,
494
508
  paused: boolean,
509
+ byPerson = false,
495
510
  ): Promise<Interpreted> {
496
511
  const { ctx } = this.#deps
497
512
  const denials = new Map<string, string>()
@@ -534,7 +549,7 @@ export class PerCallReview implements ReviewedExecution {
534
549
  })
535
550
  }
536
551
  }
537
- return { verdicts: result, endsTurn, cancelled, paused }
552
+ return { verdicts: result, endsTurn, byPerson, cancelled, paused }
538
553
  }
539
554
 
540
555
  #interpret(decision: HITLResumeDecision, calls: readonly ToolCallSummary[]): Interpreted {
@@ -545,6 +560,7 @@ export class PerCallReview implements ReviewedExecution {
545
560
  let endsTurn = false
546
561
  let cancelled = false
547
562
  let paused = false
563
+ let byPerson = false
548
564
  switch (decision.action) {
549
565
  case 'approve_tools':
550
566
  case 'continue':
@@ -562,6 +578,7 @@ export class PerCallReview implements ReviewedExecution {
562
578
  ...(decision.declined ? { declined: note ? { note } : {} } : {}),
563
579
  })
564
580
  endsTurn = decision.endTurn === true
581
+ byPerson = decision.declined !== undefined
565
582
  break
566
583
  }
567
584
  case 'modify_tools': {
@@ -600,7 +617,7 @@ export class PerCallReview implements ReviewedExecution {
600
617
  })
601
618
  refuseAll({ run: false, reason: NOT_THIS_QUESTION })
602
619
  }
603
- return { verdicts, endsTurn, cancelled, paused }
620
+ return { verdicts, endsTurn, byPerson, cancelled, paused }
604
621
  }
605
622
  }
606
623
 
@@ -330,4 +330,8 @@ export async function selectContextModel(
330
330
  model && model !== ctx.turnConfig.model && !ctx.compactionConfig?.contextWindowTokens
331
331
  ? await ctx.resolveModelContextWindow?.(model)
332
332
  : undefined
333
+ ctx.activeProviderAutoCompactLimit =
334
+ model && model !== ctx.turnConfig.model && !ctx.compactionConfig?.contextWindowTokens
335
+ ? await ctx.resolveModelAutoCompactLimit?.(model)
336
+ : undefined
333
337
  }
@@ -86,7 +86,9 @@ export interface PreparedTurn {
86
86
  readonly resilientProvider: LLMProvider
87
87
  readonly serving: { current: ServingMember }
88
88
  readonly providerContextWindow: number | undefined
89
+ readonly providerAutoCompactLimit: number | undefined
89
90
  readonly modelContextWindows: Map<string, number | undefined>
91
+ readonly modelAutoCompactLimits: Map<string, number | undefined>
90
92
  readonly approvalPolicy: SessionApprovalPolicy
91
93
  readonly eventTranslator: EventTranslator
92
94
  readonly executeUserInterruptHooks: (terminalError: unknown) => Promise<void>
@@ -224,8 +226,11 @@ export async function resolveProviderContextWindow(
224
226
  signal: AbortSignal | undefined,
225
227
  timeoutMs: number,
226
228
  log: Logger,
229
+ /** Which of the driver's two optional limit lookups to ask; both share one bounded, swallowed path. */
230
+ member: 'resolveContextWindow' | 'resolveAutoCompactLimit' = 'resolveContextWindow',
227
231
  ): Promise<number | undefined> {
228
- if (!provider.resolveContextWindow || !model) return undefined
232
+ const lookup = provider[member]
233
+ if (!lookup || !model) return undefined
229
234
  if (signal?.aborted) return undefined
230
235
 
231
236
  // The resolver is an optional optimisation that runs before TurnContext
@@ -253,7 +258,7 @@ export async function resolveProviderContextWindow(
253
258
  }, deadlineMs)
254
259
 
255
260
  try {
256
- const resolution = provider.resolveContextWindow(model, resolverSignal)
261
+ const resolution = lookup.call(provider, model, resolverSignal)
257
262
  const reported = await Promise.race([resolution, interruption])
258
263
  if (reported === interrupted) {
259
264
  if (deadline.signal.aborted) {
@@ -499,6 +504,17 @@ export async function prepareTurn(params: QueryParams): Promise<PreparedTurn> {
499
504
  )
500
505
  const modelContextWindows = new Map<string, number | undefined>()
501
506
  if (turnConfig.model) modelContextWindows.set(turnConfig.model, providerContextWindow)
507
+ // The same lookup, for the threshold the driver's own service says compaction starts at.
508
+ const providerAutoCompactLimit = await resolveProviderContextWindow(
509
+ resilientProvider,
510
+ turnConfig.model,
511
+ params.signal,
512
+ turnConfig.timeoutMs,
513
+ log,
514
+ 'resolveAutoCompactLimit',
515
+ )
516
+ const modelAutoCompactLimits = new Map<string, number | undefined>()
517
+ if (turnConfig.model) modelAutoCompactLimits.set(turnConfig.model, providerAutoCompactLimit)
502
518
 
503
519
  // The mode this conversation was left in, when the turn config names none.
504
520
  // Read once, before the loop exists, for the same reason the context
@@ -880,7 +896,9 @@ export async function prepareTurn(params: QueryParams): Promise<PreparedTurn> {
880
896
  resilientProvider,
881
897
  serving,
882
898
  providerContextWindow,
899
+ providerAutoCompactLimit,
883
900
  modelContextWindows,
901
+ modelAutoCompactLimits,
884
902
  approvalPolicy,
885
903
  eventTranslator,
886
904
  executeUserInterruptHooks,
@@ -949,11 +949,20 @@ export interface ReviewPolicyOptions {
949
949
  /**
950
950
  * Called when the classifier has given no verdict several times in a row
951
951
  * (`AutoReviewLimits.noVerdict`): it could not be reached, or its answers
952
- * could not be read. The policy refuses the batch and ends the turn, with a
953
- * person to ask or without one, rather than hold back call after call; this
952
+ * could not be read. With nobody to ask, the policy refuses the batch and
953
+ * ends the turn rather than hold back call after call; with a person to ask,
954
+ * the person is asked instead and this is not called. This
954
955
  * is where a host says so in its own words. `reason` is the last block's.
955
956
  */
956
957
  readonly onClassifierUnavailable?: (event: { readonly reason: string }) => void
958
+ /**
959
+ * Called when the classifier could not complete a check (or gave an answer
960
+ * that was not a verdict) and a person was asked about the call instead.
961
+ * Only with a `prompt`; without one the call is refused and
962
+ * {@link onClassifierUnavailable} is how a run of them is reported.
963
+ * `reason` names the class of failure.
964
+ */
965
+ readonly onClassifierFellBack?: (event: { readonly reason: string }) => void
957
966
  }
958
967
 
959
968
  /**
@@ -1370,8 +1379,19 @@ export function createReviewHandler(options: ReviewPolicyOptions = {}): ResumeHa
1370
1379
  return askPerson(escapes)
1371
1380
  }
1372
1381
  transcriptTooLong = false
1373
- // A check that keeps giving no verdict ends the turn, person or not:
1374
- // holding calls back one at a time against it gets nowhere, and
1382
+ // A check that could not be completed says nothing about the call,
1383
+ // so with a person to ask the person is asked, as for a call the
1384
+ // classifier was never going to judge. This is not a refusal and it
1385
+ // does not count toward ending the turn. The host hears why, so it
1386
+ // can say the check is down.
1387
+ if (decision.cause === 'unavailable' || decision.cause === 'unreadable') {
1388
+ if (prompt) {
1389
+ options.onClassifierFellBack?.({ reason: decision.reason })
1390
+ return askPerson(escapes)
1391
+ }
1392
+ }
1393
+ // With nobody to ask, a check that keeps giving no verdict ends the
1394
+ // turn: holding calls back one at a time against it gets nowhere, and
1375
1395
  // nothing is run unchecked.
1376
1396
  if (decision.noVerdictLimitReached === true) {
1377
1397
  options.onClassifierUnavailable?.({ reason: decision.reason })
@@ -140,6 +140,8 @@ export interface OutcomeLedgerSnapshot {
140
140
  readonly unseen?: boolean
141
141
  /** Absent in a snapshot written before it existed. */
142
142
  readonly pathless?: number
143
+ /** Background jobs that run a recognised check: job id and command. Absent in an older snapshot. */
144
+ readonly jobs?: readonly (readonly [string, string])[]
143
145
  readonly checks: readonly {
144
146
  readonly key: string
145
147
  readonly command: string
@@ -369,6 +371,8 @@ export class OutcomeLedger {
369
371
  private couldHaveChangedUnseen = false
370
372
  private writes = 0
371
373
  private readonly checks = new Map<string, CheckState>()
374
+ /** Background jobs that run a recognised check, by job id: the command they run. */
375
+ private readonly jobChecks = new Map<string, string>()
372
376
  private unrecorded = false
373
377
  private settled: TurnOutcome | undefined
374
378
 
@@ -403,6 +407,8 @@ export class OutcomeLedger {
403
407
  this.writes = parsed.writes
404
408
  this.pathless = parsed.pathless ?? 0
405
409
  this.couldHaveChangedUnseen = parsed.unseen === true
410
+ this.jobChecks.clear()
411
+ for (const [id, command] of parsed.jobs ?? []) this.jobChecks.set(id, command)
406
412
  this.checks.clear()
407
413
  for (const check of parsed.checks) {
408
414
  this.checks.set(check.key, { ...check, fingerprint: check.fingerprint })
@@ -419,6 +425,7 @@ export class OutcomeLedger {
419
425
  writes: this.writes,
420
426
  unseen: this.couldHaveChangedUnseen,
421
427
  pathless: this.pathless,
428
+ jobs: [...this.jobChecks.entries()].slice(-MAX_REMEMBERED_CHECKS),
422
429
  checks: [...this.checks.values()].map((check) => ({
423
430
  key: check.key,
424
431
  command: check.command,
@@ -486,6 +493,21 @@ export class OutcomeLedger {
486
493
  // answers for exactly the state they left.
487
494
  let pending: CheckState[] = []
488
495
  for (const call of calls) {
496
+ // A check started as a background job is not a result yet; the wait that
497
+ // reads its exit is. Remember which command the job runs.
498
+ // A foreground check the time limit moved to the background is a job too,
499
+ // though the call was not marked `launched`.
500
+ if (
501
+ call.toolName === 'bash' &&
502
+ call.facts?.kind === 'command' &&
503
+ call.facts.jobId !== undefined &&
504
+ (call.launched === true || call.facts.background === true)
505
+ ) {
506
+ const started = commandOf(call.input)
507
+ if (started !== undefined && runsRecognisedCheck(started, this.config.isCheck)) {
508
+ this.jobChecks.set(call.facts.jobId, started)
509
+ }
510
+ }
489
511
  // A call that did not run, or only started work elsewhere, changed nothing here.
490
512
  if (call.skipped === true || call.notRun === true || call.launched === true) continue
491
513
  const written = WRITING_TOOLS.has(call.toolName)
@@ -498,7 +520,16 @@ export class OutcomeLedger {
498
520
  continue
499
521
  }
500
522
  if (written) continue
501
- const command = call.toolName === 'bash' ? commandOf(call.input) : undefined
523
+ // The exit of a background check, read by `wait_for_job`, is that check's
524
+ // result: the job's own command, with the exit code the wait reported.
525
+ const jobCommand =
526
+ call.toolName === 'wait_for_job' &&
527
+ call.facts?.kind === 'command' &&
528
+ call.facts.jobId !== undefined &&
529
+ call.facts.exitCode !== undefined
530
+ ? this.jobChecks.get(call.facts.jobId)
531
+ : undefined
532
+ const command = call.toolName === 'bash' ? commandOf(call.input) : jobCommand
502
533
  if (command !== undefined && runsRecognisedCheck(command, this.config.isCheck)) {
503
534
  this.afterEveryCheck('other')
504
535
  for (const check of pending) check.fingerprint = null
@@ -720,6 +751,19 @@ function parseSnapshot(value: unknown): OutcomeLedgerSnapshot | undefined {
720
751
  ) {
721
752
  return undefined
722
753
  }
754
+ if (
755
+ snap.jobs !== undefined &&
756
+ (!Array.isArray(snap.jobs) ||
757
+ !snap.jobs.every(
758
+ (j) =>
759
+ Array.isArray(j) &&
760
+ j.length === 2 &&
761
+ typeof j[0] === 'string' &&
762
+ typeof j[1] === 'string',
763
+ ))
764
+ ) {
765
+ return undefined
766
+ }
723
767
  if (!Array.isArray(snap.checks)) return undefined
724
768
  const results = new Set<string>(['passed', 'failed', 'masked', 'unsettled'])
725
769
  for (const raw of snap.checks) {
@@ -49,6 +49,7 @@ import type {
49
49
  import { subscribeToAbort } from '../../utils/abort.js'
50
50
  import { generateSandboxId } from '../../utils/id.js'
51
51
  import type { Logger } from '../../utils/logger.js'
52
+ import { withNodeOnPath } from '../../utils/node-on-path.js'
52
53
  import {
53
54
  WINDOWS_CORE_ENV_KEYS,
54
55
  applyEnvironmentOverrides,
@@ -603,7 +604,8 @@ export function buildSafeEnv(
603
604
  // Last: a command in a sandbox is still a command a session started.
604
605
  setEnvironmentEntry(env, SESSION_CHILD_ENV, '1')
605
606
 
606
- return env
607
+ // A shell inside the sandbox can run `node` when the user's PATH has none.
608
+ return withNodeOnPath(env)
607
609
  }
608
610
 
609
611
  /**
@@ -184,6 +184,24 @@ export function admitToolFacts(value: unknown): ToolFacts | undefined {
184
184
  hunksTruncated: flag(value.hunksTruncated),
185
185
  })
186
186
  }
187
+ case 'shared': {
188
+ if (!Array.isArray(value.files) || value.files.length === 0 || value.files.length > 50)
189
+ return undefined
190
+ const files: { path: string; real?: string; bytes?: number }[] = []
191
+ for (const file of value.files) {
192
+ if (!isRecord(file)) return undefined
193
+ const path = text(file.path)
194
+ if (path === undefined) return undefined
195
+ const bytes = count(file.bytes)
196
+ const real = text(file.real)
197
+ files.push({
198
+ path,
199
+ ...(real === undefined ? {} : { real }),
200
+ ...(bytes === undefined ? {} : { bytes }),
201
+ })
202
+ }
203
+ return pick<ToolFacts>({ kind: 'shared', files, caption: text(value.caption) })
204
+ }
187
205
  case 'failure': {
188
206
  const reason = FAILURE_REASONS.find((candidate) => candidate === value.reason)
189
207
  if (reason === undefined) return undefined