@warpgogol/forge 9.2.3 → 9.3.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 (247) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/bin/cli.ts +3 -2
  3. package/dist/bin/cli.js +3 -2
  4. package/dist/bin/cli.js.map +1 -1
  5. package/dist/os/adr/handlers/implement-stamp.d.ts +6 -0
  6. package/dist/os/adr/handlers/implement-stamp.d.ts.map +1 -1
  7. package/dist/os/adr/handlers/implement-stamp.js +23 -15
  8. package/dist/os/adr/handlers/implement-stamp.js.map +1 -1
  9. package/dist/os/checks/handlers/counters-journal.d.ts.map +1 -1
  10. package/dist/os/checks/handlers/counters-journal.js +9 -1
  11. package/dist/os/checks/handlers/counters-journal.js.map +1 -1
  12. package/dist/os/core/core.module.d.ts.map +1 -1
  13. package/dist/os/core/core.module.js +27 -36
  14. package/dist/os/core/core.module.js.map +1 -1
  15. package/dist/os/core/lock-holder.d.ts +32 -0
  16. package/dist/os/core/lock-holder.d.ts.map +1 -0
  17. package/dist/os/core/lock-holder.js +81 -0
  18. package/dist/os/core/lock-holder.js.map +1 -0
  19. package/dist/os/core/stamp-lock.d.ts +30 -0
  20. package/dist/os/core/stamp-lock.d.ts.map +1 -0
  21. package/dist/os/core/stamp-lock.js +112 -0
  22. package/dist/os/core/stamp-lock.js.map +1 -0
  23. package/dist/os/flow/digest.d.ts +19 -0
  24. package/dist/os/flow/digest.d.ts.map +1 -1
  25. package/dist/os/flow/digest.js +33 -4
  26. package/dist/os/flow/digest.js.map +1 -1
  27. package/dist/os/flow/flow.module.d.ts.map +1 -1
  28. package/dist/os/flow/flow.module.js +61 -6
  29. package/dist/os/flow/flow.module.js.map +1 -1
  30. package/dist/os/flow/handlers/flow-cut.d.ts +8 -0
  31. package/dist/os/flow/handlers/flow-cut.d.ts.map +1 -1
  32. package/dist/os/flow/handlers/flow-cut.js +91 -5
  33. package/dist/os/flow/handlers/flow-cut.js.map +1 -1
  34. package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
  35. package/dist/os/flow/handlers/flow-digest.js +6 -0
  36. package/dist/os/flow/handlers/flow-digest.js.map +1 -1
  37. package/dist/os/flow/handlers/flow-discard.d.ts.map +1 -1
  38. package/dist/os/flow/handlers/flow-discard.js +17 -13
  39. package/dist/os/flow/handlers/flow-discard.js.map +1 -1
  40. package/dist/os/flow/handlers/flow-fix.d.ts.map +1 -1
  41. package/dist/os/flow/handlers/flow-fix.js +99 -10
  42. package/dist/os/flow/handlers/flow-fix.js.map +1 -1
  43. package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
  44. package/dist/os/flow/handlers/flow-integrate.js +32 -15
  45. package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
  46. package/dist/os/flow/handlers/flow-publication-retire.d.ts +17 -0
  47. package/dist/os/flow/handlers/flow-publication-retire.d.ts.map +1 -0
  48. package/dist/os/flow/handlers/flow-publication-retire.js +132 -0
  49. package/dist/os/flow/handlers/flow-publication-retire.js.map +1 -0
  50. package/dist/os/flow/handlers/flow-push.d.ts +7 -0
  51. package/dist/os/flow/handlers/flow-push.d.ts.map +1 -1
  52. package/dist/os/flow/handlers/flow-push.js +106 -15
  53. package/dist/os/flow/handlers/flow-push.js.map +1 -1
  54. package/dist/os/flow/locks.d.ts +6 -1
  55. package/dist/os/flow/locks.d.ts.map +1 -1
  56. package/dist/os/flow/locks.js +53 -23
  57. package/dist/os/flow/locks.js.map +1 -1
  58. package/dist/os/flow/publication-order.d.ts +25 -0
  59. package/dist/os/flow/publication-order.d.ts.map +1 -0
  60. package/dist/os/flow/publication-order.js +75 -0
  61. package/dist/os/flow/publication-order.js.map +1 -0
  62. package/dist/os/flow/publish.d.ts +18 -0
  63. package/dist/os/flow/publish.d.ts.map +1 -1
  64. package/dist/os/flow/publish.js +58 -2
  65. package/dist/os/flow/publish.js.map +1 -1
  66. package/dist/os/flow/registry.d.ts +1 -1
  67. package/dist/os/flow/registry.d.ts.map +1 -1
  68. package/dist/os/flow/registry.js +2 -1
  69. package/dist/os/flow/registry.js.map +1 -1
  70. package/dist/os/flow/release-tags.d.ts +1 -0
  71. package/dist/os/flow/release-tags.d.ts.map +1 -1
  72. package/dist/os/flow/release-tags.js +5 -4
  73. package/dist/os/flow/release-tags.js.map +1 -1
  74. package/dist/os/flow/scripts.d.ts +1 -1
  75. package/dist/os/flow/scripts.d.ts.map +1 -1
  76. package/dist/os/flow/scripts.js +1 -0
  77. package/dist/os/flow/scripts.js.map +1 -1
  78. package/dist/os/flow/task-files.d.ts +11 -0
  79. package/dist/os/flow/task-files.d.ts.map +1 -0
  80. package/dist/os/flow/task-files.js +51 -0
  81. package/dist/os/flow/task-files.js.map +1 -0
  82. package/dist/os/flow/tests/helpers.d.ts +4 -1
  83. package/dist/os/flow/tests/helpers.d.ts.map +1 -1
  84. package/dist/os/flow/tests/helpers.js +9 -5
  85. package/dist/os/flow/tests/helpers.js.map +1 -1
  86. package/dist/os/mission/handlers/archive.d.ts.map +1 -1
  87. package/dist/os/mission/handlers/archive.js +30 -74
  88. package/dist/os/mission/handlers/archive.js.map +1 -1
  89. package/dist/os/mission/lockfile.d.ts +21 -0
  90. package/dist/os/mission/lockfile.d.ts.map +1 -0
  91. package/dist/os/mission/lockfile.js +76 -0
  92. package/dist/os/mission/lockfile.js.map +1 -0
  93. package/dist/os/mission/mission.module.d.ts.map +1 -1
  94. package/dist/os/mission/mission.module.js +2 -1
  95. package/dist/os/mission/mission.module.js.map +1 -1
  96. package/dist/os/rfc/handlers/implement-stamp.d.ts +6 -0
  97. package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
  98. package/dist/os/rfc/handlers/implement-stamp.js +24 -19
  99. package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
  100. package/dist/os/system/handlers/outbox-validate.d.ts +8 -0
  101. package/dist/os/system/handlers/outbox-validate.d.ts.map +1 -0
  102. package/dist/os/system/handlers/outbox-validate.js +102 -0
  103. package/dist/os/system/handlers/outbox-validate.js.map +1 -0
  104. package/dist/os/system/handlers/system-map-validate.d.ts +13 -0
  105. package/dist/os/system/handlers/system-map-validate.d.ts.map +1 -0
  106. package/dist/os/system/handlers/system-map-validate.js +78 -0
  107. package/dist/os/system/handlers/system-map-validate.js.map +1 -0
  108. package/dist/os/system/handlers/system-outbox-scan.d.ts +10 -0
  109. package/dist/os/system/handlers/system-outbox-scan.d.ts.map +1 -0
  110. package/dist/os/system/handlers/system-outbox-scan.js +195 -0
  111. package/dist/os/system/handlers/system-outbox-scan.js.map +1 -0
  112. package/dist/os/system/handlers/system-task-collect.d.ts +13 -0
  113. package/dist/os/system/handlers/system-task-collect.d.ts.map +1 -0
  114. package/dist/os/system/handlers/system-task-collect.js +238 -0
  115. package/dist/os/system/handlers/system-task-collect.js.map +1 -0
  116. package/dist/os/system/handlers/system-task-create.d.ts +32 -0
  117. package/dist/os/system/handlers/system-task-create.d.ts.map +1 -0
  118. package/dist/os/system/handlers/system-task-create.js +216 -0
  119. package/dist/os/system/handlers/system-task-create.js.map +1 -0
  120. package/dist/os/system/handlers/system-task-dispatch.d.ts +14 -0
  121. package/dist/os/system/handlers/system-task-dispatch.d.ts.map +1 -0
  122. package/dist/os/system/handlers/system-task-dispatch.js +290 -0
  123. package/dist/os/system/handlers/system-task-dispatch.js.map +1 -0
  124. package/dist/os/system/handlers/system-task-move.d.ts +12 -0
  125. package/dist/os/system/handlers/system-task-move.d.ts.map +1 -0
  126. package/dist/os/system/handlers/system-task-move.js +217 -0
  127. package/dist/os/system/handlers/system-task-move.js.map +1 -0
  128. package/dist/os/system/handlers/system-task-status.d.ts +20 -0
  129. package/dist/os/system/handlers/system-task-status.d.ts.map +1 -0
  130. package/dist/os/system/handlers/system-task-status.js +139 -0
  131. package/dist/os/system/handlers/system-task-status.js.map +1 -0
  132. package/dist/os/system/handlers/system-versionset-record.d.ts +12 -0
  133. package/dist/os/system/handlers/system-versionset-record.d.ts.map +1 -0
  134. package/dist/os/system/handlers/system-versionset-record.js +332 -0
  135. package/dist/os/system/handlers/system-versionset-record.js.map +1 -0
  136. package/dist/os/system/index.d.ts +6 -0
  137. package/dist/os/system/index.d.ts.map +1 -0
  138. package/dist/os/system/index.js +18 -0
  139. package/dist/os/system/index.js.map +1 -0
  140. package/dist/os/system/outbox-schema.d.ts +30 -0
  141. package/dist/os/system/outbox-schema.d.ts.map +1 -0
  142. package/dist/os/system/outbox-schema.js +29 -0
  143. package/dist/os/system/outbox-schema.js.map +1 -0
  144. package/dist/os/system/repo.d.ts +64 -0
  145. package/dist/os/system/repo.d.ts.map +1 -0
  146. package/dist/os/system/repo.js +364 -0
  147. package/dist/os/system/repo.js.map +1 -0
  148. package/dist/os/system/scenario-schemas.d.ts +26 -0
  149. package/dist/os/system/scenario-schemas.d.ts.map +1 -0
  150. package/dist/os/system/scenario-schemas.js +53 -0
  151. package/dist/os/system/scenario-schemas.js.map +1 -0
  152. package/dist/os/system/schemas.d.ts +63 -0
  153. package/dist/os/system/schemas.d.ts.map +1 -0
  154. package/dist/os/system/schemas.js +83 -0
  155. package/dist/os/system/schemas.js.map +1 -0
  156. package/dist/os/system/system.module.d.ts +3 -0
  157. package/dist/os/system/system.module.d.ts.map +1 -0
  158. package/dist/os/system/system.module.js +429 -0
  159. package/dist/os/system/system.module.js.map +1 -0
  160. package/dist/os/system/task-schemas.d.ts +108 -0
  161. package/dist/os/system/task-schemas.d.ts.map +1 -0
  162. package/dist/os/system/task-schemas.js +152 -0
  163. package/dist/os/system/task-schemas.js.map +1 -0
  164. package/dist/os/system/task-store.d.ts +41 -0
  165. package/dist/os/system/task-store.d.ts.map +1 -0
  166. package/dist/os/system/task-store.js +142 -0
  167. package/dist/os/system/task-store.js.map +1 -0
  168. package/dist/os/system/tests/helpers.d.ts +30 -0
  169. package/dist/os/system/tests/helpers.d.ts.map +1 -0
  170. package/dist/os/system/tests/helpers.js +178 -0
  171. package/dist/os/system/tests/helpers.js.map +1 -0
  172. package/dist/src/index.d.ts +3 -0
  173. package/dist/src/index.d.ts.map +1 -1
  174. package/dist/src/index.js +5 -4
  175. package/dist/src/index.js.map +1 -1
  176. package/os/adr/handlers/implement-stamp-lock.test.ts +90 -0
  177. package/os/adr/handlers/implement-stamp.ts +29 -20
  178. package/os/checks/handlers/counters-journal.test.ts +10 -0
  179. package/os/checks/handlers/counters-journal.ts +8 -1
  180. package/os/core/core.module.ts +32 -36
  181. package/os/core/lock-holder.ts +88 -0
  182. package/os/core/stamp-lock.ts +142 -0
  183. package/os/flow/digest.ts +46 -4
  184. package/os/flow/flow.module.ts +62 -6
  185. package/os/flow/handlers/flow-cut.ts +118 -5
  186. package/os/flow/handlers/flow-digest.ts +6 -0
  187. package/os/flow/handlers/flow-discard.ts +22 -13
  188. package/os/flow/handlers/flow-fix.ts +116 -10
  189. package/os/flow/handlers/flow-integrate.ts +31 -15
  190. package/os/flow/handlers/flow-publication-retire.ts +156 -0
  191. package/os/flow/handlers/flow-push.ts +128 -13
  192. package/os/flow/locks.ts +75 -25
  193. package/os/flow/publication-order.ts +99 -0
  194. package/os/flow/publish.ts +73 -2
  195. package/os/flow/registry.ts +5 -2
  196. package/os/flow/release-tags.ts +5 -4
  197. package/os/flow/scripts.ts +2 -0
  198. package/os/flow/task-files.ts +59 -0
  199. package/os/flow/tests/flow-cut-prepare.test.ts +298 -0
  200. package/os/flow/tests/flow-cut.test.ts +5 -1
  201. package/os/flow/tests/flow-publication-retire.test.ts +191 -0
  202. package/os/flow/tests/flow-push-supersede.test.ts +221 -0
  203. package/os/flow/tests/flow-task-files.test.ts +59 -0
  204. package/os/flow/tests/helpers.ts +9 -5
  205. package/os/flow/tests/locks.test.ts +219 -0
  206. package/os/flow/tests/publication-order.test.ts +102 -0
  207. package/os/mission/handlers/archive.test.ts +97 -52
  208. package/os/mission/handlers/archive.ts +31 -76
  209. package/os/mission/lockfile.ts +84 -0
  210. package/os/mission/mission.module.ts +2 -1
  211. package/os/rfc/handlers/implement-stamp-lock.test.ts +133 -0
  212. package/os/rfc/handlers/implement-stamp.ts +30 -24
  213. package/os/system/handlers/outbox-validate.ts +120 -0
  214. package/os/system/handlers/system-map-validate.ts +107 -0
  215. package/os/system/handlers/system-outbox-scan.ts +320 -0
  216. package/os/system/handlers/system-task-collect.ts +305 -0
  217. package/os/system/handlers/system-task-create.ts +271 -0
  218. package/os/system/handlers/system-task-dispatch.ts +387 -0
  219. package/os/system/handlers/system-task-move.ts +353 -0
  220. package/os/system/handlers/system-task-status.ts +176 -0
  221. package/os/system/handlers/system-versionset-record.ts +476 -0
  222. package/os/system/index.ts +47 -0
  223. package/os/system/outbox-schema.ts +47 -0
  224. package/os/system/repo.ts +451 -0
  225. package/os/system/scenario-schemas.ts +62 -0
  226. package/os/system/schemas.ts +102 -0
  227. package/os/system/system.module.ts +449 -0
  228. package/os/system/task-schemas.ts +190 -0
  229. package/os/system/task-store.ts +184 -0
  230. package/os/system/tests/helpers.ts +189 -0
  231. package/os/system/tests/outbox-validate.test.ts +92 -0
  232. package/os/system/tests/system-map-validate.test.ts +321 -0
  233. package/os/system/tests/system-outbox-scan.test.ts +273 -0
  234. package/os/system/tests/system-profile.test.ts +90 -0
  235. package/os/system/tests/system-task-collect.test.ts +293 -0
  236. package/os/system/tests/system-task-dispatch.test.ts +279 -0
  237. package/os/system/tests/system-task-status.test.ts +153 -0
  238. package/os/system/tests/system-task.test.ts +330 -0
  239. package/os/system/tests/system-versionset.test.ts +314 -0
  240. package/package.json +33 -1
  241. package/profiles/system.yaml +650 -0
  242. package/skills/fo/fo-outbox/SKILL.md +71 -0
  243. package/skills/fo/fo-system-dispatch/SKILL.md +65 -0
  244. package/skills/fo/fo-task-run/SKILL.md +75 -0
  245. package/src/index.ts +11 -4
  246. package/src/tests/fixtures/agents-generate-business-before.txt +6 -0
  247. package/src/tests/profile-schema.test.ts +2 -1
