@sema-agent/core 7.72.0 → 7.73.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 (256) hide show
  1. package/CHANGELOG.md +319 -0
  2. package/dist/agents/inherited-tool-pool.d.ts +26 -1
  3. package/dist/agents/inherited-tool-pool.js +46 -2
  4. package/dist/agents/parked-resume-drive.d.ts +10 -0
  5. package/dist/agents/parked-resume-drive.js +9 -0
  6. package/dist/agents/retain-ledger.d.ts +3 -0
  7. package/dist/agents/send-message-tool.js +1 -0
  8. package/dist/agents/send-user-message-tool.d.ts +12 -0
  9. package/dist/agents/send-user-message-tool.js +67 -0
  10. package/dist/agents/subagent-steps.d.ts +9 -0
  11. package/dist/agents/subagent-steps.js +38 -0
  12. package/dist/agents/subagent.d.ts +2 -0
  13. package/dist/agents/subagent.js +43 -12
  14. package/dist/agents/verify.js +23 -8
  15. package/dist/agents/yield-adoption.js +3 -1
  16. package/dist/brain/anthropic.js +14 -9
  17. package/dist/brain/open-responses.js +4 -5
  18. package/dist/brain/openai.js +30 -23
  19. package/dist/brain/stream-engine.js +159 -151
  20. package/dist/core/actions-digest.d.ts +43 -0
  21. package/dist/core/actions-digest.js +22 -0
  22. package/dist/core/allow-entry.js +3 -3
  23. package/dist/core/auto-mode.d.ts +7 -9
  24. package/dist/core/auto-mode.js +114 -8
  25. package/dist/core/checkpoint-features.d.ts +3 -2
  26. package/dist/core/checkpoint-features.js +1 -1
  27. package/dist/core/checkpoint-rekey.d.ts +1 -1
  28. package/dist/core/checkpoint-rekey.js +6 -1
  29. package/dist/core/checkpoint-requirements.d.ts +23 -3
  30. package/dist/core/checkpoint-requirements.js +5 -1
  31. package/dist/core/checkpoint-row-verdict.js +7 -1
  32. package/dist/core/checkpoint-store.d.ts +24 -2
  33. package/dist/core/checkpoint-store.js +1 -0
  34. package/dist/core/child-clamp-seats.d.ts +15 -0
  35. package/dist/core/child-clamp-seats.js +15 -0
  36. package/dist/core/delegation-frames.d.ts +1 -0
  37. package/dist/core/delegation-frames.js +1 -1
  38. package/dist/core/engine-capabilities.d.ts +5 -1
  39. package/dist/core/engine-capabilities.js +1 -1
  40. package/dist/core/engine-notice.d.ts +30 -22
  41. package/dist/core/engine-version.js +1 -1
  42. package/dist/core/entries-not-applied.d.ts +19 -7
  43. package/dist/core/entries-not-applied.js +33 -1
  44. package/dist/core/governance-codes.d.ts +7 -1
  45. package/dist/core/governance-codes.js +13 -5
  46. package/dist/core/hooks.d.ts +3 -0
  47. package/dist/core/hooks.js +1 -0
  48. package/dist/core/host-instance.d.ts +23 -0
  49. package/dist/core/host-instance.js +69 -0
  50. package/dist/core/instruction-preview.d.ts +63 -0
  51. package/dist/core/instruction-preview.js +406 -0
  52. package/dist/core/leg-budget.d.ts +26 -0
  53. package/dist/core/leg-budget.js +9 -0
  54. package/dist/core/leg-identity.d.ts +51 -1
  55. package/dist/core/leg-identity.js +45 -2
  56. package/dist/core/manager-launch-check.d.ts +48 -0
  57. package/dist/core/manager-launch-check.js +64 -0
  58. package/dist/core/mcp-call-meta.d.ts +2 -2
  59. package/dist/core/mcp-injection-drop.d.ts +20 -10
  60. package/dist/core/mcp-injection-drop.js +9 -3
  61. package/dist/core/mcp-server-spec.d.ts +2 -1
  62. package/dist/core/member-outcome.d.ts +3 -2
  63. package/dist/core/member-outcome.js +1 -1
  64. package/dist/core/memory-engine/deletion-record.d.ts +46 -0
  65. package/dist/core/memory-engine/deletion-record.js +96 -0
  66. package/dist/core/memory-engine/engine.js +24 -16
  67. package/dist/core/memory-engine/file-backend.js +7 -5
  68. package/dist/core/memory-engine/projection-ledger.d.ts +1 -1
  69. package/dist/core/memory-engine/projection-ledger.js +1 -1
  70. package/dist/core/memory-engine/scope-contract.d.ts +18 -13
  71. package/dist/core/memory-engine/scope-contract.js +18 -18
  72. package/dist/core/memory-engine/sync-client.js +26 -6
  73. package/dist/core/memory-engine/sync.d.ts +20 -2
  74. package/dist/core/memory-engine/sync.js +18 -17
  75. package/dist/core/mode-policy.d.ts +21 -6
  76. package/dist/core/mode-policy.js +15 -6
  77. package/dist/core/own-property-receipt.js +11 -4
  78. package/dist/core/parent-spec-seat.d.ts +13 -11
  79. package/dist/core/parent-spec-seat.js +13 -9
  80. package/dist/core/peer-seat.js +3 -3
  81. package/dist/core/peer-task-store.d.ts +365 -0
  82. package/dist/core/peer-task-store.js +682 -0
  83. package/dist/core/permission-rule-consent.js +6 -11
  84. package/dist/core/permission-rule-model.d.ts +27 -0
  85. package/dist/core/permission-rule-model.js +33 -5
  86. package/dist/core/permission-rule-provider.d.ts +35 -33
  87. package/dist/core/permission-rule-provider.js +38 -295
  88. package/dist/core/permission-rule-store.d.ts +181 -8
  89. package/dist/core/permission-rule-store.js +420 -17
  90. package/dist/core/permission-rule-sync.js +15 -1
  91. package/dist/core/project-seat.d.ts +55 -0
  92. package/dist/core/project-seat.js +96 -0
  93. package/dist/core/protocol-http-auth.d.ts +3 -2
  94. package/dist/core/protocol-http-auth.js +26 -18
  95. package/dist/core/remote-env.d.ts +4 -4
  96. package/dist/core/retired-keys.js +1 -0
  97. package/dist/core/rule-offer-read.d.ts +1 -1
  98. package/dist/core/rule-offer-read.js +32 -4
  99. package/dist/core/run-ledger-seat.d.ts +66 -0
  100. package/dist/core/run-ledger-seat.js +70 -0
  101. package/dist/core/run-ledger.d.ts +332 -0
  102. package/dist/core/run-ledger.js +550 -0
  103. package/dist/core/runner/checkpoint-scope.d.ts +13 -3
  104. package/dist/core/runner/checkpoint-scope.js +12 -4
  105. package/dist/core/runner/construction-doors.js +6 -0
  106. package/dist/core/runner/contracts.d.ts +21 -5
  107. package/dist/core/runner/delegation-owner.d.ts +30 -0
  108. package/dist/core/runner/delegation-owner.js +20 -4
  109. package/dist/core/runner/finish-reason-seat.js +4 -2
  110. package/dist/core/runner/leg-frame.js +3 -0
  111. package/dist/core/runner/nested-memory-lane.d.ts +22 -5
  112. package/dist/core/runner/nested-memory-lane.js +91 -30
  113. package/dist/core/runner/person-path-rows.d.ts +21 -16
  114. package/dist/core/runner/person-path-rows.js +80 -15
  115. package/dist/core/runner/prepare-caps-and-workflow.js +98 -88
  116. package/dist/core/runner/prepare-config-doors.d.ts +1 -0
  117. package/dist/core/runner/prepare-config-doors.js +5 -3
  118. package/dist/core/runner/prepare-context-lane.js +1 -0
  119. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  120. package/dist/core/runner/prepare-delegation-surface.js +6 -0
  121. package/dist/core/runner/prepare-execution-env.d.ts +3 -3
  122. package/dist/core/runner/prepare-hands-readface.d.ts +5 -2
  123. package/dist/core/runner/prepare-hands-readface.js +12 -1
  124. package/dist/core/runner/prepare-inherited-gate.d.ts +6 -3
  125. package/dist/core/runner/prepare-inherited-gate.js +13 -5
  126. package/dist/core/runner/prepare-run-refs.d.ts +1 -1
  127. package/dist/core/runner/prepare-run-refs.js +3 -2
  128. package/dist/core/runner/prepare-suspend-saga.d.ts +6 -2
  129. package/dist/core/runner/prepare-suspend-saga.js +4 -2
  130. package/dist/core/runner/prepare-task.js +36 -27
  131. package/dist/core/runner/prepare-turn-wiring.d.ts +4 -3
  132. package/dist/core/runner/prepare-turn-wiring.js +2 -1
  133. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  134. package/dist/core/runner/prepare-wiring-manifest.js +5 -2
  135. package/dist/core/runner/resume-apply.js +11 -5
  136. package/dist/core/runner/resume-review-outcome.d.ts +3 -0
  137. package/dist/core/runner/resume-review-outcome.js +24 -1
  138. package/dist/core/runner/run-harness-handlers.js +3 -0
  139. package/dist/core/runner/run-identity-wiring.js +3 -2
  140. package/dist/core/runner/run-leg.js +3 -0
  141. package/dist/core/runner/run-notification-lane.js +20 -1
  142. package/dist/core/runner/run-settle-and-teardown.js +21 -12
  143. package/dist/core/runner/run-stop-and-final-verify.js +6 -0
  144. package/dist/core/runner/run-telemetry-and-budget-seats.js +1 -1
  145. package/dist/core/runner/runtask.d.ts +6 -2
  146. package/dist/core/runner/runtask.js +21 -9
  147. package/dist/core/runner/shell-env-withheld.d.ts +3 -2
  148. package/dist/core/runner/shell-env-withheld.js +1 -2
  149. package/dist/core/runner/stop-tail-notice.d.ts +10 -2
  150. package/dist/core/runner/stop-tail-notice.js +9 -2
  151. package/dist/core/runner/stream-settle-backstop.d.ts +1 -0
  152. package/dist/core/runner/stream-settle-backstop.js +1 -0
  153. package/dist/core/runner/task-start-doors.js +6 -3
  154. package/dist/core/runner/terminal-account.d.ts +6 -1
  155. package/dist/core/runner/terminal-account.js +16 -1
  156. package/dist/core/runner/unreadable-person-rows.d.ts +2 -1
  157. package/dist/core/runner-deps.d.ts +13 -10
  158. package/dist/core/secret-env.d.ts +53 -37
  159. package/dist/core/secret-env.js +44 -47
  160. package/dist/core/session-checkout.d.ts +3 -0
  161. package/dist/core/session-checkout.js +1 -0
  162. package/dist/core/session-store.d.ts +12 -6
  163. package/dist/core/session-store.js +26 -6
  164. package/dist/core/session.d.ts +31 -8
  165. package/dist/core/store-contracts/checkpoint-store-contract.js +10 -0
  166. package/dist/core/store-contracts/peer-task-store-contract.d.ts +21 -0
  167. package/dist/core/store-contracts/peer-task-store-contract.js +516 -0
  168. package/dist/core/store-contracts/session-store-contract.d.ts +15 -2
  169. package/dist/core/store-contracts/session-store-contract.js +87 -3
  170. package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +19 -1
  171. package/dist/core/store-contracts/workflow-journal-store-contract.js +89 -1
  172. package/dist/core/task-event.d.ts +10 -3
  173. package/dist/core/task-notification.d.ts +96 -10
  174. package/dist/core/task-notification.js +129 -5
  175. package/dist/core/task-registry-shared.d.ts +12 -1
  176. package/dist/core/task-registry-shared.js +3 -1
  177. package/dist/core/task-registry-workflow.d.ts +1 -1
  178. package/dist/core/task-registry-workflow.js +9 -1
  179. package/dist/core/task-registry.d.ts +39 -2
  180. package/dist/core/task-registry.js +76 -12
  181. package/dist/core/task-result.d.ts +13 -0
  182. package/dist/core/task-spec-members.d.ts +3 -1
  183. package/dist/core/task-spec-members.js +11 -3
  184. package/dist/core/task-spec.d.ts +48 -22
  185. package/dist/core/tool-catalog-entries.js +2 -0
  186. package/dist/core/tool-mount-facts.d.ts +1 -1
  187. package/dist/core/tool-mount-facts.js +1 -0
  188. package/dist/core/tool-mount-plan.d.ts +3 -1
  189. package/dist/core/tool-mount-plan.js +6 -0
  190. package/dist/core/tool-mount-static.d.ts +1 -1
  191. package/dist/core/tool-mount-static.js +4 -2
  192. package/dist/core/tool-result-store.d.ts +19 -2
  193. package/dist/core/tool-result-store.js +51 -2
  194. package/dist/core/tool-spec.d.ts +9 -2
  195. package/dist/core/user-attachment.d.ts +5 -1
  196. package/dist/core/user-attachment.js +14 -7
  197. package/dist/core/wiring-manifest.d.ts +26 -20
  198. package/dist/core/wiring-manifest.js +7 -3
  199. package/dist/core/workflow-journal-store.d.ts +53 -10
  200. package/dist/core/workflow-journal-store.js +27 -4
  201. package/dist/core/workflow-run-store-contract.js +16 -0
  202. package/dist/core/workflow-run-store.d.ts +9 -7
  203. package/dist/core/workflow-run-store.js +4 -1
  204. package/dist/engine/execution-env/node-execution-env.js +3 -1
  205. package/dist/engine/harness/types.d.ts +24 -1
  206. package/dist/engine/harness/types.js +10 -0
  207. package/dist/engine/llm/types.d.ts +5 -7
  208. package/dist/engine/lsp/node-lsp-manager.js +2 -1
  209. package/dist/engine/session/import-validate.js +6 -1
  210. package/dist/engine/session/session.d.ts +15 -2
  211. package/dist/engine/session/session.js +34 -4
  212. package/dist/index.d.ts +18 -7
  213. package/dist/index.js +13 -4
  214. package/dist/orchestration/run-workflow-tool.js +40 -32
  215. package/dist/orchestration/workflow-park-adoption.d.ts +51 -12
  216. package/dist/orchestration/workflow-park-adoption.js +47 -12
  217. package/dist/orchestration/workflow-stop.d.ts +128 -0
  218. package/dist/orchestration/workflow-stop.js +156 -0
  219. package/dist/orchestration/workflow.d.ts +30 -6
  220. package/dist/orchestration/workflow.js +117 -55
  221. package/dist/prompts/manager-recipe.d.ts +18 -0
  222. package/dist/prompts/manager-recipe.js +24 -0
  223. package/dist/stores/file/permission-rule-store.d.ts +3 -1
  224. package/dist/stores/file/permission-rule-store.js +0 -1
  225. package/dist/stores/file/workflow-journal-store.d.ts +16 -3
  226. package/dist/stores/file/workflow-journal-store.js +93 -5
  227. package/dist/stores/file/workflow-run-store.d.ts +1 -1
  228. package/dist/tools/fs/file-write-check.js +9 -3
  229. package/dist/tools/fs/index.d.ts +8 -7
  230. package/dist/tools/fs/index.js +4 -4
  231. package/dist/tools/fs/read-deny-home.d.ts +1 -1
  232. package/dist/tools/fs/read-deny-home.js +5 -5
  233. package/dist/tools/fs/read-deny.d.ts +33 -8
  234. package/dist/tools/fs/read-deny.js +114 -25
  235. package/dist/tools/fs/safety.d.ts +4 -1
  236. package/dist/tools/fs/safety.js +4 -2
  237. package/dist/tools/fs/shell-read-check.d.ts +9 -2
  238. package/dist/tools/fs/shell-read-check.js +96 -14
  239. package/dist/tools/fs/shell-read-establish.d.ts +9 -0
  240. package/dist/tools/fs/shell-read-establish.js +21 -11
  241. package/dist/tools/fs/shell-read-judge.d.ts +13 -1
  242. package/dist/tools/fs/shell-read-judge.js +26 -7
  243. package/dist/tools/fs/shell-read-plan.d.ts +5 -0
  244. package/dist/tools/fs/shell-read-write-targets.js +17 -9
  245. package/package.json +2 -2
  246. package/test/export-surface.snapshot.json +131 -1
  247. package/wire-changes/answers/core-stores-sql@7.73.0.json +28 -0
  248. package/wire-changes/answers/core@7.73.0.json +216 -0
  249. package/wire-changes/answers/mods-kernel@7.73.0.json +7 -0
  250. package/wire-changes/answers/primitives@7.73.0.json +12 -0
  251. package/wire-changes/answers/wiki-gate@7.73.0.json +7 -0
  252. package/wire-changes/core-stores-sql@7.73.0.json +326 -0
  253. package/wire-changes/core@7.73.0.json +6480 -0
  254. package/wire-changes/mods-kernel@7.73.0.json +147 -0
  255. package/wire-changes/primitives@7.73.0.json +227 -0
  256. package/wire-changes/wiki-gate@7.73.0.json +145 -0
