harnery 0.43.0 → 0.44.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 (278) hide show
  1. package/README.md +3 -3
  2. package/dist/commands/agents.d.ts.map +1 -1
  3. package/dist/commands/agents.js +41 -48
  4. package/dist/commands/browse.d.ts.map +1 -1
  5. package/dist/commands/browse.js +38 -11
  6. package/dist/commands/diagnostics.d.ts.map +1 -1
  7. package/dist/commands/diagnostics.js +10 -0
  8. package/dist/commands/doctor.d.ts +12 -0
  9. package/dist/commands/doctor.d.ts.map +1 -1
  10. package/dist/commands/doctor.js +22 -7
  11. package/dist/commands/governor.js +22 -10
  12. package/dist/commands/inbox.d.ts +1 -1
  13. package/dist/commands/inbox.d.ts.map +1 -1
  14. package/dist/commands/inbox.js +55 -2
  15. package/dist/commands/rm.d.ts.map +1 -1
  16. package/dist/commands/rm.js +28 -4
  17. package/dist/commands/servers.d.ts.map +1 -1
  18. package/dist/commands/servers.js +16 -1
  19. package/dist/commands/supervisor.d.ts.map +1 -1
  20. package/dist/commands/supervisor.js +7 -2
  21. package/dist/commands/toc.d.ts +14 -0
  22. package/dist/commands/toc.d.ts.map +1 -1
  23. package/dist/commands/toc.js +7 -4
  24. package/dist/commands/workflow.js +24 -30
  25. package/dist/core/agents/live-authority-v3.d.ts +1 -0
  26. package/dist/core/agents/live-authority-v3.d.ts.map +1 -1
  27. package/dist/core/agents/live-authority-v3.js +11 -0
  28. package/dist/core/agents/live-lifecycle-v3.d.ts +4 -2
  29. package/dist/core/agents/live-lifecycle-v3.d.ts.map +1 -1
  30. package/dist/core/agents/live-lifecycle-v3.js +28 -7
  31. package/dist/core/agents/mailbox.d.ts +9 -8
  32. package/dist/core/agents/mailbox.d.ts.map +1 -1
  33. package/dist/core/agents/mailbox.js +24 -17
  34. package/dist/core/agents/render/prompt-context.d.ts +2 -0
  35. package/dist/core/agents/render/prompt-context.d.ts.map +1 -1
  36. package/dist/core/agents/render/prompt-context.js +8 -12
  37. package/dist/core/agents/render/session-context.d.ts +2 -8
  38. package/dist/core/agents/render/session-context.d.ts.map +1 -1
  39. package/dist/core/agents/render/session-context.js +7 -30
  40. package/dist/core/agents/rules/stop-hook.js +3 -3
  41. package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -1
  42. package/dist/core/agents/state/heartbeat-writer.js +25 -14
  43. package/dist/core/agents/state/live-coordination-writer.d.ts.map +1 -1
  44. package/dist/core/agents/state/live-coordination-writer.js +5 -0
  45. package/dist/core/agents/state/pidmap.d.ts.map +1 -1
  46. package/dist/core/agents/state/pidmap.js +5 -0
  47. package/dist/core/agents/state/proc-start.d.ts +19 -0
  48. package/dist/core/agents/state/proc-start.d.ts.map +1 -1
  49. package/dist/core/agents/state/proc-start.js +41 -0
  50. package/dist/core/agents/state/stale-sweep.d.ts.map +1 -1
  51. package/dist/core/agents/state/stale-sweep.js +180 -70
  52. package/dist/core/agents/state/unchanged-file.d.ts +44 -0
  53. package/dist/core/agents/state/unchanged-file.d.ts.map +1 -0
  54. package/dist/core/agents/state/unchanged-file.js +390 -0
  55. package/dist/core/context/index.d.ts +22 -10
  56. package/dist/core/context/index.d.ts.map +1 -1
  57. package/dist/core/context/index.js +381 -119
  58. package/dist/core/context/observation.d.ts +26 -0
  59. package/dist/core/context/observation.d.ts.map +1 -0
  60. package/dist/core/context/observation.js +11 -0
  61. package/dist/core/diagnostics/bundle.d.ts.map +1 -1
  62. package/dist/core/diagnostics/bundle.js +25 -14
  63. package/dist/core/diagnostics/path-identity.d.ts +3 -0
  64. package/dist/core/diagnostics/path-identity.d.ts.map +1 -0
  65. package/dist/core/diagnostics/path-identity.js +12 -0
  66. package/dist/core/diagnostics/sanitize.d.ts.map +1 -1
  67. package/dist/core/diagnostics/sanitize.js +4 -3
  68. package/dist/core/events/v3/authority-outbox.d.ts.map +1 -1
  69. package/dist/core/events/v3/authority-outbox.js +29 -0
  70. package/dist/core/events/v3/generation-custody.d.ts +5 -0
  71. package/dist/core/events/v3/generation-custody.d.ts.map +1 -0
  72. package/dist/core/events/v3/generation-custody.js +50 -0
  73. package/dist/core/events/v3/producers/coordination-recorder.d.ts +1 -0
  74. package/dist/core/events/v3/producers/coordination-recorder.d.ts.map +1 -1
  75. package/dist/core/events/v3/producers/coordination-recorder.js +7 -0
  76. package/dist/core/events/v3/producers/recorder.d.ts.map +1 -1
  77. package/dist/core/events/v3/producers/recorder.js +77 -64
  78. package/dist/core/governor/planning.d.ts.map +1 -1
  79. package/dist/core/governor/planning.js +14 -1
  80. package/dist/core/governor/service-read.d.ts +10 -2
  81. package/dist/core/governor/service-read.d.ts.map +1 -1
  82. package/dist/core/governor/service-read.js +105 -22
  83. package/dist/core/governor/service.d.ts +20 -2
  84. package/dist/core/governor/service.d.ts.map +1 -1
  85. package/dist/core/governor/service.js +72 -47
  86. package/dist/core/hooks/cli.js +33 -5
  87. package/dist/core/inbox/contract.d.ts +2 -1
  88. package/dist/core/inbox/contract.d.ts.map +1 -1
  89. package/dist/core/inbox/index.d.ts +2 -0
  90. package/dist/core/inbox/index.d.ts.map +1 -1
  91. package/dist/core/inbox/index.js +2 -0
  92. package/dist/core/inbox/peer-messages.d.ts +37 -0
  93. package/dist/core/inbox/peer-messages.d.ts.map +1 -0
  94. package/dist/core/inbox/peer-messages.js +72 -0
  95. package/dist/core/inbox/service.d.ts +8 -1
  96. package/dist/core/inbox/service.d.ts.map +1 -1
  97. package/dist/core/inbox/service.js +67 -21
  98. package/dist/core/inbox/targets.d.ts +22 -0
  99. package/dist/core/inbox/targets.d.ts.map +1 -0
  100. package/dist/core/inbox/targets.js +108 -0
  101. package/dist/core/inbox/watcher.js +7 -3
  102. package/dist/core/journal/index.d.ts.map +1 -1
  103. package/dist/core/journal/index.js +17 -2
  104. package/dist/core/resources/contract.d.ts +3 -0
  105. package/dist/core/resources/contract.d.ts.map +1 -1
  106. package/dist/core/resources/service-status.d.ts +14 -1
  107. package/dist/core/resources/service-status.d.ts.map +1 -1
  108. package/dist/core/resources/service-status.js +23 -13
  109. package/dist/core/resources/service.d.ts +9 -1
  110. package/dist/core/resources/service.d.ts.map +1 -1
  111. package/dist/core/resources/service.js +47 -27
  112. package/dist/core/resources/status.d.ts +2 -5
  113. package/dist/core/resources/status.d.ts.map +1 -1
  114. package/dist/core/resources/status.js +36 -7
  115. package/dist/core/servers/index.d.ts +24 -13
  116. package/dist/core/servers/index.d.ts.map +1 -1
  117. package/dist/core/servers/index.js +132 -92
  118. package/dist/core/servers/tunnels.d.ts +3 -5
  119. package/dist/core/servers/tunnels.d.ts.map +1 -1
  120. package/dist/core/servers/tunnels.js +3 -9
  121. package/dist/core/supervisor/contract.d.ts +12 -0
  122. package/dist/core/supervisor/contract.d.ts.map +1 -1
  123. package/dist/core/supervisor/explanations.d.ts.map +1 -1
  124. package/dist/core/supervisor/explanations.js +2 -1
  125. package/dist/core/supervisor/findings.d.ts.map +1 -1
  126. package/dist/core/supervisor/findings.js +54 -9
  127. package/dist/core/supervisor/service.d.ts +9 -1
  128. package/dist/core/supervisor/service.d.ts.map +1 -1
  129. package/dist/core/supervisor/service.js +59 -29
  130. package/dist/core/supervisor/services.d.ts.map +1 -1
  131. package/dist/core/supervisor/services.js +22 -1
  132. package/dist/core/supervisor/status.d.ts +17 -2
  133. package/dist/core/supervisor/status.d.ts.map +1 -1
  134. package/dist/core/supervisor/status.js +70 -12
  135. package/dist/core/supervisor/timeline.d.ts.map +1 -1
  136. package/dist/core/supervisor/timeline.js +2 -1
  137. package/dist/core/work/state.js +7 -7
  138. package/dist/core/workflow/engine.d.ts.map +1 -1
  139. package/dist/core/workflow/engine.js +105 -32
  140. package/dist/core/workflow/failure-evidence.d.ts +16 -0
  141. package/dist/core/workflow/failure-evidence.d.ts.map +1 -0
  142. package/dist/core/workflow/failure-evidence.js +114 -0
  143. package/dist/core/workflow/index.d.ts +1 -1
  144. package/dist/core/workflow/index.d.ts.map +1 -1
  145. package/dist/core/workflow/index.js +1 -1
  146. package/dist/core/workflow/live-session-v3.d.ts +6 -0
  147. package/dist/core/workflow/live-session-v3.d.ts.map +1 -1
  148. package/dist/core/workflow/live-session-v3.js +126 -5
  149. package/dist/core/workflow/proof.d.ts +5 -5
  150. package/dist/core/workflow/proof.d.ts.map +1 -1
  151. package/dist/core/workflow/proof.js +115 -20
  152. package/dist/core/workflow/run-state.d.ts +3 -1
  153. package/dist/core/workflow/run-state.d.ts.map +1 -1
  154. package/dist/core/workflow/run-state.js +31 -27
  155. package/dist/core/workflow/spawn-claude.d.ts.map +1 -1
  156. package/dist/core/workflow/spawn-claude.js +19 -0
  157. package/dist/core/workflow/spawn-codex.d.ts.map +1 -1
  158. package/dist/core/workflow/spawn-codex.js +13 -0
  159. package/dist/core/workflow/spawn-cursor.d.ts.map +1 -1
  160. package/dist/core/workflow/spawn-cursor.js +19 -0
  161. package/dist/core/workflow/spawn-opencode.d.ts.map +1 -1
  162. package/dist/core/workflow/spawn-opencode.js +14 -0
  163. package/dist/core/workflow/types.d.ts +64 -17
  164. package/dist/core/workflow/types.d.ts.map +1 -1
  165. package/dist/core/workflow/workspaces/index.d.ts +0 -1
  166. package/dist/core/workflow/workspaces/index.d.ts.map +1 -1
  167. package/dist/core/workflow/workspaces/index.js +0 -1
  168. package/dist/core/workflow/workspaces/leases.d.ts +3 -1
  169. package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
  170. package/dist/core/workflow/workspaces/leases.js +30 -16
  171. package/dist/core/workflow/workspaces/local-git.d.ts +6 -2
  172. package/dist/core/workflow/workspaces/local-git.d.ts.map +1 -1
  173. package/dist/core/workflow/workspaces/local-git.js +270 -6
  174. package/dist/core/workflow/workspaces/ownership.d.ts +11 -0
  175. package/dist/core/workflow/workspaces/ownership.d.ts.map +1 -0
  176. package/dist/core/workflow/workspaces/ownership.js +194 -0
  177. package/dist/core/workflow/workspaces/reclaim.d.ts +35 -0
  178. package/dist/core/workflow/workspaces/reclaim.d.ts.map +1 -1
  179. package/dist/core/workflow/workspaces/reclaim.js +14 -0
  180. package/dist/core/workflow/workspaces/recovery.d.ts.map +1 -1
  181. package/dist/core/workflow/workspaces/recovery.js +21 -13
  182. package/dist/core/workflow/workspaces/state.d.ts +1 -0
  183. package/dist/core/workflow/workspaces/state.d.ts.map +1 -1
  184. package/dist/core/workflow/workspaces/state.js +21 -1
  185. package/dist/lib/browser/windows-chrome.d.ts +100 -12
  186. package/dist/lib/browser/windows-chrome.d.ts.map +1 -1
  187. package/dist/lib/browser/windows-chrome.js +262 -73
  188. package/dist/lib/docs-links.d.ts.map +1 -1
  189. package/dist/lib/docs-links.js +45 -2
  190. package/dist/lib/guarded-remove.d.ts +7 -0
  191. package/dist/lib/guarded-remove.d.ts.map +1 -1
  192. package/dist/lib/guarded-remove.js +106 -12
  193. package/dist/lib/identities/assume.d.ts.map +1 -1
  194. package/dist/lib/identities/assume.js +4 -0
  195. package/dist/lib/zip/index.d.ts +41 -0
  196. package/dist/lib/zip/index.d.ts.map +1 -0
  197. package/dist/lib/zip/index.js +398 -0
  198. package/package.json +7 -1
  199. package/src/commands/agents.ts +54 -63
  200. package/src/commands/browse.ts +50 -14
  201. package/src/commands/diagnostics.ts +10 -0
  202. package/src/commands/doctor.ts +26 -7
  203. package/src/commands/governor.ts +23 -10
  204. package/src/commands/inbox.ts +52 -2
  205. package/src/commands/rm.ts +43 -4
  206. package/src/commands/servers.ts +16 -4
  207. package/src/commands/supervisor.ts +7 -2
  208. package/src/commands/toc.ts +14 -6
  209. package/src/commands/workflow.ts +30 -30
  210. package/src/core/agents/live-authority-v3.ts +17 -0
  211. package/src/core/agents/live-lifecycle-v3.ts +52 -14
  212. package/src/core/agents/mailbox.ts +26 -17
  213. package/src/core/agents/render/prompt-context.ts +10 -12
  214. package/src/core/agents/render/session-context.ts +9 -32
  215. package/src/core/agents/rules/stop-hook.ts +3 -3
  216. package/src/core/agents/state/heartbeat-writer.ts +29 -12
  217. package/src/core/agents/state/live-coordination-writer.ts +29 -0
  218. package/src/core/agents/state/pidmap.ts +13 -0
  219. package/src/core/agents/state/proc-start.ts +57 -0
  220. package/src/core/agents/state/stale-sweep.ts +247 -82
  221. package/src/core/agents/state/unchanged-file.ts +456 -0
  222. package/src/core/context/index.ts +446 -136
  223. package/src/core/context/observation.ts +29 -0
  224. package/src/core/diagnostics/bundle.ts +23 -18
  225. package/src/core/diagnostics/path-identity.ts +15 -0
  226. package/src/core/diagnostics/sanitize.ts +4 -3
  227. package/src/core/events/v3/authority-outbox.ts +56 -0
  228. package/src/core/events/v3/generation-custody.ts +59 -0
  229. package/src/core/events/v3/producers/coordination-recorder.ts +15 -0
  230. package/src/core/events/v3/producers/recorder.ts +94 -68
  231. package/src/core/governor/planning.ts +20 -8
  232. package/src/core/governor/service-read.ts +128 -20
  233. package/src/core/governor/service.ts +119 -42
  234. package/src/core/hooks/cli.ts +33 -5
  235. package/src/core/inbox/contract.ts +2 -1
  236. package/src/core/inbox/index.ts +2 -0
  237. package/src/core/inbox/peer-messages.ts +94 -0
  238. package/src/core/inbox/service.ts +88 -22
  239. package/src/core/inbox/targets.ts +148 -0
  240. package/src/core/inbox/watcher.ts +8 -9
  241. package/src/core/journal/index.ts +19 -2
  242. package/src/core/resources/contract.ts +4 -0
  243. package/src/core/resources/service-status.ts +35 -12
  244. package/src/core/resources/service.ts +71 -24
  245. package/src/core/resources/status.ts +57 -8
  246. package/src/core/servers/index.ts +177 -91
  247. package/src/core/servers/tunnels.ts +3 -11
  248. package/src/core/supervisor/contract.ts +13 -0
  249. package/src/core/supervisor/explanations.ts +4 -1
  250. package/src/core/supervisor/findings.ts +68 -10
  251. package/src/core/supervisor/service.ts +88 -26
  252. package/src/core/supervisor/services.ts +26 -8
  253. package/src/core/supervisor/status.ts +89 -12
  254. package/src/core/supervisor/timeline.ts +2 -1
  255. package/src/core/work/state.ts +7 -7
  256. package/src/core/workflow/engine.ts +131 -49
  257. package/src/core/workflow/failure-evidence.ts +141 -0
  258. package/src/core/workflow/index.ts +0 -1
  259. package/src/core/workflow/live-session-v3.ts +146 -5
  260. package/src/core/workflow/proof.ts +134 -26
  261. package/src/core/workflow/run-state.ts +31 -29
  262. package/src/core/workflow/spawn-claude.ts +18 -0
  263. package/src/core/workflow/spawn-codex.ts +13 -0
  264. package/src/core/workflow/spawn-cursor.ts +18 -0
  265. package/src/core/workflow/spawn-opencode.ts +14 -0
  266. package/src/core/workflow/types.ts +51 -17
  267. package/src/core/workflow/workspaces/index.ts +0 -1
  268. package/src/core/workflow/workspaces/leases.ts +48 -17
  269. package/src/core/workflow/workspaces/local-git.ts +315 -5
  270. package/src/core/workflow/workspaces/ownership.ts +232 -0
  271. package/src/core/workflow/workspaces/reclaim.ts +58 -0
  272. package/src/core/workflow/workspaces/recovery.ts +25 -13
  273. package/src/core/workflow/workspaces/state.ts +20 -0
  274. package/src/lib/browser/windows-chrome.ts +346 -86
  275. package/src/lib/docs-links.ts +49 -2
  276. package/src/lib/guarded-remove.ts +132 -14
  277. package/src/lib/identities/assume.ts +4 -0
  278. package/src/lib/zip/index.ts +483 -0
