@sema-agent/core 7.61.0 → 7.62.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 (176) hide show
  1. package/CHANGELOG.md +312 -0
  2. package/dist/agents/cascade.d.ts +11 -3
  3. package/dist/agents/cascade.js +1 -1
  4. package/dist/agents/peer-held-queue.d.ts +27 -4
  5. package/dist/agents/peer-held-queue.js +81 -36
  6. package/dist/agents/peer-session-drain.js +13 -3
  7. package/dist/agents/subagent.d.ts +6 -1
  8. package/dist/agents/subagent.js +66 -12
  9. package/dist/agents/suspend-guard.d.ts +38 -16
  10. package/dist/agents/suspend-guard.js +9 -4
  11. package/dist/agents/verify.js +4 -3
  12. package/dist/core/checkpoint-features.d.ts +722 -0
  13. package/dist/core/checkpoint-features.js +98 -0
  14. package/dist/core/checkpoint-requirements.d.ts +9 -2
  15. package/dist/core/checkpoint-requirements.js +9 -4
  16. package/dist/core/checkpoint-row-verdict.d.ts +99 -0
  17. package/dist/core/checkpoint-row-verdict.js +225 -0
  18. package/dist/core/checkpoint-store.d.ts +55 -745
  19. package/dist/core/checkpoint-store.js +39 -141
  20. package/dist/core/engine-notice.d.ts +19 -3
  21. package/dist/core/engine-notice.js +9 -2
  22. package/dist/core/gate-fold.js +2 -2
  23. package/dist/core/governance-codes.d.ts +3 -1
  24. package/dist/core/governance-codes.js +3 -0
  25. package/dist/core/hooks.d.ts +13 -0
  26. package/dist/core/human-input-projection.d.ts +1 -0
  27. package/dist/core/human-input-projection.js +3 -0
  28. package/dist/core/image-admission.d.ts +1 -1
  29. package/dist/core/locked-config.d.ts +2 -2
  30. package/dist/core/mcp-host-seat.js +6 -1
  31. package/dist/core/memory-engine/consolidation-driver.d.ts +1 -1
  32. package/dist/core/memory-vector.d.ts +1 -1
  33. package/dist/core/memory.d.ts +10 -10
  34. package/dist/core/mode-policy.js +1 -1
  35. package/dist/core/mods/classic-events.d.ts +9 -1
  36. package/dist/core/mods/dollar.d.ts +32 -1
  37. package/dist/core/mods/dollar.js +13 -1
  38. package/dist/core/mods/kernel/events.d.ts +11 -3
  39. package/dist/core/mods/kernel/events.js +13 -10
  40. package/dist/core/mods/lifecycle-stations.d.ts +36 -4
  41. package/dist/core/mods/lifecycle-stations.js +44 -9
  42. package/dist/core/mods/session-append.d.ts +4 -1
  43. package/dist/core/mods/session-append.js +7 -0
  44. package/dist/core/mods/session-receive.js +12 -15
  45. package/dist/core/mods/stations.d.ts +51 -6
  46. package/dist/core/mods/stations.js +124 -0
  47. package/dist/core/own-property-receipt.d.ts +7 -0
  48. package/dist/core/own-property-receipt.js +3 -0
  49. package/dist/core/read-root-candidate.js +1 -1
  50. package/dist/core/resume-startup-cause.d.ts +5 -4
  51. package/dist/core/runner/compact-session.js +5 -2
  52. package/dist/core/runner/contracts.d.ts +18 -8
  53. package/dist/core/runner/delegation-owner.d.ts +43 -0
  54. package/dist/core/runner/delegation-owner.js +59 -0
  55. package/dist/core/runner/lineage-reroot-view.d.ts +56 -0
  56. package/dist/core/runner/lineage-reroot-view.js +108 -0
  57. package/dist/core/runner/permission-rule-lanes.d.ts +2 -1
  58. package/dist/core/runner/permission-rule-lanes.js +2 -2
  59. package/dist/core/runner/person-path-rows.d.ts +15 -0
  60. package/dist/core/runner/person-path-rows.js +26 -3
  61. package/dist/core/runner/prepare-acquire-reconcile.d.ts +4 -1
  62. package/dist/core/runner/prepare-acquire-reconcile.js +7 -2
  63. package/dist/core/runner/prepare-caps-and-workflow.d.ts +1 -0
  64. package/dist/core/runner/prepare-caps-and-workflow.js +1 -1
  65. package/dist/core/runner/prepare-config-doors.d.ts +6 -6
  66. package/dist/core/runner/prepare-config-doors.js +3 -4
  67. package/dist/core/runner/prepare-hands-readface.d.ts +1 -1
  68. package/dist/core/runner/prepare-hands-readface.js +28 -7
  69. package/dist/core/runner/prepare-inherited-gate.d.ts +2 -0
  70. package/dist/core/runner/prepare-inherited-gate.js +7 -3
  71. package/dist/core/runner/prepare-task.js +10 -7
  72. package/dist/core/runner/resume-admission.d.ts +3 -3
  73. package/dist/core/runner/resume-admission.js +6 -3
  74. package/dist/core/runner/resume-apply.d.ts +4 -0
  75. package/dist/core/runner/resume-apply.js +11 -4
  76. package/dist/core/runner/resume-checkpoint-screen.d.ts +9 -0
  77. package/dist/core/runner/resume-checkpoint-screen.js +4 -84
  78. package/dist/core/runner/run-git-lane.d.ts +2 -0
  79. package/dist/core/runner/run-git-lane.js +4 -1
  80. package/dist/core/runner/run-harness-handlers.d.ts +2 -0
  81. package/dist/core/runner/run-harness-handlers.js +3 -2
  82. package/dist/core/runner/run-leg.js +24 -7
  83. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  84. package/dist/core/runner/run-stop-and-final-verify.js +2 -1
  85. package/dist/core/runner/run-turn-boundary.js +7 -4
  86. package/dist/core/runner/runtask.js +6 -6
  87. package/dist/core/runner/steering-preview.d.ts +9 -0
  88. package/dist/core/runner/steering-preview.js +5 -0
  89. package/dist/core/runner/stream-steer-verb.js +8 -0
  90. package/dist/core/runner/tool-face-overlay.js +2 -0
  91. package/dist/core/runner/turn-attachments.d.ts +5 -0
  92. package/dist/core/runner/turn-attachments.js +1 -1
  93. package/dist/core/runner-deps.d.ts +2 -2
  94. package/dist/core/secret-env.d.ts +8 -5
  95. package/dist/core/secret-env.js +37 -18
  96. package/dist/core/session-store.d.ts +1 -1
  97. package/dist/core/session-store.js +5 -1
  98. package/dist/core/session.d.ts +14 -4
  99. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +6 -0
  100. package/dist/core/store-contracts/checkpoint-store-contract.js +68 -0
  101. package/dist/core/store-contracts/session-store-contract.js +22 -8
  102. package/dist/core/task-event.d.ts +7 -1
  103. package/dist/core/task-notification.js +2 -1
  104. package/dist/core/task-registry-agent.d.ts +27 -7
  105. package/dist/core/task-registry-agent.js +12 -5
  106. package/dist/core/task-registry-shared.d.ts +7 -0
  107. package/dist/core/task-registry-workflow.js +4 -3
  108. package/dist/core/task-registry.d.ts +13 -2
  109. package/dist/core/task-registry.js +11 -4
  110. package/dist/core/task-result.d.ts +5 -5
  111. package/dist/core/task-spec.d.ts +1 -1
  112. package/dist/core/terminal-cause.d.ts +6 -6
  113. package/dist/core/tool-face.d.ts +6 -2
  114. package/dist/core/tool-face.js +1 -1
  115. package/dist/core/tool-policy.d.ts +2 -1
  116. package/dist/core/tool-roster.d.ts +4 -4
  117. package/dist/core/tool-spec.d.ts +4 -0
  118. package/dist/core/types.d.ts +1 -1
  119. package/dist/core/types.js +1 -1
  120. package/dist/engine/execution-env/node-execution-env.d.ts +3 -0
  121. package/dist/engine/execution-env/node-execution-env.js +12 -5
  122. package/dist/engine/harness/types.d.ts +11 -0
  123. package/dist/engine/session/parent-chain-guard.d.ts +3 -3
  124. package/dist/engine/session/parent-chain-guard.js +1 -1
  125. package/dist/engine/session/path-to-root.d.ts +18 -3
  126. package/dist/engine/session/path-to-root.js +15 -1
  127. package/dist/engine/session/repo-utils.d.ts +12 -1
  128. package/dist/engine/session/repo-utils.js +41 -0
  129. package/dist/engine/session/session.js +1 -1
  130. package/dist/engine/session/storage-base.d.ts +20 -0
  131. package/dist/engine/session/storage-base.js +28 -9
  132. package/dist/index.d.ts +9 -8
  133. package/dist/index.js +4 -4
  134. package/dist/internal/harness.d.ts +4 -3
  135. package/dist/internal/harness.js +3 -2
  136. package/dist/orchestration/run-workflow-tool.d.ts +3 -0
  137. package/dist/orchestration/run-workflow-tool.js +27 -11
  138. package/dist/orchestration/workflow-governance.d.ts +1 -1
  139. package/dist/orchestration/workflow.d.ts +3 -0
  140. package/dist/orchestration/workflow.js +2 -7
  141. package/dist/stores/file/checkpoint-store.d.ts +2 -0
  142. package/dist/stores/file/checkpoint-store.js +7 -6
  143. package/dist/stores/file/fs-atomic.d.ts +0 -22
  144. package/dist/stores/file/fs-atomic.js +0 -17
  145. package/dist/stores/file/index.d.ts +2 -9
  146. package/dist/stores/file/index.js +2 -4
  147. package/dist/stores/file/session-store.d.ts +13 -7
  148. package/dist/stores/file/session-store.js +40 -17
  149. package/dist/tools/fs/bash-program-position.d.ts +3 -2
  150. package/dist/tools/fs/bash-program-position.js +7 -7
  151. package/dist/tools/fs/removal-targets.js +2 -2
  152. package/dist/tools/fs/shell-read-argv.d.ts +4 -2
  153. package/dist/tools/fs/shell-read-argv.js +14 -3
  154. package/dist/tools/fs/shell-read-bindings.d.ts +18 -2
  155. package/dist/tools/fs/shell-read-bindings.js +148 -68
  156. package/dist/tools/fs/shell-read-check.js +20 -4
  157. package/dist/tools/fs/shell-read-establish.js +22 -8
  158. package/dist/tools/fs/shell-read-functions.js +2 -2
  159. package/dist/tools/fs/shell-read-object-path.d.ts +59 -0
  160. package/dist/tools/fs/shell-read-object-path.js +119 -0
  161. package/dist/tools/fs/shell-read-plan.d.ts +8 -0
  162. package/dist/tools/fs/shell-read-plan.js +47 -30
  163. package/dist/tools/fs/shell-read-start.d.ts +66 -13
  164. package/dist/tools/fs/shell-read-start.js +89 -17
  165. package/dist/tools/fs/shell-read-workdir.d.ts +29 -8
  166. package/dist/tools/fs/shell-read-workdir.js +31 -8
  167. package/package.json +2 -2
  168. package/test/export-surface.snapshot.json +21 -33
  169. package/wire-changes/core-stores-sql@7.62.0.json +30 -0
  170. package/wire-changes/core@7.62.0.json +2181 -0
  171. package/wire-changes/mods-kernel@7.62.0.json +42 -0
  172. package/wire-changes/primitives@7.62.0.json +30 -0
  173. package/dist/core/consolidate-scope.d.ts +0 -93
  174. package/dist/core/consolidate-scope.js +0 -98
  175. package/dist/core/runner/memory-consolidation.d.ts +0 -109
  176. package/dist/core/runner/memory-consolidation.js +0 -251
