@sema-agent/core 7.64.0 → 7.66.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 (192) hide show
  1. package/CHANGELOG.md +571 -0
  2. package/dist/agents/delegation-registry-seat.d.ts +15 -0
  3. package/dist/agents/delegation-registry-seat.js +13 -0
  4. package/dist/agents/org-delivery-gate.d.ts +8 -1
  5. package/dist/agents/org-delivery-gate.js +9 -3
  6. package/dist/agents/peer-held-queue.js +1 -1
  7. package/dist/agents/peer-idle.js +1 -1
  8. package/dist/agents/peer-session-drain.d.ts +51 -12
  9. package/dist/agents/peer-session-drain.js +47 -34
  10. package/dist/agents/read-inbox-tool.d.ts +6 -2
  11. package/dist/agents/read-inbox-tool.js +18 -5
  12. package/dist/agents/subagent.d.ts +3 -1
  13. package/dist/agents/subagent.js +84 -77
  14. package/dist/brain/reasoning.d.ts +2 -0
  15. package/dist/brain/reasoning.js +1 -0
  16. package/dist/core/allow-entry.d.ts +9 -0
  17. package/dist/core/allow-entry.js +7 -1
  18. package/dist/core/ask-origin.d.ts +23 -3
  19. package/dist/core/ask-origin.js +11 -1
  20. package/dist/core/auto-promote.d.ts +3 -2
  21. package/dist/core/background-agent-store.d.ts +7 -0
  22. package/dist/core/checkpoint-store.d.ts +2 -3
  23. package/dist/core/context-settings.d.ts +1 -2
  24. package/dist/core/context-settings.js +1 -1
  25. package/dist/core/engine-attestation.d.ts +2 -2
  26. package/dist/core/engine-notice.d.ts +13 -1
  27. package/dist/core/engine-notice.js +3 -1
  28. package/dist/core/file-history-store.d.ts +2 -2
  29. package/dist/core/file-history-store.js +0 -4
  30. package/dist/core/gate-fold.js +3 -1
  31. package/dist/core/governance-codes.d.ts +6 -4
  32. package/dist/core/governance-codes.js +5 -3
  33. package/dist/core/human-input-projection.d.ts +9 -0
  34. package/dist/core/human-input-projection.js +13 -0
  35. package/dist/core/input-author.d.ts +66 -6
  36. package/dist/core/input-author.js +21 -3
  37. package/dist/core/leg-identity.d.ts +18 -2
  38. package/dist/core/leg-identity.js +5 -7
  39. package/dist/core/mailbox-store.d.ts +1 -1
  40. package/dist/core/memory-engine/consolidation.d.ts +30 -10
  41. package/dist/core/memory-engine/consolidation.js +41 -6
  42. package/dist/core/memory-engine/control-objects.d.ts +36 -3
  43. package/dist/core/memory-engine/control-objects.js +134 -12
  44. package/dist/core/memory-engine/control-plane-adoption.d.ts +13 -9
  45. package/dist/core/memory-engine/control-plane-adoption.js +58 -31
  46. package/dist/core/memory-engine/delegation-settlement.d.ts +75 -52
  47. package/dist/core/memory-engine/delegation-settlement.js +211 -228
  48. package/dist/core/memory-engine/dual-root.d.ts +3 -2
  49. package/dist/core/memory-engine/dual-root.js +5 -1
  50. package/dist/core/memory-engine/engine.d.ts +33 -16
  51. package/dist/core/memory-engine/engine.js +213 -177
  52. package/dist/core/memory-engine/file-backend.d.ts +21 -12
  53. package/dist/core/memory-engine/file-backend.js +58 -104
  54. package/dist/core/memory-engine/index.d.ts +2 -2
  55. package/dist/core/memory-engine/index.js +2 -2
  56. package/dist/core/memory-engine/layout.d.ts +184 -83
  57. package/dist/core/memory-engine/layout.js +267 -172
  58. package/dist/core/memory-engine/memory-age.d.ts +12 -0
  59. package/dist/core/memory-engine/memory-age.js +17 -0
  60. package/dist/core/memory-engine/memory-backend-contract.js +12 -11
  61. package/dist/core/memory-engine/memory-deployment.d.ts +4 -3
  62. package/dist/core/memory-engine/memory-deployment.js +6 -3
  63. package/dist/core/memory-engine/origin-clearance.d.ts +43 -15
  64. package/dist/core/memory-engine/origin-clearance.js +142 -58
  65. package/dist/core/memory-engine/tools.d.ts +2 -2
  66. package/dist/core/memory-engine/tools.js +7 -7
  67. package/dist/core/memory-engine/types.d.ts +16 -10
  68. package/dist/core/memory-vector.d.ts +6 -14
  69. package/dist/core/memory.d.ts +0 -462
  70. package/dist/core/memory.js +0 -333
  71. package/dist/core/model-receipt.d.ts +2 -1
  72. package/dist/core/model-receipt.js +5 -0
  73. package/dist/core/mods/dollar.d.ts +12 -0
  74. package/dist/core/mods/kernel/dispatch.d.ts +3 -1
  75. package/dist/core/mods/kernel/dispatch.js +5 -2
  76. package/dist/core/mods/kernel/events.d.ts +3 -1
  77. package/dist/core/mods/kernel/events.js +2 -2
  78. package/dist/core/mods/prompt-submit.d.ts +4 -0
  79. package/dist/core/mods/prompt-submit.js +24 -0
  80. package/dist/core/mods/stations.d.ts +23 -4
  81. package/dist/core/mods/stations.js +14 -7
  82. package/dist/core/permission-rule-consent.d.ts +49 -18
  83. package/dist/core/permission-rule-consent.js +59 -38
  84. package/dist/core/permission-rule-store.d.ts +24 -14
  85. package/dist/core/retention.d.ts +2 -7
  86. package/dist/core/retention.js +0 -1
  87. package/dist/core/retired-host-table-account.d.ts +19 -0
  88. package/dist/core/retired-host-table-account.js +28 -0
  89. package/dist/core/retired-tool-name-account.d.ts +60 -0
  90. package/dist/core/retired-tool-name-account.js +32 -0
  91. package/dist/core/roles.d.ts +3 -1
  92. package/dist/core/roles.js +5 -2
  93. package/dist/core/runner/classifier-ladder.d.ts +3 -1
  94. package/dist/core/runner/classifier-ladder.js +2 -2
  95. package/dist/core/runner/compact-session.js +2 -1
  96. package/dist/core/runner/contracts.d.ts +9 -9
  97. package/dist/core/runner/delegation-owner.d.ts +0 -8
  98. package/dist/core/runner/delegation-owner.js +1 -3
  99. package/dist/core/runner/gate-exit.js +9 -2
  100. package/dist/core/runner/memory-consolidation-driver.js +2 -2
  101. package/dist/core/runner/prepare-config-doors.js +1 -1
  102. package/dist/core/runner/prepare-delegation-surface.d.ts +1 -1
  103. package/dist/core/runner/prepare-delegation-surface.js +5 -3
  104. package/dist/core/runner/prepare-gate-stations.d.ts +8 -5
  105. package/dist/core/runner/prepare-gate-stations.js +13 -5
  106. package/dist/core/runner/prepare-inherited-gate.js +2 -0
  107. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  108. package/dist/core/runner/prepare-memory.js +35 -14
  109. package/dist/core/runner/prepare-policy-chain.js +12 -3
  110. package/dist/core/runner/prepare-project-context.js +2 -2
  111. package/dist/core/runner/prepare-task.d.ts +9 -1
  112. package/dist/core/runner/prepare-task.js +6 -5
  113. package/dist/core/runner/prepare-wiring-manifest.js +5 -4
  114. package/dist/core/runner/prompt-suggestions.js +1 -1
  115. package/dist/core/runner/run-identity-wiring.js +2 -2
  116. package/dist/core/runner/run-leg.js +3 -3
  117. package/dist/core/runner/run-notification-lane.d.ts +3 -0
  118. package/dist/core/runner/run-notification-lane.js +2 -2
  119. package/dist/core/runner/runtask.js +6 -3
  120. package/dist/core/runner/steer-admission.d.ts +11 -2
  121. package/dist/core/runner/stream-steer-verb.d.ts +5 -2
  122. package/dist/core/runner/stream-steer-verb.js +67 -14
  123. package/dist/core/runner/sub-agent-deny-lists.d.ts +8 -8
  124. package/dist/core/runner/sub-agent-deny-lists.js +22 -8
  125. package/dist/core/runner-deps.d.ts +4 -4
  126. package/dist/core/secret-env.d.ts +2 -2
  127. package/dist/core/secret-env.js +6 -20
  128. package/dist/core/session-store.d.ts +6 -6
  129. package/dist/core/session-store.js +3 -3
  130. package/dist/core/shell-run-candidates.js +3 -3
  131. package/dist/core/side-query.js +1 -1
  132. package/dist/core/skill-grant.d.ts +7 -0
  133. package/dist/core/skill-grant.js +14 -5
  134. package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
  135. package/dist/core/task-event.d.ts +14 -0
  136. package/dist/core/task-notification.d.ts +35 -8
  137. package/dist/core/task-notification.js +31 -13
  138. package/dist/core/task-registry-agent.js +1 -0
  139. package/dist/core/task-registry-shared.d.ts +4 -0
  140. package/dist/core/tool-errors.d.ts +3 -3
  141. package/dist/core/tool-policy.js +2 -3
  142. package/dist/core/tool-spec.d.ts +20 -10
  143. package/dist/core/user-attachment.d.ts +5 -1
  144. package/dist/core/user-attachment.js +11 -5
  145. package/dist/core/write-protect.d.ts +16 -0
  146. package/dist/core/write-protect.js +10 -0
  147. package/dist/engine/harness/agent-harness.d.ts +19 -11
  148. package/dist/engine/harness/agent-harness.js +7 -4
  149. package/dist/engine/llm/types.d.ts +22 -10
  150. package/dist/engine/session/repo-utils.d.ts +14 -4
  151. package/dist/engine/session/repo-utils.js +5 -4
  152. package/dist/index.d.ts +10 -8
  153. package/dist/index.js +9 -7
  154. package/dist/prompts/default.d.ts +1 -2
  155. package/dist/scenarios/full-body.d.ts +1 -1
  156. package/dist/shell/lex.d.ts +50 -15
  157. package/dist/shell/lex.js +43 -9
  158. package/dist/stores/file/adoption/adopt.d.ts +1 -1
  159. package/dist/stores/file/index.d.ts +1 -15
  160. package/dist/stores/file/index.js +1 -15
  161. package/dist/stores/file/permission-rule-store.d.ts +12 -1
  162. package/dist/stores/file/permission-rule-store.js +31 -4
  163. package/dist/stores/file/session-store.js +1 -1
  164. package/dist/tools/fs/fs-bash.js +3 -3
  165. package/dist/tools/fs/removal-targets.d.ts +8 -2
  166. package/dist/tools/fs/removal-targets.js +31 -4
  167. package/dist/tools/fs/shell-read-argv.js +7 -1
  168. package/dist/tools/fs/shell-read-bindings.d.ts +21 -5
  169. package/dist/tools/fs/shell-read-bindings.js +130 -44
  170. package/dist/tools/fs/shell-read-plan.js +95 -29
  171. package/dist/tools/fs/shell-read-sourced.d.ts +25 -0
  172. package/dist/tools/fs/shell-read-sourced.js +119 -0
  173. package/dist/tools/fs/shell-read-word.d.ts +2 -2
  174. package/dist/tools/fs/shell-read-word.js +4 -5
  175. package/dist/tools/fs/shell-read-workdir.d.ts +19 -3
  176. package/dist/tools/fs/shell-read-workdir.js +60 -15
  177. package/dist/tools/fs/shell-reentry-text.d.ts +10 -2
  178. package/dist/tools/fs/shell-reentry-text.js +11 -4
  179. package/package.json +2 -2
  180. package/test/export-surface.snapshot.json +21 -79
  181. package/wire-changes/core-stores-sql@7.65.0.json +30 -0
  182. package/wire-changes/core-stores-sql@7.66.0.json +30 -0
  183. package/wire-changes/core@7.65.0.json +1650 -0
  184. package/wire-changes/core@7.66.0.json +1218 -0
  185. package/wire-changes/mods-kernel@7.65.0.json +30 -0
  186. package/wire-changes/mods-kernel@7.66.0.json +65 -0
  187. package/wire-changes/primitives@7.65.0.json +337 -0
  188. package/wire-changes/primitives@7.66.0.json +30 -0
  189. package/dist/core/memory-recall.d.ts +0 -208
  190. package/dist/core/memory-recall.js +0 -136
  191. package/dist/stores/file/memory-store.d.ts +0 -124
  192. package/dist/stores/file/memory-store.js +0 -353
