@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
@@ -0,0 +1,202 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1633: evidence-consult serialization + degraded reader mode —
4
+ AC-1/AC-4 lock serialization + dead-holder recovery on the
5
+ withEvidenceConsultLock seam, AC-2 bestEffort marks trusted:false and
6
+ never touches the lock, AC-3 assertJudgedEvidence boundary throw,
7
+ AC-5 EVIDENCE-BUDGET phase refusal, AC-7 concurrent holders serialize and
8
+ all complete. Plus the call-site scan: `mode: "bestEffort"` may appear
9
+ only in the enumerated non-judging call sites.</purpose>
10
+ <non-goals>
11
+ <item>No full judged-consult e2e — the preflight/watch/settle machinery is
12
+ RFC-1616's own suite; this file covers the scheduling layer.</item>
13
+ </non-goals>
14
+ </MODULE_CONTRACT>
15
+ <CHANGE_SUMMARY>
16
+ <item>RFC-1633: step 5 — serialization/mode/budget/scan-guard tests</item>
17
+ <item>RFC-1633: serialize evidence consults + bestEffort reader mode (RFC-1633)</item>
18
+ <item>RFC-1633: review round 1 — digest envInputs, package-wide bestEffort scan, holder command, serialized standalone preflight</item>
19
+ </CHANGE_SUMMARY>
20
+ */
21
+
22
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
23
+ import { existsSync, mkdirSync, readFileSync, readdirSync } from "node:fs";
24
+ import { tmpdir, hostname } from "node:os";
25
+ import { join, relative, resolve } from "node:path";
26
+ import { spawnSync } from "node:child_process";
27
+
28
+ import { afterEach, describe, expect, it } from "vitest";
29
+
30
+ import { assertJudgedEvidence, evidenceBudgetBreach, gitEvidence } from "../../os/flow/git.ts";
31
+ import {
32
+ EVIDENCE_CONSULT_LOCK_RELATIVE_PATH,
33
+ resolveEvidenceCommonGitDir,
34
+ withEvidenceConsultLock,
35
+ } from "../../os/flow/evidence-lock.ts";
36
+
37
+ const dirs: string[] = [];
38
+ afterEach(async () => {
39
+ for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true });
40
+ }, 20_000);
41
+
42
+ const HOST = hostname();
43
+
44
+ async function scratchRepo(): Promise<string> {
45
+ const dir = await mkdtemp(join(tmpdir(), "ev-consult-"));
46
+ dirs.push(dir);
47
+ mkdirSync(join(dir, ".git"));
48
+ return dir;
49
+ }
50
+
51
+ async function realRepo(): Promise<string> {
52
+ const dir = await mkdtemp(join(tmpdir(), "ev-real-"));
53
+ dirs.push(dir);
54
+ const init = spawnSync("git", ["init", "-q", dir]);
55
+ if (init.status !== 0) throw new Error(`git init failed: ${init.stderr}`);
56
+ return dir;
57
+ }
58
+
59
+ const deferred = <T>() => {
60
+ let resolve!: (v: T) => void;
61
+ let reject!: (e: unknown) => void;
62
+ const promise = new Promise<T>((res, rej) => {
63
+ resolve = res;
64
+ reject = rej;
65
+ });
66
+ return { promise, resolve, reject };
67
+ };
68
+
69
+ describe("evidence-consult lock serialization (AC-1, AC-4, AC-7)", () => {
70
+ it("AC-1: two overlapping consults on one commonGitDir never interleave", async () => {
71
+ const repo = await scratchRepo();
72
+ let inside = 0;
73
+ let maxInside = 0;
74
+ const gate = deferred<void>();
75
+ const order: string[] = [];
76
+ const first = withEvidenceConsultLock(repo, { waitMs: 5_000 }, async () => {
77
+ inside++;
78
+ maxInside = Math.max(maxInside, inside);
79
+ order.push("first-in");
80
+ await gate.promise;
81
+ inside--;
82
+ order.push("first-out");
83
+ });
84
+ // Yield so the first consult holds the lock before the second starts.
85
+ await new Promise((r) => setTimeout(r, 20));
86
+ const second = withEvidenceConsultLock(repo, { waitMs: 5_000 }, async () => {
87
+ inside++;
88
+ maxInside = Math.max(maxInside, inside);
89
+ order.push("second-in");
90
+ inside--;
91
+ order.push("second-out");
92
+ });
93
+ gate.resolve();
94
+ await Promise.all([first, second]);
95
+ expect(maxInside).toBe(1);
96
+ expect(order).toEqual(["first-in", "first-out", "second-in", "second-out"]);
97
+ });
98
+
99
+ it("AC-4: a dead holder's lock is broken without waiting", async () => {
100
+ const repo = await scratchRepo();
101
+ const common = resolveEvidenceCommonGitDir(repo);
102
+ expect(common).not.toBeNull();
103
+ const lockPath = join(common!, EVIDENCE_CONSULT_LOCK_RELATIVE_PATH);
104
+ mkdirSync(join(common!, "forge"), { recursive: true });
105
+ const deadPid = spawnSync(process.execPath, ["-e", ""]).pid;
106
+ expect(deadPid).toBeDefined();
107
+ await writeFile(
108
+ lockPath,
109
+ JSON.stringify({ pid: deadPid, host: HOST, at: new Date().toISOString() }),
110
+ );
111
+ let ran = false;
112
+ await withEvidenceConsultLock(repo, { waitMs: 2_000 }, async () => {
113
+ ran = true;
114
+ });
115
+ expect(ran).toBe(true);
116
+ // The lock released cleanly after fn.
117
+ expect(existsSync(lockPath)).toBe(false);
118
+ });
119
+
120
+ it("AC-7: three concurrent holders serialize and all complete", async () => {
121
+ const repo = await scratchRepo();
122
+ let inside = 0;
123
+ let maxInside = 0;
124
+ const holder = async () => {
125
+ await withEvidenceConsultLock(repo, { waitMs: 5_000 }, async () => {
126
+ inside++;
127
+ maxInside = Math.max(maxInside, inside);
128
+ await new Promise((r) => setTimeout(r, 15));
129
+ inside--;
130
+ });
131
+ };
132
+ await Promise.all([holder(), holder(), holder()]);
133
+ expect(maxInside).toBe(1);
134
+ });
135
+ });
136
+
137
+ describe("bestEffort mode (AC-2) + boundary (AC-3)", () => {
138
+ it("AC-2: mode:'bestEffort' returns trusted:false and creates no lock", async () => {
139
+ const repo = await realRepo();
140
+ const r = await gitEvidence(repo, ["rev-parse", "--git-dir"], {
141
+ mode: "bestEffort",
142
+ });
143
+ expect(r.exitCode).toBe(0);
144
+ expect(r.trusted).toBe(false);
145
+ // No preflight, no watch, no lock — the lock artifact never appears.
146
+ const common = resolveEvidenceCommonGitDir(repo);
147
+ expect(existsSync(join(common!, EVIDENCE_CONSULT_LOCK_RELATIVE_PATH))).toBe(false);
148
+ });
149
+
150
+ it("AC-3: assertJudgedEvidence throws EVIDENCE-MODE on trusted:false", () => {
151
+ expect(() =>
152
+ assertJudgedEvidence({ exitCode: 0, stdout: "", stderr: "", trusted: false }),
153
+ ).toThrowError(/EVIDENCE-MODE/);
154
+ expect(() =>
155
+ assertJudgedEvidence({ exitCode: 0, stdout: "", stderr: "", trusted: true }),
156
+ ).not.toThrow();
157
+ });
158
+ });
159
+
160
+ describe("consult budget (AC-5)", () => {
161
+ it("AC-5: a breach refuses EVIDENCE-BUDGET naming phase and elapsed vs budget", () => {
162
+ const startedAt = Date.now() - 10_000;
163
+ const refusal = evidenceBudgetBreach(["rev-parse", "--git-dir"], "arm", startedAt, 5_000);
164
+ expect(refusal).not.toBeNull();
165
+ expect(refusal!.exitCode).toBe(-1);
166
+ expect(refusal!.stderr).toContain("EVIDENCE-BUDGET");
167
+ expect(refusal!.stderr).toContain("arm");
168
+ expect(refusal!.stderr).toMatch(/elapsed > 5000ms budget/);
169
+ // No clock started → no budget accounting (preflight:false reads).
170
+ expect(evidenceBudgetBreach(["x"], "arm", undefined, 5)).toBeNull();
171
+ });
172
+ });
173
+
174
+ describe("bestEffort call-site scan", () => {
175
+ it("mode:'bestEffort' appears only in the enumerated non-judging call sites", () => {
176
+ const PKG_DIR = resolve(__dirname, "../..");
177
+ const ALLOWLIST = new Set(["digest.ts"]);
178
+ const offenders: string[] = [];
179
+ const scan = (dir: string) => {
180
+ for (const entry of readdirSync(dir, { withFileTypes: true })) {
181
+ const p = join(dir, entry.name);
182
+ const rel = relative(PKG_DIR, p).replaceAll("\\", "/");
183
+ if (entry.isDirectory()) {
184
+ if (rel === "src/tests" || entry.name === "tests" || entry.name === "node_modules") {
185
+ continue;
186
+ }
187
+ scan(p);
188
+ continue;
189
+ }
190
+ if (!entry.name.endsWith(".ts")) continue;
191
+ const content = readFileSync(p, "utf8");
192
+ if (/mode:\s*"bestEffort"/.test(content)) {
193
+ if (!ALLOWLIST.has(entry.name)) offenders.push(p);
194
+ }
195
+ }
196
+ };
197
+ for (const root of [join(PKG_DIR, "os"), join(PKG_DIR, "src")]) {
198
+ if (existsSync(root)) scan(root);
199
+ }
200
+ expect(offenders).toEqual([]);
201
+ });
202
+ });
@@ -19,6 +19,7 @@ import { promisify } from "node:util";
19
19
  import { join } from "node:path";
