@warpgogol/forge 2.8.0 → 2.8.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.
- package/AGENTS.md +1 -1
- package/README.md +23 -13
- package/README.uk.md +19 -12
- package/dist/os/session/handlers/validate.d.ts.map +1 -1
- package/dist/os/session/handlers/validate.js +23 -1
- package/dist/os/session/handlers/validate.js.map +1 -1
- package/dist/os/session/types.d.ts +31 -1
- package/dist/os/session/types.d.ts.map +1 -1
- package/dist/os/session/types.js +7 -0
- package/dist/os/session/types.js.map +1 -1
- package/os/adr/adr.module.ts +158 -0
- package/os/adr/frontmatter-io.ts +80 -0
- package/os/adr/handlers/archive.ts +244 -0
- package/os/adr/handlers/implement-stamp.ts +331 -0
- package/os/adr/handlers/list-create.ts +207 -0
- package/os/adr/handlers/validate.test.ts +232 -0
- package/os/adr/handlers/validate.ts +429 -0
- package/os/adr/index.ts +33 -0
- package/os/adr/types.ts +141 -0
- package/os/audit/audit.module.ts +48 -0
- package/os/audit/frontmatter-io.ts +84 -0
- package/os/audit/handlers/archive.ts +239 -0
- package/os/audit/index.ts +23 -0
- package/os/audit/types.ts +29 -0
- package/os/compass/compass.module.ts +186 -0
- package/os/compass/handlers/compass-audit-handler.ts +382 -0
- package/os/compass/handlers/compass-change-summary-handler.ts +272 -0
- package/os/compass/handlers/compass-inventory-handler.ts +294 -0
- package/os/compass/handlers/compass-inventory.ts +521 -0
- package/os/compass/handlers/git-revision.ts +137 -0
- package/os/compass/handlers/resolve-scan-root-workpiece.test.ts +65 -0
- package/os/compass/handlers/resolve-scan-root.ts +79 -0
- package/os/compass/index.ts +33 -0
- package/os/core/core.module.ts +948 -0
- package/os/core/handlers/assets-check.ts +122 -0
- package/os/core/handlers/assets-helpers.ts +174 -0
- package/os/core/handlers/assets-list.ts +99 -0
- package/os/core/handlers/build.ts +155 -0
- package/os/core/handlers/determinism-check.ts +354 -0
- package/os/core/handlers/dev.ts +127 -0
- package/os/core/handlers/invariant-engine.test.ts +681 -0
- package/os/core/handlers/knowledge-compact.ts +248 -0
- package/os/core/handlers/lifecycle-handlers.test.ts +524 -0
- package/os/core/handlers/note-frontmatter-validate.test.ts +93 -0
- package/os/core/handlers/note-link-validate.test.ts +117 -0
- package/os/core/handlers/note-orphan-detect.test.ts +94 -0
- package/os/core/handlers/package-health.test.ts +226 -0
- package/os/core/handlers/package-health.ts +231 -0
- package/os/core/handlers/pinned-check.ts +200 -0
- package/os/core/handlers/pinned-init.ts +333 -0
- package/os/core/handlers/pinned-types.ts +50 -0
- package/os/core/handlers/pinned-validate.ts +301 -0
- package/os/core/handlers/profile-resolve.ts +92 -0
- package/os/core/handlers/release-prepare.ts +294 -0
- package/os/core/handlers/release-publish.ts +211 -0
- package/os/core/handlers/validate.ts +262 -0
- package/os/core/handlers/workspace-deps.ts +55 -0
- package/os/core/index.ts +13 -0
- package/os/exploration/exploration.module.ts +90 -0
- package/os/exploration/frontmatter-io.ts +77 -0
- package/os/exploration/handlers/archive.ts +159 -0
- package/os/exploration/handlers/list.ts +77 -0
- package/os/exploration/handlers/show.ts +107 -0
- package/os/exploration/index.ts +25 -0
- package/os/exploration/types.ts +65 -0
- package/os/mission/handlers/archive.test.ts +391 -0
- package/os/mission/handlers/archive.ts +453 -0
- package/os/mission/index.ts +1 -0
- package/os/mission/mission.module.ts +48 -0
- package/os/mission/types.ts +41 -0
- package/os/naming/index.ts +14 -0
- package/os/naming/naming-convention.test.ts +163 -0
- package/os/naming/naming-convention.ts +378 -0
- package/os/naming/naming.module.ts +36 -0
- package/os/notes/index.ts +10 -0
- package/os/notes/notes.module.ts +109 -0
- package/os/plan/frontmatter-io.ts +82 -0
- package/os/plan/handlers/archive.ts +238 -0
- package/os/plan/index.ts +23 -0
- package/os/plan/plan.module.ts +48 -0
- package/os/plan/types.ts +29 -0
- package/os/program/discovery.ts +294 -0
- package/os/program/handlers/complete.ts +419 -0
- package/os/program/handlers/lease.ts +433 -0
- package/os/program/handlers/seal.ts +332 -0
- package/os/program/handlers/validate.ts +213 -0
- package/os/program/lease.ts +156 -0
- package/os/program/program.module.ts +212 -0
- package/os/program/schemas.ts +218 -0
- package/os/program/state.ts +264 -0
- package/os/rfc/acceptance.ts +344 -0
- package/os/rfc/decision-log.ts +310 -0
- package/os/rfc/dna-trace.ts +280 -0
- package/os/rfc/frontmatter-io.test.ts +132 -0
- package/os/rfc/frontmatter-io.ts +130 -0
- package/os/rfc/handlers/archive.ts +300 -0
- package/os/rfc/handlers/check.ts +238 -0
- package/os/rfc/handlers/implement-stamp.ts +515 -0
- package/os/rfc/handlers/index-graph.ts +237 -0
- package/os/rfc/handlers/lifecycle.test.ts +127 -0
- package/os/rfc/handlers/lifecycle.ts +249 -0
- package/os/rfc/handlers/list-create.ts +296 -0
- package/os/rfc/handlers/pipeline-status.ts +173 -0
- package/os/rfc/handlers/shared.ts +121 -0
- package/os/rfc/handlers/supersede-propose.ts +241 -0
- package/os/rfc/handlers/validate-rules.test.ts +891 -0
- package/os/rfc/handlers/validate-rules.ts +984 -0
- package/os/rfc/handlers/validate.ts +166 -0
- package/os/rfc/handlers.ts +19 -0
- package/os/rfc/index.ts +97 -0
- package/os/rfc/rfc.module.ts +416 -0
- package/os/rfc/types.ts +596 -0
- package/os/rfc/verification-evidence.ts +244 -0
- package/os/session/atif-parser.ts +166 -0
- package/os/session/frontmatter-io.ts +163 -0
- package/os/session/handlers/archive.ts +288 -0
- package/os/session/handlers/list.ts +174 -0
- package/os/session/handlers/save.ts +348 -0
- package/os/session/handlers/validate.ts +250 -0
- package/os/session/index.ts +50 -0
- package/os/session/session.module.ts +126 -0
- package/os/session/types.ts +203 -0
- package/os/spec/live-spec-list-show-validate.test.ts +257 -0
- package/os/spec/live-spec-list.ts +78 -0
- package/os/spec/live-spec-merge.test.ts +261 -0
- package/os/spec/live-spec-merge.ts +413 -0
- package/os/spec/live-spec-show.ts +117 -0
- package/os/spec/live-spec-types.ts +93 -0
- package/os/spec/live-spec-validate.ts +170 -0
- package/os/spec/spec-materialize.ts +390 -0
- package/os/spec/spec-schema.ts +174 -0
- package/os/spec/spec-status.ts +284 -0
- package/os/spec/spec-validate.ts +513 -0
- package/os/spec/spec.module.ts +135 -0
- package/os/werkstatt/handlers/lock.ts +168 -0
- package/os/werkstatt/handlers/schema.ts +47 -0
- package/os/werkstatt/handlers/werkstatt-lock-recover.ts +175 -0
- package/os/werkstatt/handlers/werkstatt-lock-status.ts +73 -0
- package/os/werkstatt/handlers/werkstatt-operation-validate.ts +104 -0
- package/os/werkstatt/index.ts +39 -0
- package/os/werkstatt/werkstatt.module.ts +62 -0
- package/os/workflow/handlers.ts +304 -0
- package/os/workflow/index.ts +28 -0
- package/os/workflow/types.ts +99 -0
- package/os/workflow/workflow.module.ts +54 -0
- package/package.json +3 -3
- package/profiles/godot-csharp.yaml +4 -4
- package/profiles/knowledge-typescript-turborepo.yaml +110 -0
- package/profiles/phaser-turborepo.yaml +5 -5
- package/skills/_shared/fo-session-summary.md +132 -16
- package/skills/fo/fo-add-tests/pbt-guide.md +13 -13
- package/skills/fo/fo-doc-audit/SKILL.md +6 -6
- package/skills/fo/fo-handoff/SKILL.md +5 -0
- package/skills/fo/fo-idea/SKILL.md +1 -1
- package/skills/fo/fo-review/SKILL.md +1 -1
- package/skills/fo/fo-session-retro/SKILL.md +8 -0
- package/skills/fo/fo-session-save/SKILL.md +8 -0
- package/src/cli-output.ts +59 -0
- package/src/config/__tests__/resolve-terminology.test.ts +45 -0
- package/src/config/forge-config.ts +524 -0
- package/src/forge-module.ts +39 -0
- package/src/index.ts +172 -0
- package/src/knowledge/__tests__/promote.test.ts +219 -0
- package/src/knowledge/__tests__/serialize.test.ts +192 -0
- package/src/knowledge/budgets.ts +202 -0
- package/src/knowledge/compact.ts +405 -0
- package/src/knowledge/index.ts +53 -0
- package/src/knowledge/parse.ts +227 -0
- package/src/knowledge/promote.ts +156 -0
- package/src/knowledge/schema.ts +112 -0
- package/src/knowledge/serialize.ts +72 -0
- package/src/migration-adapters/__tests__/ignored-files.test.ts +51 -0
- package/src/migration-adapters/__tests__/registry.test.ts +131 -0
- package/src/migration-adapters/__tests__/types.test.ts +86 -0
- package/src/migration-adapters/git-utils.ts +71 -0
- package/src/migration-adapters/ignored-files.ts +221 -0
- package/src/migration-adapters/index.ts +21 -0
- package/src/migration-adapters/node-typescript-pnpm/index.ts +189 -0
- package/src/migration-adapters/phaser-pnpm/index.ts +189 -0
- package/src/migration-adapters/registry.ts +61 -0
- package/src/migration-adapters/types.ts +68 -0
- package/src/onboarding/__tests__/workspace-discovery.test.ts +134 -0
- package/src/onboarding/agents-generate.ts +443 -0
- package/src/onboarding/create.ts +427 -0
- package/src/onboarding/doctor.ts +1297 -0
- package/src/onboarding/init.ts +337 -0
- package/src/onboarding/invariant-engine.ts +448 -0
- package/src/onboarding/memory-scaffold.ts +189 -0
- package/src/onboarding/nested-agents-generate.ts +93 -0
- package/src/onboarding/nested-agents-templates.ts +233 -0
- package/src/onboarding/profile-validate.ts +139 -0
- package/src/onboarding/scaffold-project.ts +299 -0
- package/src/onboarding/scaffold.ts +143 -0
- package/src/onboarding/upgrade.ts +558 -0
- package/src/onboarding/workspace-discovery.ts +167 -0
- package/src/profiles/__tests__/profile-schema.test.ts +228 -0
- package/src/profiles/__tests__/stack-profile.test.ts +190 -0
- package/src/profiles/__tests__/terminology-utils.test.ts +71 -0
- package/src/profiles/profile-schema.ts +350 -0
- package/src/profiles/stack-profile.ts +188 -0
- package/src/profiles/terminology-utils.ts +36 -0
- package/src/registry.ts +185 -0
- package/src/skill-schema.ts +37 -0
- package/src/tests/acceptance-criteria.test.ts +99 -0
- package/src/tests/adr-implement-stamp.test.ts +368 -0
- package/src/tests/agents-generate-domain.test.ts +317 -0
- package/src/tests/agents-generate.test.ts +458 -0
- package/src/tests/bindings-schema.test.ts +314 -0
- package/src/tests/budgets.test.ts +213 -0
- package/src/tests/cli-output.test.ts +196 -0
- package/src/tests/compact.test.ts +796 -0
- package/src/tests/create.test.ts +289 -0
- package/src/tests/doctor-autonomy.test.ts +98 -0
- package/src/tests/doctor-bindings.test.ts +286 -0
- package/src/tests/doctor-domain.test.ts +113 -0
- package/src/tests/exploration-handlers.test.ts +256 -0
- package/src/tests/fixtures/agents-generate-business-before.txt +288 -0
- package/src/tests/forge-config.test.ts +420 -0
- package/src/tests/fs-atomic.test.ts +96 -0
- package/src/tests/fs.test.ts +103 -0
- package/src/tests/generated-marker.test.ts +161 -0
- package/src/tests/hash.test.ts +37 -0
- package/src/tests/implement-stamp.test.ts +505 -0
- package/src/tests/init-bindings.test.ts +183 -0
- package/src/tests/knowledge-parse.test.ts +307 -0
- package/src/tests/knowledge-pbt.test.ts +164 -0
- package/src/tests/memory-scaffold.test.ts +192 -0
- package/src/tests/migration-adapters.test.ts +480 -0
- package/src/tests/package-files.test.ts +54 -0
- package/src/tests/pinned-check.test.ts +194 -0
- package/src/tests/pinned-init.test.ts +126 -0
- package/src/tests/profile-schema.test.ts +194 -0
- package/src/tests/profile-validate.test.ts +120 -0
- package/src/tests/program-lease.test.ts +245 -0
- package/src/tests/program-paths-extended.test.ts +117 -0
- package/src/tests/program-paths.test.ts +98 -0
- package/src/tests/program-property.test.ts +139 -0
- package/src/tests/program-schemas.test.ts +445 -0
- package/src/tests/program-spec-node.test.ts +250 -0
- package/src/tests/promote.test.ts +481 -0
- package/src/tests/registry.test.ts +73 -0
- package/src/tests/scaffold-project.test.ts +150 -0
- package/src/tests/session-handlers.test.ts +503 -0
- package/src/tests/session-pbt.test.ts +190 -0
- package/src/tests/skill-schema.test.ts +146 -0
- package/src/tests/skill-validate-knowledge.test.ts +26 -0
- package/src/tests/skill-validate.test.ts +254 -0
- package/src/tests/stack-profile.test.ts +221 -0
- package/src/tests/string-utils.test.ts +42 -0
- package/src/tests/upgrade.test.ts +428 -0
- package/src/tests/werkstatt-lock.test.ts +343 -0
- package/src/tests/workspace-discovery-domain.test.ts +112 -0
- package/src/tests/workspace-discovery.test.ts +135 -0
- package/src/types.ts +221 -0
- package/src/utils/__tests__/fs-idempotent.test.ts +73 -0
- package/src/utils/__tests__/fs-trash.test.ts +45 -0
- package/src/utils/fs-atomic.ts +93 -0
- package/src/utils/fs-idempotent.ts +41 -0
- package/src/utils/fs-trash-sync.ts +37 -0
- package/src/utils/fs-trash.ts +24 -0
- package/src/utils/fs.ts +74 -0
- package/src/utils/generated-marker.ts +166 -0
- package/src/utils/hash.ts +19 -0
- package/src/utils/index.ts +29 -0
- package/src/utils/string-utils.ts +19 -0
- package/src/validators/__tests__/note-orphan-detect.test.ts +94 -0
- package/src/validators/note-frontmatter-validate.ts +142 -0
- package/src/validators/note-link-validate.ts +145 -0
- package/src/validators/note-orphan-detect.ts +146 -0
- package/src/validators/port-validate.ts +97 -0
- package/src/validators/skill-validate.ts +831 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>forge.determinism.check — verify artifact determinism by building twice and comparing output hashes. Profile-driven via determinism.inputs glob patterns.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>Do not implement build or validate logic — those are separate handlers.</item>
|
|
6
|
+
<item>Do not import from @warpgogol/* in autonomous modules — os/core/ may import from @warpgogol/*.</item>
|
|
7
|
+
</non-goals>
|
|
8
|
+
</MODULE_CONTRACT>
|
|
9
|
+
<CHANGE_SUMMARY>
|
|
10
|
+
<item>RFC-0678: initial forge.determinism.check handler with profile resolution, --dry-run, --artifact, cache, and double-build hash comparison.</item>
|
|
11
|
+
</CHANGE_SUMMARY>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { exec } from "node:child_process";
|
|
15
|
+
import { promisify } from "node:util";
|
|
16
|
+
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
17
|
+
import { existsSync } from "node:fs";
|
|
18
|
+
import { join, relative, dirname } from "node:path";
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
import { loadWorkspaceDeps } from "./workspace-deps.ts";
|
|
21
|
+
import type {
|
|
22
|
+
ForgeCommandInput,
|
|
23
|
+
ForgeCommandResult,
|
|
24
|
+
ForgeRuntimeContext,
|
|
25
|
+
} from "../../../src/types.ts";
|
|
26
|
+
import { resolveActiveProfile, resolveLifecycleFlags } from "./profile-resolve.ts";
|
|
27
|
+
|
|
28
|
+
const execAsync = promisify(exec);
|
|
29
|
+
|
|
30
|
+
export interface DeterminismCheckResult {
|
|
31
|
+
artifactId: string;
|
|
32
|
+
hashable: boolean;
|
|
33
|
+
inputs: string[];
|
|
34
|
+
inputHash: string;
|
|
35
|
+
firstBuildHash: string | null;
|
|
36
|
+
secondBuildHash: string | null;
|
|
37
|
+
deterministic: boolean;
|
|
38
|
+
cached: boolean;
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface ForgeDeterminismCheckResult {
|
|
43
|
+
command: "forge.determinism.check";
|
|
44
|
+
profileId: string;
|
|
45
|
+
artifacts: DeterminismCheckResult[];
|
|
46
|
+
allDeterministic: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface CacheEntry {
|
|
50
|
+
inputHash: string;
|
|
51
|
+
produceCommand: string;
|
|
52
|
+
outputHash: string;
|
|
53
|
+
deterministic: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface CacheFile {
|
|
57
|
+
entries: Record<string, CacheEntry>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function globToRegex(pattern: string): RegExp {
|
|
61
|
+
let regex = "";
|
|
62
|
+
let i = 0;
|
|
63
|
+
while (i < pattern.length) {
|
|
64
|
+
const char = pattern[i];
|
|
65
|
+
if (char === "*") {
|
|
66
|
+
if (pattern[i + 1] === "*") {
|
|
67
|
+
regex += ".*";
|
|
68
|
+
i += 2;
|
|
69
|
+
if (pattern[i] === "/") i++;
|
|
70
|
+
} else {
|
|
71
|
+
regex += "[^/]*";
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
} else if (char === "?") {
|
|
75
|
+
regex += "[^/]";
|
|
76
|
+
i++;
|
|
77
|
+
} else if (".+^${}()|[]\\".includes(char)) {
|
|
78
|
+
regex += "\\" + char;
|
|
79
|
+
i++;
|
|
80
|
+
} else {
|
|
81
|
+
regex += char;
|
|
82
|
+
i++;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return new RegExp("^" + regex + "$");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function matchesGlob(filePath: string, patterns: string[]): boolean {
|
|
89
|
+
return patterns.some((pattern) => globToRegex(pattern).test(filePath));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async function computeInputHash(workspaceRoot: string, inputPatterns: string[]): Promise<string> {
|
|
93
|
+
const { collectFiles, byteHashFile } = await loadWorkspaceDeps();
|
|
94
|
+
const allFiles = await collectFiles(workspaceRoot, {
|
|
95
|
+
ignore: (name) =>
|
|
96
|
+
name.startsWith("-") ||
|
|
97
|
+
name.startsWith("old-") ||
|
|
98
|
+
name === "node_modules" ||
|
|
99
|
+
name === "dist" ||
|
|
100
|
+
name === ".turbo" ||
|
|
101
|
+
name === ".cache" ||
|
|
102
|
+
name === ".git",
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const matched = allFiles
|
|
106
|
+
.map((abs) => relative(workspaceRoot, abs))
|
|
107
|
+
.filter((rel) => matchesGlob(rel, inputPatterns))
|
|
108
|
+
.sort();
|
|
109
|
+
|
|
110
|
+
const hasher = createHash("sha256");
|
|
111
|
+
for (const relPath of matched) {
|
|
112
|
+
const absPath = join(workspaceRoot, relPath);
|
|
113
|
+
const fileHash = await byteHashFile(absPath);
|
|
114
|
+
hasher.update(relPath + "\0" + fileHash + "\0");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return `sha256:${hasher.digest("hex")}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function readCache(cachePath: string): Promise<CacheFile> {
|
|
121
|
+
try {
|
|
122
|
+
const content = await readFile(cachePath, "utf8");
|
|
123
|
+
return JSON.parse(content) as CacheFile;
|
|
124
|
+
} catch {
|
|
125
|
+
return { entries: {} };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async function writeCache(cachePath: string, cache: CacheFile): Promise<void> {
|
|
130
|
+
const dir = dirname(cachePath);
|
|
131
|
+
if (!existsSync(dir)) {
|
|
132
|
+
await mkdir(dir, { recursive: true });
|
|
133
|
+
}
|
|
134
|
+
await writeFile(cachePath, JSON.stringify(cache, null, 2) + "\n", "utf8");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function runDeterminismCheck(
|
|
138
|
+
input: ForgeCommandInput,
|
|
139
|
+
context: ForgeRuntimeContext,
|
|
140
|
+
): Promise<ForgeCommandResult<ForgeDeterminismCheckResult>> {
|
|
141
|
+
const { workspaceRoot, logger } = context;
|
|
142
|
+
const { dryRun, profileIdOverride } = resolveLifecycleFlags(input, context);
|
|
143
|
+
const artifactFilter =
|
|
144
|
+
typeof input.flags["artifact"] === "string" ? (input.flags["artifact"] as string) : undefined;
|
|
145
|
+
|
|
146
|
+
const resolved = resolveActiveProfile(workspaceRoot, context.forgeRoot, profileIdOverride);
|
|
147
|
+
if (!resolved) {
|
|
148
|
+
return {
|
|
149
|
+
data: {
|
|
150
|
+
command: "forge.determinism.check",
|
|
151
|
+
profileId: "",
|
|
152
|
+
artifacts: [],
|
|
153
|
+
allDeterministic: false,
|
|
154
|
+
},
|
|
155
|
+
exitCode: 1,
|
|
156
|
+
summary: "No active profile found. Set `profile` in forge.yaml or use --profile <id>.",
|
|
157
|
+
nextSteps: [{ action: "Set profile in forge.yaml or use --profile <id>", kind: "required" }],
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const { profile } = resolved;
|
|
162
|
+
|
|
163
|
+
if (!profile.artifacts || profile.artifacts.length === 0) {
|
|
164
|
+
return {
|
|
165
|
+
data: {
|
|
166
|
+
command: "forge.determinism.check",
|
|
167
|
+
profileId: profile.id,
|
|
168
|
+
artifacts: [],
|
|
169
|
+
allDeterministic: false,
|
|
170
|
+
},
|
|
171
|
+
exitCode: 1,
|
|
172
|
+
summary: `Profile ${profile.id} does not declare any artifacts.`,
|
|
173
|
+
nextSteps: [{ action: `Add artifacts section to profile ${profile.id}`, kind: "required" }],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (artifactFilter) {
|
|
178
|
+
const found = profile.artifacts.find((a) => a.id === artifactFilter);
|
|
179
|
+
if (!found) {
|
|
180
|
+
return {
|
|
181
|
+
data: {
|
|
182
|
+
command: "forge.determinism.check",
|
|
183
|
+
profileId: profile.id,
|
|
184
|
+
artifacts: [],
|
|
185
|
+
allDeterministic: false,
|
|
186
|
+
},
|
|
187
|
+
exitCode: 1,
|
|
188
|
+
summary: `Artifact ${artifactFilter} not declared in profile ${profile.id}.`,
|
|
189
|
+
nextSteps: [{ action: `Check artifacts in profile ${profile.id}`, kind: "required" }],
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const artifactsToCheck = artifactFilter
|
|
195
|
+
? profile.artifacts.filter((a) => a.id === artifactFilter)
|
|
196
|
+
: profile.artifacts;
|
|
197
|
+
|
|
198
|
+
const hashableArtifacts = artifactsToCheck.filter((a) => a.determinism?.hashable === true);
|
|
199
|
+
|
|
200
|
+
if (hashableArtifacts.length === 0) {
|
|
201
|
+
return {
|
|
202
|
+
data: {
|
|
203
|
+
command: "forge.determinism.check",
|
|
204
|
+
profileId: profile.id,
|
|
205
|
+
artifacts: [],
|
|
206
|
+
allDeterministic: true,
|
|
207
|
+
},
|
|
208
|
+
exitCode: 0,
|
|
209
|
+
summary: `Profile ${profile.id} has no hashable artifacts — nothing to check.`,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (dryRun) {
|
|
214
|
+
const items = hashableArtifacts.map((a) => ({
|
|
215
|
+
artifactId: a.id,
|
|
216
|
+
inputs: a.determinism!.inputs,
|
|
217
|
+
}));
|
|
218
|
+
logger.info(`[dry-run] forge.determinism.check — profile: ${profile.id}`);
|
|
219
|
+
for (const item of items) {
|
|
220
|
+
logger.info(` ${item.artifactId}: inputs=${item.inputs.join(", ")}`);
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
data: {
|
|
224
|
+
command: "forge.determinism.check",
|
|
225
|
+
profileId: profile.id,
|
|
226
|
+
artifacts: items.map((item) => ({
|
|
227
|
+
artifactId: item.artifactId,
|
|
228
|
+
hashable: true,
|
|
229
|
+
inputs: item.inputs,
|
|
230
|
+
inputHash: "",
|
|
231
|
+
firstBuildHash: null,
|
|
232
|
+
secondBuildHash: null,
|
|
233
|
+
deterministic: true,
|
|
234
|
+
cached: false,
|
|
235
|
+
})),
|
|
236
|
+
allDeterministic: true,
|
|
237
|
+
},
|
|
238
|
+
summary: `[dry-run] ${items.length} hashable artifact(s) resolved`,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const cachePath = join(workspaceRoot, "dist", ".determinism-cache.json");
|
|
243
|
+
const cache = await readCache(cachePath);
|
|
244
|
+
const results: DeterminismCheckResult[] = [];
|
|
245
|
+
|
|
246
|
+
for (const artifact of hashableArtifacts) {
|
|
247
|
+
const determinism = artifact.determinism!;
|
|
248
|
+
const produceCommand = artifact.produce?.command ?? "";
|
|
249
|
+
const outputPath = artifact.produce?.output ?? "";
|
|
250
|
+
|
|
251
|
+
if (!produceCommand || !outputPath) {
|
|
252
|
+
results.push({
|
|
253
|
+
artifactId: artifact.id,
|
|
254
|
+
hashable: true,
|
|
255
|
+
inputs: determinism.inputs,
|
|
256
|
+
inputHash: "",
|
|
257
|
+
firstBuildHash: null,
|
|
258
|
+
secondBuildHash: null,
|
|
259
|
+
deterministic: false,
|
|
260
|
+
cached: false,
|
|
261
|
+
error: "Artifact has no produce.command or produce.output — cannot verify determinism",
|
|
262
|
+
});
|
|
263
|
+
logger.error(` ${artifact.id}: no produce command or output`);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const inputHash = await computeInputHash(workspaceRoot, determinism.inputs);
|
|
268
|
+
const cacheKey = `${artifact.id}:${inputHash}:${produceCommand}`;
|
|
269
|
+
const cachedEntry = cache.entries[cacheKey];
|
|
270
|
+
|
|
271
|
+
if (cachedEntry) {
|
|
272
|
+
results.push({
|
|
273
|
+
artifactId: artifact.id,
|
|
274
|
+
hashable: true,
|
|
275
|
+
inputs: determinism.inputs,
|
|
276
|
+
inputHash,
|
|
277
|
+
firstBuildHash: cachedEntry.outputHash,
|
|
278
|
+
secondBuildHash: cachedEntry.outputHash,
|
|
279
|
+
deterministic: cachedEntry.deterministic,
|
|
280
|
+
cached: true,
|
|
281
|
+
});
|
|
282
|
+
logger.success(` ${artifact.id}: cached (deterministic=${cachedEntry.deterministic})`);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const absOutputPath = join(workspaceRoot, outputPath);
|
|
287
|
+
|
|
288
|
+
try {
|
|
289
|
+
const { byteHashFile } = await loadWorkspaceDeps();
|
|
290
|
+
await execAsync(produceCommand, { cwd: workspaceRoot, timeout: 60_000 });
|
|
291
|
+
const firstHash = await byteHashFile(absOutputPath);
|
|
292
|
+
|
|
293
|
+
await execAsync(produceCommand, { cwd: workspaceRoot, timeout: 60_000 });
|
|
294
|
+
const secondHash = await byteHashFile(absOutputPath);
|
|
295
|
+
|
|
296
|
+
const deterministic = firstHash === secondHash;
|
|
297
|
+
|
|
298
|
+
results.push({
|
|
299
|
+
artifactId: artifact.id,
|
|
300
|
+
hashable: true,
|
|
301
|
+
inputs: determinism.inputs,
|
|
302
|
+
inputHash,
|
|
303
|
+
firstBuildHash: firstHash,
|
|
304
|
+
secondBuildHash: secondHash,
|
|
305
|
+
deterministic,
|
|
306
|
+
cached: false,
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
cache.entries[cacheKey] = {
|
|
310
|
+
inputHash,
|
|
311
|
+
produceCommand,
|
|
312
|
+
outputHash: firstHash,
|
|
313
|
+
deterministic,
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
if (deterministic) {
|
|
317
|
+
logger.success(` ${artifact.id}: deterministic`);
|
|
318
|
+
} else {
|
|
319
|
+
logger.error(` ${artifact.id}: NON-DETERMINISTIC (hashes differ)`);
|
|
320
|
+
}
|
|
321
|
+
} catch (err) {
|
|
322
|
+
const e = err as { code?: number; stdout?: string; stderr?: string; message: string };
|
|
323
|
+
results.push({
|
|
324
|
+
artifactId: artifact.id,
|
|
325
|
+
hashable: true,
|
|
326
|
+
inputs: determinism.inputs,
|
|
327
|
+
inputHash,
|
|
328
|
+
firstBuildHash: null,
|
|
329
|
+
secondBuildHash: null,
|
|
330
|
+
deterministic: false,
|
|
331
|
+
cached: false,
|
|
332
|
+
error: e.stderr ?? e.message,
|
|
333
|
+
});
|
|
334
|
+
logger.error(` ${artifact.id}: build failed (${e.message})`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
await writeCache(cachePath, cache);
|
|
339
|
+
|
|
340
|
+
const allDeterministic = results.every((r) => r.deterministic);
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
data: {
|
|
344
|
+
command: "forge.determinism.check",
|
|
345
|
+
profileId: profile.id,
|
|
346
|
+
artifacts: results,
|
|
347
|
+
allDeterministic,
|
|
348
|
+
},
|
|
349
|
+
exitCode: allDeterministic ? 0 : 1,
|
|
350
|
+
summary: allDeterministic
|
|
351
|
+
? `forge.determinism.check: all ${results.length} artifact(s) deterministic`
|
|
352
|
+
: `forge.determinism.check: ${results.filter((r) => !r.deterministic).length} artifact(s) non-deterministic`,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>forge.dev — start the dev/preview server declared in the active stack profile. Supports --dry-run to print the resolved command without executing.</purpose>
|
|
4
|
+
<non-goals>
|
|
5
|
+
<item>Do not implement build or validate logic — those are separate handlers.</item>
|
|
6
|
+
<item>Do not import from @warpgogol/* — this module is portable.</item>
|
|
7
|
+
</non-goals>
|
|
8
|
+
</MODULE_CONTRACT>
|
|
9
|
+
<CHANGE_SUMMARY>
|
|
10
|
+
<item>RFC-0674: initial forge.dev handler with profile resolution, --dry-run, and SIGINT handling.</item>
|
|
11
|
+
</CHANGE_SUMMARY>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { spawn } from "node:child_process";
|
|
15
|
+
import type {
|
|
16
|
+
ForgeCommandInput,
|
|
17
|
+
ForgeCommandResult,
|
|
18
|
+
ForgeRuntimeContext,
|
|
19
|
+
} from "../../../src/types.ts";
|
|
20
|
+
import { resolveActiveProfile, resolveLifecycleFlags } from "./profile-resolve.ts";
|
|
21
|
+
|
|
22
|
+
export interface ForgeDevResult {
|
|
23
|
+
command: "forge.dev";
|
|
24
|
+
profileId: string;
|
|
25
|
+
devServerCommand: string;
|
|
26
|
+
port?: number;
|
|
27
|
+
exitCode: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function runDev(
|
|
31
|
+
input: ForgeCommandInput,
|
|
32
|
+
context: ForgeRuntimeContext,
|
|
33
|
+
): Promise<ForgeCommandResult<ForgeDevResult>> {
|
|
34
|
+
const { workspaceRoot, logger } = context;
|
|
35
|
+
const { dryRun, profileIdOverride } = resolveLifecycleFlags(input, context);
|
|
36
|
+
|
|
37
|
+
const resolved = resolveActiveProfile(workspaceRoot, context.forgeRoot, profileIdOverride);
|
|
38
|
+
if (!resolved) {
|
|
39
|
+
return {
|
|
40
|
+
data: {
|
|
41
|
+
command: "forge.dev",
|
|
42
|
+
profileId: "",
|
|
43
|
+
devServerCommand: "",
|
|
44
|
+
exitCode: 1,
|
|
45
|
+
},
|
|
46
|
+
exitCode: 1,
|
|
47
|
+
summary: "No active profile found. Set `profile` in forge.yaml or use --profile <id>.",
|
|
48
|
+
nextSteps: [{ action: "Set profile in forge.yaml or use --profile <id>", kind: "required" }],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const { profile } = resolved;
|
|
53
|
+
|
|
54
|
+
if (!profile.devServer) {
|
|
55
|
+
return {
|
|
56
|
+
data: {
|
|
57
|
+
command: "forge.dev",
|
|
58
|
+
profileId: profile.id,
|
|
59
|
+
devServerCommand: "",
|
|
60
|
+
exitCode: 1,
|
|
61
|
+
},
|
|
62
|
+
exitCode: 1,
|
|
63
|
+
summary: `Profile ${profile.id} does not declare a devServer.`,
|
|
64
|
+
nextSteps: [{ action: `Add devServer section to profile ${profile.id}`, kind: "required" }],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { command, port } = profile.devServer;
|
|
69
|
+
|
|
70
|
+
if (dryRun) {
|
|
71
|
+
logger.info(`[dry-run] forge.dev — profile: ${profile.id}`);
|
|
72
|
+
logger.info(` command: ${command}`);
|
|
73
|
+
if (port) logger.info(` port: ${port}`);
|
|
74
|
+
return {
|
|
75
|
+
data: {
|
|
76
|
+
command: "forge.dev",
|
|
77
|
+
profileId: profile.id,
|
|
78
|
+
devServerCommand: command,
|
|
79
|
+
port,
|
|
80
|
+
exitCode: 0,
|
|
81
|
+
},
|
|
82
|
+
summary: `[dry-run] ${command}`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return new Promise<ForgeCommandResult<ForgeDevResult>>((resolve) => {
|
|
87
|
+
const child = spawn(command, {
|
|
88
|
+
shell: true,
|
|
89
|
+
stdio: "inherit",
|
|
90
|
+
cwd: workspaceRoot,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const onSigint = () => {
|
|
94
|
+
child.kill("SIGINT");
|
|
95
|
+
};
|
|
96
|
+
process.once("SIGINT", onSigint);
|
|
97
|
+
|
|
98
|
+
child.on("close", (code) => {
|
|
99
|
+
process.removeListener("SIGINT", onSigint);
|
|
100
|
+
resolve({
|
|
101
|
+
data: {
|
|
102
|
+
command: "forge.dev",
|
|
103
|
+
profileId: profile.id,
|
|
104
|
+
devServerCommand: command,
|
|
105
|
+
port,
|
|
106
|
+
exitCode: code ?? 0,
|
|
107
|
+
},
|
|
108
|
+
summary: `forge.dev exited with code ${code ?? 0}`,
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
child.on("error", (err) => {
|
|
113
|
+
process.removeListener("SIGINT", onSigint);
|
|
114
|
+
resolve({
|
|
115
|
+
data: {
|
|
116
|
+
command: "forge.dev",
|
|
117
|
+
profileId: profile.id,
|
|
118
|
+
devServerCommand: command,
|
|
119
|
+
port,
|
|
120
|
+
exitCode: 1,
|
|
121
|
+
},
|
|
122
|
+
exitCode: 1,
|
|
123
|
+
summary: `forge.dev failed: ${err.message}`,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
}
|