@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
@@ -1,4 +1,4 @@
1
- import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, readSessionRepoRowCells, recordedOwnerName, sessionLogMarkOf, uuidv7, } from "../internal/harness.js";
1
+ import { InMemorySessionRepo, ParentChainGuard, SessionError, findUnansweredToolBatch, compareOccupants, ownerCell, readSessionRepoRowCells, recordedOwnerName, sessionLogMarkOf, sessionRowMatches, uuidv7, } from "../internal/harness.js";
2
2
  import { isSessionConflict, readSessionListQuery, readUnreadableDeleteId, rowUnreadableAt } from "./session.js";
3
3
  import { readHolderJudge } from "./checkpoint-generation.js";
4
4
  import { readRetentionDeclaration } from "./retention.js";
@@ -9,6 +9,7 @@ import { describeFault, receive } from "./mods/kernel/receive.js";
9
9
  import { describeRejectedValue } from "./tool-search-setting.js";
10
10
  import { readIntegerOption, TIMER_DELAY_MS } from "./integer-option.js";
11
11
  import { repoLogTransfer } from "./session-log-transfer.js";
12
+ import { readOccupantExpectation } from "./runner/session-verb-doors.js";
12
13
  import { deliverEngineNotice } from "./engine-notice.js";
13
14
  let ownerDeleteWithheldSaid = false;
