@sema-agent/core 7.63.0 → 7.65.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 (239) hide show
  1. package/CHANGELOG.md +725 -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 +25 -5
  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/auto-promote.d.ts +3 -2
  30. package/dist/core/background-agent-store.d.ts +14 -0
  31. package/dist/core/background-agent-store.js +3 -0
  32. package/dist/core/checkpoint-queries.d.ts +9 -6
  33. package/dist/core/checkpoint-queries.js +8 -3
  34. package/dist/core/checkpoint-store.d.ts +7 -4
  35. package/dist/core/context-settings.d.ts +39 -9
  36. package/dist/core/context-settings.js +32 -10
  37. package/dist/core/engine-attestation.d.ts +26 -6
  38. package/dist/core/engine-attestation.js +5 -1
  39. package/dist/core/engine-notice.d.ts +37 -2
  40. package/dist/core/engine-notice.js +3 -1
  41. package/dist/core/extension-requester.d.ts +9 -0
  42. package/dist/core/extension-requester.js +7 -0
  43. package/dist/core/file-history-store.d.ts +30 -2
  44. package/dist/core/file-history-store.js +48 -9
  45. package/dist/core/fs-write-gate-policy.js +1 -1
  46. package/dist/core/gate-fold.js +5 -1
  47. package/dist/core/gate-lanes.js +2 -0
  48. package/dist/core/gate-outcome.d.ts +39 -2
  49. package/dist/core/gate-outcome.js +20 -1
  50. package/dist/core/governance-codes.d.ts +8 -4
  51. package/dist/core/governance-codes.js +8 -3
  52. package/dist/core/leg-identity.d.ts +35 -1
  53. package/dist/core/leg-identity.js +10 -0
  54. package/dist/core/mailbox-store.d.ts +39 -4
  55. package/dist/core/mailbox-store.js +14 -2
  56. package/dist/core/memory-engine/consolidation.d.ts +13 -6
  57. package/dist/core/memory-engine/consolidation.js +26 -0
  58. package/dist/core/memory-engine/control-objects.d.ts +58 -0
  59. package/dist/core/memory-engine/control-objects.js +273 -0
  60. package/dist/core/memory-engine/control-plane-adoption.d.ts +51 -0
  61. package/dist/core/memory-engine/control-plane-adoption.js +161 -0
  62. package/dist/core/memory-engine/delegation-settlement.d.ts +73 -40
  63. package/dist/core/memory-engine/delegation-settlement.js +271 -107
  64. package/dist/core/memory-engine/dual-root.d.ts +3 -2
  65. package/dist/core/memory-engine/dual-root.js +7 -3
  66. package/dist/core/memory-engine/engine.d.ts +54 -33
  67. package/dist/core/memory-engine/engine.js +150 -157
  68. package/dist/core/memory-engine/file-backend.d.ts +58 -76
  69. package/dist/core/memory-engine/file-backend.js +111 -268
  70. package/dist/core/memory-engine/index.d.ts +3 -2
  71. package/dist/core/memory-engine/index.js +2 -1
  72. package/dist/core/memory-engine/layout.d.ts +135 -50
  73. package/dist/core/memory-engine/layout.js +214 -89
  74. package/dist/core/memory-engine/memory-age.d.ts +12 -0
  75. package/dist/core/memory-engine/memory-age.js +17 -0
  76. package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
  77. package/dist/core/memory-engine/memory-backend-contract.js +159 -2
  78. package/dist/core/memory-engine/memory-deployment.d.ts +12 -4
  79. package/dist/core/memory-engine/memory-deployment.js +31 -6
  80. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  81. package/dist/core/memory-engine/origin-clearance.js +64 -9
  82. package/dist/core/memory-engine/session-write-home.d.ts +34 -1
  83. package/dist/core/memory-engine/session-write-home.js +37 -10
  84. package/dist/core/memory-engine/tools.d.ts +2 -2
  85. package/dist/core/memory-engine/tools.js +7 -7
  86. package/dist/core/memory-engine/types.d.ts +55 -12
  87. package/dist/core/memory-engine/types.js +2 -1
  88. package/dist/core/memory-vector.d.ts +6 -14
  89. package/dist/core/memory.d.ts +0 -462
  90. package/dist/core/memory.js +0 -333
  91. package/dist/core/mode-policy.js +3 -3
  92. package/dist/core/mods/agent-stations.d.ts +18 -0
  93. package/dist/core/mods/agent-stations.js +8 -6
  94. package/dist/core/mods/extension-call.d.ts +4 -0
  95. package/dist/core/mods/extension-call.js +8 -0
  96. package/dist/core/mods/tool-call.js +3 -4
  97. package/dist/core/parent-spec-seat.d.ts +2 -2
  98. package/dist/core/peer-channel.d.ts +5 -0
  99. package/dist/core/permission-rule-consent.d.ts +64 -22
  100. package/dist/core/permission-rule-consent.js +106 -58
  101. package/dist/core/permission-rule-store.d.ts +56 -21
  102. package/dist/core/permission-rule-store.js +2 -0
  103. package/dist/core/refusal-echo.d.ts +20 -0
  104. package/dist/core/refusal-echo.js +33 -0
  105. package/dist/core/retention.d.ts +175 -10
  106. package/dist/core/retention.js +44 -0
  107. package/dist/core/retired-keys.d.ts +5 -0
  108. package/dist/core/retired-keys.js +3 -0
  109. package/dist/core/rule-offer-read.d.ts +0 -4
  110. package/dist/core/rule-offer-read.js +2 -18
  111. package/dist/core/runner/classifier-ladder.d.ts +10 -2
  112. package/dist/core/runner/classifier-ladder.js +4 -2
  113. package/dist/core/runner/compact-session.js +10 -7
  114. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  115. package/dist/core/runner/compaction-call-options.js +3 -2
  116. package/dist/core/runner/contracts.d.ts +28 -9
  117. package/dist/core/runner/delegation-owner.d.ts +2 -3
  118. package/dist/core/runner/delegation-owner.js +2 -1
  119. package/dist/core/runner/gate-exit.d.ts +6 -0
  120. package/dist/core/runner/gate-exit.js +11 -2
  121. package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
  122. package/dist/core/runner/memory-consolidation-driver.js +8 -5
  123. package/dist/core/runner/prepare-ask-lane.js +3 -3
  124. package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
  125. package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
  126. package/dist/core/runner/prepare-config-doors.js +4 -0
  127. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  128. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  129. package/dist/core/runner/prepare-gate-stations.d.ts +8 -0
  130. package/dist/core/runner/prepare-gate-stations.js +15 -7
  131. package/dist/core/runner/prepare-hands-readface.js +1 -1
  132. package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
  133. package/dist/core/runner/prepare-inherited-gate.js +4 -2
  134. package/dist/core/runner/prepare-memory-engine-session.js +1 -1
  135. package/dist/core/runner/prepare-memory.d.ts +4 -0
  136. package/dist/core/runner/prepare-memory.js +22 -28
  137. package/dist/core/runner/prepare-policy-chain.js +18 -10
  138. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  139. package/dist/core/runner/prepare-task.d.ts +5 -1
  140. package/dist/core/runner/prepare-task.js +16 -11
  141. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  142. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  143. package/dist/core/runner/resume-admission.d.ts +2 -2
  144. package/dist/core/runner/resume-admission.js +2 -23
  145. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  146. package/dist/core/runner/role-resolution-table.js +62 -0
  147. package/dist/core/runner/run-compaction-machinery.js +2 -2
  148. package/dist/core/runner/run-identity-wiring.js +12 -9
  149. package/dist/core/runner/run-leg.js +8 -4
  150. package/dist/core/runner/run-notification-lane.js +23 -23
  151. package/dist/core/runner/run-recovery-lanes.js +3 -3
  152. package/dist/core/runner/run-terminal-adoption.js +1 -1
  153. package/dist/core/runner/run-turn-boundary.js +14 -15
  154. package/dist/core/runner/runtask.js +1 -1
  155. package/dist/core/runner/sub-agent-deny-lists.d.ts +19 -0
  156. package/dist/core/runner/sub-agent-deny-lists.js +25 -0
  157. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  158. package/dist/core/runner/tool-occurrence.js +2 -2
  159. package/dist/core/runner-deps.d.ts +1 -1
  160. package/dist/core/secret-env.d.ts +2 -2
  161. package/dist/core/secret-env.js +6 -20
  162. package/dist/core/session-checkout.d.ts +63 -3
  163. package/dist/core/session-checkout.js +152 -58
  164. package/dist/core/session-store.d.ts +6 -6
  165. package/dist/core/session-store.js +3 -3
  166. package/dist/core/shell-read-silence.js +8 -0
  167. package/dist/core/store-contracts/background-agent-store-contract.js +13 -0
  168. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  169. package/dist/core/task-event.d.ts +9 -5
  170. package/dist/core/task-notification.d.ts +137 -31
  171. package/dist/core/task-notification.js +198 -100
  172. package/dist/core/task-registry-agent.d.ts +11 -0
  173. package/dist/core/task-registry-agent.js +12 -3
  174. package/dist/core/task-registry-shared.d.ts +11 -0
  175. package/dist/core/task-registry.d.ts +18 -0
  176. package/dist/core/task-registry.js +27 -8
  177. package/dist/core/task-spec.d.ts +7 -2
  178. package/dist/core/tool-errors.d.ts +17 -9
  179. package/dist/core/tool-errors.js +1 -1
  180. package/dist/core/tool-policy.d.ts +18 -1
  181. package/dist/core/tool-policy.js +16 -7
  182. package/dist/core/tool-result-store.d.ts +20 -0
  183. package/dist/core/tool-spec.d.ts +10 -6
  184. package/dist/core/trace.d.ts +3 -2
  185. package/dist/core/workflow-journal-store.d.ts +11 -0
  186. package/dist/core/workflow-journal-store.js +7 -0
  187. package/dist/core/workflow-run-store.d.ts +9 -0
  188. package/dist/core/workflow-run-store.js +6 -0
  189. package/dist/core/write-protect.d.ts +16 -0
  190. package/dist/core/write-protect.js +10 -0
  191. package/dist/engine/compaction/compaction.d.ts +2 -1
  192. package/dist/engine/harness/types.d.ts +1 -0
  193. package/dist/engine/session/repo-utils.d.ts +14 -4
  194. package/dist/engine/session/repo-utils.js +5 -4
  195. package/dist/engine/session/session.d.ts +7 -1
  196. package/dist/engine/session/session.js +5 -2
  197. package/dist/index.d.ts +13 -11
  198. package/dist/index.js +13 -11
  199. package/dist/orchestration/run-workflow-tool.d.ts +4 -0
  200. package/dist/orchestration/run-workflow-tool.js +7 -0
  201. package/dist/orchestration/workflow-types.d.ts +2 -1
  202. package/dist/orchestration/workflow.d.ts +3 -0
  203. package/dist/orchestration/workflow.js +2 -1
  204. package/dist/prompts/default.d.ts +1 -2
  205. package/dist/scenarios/full-body.d.ts +1 -1
  206. package/dist/stores/file/adoption/adopt.d.ts +1 -1
  207. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  208. package/dist/stores/file/checkpoint-store.js +4 -1
  209. package/dist/stores/file/file-history-store.d.ts +13 -0
  210. package/dist/stores/file/file-history-store.js +75 -13
  211. package/dist/stores/file/index.d.ts +12 -16
  212. package/dist/stores/file/index.js +7 -25
  213. package/dist/stores/file/permission-rule-store.d.ts +34 -0
  214. package/dist/stores/file/permission-rule-store.js +104 -9
  215. package/dist/stores/file/session-store.js +1 -1
  216. package/dist/stores/file/tool-result-store.d.ts +14 -0
  217. package/dist/stores/file/tool-result-store.js +39 -2
  218. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  219. package/dist/stores/file/workflow-journal-store.js +17 -0
  220. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  221. package/dist/stores/file/workflow-run-store.js +15 -0
  222. package/dist/tools/fs/read-deny.d.ts +15 -2
  223. package/dist/tools/fs/read-deny.js +10 -2
  224. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  225. package/dist/tools/fs/shell-read-check.js +7 -7
  226. package/package.json +2 -2
  227. package/test/export-surface.snapshot.json +71 -73
  228. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  229. package/wire-changes/core-stores-sql@7.65.0.json +30 -0
  230. package/wire-changes/core@7.64.0.json +2653 -0
  231. package/wire-changes/core@7.65.0.json +1650 -0
  232. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  233. package/wire-changes/mods-kernel@7.65.0.json +30 -0
  234. package/wire-changes/primitives@7.64.0.json +30 -0
  235. package/wire-changes/primitives@7.65.0.json +337 -0
  236. package/dist/core/memory-recall.d.ts +0 -208
  237. package/dist/core/memory-recall.js +0 -136
  238. package/dist/stores/file/memory-store.d.ts +0 -124
  239. package/dist/stores/file/memory-store.js +0 -353