@@ -1,7 +1,8 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
- import { isAbsolute, relative, resolve, sep } from "node:path";
2
+ import { existsSync, lstatSync, readFileSync, realpathSync } from "node:fs";
3
+ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
4
4
  import { resolveCoordRoot } from "../core/agents/coord-client.js";
5
+ import { artifactsRoot, parseArtifactManifest } from "../core/artifacts/index.js";
5
6
  import { readCoordinationViewV3, requireAuthoritySafeCoordinationViewV3, } from "../core/events/v3/coordination-view.js";
6
7
  import { liveInstanceIdV3 } from "../core/events/v3/live-route-observer.js";
7
8
  import { resolveOwner } from "../core/hooks/resolve/owner.js";
@@ -12,6 +13,8 @@ export function registerRmCommand(program, emit, context) {
12
13
  .description("Preview guarded removal of untracked files; --yes applies permanent deletion")
13
14
  .requiredOption("--root <directory>", "Allowed directory; each target must be strictly inside it")
14
15
  .option("-r, --recursive", "Permit directory removal after inspecting its complete contents")
16
+ .option("--clean-clone", "Remove only clean standalone clones inside one owned artifact; refuse local-only commits and worktrees")
17
+ .option("--entry-limit <n>", "Maximum inspected entries, 1-100000 (default 10000); larger limits require one current caller-owned managed artifact as --root", (value) => Number(value))
15
18
  .option("--allow-protected <path>", "Remove this one protected path (Git metadata, credentials, Harnery state, keys) inside a target; repeat per path", (value, previous = []) => [...previous, value])
16
19
  .option("--yes", "Permanently remove validated targets")
17
20
  .option("--dry-run", "Preview only, even with --yes")
@@ -43,7 +46,26 @@ export function registerRmCommand(program, emit, context) {
43
46
  // The workspace this command coordinates, and the checkout it runs in:
44
47
  // their own .git and .harnery can never be allowed.
45
48
  const liveRoots = [coordRoot, gitTopLevel(process.cwd())].filter((dir) => Boolean(dir));
46
- const report = guardedRemove(paths, { ...options, liveRoots }, checkClaims);
49
+ const assertOwnedArtifact = (root) => {
50
+ if (!coordRoot || dirname(root) !== realpathSync(artifactsRoot(coordRoot)))
51
+ throw new Error("Copied state requires --root to name one owned managed artifact");
52
+ const view = requireAuthoritySafeCoordinationViewV3(readCoordinationViewV3(coordRoot));
53
+ const owner = resolveOwner({ payload: null, coordRoot });
54
+ const ownId = owner ? liveInstanceIdV3(owner.instance_id) : undefined;
55
+ if (!ownId || !view.instances[ownId]?.authority_eligible)
56
+ throw new Error("Copied state requires an authenticated current artifact owner");
57
+ const record = resolve(root, ".harnery-artifact.json");
58
+ const stat = lstatSync(record);
59
+ if (!stat.isFile() || stat.isSymbolicLink())
60
+ throw new Error("An owned artifact requires a regular manifest file");
61
+ const parsed = parseArtifactManifest(JSON.parse(readFileSync(record, "utf8")));
62
+ if (!parsed.ok ||
63
+ parsed.manifest.released_at ||
64
+ !parsed.manifest.created_by?.instance_id ||
65
+ liveInstanceIdV3(parsed.manifest.created_by.instance_id) !== ownId)
66
+ throw new Error("Copied state requires a valid unreleased artifact owned by the caller");
67
+ };
68
+ const report = guardedRemove(paths, { ...options, liveRoots, assertOwnedArtifact }, checkClaims);
47
69
  if (options.json) {
48
70
  emit.config({ format: "json" });
49
71
  emit.data(report);
@@ -54,7 +76,9 @@ export function registerRmCommand(program, emit, context) {
54
76
  ...report.targets,
55
77
  ];
56
78
  if (report.protected.length)
57
- lines.push("Protected paths named with --allow-protected:", ...report.protected.map((path) => ` ${path}`));
79
+ lines.push(options.cleanClone
80
+ ? "Verified clone metadata:"
81
+ : "Protected paths named with --allow-protected:", ...report.protected.map((path) => ` ${path}`));
58
82
  if (report.links.length)
59
83
  lines.push("Links removed as links (their targets are untouched):", ...report.links.map((link) => ` ${link.path} -> ${link.target}`));
60
84
  if (!report.applied)
@@ -1 +1 @@
1
- {"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../../src/commands/servers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG1E,OAAO,EAWL,KAAK,aAAa,EAMnB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,IAAI,CA0YN;AA8BD,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAmDvE"}
1
+ {"version":3,"file":"servers.d.ts","sourceRoot":"","sources":["../../src/commands/servers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAG1E,OAAO,EAWL,KAAK,aAAa,EAMnB,MAAM,0BAA0B,CAAC;AAElC,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,IAAI,CAsZN;AA8BD,4DAA4D;AAC5D,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAmDvE"}
@@ -81,6 +81,7 @@ export function registerServersCommand(program, emit, context) {
81
81
  type: "unregistered",
82
82
  label: stray.command,
83
83
  pid: stray.pid,
84
+ ...(stray.start_token ? { start_token: stray.start_token } : {}),
84
85
  host: hostname(),
85
86
  started_at: new Date().toISOString(),
86
87
  registered_at: new Date().toISOString(),
@@ -141,7 +142,19 @@ export function registerServersCommand(program, emit, context) {
141
142
  emit.data({ applied: Boolean(options.yes), pruned: report.pruned, decisions, results });
142
143
  }
143
144
  else {
144
- const lines = decisions.map((d) => `${d.action === "stop" ? (options.yes ? "stopped" : "would stop") : "keep"} ${d.id} ${d.reason}`);
145
+ const lines = decisions.map((decision) => {
146
+ const result = results.find((item) => item.id === decision.id);
147
+ const action = decision.action === "keep"
148
+ ? "keep"
149
+ : !options.yes
150
+ ? "would stop"
151
+ : result?.stopped
152
+ ? "stopped"
153
+ : result?.method === "not-running"
154
+ ? "already stopped"
155
+ : "could not stop";
156
+ return `${action} ${decision.id} ${result?.detail ?? decision.reason}`;
157
+ });
145
158
  if (report.pruned.length)
146
159
  lines.push(`Removed records of exited servers: ${report.pruned.join(", ")}`);
147
160
  if (!decisions.length)
@@ -150,6 +163,8 @@ export function registerServersCommand(program, emit, context) {
150
163
  lines.push("Preview only. Re-run with --yes to stop.");
151
164
  emit.text(lines.join("\n"));
152
165
  }
166
+ if (results.some((result) => result.method === "refused"))
167
+ emit.setExitCode(1);
153
168
  }
154
169
  catch (error) {
155
170
  fail(error);
@@ -1 +1 @@
1
- {"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/commands/supervisor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAe1E,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,IAAI,CAwGN"}
1
+ {"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/commands/supervisor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAe1E,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,OAAO,EAChB,IAAI,EAAE,WAAW,EACjB,OAAO,CAAC,EAAE,qBAAqB,GAC9B,IAAI,CA6GN"}
@@ -53,11 +53,16 @@ export function registerSupervisorCommand(program, emit, context) {
53
53
  .action(async (options) => {
54
54
  try {
55
55
  const root = resolve(options.root ?? coordRoot(context));
56
- let status = requestSupervisorStop(root);
56
+ const requested = requestSupervisorStop(root);
57
+ let status = requested;
57
58
  const deadline = Date.now() + 5_000;
58
59
  while (status.running && Date.now() < deadline) {
59
60
  await new Promise((done) => setTimeout(done, 50));
60
- status = readSupervisorStatus(root);
61
+ status = {
62
+ ...readSupervisorStatus(root),
63
+ signal_sent: requested.signal_sent,
64
+ signal_verdict: requested.signal_verdict,
65
+ };
61
66
  }
62
67
  emit.data(status);
63
68
  }
@@ -1,5 +1,19 @@
1
1
  import type { Command } from "commander";
2
2
  import type { EmitContext } from "../commander.js";
3
+ interface SectionOpts {
4
+ json?: boolean;
5
+ caseSensitive?: boolean;
6
+ }
7
+ interface SectionResult {
8
+ file: string;
9
+ matched_header: string;
10
+ matched_level: number;
11
+ line_start: number;
12
+ line_end: number;
13
+ content: string;
14
+ }
3
15
  export declare function registerTocCommand(program: Command, emit: EmitContext): void;
4
16
  export declare function registerSectionCommand(program: Command, emit: EmitContext): void;
17
+ export declare function runSection(file: string, query: string, opts: SectionOpts): Promise<SectionResult>;
18
+ export {};
5
19
  //# sourceMappingURL=toc.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/commands/toc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA4CnD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqB5E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CA0BhF"}
1
+ {"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/commands/toc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAiBnD,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAeD,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqB5E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CA0BhF;AA8ED,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,aAAa,CAAC,CA+CxB"}
@@ -116,15 +116,18 @@ function renderToc(r) {
116
116
  }
117
117
  return lines.join("\n");
118
118
  }
119
- async function runSection(file, query, opts) {
119
+ export async function runSection(file, query, opts) {
120
120
  if (!query.trim())
121
121
  throw new Error("header query required");
122
122
  const tocResult = await runToc(file, {});
123
123
  const absPath = resolve(file);
124
124
  const lines = readFileSync(absPath, "utf8").split("\n");
125
- const matches = tocResult.headers.filter((h) => opts.caseSensitive
126
- ? h.text.includes(query)
127
- : h.text.toLowerCase().includes(query.toLowerCase()));
125
+ const same = (a, b) => opts.caseSensitive ? a === b : a.toLowerCase() === b.toLowerCase();
126
+ const contains = (a, b) => opts.caseSensitive ? a.includes(b) : a.toLowerCase().includes(b.toLowerCase());
127
+ // A header that equals the query wins over headers that merely contain it,
128
+ // so "Media" can still select "## Media" beside "## Media recipes".
129
+ const exact = tocResult.headers.filter((h) => same(h.text, query.trim()));
130
+ const matches = exact.length > 0 ? exact : tocResult.headers.filter((h) => contains(h.text, query));
128
131
  if (matches.length === 0) {
129
132
  throw new Error(`no header matching "${query}". Run \`${resolveBinName()} toc ${file}\` to list available headers.`);
130
133
  }
@@ -472,10 +472,10 @@ export function registerWorkflowCommand(program, emit) {
472
472
  });
473
473
  workflow
474
474
  .command("reclaim <run-id>")
475
- .description("Resolve a workspace preserved because it was dirty: salvage the work to its branch, then release.")
475
+ .description("Preview reclaim of an inactive owned workspace, or confirm salvage or discard and release.")
476
476
  .option("--yes", "Confirm that this commits or discards uncommitted work, then releases")
477
477
  .option("--discard", "Throw the uncommitted work away instead of salvaging it")
478
- .option("--json", "Emit the reclaim preparation and cleanup result as JSON")
478
+ .option("--json", "Emit the reclaim preview or confirmed result as JSON")
479
479
  .action(async (runId, opts) => {
480
480
  const coordRoot = resolveCoordRoot();
481
481
  if (!coordRoot) {
@@ -485,50 +485,44 @@ export function registerWorkflowCommand(program, emit) {
485
485
  });
486
486
  process.exit(1);
487
487
  }
488
- if (!opts.yes) {
489
- emit.error({
490
- code: "reclaim_confirmation_required",
491
- message: opts.discard
492
- ? "reclaim --discard permanently destroys uncommitted work; pass --yes to confirm"
493
- : "workspace reclaim commits uncommitted work to its branch and then releases the worktree; pass --yes to confirm",
494
- });
495
- process.exit(1);
496
- }
497
488
  try {
498
- const { inspectWorkflowWorkspace, prepareReclaim, cleanupWorkspace } = await import("../core/workflow/index.js");
499
- const inspection = inspectWorkflowWorkspace(coordRoot, runId);
500
- if (!inspection.ok) {
501
- emit.error({ code: "workflow_reclaim_failed", message: inspection.error });
502
- process.exit(1);
503
- }
504
- const allocation = inspection.value.allocation;
505
- if (!allocation) {
489
+ const { createLocalGitWorktreeProvider, readWorkflowRunManifest } = await import("../core/workflow/index.js");
490
+ const binding = readWorkflowRunManifest(coordRoot, runId).execution.workspace_binding;
491
+ if (binding?.provider.id !== "local-git-worktree") {
506
492
  emit.error({
507
493
  code: "workflow_reclaim_unavailable",
508
494
  message: `run ${runId} has no provider-owned Git workspace to reclaim`,
509
495
  });
510
496
  process.exit(1);
511
497
  }
512
- const preparation = prepareReclaim({
513
- worktreePath: allocation.active_root,
498
+ const provider = createLocalGitWorktreeProvider({ coordRoot });
499
+ const result = await provider.reclaim(binding, {
514
500
  mode: opts.discard ? "discard" : "salvage",
515
- runId,
501
+ yes: opts.yes,
516
502
  });
517
- // Cleanup still owns removal. Reclaim only changes whether the tree it
518
- // finds is dirty, so there is one audited release path, not two.
519
- const provider = await builtInProviderForRun(coordRoot, runId);
520
- const cleanup = await cleanupWorkspace({ coordRoot, runId, provider });
521
503
  if (opts.json) {
522
504
  emit.config({ format: "json" });
523
- emit.data({ preparation, cleanup });
505
+ emit.data(result);
506
+ return;
507
+ }
508
+ if (result.action === "preview") {
509
+ const holders = result.lease_holder.map((holder) => `${holder.scope}: ${holder.owner_id ?? "unknown"}${holder.pid ? ` (pid ${holder.pid})` : ""}${holder.detail ? `; ${holder.detail}` : ""}`);
510
+ emit.text(`reclaim preview: ${result.run_id}\n` +
511
+ `mode: ${result.mode}\nliveness: ${result.liveness}\nownership: ${result.ownership}\n` +
512
+ `lease holder: ${holders.length > 0 ? holders.join(", ") : "none observed"}\n` +
513
+ `dirty paths: ${result.dirty_paths === null ? "unknown" : result.dirty_paths.length > 0 ? result.dirty_paths.join(", ") : "none"}\n` +
514
+ (result.ownership_detail ? `ownership detail: ${result.ownership_detail}\n` : "") +
515
+ `Pass --yes to confirm ${result.mode} and release after all checks pass.\n`);
524
516
  return;
525
517
  }
526
- emit.text(`reclaim ${preparation.action}: ${preparation.detail}\n` +
527
- `workspace cleanup ${cleanup.status}: ${cleanup.binding_id}\n`);
518
+ emit.text(`reclaim ${result.preparation.action}: ${result.preparation.detail}\n` +
519
+ `workspace cleanup ${result.cleanup.status}: ${result.cleanup.binding_id}\n`);
528
520
  }
529
521
  catch (error) {
530
522
  emit.error({
531
- code: "workflow_reclaim_failed",
523
+ code: error instanceof Error && "code" in error && typeof error.code === "string"
524
+ ? error.code
525
+ : "workflow_reclaim_failed",
532
526
  message: error instanceof Error ? error.message : String(error),
533
527
  });
534
528
  process.exit(1);
@@ -38,6 +38,7 @@ interface LiveAuthorityBaseV3 {
38
38
  nativeSessionId: string;
39
39
  adapter: Adapter;
40
40
  observationId?: string;
41
+ expectedGenerationId?: `gen_${string}`;
41
42
  }
42
43
  /**
43
44
  * Establish the missing generation authority for one adapter-native session,
@@ -1 +1 @@
1
- {"version":3,"file":"live-authority-v3.d.ts","sourceRoot":"","sources":["../../../src/core/agents/live-authority-v3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,EAAE,KAAK,gBAAgB,EAA2B,MAAM,yBAAyB,CAAC;AAgBzF,OAAO,EACL,KAAK,mCAAmC,EAEzC,MAAM,iDAAiD,CAAC;AASzD,OAAO,EAEL,KAAK,SAAS,EAMf,MAAM,6BAA6B,CAAC;AAQrC,eAAO,MAAM,gCAAgC,EAAG,iBAA0B,CAAC;AAE3E,qBAAa,gCAAiC,SAAQ,KAAK;aAC7B,MAAM,EAAE,MAAM;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AuB,CACrC,KAAK,EAAE,mBAAmB,GAAG;IAC3B,SAAS,EAAE,UAAU,GAAG,UAAU,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B,GACA,iCAAiC,CAwCnC;AAED,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,mBAAmB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAChE,iCAAiC,CAwBnC;AA8DD,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAI/E;AAsBD,wBAAgB,kCAAkC,CAAC,SAAS,EAAE,SAAS,GAAG,UAAU,MAAM,EAAE,CAa3F"}
@@ -419,6 +419,10 @@ function recordLiveAuthority(input, signal, observation, expected, desired, appl
419
419
  platform: livePlatformV3(),
420
420
  expected_prior_state_digest: coordinationAuthorityStateDigestV3(expected),
421
421
  desired_state_digest: coordinationAuthorityStateDigestV3(desired),
422
+ expected_generation_id: input.expectedGenerationId ??
423
+ (subject === input.owner
424
+ ? expected.v3_generation_id
425
+ : readLiveCoordinationRow(input.coordRoot, input.owner)?.v3_generation_id),
422
426
  reconciler: {
423
427
  readStateDigest: () => {
424
428
  const heartbeat = readHeartbeat(input.coordRoot, subject);
@@ -448,9 +452,16 @@ export function liveCoordinationWriteModeV3(coordRoot) {
448
452
  return route.mode;
449
453
  }
450
454
  function requireHeartbeat(input, owner) {
455
+ if (input.expectedGenerationId &&
456
+ readLiveCoordinationRow(input.coordRoot, owner)?.v3_generation_id !== input.expectedGenerationId) {
457
+ throw new LiveCoordinationAuthorityV3Error("expected_generation_changed");
458
+ }
451
459
  const heartbeat = ensureLiveCoordinationHeartbeat(input.coordRoot, owner, owner === input.owner ? input.nativeSessionId : owner, input.adapter);
452
460
  if (!heartbeat)
453
461
  throw new LiveCoordinationAuthorityV3Error(`heartbeat_missing:${owner}`);
462
+ if (input.expectedGenerationId && heartbeat.v3_generation_id !== input.expectedGenerationId) {
463
+ throw new LiveCoordinationAuthorityV3Error("expected_generation_changed");
464
+ }
454
465
  return heartbeat;
455
466
  }
456
467
  export function coordinationAuthorityStateDigestV3(heartbeat) {
@@ -11,10 +11,12 @@ interface LiveLifecycleObservationBaseV3 {
11
11
  adapter: EventAdapterIdV3;
12
12
  observedAt?: string;
13
13
  }
14
- export declare function recordLiveSweepObservationV3(input: LiveLifecycleObservationBaseV3 & {
14
+ interface LiveSweepObservationV3Input extends LiveLifecycleObservationBaseV3 {
15
+ expectedGenerationId: `gen_${string}` | null;
15
16
  observation: "stale_heartbeat" | "killed" | "unparseable_heartbeat" | "missing_timestamp";
16
17
  ageMs: number;
17
- }): LiveLifecycleObservationV3Result;
18
+ }
19
+ export declare function recordLiveSweepObservationV3(input: LiveSweepObservationV3Input): LiveLifecycleObservationV3Result;
18
20
  export declare function recordLiveResumeObservationV3(input: LiveLifecycleObservationBaseV3): LiveLifecycleObservationV3Result;
19
21
  export {};
20
22
  //# sourceMappingURL=live-lifecycle-v3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"live-lifecycle-v3.d.ts","sourceRoot":"","sources":["../../../src/core/agents/live-lifecycle-v3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAaxD,MAAM,MAAM,gCAAgC,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAErF,UAAU,8BAA8B;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,8BAA8B,GAAG;IACtC,WAAW,EAAE,iBAAiB,GAAG,QAAQ,GAAG,uBAAuB,GAAG,mBAAmB,CAAC;IAC1F,KAAK,EAAE,MAAM,CAAC;CACf,GACA,gCAAgC,CAOlC;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,8BAA8B,GACpC,gCAAgC,CAQlC"}
1
+ {"version":3,"file":"live-lifecycle-v3.d.ts","sourceRoot":"","sources":["../../../src/core/agents/live-lifecycle-v3.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAGnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAcxD,MAAM,MAAM,gCAAgC,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAErF,UAAU,8BAA8B;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,UAAU,2BAA4B,SAAQ,8BAA8B;IAC1E,oBAAoB,EAAE,OAAO,MAAM,EAAE,GAAG,IAAI,CAAC;IAC7C,WAAW,EAAE,iBAAiB,GAAG,QAAQ,GAAG,uBAAuB,GAAG,mBAAmB,CAAC;IAC1F,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,2BAA2B,GACjC,gCAAgC,CAqBlC;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,8BAA8B,GACpC,gCAAgC,CAalC"}
@@ -3,17 +3,27 @@ import { buildEventV3 } from "../events/v3/builder.js";
3
3
  import { normalizeNativeIdV3 } from "../events/v3/canonical.js";
4
4
  import { readEventV3ControlState } from "../events/v3/control.js";
5
5
  import { fingerprintContextV3 } from "../events/v3/fingerprint-keys.js";
6
+ import { withGenerationCustodyV3 } from "../events/v3/generation-custody.js";
6
7
  import { liveInstanceIdV3, livePlatformV3, resolveLiveEventLedgerRouteV3, } from "../events/v3/live-routing.js";
7
8
  import { readJoinableHookProducerStateV3 } from "../events/v3/producers/recorder.js";
8
9
  import { writeEventV3 } from "../events/v3/writer.js";
9
10
  import { LiveCoordinationAuthorityV3Error } from "./live-authority-v3.js";
10
11
  import { liveCoordinationAdapterV3 } from "./state/live-coordination-view.js";
11
12
  export function recordLiveSweepObservationV3(input) {
12
- return recordObservation(input, "lifecycle.sweep_observed", {
13
- subject_instance_id: liveInstanceIdV3(input.owner),
14
- observation: input.observation,
15
- provisional: true,
16
- age_ms: Math.max(0, Math.floor(input.ageMs)),
13
+ input = { ...input };
14
+ // Reject stale observations before preparing durable custody state. The
15
+ // in-custody checks cover replacement while acquiring custody and reentry.
16
+ requireSweepHookState(input);
17
+ return withGenerationCustodyV3(input.coordRoot, [liveInstanceIdV3(input.owner)], () => {
18
+ requireSweepHookState(input);
19
+ return recordObservation(input, "lifecycle.sweep_observed", {
20
+ subject_instance_id: liveInstanceIdV3(input.owner),
21
+ observation: input.observation,
22
+ provisional: true,
23
+ age_ms: Math.max(0, Math.floor(input.ageMs)),
24
+ }, () => {
25
+ requireSweepHookState(input);
26
+ });
17
27
  });
18
28
  }
19
29
  export function recordLiveResumeObservationV3(input) {
@@ -23,9 +33,9 @@ export function recordLiveResumeObservationV3(input) {
23
33
  prior_generation_id: hook.generation_id,
24
34
  continuity: "native",
25
35
  evidence_reference: "heartbeat_recreated",
26
- });
36
+ }, () => { });
27
37
  }
28
- function recordObservation(input, eventType, payload) {
38
+ function recordObservation(input, eventType, payload, beforeWrite) {
29
39
  const route = resolveLiveEventLedgerRouteV3(input.coordRoot);
30
40
  if (route.state === "blocked")
31
41
  throw new LiveCoordinationAuthorityV3Error(route.reason);
@@ -73,6 +83,7 @@ function recordObservation(input, eventType, payload) {
73
83
  monotonic_ns: process.hrtime.bigint().toString(),
74
84
  };
75
85
  const event = buildEventV3(eventType, { ...common, payload });
86
+ beforeWrite();
76
87
  const durability = writeEventV3(input.coordRoot, event, {
77
88
  expectedGenesisId: control.genesis.event.payload.genesis_id,
78
89
  });
@@ -81,6 +92,16 @@ function recordObservation(input, eventType, payload) {
81
92
  }
82
93
  return { state: "recorded", event };
83
94
  }
95
+ function requireSweepHookState(input) {
96
+ if (typeof input.expectedGenerationId !== "string" ||
97
+ !/^gen_[a-zA-Z0-9._-]+$/.test(input.expectedGenerationId)) {
98
+ throw new LiveCoordinationAuthorityV3Error("hook_generation_not_joinable");
99
+ }
100
+ const hook = requireHookState(withAttestedAdapter(input));
101
+ if (hook.generation_id !== input.expectedGenerationId) {
102
+ throw new LiveCoordinationAuthorityV3Error("expected_generation_changed");
103
+ }
104
+ }
84
105
  function withAttestedAdapter(input) {
85
106
  const adapter = liveCoordinationAdapterV3(input.coordRoot, input.owner);
86
107
  if (!adapter)
@@ -9,13 +9,14 @@
9
9
  * shown to them, because nothing surfaces another session's journal.
10
10
  *
11
11
  * This module addresses the durable persona name instead of the instance, so a
12
- * message can be queued before its recipient exists. Delivery happens on the
13
- * recipient's side: their next SessionStart or prompt drains the queue, shows
14
- * the messages, and records them in their journal.
12
+ * message can be queued before its recipient exists. The recipient's next
13
+ * SessionStart or prompt can drain the queue for injection. A drain does not
14
+ * confirm that the adapter emitted the context or that anyone read it.
15
15
  *
16
16
  * Storage: `.harnery/mailbox/<slug>.jsonl`, one JSON record per line, appended
17
- * by senders and removed by an atomic claim on the recipient's side. Delivered
18
- * records are appended to `.harnery/mailbox/delivered/<slug>.jsonl` for audit.
17
+ * by senders and removed by an atomic claim on the recipient's side. Drained
18
+ * records are appended to `.harnery/mailbox/delivered/<slug>.jsonl` for audit,
19
+ * with injection explicitly unconfirmed.
19
20
  *
20
21
  * Related but distinct: `core/inbox` is an instance-keyed transport with a
21
22
  * storage-framework service behind it. This mailbox is name-keyed, file-only,
@@ -81,10 +82,10 @@ export declare function peekMailbox(coordRoot: string, name: string): MailboxMes
81
82
  /**
82
83
  * Claim and return every pending message for a name.
83
84
  *
84
- * The claim is an atomic rename, so two sessions sharing a name cannot deliver
85
+ * The claim is an atomic rename, so two sessions sharing a name cannot claim
85
86
  * the same message twice: whichever rename wins owns the batch. Claimed records
86
- * are appended to the delivered archive before the claim file is removed, so a
87
- * crash between the two leaves an auditable copy rather than a silent loss.
87
+ * are archived before the claim file is removed. The archive records only the
88
+ * drain; output, recipient read, and turn completion remain unconfirmed.
88
89
  */
89
90
  export declare function drainMailbox(coordRoot: string, name: string): MailboxMessageV1[];
90
91
  /** Render a drained batch as the context block a recipient reads. */
@@ -1 +1 @@
1
- {"version":3,"file":"mailbox.d.ts","sourceRoot":"","sources":["../../../src/core/agents/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAqBH,eAAO,MAAM,sBAAsB,EAAG,4BAAqC,CAAC;AAE5E;mCACmC;AACnC,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,qEAAqE;AACrE,eAAO,MAAM,WAAW,KAAK,CAAC;AAI9B,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,sBAAsB,CAAC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb;qEACiE;IACjE,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAAG,eAAe,CAAC;AAEnE,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,WAAW,EAAE,qBAAqB;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM;gBAFb,WAAW,EAAE,qBAAqB,EACl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E,MAAM,GAAG,OAAO,CAU1E;AAED,gFAAgF;AAChF,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,EAAE,CAiBjF;AAiBD,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CA6BlE;AAED,0DAA0D;AAC1D,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CAa/E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,EAAE,CA2DhF;AA8CD,qEAAqE;AACrE,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,SAAS,gBAAgB,EAAE,GACpC,MAAM,CAcR"}
@@ -9,13 +9,14 @@
9
9
  * shown to them, because nothing surfaces another session's journal.
10
10
  *
11
11
  * This module addresses the durable persona name instead of the instance, so a
12
- * message can be queued before its recipient exists. Delivery happens on the
13
- * recipient's side: their next SessionStart or prompt drains the queue, shows
14
- * the messages, and records them in their journal.
12
+ * message can be queued before its recipient exists. The recipient's next
13
+ * SessionStart or prompt can drain the queue for injection. A drain does not
14
+ * confirm that the adapter emitted the context or that anyone read it.
15
15
  *
16
16
  * Storage: `.harnery/mailbox/<slug>.jsonl`, one JSON record per line, appended
17
- * by senders and removed by an atomic claim on the recipient's side. Delivered
18
- * records are appended to `.harnery/mailbox/delivered/<slug>.jsonl` for audit.
17
+ * by senders and removed by an atomic claim on the recipient's side. Drained
18
+ * records are appended to `.harnery/mailbox/delivered/<slug>.jsonl` for audit,
19
+ * with injection explicitly unconfirmed.
19
20
  *
20
21
  * Related but distinct: `core/inbox` is an instance-keyed transport with a
21
22
  * storage-framework service behind it. This mailbox is name-keyed, file-only,
@@ -34,8 +35,8 @@ export const MAILBOX_MESSAGE_SCHEMA = "harnery.mailbox-message/v1";
34
35
  export const MAX_BODY_BYTES = 4000;
35
36
  /** Pending messages held for one name before senders are refused. */
36
37
  export const MAX_PENDING = 25;
37
- /** Delivered-archive ceiling; the file is truncated from the head past this. */
38
- const MAX_DELIVERED_BYTES = 256 * 1024;
38
+ /** Drain-archive ceiling; the file is truncated from the head past this. */
39
+ const MAX_ARCHIVE_BYTES = 256 * 1024;
39
40
  export class MailboxCapacityError extends Error {
40
41
  reason_code;
41
42
  current;
@@ -68,7 +69,7 @@ export function mailboxDir(coordRoot) {
68
69
  export function mailboxPath(coordRoot, name) {
69
70
  return join(mailboxDir(coordRoot), `${slugFor(name)}.jsonl`);
70
71
  }
71
- function deliveredPath(coordRoot, name) {
72
+ function archivePath(coordRoot, name) {
72
73
  return join(mailboxDir(coordRoot), "delivered", `${slugFor(name)}.jsonl`);
73
74
  }
74
75
  function parseLines(content) {
@@ -196,10 +197,10 @@ export function peekMailbox(coordRoot, name) {
196
197
  /**
197
198
  * Claim and return every pending message for a name.
198
199
  *
199
- * The claim is an atomic rename, so two sessions sharing a name cannot deliver
200
+ * The claim is an atomic rename, so two sessions sharing a name cannot claim
200
201
  * the same message twice: whichever rename wins owns the batch. Claimed records
201
- * are appended to the delivered archive before the claim file is removed, so a
202
- * crash between the two leaves an auditable copy rather than a silent loss.
202
+ * are archived before the claim file is removed. The archive records only the
203
+ * drain; output, recipient read, and turn completion remain unconfirmed.
203
204
  */
204
205
  export function drainMailbox(coordRoot, name) {
205
206
  let path;
@@ -233,10 +234,16 @@ export function drainMailbox(coordRoot, name) {
233
234
  }
234
235
  if (messages.length > 0) {
235
236
  try {
236
- const archive = deliveredPath(coordRoot, name);
237
+ const archive = archivePath(coordRoot, name);
237
238
  mkdirSync(join(mailboxDir(coordRoot), "delivered"), { recursive: true });
238
- const deliveredAt = new Date().toISOString();
239
- appendFileSync(archive, `${messages.map((m) => JSON.stringify({ ...m, delivered_at: deliveredAt })).join("\n")}\n`, "utf8");
239
+ const drainedAt = new Date().toISOString();
240
+ appendFileSync(archive, `${messages
241
+ .map((m) => JSON.stringify({
242
+ ...m,
243
+ drained_at: drainedAt,
244
+ delivery_status: "injection-unconfirmed",
245
+ }))
246
+ .join("\n")}\n`, "utf8");
240
247
  trimArchive(archive);
241
248
  }
242
249
  catch {
@@ -291,7 +298,7 @@ function sweepStaleClaims(coordRoot) {
291
298
  }
292
299
  function trimArchive(path) {
293
300
  try {
294
- if (statSync(path).size <= MAX_DELIVERED_BYTES)
301
+ if (statSync(path).size <= MAX_ARCHIVE_BYTES)
295
302
  return;
296
303
  const lines = readFileSync(path, "utf8").split("\n").filter(Boolean);
297
304
  const keep = lines.slice(Math.floor(lines.length / 2));
@@ -307,8 +314,8 @@ export function formatMailboxDelivery(coordRoot, messages) {
307
314
  return "";
308
315
  const bin = resolveBinName(coordRoot);
309
316
  const header = messages.length === 1
310
- ? `Message from a peer agent (delivered now, recorded in your journal):`
311
- : `${messages.length} messages from peer agents (delivered now, recorded in your journal):`;
317
+ ? `Message from a peer agent (prepared for injection, recorded in your journal):`
318
+ : `${messages.length} messages from peer agents (prepared for injection, recorded in your journal):`;
312
319
  const body = messages
313
320
  .map((m) => {
314
321
  const when = m.created_at.replace("T", " ").replace(/\.\d+Z$/, "Z");
@@ -55,6 +55,8 @@ export interface PromptContextOpts {
55
55
  * being bounced into a retry. Not hash-deduped, same rationale as the
56
56
  * status footer. */
57
57
  turnRitualNudge?: string;
58
+ /** The emitter acknowledges exactly these IDs only after output succeeds. */
59
+ onInboxPrepared?: (messageIds: readonly string[]) => void;
58
60
  }
59
61
  /**
60
62
  * Build the combined UserPromptSubmit additionalContext string. Returns "" when
@@ -1 +1 @@
1
- {"version":3,"file":"prompt-context.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/render/prompt-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAiDH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;8EAC0E;IAC1E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;kFAC8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;kFAC8E;IAC9E,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;uEACmE;IACnE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;wBAIoB;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CAkFnE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA6CtF"}
1
+ {"version":3,"file":"prompt-context.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/render/prompt-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAiDH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;8EAC0E;IAC1E,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;kFAC8E;IAC9E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;kFAC8E;IAC9E,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;uEACmE;IACnE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;wBAIoB;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;CAC3D;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,iBAAiB,GAAG,MAAM,CA8EnE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA6CtF"}
@@ -37,14 +37,14 @@ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, w
37
37
  import { join } from "node:path";
38
38
  import { coordEnv } from "../../../lib/env.js";
39
39
  import { endOfTurnStatusCommand, hostPromptReminder, resolveBinName } from "../../config.js";
40
+ import { formatPeerInbox, peerInbox } from "../../inbox/peer-messages.js";
40
41
  import { readRemoteMachines } from "../../presence/index.js";
41
42
  import { readResourceStatus } from "../../resources/status.js";
42
- import { drainMailbox, formatMailboxDelivery } from "../mailbox.js";
43
43
  import { sessionNameDisplayBlock, sessionNameDisplayPending } from "../session-name-display.js";
44
44
  import { heartbeatPath } from "../state/heartbeat-reader.js";
45
45
  import { readLiveCoordinationRow, readLiveCoordinationRows, } from "../state/live-coordination-view.js";
46
46
  import { forkRelationLabels } from "../state/names.js";
47
- import { formatPendingCouncils, recordDeliveredMessages } from "./session-context.js";
47
+ import { formatPendingCouncils } from "./session-context.js";
48
48
  /**
49
49
  * Build the combined UserPromptSubmit additionalContext string. Returns "" when
50
50
  * nothing has changed since the last call (so the caller can skip the JSON emit).
@@ -60,16 +60,12 @@ export function renderPromptContext(opts) {
60
60
  // Every name-addressed section below (messages, councils) is silently
61
61
  // skipped without it.
62
62
  const resolvedName = agentName ?? readLiveCoordinationRow(coordRoot, instanceId)?.name;
63
- // 1. Peer messages. Drained first and never deduped: a message is delivered
64
- // exactly once, and it is the one section here that carries new information
65
- // from another agent rather than a reminder.
66
- //
67
- if (resolvedName) {
68
- const delivered = drainMailbox(coordRoot, resolvedName);
69
- if (delivered.length > 0) {
70
- recordDeliveredMessages(instanceId, delivered);
71
- sections.push(formatMailboxDelivery(coordRoot, delivered));
72
- }
63
+ // 1. Instance-bound messages. Rendering is read-only; failed output leaves
64
+ // this same batch pending rather than losing it before a prompt sees it.
65
+ const delivered = peerInbox(coordRoot).prepareSurface(instanceId);
66
+ if (delivered.length > 0) {
67
+ opts.onInboxPrepared?.(delivered.map(({ message_id }) => message_id));
68
+ sections.push(formatPeerInbox(coordRoot, delivered));
73
69
  }
74
70
  // 2. Peer table with hash dedup.
75
71
  const peerTable = computePeerTableIfChanged(coordRoot, instanceId, sessionId);