14
15
  export function __resetSessionDeleteWithheldNotice() {
@@ -46,6 +47,7 @@ export class TtlSessionStore {
46
47
  listPlaced;
47
48
  headOf;
48
49
  repoHead;
50
+ readRow;
49
51
  logTransfer;
50
52
  delete;
51
53
  deleteUnreadable;
@@ -96,6 +98,8 @@ export class TtlSessionStore {
96
98
  this.repoHead = repoHead;
97
99
  this.headOf = repoHead;
98
100
  const { readRow, importEntries, deleteUnreadable, placementOf, recordOwner } = this.repo;
101
+ if (typeof readRow === "function")
102
+ this.readRow = (sessionId) => readRow.call(this.repo, sessionId);
99
103
  if (typeof recordOwner === "function") {
100
104
  this.recordOwner = async (sessionId, owner, expect) => {
101
105
  const name = recordedOwnerName(owner);
@@ -454,11 +458,11 @@ export class TtlSessionStore {
454
458
  });
455
459
  }
456
460
  async deleteOwned(sessionId, guard, readHead, readHeaderPlacement) {
457
- const want = readDeleteGuard(guard);
461
+ const wants = readDeleteGuard(guard);
458
462
  return this.holdingId(sessionId, async () => {
459
463
  this.entries.delete(sessionId);
460
464
  const head = await readHead(sessionId);
461
- if (head === undefined || head.owner !== want)
465
+ if (head === undefined || !wants(head))
462
466
  return false;
463
467
  if ((await readHeaderPlacement(sessionId)) !== undefined)
464
468
  return false;
@@ -640,14 +644,30 @@ function readStoreHooks(hooks) {
640
644
  }
641
645
  function readDeleteGuard(guard) {
642
646
  if (typeof guard !== "object" || guard === null)
643
- throw new TypeError(`SessionStore.delete: the guard must be an object { owner }, got ${guard === null ? "null" : typeof guard}`);
647
+ throw new TypeError(`SessionStore.delete: the guard must be an object { owner } or { row: { owner, incarnation } }, got ${guard === null ? "null" : typeof guard}`);
648
+ let hasRow;
649
+ try {
650
+ hasRow = "row" in guard;
651
+ }
652
+ catch {
653
+ hasRow = true;
654
+ }
655
+ if (hasRow) {
656
+ const occupant = readOccupantExpectation(guard, (what) => {
657
+ throw new TypeError(`SessionStore.delete: the guard's ${what}`);
658
+ });
659
+ return (head) => sessionRowMatches(occupant, head, occupantBindsNoLog);
660
+ }
644
661
  const owner = readMember(guard, "owner");
645
662
  if (owner === null)
646
- return null;
663
+ return (head) => head.owner === null;
647
664
  const name = recordedPrincipalNameOf(owner);
648
665
  if (name === undefined)
649
666
  throw new TypeError(`SessionStore.delete: guard.owner must be null (anonymous) or the owner name a session row holds — ${RECORDED_PRINCIPAL_NAME_SPELLING} — got ${principalNameFault(owner)}`);
650
- return name;
667
+ return (head) => head.owner === name;
668
+ }
669
+ function occupantBindsNoLog() {
670
+ throw new TypeError("SessionStore.delete: an occupant guard binds no log");
651
671
  }
652
672
  function isNotFound(err) {
653
673
  return readMember(err, "code") === "not_found";
@@ -9,7 +9,7 @@ export { CORRUPT_SESSION_DELETE_DOORS, CORRUPT_SESSION_FORMS, CORRUPT_SESSION_WA
9
9
  export type { CorruptSessionDeleteDoor, CorruptSessionDetail, CorruptSessionForm, CorruptSessionWay, CorruptSessionWayOut } from "../internal/harness.js";
10
10
  import type { CorruptSessionForm } from "../internal/harness.js";
11
11
  import type { Session } from "../internal/harness.js";
12
- import type { SessionHead, SessionRowExpectation, SessionTreeEntry } from "../internal/harness.js";
12
+ import type { SessionHead, SessionRowExpectation, SessionRowRead, SessionTreeEntry } from "../internal/harness.js";
13
13
  export type { SessionPlacementRecord } from "../internal/harness.js";
14
14
  export type { SessionHead, SessionLogMark, SessionRowExpectation, SessionRowRead } from "../internal/harness.js";
15
15
  /** True when `err` is a session optimistic-lock conflict (a concurrent writer won the branch leaf). Both
@@ -104,14 +104,15 @@ export interface SessionStoreSummary {
104
104
  * another replica or a dropped cache reads the same time, and only a later activity moves it. An acquire that writes nothing is not
105
105
  * activity. */
106
106
  lastActiveAt: number;
107
- /** The most recent task run on this session (core's `taskId`; the service projects it as `lastRunId`).
107
+ /** The most recent task run on this session (core's `taskId` — on a ledger run, the host's if it gave one other than the session id, the id the parked row recorded on a resume, otherwise the minted `rl-…` one; the service projects it as `lastRunId`).
108
108
  * Absent until a task has run on the session (recorded via {@link SessionStore.noteTaskRun}). */
109
109
  lastTaskId?: string;
110
110
  /**
111
111
  * An ENGINE-minted run identity for this session ({@link import("./types.js").TaskResult.runId}),
112
112
  * recorded by the most recent {@link SessionStore.noteTaskRun} write to LAND.
113
- * {@link lastTaskId} above is the leg's task id (a background row's id, else the declared one, else the
114
- * session id), so on the ordinary deployment that supplies no
113
+ * {@link lastTaskId} above is the leg's task id (a background row's id; on a ledger run, the host's if it gave one
114
+ * other than the session id, the id the parked row recorded on a resume, otherwise the minted `rl-…` one; else the
115
+ * declared one or the session id), so on the ordinary deployment that supplies no
115
116
  * host task id it answers the SESSION's own id: a "last run" handle that names the session it hangs off
116
117
  * cannot say WHICH run it means. This one names a specific run — read the ORDERING clause below for
117
118
  * exactly how strong "most recent" is here, which is weaker than the sibling field's wording implies.
@@ -332,7 +333,8 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
332
333
  *
333
334
  * `runId` (#499, additive third parameter — an existing implementation keeps typechecking and keeps
334
335
  * working): the engine's own identity for THIS run, for {@link SessionStoreSummary.lastTaskRunId}. It
335
- * is supplied because `taskId` cannot answer "which run": with no host task id it IS the session id.
336
+ * is supplied because `taskId` cannot answer "which run": with no host task id it IS the session id (on a run that keeps no
337
+ * member ledger; one that keeps one records the task id the engine minted for it, `rl-…`, the same on every run of that task).
336
338
  *
337
339
  * The two seats describe ONE run and MUST move together: a call that omits `runId` records the new
338
340
  * `lastTaskId` and CLEARS `lastTaskRunId`. Keeping the previous run's id beside a newer task id would
@@ -420,6 +422,20 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
420
422
  * fail-closed arm.
421
423
  */
422
424
  headOf?(sessionId: string): Promise<SessionHead | undefined>;
425
+ /**
426
+ * The row as it stands, for a reader that does not run on it: its metadata, its head and its whole log oldest-first, all of one row
427
+ * generation ({@link SessionRowRead}). Four rules, the same on every store:
428
+ * · **It writes nothing** — no row, entry, owner cell, file or cached view is created or changed by it, an id with no row included.
429
+ * · **It sweeps nothing** — no session, the one read or any other, is evicted from a cache or deleted because of this read.
430
+ * · **It is no activity** — no idle clock moves (the read session stays exactly as near its idle eviction as it was), nor the time
431
+ * {@link list} orders by.
432
+ * · **No row and a failed read are two answers** — an id with no row RESOLVES `undefined`: a definite "there is no such row". A row
433
+ * that is there and cannot be read REJECTS with a coded error, never `undefined`: on the bundled stores a `SessionError` with code
434
+ * `corrupt_session` for a row whose header the store cannot read, and a backend's own coded fault for a read that did not complete.
435
+ * **Optional**: absent ⇒ an entry that reads a session without running on it (`Runner.previewInstructions`) refuses a named session
436
+ * (`config.invalid_session_store`) rather than open it through {@link acquire}, which sweeps and records activity.
437
+ */
438
+ readRow?(sessionId: string): Promise<SessionRowRead | undefined>;
423
439
  /**
424
440
  * The owner write of the ownership pair ({@link headOf} + this). On an id with NO row it creates the row — an ordinary row, no
425
441
  * placement — recording `owner` in the creating write, first-write-wins and atomic: of two concurrent first registers, both
@@ -470,9 +486,14 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
470
486
  * Delete ONE session row and its log — the row primitive, and the last leg of the session-deletion cascade
471
487
  * ({@link import("./retention.js").RETENTION_CASCADE}). It reads no reference and touches no other store: the session's checkpoints,
472
488
  * offloaded tool results, session rules, file history and the rest outlive it until the cascade's executor removes them, so a host that
473
- * offers "delete a session" runs the cascade, not this call alone. Only when the row's owner equals `guard.owner` (null-safe:
489
+ * offers "delete a session" runs the cascade, not this call alone. The guard names the row it is for in one of two forms:
490
+ * `{ owner }` — the row whose owner equals `guard.owner`, whichever occupant it holds (null-safe:
474
491
  * `null` deletes only an anonymous row; the owner is read as a stored name is — `recordedPrincipalNameOf` — so the owner of a row an
475
- * earlier release wrote under a name the rule now refuses as ill-formed deletes it by that same string); a placed row is not deleted here (its deletion is `release`'s, through the joint reap). `true`
492
+ * earlier release wrote under a name the rule now refuses as ill-formed deletes it by that same string) — or the occupant a read of the
493
+ * row answered, `{ row: { owner, incarnation } }` (#4746: the expectation the out-of-run verbs take, read by the same reader —
494
+ * `row: null`, a `log` mark and a key besides `row` are refused — and judged by `sessionRowMatches` on the head in the step that removes
495
+ * the row: a row deleted and created again under the id since that read, by the same owner too, is another occupant and is not deleted).
496
+ * A guard that is neither form, or both, is refused (`TypeError`) before anything is read. A placed row is not deleted here (its deletion is `release`'s, through the joint reap). `true`
476
497
  * = this call deleted the row; `false` = there was no row, the guard did not hold, or the row is placed — nothing was deleted, so a
477
498
  * repeat is harmless. The id answers nothing afterwards, and a later create under it is a new occupant. A store wired with
478
499
  * {@link SessionStoreHooks.beforeSessionDelete} runs it first and deletes nothing when it rejects (the call rejects with it).
@@ -482,7 +503,9 @@ export interface SessionStore<S extends SessionStoreSummary = SessionStoreSummar
482
503
  * read and a header-only placement read, `SessionRepo.placementOf`).
483
504
  */
484
505
  delete?(sessionId: string, guard: {
485
- owner: string | null;
506
+ readonly owner: string | null;
507
+ } | {
508
+ readonly row: NonNullable<SessionRowExpectation["row"]>;
486
509
  }): Promise<boolean>;
487
510
  /**
488
511
  * Delete a session whose head cannot be read — a deployment operator's act, never an owner's request: a row that cannot be read names
@@ -185,6 +185,16 @@ export async function checkpointStoreContract(make, runAssertion, options = {})
185
185
  assert.equal(got.resolvedOutcome.boundCallId, "call-3");
186
186
  assert.equal(got.rev, 2);
187
187
  });
188
+ run("a plan review's winner keeps the mode its approval named, whole, across a reopen(env_failed)", async () => {
189
+ const store = make();
190
+ const cp = createCheckpointFixture();
191
+ await store.put(cp.token, cp);
192
+ await store.resolve(cp.token, cp.scope, { gate: "plan_review", decision: "approve", hostDecision: { decidedBy: "person" }, permissionMode: "acceptEdits" });
193
+ assert.equal((await store.get(cp.token)).resolvedOutcome?.permissionMode, "acceptEdits");
194
+ assert.equal(await store.reopen(cp.token, cp.scope, "env_failed"), true);
195
+ const got = (await store.get(cp.token)).resolvedOutcome;
196
+ assert.deepEqual({ decision: got?.decision, permissionMode: got?.permissionMode }, { decision: "approve", permissionMode: "acceptEdits" });
197
+ });
188
198
  run("rev OCC: a stale-rev resolve loses, the current-rev resolve wins", async () => {
189
199
  const store = make();
190
200
  const cp = createCheckpointFixture();
@@ -0,0 +1,21 @@
1
+ import { type PeerTaskRow, type PeerTaskStore } from "../peer-task-store.js";
2
+ import { type ContractAssertionRunner } from "./contract-harness.js";
3
+ /** Primary tenant scope used across contract cases. */
4
+ export declare const PEER_TASK_CONTRACT_SCOPE = "tenant-A";
5
+ /** Build a valid {@link PeerTaskRow} fixture; overrides adjust digest and settlement pairing unless supplied explicitly. */
6
+ export declare function createPeerTaskRowFixture(over?: Partial<PeerTaskRow>): PeerTaskRow;
7
+ /** Hooks for the damaged-row clause; provide `plantRow` for persistent backends or `unplantable` with a reason. */
8
+ export interface PeerTaskStoreContractHooks {
9
+ readonly plantRow?: (store: PeerTaskStore, key: {
10
+ readonly task_id: string;
11
+ readonly scope: string;
12
+ }, raw: unknown) => Promise<PeerTaskStore>;
13
+ readonly unplantable?: string;
14
+ }
15
+ /**
16
+ * Cross-backend {@link PeerTaskStore} contract kit (vitest-free; runs under any harness or sequentially by default).
17
+ * Every bundled and third-party backend must pass all cases; pass `hooks.plantRow` to include damaged-row checks.
18
+ */
19
+ export declare function peerTaskStoreContract(mk: () => PeerTaskStore, runAssertion?: ContractAssertionRunner, hooks?: PeerTaskStoreContractHooks): Promise<void>;
20
+ /** Optional capability contract for backends implementing {@link PeerTaskStore.listScopes}. */
21
+ export declare function peerTaskStoreScopesContract(mk: () => PeerTaskStore, runAssertion?: ContractAssertionRunner): Promise<void>;