@warpgogol/forge 9.7.0 → 10.0.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 (327) hide show
  1. package/AGENTS.md +50 -27
  2. package/CHANGELOG.md +52 -0
  3. package/bin/cli.js +0 -0
  4. package/dist/os/adr/handlers/archive.d.ts.map +1 -1
  5. package/dist/os/adr/handlers/archive.js +3 -7
  6. package/dist/os/adr/handlers/archive.js.map +1 -1
  7. package/dist/os/adr/handlers/list-create.d.ts.map +1 -1
  8. package/dist/os/adr/handlers/list-create.js +8 -6
  9. package/dist/os/adr/handlers/list-create.js.map +1 -1
  10. package/dist/os/audit/handlers/archive.d.ts.map +1 -1
  11. package/dist/os/audit/handlers/archive.js +3 -7
  12. package/dist/os/audit/handlers/archive.js.map +1 -1
  13. package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
  14. package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
  15. package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
  16. package/dist/os/core/archive-regen.d.ts +1 -0
  17. package/dist/os/core/archive-regen.d.ts.map +1 -1
  18. package/dist/os/core/archive-regen.js +31 -6
  19. package/dist/os/core/archive-regen.js.map +1 -1
  20. package/dist/os/core/core.module.d.ts.map +1 -1
  21. package/dist/os/core/core.module.js +6 -69
  22. package/dist/os/core/core.module.js.map +1 -1
  23. package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
  24. package/dist/os/core/handlers/assets-helpers.js +2 -3
  25. package/dist/os/core/handlers/assets-helpers.js.map +1 -1
  26. package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
  27. package/dist/os/core/handlers/determinism-check.js +2 -3
  28. package/dist/os/core/handlers/determinism-check.js.map +1 -1
  29. package/dist/os/core/handlers/pinned-check.d.ts +13 -0
  30. package/dist/os/core/handlers/pinned-check.d.ts.map +1 -1
  31. package/dist/os/core/handlers/pinned-check.js +25 -0
  32. package/dist/os/core/handlers/pinned-check.js.map +1 -1
  33. package/dist/os/core/handlers/pinned-types.d.ts +7 -0
  34. package/dist/os/core/handlers/pinned-types.d.ts.map +1 -1
  35. package/dist/os/core/handlers/pinned-validate.d.ts.map +1 -1
  36. package/dist/os/core/handlers/pinned-validate.js +24 -1
  37. package/dist/os/core/handlers/pinned-validate.js.map +1 -1
  38. package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
  39. package/dist/os/core/handlers/release-prepare.js +2 -4
  40. package/dist/os/core/handlers/release-prepare.js.map +1 -1
  41. package/dist/os/flow/digest.d.ts +73 -1
  42. package/dist/os/flow/digest.d.ts.map +1 -1
  43. package/dist/os/flow/digest.js +344 -92
  44. package/dist/os/flow/digest.js.map +1 -1
  45. package/dist/os/flow/evidence-lock.d.ts +36 -0
  46. package/dist/os/flow/evidence-lock.d.ts.map +1 -0
  47. package/dist/os/flow/evidence-lock.js +156 -0
  48. package/dist/os/flow/evidence-lock.js.map +1 -0
  49. package/dist/os/flow/flow.module.d.ts.map +1 -1
  50. package/dist/os/flow/flow.module.js +36 -14
  51. package/dist/os/flow/flow.module.js.map +1 -1
  52. package/dist/os/flow/git.d.ts +50 -3
  53. package/dist/os/flow/git.d.ts.map +1 -1
  54. package/dist/os/flow/git.js +144 -12
  55. package/dist/os/flow/git.js.map +1 -1
  56. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  57. package/dist/os/flow/handlers/flow-digest.js +3 -5
  58. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  59. package/dist/os/flow/handlers/flow-peers.js +1 -1
  60. package/dist/os/flow/handlers/flow-peers.js.map +1 -1
  61. package/dist/os/flow/handlers/flow-push.d.ts +81 -0
  62. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
  63. package/dist/os/flow/handlers/flow-push.js +642 -138
  64. package/dist/os/flow/handlers/flow-push.js.map +1 -1
  65. package/dist/os/flow/locks.d.ts +8 -0
  66. package/dist/os/flow/locks.d.ts.map +1 -1
  67. package/dist/os/flow/locks.js +6 -3
  68. package/dist/os/flow/locks.js.map +1 -1
  69. package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
  70. package/dist/os/flow/open-missions.d.ts.map +1 -0
  71. package/dist/os/flow/open-missions.js +37 -0
  72. package/dist/os/flow/open-missions.js.map +1 -0
  73. package/dist/os/flow/preflight.d.ts.map +1 -1
  74. package/dist/os/flow/preflight.js +5 -3
  75. package/dist/os/flow/preflight.js.map +1 -1
  76. package/dist/os/flow/registry.d.ts +9 -5
  77. package/dist/os/flow/registry.d.ts.map +1 -1
  78. package/dist/os/flow/registry.js +2 -2
  79. package/dist/os/flow/registry.js.map +1 -1
  80. package/dist/os/friction/friction.module.d.ts.map +1 -1
  81. package/dist/os/friction/friction.module.js +30 -5
  82. package/dist/os/friction/friction.module.js.map +1 -1
  83. package/dist/os/friction/handlers/friction-add.d.ts.map +1 -1
  84. package/dist/os/friction/handlers/friction-add.js +10 -17
  85. package/dist/os/friction/handlers/friction-add.js.map +1 -1
  86. package/dist/os/friction/handlers/friction-migrate.d.ts.map +1 -1
  87. package/dist/os/friction/handlers/friction-migrate.js +188 -2
  88. package/dist/os/friction/handlers/friction-migrate.js.map +1 -1
  89. package/dist/os/friction/store.d.ts +4 -0
  90. package/dist/os/friction/store.d.ts.map +1 -1
  91. package/dist/os/friction/store.js +20 -0
  92. package/dist/os/friction/store.js.map +1 -1
  93. package/dist/os/friction/types.d.ts +12 -0
  94. package/dist/os/friction/types.d.ts.map +1 -1
  95. package/dist/os/friction/types.js +8 -0
  96. package/dist/os/friction/types.js.map +1 -1
  97. package/dist/os/gate/handlers/gate-probe-catalog.d.ts.map +1 -1
  98. package/dist/os/gate/handlers/gate-probe-catalog.js +38 -5
  99. package/dist/os/gate/handlers/gate-probe-catalog.js.map +1 -1
  100. package/dist/os/plan/handlers/archive.d.ts.map +1 -1
  101. package/dist/os/plan/handlers/archive.js +3 -7
  102. package/dist/os/plan/handlers/archive.js.map +1 -1
  103. package/dist/os/rfc/handlers/archive.d.ts.map +1 -1
  104. package/dist/os/rfc/handlers/archive.js +3 -7
  105. package/dist/os/rfc/handlers/archive.js.map +1 -1
  106. package/dist/os/rfc/handlers/list-create.d.ts.map +1 -1
  107. package/dist/os/rfc/handlers/list-create.js +15 -7
  108. package/dist/os/rfc/handlers/list-create.js.map +1 -1
  109. package/dist/os/session/handlers/archive.d.ts.map +1 -1
  110. package/dist/os/session/handlers/archive.js +3 -7
  111. package/dist/os/session/handlers/archive.js.map +1 -1
  112. package/dist/os/system/handlers/system-product-register.d.ts +24 -0
  113. package/dist/os/system/handlers/system-product-register.d.ts.map +1 -0
  114. package/dist/os/system/handlers/system-product-register.js +322 -0
  115. package/dist/os/system/handlers/system-product-register.js.map +1 -0
  116. package/dist/os/system/handlers/system-products-status.d.ts +23 -0
  117. package/dist/os/system/handlers/system-products-status.d.ts.map +1 -0
  118. package/dist/os/system/handlers/system-products-status.js +235 -0
  119. package/dist/os/system/handlers/system-products-status.js.map +1 -0
  120. package/dist/os/system/schemas.d.ts +13 -0
  121. package/dist/os/system/schemas.d.ts.map +1 -1
  122. package/dist/os/system/schemas.js +15 -0
  123. package/dist/os/system/schemas.js.map +1 -1
  124. package/dist/os/system/system.module.d.ts.map +1 -1
  125. package/dist/os/system/system.module.js +113 -3
  126. package/dist/os/system/system.module.js.map +1 -1
  127. package/dist/src/command-modules.d.ts.map +1 -1
  128. package/dist/src/command-modules.js +0 -2
  129. package/dist/src/command-modules.js.map +1 -1
  130. package/dist/src/config/forge-config.d.ts +2 -0
  131. package/dist/src/config/forge-config.d.ts.map +1 -1
  132. package/dist/src/config/forge-config.js +11 -10
  133. package/dist/src/config/forge-config.js.map +1 -1
  134. package/dist/src/index.d.ts +0 -2
  135. package/dist/src/index.d.ts.map +1 -1
  136. package/dist/src/index.js +0 -2
  137. package/dist/src/index.js.map +1 -1
  138. package/dist/src/onboarding/create.d.ts.map +1 -1
  139. package/dist/src/onboarding/create.js +27 -2
  140. package/dist/src/onboarding/create.js.map +1 -1
  141. package/dist/src/onboarding/doctor.d.ts +0 -5
  142. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  143. package/dist/src/onboarding/doctor.js +6 -79
  144. package/dist/src/onboarding/doctor.js.map +1 -1
  145. package/dist/src/onboarding/npm-token-check.d.ts +1 -1
  146. package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
  147. package/dist/src/onboarding/npm-token-check.js +2 -2
  148. package/dist/src/onboarding/npm-token-check.js.map +1 -1
  149. package/dist/src/profiles/stack-profile.js +2 -2
  150. package/dist/src/types.js +2 -2
  151. package/dist/src/utils/hash.d.ts +1 -0
  152. package/dist/src/utils/hash.d.ts.map +1 -1
  153. package/dist/src/utils/hash.js +4 -0
  154. package/dist/src/utils/hash.js.map +1 -1
  155. package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
  156. package/dist/src/utils/lockfile.d.ts.map +1 -0
  157. package/dist/src/utils/lockfile.js +70 -0
  158. package/dist/src/utils/lockfile.js.map +1 -0
  159. package/dist/src/utils/verifier-git.d.ts +27 -1
  160. package/dist/src/utils/verifier-git.d.ts.map +1 -1
  161. package/dist/src/utils/verifier-git.js +36 -6
  162. package/dist/src/utils/verifier-git.js.map +1 -1
  163. package/docs/reference/system-hub.md +104 -0
  164. package/os/adr/handlers/archive.ts +3 -11
  165. package/os/adr/handlers/list-create.test.ts +174 -0
  166. package/os/adr/handlers/list-create.ts +16 -8
  167. package/os/audit/handlers/archive.ts +3 -11
  168. package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
  169. package/os/core/archive-regen.ts +33 -7
  170. package/os/core/core.module.ts +10 -76
  171. package/os/core/docs-archive.test.ts +25 -0
  172. package/os/core/handlers/assets-helpers.ts +2 -4
  173. package/os/core/handlers/determinism-check.ts +2 -3
  174. package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
  175. package/os/core/handlers/pinned-check.ts +30 -0
  176. package/os/core/handlers/pinned-types.ts +7 -0
  177. package/os/core/handlers/pinned-validate.ts +28 -3
  178. package/os/core/handlers/release-prepare.ts +2 -4
  179. package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
  180. package/os/flow/digest.ts +436 -95
  181. package/os/flow/evidence-lock.ts +184 -0
  182. package/os/flow/flow.module.ts +37 -14
  183. package/os/flow/git.ts +206 -11
  184. package/os/flow/handlers/flow-digest.ts +12 -8
  185. package/os/flow/handlers/flow-peers.ts +1 -1
  186. package/os/flow/handlers/flow-push.ts +725 -137
  187. package/os/flow/locks.ts +24 -7
  188. package/os/flow/open-missions.ts +45 -0
  189. package/os/flow/preflight.ts +5 -3
  190. package/os/flow/registry.ts +7 -3
  191. package/os/flow/tests/digest-id-inputs.test.ts +106 -0
  192. package/os/flow/tests/digest-persist.test.ts +243 -0
  193. package/os/flow/tests/evidence-preflight-surface-skip.test.ts +218 -0
  194. package/os/flow/tests/flow-push-attest.test.ts +137 -0
  195. package/os/flow/tests/flow-push-review-baseline.test.ts +339 -0
  196. package/os/flow/tests/flow-push-verifier-batch.test.ts +134 -0
  197. package/os/flow/tests/release-lines.test.ts +136 -0
  198. package/os/flow/tests/state-roots.test.ts +1 -48
  199. package/os/friction/friction-add.test.ts +42 -0
  200. package/os/friction/friction-migrate.test.ts +67 -2
  201. package/os/friction/friction.module.ts +33 -5
  202. package/os/friction/handlers/friction-add.ts +10 -15
  203. package/os/friction/handlers/friction-migrate.ts +220 -1
  204. package/os/friction/store.ts +19 -0
  205. package/os/friction/types.ts +8 -0
  206. package/os/gate/handlers/gate-probe-catalog.ts +39 -7
  207. package/os/gate/handlers/gate-probe-ratchet.test.ts +57 -22
  208. package/os/plan/handlers/archive.ts +3 -11
  209. package/os/rfc/handlers/archive.ts +3 -11
  210. package/os/rfc/handlers/list-create.ts +22 -17
  211. package/os/rfc/handlers/validate-corpus.test.ts +149 -0
  212. package/os/rfc/probe-batch.test.ts +253 -0
  213. package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
  214. package/os/session/handlers/archive.ts +3 -11
  215. package/os/system/handlers/system-product-register.ts +492 -0
  216. package/os/system/handlers/system-products-status.ts +395 -0
  217. package/os/system/schemas.ts +17 -0
  218. package/os/system/system.module.ts +117 -3
  219. package/os/system/tests/system-product-register.test.ts +304 -0
  220. package/os/system/tests/system-products-status.test.ts +154 -0
  221. package/package.json +161 -506
  222. package/profiles/root-agents-system.md +82 -0
  223. package/profiles/system.yaml +1 -0
  224. package/src/command-modules.ts +0 -2
  225. package/src/config/forge-config.ts +16 -11
  226. package/src/index.ts +0 -2
  227. package/src/onboarding/create-superfolder-guard.test.ts +73 -0
  228. package/src/onboarding/create.ts +28 -2
  229. package/src/onboarding/doctor.ts +9 -96
  230. package/src/onboarding/npm-token-check.ts +3 -3
  231. package/src/profiles/stack-profile.ts +2 -2
  232. package/src/tests/evidence-consult-serialization.test.ts +202 -0
  233. package/src/tests/pinned-validate.test.ts +194 -0
  234. package/src/tests/pkg-health-self-scan.test.ts +29 -0
  235. package/src/tests/profile-flow-hooks.test.ts +1 -0
  236. package/src/tests/profile-schema.test.ts +1 -0
  237. package/src/tests/rfc-evidence-sync.test.ts +369 -0
  238. package/src/tests/skill-agents-sync.test.ts +192 -0
  239. package/src/tests/stack-profile.test.ts +1 -0
  240. package/src/types.ts +2 -2
  241. package/src/utils/hash.ts +5 -0
  242. package/src/utils/lockfile.ts +78 -0
  243. package/src/utils/verifier-git.ts +53 -5
  244. package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
  245. package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
  246. package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
  247. package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
  248. package/dist/os/mission/handlers/archive.d.ts +0 -4
  249. package/dist/os/mission/handlers/archive.d.ts.map +0 -1
  250. package/dist/os/mission/handlers/archive.js +0 -587
  251. package/dist/os/mission/handlers/archive.js.map +0 -1
  252. package/dist/os/mission/importer-block.d.ts +0 -19
  253. package/dist/os/mission/importer-block.d.ts.map +0 -1
  254. package/dist/os/mission/importer-block.js +0 -124
  255. package/dist/os/mission/importer-block.js.map +0 -1
  256. package/dist/os/mission/index.d.ts +0 -2
  257. package/dist/os/mission/index.d.ts.map +0 -1
  258. package/dist/os/mission/index.js +0 -15
  259. package/dist/os/mission/index.js.map +0 -1
  260. package/dist/os/mission/lockfile.d.ts.map +0 -1
  261. package/dist/os/mission/lockfile.js +0 -138
  262. package/dist/os/mission/lockfile.js.map +0 -1
  263. package/dist/os/mission/mission.module.d.ts +0 -3
  264. package/dist/os/mission/mission.module.d.ts.map +0 -1
  265. package/dist/os/mission/mission.module.js +0 -63
  266. package/dist/os/mission/mission.module.js.map +0 -1
  267. package/dist/os/mission/open-missions.d.ts.map +0 -1
  268. package/dist/os/mission/open-missions.js +0 -42
  269. package/dist/os/mission/open-missions.js.map +0 -1
  270. package/dist/os/mission/types.d.ts +0 -23
  271. package/dist/os/mission/types.d.ts.map +0 -1
  272. package/dist/os/mission/types.js +0 -19
  273. package/dist/os/mission/types.js.map +0 -1
  274. package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
  275. package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
  276. package/dist/os/werkstatt/handlers/lock.js +0 -153
  277. package/dist/os/werkstatt/handlers/lock.js.map +0 -1
  278. package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
  279. package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
  280. package/dist/os/werkstatt/handlers/schema.js +0 -42
  281. package/dist/os/werkstatt/handlers/schema.js.map +0 -1
  282. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
  283. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
  284. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
  285. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
  286. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
  287. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
  288. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
  289. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
  290. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
  291. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
  292. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
  293. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
  294. package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
  295. package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
  296. package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
  297. package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
  298. package/dist/os/werkstatt/index.d.ts +0 -7
  299. package/dist/os/werkstatt/index.d.ts.map +0 -1
  300. package/dist/os/werkstatt/index.js +0 -18
  301. package/dist/os/werkstatt/index.js.map +0 -1
  302. package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
  303. package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
  304. package/dist/os/werkstatt/werkstatt.module.js +0 -91
  305. package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
  306. package/os/core/handlers/forge-autonomy-validate.ts +0 -276
  307. package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
  308. package/os/mission/handlers/archive.test.ts +0 -764
  309. package/os/mission/handlers/archive.ts +0 -719
  310. package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
  311. package/os/mission/importer-block.ts +0 -119
  312. package/os/mission/index.ts +0 -15
  313. package/os/mission/lockfile.ts +0 -152
  314. package/os/mission/mission.module.ts +0 -68
  315. package/os/mission/open-missions.ts +0 -50
  316. package/os/mission/types.ts +0 -42
  317. package/os/werkstatt/handlers/lock.ts +0 -168
  318. package/os/werkstatt/handlers/schema.ts +0 -47
  319. package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
  320. package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
  321. package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
  322. package/os/werkstatt/handlers/workspace-deps.ts +0 -56
  323. package/os/werkstatt/index.ts +0 -39
  324. package/os/werkstatt/werkstatt.module.ts +0 -95
  325. package/src/tests/doctor-autonomy.test.ts +0 -246
  326. package/src/tests/forge-autonomy-validate.test.ts +0 -159
  327. package/src/tests/werkstatt-lock.test.ts +0 -357
