blun-king-cli 9.1.643 → 9.1.644

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 (266) hide show
  1. package/LIESMICH.txt +18 -0
  2. package/README.md +20 -6
  3. package/bin/blun.js +3 -3
  4. package/bin/king.js +3 -3
  5. package/bin/launcher-mode.js +125 -126
  6. package/bin/launcher-runtime.js +603 -616
  7. package/bin/plugin-bootstrap.js +339 -405
  8. package/bin/rename-private-staging.cjs +2 -2
  9. package/bin/retired-bundled-plugins.cjs +84 -0
  10. package/bin/startup-security-host.cjs +105 -0
  11. package/bin/startup-security.cjs +9 -105
  12. package/bin/startup-warning-policy.cjs +22 -0
  13. package/bin/update-lease-installer.cjs +125 -0
  14. package/bin/update-lease-sockets.cjs +228 -0
  15. package/bin/update-lease.js +22 -327
  16. package/bin/verify-bundled-agent-sources.cjs +2 -4
  17. package/blun.mjs +18 -179
  18. package/bundled-agent-sources.json +1 -552
  19. package/package.json +1 -5
  20. package/tool-liveness642/receipt.json +1 -1
  21. package/worker-host.mjs +3 -119
  22. package/agent-spine-plugin/.claude-plugin/marketplace.json +0 -20
  23. package/agent-spine-plugin/.claude-plugin/plugin.json +0 -14
  24. package/agent-spine-plugin/.codex-plugin/plugin.json +0 -47
  25. package/agent-spine-plugin/.mcp.json +0 -8
  26. package/agent-spine-plugin/CHANGELOG.md +0 -1614
  27. package/agent-spine-plugin/LICENSE +0 -186
  28. package/agent-spine-plugin/README.md +0 -432
  29. package/agent-spine-plugin/assets/agentspine-banner.svg +0 -32
  30. package/agent-spine-plugin/bin/agentspine-mcp.js +0 -4
  31. package/agent-spine-plugin/bin/agentspine.js +0 -7
  32. package/agent-spine-plugin/blun.plugin.json +0 -68
  33. package/agent-spine-plugin/docs/acceptance.md +0 -61
  34. package/agent-spine-plugin/docs/artifact-evaluation.md +0 -93
  35. package/agent-spine-plugin/docs/host-integration.md +0 -193
  36. package/agent-spine-plugin/docs/preflight-recall.md +0 -71
  37. package/agent-spine-plugin/docs/preservation-contract.md +0 -53
  38. package/agent-spine-plugin/docs/quality-gates.md +0 -50
  39. package/agent-spine-plugin/docs/session-timeline.md +0 -112
  40. package/agent-spine-plugin/docs/source-roots.md +0 -113
  41. package/agent-spine-plugin/docs/world-model.md +0 -119
  42. package/agent-spine-plugin/hooks/codex.json +0 -47
  43. package/agent-spine-plugin/hooks/hooks.json +0 -106
  44. package/agent-spine-plugin/hooks/version.json +0 -5
  45. package/agent-spine-plugin/package.json +0 -77
  46. package/agent-spine-plugin/scripts/check-codex-install.js +0 -226
  47. package/agent-spine-plugin/scripts/check-hosts.js +0 -208
  48. package/agent-spine-plugin/scripts/check-install-hook.js +0 -227
  49. package/agent-spine-plugin/scripts/check-install-selfstarter.js +0 -154
  50. package/agent-spine-plugin/scripts/check-install.js +0 -478
  51. package/agent-spine-plugin/scripts/check-line-budget.js +0 -58
  52. package/agent-spine-plugin/scripts/check-syntax.js +0 -29
  53. package/agent-spine-plugin/scripts/github-actions.js +0 -11
  54. package/agent-spine-plugin/scripts/hermetic-process.js +0 -191
  55. package/agent-spine-plugin/scripts/release-check.js +0 -150
  56. package/agent-spine-plugin/scripts/run-acceptance.js +0 -19
  57. package/agent-spine-plugin/scripts/run-checks.js +0 -50
  58. package/agent-spine-plugin/scripts/run-tests-hermetic.js +0 -112
  59. package/agent-spine-plugin/skills/agent-spine/SKILL.md +0 -99
  60. package/agent-spine-plugin/spine-example/1-identity.md +0 -12
  61. package/agent-spine-plugin/spine-example/2-voice.md +0 -6
  62. package/agent-spine-plugin/spine-example/3-conduct.md +0 -8
  63. package/agent-spine-plugin/spine-example/4-history.md +0 -4
  64. package/agent-spine-plugin/src/cli-agent.js +0 -315
  65. package/agent-spine-plugin/src/cli-attention.js +0 -95
  66. package/agent-spine-plugin/src/cli-autonomy.js +0 -36
  67. package/agent-spine-plugin/src/cli-common.js +0 -71
  68. package/agent-spine-plugin/src/cli-continuity.js +0 -116
  69. package/agent-spine-plugin/src/cli-core.js +0 -128
  70. package/agent-spine-plugin/src/cli-diagnostics.js +0 -291
  71. package/agent-spine-plugin/src/cli-host.js +0 -21
  72. package/agent-spine-plugin/src/cli-learning.js +0 -320
  73. package/agent-spine-plugin/src/cli-premortem.js +0 -16
  74. package/agent-spine-plugin/src/cli-sharing.js +0 -230
  75. package/agent-spine-plugin/src/cli.js +0 -181
  76. package/agent-spine-plugin/src/codex-reader-launcher.js +0 -182
  77. package/agent-spine-plugin/src/hook.js +0 -500
  78. package/agent-spine-plugin/src/index.js +0 -108
  79. package/agent-spine-plugin/src/lib/acceptance.js +0 -435
  80. package/agent-spine-plugin/src/lib/action-lesson-recall.js +0 -118
  81. package/agent-spine-plugin/src/lib/attention-context.js +0 -167
  82. package/agent-spine-plugin/src/lib/attention-events.js +0 -113
  83. package/agent-spine-plugin/src/lib/attention-privacy.js +0 -72
  84. package/agent-spine-plugin/src/lib/attention-schema.js +0 -164
  85. package/agent-spine-plugin/src/lib/attention-storage.js +0 -93
  86. package/agent-spine-plugin/src/lib/attention.js +0 -164
  87. package/agent-spine-plugin/src/lib/audit-premortem.js +0 -223
  88. package/agent-spine-plugin/src/lib/audit.js +0 -401
  89. package/agent-spine-plugin/src/lib/authentication.js +0 -515
  90. package/agent-spine-plugin/src/lib/autonomy-policy.js +0 -110
  91. package/agent-spine-plugin/src/lib/autonomy-store.js +0 -202
  92. package/agent-spine-plugin/src/lib/autonomy.js +0 -8
  93. package/agent-spine-plugin/src/lib/briefing.js +0 -493
  94. package/agent-spine-plugin/src/lib/catalog-document-read.js +0 -51
  95. package/agent-spine-plugin/src/lib/catalog.js +0 -167
  96. package/agent-spine-plugin/src/lib/channel-continuity.js +0 -19
  97. package/agent-spine-plugin/src/lib/channel-runtime.js +0 -665
  98. package/agent-spine-plugin/src/lib/codex-installation.js +0 -231
  99. package/agent-spine-plugin/src/lib/codex-skill-installation.js +0 -211
  100. package/agent-spine-plugin/src/lib/context.js +0 -156
  101. package/agent-spine-plugin/src/lib/continuity.js +0 -338
  102. package/agent-spine-plugin/src/lib/coordination.js +0 -577
  103. package/agent-spine-plugin/src/lib/delivery-agent-usage.js +0 -231
  104. package/agent-spine-plugin/src/lib/delivery-assignment.js +0 -220
  105. package/agent-spine-plugin/src/lib/delivery-command-actions.js +0 -462
  106. package/agent-spine-plugin/src/lib/delivery-knowledge.js +0 -78
  107. package/agent-spine-plugin/src/lib/delivery-premortem-binding.js +0 -107
  108. package/agent-spine-plugin/src/lib/delivery-premortem-closure.js +0 -171
  109. package/agent-spine-plugin/src/lib/delivery-premortem-codec.js +0 -45
  110. package/agent-spine-plugin/src/lib/delivery-premortem-correction.js +0 -101
  111. package/agent-spine-plugin/src/lib/delivery-premortem-file.js +0 -21
  112. package/agent-spine-plugin/src/lib/delivery-premortem-index.js +0 -493
  113. package/agent-spine-plugin/src/lib/delivery-premortem-inspection.js +0 -37
  114. package/agent-spine-plugin/src/lib/delivery-premortem-recovery.js +0 -120
  115. package/agent-spine-plugin/src/lib/delivery-premortem-rejection.js +0 -65
  116. package/agent-spine-plugin/src/lib/delivery-premortem-results.js +0 -28
  117. package/agent-spine-plugin/src/lib/delivery-premortem-session-guard.js +0 -46
  118. package/agent-spine-plugin/src/lib/delivery-premortem-write-ledger.js +0 -285
  119. package/agent-spine-plugin/src/lib/delivery-premortem.js +0 -499
  120. package/agent-spine-plugin/src/lib/delivery-shell-heredoc.js +0 -115
  121. package/agent-spine-plugin/src/lib/delivery-shell-substitutions.js +0 -111
  122. package/agent-spine-plugin/src/lib/delivery-shell-wrapper.js +0 -64
  123. package/agent-spine-plugin/src/lib/delivery-target.js +0 -73
  124. package/agent-spine-plugin/src/lib/delivery-verification.js +0 -445
  125. package/agent-spine-plugin/src/lib/documents.js +0 -239
  126. package/agent-spine-plugin/src/lib/feed-transport.js +0 -499
  127. package/agent-spine-plugin/src/lib/filesystem-retry.js +0 -34
  128. package/agent-spine-plugin/src/lib/gateway-common.js +0 -68
  129. package/agent-spine-plugin/src/lib/gateway-control.js +0 -370
  130. package/agent-spine-plugin/src/lib/gateway-delivery.js +0 -103
  131. package/agent-spine-plugin/src/lib/gateway-execution.js +0 -350
  132. package/agent-spine-plugin/src/lib/gateway-group-response.js +0 -128
  133. package/agent-spine-plugin/src/lib/gateway-host-fencing.js +0 -92
  134. package/agent-spine-plugin/src/lib/gateway-host-lifecycle.js +0 -193
  135. package/agent-spine-plugin/src/lib/gateway-inspection.js +0 -85
  136. package/agent-spine-plugin/src/lib/gateway-knowledge.js +0 -129
  137. package/agent-spine-plugin/src/lib/gateway-policy-provenance.js +0 -197
  138. package/agent-spine-plugin/src/lib/gateway-premortem-disposition.js +0 -82
  139. package/agent-spine-plugin/src/lib/gateway-premortem.js +0 -363
  140. package/agent-spine-plugin/src/lib/gateway-prepared-host.js +0 -28
  141. package/agent-spine-plugin/src/lib/gateway-runs.js +0 -345
  142. package/agent-spine-plugin/src/lib/gateway-runtime-identity.js +0 -31
  143. package/agent-spine-plugin/src/lib/gateway-runtime-records.js +0 -21
  144. package/agent-spine-plugin/src/lib/gateway-runtime.js +0 -18
  145. package/agent-spine-plugin/src/lib/gateway-state-transaction.js +0 -356
  146. package/agent-spine-plugin/src/lib/gateway-state.js +0 -344
  147. package/agent-spine-plugin/src/lib/graph.js +0 -337
  148. package/agent-spine-plugin/src/lib/hook-artifact-guards.js +0 -356
  149. package/agent-spine-plugin/src/lib/hook-audit.js +0 -43
  150. package/agent-spine-plugin/src/lib/hook-briefing-use.js +0 -78
  151. package/agent-spine-plugin/src/lib/hook-context.js +0 -441
  152. package/agent-spine-plugin/src/lib/hook-final-message.js +0 -26
  153. package/agent-spine-plugin/src/lib/hook-input.js +0 -27
  154. package/agent-spine-plugin/src/lib/hook-output.js +0 -284
  155. package/agent-spine-plugin/src/lib/hook-premortem.js +0 -257
  156. package/agent-spine-plugin/src/lib/hook-process-advisory.js +0 -36
  157. package/agent-spine-plugin/src/lib/hook-protection.js +0 -95
  158. package/agent-spine-plugin/src/lib/hook-stop-verification.js +0 -84
  159. package/agent-spine-plugin/src/lib/hook-timeline.js +0 -102
  160. package/agent-spine-plugin/src/lib/host-instruction-budget.js +0 -11
  161. package/agent-spine-plugin/src/lib/https-transport.js +0 -392
  162. package/agent-spine-plugin/src/lib/identifier-analysis.js +0 -446
  163. package/agent-spine-plugin/src/lib/indexed-memory-offline.js +0 -40
  164. package/agent-spine-plugin/src/lib/indexed-memory.js +0 -298
  165. package/agent-spine-plugin/src/lib/knowledge-evidence.js +0 -431
  166. package/agent-spine-plugin/src/lib/learning-applications.js +0 -441
  167. package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +0 -114
  168. package/agent-spine-plugin/src/lib/learning-candidates.js +0 -274
  169. package/agent-spine-plugin/src/lib/learning-context.js +0 -137
  170. package/agent-spine-plugin/src/lib/learning-delivery-contracts.js +0 -310
  171. package/agent-spine-plugin/src/lib/learning-evaluation-contracts.js +0 -350
  172. package/agent-spine-plugin/src/lib/learning-evaluation-registration.js +0 -372
  173. package/agent-spine-plugin/src/lib/learning-evaluation-revocation.js +0 -292
  174. package/agent-spine-plugin/src/lib/learning-evidence-contracts.js +0 -321
  175. package/agent-spine-plugin/src/lib/learning-findings.js +0 -458
  176. package/agent-spine-plugin/src/lib/learning-measurement-contracts.js +0 -285
  177. package/agent-spine-plugin/src/lib/learning-measurements.js +0 -265
  178. package/agent-spine-plugin/src/lib/learning-outcome-contracts.js +0 -165
  179. package/agent-spine-plugin/src/lib/learning-outcomes.js +0 -343
  180. package/agent-spine-plugin/src/lib/learning-reconciliation.js +0 -290
  181. package/agent-spine-plugin/src/lib/learning-retry-contracts.js +0 -188
  182. package/agent-spine-plugin/src/lib/learning-schema.js +0 -229
  183. package/agent-spine-plugin/src/lib/learning-scope-targets.js +0 -424
  184. package/agent-spine-plugin/src/lib/learning-state-upgrade.js +0 -477
  185. package/agent-spine-plugin/src/lib/learning-status-configuration.js +0 -476
  186. package/agent-spine-plugin/src/lib/learning-storage.js +0 -203
  187. package/agent-spine-plugin/src/lib/learning-trial-recovery.js +0 -218
  188. package/agent-spine-plugin/src/lib/learning-validation-contracts.js +0 -375
  189. package/agent-spine-plugin/src/lib/learning-validation-renewal.js +0 -298
  190. package/agent-spine-plugin/src/lib/learning-validation-runtime.js +0 -234
  191. package/agent-spine-plugin/src/lib/learning.js +0 -36
  192. package/agent-spine-plugin/src/lib/lesson-recall-session.js +0 -172
  193. package/agent-spine-plugin/src/lib/mcp-autonomy-tools.js +0 -37
  194. package/agent-spine-plugin/src/lib/mcp-delivery-completion.js +0 -124
  195. package/agent-spine-plugin/src/lib/mcp-delivery-tools.js +0 -45
  196. package/agent-spine-plugin/src/lib/mcp-premortem.js +0 -68
  197. package/agent-spine-plugin/src/lib/mcp-runtime.js +0 -355
  198. package/agent-spine-plugin/src/lib/mcp-source-context.js +0 -61
  199. package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +0 -240
  200. package/agent-spine-plugin/src/lib/mcp-world-tools.js +0 -52
  201. package/agent-spine-plugin/src/lib/object-transport.js +0 -206
  202. package/agent-spine-plugin/src/lib/owned-file-lock.js +0 -182
  203. package/agent-spine-plugin/src/lib/paths.js +0 -109
  204. package/agent-spine-plugin/src/lib/peer-transport.js +0 -283
  205. package/agent-spine-plugin/src/lib/persona-runtime.js +0 -581
  206. package/agent-spine-plugin/src/lib/pre-answer-timeline-recall.js +0 -104
  207. package/agent-spine-plugin/src/lib/preflight-delivery-id.js +0 -27
  208. package/agent-spine-plugin/src/lib/preflight.js +0 -688
  209. package/agent-spine-plugin/src/lib/project-portfolio.js +0 -176
  210. package/agent-spine-plugin/src/lib/runtime.js +0 -13
  211. package/agent-spine-plugin/src/lib/selfstarter-core.js +0 -382
  212. package/agent-spine-plugin/src/lib/selfstarter-jobs.js +0 -149
  213. package/agent-spine-plugin/src/lib/selfstarter-lease.js +0 -204
  214. package/agent-spine-plugin/src/lib/selfstarter-policy.js +0 -90
  215. package/agent-spine-plugin/src/lib/selfstarter-workspace.js +0 -111
  216. package/agent-spine-plugin/src/lib/selfstarter.js +0 -11
  217. package/agent-spine-plugin/src/lib/session-timeline-auth.js +0 -316
  218. package/agent-spine-plugin/src/lib/session-timeline-codex.js +0 -69
  219. package/agent-spine-plugin/src/lib/session-timeline-contract.js +0 -56
  220. package/agent-spine-plugin/src/lib/session-timeline-enrollment-source.js +0 -38
  221. package/agent-spine-plugin/src/lib/session-timeline-enrollment-storage.js +0 -128
  222. package/agent-spine-plugin/src/lib/session-timeline-enrollment-transport.js +0 -15
  223. package/agent-spine-plugin/src/lib/session-timeline-enrollment.js +0 -478
  224. package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +0 -186
  225. package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +0 -73
  226. package/agent-spine-plugin/src/lib/session-timeline-host-receipt.js +0 -117
  227. package/agent-spine-plugin/src/lib/session-timeline-invocation.js +0 -201
  228. package/agent-spine-plugin/src/lib/session-timeline-king.js +0 -93
  229. package/agent-spine-plugin/src/lib/session-timeline-prior.js +0 -57
  230. package/agent-spine-plugin/src/lib/session-timeline-provider.js +0 -36
  231. package/agent-spine-plugin/src/lib/session-timeline-query.js +0 -56
  232. package/agent-spine-plugin/src/lib/session-timeline-results.js +0 -56
  233. package/agent-spine-plugin/src/lib/session-timeline-root.js +0 -11
  234. package/agent-spine-plugin/src/lib/session-timeline-search.js +0 -82
  235. package/agent-spine-plugin/src/lib/session-timeline-sid-acl.js +0 -213
  236. package/agent-spine-plugin/src/lib/session-timeline-source-open.js +0 -30
  237. package/agent-spine-plugin/src/lib/session-timeline-source.js +0 -80
  238. package/agent-spine-plugin/src/lib/session-timeline-state.js +0 -45
  239. package/agent-spine-plugin/src/lib/session-timeline-transport.js +0 -42
  240. package/agent-spine-plugin/src/lib/session-timeline-windows-acl.js +0 -145
  241. package/agent-spine-plugin/src/lib/session-timeline.js +0 -462
  242. package/agent-spine-plugin/src/lib/sharing.js +0 -969
  243. package/agent-spine-plugin/src/lib/source-roots.js +0 -475
  244. package/agent-spine-plugin/src/lib/source-tree-scan.js +0 -178
  245. package/agent-spine-plugin/src/lib/sqlite-transport.js +0 -501
  246. package/agent-spine-plugin/src/lib/task-knowledge-context.js +0 -99
  247. package/agent-spine-plugin/src/lib/telegram-adapter.js +0 -119
  248. package/agent-spine-plugin/src/lib/timeline-continuation-update.js +0 -100
  249. package/agent-spine-plugin/src/lib/timeline-tool-guard.js +0 -225
  250. package/agent-spine-plugin/src/lib/timeline-user-feedback.js +0 -216
  251. package/agent-spine-plugin/src/lib/timeline-world-capture.js +0 -233
  252. package/agent-spine-plugin/src/lib/voice-runtime.js +0 -39
  253. package/agent-spine-plugin/src/lib/world-knowledge.js +0 -306
  254. package/agent-spine-plugin/src/lib/world-model.js +0 -333
  255. package/agent-spine-plugin/src/mcp.js +0 -456
  256. package/agent-spine-plugin/src/version.js +0 -1
  257. package/agent-spine-plugin/src/worker.js +0 -257
  258. package/bin/agentspine-king-goal-inbox.mjs +0 -127
  259. package/bin/agentspine-king-goal-intake.mjs +0 -106
  260. package/bin/agentspine-king-host-runner.mjs +0 -109
  261. package/bin/agentspine-king-snapshot-policy.cjs +0 -80
  262. package/bin/agentspine-king-status-policy.mjs +0 -226
  263. package/bin/agentspine-king-worker-host.mjs +0 -160
  264. package/bin/managed-plugin-selection.cjs +0 -141
  265. package/bin/verify-agent-behavior.cjs +0 -122
  266. package/bin/verify-agent-components.cjs +0 -104
