@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,96 @@
1
+ import { isAbsoluteHostPath } from "@sema-agent/primitives";
2
+ export const PROJECT_ID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
3
+ export const PROJECT_SEAT_NAME_MAX = 256;
4
+ export const PROJECT_SEAT_FILES_MAX = 100;
5
+ const SEAT_MEMBERS = ["id", "name", "description", "instructions", "files"];
6
+ const TEXT_MEMBERS = ["name", "description", "instructions"];
7
+ const shown = (v) => {
8
+ if (typeof v === "string")
9
+ return JSON.stringify(v.length > 48 ? `${v.slice(0, 48)}…` : v);
10
+ if (v === null)
11
+ return "null";
12
+ if (Array.isArray(v))
13
+ return "an array";
14
+ return typeof v === "object" ? "an object" : typeof v === "function" ? "a function" : String(v);
15
+ };
16
+ export function screenProjectSeat(value, at = "TaskSpec.project") {
17
+ try {
18
+ return screenRead(value, at);
19
+ }
20
+ catch {
21
+ return refusal(at, "could not be read: its read threw — a seat whose read throws is refused rather than read as absent");
22
+ }
23
+ }
24
+ function refusal(field, why, code = "config.invalid_argument") {
25
+ return { ok: false, code, field, message: `${field}: ${why} — the leg is refused rather than run under a project it was not given.` };
26
+ }
27
+ function screenRead(value, at) {
28
+ if (value === undefined)
29
+ return { ok: true };
30
+ const refuse = refusal;
31
+ const proto = value === null || typeof value !== "object" || Array.isArray(value) ? undefined : Object.getPrototypeOf(value);
32
+ if (proto === undefined || (proto !== null && Object.getPrototypeOf(proto) !== null)) {
33
+ return refuse(at, `must be a plain object { id, name?, description?, instructions?, files? } (got ${shown(value)})`);
34
+ }
35
+ const own = Reflect.ownKeys(value);
36
+ const stray = own.find((k) => typeof k !== "string" || !SEAT_MEMBERS.includes(k));
37
+ if (stray !== undefined)
38
+ return refuse(`${at}.${String(stray)}`, `is no member of a project seat (its members are ${SEAT_MEMBERS.join(", ")})`);
39
+ const read = {};
40
+ for (const k of own) {
41
+ const d = Object.getOwnPropertyDescriptor(value, k);
42
+ if (d === undefined || !("value" in d))
43
+ return refuse(`${at}.${k}`, "must be a plain data member, not an accessor");
44
+ if (d.value !== undefined)
45
+ read[k] = d.value;
46
+ }
47
+ const id = read["id"];
48
+ if (id === undefined)
49
+ return refuse(`${at}.id`, "is required — a seat names its project");
50
+ if (typeof id !== "string" || !PROJECT_ID_REGEX.test(id)) {
51
+ return refuse(`${at}.id`, `must be a project UUID (the id a \`.sema/project\` marker carries), got ${shown(id)}`, "config.project_id_invalid");
52
+ }
53
+ for (const k of TEXT_MEMBERS) {
54
+ const v = read[k];
55
+ if (v === undefined)
56
+ continue;
57
+ if (typeof v !== "string")
58
+ return refuse(`${at}.${k}`, `must be a string (got ${shown(v)}); leave it out to say none`);
59
+ if (v.trim() === "")
60
+ return refuse(`${at}.${k}`, "is empty or only whitespace; leave it out to say none");
61
+ }
62
+ const name = read["name"];
63
+ if (name !== undefined && /[\r\n]/.test(name))
64
+ return refuse(`${at}.name`, "is one line — it carries a line break");
65
+ if (name !== undefined && name.length > PROJECT_SEAT_NAME_MAX)
66
+ return refuse(`${at}.name`, `is at most ${PROJECT_SEAT_NAME_MAX} characters (got ${name.length})`);
67
+ const given = read["files"];
68
+ let files;
69
+ if (given !== undefined) {
70
+ if (!Array.isArray(given))
71
+ return refuse(`${at}.files`, `must be a list of absolute host paths (got ${shown(given)})`);
72
+ const length = given.length;
73
+ if (length > PROJECT_SEAT_FILES_MAX)
74
+ return refuse(`${at}.files`, `holds at most ${PROJECT_SEAT_FILES_MAX} entries (got ${length})`);
75
+ const entries = Array.from({ length }, (_, i) => given[i]);
76
+ const bad = entries.findIndex((p) => !isAbsoluteHostPath(p));
77
+ if (bad >= 0)
78
+ return refuse(`${at}.files[${bad}]`, `must be an absolute host path (got ${shown(entries[bad])})`);
79
+ files = entries;
80
+ }
81
+ const seat = Object.freeze({
82
+ id,
83
+ ...Object.fromEntries(TEXT_MEMBERS.filter((k) => read[k] !== undefined).map((k) => [k, read[k]])),
84
+ ...(files !== undefined ? { files: Object.freeze(files) } : {}),
85
+ });
86
+ return { ok: true, seat };
87
+ }
88
+ const REFUSED = Symbol("refused project seat");
89
+ export function captureProjectSeat(value, at) {
90
+ const screened = screenProjectSeat(value, at);
91
+ return screened.ok ? screened.seat : Object.freeze({ [REFUSED]: screened });
92
+ }
93
+ export function handedProjectSeat(captured) {
94
+ const refused = captured?.[REFUSED];
95
+ return refused ?? { ok: true, ...(captured !== undefined ? { seat: captured } : {}) };
96
+ }
@@ -244,8 +244,9 @@ export declare function foreignLine(text: string, maxLen?: number, reading?: For
244
244
  * these words does their remote-words reading not carry", for a reader that carries the same words in another spelling and must carry
245
245
  * no less: the regions its echo pass withholds and the spans its vocabulary pass then withholds in those marked words
246
246
  * ({@link egressCredentialReading}: the label a rendering keeps is not in the span), read back through the marks (a span that touches a
247
- * mark reaches the whole region the mark stands for). Where the marked words cannot be read back (see {@link writtenRegions}), the whole
248
- * text; and checked against the reading's own output: where the text outside the spans does not stand in it as written
247
+ * mark reaches the whole region the mark stands for); the regions are the merge's own account of what it wrote ({@link mergeWithheldSpans}),
248
+ * and where a mark the text already held meets what is taken (see {@link writtenRegions}), the answer is the whole text; and checked against
249
+ * the reading's own output: where the text outside the spans does not stand in it as written
249
250
  * ({@link carriesTheRest}), the spans missed a removal, and the answer is the whole text.