@@ -0,0 +1,64 @@
1
+ export const MANAGER_LAUNCH_ITEMS = Object.freeze([
2
+ "background_delegation",
3
+ "report_tool",
4
+ "read_hands",
5
+ "worker_transcript",
6
+ "isolated_checks",
7
+ "worker_write_approval",
8
+ "task_list",
9
+ ]);
10
+ const REFUSING = new Set(["background_delegation", "report_tool"]);
11
+ const NARROWED = {
12
+ background_delegation: "it cannot dispatch workers that report back, so it cannot direct anyone",
13
+ report_tool: "it has no report tool, so nothing it concludes reaches the person with the engine's ledger beside it",
14
+ read_hands: "it cannot read the work itself; it can only send workers to look",
15
+ worker_transcript: "it cannot read a worker's record; it sees only what each worker says",
16
+ isolated_checks: "checks that need running something go to a verification worker (no isolated environment for the manager's own checks)",
17
+ worker_write_approval: "a worker's writes will be refused: nobody on this run can approve them",
18
+ task_list: "the plan cannot be kept as a shared task list",
19
+ };
20
+ const ITEM_WORDS = {
21
+ background_delegation: "dispatching workers that report back",
22
+ report_tool: "the report tool",
23
+ read_hands: "reading the work",
24
+ worker_transcript: "reading a worker's record",
25
+ isolated_checks: "running checks in isolation",
26
+ worker_write_approval: "an approval route for the workers' writes",
27
+ task_list: "a shared task list",
28
+ };
29
+ export function managerLaunchNarrowedNotice(c, ids) {
30
+ return { code: "task.manager_launch_narrowed", message: managerLaunchCheckSentence(c), detail: { ...ids, launch: c } };
31
+ }
32
+ export function managerLaunchCheck(facts) {
33
+ const items = MANAGER_LAUNCH_ITEMS.map((item) => {
34
+ const v = facts[item];
35
+ const state = v === true ? "ok" : v === false ? "missing" : "unknown";
36
+ return Object.freeze({ item, state, ...(state === "missing" ? { means: NARROWED[item] } : {}) });
37
+ });
38
+ const missing = items.filter((i) => i.state === "missing");
39
+ const verdict = missing.some((i) => REFUSING.has(i.item)) ? "refused" : missing.length > 0 ? "narrowed" : "ready";
40
+ return Object.freeze({ verdict, items: Object.freeze(items) });
41
+ }
42
+ export function managerLaunchFactsOf(r) {
43
+ const has = (...names) => names.every((n) => r.names.has(n));
44
+ return {
45
+ background_delegation: r.backgroundAgents === undefined ? undefined : r.backgroundAgents && r.completionLane,
46
+ report_tool: has("SendUserMessage"),
47
+ read_hands: has("Read", "Grep", "Glob"),
48
+ worker_transcript: has("AgentTranscript"),
49
+ isolated_checks: false,
50
+ worker_write_approval: r.approver ? true : !r.parkStore && r.oneShot ? false : undefined,
51
+ task_list: has("TaskCreate", "TaskList"),
52
+ };
53
+ }
54
+ export function managerLaunchCheckSentence(c) {
55
+ const missing = c.items.filter((i) => i.state === "missing");
56
+ const unknown = c.items.filter((i) => i.state === "unknown").map((i) => ITEM_WORDS[i.item]);
57
+ const said = missing.map((i) => i.means).join("; ");
58
+ const unread = unknown.length > 0 ? ` Not read here: ${unknown.join(", ")}.` : "";
59
+ if (c.verdict === "ready")
60
+ return `The launch check found everything this run needs.${unread}`;
61
+ if (c.verdict === "refused")
62
+ return `This run declares a member ledger but cannot do that job — ${said}.${unread}`;
63
+ return `This run starts narrowed — ${said}.${unread}`;
64
+ }
@@ -45,14 +45,14 @@ export declare const MCP_CALLER_META_KEY = "sema/caller";
45
45
  * Who is calling: the identity facts of the leg a request is sent for, every one a value the engine already mints for the leg's own
