@warpgogol/forge 9.7.1 → 10.1.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 (262) hide show
  1. package/AGENTS.md +50 -27
  2. package/CHANGELOG.md +39 -0
  3. package/bin/cli.js +0 -0
  4. package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
  5. package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
  6. package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
  7. package/dist/os/core/core.module.d.ts.map +1 -1
  8. package/dist/os/core/core.module.js +1 -69
  9. package/dist/os/core/core.module.js.map +1 -1
  10. package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
  11. package/dist/os/core/handlers/assets-helpers.js +2 -3
  12. package/dist/os/core/handlers/assets-helpers.js.map +1 -1
  13. package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
  14. package/dist/os/core/handlers/determinism-check.js +2 -3
  15. package/dist/os/core/handlers/determinism-check.js.map +1 -1
  16. package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
  17. package/dist/os/core/handlers/release-prepare.js +2 -4
  18. package/dist/os/core/handlers/release-prepare.js.map +1 -1
  19. package/dist/os/flow/handlers/flow-peers.js +1 -1
  20. package/dist/os/flow/handlers/flow-peers.js.map +1 -1
  21. package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
  22. package/dist/os/flow/open-missions.d.ts.map +1 -0
  23. package/dist/os/flow/open-missions.js +37 -0
  24. package/dist/os/flow/open-missions.js.map +1 -0
  25. package/dist/os/flow/preflight.js +1 -1
  26. package/dist/os/flow/preflight.js.map +1 -1
  27. package/dist/os/rfc/probe-batch.d.ts.map +1 -1
  28. package/dist/os/rfc/probe-batch.js +13 -6
  29. package/dist/os/rfc/probe-batch.js.map +1 -1
  30. package/dist/src/command-modules.d.ts.map +1 -1
  31. package/dist/src/command-modules.js +0 -2
  32. package/dist/src/command-modules.js.map +1 -1
  33. package/dist/src/contract/core-nodes.d.ts +8 -0
  34. package/dist/src/contract/core-nodes.d.ts.map +1 -0
  35. package/dist/src/contract/core-nodes.js +101 -0
  36. package/dist/src/contract/core-nodes.js.map +1 -0
  37. package/dist/src/contract/evaluator.d.ts +48 -0
  38. package/dist/src/contract/evaluator.d.ts.map +1 -0
  39. package/dist/src/contract/evaluator.js +158 -0
  40. package/dist/src/contract/evaluator.js.map +1 -0
  41. package/dist/src/contract/evidence-store.d.ts +17 -0
  42. package/dist/src/contract/evidence-store.d.ts.map +1 -0
  43. package/dist/src/contract/evidence-store.js +113 -0
  44. package/dist/src/contract/evidence-store.js.map +1 -0
  45. package/dist/src/contract/executors/zero-deps.d.ts +3 -0
  46. package/dist/src/contract/executors/zero-deps.d.ts.map +1 -0
  47. package/dist/src/contract/executors/zero-deps.js +88 -0
  48. package/dist/src/contract/executors/zero-deps.js.map +1 -0
  49. package/dist/src/contract/fingerprint.d.ts +34 -0
  50. package/dist/src/contract/fingerprint.d.ts.map +1 -0
  51. package/dist/src/contract/fingerprint.js +153 -0
  52. package/dist/src/contract/fingerprint.js.map +1 -0
  53. package/dist/src/contract/graph.d.ts +23 -0
  54. package/dist/src/contract/graph.d.ts.map +1 -0
  55. package/dist/src/contract/graph.js +158 -0
  56. package/dist/src/contract/graph.js.map +1 -0
  57. package/dist/src/contract/migration-map.d.ts +51 -0
  58. package/dist/src/contract/migration-map.d.ts.map +1 -0
  59. package/dist/src/contract/migration-map.js +130 -0
  60. package/dist/src/contract/migration-map.js.map +1 -0
  61. package/dist/src/contract/types.d.ts +108 -0
  62. package/dist/src/contract/types.d.ts.map +1 -0
  63. package/dist/src/contract/types.js +23 -0
  64. package/dist/src/contract/types.js.map +1 -0
  65. package/dist/src/index.d.ts +0 -2
  66. package/dist/src/index.d.ts.map +1 -1
  67. package/dist/src/index.js +0 -2
  68. package/dist/src/index.js.map +1 -1
  69. package/dist/src/integration/drain.d.ts +31 -0
  70. package/dist/src/integration/drain.d.ts.map +1 -0
  71. package/dist/src/integration/drain.js +195 -0
  72. package/dist/src/integration/drain.js.map +1 -0
  73. package/dist/src/integration/enqueue.d.ts +30 -0
  74. package/dist/src/integration/enqueue.d.ts.map +1 -0
  75. package/dist/src/integration/enqueue.js +64 -0
  76. package/dist/src/integration/enqueue.js.map +1 -0
  77. package/dist/src/integration/gitops.d.ts +33 -0
  78. package/dist/src/integration/gitops.d.ts.map +1 -0
  79. package/dist/src/integration/gitops.js +128 -0
  80. package/dist/src/integration/gitops.js.map +1 -0
  81. package/dist/src/integration/lease.d.ts +16 -0
  82. package/dist/src/integration/lease.d.ts.map +1 -0
  83. package/dist/src/integration/lease.js +140 -0
  84. package/dist/src/integration/lease.js.map +1 -0
  85. package/dist/src/integration/materialize.d.ts +7 -0
  86. package/dist/src/integration/materialize.d.ts.map +1 -0
  87. package/dist/src/integration/materialize.js +34 -0
  88. package/dist/src/integration/materialize.js.map +1 -0
  89. package/dist/src/integration/store.d.ts +21 -0
  90. package/dist/src/integration/store.d.ts.map +1 -0
  91. package/dist/src/integration/store.js +131 -0
  92. package/dist/src/integration/store.js.map +1 -0
  93. package/dist/src/integration/types.d.ts +71 -0
  94. package/dist/src/integration/types.d.ts.map +1 -0
  95. package/dist/src/integration/types.js +18 -0
  96. package/dist/src/integration/types.js.map +1 -0
  97. package/dist/src/onboarding/doctor.d.ts +0 -5
  98. package/dist/src/onboarding/doctor.d.ts.map +1 -1
  99. package/dist/src/onboarding/doctor.js +6 -79
  100. package/dist/src/onboarding/doctor.js.map +1 -1
  101. package/dist/src/onboarding/npm-token-check.d.ts +1 -1
  102. package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
  103. package/dist/src/onboarding/npm-token-check.js +2 -2
  104. package/dist/src/onboarding/npm-token-check.js.map +1 -1
  105. package/dist/src/sdk/context.d.ts +13 -0
  106. package/dist/src/sdk/context.d.ts.map +1 -0
  107. package/dist/src/sdk/context.js +128 -0
  108. package/dist/src/sdk/context.js.map +1 -0
  109. package/dist/src/sdk/loader.d.ts +25 -0
  110. package/dist/src/sdk/loader.d.ts.map +1 -0
  111. package/dist/src/sdk/loader.js +155 -0
  112. package/dist/src/sdk/loader.js.map +1 -0
  113. package/dist/src/sdk/scan.d.ts +16 -0
  114. package/dist/src/sdk/scan.d.ts.map +1 -0
  115. package/dist/src/sdk/scan.js +126 -0
  116. package/dist/src/sdk/scan.js.map +1 -0
  117. package/dist/src/sdk/skills-gen.d.ts +27 -0
  118. package/dist/src/sdk/skills-gen.d.ts.map +1 -0
  119. package/dist/src/sdk/skills-gen.js +87 -0
  120. package/dist/src/sdk/skills-gen.js.map +1 -0
  121. package/dist/src/sdk/types.d.ts +124 -0
  122. package/dist/src/sdk/types.d.ts.map +1 -0
  123. package/dist/src/sdk/types.js +34 -0
  124. package/dist/src/sdk/types.js.map +1 -0
  125. package/dist/src/utils/hash.d.ts +1 -0
  126. package/dist/src/utils/hash.d.ts.map +1 -1
  127. package/dist/src/utils/hash.js +4 -0
  128. package/dist/src/utils/hash.js.map +1 -1
  129. package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
  130. package/dist/src/utils/lockfile.d.ts.map +1 -0
  131. package/dist/src/utils/lockfile.js +70 -0
  132. package/dist/src/utils/lockfile.js.map +1 -0
  133. package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
  134. package/os/core/core.module.ts +3 -76
  135. package/os/core/handlers/assets-helpers.ts +2 -4
  136. package/os/core/handlers/determinism-check.ts +2 -3
  137. package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
  138. package/os/core/handlers/release-prepare.ts +2 -4
  139. package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
  140. package/os/flow/handlers/flow-peers.ts +1 -1
  141. package/os/flow/open-missions.ts +45 -0
  142. package/os/flow/preflight.ts +1 -1
  143. package/os/flow/tests/release-lines.test.ts +136 -0
  144. package/os/flow/tests/state-roots.test.ts +1 -48
  145. package/os/rfc/handlers/validate-corpus.test.ts +149 -0
  146. package/os/rfc/probe-batch.test.ts +253 -0
  147. package/os/rfc/probe-batch.ts +13 -6
  148. package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
  149. package/package.json +177 -506
  150. package/src/command-modules.ts +0 -2
  151. package/src/contract/core-nodes.ts +111 -0
  152. package/src/contract/evaluator.ts +207 -0
  153. package/src/contract/evidence-store.ts +119 -0
  154. package/src/contract/executors/zero-deps.ts +92 -0
  155. package/src/contract/fingerprint.ts +176 -0
  156. package/src/contract/graph.ts +181 -0
  157. package/src/contract/migration-map.ts +174 -0
  158. package/src/contract/types.ts +125 -0
  159. package/src/index.ts +0 -2
  160. package/src/integration/drain.ts +271 -0
  161. package/src/integration/enqueue.ts +92 -0
  162. package/src/integration/gitops.ts +174 -0
  163. package/src/integration/lease.ts +144 -0
  164. package/src/integration/materialize.ts +40 -0
  165. package/src/integration/store.ts +153 -0
  166. package/src/integration/types.ts +79 -0
  167. package/src/onboarding/doctor.ts +9 -96
  168. package/src/onboarding/npm-token-check.ts +3 -3
  169. package/src/sdk/context.ts +135 -0
  170. package/src/sdk/loader.ts +170 -0
  171. package/src/sdk/scan.ts +132 -0
  172. package/src/sdk/skills-gen.ts +104 -0
  173. package/src/sdk/types.ts +135 -0
  174. package/src/tests/pkg-health-self-scan.test.ts +29 -0
  175. package/src/tests/rfc-evidence-sync.test.ts +369 -0
  176. package/src/tests/skill-agents-sync.test.ts +192 -0
  177. package/src/utils/hash.ts +5 -0
  178. package/src/utils/lockfile.ts +78 -0
  179. package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
  180. package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
  181. package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
  182. package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
  183. package/dist/os/mission/handlers/archive.d.ts +0 -4
  184. package/dist/os/mission/handlers/archive.d.ts.map +0 -1
  185. package/dist/os/mission/handlers/archive.js +0 -583
  186. package/dist/os/mission/handlers/archive.js.map +0 -1
  187. package/dist/os/mission/importer-block.d.ts +0 -19
  188. package/dist/os/mission/importer-block.d.ts.map +0 -1
  189. package/dist/os/mission/importer-block.js +0 -124
  190. package/dist/os/mission/importer-block.js.map +0 -1
  191. package/dist/os/mission/index.d.ts +0 -2
  192. package/dist/os/mission/index.d.ts.map +0 -1
  193. package/dist/os/mission/index.js +0 -15
  194. package/dist/os/mission/index.js.map +0 -1
  195. package/dist/os/mission/lockfile.d.ts.map +0 -1
  196. package/dist/os/mission/lockfile.js +0 -138
  197. package/dist/os/mission/lockfile.js.map +0 -1
  198. package/dist/os/mission/mission.module.d.ts +0 -3
  199. package/dist/os/mission/mission.module.d.ts.map +0 -1
  200. package/dist/os/mission/mission.module.js +0 -63
  201. package/dist/os/mission/mission.module.js.map +0 -1
  202. package/dist/os/mission/open-missions.d.ts.map +0 -1
  203. package/dist/os/mission/open-missions.js +0 -42
  204. package/dist/os/mission/open-missions.js.map +0 -1
  205. package/dist/os/mission/types.d.ts +0 -23
  206. package/dist/os/mission/types.d.ts.map +0 -1
  207. package/dist/os/mission/types.js +0 -19
  208. package/dist/os/mission/types.js.map +0 -1
  209. package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
  210. package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
  211. package/dist/os/werkstatt/handlers/lock.js +0 -153
  212. package/dist/os/werkstatt/handlers/lock.js.map +0 -1
  213. package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
  214. package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
  215. package/dist/os/werkstatt/handlers/schema.js +0 -42
  216. package/dist/os/werkstatt/handlers/schema.js.map +0 -1
  217. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
  218. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
  219. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
  220. package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
  221. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
  222. package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
  223. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
  224. package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
  225. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
  226. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
  227. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
  228. package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
  229. package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
  230. package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
  231. package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
  232. package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
  233. package/dist/os/werkstatt/index.d.ts +0 -7
  234. package/dist/os/werkstatt/index.d.ts.map +0 -1
  235. package/dist/os/werkstatt/index.js +0 -18
  236. package/dist/os/werkstatt/index.js.map +0 -1
  237. package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
  238. package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
  239. package/dist/os/werkstatt/werkstatt.module.js +0 -91
  240. package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
  241. package/os/core/handlers/forge-autonomy-validate.ts +0 -276
  242. package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
  243. package/os/mission/handlers/archive.test.ts +0 -764
  244. package/os/mission/handlers/archive.ts +0 -711
  245. package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
  246. package/os/mission/importer-block.ts +0 -119
  247. package/os/mission/index.ts +0 -15
  248. package/os/mission/lockfile.ts +0 -152
  249. package/os/mission/mission.module.ts +0 -68
  250. package/os/mission/open-missions.ts +0 -50
  251. package/os/mission/types.ts +0 -42
  252. package/os/werkstatt/handlers/lock.ts +0 -168
  253. package/os/werkstatt/handlers/schema.ts +0 -47
  254. package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
  255. package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
  256. package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
  257. package/os/werkstatt/handlers/workspace-deps.ts +0 -56
  258. package/os/werkstatt/index.ts +0 -39
  259. package/os/werkstatt/werkstatt.module.ts +0 -95
  260. package/src/tests/doctor-autonomy.test.ts +0 -246
  261. package/src/tests/forge-autonomy-validate.test.ts +0 -159
  262. package/src/tests/werkstatt-lock.test.ts +0 -357
