@sema-agent/core 7.63.0 → 7.64.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 (204) hide show
  1. package/CHANGELOG.md +408 -0
  2. package/dist/agents/cc-peer-directory.js +1 -0
  3. package/dist/agents/cc-peer-wire.d.ts +4 -0
  4. package/dist/agents/cc-peer-wire.js +1 -0
  5. package/dist/agents/cc-uds-peer-channel.js +5 -0
  6. package/dist/agents/cross-session-judge.d.ts +3 -1
  7. package/dist/agents/cross-session-judge.js +4 -1
  8. package/dist/agents/peer-directory.d.ts +8 -0
  9. package/dist/agents/peer-directory.js +4 -0
  10. package/dist/agents/peer-held-queue.d.ts +9 -3
  11. package/dist/agents/peer-held-queue.js +12 -9
  12. package/dist/agents/peer-idle.d.ts +20 -1
  13. package/dist/agents/peer-idle.js +23 -12
  14. package/dist/agents/peer-notice-route.d.ts +16 -5
  15. package/dist/agents/peer-notice-route.js +11 -9
  16. package/dist/agents/peer-notices.d.ts +25 -8
  17. package/dist/agents/peer-notices.js +6 -1
  18. package/dist/agents/peer-session-drain.d.ts +32 -6
  19. package/dist/agents/peer-session-drain.js +100 -26
  20. package/dist/agents/send-message-tool.d.ts +7 -0
  21. package/dist/agents/send-message-tool.js +18 -6
  22. package/dist/agents/subagent.js +20 -3
  23. package/dist/core/allow-entry.d.ts +4 -0
  24. package/dist/core/ask-origin.d.ts +1 -1
  25. package/dist/core/ask-origin.js +2 -2
  26. package/dist/core/ask-unresolvable-notice.d.ts +13 -4
  27. package/dist/core/ask-unresolvable-notice.js +10 -3
  28. package/dist/core/auto-compaction.d.ts +7 -5
  29. package/dist/core/background-agent-store.d.ts +7 -0
  30. package/dist/core/background-agent-store.js +3 -0
  31. package/dist/core/checkpoint-queries.d.ts +9 -6
  32. package/dist/core/checkpoint-queries.js +8 -3
  33. package/dist/core/checkpoint-store.d.ts +5 -1
  34. package/dist/core/context-settings.d.ts +40 -9
  35. package/dist/core/context-settings.js +32 -10
  36. package/dist/core/engine-attestation.d.ts +26 -6
  37. package/dist/core/engine-attestation.js +5 -1
  38. package/dist/core/engine-notice.d.ts +24 -1
  39. package/dist/core/extension-requester.d.ts +9 -0
  40. package/dist/core/extension-requester.js +7 -0
  41. package/dist/core/file-history-store.d.ts +28 -0
  42. package/dist/core/file-history-store.js +48 -5
  43. package/dist/core/fs-write-gate-policy.js +1 -1
  44. package/dist/core/gate-fold.js +2 -0
  45. package/dist/core/gate-lanes.js +2 -0
  46. package/dist/core/gate-outcome.d.ts +39 -2
  47. package/dist/core/gate-outcome.js +20 -1
  48. package/dist/core/governance-codes.d.ts +3 -1
  49. package/dist/core/governance-codes.js +4 -0
  50. package/dist/core/leg-identity.d.ts +19 -1
  51. package/dist/core/leg-identity.js +12 -0
  52. package/dist/core/mailbox-store.d.ts +39 -4
  53. package/dist/core/mailbox-store.js +14 -2
  54. package/dist/core/memory-engine/consolidation.d.ts +3 -2
  55. package/dist/core/memory-engine/consolidation.js +16 -0
  56. package/dist/core/memory-engine/control-objects.d.ts +25 -0
  57. package/dist/core/memory-engine/control-objects.js +151 -0
  58. package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
  59. package/dist/core/memory-engine/control-plane-adoption.js +159 -0
  60. package/dist/core/memory-engine/delegation-settlement.d.ts +21 -5
  61. package/dist/core/memory-engine/delegation-settlement.js +217 -26
  62. package/dist/core/memory-engine/dual-root.js +2 -2
  63. package/dist/core/memory-engine/engine.d.ts +38 -23
  64. package/dist/core/memory-engine/engine.js +14 -14
  65. package/dist/core/memory-engine/file-backend.d.ts +41 -65
  66. package/dist/core/memory-engine/file-backend.js +59 -166
  67. package/dist/core/memory-engine/index.d.ts +3 -2
  68. package/dist/core/memory-engine/index.js +2 -1
  69. package/dist/core/memory-engine/layout.d.ts +6 -1
  70. package/dist/core/memory-engine/layout.js +12 -7
  71. package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
  72. package/dist/core/memory-engine/memory-backend-contract.js +158 -2
  73. package/dist/core/memory-engine/memory-deployment.d.ts +11 -3
  74. package/dist/core/memory-engine/memory-deployment.js +31 -6
  75. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  76. package/dist/core/memory-engine/origin-clearance.js +68 -9
  77. package/dist/core/memory-engine/session-write-home.d.ts +34 -1
  78. package/dist/core/memory-engine/session-write-home.js +37 -10
  79. package/dist/core/memory-engine/types.d.ts +44 -7
  80. package/dist/core/memory-engine/types.js +2 -1
  81. package/dist/core/mode-policy.js +3 -3
  82. package/dist/core/mods/agent-stations.d.ts +18 -0
  83. package/dist/core/mods/agent-stations.js +8 -6
  84. package/dist/core/mods/extension-call.d.ts +4 -0
  85. package/dist/core/mods/extension-call.js +8 -0
  86. package/dist/core/mods/tool-call.js +3 -4
  87. package/dist/core/parent-spec-seat.d.ts +2 -2
  88. package/dist/core/peer-channel.d.ts +5 -0
  89. package/dist/core/permission-rule-consent.d.ts +21 -10
  90. package/dist/core/permission-rule-consent.js +50 -23
  91. package/dist/core/permission-rule-store.d.ts +41 -16
  92. package/dist/core/permission-rule-store.js +2 -0
  93. package/dist/core/refusal-echo.d.ts +20 -0
  94. package/dist/core/refusal-echo.js +33 -0
  95. package/dist/core/retention.d.ts +180 -10
  96. package/dist/core/retention.js +45 -0
  97. package/dist/core/retired-keys.d.ts +5 -0
  98. package/dist/core/retired-keys.js +3 -0
  99. package/dist/core/rule-offer-read.d.ts +0 -4
  100. package/dist/core/rule-offer-read.js +2 -18
  101. package/dist/core/runner/classifier-ladder.d.ts +7 -1
  102. package/dist/core/runner/classifier-ladder.js +4 -2
  103. package/dist/core/runner/compact-session.js +10 -7
  104. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  105. package/dist/core/runner/compaction-call-options.js +3 -2
  106. package/dist/core/runner/contracts.d.ts +21 -2
  107. package/dist/core/runner/delegation-owner.d.ts +10 -3
  108. package/dist/core/runner/delegation-owner.js +4 -1
  109. package/dist/core/runner/gate-exit.d.ts +6 -0
  110. package/dist/core/runner/gate-exit.js +11 -2
  111. package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
  112. package/dist/core/runner/memory-consolidation-driver.js +8 -5
  113. package/dist/core/runner/prepare-ask-lane.js +3 -3
  114. package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
  115. package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
  116. package/dist/core/runner/prepare-config-doors.js +4 -0
  117. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  118. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  119. package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
  120. package/dist/core/runner/prepare-gate-stations.js +5 -5
  121. package/dist/core/runner/prepare-hands-readface.js +1 -1
  122. package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
  123. package/dist/core/runner/prepare-inherited-gate.js +4 -2
  124. package/dist/core/runner/prepare-memory.d.ts +4 -0
  125. package/dist/core/runner/prepare-memory.js +14 -20
  126. package/dist/core/runner/prepare-policy-chain.js +7 -7
  127. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  128. package/dist/core/runner/prepare-task.js +15 -10
  129. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  130. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  131. package/dist/core/runner/resume-admission.d.ts +2 -2
  132. package/dist/core/runner/resume-admission.js +2 -23
  133. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  134. package/dist/core/runner/role-resolution-table.js +62 -0
  135. package/dist/core/runner/run-compaction-machinery.js +2 -2
  136. package/dist/core/runner/run-identity-wiring.js +12 -9
  137. package/dist/core/runner/run-leg.js +8 -4
  138. package/dist/core/runner/run-notification-lane.js +22 -22
  139. package/dist/core/runner/run-recovery-lanes.js +3 -3
  140. package/dist/core/runner/run-terminal-adoption.js +1 -1
  141. package/dist/core/runner/run-turn-boundary.js +14 -15
  142. package/dist/core/runner/runtask.js +1 -1
  143. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  144. package/dist/core/runner/tool-occurrence.js +2 -2
  145. package/dist/core/runner-deps.d.ts +1 -1
  146. package/dist/core/session-checkout.d.ts +63 -3
  147. package/dist/core/session-checkout.js +152 -58
  148. package/dist/core/shell-read-silence.js +8 -0
  149. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  150. package/dist/core/task-event.d.ts +9 -5
  151. package/dist/core/task-notification.d.ts +110 -31
  152. package/dist/core/task-notification.js +180 -100
  153. package/dist/core/task-registry-agent.d.ts +11 -0
  154. package/dist/core/task-registry-agent.js +11 -3
  155. package/dist/core/task-registry-shared.d.ts +7 -0
  156. package/dist/core/task-registry.d.ts +18 -0
  157. package/dist/core/task-registry.js +27 -8
  158. package/dist/core/task-spec.d.ts +7 -2
  159. package/dist/core/tool-errors.d.ts +14 -6
  160. package/dist/core/tool-errors.js +1 -1
  161. package/dist/core/tool-policy.d.ts +18 -1
  162. package/dist/core/tool-policy.js +16 -7
  163. package/dist/core/tool-result-store.d.ts +20 -0
  164. package/dist/core/tool-spec.d.ts +4 -0
  165. package/dist/core/trace.d.ts +3 -2
  166. package/dist/core/workflow-journal-store.d.ts +11 -0
  167. package/dist/core/workflow-journal-store.js +7 -0
  168. package/dist/core/workflow-run-store.d.ts +9 -0
  169. package/dist/core/workflow-run-store.js +6 -0
  170. package/dist/engine/compaction/compaction.d.ts +2 -1
  171. package/dist/engine/harness/types.d.ts +1 -0
  172. package/dist/engine/session/session.d.ts +7 -1
  173. package/dist/engine/session/session.js +5 -2
  174. package/dist/index.d.ts +7 -5
  175. package/dist/index.js +7 -5
  176. package/dist/orchestration/run-workflow-tool.d.ts +4 -0
  177. package/dist/orchestration/run-workflow-tool.js +7 -0
  178. package/dist/orchestration/workflow-types.d.ts +2 -1
  179. package/dist/orchestration/workflow.d.ts +3 -0
  180. package/dist/orchestration/workflow.js +2 -1
  181. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  182. package/dist/stores/file/checkpoint-store.js +4 -1
  183. package/dist/stores/file/file-history-store.d.ts +13 -0
  184. package/dist/stores/file/file-history-store.js +75 -13
  185. package/dist/stores/file/index.d.ts +11 -1
  186. package/dist/stores/file/index.js +7 -11
  187. package/dist/stores/file/permission-rule-store.d.ts +23 -0
  188. package/dist/stores/file/permission-rule-store.js +75 -7
  189. package/dist/stores/file/tool-result-store.d.ts +14 -0
  190. package/dist/stores/file/tool-result-store.js +39 -2
  191. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  192. package/dist/stores/file/workflow-journal-store.js +17 -0
  193. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  194. package/dist/stores/file/workflow-run-store.js +15 -0
  195. package/dist/tools/fs/read-deny.d.ts +15 -2
  196. package/dist/tools/fs/read-deny.js +10 -2
  197. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  198. package/dist/tools/fs/shell-read-check.js +7 -7
  199. package/package.json +2 -2
  200. package/test/export-surface.snapshot.json +63 -1
  201. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  202. package/wire-changes/core@7.64.0.json +2653 -0
  203. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  204. package/wire-changes/primitives@7.64.0.json +30 -0