@@ -1,105 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>
4
- RFC-1397 standalone-degradation coverage: when
5
- @warpgogol/werkstatt-shared/kernel/ship-inflight cannot be imported — the
6
- situation on a standalone forge install, where the package is only a
7
- workspace devDependency — the ship-in-flight guard degrades to warn-once +
8
- proceed instead of breaking mission.archive at module load.
9
- </purpose>
10
- <non-goals>
11
- <item>Full guard coverage lives in ship-inflight.test.ts — this file only exercises the unavailable-module path and needs its own vi.mock.</item>
12
- </non-goals>
13
- </MODULE_CONTRACT>
14
- <CHANGE_SUMMARY>
15
- <item>RFC-1397: initial suite — lazy-bridge import failure warns and the sweep proceeds.</item>
16
- <item>RFC-1397: harden ship-in-flight guard per independent review (RFC-1397)</item>
17
- </CHANGE_SUMMARY>
18
- */
19
-
20
- import { test, expect, describe, beforeEach, afterEach, vi } from "vitest";
21
- import fs from "node:fs/promises";
22
- import { existsSync } from "node:fs";
23
- import path from "node:path";
24
- import os from "node:os";
25
-
26
- vi.mock("@warpgogol/werkstatt-shared/kernel/ship-inflight", () => {
27
- throw new Error("Cannot find module '@warpgogol/werkstatt-shared/kernel/ship-inflight'");
28
- });
29
-
30
- vi.mock("../../../src/utils/fs-trash.ts", () => ({
31
- trashPath: (targetPath: string) => fs.rm(targetPath, { recursive: true, force: true }),
32
- }));
33
-
34
- const execSyncMock = vi.fn<(cmd: string, opts?: Record<string, unknown>) => string | Buffer>();
35
-
36
- vi.mock("node:child_process", () => ({
37
- execSync: (cmd: string, opts?: Record<string, unknown>) => execSyncMock(cmd, opts),
38
- }));
39
-
40
- import { runMissionArchive } from "./archive.ts";
41
- import type { ForgeCommandInput, ForgeRuntimeContext } from "../../../src/types.ts";
42
-
43
- let testRoot: string;
44
- let workspaceRoot: string;
45
- let missionsDir: string;
46
-
47
- beforeEach(async () => {
48
- testRoot = await fs.mkdtemp(path.join(os.tmpdir(), "ship-inflight-degraded-"));
49
- workspaceRoot = path.join(testRoot, "werkstatt");
50
- missionsDir = path.join(workspaceRoot, "missions");
51
- await fs.mkdir(missionsDir, { recursive: true });
52
- execSyncMock.mockReset();
53
- execSyncMock.mockReturnValue("");
54
- });
55
-
56
- afterEach(async () => {
57
- await fs.rm(testRoot, { recursive: true, force: true });
58
- });
59
-
60
- function makeContext(warn: (m: string) => void): ForgeRuntimeContext {
61
- return {
62
- workspaceRoot,
63
- logger: { info: () => {}, success: () => {}, warn, error: () => {}, debug: () => {} },
64
- outputFormat: "json",
65
- dryRun: false,
66
- } as unknown as ForgeRuntimeContext;
67
- }
68
-
69
- function makeInput(flags: Record<string, unknown> = {}): ForgeCommandInput {
70
- return { commandName: "mission.archive", flags } as unknown as ForgeCommandInput;
71
- }
72
-
73
- describe("mission.archive ship-in-flight degradation (RFC-1397)", () => {
74
- test("missing werkstatt-shared warns once and the sweep proceeds", async () => {
75
- const missionId = "testsys-m000001";
76
- const missionDir = path.join(missionsDir, missionId);
77
- await fs.mkdir(missionDir, { recursive: true });
78
- await fs.writeFile(
79
- path.join(missionDir, "mission.yaml"),
80
- `missionId: ${missionId}\nsystemId: testsys\nstate: closed\n`,
81
- );
82
- // An in-flight journal exists but cannot be consulted — the guard is
83
- // vacuous where the predicate module itself is absent.
84
- const opsDir = path.join(testRoot, "systems-cache", "testsys", "operations");
85
- await fs.mkdir(opsDir, { recursive: true });
86
- await fs.writeFile(
87
- path.join(opsDir, `ship-${missionId}.jsonl`),
88
- JSON.stringify({
89
- kind: "op-started",
90
- opId: "op-ship-1",
91
- op: "leitstand.ship",
92
- missionId,
93
- at: new Date().toISOString(),
94
- }) + "\n",
95
- );
96
-
97
- const warn = vi.fn();
98
- const result = await runMissionArchive(makeInput(), makeContext(warn));
99
-
100
- expect(warn).toHaveBeenCalledWith(expect.stringContaining("ship-inflight guard unavailable"));
101
- const movedIds = (result.data?.moved ?? []).map((m: { missionId: string }) => m.missionId);
102
- expect(movedIds).toContain(missionId);
103
- expect(existsSync(path.join(missionsDir, "archive", "closed", missionId))).toBe(true);
104
- });
105
- });
@@ -1,119 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>Text-splice primitives for a single importer subtree inside
4
- pnpm-lock.yaml (RFC-1544). A mission workpiece registers as the importer key
5
- `missions/<id>/workpiece:` at the fixed two-space indent under `importers:`;
6
- both consumers — flow.integrate's foreign-open-mission restore and
7
- mission.archive's bookkeeping prune — must move exactly that key's block and
8
- nothing else, so a whole-file checkout or a YAML round-trip (which rewrites
9
- unrelated formatting) is never the mechanism.</purpose>
10
- <non-goals>
11
- <item>No YAML semantics — block boundaries are indent arithmetic on the pnpm-lock layout, not a parse.</item>
12
- <item>No git/file I/O — pure string transforms; callers own reads and writes.</item>
13
- </non-goals>
14
- </MODULE_CONTRACT>
15
- <CHANGE_SUMMARY>
16
- <item>RFC-1544: importer-block extract/insert/remove text splices shared by flow.integrate restore and mission.archive prune</item>
17
- <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
18
- </CHANGE_SUMMARY>
19
- */
20
-
21
- const IMPORTER_INDENT = 2;
22
-
23
- function indentOf(line: string): number {
24
- return line.length - line.trimStart().length;
25
- }
26
-
27
- /** Locate ` <key>:` at the importer indent — exact key, no prefix bleed. */
28
- function importerKeyIndex(lines: string[], key: string): number {
29
- const wanted = `${" ".repeat(IMPORTER_INDENT)}${key}:`;
30
- return lines.findIndex((l) => l.trimEnd() === wanted);
31
- }
32
-
33
- /**
34
- * The importer block lines for `key` inside lockfile `text`: the key line
35
- * plus every deeper-indented member, trailing blanks excluded. Null when the
36
- * key is absent.
37
- */
38
- export function extractImporterBlock(text: string, key: string): string[] | null {
39
- const lines = text.split("\n");
40
- const start = importerKeyIndex(lines, key);
41
- if (start === -1) return null;
42
- let end = start + 1;
43
- while (end < lines.length) {
44
- const l = lines[end];
45
- if (l.trim().length === 0) {
46
- end += 1;
47
- continue;
48
- }
49
- if (indentOf(l) <= IMPORTER_INDENT) break;
50
- end += 1;
51
- }
52
- while (end > start + 1 && lines[end - 1].trim().length === 0) end -= 1;
53
- return lines.slice(start, end);
54
- }
55
-
56
- /**
57
- * `text` without `key`'s importer block — the block plus its separating
58
- * blank line(s), so removal leaves the surrounding layout intact. Returns
59
- * the input unchanged when the key is absent.
60
- */
61
- export function removeImporterBlock(text: string, key: string): string {
62
- const lines = text.split("\n");
63
- const start = importerKeyIndex(lines, key);
64
- if (start === -1) return text;
65
- let end = start + 1;
66
- while (end < lines.length) {
67
- const l = lines[end];
68
- if (l.trim().length === 0) {
69
- end += 1;
70
- continue;
71
- }
72
- if (indentOf(l) <= IMPORTER_INDENT) break;
73
- end += 1;
74
- }
75
- // Also absorb the blank separator BEFORE the block when one exists —
76
- // pnpm separates importer stanzas with a single blank line.
77
- let s = start;
78
- if (s > 0 && lines[s - 1].trim().length === 0) s -= 1;
79
- const out = [...lines.slice(0, s), ...lines.slice(end)];
80
- // Collapse a doubled blank left at the seam when both sides kept one.
81
- return out.join("\n").replace(/\n{3,}/g, "\n\n");
82
- }
83
-
84
- /**
85
- * `text` with `block` inserted under `importers:` at pnpm's alphabetical
86
- * position — before the first importer key sorting after `key`, else at the
87
- * end of the importers section. Null when no `importers:` section exists.
88
- */
89
- export function insertImporterBlock(text: string, key: string, block: string[]): string | null {
90
- const lines = text.split("\n");
91
- const importersIdx = lines.findIndex((l) => l.trimEnd() === "importers:");
92
- if (importersIdx === -1) return null;
93
- // Section end: first non-blank line with indent < 2 (or EOF).
94
- let sectionEnd = lines.length;
95
- for (let i = importersIdx + 1; i < lines.length; i += 1) {
96
- const l = lines[i];
97
- if (l.trim().length === 0) continue;
98
- if (indentOf(l) < IMPORTER_INDENT) {
99
- sectionEnd = i;
100
- break;
101
- }
102
- }
103
- // First importer key sorting after ours — mid-section insert.
104
- for (let i = importersIdx + 1; i < sectionEnd; i += 1) {
105
- const l = lines[i];
106
- if (l.trim().length === 0 || indentOf(l) !== IMPORTER_INDENT) continue;
107
- const other = l.trim().replace(/:$/, "");
108
- if (other > key) {
109
- return [...lines.slice(0, i), ...block, "", ...lines.slice(i)].join("\n");
110
- }
111
- }
112
- // End-of-section insert: splice before the trailing blank run when one
113
- // exists (it already separates the last block from the next section).
114
- let at = sectionEnd;
115
- while (at > importersIdx + 1 && lines[at - 1].trim().length === 0) at -= 1;
116
- const hadTrailingBlanks = at < sectionEnd;
117
- const payload = ["", ...block, ...(hadTrailingBlanks ? [] : [""])];
118
- return [...lines.slice(0, at), ...payload, ...lines.slice(at)].join("\n");
119
- }
@@ -1,15 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>Mission module index — re-export createForgeMissionModule for the forge kernel registry.</purpose>
4
- <non-goals>
5
- <item>Do not implement mission logic here — the module registration lives in mission.module.ts.</item>
6
- </non-goals>
7
- </MODULE_CONTRACT>
8
- <CHANGE_SUMMARY>
9
- <item>RFC-1097: sweep — packages/forge + services clean
10
-
11
- Sweep batch 2: real KEY_DECISIONS on 10 files, expanded purposes (CONTRACT-02/PURPOSE-02), headers on mission/index + gen-upstreams, sanitizeItemText in summary.record (literal Compass tags corrupted history), excludedPaths for wrangler types, test-fixtures testPattern. forge+services now 0 diagnostics under --mode error.</item>
12
- </CHANGE_SUMMARY>
13
- */
14
-
15
- export { createForgeMissionModule } from "./mission.module.ts";
@@ -1,152 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>
4
- Tracked lockfile restoration — after a mission lifecycle step runs `pnpm install`
5
- for dependency pruning, the local install may rewrite `pnpm-lock.yaml`. That churn
6
- is local mission state and must never land in tracked artifacts: this helper
7
- restores the file committed at HEAD so the worktree returns clean.
8
- </purpose>
9
- <non-goals>
10
- <item>Does not commit, stage, or delete the lockfile — only restores tracked bytes.</item>
11
- <item>Does not synthesize a lockfile when HEAD carries none — returns false and changes nothing.</item>
12
- </non-goals>
13
- </MODULE_CONTRACT>
14
- <CHANGE_SUMMARY>
15
- <item>RFC-1505: steps 3-5 — tracked lockfile restore, no side-effect commits</item>
16
- <item>RFC-1505: review r1 — durable projections and lockfile restore hardening</item>
17
- <item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
18
- <item>RFC-1544: attribute mission lockfile churn to owning checkout and auto-resolve foreign importer diffs (RFC-1544)</item>
19
- <item>RFC-1616: close r19 counterexamples CX-166 through CX-171</item>
20
- <history>RFC-1505</history>
21
- </CHANGE_SUMMARY>
22
- */
23
-
24
- import path from "node:path";
25
- import { execFileSync } from "../../src/utils/sync-fs.ts";
26
- import type { ExecOptions, ExecResult, WorkspaceIO } from "../../src/types.ts";
27
- import {
28
- closeEvidenceIndex,
29
- evidenceAnchoredGit,
30
- evidenceRepoPreflight,
31
- verifierGit,
32
- } from "../../src/utils/verifier-git.ts";
33
- import { extractImporterBlock, removeImporterBlock } from "./importer-block.ts";
34
-
35
- const LOCKFILE_NAME = "pnpm-lock.yaml";
36
-
37
- /**
38
- * Restore `pnpm-lock.yaml` to the bytes committed at HEAD.
39
- *
40
- * Runs `git show HEAD:pnpm-lock.yaml` in `root`. On exit 0 the stdout is written
41
- * back over `root/pnpm-lock.yaml` and the call returns `true`. On a non-zero
42
- * exit (no such file at HEAD, not a git repository) it returns `false` and
43
- * changes nothing. Spawn failures (missing git binary) propagate.
44
- * `root` is the repository root — git resolves `HEAD:pnpm-lock.yaml` against
45
- * the enclosing repo's top level, so passing a nested directory of a larger
46
- * repo would restore that repo's root lockfile instead.
47
- */
48
- export async function restoreTrackedLockfile(
49
- root: string,
50
- io: Pick<WorkspaceIO, "exec" | "writeFile">,
51
- ): Promise<boolean> {
52
- // The committed-bytes read goes through the judged channel — the
53
- // ambient exec layer inherits `process.env`, so a session `GIT_DIR`
54
- // would serve `HEAD:` from a foreign object store and this "restore"
55
- // would write forged bytes into the real worktree (CX-164). A refused
56
- // read restores nothing and reports false.
57
- const res = await verifierGit(root, ["show", `HEAD:${LOCKFILE_NAME}`]);
58
- if (res.exitCode !== 0) return false;
59
- await io.writeFile(path.join(root, LOCKFILE_NAME), res.stdout);
60
- return true;
61
- }
62
-
63
- /**
64
- * Sync-world adapter for `io.exec` — wraps `execFileSync` so handlers that still
65
- * run on `execSync`/`execFileSync` (e.g. mission.archive) can call
66
- * `restoreTrackedLockfile` without duplicating its logic. A non-zero exit maps
67
- * to `exitCode`; a spawn failure (missing binary) keeps throwing.
68
- */
69
- export function execFileSyncAdapter(): Pick<WorkspaceIO, "exec"> {
70
- return {
71
- exec(command: string, args: string[], opts?: ExecOptions): Promise<ExecResult> {
72
- try {
73
- const stdout = execFileSync(command, args, {
74
- cwd: opts?.cwd,
75
- encoding: "utf-8",
76
- stdio: ["pipe", "pipe", "pipe"],
77
- timeout: opts?.timeoutMs,
78
- // Real pnpm-lock.yaml files exceed the 1 MiB default many times over —
79
- // an ENOBUFS kill carries status null and would rethrow below.
80
- maxBuffer: 64 * 1024 * 1024,
81
- });
82
- return Promise.resolve({ exitCode: 0, stdout, stderr: "" });
83
- } catch (err) {
84
- const e = err as {
85
- status?: number | null;
86
- stdout?: Buffer | string;
87
- stderr?: Buffer | string;
88
- };
89
- if (e.status === undefined || e.status === null) throw err;
90
- return Promise.resolve({
91
- exitCode: e.status,
92
- stdout: e.stdout?.toString() ?? "",
93
- stderr: e.stderr?.toString() ?? "",
94
- });
95
- }
96
- },
97
- };
98
- }
99
-
100
- /**
101
- * RFC-1544 AC-5: drop the listed missions' `missions/<id>/workpiece`
102
- * importer subtrees from the tracked `pnpm-lock.yaml` and stage the result
103
- * for the archive bookkeeping commit. The written bytes are HEAD-minus-
104
- * importers — the post-archive `pnpm install` may churn unrelated lockfile
105
- * state, and only the importer removal is legitimate tracked change, so
106
- * everything else is discarded exactly like `restoreTrackedLockfile` did.
107
- *
108
- * Returns `pruned` = mission ids whose importer block was actually removed;
109
- * `staged` = whether `pnpm-lock.yaml` reached the index. When no listed
110
- * importer exists at HEAD the tracked file is restored instead (the old
111
- * churn-discard behavior) and `staged` stays false.
112
- */
113
- export async function pruneMissionImportersFromLockfile(
114
- root: string,
115
- missionIds: string[],
116
- io: Pick<WorkspaceIO, "exec" | "writeFile">,
117
- ): Promise<{ pruned: string[]; staged: boolean }> {
118
- // One preflight anchors the whole read→write→stage sequence: a `.git`
119
- // indirection swap landing between the judged `show` and the `add`
120
- // re-points the staging target into a foreign index, and a fresh
121
- // preflight would happily attest THAT repo — the anchored fingerprint
122
- // is re-proved immediately before the mutation and any drift refuses
123
- // (CX-169). The `show` read itself runs on the same anchored surface.
124
- const preflight = await evidenceRepoPreflight(root);
125
- if (preflight === null) return { pruned: [], staged: false };
126
- try {
127
- // Judged channel for the committed-bytes read — same CX-164
128
- // redirect: ambient `GIT_DIR` would serve the foreign repo's
129
- // lockfile bytes.
130
- const head = await verifierGit(root, ["show", `HEAD:${LOCKFILE_NAME}`], { preflight });
131
- if (head.exitCode !== 0) return { pruned: [], staged: false };
132
- let next = head.stdout;
133
- const pruned: string[] = [];
134
- for (const missionId of missionIds) {
135
- const key = `missions/${missionId}/workpiece`;
136
- if (extractImporterBlock(next, key) === null) continue;
137
- next = removeImporterBlock(next, key);
138
- pruned.push(missionId);
139
- }
140
- const target = path.join(root, LOCKFILE_NAME);
141
- if (pruned.length === 0) {
142
- // Nothing legitimately prunes — keep the discard-churn restore.
143
- await io.writeFile(target, head.stdout);
144
- return { pruned, staged: false };
145
- }
146
- await io.writeFile(target, next);
147
- const add = await evidenceAnchoredGit(root, ["add", "--", LOCKFILE_NAME], { preflight });
148
- return { pruned, staged: add.exitCode === 0 };
149
- } finally {
150
- closeEvidenceIndex(preflight);
151
- }
152
- }
@@ -1,68 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>Register the mission archive command with the forge kernel registry.</purpose>
4
- <non-goals>
5
- <item>Do not implement handler logic here — delegate to handlers/archive.ts.</item>
6
- </non-goals>
7
- </MODULE_CONTRACT>
8
- <CHANGE_SUMMARY>
9
- <item>RFC-0573: initial forgeMissionModule registering mission.archive command.</item>
10
- <item>RFC-0982: add --clean-orphans flag for trashing orphaned remnant directories.</item>
11
- <item>RFC-1397: declare internal --ship-op flag — ship's own opId marker for the terminal archive step exemption.</item>
12
- <item>RFC-1505: review r2 — clone-only sternsystem enumeration and mission-gated lockfile net</item>
13
- </CHANGE_SUMMARY>
14
- */
15
-
16
- import type { ForgeModule } from "../../src/forge-module.ts";
17
-
18
- export async function createForgeMissionModule(): Promise<ForgeModule> {
19
- const { runMissionArchive } = await import("./handlers/archive.ts");
20
- return {
21
- name: "forge-mission",
22
- version: "0.1.0",
23
- runtime: "autonomous",
24
- declarations: [],
25
- commands: [
26
- {
27
- name: "mission.archive",
28
- description:
29
- "Move terminal-state mission directories (state: closed or aborted in " +
30
- "mission.yaml) into missions/archive/<state>/<missionId>/ subdirectories. " +
31
- "Bidirectional: moves open missions found in archive subdirectories back " +
32
- "to missions/. Use --dry-run to preview. Use --status to filter to a " +
33
- "single terminal status (closed, aborted). " +
34
- "Prefer the docs.archive umbrella command unless you need to archive only missions.",
35
- scope: "workspace",
36
- mutatesState: true,
37
- writes: ["missions/*", "missions/archive/**", "pnpm-lock.yaml"],
38
- generates: [],
39
- reads: ["missions/**"],
40
- cacheable: false,
41
- flags: {
42
- "dry-run": {
43
- kind: "boolean",
44
- description: "Preview what would be moved without touching the filesystem.",
45
- },
46
- status: {
47
- kind: "string",
48
- description: "Filter to a single terminal status (closed, aborted).",
49
- },
50
- "clean-orphans": {
51
- kind: "boolean",
52
- description:
53
- "Trash orphaned directories (no mission.yaml, only cache files) instead of archiving them.",
54
- },
55
- "ship-op": {
56
- kind: "string",
57
- description:
58
- "Internal marker (RFC-1397): the leitstand.ship opId allowed to archive its own mission. " +
59
- "Set only by ship's terminal mission-archive step — agents MUST NOT pass it by hand; " +
60
- "a foreign opId self-inflicts an archive skip.",
61
- },
62
- },
63
- execute: runMissionArchive,
64
- },
65
- ],
66
- pipelines: [],
67
- };
68
- }
@@ -1,50 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>Open-mission scan for forge's flow gates (RFC-1537) — a forge-local
4
- port of werkstatt.worktree.gate's openMissionsIn semantics: glob the
5
- missions/<id>/mission.yaml manifests under a checkout, count `state: "open"`,
6
- and treat an unreadable manifest as open (a corrupt live mission must never
7
- silently pass — DNA-106). Forge cannot import the site plugin
8
- (FORGE-AUTONOMY-01), so parity is pinned by the contract the preflight mission
9
- check consumes.</purpose>
10
- <non-goals>
11
- <item>Read-only — never mutates mission state; mission lifecycle lives in mission.* commands.</item>
12
- </non-goals>
13
- </MODULE_CONTRACT>
14
- <CHANGE_SUMMARY>
15
- <item>RFC-1537: open-mission scan shared by the integrate preflight's cheap-first check and the importer-materialize dirt class</item>
16
- <item>RFC-1537: classify regenerable worktree dirt and journal integrate refusals cheapest-first</item>
17
- </CHANGE_SUMMARY>
18
- */
19
-
20
- import { basename, dirname, join } from "node:path";
21
-
22
- import { parse as yamlParse } from "yaml";
23
-
24
- import type { WorkspaceIO } from "../../src/types.ts";
25
-
26
- /**
27
- * Mission ids whose `missions/<id>/mission.yaml` declares `state: "open"`.
28
- * An unreadable manifest counts as open — same closed-shape semantics as the
29
- * site plugin's worktree gate. Sorted for deterministic output.
30
- */
31
- export async function openMissionsIn(
32
- worktree: string,
33
- io: WorkspaceIO,
34
- ): Promise<string[]> {
35
- const manifests = await io.glob("missions/*/mission.yaml", { cwd: worktree });
36
- const open: string[] = [];
37
- for (const rel of manifests) {
38
- try {
39
- const parsed = yamlParse(await io.readFile(join(worktree, rel))) as {
40
- state?: unknown;
41
- } | null;
42
- if (parsed?.state === "open") {
43
- open.push(basename(dirname(rel)));
44
- }
45
- } catch {
46
- open.push(basename(dirname(rel)));
47
- }
48
- }
49
- return open.sort();
50
- }
@@ -1,42 +0,0 @@
1
- /*
2
- <MODULE_CONTRACT>
3
- <purpose>
4
- Type definitions for the mission archive domain — mission directory discovery,
5
- manifest state extraction, and archive result shapes.
6
- </purpose>
7
- <non-goals>
8
- <item>Do not define archive handler logic here — that lives in handlers/archive.ts.</item>
9
- </non-goals>
10
- </MODULE_CONTRACT>
11
- <CHANGE_SUMMARY>
12
- <item>RFC-0573: initial mission archive types.</item>
13
- <item>RFC-0982: add "trashed-orphan" to MissionArchiveMove.direction.</item>
14
- </CHANGE_SUMMARY>
15
- */
16
-
17
- export const MISSIONS_DIR = "missions";
18
- export const ARCHIVE_DIR_NAME = "archive";
19
-
20
- export const MISSION_TERMINAL_STATUSES = ["closed", "aborted"] as const;
21
-
22
- export interface MissionArchiveMove {
23
- missionId: string;
24
- state: string;
25
- from: string;
26
- to: string;
27
- direction: "into-archive" | "out-of-archive" | "trashed-orphan";
28
- }
29
-
30
- export interface MissionArchiveSkip {
31
- missionId: string;
32
- dir: string;
33
- reason: string;
34
- }
35
-
36
- export interface MissionArchiveResult {
37
- command: "mission.archive";
38
- status: "ok";
39
- moved: MissionArchiveMove[];
40
- skipped: MissionArchiveSkip[];
41
- dryRun: boolean;
42
- }