@warpgogol/forge 6.3.6 → 8.0.2

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 (405) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +2 -1
  3. package/bin/cli.js +6 -12
  4. package/bin/resolve-entry.js +24 -0
  5. package/dist/os/compass/comment-safety.d.ts +83 -0
  6. package/dist/os/compass/comment-safety.d.ts.map +1 -0
  7. package/dist/os/compass/comment-safety.js +305 -0
  8. package/dist/os/compass/comment-safety.js.map +1 -0
  9. package/dist/os/compass/compass.module.d.ts.map +1 -1
  10. package/dist/os/compass/compass.module.js +47 -4
  11. package/dist/os/compass/compass.module.js.map +1 -1
  12. package/dist/os/compass/handlers/compass-change-summary-handler.d.ts +2 -1
  13. package/dist/os/compass/handlers/compass-change-summary-handler.d.ts.map +1 -1
  14. package/dist/os/compass/handlers/compass-change-summary-handler.js +34 -10
  15. package/dist/os/compass/handlers/compass-change-summary-handler.js.map +1 -1
  16. package/dist/os/compass/handlers/compass-docs-scaffold.d.ts.map +1 -1
  17. package/dist/os/compass/handlers/compass-docs-scaffold.js +54 -17
  18. package/dist/os/compass/handlers/compass-docs-scaffold.js.map +1 -1
  19. package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts +14 -0
  20. package/dist/os/compass/handlers/compass-header-scaffold-handler.d.ts.map +1 -0
  21. package/dist/os/compass/handlers/compass-header-scaffold-handler.js +261 -0
  22. package/dist/os/compass/handlers/compass-header-scaffold-handler.js.map +1 -0
  23. package/dist/os/compass/handlers/compass-header-scaffold.d.ts +31 -0
  24. package/dist/os/compass/handlers/compass-header-scaffold.d.ts.map +1 -0
  25. package/dist/os/compass/handlers/compass-header-scaffold.js +739 -0
  26. package/dist/os/compass/handlers/compass-header-scaffold.js.map +1 -0
  27. package/dist/os/compass/handlers/compass-inventory-handler.d.ts.map +1 -1
  28. package/dist/os/compass/handlers/compass-inventory-handler.js +8 -4
  29. package/dist/os/compass/handlers/compass-inventory-handler.js.map +1 -1
  30. package/dist/os/compass/handlers/compass-inventory.d.ts +6 -0
  31. package/dist/os/compass/handlers/compass-inventory.d.ts.map +1 -1
  32. package/dist/os/compass/handlers/compass-inventory.js +28 -13
  33. package/dist/os/compass/handlers/compass-inventory.js.map +1 -1
  34. package/dist/os/compass/handlers/compass-migrate-handler.d.ts.map +1 -1
  35. package/dist/os/compass/handlers/compass-migrate-handler.js +12 -26
  36. package/dist/os/compass/handlers/compass-migrate-handler.js.map +1 -1
  37. package/dist/os/compass/handlers/compass-migrate.d.ts +15 -2
  38. package/dist/os/compass/handlers/compass-migrate.d.ts.map +1 -1
  39. package/dist/os/compass/handlers/compass-migrate.js +58 -20
  40. package/dist/os/compass/handlers/compass-migrate.js.map +1 -1
  41. package/dist/os/compass/handlers/git-revision.d.ts +10 -0
  42. package/dist/os/compass/handlers/git-revision.d.ts.map +1 -1
  43. package/dist/os/compass/handlers/git-revision.js +58 -4
  44. package/dist/os/compass/handlers/git-revision.js.map +1 -1
  45. package/dist/os/compass/handlers/summary-record.d.ts +20 -5
  46. package/dist/os/compass/handlers/summary-record.d.ts.map +1 -1
  47. package/dist/os/compass/handlers/summary-record.js +175 -44
  48. package/dist/os/compass/handlers/summary-record.js.map +1 -1
  49. package/dist/os/compass/index.d.ts +1 -0
  50. package/dist/os/compass/index.d.ts.map +1 -1
  51. package/dist/os/compass/index.js +2 -0
  52. package/dist/os/compass/index.js.map +1 -1
  53. package/dist/os/compass/policy.d.ts +9 -0
  54. package/dist/os/compass/policy.d.ts.map +1 -1
  55. package/dist/os/compass/policy.js +11 -2
  56. package/dist/os/compass/policy.js.map +1 -1
  57. package/dist/os/core/core.module.js +1 -1
  58. package/dist/os/core/handlers/package-health.d.ts.map +1 -1
  59. package/dist/os/core/handlers/package-health.js +1 -6
  60. package/dist/os/core/handlers/package-health.js.map +1 -1
  61. package/dist/os/queue/types.d.ts +2 -0
  62. package/dist/os/queue/types.d.ts.map +1 -1
  63. package/dist/os/queue/types.js +3 -1
  64. package/dist/os/queue/types.js.map +1 -1
  65. package/dist/os/rfc/acceptance.d.ts.map +1 -1
  66. package/dist/os/rfc/acceptance.js +66 -2
  67. package/dist/os/rfc/acceptance.js.map +1 -1
  68. package/dist/os/rfc/decision-log.d.ts.map +1 -1
  69. package/dist/os/rfc/decision-log.js +21 -3
  70. package/dist/os/rfc/decision-log.js.map +1 -1
  71. package/dist/os/rfc/dna-trace.d.ts +2 -0
  72. package/dist/os/rfc/dna-trace.d.ts.map +1 -1
  73. package/dist/os/rfc/dna-trace.js +13 -4
  74. package/dist/os/rfc/dna-trace.js.map +1 -1
  75. package/dist/os/rfc/handlers/implement-stamp-origin.d.ts +37 -0
  76. package/dist/os/rfc/handlers/implement-stamp-origin.d.ts.map +1 -0
  77. package/dist/os/rfc/handlers/implement-stamp-origin.js +118 -0
  78. package/dist/os/rfc/handlers/implement-stamp-origin.js.map +1 -0
  79. package/dist/os/rfc/handlers/implement-stamp.d.ts +41 -1
  80. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  81. package/dist/os/rfc/handlers/implement-stamp.js +645 -47
  82. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  83. package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts +42 -0
  84. package/dist/os/rfc/handlers/rfc-evidence-sync.d.ts.map +1 -0
  85. package/dist/os/rfc/handlers/rfc-evidence-sync.js +147 -0
  86. package/dist/os/rfc/handlers/rfc-evidence-sync.js.map +1 -0
  87. package/dist/os/rfc/handlers/validate-rules.d.ts +9 -1
  88. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  89. package/dist/os/rfc/handlers/validate-rules.js +71 -10
  90. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  91. package/dist/os/rfc/reachable-symbol.d.ts +17 -0
  92. package/dist/os/rfc/reachable-symbol.d.ts.map +1 -0
  93. package/dist/os/rfc/reachable-symbol.js +376 -0
  94. package/dist/os/rfc/reachable-symbol.js.map +1 -0
  95. package/dist/os/rfc/rfc.module.d.ts.map +1 -1
  96. package/dist/os/rfc/rfc.module.js +99 -10
  97. package/dist/os/rfc/rfc.module.js.map +1 -1
  98. package/dist/os/rfc/types.d.ts +112 -14
  99. package/dist/os/rfc/types.d.ts.map +1 -1
  100. package/dist/os/rfc/types.js +27 -10
  101. package/dist/os/rfc/types.js.map +1 -1
  102. package/dist/os/rfc/verification-evidence.d.ts +25 -0
  103. package/dist/os/rfc/verification-evidence.d.ts.map +1 -1
  104. package/dist/os/rfc/verification-evidence.js +244 -13
  105. package/dist/os/rfc/verification-evidence.js.map +1 -1
  106. package/dist/os/rfc/verification-origin.d.ts +58 -0
  107. package/dist/os/rfc/verification-origin.d.ts.map +1 -0
  108. package/dist/os/rfc/verification-origin.js +346 -0
  109. package/dist/os/rfc/verification-origin.js.map +1 -0
  110. package/dist/os/rfc/verification-refresh.d.ts.map +1 -1
  111. package/dist/os/rfc/verification-refresh.js +11 -1
  112. package/dist/os/rfc/verification-refresh.js.map +1 -1
  113. package/dist/os/rfc/verify-workspace.d.ts +23 -0
  114. package/dist/os/rfc/verify-workspace.d.ts.map +1 -0
  115. package/dist/os/rfc/verify-workspace.js +278 -0
  116. package/dist/os/rfc/verify-workspace.js.map +1 -0
  117. package/dist/os/session/handlers/metrics-rfc.d.ts.map +1 -1
  118. package/dist/os/session/handlers/metrics-rfc.js +3 -0
  119. package/dist/os/session/handlers/metrics-rfc.js.map +1 -1
  120. package/dist/os/spec/spec-status.d.ts.map +1 -1
  121. package/dist/os/spec/spec-status.js +5 -23
  122. package/dist/os/spec/spec-status.js.map +1 -1
  123. package/dist/os/spec/spec-validate.d.ts.map +1 -1
  124. package/dist/os/spec/spec-validate.js +30 -9
  125. package/dist/os/spec/spec-validate.js.map +1 -1
  126. package/dist/os/workflow/handlers.d.ts +0 -4
  127. package/dist/os/workflow/handlers.d.ts.map +1 -1
  128. package/dist/os/workflow/handlers.js +9 -36
  129. package/dist/os/workflow/handlers.js.map +1 -1
  130. package/dist/os/workflow/index.d.ts +2 -2
  131. package/dist/os/workflow/index.d.ts.map +1 -1
  132. package/dist/os/workflow/index.js +1 -1
  133. package/dist/os/workflow/index.js.map +1 -1
  134. package/dist/os/workflow/types.d.ts +0 -19
  135. package/dist/os/workflow/types.d.ts.map +1 -1
  136. package/dist/os/workflow/types.js +0 -2
  137. package/dist/os/workflow/types.js.map +1 -1
  138. package/dist/os/workflow/workflow.module.d.ts.map +1 -1
  139. package/dist/os/workflow/workflow.module.js +6 -15
  140. package/dist/os/workflow/workflow.module.js.map +1 -1
  141. package/dist/src/config/forge-config.d.ts +5 -0
  142. package/dist/src/config/forge-config.d.ts.map +1 -1
  143. package/dist/src/config/forge-config.js +5 -2
  144. package/dist/src/config/forge-config.js.map +1 -1
  145. package/dist/src/onboarding/agents-generate.js +1 -1
  146. package/dist/src/onboarding/doctor.js +3 -3
  147. package/dist/src/onboarding/doctor.js.map +1 -1
  148. package/dist/src/onboarding/init.js +2 -2
  149. package/dist/src/onboarding/nested-agents-templates.js +1 -1
  150. package/dist/src/onboarding/prettierignore.js +1 -1
  151. package/dist/src/onboarding/upgrade.js +2 -2
  152. package/dist/src/onboarding/workspace-discovery.js +1 -1
  153. package/dist/src/profiles/profile-schema.d.ts +2 -0
  154. package/dist/src/profiles/profile-schema.d.ts.map +1 -1
  155. package/dist/src/profiles/profile-schema.js +1 -0
  156. package/dist/src/profiles/profile-schema.js.map +1 -1
  157. package/dist/src/profiles/stack-profile.d.ts +1 -0
  158. package/dist/src/profiles/stack-profile.d.ts.map +1 -1
  159. package/dist/src/skill-schema.d.ts +2 -0
  160. package/dist/src/skill-schema.d.ts.map +1 -1
  161. package/dist/src/skill-schema.js +9 -1
  162. package/dist/src/skill-schema.js.map +1 -1
  163. package/dist/src/types.d.ts +23 -0
  164. package/dist/src/types.d.ts.map +1 -1
  165. package/dist/src/types.js +2 -1
  166. package/dist/src/types.js.map +1 -1
  167. package/docs/reference/cli.md +0 -1
  168. package/docs/reference/programmatic-api.md +1 -1
  169. package/os/adr/handlers/validate.test.ts +14 -0
  170. package/os/compass/comment-safety.ts +331 -0
  171. package/os/compass/compass.module.ts +50 -4
  172. package/os/compass/handlers/compass-change-summary-handler.ts +41 -11
  173. package/os/compass/handlers/compass-docs-scaffold.ts +59 -17
  174. package/os/compass/handlers/compass-game-extensions.test.ts +3 -7
  175. package/os/compass/handlers/compass-header-scaffold-handler.ts +352 -0
  176. package/os/compass/handlers/compass-header-scaffold.ts +847 -0
  177. package/os/compass/handlers/compass-inventory-handler.ts +9 -4
  178. package/os/compass/handlers/compass-inventory.ts +29 -13
  179. package/os/compass/handlers/compass-migrate-handler.ts +13 -27
  180. package/os/compass/handlers/compass-migrate.ts +77 -21
  181. package/os/compass/handlers/git-revision.ts +59 -4
  182. package/os/compass/handlers/resolve-scan-root-package.test.ts +14 -0
  183. package/os/compass/handlers/resolve-scan-root-workpiece.test.ts +14 -0
  184. package/os/compass/handlers/summary-record.ts +194 -41
  185. package/os/compass/handlers/tests/compass-audit-plan.test.ts +6 -0
  186. package/os/compass/handlers/tests/compass-audit-record.test.ts +6 -0
  187. package/os/compass/handlers/tests/compass-audit-validate.test.ts +6 -0
  188. package/os/compass/handlers/tests/compass-change-summary-handler.test.ts +131 -0
  189. package/os/compass/handlers/tests/compass-docs-validate.test.ts +6 -0
  190. package/os/compass/handlers/tests/compass-header-scaffold.test.ts +896 -0
  191. package/os/compass/handlers/tests/compass-ledger-scope.test.ts +6 -0
  192. package/os/compass/handlers/tests/compass-migrate.test.ts +87 -9
  193. package/os/compass/handlers/tests/compass-policy.test.ts +1 -1
  194. package/os/compass/handlers/tests/compass-text-safety.test.ts +271 -0
  195. package/os/compass/handlers/tests/compass-v2-contract.test.ts +52 -3
  196. package/os/compass/handlers/tests/summary-record.test.ts +324 -3
  197. package/os/compass/index.ts +15 -0
  198. package/os/compass/policy.ts +27 -2
  199. package/os/core/core.module.ts +1 -1
  200. package/os/core/handlers/invariant-engine.test.ts +3 -1
  201. package/os/core/handlers/note-frontmatter-validate.test.ts +6 -1
  202. package/os/core/handlers/note-link-validate.test.ts +6 -1
  203. package/os/core/handlers/note-orphan-detect.test.ts +6 -1
  204. package/os/core/handlers/package-health.test.ts +6 -0
  205. package/os/core/handlers/package-health.ts +1 -6
  206. package/os/mission/handlers/archive.test.ts +14 -0
  207. package/os/naming/naming-convention.test.ts +14 -0
  208. package/os/queue/decision-ledger.test.ts +27 -4
  209. package/os/queue/queue-validate.test.ts +14 -0
  210. package/os/queue/types.ts +3 -1
  211. package/os/rfc/acceptance-reachable.test.ts +146 -0
  212. package/os/rfc/acceptance.test.ts +136 -0
  213. package/os/rfc/acceptance.ts +71 -2
  214. package/os/rfc/decision-log.ts +22 -4
  215. package/os/rfc/dna-trace.ts +17 -5
  216. package/os/rfc/frontmatter-io.test.ts +14 -0
  217. package/os/rfc/handlers/implement-stamp-acceptance-verification.test.ts +81 -0
  218. package/os/rfc/handlers/implement-stamp-binding.test.ts +79 -0
  219. package/os/rfc/handlers/implement-stamp-origin.test.ts +132 -0
  220. package/os/rfc/handlers/implement-stamp-origin.ts +154 -0
  221. package/os/rfc/handlers/implement-stamp-stale.test.ts +285 -0
  222. package/os/rfc/handlers/implement-stamp.ts +783 -55
  223. package/os/rfc/handlers/lifecycle.test.ts +14 -0
  224. package/os/rfc/handlers/rfc-evidence-sync.ts +221 -0
  225. package/os/rfc/handlers/validate-rules-rfc0997.test.ts +14 -0
  226. package/os/rfc/handlers/validate-rules-rfc1006.test.ts +14 -0
  227. package/os/rfc/handlers/validate-rules-rfc1330.test.ts +120 -0
  228. package/os/rfc/handlers/validate-rules-rfc1334.test.ts +65 -0
  229. package/os/rfc/handlers/validate-rules.test.ts +56 -0
  230. package/os/rfc/handlers/validate-rules.ts +101 -10
  231. package/os/rfc/handlers/validate.test.ts +4 -3
  232. package/os/rfc/reachable-symbol.ts +441 -0
  233. package/os/rfc/rfc-0000-template.md +21 -1
  234. package/os/rfc/rfc-create-concurrent.test.ts +6 -0
  235. package/os/rfc/rfc-create-hint.test.ts +6 -0
  236. package/os/rfc/rfc-read-only-no-side-effects.test.ts +6 -0
  237. package/os/rfc/rfc.module.ts +106 -10
  238. package/os/rfc/types.ts +151 -14
  239. package/os/rfc/verification-emit-check.test.ts +215 -0
  240. package/os/rfc/verification-emit-freshness.test.ts +415 -0
  241. package/os/rfc/verification-emit.test.ts +14 -0
  242. package/os/rfc/verification-evidence.ts +301 -13
  243. package/os/rfc/verification-normalize.test.ts +75 -0
  244. package/os/rfc/verification-origin.test.ts +236 -0
  245. package/os/rfc/verification-origin.ts +417 -0
  246. package/os/rfc/verification-refresh.test.ts +14 -0
  247. package/os/rfc/verification-refresh.ts +12 -1
  248. package/os/rfc/verifier/rfc-1333/imp12-binding.acceptance.test.ts +78 -0
  249. package/os/rfc/verifier/rfc-1333/imp12-gate.acceptance.test.ts +81 -0
  250. package/os/rfc/verifier/rfc-1333/skills-and-types.acceptance.test.ts +50 -0
  251. package/os/rfc/verifier/rfc-1333/verify-workspace.acceptance.test.ts +103 -0
  252. package/os/rfc/verify-workspace.test.ts +122 -0
  253. package/os/rfc/verify-workspace.ts +342 -0
  254. package/os/session/handlers/metrics-rfc.ts +3 -0
  255. package/os/spec/spec-status.test.ts +130 -0
  256. package/os/spec/spec-status.ts +5 -18
  257. package/os/spec/spec-validate.test.ts +76 -1
  258. package/os/spec/spec-validate.ts +26 -7
  259. package/os/workflow/handlers.ts +8 -42
  260. package/os/workflow/index.ts +1 -4
  261. package/os/workflow/types.ts +0 -22
  262. package/os/workflow/workflow.module.ts +6 -16
  263. package/package.json +1 -1
  264. package/skills/_shared/agent-operating-model.md +83 -0
  265. package/skills/_shared/fo-pipeline-conventions.md +1 -0
  266. package/skills/fo/fo-add-tests/SKILL.md +14 -0
  267. package/skills/fo/fo-fix/SKILL.md +2 -1
  268. package/skills/fo/fo-handoff/SKILL.md +1 -1
  269. package/skills/fo/fo-idea/SKILL.md +6 -3
  270. package/skills/fo/fo-idea-create-rfc/acceptance-criteria-standard.md +8 -0
  271. package/skills/fo/fo-idea-i-just-want-to-see-the-result/SKILL.md +4 -2
  272. package/skills/fo/fo-idea-implement/SKILL.md +68 -53
  273. package/skills/fo/fo-idea-plan/SKILL.md +3 -1
  274. package/skills/fo/fo-review/SKILL.md +12 -0
  275. package/skills/fo/fo-session-save/learned-principles.md +13 -0
  276. package/skills/fo/fo-step-commit/SKILL.md +1 -1
  277. package/src/bin-entry.test.ts +37 -0
  278. package/src/compass/contract-registry.test.ts +14 -0
  279. package/src/compass/types.test.ts +14 -0
  280. package/src/config/__tests__/resolve-terminology.test.ts +14 -0
  281. package/src/config/forge-config.test.ts +14 -0
  282. package/src/config/forge-config.ts +7 -2
  283. package/src/forge-module.test.ts +14 -0
  284. package/src/knowledge/__tests__/promote.test.ts +14 -0
  285. package/src/knowledge/__tests__/serialize.test.ts +14 -0
  286. package/src/knowledge/__tests__/sync.test.ts +4 -1
  287. package/src/knowledge/budgets.test.ts +14 -0
  288. package/src/knowledge/compact.test.ts +14 -0
  289. package/src/knowledge/parse.test.ts +14 -0
  290. package/src/knowledge/schema.test.ts +14 -0
  291. package/src/migration-adapters/__tests__/ignored-files.test.ts +14 -0
  292. package/src/migration-adapters/__tests__/registry.test.ts +14 -0
  293. package/src/migration-adapters/__tests__/types.test.ts +14 -0
  294. package/src/onboarding/__tests__/workspace-discovery.test.ts +14 -0
  295. package/src/onboarding/agents-generate.ts +1 -1
  296. package/src/onboarding/compass-docs/semantic-layer-block.test.ts +6 -0
  297. package/src/onboarding/create.test.ts +14 -0
  298. package/src/onboarding/doctor-token-check.test.ts +3 -0
  299. package/src/onboarding/doctor.test.ts +14 -0
  300. package/src/onboarding/doctor.ts +3 -3
  301. package/src/onboarding/init.test.ts +14 -0
  302. package/src/onboarding/init.ts +2 -2
  303. package/src/onboarding/nested-agents-templates.ts +1 -1
  304. package/src/onboarding/prettierignore.ts +1 -1
  305. package/src/onboarding/scaffold.test.ts +14 -0
  306. package/src/onboarding/site-workshop-profile.test.ts +3 -0
  307. package/src/onboarding/templates/behavioral-layer-core.md +8 -0
  308. package/src/onboarding/upgrade.test.ts +14 -0
  309. package/src/onboarding/upgrade.ts +2 -2
  310. package/src/onboarding/workspace-discovery.ts +1 -1
  311. package/src/pipeline-status.test.ts +14 -0
  312. package/src/plugin/forge-plugin-manifest.test.ts +14 -0
  313. package/src/profiles/__tests__/profile-schema.test.ts +14 -0
  314. package/src/profiles/__tests__/stack-profile.test.ts +14 -0
  315. package/src/profiles/__tests__/terminology-utils.test.ts +14 -0
  316. package/src/profiles/profile-schema.ts +1 -0
  317. package/src/skill-schema.ts +9 -1
  318. package/src/tests/acceptance-criteria.test.ts +14 -0
  319. package/src/tests/acceptance-probe-kinds.test.ts +14 -0
  320. package/src/tests/adr-implement-stamp.test.ts +14 -0
  321. package/src/tests/agents-generate-domain.test.ts +3 -0
  322. package/src/tests/agents-generate.test.ts +3 -0
  323. package/src/tests/bindings-schema.test.ts +2 -0
  324. package/src/tests/budgets.test.ts +14 -0
  325. package/src/tests/compact.test.ts +14 -0
  326. package/src/tests/compass-docs-flag.test.ts +6 -0
  327. package/src/tests/compass-docs-scaffold.test.ts +6 -0
  328. package/src/tests/compass-docs-validate-scope.test.ts +6 -0
  329. package/src/tests/contract-registry.test.ts +14 -0
  330. package/src/tests/create.test.ts +3 -0
  331. package/src/tests/discover-pack-skills.test.ts +14 -0
  332. package/src/tests/doctor-autonomy.test.ts +3 -0
  333. package/src/tests/doctor-bindings.test.ts +6 -1
  334. package/src/tests/doctor-dist-freshness.test.ts +26 -2
  335. package/src/tests/doctor-domain.test.ts +6 -1
  336. package/src/tests/doctor-fix.test.ts +3 -0
  337. package/src/tests/doctor-nested-agents.test.ts +3 -0
  338. package/src/tests/doctor-profile-id-known.test.ts +3 -0
  339. package/src/tests/doctor-skills-unmanaged.test.ts +3 -0
  340. package/src/tests/doctor-version-sync.test.ts +4 -1
  341. package/src/tests/editable-generated-region.test.ts +6 -3
  342. package/src/tests/exploration-handlers.test.ts +14 -0
  343. package/src/tests/file-size-lint.test.ts +6 -1
  344. package/src/tests/fixtures/agents-generate-business-before.txt +8 -0
  345. package/src/tests/forge-autonomy-validate.test.ts +3 -1
  346. package/src/tests/forge-config.test.ts +6 -1
  347. package/src/tests/forge-validate-compass-docs.test.ts +6 -0
  348. package/src/tests/fs-atomic.test.ts +14 -0
  349. package/src/tests/fs.test.ts +14 -0
  350. package/src/tests/generated-marker.test.ts +14 -0
  351. package/src/tests/hash.test.ts +14 -0
  352. package/src/tests/implement-stamp.test.ts +476 -10
  353. package/src/tests/init-bindings.test.ts +6 -1
  354. package/src/tests/knowledge-parse.test.ts +14 -0
  355. package/src/tests/knowledge-pbt.test.ts +14 -0
  356. package/src/tests/markdown-table.test.ts +6 -3
  357. package/src/tests/memory-compact.test.ts +3 -0
  358. package/src/tests/memory-scaffold.test.ts +6 -1
  359. package/src/tests/metrics-rfc-1053.test.ts +14 -0
  360. package/src/tests/migration-adapters.test.ts +3 -0
  361. package/src/tests/package-files.test.ts +4 -1
  362. package/src/tests/package-health-lint-surface.test.ts +3 -0
  363. package/src/tests/pinned-check.test.ts +14 -0
  364. package/src/tests/pinned-init.test.ts +14 -0
  365. package/src/tests/pinned-validate.test.ts +14 -0
  366. package/src/tests/plugin-manifest.test.ts +14 -0
  367. package/src/tests/prettierignore-manage.test.ts +3 -0
  368. package/src/tests/profile-schema.test.ts +6 -1
  369. package/src/tests/profile-validate.test.ts +6 -1
  370. package/src/tests/program-lease.test.ts +3 -0
  371. package/src/tests/program-paths-extended.test.ts +3 -0
  372. package/src/tests/program-paths.test.ts +3 -0
  373. package/src/tests/program-property.test.ts +3 -0
  374. package/src/tests/program-schemas.test.ts +3 -0
  375. package/src/tests/program-spec-node.test.ts +3 -0
  376. package/src/tests/promote.test.ts +14 -0
  377. package/src/tests/public-surface.test.ts +6 -1
  378. package/src/tests/registry.test.ts +14 -0
  379. package/src/tests/rfc-evidence-sync.test.ts +347 -0
  380. package/src/tests/rfc-implement-stamp-governance.test.ts +403 -0
  381. package/src/tests/scaffold-project.test.ts +3 -0
  382. package/src/tests/session-handlers.test.ts +14 -0
  383. package/src/tests/session-pbt.test.ts +14 -0
  384. package/src/tests/skill-agents-sync.test.ts +3 -4
  385. package/src/tests/skill-schema.test.ts +53 -0
  386. package/src/tests/skill-sync-marker.test.ts +3 -0
  387. package/src/tests/skill-validate-knowledge.test.ts +14 -0
  388. package/src/tests/skill-validate.test.ts +14 -0
  389. package/src/tests/stack-profile.test.ts +6 -1
  390. package/src/tests/string-utils.test.ts +14 -0
  391. package/src/tests/upgrade.test.ts +6 -1
  392. package/src/tests/werkstatt-lock.test.ts +14 -0
  393. package/src/tests/workspace-discovery-domain.test.ts +6 -1
  394. package/src/tests/workspace-discovery.test.ts +6 -1
  395. package/src/types.test.ts +14 -0
  396. package/src/types.ts +30 -1
  397. package/src/utils/__tests__/fs-idempotent.test.ts +17 -0
  398. package/src/utils/__tests__/fs-trash.test.ts +17 -0
  399. package/src/utils/fs-atomic.test.ts +17 -0
  400. package/src/utils/fs-trash-sync.test.ts +17 -0
  401. package/src/utils/fs.test.ts +17 -0
  402. package/src/utils/generated-marker.test.ts +17 -0
  403. package/src/utils/hash.test.ts +17 -0
  404. package/src/utils/string-utils.test.ts +17 -0
  405. package/src/validators/__tests__/note-orphan-detect.test.ts +14 -0
