@sema-agent/core 7.63.0 → 7.64.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 (204) hide show
  1. package/CHANGELOG.md +408 -0
  2. package/dist/agents/cc-peer-directory.js +1 -0
  3. package/dist/agents/cc-peer-wire.d.ts +4 -0
  4. package/dist/agents/cc-peer-wire.js +1 -0
  5. package/dist/agents/cc-uds-peer-channel.js +5 -0
  6. package/dist/agents/cross-session-judge.d.ts +3 -1
  7. package/dist/agents/cross-session-judge.js +4 -1
  8. package/dist/agents/peer-directory.d.ts +8 -0
  9. package/dist/agents/peer-directory.js +4 -0
  10. package/dist/agents/peer-held-queue.d.ts +9 -3
  11. package/dist/agents/peer-held-queue.js +12 -9
  12. package/dist/agents/peer-idle.d.ts +20 -1
  13. package/dist/agents/peer-idle.js +23 -12
  14. package/dist/agents/peer-notice-route.d.ts +16 -5
  15. package/dist/agents/peer-notice-route.js +11 -9
  16. package/dist/agents/peer-notices.d.ts +25 -8
  17. package/dist/agents/peer-notices.js +6 -1
  18. package/dist/agents/peer-session-drain.d.ts +32 -6
  19. package/dist/agents/peer-session-drain.js +100 -26
  20. package/dist/agents/send-message-tool.d.ts +7 -0
  21. package/dist/agents/send-message-tool.js +18 -6
  22. package/dist/agents/subagent.js +20 -3
  23. package/dist/core/allow-entry.d.ts +4 -0
  24. package/dist/core/ask-origin.d.ts +1 -1
  25. package/dist/core/ask-origin.js +2 -2
  26. package/dist/core/ask-unresolvable-notice.d.ts +13 -4
  27. package/dist/core/ask-unresolvable-notice.js +10 -3
  28. package/dist/core/auto-compaction.d.ts +7 -5
  29. package/dist/core/background-agent-store.d.ts +7 -0
  30. package/dist/core/background-agent-store.js +3 -0
  31. package/dist/core/checkpoint-queries.d.ts +9 -6
  32. package/dist/core/checkpoint-queries.js +8 -3
  33. package/dist/core/checkpoint-store.d.ts +5 -1
  34. package/dist/core/context-settings.d.ts +40 -9
  35. package/dist/core/context-settings.js +32 -10
  36. package/dist/core/engine-attestation.d.ts +26 -6
  37. package/dist/core/engine-attestation.js +5 -1
  38. package/dist/core/engine-notice.d.ts +24 -1
  39. package/dist/core/extension-requester.d.ts +9 -0
  40. package/dist/core/extension-requester.js +7 -0
  41. package/dist/core/file-history-store.d.ts +28 -0
  42. package/dist/core/file-history-store.js +48 -5
  43. package/dist/core/fs-write-gate-policy.js +1 -1
  44. package/dist/core/gate-fold.js +2 -0
  45. package/dist/core/gate-lanes.js +2 -0
  46. package/dist/core/gate-outcome.d.ts +39 -2
  47. package/dist/core/gate-outcome.js +20 -1
  48. package/dist/core/governance-codes.d.ts +3 -1
  49. package/dist/core/governance-codes.js +4 -0
  50. package/dist/core/leg-identity.d.ts +19 -1
  51. package/dist/core/leg-identity.js +12 -0
  52. package/dist/core/mailbox-store.d.ts +39 -4
  53. package/dist/core/mailbox-store.js +14 -2
  54. package/dist/core/memory-engine/consolidation.d.ts +3 -2
  55. package/dist/core/memory-engine/consolidation.js +16 -0
  56. package/dist/core/memory-engine/control-objects.d.ts +25 -0
  57. package/dist/core/memory-engine/control-objects.js +151 -0
  58. package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
  59. package/dist/core/memory-engine/control-plane-adoption.js +159 -0
  60. package/dist/core/memory-engine/delegation-settlement.d.ts +21 -5
  61. package/dist/core/memory-engine/delegation-settlement.js +217 -26
  62. package/dist/core/memory-engine/dual-root.js +2 -2
  63. package/dist/core/memory-engine/engine.d.ts +38 -23
  64. package/dist/core/memory-engine/engine.js +14 -14
  65. package/dist/core/memory-engine/file-backend.d.ts +41 -65
  66. package/dist/core/memory-engine/file-backend.js +59 -166
  67. package/dist/core/memory-engine/index.d.ts +3 -2
  68. package/dist/core/memory-engine/index.js +2 -1
  69. package/dist/core/memory-engine/layout.d.ts +6 -1
  70. package/dist/core/memory-engine/layout.js +12 -7
  71. package/dist/core/memory-engine/memory-backend-contract.d.ts +10 -3
  72. package/dist/core/memory-engine/memory-backend-contract.js +158 -2
  73. package/dist/core/memory-engine/memory-deployment.d.ts +11 -3
  74. package/dist/core/memory-engine/memory-deployment.js +31 -6
  75. package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
  76. package/dist/core/memory-engine/origin-clearance.js +68 -9
  77. package/dist/core/memory-engine/session-write-home.d.ts +34 -1
  78. package/dist/core/memory-engine/session-write-home.js +37 -10
  79. package/dist/core/memory-engine/types.d.ts +44 -7
  80. package/dist/core/memory-engine/types.js +2 -1
  81. package/dist/core/mode-policy.js +3 -3
  82. package/dist/core/mods/agent-stations.d.ts +18 -0
  83. package/dist/core/mods/agent-stations.js +8 -6
  84. package/dist/core/mods/extension-call.d.ts +4 -0
  85. package/dist/core/mods/extension-call.js +8 -0
  86. package/dist/core/mods/tool-call.js +3 -4
  87. package/dist/core/parent-spec-seat.d.ts +2 -2
  88. package/dist/core/peer-channel.d.ts +5 -0
  89. package/dist/core/permission-rule-consent.d.ts +21 -10
  90. package/dist/core/permission-rule-consent.js +50 -23
  91. package/dist/core/permission-rule-store.d.ts +41 -16
  92. package/dist/core/permission-rule-store.js +2 -0
  93. package/dist/core/refusal-echo.d.ts +20 -0
  94. package/dist/core/refusal-echo.js +33 -0
  95. package/dist/core/retention.d.ts +180 -10
  96. package/dist/core/retention.js +45 -0
  97. package/dist/core/retired-keys.d.ts +5 -0
  98. package/dist/core/retired-keys.js +3 -0
  99. package/dist/core/rule-offer-read.d.ts +0 -4
  100. package/dist/core/rule-offer-read.js +2 -18
  101. package/dist/core/runner/classifier-ladder.d.ts +7 -1
  102. package/dist/core/runner/classifier-ladder.js +4 -2
  103. package/dist/core/runner/compact-session.js +10 -7
  104. package/dist/core/runner/compaction-call-options.d.ts +7 -7
  105. package/dist/core/runner/compaction-call-options.js +3 -2
  106. package/dist/core/runner/contracts.d.ts +21 -2
  107. package/dist/core/runner/delegation-owner.d.ts +10 -3
  108. package/dist/core/runner/delegation-owner.js +4 -1
  109. package/dist/core/runner/gate-exit.d.ts +6 -0
  110. package/dist/core/runner/gate-exit.js +11 -2
  111. package/dist/core/runner/memory-consolidation-driver.d.ts +4 -2
  112. package/dist/core/runner/memory-consolidation-driver.js +8 -5
  113. package/dist/core/runner/prepare-ask-lane.js +3 -3
  114. package/dist/core/runner/prepare-caps-and-workflow.d.ts +3 -1
  115. package/dist/core/runner/prepare-caps-and-workflow.js +2 -2
  116. package/dist/core/runner/prepare-config-doors.js +4 -0
  117. package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
  118. package/dist/core/runner/prepare-delegation-surface.js +2 -2
  119. package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
  120. package/dist/core/runner/prepare-gate-stations.js +5 -5
  121. package/dist/core/runner/prepare-hands-readface.js +1 -1
  122. package/dist/core/runner/prepare-inherited-gate.d.ts +3 -1
  123. package/dist/core/runner/prepare-inherited-gate.js +4 -2
  124. package/dist/core/runner/prepare-memory.d.ts +4 -0
  125. package/dist/core/runner/prepare-memory.js +14 -20
  126. package/dist/core/runner/prepare-policy-chain.js +7 -7
  127. package/dist/core/runner/prepare-prompt-inputs.js +1 -1
  128. package/dist/core/runner/prepare-task.js +15 -10
  129. package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
  130. package/dist/core/runner/prepare-wiring-manifest.js +3 -2
  131. package/dist/core/runner/resume-admission.d.ts +2 -2
  132. package/dist/core/runner/resume-admission.js +2 -23
  133. package/dist/core/runner/role-resolution-table.d.ts +98 -0
  134. package/dist/core/runner/role-resolution-table.js +62 -0
  135. package/dist/core/runner/run-compaction-machinery.js +2 -2
  136. package/dist/core/runner/run-identity-wiring.js +12 -9
  137. package/dist/core/runner/run-leg.js +8 -4
  138. package/dist/core/runner/run-notification-lane.js +22 -22
  139. package/dist/core/runner/run-recovery-lanes.js +3 -3
  140. package/dist/core/runner/run-terminal-adoption.js +1 -1
  141. package/dist/core/runner/run-turn-boundary.js +14 -15
  142. package/dist/core/runner/runtask.js +1 -1
  143. package/dist/core/runner/tool-occurrence.d.ts +4 -2
  144. package/dist/core/runner/tool-occurrence.js +2 -2
  145. package/dist/core/runner-deps.d.ts +1 -1
  146. package/dist/core/session-checkout.d.ts +63 -3
  147. package/dist/core/session-checkout.js +152 -58
  148. package/dist/core/shell-read-silence.js +8 -0
  149. package/dist/core/store-contracts/peer-directory-contract.js +8 -1
  150. package/dist/core/task-event.d.ts +9 -5
  151. package/dist/core/task-notification.d.ts +110 -31
  152. package/dist/core/task-notification.js +180 -100
  153. package/dist/core/task-registry-agent.d.ts +11 -0
  154. package/dist/core/task-registry-agent.js +11 -3
  155. package/dist/core/task-registry-shared.d.ts +7 -0
  156. package/dist/core/task-registry.d.ts +18 -0
  157. package/dist/core/task-registry.js +27 -8
  158. package/dist/core/task-spec.d.ts +7 -2
  159. package/dist/core/tool-errors.d.ts +14 -6
  160. package/dist/core/tool-errors.js +1 -1
  161. package/dist/core/tool-policy.d.ts +18 -1
  162. package/dist/core/tool-policy.js +16 -7
  163. package/dist/core/tool-result-store.d.ts +20 -0
  164. package/dist/core/tool-spec.d.ts +4 -0
  165. package/dist/core/trace.d.ts +3 -2
  166. package/dist/core/workflow-journal-store.d.ts +11 -0
  167. package/dist/core/workflow-journal-store.js +7 -0
  168. package/dist/core/workflow-run-store.d.ts +9 -0
  169. package/dist/core/workflow-run-store.js +6 -0
  170. package/dist/engine/compaction/compaction.d.ts +2 -1
  171. package/dist/engine/harness/types.d.ts +1 -0
  172. package/dist/engine/session/session.d.ts +7 -1
  173. package/dist/engine/session/session.js +5 -2
  174. package/dist/index.d.ts +7 -5
  175. package/dist/index.js +7 -5
  176. package/dist/orchestration/run-workflow-tool.d.ts +4 -0
  177. package/dist/orchestration/run-workflow-tool.js +7 -0
  178. package/dist/orchestration/workflow-types.d.ts +2 -1
  179. package/dist/orchestration/workflow.d.ts +3 -0
  180. package/dist/orchestration/workflow.js +2 -1
  181. package/dist/stores/file/checkpoint-store.d.ts +6 -0
  182. package/dist/stores/file/checkpoint-store.js +4 -1
  183. package/dist/stores/file/file-history-store.d.ts +13 -0
  184. package/dist/stores/file/file-history-store.js +75 -13
  185. package/dist/stores/file/index.d.ts +11 -1
  186. package/dist/stores/file/index.js +7 -11
  187. package/dist/stores/file/permission-rule-store.d.ts +23 -0
  188. package/dist/stores/file/permission-rule-store.js +75 -7
  189. package/dist/stores/file/tool-result-store.d.ts +14 -0
  190. package/dist/stores/file/tool-result-store.js +39 -2
  191. package/dist/stores/file/workflow-journal-store.d.ts +4 -0
  192. package/dist/stores/file/workflow-journal-store.js +17 -0
  193. package/dist/stores/file/workflow-run-store.d.ts +3 -0
  194. package/dist/stores/file/workflow-run-store.js +15 -0
  195. package/dist/tools/fs/read-deny.d.ts +15 -2
  196. package/dist/tools/fs/read-deny.js +10 -2
  197. package/dist/tools/fs/shell-read-check.d.ts +8 -2
  198. package/dist/tools/fs/shell-read-check.js +7 -7
  199. package/package.json +2 -2
  200. package/test/export-surface.snapshot.json +63 -1
  201. package/wire-changes/core-stores-sql@7.64.0.json +30 -0
  202. package/wire-changes/core@7.64.0.json +2653 -0
  203. package/wire-changes/mods-kernel@7.64.0.json +30 -0
  204. package/wire-changes/primitives@7.64.0.json +30 -0