@@ -0,0 +1,40 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Candidate tree materialization (Werkstatt RFC-1647) — the contract graph evaluates
5
+ the exact content that would integrate. The frozen candidate tree object is
6
+ expanded into an ephemeral filesystem root via git archive; callers own cleanup.
7
+ </purpose>
8
+ <non-goals>
9
+ <item>No caching of materializations — evaluation frequency is human-scale.</item>
10
+ </non-goals>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1647 (WP-4): initial materializer.</item>
13
+ </CHANGE_SUMMARY>
14
+ */
15
+
16
+ import { execFileSync } from "node:child_process";
17
+ import { mkdtempSync, rmSync } from "node:fs";
18
+ import { tmpdir } from "node:os";
19
+ import { join } from "node:path";
20
+
21
+ export interface MaterializedTree {
22
+ root: string;
23
+ cleanup(): void;
24
+ }
25
+
26
+ /** Expand a git tree object into a fresh ephemeral directory. */
27
+ export function materializeTree(repoDir: string, treeDigest: string): MaterializedTree {
28
+ const root = mkdtempSync(join(tmpdir(), "forge-candidate-"));
29
+ // git archive writes a tar of the tree to stdout — expand in place.
30
+ execFileSync("sh", ["-c", `git archive "${treeDigest}" | tar -x -C "${root}"`], {
31
+ cwd: repoDir,
32
+ stdio: ["ignore", "pipe", "pipe"],
33
+ });
34
+ return {
35
+ root,
36
+ cleanup() {
37
+ rmSync(root, { recursive: true, force: true });
38
+ },
39
+ };
40
+ }
@@ -0,0 +1,153 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Queue persistence (Werkstatt RFC-1647) — atomic enqueue via staging plus a single
5
+ journal append; append-only journal as the source of truth with bounded fold via
6
+ checkpoints; unit records immutable once terminal. A journal entry referencing a
7
+ missing or incomplete unit record is proof of crash-mid-enqueue and is discarded
8
+ as never-enqueued.
9
+ </purpose>
10
+ <non-goals>
11
+ <item>No lease or drain logic — persistence only.</item>
12
+ </non-goals>
13
+ <CHANGE_SUMMARY>
14
+ <item>RFC-1647 (WP-4): initial queue store.</item>
15
+ </CHANGE_SUMMARY>
16
+ */
17
+
18
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, readdirSync, renameSync, unlinkSync, writeSync } from "node:fs";
19
+ import { randomBytes } from "node:crypto";
20
+ import { join } from "node:path";
21
+
22
+ import type { IntegrationUnit, QueueJournalEntry } from "./types.ts";
23
+
24
+ function atomicWrite(path: string, content: string): void {
25
+ mkdirSync(join(path, ".."), { recursive: true });
26
+ const tmp = join(join(path, ".."), `.tmp-${randomBytes(8).toString("hex")}`);
27
+ const fd = openSync(tmp, "w");
28
+ try {
29
+ writeSync(fd, content);
30
+ } finally {
31
+ closeSync(fd);
32
+ }
33
+ renameSync(tmp, path);
34
+ }
35
+
36
+ export interface QueueStore {
37
+ /**
38
+ * Atomic enqueue: the unit record is staged, then becomes visible through one
39
+ * atomic journal append. Either the unit exists complete in the queue or not
40
+ * at all — partial units are impossible by construction.
41
+ */
42
+ enqueue(unit: IntegrationUnit): void;
43
+ appendJournal(entry: QueueJournalEntry): void;
44
+ readUnit(id: string): IntegrationUnit | null;
45
+ writeUnit(unit: IntegrationUnit): void;
46
+ /** All live units folded from journal + records — never-enqueued partial entries discarded. */
47
+ units(): IntegrationUnit[];
48
+ journal(): QueueJournalEntry[];
49
+ checkpoint(): void;
50
+ queueDir: string;
51
+ }
52
+
53
+ export function createQueueStore(queueDir: string): QueueStore {
54
+ const unitsDir = join(queueDir, "units");
55
+ const journalPath = join(queueDir, "journal.log");
56
+ const checkpointPath = join(queueDir, "checkpoint.json");
57
+ mkdirSync(unitsDir, { recursive: true });
58
+
59
+ function unitPath(id: string): string {
60
+ return join(unitsDir, `${id}.json`);
61
+ }
62
+
63
+ function appendJournal(entry: QueueJournalEntry): void {
64
+ mkdirSync(queueDir, { recursive: true });
65
+ const fd = openSync(journalPath, "a");
66
+ try {
67
+ writeSync(fd, JSON.stringify(entry) + "\n");
68
+ } finally {
69
+ closeSync(fd);
70
+ }
71
+ }
72
+
73
+ function readJournalRaw(): QueueJournalEntry[] {
74
+ if (!existsSync(journalPath)) return [];
75
+ return readFileSync(journalPath, "utf8")
76
+ .split("\n")
77
+ .filter((l) => l.trim().length > 0)
78
+ .map((l) => JSON.parse(l) as QueueJournalEntry);
79
+ }
80
+
81
+ function readUnit(id: string): IntegrationUnit | null {
82
+ try {
83
+ return JSON.parse(readFileSync(unitPath(id), "utf8")) as IntegrationUnit;
84
+ } catch {
85
+ return null;
86
+ }
87
+ }
88
+
89
+ function writeUnit(unit: IntegrationUnit): void {
90
+ atomicWrite(unitPath(unit.id), JSON.stringify(unit, null, 2));
91
+ }
92
+
93
+ function units(): IntegrationUnit[] {
94
+ // Fold the journal: a unit is live when its enqueued entry resolves to a
95
+ // complete record. Entries referencing missing/incomplete records are proof
96
+ // of crash-mid-enqueue — discarded as never-enqueued.
97
+ const entries = readJournalRaw();
98
+ const ids: string[] = [];
99
+ for (const e of entries) {
100
+ if (e.transition === "enqueued" && !ids.includes(e.unitId)) {
101
+ if (readUnit(e.unitId) != null) ids.push(e.unitId);
102
+ }
103
+ }
104
+ return ids.map((id) => readUnit(id)!).filter(Boolean);
105
+ }
106
+
107
+ return {
108
+ queueDir,
109
+ enqueue(unit) {
110
+ // Stage the complete record first, then the single atomic journal append
111
+ // that makes it visible. Reverse order would expose a referencing entry
112
+ // without a record; this order makes crash-mid-enqueue detectable and
113
+ // discardable.
114
+ writeUnit(unit);
115
+ appendJournal({
116
+ schema: "forge:queue-journal/v1",
117
+ unitId: unit.id,
118
+ transition: "enqueued",
119
+ at: new Date().toISOString(),
120
+ actor: `session:${unit.source.sessionId}`,
121
+ });
122
+ },
123
+ appendJournal,
124
+ readUnit,
125
+ writeUnit,
126
+ units,
127
+ journal: readJournalRaw,
128
+ checkpoint() {
129
+ // Fold-on-read stays bounded by checkpoint spacing, not journal age.
130
+ const snapshot = {
131
+ at: new Date().toISOString(),
132
+ units: units().map((u) => ({ id: u.id, state: u.state })),
133
+ };
134
+ atomicWrite(checkpointPath, JSON.stringify(snapshot, null, 2));
135
+ },
136
+ };
137
+ }
138
+
139
+ /** Garbage-collect staging residue older than crash windows — safe because incomplete units are never visible. */
140
+ export function cleanStagingResidue(queueDir: string): number {
141
+ const staging = join(queueDir, "staging");
142
+ if (!existsSync(staging)) return 0;
143
+ let removed = 0;
144
+ for (const entry of readdirSync(staging)) {
145
+ try {
146
+ unlinkSync(join(staging, entry));
147
+ removed += 1;
148
+ } catch {
149
+ // concurrent writer — leave it
150
+ }
151
+ }
152
+ return removed;
153
+ }
@@ -0,0 +1,79 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ Transactional integration queue types (Werkstatt RFC-1647) — immutable units,
5
+ the unit state machine, drain leases, and the append-only queue journal.
6
+ Mutable bookkeeping is separated from evidence per RFC-1646.
7
+ </purpose>
8
+ <non-goals>
9
+ <item>No drain/store logic — types only.</item>
10
+ </non-goals>
11
+ <CHANGE_SUMMARY>
12
+ <item>RFC-1647 (WP-4): initial queue contracts.</item>
13
+ </CHANGE_SUMMARY>
14
+ */
15
+
16
+ /** Immutable unit of integration — frozen at enqueue, never mutated. */
17
+ export interface IntegrationUnit {
18
+ schema: "forge:integration-unit/v1";
19
+ /** uuidv7-style time-ordered id. */
20
+ id: string;
21
+ /** Frozen session tree — git tree object id is the content digest. */
22
+ treeDigest: string;
23
+ /** Governed ref digest at enqueue time. */
24
+ baseRef: string;
25
+ source: {
26
+ sessionId: string;
27
+ /** Informational only. */
28
+ worktreePath: string;
29
+ /** RFC/ADR/friction anchors. */
30
+ governanceIds: string[];
31
+ };
32
+ /** Commit chain preserved for replay, oldest first — squash is forbidden. */
33
+ commitChain: string[];
34
+ enqueuedAt: string;
35
+ state: UnitState;
36
+ /** Crash-recovery counter, not retry-of-failure. */
37
+ attempts: number;
38
+ }
39
+
40
+ export type UnitState =
41
+ | { status: "queued" }
42
+ | { status: "evaluating"; leaseId: string; since: string }
43
+ | { status: "integrated"; commitSha: string; evidenceKey: string }
44
+ | { status: "refused"; reason: RefusalReason; evidenceKey: string }
45
+ | { status: "conflicted"; conflictingPaths: string[] }
46
+ | { status: "cancelled"; by: string };
47
+
48
+ export interface RefusalReason {
49
+ /** The blocking contract node — one explanation path. */
50
+ nodeId: string;
51
+ summary: string;
52
+ violations: number;
53
+ }
54
+
55
+ export interface DrainLease {
56
+ leaseId: string;
57
+ workerPid: number;
58
+ /** Same-machine fencing, inheriting the v9 machine-local trust model. */
59
+ hostBootId: string;
60
+ acquiredAt: string;
61
+ /** Expiry = heartbeat + leaseTtl. */
62
+ heartbeatAt: string;
63
+ }
64
+
65
+ export interface QueueJournalEntry {
66
+ schema: "forge:queue-journal/v1";
67
+ unitId: string;
68
+ transition: "enqueued" | "evaluating" | "integrated" | "refused" | "conflicted" | "cancelled" | "requeued";
69
+ at: string;
70
+ /** drain:<leaseId> | session:<id> | operator */
71
+ actor: string;
72
+ detail?: Record<string, string>;
73
+ }
74
+
75
+ export type TerminalStatus = "integrated" | "refused" | "conflicted" | "cancelled";
76
+
77
+ export function isTerminal(state: UnitState): boolean {
78
+ return state.status === "integrated" || state.status === "refused" || state.status === "conflicted" || state.status === "cancelled";
79
+ }
@@ -2,7 +2,7 @@
2
2
  <MODULE_CONTRACT>