@@ -46,6 +46,7 @@ import { uuidv7 } from "../internal/harness.js";
46
46
  import { addWorktree } from "../core/git-worktree-env.js";
47
47
  import { shellQuote } from "../tools/fs/search.js";
48
48
  import { BG_AGENT_REAP_STOP_ERROR, chosenAgentName } from "../core/task-registry.js";
49
+ import { delegationRegistryOf } from "./delegation-registry-seat.js";
49
50
  import { agentOutcomeIsError } from "../core/task-registry-agent.js";
50
51
  import { readDurableOrgAdmission } from "../core/memory-admission.js";
51
52
  import { governanceRetryClass } from "../core/governance-codes.js";
@@ -1549,10 +1550,11 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
1549
1550
  execute: async (args, ctx) => {
1550
1551
  const a = canonicalSubagentTypeArgs(args, acceptedSubagentTypes(), generalPurposeShadowed);
1551
1552
  const parentSpecSeat = parentSpecSeatOfCtx(ctx);
1553
+ const background = opts.background, backgroundRegistry = delegationRegistryOf(ctx, background);
1552
1554
  const reviveClaim = ctx.reviveClaim;
1553
- const parkedLane = reviveClaim?.parkedResume !== undefined ? opts.background?.registry.parkedCompletionSink(reviveClaim.row.handle) : undefined;
1554
- const backgroundSink = opts.background !== undefined ? resolveCompletionSink(ctx.onTaskNotification ?? parkedLane, opts.background.notify) : undefined;
1555
- const backgroundLane = opts.background !== undefined && admitsBackgroundLaunch(backgroundSink);
1555
+ const parkedLane = reviveClaim?.parkedResume !== undefined ? backgroundRegistry?.parkedCompletionSink(reviveClaim.row.handle) : undefined;
1556
+ const backgroundSink = background !== undefined ? resolveCompletionSink(ctx.onTaskNotification ?? parkedLane, background.notify) : undefined;
1557
+ const backgroundLane = background !== undefined && admitsBackgroundLaunch(backgroundSink);
1556
1558
  if (reviveClaim !== undefined && !backgroundLane) {
1557
1559
  return notStartedResult({
1558
1560
  isError: true,
@@ -1614,7 +1616,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
1614
1616
  });
1615
1617
  }
1616
1618
  }
