@sema-agent/core 5.65.0 → 7.0.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 (165) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/agents/subagent.d.ts +2 -2
  3. package/dist/agents/subagent.js +11 -0
  4. package/dist/agents/verify.d.ts +1 -1
  5. package/dist/brain/anthropic.js +1 -1
  6. package/dist/brain/errors.d.ts +29 -0
  7. package/dist/brain/errors.js +20 -0
  8. package/dist/brain/open-responses.js +2 -2
  9. package/dist/brain/route-adjudicator.d.ts +8 -1
  10. package/dist/brain/route-adjudicator.js +1 -0
  11. package/dist/brain/status-sink.js +12 -1
  12. package/dist/brain/stream-engine.js +17 -6
  13. package/dist/core/auto-compaction.d.ts +26 -0
  14. package/dist/core/auto-compaction.js +7 -2
  15. package/dist/core/auto-mode-arming.d.ts +138 -0
  16. package/dist/core/auto-mode-arming.js +181 -0
  17. package/dist/core/auto-mode-defaults.d.ts +13 -0
  18. package/dist/core/auto-mode-defaults.js +5 -0
  19. package/dist/core/auto-mode-prompt.d.ts +14 -3
  20. package/dist/core/auto-mode-prompt.js +10 -7
  21. package/dist/core/auto-mode-rebuild.d.ts +75 -0
  22. package/dist/core/auto-mode-rebuild.js +41 -0
  23. package/dist/core/auto-mode.d.ts +15 -0
  24. package/dist/core/auto-mode.js +4 -2
  25. package/dist/core/checkpoint-store.d.ts +18 -0
  26. package/dist/core/context-edit.d.ts +47 -5
  27. package/dist/core/context-guard.d.ts +1 -1
  28. package/dist/core/file-history-retention.d.ts +106 -0
  29. package/dist/core/file-history-retention.js +36 -0
  30. package/dist/core/file-history-store.d.ts +768 -0
  31. package/dist/core/file-history-store.js +880 -0
  32. package/dist/core/governance-codes.d.ts +13 -3
  33. package/dist/core/governance-codes.js +15 -0
  34. package/dist/core/hooks.d.ts +39 -7
  35. package/dist/core/hooks.js +38 -21
  36. package/dist/core/lsp.d.ts +2 -2
  37. package/dist/core/mcp.d.ts +29 -7
  38. package/dist/core/memory-engine/consolidation-driver.d.ts +11 -0
  39. package/dist/core/memory-engine/consolidation-driver.js +71 -4
  40. package/dist/core/memory-engine/consolidation.d.ts +25 -2
  41. package/dist/core/memory-engine/consolidation.js +4 -1
  42. package/dist/core/memory-engine/distiller.d.ts +84 -1
  43. package/dist/core/memory-engine/distiller.js +68 -0
  44. package/dist/core/memory-engine/dual-root.js +3 -0
  45. package/dist/core/memory-engine/engine.d.ts +328 -15
  46. package/dist/core/memory-engine/engine.js +355 -29
  47. package/dist/core/memory-engine/file-backend.d.ts +30 -0
  48. package/dist/core/memory-engine/file-backend.js +14 -13
  49. package/dist/core/memory-engine/frontmatter.d.ts +22 -1
  50. package/dist/core/memory-engine/frontmatter.js +3 -0
  51. package/dist/core/memory-engine/header-hints.d.ts +5 -0
  52. package/dist/core/memory-engine/index.d.ts +5 -4
  53. package/dist/core/memory-engine/index.js +5 -4
  54. package/dist/core/memory-engine/layout.d.ts +88 -2
  55. package/dist/core/memory-engine/layout.js +112 -3
  56. package/dist/core/memory-engine/provenance-wording.d.ts +7 -0
  57. package/dist/core/memory-engine/provenance-wording.js +3 -0
  58. package/dist/core/memory-engine/tools.d.ts +89 -8
  59. package/dist/core/memory-engine/tools.js +263 -22
  60. package/dist/core/memory-engine/types.d.ts +64 -1
  61. package/dist/core/memory-recall.d.ts +6 -0
  62. package/dist/core/memory.d.ts +27 -1
  63. package/dist/core/memory.js +16 -2
  64. package/dist/core/permission-rule-consent.d.ts +62 -2
  65. package/dist/core/permission-rule-consent.js +105 -14
  66. package/dist/core/permission-rule-model.d.ts +118 -16
  67. package/dist/core/permission-rule-model.js +57 -9
  68. package/dist/core/permission-rule-session.d.ts +124 -0
  69. package/dist/core/permission-rule-session.js +121 -0
  70. package/dist/core/permission-rule-store.d.ts +65 -2
  71. package/dist/core/permission-rule-store.js +75 -16
  72. package/dist/core/permission-rule-sync.d.ts +9 -0
  73. package/dist/core/permission-rule-sync.js +52 -19
  74. package/dist/core/retention-policy.d.ts +9 -0
  75. package/dist/core/retention-policy.js +5 -2
  76. package/dist/core/retention.d.ts +13 -2
  77. package/dist/core/runner/assemble-result.d.ts +19 -1
  78. package/dist/core/runner/assemble-result.js +17 -2
  79. package/dist/core/runner/compaction-call-options.d.ts +93 -0
  80. package/dist/core/runner/compaction-call-options.js +3 -0
  81. package/dist/core/runner/memory-capture-optout.d.ts +80 -0
  82. package/dist/core/runner/memory-capture-optout.js +53 -0
  83. package/dist/core/runner/prepare-config-doors.d.ts +5 -0
  84. package/dist/core/runner/prepare-config-doors.js +16 -0
  85. package/dist/core/runner/prepare-hands-readface.d.ts +110 -5
  86. package/dist/core/runner/prepare-hands-readface.js +99 -7
  87. package/dist/core/runner/prepare-memory.d.ts +88 -0
  88. package/dist/core/runner/prepare-memory.js +305 -24
  89. package/dist/core/runner/prepare-task.d.ts +141 -1
  90. package/dist/core/runner/prepare-task.js +478 -81
  91. package/dist/core/runner/runtask.d.ts +9 -20
  92. package/dist/core/runner/runtask.js +133 -96
  93. package/dist/core/runner/session-file-state-replay.d.ts +18 -10
  94. package/dist/core/runner/session-file-state-replay.js +52 -1
  95. package/dist/core/runner/tool-disclosure.js +2 -1
  96. package/dist/core/runner/turn-attachments.d.ts +22 -12
  97. package/dist/core/session-store.d.ts +1 -1
  98. package/dist/core/session-store.js +6 -1
  99. package/dist/core/session.d.ts +34 -1
  100. package/dist/core/store-contracts/file-history-store-contract.d.ts +3 -0
  101. package/dist/core/store-contracts/file-history-store-contract.js +720 -0
  102. package/dist/core/store-contracts/permission-rule-sync-contract.js +15 -1
  103. package/dist/core/task-registry-shared.js +11 -1
  104. package/dist/core/tool-errors.js +1 -0
  105. package/dist/core/tool-policy.d.ts +172 -1
  106. package/dist/core/tool-policy.js +32 -1
  107. package/dist/core/tool-result-store.js +2 -1
  108. package/dist/core/trace.d.ts +31 -2
  109. package/dist/core/types.d.ts +795 -89
  110. package/dist/core/types.js +4 -3
  111. package/dist/core/untrusted-text.d.ts +1 -1
  112. package/dist/core/untrusted-text.js +8 -0
  113. package/dist/core/workflow-run-store-contract.js +6 -2
  114. package/dist/core/workflow-run-store.d.ts +4 -1
  115. package/dist/engine/compaction/compaction.d.ts +88 -10
  116. package/dist/engine/compaction/compaction.js +109 -30
  117. package/dist/engine/execution-env/node-execution-env.d.ts +9 -1
  118. package/dist/engine/execution-env/node-execution-env.js +28 -0
  119. package/dist/engine/harness/agent-harness.d.ts +52 -1
  120. package/dist/engine/harness/agent-harness.js +36 -1
  121. package/dist/engine/harness/types.d.ts +26 -1
  122. package/dist/engine/llm/types.d.ts +50 -4
  123. package/dist/engine/loop/agent-loop.d.ts +5 -1
  124. package/dist/engine/loop/agent-loop.js +25 -0
  125. package/dist/engine/loop/types.d.ts +19 -0
  126. package/dist/engine/lsp/node-lsp-manager.d.ts +1 -1
  127. package/dist/engine/session/session.js +1 -1
  128. package/dist/index.d.ts +20 -9
  129. package/dist/index.js +16 -7
  130. package/dist/orchestration/run-workflow-tool.d.ts +20 -2
  131. package/dist/orchestration/run-workflow-tool.js +22 -3
  132. package/dist/orchestration/workflow-governance.d.ts +59 -1
  133. package/dist/orchestration/workflow-governance.js +61 -8
  134. package/dist/orchestration/workflow-meta.d.ts +4 -2
  135. package/dist/orchestration/workflow-primitives.js +56 -13
  136. package/dist/orchestration/workflow-types.d.ts +78 -2
  137. package/dist/orchestration/workflow.d.ts +20 -0
  138. package/dist/orchestration/workflow.js +163 -14
  139. package/dist/prompt-assembly/event-registry.js +1 -1
  140. package/dist/prompts/default.d.ts +7 -7
  141. package/dist/stores/file/file-history-store.d.ts +368 -0
  142. package/dist/stores/file/file-history-store.js +1248 -0
  143. package/dist/stores/file/index.d.ts +22 -13
  144. package/dist/stores/file/index.js +4 -4
  145. package/dist/stores/file/permission-rule-store.d.ts +11 -0
  146. package/dist/stores/file/permission-rule-store.js +23 -9
  147. package/dist/stores/file/strategy-store.d.ts +3 -3
  148. package/dist/tools/fs/bash-readonly-classifier.d.ts +87 -3
  149. package/dist/tools/fs/bash-readonly-classifier.js +106 -4
  150. package/dist/tools/fs/fs-bash.js +9 -5
  151. package/dist/tools/fs/fs-shared.d.ts +52 -1
  152. package/dist/tools/fs/fs-shared.js +14 -0
  153. package/dist/tools/fs/fs-write.d.ts +5 -5
  154. package/dist/tools/fs/fs-write.js +71 -14
  155. package/dist/tools/fs/index.d.ts +6 -1
  156. package/dist/tools/fs/index.js +1 -1
  157. package/dist/tools/web.js +2 -1
  158. package/package.json +5 -1
  159. package/test/export-surface.snapshot.json +169 -23
  160. package/dist/core/file-snapshot-store.d.ts +0 -165
  161. package/dist/core/file-snapshot-store.js +0 -259
  162. package/dist/core/store-contracts/file-snapshot-store-contract.d.ts +0 -13
  163. package/dist/core/store-contracts/file-snapshot-store-contract.js +0 -134
  164. package/dist/stores/file/file-snapshot-store.d.ts +0 -58
  165. package/dist/stores/file/file-snapshot-store.js +0 -353