@@ -0,0 +1,476 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>system.versionset.record command handler (RFC-1511): runs every check
4
+ of every named business scenario inside a temporary detached worktree of the
5
+ product at the named forge/release-tag@1 tag, then writes
6
+ system/version-sets/VS-NNNN.yaml with sha256 evidence per scenario only when
7
+ all checks exit 0. No partial sets — a failing check leaves logs but no set
8
+ file (DNA-106).</purpose>
9
+ <non-goals>
10
+ <item>No scheduling — the operator runs the command; no published-package pins (stage 3).</item>
11
+ <item>No dispatch — a set is evidence, system.task.move --to verified reads it later.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <KEY_DECISIONS>
15
+ <item>Checks run with argv vectors and no shell, cwd inside the detached tag worktree — the product's primary checkout stays on develop.</item>
16
+ <item>The product's own hooks/worktree-setup.sh (from the primary, like flow.open) prepares each tag worktree before checks run.</item>
17
+ <item>--dry-run validates the whole declaration layer (flags, scenarios, folders, tags) and stops before any worktree or write.</item>
18
+ <item>exec spawn rejections map to SYSTEM-VS-04 (distinct from timeout exitCode:null); each worktree removal failure maps to SYSTEM-VS-05 so one stuck removal never skips the rest.</item>
19
+ <item>%(refname) pins the tag match exactly — for-each-ref patterns are globs; folders lookup goes through Object.hasOwn so product ids like "constructor" stay legal.</item>
20
+ </KEY_DECISIONS>
21
+ <CHANGE_SUMMARY>
22
+ <item>RFC-1511: step 3 — versionset.record handler</item>
23
+ <item>RFC-1511: scenarios, version sets and system.versionset.record</item>
24
+ <item>RFC-1511: accept recorded products map in verified gate, guard folders lookup and exec edges (RFC-1511 review r1)</item>
25
+ <item>RFC-1511: record KEY_DECISIONS for exported tag-schema regex and exec edge handling (RFC-1511 review r1)</item>
26
+ </CHANGE_SUMMARY>
27
+ */
28
+
29
+ import { createHash } from "node:crypto";
30
+ import os from "node:os";
31
+ import path from "node:path";
32
+
33
+ import YAML from "yaml";
34
+
35
+ import { resolveIo } from "../../../src/utils/io.ts";
36
+ import type {
37
+ Diagnostic,
38
+ ForgeCommandInput,
39
+ ForgeCommandResult,
40
+ ForgeRuntimeContext,
41
+ } from "../../../src/types.ts";
42
+ import { git } from "../../flow/git.ts";
43
+ import { RELEASE_TAG_SCHEMA_LINE } from "../../flow/release-tags.ts";
44
+ import { runFlowScript } from "../../flow/scripts.ts";
45
+ import {
46
+ assertSystemRepository,
47
+ loadScenarios,
48
+ loadSystemMap,
49
+ type SystemMap,
50
+ } from "../repo.ts";
51
+ import {
52
+ SYSTEM_VERSION_SETS_DIR,
53
+ versionSetSchema,
54
+ type SystemScenario,
55
+ type VersionSet,
56
+ } from "../scenario-schemas.ts";
57
+
58
+ export interface VersionSetRecordResult {
59
+ command: "system.versionset.record";
60
+ id: string | null;
61
+ products: Record<string, string>;
62
+ scenarios: string[];
63
+ evidence: Record<string, string>;
64
+ created: boolean;
65
+ diagnostics: Diagnostic[];
66
+ }
67
+
68
+ function diag(
69
+ ruleId: string,
70
+ severity: Diagnostic["severity"],
71
+ message: string,
72
+ fixHint?: string,
73
+ file?: string,
74
+ ): Diagnostic {
75
+ return { ruleId, severity, ...(file ? { file } : {}), message, ...(fixHint ? { fixHint } : {}) };
76
+ }
77
+
78
+ /** Parse "a=v1.2.3,b=v0.9.0" into product→tag entries; malformed entries are SYSTEM-VS-01. */
79
+ function parseProductsFlag(
80
+ raw: string | undefined,
81
+ diagnostics: Diagnostic[],
82
+ ): Map<string, string> | null {
83
+ if (raw === undefined || raw.trim() === "") {
84
+ diagnostics.push(
85
+ diag(
86
+ "SYSTEM-VS-01",
87
+ "error",
88
+ "--products <product=tag,…> is required",
89
+ "Pass the release combination, e.g. --products alpha=v1.2.3,beta=v0.9.0.",
90
+ ),
91
+ );
92
+ return null;
93
+ }
94
+ const out = new Map<string, string>();
95
+ for (const entry of raw.split(",")) {
96
+ const trimmed = entry.trim();
97
+ const eq = trimmed.indexOf("=");
98
+ if (eq <= 0 || eq === trimmed.length - 1) {
99
+ diagnostics.push(
100
+ diag(
101
+ "SYSTEM-VS-01",
102
+ "error",
103
+ `malformed --products entry "${trimmed}" — expected <product>=<tag>`,
104
+ ),
105
+ );
106
+ continue;
107
+ }
108
+ out.set(trimmed.slice(0, eq).trim(), trimmed.slice(eq + 1).trim());
109
+ }
110
+ return out;
111
+ }
112
+
113
+ function parseScenariosFlag(
114
+ raw: string | undefined,
115
+ diagnostics: Diagnostic[],
116
+ ): string[] | null {
117
+ if (raw === undefined || raw.trim() === "") {
118
+ diagnostics.push(
119
+ diag(
120
+ "SYSTEM-VS-01",
121
+ "error",
122
+ "--scenarios <id,…> is required",
123
+ "Pass the scenario ids declared under system/scenarios/.",
124
+ ),
125
+ );
126
+ return null;
127
+ }
128
+ const ids = raw
129
+ .split(",")
130
+ .map((s) => s.trim())
131
+ .filter((s) => s.length > 0);
132
+ if (ids.length === 0) {
133
+ diagnostics.push(
134
+ diag(
135
+ "SYSTEM-VS-01",
136
+ "error",
137
+ "--scenarios names no scenario ids",
138
+ "Pass at least one scenario id declared under system/scenarios/.",
139
+ ),
140
+ );
141
+ return null;
142
+ }
143
+ return ids;
144
+ }
145
+
146
+ /** Verify the tag exists locally and is an annotated forge/release-tag@1 tag (SYSTEM-VS-03). */
147
+ async function checkReleaseTag(
148
+ io: ReturnType<typeof resolveIo>,
149
+ productRoot: string,
150
+ product: string,
151
+ tag: string,
152
+ ): Promise<Diagnostic | null> {
153
+ const sep = "\x1f";
154
+ const res = await git(productRoot, io, [
155
+ "for-each-ref",
156
+ `refs/tags/${tag}`,
157
+ `--format=%(refname)${sep}%(objecttype)${sep}%(contents)`,
158
+ ]);
159
+ // %(contents) is multi-line — split on the first two field separators only;
160
+ // %(refname) pins the match exactly (the pattern is a glob).
161
+ const firstSep = res.stdout.indexOf(sep);
162
+ const secondSep = firstSep === -1 ? -1 : res.stdout.indexOf(sep, firstSep + 1);
163
+ const refname = firstSep === -1 ? "" : res.stdout.slice(0, firstSep);
164
+ const objecttype = secondSep === -1 ? "" : res.stdout.slice(firstSep + 1, secondSep);
165
+ const contents = secondSep === -1 ? "" : res.stdout.slice(secondSep + 1);
166
+ if (res.exitCode !== 0 || refname !== `refs/tags/${tag}`) {
167
+ return diag(
168
+ "SYSTEM-VS-03",
169
+ "error",
170
+ `product "${product}" has no local tag "${tag}"`,
171
+ `Fetch or cut the release tag in the ${product} checkout before recording a version set.`,
172
+ );
173
+ }
174
+ if (objecttype !== "tag" || !RELEASE_TAG_SCHEMA_LINE.test(contents)) {
175
+ return diag(
176
+ "SYSTEM-VS-03",
177
+ "error",
178
+ `product "${product}" tag "${tag}" is not a forge/release-tag@1 annotation`,
179
+ `Version sets only accept annotated release tags cut by flow.cut.`,
180
+ );
181
+ }
182
+ return null;
183
+ }
184
+
185
+ /** Highest VS-NNNN under system/version-sets/ plus one. */
186
+ async function nextVersionSetId(root: string, io: ReturnType<typeof resolveIo>): Promise<string> {
187
+ const dir = path.join(root, SYSTEM_VERSION_SETS_DIR);
188
+ let max = 0;
189
+ let isDir = false;
190
+ try {
191
+ isDir = (await io.stat(dir)).isDirectory;
192
+ } catch {
193
+ isDir = false;
194
+ }
195
+ if (isDir) {
196
+ try {
197
+ for (const entry of await io.readdir(dir)) {
198
+ const m = /^VS-(\d{4})\.yaml$/.exec(entry.name);
199
+ if (entry.isFile && m) max = Math.max(max, Number.parseInt(m[1]!, 10));
200
+ }
201
+ } catch {
202
+ // dir vanished between stat and readdir — start at VS-0001
203
+ }
204
+ }
205
+ return `VS-${String(max + 1).padStart(4, "0")}`;
206
+ }
207
+
208
+ export async function runSystemVersionSetRecord(
209
+ input: ForgeCommandInput,
210
+ context: ForgeRuntimeContext,
211
+ ): Promise<ForgeCommandResult<VersionSetRecordResult>> {
212
+ const io = resolveIo(context.io);
213
+ const root = context.workspaceRoot;
214
+ const diagnostics: Diagnostic[] = [];
215
+ const dryRun = context.dryRun === true || input.flags["dry-run"] === true;
216
+
217
+ const refusal = await assertSystemRepository(root, io);
218
+ let map: SystemMap | null = null;
219
+ if (refusal) {
220
+ diagnostics.push(refusal);
221
+ } else {
222
+ const loaded = await loadSystemMap(root, io);
223
+ diagnostics.push(...loaded.diagnostics);
224
+ map = loaded.map;
225
+ }
226
+
227
+ const strFlag = (name: string): string | undefined => {
228
+ const v = input.flags[name];
229
+ return typeof v === "string" ? v : undefined;
230
+ };
231
+ const productTags = parseProductsFlag(strFlag("products"), diagnostics);
232
+ const scenarioIds = parseScenariosFlag(strFlag("scenarios"), diagnostics);
233
+
234
+ const scenarios: SystemScenario[] = [];
235
+ if (map && scenarioIds) {
236
+ const loaded = await loadScenarios(root, io);
237
+ diagnostics.push(...loaded.diagnostics);
238
+ for (const id of scenarioIds) {
239
+ const scenario = loaded.scenarios.get(id);
240
+ if (!scenario) {
241
+ diagnostics.push(
242
+ diag(
243
+ "SYSTEM-VS-01",
244
+ "error",
245
+ `unknown or unloadable scenario "${id}" — no valid ${`system/scenarios/${id}.yaml`}`,
246
+ "Declare the scenario under system/scenarios/ or fix the id.",
247
+ ),
248
+ );
249
+ continue;
250
+ }
251
+ scenarios.push(scenario);
252
+ }
253
+ }
254
+
255
+ // Products the named scenarios actually exercise: scenario.products plus
256
+ // every check's product (a check may name a product the products[] list omits).
257
+ const neededProducts = new Set<string>();
258
+ for (const scenario of scenarios) {
259
+ for (const p of scenario.products) neededProducts.add(p);
260
+ for (const check of scenario.checks) neededProducts.add(check.product);
261
+ }
262
+
263
+ const productRoots = new Map<string, string>();
264
+ if (map && productTags) {
265
+ for (const product of neededProducts) {
266
+ if (!productTags.has(product)) {
267
+ diagnostics.push(
268
+ diag(
269
+ "SYSTEM-VS-02",
270
+ "error",
271
+ `scenario needs product "${product}" but --products does not name it`,
272
+ `Add ${product}=<release-tag> to --products.`,
273
+ ),
274
+ );
275
+ continue;
276
+ }
277
+ const folder =
278
+ map.local !== null && Object.hasOwn(map.local.folders, product)
279
+ ? map.local.folders[product]
280
+ : undefined;
281
+ if (!folder) {
282
+ diagnostics.push(
283
+ diag(
284
+ "SYSTEM-VS-02",
285
+ "error",
286
+ `product "${product}" has no local checkout — absent from system/products.local.yaml`,
287
+ `Map "${product}" to a local folder in system/products.local.yaml.`,
288
+ ),
289
+ );
290
+ continue;
291
+ }
292
+ const productRoot = path.isAbsolute(folder) ? folder : path.join(root, folder);
293
+ let isDir = false;
294
+ try {
295
+ isDir = (await io.stat(productRoot)).isDirectory;
296
+ } catch {
297
+ isDir = false;
298
+ }
299
+ if (!isDir) {
300
+ diagnostics.push(
301
+ diag(
302
+ "SYSTEM-VS-02",
303
+ "error",
304
+ `product "${product}" local folder does not exist: ${folder}`,
305
+ `Check out the ${product} repository at ${folder}.`,
306
+ ),
307
+ );
308
+ continue;
309
+ }
310
+ productRoots.set(product, productRoot);
311
+ const tagDiag = await checkReleaseTag(io, productRoot, product, productTags.get(product)!);
312
+ if (tagDiag) diagnostics.push(tagDiag);
313
+ }
314
+ }
315
+
316
+ const result: VersionSetRecordResult = {
317
+ command: "system.versionset.record",
318
+ id: null,
319
+ products: productTags ? Object.fromEntries(productTags) : {},
320
+ scenarios: scenarioIds ?? [],
321
+ evidence: {},
322
+ created: false,
323
+ diagnostics,
324
+ };
325
+
326
+ let errors = diagnostics.filter((d) => d.severity === "error").length;
327
+ if (dryRun || errors > 0 || !map || !productTags) {
328
+ return {
329
+ data: result,
330
+ exitCode: errors > 0 ? 1 : 0,
331
+ summary: `system.versionset.record${dryRun ? " (dry-run)" : ""}: ${errors} error(s) — no set written`,
332
+ };
333
+ }
334
+
335
+ // --- Recording pass: tag worktrees, setup hooks, checks, evidence, set file.
336
+ const id = await nextVersionSetId(root, io);
337
+ result.id = id;
338
+ const evidenceDir = path.join(root, SYSTEM_VERSION_SETS_DIR, "evidence", id);
339
+ const worktrees = new Map<string, string>();
340
+ let aborted: Diagnostic | null = null;
341
+
342
+ try {
343
+ for (const [product, productRoot] of productRoots) {
344
+ const tmp = await io.mkdtemp(path.join(os.tmpdir(), `versionset-${product}-`));
345
+ const added = await git(productRoot, io, ["worktree", "add", "--detach", tmp, productTags.get(product)!]);
346
+ if (added.exitCode !== 0) {
347
+ aborted = diag(
348
+ "SYSTEM-VS-04",
349
+ "error",
350
+ `could not create the detached worktree for "${product}" at ${productTags.get(product)}: ${added.stderr.trim()}`,
351
+ );
352
+ break;
353
+ }
354
+ worktrees.set(product, tmp);
355
+ const setup = await runFlowScript(io, "worktree-setup", {
356
+ primary: productRoot,
357
+ cwd: tmp,
358
+ env: { FLOW_PRIMARY: productRoot, FLOW_BRANCH: productTags.get(product)! },
359
+ });
360
+ if (setup.status === "failed") {
361
+ aborted = diag(
362
+ "SYSTEM-VS-04",
363
+ "error",
364
+ `worktree-setup for "${product}" failed (exit ${setup.exitCode}): ${setup.stderrTail}`,
365
+ `Fix ${productRoot}/hooks/worktree-setup.sh — no set file is written.`,
366
+ );
367
+ break;
368
+ }
369
+ }
370
+
371
+ for (const scenario of scenarios) {
372
+ if (aborted) break;
373
+ const log: string[] = [];
374
+ for (const check of scenario.checks) {
375
+ const cwd = worktrees.get(check.product)!;
376
+ log.push(`### ${check.product}$ ${check.argv.join(" ")}\n`);
377
+ let res;
378
+ let spawnError = "";
379
+ try {
380
+ res = await io.exec(check.argv[0]!, check.argv.slice(1), {
381
+ cwd,
382
+ timeoutMs: check.timeoutSec * 1000,
383
+ });
384
+ } catch (error) {
385
+ res = { exitCode: null as number | null, stdout: "", stderr: "" };
386
+ spawnError = error instanceof Error ? error.message : String(error);
387
+ }
388
+ log.push(res.stdout, res.stderr !== "" ? res.stderr : spawnError);
389
+ if (res.exitCode !== 0) {
390
+ aborted = diag(
391
+ "SYSTEM-VS-04",
392
+ "error",
393
+ `scenario "${scenario.id}" check failed in "${check.product}" (${check.argv.join(" ")}) — ` +
394
+ (spawnError !== ""
395
+ ? spawnError
396
+ : res.exitCode === null
397
+ ? `timed out after ${check.timeoutSec}s`
398
+ : `exit ${res.exitCode}`),
399
+ "Fix the check or the product release — no set file is written.",
400
+ );
401
+ break;
402
+ }
403
+ }
404
+ await io.mkdir(evidenceDir);
405
+ const logText = log.join("");
406
+ await io.writeFile(path.join(evidenceDir, `${scenario.id}.log`), logText);
407
+ if (!aborted) {
408
+ result.evidence[scenario.id] = `sha256:${createHash("sha256").update(logText).digest("hex")}`;
409
+ }
410
+ }
411
+ } finally {
412
+ for (const [product, tmp] of worktrees) {
413
+ let removalNote = "";
414
+ try {
415
+ const removed = await git(productRoots.get(product)!, io, ["worktree", "remove", "--force", tmp]);
416
+ removalNote = removed.exitCode === 0 ? "" : removed.stderr.trim();
417
+ } catch (error) {
418
+ removalNote = error instanceof Error ? error.message : String(error);
419
+ }
420
+ if (removalNote !== "") {
421
+ diagnostics.push(
422
+ diag(
423
+ "SYSTEM-VS-05",
424
+ "warning",
425
+ `temporary worktree ${tmp} for "${product}" could not be removed: ${removalNote}`,
426
+ `Remove it manually with: git -C ${productRoots.get(product)} worktree remove --force ${tmp}`,
427
+ ),
428
+ );
429
+ }
430
+ }
431
+ }
432
+
433
+ if (aborted) {
434
+ diagnostics.push(aborted);
435
+ } else {
436
+ const set: VersionSet = {
437
+ schema: "forge/version-set@1",
438
+ id,
439
+ products: result.products,
440
+ scenarios: scenarios.map((s) => s.id),
441
+ evidence: result.evidence,
442
+ verifiedAt: new Date().toISOString(),
443
+ };
444
+ const parsed = versionSetSchema.safeParse(set);
445
+ if (!parsed.success) {
446
+ diagnostics.push(
447
+ diag("SYSTEM-VS-04", "error", `internal: assembled set failed schema: ${parsed.error.message}`),
448
+ );
449
+ } else {
450
+ await io.mkdir(path.join(root, SYSTEM_VERSION_SETS_DIR));
451
+ await io.writeFile(
452
+ path.join(root, SYSTEM_VERSION_SETS_DIR, `${id}.yaml`),
453
+ YAML.stringify(parsed.data),
454
+ );
455
+ result.created = true;
456
+ }
457
+ }
458
+
459
+ result.diagnostics = diagnostics;
460
+ errors = diagnostics.filter((d) => d.severity === "error").length;
461
+ return {
462
+ data: result,
463
+ exitCode: errors > 0 ? 1 : 0,
464
+ summary: result.created
465
+ ? `system.versionset.record: ${id} recorded — ${scenarios.length} scenario(s), ${worktrees.size} product worktree(s)`
466
+ : `system.versionset.record: ${errors} error(s) — no set written`,
467
+ nextSteps: result.created
468
+ ? [
469
+ {
470
+ action: `Reference ${id} from system.task.move --to verified when a task proves this combination`,
471
+ kind: "optional" as const,
472
+ },
473
+ ]
474
+ : [{ action: "Fix the error-severity diagnostics and re-run", kind: "required" as const }],
475
+ };
476
+ }
@@ -0,0 +1,47 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Barrel export for the forge system module (RFC-1508) — module factory,
4
+ system-map loader/validator and schemas for reuse by RFC-1509..1511.</purpose>
5
+ <non-goals>
6
+ <item>Do not add logic here — re-exports only.</item>
7
+ </non-goals>
8
+ </MODULE_CONTRACT>
9
+ <CHANGE_SUMMARY>
10
+ <item>RFC-1508: step 3 — system module barrel export</item>
11
+ <item>RFC-1508: implement RFC-1508 — system profile, system map schemas and system.map.validate</item>
12
+ <item>RFC-1508: align rfc-1508 schemas with the normative contract after review r1</item>
13
+ </CHANGE_SUMMARY>
14
+ */
15
+
16
+ export { createForgeSystemModule } from "./system.module.ts";
17
+ export {
18
+ assertSystemRepository,
19
+ edgeVerdict,
20
+ loadSystemMap,
21
+ validateSystemMap,
22
+ SYSTEM_DIR,
23
+ SYSTEM_CONFIG_FILE,
24
+ SYSTEM_PRODUCTS_FILE,
25
+ SYSTEM_EDGES_FILE,
26
+ SYSTEM_LOCAL_FILE,
27
+ } from "./repo.ts";
28
+ export type { EdgeVerdict, SystemMap, SystemMapLoadResult } from "./repo.ts";
29
+ export {
30
+ systemEdgeSchema,
31
+ systemEdgesSchema,
32
+ systemForbiddenEdgeSchema,
33
+ systemProductSchema,
34
+ systemProductsLocalSchema,
35
+ systemProductsSchema,
36
+ systemSchema,
37
+ SYSTEM_ID_PATTERN,
38
+ } from "./schemas.ts";
39
+ export type {
40
+ System,
41
+ SystemEdge,
42
+ SystemEdges,
43
+ SystemForbiddenEdge,
44
+ SystemProduct,
45
+ SystemProducts,
46
+ SystemProductsLocal,
47
+ } from "./schemas.ts";
@@ -0,0 +1,47 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>Product outbox schemas for dependency-contract requests (RFC-1510):
4
+ the forge/outbox@1 entry file at docs/outbox/&lt;id&gt;.yaml plus the scan-side
5
+ OutboxProposal row. An entry names a contract and never a system or serving
6
+ product — the system matches needs to offers, not the other way around.</purpose>
7
+ <non-goals>
8
+ <item>No handler or store logic — schema and proposal types only.</item>
9
+ </non-goals>
10
+ </MODULE_CONTRACT>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1510: step 2 — forge/outbox@1 schema and OutboxProposal row</item>
13
+ <item>RFC-1510: implement RFC-1510 — product outbox for dependency-contract requests</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+
17
+ import { z } from "zod";
18
+
19
+ export const OUTBOX_DIR = "docs/outbox";
20
+ export const OUTBOX_ID_RE = /^OB-\d{4}$/;
21
+
22
+ export const outboxEntrySchema = z
23
+ .object({
24
+ schema: z.literal("forge/outbox@1"),
25
+ id: z.string().regex(OUTBOX_ID_RE),
26
+ contract: z.string().min(1),
27
+ need: z.string().min(1),
28
+ why: z.string().min(1),
29
+ state: z.enum(["open", "served", "withdrawn"]),
30
+ })
31
+ .strict();
32
+
33
+ export type OutboxEntry = z.infer<typeof outboxEntrySchema>;
34
+
35
+ /** One row of the system.outbox.scan projection. */
36
+ export interface OutboxProposal {
37
+ /** The asking product. */
38
+ product: string;
39
+ /** Entry id, e.g. OB-0003. */
40
+ entry: string;
41
+ contract: string;
42
+ /** Offering product, null when no product offers the contract. */
43
+ target: string | null;
44
+ verdict: "allowed" | "forbidden" | "undeclared" | "own-contract";
45
+ /** Existing or created task for this entry. */
46
+ taskId: string | null;
47
+ }