@@ -0,0 +1,236 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1330: verification-origin tests — derive probe origins over a real temporary git repository so range anchoring, rename-free file history, and trailer recognition are exercised end to end.</purpose>
4
+ <non-goals>
5
+ <item>Do not touch the workspace repository — every test builds its own repo under the OS temp dir.</item>
6
+ </non-goals>
7
+ </MODULE_CONTRACT>
8
+ <CHANGE_SUMMARY>
9
+ <item>RFC-1330: origin derivation tests over a temporary git repository.</item>
10
+ </CHANGE_SUMMARY>
11
+ */
12
+
13
+ import { execFileSync } from "node:child_process";
14
+ import * as fs from "node:fs/promises";
15
+ import * as os from "node:os";
16
+ import * as path from "node:path";
17
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
18
+ import { stringify as yamlStringify } from "yaml";
19
+ import {
20
+ attachProbeOrigins,
21
+ createOriginGit,
22
+ deriveProbeOrigins,
23
+ isPresenceProbe,
24
+ resolveImplementationRange,
25
+ } from "./verification-origin.ts";
26
+ import type { AcceptanceProbe, ProbeOriginRecord } from "./types.ts";
27
+
28
+ const RFC_PATH = "docs/rfcs/rfc-9001-fixture.md";
29
+ const TEST_PATH = "src/foo.test.ts";
30
+
31
+ let root: string;
32
+
33
+ function git(...args: string[]): string {
34
+ return execFileSync("git", ["-c", "core.hooksPath=/dev/null", ...args], {
35
+ cwd: root,
36
+ encoding: "utf8",
37
+ env: {
38
+ ...process.env,
39
+ GIT_AUTHOR_NAME: "t",
40
+ GIT_AUTHOR_EMAIL: "t@example.com",
41
+ GIT_COMMITTER_NAME: "t",
42
+ GIT_COMMITTER_EMAIL: "t@example.com",
43
+ },
44
+ });
45
+ }
46
+
47
+ async function write(rel: string, content: string): Promise<void> {
48
+ await fs.mkdir(path.dirname(path.join(root, rel)), { recursive: true });
49
+ await fs.writeFile(path.join(root, rel), content);
50
+ }
51
+
52
+ function rfcSource(
53
+ status: string,
54
+ acceptance: AcceptanceProbe[],
55
+ commands: Record<string, string[]> = {},
56
+ ): string {
57
+ const fm = yamlStringify({
58
+ id: "RFC-9001",
59
+ title: "Fixture",
60
+ status,
61
+ createdAt: "2026-10-18",
62
+ commands: { proposed: [], added: [], changed: [], removed: [], ...commands },
63
+ acceptance,
64
+ });
65
+ return `---\n${fm}---\n\n# RFC-9001\n`;
66
+ }
67
+
68
+ async function commit(message: string, files: Record<string, string>): Promise<string> {
69
+ for (const [rel, content] of Object.entries(files)) await write(rel, content);
70
+ git("add", "-A");
71
+ git("commit", "-q", "-m", message);
72
+ return git("rev-parse", "HEAD").trim();
73
+ }
74
+
75
+ const testProbe: AcceptanceProbe = {
76
+ probe: "test",
77
+ criterion: "AC-1",
78
+ file: TEST_PATH,
79
+ expect: { exitCode: 0 },
80
+ expectationSource: "requirement",
81
+ };
82
+
83
+ const VERIFIER_BODY =
84
+ "\n\nX-Expectation-Origin: independent-verifier\nX-Verifier-Report: docs/reviews/acceptance/rfc-9001/acceptance-2026-10-18-r0.md";
85
+
86
+ async function derive(probes: AcceptanceProbe[], commands: Record<string, string[]> = {}) {
87
+ const gitPort = createOriginGit(root);
88
+ const fm = { commands: { proposed: [], added: [], changed: [], ...commands } };
89
+ return deriveProbeOrigins({ git: gitPort, rfcRelPath: RFC_PATH, frontmatter: fm, probes });
90
+ }
91
+
92
+ beforeEach(async () => {
93
+ root = await fs.mkdtemp(path.join(os.tmpdir(), "rfc-origin-"));
94
+ git("init", "-q");
95
+ await commit("draft", {
96
+ [RFC_PATH]: rfcSource("draft", [testProbe]),
97
+ [TEST_PATH]: "it('x', () => {});\n",
98
+ });
99
+ });
100
+
101
+ afterEach(async () => {
102
+ await fs.rm(root, { recursive: true, force: true });
103
+ });
104
+
105
+ describe("deriveProbeOrigins (RFC-1330)", () => {
106
+ it("classes a test probe self when its file changed in the implementation range", async () => {
107
+ await commit("accept", { [RFC_PATH]: rfcSource("accepted", [testProbe]) });
108
+ const sha = await commit("unrelated subject", { [TEST_PATH]: "it('y', () => {});\n" });
109
+ const [record] = await derive([testProbe]);
110
+ expect(record?.derivedOrigin).toBe("self");
111
+ expect(record?.effective).toBe("self");
112
+ expect(record?.reason.join(" ")).toContain(sha.slice(0, 7));
113
+ });
114
+
115
+ it("classes a probe self when its declaration changed in the implementation range", async () => {
116
+ await commit("accept", { [RFC_PATH]: rfcSource("accepted", [testProbe]) });
117
+ const loosened: AcceptanceProbe = { ...testProbe, testName: "renamed" } as AcceptanceProbe;
118
+ await commit("edit probe", { [RFC_PATH]: rfcSource("accepted", [loosened]) });
119
+ const [record] = await derive([loosened]);
120
+ expect(record?.derivedOrigin).toBe("self");
121
+ });
122
+
123
+ it("classes a run probe self when its command is listed in the RFC commands block", async () => {
124
+ const runProbe: AcceptanceProbe = {
125
+ probe: "run",
126
+ criterion: "AC-2",
127
+ command: "werkstatt run demo.validate --json",
128
+ expect: { exitCode: 0 },
129
+ };
130
+ await commit("accept", {
131
+ [RFC_PATH]: rfcSource("accepted", [runProbe], { changed: ["demo.validate"] }),
132
+ });
133
+ const [record] = await derive([runProbe], { changed: ["demo.validate"] });
134
+ expect(record?.derivedOrigin).toBe("self");
135
+ });
136
+
137
+ it("keeps the declared origin for a test file touched only by sanctioned verifier commits", async () => {
138
+ await commit("accept", { [RFC_PATH]: rfcSource("accepted", [testProbe]) });
139
+ await commit(`test: verifier check${VERIFIER_BODY}`, { [TEST_PATH]: "it('v', () => {});\n" });
140
+ const [record] = await derive([testProbe]);
141
+ expect(record?.derivedOrigin).toBe("verifier");
142
+ expect(record?.effective).toBe("independent");
143
+ expect(record?.reason[0]).toContain("docs/reviews/acceptance/rfc-9001");
144
+ });
145
+
146
+ it("includes commits after the implementation commit up to HEAD in the range", async () => {
147
+ await commit("accept", { [RFC_PATH]: rfcSource("accepted", [testProbe]) });
148
+ await commit("implement: RFC-9001 step 1", { "src/foo.ts": "export const a = 1;\n" });
149
+ const later = await commit("fix: review finding", { [TEST_PATH]: "it('z', () => {});\n" });
150
+ const [record] = await derive([testProbe]);
151
+ expect(record?.derivedOrigin).toBe("self");
152
+ expect(record?.reason.join(" ")).toContain(later.slice(0, 7));
153
+ });
154
+
155
+ it("anchors the range base at the accepted transition of the RFC file", async () => {
156
+ // Maturation edits the probe declaration and the test file before acceptance.
157
+ const edited: AcceptanceProbe = { ...testProbe, testName: "maturation" } as AcceptanceProbe;
158
+ await commit("enhance", {
159
+ [RFC_PATH]: rfcSource("draft", [edited]),
160
+ [TEST_PATH]: "it('pre', () => {});\n",
161
+ });
162
+ const accept = await commit("accept", { [RFC_PATH]: rfcSource("accepted", [edited]) });
163
+ await commit("implement: later stamp-like edit", {
164
+ [RFC_PATH]: rfcSource("implemented", [edited]),
165
+ });
166
+ const range = await resolveImplementationRange(createOriginGit(root), RFC_PATH);
167
+ expect(range.base).toBe(accept);
168
+ const [record] = await derive([edited]);
169
+ expect(record?.derivedOrigin).not.toBe("self");
170
+ expect(record?.derivedOrigin).toBe("unchanged");
171
+ });
172
+
173
+ it("exempts declarations introduced by a verifier-trailer commit from the declaration rule", async () => {
174
+ await commit("accept", { [RFC_PATH]: rfcSource("accepted", [testProbe]) });
175
+ const verifierProbe: AcceptanceProbe = {
176
+ probe: "test",
177
+ criterion: "AC-1",
178
+ file: "src/verify.test.ts",
179
+ expect: { exitCode: 0 },
180
+ expectationSource: "independent",
181
+ };
182
+ await commit(`test: bind verifier check${VERIFIER_BODY}`, {
183
+ [RFC_PATH]: rfcSource("accepted", [testProbe, verifierProbe]),
184
+ "src/verify.test.ts": "it('cx-1', () => {});\n",
185
+ });
186
+ const records = await derive([testProbe, verifierProbe]);
187
+ expect(records[1]?.derivedOrigin).toBe("verifier");
188
+ expect(records[0]?.derivedOrigin).toBe("unchanged");
189
+ });
190
+
191
+ it("resolves the base when the accepted status is quoted", async () => {
192
+ const quoted = rfcSource("accepted", [testProbe]).replace(
193
+ "status: accepted",
194
+ 'status: "accepted"',
195
+ );
196
+ const accept = await commit("accept quoted", { [RFC_PATH]: quoted });
197
+ const range = await resolveImplementationRange(createOriginGit(root), RFC_PATH);
198
+ expect(range.base).toBe(accept);
199
+ });
200
+
201
+ it("reports unresolved when the RFC was never accepted", async () => {
202
+ const [record] = await derive([testProbe]);
203
+ expect(record?.derivedOrigin).toBe("unresolved");
204
+ expect(record?.effective).toBe("self");
205
+ });
206
+
207
+ it("attaches origin records only for RFCs created on or after the cutoff", async () => {
208
+ await commit("accept", { [RFC_PATH]: rfcSource("accepted", [testProbe]) });
209
+ const post = [{} as { origin?: ProbeOriginRecord }];
210
+ await attachProbeOrigins({
211
+ workspaceRoot: root,
212
+ rfcRelPath: RFC_PATH,
213
+ frontmatter: { createdAt: "2026-10-18" },
214
+ probes: [testProbe],
215
+ records: post,
216
+ });
217
+ expect(post[0]?.origin).toBeDefined();
218
+ const pre = [{} as { origin?: ProbeOriginRecord }];
219
+ await attachProbeOrigins({
220
+ workspaceRoot: root,
221
+ rfcRelPath: RFC_PATH,
222
+ frontmatter: { createdAt: "2026-10-01" },
223
+ probes: [testProbe],
224
+ records: pre,
225
+ });
226
+ expect(pre[0]?.origin, "pre-cutoff envelopes must stay byte-compatible").toBeUndefined();
227
+ });
228
+
229
+ it("classes structural probes as presence", () => {
230
+ expect(isPresenceProbe({ probe: "file-exists", path: "a.ts" })).toBe(true);
231
+ expect(isPresenceProbe({ probe: "file-contains", path: "src/a.ts", pattern: "x" })).toBe(true);
232
+ expect(isPresenceProbe({ probe: "file-contains", path: "AGENTS.md", pattern: "x" })).toBe(
233
+ false,
234
+ );
235
+ });
236
+ });
@@ -0,0 +1,417 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ RFC-1330: derive each acceptance probe's origin from git history of the RFC's
5
+ implementation range — base is the commit that transitioned the RFC file to
6
+ `status: accepted`, head is HEAD — so evidence envelopes record who authored
7
+ the expectation instead of trusting the declared expectationSource.
8
+ </purpose>
9
+ <non-goals>
10
+ <item>Do not decide stamp outcomes — implement-stamp owns RFC-IMP-10/11.</item>
11
+ <item>Do not prove authorship — git history and trailers are agent-writable; this raises the cost of mislabeling only.</item>
12
+ <item>Do not write the verifier trailer — only the RFC-1333 workflow commits it.</item>
13
+ </non-goals>
14
+ </MODULE_CONTRACT>
15
+ <KEY_DECISIONS>
16
+ <item>Range head is HEAD, never the auto-detected implementation commit — later fix commits stay in range.</item>
17
+ <item>Range base is the oldest commit adding `status: accepted` — maturation edits never count as self.</item>
18
+ <item>All in-range commits count regardless of subject, so unrelated subjects cannot hide test edits.</item>
19
+ <item>Unresolvable history yields `unresolved`, which tier rules treat as self.</item>
20
+ <item>Git access goes through an injectable port so derivation stays testable.</item>
21
+ <item>Declarations compare acceptance-time vs current bytes; a loosen-then-restore within range stays unchanged.</item>
22
+ </KEY_DECISIONS>
23
+ <CHANGE_SUMMARY>
24
+ <item>RFC-1330: git-derived probe origin — range anchoring, declaration/test/run rules, verifier trailers, presence classes, attachProbeOrigins.</item>
25
+ </CHANGE_SUMMARY>
26
+ */
27
+
28
+ import { execFile } from "../../src/utils/sync-fs.ts";
29
+ import { parseRfcFile } from "./frontmatter-io.ts";
30
+ import { RFC_ORIGIN_CUTOFF } from "./types.ts";
31
+ import type {
32
+ AcceptanceProbe,
33
+ DerivedProbeOrigin,
34
+ ImplementationRange,
35
+ ProbeOriginRecord,
36
+ RfcExpectationSource,
37
+ } from "./types.ts";
38
+
39
+ /** Git port — returns stdout, or null when the command failed. */
40
+ export interface OriginGit {
41
+ run(args: string[]): Promise<string | null>;
42
+ }
43
+
44
+ /**
45
+ * Env for git subprocesses that pass an explicit cwd: repository-locating
46
+ * variables inherited from a hook or outer git command (GIT_DIR, GIT_INDEX_FILE,
47
+ * …) would otherwise redirect every call to the outer repository.
48
+ */
49
+ export function gitEnvForCwd(): NodeJS.ProcessEnv {
50
+ const env = { ...process.env };
51
+ for (const key of [
52
+ "GIT_DIR",
53
+ "GIT_WORK_TREE",
54
+ "GIT_INDEX_FILE",
55
+ "GIT_PREFIX",
56
+ "GIT_COMMON_DIR",
57
+ "GIT_OBJECT_DIRECTORY",
58
+ ]) {
59
+ delete env[key];
60
+ }
61
+ return env;
62
+ }
63
+
64
+ export function createOriginGit(workspaceRoot: string): OriginGit {
65
+ return {
66
+ run: (args) =>
67
+ new Promise((resolve) => {
68
+ execFile(
69
+ "git",
70
+ args,
71
+ { cwd: workspaceRoot, timeout: 15000, maxBuffer: 32 * 1024 * 1024, env: gitEnvForCwd() },
72
+ (err, stdout) => resolve(err ? null : String(stdout)),
73
+ );
74
+ }),
75
+ };
76
+ }
77
+
78
+ export const VERIFIER_ORIGIN_TRAILER = "X-Expectation-Origin: independent-verifier";
79
+ const VERIFIER_ORIGIN_RE = /^X-Expectation-Origin:\s*independent-verifier\s*$/m;
80
+ const VERIFIER_REPORT_RE = /^X-Verifier-Report:\s*(\S+)\s*$/m;
81
+
82
+ /** True when a commit body carries the sanctioned verifier trailer pair. */
83
+ export function hasVerifierTrailers(body: string): boolean {
84
+ return VERIFIER_ORIGIN_RE.test(body) && VERIFIER_REPORT_RE.test(body);
85
+ }
86
+
87
+ function verifierReportOf(body: string): string | null {
88
+ return VERIFIER_REPORT_RE.exec(body)?.[1] ?? null;
89
+ }
90
+
91
+ const DOC_EXTENSIONS = [".md", ".mdx", ".txt", ".xml"];
92
+
93
+ export function isDocPath(path: string): boolean {
94
+ const lower = path.toLowerCase();
95
+ return DOC_EXTENSIONS.some((ext) => lower.endsWith(ext));
96
+ }
97
+
98
+ /**
99
+ * Presence probes prove structure, not behavior: `file-exists`,
100
+ * `command-registered`, and `file-contains` / `json-schema` over non-doc
101
+ * targets. Their origin is not counted toward tier rules (V-44, RFC-IMP-11).
102
+ */
103
+ export function isPresenceProbe(probe: AcceptanceProbe): boolean {
104
+ switch (probe.probe) {
105
+ case "file-exists":
106
+ case "command-registered":
107
+ return true;
108
+ case "file-contains":
109
+ return !isDocPath(probe.path);
110
+ case "json-schema":
111
+ return !isDocPath(probe.artifact);
112
+ default:
113
+ // Future structural kinds (e.g. RFC-1334 `reachable`) opt in here.
114
+ return (probe as { probe: string }).probe === "reachable";
115
+ }
116
+ }
117
+
118
+ const SHORT = 7;
119
+ const short = (sha: string): string => sha.slice(0, SHORT);
120
+
121
+ function sortKeysDeep(value: unknown): unknown {
122
+ if (Array.isArray(value)) return value.map(sortKeysDeep);
123
+ if (value && typeof value === "object") {
124
+ const out: Record<string, unknown> = {};
125
+ for (const key of Object.keys(value as Record<string, unknown>).sort()) {
126
+ out[key] = sortKeysDeep((value as Record<string, unknown>)[key]);
127
+ }
128
+ return out;
129
+ }
130
+ return value;
131
+ }
132
+
133
+ /** Stable identity of a probe declaration (sorted-key JSON). */
134
+ export function probeDeclarationKey(probe: AcceptanceProbe): string {
135
+ return JSON.stringify(sortKeysDeep(probe));
136
+ }
137
+
138
+ /** `git log --follow` names the file per commit: commit sha → path at that commit. */
139
+ async function pathHistory(git: OriginGit, relPath: string): Promise<Map<string, string>> {
140
+ const out = await git.run([
141
+ "log",
142
+ "--follow",
143
+ "--name-only",
144
+ "--format=COMMIT %H",
145
+ "--",
146
+ relPath,
147
+ ]);
148
+ const map = new Map<string, string>();
149
+ if (!out) return map;
150
+ let current: string | null = null;
151
+ for (const raw of out.split("\n")) {
152
+ const line = raw.trim();
153
+ if (!line) continue;
154
+ if (line.startsWith("COMMIT ")) {
155
+ current = line.slice("COMMIT ".length);
156
+ continue;
157
+ }
158
+ if (current && !map.has(current)) map.set(current, line);
159
+ }
160
+ return map;
161
+ }
162
+
163
+ /**
164
+ * Range for RFC origin derivation. Base = oldest commit whose diff adds or
165
+ * removes a `status: accepted` line in the RFC file (the acceptance
166
+ * transition), head = HEAD.
167
+ */
168
+ export async function resolveImplementationRange(
169
+ git: OriginGit,
170
+ rfcRelPath: string,
171
+ ): Promise<ImplementationRange> {
172
+ const head = (await git.run(["rev-parse", "HEAD"]))?.trim() ?? "HEAD";
173
+ const out = await git.run([
174
+ "log",
175
+ "--follow",
176
+ "--format=%H",
177
+ "-G",
178
+ "^status:[[:space:]]*[\"']?accepted[\"']?[[:space:]]*$",
179
+ "--",
180
+ rfcRelPath,
181
+ ]);
182
+ const shas = (out ?? "")
183
+ .split("\n")
184
+ .map((l) => l.trim())
185
+ .filter(Boolean);
186
+ return { base: shas.length > 0 ? shas[shas.length - 1]! : null, head };
187
+ }
188
+
189
+ interface RangeCommit {
190
+ sha: string;
191
+ body: string;
192
+ }
193
+
194
+ /** Commits in base..head touching `relPath` (renames followed), oldest first. */
195
+ async function commitsTouching(
196
+ git: OriginGit,
197
+ range: ImplementationRange,
198
+ relPath: string,
199
+ ): Promise<RangeCommit[]> {
200
+ if (!range.base) return [];
201
+ const out = await git.run([
202
+ "log",
203
+ "--follow",
204
+ "--format=%H%x1f%B%x1e",
205
+ `${range.base}..${range.head}`,
206
+ "--",
207
+ relPath,
208
+ ]);
209
+ if (!out) return [];
210
+ return out
211
+ .split("\x1e")
212
+ .map((chunk) => chunk.replace(/^\s+/, ""))
213
+ .filter((chunk) => chunk.includes("\x1f"))
214
+ .map((chunk) => {
215
+ const [sha, body] = chunk.split("\x1f");
216
+ return { sha: (sha ?? "").trim(), body: body ?? "" };
217
+ })
218
+ .filter((c) => c.sha.length > 0)
219
+ .reverse();
220
+ }
221
+
222
+ async function acceptanceAt(
223
+ git: OriginGit,
224
+ sha: string,
225
+ pathAt: Map<string, string>,
226
+ fallbackPath: string,
227
+ ): Promise<AcceptanceProbe[] | null> {
228
+ const path = pathAt.get(sha) ?? fallbackPath;
229
+ const source = await git.run(["show", `${sha}:${path}`]);
230
+ if (source === null) return null;
231
+ try {
232
+ const acceptance = parseRfcFile(source).frontmatter["acceptance"];
233
+ return Array.isArray(acceptance) ? (acceptance as AcceptanceProbe[]) : [];
234
+ } catch {
235
+ return null;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * For each in-range commit touching the RFC file, the probe declaration keys
241
+ * it introduced (present after, absent before) — newest introduction wins.
242
+ */
243
+ async function declarationIntroductions(
244
+ git: OriginGit,
245
+ range: ImplementationRange,
246
+ rfcRelPath: string,
247
+ ): Promise<{ baseKeys: Set<string> | null; introducedBy: Map<string, RangeCommit> }> {
248
+ const introducedBy = new Map<string, RangeCommit>();
249
+ if (!range.base) return { baseKeys: null, introducedBy };
250
+ const pathAt = await pathHistory(git, rfcRelPath);
251
+ const baseProbes = await acceptanceAt(git, range.base, pathAt, rfcRelPath);
252
+ if (baseProbes === null) return { baseKeys: null, introducedBy };
253
+ const baseKeys = new Set(baseProbes.map(probeDeclarationKey));
254
+ let previous = baseKeys;
255
+ for (const commit of await commitsTouching(git, range, rfcRelPath)) {
256
+ const probes = await acceptanceAt(git, commit.sha, pathAt, rfcRelPath);
257
+ if (probes === null) continue;
258
+ const keys = new Set(probes.map(probeDeclarationKey));
259
+ for (const key of keys) {
260
+ if (!previous.has(key)) introducedBy.set(key, commit);
261
+ }
262
+ previous = keys;
263
+ }
264
+ return { baseKeys, introducedBy };
265
+ }
266
+
267
+ function runCommandName(command: string): string | null {
268
+ const match = /^(?:pnpm\s+exec\s+)?werkstatt\s+(?:run|pipeline)\s+(\S+)/.exec(command.trim());
269
+ return match?.[1] ?? null;
270
+ }
271
+
272
+ function rfcCommandSet(frontmatter: Record<string, unknown>): Set<string> {
273
+ const block = (frontmatter["commands"] ?? {}) as Record<string, unknown>;
274
+ const names = new Set<string>();
275
+ for (const bucket of ["proposed", "added", "changed"]) {
276
+ const list = block[bucket];
277
+ if (Array.isArray(list)) for (const n of list) names.add(String(n));
278
+ }
279
+ return names;
280
+ }
281
+
282
+ function effectiveOf(
283
+ derived: DerivedProbeOrigin | "presence",
284
+ declared: RfcExpectationSource | "undeclared",
285
+ ): ProbeOriginRecord["effective"] {
286
+ if (derived === "presence") return "presence";
287
+ if (derived === "self" || derived === "unresolved") return "self";
288
+ if (derived === "verifier") return "independent";
289
+ return declared;
290
+ }
291
+
292
+ export interface DeriveProbeOriginsInput {
293
+ git: OriginGit;
294
+ rfcRelPath: string;
295
+ frontmatter: Record<string, unknown>;
296
+ probes: AcceptanceProbe[];
297
+ /** Precomputed range (tests / callers that already resolved it). */
298
+ range?: ImplementationRange;
299
+ }
300
+
301
+ /** Derive one origin record per probe, in probe order. */
302
+ export async function deriveProbeOrigins(
303
+ input: DeriveProbeOriginsInput,
304
+ ): Promise<ProbeOriginRecord[]> {
305
+ const { git, rfcRelPath, frontmatter, probes } = input;
306
+ const range = input.range ?? (await resolveImplementationRange(git, rfcRelPath));
307
+ const { baseKeys, introducedBy } = await declarationIntroductions(git, range, rfcRelPath);
308
+ const rfcCommands = rfcCommandSet(frontmatter);
309
+ const fileCache = new Map<string, RangeCommit[]>();
310
+
311
+ const records: ProbeOriginRecord[] = [];
312
+ for (const probe of probes) {
313
+ const declared: RfcExpectationSource | "undeclared" = probe.expectationSource ?? "undeclared";
314
+ const finish = (derived: DerivedProbeOrigin | "presence", reason: string[]): void => {
315
+ records.push({
316
+ declared,
317
+ derivedOrigin: derived,
318
+ effective: effectiveOf(derived, declared),
319
+ reason,
320
+ });
321
+ };
322
+
323
+ if (isPresenceProbe(probe)) {
324
+ finish("presence", []);
325
+ continue;
326
+ }
327
+ if (!range.base || baseKeys === null) {
328
+ finish("unresolved", ["no `status: accepted` transition found in history"]);
329
+ continue;
330
+ }
331
+
332
+ // Declaration rule — added/changed after acceptance ⇒ self, unless the
333
+ // introducing commit carries the verifier trailer pair (RFC-1333).
334
+ const key = probeDeclarationKey(probe);
335
+ let declarationByVerifier: RangeCommit | null = null;
336
+ if (!baseKeys.has(key)) {
337
+ const intro = introducedBy.get(key);
338
+ if (intro && hasVerifierTrailers(intro.body)) {
339
+ declarationByVerifier = intro;
340
+ } else {
341
+ finish("self", [
342
+ intro
343
+ ? `${short(intro.sha)} changed the probe declaration`
344
+ : "probe declaration changed after acceptance",
345
+ ]);
346
+ continue;
347
+ }
348
+ }
349
+
350
+ if (probe.probe === "test") {
351
+ let commits = fileCache.get(probe.file);
352
+ if (!commits) {
353
+ commits = await commitsTouching(git, range, probe.file);
354
+ fileCache.set(probe.file, commits);
355
+ }
356
+ const nonVerifier = commits.filter((c) => !hasVerifierTrailers(c.body));
357
+ if (nonVerifier.length > 0) {
358
+ finish(
359
+ "self",
360
+ nonVerifier.map((c) => `${short(c.sha)} touched ${probe.file}`),
361
+ );
362
+ continue;
363
+ }
364
+ if (commits.length > 0) {
365
+ finish(
366
+ "verifier",
367
+ commits.map((c) => verifierReportOf(c.body) ?? short(c.sha)),
368
+ );
369
+ continue;
370
+ }
371
+ } else if (probe.probe === "run") {
372
+ const name = runCommandName(probe.command);
373
+ if (name && rfcCommands.has(name)) {
374
+ finish("self", [`runs ${name}, listed in the RFC's commands block`]);
375
+ continue;
376
+ }
377
+ }
378
+
379
+ if (declarationByVerifier) {
380
+ finish("verifier", [
381
+ verifierReportOf(declarationByVerifier.body) ?? short(declarationByVerifier.sha),
382
+ ]);
383
+ continue;
384
+ }
385
+ finish("unchanged", []);
386
+ }
387
+ return records;
388
+ }
389
+
390
+ /**
391
+ * RFC-1330: attach `origin` to envelope probe records for RFCs created on or
392
+ * after RFC_ORIGIN_CUTOFF. Shared by `rfc.verification.emit` and
393
+ * `rfc.verification.refresh` so both envelope writers stay identical.
394
+ * `origin` is volatile evidence context — `checkEvidenceEnvelope` never
395
+ * compares it because it depends on git history, not on the RFC bytes.
396
+ */
397
+ export async function attachProbeOrigins(opts: {
398
+ workspaceRoot: string;
399
+ rfcRelPath: string;
400
+ frontmatter: Record<string, unknown>;
401
+ probes: AcceptanceProbe[];
402
+ records: Array<{ origin?: ProbeOriginRecord }>;
403
+ git?: OriginGit;
404
+ }): Promise<void> {
405
+ const createdAt = String(opts.frontmatter["createdAt"] ?? "");
406
+ if (createdAt < RFC_ORIGIN_CUTOFF) return;
407
+ const origins = await deriveProbeOrigins({
408
+ git: opts.git ?? createOriginGit(opts.workspaceRoot),
409
+ rfcRelPath: opts.rfcRelPath,
410
+ frontmatter: opts.frontmatter,
411
+ probes: opts.probes,
412
+ });
413
+ origins.forEach((origin, i) => {
414
+ const record = opts.records[i];
415
+ if (record) record.origin = origin;
416
+ });
417
+ }
@@ -1,3 +1,17 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Unit tests for verification refresh covering rfc.verification.refresh — sweep delta report; rfc.verification.refresh — AC-1: single-RFC refresh; rfc.verification.refresh — AC-2: --all mode.
5
+ </purpose>
6
+ <non-goals>
7
+ <item>Not a contract source of truth — the module under test owns the authoritative behavior; fixtures are minimal scaffolding only.</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1311: Compass header sweep — declares the verification suite's contract for test-file scaffold coverage.</item>
12
+ </CHANGE_SUMMARY>
13
+ */
14
+
1
15
  // @vitest-environment node
2
16
  import { test, expect, describe, vi, beforeEach, afterEach } from "vitest";
3
17
  import fs from "node:fs/promises";