@@ -0,0 +1,106 @@
1
+ /**
2
+ * design/381 §片2 — the engine's OWN bound on file-history growth, and the door its one knob passes
3
+ * through.
4
+ *
5
+ * The hole this closes: `FileHistoryStore.reap` is a complete, contract-tested GC verb that nothing
6
+ * in the engine ever called. Every turn of a wired session commits one more boundary, each boundary
7
+ * is a complete mapping over the tracked set, and no seat anywhere dropped the old ones — so a long
8
+ * session's history grew without bound, silently, which is precisely the shape the bad-value
9
+ * loudness rule exists to forbid (a limit nobody states is still a limit; it is just the disk's).
10
+ * The bundled backends therefore carry the bound THEMSELVES: each one commits a boundary and then
11
+ * trims its scope back to the retention bound, and a host that wants the GC schedule for itself
12
+ * says so (`keep: "unbounded"`) rather than discovering the default by running out of disk.
13
+ *
14
+ * PROVENANCE OF THE DEFAULT (not a taste call, and not a JSDoc-only constraint): the reference
15
+ * implementation caps its own file-history at the newest 100 snapshots and evicts the rest — CC
16
+ * 2.1.250 holds the cap as a module constant (`R1e = 100`) and applies it in the snapshot reducer
17
+ * (`if (E.length > R1e) R = E.slice(-R1e), <evict>(E.slice(0, E.length - R1e), R, …).catch(…)`),
18
+ * i.e. keep the newest N by commit order, hand the evicted ones to a best-effort eviction pass, and
19
+ * never let that pass fail the turn that triggered it. Its eviction unlinks a backup only when no
20
+ * surviving snapshot references it AND its version is not 1 — the same v1-permanence law this
21
+ * store's `reap` already implements. design/381 §片2 carries the number over as "边界上限(默认
22
+ * 100,store 旋钮)", which is the shape below: engine default, store-level, host-overridable.
23
+ *
24
+ * @see {@link import("./retention-policy.js").assertRetentionPolicy} — the sibling row stores' door.
25
+ * This one is separate because its admissible range is different (see {@link refuseRetentionPolicy}).
26
+ */
27
+ export declare const DEFAULT_FILE_HISTORY_BOUNDARY_KEEP = 100;
28
+ /**
29
+ * The file-history retention knob, as a deployment writes it. ONE knob on purpose — the graph has
30
+ * exactly one unbounded dimension (boundaries per scope); version records and blobs are already
31
+ * bounded by it, because `reap` drops every version no surviving boundary references (v1 and the
32
+ * base-unavailable markers excepted, which are per tracked file, not per turn).
33
+ *
34
+ * Absent ⇒ {@link DEFAULT_FILE_HISTORY_BOUNDARY_KEEP}. Every other reading of a badly-formed value
35
+ * is a REFUSAL at construction, never a quiet fallback — see {@link resolveFileHistoryRetention}.
36
+ */
37
+ export interface FileHistoryRetentionPolicy {
38
+ /**
39
+ * How many of a scope's NEWEST boundaries survive each retention pass. A whole number `>= 1`, or
40
+ * the literal `"unbounded"` to switch the store's self-trim OFF and take the GC schedule over
41
+ * (the host then owns calling {@link import("./file-history-store.js").FileHistoryStore.reap};
42
+ * nothing else collects boundaries).
43
+ *
44
+ * `0` is REFUSED rather than accepted as "keep nothing": a boundary is minted by the very commit
45
+ * that would then reap it, so a store configured that way would answer `ok` to every `snapshot`
46
+ * and `false` to every `canRestore` — a rewind seat that is on, reports success, and can never
47
+ * restore anything. `"unbounded"` is the ONE spelling of "do not trim"; omitting the knob is NOT
48
+ * that spelling — it selects the engine default and therefore trims (cross-review round 3 caught
49
+ * this said the opposite here and in the refusal text, which would have sent an operator who
50
+ * wanted everything kept down the path that deletes).
51
+ */
52
+ keep?: number | "unbounded";
53
+ }
54
+ /**
55
+ * The retention door: resolve a deployment's policy to a boundary cap, or REFUSE loudly.
56
+ *
57
+ * Returns the cap (a whole number `>= 1`), or `null` for the explicit `"unbounded"` opt-out. Called
58
+ * at CONSTRUCTION by every bundled backend, so a malformed policy fails where the operator wired it
59
+ * rather than mid-session inside a GC pass they cannot see.
60
+ *
61
+ * The three ways a value can be bad each get their own named exit — none of them falls back to the
62
+ * default, because a retention knob that quietly became a different number is the failure this whole
63
+ * seam exists to remove:
64
+ * 1. GARBAGE — the policy is not a knob bag, a knob is misspelled, or `keep` is not a whole number
65
+ * (NaN from a `Number(cfg.keep)` on a missing field, `Infinity`, `2.5`, `"100"`, `null`).
66
+ * 2. OUT OF RANGE — a negative `keep`. (Reached by the same route as NaN in the sibling stores'
67
+ * history: `slice(Math.max(0, keep))` turns both into `slice(0)` = delete everything.)
68
+ * 3. CONTRADICTORY — `keep: 0`, well-formed and in the range its siblings accept, but self-cancelling
69
+ * here; refused with the ONE spelling of "do not trim" named, and with what omission really does
70
+ * said out loud so the remediation cannot be followed into the opposite outcome.
71
+ *
72
+ * @param label the seam the operator configured, so the refusal names it.
73
+ */
74
+ export declare function resolveFileHistoryRetention(label: string, policy: FileHistoryRetentionPolicy | undefined): number | null;
75
+ /**
76
+ * Which boundaries survive the pass that `justCommitted`'s commit triggered — the SELECTION half,
77
+ * shared so the two bundled backends (and an out-of-tree twin) cannot drift on which boundary dies.
78
+ *
79
+ * Returns `null` when the scope is still within its bound, which is the answer the caller wants
80
+ * cheaply: no `reap` call at all, so a session under the cap pays one directory listing per turn and
81
+ * nothing else. Otherwise returns the keep set for
82
+ * {@link import("./file-history-store.js").FileHistoryStore.reap} — the newest `keep` ids, with
83
+ * `justCommitted` PINNED into it unconditionally.
84
+ *
85
+ * The pin is not belt-and-braces. `orderedOldestFirst` is whatever commit order its backend can
86
+ * PROVE, and the two bundled ones prove different amounts: the in-memory reference reads an
87
+ * insertion-ordered map (exact), while the durable one reads each boundary's own publication stamp,
88
+ * falling back to file mtime for records written before that field or rebuilt from an import, and
89
+ * to the entry id for ties. A clock stepped backwards, or a host minting non-monotonic ids of its
90
+ * own, can still invert two neighbours there.
91
+ * An ordering that is off by one place costs a different-but-equally-legal retention choice; an
92
+ * ordering that put the JUST-COMMITTED boundary at the bottom would cost this turn its rewind seat.
93
+ * Pinning makes the second outcome unreachable by construction rather than by trusting the clock.
94
+ *
95
+ * One more place the order is only as good as its source, said plainly rather than assumed away: an
96
+ * envelope round trip (`exportHistory` → `importHistory`) writes boundaries in CANONICAL — i.e.
97
+ * lexicographic — entry-id order, so a scope rebuilt from one has entry-id order where it used to
98
+ * have commit order. For engine-minted uuidv7 ids those are the same order; for a foreign graph's
99
+ * ids they need not be, and such a scope's oldest-first reading is by id. The consequence is again
100
+ * only WHICH legal boundary is retained, and the just-committed pin still holds.
101
+ *
102
+ * @param orderedOldestFirst every committed boundary id in the scope, oldest first.
103
+ * @param justCommitted the boundary whose commit triggered the pass.
104
+ * @param keep the resolved cap (`>= 1`).
105
+ */
106
+ export declare function fileHistoryBoundariesToKeep(orderedOldestFirst: readonly string[], justCommitted: string, keep: number): string[] | null;
@@ -0,0 +1,36 @@
1
+ import { refuseRetentionPolicy } from "./retention-policy.js";
2
+ export const DEFAULT_FILE_HISTORY_BOUNDARY_KEEP = 100;
3
+ const KNOWN_KNOBS = new Set(["keep"]);
4
+ export function resolveFileHistoryRetention(label, policy) {
5
+ if (policy === undefined)
6
+ return DEFAULT_FILE_HISTORY_BOUNDARY_KEEP;
7
+ if (typeof policy !== "object" || policy === null || Array.isArray(policy)) {
8
+ refuseRetentionPolicy(label, "retention", policy, `an object of retention knobs (${[...KNOWN_KNOBS].join(", ")}) or omitted`);
9
+ }
10
+ const unknown = Object.keys(policy).filter((k) => !KNOWN_KNOBS.has(k));
11
+ if (unknown.length > 0) {
12
+ const first = unknown[0];
13
+ refuseRetentionPolicy(label, `retention.${first}`, policy[first], `omitted — ${JSON.stringify(first)} is not a retention knob (the only knob is "keep"), and a misspelled one would leave the engine default in force while the operator believes their own number is`);
14
+ }
15
+ const keep = policy.keep;
16
+ if (keep === undefined)
17
+ return DEFAULT_FILE_HISTORY_BOUNDARY_KEEP;
18
+ if (keep === "unbounded")
19
+ return null;
20
+ if (keep === 0) {
21
+ refuseRetentionPolicy(label, "retention.keep", keep, `at least 1 boundary — a cap of 0 would reap the boundary its own commit just minted, leaving a rewind seat that answers ok to every snapshot and false to every canRestore; write "unbounded" to mean "do not trim" (omitting the knob does NOT mean that — it selects the engine default of ${DEFAULT_FILE_HISTORY_BOUNDARY_KEEP})`);
22
+ }
23
+ if (typeof keep !== "number" || !Number.isInteger(keep) || keep < 1) {
24
+ refuseRetentionPolicy(label, "retention.keep", keep, `a whole number of boundaries, 1 or more, or the literal "unbounded"`);
25
+ }
26
+ return keep;
27
+ }
28
+ export function fileHistoryBoundariesToKeep(orderedOldestFirst, justCommitted, keep) {
29
+ if (orderedOldestFirst.length <= keep)
30
+ return null;
31
+ const survivors = new Set([justCommitted]);
32
+ for (let i = orderedOldestFirst.length - 1; i >= 0 && survivors.size < keep; i--) {
33
+ survivors.add(orderedOldestFirst[i]);
34
+ }
35
+ return [...survivors];
36
+ }