@@ -5,6 +5,8 @@ import { readRuleOwner } from "./rule-owner.js";
5
5
  import { thrownText } from "./thrown-value.js";
6
6
  import { validatePath } from "./effective-path-target.js";
7
7
  export const PERMISSION_RULES_LATER_GRAMMAR_CODE = "permission_rules.later_grammar";
8
+ export const PERMISSION_RULES_DAMAGED_BUCKET_CODE = "permission_rules.bucket_damaged";
9
+ export const PERMISSION_RULES_UNREADABLE_BUCKET_CODE = "permission_rules.bucket_unreadable";
8
10
  export function isRuleRevision(rev) {
9
11
  return typeof rev === "number" && Number.isSafeInteger(rev) && rev >= 0;
10
12
  }
@@ -0,0 +1,20 @@
1
+ /** What a quoted span of a refusal sentence IS: a file path, a command line, or a deny/rule pattern. */
2
+ export declare const REFUSAL_ECHO_KINDS: readonly ["path", "command", "pattern"];
3
+ export type RefusalEchoKind = (typeof REFUSAL_ECHO_KINDS)[number];
4
+ /** Membership test for {@link RefusalEchoKind}. */
5
+ export declare function isRefusalEchoKind(v: unknown): v is RefusalEchoKind;
6
+ /**
7
+ * One literal the sentence quotes, in the order the sentence quotes them. `value` is the literal as the refusing judge
8
+ * held it — the sentence elides the middle of a long one, this member never does. `canonical` stands on a `path` whose
9
+ * canonical target the sentence also names because the two differ.
10
+ */
11
+ export interface RefusalEcho {
12
+ readonly kind: RefusalEchoKind;
13
+ readonly value: string;
14
+ readonly canonical?: string;
15
+ }
16
+ /** The defects of `v` read as a list of {@link RefusalEcho} (an empty list is a clean one): a dense non-empty array holding nothing
17
+ * but its elements (no hole, no member of its own beside them — a method name or a symbol on the array is read by nobody here and
18
+ * JSON drops it), of records that hold exactly `kind` (a member of the set), `value` (a non-empty string) and, on a `path`, an
19
+ * optional non-empty `canonical`. Reads the list by index alone: no method of a caller's array is ever called. */
20
+ export declare function refusalEchoDefects(v: unknown): string[];
@@ -0,0 +1,33 @@
1
+ import { strayMembersOf } from "./own-property-receipt.js";
2
+ const ECHO_MEMBERS = Object.freeze(["kind", "value", "canonical"]);
3
+ const ECHO_WORDS = Object.freeze({ subject: "an echo", unit: "member", moment: "at the gate record" });
4
+ export const REFUSAL_ECHO_KINDS = Object.freeze(["path", "command", "pattern"]);
5
+ const KIND_SET = new Set(REFUSAL_ECHO_KINDS);
6
+ export function isRefusalEchoKind(v) {
7
+ return KIND_SET.has(v);
8
+ }
9
+ export function refusalEchoDefects(v) {
10
+ if (!Array.isArray(v) || v.length === 0)
11
+ return ["echoed is not a non-empty list"];
12
+ const out = [];
13
+ if (Reflect.ownKeys(v).length !== v.length + 1)
14
+ out.push("echoed holds a hole or a member that is no element");
15
+ for (let i = 0; i < v.length; i++) {
16
+ const e = v[i];
17
+ if (typeof e !== "object" || e === null || Array.isArray(e)) {
18
+ out.push(`echoed[${i}] is not an object`);
19
+ continue;
20
+ }
21
+ const r = e;
22
+ if (!isRefusalEchoKind(r.kind))
23
+ out.push(`echoed[${i}].kind is outside the closed set`);
24
+ if (typeof r.value !== "string" || r.value === "")
25
+ out.push(`echoed[${i}].value is not a non-empty string`);
26
+ if (r.canonical !== undefined && (typeof r.canonical !== "string" || r.canonical === "" || r.kind !== "path"))
27
+ out.push(`echoed[${i}].canonical stands only on a path, as a non-empty string`);
28
+ const stray = strayMembersOf(r, ECHO_WORDS, ECHO_MEMBERS);
29
+ if (stray !== undefined)
30
+ out.push(`echoed[${i}]: ${stray.sentence}`);
31
+ }
32
+ return out;
33
+ }
@@ -1,3 +1,5 @@
1
+ import type { EngineStorageBackend } from "./engine-storage-backend.js";
2
+ import type { WorkflowRunStore } from "./workflow-run-store.js";
1
3
  /** A store's retention declaration: `"managed"` = this store's rows are deleted on schedule by the
2
4
  * deployment; `"none"` = nothing deletes them on schedule. Absent ⇒ read fail-closed as `"none"`. */