3
3
  <purpose>forge.doctor — diagnoses forge state in an existing project.
4
4
  Checks for forge.yaml, AGENTS.md, PREFERENCES.md, .agents/skills/, docs/rfcs/,
5
- @warpgogol/* import autonomy guard, and bindings contract (RFC-0393).</purpose>
5
+ bindings contract (RFC-0393).</purpose>
6
6
  <non-goals>
7
7
  <item>Do not modify files — doctor is read-only diagnostics.</item>
8
8
  </non-goals>
@@ -27,7 +27,7 @@ import {
27
27
  commentStyleForPath,
28
28
  } from "../utils/index.ts";
29
29
  import { readFileSync, existsSync } from "../utils/sync-fs.ts";
30
- import { join, relative, dirname, resolve, sep } from "node:path";
30
+ import { join, relative, dirname, resolve } from "node:path";
31
31
  import picomatch from "picomatch";
32
32
  import { parse as parseYaml } from "yaml";
33
33
  import { forgePluginManifestSchema } from "../plugin/forge-plugin-manifest.ts";
@@ -77,10 +77,6 @@ interface DoctorCheck {
77
77
  unmappedFiles?: string[];
78
78
  }
79
79
 
80
- interface ForbiddenImport {
81
- file: string;
82
- specifier: string;
83
- }
84
80
 
85
81
  interface BindingValidation {
86
82
  resolved: string[];
@@ -99,26 +95,6 @@ async function pathExists(target: string, io: WorkspaceIO): Promise<boolean> {
99
95
  return io.exists(target);
100
96
  }
101
97
 
102
- // FORGE-AUTONOMY-01 (RFC-0940, ADR-0019): `import type` statements are exempt
103
- // (erased at compile time); `os/werkstatt/` is the declared werkstatt-adapter
104
- // boundary and may import @warpgogol/*; other `os/` dirs may not import
105
- // @warpgogol/werkstatt-engine but may use @warpgogol/werkstatt-shared (exempt
106
- // shared infrastructure); `src/` and the rest of the tree may not carry any
107
- // runtime @warpgogol/* import. dist/, tests dirs, and *.test.ts/*.spec.ts/
108
- // *.d.ts are generated or fixture surfaces, not scanned source.
109
- const FORBIDDEN_IMPORT_PATTERN =
110
- /(?:^|\n)\s*(import\s+[^;]+?\s+from\s+|require\s*\(\s*)["'`](@warpgogol\/[^"'`]+)["'`]/g;
111
-
112
- const AUTONOMY_EXCLUDE_DIRS = new Set([
113
- "node_modules",
114
- "dist",
115
- "tests",
116
- "tests-handoff",
117
- "templates",
118
- ]);
119
- const AUTONOMY_EXCLUDE_SUFFIXES = [".test.ts", ".spec.ts", ".d.ts"];
120
- const ENGINE_SPECIFIER = "@warpgogol/werkstatt-engine";
121
-
122
98
  // Per-check fix hints for the pretty-output failure line — a generic
123
99
  // "run 'forge create'" hint is wrong for checks create cannot repair.
124
100
  const CHECK_FIX_HINTS: Record<string, string> = {
@@ -129,59 +105,10 @@ const CHECK_FIX_HINTS: Record<string, string> = {
129
105
  "npm-token (@warpgogol)": "configure a @warpgogol npm token in .npmrc",
130
106
  "git-branch": "rename the default branch to 'main'",
131
107
  "domain-invariants": "fix the reported invariant violations",
132
- "autonomy-guard":
133
- "remove the flagged @warpgogol/* imports or place them behind the os/werkstatt/ adapter boundary (FORGE-AUTONOMY-01)",
134
108
  bindings: "fix the invalid forge.yaml bindings",
135
109
  "outcome-config": "declare the outcomeBuild/outcomeServe bindings or drop the outcomeSurfaces entry",
136
110
  };
137
111
 
138
- function isForbiddenSpecifier(specifier: string, relToForge: string): boolean {
139
- if (relToForge.startsWith("os/werkstatt/")) return false;
140
- if (relToForge.startsWith("os/")) {
141
- return specifier === ENGINE_SPECIFIER || specifier.startsWith(`${ENGINE_SPECIFIER}/`);
142
- }
143
- return true;
144
- }
145
-
146
- async function scanForForbiddenImports(
147
- dir: string,
148
- forgeRoot: string,
149
- workspaceRoot: string,
150
- io: WorkspaceIO,
151
- ): Promise<ForbiddenImport[]> {
152
- const violations: ForbiddenImport[] = [];
153
- const entries = await io.readdir(dir).catch(() => []);
154
-
155
- for (const entry of entries) {
156
- const fullPath = join(dir, entry.name);
157
-
158
- if (entry.isDirectory) {
159
- if (AUTONOMY_EXCLUDE_DIRS.has(entry.name)) continue;
160
- const sub = await scanForForbiddenImports(fullPath, forgeRoot, workspaceRoot, io);
161
- violations.push(...sub);
162
- } else if (
163
- entry.name.endsWith(".ts") &&
164
- !AUTONOMY_EXCLUDE_SUFFIXES.some((suffix) => entry.name.endsWith(suffix))
165
- ) {
166
- const relToForge = relative(forgeRoot, fullPath).split(sep).join("/");
167
- const content = await io.readFile(fullPath).catch(() => "");
168
- let match: RegExpExecArray | null;
169
- const pattern = new RegExp(FORBIDDEN_IMPORT_PATTERN.source, "g");
170
- while ((match = pattern.exec(content)) !== null) {
171
- if (/\bimport\s+type\b/.test(match[1]!)) continue;
172
- const specifier = match[2]!;
173
- if (!isForbiddenSpecifier(specifier, relToForge)) continue;
174
- violations.push({
175
- file: relative(workspaceRoot, fullPath),
176
- specifier,
177
- });
178
- }
179
- }
180
- }
181
-
182
- return violations;
183
- }
184
-
185
112
  // ---------------------------------------------------------------------------
186
113
  // Bindings validation (RFC-0393)
187
114
  // ---------------------------------------------------------------------------
@@ -1481,7 +1408,7 @@ function checkPrerequisites(prerequisites: ProfilePrerequisite[]): DoctorCheck {
1481
1408
  export async function runDoctor(
1482
1409
  input: ForgeCommandInput,
1483
1410
  context: ForgeRuntimeContext,
1484
- ): Promise<ForgeCommandResult<{ command: string; checks: DoctorCheck[]; allPass: boolean; forbiddenImports: ForbiddenImport[]; bindings: BindingValidation; domain?: DomainReport; fixes?: DoctorFixResult[] }>> {
1411
+ ): Promise<ForgeCommandResult<{ command: string; checks: DoctorCheck[]; allPass: boolean; bindings: BindingValidation; domain?: DomainReport; fixes?: DoctorFixResult[] }>> {
1485
1412
  const { workspaceRoot, logger, outputFormat, dryRun } = context;
1486
1413
  const fio = resolveIo(context.io);
1487
1414
  const strict = input.flags["strict"] === true;
@@ -1559,7 +1486,7 @@ export async function runDoctor(
1559
1486
  name: "npm-token (@warpgogol)",
1560
1487
  status: tokenCheck.canFetch ? "pass" : "fail",
1561
1488
  message: tokenCheck.canFetch
1562
- ? `npm token fetches @warpgogol/werkstatt-engine (${tokenCheck.registry ?? "default registry"})`
1489
+ ? `registry fetches @warpgogol/forge (${tokenCheck.registry ?? "default registry"})`
1563
1490
  : tokenCheck.fixHint!,
1564
1491
  });
1565
1492
  }
@@ -1567,7 +1494,7 @@ export async function runDoctor(
1567
1494
  // Check git branch is 'main' (not 'master')
1568
1495
  checks.push(checkGitBranch(workspaceRoot));
1569
1496
 
1570
- // Check @warpgogol/* forbidden imports (autonomy guard)
1497
+
1571
1498
  let forgeRoot: string;
1572
1499
  try {
1573
1500
  forgeRoot = resolveForgeRoot(workspaceRoot);
@@ -1575,6 +1502,9 @@ export async function runDoctor(
1575
1502
  forgeRoot = join(workspaceRoot, "packages", "forge");
1576
1503
  }
1577
1504
 
1505
+ // Source-scanning checks distinguish development checkouts from immutable npm installs.
1506
+ const forgeSourceCheckout = isForgeSourceCheckout(forgeRoot);
1507
+
1578
1508
  // RFC-0640: Resolve domain report for domain-aware checks
1579
1509
  const domainReport = resolveDomainReport(workspaceRoot, forgeRoot);
1580
1510
 
@@ -1648,23 +1578,6 @@ export async function runDoctor(
1648
1578
  : `${invalidProfiles.length} profile(s) invalid (advisory): ${invalidProfiles.map((p) => p.id).join(", ")}`,
1649
1579
  });
1650
1580
 
1651
- // Source-scanning checks only make sense on a forge development checkout —
1652
- // the published tarball ships src/ and os/, but an installed package's
1653
- // source is immutable and a finding there is not actionable for consumers.
1654
- const forgeSourceCheckout = isForgeSourceCheckout(forgeRoot);
1655
- const forbiddenImports = forgeSourceCheckout
1656
- ? await scanForForbiddenImports(forgeRoot, forgeRoot, workspaceRoot, fio)
1657
- : [];
1658
- checks.push({
1659
- name: "autonomy-guard",
1660
- status: forbiddenImports.length === 0 ? "pass" : "fail",
1661
- message:
1662
- forbiddenImports.length === 0
1663
- ? forgeSourceCheckout
1664
- ? "No @warpgogol/* imports in forge source"
1665
- : "npm-installed forge — source autonomy check skipped"
1666
- : `${forbiddenImports.length} @warpgogol/* import(s) found in forge source — remove them`,
1667
- });
1668
1581
 
1669
1582
  // Check bindings contract (RFC-0393)
1670
1583
  const bindingsResult = await validateBindings(workspaceRoot, fio);
@@ -1798,7 +1711,7 @@ export async function runDoctor(
1798
1711
  const fixFailed = fixes.some((f) => f.action === "failed");
1799
1712
 
1800
1713
  return {
1801
- data: { command: "forge.doctor", checks: finalChecks, allPass, forbiddenImports, bindings: bindingsResult, domain: domainReport, ...(fix ? { fixes } : {}) },
1714
+ data: { command: "forge.doctor", checks: finalChecks, allPass, bindings: bindingsResult, domain: domainReport, ...(fix ? { fixes } : {}) },
1802
1715
  exitCode: hasFails || fixFailed ? 1 : 0,
1803
1716
  summary: allPass
1804
1717
  ? "forge.doctor: all checks passed"
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  <MODULE_CONTRACT>
3
- <purpose>Non-interactive npm-token probe for the private @warpgogol registry scope (RFC-1125) — parses .npmrc for the @warpgogol scope registry and auth token presence, probes the registry via `npm view @warpgogol/werkstatt-engine version` (injectable for tests) before pnpm install runs in forge create, re-verifies post-install in forge.doctor, and returns a structured NpmTokenCheck with an actionable fixHint on failure.</purpose>
3
+ <purpose>Non-interactive npm-token probe for the private @warpgogol registry scope (RFC-1125) — parses .npmrc for the @warpgogol scope registry and auth token presence, probes the registry via `npm view @warpgogol/forge version` (injectable for tests) before pnpm install runs in forge create, re-verifies post-install in forge.doctor, and returns a structured NpmTokenCheck with an actionable fixHint on failure.</purpose>
4
4
  <non-goals>
5
5
  <item>Do not prompt the operator — the probe is non-interactive (create.ts forbids prompts).</item>
6
6
  <item>Do not accept tokens via CLI flags — tokens must not appear in argv/history.</item>
@@ -22,7 +22,7 @@ export interface NpmTokenCheck {
22
22
  registry: string | null;
23
23
  /** A usable token is configured — NPM_TOKEN env or a real _authToken value. */