46
46
  * frames (none is minted for this record). Frozen, no prototype.
47
47
  * - `taskId` — the leg's task id, minted once at prepare (`legTaskIdOf`): the value `TaskResult.taskId` and `task_progress.taskId` carry,
48
- * whatever that reading answers on this run (the leg's registry row id, else the host's task id, else the leg's session id).
48
+ * whatever that reading answers on this run (the leg's registry row id; on a ledger run, the host's task id if it gave one other than the session id, the id the parked row recorded on a resume, otherwise the minted `rl-…` id; else the host's task id or the leg's session id).
49
49
  * - `runId` — this invocation of the engine (`Prepared.runId`): new on every run, a resume included.
50
50
  * - `rootSessionId` — the delegation tree's root session (`rootAnchorOf`): the leg's own session on a top-level leg.
51
51
  * - `parentTaskId` — the spawning leg's task id (`RunInternals.parentTaskId`, the value `task_progress.parentTaskId` carries); absent on a
52
52
  * leg nobody spawned under a known task.
53
53
  * Built once per leg and run, at prepare: every call and fetch of that run carries the same record. No principal, path, model or display
54
54
  * name rides it. Session ids do: `taskId` is the leg's own session id wherever that is its task id (a foreground child, a workflow member
55
- * or a top-level leg handed no task id), and `rootSessionId` is the tree root's session — independent of `sessionMetaKey`.
55
+ * or a non-ledger top-level leg handed no task id; on a ledger run the task id is the host's if it gave one other than the session id, the id the parked row recorded on a resume, otherwise the minted `rl-…` one), and `rootSessionId` is the tree root's session — independent of `sessionMetaKey`.
56
56
  */