3
5
  export type RetentionDeclaration = "managed" | "none";
@@ -30,7 +32,7 @@ export interface RetentionPolicy {
30
32
  /**
31
33
  * The executor that deletes the rows of the stores declaring `retention: "managed"` — a backend's
32
34
  * `retention` member (contract TYPE — core ships no implementation; the server half consumes this.
33
- * Reference implementation of the cascade: the server's session-purge order contract). A deployment
35
+ * The legs it calls, store by store and in order, are {@link RETENTION_CASCADE}). A deployment
34
36
  * that declares a store managed runs one over that store's rows. Every method is expected to be:
35
37
  * - **tenant-domain scoped**: work is enumerated and executed per retention domain (tenant/scope),
36
38
  * never as one global sweep;
@@ -45,7 +47,10 @@ export interface RetentionPolicy {
45
47
  * therefore the CALL's three counts, deliberately not an audit row. Where the deletion and the
46
48
  * sweep's context live on two sides — a SQL backend writes the deletion, the deployment holds the op —
47
49
  * the deployment writes the audit row through the backend's `audit` transaction hook, inside the
48
- * deleting transaction, from the receipt it is handed there.
50
+ * deleting transaction, from the receipt it is handed there;
51
+ * - **bounded by its call**: each call carries its own `cutoffMs`, computed by the party that runs the
52
+ * sweep (from its own horizon, e.g. a host's cleanup period in days) — an executor never reads
53
+ * {@link RetentionPolicy.maxAgeDays}, which is the startup check's to judge.
49
54
  */
50
55
  export interface ManagedRetentionCapability {
51
56
  /** Enumerate the retention domains (tenant/scope keys) this store holds data for. */
@@ -60,7 +65,8 @@ export interface ManagedRetentionCapability {
60
65
  /** Lineage-aware transcript/session deletion: a session tree is deleted only when no live
61
66
  * reference (fork child, background child, workflow run, pending checkpoint) still points into
62
67
  * it — references are re-checked inside the deletion transaction, never assumed from a prior
63
- * scan; {@link RETENTION_CASCADE_EXEMPT} is never deleted with one. */
68
+ * scan; {@link RETENTION_CASCADE_EXEMPT} is never deleted with one. What one session's deletion
69
+ * erases, and in which order, is {@link RETENTION_CASCADE}'s session-tree legs. */
64
70
  deleteExpiredSessions(input: {
65
71
  domain: string;
66
72
  cutoffMs: number;
@@ -72,6 +78,172 @@ export interface ManagedRetentionCapability {
72
78
  cutoffMs: number;
73
79
  }): Promise<RetentionReceipt>;
74
80
  }
81
+ /** @contract retention.cascade_domains — the executor's three destructive operations, one domain each: checkpoint expiry
82
+ * (`expireCheckpoints`), session-tree deletion (`deleteExpiredSessions`) and orphan tool-result deletion
83
+ * (`deleteOrphanToolResults`). Every leg of {@link RETENTION_CASCADE} belongs to exactly one of them, and each has a leg. */
84
+ export declare const RETENTION_CASCADE_DOMAINS: readonly ["checkpoints", "session-trees", "orphan-tool-results"];
85
+ /** One of {@link RETENTION_CASCADE_DOMAINS}. */
86
+ export type RetentionCascadeDomain = (typeof RETENTION_CASCADE_DOMAINS)[number];
87
+ /** @contract retention.governance_records_outlive_the_purge — the pollution marker dir, the capture
88
+ * opt-out record dir and the lineage ledger are governance FACTS about content that exists, not
89
+ * session data: deleting them makes a one-way privacy record revocable. */
90
+ export declare const RETENTION_CASCADE_EXEMPT: readonly ["session-pollution", "session-capture-optout", "lineage.json"];
91
+ /** The stores {@link RETENTION_CASCADE} covers, by seat name: every store member of {@link EngineStorageBackend} and the
92
+ * workflow-run store a deployment constructs itself. */
93
+ export type RetentionCascadeStores = Omit<EngineStorageBackend, "retention" | "dispose"> & {
94
+ readonly workflowRunStore: WorkflowRunStore;
95
+ };
96
+ /** One leg of a store's row: the store method a domain's operation calls on it. */
97
+ export interface RetentionCascadeLeg<S = {
98
+ readonly [verb: string]: unknown;
99
+ }> {
100
+ readonly domain: RetentionCascadeDomain;
101
+ /** The store's method — a member of its interface (checked by the table's type). */
102
+ readonly verb: Extract<keyof S, string>;
103
+ /** What the call is given and what it removes. */
104
+ readonly selects: string;
105
+ /** A session-tree leg's place in one session's erasure (ascending; unique across the table). Present on a
106
+ * `"session-trees"` leg, absent on the other two domains' legs, whose operations each call one leg. */
107
+ readonly step?: number;
108
+ /** A fence the leg's store runs before the session's first step, where the store carries it (absent there ⇒ no fence). */
109
+ readonly fence?: Extract<keyof S, string>;
110
+ }
111
+ /** A store's one row: the legs that erase its rows, or why none do. */
112
+ export type RetentionCascadeRow<S = {
113
+ readonly [verb: string]: unknown;
114
+ }> = {
115
+ readonly legs: readonly RetentionCascadeLeg<S>[];
116
+ } | {
117
+ readonly exempt: string;
118
+ };
119
+ /**
120
+ * @contract retention.cascade_table — what deleting a session erases, as one table: every store the engine persists in has exactly one
121
+ * row (typed complete against {@link RetentionCascadeStores}), either the legs that erase its rows (domain, verb, what the verb selects,
122
+ * and for a session-tree leg its step) or an exemption naming why its rows are not session data. A session tree is erased child
123
+ * sessions first; within one session every leg's fence runs before the first step, then the steps ascend and the session row's leg
124
+ * is last — a leg that fails leaves the row, so a retry runs the cascade again from its first step and converges. A leg that finds
125
+ * what it erases through another store's rows runs before that store's leg (the journals before the runs, the background agents'
126
+ * boxes before their rows), so a retry still finds them. A workflow run
127
+ * started in a deleted session goes with it, journal included: a later resume of that run from another session is refused
128
+ * `workflow.park_truth_unreadable` with `detail.reason: "record_missing"`, the word an absent prior record already answers. The run
129
+ * store is what indexes runs by session, so a deployment that wires a journal store without one leaves its journals out of reach.
130
+ */
131
+ export declare const RETENTION_CASCADE: {
132
+ workflowJournalStore: {
133
+ legs: {
134
+ domain: "session-trees";
135
+ step: number;
136
+ verb: "deleteRun";
137
+ selects: string;
138
+ }[];
139
+ };
140
+ workflowRunStore: {
141
+ legs: {
142
+ domain: "session-trees";
143
+ step: number;
144
+ verb: "deleteBySession";
145
+ selects: string;
146
+ }[];
147
+ };
148
+ backgroundAgentStore: {
149
+ legs: {
150
+ domain: "session-trees";
151
+ step: number;
152
+ verb: "delete";
153
+ selects: string;
154
+ }[];
155
+ };
156
+ rosterStore: {
157
+ legs: {
158
+ domain: "session-trees";
159
+ step: number;
160
+ verb: "releaseAgent";
161
+ selects: string;
162
+ }[];
163
+ };
164
+ checkpointStore: {
165
+ legs: ({
166
+ domain: "session-trees";
167
+ step: number;
168
+ verb: "deleteSessionCheckpoints";
169
+ selects: string;
170
+ } | {
171
+ domain: "checkpoints";
172
+ verb: "reap";
173
+ selects: string;
174
+ step?: undefined;
175
+ })[];
176
+ };
177
+ toolResultStore: {
178
+ legs: ({
179
+ domain: "session-trees";
180
+ step: number;
181
+ verb: "deleteBySession";
182
+ selects: string;
183
+ } | {
184
+ domain: "orphan-tool-results";
185
+ verb: "deleteUnattributable";
186
+ selects: string;
187
+ step?: undefined;
188
+ })[];
189
+ };
190
+ sessionPolicyStore: {
191
+ legs: {
192
+ domain: "session-trees";
193
+ step: number;
194
+ verb: "deleteBySession";
195
+ selects: string;
196
+ }[];
197
+ };
198
+ fileHistoryStore: {
199
+ legs: {
200
+ domain: "session-trees";
201
+ step: number;
202
+ verb: "deleteBySession";
203
+ selects: string;
204
+ }[];
205
+ };
206
+ mailboxStore: {
207
+ legs: ({
208
+ domain: "session-trees";
209
+ step: number;
210
+ verb: "drop";
211
+ selects: string;
212
+ fence?: undefined;
213
+ } | {
214
+ domain: "session-trees";
215
+ step: number;
216
+ verb: "drop";
217
+ fence: "retireRecipient";
218
+ selects: string;
219
+ })[];
220
+ };
221
+ /**
222
+ * @contract retention.image_bytes_live_in_the_session_store — a transcript's image bytes have one holder, the engine's session store:
223
+ * they ride the session's log entries, so the session row's leg deletes them. A host that keeps a transcript of its own keeps a
224
+ * reference to them (session id, entry id, block index), never a second copy.
225
+ */
226
+ sessionStore: {
227
+ legs: ({
228
+ domain: "session-trees";
229
+ step: number;
230
+ verb: "delete";
231
+ selects: string;
232
+ } | {
233
+ domain: "checkpoints";
234
+ verb: "unpin";
235
+ selects: string;
236
+ step?: undefined;
237
+ })[];
238
+ };
239
+ usageWindowStore: {
240
+ exempt: string;
241
+ };
242
+ };
243
+ /** One session's erasure in order — {@link RETENTION_CASCADE}'s session-tree legs, ascending by step (the one reading of the order). */
244
+ export declare const RETENTION_SESSION_TREE_STEPS: readonly (RetentionCascadeLeg & {
245
+ readonly store: keyof RetentionCascadeStores;
246
+ })[];
75
247
  /**
76
248
  * The three counts one destructive retention call produced. NOT an audit row and deliberately
77
249
  * identity-free (see the capability's `audited` clause): a scheduler that needs to tell two
@@ -79,13 +251,6 @@ export interface ManagedRetentionCapability {
79
251
  * own occurrence id, operation, and timestamp inside the deleting transaction. Adding those here
80
252
  * would ask a return value to know its own call context.
81
253
  */
82
- /** @contract retention.cascade_domains — a managed-retention cascade deletes checkpoint rows,
83
- * session trees (transcripts and lineage) and orphan tool results; nothing else is session data. */
84
- export declare const RETENTION_CASCADE_DOMAINS: readonly ["checkpoints", "session-trees", "orphan-tool-results"];
85
- /** @contract retention.governance_records_outlive_the_purge — the pollution marker dir, the capture
86
- * opt-out record dir and the lineage ledger are governance FACTS about content that exists, not
87
- * session data: deleting them makes a one-way privacy record revocable. */
88
- export declare const RETENTION_CASCADE_EXEMPT: readonly ["session-pollution", "session-capture-optout", "lineage.json"];
89
254
  export interface RetentionReceipt {
90
255
  domain: string;
91
256
  /** Rows destroyed by THIS call (idempotent retries count already-gone rows as 0, not errors). */
@@ -11,6 +11,50 @@ export function readRetentionDeclaration(name, value) {
11
11
  }
12
12
  export const RETENTION_CASCADE_DOMAINS = Object.freeze(["checkpoints", "session-trees", "orphan-tool-results"]);
13
13
  export const RETENTION_CASCADE_EXEMPT = Object.freeze(["session-pollution", "session-capture-optout", "lineage.json"]);
14
+ function deepFreeze(value) {
15
+ if (typeof value === "object" && value !== null) {
16
+ for (const member of Object.values(value))
17
+ deepFreeze(member);
18
+ Object.freeze(value);
19
+ }
20
+ return value;
21
+ }
22
+ export const RETENTION_CASCADE = deepFreeze({
23
+ workflowJournalStore: { legs: [{ domain: "session-trees", step: 1, verb: "deleteRun", selects: "the journal of each terminal workflow run the session started, found through the run store's listByScope session filter while the run rows still exist (a running run is a live reference, so the tree is not deleted)" }] },
24
+ workflowRunStore: { legs: [{ domain: "session-trees", step: 2, verb: "deleteBySession", selects: "the session's terminal workflow runs in its scope; answers the run ids it deleted" }] },
25
+ backgroundAgentStore: { legs: [{ domain: "session-trees", step: 4, verb: "delete", selects: "each terminal row listBySession names for the session (a running or parked row is a live reference)" }] },
26
+ rosterStore: { legs: [{ domain: "session-trees", step: 5, verb: "releaseAgent", selects: "every agent whose roster entry names the session as its session" }] },
27
+ checkpointStore: {
28
+ legs: [
29
+ { domain: "session-trees", step: 6, verb: "deleteSessionCheckpoints", selects: "the session's checkpoint rows in any status, guarded by the session row's owner (so it runs while the row exists)" },
30
+ { domain: "checkpoints", verb: "reap", selects: "the scope's pending rows whose deadline is before the call's cutoff, flipped to expired (no row is deleted)" },
31
+ ],
32
+ },
33
+ toolResultStore: {
34
+ legs: [
35
+ { domain: "session-trees", step: 7, verb: "deleteBySession", selects: "the entries whose owner record names the session" },
36
+ { domain: "orphan-tool-results", verb: "deleteUnattributable", selects: "the entries stored with no owner record, older than the call's cutoff" },
37
+ ],
38
+ },
39
+ sessionPolicyStore: { legs: [{ domain: "session-trees", step: 8, verb: "deleteBySession", selects: "the session's permission rules" }] },
40
+ fileHistoryStore: { legs: [{ domain: "session-trees", step: 9, verb: "deleteBySession", selects: "the session's whole history scope (the scope is the session id): boundaries, version records, pristine baselines, and the blobs no other scope references" }] },
41
+ mailboxStore: {
42
+ legs: [
43
+ { domain: "session-trees", step: 3, verb: "drop", selects: "the box of each terminal background-agent row backgroundAgentStore.listBySession names for the session (the row's scope and handle), found through those rows while they still exist" },
44
+ { domain: "session-trees", step: 10, verb: "drop", fence: "retireRecipient", selects: "the session's box (its peer session handle) in the session owner's scope; the fence is the optional retireRecipient pair's — run first, it refuses deliveries from then on, and a store without the pair (the bundled two) keeps no recipient lifecycle and has its box dropped" },
45
+ ],
46
+ },
47
+ sessionStore: {
48
+ legs: [
49
+ { domain: "session-trees", step: 11, verb: "delete", selects: "the session's row and its whole log (a placed subagent row is its agent row's joint reap: release after a winning delete)" },
50
+ { domain: "checkpoints", verb: "unpin", selects: "the session each expired checkpoint pinned" },
51
+ ],
52
+ },
53
+ usageWindowStore: { exempt: "a usage-governance ledger keyed by principal: token and cost counts, no session content, bounded by the deployment's live window set" },
54
+ });
55
+ export const RETENTION_SESSION_TREE_STEPS = deepFreeze(Object.entries(RETENTION_CASCADE)
56
+ .flatMap(([store, row]) => ("legs" in row ? row.legs.filter((leg) => leg.domain === "session-trees").map((leg) => ({ store, ...leg })) : []))
57
+ .sort((a, b) => (a.step ?? 0) - (b.step ?? 0)));
14
58
  function codedError(code, message) {
15
59
  const e = new Error(message);
16
60
  e.code = code;
@@ -42,6 +42,11 @@ export declare const RETIRED_TASK_SPEC_KEYS: Readonly<Record<string, string>>;
42
42
  * the seat, owner `TaskSpec` (same code, same `TaskSpec.skills[].…` sentence). Kept out of {@link RETIRED_TASK_SPEC_KEYS}:
43
43
  * the spec's read judging these rows would read into the caller's `skills` entries before the seat's reader does. */
44
44
  export declare const RETIRED_SKILLS_SEAT_KEYS: Readonly<Record<string, string>>;
45
+ /** The RETIRED member of every bag that carries the compaction seats — a task's `compaction`, a `Runner.compactSession`
46
+ * request's `compaction`, a deployment's `contextSettings` overlay — keyed relative to the bag. The table the seats' one
47
+ * judgment reads (`compactionSeatsDefect`, `context-settings.ts`), each door with its own owner and code. Kept out of
48
+ * {@link RETIRED_TASK_SPEC_KEYS} for the reason the skills rows are: the seats have their own reader. */
49
+ export declare const RETIRED_COMPACTION_SEAT_KEYS: Readonly<Record<string, string>>;
45
50
  /** The RETIRED `ToolSpec` members — a spec still carrying one is refused by name (`config.deps_retired_key`) where the
46
51
  * factory reads the spec, never dropped unseen: a description the author wrote for one prompt shape would silently
47
52
  * never be shown. */
@@ -39,6 +39,9 @@ export const RETIRED_TASK_SPEC_KEYS = Object.freeze({
39
39
  export const RETIRED_SKILLS_SEAT_KEYS = Object.freeze({
40
40
  "skills[].manifest": "a skill's tools are its `allowedTools` / `disallowedTools` now — an allow-rule and a deny-rule source for the run the skill is activated in, never a fence; move `manifest.allowTools` to `allowedTools`. To fence tools write deny rules (or a delegated agent definition's `allowTools`); to fence write paths use session `allowDirs`",
41
41
  });
42
+ export const RETIRED_COMPACTION_SEAT_KEYS = Object.freeze({
43
+ enabled: "compaction is switched by two seats now — `autoCompact` (the passes the engine starts by itself: the turn-boundary pass at the window threshold, a prompt-too-long or guard recovery pass, the end-of-task summary) and `manualCompact` (the passes a caller asks for: `TaskStream.compact`, `Runner.compactSession`, `$.session.compact`). Write the seat you mean; `enabled: false` switched off both",
44
+ });
42
45
  export const RETIRED_TOOL_SPEC_KEYS = Object.freeze({
43
46
  descriptionClassic: 'a description\'s other forms are `descriptionVariants` now — the long form is `{ id: "classic", traits: { noneOf: ["lean_prompt"] }, text }`, chosen at mount by the run\'s prompt traits',
44
47
  });
@@ -24,10 +24,6 @@ export interface RuleOfferRead {
24
24
  /** Present when the batch's `uncoveredDetail` seat was not one well-formed row per counted segment and was left out
25
25
  * (the count is the truth source and an absent seat claims nothing); the caller owes that loss a disclosure. */
26
26
  readonly uncoveredDetailDropped?: true;
27
- /** Present when at least one batch member was read through the kind-less stored form (no `kind`, the four command
28
- * text members). A backend counts these to know whether its rows still carry the form that retirement line
29
- * RL-2164-kindless-batch-member waits on. */
30
- readonly kindlessForm?: true;
31
27
  }
32
28
  /** One element not read, and why. The rest of the list is read regardless. */
33
29
  export interface RuleOfferDropped {
@@ -62,29 +62,23 @@ function readBatch(value) {
62
62
  if (length === 0)
63
63
  return MALFORMED;
64
64
  const members = [];
65
- let kindless = false;
66
65
  for (let i = 0; i < length; i++) {
67
66
  const verdict = readBatchMember(rules[i]);
68
67
  if ("problem" in verdict)
69
68
  return verdict;
70
69
  members.push(verdict.member);
71
- if (verdict.kindlessForm === true)
72
- kindless = true;
73
70
  }
74
71
  if (typeof count !== "number" || !Number.isSafeInteger(count) || count < 0)
75
72
  return MALFORMED;
76
73
  const offer = { kind: "batch", rules: members, uncoveredSegments: count };
77
- const marks = kindless ? { kindlessForm: true } : {};
78
74
  if (detail === undefined)
79
- return { offer, ...marks };
75
+ return { offer };
80
76
  const rows = detailRowsOf(detail, count);
81
- return rows !== undefined ? { offer: { ...offer, uncoveredDetail: rows }, ...marks } : { offer, uncoveredDetailDropped: true, ...marks };
77
+ return rows !== undefined ? { offer: { ...offer, uncoveredDetail: rows } } : { offer, uncoveredDetailDropped: true };
82
78
  }
83
79
  function readBatchMember(value) {
84
80
  if (!isPlainRecord(value))
85
81
  return MALFORMED;
86
- if (!("kind" in value))
87
- return readKindlessBatchMember(value);
88
82
  const kind = wordOf(value.kind, RULE_OFFER_BATCH_MEMBER_KINDS);
89
83
  if (typeof kind !== "string")
90
84
  return kind;
@@ -105,16 +99,6 @@ function readBatchMember(value) {
105
99
  }
106
100
  }
107
101
  }
108
- function readKindlessBatchMember(value) {
109
- const rule = value.rule;
110
- const match = value.match;
111
- const command = value.command;
112
- const segment = value.segment;
113
- if (typeof rule !== "string" || typeof match !== "string" || typeof command !== "string" || typeof segment !== "string")
114
- return MALFORMED;
115
- const verdict = commandMember(rule, match, command, segment);
116
- return "problem" in verdict ? verdict : { ...verdict, kindlessForm: true };
117
- }
118
102
  function commandMember(rule, rawMatch, command, segment) {
119
103
  if (typeof rule !== "string")
120
104
  return MALFORMED;
@@ -152,7 +152,9 @@ export declare function announceClassifierRoleDefaulted(args: {
152
152
  * itself is never the count: the unavailable form is never counted; a reply with no verdict refused for want of a seat is
153
153
  * counted by the station's ruling path, not by this line.
154
154
  *
155
- * `detail: { toolName, toolCallId, cause, disposition, sessionId?, runId? }` — `cause` is why the classification did not rule,
155
+ * `detail: { toolName, toolCallId, cause, disposition, sessionId?, sourceSessionId?, agentId?, runId? }` — the session triple is the
156
+ * station's notice address (`noticeAddressOf`, leg-identity.ts: a delegated leg's notice goes to the tree's root and names its
157
+ * source leg); `cause` is why the classification did not rule,
156
158
  * an `AutoModeFallbackCause` word (`timeout` / `error`, or `parse_error` for a reply with no verdict). The sentence names the seat the station forked on — `leg` (this
157
159
  * run's own approval seat) or `ancestor` (the frozen approver of the ancestor layer whose classifier it was) — and, on a
158
160
  * timeout, the budget the classifier actually held (`budgetMs`, the decider's {@link AutoModeDecider.timeoutMs}; a
@@ -160,14 +162,20 @@ export declare function announceClassifierRoleDefaulted(args: {
160
162
  */
161
163
  export declare function classifierUnavailableNotice(args: ClassifierUnavailableInfo & ClassifierUnavailableStation & {
162
164
  sessionId?: string;
165
+ sourceSessionId?: string;
166
+ agentId?: string;
163
167
  runId?: string;
164
168
  }): EngineNotice;
165
169
  /** A classifier station's fork facts, wired once per leg: the route an ask the station hands on takes, and the
166
- * `classifier.unavailable` notice through the one throat. Both stations (the gate, the inherited fold) take it. */
170
+ * `classifier.unavailable` notice through the one throat, under the leg's notice admission when it has one (`admission`).
171
+ * Both stations (the gate, the inherited fold) take it. */
167
172
  export declare function classifierUnavailableSeat(args: ClassifierUnavailableStation & {
168
173
  route: ApprovalRoute;
169
174
  onNotice: RunnerDeps["onNotice"];
175
+ admission?: (notice: EngineNotice) => boolean;
170
176
  sessionId?: string;
177
+ sourceSessionId?: string;
178
+ agentId?: string;
171
179
  runId?: string;
172
180
  }): ClassifierUnavailableSeat;
173
181
  /** Which station forked (`leg` — the leg's gate, on its own approval seat; `ancestor` — an ancestor's frozen classifier in
@@ -129,13 +129,15 @@ export function classifierUnavailableNotice(args) {
129
129
  cause: args.cause,
130
130
  disposition: classifierUnavailableDispositionOf(args.route),
131
131
  ...(args.sessionId !== undefined ? { sessionId: args.sessionId } : {}),
132
+ ...(args.sourceSessionId !== undefined ? { sourceSessionId: args.sourceSessionId } : {}),
133
+ ...(args.agentId !== undefined ? { agentId: args.agentId } : {}),
132
134
  ...(args.runId !== undefined ? { runId: args.runId } : {}),
133
135
  },
134
136
  };
135
137
  }
136
138
  export function classifierUnavailableSeat(args) {
137
- const { route, onNotice, sessionId, runId, station, budgetMs } = args;
138
- return { route, onUnavailable: (info) => deliverEngineNotice(onNotice, classifierUnavailableNotice({ ...info, station, ...(budgetMs !== undefined ? { budgetMs } : {}), ...(sessionId !== undefined ? { sessionId } : {}), ...(runId !== undefined ? { runId } : {}) })) };
139
+ const { route, onNotice, admission, sessionId, sourceSessionId, agentId, runId, station, budgetMs } = args;
140
+ return { route, onUnavailable: (info) => deliverEngineNotice(onNotice, classifierUnavailableNotice({ ...info, station, ...(budgetMs !== undefined ? { budgetMs } : {}), ...(sessionId !== undefined ? { sessionId } : {}), ...(sourceSessionId !== undefined ? { sourceSessionId } : {}), ...(agentId !== undefined ? { agentId } : {}), ...(runId !== undefined ? { runId } : {}) }), admission) };
139
141
  }
140
142
  function classifierFallbackAnnouncer(args) {
141
143
  const announced = new Set();
@@ -1,6 +1,7 @@
1
1
  import { convertToLlm, uuidv7 } from "../../internal/harness.js";
2
2
  import { compactionFailureReason, compactionPassReport, DEFAULT_COMPACTION_INSTRUCTIONS, isCompactionManualCancel, manualCompactOutcomeOf, maybeCompact, mintCompactedEvent } from "../auto-compaction.js";
3
- import { contextOverlayFor } from "../context-settings.js";
3
+ import { compactionSeatsDefect, contextOverlayFor } from "../context-settings.js";
4
+ import { RETIRED_COMPACTION_SEAT_KEYS } from "../retired-keys.js";
4
5
  import { createRowSeat, promptCountOf } from "../mods/session-append.js";
5
6
  import { createCompactStation } from "../mods/session-compact.js";
6
7
  import { admitLegMods, legFacadeSeats } from "../mods/stations.js";
@@ -18,7 +19,7 @@ import { derivedLegBrain, sideCallBookOf } from "./side-call-account.js";
18
19
  import { acquireExistingSession, claimIdleSession, readPlainRequest, shownValue } from "./session-verb-doors.js";
19
20
  const VERB = "Runner.compactSession";
20
21
  const REQUEST_KEYS = new Set(["sessionId", "model", "instructions", "compaction", "compactionModel", "getApiKeyAndHeaders", "signal"]);
21
- const SETTINGS_KEYS = new Set(["enabled", "reserveTokens", "keepRecentTokens", "instructions", "clampTolerance"]);
22
+ const SETTINGS_KEYS = new Set(["manualCompact", "reserveTokens", "keepRecentTokens", "instructions", "clampTolerance", ...Object.keys(RETIRED_COMPACTION_SEAT_KEYS)]);
22
23
  export async function compactIdleSession(seats, request) {
23
24
  const req = screenCompactSessionRequest(request);
24
25
  const { deps } = seats;
@@ -90,7 +91,7 @@ async function compactOnSession(req, deps, session, resolved, named, legMods) {
90
91
  brain: derivedLegBrain(() => deps.brain, "compaction", book),
91
92
  ...(req.getApiKeyAndHeaders !== undefined ? { getApiKeyAndHeaders: req.getApiKeyAndHeaders } : {}),
92
93
  ...(thinking !== undefined ? { thinking } : {}),
93
- settings: legCompactionSettings(req.compaction !== undefined ? { compaction: req.compaction } : {}, overlay),
94
+ settings: legCompactionSettings(req.compaction !== undefined ? { compaction: req.compaction } : {}, overlay, "manualCompact"),
94
95
  customInstructions: req.instructions ?? req.compaction?.instructions ?? DEFAULT_COMPACTION_INSTRUCTIONS,
95
96
  ...(req.signal !== undefined ? { signal: req.signal, manualCancelSignal: req.signal } : {}),
96
97
  minTokens: 0,
@@ -193,9 +194,11 @@ function screenCompactSessionRequest(request) {
193
194
  };
194
195
  }
195
196
  function screenSettings(raw, bad) {
196
- const { enabled, reserveTokens, keepRecentTokens, instructions, clampTolerance } = readPlainRequest(raw, SETTINGS_KEYS, (what) => bad(`compaction: ${what}`));
197
- if (enabled !== undefined && typeof enabled !== "boolean")
198
- return bad(`compaction.enabled must be a boolean when given, got ${shownValue(enabled)}`);
197
+ const read = readPlainRequest(raw, SETTINGS_KEYS, (what) => bad(`compaction: ${what}`));
198
+ const seats = compactionSeatsDefect(read, "compaction");
199
+ if (seats !== undefined)
200
+ return bad(seats.sentence);
201
+ const { manualCompact, reserveTokens, keepRecentTokens, instructions, clampTolerance } = read;
199
202
  for (const [name, v] of [["reserveTokens", reserveTokens], ["keepRecentTokens", keepRecentTokens], ["clampTolerance", clampTolerance]]) {
200
203
  if (v !== undefined && typeof v !== "number")
201
204
  return bad(`compaction.${name} must be a number when given, got ${shownValue(v)}`);
@@ -203,7 +206,7 @@ function screenSettings(raw, bad) {
203
206
  if (instructions !== undefined && typeof instructions !== "string")
204
207
  return bad(`compaction.instructions must be a string when given, got ${shownValue(instructions)}`);
205
208
  return {
206
- ...(enabled !== undefined ? { enabled: enabled } : {}),
209
+ ...(manualCompact !== undefined ? { manualCompact: manualCompact } : {}),
207
210
  ...(reserveTokens !== undefined ? { reserveTokens: reserveTokens } : {}),
208
211
  ...(keepRecentTokens !== undefined ? { keepRecentTokens: keepRecentTokens } : {}),
209
212
  ...(instructions !== undefined ? { instructions: instructions } : {}),
@@ -4,7 +4,7 @@ import type { StaleToolResultOffloadOptions, TaskSpec } from "../types.js";
4
4
  import type { Context } from "../../internal/llm.js";
5
5
  import { type ToolResultStore } from "../tool-result-store.js";
6
6
  import type { Prepared, RunnerDepsSeat } from "./contracts.js";
7
- import { type ContextWindowOverlay } from "../context-settings.js";
7
+ import { type CompactionSeat, type ContextWindowOverlay } from "../context-settings.js";
8
8
  import { type CompactionSettings } from "../../internal/harness.js";
9
9
  /**
10
10
  * The maybeCompact call arguments that MUST be assembled identically on all three
@@ -159,10 +159,10 @@ export declare function legContextOverlayOption(prepared: Prepared, runner: Runn
159
159
  * The compaction SETTINGS a pass runs under — the assembly all three lanes and the out-of-run `Runner.compactSession` share.
160
160
  *
161
161
  * `{ ...DEFAULT_COMPACTION_SETTINGS, ...spec.compaction }` was hand-copied at each lane, and it is where the
162
- * deployment's live `enabled` declaration belongs: `maybeCompact` has exactly one enablement gate (it reads
163
- * `settings.enabled`), so folding the overlay in HERE makes the deployment's switch reach the boundary pass,
164
- * the recovery pass and the end-of-task summary by one edit instead of three, and keeps "who decides whether
165
- * compaction runs" a single expression ({@link compactionEnabled}: the request authored it > the deployment
166
- * declared it > on).
162
+ * deployment's live seat declarations belong: `maybeCompact` has exactly one enablement gate (it reads
163
+ * `settings.enabled`, the pass's own), so resolving it HERE from the seat of the pass the lane runs — `autoCompact`
164
+ * for the boundary's own pass, the recovery pass and the end-of-task summary, `manualCompact` for a requested one —
165
+ * keeps "who decides whether this pass runs" a single expression ({@link compactionEnabled}: the request authored the
166
+ * seat > the deployment declared it > on). The two seats themselves do not ride the settings: the pass reads its gate.
167
167
  */
168
- export declare function legCompactionSettings(spec: Pick<TaskSpec, "compaction">, overlay: ContextWindowOverlay | undefined): CompactionSettings;
168
+ export declare function legCompactionSettings(spec: Pick<TaskSpec, "compaction">, overlay: ContextWindowOverlay | undefined, seat: CompactionSeat): CompactionSettings;
@@ -121,6 +121,7 @@ export function legContextOverlayOption(prepared, runner) {
121
121
  const overlay = contextOverlayFor(runner.deps.contextSettings, prepared.harness.getModelRef(), runner.deps);
122
122
  return overlay !== undefined ? { contextOverlay: overlay } : {};
123
123
  }
124
- export function legCompactionSettings(spec, overlay) {
125
- return { ...DEFAULT_COMPACTION_SETTINGS, ...spec.compaction, enabled: compactionEnabled(spec.compaction?.enabled, overlay) };
124
+ export function legCompactionSettings(spec, overlay, seat) {
125
+ const { autoCompact: _auto, manualCompact: _manual, ...members } = spec.compaction ?? {};
126
+ return { ...DEFAULT_COMPACTION_SETTINGS, ...members, enabled: compactionEnabled(seat, spec.compaction, overlay) };
126
127
  }