1617
- const backgroundAsked = opts.background !== undefined && (a.run_in_background !== false || def?.background === true || agentName !== undefined);
1619
+ const backgroundAsked = background !== undefined && (a.run_in_background !== false || def?.background === true || agentName !== undefined);
1618
1620
  const wantsBackground = backgroundLane && backgroundAsked;
1619
1621
  const ranSyncNote = backgroundAsked && !backgroundLane ? AGENT_RAN_SYNC_NO_CHANNEL_NOTE : undefined;
1620
1622
  const stations = reviveClaim === undefined ? ctx.agentStations : undefined;
@@ -1993,7 +1995,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
1993
1995
  throw new Error("observed child has no steer lane (report undeliverable)");
1994
1996
  if (author !== "observer")
1995
1997
  pendingTrigger.push(text);
1996
- await steer(author, text);
1998
+ const answer = await steer(author, text);
1999
+ if ("drop" in answer)
2000
+ throw new Error(`observed child's steer lane did not take the report (${answer.drop})`);
1997
2001
  };
1998
2002
  if (observerArm) {
1999
2003
  pendingTrigger.push(prompt);
@@ -2180,8 +2184,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2180
2184
  const editedFiles = stepRecorder.editedFiles();
2181
2185
  return { ...(recentSteps ? { recentSteps } : {}), ...(editedFiles ? { editedFiles } : {}) };
2182
2186
  };
2183
- const treeScope = reviveClaim?.row.scope ?? parentSpecSeat?.principal ?? opts.background?.scope;
2184
- const entryCapPoolAnchor = opts.background?.registry ?? opts;
2187
+ const treeScope = reviveClaim?.row.scope ?? parentSpecSeat?.principal ?? background?.scope;
2188
+ const entryCapPoolAnchor = backgroundRegistry ?? opts;
2185
2189
  const entryCaps = ctx.delegationEntryCaps ?? { maxConcurrent: DELEGATION_MAX_CONCURRENT_DEFAULT, maxCumulativePerSession: DELEGATION_MAX_PER_SESSION_DEFAULT };
2186
2190
  const entryCapRoot = reviveClaim !== undefined
2187
2191
  ? (reviveClaim.row.rootSessionId ?? reviveClaim.row.parentSessionId ?? (reviveClaim.row.sessionScoped ? reviveClaim.row.owner : undefined))
@@ -2189,11 +2193,11 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2189
2193
  const entryPoolSeat = { poolAnchor: entryCapPoolAnchor, scope: treeScope, root: entryCapRoot };
2190
2194
  const openEntryGate = () => openDelegationEntryGate({
2191
2195
  ...entryPoolSeat,
2192
- registry: opts.background?.registry,
2193
- store: opts.background?.agentStore,
2196
+ registry: backgroundRegistry,
2197
+ store: background?.agentStore,
2194
2198
  caps: entryCaps,
2195
2199
  signal: ctx.signal,
2196
- caller: { owner: ctx.taskId ?? opts.background?.owner, ...(ctx.sessionId !== undefined ? { sessionId: ctx.sessionId } : {}) },
2200
+ caller: { owner: ctx.taskId ?? background?.owner, ...(ctx.sessionId !== undefined ? { sessionId: ctx.sessionId } : {}) },
2197
2201
  });
2198
2202
  const provenanceRequest = ctx.delegationProvenanceForChildren?.();
2199
2203
  const childProvenanceRef = provenanceRequest !== undefined ? { current: newDelegationProvenanceAggregate() } : undefined;
@@ -2252,6 +2256,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2252
2256
  ...((reviveClaim.row.rootSessionId ?? reviveClaim.row.parentSessionId) !== undefined
2253
2257
  ? { rootSessionId: reviveClaim.row.rootSessionId ?? reviveClaim.row.parentSessionId }
2254
2258
  : {}),
2259
+ ...(reviveClaim.row.rootSessionId !== undefined && reviveClaim.row.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: reviveClaim.row.rootSessionIncarnation } : {}),
2255
2260
  }