@@ -0,0 +1,98 @@
1
+ import { PROBE_CAUSE_PATH_MAX, PROBE_REASON_MAX, inlineUntrusted } from "./untrusted-text.js";
2
+ export function isPlainRecord(x) {
3
+ try {
4
+ if (x === null || typeof x !== "object" || Array.isArray(x))
5
+ return false;
6
+ const p = Object.getPrototypeOf(x);
7
+ return p === Object.prototype || p === null;
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }
13
+ export function safeDataValue(obj, key) {
14
+ try {
15
+ const d = Object.getOwnPropertyDescriptor(obj, key);
16
+ return d && "value" in d ? d.value : undefined;
17
+ }
18
+ catch {
19
+ return undefined;
20
+ }
21
+ }
22
+ const PROBE_CAUSE_MAX_SHOWN = 8;
23
+ export function normalizeProbeCause(value) {
24
+ if (!isPlainRecord(value))
25
+ return undefined;
26
+ const code = safeDataValue(value, "code");
27
+ if (typeof code !== "string" || code.trim().length === 0)
28
+ return undefined;
29
+ const family = (raw) => {
30
+ if (!isPlainRecord(raw))
31
+ return undefined;
32
+ const shownRaw = safeDataValue(raw, "shown");
33
+ if (!Array.isArray(shownRaw))
34
+ return undefined;
35
+ const shown = shownRaw
36
+ .filter((p) => typeof p === "string")
37
+ .slice(0, PROBE_CAUSE_MAX_SHOWN)
38
+ .map((p) => inlineUntrusted(p, PROBE_CAUSE_PATH_MAX));
39
+ const totalRaw = safeDataValue(raw, "total");
40
+ const total = typeof totalRaw === "number" && Number.isFinite(totalRaw) ? Math.max(0, Math.floor(totalRaw)) : shown.length;
41
+ return { shown, total: Math.max(total, shown.length) };
42
+ };
43
+ const roots = family(safeDataValue(value, "roots"));
44
+ if (roots === undefined)
45
+ return undefined;
46
+ const further = family(safeDataValue(value, "further"));
47
+ return {
48
+ code: inlineUntrusted(code, PROBE_REASON_MAX),
49
+ roots,
50
+ ...(further !== undefined && further.total > 0 ? { further } : {}),
51
+ };
52
+ }
53
+ export const CHECKPOINT_FEATURES = {
54
+ baseline: { version: 1, introduced: "design/49", writes: "the row itself" },
55
+ resource: { version: 2, introduced: "design/74", writes: "resourceLedger; gate/pendingAction kind resource_limit" },
56
+ binding: { version: 3, introduced: "design/80", writes: "pendingAction.boundCallId + boundInputHash on a tool_approval; a plan_review carries the stamp only" },
57
+ token: { version: 5, introduced: "design/164", writes: "resourceLedger.totalTokens" },
58
+ orgAdmission: { version: 6, introduced: "org-admission", writes: "inheritedGate.admittedOrgScopes / ownAdmittedOrgScopes / ownAdmittedOrgWriteScope / orgAdmissionGoverned" },
59
+ f012: { version: 7, introduced: "F-012", writes: "inheritedGate.constraintChain + constraintDigest together; delegationProvenance" },
60
+ realApproval: { version: 8, introduced: "#130/#120", writes: "gate.realApproval (a well-formed bit) + pendingAction.requiresRealApproval; from v9: readFace.realApproval = true beside it" },
61
+ face: { version: 9, introduced: "design/199", writes: "state.readFace { face, denyEntries? } for a non-default posture; realApproval: true only at the mint whose gate carries the bit (a hands-less re-park never carries the seed's marker forward)" },
62
+ requirements: { version: 10, introduced: "#1320", writes: "requires (the row's words) + requirementsDigest (the row digest), both derived from its content (checkpoint-requirements.ts)" },
63
+ };
64
+ export const CURRENT_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.baseline.version;
65
+ export const RESOURCE_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.resource.version;
66
+ export const BINDING_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.binding.version;
67
+ export const TOKEN_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.token.version;
68
+ export const ORG_ADMISSION_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.orgAdmission.version;
69
+ export const F012_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.f012.version;
70
+ export const REAL_APPROVAL_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.realApproval.version;
71
+ export const FACE_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.face.version;
72
+ export const MAX_SUPPORTED_CHECKPOINT_VERSION = CHECKPOINT_FEATURES.requirements.version;
73
+ export function checkpointVersionOf(cp) {
74
+ return cp.version ?? 0;
75
+ }
76
+ export const CHECKPOINT_CONFIG_REFUSAL_CODES = Object.freeze(["config.spec_retired_key", "config.output_style_invalid", "config.permission_mode_invalid", "config.shell_gate_value_retired", "config.approval_reach_invalid", "config.run_origin_invalid", "config.user_invoked_skill_unknown", "config.skill_deny_unreadable", "config.user_attachment_invalid", "config.tool_face_control", "config.deps_retired_key", "config.peer_presence_invalid", "config.tool_model_gate_invalid", "config.microcompact_invalid", "config.prompt_selector_invalid", "resume_at.conflicts_resume", "resume_at.mode_without_target", "config.read_face_invalid", "config.write_face_invalid", "config.invalid_argument", "config.tool_face_invalid", "config.memory_delegation_evidence", "config.memory_provenance", "config.memory_capture_policy", "config.cross_boundary_posture", "config.advisor_tool_invalid", "config.advisor_model_invalid", "config.auto_consolidation", "config.unknown_role", "config.tool_materialize_invalid", "config.memory_persistence_invalid", "config.tool_materialize_unreachable", "config.locked_registry", "config.locked_key", "config.mcp_content_class", "config.skill_listing_budget_invalid", "config.limit_unknown_key", "config.limit_invalid", "config.attachment_invalid", "config.usage_window_invalid", "config.brain_call_guardrail_invalid", "config.retention_policy", "config.retention_capability", "config.invalid_checkpoint_store", "config.skill_base_dir_invalid", "config.host_floor_invalid", "config.credential_in_declaration", "config.credential_ref_invalid", "config.peer_seat_missing", "config.spec_member_unreadable", "config.spec_unknown_key"]);
77
+ export const isCheckpointConfigRefusalCode = (word) => CHECKPOINT_CONFIG_REFUSAL_CODES.some((w) => w === word);
78
+ export class CheckpointError extends Error {
79
+ code;
80
+ detail;
81
+ constructor(code, message, detail) {
82
+ super(message);
83
+ this.code = code;
84
+ this.detail = detail;
85
+ this.name = "CheckpointError";
86
+ }
87
+ }
88
+ export function encodeAtFidelity(fidelity, value) {
89
+ if (fidelity === "structured-clone")
90
+ return { ok: true, value };
91
+ try {
92
+ const encoded = JSON.stringify(value);
93
+ return { ok: true, value: encoded === undefined ? undefined : JSON.parse(encoded) };
94
+ }
95
+ catch (err) {
96
+ return { ok: false, cause: err };
97
+ }
98
+ }
@@ -1,5 +1,6 @@
1
1
  import type { AssertAllKeysHandled } from "./ask-origin.js";
2
- import { type StoreFidelity, type Checkpoint, type CheckpointFeature, type CheckpointGate, type PendingAction } from "./checkpoint-store.js";
2
+ import { type CheckpointFeature } from "./checkpoint-features.js";
3
+ import type { StoreFidelity, Checkpoint, CheckpointGate, PendingAction } from "./checkpoint-store.js";
3
4
  /**
4
5
  * The closed set of reader-requirement words this engine knows. The first seven are the feature table's keys
5
6
  * (the features that raised the row format before it froze); then the row digest's scheme; then the members a feature
@@ -944,7 +945,13 @@ export declare function requirementsDigestOf(cp: Checkpoint): string;
944
945
  * fidelity, and writes exactly the row returned here), with the frozen version, the row digest of that reading and
945
946
  * the words derived from it (the digest's word among them) — so a reader digests exactly what it read. A row that
946
947
  * store's codec or the digest cannot encode is returned WITHOUT a digest, so it fails its own judge — which the
947
- * commit asks before the write. */
948
+ * commit asks before the write.
949
+ *
950
+ * ONE ABSENCE FORM: the row's top level and its `state` are written with an absent member OMITTED — a mint site may
951
+ * spell one as a key holding `undefined` (the state serializer names every member), and the stamp leaves that key out —
952
+ * so every store holds an engine-written row with one key set, and a key-reading answers as the value-reading does. The
953
+ * members below those two levels are written as given: a tool call's arguments, a decision-read record and the
954
+ * resource ledger are data whose keys the binding hash, the digest and the park's argument comparison read. */
948
955
  export declare function stampCheckpointRequirements(row: Checkpoint, fidelity: StoreFidelity): Checkpoint;
949
956
  /** The row as the store at `fidelity` hands it back, judged — the commit's question before the write. */
950
957
  export declare function judgeAsStored(cp: Checkpoint, fidelity: StoreFidelity): CheckpointRequirementsVerdict;
@@ -1,6 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { canonicalize, MAX_DEPTH, UNCANONICALIZABLE } from "./canonical-json.js";
3
- import { CHECKPOINT_FEATURES, checkpointVersionOf, encodeAtFidelity } from "./checkpoint-store.js";
3
+ import { CHECKPOINT_FEATURES, checkpointVersionOf, encodeAtFidelity } from "./checkpoint-features.js";
4
+ import { memberPresent } from "./own-property-receipt.js";
4
5
  export const REQUIREMENT_WORDS = Object.freeze([
5
6
  "resource",
6
7
  "binding",
@@ -198,9 +199,9 @@ function digestedMembers(record, table, path, out) {
198
199
  for (const [key, cls] of Object.entries(table)) {
199
200
  if ("ignorable" in cls || "mutable" in cls)
200
201
  continue;
201
- const value = Reflect.get(record, key);
202
- if (value === undefined)
202
+ if (!memberPresent(record, key))
203
203
  continue;
204
+ const value = Reflect.get(record, key);
204
205
  const at = path === "" ? key : `${path}.${key}`;
205
206
  if ("word" in cls)
206
207
  out.push({ path: at, word: cls.word, value });
@@ -296,8 +297,12 @@ function digestOrUnencodable(cp) {
296
297
  }
297
298
  }
298
299
  const unencodableWhy = (at) => `a member a decision reads cannot be encoded: ${at.path} (${at.kind})`;
300
+ function presentMembersOf(record) {
301
+ return Object.fromEntries(Object.entries(record).filter(([name]) => memberPresent(record, name)));
302
+ }
299
303
  export function stampCheckpointRequirements(row, fidelity) {
300
- const { requirementsDigest: _stale, ...framed } = { ...row, version: CHECKPOINT_FEATURES.requirements.version };
304
+ const omitted = presentMembersOf(row);
305
+ const { requirementsDigest: _stale, ...framed } = { ...omitted, ...(typeof omitted.state === "object" && omitted.state !== null ? { state: presentMembersOf(omitted.state) } : {}), version: CHECKPOINT_FEATURES.requirements.version };
301
306
  const stored = encodeAtFidelity(fidelity, framed);
302
307
  const held = (stored.ok ? stored.value : framed);
303
308
  const got = stored.ok ? digestOrUnencodable(held) : { at: { path: "(row)", kind: "codec" } };
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The checkpoint row's own answer to "does anything IN THIS ROW keep this engine from resuming it": every refusal of the
3
+ * resume ladder that the row and this engine decide alone — no deployment fact, no resume input, no decision — judged by
4
+ * one pure, total function ({@link judgeCheckpointRow}). Two readers ask it and no other site decides those refusals:
5
+ * - the resume ladder, at its first statement after the row is read `pending` (resume-admission): a non-`ok` verdict is
6
+ * thrown there, before the claim (the row stays `pending` and byte-identical);
7
+ * - the listing projection (`summarizeCheckpoint`, checkpoint-store.ts), which carries it as `CheckpointSummary.rowVerdict`,
8
+ * so a row this engine will refuse is listed as such instead of as an approvable card.
9
+ *
10
+ * ONE ANSWER, TWO FACES: the verdict's `sentence` is a fixed engine sentence chosen by the refusal's code and arm
11
+ * ({@link ROW_REFUSAL_SENTENCES}), never built from the row; the resume error's `message` is that sentence followed by the
12
+ * row's own diagnostic (member paths, a refused value), and its `detail` is the refusal's. So a listing carries no row
13
+ * content and the refusal a person gets on approving starts with the very sentence the listing showed.
14
+ *
15
+ * WHAT `ok` SAYS: nothing in the row keeps this engine from resuming it — not that the resume will run. The refusals a
16
+ * deployment fact, a resume input or the decision itself decides (no env factory for a remote workspace, organization
17
+ * governance unwired, an aborted signal, the re-supplied parent constraints, a decision that does not bind the parked call)
18
+ * are still told at the resume.
19
+ *
20
+ * ORDER (one law: the specific before the general): a newer row is refused as newer before any segment of it is read (the
21
+ * version ceiling, then a reader word this worker lacks); then the seats and the axis a release retired (each names what
22
+ * to do about it); then the reader-requirement list and the row digest — "its content does not read the way it was
23
+ * written", told only when nothing more specific is; then the recorded mode words, the sections by their shapes, the
24
+ * frozen chain's tool names, the recorded run origin, and the parent-constraint record's own integrity. The first refusal
25
+ * is the verdict.
26
+ *
27
+ * TOTAL: a row the judge cannot read (a member that throws when read, a container that is not one) is `damaged`
28
+ * (`requirements_damaged`); the resume error's `detail.thrownName` names what was thrown, so an engine defect and a
29
+ * damaged row are told apart.
30
+ *
31
+ * The row-seat readers the judge asks and other readers share live here too — the retired seats' refusals and the recorded
32
+ * mode seed (prepare reads the seed; the parked-steer queue's read asks the retired steer seat's refusal).
33
+ */
34
+ import { CheckpointError } from "./checkpoint-features.js";
35
+ import type { Checkpoint, CheckpointRowVerdict, CheckpointState } from "./checkpoint-store.js";
36
+ import type { PermissionMode, ShellGateDoctrine } from "./types.js";
37
+ /**
38
+ * The fixed sentence of each row refusal, keyed by its code and arm (`code|reason`), or — for a recorded word the resume
39
+ * refuses through prepare's refusal channel (`checkpoint.config_refused`) — by prepare's own code (`detail.code`). Engine
40
+ * text only: no sentence names a value, a path or a word the row holds.
41
+ */
42
+ export declare const ROW_REFUSAL_SENTENCES: Readonly<{
43
+ readonly "checkpoint.unsupported_version|version_newer": "This engine cannot resume this checkpoint: it was parked by a newer engine release, whose row this release cannot read. The checkpoint stays pending; resume it on a worker at or above the release that parked it.";
44
+ readonly "checkpoint.unsupported_version|seat_retired": "This engine cannot resume this checkpoint: it carries a seat an earlier engine release wrote and this release retired. The checkpoint stays pending and nothing was consumed; finish it on a worker of a release that still reads that seat, or expire it.";
45
+ readonly "checkpoint.invalid_outcome|requirements_damaged": "This engine cannot resume this checkpoint: its content does not read the way it was written — it was parked by an earlier engine release whose reading this release changed, or it was changed in storage. The checkpoint stays pending; start the task again (a worker of the release that parked it may still resume it).";
46
+ readonly "checkpoint.invalid_outcome|real_approval_damaged": "This engine cannot resume this checkpoint: its real-approval mark is missing or malformed (a corruption or downgrade guard). The checkpoint stays pending.";
47
+ readonly "checkpoint.invalid_outcome|real_approval_forged": "This engine cannot resume this checkpoint: it carries a real-approval mark no release of its row format ever wrote (a corruption or forgery guard). The checkpoint stays pending.";
48
+ readonly "checkpoint.invalid_outcome|read_face_damaged": "This engine cannot resume this checkpoint: its read-face section is missing or malformed (a corruption or downgrade guard). The checkpoint stays pending.";
49
+ readonly "checkpoint.invalid_outcome|read_face_forged": "This engine cannot resume this checkpoint: it carries a read-face section no release of its row format ever wrote (a corruption or forgery guard). The checkpoint stays pending.";
50
+ readonly "checkpoint.invalid_outcome|write_face_damaged": "This engine cannot resume this checkpoint: its write-face section is malformed (a corruption guard). The checkpoint stays pending.";
51
+ readonly "checkpoint.invalid_outcome|skill_grants_damaged": "This engine cannot resume this checkpoint: its skill-grant section does not read as grant rows under this engine — damaged, or written by an earlier release whose entries this release reads differently. The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.";
52
+ readonly "checkpoint.invalid_outcome|skill_scopes_damaged": "This engine cannot resume this checkpoint: its skill-scope section does not read as a list of named skills (a damaged section). The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.";
53
+ readonly "checkpoint.invalid_outcome|hands_coordinates_damaged": "This engine cannot resume this checkpoint: one of its recorded workspace coordinates is not an absolute path (a corruption guard). The checkpoint stays pending.";
54
+ readonly "checkpoint.invalid_outcome|constraint_chain_missing": "This engine cannot resume this checkpoint: it requires parent constraints but does not carry both their frozen chain and its digest (a corruption or downgrade guard). The checkpoint stays pending.";
55
+ readonly "checkpoint.walltime_axis_retired|": "This engine cannot resume this checkpoint: its budget carries a wall-clock allocation, an axis this engine retired, so resuming here would run the work with that ceiling unenforced. The checkpoint stays pending; finish it on a worker of the previous release, or start a fresh task bounded by tokens or budget.";
56
+ readonly "resume.parent_constraint_mismatch|": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending.";
57
+ readonly "config.permission_mode_invalid": "This engine cannot resume this checkpoint: a permission mode it records is not one this engine reads (or not one a plan can return to). The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.";
58
+ readonly "config.run_origin_invalid": "This engine cannot resume this checkpoint: the run origin it records is not a word this engine knows. The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.";
59
+ readonly "config.tool_face_control": "This engine cannot resume this checkpoint: its frozen inherited constraint chain records a tool name in a spelling this engine does not replay. The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it and run the work again.";
60
+ }>;
61
+ /**
62
+ * The ONE refusal of the RETIRED pre-queue single steer seat (`state.pendingSteer`, written before the queue existed): the
63
+ * seat has no `inputId`, `seq` or actor, so folding it in would mint a synthetic identity nothing else can name. The refusal is
64
+ * `checkpoint.unsupported_version` with `reason: "seat_retired"` — terminal for the row's bytes; the host decides the parked
65
+ * instruction on its own surface and parks it again through `setPendingSteer` if it still applies. The row's judge
66
+ * ({@link judgeCheckpointRow}) and the queue's read (`readPendingSteerQueue`, checkpoint-store.ts) ask it. Returns the
67
+ * refusal, `undefined` for none.
68
+ */
69
+ export declare function retiredSteerSeatRefusal(state: object): CheckpointError | undefined;
70
+ /**
71
+ * The ONE refusal of a retired mode seed — one of the row's own refusals ({@link judgeCheckpointRow}, read PRE-CAS on every
72
+ * resume kind and by every listing): a row whose `inheritedGate` still carries a retired member is refused as the engine refuses
73
+ * every retired row seat ({@link retiredSteerSeatRefusal}) — `checkpoint.unsupported_version` with `reason: "seat_retired"` —
74
+ * terminal for the row's bytes on this engine, and nothing consumed: the row stays byte-identical and `pending`. No engine
75
+ * reads the retired keys into a mode any more; an engine at 7.38.x or earlier still does, so the row can be resumed there once
76
+ * (its next suspend writes `permissionMode`), or expired (`CheckpointStore.expire`). Returns the refusal, `undefined` for none.
77
+ */
78
+ export declare function retiredModeSeedRefusal(state: Pick<CheckpointState, "inheritedGate">): CheckpointError | undefined;
79
+ /**
80
+ * The mode seed a row records (the 7.34.0 shape), read at prepare after the row's judge ({@link retiredModeSeedRefusal} among its refusals) has screened the row:
81
+ * `permissionMode` must be a member of the closed set and `prePlanMode` a mode a plan can return to (else
82
+ * `config.permission_mode_invalid`, the row cannot be resumed under a word this engine does not know); the shell floor is
83
+ * `"always"` or absent. Nothing here migrates or guesses.
84
+ */
85
+ export declare function recordedModeSeed(gate: Pick<NonNullable<CheckpointState["inheritedGate"]>, "permissionMode" | "prePlanMode" | "shellGate"> | undefined): {
86
+ permissionMode?: PermissionMode;
87
+ prePlanMode?: PermissionMode;
88
+ shellGate?: ShellGateDoctrine;
89
+ };
90
+ /**
91
+ * The row's verdict for THIS engine: `ok`, `lacking` (a newer engine can resume it: `checkpoint.unsupported_version` /
92
+ * `version_newer`, `requires` the reader words it lacks when its requirement list named them), or `damaged` (this engine
93
+ * does not resume these bytes). Pure (reads no clock, no random, no deployment) and total; the verdict is frozen. A store's
94
+ * listing carries it as `CheckpointSummary.rowVerdict`; a whole-row reader (`listBySession`, an operator queue) asks it here.
95
+ */
96
+ export declare function judgeCheckpointRow(cp: Checkpoint): CheckpointRowVerdict;
97
+ /** The refusal the resume throws for a row whose verdict is not `ok` — the verdict's code, its sentence then the row's
98
+ * diagnostic as the message, the refusal's own detail — or `undefined` for an `ok` row. Always judged now, never memoized. */
99
+ export declare function checkpointRowRefusal(cp: Checkpoint): CheckpointError | undefined;
@@ -0,0 +1,225 @@
1
+ import { CHECKPOINT_FEATURES, CheckpointError, checkpointVersionOf, MAX_SUPPORTED_CHECKPOINT_VERSION } from "./checkpoint-features.js";
2
+ import { judgeCheckpointRequirements } from "./checkpoint-requirements.js";
3
+ import { isAskOrigin, isPermissionMode } from "./ask-origin.js";
4
+ import { validatePath } from "./effective-path-target.js";
5
+ import { persistedReadDenyEntryProblem } from "../tools/fs/read-deny.js";
6
+ import { readFrozenSkillGrants } from "./skill-grant.js";
7
+ import { readFrozenSkillScopes } from "./mods/spec-seats.js";
8
+ import { constraintChainDigest } from "./tool-policy.js";
9
+ import { asResumeConfigRefusal } from "./mode-policy.js";
10
+ import { screenRecordedRunOrigin } from "./run-origin.js";
11
+ import { refusePersistedToolNames } from "./runner/sub-agent-deny-lists.js";
12
+ import { thrownName } from "./thrown-value.js";
13
+ export const ROW_REFUSAL_SENTENCES = Object.freeze({
14
+ "checkpoint.unsupported_version|version_newer": "This engine cannot resume this checkpoint: it was parked by a newer engine release, whose row this release cannot read. The checkpoint stays pending; resume it on a worker at or above the release that parked it.",
15
+ "checkpoint.unsupported_version|seat_retired": "This engine cannot resume this checkpoint: it carries a seat an earlier engine release wrote and this release retired. The checkpoint stays pending and nothing was consumed; finish it on a worker of a release that still reads that seat, or expire it.",
16
+ "checkpoint.invalid_outcome|requirements_damaged": "This engine cannot resume this checkpoint: its content does not read the way it was written — it was parked by an earlier engine release whose reading this release changed, or it was changed in storage. The checkpoint stays pending; start the task again (a worker of the release that parked it may still resume it).",
17
+ "checkpoint.invalid_outcome|real_approval_damaged": "This engine cannot resume this checkpoint: its real-approval mark is missing or malformed (a corruption or downgrade guard). The checkpoint stays pending.",
18
+ "checkpoint.invalid_outcome|real_approval_forged": "This engine cannot resume this checkpoint: it carries a real-approval mark no release of its row format ever wrote (a corruption or forgery guard). The checkpoint stays pending.",
19
+ "checkpoint.invalid_outcome|read_face_damaged": "This engine cannot resume this checkpoint: its read-face section is missing or malformed (a corruption or downgrade guard). The checkpoint stays pending.",
20
+ "checkpoint.invalid_outcome|read_face_forged": "This engine cannot resume this checkpoint: it carries a read-face section no release of its row format ever wrote (a corruption or forgery guard). The checkpoint stays pending.",
21
+ "checkpoint.invalid_outcome|write_face_damaged": "This engine cannot resume this checkpoint: its write-face section is malformed (a corruption guard). The checkpoint stays pending.",
22
+ "checkpoint.invalid_outcome|skill_grants_damaged": "This engine cannot resume this checkpoint: its skill-grant section does not read as grant rows under this engine — damaged, or written by an earlier release whose entries this release reads differently. The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.",
23
+ "checkpoint.invalid_outcome|skill_scopes_damaged": "This engine cannot resume this checkpoint: its skill-scope section does not read as a list of named skills (a damaged section). The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.",
24
+ "checkpoint.invalid_outcome|hands_coordinates_damaged": "This engine cannot resume this checkpoint: one of its recorded workspace coordinates is not an absolute path (a corruption guard). The checkpoint stays pending.",
25
+ "checkpoint.invalid_outcome|constraint_chain_missing": "This engine cannot resume this checkpoint: it requires parent constraints but does not carry both their frozen chain and its digest (a corruption or downgrade guard). The checkpoint stays pending.",
26
+ "checkpoint.walltime_axis_retired|": "This engine cannot resume this checkpoint: its budget carries a wall-clock allocation, an axis this engine retired, so resuming here would run the work with that ceiling unenforced. The checkpoint stays pending; finish it on a worker of the previous release, or start a fresh task bounded by tokens or budget.",
27
+ "resume.parent_constraint_mismatch|": "This engine cannot resume this checkpoint: its own recorded constraint chain does not match the digest it records (a corrupt or inconsistently minted row). The checkpoint stays pending.",
28
+ "config.permission_mode_invalid": "This engine cannot resume this checkpoint: a permission mode it records is not one this engine reads (or not one a plan can return to). The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.",
29
+ "config.run_origin_invalid": "This engine cannot resume this checkpoint: the run origin it records is not a word this engine knows. The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it.",
30
+ "config.tool_face_control": "This engine cannot resume this checkpoint: its frozen inherited constraint chain records a tool name in a spelling this engine does not replay. The checkpoint stays pending; finish it on a worker of the release that parked it, or expire it and run the work again.",
31
+ });
32
+ const LISTED_REQUIREMENT_WORD = /^[a-z][a-z_]{0,39}$/;
33
+ const MAX_LISTED_REQUIREMENT_WORDS = 8;
34
+ const MAX_THROWN_NAME_CHARS = 64;
35
+ const OK = Object.freeze({ kind: "ok" });
36
+ export function retiredSteerSeatRefusal(state) {
37
+ if (state.pendingSteer === undefined)
38
+ return undefined;
39
+ return new CheckpointError("checkpoint.unsupported_version", "this checkpoint carries a parked steer in the retired pre-queue single seat (`state.pendingSteer`), which this engine does not read — decide the parked instruction on the host's surface and, if it still applies, park it again with setPendingSteer", { reason: "seat_retired" });
40
+ }
41
+ const RETIRED_MODE_SEED_MEMBERS = Object.freeze([
42
+ ["autoModeRequested", () => true],
43
+ ["approverPosture", () => true],
44
+ ["shellGate", (v) => v !== "always"],
45
+ ]);
46
+ export function retiredModeSeedRefusal(state) {
47
+ const gate = state.inheritedGate;
48
+ if (gate === undefined)
49
+ return undefined;
50
+ for (const [key, retired] of RETIRED_MODE_SEED_MEMBERS) {
51
+ const value = gate[key];
52
+ if (value === undefined || !retired(value))
53
+ continue;
54
+ const shown = typeof value === "string" ? JSON.stringify(value.slice(0, 40)) : typeof value === "boolean" ? String(value) : typeof value;
55
+ return new CheckpointError("checkpoint.unsupported_version", `this checkpoint's inheritedGate carries the retired mode-seed member \`${key}\` (${shown}), written before 7.34.0 and read by no engine since 7.39.0 — resume it once on an engine at 7.38.x or earlier (which reads it into \`permissionMode\`), or expire the row (\`CheckpointStore.expire\`); nothing was consumed`, { reason: "seat_retired" });
56
+ }
57
+ return undefined;
58
+ }
59
+ export function recordedModeSeed(gate) {
60
+ if (gate === undefined)
61
+ return {};
62
+ const refusal = (message) => {
63
+ const e = new Error(message);
64
+ e.code = "config.permission_mode_invalid";
65
+ return e;
66
+ };
67
+ const { permissionMode, prePlanMode, shellGate } = gate;
68
+ if (permissionMode !== undefined && !isPermissionMode(permissionMode))
69
+ throw refusal(`the checkpoint row's inheritedGate.permissionMode is ${JSON.stringify(permissionMode)}, not a permission mode — the row cannot be resumed under a mode this engine does not know`);
70
+ if (prePlanMode !== undefined && (!isPermissionMode(prePlanMode) || prePlanMode === "plan"))
71
+ throw refusal(`the checkpoint row's inheritedGate.prePlanMode is ${JSON.stringify(prePlanMode)}, not a permission mode a plan can return to`);
72
+ return { ...(permissionMode !== undefined ? { permissionMode } : {}), ...(prePlanMode !== undefined ? { prePlanMode } : {}), ...(shellGate !== undefined ? { shellGate } : {}) };
73
+ }
74
+ function recordedWordRefusal(screen) {
75
+ try {
76
+ asResumeConfigRefusal("inheritedGate", screen);
77
+ return undefined;
78
+ }
79
+ catch (e) {
80
+ if (e instanceof CheckpointError)
81
+ return e;
82
+ throw e;
83
+ }
84
+ }
85
+ function rowRefusalOf(cp) {
86
+ const { realApproval: realApprovalRow, face: faceRow, f012: f012Row } = CHECKPOINT_FEATURES;
87
+ if (checkpointVersionOf(cp) > MAX_SUPPORTED_CHECKPOINT_VERSION) {
88
+ return new CheckpointError("checkpoint.unsupported_version", `checkpoint requires reader capabilities this worker lacks (row format v${checkpointVersionOf(cp)}; this worker reads up to v${MAX_SUPPORTED_CHECKPOINT_VERSION}) — resume it on a worker at or above the version that parked it`, { reason: "version_newer" });
89
+ }
90
+ const requirements = judgeCheckpointRequirements(cp);
91
+ if (requirements.kind === "lacking")
92
+ return new CheckpointError("checkpoint.unsupported_version", `checkpoint requires reader capabilities this worker lacks (${requirements.words.join(", ")}) — resume it on a worker at or above the version that parked it`, { reason: "version_newer", requires: requirements.words });
93
+ const retiredSeed = retiredModeSeedRefusal(cp.state);
94
+ if (retiredSeed !== undefined)
95
+ return retiredSeed;
96
+ const retiredSteer = retiredSteerSeatRefusal(cp.state);
97
+ if (retiredSteer !== undefined)
98
+ return retiredSteer;
99
+ const retiredWalltimeTotal = cp.resourceLedger?.totalWalltimeSec;
100
+ if (retiredWalltimeTotal !== undefined) {
101
+ return new CheckpointError("checkpoint.walltime_axis_retired", "this checkpoint's ledger carries a cross-slice WALL-CLOCK allocation (resourceLedger.totalWalltimeSec), an axis this engine version retired — " +
102
+ "resuming here would run the leg with that ceiling unenforced. Rejected pre-CAS (the checkpoint stays pending): finish it on a worker of the " +
103
+ "previous release, or start a fresh task bounded by resourceSuspend.totalTokens / totalBudgetUsd.");
104
+ }
105
+ if (requirements.kind === "damaged")
106
+ return new CheckpointError("checkpoint.invalid_outcome", `this checkpoint's reader-requirement list does not match the row (${requirements.why})`, { reason: "requirements_damaged" });
107
+ const modeWords = recordedWordRefusal(() => void recordedModeSeed(cp.state.inheritedGate));
108
+ if (modeWords !== undefined)
109
+ return modeWords;
110
+ const gateBit = cp.gate.kind === "irreversible_ask" ? cp.gate.realApproval : undefined;
111
+ const bitWellFormed = gateBit !== undefined && typeof gateBit === "object" && isAskOrigin(gateBit.origin);
112
+ const faceSaysGoverned = (cp.state.readFace?.realApproval) === true;
113
+ const bitViolation = checkpointVersionOf(cp) === realApprovalRow.version
114
+ ? !bitWellFormed
115
+ : checkpointVersionOf(cp) < realApprovalRow.version
116
+ ? gateBit !== undefined
117
+ : faceSaysGoverned
118
+ ? !bitWellFormed
119
+ : gateBit !== undefined && !bitWellFormed;
120
+ if (bitViolation) {
121
+ return new CheckpointError("checkpoint.invalid_outcome", checkpointVersionOf(cp) >= realApprovalRow.version
122
+ ? `a v${checkpointVersionOf(cp)} checkpoint's realApproval gate bit must be well-formed (origin a member of the closed ask-origin set)${checkpointVersionOf(cp) === realApprovalRow.version ? " and present on an irreversible_ask gate" : ""} — this row's is not; refusing to resume a damaged real-approval row (corruption / downgrade guard), the checkpoint stays pending`
123
+ : `a v${checkpointVersionOf(cp)} checkpoint carries a realApproval gate bit no release of that version ever minted — refusing to honor a fabricated origin (corruption / forgery guard), the checkpoint stays pending`, { reason: checkpointVersionOf(cp) >= realApprovalRow.version ? "real_approval_damaged" : "real_approval_forged" });
124
+ }
125
+ const faceSectionRaw = cp.state.readFace;
126
+ const faceCandidate = faceSectionRaw !== undefined && typeof faceSectionRaw === "object" && faceSectionRaw !== null
127
+ ? faceSectionRaw
128
+ : undefined;
129
+ const faceWellFormed = faceCandidate !== undefined &&
130
+ (faceCandidate.face === "open" || faceCandidate.face === "roots") &&
131
+ (faceCandidate.realApproval === undefined || faceCandidate.realApproval === true) &&
132
+ (faceCandidate.denyEntries === undefined ||
133
+ (Array.isArray(faceCandidate.denyEntries) && faceCandidate.denyEntries.every((e) => persistedReadDenyEntryProblem(e) === null)));
134
+ const v = checkpointVersionOf(cp);
135
+ if (v === faceRow.version ? !faceWellFormed : v < faceRow.version ? faceSectionRaw !== undefined : faceSectionRaw !== undefined && !faceWellFormed) {
136
+ return new CheckpointError("checkpoint.invalid_outcome", checkpointVersionOf(cp) >= faceRow.version
137
+ ? `a v${checkpointVersionOf(cp)} checkpoint must carry a well-formed read-face section (state.readFace) — this row's is missing or malformed; refusing to resume a damaged read-face row (corruption / downgrade guard), the checkpoint stays pending`
138
+ : `a v${checkpointVersionOf(cp)} checkpoint carries a read-face section no release of that version ever minted — refusing to honor a fabricated read-face state (corruption / forgery guard), the checkpoint stays pending`, { reason: checkpointVersionOf(cp) >= faceRow.version ? "read_face_damaged" : "read_face_forged" });
139
+ }
140
+ const writeFaceSectionRaw = cp.state.writeFace;
141
+ if (writeFaceSectionRaw !== undefined) {
142
+ const c = typeof writeFaceSectionRaw === "object" && writeFaceSectionRaw !== null ? writeFaceSectionRaw : undefined;
143
+ if (c === undefined || !(c.face === "open" || c.face === "roots")) {
144
+ return new CheckpointError("checkpoint.invalid_outcome", `this checkpoint carries a write-face section (state.writeFace) that is not well-formed — refusing to resume a damaged write-face row (corruption guard), the checkpoint stays pending`, { reason: "write_face_damaged" });
145
+ }
146
+ }
147
+ if (readFrozenSkillGrants(cp.state.skillGrants) === undefined)
148
+ return new CheckpointError("checkpoint.invalid_outcome", "this checkpoint carries a skill-grant section (state.skillGrants) that does not read as grant rows under this engine — a damaged section, or a row an earlier release wrote whose entry this release reads as nothing (an entry with a surrounding space, say) — refusing to resume without the grant rows and refusals it carries; the checkpoint stays pending: finish it on a worker of the release that parked it, or expire it", { reason: "skill_grants_damaged" });
149
+ if (readFrozenSkillScopes(cp.state.skillScopes) === undefined)
150
+ return new CheckpointError("checkpoint.invalid_outcome", "this checkpoint carries a skill-scope section (state.skillScopes) that does not read as a list of SkillSpec names — a damaged section — refusing to resume without the active skills' hooks it records; the checkpoint stays pending: finish it on a worker of the release that parked it, or expire it", { reason: "skill_scopes_damaged" });
151
+ for (const field of ["handsRoot", "handsHome", "handsCwd"]) {
152
+ const coordinate = cp.state[field];
153
+ if (coordinate !== undefined && validatePath(coordinate, { intent: "validate-coordinate" }) === undefined)
154
+ return new CheckpointError("checkpoint.invalid_outcome", `this checkpoint's state.${field} is not an absolute path — refusing to resume a row whose hands' coordinates are damaged (corruption guard), the checkpoint stays pending`, { reason: "hands_coordinates_damaged" });
155
+ }
156
+ const chainNames = recordedWordRefusal(() => refusePersistedToolNames(undefined, cp.state.inheritedGate?.constraintChain, undefined));
157
+ if (chainNames !== undefined)
158
+ return chainNames;
159
+ const runOrigin = recordedWordRefusal(() => void screenRecordedRunOrigin(cp.state.runOrigin));
160
+ if (runOrigin !== undefined)
161
+ return runOrigin;
162
+ const gate = cp.state.inheritedGate;
163
+ if (gate?.requiresParentConstraint === true) {
164
+ if (checkpointVersionOf(cp) >= f012Row.version && (gate.constraintChain === undefined || gate.constraintDigest === undefined)) {
165
+ return new CheckpointError("checkpoint.invalid_outcome", `a v${checkpointVersionOf(cp)} checkpoint that requires parent constraints must carry BOTH the frozen constraintChain and its constraintDigest (they are minted in one write with the version stamp) — this row carries neither or only one; refusing to fall back to the count-only contract on a damaged row (corruption / downgrade guard), the checkpoint stays pending`, { reason: "constraint_chain_missing" });
166
+ }
167
+ const expectedDigest = gate.constraintDigest;
168
+ if (expectedDigest !== undefined && (gate.constraintChain === undefined || constraintChainDigest(gate.constraintChain) !== expectedDigest)) {
169
+ return new CheckpointError("resume.parent_constraint_mismatch", "the checkpoint's OWN recorded constraint chain does not match its recorded digest " +
170
+ "(corrupt / inconsistently-minted row) — the frozen deny data the resume would execute is not the data the " +
171
+ "digest authenticates; rejected pre-CAS (the checkpoint stays pending)");
172
+ }
173
+ }
174
+ return undefined;
175
+ }
176
+ function refusalKeyOf(refusal) {
177
+ return refusal.code === "checkpoint.config_refused" ? String(refusal.detail?.code) : `${refusal.code}|${refusal.detail?.reason ?? ""}`;
178
+ }
179
+ function isRowRefusalKey(key) {
180
+ return Object.prototype.hasOwnProperty.call(ROW_REFUSAL_SENTENCES, key);
181
+ }
182
+ function readRow(cp) {
183
+ const refusal = rowRefusalOf(cp);
184
+ if (refusal === undefined)
185
+ return { verdict: OK };
186
+ const key = refusalKeyOf(refusal);
187
+ if (!isRowRefusalKey(key))
188
+ throw new Error(`row refusal ${key} has no sentence`);
189
+ const sentence = ROW_REFUSAL_SENTENCES[key];
190
+ const lacking = refusal.code === "checkpoint.unsupported_version" && refusal.detail?.reason === "version_newer";
191
+ const token = cp.token;
192
+ const requires = (refusal.detail?.requires ?? []).filter((w) => LISTED_REQUIREMENT_WORD.test(w) && w !== token).slice(0, MAX_LISTED_REQUIREMENT_WORDS);
193
+ const verdict = Object.freeze({
194
+ kind: lacking ? "lacking" : "damaged",
195
+ code: refusal.code,
196
+ ...(refusal.detail?.reason !== undefined ? { reason: refusal.detail.reason } : {}),
197
+ ...(requires.length > 0 ? { requires: Object.freeze(requires) } : {}),
198
+ sentence,
199
+ });
200
+ refusal.message = `${sentence} Diagnostic: ${refusal.message}`;
201
+ return { verdict, refusal };
202
+ }
203
+ function boundedThrownName(e) {
204
+ const name = thrownName(e);
205
+ return name === undefined || name === "" ? typeof e : name.slice(0, MAX_THROWN_NAME_CHARS);
206
+ }
207
+ function readRowTotal(cp) {
208
+ try {
209
+ return readRow(cp);
210
+ }
211
+ catch (e) {
212
+ const name = boundedThrownName(e);
213
+ const sentence = ROW_REFUSAL_SENTENCES["checkpoint.invalid_outcome|requirements_damaged"];
214
+ return {
215
+ verdict: Object.freeze({ kind: "damaged", code: "checkpoint.invalid_outcome", reason: "requirements_damaged", sentence }),
216
+ refusal: new CheckpointError("checkpoint.invalid_outcome", `${sentence} Diagnostic: the row could not be read (${name} thrown while judging it)`, { reason: "requirements_damaged", thrownName: name }),
217
+ };
218
+ }
219
+ }
220
+ export function judgeCheckpointRow(cp) {
221
+ return readRowTotal(cp).verdict;
222
+ }
223
+ export function checkpointRowRefusal(cp) {
224
+ return readRowTotal(cp).refusal;
225
+ }