@@ -1,171 +0,0 @@
1
- import { createHash } from "node:crypto";
2
-
3
- const CLOSURE_SCHEMA = "agentspine.delivery-premortem-closure/v1";
4
- const ATTACHMENT_SCHEMA = "agentspine.goal-premortem-attachment/v1";
5
- const ARTIFACT_SCHEMA = "agentspine.delivery-premortem-artifact/v1";
6
- const AUTHORITY = "context-only";
7
- const DIGEST_RE = /^[a-f0-9]{64}$/;
8
- const CATEGORIES = ["baseline-environment", "contract-tests", "delivery-path"];
9
- const RESULT_LIMIT = 1024;
10
- const VALUE_LIMIT = 512;
11
- const FAILURE_RE = /^this delivery fails because \S/i;
12
- export const DELIVERY_PREMORTEM_SECRET_RE = /-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:sk|gh[opusr])_[A-Za-z0-9_-]{20,}\b|\bBearer\s+[A-Za-z0-9._~+/-]{20,}|\b(?:api[-_ ]?key|token|password|passwort|secret|geheimnis|credential)\s*[:=]\s*\S{8,}|\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/i;
13
-
14
- export function hasSecretShapedText(value) {
15
- return typeof value === "string" && DELIVERY_PREMORTEM_SECRET_RE.test(value);
16
- }
17
-
18
- function canonical(value) {
19
- if (value === null || typeof value !== "object") return JSON.stringify(value);
20
- if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
21
- return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}`;
22
- }
23
-
24
- function sha256(value) {
25
- return createHash("sha256").update(typeof value === "string" ? value : canonical(value)).digest("hex");
26
- }
27
-
28
- function sealed(value, key = "digest") {
29
- const material = { ...value };
30
- delete material[key];
31
- return { ...material, [key]: sha256(material) };
32
- }
33
-
34
- function validSeal(value, key = "digest") {
35
- if (!value || typeof value !== "object" || Array.isArray(value) || !DIGEST_RE.test(value[key] || "")) return false;
36
- const material = { ...value };
37
- delete material[key];
38
- return value[key] === sha256(material);
39
- }
40
-
41
- function bounded(value, name, limit = VALUE_LIMIT) {
42
- if (typeof value !== "string" || !value || value.length > limit || /[\0\r\n]/.test(value)) {
43
- throw new Error(`premortem ${name} is invalid`);
44
- }
45
- return value;
46
- }
47
-
48
- function normalizedItems(items) {
49
- if (!Array.isArray(items) || items.length !== CATEGORIES.length) {
50
- throw new Error("premortem requires exactly three items");
51
- }
52
- const output = items.map((item) => {
53
- if (!item || typeof item !== "object" || Array.isArray(item)) throw new Error("premortem item is invalid");
54
- const category = bounded(item.category, "category", 64);
55
- if (!CATEGORIES.includes(category)) throw new Error(`premortem category is invalid: ${category}`);
56
- const failure = bounded(item.failure, "failure");
57
- if (!FAILURE_RE.test(failure)) {
58
- throw new Error(`premortem ${category} failure must start with 'this delivery fails because '`);
59
- }
60
- const check = bounded(item.check, "check");
61
- if (!check.trim()) throw new Error(`premortem ${category} check is invalid`);
62
- if (hasSecretShapedText(failure) || hasSecretShapedText(check)) {
63
- const error = new Error(`premortem ${category} contains secret-shaped content`);
64
- error.code = "AGENTSPINE_PREMORTEM_SECRET";
65
- throw error;
66
- }
67
- return { category, failure, checkId: `check-${sha256({ category, failure, check }).slice(0, 20)}`, check };
68
- });
69
- if (new Set(output.map((item) => item.category)).size !== CATEGORIES.length) {
70
- throw new Error("premortem categories must appear exactly once");
71
- }
72
- return CATEGORIES.map((category) => output.find((item) => item.category === category));
73
- }
74
-
75
- export function createPremortemArtifact({ requirement, items, recordedAt }) {
76
- return sealed({ schema: ARTIFACT_SCHEMA, requirementId: requirement.requirementId,
77
- laneDigest: requirement.laneDigest, items: normalizedItems(items), recordedAt,
78
- authority: AUTHORITY });
79
- }
80
-
81
- export function validPremortemArtifact(value, state) {
82
- if (!value || value.schema !== ARTIFACT_SCHEMA || value.authority !== AUTHORITY
83
- || value.laneDigest !== state.laneDigest || value.requirementId !== state.requirement?.requirementId
84
- || typeof value.recordedAt !== "string" || !Number.isFinite(new Date(value.recordedAt).getTime())
85
- || !validSeal(value)) return false;
86
- try {
87
- return canonical(value.items) === canonical(normalizedItems(value.items.map(({ category, failure, check }) =>
88
- ({ category, failure, check }))));
89
- } catch {
90
- return false;
91
- }
92
- }
93
-
94
- function parsedClosure(message) {
95
- const text = typeof message === "string" ? message.replace(/\r\n/g, "\n").trimEnd() : "";
96
- const lines = text.split("\n").slice(-5);
97
- const artifact = lines[0]?.match(/^Premortem closure sha256 ([a-f0-9]{64})$/i);
98
- const write = lines[1]?.match(/^Premortem latest write sha256 ([a-f0-9]{64})$/i);
99
- const artifactDigests = artifact ? [artifact[1].toLowerCase()] : [];
100
- const writeDigests = write ? [write[1].toLowerCase()] : [];
101
- const checks = [];
102
- const expression = /^- (baseline-environment|contract-tests|delivery-path) ([^:\s]{1,80}): (PASS|FAIL|PENDING) — (.*)$/i;
103
- for (const line of lines.slice(2)) {
104
- const match = line.match(expression);
105
- if (match) checks.push({ category: match[1].toLowerCase(),
106
- checkId: match[2], status: match[3].toUpperCase(), result: match[4].trim() });
107
- }
108
- return { artifactDigests, writeDigests, checks };
109
- }
110
-
111
- export function reviewPremortemClosure(message, artifact, lastWriteDigest) {
112
- const parsed = parsedClosure(message);
113
- const missing = [];
114
- if (parsed.artifactDigests.length !== 1 || parsed.artifactDigests[0] !== artifact.digest) {
115
- missing.push("closure-digest");
116
- }
117
- if (parsed.writeDigests.length !== 1 || parsed.writeDigests[0] !== lastWriteDigest) {
118
- missing.push("latest-write-digest");
119
- }
120
- const checks = [];
121
- for (const item of artifact.items) {
122
- const found = parsed.checks.filter((check) => check.category === item.category);
123
- if (found.length !== 1 || found[0].checkId !== item.checkId || found[0].status !== "PASS"
124
- || !found[0].result || found[0].result.length > RESULT_LIMIT
125
- || /[\0\r\n]/.test(found[0].result) || hasSecretShapedText(found[0].result)) missing.push(item.category);
126
- else checks.push(found[0]);
127
- }
128
- return { missing: [...new Set(missing)], checks };
129
- }
130
-
131
- export function createPremortemClosure({ requirementId, artifactDigest, lastWriteDigest, checks, closedAt,
132
- testStateDigest = null }) {
133
- if (testStateDigest !== null && !DIGEST_RE.test(testStateDigest)) {
134
- throw new Error("completion test-state digest is invalid");
135
- }
136
- return sealed({ schema: CLOSURE_SCHEMA, requirementId, artifactDigest, lastWriteDigest,
137
- ...(testStateDigest ? { completionSource: "mcp", testStateDigest } : {}),
138
- checks, closedAt, authority: AUTHORITY });
139
- }
140
-
141
- export function validPremortemClosure(value, state) {
142
- if (value && (value.completionSource !== undefined || value.testStateDigest !== undefined)
143
- && (value.completionSource !== "mcp" || !DIGEST_RE.test(value.testStateDigest || ""))) return false;
144
- if (!value || !state.artifact || !state.lastWrite || value.schema !== CLOSURE_SCHEMA
145
- || value.authority !== AUTHORITY || value.requirementId !== state.requirement?.requirementId
146
- || value.artifactDigest !== state.artifact.digest || value.lastWriteDigest !== state.lastWrite.digest
147
- || typeof value.closedAt !== "string" || !Number.isFinite(new Date(value.closedAt).getTime())
148
- || !validSeal(value) || !Array.isArray(value.checks) || value.checks.length !== CATEGORIES.length) return false;
149
- return CATEGORIES.every((category) => {
150
- const expected = state.artifact.items.find((item) => item.category === category);
151
- const matches = value.checks.filter((item) => item.category === category);
152
- return matches.length === 1 && matches[0].checkId === expected?.checkId && matches[0].status === "PASS"
153
- && typeof matches[0].result === "string" && matches[0].result.trim().length > 0
154
- && matches[0].result.length <= RESULT_LIMIT && !/[\0\r\n]/.test(matches[0].result)
155
- && !hasSecretShapedText(matches[0].result);
156
- });
157
- }
158
-
159
- export function createPremortemAttachment(state) {
160
- return sealed({ schema: ATTACHMENT_SCHEMA, goalId: state.binding.goalId,
161
- goalStepId: state.binding.goalStepId, queueId: state.binding.queueId,
162
- planDefinitionsDigest: state.binding.planDefinitionsDigest, laneDigest: state.laneDigest,
163
- sessionDigest: sha256(state.binding.sessionId), host: state.binding.host,
164
- projectId: state.binding.projectId, entityId: state.binding.entityId,
165
- groupId: state.binding.groupId, taskId: state.binding.taskId,
166
- gatewayAttempt: state.binding.gatewayAttempt,
167
- premortemText: state.artifact.items.map((item) => `${item.failure} Check: ${item.check}`).join("\n"),
168
- premortemDigest: state.artifact.digest, lastWriteDigest: state.lastWrite.digest,
169
- checkResults: structuredClone(state.closure.checks), closureDigest: state.closure.digest,
170
- authority: AUTHORITY }, "attachmentDigest");
171
- }
@@ -1,45 +0,0 @@
1
- import { createHash } from "node:crypto";
2
-
3
- const DIGEST_RE = /^[a-f0-9]{64}$/;
4
-
5
- export function canonicalPremortem(value) {
6
- if (value === null || typeof value !== "object") return JSON.stringify(value);
7
- if (Array.isArray(value)) return `[${value.map(canonicalPremortem).join(",")}]`;
8
- return `{${Object.keys(value).sort().map((key) =>
9
- `${JSON.stringify(key)}:${canonicalPremortem(value[key])}`).join(",")}}`;
10
- }
11
-
12
- export function premortemSha256(value) {
13
- return createHash("sha256").update(typeof value === "string"
14
- ? value : canonicalPremortem(value)).digest("hex");
15
- }
16
-
17
- export function premortemTime(value) {
18
- const parsed = new Date(value ?? Date.now());
19
- if (!Number.isFinite(parsed.getTime())) throw new Error("premortem timestamp is invalid");
20
- return parsed.toISOString();
21
- }
22
-
23
- export function sealPremortem(value, digestKey = "digest") {
24
- const material = { ...value };
25
- delete material[digestKey];
26
- return { ...material, [digestKey]: premortemSha256(material) };
27
- }
28
-
29
- export function validPremortemSeal(value, key = "digest") {
30
- if (!value || typeof value !== "object" || Array.isArray(value)
31
- || !DIGEST_RE.test(value[key] || "")) return false;
32
- const material = { ...value };
33
- delete material[key];
34
- return value[key] === premortemSha256(material);
35
- }
36
-
37
- export function validPremortemTime(value) {
38
- return typeof value === "string" && Number.isFinite(new Date(value).getTime());
39
- }
40
-
41
- export function premortemMismatchError(message) {
42
- const error = new Error(message);
43
- error.code = "AGENTSPINE_PREMORTEM_MISMATCH";
44
- return error;
45
- }
@@ -1,101 +0,0 @@
1
- import { mkdir, readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { withOwnedFileLock } from "./owned-file-lock.js";
4
- import { beginDeliveryAssignment, assignmentPremortemBinding } from "./delivery-assignment.js";
5
- import { inspectPremortemState, preparePremortemRequirement } from "./delivery-premortem.js";
6
- import { writePremortemFile } from "./delivery-premortem-file.js";
7
- import { premortemBlock as block, premortemBoundary as boundary } from "./delivery-premortem-results.js";
8
- import { canonicalPath, projectStateDir } from "./paths.js";
9
- import { premortemSha256 as sha256, premortemTime as at,
10
- sealPremortem as seal, validPremortemSeal as validSeal,
11
- validPremortemTime as validTime } from "./delivery-premortem-codec.js";
12
-
13
- const SCHEMA = "agentspine.delivery-premortem-recovery/v1";
14
- const AUTHORITY = "context-only";
15
- const MAX_BYTES = 12 * 1024;
16
- const DIGEST_RE = /^[a-f0-9]{64}$/;
17
-
18
- function valid(value) {
19
- return value && value.schema === SCHEMA && value.authority === AUTHORITY
20
- && typeof value.predecessorRequirementId === "string"
21
- && typeof value.requirementId === "string"
22
- && DIGEST_RE.test(value.predecessorArtifactDigest || "")
23
- && DIGEST_RE.test(value.bindingDigest || "")
24
- && /^assignment:[a-f0-9]{64}$/.test(value.assignmentId || "")
25
- && validTime(value.recoveredAt) && validSeal(value);
26
- }
27
-
28
- async function read(path) {
29
- try {
30
- const text = await readFile(path, "utf8");
31
- if (Buffer.byteLength(text) > MAX_BYTES) throw new Error("premortem recovery exceeds 12 KiB");
32
- const value = JSON.parse(text);
33
- if (!valid(value)) throw new Error("premortem recovery failed integrity validation");
34
- return value;
35
- } catch (error) {
36
- if (error.code === "ENOENT") return null;
37
- if (error instanceof SyntaxError) throw new Error("premortem recovery is not valid JSON");
38
- throw error;
39
- }
40
- }
41
-
42
- async function storeRecovery(root, receipt) {
43
- const digest = sha256({ predecessorRequirementId: receipt.predecessorRequirementId,
44
- requirementId: receipt.requirementId });
45
- const directory = join(await projectStateDir(await canonicalPath(root)),
46
- "delivery-premortem-recoveries");
47
- await mkdir(directory, { recursive: true, mode: 0o700 });
48
- const path = join(directory, `${digest}.json`);
49
- return withOwnedFileLock(`${path}.lock`, async ({ assertOwned }) => {
50
- const existing = await read(path);
51
- if (existing) {
52
- if (existing.predecessorRequirementId !== receipt.predecessorRequirementId
53
- || existing.requirementId !== receipt.requirementId) {
54
- throw new Error("premortem recovery receipt conflicts with history");
55
- }
56
- return existing;
57
- }
58
- await writePremortemFile(path, receipt, assertOwned, MAX_BYTES);
59
- return receipt;
60
- });
61
- }
62
-
63
- export async function recoverDeliveryPremortem({ root, predecessorRequirementId,
64
- taskId = null, now = new Date() }) {
65
- try {
66
- const predecessor = await inspectPremortemState({ root,
67
- requirementId: predecessorRequirementId });
68
- if (predecessor.status === "degraded" || predecessor.blocked) return predecessor;
69
- if (predecessor.status === "absent" || !predecessor.requirement) {
70
- return block("stale", "The predecessor premortem requirement does not exist.",
71
- { predecessorRequirementId });
72
- }
73
- if (!predecessor.conflicted) {
74
- return block("not-needed",
75
- "The predecessor was not poisoned; reuse its first valid registration or start the next assignment.",
76
- { predecessorRequirementId });
77
- }
78
- const source = { ...predecessor.binding, taskId: taskId || predecessor.binding.taskId,
79
- assignmentId: null };
80
- const assignment = await beginDeliveryAssignment({ root, binding: source,
81
- eventId: `recovery:${predecessorRequirementId}`, now });
82
- if (assignment.blocked) return assignment;
83
- const binding = assignmentPremortemBinding(source, assignment);
84
- const prepared = await preparePremortemRequirement({ root, binding, now });
85
- if (prepared.blocked || prepared.status === "degraded") return prepared;
86
- const receipt = seal({ schema: SCHEMA,
87
- predecessorRequirementId,
88
- predecessorArtifactDigest: predecessor.artifactDigest,
89
- requirementId: prepared.requirementId,
90
- assignmentId: assignment.assignmentId,
91
- bindingDigest: sha256(binding),
92
- recoveredAt: at(now), authority: AUTHORITY });
93
- const stored = await storeRecovery(root, receipt);
94
- return { status: "recovered", blocked: false,
95
- predecessorRequirementId, requirementId: prepared.requirementId,
96
- assignmentId: assignment.assignmentId, recoveryReceipt: stored,
97
- instruction: "Run session_briefing, delivery_knowledge_query, and record_delivery_premortem for the new requirement. Recovery grants no authority." };
98
- } catch (error) {
99
- return boundary(error);
100
- }
101
- }
@@ -1,21 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { unlink, writeFile } from "node:fs/promises";
3
- import { replaceFileWithRetry } from "./filesystem-retry.js";
4
- import { premortemMismatchError as mismatchError } from "./delivery-premortem-codec.js";
5
-
6
- export async function writePremortemFile(path, value, assertOwned, maxBytes = Infinity) {
7
- const text = typeof value === "string" ? value : `${JSON.stringify(value, null, 2)}\n`;
8
- if (Buffer.byteLength(text) > maxBytes) throw mismatchError("delivery premortem state exceeds 64 KiB");
9
- const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
10
- try {
11
- await writeFile(temporary, text, { mode: 0o600 });
12
- await replaceFileWithRetry(temporary, path, { beforeAttempt: assertOwned });
13
- // A stale lock holder can lose ownership in the narrow interval around rename.
14
- // Do not report this replacement as a committed state transition in that case.
15
- await assertOwned();
16
- } finally {
17
- await unlink(temporary).catch((error) => {
18
- if (error.code !== "ENOENT") throw error;
19
- });
20
- }
21
- }