@@ -2,7 +2,7 @@ import { createPeerInboundChainRef, createPeerSelfRef } from "../../agents/peer-
2
2
  import { boundInputHashOf } from "../canonical-json.js";
3
3
  import { readPendingSteerQueue } from "../checkpoint-store.js";
4
4
  import { wakeOpening } from "../run-origin.js";
5
- import { bindDeliveryObligations, createLiveNotificationLane, DeliveryObligations, DurableAppendObligations, injectionLaneOf, isDelegatedAgentTerminal, isTerminalTaskNotification, renderTaskNotificationXml, routeOrParkNotification, SystemInjectionQueue, taskNotificationDedupKey } from "../task-notification.js";
5
+ import { bindDeliveryObligations, createLiveNotificationLane, DeliveryObligations, DurableAppendObligations, injectionLaneOf, isDelegatedAgentTerminal, isTerminalTaskNotification, renderTaskNotificationXml, routeOrParkNotification, sessionAddressOf, SystemInjectionQueue, taskNotificationDedupKey } from "../task-notification.js";
6
6
  import { settleConsumedFrame } from "../frame-settlement.js";
7
7
  import { createReceivingChain } from "../mods/session-receive.js";
8
8
  import { asThrownError } from "../thrown-value.js";
@@ -43,11 +43,11 @@ async function runNotificationLaneAs(input, obligations) {
43
43
  let notificationHarness;
44
44
  let notificationIdent = () => ({});
45
45
  let notificationLaneLive = true;
46
- let notificationSessionId;
46
+ let notificationAddress;
47
47
  let descendantAnchorDisclosed = false;
48
48
  const parkTaskNotification = (payload, priority, onDisposition) => {
49
49
  laneSeat.handOff(payload);
50
- const ownSession = notificationSessionId;
50
+ const ownSession = notificationAddress;
51
51
  if (ownSession !== undefined)
52
52
  routeOrParkNotification(pendingSessionNotifications, ownSession, payload, priority, onDisposition);
53
53
  else
@@ -60,18 +60,18 @@ async function runNotificationLaneAs(input, obligations) {
60
60
  uplink(payload, { priority });
61
61
  }
62
62
  catch (e) {
63
- runner.deps.onError?.(e, { phase: "degraded", sessionId: notificationSessionId ?? "", classification: "descendant-terminal-uplink" });
63
+ runner.deps.onError?.(e, { phase: "degraded", sessionId: notificationAddress?.sessionId ?? "", classification: "descendant-terminal-uplink" });
64
64
  }
65
65
  return;
66
66
  }
67
67
  const rootAnchor = internals?.rootSessionId;
68
- if (rootAnchor !== undefined && rootAnchor !== notificationSessionId) {
69
- routeOrParkNotification(pendingSessionNotifications, rootAnchor, payload, priority);
68
+ if (rootAnchor !== undefined && rootAnchor !== notificationAddress?.sessionId) {
69
+ routeOrParkNotification(pendingSessionNotifications, { sessionId: rootAnchor, occupant: internals?.rootSessionIncarnation }, payload, priority);
70
70
  return;
71
71
  }
72
72
  if (internals?.parentSessionId !== undefined && !descendantAnchorDisclosed) {
73
73
  descendantAnchorDisclosed = true;
74
- runner.deps.onError?.(new Error(`background-agent terminal ${payload.task_id} stayed on this run's own session — the delegation tree's root session is not reachable from this run (no uplink, no root anchor)`), { phase: "degraded", sessionId: notificationSessionId ?? "", classification: "descendant-terminal-unrouted" });
74
+ runner.deps.onError?.(new Error(`background-agent terminal ${payload.task_id} stayed on this run's own session — the delegation tree's root session is not reachable from this run (no uplink, no root anchor)`), { phase: "degraded", sessionId: notificationAddress?.sessionId ?? "", classification: "descendant-terminal-unrouted" });
75
75
  }
76
76
  };
77
77
  const receiving = createReceivingChain(() => prepared.receiveSeat);
@@ -83,7 +83,7 @@ async function runNotificationLaneAs(input, obligations) {
83
83
  settleConsumedFrame(prepared.frameSettlement, taskNotificationDedupKey(item.payload), verdict.by, verdict.reason);
84
84
  item.onDisposition?.("refused");
85
85
  },
86
- fault: (e) => runner.deps.onError?.(asThrownError(e), { phase: "degraded", sessionId: notificationSessionId ?? "", classification: "receive-hand-over" }),
86
+ fault: (e) => runner.deps.onError?.(asThrownError(e), { phase: "degraded", sessionId: notificationAddress?.sessionId ?? "", classification: "receive-hand-over" }),
87
87
  });