20
20
  import { tmpdir } from "node:os";
21
21
  import { runPinnedValidate } from "../../os/core/handlers/pinned-validate.ts";
22
+ import { isArchiveBlocked, loadPinnedManifest } from "../../os/core/handlers/pinned-check.ts";
22
23
  import type { ForgeCommandInput, ForgeRuntimeContext } from "../../src/types.ts";
23
24
 
24
25
  const execFileAsync = promisify(execFile);
@@ -145,4 +146,197 @@ describe("runPinnedValidate", () => {
145
146
  await rm(dir, { recursive: true, force: true });
146
147
  }
147
148
  });
149
+
150
+ test("passes an intra-dir move reported as D+A (rename detection off)", async () => {
151
+ const dir = await makeRepo();
152
+ try {
153
+ // A consumer's `diff.renames=false` (or a below-threshold similarity)
154
+ // splits the move into D + A — same exemption as the R pair.
155
+ await git(dir, ["config", "diff.renames", "false"]);
156
+ await mkdir(join(dir, "docs", "rfcs", "archive", "implemented"), { recursive: true });
157
+ await git(dir, ["mv", "docs/rfcs/rfc-0001.md", "docs/rfcs/archive/implemented/rfc-0001.md"]);
158
+
159
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
160
+ expect(result.data?.status).toBe("pass");
161
+ expect(result.data?.violations).toHaveLength(0);
162
+ } finally {
163
+ await rm(dir, { recursive: true, force: true });
164
+ }
165
+ });
166
+
167
+ test("passes an intra-dir move reported as D+M (destination already tracked)", async () => {
168
+ const dir = await makeRepo();
169
+ try {
170
+ // docs/rfcs/archive/rfc-0001.md already exists in HEAD — git reports
171
+ // `D docs/rfcs/rfc-0001.md` + `M docs/rfcs/archive/rfc-0001.md`, never R.
172
+ await mkdir(join(dir, "docs", "rfcs", "archive"), { recursive: true });
173
+ await writeFile(join(dir, "docs", "rfcs", "archive", "rfc-0001.md"), "# old\n");
174
+ await git(dir, ["add", "-A"]);
175
+ await git(dir, ["commit", "-m", "archive dir"]);
176
+ await writeFile(join(dir, "docs", "rfcs", "archive", "rfc-0001.md"), "# RFC 1\n");
177
+ await git(dir, ["rm", "docs/rfcs/rfc-0001.md"]);
178
+ await git(dir, ["add", "-A"]);
179
+
180
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
181
+ expect(result.data?.status).toBe("pass");
182
+ expect(result.data?.violations).toHaveLength(0);
183
+ } finally {
184
+ await rm(dir, { recursive: true, force: true });
185
+ }
186
+ });
187
+
188
+ test("still flags a delete when the same-basename file lands outside the pinned dir", async () => {
189
+ const dir = await makeRepo();
190
+ try {
191
+ await git(dir, ["config", "diff.renames", "false"]);
192
+ await mkdir(join(dir, "docs", "other"), { recursive: true });
193
+ await git(dir, ["mv", "docs/rfcs/rfc-0001.md", "docs/other/rfc-0001.md"]);
194
+
195
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
196
+ expect(result.data?.status).toBe("fail");
197
+ expect(
198
+ result.data?.violations.some(
199
+ (v) => v.path === "docs/rfcs/rfc-0001.md" && v.operation === "delete",
200
+ ),
201
+ ).toBe(true);
202
+ } finally {
203
+ await rm(dir, { recursive: true, force: true });
204
+ }
205
+ });
206
+
207
+ test("still flags a bare delete with no same-basename counterpart", async () => {
208
+ const dir = await makeRepo();
209
+ try {
210
+ await git(dir, ["config", "diff.renames", "false"]);
211
+ // Delete + unrelated add under the same pinned dir — not a move.
212
+ await git(dir, ["rm", "docs/rfcs/rfc-0001.md"]);
213
+ await mkdir(join(dir, "docs", "rfcs"), { recursive: true });
214
+ await writeFile(join(dir, "docs", "rfcs", "rfc-0002.md"), "# RFC 2\n");
215
+ await git(dir, ["add", "-A"]);
216
+
217
+ const result = await runPinnedValidate(makeInput(), makeContext(dir));
218
+ expect(result.data?.status).toBe("fail");
219
+ expect(
220
+ result.data?.violations.some(
221
+ (v) => v.path === "docs/rfcs/rfc-0001.md" && v.operation === "delete",
222
+ ),
223
+ ).toBe(true);
224
+ } finally {
225
+ await rm(dir, { recursive: true, force: true });
226
+ }
227
+ });
228
+ });
229
+
230
+ describe("isArchiveBlocked (F-0004 archive opt-out)", () => {
231
+ async function makeManifestRepo(entries: string): Promise<string> {
232
+ const dir = await makeTempDir();
233
+ await mkdir(join(dir, ".forge"), { recursive: true });
234
+ await writeFile(join(dir, ".forge", "pinned.yaml"), entries);
235
+ return dir;
236
+ }
237
+
238
+ test("protect-pinned dir allows the intra-dir archive move (default contract)", async () => {
239
+ const dir = await makeManifestRepo(
240
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n",
241
+ );
242
+ try {
243
+ const manifest = (await loadPinnedManifest(dir))!;
244
+ expect(
245
+ isArchiveBlocked(manifest, "docs/rfcs/rfc-1.md", "docs/rfcs/archive/rfc-1.md"),
246
+ ).toBeNull();
247
+ expect(
248
+ isArchiveBlocked(manifest, "docs/rfcs/rfc-1.md", "docs/other/rfc-1.md"),
249
+ )?.not.toBeNull();
250
+ } finally {
251
+ await rm(dir, { recursive: true, force: true });
252
+ }
253
+ });
254
+
255
+ test("archive: false blocks the intra-dir move entirely", async () => {
256
+ const dir = await makeManifestRepo(
257
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n archive: false\n",
258
+ );
259
+ try {
260
+ const manifest = (await loadPinnedManifest(dir))!;
261
+ const blocked = isArchiveBlocked(
262
+ manifest,
263
+ "docs/rfcs/rfc-1.md",
264
+ "docs/rfcs/archive/rfc-1.md",
265
+ );
266
+ expect(blocked).not.toBeNull();
267
+ expect(blocked?.archive).toBe(false);
268
+ } finally {
269
+ await rm(dir, { recursive: true, force: true });
270
+ }
271
+ });
272
+
273
+ test("freeze mode blocks the intra-dir move too", async () => {
274
+ const dir = await makeManifestRepo(
275
+ "pinned:\n - path: docs/rfcs/\n mode: freeze\n reason: locked\n",
276
+ );
277
+ try {
278
+ const manifest = (await loadPinnedManifest(dir))!;
279
+ expect(
280
+ isArchiveBlocked(manifest, "docs/rfcs/rfc-1.md", "docs/rfcs/archive/rfc-1.md"),
281
+ ).not.toBeNull();
282
+ } finally {
283
+ await rm(dir, { recursive: true, force: true });
284
+ }
285
+ });
286
+
287
+ test("non-pinned source is never blocked", async () => {
288
+ const dir = await makeManifestRepo(
289
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n archive: false\n",
290
+ );
291
+ try {
292
+ const manifest = (await loadPinnedManifest(dir))!;
293
+ expect(isArchiveBlocked(manifest, "docs/other/x.md", "docs/rfcs/x.md")).toBeNull();
294
+ } finally {
295
+ await rm(dir, { recursive: true, force: true });
296
+ }
297
+ });
298
+
299
+ test("a non-boolean archive value is malformed", async () => {
300
+ const dir = await makeManifestRepo(
301
+ "pinned:\n - path: docs/rfcs/\n mode: protect\n reason: RFC directory\n archive: never\n",
302
+ );
303
+ try {
304
+ await expect(loadPinnedManifest(dir)).rejects.toThrow(/invalid archive/);
305
+ } finally {
306
+ await rm(dir, { recursive: true, force: true });
307
+ }
308
+ });
309
+ });
310
+
311
+ describe("session.archive with archive:false entries (F-0004)", () => {
312
+ const SESSION_FM = (date: string) =>
313
+ `---\nid: s-1\ndate: ${date}\ntype: session\n---\n\n# session\n`;
314
+
315
+ test("docs.archive family skips files under archive:false dirs entirely", async () => {
316
+ const { runSessionArchive } = await import("../../os/session/handlers/archive.ts");
317
+ const dir = await makeTempDir();
318
+ await mkdir(join(dir, ".forge"), { recursive: true });
319
+ await writeFile(
320
+ join(dir, ".forge", "pinned.yaml"),
321
+ "pinned:\n - path: docs/sessions/\n mode: protect\n reason: Session directory\n archive: false\n",
322
+ );
323
+ await mkdir(join(dir, "docs", "sessions"), { recursive: true });
324
+ await writeFile(
325
+ join(dir, "docs", "sessions", "2020-01-01-00-00-00-aaaaaa.md"),
326
+ SESSION_FM("2020-01-01"),
327
+ );
328
+ try {
329
+ const result = await runSessionArchive(
330
+ { argv: [], flags: { "max-age-days": "7" } },
331
+ makeContext(dir),
332
+ );
333
+ expect(result.data?.moved).toHaveLength(0);
334
+ expect(result.data?.skipped.some((s) => s.reason?.includes("pinned"))).toBe(true);
335
+ // File stays in place — nothing was moved.
336
+ const { existsSync } = await import("node:fs");
337
+ expect(existsSync(join(dir, "docs", "sessions", "2020-01-01-00-00-00-aaaaaa.md"))).toBe(true);
338
+ } finally {
339
+ await rm(dir, { recursive: true, force: true });
340
+ }
341
+ });
148
342
  });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * RFC-1517 self-scan regression: the real werkstatt workspace must carry zero