2256
2261
  : {
2257
2262
  ...(ctx.taskId !== undefined ? { parentTaskId: ctx.taskId } : {}),
@@ -2407,8 +2412,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2407
2412
  ? getOrCreateSessionRetainLedger(ctx.sessionId, { ttlMs: FAILED_SESSION_RETAIN_TTL_MS, max: RETAIN_DEFAULT_MAX })
2408
2413
  : ctx.subagentRetain;
2409
2414
  if (ledger !== undefined && !ledger.disposed) {
2410
- if (opts.background)
2411
- ensureSessionReapHook(opts.background.registry);
2415
+ if (backgroundRegistry)
2416
+ ensureSessionReapHook(backgroundRegistry);
2412
2417
  const failedRetainStrip = stripSpawnTurnQuestionFace(buildChildSpec(undefined));
2413
2418
  const { signal: _spawnSignal, ...plainSpec } = failedRetainStrip.spec;
2414
2419
  const entry = ledger.register(ctx.toolCallId, {
@@ -2511,8 +2516,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2511
2516
  const forkTree = await delegationOwnerOf(ctx.delegationOwner);
2512
2517
  if (!forkTree.bound)
2513
2518
  return ownerUnboundResult(false, forkTree);
2514
- const forkBg = wantsBackground ? opts.background : undefined;
2515
- const forkPlacementHandle = forkBg?.agentStore !== undefined ? forkBg.registry.mintTaskId("background_agent") : undefined;
2519
+ const forkBg = wantsBackground ? background : undefined;
2520
+ const forkPlacementHandle = forkBg?.agentStore !== undefined ? backgroundRegistry.mintTaskId("background_agent") : undefined;
2516
2521
  const forkOpts = forkPlacementHandle !== undefined ? { placement: subagentTranscriptPlacement(ctx, treeScope, forkPlacementHandle) } : undefined;
2517
2522
  try {
2518
2523
  if (ctx.hostSessionFork) {
@@ -2537,7 +2542,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2537
2542
  const forkWorktreeNote = worktreeDir !== undefined ? forkWorktreeTranslationNote(ctx.parentCwd, worktreeDir) : undefined;
2538
2543
  const forkObjective = `${FORK_DIRECTIVE_FRAME}${prompt}${forkWorktreeNote !== undefined ? `\n\n${forkWorktreeNote}` : ""}${parentSpecSeat?.advisorModel !== undefined ? `\n\n${ADVISOR_FORK_SENTENCE}` : ""}`;
2539
2544
  if (wantsBackground) {
2540
- const bg = opts.background;
2545
+ const bg = background, bgRegistry = backgroundRegistry;
2541
2546
  const notify = backgroundSink;
2542
2547
  const abort = new AbortController();
2543
2548
  const sessionScopedBg = ctx.backgroundScope === "session" && ctx.sessionId !== undefined;
@@ -2601,7 +2606,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2601
2606
  }
2602
2607
  if (settled && verdict === "external") {
2603
2608
  try {
2604
- await replayExternalSettlementEffects(forkSettlementSeat.governance, forkSettlementSeat.controlDir, { carry: true, now: Date.now });
2609
+ await replayExternalSettlementEffects(forkSettlementSeat.governance, { carry: true, now: Date.now });
2605
2610
  }
2606
2611
  catch {
2607
2612
  }
@@ -2613,7 +2618,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2613
2618
  };
2614
2619
  let taskId;
2615
2620
  try {
2616
- taskId = bg.registry.registerBackgroundAgent({
2621
+ taskId = bgRegistry.registerBackgroundAgent({
2617
2622
  ...(forkPlacementHandle !== undefined ? { id: forkPlacementHandle } : {}),
2618
2623
  ...(bgOwner !== undefined ? { owner: bgOwner } : {}),
2619
2624
  ...(bgScope !== undefined ? { scope: bgScope } : {}),
@@ -2625,6 +2630,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2625
2630
  ...(ctx.taskId !== undefined && ctx.taskId !== ctx.sessionId ? { parentTaskId: ctx.taskId } : {}),
2626
2631
  ...(ctx.sessionId !== undefined ? { parentSessionId: ctx.sessionId } : {}),
2627
2632
  ...((ctx.rootSessionId ?? ctx.sessionId) !== undefined ? { rootSessionId: ctx.rootSessionId ?? ctx.sessionId } : {}),
2633
+ ...(ctx.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: ctx.rootSessionIncarnation } : {}),
2628
2634
  ...(rowModelKey !== undefined ? { model: rowModelKey } : {}),
2629
2635
  deliveryChannel: "attaching",
2630
2636
  toolUseId: ctx.toolCallId,
@@ -2651,16 +2657,16 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2651
2657
  return notStartedResult({ isError: true, content: `Sub-agent not started in background: the background task could not be registered.${wt ? `\n${wt}` : ""}`, details: { error: "register_failed", ...faultDetails(e) } });
2652
2658
  }
2653
2659
  if (forkEntryGate.key !== undefined)
2654
- chargeDelegationEntryHandle(bg.registry, forkEntryGate.key, bg.agentStore, taskId);
2660
+ chargeDelegationEntryHandle(bgRegistry, forkEntryGate.key, bg.agentStore, taskId);
2655
2661
  oweTerminalDelivery(notify, { task_id: taskId, task_type: "background_agent" });
2656
2662
  childInternals.peerSelfRef?.addAxis("h", taskId);
2657
- bg.registry.bindBackgroundAgentSession(taskId, forkedId, opts.runner.sessions);
2663
+ bgRegistry.bindBackgroundAgentSession(taskId, forkedId, opts.runner.sessions);
2658
2664
  stepRecorder.lockTo(taskId);
2659
2665
  const forkBgHangAt = Date.now();
2660
- bg.registry.attachAgentTerminalNotifier(taskId, () => {
2661
- const stoppedByReap = bg.registry.getStopAttribution(taskId) ?? "system";
2662
- const completionIdReap = bg.registry.getCompletionId(taskId);
2663
- const seqReap = bg.registry.backgroundAgentCycleSeq(taskId);
2666
+ bgRegistry.attachAgentTerminalNotifier(taskId, () => {
2667
+ const stoppedByReap = bgRegistry.getStopAttribution(taskId) ?? "system";
2668
+ const completionIdReap = bgRegistry.getCompletionId(taskId);
2669
+ const seqReap = bgRegistry.backgroundAgentCycleSeq(taskId);
2664
2670
  const reapFrame = {
2665
2671
  task_id: taskId,
2666
2672
  task_type: "background_agent",
@@ -2686,7 +2692,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2686
2692
  catch {
2687
2693
  }
2688
2694
  };
2689
- const bgForkCycleSeq = bg.registry.backgroundAgentCycleSeq(taskId);
2695
+ const bgForkCycleSeq = bgRegistry.backgroundAgentCycleSeq(taskId);
2690
2696
  sinkEmit({
2691
2697
  kind: "spawn",
2692
2698
  taskId,
@@ -2711,7 +2717,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2711
2717
  const forkQuestionStrip = sessionScopedBg ? stripSpawnTurnQuestionFace(bgForkSpecBase) : undefined;
2712
2718
  const bgForkSpec = forkQuestionStrip !== undefined ? forkQuestionStrip.spec : bgForkSpecBase;
2713
2719
  const s2ForkNotifyReady = (inject) => {
2714
- bg.registry.attachAgentNotify(taskId, inject);
2720
+ bgRegistry.attachAgentNotify(taskId, inject);
2715
2721
  };
2716
2722
  const bgForkActivityBeat = createBgActivityBeat(ctx.toolCallId, (toolStarts) => {
2717
2723
  const currentAction = stepRecorder.currentAction();
@@ -2731,7 +2737,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2731
2737
  ...(currentTool !== undefined ? { currentTool } : {}),
2732
2738
  usage: { toolUses: toolStarts },
2733
2739
  });
2734
- }, () => bg.registry.noteBackgroundAgentActivity(taskId));
2740
+ }, () => bgRegistry.noteBackgroundAgentActivity(taskId));
2735
2741
  const bgForkInternals = bgSink
2736
2742
  ? {
2737
2743
  ...forkInternals,
@@ -2812,11 +2818,11 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2812
2818
  const forkBgResult = withHandbackWarning(forkBgWarning, child.result);
2813
2819
  const okBg = child.terminal.kind === "completed";
2814
2820
  const reapedBg = !okBg && abort.signal.aborted;
2815
- const collateralBg = reapedBg && bg.registry.getAccessibleTask(taskId, { ...(bgOwner !== undefined ? { owner: bgOwner } : {}), ...(bgScope !== undefined ? { scope: bgScope } : {}) })?.status === "running";
2821
+ const collateralBg = reapedBg && bgRegistry.getAccessibleTask(taskId, { ...(bgOwner !== undefined ? { owner: bgOwner } : {}), ...(bgScope !== undefined ? { scope: bgScope } : {}) })?.status === "running";
2816
2822
  const failedFork = !okBg && !reapedBg;
2817
2823
  const errCodeFork = failedFork ? childFace.errorCode : undefined;
2818
2824
  const errClassFork = failedFork ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
2819
- const settleWinnerFork = bg.registry.settleBackgroundAgent(taskId, {
2825
+ const settleWinnerFork = bgRegistry.settleBackgroundAgent(taskId, {
2820
2826
  cycle: 0,
2821
2827
  status: okBg ? "completed" : reapedBg ? "killed" : "failed",
2822
2828
  ...resultSettleFields(forkBgResult),
@@ -2824,12 +2830,12 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2824
2830
  ...(errCodeFork !== undefined ? { errorCode: errCodeFork } : {}),
2825
2831
  ...(errClassFork !== undefined ? { retryable: errClassFork.retryable, errorKind: errClassFork.errorKind } : {}),
2826
2832
  });
2827
- const completionIdFork = settleWinnerFork !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
2833
+ const completionIdFork = settleWinnerFork !== undefined ? bgRegistry.getCompletionId(taskId) : undefined;
2828
2834
  const settledBg = settleWinnerFork ?? (abort.signal.aborted ? "killed" : okBg ? "completed" : "failed");
2829
- const stoppedByBg = settledBg === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
2835
+ const stoppedByBg = settledBg === "killed" ? bgRegistry.getStopAttribution(taskId) ?? "system" : undefined;
2830
2836
  const stillbornFork = child.terminal.kind === "failed" && child.terminal.code === "resume.session_not_found";
2831
2837
  if (stillbornFork) {
2832
- await releaseBoundChildSession({ registry: bg.registry, taskId }, forkedId, () => (releaseForked ? releaseForked() : opts.runner.sessions.release?.(forkedId)));
2838
+ await releaseBoundChildSession({ registry: bgRegistry, taskId }, forkedId, () => (releaseForked ? releaseForked() : opts.runner.sessions.release?.(forkedId)));
2833
2839
  }
2834
2840
  const residualFork = residualFields();
2835
2841
  const resumableFork = false;
@@ -2839,8 +2845,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2839
2845
  const forkTerminalSummary = failReasonFork !== undefined
2840
2846
  ? `Agent "${shortDesc}" failed: ${failReasonFork}${ccElapsedTag(forkElapsedMs)}`.slice(0, 300) + errorKindClause(errClassFork)
2841
2847
  : `${ccCompletionText(shortDesc, settledBg, childFace.status, forkElapsedMs)}`;
2842
- const ownsTerminalFacesFork = bg.registry.claimAgentTerminalNotify(taskId);
2843
- const forkResultField = await completionResultField(forkBgResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdFork), notifier);
2848
+ const ownsTerminalFacesFork = bgRegistry.claimAgentTerminalNotify(taskId);
2849
+ const forkResultField = await completionResultField(forkBgResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bgRegistry.recordArtifactRef(taskId, ref, completionIdFork), notifier);
2844
2850
  const forkFrame = {
2845
2851
  task_id: taskId,
2846
2852
  task_type: "background_agent",
@@ -2877,18 +2883,18 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
2877
2883
  const msgFork = childThrownText(e);
2878
2884
  const errCodeForkReject = killed ? undefined : thrownErrorCode(e);
2879
2885
  const errClassForkReject = killed ? undefined : classifySubagentError({ kind: "failed", ...(errCodeForkReject !== undefined ? { code: errCodeForkReject } : {}) });
2880
- const settleWinnerForkReject = bg.registry.settleBackgroundAgent(taskId, {
2886
+ const settleWinnerForkReject = bgRegistry.settleBackgroundAgent(taskId, {
2881
2887
  cycle: 0,
2882
2888
  status: killed ? "killed" : "failed",
2883
2889
  error: killed ? BG_AGENT_REAP_STOP_ERROR : msgFork,
2884
2890
  ...(errCodeForkReject !== undefined ? { errorCode: errCodeForkReject } : {}),
2885
2891
  ...(errClassForkReject !== undefined ? { retryable: errClassForkReject.retryable, errorKind: errClassForkReject.errorKind } : {}),
2886
2892
  });
2887
- const completionIdForkReject = settleWinnerForkReject !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
2893
+ const completionIdForkReject = settleWinnerForkReject !== undefined ? bgRegistry.getCompletionId(taskId) : undefined;
2888
2894
  const settledBg = settleWinnerForkReject ?? (killed ? "killed" : "failed");
2889
- const stoppedByBg = settledBg === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
2895
+ const stoppedByBg = settledBg === "killed" ? bgRegistry.getStopAttribution(taskId) ?? "system" : undefined;
2890
2896
  const summaryBg = `${shortDesc} — ${settledBg === "failed" ? `failed: ${msgFork}` : settledBg}`.slice(0, 300) + (settledBg === "failed" ? errorKindClause(errClassForkReject) : "");
2891
- const ownsTerminalFacesForkReject = bg.registry.claimAgentTerminalNotify(taskId);
2897
+ const ownsTerminalFacesForkReject = bgRegistry.claimAgentTerminalNotify(taskId);
2892
2898
  const forkRejectFrame = {
2893
2899
  task_id: taskId,
2894
2900
  task_type: "background_agent",
@@ -3036,7 +3042,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3036
3042
  };
3037
3043
  }
3038
3044
  if (wantsBackground) {
3039
- const bg = opts.background;
3045
+ const bg = background, bgRegistry = backgroundRegistry;
3040
3046
  if (ctx.checkpointStoreForChildren !== undefined && ctx.checkpointStoreForChildren !== "disabled" && bg.checkpointStore !== undefined && bg.checkpointStore !== ctx.checkpointStoreForChildren)
3041
3047
  throw configError("background.checkpointStore is not the store this run's children park in (the host's resolved checkpoint seat, TaskSpec/RunnerDeps.checkpointStore) — wire the one store, or leave the option unset and let the seat ride.", "config.invalid_checkpoint_store");
3042
3048
  const childParkStore = ctx.checkpointStoreForChildren === undefined ? bg.checkpointStore : ctx.checkpointStoreForChildren === "disabled" ? undefined : ctx.checkpointStoreForChildren;
@@ -3118,7 +3124,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3118
3124
  }
3119
3125
  if (settled && verdict === "external") {
3120
3126
  try {
3121
- await replayExternalSettlementEffects(settlementSeat.governance, settlementSeat.controlDir, { carry: true, now: Date.now });
3127
+ await replayExternalSettlementEffects(settlementSeat.governance, { carry: true, now: Date.now });
3122
3128
  }
3123
3129
  catch {
3124
3130
  }
@@ -3130,7 +3136,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3130
3136
  };
3131
3137
  let taskId;
3132
3138
  try {
3133
- taskId = bg.registry.registerBackgroundAgent(reviveRow !== undefined
3139
+ taskId = bgRegistry.registerBackgroundAgent(reviveRow !== undefined
3134
3140
  ? {
3135
3141
  id: reviveRow.handle,
3136
3142
  owner: reviveRow.owner,
@@ -3177,6 +3183,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3177
3183
  ...(ctx.taskId !== undefined && ctx.taskId !== ctx.sessionId ? { parentTaskId: ctx.taskId } : {}),
3178
3184
  ...(ctx.sessionId !== undefined ? { parentSessionId: ctx.sessionId } : {}),
3179
3185
  ...((ctx.rootSessionId ?? ctx.sessionId) !== undefined ? { rootSessionId: ctx.rootSessionId ?? ctx.sessionId } : {}),
3186
+ ...(ctx.rootSessionIncarnation !== undefined ? { rootSessionIncarnation: ctx.rootSessionIncarnation } : {}),
3180
3187
  ...(rowModelKey !== undefined ? { model: rowModelKey } : {}),
3181
3188
  deliveryChannel: "attaching",
3182
3189
  toolUseId: ctx.toolCallId,
@@ -3199,7 +3206,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3199
3206
  return notStartedResult({ isError: true, content: `Sub-agent not started in background: the background task could not be registered.${wt ? `\n${wt}` : ""}`, details: { error: "register_failed", ...faultDetails(e) } });
3200
3207
  }
3201
3208
  if (capLedgerKey !== undefined)
3202
- chargeDelegationEntryHandle(bg.registry, capLedgerKey, bg.agentStore, reviveRow === undefined ? taskId : undefined);
3209
+ chargeDelegationEntryHandle(bgRegistry, capLedgerKey, bg.agentStore, reviveRow === undefined ? taskId : undefined);
3203
3210
  if (parkedResume === undefined)
3204
3211
  oweTerminalDelivery(notify, { task_id: taskId, task_type: "background_agent" });
3205
3212
  childInternals.peerSelfRef?.addAxis("h", taskId);
@@ -3217,14 +3224,14 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3217
3224
  const bgChildSessionId = reviveRow?.sessionId ?? uuidv7();
3218
3225
  const bgStartedAt = Date.now();
3219
3226
  stepRecorder.lockTo(taskId);
3220
- bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
3221
- const bgCycleSeq = bg.registry.backgroundAgentCycleSeq(taskId);
3227
+ bgRegistry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
3228
+ const bgCycleSeq = bgRegistry.backgroundAgentCycleSeq(taskId);
3222
3229
  let retainedCycle;
3223
3230
  const cycleSeqOfFrames = () => retainedCycle?.cycleSeq ?? (parkedResume !== undefined ? (reviveRow?.seq ?? 1) + 1 : reviveRow?.seq);
3224
- bg.registry.attachAgentTerminalNotifier(taskId, (ending) => {
3225
- const stoppedByLanded = ending.status === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
3226
- const completionIdLanded = bg.registry.getCompletionId(taskId);
3227
- const seqLanded = bg.registry.backgroundAgentCycleSeq(taskId);
3231
+ bgRegistry.attachAgentTerminalNotifier(taskId, (ending) => {
3232
+ const stoppedByLanded = ending.status === "killed" ? bgRegistry.getStopAttribution(taskId) ?? "system" : undefined;
3233
+ const completionIdLanded = bgRegistry.getCompletionId(taskId);
3234
+ const seqLanded = bgRegistry.backgroundAgentCycleSeq(taskId);
3228
3235
  const landedElapsedMs = Date.now() - bgStartedAt;
3229
3236
  const landedFrame = {
3230
3237
  task_id: taskId,
@@ -3244,7 +3251,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3244
3251
  const landedLane = ending.parkLane ?? cycleSink;
3245
3252
  notifier.notify(() => landedLane?.(landedFrame, { priority: "next" }), "subagent.landedTerminalNotify");
3246
3253
  });
3247
- const bgDurableProbe = bg.registry.durableAgentRowProbe(taskId);
3254
+ const bgDurableProbe = bgRegistry.durableAgentRowProbe(taskId);
3248
3255
  const bgRowConfirmed = async () => (bgDurableProbe ? await bgDurableProbe().catch(() => false) : false);
3249
3256
  sinkEmit({
3250
3257
  kind: "spawn",
@@ -3281,18 +3288,18 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3281
3288
  : undefined
3282
3289
  : ctx.subagentRetain;
3283
3290
  if (sessionScopedBg && bgRetainLedger)
3284
- ensureSessionReapHook(bg.registry);
3285
- const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bg.registry, taskId }, backgroundLegFacts(taskId));
3291
+ ensureSessionReapHook(bgRegistry);
3292
+ const bgRetain = await tryRetainChild(bgRetainLedger, sessionScopedBg && ctx.subagentRetain ? ctx.subagentRetain.ttlMs : undefined, bgChildSessionId, bgDurableProbe, { registry: bgRegistry, taskId }, backgroundLegFacts(taskId));
3286
3293
  retainedCycle = bgRetain;
3287
3294
  if (bgRetain) {
3288
- bg.registry.markRetainedContinuation(taskId);
3295
+ bgRegistry.markRetainedContinuation(taskId);
3289
3296
  const origRelease = bgRetain.release;
3290
3297
  bgRetain.release = async () => {
3291
- bg.registry.unmarkRetainedContinuation(taskId);
3298
+ bgRegistry.unmarkRetainedContinuation(taskId);
3292
3299
  await origRelease();
3293
3300
  };
3294
3301
  }
3295
- bg.registry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
3302
+ bgRegistry.bindBackgroundAgentSession(taskId, bgChildSessionId, opts.runner.sessions);
3296
3303
  const forwardDurableApproval = ctx.durableApprovalForChildren !== undefined &&
3297
3304
  bg.agentStore !== undefined &&
3298
3305
  childParkStore !== undefined &&
@@ -3308,12 +3315,12 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3308
3315
  let reviveAttachedResolve;
3309
3316
  const reviveAttached = reviveRow !== undefined ? new Promise((r) => (reviveAttachedResolve = r)) : undefined;
3310
3317
  const s2NotifyReady = (inject) => {
3311
- bg.registry.attachAgentNotify(taskId, inject);
3318
+ bgRegistry.attachAgentNotify(taskId, inject);
3312
3319
  if (parkedResume !== undefined)
3313
- bg.registry.finalizeParkedResume(taskId);
3320
+ bgRegistry.finalizeParkedResume(taskId);
3314
3321
  const legOrgVerdict = childInternals.ownOrgAdmissionRef?.current;
3315
3322
  if (legOrgVerdict !== undefined)
3316
- bg.registry.recordBackgroundAgentOrgAdmission(taskId, legOrgVerdict);
3323
+ bgRegistry.recordBackgroundAgentOrgAdmission(taskId, legOrgVerdict);
3317
3324
  reviveAttachedResolve?.();
3318
3325
  };
3319
3326
  const bgActivityBeat = createBgActivityBeat(ctx.toolCallId, (toolStarts) => {
@@ -3334,7 +3341,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3334
3341
  ...(currentTool !== undefined ? { currentTool } : {}),
3335
3342
  usage: { toolUses: toolStarts },
3336
3343
  });
3337
- }, () => bg.registry.noteBackgroundAgentActivity(taskId));
3344
+ }, () => bgRegistry.noteBackgroundAgentActivity(taskId));
3338
3345
  const bgPlacement = placedTreeOwner !== undefined
3339
3346
  ? { ...subagentTranscriptPlacement(ctx, bgScope, taskId), owner: placedTreeOwner }
3340
3347
  : undefined;
@@ -3397,7 +3404,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3397
3404
  const rollbackAndThrow = async (e) => {
3398
3405
  let disp = "retry";
3399
3406
  try {
3400
- disp = await bg.registry.rollbackParkedClaim(claimStores, pr.ticket);
3407
+ disp = await bgRegistry.rollbackParkedClaim(claimStores, pr.ticket);
3401
3408
  }
3402
3409
  catch {
3403
3410
  }
@@ -3458,7 +3465,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3458
3465
  }
3459
3466
  }
3460
3467
  const afterCheckpointResolve = async () => {
3461
- const won = await bg.registry.consumeParkedFlip(taskId, { agentStore: bg.agentStore }, pr.ticket);
3468
+ const won = await bgRegistry.consumeParkedFlip(taskId, { agentStore: bg.agentStore }, pr.ticket);
3462
3469
  if (!won)
3463
3470
  throw new Error("the parked row moved under the resume (a stop or another transition won) — resume aborted");
3464
3471
  moveTerminalDelivery(parkedLane, notify, { task_id: taskId, task_type: "background_agent" });
@@ -3517,7 +3524,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3517
3524
  reopened = false;
3518
3525
  }
3519
3526
  if (reopened) {
3520
- const reParked = bg.registry.parkBackgroundAgent(taskId, {
3527
+ const reParked = bgRegistry.parkBackgroundAgent(taskId, {
3521
3528
  checkpointToken: pr.ticket.token,
3522
3529
  completionSink: cycleSink,
3523
3530
  resolveStop: async () => {
@@ -3621,7 +3628,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3621
3628
  attested = false;
3622
3629
  }
3623
3630
  const parked = attested
3624
- ? bg.registry.parkBackgroundAgent(taskId, {
3631
+ ? bgRegistry.parkBackgroundAgent(taskId, {
3625
3632
  checkpointToken: token,
3626
3633
  seq: seqAtSettle ?? 1,
3627
3634
  completionSink: cycleSink,
@@ -3646,7 +3653,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3646
3653
  }
3647
3654
  const ok = child.terminal.kind === "completed";
3648
3655
  const reaped = !ok && abort.signal.aborted;
3649
- const collateral = reaped && bg.registry.getAccessibleTask(taskId, { ...(bgOwner !== undefined ? { owner: bgOwner } : {}), ...(bgScope !== undefined ? { scope: bgScope } : {}) })?.status === "running";
3656
+ const collateral = reaped && bgRegistry.getAccessibleTask(taskId, { ...(bgOwner !== undefined ? { owner: bgOwner } : {}), ...(bgScope !== undefined ? { scope: bgScope } : {}) })?.status === "running";
3650
3657
  const failedBg = !ok && !reaped;
3651
3658
  const unparkedPauseReason = unparkedPause !== undefined && failedBg ? unparkedDurablePauseReason(unparkedPause) : undefined;
3652
3659
  const errCodeBg = failedBg
@@ -3659,7 +3666,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3659
3666
  : childFace.errorCode
3660
3667
  : undefined;
3661
3668
  const errClassBg = failedBg ? classifySubagentError({ kind: "failed", ...(childFace.errorCode !== undefined ? { code: childFace.errorCode } : {}) }) : undefined;
3662
- const settleWinnerBg = bg.registry.settleBackgroundAgent(taskId, {
3669
+ const settleWinnerBg = bgRegistry.settleBackgroundAgent(taskId, {
3663
3670
  cycle: 0,
3664
3671
  status: ok ? "completed" : reaped ? "killed" : "failed",
3665
3672
  seq: seqAtSettle ?? 1,
@@ -3669,13 +3676,13 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3669
3676
  ...(errClassBg !== undefined ? { retryable: errClassBg.retryable, errorKind: errClassBg.errorKind } : {}),
3670
3677
  ...(failedBg && child.retryAfterMs !== undefined ? { retryAfterMs: child.retryAfterMs } : {}),
3671
3678
  });
3672
- const completionIdBg = settleWinnerBg !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
3679
+ const completionIdBg = settleWinnerBg !== undefined ? bgRegistry.getCompletionId(taskId) : undefined;
3673
3680
  const settled = settleWinnerBg ??
3674
3681
  (abort.signal.aborted ? "killed" : ok ? "completed" : "failed");
3675
3682
  if (!bgRetain && reviveRow === undefined && !(await bgRowConfirmed())) {
3676
- await releaseBoundChildSession({ registry: bg.registry, taskId }, child.sessionId, () => opts.runner.sessions.release(child.sessionId));
3683
+ await releaseBoundChildSession({ registry: bgRegistry, taskId }, child.sessionId, () => opts.runner.sessions.release(child.sessionId));
3677
3684
  }
3678
- const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
3685
+ const stoppedBy = settled === "killed" ? bgRegistry.getStopAttribution(taskId) ?? "system" : undefined;
3679
3686
  const observerNote = observerNoteFor(await startBoundedObserverDrain());
3680
3687
  const residual = residualFields();
3681
3688
  const bgDurableRow = await bgRowConfirmed();
@@ -3693,8 +3700,8 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3693
3700
  ? `Agent "${shortDesc}" failed: ${failReasonBg}${ccElapsedTag(bgElapsedMs)}${observerNote}`.slice(0, 300) + errorKindClause(errClassBg)
3694
3701
  : `${ccCompletionText(shortDesc, settled, childFace.status, bgElapsedMs)}${observerNote}`;
3695
3702
  const completionSink = cycleSink;
3696
- const ownsTerminalFaces = completionSink !== undefined && bg.registry.claimAgentTerminalNotify(taskId);
3697
- const bgResultField = await completionResultField(bgHandbackResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bg.registry.recordArtifactRef(taskId, ref, completionIdBg), notifier);
3703
+ const ownsTerminalFaces = completionSink !== undefined && bgRegistry.claimAgentTerminalNotify(taskId);
3704
+ const bgResultField = await completionResultField(bgHandbackResult, (report) => persistTaskArtifact(ctx.taskArtifacts, taskId, report), (ref) => bgRegistry.recordArtifactRef(taskId, ref, completionIdBg), notifier);
3698
3705
  const completionFrame = {
3699
3706
  task_id: taskId,
3700
3707
  task_type: "background_agent",
@@ -3718,10 +3725,10 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3718
3725
  if (ownsTerminalFaces)
3719
3726
  sinkEmit(backgroundChildTerminal(completionFrame, { taskId, sessionScoped: sessionScopedBg === true, ...(child.sessionId ? { sessionId: child.sessionId, transcriptId: child.sessionId } : {}), parentToolCallId: ctx.toolCallId, ...(bgCycleSeq !== undefined ? { generation: bgCycleSeq } : {}) }));
3720
3727
  const gateOwners = ownsTerminalFaces && settled === "completed" && bgRetain !== undefined ? childOwnerKeys(child.taskId, bgRetain.childSessionId) : [];
3721
- const aliveBgCount = runningBackgroundUnder(bg.registry, gateOwners);
3728
+ const aliveBgCount = runningBackgroundUnder(bgRegistry, gateOwners);
3722
3729
  if (bgRetain !== undefined && aliveBgCount > 0) {
3723
3730
  parkCompletionNotify({
3724
- registry: bg.registry,
3731
+ registry: bgRegistry,
3725
3732
  entry: bgRetain,
3726
3733
  owners: gateOwners,
3727
3734
  pendingCount: aliveBgCount,
@@ -3754,7 +3761,7 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3754
3761
  const msg = childThrownText(e);
3755
3762
  const errCodeBgReject = killed ? undefined : thrownErrorCode(e);
3756
3763
  const errClassBgReject = killed ? undefined : classifySubagentError({ kind: "failed", ...(errCodeBgReject !== undefined ? { code: errCodeBgReject } : {}) });
3757
- const settleWinnerBgReject = bg.registry.settleBackgroundAgent(taskId, {
3764
+ const settleWinnerBgReject = bgRegistry.settleBackgroundAgent(taskId, {
3758
3765
  cycle: 0,
3759
3766
  status: killed ? "killed" : "failed",
3760
3767
  error: msg,
@@ -3762,15 +3769,15 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3762
3769
  ...(errCodeBgReject !== undefined ? { errorCode: errCodeBgReject } : {}),
3763
3770
  ...(errClassBgReject !== undefined ? { retryable: errClassBgReject.retryable, errorKind: errClassBgReject.errorKind } : {}),
3764
3771
  });
3765
- const completionIdBgReject = settleWinnerBgReject !== undefined ? bg.registry.getCompletionId(taskId) : undefined;
3772
+ const completionIdBgReject = settleWinnerBgReject !== undefined ? bgRegistry.getCompletionId(taskId) : undefined;
3766
3773
  const settled = settleWinnerBgReject ?? (killed ? "killed" : "failed");
3767
3774
  if (!bgRetain && reviveRow === undefined && !(await bgRowConfirmed())) {
3768
- await releaseBoundChildSession({ registry: bg.registry, taskId }, bgChildSessionId, () => opts.runner.sessions.release(bgChildSessionId));
3775
+ await releaseBoundChildSession({ registry: bgRegistry, taskId }, bgChildSessionId, () => opts.runner.sessions.release(bgChildSessionId));
3769
3776
  }
3770
- const stoppedBy = settled === "killed" ? bg.registry.getStopAttribution(taskId) ?? "system" : undefined;
3777
+ const stoppedBy = settled === "killed" ? bgRegistry.getStopAttribution(taskId) ?? "system" : undefined;
3771
3778
  const observerNote = observerNoteFor(await startBoundedObserverDrain());
3772
3779
  const rejectSink = cycleSink;
3773
- const ownsTerminalFacesReject = rejectSink !== undefined && bg.registry.claimAgentTerminalNotify(taskId);
3780
+ const ownsTerminalFacesReject = rejectSink !== undefined && bgRegistry.claimAgentTerminalNotify(taskId);
3774
3781
  const rejectFrame = {
3775
3782
  task_id: taskId,
3776
3783
  task_type: "background_agent",
@@ -3867,9 +3874,9 @@ function createSubagentToolNode(opts, depth, excluded, extraToolsBudget) {
3867
3874
  ledger: ctx.subagentRetain,
3868
3875
  parentToolCallId: ctx.toolCallId,
3869
3876
  runner: opts.runner,
3870
- ...(opts.background?.notify ? { notify: opts.background.notify } : {}),
3877
+ ...(background?.notify ? { notify: background.notify } : {}),
3871
3878
  sink: ctx.onSubagentSpawn,
3872
- ...(opts.background ? { registry: opts.background.registry } : {}),
3879
+ ...(backgroundRegistry ? { registry: backgroundRegistry } : {}),
3873
3880
  entryGate: syncEntryGate,
3874
3881
  ...(opts.onObserverError !== undefined ? { onNotifyError: (f) => opts.onObserverError?.(f.error, { site: f.site }) } : {}),
3875
3882
  ...(ctx.onQuestion !== undefined ? { currentOnQuestion: ctx.onQuestion } : {}),
@@ -14,6 +14,8 @@ import type { ThinkingLevel } from "../internal/harness-types.js";
14
14
  * later config-domain slice (design/96 S6); here it is a pure, tested mapping.
15
15
  */
16
16
  export type ReasoningIntensity = ThinkingLevel;
17
+ /** The seven tiers in rank order, read off the one rank table — for a sentence that names the closed set. */
18
+ export declare const THINKING_LEVELS: readonly ThinkingLevel[];
17
19
  /** Type guard: is `v` one of the 7 {@link ThinkingLevel} tiers? (A legacy/unknown reasoning string is not.) */
18
20
  export declare function isThinkingLevel(v: unknown): v is ThinkingLevel;
19
21
  /**
@@ -8,6 +8,7 @@ const RANK = {
8
8
  xhigh: 5,
9
9
  max: 6,
10
10
  };
11
+ export const THINKING_LEVELS = Object.freeze(Object.keys(RANK));
11
12
  export function isThinkingLevel(v) {
12
13
  return typeof v === "string" && Object.prototype.hasOwnProperty.call(RANK, v);
13
14
  }
@@ -49,6 +49,15 @@ export type AllowEntryInert = {
49
49
  readonly entry: string;
50
50
  readonly reason: AllowEntryInertReason;
51
51
  } & AllowEntryInertDetail;
52
+ /**
53
+ * Does the reader read this entry as a tool the engine retired with NO successor (`removed` / `folded`: no `currentName`)? Such a name reaches no
54
+ * tool in any roster, now or later, and never did anything a rewrite could restore — so a RESTRICTING list (a task's tool-name list, a skill's
55
+ * `disallowed-tools`) leaves it out and says so in the retired-name notice instead of refusing; a name that was RENAMED has a successor, the
56
+ * entry guarded a tool that is still mounted, and stays refused. So does a name whose tool the roster carries under ANOTHER CASE (`TEAMCREATE`
57
+ * beside `TeamCreate`: the entry was written for that tool — the policy audit asks the same question): `roster` is the one the reader read
58
+ * the entry against; absent, no tool is known to be mounted. The one question the engine's tables put to the one reader's answer.
59
+ */
60
+ export declare function isRetiredLeftOut(e: Pick<AllowEntryInert, "entry" | "reason" | "verdict" | "currentName">, roster: ReadonlySet<string> | undefined): boolean;
52
61
  /** One entry the grammar reads (kind closed): a whole non-shell tool; a covering spelling — a set of tool names
53
62
  * ({@link isCoveringRuleName}: a protocol peer, a glob over a protocol name's tool segment, and on a deny list a `*` anywhere in
54
63
  * the name, `*` alone every tool); the whole shell tool; and one kind per rule grammar (`ruleToolGrammarOf`) — a shell command
@@ -2,7 +2,7 @@ import { heldBy, wireOf } from "./tool-name-readings.js";
2
2
  import { ruleIssue } from "./permission-rules.js";
3
3
  import { isCoveringRuleName, ruleNameCovers } from "./namespaced-rule-name.js";
4
4
  import { ruleSpellingOf } from "./permission-rule-syntax.js";
5
- import { splitNamespacedName, toolNameFaultOf } from "./tool-name-aliases.js";
5
+ import { nearMissSpellingOf, splitNamespacedName, toolNameFaultOf } from "./tool-name-aliases.js";
6
6
  import { catalogToolNames, isShellFaceToolName } from "./tool-registry.js";
7
7
  import { ALLOW_RULE_MEMBERS } from "./allow-rule-shadow.js";
8
8
  import { callHostTargetOf } from "./host-target.js";
@@ -24,6 +24,12 @@ export function nonStringMemberLabel(value) {
24
24
  export function nonListValueLabel(read) {
25
25
  return read.kind === "not_a_list" ? `<not a list: ${read.type}>` : "<a list whose entries cannot be read>";
26
26
  }
27
+ export function isRetiredLeftOut(e, roster) {
28
+ if (e.reason !== "tool_name" || e.verdict !== "retired" || e.currentName !== undefined)
29
+ return false;
30
+ const name = ruleSpellingOf(e.entry)?.toolName;
31
+ return name === undefined || roster === undefined || nearMissSpellingOf(name, roster) === undefined;
32
+ }
27
33
  function ruleRowOf(parsed) {
28
34
  return { ...parsed, scope: { kind: "global" }, adds: [{ dot: { actor: "list", counter: 1 }, origin: "user", createdAt: "" }] };
29
35
  }
@@ -956,9 +956,29 @@ export declare function foldArbitrationRow(classes: ReadonlySet<AskClass>, readF
956
956
  export declare function classifyAsk(d: Extract<PermissionResult, {
957
957
  action: "ask";
958
958
  }>, facts: AskClassFacts): AskClassification;
959
- /** The refusal the model reads when an ask reaches a run with no approver: the reference implementation's sentence
960
- * the call did NOT run because this session has no approval surface — with the run's own fact beside it
961
- * and the ask's prompt as what was requested. The gate appends the caller-side remedy. */
959
+ /** The two causes whose refusal sentence is minted by {@link unresolvedAskDenialMessage}: nobody could be asked because no approver is
960
+ * wired, or because the wired one answered `unavailable` for this ask. */
961
+ export type UnresolvedAskCause = "no_approver_wired" | "approver_unavailable";
962
+ /**
963
+ * The base sentence of a refusal for an ask nobody could answer — the one mint for both causes, in the two forms the park state allows.
964
+ * `parkFailed` is whether a durable park was ATTEMPTED for this call and could not be minted; the park-failure note the gate's deny exit
965
+ * appends ({@link import("./runner/gate-exit.js")}) is then the only sentence that speaks about the park, so a clause that depends on the
966
+ * park state is in exactly one form of the base: "do not retry it in this session" and "no durable approval gate is armed" belong to a run
967
+ * with no park attempt, "it can be issued again once its park can be minted" to a park that failed, and no refusal says both.
968
+ * · `no_approver_wired` — the reference implementation's sentence: the call did NOT run because this session has no approval surface,
969
+ * with the run's own fact beside it and the ask's prompt as what was requested. The gate appends the caller-side remedy.
970
+ * · `approver_unavailable` — the approver affirmed that nobody is reachable for this ask; with no park attempt this is the fail-closed
971
+ * fallback that stands.
972
+ */
973
+ export declare function unresolvedAskDenialMessage(cause: UnresolvedAskCause, toolName: string, question: string, parkFailed: boolean): string;
974
+ /**
975
+ * The question a refusal minted by {@link unresolvedAskDenialMessage} (no park attempt) quotes — its tail after the fixed stem — or
976
+ * `undefined` when `text` is not that refusal (a binding's sentence, a hook's, a fold's own): the deny exit re-words a base sentence only
977
+ * when it is the one this module minted, over the very question the resolver quoted (a card's allow-rule note included).
978
+ */
979
+ export declare function unresolvedAskQuestionOf(cause: UnresolvedAskCause, toolName: string, text: string): string | undefined;
980
+ /** The refusal the model reads when an ask reaches a run with no approver (no park attempt): {@link unresolvedAskDenialMessage}'s
981
+ * `no_approver_wired` form. */
962
982
  export declare function headlessDenialMessage(toolName: string, askMessage: string): string;
963
983
  /**
964
984
  * The refusal the model reads when the `dontAsk` permission mode refuses an ask (`deniedBy: "mode"`): the reference implementation's