88
88
  });
89
89
  function handOver(item, shown) {
@@ -153,31 +153,31 @@ async function runNotificationLaneAs(input, obligations) {
153
153
  sessionModeSeats,
154
154
  onTaskNotification: laneSink,
155
155
  }, self, taskIdRef, holdSessionLock, legWrites);
156
- pendingSessionNotifications.bindSessionBox(prepared.sessionId, prepared.sessionBox);
157
- const settling = pendingSessionNotifications.settleBoxDebts(prepared.sessionId, prepared.abortController.signal);
156
+ pendingSessionNotifications.admit(sessionAddressOf(prepared), prepared.sessionBox);
157
+ const settling = pendingSessionNotifications.settleBoxDebts(sessionAddressOf(prepared), prepared.abortController.signal);
158
158
  if (settling !== undefined)
159
159
  await settling;
160
160
  const notificationLane = {
161
161
  get harness() { return notificationHarness; }, set harness(h) { notificationHarness = h; },
162
- get sessionId() { return notificationSessionId; },
163
- set sessionId(s) {
164
- if (notificationSessionId !== undefined)
165
- pendingSessionNotifications.liveLanes.unregister(notificationSessionId, takeAsDestination);
166
- notificationSessionId = s;
167
- if (s !== undefined && notificationLaneLive)
168
- pendingSessionNotifications.liveLanes.register(s, takeAsDestination);
162
+ get address() { return notificationAddress; },
163
+ set address(a) {
164
+ if (notificationAddress !== undefined)
165
+ pendingSessionNotifications.liveLanes.unregister(notificationAddress, takeAsDestination);
166
+ notificationAddress = a;
167
+ if (a !== undefined && notificationLaneLive)
168
+ pendingSessionNotifications.liveLanes.register(a, takeAsDestination);
169
169
  },
170
170
  get ident() { return notificationIdent; }, set ident(f) { notificationIdent = f; },
171
171
  get live() { return notificationLaneLive; },
172
172
  set live(v) {
173
173
  notificationLaneLive = v;
174
- if (notificationSessionId === undefined)
174
+ if (notificationAddress === undefined)
175
175
  return;
176
176
  if (v) {
177
- pendingSessionNotifications.liveLanes.register(notificationSessionId, takeAsDestination);
177
+ pendingSessionNotifications.liveLanes.register(notificationAddress, takeAsDestination);
178
178
  }
179
179
  else {
180
- pendingSessionNotifications.liveLanes.unregister(notificationSessionId, takeAsDestination);
180
+ pendingSessionNotifications.liveLanes.unregister(notificationAddress, takeAsDestination);
181
181
  laneSeat.release();
182
182
  }
183
183
  },
@@ -186,8 +186,8 @@ async function runNotificationLaneAs(input, obligations) {
186
186
  return await next({ prepared, injectTaskNotification, deliveredAtTurnOpen, peerInboundChainRef, modelCatalog, notificationLane, unsubscribeTaskNotifications, deliveryObligations });
187
187
  }
188
188
  finally {
189
- if (notificationSessionId !== undefined)
190
- pendingSessionNotifications.liveLanes.unregister(notificationSessionId, takeAsDestination);
189
+ if (notificationAddress !== undefined)
190
+ pendingSessionNotifications.liveLanes.unregister(notificationAddress, takeAsDestination);
191
191
  await obligations.settle();
192
192
  }
193
193
  }
@@ -15,7 +15,7 @@ import { asThrownError } from "../thrown-value.js";
15
15
  export function runRecoveryLanes(input) {
16
16
  const { spec, prepared, queue, rs, ident, compactionBrain, compactionBreaker, windowSafetyOptions, callerStop, runner } = input;
17
17
  const runForcedCompactionPass = async (lane, turnSignal) => {
18
- if (!compactionEnabled(spec.compaction?.enabled, legContextOverlayOption(prepared, runner).contextOverlay))
18
+ if (!compactionEnabled("autoCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay))
19
19
  return false;
20
20
  if (compactionBreaker.failures >= MAX_CONSECUTIVE_COMPACTION_FAILURES)
21
21
  return false;
@@ -36,7 +36,7 @@ export function runRecoveryLanes(input) {
36
36
  brain: compactionBrain,
37
37
  getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
38
38
  thinking: prepared.thinking,
39
- settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay),
39
+ settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, "autoCompact"),
40
40
  customInstructions: spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
41
41
  signal: passSignal,
42
42
  manualCancelSignal: callerStop.signal,
@@ -120,7 +120,7 @@ export function runRecoveryLanes(input) {
120
120
  return false;
121
121
  if (prepared.microCompact.clearOnRejection && attempt === 1) {
122
122
  const proj = prepared.microCompact.projectionRef.current;
123
- const compactionAvailable = compactionEnabled(spec.compaction?.enabled, legContextOverlayOption(prepared, runner).contextOverlay) && compactionBreaker.failures < MAX_CONSECUTIVE_COMPACTION_FAILURES;
123
+ const compactionAvailable = compactionEnabled("autoCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay) && compactionBreaker.failures < MAX_CONSECUTIVE_COMPACTION_FAILURES;
124
124
  const declineArm = compactionAvailable ? "forced_compaction" : "none";
125
125
  const plan = proj === undefined
126
126
  ? { declined: "no_candidates" }
@@ -166,7 +166,7 @@ async function finish(spec, prepared, opts, runner, sessions) {
166
166
  brain: opts?.brain ?? runner.deps.brain,
167
167
  getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
168
168
  thinking: prepared.thinking,
169
- settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay),
169
+ settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, "autoCompact"),
170
170
  customInstructions: spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
171
171
  signal: opts.callerStop.signal,
172
172
  manualCancelSignal: opts.callerStop.signal,
@@ -3,6 +3,7 @@ import { mintSystemReminder } from "../reminder-mint.js";
3
3
  import { eventDefaultOn } from "../../prompt-assembly/event-registry.js";
4
4
  import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, manualCompactOutcomeOf, maybeCompact, mintCompactedEvent, nextTrimForceBackoff, recordCompactionAndCheckRapidRefill } from "../auto-compaction.js";
5
5
  import { emitTrace } from "../trace.js";
6
+ import { compactionEnabled } from "../context-settings.js";
6
7
  import { steeringPreview } from "./steering-preview.js";
7
8
  import { ATTACHMENT_BYTE_CAP, CHANGED_FILES_MAX, TOTAL_TOKENS_REMINDER_DEFAULT_MODE, attachmentEnvelopeTags, clipToBytes, collectDateChange, collectDueAttachments, collectInstructionsChange, commitAgentListing, commitInstructionsChange, commitSkillsListing, isIntactSource, rebaseCadenceWindows, renderAgentListingFrame, renderMcpInstructionsDelta, selectMcpDroppedBatch, renderSkillsListingFrame } from "./turn-attachments.js";
8
9
  import { announceListingTruncation } from "../skill-listing-budget.js";
@@ -514,6 +515,11 @@ export function createTurnBoundary(input) {
514
515
  return outcome;
515
516
  };
516
517
  const compactionPass = async (model, call) => {
518
+ if (manualCompactRef.requested && !compactionEnabled("manualCompact", spec.compaction, legContextOverlayOption(prepared, runner).contextOverlay)) {
519
+ emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.disabled", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
520
+ queue.push({ type: "compaction_outcome", outcome: "disabled", trigger: "manual", ...requesterOf(manualCompactRef.waiters), ...ident() });
521
+ drainManualCompact("disabled");
522
+ }
517
523
  const forceManual = manualCompactRef.requested;
518
524
  if ((!withinTaskCompaction() && !forceManual) ||
519
525
  prepared.abortController.signal.aborted ||
@@ -570,7 +576,7 @@ export function createTurnBoundary(input) {
570
576
  const trimPressureArmed = prepared.trimPressureRef.droppedMessages;
571
577
  if (trimPressureArmed)
572
578
  prepared.trimPressureRef.droppedMessages = false;
573
- const trimPressure = trimPressureArmed && !rs.counters.trimForceBackoff;
579
+ const trimPressure = trimPressureArmed && !rs.counters.trimForceBackoff && withinTaskCompaction();
574
580
  const passTrigger = trimPressure ? "forced" : forceManual ? "manual" : "auto";
575
581
  let manualOutcome = "failed";
576
582
  const manualInstructions = claimedManual?.instructions;
@@ -588,7 +594,7 @@ export function createTurnBoundary(input) {
588
594
  brain: compactionBrain,
589
595
  getApiKeyAndHeaders: spec.getApiKeyAndHeaders,
590
596
  thinking: prepared.thinking,
591
- settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay),
597
+ settings: legCompactionSettings(spec, legContextOverlayOption(prepared, runner).contextOverlay, forceManual ? "manualCompact" : "autoCompact"),
592
598
  customInstructions: manualInstructions ?? spec.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
593
599
  signal: compactionPassSignal,
594
600
  manualCancelSignal,
@@ -643,23 +649,16 @@ export function createTurnBoundary(input) {
643
649
  }
644
650
  manualOutcome = manualCompactOutcomeOf(comp);
645
651
  if (forceManual && !comp.compacted && !comp.blocked) {
646
- if (comp.disabled) {
647
- emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.disabled", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
648
- }
649
- else {
650
- emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.noop", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
651
- }
652
+ emitTrace(rs.telemetry.tracer, () => ({ kind: "compaction.noop", version: 1, taskId: rs.telemetry.taskId, ts: Date.now() }));
652
653
  }
653
654
  if (!comp.compacted) {
654
655
  const outcome = comp.blocked
655
656
  ? "blocked"
656
- : comp.disabled
657
- ? (forceManual || trimPressure ? "disabled" : undefined)
658
- : comp.suppressedByFloor
659
- ? "suppressed"
660
- : comp.noop || forceManual
661
- ? "noop"
662
- : undefined;
657
+ : comp.suppressedByFloor
658
+ ? "suppressed"
659
+ : comp.noop || forceManual
660
+ ? "noop"
661
+ : undefined;
663
662
  if (outcome !== undefined) {
664
663
  queue.push({ type: "compaction_outcome", outcome, trigger: passTrigger, ...requester, ...ident() });
665
664
  }
@@ -83,7 +83,7 @@ export class Runner {
83
83
  verbLockSeats = { sessionBusy: (id) => this.sessionLocks.has(id) || this.sessionWrites.busy(id), takeSessionLock: (id) => this.acquireSessionLock(id) };
84
84
  sessionReadStates = new SessionReadFileStates();
85
85
  sessionModeSeats = new SessionModeSeats();
86
- pendingSessionNotifications = new PendingSessionNotifications();
86
+ pendingSessionNotifications = new PendingSessionNotifications({ onNotice: () => this.deps.onNotice });
87
87
  parentConstraintRegistry = new Map();
88
88
  suspendedEnvReaps = new Map();
89
89
  locallyClaimedTokens = new LocalClaims();
@@ -24,6 +24,7 @@
24
24
  * the resumed leg's), joined by the checkpoint row the resumed leg was opened from — never by a field here.
25
25
  */
26
26
  import type { DeniedBy, GateOutcome } from "../gate-outcome.js";
27
+ import { type GateExitFacts } from "./gate-exit.js";
27
28
  /** The one clock the occurrence's heartbeat facts are stamped on. MONOTONIC for the reason the progress lane
28
29
  * states: every reading is subtracted from another, and a wall-clock step backwards would silence the beat. A
29
30
  * host without `performance` falls back to the wall clock and inherits its rollback behaviour. */
@@ -92,8 +93,9 @@ export interface ToolOccurrenceTable {
92
93
  /** A gate exit for this call: its record and the input it decided on (frozen by the gate's exit). */
93
94
  gateRound(toolCallId: string, outcome: GateOutcome, finalInput?: unknown, rewrite?: import("../task-event.js").ToolInputRewrite): void;
94
95
  /** A station after the gate refused the call: one more gate record, minted as a veto of whatever the latest one
95
- * settled (a person's yes stays on the settlement; the refusing layer is the disposition). Returns the record. */
96
- refuse(toolCallId: string, layer: DeniedBy, extension?: string): GateOutcome;
96
+ * settled (a person's yes stays on the settlement; the refusing layer is the disposition). `facts` is what the refusing
97
+ * station knows beside the layer word: the extension that refused, the literals its sentence quoted. Returns the record. */
98
+ refuse(toolCallId: string, layer: DeniedBy, facts?: Pick<GateExitFacts, "extension" | "echoed">): GateOutcome;
97
99
  /** An extension at `tool.call` answered for the call before its body was called (the kernel's record says the body had
98
100
  * not started): the body is never called for this attempt. Once per attempt; a second is an engine defect. */
99
101
  answeredInPlace(toolCallId: string, by: string): void;
@@ -91,10 +91,10 @@ export function createToolOccurrenceTable() {
91
91
  occ.finalInput = finalInput;
92
92
  occ.rewrite = rewrite;
93
93
  },
94
- refuse(toolCallId, layer, extension) {
94
+ refuse(toolCallId, layer, facts) {
95
95
  const occ = held(toolCallId, "a refusal");
96
96
  const latest = occ.gateRounds.at(-1);
97
- const round = mintGateOutcome({ deniedBy: layer, ...(extension !== undefined ? { extension } : {}), ...(latest?.settlement !== undefined && latest.origin !== undefined ? { settled: { settlement: latest.settlement, origin: latest.origin } } : {}) });
97
+ const round = mintGateOutcome({ deniedBy: layer, ...(facts?.extension !== undefined ? { extension: facts.extension } : {}), ...(facts?.echoed !== undefined ? { echoed: facts.echoed } : {}), ...(latest?.settlement !== undefined && latest.origin !== undefined ? { settled: { settlement: latest.settlement, origin: latest.origin } } : {}) });
98
98
  occ.gateRounds.push(round);
99
99
  return round;
100
100
  },
@@ -114,7 +114,7 @@ export interface RunnerDeps {
114
114
  models?: Record<string, Model>;
115
115
  /**
116
116
  * The deployment's per-model CONTEXT-WINDOW overlay, keyed by CATALOG WORD ({@link ContextSettings}):
117
- * `contextTokens` / `autoCompactTokens` / `enabled` over what the model card declares.
117
+ * `contextTokens` / `autoCompactTokens` over what the model card declares, `autoCompact` / `manualCompact` the task seats' twins.
118
118
  *
119
119
  * It is the ONE hot-swappable seat an IN-FLIGHT leg re-reads. Every other seat follows the snapshot law
120
120
  * (a running task keeps the deps object it prepared under) because those seats are the routing card —
@@ -84,8 +84,9 @@ export interface OpenedSessionCheckout {
84
84
  /**
85
85
  * THE per-leg judge of a session's checkout (see the module header): reads the record, compares the leg's declaration with it,
86
86
  * mints the allocation on the session's first leg, and answers the leg's task root. Throws a coded refusal; the first leg's
87
- * allocation is all or nothing (every check runs before the mint, a tree minted for a refused allocation is removed while it is
88
- * still clean, and the record is written only once everything succeeded — immediately, not at settle).
87
+ * allocation records nothing unless everything succeeded (every path check runs before the mint; a tree minted for a refused
88
+ * allocation is removed while still clean only when its allocation mark is proved absent, else kept and named; the record is
89
+ * written only once everything succeeded — immediately, not at settle).
89
90
  */
90
91
  export declare function openSessionCheckout(input: OpenSessionCheckoutInput): Promise<OpenedSessionCheckout>;
91
92
  /**
@@ -97,12 +98,71 @@ export declare function openSessionCheckout(input: OpenSessionCheckoutInput): Pr
97
98
  * again re-reports and never removes a tree another allocation took over.
98
99
  *
99
100
  * `onExit`: `"keep-if-dirty"` (default) | `"keep"` (keep every tree; only record the release). A discarding removal is not
100
- * offered. A session with no checkout answers an empty list.
101
+ * offered. A session with no checkout answers an empty list; a tree its first leg kept because the record could not be written
102
+ * is no record's to release — {@link listOrphanSessionTrees} lists it.
101
103
  */
102
104
  export declare function releaseSessionCheckout(env: ExecutionEnv, session: Session, opts?: {
103
105
  readonly onExit?: "keep-if-dirty" | "keep";
104
106
  }): Promise<{
105
107
  readonly trees: readonly ReleasedTree[];
106
108
  }>;
109
+ /** Why a session tree whose allocation mark reads is no record's ({@link OrphanSessionTree.why}). */
110
+ export type OrphanSessionTreeWhy = "unrecorded" | "record_unreadable" | "record_elsewhere";
111
+ /** A session tree no record holds — what {@link listOrphanSessionTrees} lists. */
112
+ export interface OrphanSessionTree {
113
+ /** `<repository root>/.sema/worktrees/<name>`, the list's spelling — the path {@link releaseOrphanSessionTree} takes. */
114
+ readonly path: string;
115
+ /** The tree's branch (`sema/<name>`), present while it exists. */
116
+ readonly branch?: string;
117
+ /** The session its allocation mark names. */
118
+ readonly sessionId: string;
119
+ /** The allocation its mark names. */
120
+ readonly allocationId: string;
121
+ /** The commit it was minted at (its mark). */
122
+ readonly baseSha: string;
123
+ /** `unrecorded`: the host's lookup says that session does not exist, or its log holds no checkout record · `record_unreadable`:
124
+ * the lookup threw, the session's record cannot be read, or its log is loaded from a bounded window that may hold the record
125
+ * below its floor · `record_elsewhere`: the session's record holds another allocation (a first leg refused while another leg
126
+ * recorded kept the tree it minted). */
127
+ readonly why: OrphanSessionTreeWhy;
128
+ /** `record_unreadable`: why; `record_elsewhere`: the allocation the record holds. */
129
+ readonly detail?: string;
130
+ /** The tree directory's modification time (ms since the epoch): a hint for a host's retention policy, not liveness. */
131
+ readonly modifiedAt: number;
132
+ }
133
+ /**
134
+ * The host's lookup of a session by id, handed to the orphan doors.
135
+ *
136
+ * @contract session_checkout.session_of.absence_is_authority — `undefined` asserts that the host's DURABLE session store holds no
137
+ * session with that id (a cache miss is not absence), and the lookup throws whenever it cannot tell. The doors read `undefined` as
138
+ * "no leg of that session will take the tree back" (the host never reuses a session id) and a throw as `record_unreadable`, which
139
+ * neither door removes.
140
+ */
141
+ export type OrphanSessionLookup = (sessionId: string) => Promise<Session | undefined>;
142
+ /**
143
+ * List the session trees under the repository at `root` that no record holds: each managed tree whose allocation mark reads and
144
+ * whose session ({@link OrphanSessionLookup}) holds no record of that allocation — the tree a first leg kept when its record could
145
+ * not be written, or one whose session the host deleted without releasing it. Reads only. A tree its session's record holds is
146
+ * not listed ({@link releaseSessionCheckout} is its door), nor a directory with no readable mark (no session tree, or one neither
147
+ * door touches). Answers `{ repository, trees }`; a repository with no managed parent answers no trees.
148
+ */
149
+ export declare function listOrphanSessionTrees(env: ExecutionEnv, root: string, opts: {
150
+ readonly sessionOf: OrphanSessionLookup;
151
+ }): Promise<{
152
+ readonly repository: string;
153
+ readonly trees: readonly OrphanSessionTree[];
154
+ }>;
155
+ /**
156
+ * Release one orphan session tree — the host's door for a tree no record holds (as {@link listOrphanSessionTrees} lists it).
157
+ * The tree is judged again: a tree a session's record holds now answers `kept: "not_owned"` (release that session's checkout
158
+ * instead), one whose record cannot be read `kept: "unverifiable"`, one with no allocation mark `not_owned`; an orphan is then
159
+ * removed by the same judgment as {@link releaseSessionCheckout} (clean, no commit past its base, the mark read again right
160
+ * before the removal, no `--force`; the branch only while it sits at the base commit). Removes nothing on its own initiative,
161
+ * appends to no session. The host runs the removals of one repository one at a time — this door's, the release's, a deleted
162
+ * session's cascade (a removal and a mint of the same name between two of them is the known window, KNOWN-LIMITS KL-3462-a).
163
+ */
164
+ export declare function releaseOrphanSessionTree(env: ExecutionEnv, path: string, opts: {
165
+ readonly sessionOf: OrphanSessionLookup;
166
+ }): Promise<ReleasedTree>;
107
167
  /** The frame's `session` member: the record's cells as the leg reports them (`undefined` when the session has no checkout). */
108
168
  export declare function sessionFrameOf(record: SessionCheckoutRecord | undefined): ReadonlyArray<SessionCheckoutCell> | undefined;