250
251
  */
251
252
  export declare function remoteWordsSpans(text: string, declared: readonly string[], found?: FoundElsewhere): Array<readonly [number, number]>;
@@ -1,5 +1,5 @@
1
1
  import { boundedForeignReading, egressCredentialFinds, egressCredentialReading, egressText, oneLineFinds, wholeForeignReading } from "./untrusted-egress.js";
2
- import { CREDENTIAL_MIN_CHARS, crossesNetworkInClear, isRedactionMark, isSensitiveRecordKey, REDACTION_MARKS, renderWithheld } from "@sema-agent/primitives";
2
+ import { CREDENTIAL_MIN_CHARS, crossesNetworkInClear, isRedactionMark, isSensitiveRecordKey, mergeWithheldSpans, REDACTION_MARKS, renderWithheld } from "@sema-agent/primitives";
3
3
  import { foldPlaces, foldToOneLine, INLINE_TRUNCATION_MARK, inlineUntrusted, LABEL_MAX, withoutUnrenderable } from "./untrusted-text.js";
4
4
  import { callerText } from "./caller-text.js";
5
5
  import { PRINCIPAL_NAME_SPELLING, readPrincipal } from "./principal-name.js";
@@ -481,8 +481,8 @@ function echoTaken(text, declared, found) {
481
481
  }