57
57
  export type McpCaller = Readonly<{
58
58
  taskId: string;
@@ -41,9 +41,12 @@ import type { EngineNotice } from "./engine-notice.js";
41
41
  * · `credentials_not_carried` — a request does not carry an MCP server's credentials, so the
42
42
  * deployment has to mount this server itself: the recovery is the
43
43
  * administrator's configuration or the entry without its credentials;
44
- * `field` names the credentials key when the host knows it.
44
+ * `field` names the credentials key when the host knows it;
45
+ * · `name_already_mounted` — an agent definition declared an MCP server whose normalized
46
+ * namespace is already mounted on the run (the run's server stays
47
+ * in use; the agent's duplicate entry was not mounted).
45
48
  */
46
- export declare const MCP_INJECTION_DROP_REASONS: readonly ["malformed_entry", "name_reserved_by_deployment", "gate_closed", "over_cap", "key_retired", "credentials_not_carried"];
49
+ export declare const MCP_INJECTION_DROP_REASONS: readonly ["malformed_entry", "name_reserved_by_deployment", "gate_closed", "over_cap", "key_retired", "credentials_not_carried", "name_already_mounted"];
47
50
  export type McpInjectionDropReason = (typeof MCP_INJECTION_DROP_REASONS)[number];
48
51
  /**
49
52
  * The user-facing sentence per reason — the disposition table over {@link MCP_INJECTION_DROP_REASONS}
@@ -57,9 +60,10 @@ export declare const MCP_INJECTION_DROP_TEXT: {
57
60
  readonly over_cap: "the request named more MCP servers than this deployment mounts per leg — trim the list";
58
61
  readonly key_retired: "its declaration carries a configuration key this service no longer accepts — update the application that sent this entry, or remove that key from the entry, then start a new session";
59
62
  readonly credentials_not_carried: "requests do not carry credentials for MCP servers, so the deployment has to mount this one — ask an administrator to configure it in the deployment, or remove the credentials from this entry";
63
+ readonly name_already_mounted: "another server of that name is already mounted on this run and stays in use — rename the server in this agent's configuration, or remove the duplicate";
60
64
  };
61
65
  export type DropTextCoversEveryReason = AssertAllKeysHandled<Exclude<McpInjectionDropReason, keyof typeof MCP_INJECTION_DROP_TEXT>>;
62
- /** What a host knows at the drop site — facts only, no words of the engine's vocabulary composed. */
66
+ /** What a host (or spawn merge) knows at the drop site — facts only, no words of the engine's vocabulary composed. */
63
67
  export interface McpInjectionDropFacts {
64
68
  /** The session whose injection carried the entry — the notice's routing key, required (see module note). */
65
69
  readonly sessionId: string;
@@ -72,20 +76,26 @@ export interface McpInjectionDropFacts {
72
76
  * carried in `detail` only.
73
77
  */
74
78
  readonly field?: string;
79
+ /**
80
+ * Optional: the agent definition that declared this server entry (for drops in host intake of
81
+ * agent-level MCP declarations and spawn-time collisions with a server already mounted on the run).
82
+ * Carried in `detail.entries[0].agent` and named in the message when non-empty.
83
+ */
84
+ readonly agent?: string;
75
85
  }
76
86
  /**
77
- * Compose the notice for one request-lane MCP entry that was not mounted, from a host's facts: `config.entries_not_applied`,
87
+ * Compose the notice for one MCP server declaration that was not mounted, from drop facts: `config.entries_not_applied`,
78
88
  * kind `mcp_injection_dropped` (until 7.70.0 its own code, `mcp.injection_dropped`).
79
89
  *
80
- * @contract mcp.injection_dropped.single_mint — the notice for a dropped request-lane MCP entry is composed by CORE
81
- * from a host's drop FACTS (session, server name, one of the closed reasons, optionally the bad field); a
82
- * host never spells the code, the audience or the sentence, and a fact outside the vocabulary (an
90
+ * @contract mcp.injection_dropped.single_mint — the notice for a dropped MCP server declaration is composed by CORE
91
+ * from drop FACTS (session, server name, one of the closed reasons, optionally the bad field and declaring agent); a
92
+ * caller never spells the code, the audience or the sentence, and a fact outside the vocabulary (an
83
93
  * unlisted reason word, an empty session or server name) is refused at the mint with a `TypeError`
84
94
  * rather than shaped into a notice that would route nowhere or read as an unknown word downstream.
85
95
  *
86
- * `detail: { kind: "mcp_injection_dropped", entries: [{ entry, reason, field? }], count: 1, identity, sessionId }` — `entry` is the
87
- * server's name as the user spelled it, `reason` one of {@link MCP_INJECTION_DROP_REASONS}, `field` present only when the host
88
- * supplied a non-empty one; `sessionId` is lifted onto the typed key by {@link import("./engine-notice.js").deliverEngineNotice},
96
+ * `detail: { kind: "mcp_injection_dropped", entries: [{ entry, reason, field?, agent? }], count: 1, identity, sessionId }` — `entry` is the
97
+ * server's name as spelled, `reason` one of {@link MCP_INJECTION_DROP_REASONS}, `field` and `agent` present only when supplied as
98
+ * non-empty strings; `sessionId` is lifted onto the typed key by {@link import("./engine-notice.js").deliverEngineNotice},
89
99
  * the one throat, so the two spellings cannot disagree.
90
100
  */
91
101
  export declare function mcpInjectionDroppedNotice(facts: McpInjectionDropFacts): EngineNotice;
@@ -6,6 +6,7 @@ export const MCP_INJECTION_DROP_REASONS = Object.freeze([
6
6
  "over_cap",
7
7
  "key_retired",
8
8
  "credentials_not_carried",
9
+ "name_already_mounted",
9
10
  ]);
10
11
  export const MCP_INJECTION_DROP_TEXT = {
11
12
  malformed_entry: "its declaration could not be read — fix the entry and start a new session",
@@ -14,6 +15,7 @@ export const MCP_INJECTION_DROP_TEXT = {
14
15
  over_cap: "the request named more MCP servers than this deployment mounts per leg — trim the list",
15
16
  key_retired: "its declaration carries a configuration key this service no longer accepts — update the application that sent this entry, or remove that key from the entry, then start a new session",
16
17
  credentials_not_carried: "requests do not carry credentials for MCP servers, so the deployment has to mount this one — ask an administrator to configure it in the deployment, or remove the credentials from this entry",
18
+ name_already_mounted: "another server of that name is already mounted on this run and stays in use — rename the server in this agent's configuration, or remove the duplicate",
17
19
  };
18
20
  const SENTENCE_NAMES_FIELD = {
19
21
  malformed_entry: true,
@@ -22,10 +24,11 @@ const SENTENCE_NAMES_FIELD = {
22
24
  over_cap: false,
23
25
  key_retired: true,
24
26
  credentials_not_carried: true,
27
+ name_already_mounted: false,
25
28
  };
26
29
  const isReason = (x) => typeof x === "string" && MCP_INJECTION_DROP_REASONS.includes(x);
27
30
  export function mcpInjectionDroppedNotice(facts) {
28
- const { sessionId, server, reason, field } = facts;
31
+ const { sessionId, server, reason, field, agent } = facts;
29
32
  if (typeof sessionId !== "string" || sessionId.length === 0) {
30
33
  throw new TypeError("mcpInjectionDroppedNotice: sessionId is required — a user-audience notice with no session routes nowhere");
31
34
  }
@@ -36,10 +39,13 @@ export function mcpInjectionDroppedNotice(facts) {
36
39
  throw new TypeError(`mcpInjectionDroppedNotice: reason ${JSON.stringify(reason)} is not one of ${MCP_INJECTION_DROP_REASONS.join("/")}`);
37
40
  }
38
41
  const fieldSeat = typeof field === "string" && field.length > 0 ? { field } : {};
42
+ const agentName = typeof agent === "string" && agent.length > 0 ? agent : undefined;
43
+ const agentSeat = agentName !== undefined ? { agent: agentName } : {};
39
44
  const where = SENTENCE_NAMES_FIELD[reason] && typeof field === "string" && field.length > 0 ? ` (field \`${field}\`)` : "";
45
+ const source = agentName !== undefined ? `declared by agent "${agentName}"` : "from this request";
40
46
  return {
41
47
  code: "config.entries_not_applied",
42
- message: `MCP server "${server}" from this request was not mounted: ${MCP_INJECTION_DROP_TEXT[reason]}${where}.`,
43
- detail: { ...entriesNotAppliedDetail("mcp_injection_dropped", [{ entry: server, reason, ...fieldSeat }]), sessionId },
48
+ message: `MCP server "${server}" ${source} was not mounted: ${MCP_INJECTION_DROP_TEXT[reason]}${where}.`,
49
+ detail: { ...entriesNotAppliedDetail("mcp_injection_dropped", [{ entry: server, reason, ...fieldSeat, ...agentSeat }]), sessionId },
44
50
  };
45
51
  }
@@ -216,7 +216,8 @@ export interface McpServerSpec {
216
216
  * spawned under a known task, the spawner's task id (`task_progress.parentTaskId`). One record per leg and run, built at its prepare, so
217
217
  * every call and fetch of the run — every attempt of one call included — carries the same; two legs on one pooled connection each send
218
218
  * their own. No principal, path or model rides it. Session ids do, with or without {@link sessionMetaKey}: `taskId` is the leg's own
219
- * session id wherever that is its task id (a foreground child, a workflow member or a top-level leg handed no `taskId`), and
219
+ * session id wherever that is its task id (a foreground child, a workflow member or a top-level leg handed no `taskId` that keeps no
220
+ * member ledger — one that keeps one runs as the task id the engine minted for it, `rl-…`), and
220
221
  * `rootSessionId` is the tree root's session (a top-level leg's own) — a deployment that must not let a server learn any session id does
221
222
  * not declare this for it. Absent or `false` ⇒ nothing is sent.
222
223
  *
@@ -44,7 +44,7 @@ export type MemberOutcomeWord = (typeof MEMBER_OUTCOMES)[number];
44
44
  /** Membership test for {@link MemberOutcomeWord} — the word crosses process boundaries on the completion frames and the stored rows. */
45
45
  export declare function isMemberOutcomeWord(v: unknown): v is MemberOutcomeWord;
46
46
  /** What kind of member a row is. Grows by a word when a new holder mints rows (a peer task, a nested workflow). */
47
- export declare const MEMBER_KINDS: readonly ["workflow_member", "subagent", "background_agent"];
47
+ export declare const MEMBER_KINDS: readonly ["workflow_member", "subagent", "background_agent", "workflow", "peer_task"];
48
48
  export type MemberKind = (typeof MEMBER_KINDS)[number];
49
49
  /**
50
50
  * What ended the run whose end stopped a member (the closed set of {@link MemberOutcome.runEnd}`.cause`). The five stop words are the
@@ -215,7 +215,8 @@ export type MemberFacts = {
215
215
  readonly runEnd?: MemberOutcome["runEnd"];
216
216
  readonly refused?: MemberRefusals;
217
217
  };
218
- /** The ONE mint of a member's outcome. `kind` / `provenance` are the holder's. The outcome comes back sealed ({@link sealMemberOutcome}). */
218
+ /** The ONE mint of a member's outcome. `kind` / `provenance` are the holder's; `kind` is carried as {@link isMemberOutcome} reads it
219
+ * (a string — a later release's word passes through). The outcome comes back sealed ({@link sealMemberOutcome}). */
219
220
  export declare function memberOutcomeOf(kind: MemberKind, provenance: "live" | "replayed", facts: MemberFacts): MemberOutcome;
220
221
  /**
221
222
  * A background agent row's outcome, as the task registry mints it at the settle that wins the row (first writer wins): the winning
@@ -6,7 +6,7 @@ const MEMBER_OUTCOME_SET = new Set(MEMBER_OUTCOMES);
6
6
  export function isMemberOutcomeWord(v) {
7
7
  return MEMBER_OUTCOME_SET.has(v);
8
8
  }
9
- export const MEMBER_KINDS = Object.freeze(["workflow_member", "subagent", "background_agent"]);
9
+ export const MEMBER_KINDS = Object.freeze(["workflow_member", "subagent", "background_agent", "workflow", "peer_task"]);
10
10
  export const RUN_END_CAUSES = Object.freeze(["turn_end", "one_shot_ceiling", "interrupt", "walltime", "turns", "budget", "signal"]);
11
11
  const RUN_END_CAUSE_SET = new Set(RUN_END_CAUSES);
12
12
  export function isRunEndCause(v) {
@@ -0,0 +1,46 @@
1
+ import type { EntryCustodyReport } from "./file-backend.js";
2
+ import type { MemoryBackend } from "./types.js";
3
+ /**
4
+ * A store's answer for one id it does not hold:
5
+ * - `never` — its record is whole and names no deletion of the id in this scope: the id is new to it;
6
+ * - `deleted` — its record names a deletion of the id in this scope; `rev` is the version deleted last, when carried;
7
+ * - `undecidable` — its record cannot say (the chain is damaged, an event id is contradicted, a deletion omits scope,
8
+ * the store keeps no custody face, or the read failed); `why` says which. `why` is the engine's sentence: every word in it
9
+ * the store wrote (an event id, a damage reason, a read's thrown text) went through `foreignLine` where it was put in.
10
+ */
11
+ export type DeletionRecord = {
12
+ readonly kind: "never";
13
+ } | {
14
+ readonly kind: "deleted";
15
+ readonly rev?: string;
16
+ } | {
17
+ readonly kind: "undecidable";
18
+ readonly why: string;
19
+ };
20
+ /** The precedence every reader of deletion evidence shares: a deletion the record names stands even when the rest of the
21
+ * record is impeached (a sound prefix proves it); otherwise an impeached record answers nothing; otherwise the id was
22
+ * never deleted. `deletedRev`: `undefined` = no deletion named, `null` = one named without its version. */
23
+ export declare function deletionRecordFrom(evidence: {
24
+ readonly deletedRev: string | null | undefined;
25
+ readonly sound: boolean;
26
+ readonly unsoundWhy?: string;
27
+ }): DeletionRecord;
28
+ /** The record one custody report (`custodyOf(id)`, the File store's or any backend's) gives for `id` in `scope`;
29
+ * `undefined` = the store has no custody face. A deletion event is a fact of its own scope (`scope` or legacy
30
+ * `from.scope`) and invisible from any other scope; one carrying no scope, or a contradicted `ev`, fails closed. */
31
+ export declare function deletionRecordOf(id: string, custody: EntryCustodyReport | undefined, scope: string): DeletionRecord;
32
+ /** The store's answer for an id a memory file carries in `scope` that no baseline of the mount names, given where the
33
+ * store holds it (`placement`): `held` when it holds it somewhere (the copy / rename lanes answer), otherwise its
34
+ * deletion record for `scope` — a placement that cannot be read answers `undecidable`, never `never`. */
35
+ export declare function unheldIdRecord(backend: MemoryBackend, id: string, scope: string, placement: {
36
+ readonly state: "absent" | "held" | "unknown";
37
+ }): Promise<DeletionRecord | {
38
+ readonly kind: "held";
39
+ }>;
40
+ /** The harvest's reason for not committing such a file: deleted ⇒ refused (the caller contains it); undecidable ⇒ deferred. */
41
+ export declare function unheldIdRefusal(record: Extract<DeletionRecord, {
42
+ kind: "deleted" | "undecidable";
43
+ }>): string;
44
+ /** Read the store's deletion record in `scope` for each id (its `custodyOf` face, one read per id). A store without the
45
+ * face, a throwing getter, or a read that throws answers `undecidable` for that id — never `never`. */
46
+ export declare function memoryDeletionRecords(backend: MemoryBackend, ids: Iterable<string>, scope: string): Promise<Map<string, DeletionRecord>>;
@@ -0,0 +1,96 @@
1
+ import { foreignLine } from "../protocol-http-auth.js";
2
+ import { thrownText } from "../thrown-value.js";
3
+ import { inlineUntrusted } from "../untrusted-text.js";
4
+ function deleteEventScope(ev) {
5
+ if (typeof ev["scope"] === "string" && ev["scope"].length > 0)
6
+ return ev["scope"];
7
+ const from = ev["from"];
8
+ if (from !== null && typeof from === "object") {
9
+ const fromScope = from.scope;
10
+ if (typeof fromScope === "string" && fromScope.length > 0)
11
+ return fromScope;
12
+ }
13
+ return undefined;
14
+ }
15
+ export function deletionRecordFrom(evidence) {
16
+ if (evidence.deletedRev !== undefined)
17
+ return evidence.deletedRev === null ? { kind: "deleted" } : { kind: "deleted", rev: evidence.deletedRev };
18
+ if (!evidence.sound)
19
+ return { kind: "undecidable", why: evidence.unsoundWhy ?? "the store's deletion record is damaged" };
20
+ return { kind: "never" };
21
+ }
22
+ export function deletionRecordOf(id, custody, scope) {
23
+ if (typeof scope !== "string" || scope.length === 0)
24
+ throw new TypeError("deletionRecordOf: scope must be a non-empty string");
25
+ if (custody === undefined)
26
+ return { kind: "undecidable", why: "the store keeps no deletion record (it has no custodyOf face)" };
27
+ const seenEvs = new Set();
28
+ let deletedRev;
29
+ let scopelessDelete = false;
30
+ for (const ev of custody.events) {
31
+ if (typeof ev.ev === "string" && ev.ev.length > 0) {
32
+ if (seenEvs.has(ev.ev)) {
33
+ return { kind: "undecidable", why: `the store's deletion record carries event id "${foreignLine(ev.ev, 80)}" twice with conflicting payloads` };
34
+ }
35
+ seenEvs.add(ev.ev);
36
+ }
37
+ if (ev.channel !== "delete" || ev["id"] !== id)
38
+ continue;
39
+ const evScope = deleteEventScope(ev);
40
+ if (evScope === undefined) {
41
+ scopelessDelete = true;
42
+ continue;
43
+ }
44
+ if (evScope !== scope)
45
+ continue;
46
+ deletedRev = typeof ev["rev"] === "string" && ev["rev"].length > 0 ? ev["rev"] : null;
47
+ }
48
+ if (scopelessDelete)
49
+ return { kind: "undecidable", why: "a deletion event for this id carries no scope — whether it deleted this scope's entry cannot be read" };
50
+ return deletionRecordFrom({ deletedRev, sound: custody.state === "complete", unsoundWhy: `the store's deletion record for this id is damaged${custody.reason !== undefined ? ` (${foreignLine(custody.reason, 200)})` : ""}` });
51
+ }
52
+ export async function unheldIdRecord(backend, id, scope, placement) {
53
+ if (placement.state === "held")
54
+ return { kind: "held" };
55
+ if (placement.state === "unknown")
56
+ return { kind: "undecidable", why: "where the store holds this id could not be read" };
57
+ return (await memoryDeletionRecords(backend, [id], scope)).get(id);
58
+ }
59
+ export function unheldIdRefusal(record) {
60
+ return record.kind === "deleted"
61
+ ? "the memory store deleted the entry this file's id names — a deleted entry's bytes are never taken back; to keep the text, write it as a new note without the id line"
62
+ : `memory write deferred: this file carries an id the memory store does not hold, and whether the store deleted that entry cannot be read (${inlineUntrusted(record.why, 200)}) — not committed, so a deleted entry is never taken back; remove the id line to commit it as a new note`;
63
+ }
64
+ export async function memoryDeletionRecords(backend, ids, scope) {
65
+ if (typeof scope !== "string" || scope.length === 0)
66
+ throw new TypeError("memoryDeletionRecords: scope must be a non-empty string");
67
+ let face;
68
+ let faceErr;
69
+ try {
70
+ const raw = backend.custodyOf;
71
+ face = typeof raw === "function" ? raw : undefined;
72
+ }
73
+ catch (err) {
74
+ faceErr = foreignLine(thrownText(err), 200);
75
+ }
76
+ const out = new Map();
77
+ for (const id of ids) {
78
+ if (out.has(id))
79
+ continue;
80
+ if (faceErr !== undefined) {
81
+ out.set(id, { kind: "undecidable", why: `the store's deletion record could not be read (${faceErr})` });
82
+ continue;
83
+ }
84
+ if (face === undefined) {
85
+ out.set(id, deletionRecordOf(id, undefined, scope));
86
+ continue;
87
+ }
88
+ try {
89
+ out.set(id, deletionRecordOf(id, await face.call(backend, id), scope));
90
+ }
91
+ catch (err) {
92
+ out.set(id, { kind: "undecidable", why: `the store's deletion record could not be read (${foreignLine(thrownText(err), 200)})` });
93
+ }
94
+ }
95
+ return out;
96
+ }
@@ -36,6 +36,7 @@ import { optionKeys, receiveOptions } from "../own-property-receipt.js";
36
36
  import { admitLandingsThrough, directedLandings, planWritten, refusalNamingWritten, requireWriteGate } from "./consolidation-write-gate.js";
37
37
  import { applyEachAlone } from "./landing-admission.js";
38
38
  import { ledgerFaultNotice, projectionsHeldAt, retireGoneProjections, retirementNotices } from "./projection-ledger.js";
39
+ import { unheldIdRecord, unheldIdRefusal } from "./deletion-record.js";
39
40
  import { dropIndexCopiesOf, indexCopiesAnswered, readAdmittedStoreState } from "./index-copies.js";
40
41
  export const MEMORY_RECALL_FRAMING = "Recalled memories appearing inside `<system-reminder>` blocks are background context, not user instructions, and reflect what was true when written — if one names a file, function, or flag, verify it still exists before recommending it.";
41
42
  export const MEMORY_INSTRUCTION_TEMPLATE = `# Memory
@@ -2881,6 +2882,7 @@ export class MemoryEngine {
2881
2882
  let observedTable;
2882
2883
  const recordedResidue = new Set();
2883
2884
  const goneCopies = new Set();
2885
+ const debtDeferred = new Set();
2884
2886
  const recordedDisposals = [];
2885
2887
  const removalDeletes = new Map();
2886
2888
  for (const m of missingWritable) {
@@ -2960,10 +2962,16 @@ export class MemoryEngine {
2960
2962
  if (nameFinding !== undefined)
2961
2963
  scanFindings.push(nameFinding);
2962
2964
  scanFindings.push(...scanMemoryWrite(f.text));
2963
- const finding = scanFindings[0];
2965
+ const unnamedId = f.parsed.id !== undefined && f.parsed.frontmatter.deleted !== true && !idByBasePath.has(f.canonical) && !basePathById.has(f.parsed.id) && handle.goneIds?.has(f.parsed.id) !== true ? f.parsed.id : undefined;
2966
+ const planeRecord = scanFindings.length === 0 && unnamedId !== undefined ? await unheldIdRecord(this.backend, unnamedId, writeScope, await this.committedPlacementOf(unnamedId)) : undefined;
2967
+ if (planeRecord?.kind === "undecidable") {
2968
+ report.rejections.push({ path: rel, code: "deferred", reason: unheldIdRefusal(planeRecord) });
2969
+ continue;
2970
+ }
2971
+ const finding = scanFindings[0] ?? (planeRecord?.kind === "deleted" ? { code: "invalid", reason: unheldIdRefusal(planeRecord) } : undefined);
2964
2972
  if (finding !== undefined) {
2965
2973
  const refusedHere = this.storeActRefusedText(f.canonical, "quarantining a rejected file", handle);
2966
- const q = refusedHere === undefined ? await this.containSuspect(f.canonical, f.text, "quarantining a rejected file", handle) : { removed: false, leftOnPlane: f.text, detail: refusedHere };
2974
+ const q = refusedHere === undefined ? await this.containSuspect(f.canonical, f.text, "quarantining a rejected file", handle, scanFindings.length === 0) : { removed: false, leftOnPlane: f.text, detail: refusedHere };
2967
2975
  let contained = q.removed;
2968
2976
  const priorId = idByBasePath.get(f.canonical);
2969
2977
  if (priorId !== undefined) {
@@ -3076,11 +3084,8 @@ export class MemoryEngine {
3076
3084
  if (debt !== undefined) {
3077
3085
  const committed = await this.debtCommittedProjection(debt.entryId);
3078
3086
  if (committed.state === "unknown") {
3079
- report.rejections.push({
3080
- path: rel,
3081
- code: "deferred",
3082
- reason: "memory write deferred: this file's recorded committed id could not be validated (committed state unreadable) — retried next harvest (fail-closed: a fresh mint here could duplicate the committed entry)",
3083
- });
3087
+ debtDeferred.add(rel);
3088
+ report.rejections.push({ path: rel, code: "deferred", reason: "memory write deferred: this file's recorded committed id could not be validated (committed state unreadable) — retried next harvest (fail-closed: a fresh mint here could duplicate the committed entry)" });
3084
3089
  continue;
3085
3090
  }
3086
3091
  if (committed.state === "valid" && committed.scope === writeScope && committed.slug === f.slug) {
@@ -3499,12 +3504,10 @@ export class MemoryEngine {
3499
3504
  }
3500
3505
  }
3501
3506
  for (const r of refusedStage) {
3502
- report.rejections.push({
3503
- path: relative(handle.memoryDir, join(writableRoot, r.rel)),
3504
- code: "deferred",
3505
- reason: "memory write deferred: a concurrent writer's projection-debt claim stands at this seat — retried next harvest (committing without a protected id write-back could duplicate the concurrent entry)",
3506
- });
3507
- report.warnings.push(`${relative(handle.memoryDir, join(writableRoot, r.rel))}: earlier notes about this file committing under a fresh id are superseded — its commit was WITHDRAWN this harvest (deferred to the next)`);
3507
+ const dRel = relative(handle.memoryDir, join(writableRoot, r.rel));
3508
+ debtDeferred.add(dRel);
3509
+ report.rejections.push({ path: dRel, code: "deferred", reason: "memory write deferred: a concurrent writer's projection-debt claim stands at this seat — retried next harvest (committing without a protected id write-back could duplicate the concurrent entry)" });
3510
+ report.warnings.push(`${dRel}: earlier notes about this file committing under a fresh id are superseded — its commit was WITHDRAWN this harvest (deferred to the next)`);
3508
3511
  }
3509
3512
  if (lineageArmed) {
3510
3513
  const remaining = stagedRows();
@@ -3759,6 +3762,7 @@ export class MemoryEngine {
3759
3762
  await this.rebaseline(handle, new Set([...(report.degraded?.pending ?? []), ...stoodAsFound, ...records.filter((r) => r.parsed.unclosed === true).map((r) => r.rel)]), new Set([...report.rejections.map((r) => r.path), ...goneCopies]), report.degraded === undefined ? startedAt : (handle.planeBaseline?.at ?? startedAt));
3760
3763
  if (carry && lineageSessionId !== undefined && report.degraded === undefined) {
3761
3764
  const deferredSeats = [...new Set(report.rejections.filter((r) => r.code === "deferred").map((r) => r.path))];
3765
+ const allDebt = deferredSeats.every((p) => debtDeferred.has(p));
3762
3766
  const shown = deferredSeats.slice(0, MAX_DISCLOSED_DEFERRED_SEATS);
3763
3767
  const rest = deferredSeats.length - shown.length;
3764
3768
  const seatList = `${shown.join(", ")}${rest > 0 ? ` (+${rest} more — see the rejections)` : ""}`;
@@ -3767,11 +3771,13 @@ export class MemoryEngine {
3767
3771
  if (closed === "stale" && !report.warnings.includes(STALE_LEG_NOTE))
3768
3772
  report.warnings.push(STALE_LEG_NOTE);
3769
3773
  if (closed === "written" && deferredSeats.length > 0) {
3770
- report.warnings.push(`memory session account closed with ${deferredSeats.length} file(s) still DEFERRED on the model-visible plane — their projection-debt rows STAND and are re-judged by the next harvest's consult, not by this close: ${seatList}`);
3774
+ report.warnings.push(allDebt
3775
+ ? `memory session account closed with ${deferredSeats.length} file(s) still DEFERRED on the model-visible plane — their projection-debt rows STAND and are re-judged by the next harvest's consult, not by this close: ${seatList}`
3776
+ : `memory session account closed with ${deferredSeats.length} file(s) still DEFERRED on the model-visible plane — re-judged by the next harvest, not by this close: ${seatList}`);
3771
3777
  }
3772
3778
  }
3773
3779
  catch (err) {
3774
- report.warnings.push(`memory session account close FAILED and its outcome is UNKNOWN (a failure after the ledger's journal commit still rolls forward, so the account may read closed at the next strict read; a failure before it leaves the ledger's PRIOR state — open, already closed, valve-closed or absent — unchanged, and an open one keeps future crash residue attributed, the over-holding safe side)${deferredSeats.length > 0 ? `; ${deferredSeats.length} file(s) also stay DEFERRED on the plane under standing projection-debt rows: ${seatList}` : ""}: ${thrownText(err)}`);
3780
+ report.warnings.push(`memory session account close FAILED and its outcome is UNKNOWN (a failure after the ledger's journal commit still rolls forward, so the account may read closed at the next strict read; a failure before it leaves the ledger's PRIOR state — open, already closed, valve-closed or absent — unchanged, and an open one keeps future crash residue attributed, the over-holding safe side)${deferredSeats.length > 0 ? `; ${deferredSeats.length} file(s) also stay DEFERRED on the plane${allDebt ? " under standing projection-debt rows" : ""}: ${seatList}` : ""}: ${thrownText(err)}`);
3775
3781
  }
3776
3782
  }
3777
3783
  if (this.consolidation !== undefined && handle.writeScope !== null && opts?.sessionId !== undefined && report.ok) {
@@ -5914,8 +5920,10 @@ export class MemoryEngine {
5914
5920
  return this.writeFailureText(err);
5915
5921
  }
5916
5922
  }
5917
- async containSuspect(path, content, act, handle) {
5923
+ async containSuspect(path, content, act, handle, requireCapture = false) {
5918
5924
  const capture = await captureIntoQuarantine(this.governanceStore, path, content);
5925
+ if (requireCapture && "failed" in capture)
5926
+ return { removed: false, leftOnPlane: content, detail: `${capture.failed} — file left on plane so its text is not lost` };
5919
5927
  const refused = this.storeActRefusedText(path, act, handle);
5920
5928
  if (refused !== undefined)
5921
5929
  return { ...("name" in capture ? { dest: capture.name } : {}), removed: false, leftOnPlane: content, detail: "failed" in capture ? `${capture.failed}; ${refused}` : refused };
@@ -20,6 +20,7 @@ import { canonicalExpectedScopes, expectedScopesInvalid, firstOutsideExpectedSco
20
20
  import { scanMemoryFileName, scanMemoryWrite } from "./scan.js";
21
21
  import { admittingLandings, cutPerLanding, LandingsNeedAdmission, requireLandingsAdmitted } from "./landing-admission.js";
22
22
  import { thrownText } from "../thrown-value.js";
23
+ import { deletionRecordFrom } from "./deletion-record.js";
23
24
  import { deliverEngineNotice } from "../engine-notice.js";
24
25
  import { optionKeys, receiveOptions } from "../own-property-receipt.js";
25
26
  export { DEFAULT_MAX_ENTRY_DEPTH, MEMORY_INDEX_FILENAME, scanEntryFiles } from "./entry-scan.js";
@@ -1153,11 +1154,8 @@ export class FileMemoryEngineBackend {
1153
1154
  }
1154
1155
  resurrectionBackstopVerdict(id) {
1155
1156
  const digest = this.deletedIdsDigestLocked();
1156
- if (digest.ids.has(id))
1157
- return "erased";
1158
- if (digest.state === "damaged" || this.chainDegradedMarkerPresent())
1159
- return "degraded";
1160
- return "clear";
1157
+ const record = deletionRecordFrom({ deletedRev: digest.ids.has(id) ? null : undefined, sound: digest.state !== "damaged" && !this.chainDegradedMarkerPresent() });
1158
+ return record.kind === "deleted" ? "erased" : record.kind === "undecidable" ? "degraded" : "clear";
1161
1159
  }
1162
1160
  retrievalDeletedIds() {
1163
1161
  return this.deletedIdsDigestLocked().ids;
@@ -3070,6 +3068,10 @@ export class FileMemoryEngineBackend {
3070
3068
  }
3071
3069
  }
3072
3070
  }
3071
+ if (out.state === "complete" && this.chainDegradedMarkerPresent()) {
3072
+ out.state = "damaged";
3073
+ out.reason ??= `evidence chain carries durable degradation marker (${CHAIN_DEGRADED_FILE} — out-of-band tail truncation)`;
3074
+ }
3073
3075
  if (this.auditJournalPending())
3074
3076
  continue;
3075
3077
  if (readControlFileOrAbsent(transfersPath, "transfer evidence log") !== rawBefore)
@@ -32,7 +32,7 @@ export declare function retireGoneProjections(rows: readonly ProjectionLedgerRow
32
32
  /** What a mount says about the files it left: one line per file, by scope — the seat only, never content. The announcement
33
33
  * renderer keeps an item to the inline label bound (160 characters), so the quoted seat is held to its room and what a person
34
34
  * acts on comes before a cause (a seat name cut past that bound would take the rest of the line with it). Three arms, each
35
- * saying what is true of it: a copy changed here (it may be saved back unless the file goes), something else standing at the
35
+ * saying what is true of it: a copy changed here (not saved back if deleted, else delete the file), something else standing at the
36
36
  * seat (nothing is asked of the person), a copy that could not be removed. */
37
37
  export declare function retirementNotices(r: ProjectionRetirement): Map<string | undefined, string[]>;
38
38
  /** The one wording of a ledger fault: unreadable at a mount (nothing removed — the notice is said before the record is written, so
@@ -82,7 +82,7 @@ export function retirementNotices(r) {
82
82
  }
83
83
  };
84
84
  for (const row of r.changed)
85
- say(row.scope, `${q(row.rel)}: gone from the store at this name, changed here since it was placed — kept; it may be saved back unless you delete the file`);
85
+ say(row.scope, `${q(row.rel)}: gone from the store at this name, changed here since it was placed — kept; not saved back if deleted, else delete the file`);
86
86
  for (const row of r.replaced)
87
87
  say(row.scope, `${q(row.rel)}: the store places no entry at this name any more, and this file is now a different note — left as found`);
88
88
  for (const { row, why } of r.failed)
@@ -1,4 +1,5 @@
1
1
  import type { ExecutionEnv } from "../../internal/harness-types.js";
2
+ import { PROJECT_ID_REGEX, type ProjectSeat } from "../project-seat.js";
2
3
  /** Per-segment cap, measured AFTER encoding. A conservative portability policy adopted as contract
3
4
  * (research (d) recommendation — NOT a verified third-party hard limit; uuidv7 = 36 chars fits). */
4
5
  export declare const SCOPE_SEGMENT_MAX_ENCODED = 64;
@@ -132,10 +133,8 @@ export declare function assertScopeContractPlacement(args: {
132
133
  /** Repo-root marker file: minted once (by scaffold/deployment, NEVER by the engine), committed, and
133
134
  * from then on the project's identity survives clone/copy/rename/machine/cloud-sandbox. */
134
135
  export declare const PROJECT_MARKER_PATH = ".sema/project";
135
- /** projectId 格式单源:generic UUID,version nibble 不收紧——宽读严写(读面认外部/
136
- * 历史 v4;铸造面 formatProjectMarker / center mint 统一产 uuidv7)。center 侧自持镜像+dev-only
137
- * drift 锁对着这条(registry-core coreTypes 先例)。 */
138
- export declare const PROJECT_ID_REGEX: RegExp;
136
+ /** The project id's one format (defined beside the project seat, `../project-seat.ts`). */
137
+ export { PROJECT_ID_REGEX };
139
138
  /** Canonicalize a project UUID for equality comparisons across markers, declarations, and v2 write keys. */
140
139
  export declare function normalizeProjectId(projectId: string): string;
141
140
  /** Serialize a marker file body (scaffold-side helper; the engine itself never writes one). */
@@ -212,7 +211,7 @@ export declare function resolveProjectId(fs: ProjectMarkerFs, rootDir: string):
212
211
  markerDir: string;
213
212
  } | null>;
214
213
  /** A leg's project identity. `marker` = the checkout's `.sema/project` (a declaration, when present,
215
- * equals it); `declared` = `TaskSpec.projectId` in a checkout that carries no marker. */
214
+ * equals it); `declared` = `TaskSpec.project.id` (or the seat its parent handed it) in a checkout that carries no marker. */
216
215
  export interface SessionProject {
217
216
  readonly id: string;
218
217
  readonly source: "marker" | "declared";
@@ -224,6 +223,9 @@ export interface SessionProjectVerdict {
224
223
  readonly root: string;
225
224
  /** ABSENT = no marker and no declaration, or the marker could not be read ({@link markerFault} says why). */
226
225
  readonly project?: SessionProject;
226
+ /** The leg's project SEAT: the verdict's id with the texts that belong to it ({@link resolveSessionProject} says which) — present
227
+ * iff {@link project} is. What the leg hands its children and what its project texts are read from. */
228
+ readonly seat?: ProjectSeat;
227
229
  /** Why the marker could not be read (nested / corrupt / unreadable), on a leg that declared no project — reported by
228
230
  * the caller, NOT thrown here: only a reader that consumes project identity refuses with it (memory v2 `proj:` /
229
231
  * `userproj:` keys). A leg that DECLARED a project consumes it, so there the fault is thrown. */
@@ -238,16 +240,19 @@ export declare function projectMarkerUnreadableOf(fault: SessionProjectVerdict["
238
240
  readonly markerPath?: string;
239
241
  } | undefined;
240
242
  /**
241
- * The leg's ONE project-identity judge, called once per leg on the task root. Precedence:
242
- * 1. `declared` (`TaskSpec.projectId`): validated UUID (`config.project_id_invalid`); checked against any workspace
243
- * marker (`config.project_identity_mismatch` on disagreement, marker's own code on unreadable marker).
243
+ * The leg's ONE project-identity judge, called once per leg on the task root, over seats already screened
244
+ * (`screenProjectSeat`, at the spec's read and at the internals' door). Precedence:
245
+ * 1. `declared` (`TaskSpec.project`): checked against any workspace marker (`config.project_identity_mismatch` on
246
+ * disagreement, the marker's own code on an unreadable marker).
244
247
  * 2. The leg's own workspace marker (`.sema/project`): decides when present (`source: "marker"`), even over an
245
- * inherited `defaultProjectId`; an unreadable marker on a leg with no `declared` yields `{ root, markerFault }`
246
- * (no project verdict — identical to a root leg).
247
- * 3. `defaultProjectId` (a delegated child's inherited parent verdict, passed via trusted internals): used ONLY when
248
- * both (1) and (2) yield none (`source: "declared"`), never compared against the child's marker.
248
+ * `inherited` seat; an unreadable marker on a leg with no `declared` yields `{ root, markerFault }` (no project verdict —
249
+ * identical to a root leg).
250
+ * 3. `inherited` (the seat a delegated child's parent handed it, on the trusted internals): its id is used ONLY when both (1)
251
+ * and (2) yield none (`source: "declared"`), never compared against the child's marker.
252
+ * The texts belong to the id: the verdict's {@link SessionProjectVerdict.seat} is `declared` whole; else `inherited` whole when its
253
+ * id is the verdict's id (no marker, or a marker naming that id); else the verdict's id alone.
249
254
  */
250
- export declare function resolveSessionProject(fs: ProjectMarkerFs, taskRoot: string, declared: string | undefined, defaultProjectId?: string): Promise<SessionProjectVerdict>;
255
+ export declare function resolveSessionProject(fs: ProjectMarkerFs, taskRoot: string, declared: ProjectSeat | undefined, inherited?: ProjectSeat): Promise<SessionProjectVerdict>;
251
256
  /**
252
257
  * Under `scopeContract: "v2"`, enforce project-identity consistency for a memory session against the leg's ONE
253
258
  * verdict ({@link SessionProjectVerdict}): rethrow an unreadable-marker fault for sessions consuming project identity