24
24
  tokenPresent: boolean;
25
- /** `npm view @warpgogol/werkstatt-engine version` succeeded from workspaceRoot. */
25
+ /** `npm view @warpgogol/forge version` succeeded from workspaceRoot. */
26
26
  canFetch: boolean;
27
27
  /** Actionable remediation when canFetch is false; null on success. */
28
28
  fixHint: string | null;
@@ -37,7 +37,7 @@ export interface NpmTokenProbeDeps {
37
37
  }
38
38
 
39
39
  const WARPGOGOL_SCOPE = "@warpgogol";
40
- const PROBE_PACKAGE = "@warpgogol/werkstatt-engine";
40
+ const PROBE_PACKAGE = "@warpgogol/forge";
41
41
  const PROBE_TIMEOUT_MS = 15_000;
42
42
  const PLACEHOLDER_TOKENS = new Set(["YOUR_NPM_TOKEN", ""]);
43
43
 
@@ -0,0 +1,135 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>
4
+ PluginContext factory (Werkstatt RFC-1648) — every port enforces the manifest's
5
+ capability declarations at runtime. Omitted capabilities are default-deny: a
6
+ manifest without a capability block receives no filesystem write, no network, no
7
+ spawn, no git mutation. This is auditability, not a sandbox.
8
+ </purpose>
9
+ <non-goals><item>No static circumvention scan — that lives in the contract node.</item></non-goals>
10
+ <CHANGE_SUMMARY><item>RFC-1648 (WP-5): initial capability-enforcing context.</item></CHANGE_SUMMARY>
11
+ */
12
+
13
+ import { access, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
14
+ import { execFile } from "node:child_process";
15
+ import { dirname, resolve as pathResolve } from "node:path";
16
+ import { promisify } from "node:util";
17
+
18
+ import { CapabilityViolation, type PluginContext, type PluginManifest } from "./types.ts";
19
+
20
+ const execFileAsync = promisify(execFile);
21
+
22
+ export interface ContextHostServices {
23
+ /** Repo/workspace root the plugin is scoped to. */
24
+ workspaceRoot: string;
25
+ bindings?: Record<string, unknown>;
26
+ hooks?: {
27
+ evidenceConsult?: PluginContext["evidence"]["consult"];
28
+ registerNode?: PluginContext["contracts"]["registerNode"];
29
+ };
30
+ }
31
+
32
+ /** Build a capability-enforcing PluginContext for one activated plugin. */
33
+ export function createPluginContext(manifest: PluginManifest, host: ContextHostServices): PluginContext {
34
+ const caps = manifest.capabilities ?? {};
35
+ const pid = manifest.id;
36
+ const fsGrant = caps.filesystem ?? "none";
37
+
38
+ const deny = (capability: string, detail: string): never => {
39
+ throw new CapabilityViolation(capability, pid, detail);
40
+ };
41
+
42
+ const scoped = (path: string): string => {
43
+ const resolved = pathResolve(host.workspaceRoot, path);
44
+ if (!resolved.startsWith(pathResolve(host.workspaceRoot))) {
45
+ deny("filesystem", `path escape outside workspace root: ${path}`);
46
+ }
47
+ return resolved;
48
+ };
49
+
50
+ return {
51
+ workspace: {
52
+ async readFile(path) {
53
+ if (fsGrant === "none") deny("filesystem", "readFile with filesystem:none");
54
+ return readFile(scoped(path), "utf8");
55
+ },
56
+ async writeFile(path, content) {
57
+ if (fsGrant !== "readwrite") deny("filesystem", `writeFile with filesystem:${fsGrant}`);
58
+ const target = scoped(path);
59
+ await mkdir(dirname(target), { recursive: true });
60
+ await writeFile(target, content);
61
+ },
62
+ async exists(path) {
63
+ if (fsGrant === "none") return false;
64
+ try {
65
+ await access(scoped(path));
66
+ return true;
67
+ } catch {
68
+ return false;
69
+ }
70
+ },
71
+ async list(dir) {
72
+ if (fsGrant === "none") deny("filesystem", "list with filesystem:none");
73
+ return readdir(scoped(dir));
74
+ },
75
+ },
76
+ evidence: {
77
+ consult: host.hooks?.evidenceConsult ?? (async () => ({ hit: false })),
78
+ },
79
+ contracts: {
80
+ registerNode: host.hooks?.registerNode ?? (() => ({ ok: false as const, errors: ["contract registration unavailable in this host"] })),
81
+ },
82
+ bindings: {
83
+ get<T>(key: string): T | undefined {
84
+ return host.bindings?.[key] as T | undefined;
85
+ },
86
+ require<T>(key: string): T {
87
+ const v = host.bindings?.[key];
88
+ if (v === undefined) throw new Error(`required binding missing: ${key}`);
89
+ return v as T;
90
+ },
91
+ },
92
+ git: {
93
+ async exec(args) {
94
+ if (!caps.gitMutation && ["commit", "push", "update-ref", "checkout", "reset", "rebase", "merge", "cherry-pick", "apply"].some((m) => args[0] === m)) {
95
+ deny("gitMutation", `mutating git op refused: git ${args[0]}`);
96
+ }
97
+ const { stdout } = await execFileAsync("git", args, { cwd: host.workspaceRoot });
98
+ return stdout;
99
+ },
100
+ },
101
+ process: {
102
+ async spawn(cmd, args, opts) {
103
+ if (!caps.processSpawn) deny("processSpawn", `spawn refused: ${cmd}`);
104
+ const timeoutMs = opts?.timeoutMs ?? 120_000; // mandatory timeouts — hanging commands die as executor error
105
+ try {
106
+ const { stdout, stderr } = await execFileAsync(cmd, args, {
107
+ cwd: opts?.cwd ?? host.workspaceRoot,
108
+ timeout: timeoutMs,
109
+ maxBuffer: 16 * 1024 * 1024,
110
+ });
111
+ return { stdout, stderr, exitCode: 0 };
112
+ } catch (err) {
113
+ const e = err as { stdout?: string; stderr?: string; code?: number };
114
+ return { stdout: e.stdout ?? "", stderr: e.stderr ?? "", exitCode: typeof e.code === "number" ? e.code : 1 };
115
+ }
116
+ },
117
+ },
118
+ network: {
119
+ async fetch(url, init) {
120
+ if (!caps.network) deny("network", `fetch refused: ${url}`);
121
+ const res = await fetch(url, init);
122
+ return { status: res.status, body: await res.text() };
123
+ },
124
+ },
125
+ log: {
126
+ info: (msg) => console.log(`[${pid}] ${msg}`),
127
+ warn: (msg) => console.warn(`[${pid}] ${msg}`),
128
+ error: (msg) => console.error(`[${pid}] ${msg}`),
129
+ },
130
+ paths: {
131
+ resolve: (...parts) => pathResolve(host.workspaceRoot, ...parts),
132
+ root: () => host.workspaceRoot,
133
+ },
134
+ };
135
+ }