482
482
  export function remoteWordsSpans(text, declared, found = NOTHING_FOUND) {
483
483
  const taken = echoTaken(text, declared, found);
484
- const marked = renderWithheld(text, taken);
485
- const regions = writtenRegions(text, taken, marked);
484
+ const { text: marked, regions: merged, dropped } = mergeWithheldSpans(text, taken);
485
+ const regions = writtenRegions(taken, merged, dropped);
486
486
  if (regions === undefined)
487
487
  return [[0, text.length]];
488
488
  const reading = egressCredentialReading(marked);
@@ -539,22 +539,30 @@ function mergedRanges(ranges) {
539
539
  }
540
540
  return merged;
541
541
  }
542
- function writtenRegions(text, spans, marked) {
543
- const regions = [];
544
- let kept = 0;
545
- let at = 0;
546
- for (const [start, end] of mergedRanges(spans.map(({ start, end }) => [start, end]))) {
547
- if (!marked.startsWith(text.slice(kept, start), at))
548
- return undefined;
549
- at += start - kept;
550
- const member = MARK_MEMBERS.find((m) => marked.startsWith(m, at));
551
- if (member === undefined)
552
- return undefined;
553
- regions.push({ start, end, length: member.length });
554
- at += member.length;
555
- kept = end;
542
+ function writtenRegions(spans, merged, dropped) {
543
+ const marks = dropped.map((i) => spans[i]).sort((a, b) => a.start - b.start || a.end - b.end);
544
+ const inside = merged.map(() => []);
545
+ const standing = new Map();
546
+ let r = 0;
547
+ for (const s of marks) {
548
+ while (r < merged.length && merged[r].end < s.end)
549
+ r++;
550
+ const region = merged[r];
551
+ if (region !== undefined && region.start <= s.start && s.end <= region.end)
552
+ inside[r].push(s);
553
+ else
554
+ standing.set(`${s.start}:${s.end}`, s);
556
555
  }
557
- return marked.length - at === text.length - kept && marked.endsWith(text.slice(kept)) ? regions : undefined;
556
+ if (merged.some((region, k) => coveredLength([...region.spans.map((i) => spans[i]), ...inside[k]]) < region.end - region.start))
557
+ return undefined;
558
+ const regions = [...merged.map(({ start, end, mark }) => ({ start, end, length: mark.length })), ...[...standing.values()].map(({ start, end }) => ({ start, end, length: end - start }))].sort((a, b) => a.start - b.start || a.end - b.end);
559
+ for (let i = 1; i < regions.length; i++)
560
+ if (regions[i].start <= regions[i - 1].end)
561
+ return undefined;
562
+ return regions;
563
+ }
564
+ function coveredLength(spans) {
565
+ return mergedRanges(spans.map(({ start, end }) => [start, end])).reduce((n, [start, end]) => n + end - start, 0);
558
566
  }
559
567
  function cookieMembers(text) {
560
568
  const members = [];
@@ -589,7 +589,7 @@ export interface RemoteExecutionEnv extends ExecutionEnv {
589
589
  * Why the engine asks an {@link ExecutionEnvFactory} for an env ({@link ExecutionEnvFactoryContext.purpose}):
590
590
  * · `"run"` — a leg's own env (one per leg, destroyed when the leg ends); every leg, a delegated child's included;
591
591
  * · `"rewind_files"` — `Runner.rewindFiles`, out of any run; writes only the session's tracked files;
592
- * · `"read_changes"` — reading what a session changed, out of any run; writes nothing.
592
+ * · `"read_changes"` — read-only readings outside any run (`Runner.readSessionChanges`, `Runner.previewInstructions`); writes nothing.
593
593
  */
594
594
  export type ExecutionEnvPurpose = "run" | "rewind_files" | "read_changes";
595
595
  /** The closed set of {@link ExecutionEnvPurpose} words, frozen. */
@@ -608,9 +608,9 @@ export interface ExecutionEnvFactoryContext {
608
608
  /**
609
609
  * Why the engine asks for this env — always present. `"run"`: a leg's own env (one per leg, destroyed when the leg ends) —
610
610
  * the meaning every factory call had before this member; every leg, a delegated child's included. `"rewind_files"`:
611
- * `Runner.rewindFiles`, out of any run; writes only the session's tracked files. `"read_changes"`: reading what a session
612
- * changed, out of any run; writes nothing — asked only of a factory the deployment declares answers it
613
- * (`RunnerDeps.executionEnvFactoryHonorsReadChanges`).
611
+ * `Runner.rewindFiles`, out of any run; writes only the session's tracked files. `"read_changes"`: read-only readings
612
+ * outside any run (`Runner.readSessionChanges`, `Runner.previewInstructions`); writes nothing — asked only of a factory the
613
+ * deployment declares answers it (`RunnerDeps.executionEnvFactoryHonorsReadChanges`).
614
614
  *
615
615
  * For a purpose other than `"run"` a factory ATTACHES to the workspace the session's runs use (the same directory / host /
616
616
  * device) and never mints one — or refuses: a refusal coded {@link ENV_PURPOSE_UNSUPPORTED} when it does not serve the
@@ -36,6 +36,7 @@ export const RETIRED_TASK_SPEC_KEYS = Object.freeze({
36
36
  promptProfile: 'the prompt\'s shape is the `lean_prompt` trait now — write `promptLean: false` for the long (classic) shape, `promptLean: true` (or nothing, on a model that declares `lean_prompt`) for the lean one',
37
37
  rewindFiles: "capture needs no request (first-touch tracking is on whenever `RunnerDeps.fileHistoryStore` is wired and neither `RunnerDeps.fileHistoryCapture` nor `TaskSpec.fileHistory` turns it off); to restore files with the conversation write `resumeAt` + `restoreFiles: true`, for a code-only restore `rewindFilesTo` — drop the key",
38
38
  compactionModel: SUMMARY_ON_MAIN_MODEL,
39
+ projectId: "a leg's project is one seat now — write `project: { id }` (the same UUID, as `TaskSpec.project.id`); the project's texts (`name`, `description`, `instructions`, `files`) ride that seat beside it",
39
40
  });
40
41
  export const RETIRED_SKILLS_SEAT_KEYS = Object.freeze({
41
42
  "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`",
@@ -9,7 +9,7 @@ import { type RuleOffer } from "./permission-rule-model.js";
9
9
  * Why a stored rule-offer value, or one element of it, is not read:
10
10
  * · `not_an_array` — the value itself (present, and not a list): no element is read;
11
11
  * · `unknown_word` — a closed-set member holds a word this engine does not know: the offer `kind`, a batch member's
12
- * `kind`, a `match` (a newer minter, or another writer);
12
+ * `kind`, a `match`, a `cautions` word (a newer minter, or another writer);
13
13
  * · `malformed` — not an object, a member missing or of the wrong type, a batch with no members, an uncovered count
14
14
  * that is not a non-negative safe integer.
15
15
  * The first defect in reading order names the element's problem.
@@ -1,4 +1,4 @@
1
- import { PERSISTED_RULE_MATCHES, RULE_OFFER_BATCH_MEMBER_KINDS, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, isAddStamp, } from "./permission-rule-model.js";
1
+ import { PERSISTED_RULE_MATCHES, RULE_OFFER_BATCH_MEMBER_KINDS, RULE_OFFER_CAUTIONS, RULE_OFFER_KINDS, UNCOVERED_SEGMENT_REASONS, isAddStamp, } from "./permission-rule-model.js";
2
2
  import { isPlainRecord } from "./checkpoint-store.js";
3
3
  const OFFER_MATCHES = PERSISTED_RULE_MATCHES.filter((m) => m !== "call");
4
4
  export const RULE_OFFER_SHAPE_PROBLEMS = Object.freeze(["not_an_array", "unknown_word", "malformed"]);
@@ -46,7 +46,10 @@ function readOfferElement(value) {
46
46
  const peerFingerprint = Object.hasOwn(value, "peerFingerprint") ? value.peerFingerprint : undefined;
47
47
  if (peerFingerprint !== undefined && !isAddStamp(peerFingerprint))
48
48
  return MALFORMED;
49
- return { offer: { kind: "single", rule, match, command, ...(peerFingerprint !== undefined ? { peerFingerprint } : {}) } };
49
+ const cautions = cautionsOf(value);
50
+ if ("problem" in cautions)
51
+ return cautions;
52
+ return { offer: { kind: "single", rule, match, command, ...(peerFingerprint !== undefined ? { peerFingerprint } : {}), ...cautions.seat } };
50
53
  }
51
54
  case "batch":
52
55
  return readBatch(value);
@@ -87,8 +90,13 @@ function readBatchMember(value) {
87
90
  if (typeof kind !== "string")
88
91
  return kind;
89
92
  switch (kind) {
90
- case "command":
91
- return commandMember(value.rule, value.match, value.command, value.segment);
93
+ case "command": {
94
+ const read = commandMember(value.rule, value.match, value.command, value.segment);
95
+ if ("problem" in read)
96
+ return read;
97
+ const cautions = cautionsOf(value);
98
+ return "problem" in cautions ? cautions : { member: { ...read.member, ...cautions.seat } };
99
+ }
92
100
  case "directoryRead": {
93
101
  const rule = value.rule;
94
102
  const directory = value.directory;
@@ -113,6 +121,26 @@ function commandMember(rule, rawMatch, command, segment) {
113
121
  return MALFORMED;
114
122
  return { member: { kind: "command", rule, match, command, segment } };
115
123
  }
124
+ function cautionsOf(value) {
125
+ const raw = Object.hasOwn(value, "cautions") ? value.cautions : undefined;
126
+ if (raw === undefined)
127
+ return { seat: {} };
128
+ if (!Array.isArray(raw))
129
+ return MALFORMED;
130
+ const words = [];
131
+ let unknown = false;
132
+ const length = raw.length;
133
+ for (let i = 0; i < length; i++) {
134
+ const word = wordOf(raw[i], RULE_OFFER_CAUTIONS);
135
+ if (typeof word === "string")
136
+ words.push(word);
137
+ else if (word === MALFORMED)
138
+ return MALFORMED;
139
+ else
140
+ unknown = true;
141
+ }
142
+ return unknown ? UNKNOWN_WORD : { seat: { cautions: words } };
143
+ }
116
144
  function detailRowsOf(detail, count) {
117
145
  if (!Array.isArray(detail))
118
146
  return undefined;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The bindings of a run's member ledger book (`TaskSpec.runLedger`) that need the prepared leg: the holder's rows of the members the
3
+ * task dispatched (read at each snapshot), and the run's own tool calls (the evidence a check may cite, heard as each one starts and
4
+ * finishes). Bound once, right after prepare, by the lane that minted the book.
5
+ *
6
+ * A MEMBER is a background agent or workflow run whose registry row names this task as the one that dispatched it (`parentTaskId`,
7
+ * written at registration by the agent tool and the workflow tool alike) — one key for both kinds, whatever owner the row registered
8
+ * under (a session-scoped spawn registers under the session) and whatever else the session's reach holds (another task's spawns).
9
+ * How it stands is that row's: whether it runs, how it ended (the ending its holder minted, else the one its status word names —
10
+ * `outcomeOfLegacyRow`, the one table), a workflow run's own members (the run's member ledger, as the registry keeps it).
11
+ *
12
+ * The holder read is this process's task registry. A durable background-agent or workflow-run store is not read: a member whose row
13
+ * only such a store holds (a resume in another process) is one the holder no longer hands back — the book counts it unreadable and
14
+ * the coverage is incomplete (`docs/KNOWN-LIMITS.md`, KL-4459-b).
15
+ */
16
+ import { type TaskListRow } from "./task-registry.js";
17
+ import { type RunEndCause } from "./member-outcome.js";
18
+ import type { RunLedgerBook, RunLedgerRegistryRow } from "./run-ledger.js";
19
+ /** What the binding reads off the prepared leg: its task id (the book's), its run id, its registry access, its session, and its
20
+ * harness's event stream. */
21
+ export interface RunLedgerLeg {
22
+ readonly taskId: string;
23
+ readonly runId: string;
24
+ readonly registryAccess: {
25
+ readonly owner: string;
26
+ readonly scope: string;
27
+ };
28
+ readonly sessionId: string;
29
+ readonly harness: {
30
+ subscribe(listener: (event: {
31
+ readonly type: string;
32
+ readonly toolCallId?: string;
33
+ }) => void): () => void;
34
+ };
35
+ }
36
+ /** The task's member rows as its holder hands them (see the module head): every row of the reach that names the task as its
37
+ * parent, read as one set (no display cap — other tasks' rows in the reach never push a member out). The reach is the leg's own,
38
+ * its tree root's occupant included (`occupant`, the one its registry-facing tools act for): a worker an earlier occupant of a recycled
39
+ * session id started is no member, as it is no task of that leg. */
40
+ export declare function ledgerRegistryRows(access: {
41
+ readonly owner: string;
42
+ readonly scope: string;
43
+ }, sessionId: string, taskId: string, occupant?: string): RunLedgerRegistryRow[];
44
+ /** One member by its id — the same rule, read with no listing at all (a frame's row, however many rows the reach holds). */
45
+ export declare function ledgerMemberRow(access: {
46
+ readonly owner: string;
47
+ readonly scope: string;
48
+ }, sessionId: string, taskId: string, memberId: string, occupant?: string): RunLedgerRegistryRow | undefined;
49
+ /** One registry row as a snapshot reads it: running while its status says so; else the ending its holder minted (a background
50
+ * agent's), else the one its status word names ({@link outcomeOfLegacyRow}) — a parked row's is `parked`. A workflow row carries
51
+ * its run's own member ledger once the run settled. */
52
+ export declare function ledgerRegistryRowOf(r: TaskListRow, name?: string): RunLedgerRegistryRow;
53
+ /** The run-end reap of the run's task-scoped background agents (the teardown's own selection: `skipSessionScoped`), run ahead of a
54
+ * member ledger's last word (r3.1 R1.3: the last word is read after the reap, nothing simulated): the person's-stop mark first when
55
+ * a person stopped the run's work, then the reap with what ended the run, then — when it stopped any — a bounded wait until none
56
+ * of the agents this sweep selects remain running (ignoring monitors, background shells and session-scoped rows). The wait counts
57
+ * the task-scoped agents currently running under this owner, so an agent started by the same owner after the stop pass can hold the
58
+ * last snapshot up to the two-second bound. The teardown's own reap after it finds nothing left to take. */
59
+ export declare function reapTaskAgentsBeforeLastWord(access: {
60
+ readonly owner: string;
61
+ readonly scope: string;
62
+ }, source: "user" | "parent", runEnd: RunEndCause | undefined): Promise<void>;
63
+ /** Bind the book to the prepared leg — see the module head. The book's task is the leg's: a book minted for another task id is an
64
+ * engine fault, refused here rather than read as a ledger of nobody's members. `occupant`: the occupant of the leg's tree root the
65
+ * leg acts for (absent = none read: every row admits it, as on every registry face). */
66
+ export declare function bindRunLedgerBook(book: RunLedgerBook, prepared: RunLedgerLeg, occupant?: string): void;
@@ -0,0 +1,70 @@
1
+ import { abortBackgroundAgentsAtRunEnd, defaultTaskRegistry, onRunEndAgentsSettled } from "./task-registry.js";
2
+ import { occupantStamp } from "./task-registry-shared.js";
3
+ import { outcomeOfLegacyRow } from "./member-outcome.js";
4
+ export function ledgerRegistryRows(access, sessionId, taskId, occupant) {
5
+ const reach = { ...access, sessionId, ...occupantStamp({ rootSessionIncarnation: occupant }) };
6
+ return defaultTaskRegistry.membersOfTask(reach, taskId).flatMap((r) => memberRowOf(r, reach, taskId) ?? []);
7
+ }
8
+ export function ledgerMemberRow(access, sessionId, taskId, memberId, occupant) {
9
+ const reach = { ...access, sessionId, ...occupantStamp({ rootSessionIncarnation: occupant }) };
10
+ const row = defaultTaskRegistry.runEndReading([memberId], reach, access)[0]?.row;
11
+ return row !== undefined ? memberRowOf(row, reach, taskId) : undefined;
12
+ }
13
+ function memberRowOf(r, reach, taskId) {
14
+ if (r.type !== "background_agent" && r.type !== "workflow")
15
+ return undefined;
16
+ const facts = defaultTaskRegistry.getAccessibleTask(r.task_id, reach);
17
+ return facts?.parentTaskId === taskId ? ledgerRegistryRowOf(r, facts.name) : undefined;
18
+ }
19
+ export function ledgerRegistryRowOf(r, name) {
20
+ const running = r.status === "running" || r.status === "pending";
21
+ const kind = r.type === "workflow" ? "workflow" : "background_agent";
22
+ const minted = r.type === "background_agent" ? defaultTaskRegistry.getAgentOutcome(r.task_id) : undefined;
23
+ const outcome = running ? undefined : (minted ?? outcomeOfLegacyRow(r, kind));
24
+ const ledger = r.type === "workflow" && !running ? defaultTaskRegistry.getWorkflowMembers(r.task_id) : undefined;
25
+ const cycle = r.type === "background_agent" ? (defaultTaskRegistry.backgroundAgentCycleSeq(r.task_id) ?? 1) : 1;
26
+ return {
27
+ taskId: r.task_id,
28
+ kind: r.type,
29
+ ...(r.description !== undefined ? { label: r.description } : {}),
30
+ ...(name !== undefined ? { name } : {}),
31
+ running,
32
+ cycle,
33
+ ...(outcome !== undefined ? { outcome } : {}),
34
+ ...(ledger !== undefined ? { members: { coverage: ledger.coverage, counts: ledger.counts } } : {}),
35
+ ...(r.toolUseId !== undefined ? { toolUseId: r.toolUseId } : {}),
36
+ };
37
+ }
38
+ const LAST_WORD_REAP_WAIT_MS = 2_000;
39
+ export async function reapTaskAgentsBeforeLastWord(access, source, runEnd) {
40
+ if (source === "user")
41
+ defaultTaskRegistry.markRunEndAgentsStoppedByUser(access, { skipSessionScoped: true });
42
+ if (abortBackgroundAgentsAtRunEnd(defaultTaskRegistry, access, { skipSessionScoped: true }, runEnd) === 0)
43
+ return;
44
+ let off;
45
+ let timer;
46
+ await new Promise((resolve) => {
47
+ off = onRunEndAgentsSettled(defaultTaskRegistry, access, { skipSessionScoped: true }, resolve);
48
+ if (off === undefined)
49
+ return resolve();
50
+ timer = setTimeout(resolve, LAST_WORD_REAP_WAIT_MS);
51
+ });
52
+ off?.();
53
+ clearTimeout(timer);
54
+ }
55
+ export function bindRunLedgerBook(book, prepared, occupant) {
56
+ if (book.taskId !== undefined && book.taskId !== prepared.taskId)
57
+ throw Object.assign(new Error(`the member ledger book is task "${book.taskId}"'s, but the leg runs as task "${prepared.taskId}"`), { code: "internal.run_ledger_unbound" });
58
+ const taskId = prepared.taskId;
59
+ book.bind(prepared.runId, () => ledgerRegistryRows(prepared.registryAccess, prepared.sessionId, taskId, occupant), (memberId) => ledgerMemberRow(prepared.registryAccess, prepared.sessionId, taskId, memberId, occupant));
60
+ prepared.harness.subscribe((e) => {
61
+ if (e.type === "turn_start")
62
+ return book.turnStarted();
63
+ if (typeof e.toolCallId !== "string")
64
+ return;
65
+ if (e.type === "tool_execution_start")
66
+ book.callStarted(e.toolCallId);
67
+ else if (e.type === "tool_execution_end")
68
+ book.callEnded(e.toolCallId);
69
+ });
70
+ }