@@ -76,14 +76,14 @@ export function modeQuestionReaches(mode, roster, toolName, seat) {
76
76
  }
77
77
  const planAsk = (message, call, generic) => {
78
78
  const asked = { action: "ask", message, decisionReason: "mode" };
79
- return generic ? attest(asked, call, { genericQuestion: message }) : asked;
79
+ return generic !== undefined ? attest(asked, call, { sentence: { text: message, generic: true, ...generic } }) : asked;
80
80
  };
81
81
  export function createModeGatePolicy(modeRef, seats) {
82
82
  const askGate = createFsWriteGatePolicy({ env: seats.env, rootPath: seats.rootPath, defaultWrite: "ask" });
83
83
  const acceptSeat = seats.acceptDirs;
84
84
  const acceptDirs = typeof acceptSeat === "function" ? acceptSeat : acceptSeat !== undefined && acceptSeat.length > 0 ? [...acceptSeat] : [seats.rootPath];
85
85
  const acceptRootGate = createFsWriteGatePolicy({ env: seats.env, rootPath: seats.rootPath, acceptDirs, defaultWrite: "ask" });
86
- const planGate = createFsWriteGatePolicy({ env: seats.env, rootPath: seats.rootPath, defaultWrite: "ask", defaultAsk: (path, note, call) => planAsk(`Cannot write to ${path} while in plan mode.${note ?? ""}`, call, note === undefined) });
86
+ const planGate = createFsWriteGatePolicy({ env: seats.env, rootPath: seats.rootPath, defaultWrite: "ask", defaultAsk: (path, note, call) => planAsk(`Cannot write to ${path} while in plan mode.${note ?? ""}`, call, note === undefined ? { echoed: [Object.freeze({ kind: "path", value: path })] } : undefined) });
87
87
  return {
88
88
  async check(req, signal) {
89
89
  const gate = modePolicyOf(modeRef.current).writeGate;
@@ -93,7 +93,7 @@ export function createModeGatePolicy(modeRef, seats) {
93
93
  if (!planRefusesWrite(req, seats.roster?.current, seats.readOnlyDeclared))
94
94
  return { action: "allow" };
95
95
  if (!isProtectedWrite(req))
96
- return planAsk(`Cannot call ${req.toolName} while in plan mode.`, req, true);
96
+ return planAsk(`Cannot call ${req.toolName} while in plan mode.`, req, {});
97
97
  return planGate.check(req, signal);
98
98
  }
99
99
  return (gate === "ask" ? askGate : acceptRootGate).check(req, signal);
@@ -1,7 +1,23 @@
1
+ /**
2
+ * The delegation's two stations over the delegating leg's bus. `agent.offer`: the agent types the model is offered — ONE set
3
+ * ({@link offeredAgents}) read by the listing and by the dispatch; a handler answers `next(e)` or `{ isOffered: false }`.
4
+ * `agent.spawn`: raised before a delegated subagent is let start, every member pinned; a handler answers `next(e)` or
5
+ * `{ deny: <reason> }` in place of `next`; any other answer, a changed member, a throw or a timeout refuses while the
6
+ * subagent has not started, after which the spawn stands. A revival and an observer leg raise no spawn.
7
+ *
8
+ * `$.agent.spawn({ prompt, ... })` is `agent.spawn` called (the table's `call` column): the host entry
9
+ * ({@link createAgentSpawnEntry}) runs the delegation tool's own per-call pipeline, as `$.tool.call` runs any other tool's — the
10
+ * whole gate, `tool.call`, the delegation (whose `agent.spawn` station is raised once, at its own place), the post-execution
11
+ * stations — as the caller's call, with the subagent in the background. The delegation reads ONE fact of the call
12
+ * ({@link AgentStations.extensionSpawn}, the extension call's own record): an extension's spawn is no offer, and it never holds the
13
+ * foreground; where the delegation lets the subagent run it writes `{ agentId, model }` on the record, and the entry answers off
14
+ * that record alone (never off the call's result, which a post-execution station may withhold after the subagent started).
15
+ */
1
16
  import { type ModCallEntry } from "./kernel/index.js";
2
17
  import type { HookInvocationIdentity } from "../hooks.js";
3
18
  import type { PermissionMode } from "../ask-origin.js";
4
19
  import { type LegModBus } from "./stations.js";
20
+ import type { ExtensionRequester } from "../task-event.js";
5
21
  import { type ToolCallEntryInput } from "./tool-call.js";
6
22
  /** One agent type as the model is offered it. */
7
23
  export interface OfferedAgent {
@@ -58,6 +74,8 @@ export declare function spawnedModel(model: string | undefined): string;
58
74
  export interface ExtensionSpawn {
59
75
  /** The registration that called `$.agent.spawn`. */
60
76
  readonly by: string;
77
+ /** Who asked, as the registry row and the durable record carry it ({@link ExtensionRequester}): this extension, by its registration name. */
78
+ readonly requestedBy: ExtensionRequester;
61
79
  /** The subagent was let run under `agentId` — its registry task id, which is its leg's task id and so its events' `agentId`;
62
80
  * `model` is the one the delegation settled (`undefined` ⇒ the child's prepare decides). Written once. */
63
81
  launched(agentId: string, model: string | undefined): void;
@@ -1,4 +1,3 @@
1
- import { randomUUID } from "node:crypto";
2
1
  import { ENGINE_ORIGIN } from "./kernel/index.js";
3
2
  import { isPlainRecord } from "./kernel/receive.js";
4
3
  import { NEXT_IN_FLIGHT } from "./kernel/site-rules.js";
@@ -7,7 +6,7 @@ import { extensionWords } from "../untrusted-egress.js";
7
6
  import { declaredDelegationNameOf } from "../delegation-name.js";
8
7
  import { failedHandlerClause, seatHears } from "./stations.js";
9
8
  import { agentIdOf } from "../leg-identity.js";
10
- import { extensionCallOf, noteExtensionCallLaunched, runExtensionCall } from "./extension-call.js";
9
+ import { extensionCallOf, isExtensionCallId, mintExtensionCallId, noteExtensionCallLaunched, requesterOf, runExtensionCall } from "./extension-call.js";
11
10
  import { resultText } from "./tool-call.js";
12
11
  const ENGINE_PROVIDER = Object.freeze({ plugin: ENGINE_ORIGIN.plugin, tier: ENGINE_ORIGIN.tier });
13
12
  const OFFERED = Object.freeze({ isOffered: true });
@@ -53,10 +52,13 @@ export function createAgentStations(input) {
53
52
  listens: (event) => seatHears(input, event),
54
53
  offered: (agents, signal) => offeredAgents(input, agents, signal),
55
54
  extensionSpawn: (toolCallId) => {
56
- const call = toolCallId !== undefined ? extensionCallOf(input.bus, toolCallId) : undefined;
57
- if (call === undefined || call.door !== "agent.spawn" || toolCallId === undefined)
55
+ if (!isExtensionCallId(toolCallId))
58
56
  return undefined;
59
- return { by: call.caller.origin.plugin, launched: (agentId, model) => noteExtensionCallLaunched(input.bus, toolCallId, { agentId, model: spawnedModel(model) }) };
57
+ const call = extensionCallOf(input.bus, toolCallId);
58
+ const requestedBy = requesterOf(input.bus, toolCallId).requestedBy;
59
+ if (call === undefined || call.door !== "agent.spawn" || requestedBy === undefined)
60
+ return undefined;
61
+ return { by: call.caller.origin.plugin, requestedBy, launched: (agentId, model) => noteExtensionCallLaunched(input.bus, toolCallId, { agentId, model: spawnedModel(model) }) };
60
62
  },
61
63
  spawn: async (facts, signal) => {
62
64
  if (!seatHears(input, "agent.spawn"))
@@ -141,7 +143,7 @@ export function createAgentSpawnEntry(input) {
141
143
  throw new TypeError(`${by}: $.agent.spawn: this run mounts no delegation tool`);
142
144
  if (tools.length > 1)
143
145
  throw new TypeError(`${by}: $.agent.spawn: this run mounts ${tools.length} delegation tools (${tools.map((n) => `"${extensionWords(n, 80)}"`).join(", ")}) and a spawn names none of them`);
144
- const toolCallId = `ext-${randomUUID()}`;
146
+ const toolCallId = mintExtensionCallId();
145
147
  return runExtensionCall(input.bus, toolCallId, "agent.spawn", ctx, async (call) => {
146
148
  const finalized = await input.harness.callTool({ type: "toolCall", id: toolCallId, name: tool, arguments: delegationInput(args, prompt) }, ctx.signal, () => undefined);
147
149
  if (call.launched !== undefined)
@@ -1,5 +1,9 @@
1
1
  import { type ModBottomContext, type ModBus } from "./kernel/index.js";
2
2
  import type { ExtensionRequester } from "../task-event.js";
3
+ /** The id an extension's own call (`$.tool.call`, `$.agent.spawn`) runs under: both doors mint it here. */
4
+ export declare function mintExtensionCallId(): string;
5
+ /** Whether `id` is a call id {@link mintExtensionCallId} could have minted — the one reading of "an extension's own call id". */
6
+ export declare function isExtensionCallId(id: unknown): id is string;
3
7
  /** Which `$` call made the record: the door the extension came through. */
4
8
  export type ExtensionDoor = "tool.call" | "agent.spawn";
5
9
  /** One extension's call while it runs. */
@@ -1,5 +1,13 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { randomUUID } from "node:crypto";
2
3
  import { ENGINE_ORIGIN } from "./kernel/index.js";
4
+ const EXTENSION_CALL_ID_PREFIX = "ext-";
5
+ export function mintExtensionCallId() {
6
+ return `${EXTENSION_CALL_ID_PREFIX}${randomUUID()}`;
7
+ }
8
+ export function isExtensionCallId(id) {
9
+ return typeof id === "string" && id.startsWith(EXTENSION_CALL_ID_PREFIX);
10
+ }
3
11
  const store = new AsyncLocalStorage();
4
12
  export function extensionCallOf(bus, toolCallId) {
5
13
  const c = store.getStore();
@@ -8,9 +8,8 @@ import { ENGINE_ORIGIN } from "./kernel/index.js";
8
8
  import { isPlainRecord } from "./kernel/receive.js";
9
9
  import { NEXT_IN_FLIGHT } from "./kernel/site-rules.js";
10
10
  import { classicEventBase, failedHandlerClause, failedHandlerName, judgedInputOf } from "./stations.js";
11
- import { runExtensionCall } from "./extension-call.js";
11
+ import { mintExtensionCallId, runExtensionCall } from "./extension-call.js";
12
12
  import { settleWithheldResult } from "../frame-settlement.js";
13
- import { randomUUID } from "node:crypto";
14
13
  const FORM = "tool.call takes next(e), { deny: <reason> } or { result } (a string, or a list of text blocks)";
15
14
  const denyOf = (a) => isPlainRecord(a) && Object.keys(a).length === 1 && typeof a["deny"] === "string" && a["deny"] !== "" ? a["deny"] : undefined;
16
15
  function substituteOf(a) {
@@ -54,7 +53,7 @@ export function createToolCallStation(input) {
54
53
  const content = [{ type: "text", text: formatHookFeedback(text, input.reminderMark) }];
55
54
  if (by !== undefined) {
56
55
  if (input.occurrences.get(call.toolCallId) !== undefined) {
57
- input.occurrences.refuse(call.toolCallId, "hook", by);
56
+ input.occurrences.refuse(call.toolCallId, "hook", { extension: by });
58
57
  input.occurrences.answeredInPlace(call.toolCallId, by);
59
58
  }
60
59
  input.blockedToolCalls.add(call.toolCallId);
@@ -151,7 +150,7 @@ export function createToolCallEntry(input) {
151
150
  const { tool, ...callInput } = args;
152
151
  if (typeof tool !== "string" || tool === "")
153
152
  throw new TypeError(`${by}: $.tool.call takes the event's input: { tool, ...args }`);
154
- const toolCallId = `ext-${randomUUID()}`;
153
+ const toolCallId = mintExtensionCallId();
155
154
  return runExtensionCall(input.bus, toolCallId, "tool.call", ctx, async (call) => {
156
155
  const finalized = await input.harness.callTool({ type: "toolCall", id: toolCallId, name: tool, arguments: { ...callInput } }, ctx.signal, (t) => {
157
156
  const contractId = input.faceOf(t.name)?.contractId;
@@ -41,11 +41,11 @@ export type ParentSpecSeatFields = Pick<TaskSpec, "principal" | "oneShot" | "cli
41
41
  * · `memory` — the request-level "memory is off" FACT, `{ enabled: false }` and nothing else of the declaration (the clamp
42
42
  * table's `memory.enabled` row; present only when the parent stated `enabled: false`): a REMOVAL (floor) that
43
43
  * REWRITES the one member on the child's own memory declaration — its scopes and knobs are the child's.
44
- * · `compaction` — the request's CONTEXT-MANAGEMENT settings (enabled / withinTask / reserve / keepRecent /
44
+ * · `compaction` — the request's CONTEXT-MANAGEMENT settings (autoCompact / manualCompact / withinTask / reserve / keepRecent /
45
45
  * instructions / attachWorkingFiles / staleToolResultOffload / clampTolerance). One set of settings for the
46
46
  * whole delegation tree, measured per leg against the leg's OWN window: the numbers are repaired against the
47
47
  * child's model by the same sanitizer every leg runs (`sanitizeCompactionSettings`), so a parent's 128k-tuned
48
- * reserve does not have to be re-tuned to be legal on a 6k child. `enabled: false` is NOT a removal — the
48
+ * reserve does not have to be re-tuned to be legal on a 6k child. A seat's `false` is NOT a removal — the
49
49
  * reference implementation shares one settings object down the tree rather than flooring children, and a
50
50
  * child that authors its own settings wins the whole object (an ORDINARY seat member).
51
51
  * · `skillListingBudgetFraction` / `skillListingMaxDescChars` — the listing-budget knobs, the same shape for the
@@ -6,6 +6,11 @@ export interface PeerChannelSelf {
6
6
  sessionId: string;
7
7
  /** The mailbox scope this session's box lives in. */
8
8
  scope: string;
9
+ /** The occupant of this session's row — its `SessionMetadata.incarnation` — or `null` when the row carries no token. REQUIRED,
10
+ * `null` included: every frame the listener appends is stamped for it (`MailboxPeerMeta.occupant`), the session's drain hands a
11
+ * record only to the occupant it names, and the published registration row carries it so a peer of this engine addresses this
12
+ * session's box the same way. An addressing fact, never a credential. */
13
+ occupant: string | null;
9
14
  /** The doorbell rang (a peer appended to this session's box). The HOST decides what to do with it —
10
15
  * start a turn now, or let the next boundary drain; the engine never starts a turn on a frame. */
11
16
  onNudge?: () => void;
@@ -517,7 +517,12 @@ export declare function precheckEditedRuleText(text: string, command: string): E
517
517
  * `rev` is the DURABLE store's revision. A session-scope redemption (design/382 §4.3) lands in the
518
518
  * session overlay and does not move it: its `rev` is a best-effort read of the store's current
519
519
  * revision (0 when the store could not be read — the landing is in the overlay either way, and the
520
- * durable revision is reporting, not the landing's identity). */
520
+ * durable revision is reporting, not the landing's identity).
521
+ *
522
+ * A refusal is one shape wherever this module refuses — the single ticket, the batch's own record-level refusals and
523
+ * (with the member's identity beside them) a batch member's row: `reason` is the sentence for a person and is never
524
+ * parsed, `code` the cause ({@link RuleRefusalCode}), `committed` what may be claimed about the bytes
525
+ * ({@link RuleWriteCommitted}). */
521
526
  export type RedeemResult = {
522
527
  status: "redeemed";
523
528
  behavior: RuleBehavior;
@@ -528,6 +533,8 @@ export type RedeemResult = {
528
533
  alreadyRedeemed: boolean;
529
534
  } | {
530
535
  status: "refused";
536
+ code: RuleRefusalCode;
537
+ committed: RuleWriteCommitted;
531
538
  reason: string;
532
539
  };
533
540
  /**
@@ -536,6 +543,9 @@ export type RedeemResult = {
536
543
  * Takes a ticket and a verified principal, and nothing else. There is deliberately no field carrying rule
537
544
  * text: what gets persisted is what the engine put in the record when it drew the card, so a host cannot
538
545
  * turn a click on `git status` into a rule for something else.
546
+ *
547
+ * This is also the one leg every member of a batch walk takes ({@link redeemRuleBatch}), so a refusal here is the
548
+ * same `code` / `committed` / `reason` a member row carries (a member's row adds the member's identity).
539
549
  */
540
550
  export declare function redeemRuleTicket(opts: {
541
551
  ticket: RuleTicket;
@@ -599,11 +609,9 @@ export interface ImportPreview {
599
609
  * retry is `alreadyRedeemed: true` AND `persisted`; a rule that pre-existed in the store is
600
610
  * `false` AND `deduped` — the two axes answer different questions and neither implies the other).
601
611
  * A refused row always carries its `reason` (a sentence for a person, never parsed) and two closed words: `code`, the
602
- * cause ({@link RuleRefusalCode}), and `committed`, what may be claimed about the bytes ({@link RuleWriteCommitted}) —
603
- * `no` when the member's rule does not stand because of this call (nothing was written, or the store answered that
604
- * nothing landed, or the rule's dot is no longer live), `unknown` when the write or the read-back that would have settled
605
- * it did not settle, so the caller reconciles with `list()` rather than retrying blind. `deduped` counts as LANDED: an
606
- * equivalent rule already standing means the consent is already in effect.
612
+ * cause ({@link RuleRefusalCode}), and `committed`, what may be claimed about the bytes — the one reading is
613
+ * {@link RuleWriteCommitted}'s, stated there and not here (a member whose dot a successful read finds no longer live is
614
+ * read by it too). `deduped` counts as LANDED: an equivalent rule already standing means the consent is already in effect.
607
615
  *
608
616
  * design/382 §4.3 — on a SESSION-scope member the two landed words mean the same thing about a
609
617
  * different home: landed in / already in the session's OVERLAY (a session rule's home store), never
@@ -703,7 +711,11 @@ export declare function prepareStarterBatch(opts: {
703
711
  * offer's member order, no extras — so a caller's aggregate is an honest projection: all rows
704
712
  * landed (`persisted` or `deduped`, both count as the consent being in effect) is full
705
713
  * success, and ANY refused row must project to a non-success aggregate, never to a silent
706
- * partial one.
714
+ * partial one;
715
+ * · a walk that cannot start (the record is missing or cannot be read, another principal's, stale, pending,
716
+ * malformed, or the owner's store cannot be resolved) answers no table: it answers the
717
+ * {@link RedeemResult} refused arm, `code` / `committed` / `reason`, the one shape a single
718
+ * ticket's refusal and a member's row take.
707
719
  */
708
720
  export declare function redeemRuleBatch(opts: {
709
721
  approvalId: string;
@@ -713,7 +725,6 @@ export declare function redeemRuleBatch(opts: {
713
725
  }): Promise<{
714
726
  members: readonly RedeemedBatchMember[];
715
727
  rev: number;
716
- } | {
728
+ } | Extract<RedeemResult, {
717
729
  status: "refused";
718
- reason: string;
719
- }>;
730
+ }>>;
@@ -660,16 +660,26 @@ async function confirmEditedCandidate(rec, edit, deps) {
660
660
  function refusal(code, reason, committed = "no") {
661
661
  return { status: "refused", code, committed, reason };
662
662
  }
663
- export async function redeemRuleTicket(opts) {
664
- const res = await redeemTicketLeg(opts);
665
- return res.status === "refused" ? { status: "refused", reason: res.reason } : res;
663
+ async function storeStep(step, failure) {
664
+ try {
665
+ return { value: await step() };
666
+ }
667
+ catch (err) {
668
+ return { refused: refusal(failure.code, `${failure.what}: ${errText(err)}`, failure.code === "store_write" ? "unknown" : "no") };
669
+ }
666
670
  }
667
- async function redeemTicketLeg(opts) {
671
+ const RECORD_READ = { code: "store_read", what: "could not read the approval record" };
672
+ const RECORD_CAS = { code: "store_write", what: "the approval record store failed the compare-and-set that records this redemption's dot" };
673
+ const DOT_ALLOCATION = { code: "store_write", what: "the permission-rule store failed to allocate this redemption's dot" };
674
+ export async function redeemRuleTicket(opts) {
668
675
  const caller = resolveCallerOwner(opts.principal, opts.owner, "redeemRuleTicket");
669
676
  const parsed = parseRuleTicket(opts.ticket);
670
677
  if (parsed === undefined)
671
678
  return refusal("ticket_invalid", "malformed ticket");
672
- const rec = await opts.deps.approvals.get(parsed.recordId);
679
+ const read = await storeStep(() => opts.deps.approvals.get(parsed.recordId), RECORD_READ);
680
+ if ("refused" in read)
681
+ return read.refused;
682
+ const rec = read.value;
673
683
  if (rec === undefined)
674
684
  return refusal("record_missing", "no such approval record");
675
685
  const recOwner = ownerOfRecord(rec);
@@ -710,7 +720,16 @@ async function redeemTicketLeg(opts) {
710
720
  if (writer === undefined)
711
721
  return refusal("store_unavailable", "the resolved permission-rule store has no write face");
712
722
  const known = rec.redeemedDots?.[parsed.index];
713
- const dot = known ?? (await writer.nextDot());
723
+ let dot;
724
+ if (known !== undefined) {
725
+ dot = known;
726
+ }
727
+ else {
728
+ const minted = await storeStep(() => writer.nextDot(), DOT_ALLOCATION);
729
+ if ("refused" in minted)
730
+ return minted.refused;
731
+ dot = minted.value;
732
+ }
714
733
  if (known === undefined) {
715
734
  const next = {
716
735
  ...rec,
@@ -718,9 +737,14 @@ async function redeemTicketLeg(opts) {
718
737
  state: "redeemed",
719
738
  redeemedDots: { ...(rec.redeemedDots ?? {}), [parsed.index]: dot },
720
739
  };
721
- const ok = await opts.deps.approvals.cas(rec.id, rec.rev, next);
722
- if (!ok) {
723
- const again = await opts.deps.approvals.get(rec.id);
740
+ const casted = await storeStep(() => opts.deps.approvals.cas(rec.id, rec.rev, next), RECORD_CAS);
741
+ if ("refused" in casted)
742
+ return casted.refused;
743
+ if (!casted.value) {
744
+ const reread = await storeStep(() => opts.deps.approvals.get(rec.id), RECORD_READ);
745
+ if ("refused" in reread)
746
+ return reread.refused;
747
+ const again = reread.value;
724
748
  const theirs = again === undefined || isStale(again) ? undefined : again.redeemedDots?.[parsed.index];
725
749
  if (theirs === undefined)
726
750
  return refusal("record_changed", "the approval record changed state concurrently");
@@ -946,30 +970,33 @@ export async function prepareStarterBatch(opts) {
946
970
  }
947
971
  export async function redeemRuleBatch(opts) {
948
972
  const caller = resolveCallerOwner(opts.principal, opts.owner, "redeemRuleBatch");
949
- const rec = await opts.deps.approvals.get(opts.approvalId);
973
+ const read = await storeStep(() => opts.deps.approvals.get(opts.approvalId), RECORD_READ);
974
+ if ("refused" in read)
975
+ return read.refused;
976
+ const rec = read.value;
950
977
  if (rec === undefined)
951
- return { status: "refused", reason: "no such approval record" };
978
+ return refusal("record_missing", "no such approval record");
952
979
  const recOwner = ownerOfRecord(rec);
953
980
  if (recOwner === undefined || !sameRuleOwner(recOwner, caller))
954
- return { status: "refused", reason: "the record belongs to a different principal" };
981
+ return refusal("wrong_principal", "the record belongs to a different principal");
955
982
  if (isStale(rec))
956
- return { status: "refused", reason: `record_schema_stale: ${STALE_RECORD_MESSAGE}` };
983
+ return refusal("record_schema_stale", `record_schema_stale: ${STALE_RECORD_MESSAGE}`);
957
984
  if (rec.state === "pending")
958
- return { status: "refused", reason: "the approval record has not been confirmed" };
985
+ return refusal("not_confirmed", "the approval record has not been confirmed");
959
986
  const damage = approvalRecordDamageOf(rec);
960
987
  if (damage !== undefined)
961
- return { status: "refused", reason: `the approval record is malformed: ${damage}` };
988
+ return refusal("record_malformed", `the approval record is malformed: ${damage}`);
962
989
  const chosen = rec.selectedOffer;
963
990
  const chosenOffer = chosen !== undefined && Number.isInteger(chosen) ? rec.offers[chosen] : undefined;
964
991
  if (chosenOffer === undefined) {
965
- return { status: "refused", reason: "the approval record is malformed: it is settled but names no valid chosen offer" };
992
+ return refusal("record_malformed", "the approval record is malformed: it is settled but names no valid chosen offer");
966
993
  }
967
994
  let store;
968
995
  try {
969
996
  store = storeForOwner(opts.deps.provider, caller);
970
997
  }
971
998
  catch (err) {
972
- return { status: "refused", reason: errText(err) };
999
+ return refusal("store_unavailable", errText(err));
973
1000
  }
974
1001
  const members = [];
975
1002
  let rev = 0;
@@ -983,7 +1010,7 @@ export async function redeemRuleBatch(opts) {
983
1010
  const candidate = rec.candidates[candidateIndex];
984
1011
  const row = { candidateIndex, behavior: candidate.behavior, rule: candidate.rule, scope: candidate.scope };
985
1012
  if (candidate.behavior === "allow" && tighteningFailed !== undefined) {
986
- members.push({ ...row, status: "refused", code: "withheld", committed: "no", reason: `withheld: candidate ${tighteningFailed} (a deny/ask member of this batch) did not land, and an allow must not stand wider than the list that was confirmed — redeem the batch again once the store accepts the tightening member` });
1013
+ members.push({ ...row, ...refusal("withheld", `withheld: candidate ${tighteningFailed} (a deny/ask member of this batch) did not land, and an allow must not stand wider than the list that was confirmed — redeem the batch again once the store accepts the tightening member`) });
987
1014
  continue;
988
1015
  }
989
1016
  let alreadyThere = false;
@@ -994,19 +1021,19 @@ export async function redeemRuleBatch(opts) {
994
1021
  alreadyThere = snap.rules.some((r) => r.behavior === candidate.behavior && r.rule === candidate.rule && sameScope(r.scope, candidate.scope));
995
1022
  }
996
1023
  catch (err) {
997
- members.push({ ...row, status: "refused", code: "store_read", committed: "no", reason: `could not read the permission-rule store: ${errText(err)}` });
1024
+ members.push({ ...row, ...refusal("store_read", `could not read the permission-rule store: ${errText(err)}`) });
998
1025
  if (candidate.behavior !== "allow")
999
1026
  tighteningFailed ??= candidateIndex;
1000
1027
  continue;
1001
1028
  }
1002
1029
  }
1003
- const res = await redeemTicketLeg({
1030
+ const res = await redeemRuleTicket({
1004
1031
  ticket: mintRuleTicket(rec.id, candidateIndex),
1005
1032
  ...(caller.kind === "principal" ? { principal: caller.principal } : { owner: caller }),
1006
1033
  deps: opts.deps,
1007
1034
  });
1008
1035
  if (res.status === "refused") {
1009
- members.push({ ...row, status: "refused", code: res.code, committed: res.committed, reason: res.reason });
1036
+ members.push({ ...row, ...res });
1010
1037
  if (candidate.behavior !== "allow")
1011
1038
  tighteningFailed ??= candidateIndex;
1012
1039
  continue;
@@ -1022,12 +1049,12 @@ export async function redeemRuleBatch(opts) {
1022
1049
  unreadable = errText(err);
1023
1050
  }
1024
1051
  if (unreadable !== undefined) {
1025
- members.push({ ...row, status: "refused", code: "store_read", committed: "unknown", reason: `could not read the permission-rule store to confirm this ${candidate.behavior} member stands after its redemption: ${unreadable}` });
1052
+ members.push({ ...row, ...refusal("store_read", `could not read the permission-rule store to confirm this ${candidate.behavior} member stands after its redemption: ${unreadable}`, "unknown") });
1026
1053
  tighteningFailed ??= candidateIndex;
1027
1054
  continue;
1028
1055
  }
1029
1056
  if (!live) {
1030
- members.push({ ...row, status: "refused", code: "dot_removed", committed: "no", reason: `this ${candidate.behavior} member's redeemed dot ${res.dot.actor}#${res.dot.counter} is not live in the store (removed since it was redeemed) — a removed rule is not re-landed by replaying its record; a new consent is required` });
1057
+ members.push({ ...row, ...refusal("dot_removed", `this ${candidate.behavior} member's redeemed dot ${res.dot.actor}#${res.dot.counter} is not live in the store (removed since it was redeemed) — a removed rule is not re-landed by replaying its record; a new consent is required`) });
1031
1058
  tighteningFailed ??= candidateIndex;
1032
1059
  continue;
1033
1060
  }
@@ -64,6 +64,24 @@ export interface StoredRules {
64
64
  * partition that cannot be read: every call is asked about until a read succeeds.
65
65
  */
66
66
  export declare const PERMISSION_RULES_LATER_GRAMMAR_CODE = "permission_rules.later_grammar";
67
+ /**
68
+ * The code a file bucket's refusal carries when the bucket is DETERMINISTICALLY unreadable: the same bytes will be refused the same
69
+ * way on every read until a person repairs or removes them — a link or a file that is not a regular file, bytes that are not JSON, a
70
+ * shape that is not a schema-4 bucket, a checksum that does not match, a rule-grammar stamp that is no whole number, a row whose
71
+ * behavior word is outside the set, or a store directory this engine refuses to use. Every face refuses the bucket whole with it
72
+ * (reads answer zero rules and disclose; a write refuses), so a caller tells "this bucket cannot be read and a retry reads the same" from
73
+ * a read that failed ({@link PERMISSION_RULES_UNREADABLE_BUCKET_CODE}) and from a bucket a newer engine wrote
74
+ * ({@link PERMISSION_RULES_LATER_GRAMMAR_CODE}). Decide by the code, never by the sentence.
75
+ */
76
+ export declare const PERMISSION_RULES_DAMAGED_BUCKET_CODE = "permission_rules.bucket_damaged";
77
+ /**
78
+ * The code a file bucket's refusal carries when reading it FAILED — the filesystem answered with an error (`EIO`, `EACCES`, …) rather
79
+ * than with bytes this engine judged — so a retry may read it. The system error's name rides on the refusal as its own member `errno`
80
+ * (a string, as the system gave it: `"EIO"`, `"EACCES"`), absent when the failure carried none; it is not part of `code`, which has one
81
+ * vocabulary. A caller that must not act on a bucket it could not read (it is not known to be empty) refuses on this code and may try
82
+ * again; one that meets {@link PERMISSION_RULES_DAMAGED_BUCKET_CODE} has a bucket that will not read until a person acts.
83
+ */
84
+ export declare const PERMISSION_RULES_UNREADABLE_BUCKET_CODE = "permission_rules.bucket_unreadable";
67
85
  /**
68
86
  * The durable partition's read face: read-only, already anchored to a single owner. Rows carry the two
69
87
  * durable scopes only (`global` = the `user` source, `project` = the `project` source); a session row
@@ -596,11 +614,19 @@ export type RemovalLiveness = (typeof REMOVAL_LIVENESS_WORDS)[number];
596
614
  * What a terminal write FAILURE may claim about the bytes — the failure half of the honesty
597
615
  * {@link RemovalLiveness} keeps on the success half, spelled ONCE and read by every write entry here.
598
616
  *
599
- * `"no"` = the store ITSELF answered: a face that cannot write at all, a target the type face refuses,
617
+ * ONE reading: the word answers "has the store ITSELF settled whether anything this call wrote stands?".
618
+ *
619
+ * `"no"` = it has, and nothing does: a face that cannot write at all, a target the type face refuses,
600
620
  * a read that failed before any write, a refused preflight, an epoch seal, a compare-and-set that lost
601
- * every attempt. Each of those is the store saying nothing landed, so saying it is a fact.
602
- * `"unknown"` = the apply THREW, which proves nothing either way (a backend can commit and then lose
603
- * its acknowledgement), or the read-back that would have settled it could not be taken.
621
+ * every attempt. Each of those is the store saying nothing landed, so saying it is a fact. The same word
622
+ * covers a write that DID land and that a read which SUCCEEDED then finds removed (a redemption walk's
623
+ * `dot_removed`): the add's dot is in the raw state under its tombstone, the rule does not stand, and the
624
+ * store has said so — the word is about whether the call's rule stands, never about the history of the
625
+ * bytes, and a retry of the same ticket re-reads the same tombstone (a new consent is what lands it).
626
+ * `"unknown"` = it has not: the apply THREW, which proves nothing either way (a backend can commit and
627
+ * then lose its acknowledgement), or the read-back that would have settled it could not be taken. A
628
+ * settled absence is never `unknown`: that word would send the caller to reconcile with `list()` for an
629
+ * answer the store already gave.
604
630
  *
605
631
  * The word exists because the caller's two branches — retry, or reconcile with `list()` — are not
606
632
  * derivable from the failure PROSE. A consumer reading the strength out of the sentence is parsing a
@@ -631,11 +657,12 @@ export type RuleWriteCommitted = (typeof RULE_WRITE_COMMITTED_WORDS)[number];
631
657
  * - `store_unavailable` — the owner's store cannot be resolved, or has no write face
632
658
  * - `record_changed` — the record moved under this redemption and the dot it needed is not there
633
659
  * - `withheld` — held back because the batch's deny/ask members do not all stand, and an allow may not stand wider
634
- * - `store_read` — a permission-rule store read failed (before the write: `no`; the read-back after it: `unknown`)
635
- * - `store_write` — the write threw, answered unreadably, or was reported landed with no trace of its dot (`unknown`)
660
+ * - `store_read` — a store read failed: the permission-rule store's, or the approval record's (before the write: `no`; the read-back after it: `unknown`)
661
+ * - `store_write` — the write threw, answered unreadably, or was reported landed with no trace of its dot; or the approval record's compare-and-set that records the dot, or the dot's allocation, threw (`unknown`)
636
662
  * - `session_ended` — a session-scope rule whose session has ended; a late redemption cannot revive it
637
663
  * - `occ` — every optimistic-concurrency attempt lost its compare-and-set
638
- * - `dot_removed` — the member's redeemed dot is no longer live in the store (the rule was removed since)
664
+ * - `dot_removed` — the member's redeemed dot is no longer live in the store (the rule was removed since); its
665
+ * `committed` is `no`, the store having settled that the rule does not stand ({@link RuleWriteCommitted})
639
666
  */
640
667
  export declare const RULE_REFUSAL_CODES: readonly ["unsupported.layer_root", "ticket_invalid", "record_missing", "wrong_principal", "record_schema_stale", "not_confirmed", "record_malformed", "not_chosen", "parse_rejected", "store_unavailable", "record_changed", "withheld", "store_read", "store_write", "session_ended", "occ", "dot_removed"];
641
668
  export type RuleRefusalCode = (typeof RULE_REFUSAL_CODES)[number];
@@ -670,8 +697,8 @@ export type RemoveResult =
670
697
  }
671
698
  /** Terminal failure, in one of two strengths — word for word the dual of {@link AddResult}'s, and
672
699
  * `committed` is the word for it ({@link RuleWriteCommitted}), so the strength is READ, not parsed out
673
- * of the sentence. When the STORE answered every attempt (the compare-and-set simply lost), nothing
674
- * landed: `committed: "no"`, and the read-back confirms it in the text. When the apply THREW, a missing
700
+ * of the sentence (the one reading is {@link RuleWriteCommitted}'s). When the STORE answered every attempt (the
701
+ * compare-and-set simply lost), nothing landed: `committed: "no"`, and the read-back confirms it in the text. When the apply THREW, a missing
675
702
  * tombstone cannot tell a write that never landed from one whose evidence a paired collection erased
676
703
  * (`collectBelowFrontier` recycles a tombstone together with the adds it covered), so that outcome is
677
704
  * `committed: "unknown"`, reported INDETERMINATE, and the caller reconciles with `list()` rather than
@@ -714,10 +741,7 @@ export type RuleAddLanding = {
714
741
  landed: true;
715
742
  rev: number;
716
743
  }
717
- /** `committed` is what the caller may CLAIM afterwards. `"no"` means the store itself answered — a
718
- * read that failed before any write, a refused preflight, an epoch seal, or a compare-and-set that
719
- * lost every attempt: each of those is the store saying nothing landed. `"unknown"` means the apply
720
- * THREW, which proves nothing either way: a backend can commit and then lose its acknowledgement.
744
+ /** `committed` is what the caller may CLAIM afterwards, read as {@link RuleWriteCommitted} reads it (defined there, once).
721
745
  * `code` is the cause ({@link RuleRefusalCode}); this path mints five of them (`withheld`, `store_read`,
722
746
  * `store_write`, `session_ended`, `occ`), so a door never reads the cause out of `reason`. */
723
747
  | {
@@ -767,10 +791,11 @@ export type AddResult =
767
791
  status: "no-op";
768
792
  rev: number;
769
793
  }
770
- /** Terminal failure, in one of two strengths the `error` text distinguishes. When the STORE answered
794
+ /** Terminal failure, in one of two strengths the `error` text distinguishes (read as {@link RuleWriteCommitted}
795
+ * reads them). When the STORE answered
771
796
  * (a read that failed before any write, a refused preflight, an epoch seal, a compare-and-set that
772
- * lost every attempt) nothing landed and the text says so plainly. When the apply THREW, the write
773
- * may have committed and lost its acknowledgement: the read-back asks the raw face, where an add
797
+ * lost every attempt) nothing landed and the text says so plainly. When the apply THREW (or reported a landing
798
+ * that could not be witnessed), the write may have committed and lost its acknowledgement: the read-back asks the raw face, where an add
774
799
  * survives the tombstone a concurrent removal laid on it — but a sync collection can erase even
775
800
  * that, so a dot it cannot find is reported INDETERMINATE rather than as a confirmed nothing, and
776
801
  * the caller reconciles with `list()` instead of retrying blind (a blind retry mints a fresh dot and
@@ -5,6 +5,8 @@ import { readRuleOwner } from "./rule-owner.js";
5
5
  import { thrownText } from "./thrown-value.js";
6
6
  import { validatePath } from "./effective-path-target.js";
7
7
  export const PERMISSION_RULES_LATER_GRAMMAR_CODE = "permission_rules.later_grammar";
8
+ export const PERMISSION_RULES_DAMAGED_BUCKET_CODE = "permission_rules.bucket_damaged";
9
+ export const PERMISSION_RULES_UNREADABLE_BUCKET_CODE = "permission_rules.bucket_unreadable";
8
10
  export function isRuleRevision(rev) {
9
11
  return typeof rev === "number" && Number.isSafeInteger(rev) && rev >= 0;
10
12
  }
@@ -0,0 +1,20 @@
1
+ /** What a quoted span of a refusal sentence IS: a file path, a command line, or a deny/rule pattern. */
2
+ export declare const REFUSAL_ECHO_KINDS: readonly ["path", "command", "pattern"];
3
+ export type RefusalEchoKind = (typeof REFUSAL_ECHO_KINDS)[number];
4
+ /** Membership test for {@link RefusalEchoKind}. */
5
+ export declare function isRefusalEchoKind(v: unknown): v is RefusalEchoKind;
6
+ /**
7
+ * One literal the sentence quotes, in the order the sentence quotes them. `value` is the literal as the refusing judge
8
+ * held it — the sentence elides the middle of a long one, this member never does. `canonical` stands on a `path` whose
9
+ * canonical target the sentence also names because the two differ.
10
+ */
11
+ export interface RefusalEcho {
12
+ readonly kind: RefusalEchoKind;
13
+ readonly value: string;
14
+ readonly canonical?: string;
15
+ }
16
+ /** The defects of `v` read as a list of {@link RefusalEcho} (an empty list is a clean one): a dense non-empty array holding nothing
17
+ * but its elements (no hole, no member of its own beside them — a method name or a symbol on the array is read by nobody here and
18
+ * JSON drops it), of records that hold exactly `kind` (a member of the set), `value` (a non-empty string) and, on a `path`, an
19
+ * optional non-empty `canonical`. Reads the list by index alone: no method of a caller's array is ever called. */
20
+ export declare function refusalEchoDefects(v: unknown): string[];
@@ -0,0 +1,33 @@
1
+ import { strayMembersOf } from "./own-property-receipt.js";
2
+ const ECHO_MEMBERS = Object.freeze(["kind", "value", "canonical"]);
3
+ const ECHO_WORDS = Object.freeze({ subject: "an echo", unit: "member", moment: "at the gate record" });
4
+ export const REFUSAL_ECHO_KINDS = Object.freeze(["path", "command", "pattern"]);
5
+ const KIND_SET = new Set(REFUSAL_ECHO_KINDS);
6
+ export function isRefusalEchoKind(v) {
7
+ return KIND_SET.has(v);
8
+ }
9
+ export function refusalEchoDefects(v) {
10
+ if (!Array.isArray(v) || v.length === 0)
11
+ return ["echoed is not a non-empty list"];
12
+ const out = [];
13
+ if (Reflect.ownKeys(v).length !== v.length + 1)
14
+ out.push("echoed holds a hole or a member that is no element");
15
+ for (let i = 0; i < v.length; i++) {
16
+ const e = v[i];
17
+ if (typeof e !== "object" || e === null || Array.isArray(e)) {
18
+ out.push(`echoed[${i}] is not an object`);
19
+ continue;
20
+ }
21
+ const r = e;
22
+ if (!isRefusalEchoKind(r.kind))
23
+ out.push(`echoed[${i}].kind is outside the closed set`);
24
+ if (typeof r.value !== "string" || r.value === "")
25
+ out.push(`echoed[${i}].value is not a non-empty string`);
26
+ if (r.canonical !== undefined && (typeof r.canonical !== "string" || r.canonical === "" || r.kind !== "path"))
27
+ out.push(`echoed[${i}].canonical stands only on a path, as a non-empty string`);
28
+ const stray = strayMembersOf(r, ECHO_WORDS, ECHO_MEMBERS);
29
+ if (stray !== undefined)
30
+ out.push(`echoed[${i}]: ${stray.sentence}`);
31
+ }
32
+ return out;
33
+ }