3
+ * PKG-HEALTH-10 violations — any shipped `../` literal resolving outside its
4
+ * package root is either a genuine defect (fix it), a monorepo-bound file
5
+ * (excludePathSegments), or a justified non-path use (same-line suppression /
6
+ * pkgHealth10Suppressions). This file is monorepo-only: it reads the real
7
+ * workspace tree, so it lives in excludePathSegments for the standalone
8
+ * extract.
9
+ */
10
+ import { test, expect } from "vitest";
11
+ import { join } from "node:path";
12
+ import type { ForgeCommandInput, ForgeRuntimeContext } from "../../src/types.ts";
13
+ import { runPackageHealth } from "../../os/core/handlers/package-health.ts";
14
+
15
+ test("PKG-HEALTH-10 reports no violations on the real workspace", async () => {
16
+ const context: ForgeRuntimeContext = {
17
+ workspaceRoot: join(process.cwd(), "..", ".."),
18
+ logger: { section: () => {}, info: () => {}, warn: () => {}, error: () => {}, success: () => {} },
19
+ dryRun: false,
20
+ outputFormat: "json",
21
+ };
22
+ const input: ForgeCommandInput = { argv: [], flags: {} };
23
+ const result = await runPackageHealth(input, context, () => ({ ok: true, detail: "" }));
24
+ const v10 =
25
+ result.data?.violations
26
+ .filter((v) => v.ruleId === "PKG-HEALTH-10")
27
+ .map((v) => `${v.packageName}: ${v.message}`) ?? [];
28
+ expect(v10).toEqual([]);
29
+ }, 120_000);
@@ -11,6 +11,7 @@ shebang first line and a clean `sh -n` parse.</purpose>
11
11
  <CHANGE_SUMMARY>
12
12
  <item>RFC-1500: step 1 — profile flow hooks contract test</item>
13
13
  <item>RFC-1500: step 1 — profile flow hooks</item>
14
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
14
15
  </CHANGE_SUMMARY>
15
16
  */
16
17
 
@@ -10,6 +10,7 @@ Unit tests for profile schema covering its documented public contract and regres
10
10
  <CHANGE_SUMMARY>
11
11
  <item>RFC-0638: initial domain field tests — parsing, defaults, validation, backward compat.</item>
12
12
  <item>RFC-1508: implement RFC-1508 — system profile, system map schemas and system.map.validate</item>
13
+ <item>RFC-1639: revert container-scope contracts — superfolder governance moves to the system hub</item>
13
14
  </CHANGE_SUMMARY>
14
15
  */
15
16