@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.
- package/AGENTS.md +50 -27
- package/CHANGELOG.md +39 -0
- package/bin/cli.js +0 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -1
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +35 -4
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -1
- package/dist/os/core/core.module.d.ts.map +1 -1
- package/dist/os/core/core.module.js +1 -69
- package/dist/os/core/core.module.js.map +1 -1
- package/dist/os/core/handlers/assets-helpers.d.ts.map +1 -1
- package/dist/os/core/handlers/assets-helpers.js +2 -3
- package/dist/os/core/handlers/assets-helpers.js.map +1 -1
- package/dist/os/core/handlers/determinism-check.d.ts.map +1 -1
- package/dist/os/core/handlers/determinism-check.js +2 -3
- package/dist/os/core/handlers/determinism-check.js.map +1 -1
- package/dist/os/core/handlers/release-prepare.d.ts.map +1 -1
- package/dist/os/core/handlers/release-prepare.js +2 -4
- package/dist/os/core/handlers/release-prepare.js.map +1 -1
- package/dist/os/flow/handlers/flow-peers.js +1 -1
- package/dist/os/flow/handlers/flow-peers.js.map +1 -1
- package/dist/os/{mission → flow}/open-missions.d.ts +1 -2
- package/dist/os/flow/open-missions.d.ts.map +1 -0
- package/dist/os/flow/open-missions.js +37 -0
- package/dist/os/flow/open-missions.js.map +1 -0
- package/dist/os/flow/preflight.js +1 -1
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/rfc/probe-batch.d.ts.map +1 -1
- package/dist/os/rfc/probe-batch.js +13 -6
- package/dist/os/rfc/probe-batch.js.map +1 -1
- package/dist/src/command-modules.d.ts.map +1 -1
- package/dist/src/command-modules.js +0 -2
- package/dist/src/command-modules.js.map +1 -1
- package/dist/src/contract/core-nodes.d.ts +8 -0
- package/dist/src/contract/core-nodes.d.ts.map +1 -0
- package/dist/src/contract/core-nodes.js +101 -0
- package/dist/src/contract/core-nodes.js.map +1 -0
- package/dist/src/contract/evaluator.d.ts +48 -0
- package/dist/src/contract/evaluator.d.ts.map +1 -0
- package/dist/src/contract/evaluator.js +158 -0
- package/dist/src/contract/evaluator.js.map +1 -0
- package/dist/src/contract/evidence-store.d.ts +17 -0
- package/dist/src/contract/evidence-store.d.ts.map +1 -0
- package/dist/src/contract/evidence-store.js +113 -0
- package/dist/src/contract/evidence-store.js.map +1 -0
- package/dist/src/contract/executors/zero-deps.d.ts +3 -0
- package/dist/src/contract/executors/zero-deps.d.ts.map +1 -0
- package/dist/src/contract/executors/zero-deps.js +88 -0
- package/dist/src/contract/executors/zero-deps.js.map +1 -0
- package/dist/src/contract/fingerprint.d.ts +34 -0
- package/dist/src/contract/fingerprint.d.ts.map +1 -0
- package/dist/src/contract/fingerprint.js +153 -0
- package/dist/src/contract/fingerprint.js.map +1 -0
- package/dist/src/contract/graph.d.ts +23 -0
- package/dist/src/contract/graph.d.ts.map +1 -0
- package/dist/src/contract/graph.js +158 -0
- package/dist/src/contract/graph.js.map +1 -0
- package/dist/src/contract/migration-map.d.ts +51 -0
- package/dist/src/contract/migration-map.d.ts.map +1 -0
- package/dist/src/contract/migration-map.js +130 -0
- package/dist/src/contract/migration-map.js.map +1 -0
- package/dist/src/contract/types.d.ts +108 -0
- package/dist/src/contract/types.d.ts.map +1 -0
- package/dist/src/contract/types.js +23 -0
- package/dist/src/contract/types.js.map +1 -0
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +0 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/integration/drain.d.ts +31 -0
- package/dist/src/integration/drain.d.ts.map +1 -0
- package/dist/src/integration/drain.js +195 -0
- package/dist/src/integration/drain.js.map +1 -0
- package/dist/src/integration/enqueue.d.ts +30 -0
- package/dist/src/integration/enqueue.d.ts.map +1 -0
- package/dist/src/integration/enqueue.js +64 -0
- package/dist/src/integration/enqueue.js.map +1 -0
- package/dist/src/integration/gitops.d.ts +33 -0
- package/dist/src/integration/gitops.d.ts.map +1 -0
- package/dist/src/integration/gitops.js +128 -0
- package/dist/src/integration/gitops.js.map +1 -0
- package/dist/src/integration/lease.d.ts +16 -0
- package/dist/src/integration/lease.d.ts.map +1 -0
- package/dist/src/integration/lease.js +140 -0
- package/dist/src/integration/lease.js.map +1 -0
- package/dist/src/integration/materialize.d.ts +7 -0
- package/dist/src/integration/materialize.d.ts.map +1 -0
- package/dist/src/integration/materialize.js +34 -0
- package/dist/src/integration/materialize.js.map +1 -0
- package/dist/src/integration/store.d.ts +21 -0
- package/dist/src/integration/store.d.ts.map +1 -0
- package/dist/src/integration/store.js +131 -0
- package/dist/src/integration/store.js.map +1 -0
- package/dist/src/integration/types.d.ts +71 -0
- package/dist/src/integration/types.d.ts.map +1 -0
- package/dist/src/integration/types.js +18 -0
- package/dist/src/integration/types.js.map +1 -0
- package/dist/src/onboarding/doctor.d.ts +0 -5
- package/dist/src/onboarding/doctor.d.ts.map +1 -1
- package/dist/src/onboarding/doctor.js +6 -79
- package/dist/src/onboarding/doctor.js.map +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts +1 -1
- package/dist/src/onboarding/npm-token-check.d.ts.map +1 -1
- package/dist/src/onboarding/npm-token-check.js +2 -2
- package/dist/src/onboarding/npm-token-check.js.map +1 -1
- package/dist/src/sdk/context.d.ts +13 -0
- package/dist/src/sdk/context.d.ts.map +1 -0
- package/dist/src/sdk/context.js +128 -0
- package/dist/src/sdk/context.js.map +1 -0
- package/dist/src/sdk/loader.d.ts +25 -0
- package/dist/src/sdk/loader.d.ts.map +1 -0
- package/dist/src/sdk/loader.js +155 -0
- package/dist/src/sdk/loader.js.map +1 -0
- package/dist/src/sdk/scan.d.ts +16 -0
- package/dist/src/sdk/scan.d.ts.map +1 -0
- package/dist/src/sdk/scan.js +126 -0
- package/dist/src/sdk/scan.js.map +1 -0
- package/dist/src/sdk/skills-gen.d.ts +27 -0
- package/dist/src/sdk/skills-gen.d.ts.map +1 -0
- package/dist/src/sdk/skills-gen.js +87 -0
- package/dist/src/sdk/skills-gen.js.map +1 -0
- package/dist/src/sdk/types.d.ts +124 -0
- package/dist/src/sdk/types.d.ts.map +1 -0
- package/dist/src/sdk/types.js +34 -0
- package/dist/src/sdk/types.js.map +1 -0
- package/dist/src/utils/hash.d.ts +1 -0
- package/dist/src/utils/hash.d.ts.map +1 -1
- package/dist/src/utils/hash.js +4 -0
- package/dist/src/utils/hash.js.map +1 -1
- package/dist/{os/mission → src/utils}/lockfile.d.ts +1 -18
- package/dist/src/utils/lockfile.d.ts.map +1 -0
- package/dist/src/utils/lockfile.js +70 -0
- package/dist/src/utils/lockfile.js.map +1 -0
- package/os/codebase/handlers/codebase-measure-symbols.ts +32 -4
- package/os/core/core.module.ts +3 -76
- package/os/core/handlers/assets-helpers.ts +2 -4
- package/os/core/handlers/determinism-check.ts +2 -3
- package/os/core/handlers/lifecycle-handlers.test.ts +529 -0
- package/os/core/handlers/release-prepare.ts +2 -4
- package/os/correctness/gate/trust-boundary-cx18.test.ts +1 -1
- package/os/flow/handlers/flow-peers.ts +1 -1
- package/os/flow/open-missions.ts +45 -0
- package/os/flow/preflight.ts +1 -1
- package/os/flow/tests/release-lines.test.ts +136 -0
- package/os/flow/tests/state-roots.test.ts +1 -48
- package/os/rfc/handlers/validate-corpus.test.ts +149 -0
- package/os/rfc/probe-batch.test.ts +253 -0
- package/os/rfc/probe-batch.ts +13 -6
- package/os/rfc/verifier/rfc-1391/ac10-operating-model-policy.acceptance.test.ts +63 -0
- package/package.json +177 -506
- package/src/command-modules.ts +0 -2
- package/src/contract/core-nodes.ts +111 -0
- package/src/contract/evaluator.ts +207 -0
- package/src/contract/evidence-store.ts +119 -0
- package/src/contract/executors/zero-deps.ts +92 -0
- package/src/contract/fingerprint.ts +176 -0
- package/src/contract/graph.ts +181 -0
- package/src/contract/migration-map.ts +174 -0
- package/src/contract/types.ts +125 -0
- package/src/index.ts +0 -2
- package/src/integration/drain.ts +271 -0
- package/src/integration/enqueue.ts +92 -0
- package/src/integration/gitops.ts +174 -0
- package/src/integration/lease.ts +144 -0
- package/src/integration/materialize.ts +40 -0
- package/src/integration/store.ts +153 -0
- package/src/integration/types.ts +79 -0
- package/src/onboarding/doctor.ts +9 -96
- package/src/onboarding/npm-token-check.ts +3 -3
- package/src/sdk/context.ts +135 -0
- package/src/sdk/loader.ts +170 -0
- package/src/sdk/scan.ts +132 -0
- package/src/sdk/skills-gen.ts +104 -0
- package/src/sdk/types.ts +135 -0
- package/src/tests/pkg-health-self-scan.test.ts +29 -0
- package/src/tests/rfc-evidence-sync.test.ts +369 -0
- package/src/tests/skill-agents-sync.test.ts +192 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/lockfile.ts +78 -0
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts +0 -25
- package/dist/os/core/handlers/forge-autonomy-validate.d.ts.map +0 -1
- package/dist/os/core/handlers/forge-autonomy-validate.js +0 -208
- package/dist/os/core/handlers/forge-autonomy-validate.js.map +0 -1
- package/dist/os/mission/handlers/archive.d.ts +0 -4
- package/dist/os/mission/handlers/archive.d.ts.map +0 -1
- package/dist/os/mission/handlers/archive.js +0 -583
- package/dist/os/mission/handlers/archive.js.map +0 -1
- package/dist/os/mission/importer-block.d.ts +0 -19
- package/dist/os/mission/importer-block.d.ts.map +0 -1
- package/dist/os/mission/importer-block.js +0 -124
- package/dist/os/mission/importer-block.js.map +0 -1
- package/dist/os/mission/index.d.ts +0 -2
- package/dist/os/mission/index.d.ts.map +0 -1
- package/dist/os/mission/index.js +0 -15
- package/dist/os/mission/index.js.map +0 -1
- package/dist/os/mission/lockfile.d.ts.map +0 -1
- package/dist/os/mission/lockfile.js +0 -138
- package/dist/os/mission/lockfile.js.map +0 -1
- package/dist/os/mission/mission.module.d.ts +0 -3
- package/dist/os/mission/mission.module.d.ts.map +0 -1
- package/dist/os/mission/mission.module.js +0 -63
- package/dist/os/mission/mission.module.js.map +0 -1
- package/dist/os/mission/open-missions.d.ts.map +0 -1
- package/dist/os/mission/open-missions.js +0 -42
- package/dist/os/mission/open-missions.js.map +0 -1
- package/dist/os/mission/types.d.ts +0 -23
- package/dist/os/mission/types.d.ts.map +0 -1
- package/dist/os/mission/types.js +0 -19
- package/dist/os/mission/types.js.map +0 -1
- package/dist/os/werkstatt/handlers/lock.d.ts +0 -10
- package/dist/os/werkstatt/handlers/lock.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/lock.js +0 -153
- package/dist/os/werkstatt/handlers/lock.js.map +0 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +0 -33
- package/dist/os/werkstatt/handlers/schema.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/schema.js +0 -42
- package/dist/os/werkstatt/handlers/schema.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts +0 -15
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js +0 -171
- package/dist/os/werkstatt/handlers/werkstatt-lock-recover.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts +0 -18
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js +0 -51
- package/dist/os/werkstatt/handlers/werkstatt-lock-status.js.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts +0 -11
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js +0 -86
- package/dist/os/werkstatt/handlers/werkstatt-operation-validate.js.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts +0 -12
- package/dist/os/werkstatt/handlers/workspace-deps.d.ts.map +0 -1
- package/dist/os/werkstatt/handlers/workspace-deps.js +0 -42
- package/dist/os/werkstatt/handlers/workspace-deps.js.map +0 -1
- package/dist/os/werkstatt/index.d.ts +0 -7
- package/dist/os/werkstatt/index.d.ts.map +0 -1
- package/dist/os/werkstatt/index.js +0 -18
- package/dist/os/werkstatt/index.js.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.d.ts +0 -3
- package/dist/os/werkstatt/werkstatt.module.d.ts.map +0 -1
- package/dist/os/werkstatt/werkstatt.module.js +0 -91
- package/dist/os/werkstatt/werkstatt.module.js.map +0 -1
- package/os/core/handlers/forge-autonomy-validate.ts +0 -276
- package/os/correctness/gate/trust-boundary-cx19.test.ts +0 -514
- package/os/mission/handlers/archive.test.ts +0 -764
- package/os/mission/handlers/archive.ts +0 -711
- package/os/mission/handlers/ship-inflight-degraded.test.ts +0 -105
- package/os/mission/importer-block.ts +0 -119
- package/os/mission/index.ts +0 -15
- package/os/mission/lockfile.ts +0 -152
- package/os/mission/mission.module.ts +0 -68
- package/os/mission/open-missions.ts +0 -50
- package/os/mission/types.ts +0 -42
- package/os/werkstatt/handlers/lock.ts +0 -168
- package/os/werkstatt/handlers/schema.ts +0 -47
- package/os/werkstatt/handlers/werkstatt-lock-recover.ts +0 -206
- package/os/werkstatt/handlers/werkstatt-lock-status.ts +0 -82
- package/os/werkstatt/handlers/werkstatt-operation-validate.ts +0 -112
- package/os/werkstatt/handlers/workspace-deps.ts +0 -56
- package/os/werkstatt/index.ts +0 -39
- package/os/werkstatt/werkstatt.module.ts +0 -95
- package/src/tests/doctor-autonomy.test.ts +0 -246
- package/src/tests/forge-autonomy-validate.test.ts +0 -159
- package/src/tests/werkstatt-lock.test.ts +0 -357
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
Plugin loader (Werkstatt RFC-1648) — discover, verify, register, activate.
|
|
5
|
+
Fail-closed at every phase: a plugin failing any phase is entirely absent —
|
|
6
|
+
partial activation is impossible. Strict forgeRange compatibility; plugin
|
|
7
|
+
dependencies resolve refuse-on-conflict (never silent dedupe, never multi-instance).
|
|
8
|
+
Public npm and project-local plugins are the same species — one code path.
|
|
9
|
+
</purpose>
|
|
10
|
+
<non-goals><item>No compile cache in v1 — plugins ship compiled dist or plain-JS.</item></non-goals>
|
|
11
|
+
<CHANGE_SUMMARY><item>RFC-1648 (WP-5): initial loader.</item></CHANGE_SUMMARY>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
|
+
import { pathToFileURL } from "node:url";
|
|
17
|
+
|
|
18
|
+
import { parse as parseYaml } from "yaml";
|
|
19
|
+
|
|
20
|
+
import { createPluginContext, type ContextHostServices } from "./context.ts";
|
|
21
|
+
import { LIFECYCLE_HOOKS, PluginLoadError, type CommandModule, type PluginContext, type PluginManifest } from "./types.ts";
|
|
22
|
+
|
|
23
|
+
/** The running core version — plugins' forgeRange is checked against this. */
|
|
24
|
+
export function coreVersion(): string {
|
|
25
|
+
try {
|
|
26
|
+
const pkg = JSON.parse(readFileSync(join(import.meta.dirname ?? __dirname, "../../package.json"), "utf8"));
|
|
27
|
+
return pkg.version as string;
|
|
28
|
+
} catch {
|
|
29
|
+
return "10.0.0";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function semverSatisfies(version: string, range: string): boolean {
|
|
34
|
+
// Minimal honest semver: caret ranges and exact pins — the vocabulary forgeRange uses.
|
|
35
|
+
const parse = (v: string): [number, number, number] => {
|
|
36
|
+
const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
37
|
+
if (!m) throw new Error(`unparseable version: ${v}`);
|
|
38
|
+
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
39
|
+
};
|
|
40
|
+
const [maj, min, pat] = parse(version);
|
|
41
|
+
if (range.startsWith("^")) {
|
|
42
|
+
const [rMaj, rMin, rPat] = parse(range.slice(1));
|
|
43
|
+
if (maj !== rMaj) return false;
|
|
44
|
+
if (maj === 0) return min === rMin && pat >= rPat;
|
|
45
|
+
return min > rMin || (min === rMin && pat >= rPat);
|
|
46
|
+
}
|
|
47
|
+
if (range.startsWith(">=")) {
|
|
48
|
+
const [rMaj, rMin, rPat] = parse(range.slice(2));
|
|
49
|
+
return maj > rMaj || (maj === rMaj && (min > rMin || (min === rMin && pat >= rPat)));
|
|
50
|
+
}
|
|
51
|
+
const [eMaj, eMin, ePat] = parse(range);
|
|
52
|
+
return maj === eMaj && min === eMin && pat === ePat;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const KNOWN_CAPABILITIES = new Set(["filesystem", "network", "processSpawn", "gitMutation", "envKeys"]);
|
|
56
|
+
|
|
57
|
+
export function verifyManifest(raw: unknown, pluginDir: string): PluginManifest {
|
|
58
|
+
const m = raw as Partial<PluginManifest>;
|
|
59
|
+
if (!m || typeof m !== "object") throw new PluginLoadError("manifest-invalid", "manifest is not an object");
|
|
60
|
+
if (!m.id || typeof m.id !== "string") throw new PluginLoadError("manifest-invalid", "manifest.id missing");
|
|
61
|
+
if (!m.version) throw new PluginLoadError("manifest-invalid", `manifest.version missing`, m.id);
|
|
62
|
+
if (!m.forgeRange) throw new PluginLoadError("manifest-invalid", "manifest.forgeRange missing — strict compatibility is required", m.id);
|
|
63
|
+
for (const key of Object.keys(m.capabilities ?? {})) {
|
|
64
|
+
if (!KNOWN_CAPABILITIES.has(key)) {
|
|
65
|
+
throw new PluginLoadError("capability-unknown", `unknown capability declared: ${key}`, m.id);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const hooks = m.registers?.hooks ?? [];
|
|
69
|
+
for (const h of hooks) {
|
|
70
|
+
if (!LIFECYCLE_HOOKS.includes(h as never)) {
|
|
71
|
+
throw new PluginLoadError("manifest-invalid", `unknown lifecycle hook: ${h}`, m.id);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
void pluginDir;
|
|
75
|
+
return { schema: "forge:plugin-manifest/v1", ...m } as PluginManifest;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface LoadedPlugin {
|
|
79
|
+
manifest: PluginManifest;
|
|
80
|
+
ctx: PluginContext;
|
|
81
|
+
commands: CommandModule[];
|
|
82
|
+
skillsDir: string | null;
|
|
83
|
+
dir: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface LoadResult {
|
|
87
|
+
ok: true;
|
|
88
|
+
plugins: LoadedPlugin[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Resolve a plugin entry — npm package name or project-local path — to its
|
|
93
|
+
* directory. One code path for both species: locality is discovery, never capability.
|
|
94
|
+
*/
|
|
95
|
+
export function resolvePluginDir(entry: string, consumerRoot: string): string {
|
|
96
|
+
// Project-local: path entries starting with ./ or packages/.
|
|
97
|
+
if (entry.startsWith("./") || entry.startsWith("packages/") || entry.startsWith("/")) {
|
|
98
|
+
const p = resolve(consumerRoot, entry);
|
|
99
|
+
if (existsSync(join(p, "forge.plugin.yaml")) || existsSync(join(p, "package.json"))) return p;
|
|
100
|
+
}
|
|
101
|
+
// npm species: node_modules resolution — scoped or bare name.
|
|
102
|
+
const nm = join(consumerRoot, "node_modules", entry);
|
|
103
|
+
if (existsSync(nm)) return nm;
|
|
104
|
+
const scopedNm = join(consumerRoot, "node_modules", "@warpgogol", entry);
|
|
105
|
+
if (existsSync(scopedNm)) return scopedNm;
|
|
106
|
+
throw new PluginLoadError("manifest-invalid", `plugin entry unresolvable: ${entry}`, entry);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export async function loadPlugin(entry: string, consumerRoot: string, host: ContextHostServices): Promise<LoadedPlugin> {
|
|
110
|
+
const dir = resolvePluginDir(entry, consumerRoot);
|
|
111
|
+
const manifestPath = join(dir, "forge.plugin.yaml");
|
|
112
|
+
if (!existsSync(manifestPath)) {
|
|
113
|
+
throw new PluginLoadError("manifest-invalid", `forge.plugin.yaml missing in ${dir}`, entry);
|
|
114
|
+
}
|
|
115
|
+
const manifest = verifyManifest(parseYaml(readFileSync(manifestPath, "utf8")), dir);
|
|
116
|
+
|
|
117
|
+
// Strict compatibility — fail-closed, no degraded modes.
|
|
118
|
+
const core = coreVersion();
|
|
119
|
+
if (!semverSatisfies(core, manifest.forgeRange)) {
|
|
120
|
+
throw new PluginLoadError(
|
|
121
|
+
"forgerange-violation",
|
|
122
|
+
`plugin "${manifest.id}" requires forge ${manifest.forgeRange}, running core is ${core}`,
|
|
123
|
+
manifest.id,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const ctx = createPluginContext(manifest, host);
|
|
128
|
+
|
|
129
|
+
// Register command modules — fail-closed: any violation, the plugin is entirely absent.
|
|
130
|
+
const commands: CommandModule[] = [];
|
|
131
|
+
for (const modulePath of manifest.registers.commands ?? []) {
|
|
132
|
+
const abs = join(dir, modulePath);
|
|
133
|
+
if (!existsSync(abs)) {
|
|
134
|
+
throw new PluginLoadError("registration-refused", `command module missing: ${modulePath}`, manifest.id);
|
|
135
|
+
}
|
|
136
|
+
const mod = (await import(pathToFileURL(abs).href)) as { default?: CommandModule; command?: CommandModule };
|
|
137
|
+
const command = mod.default ?? mod.command;
|
|
138
|
+
if (!command || typeof command.id !== "string" || typeof command.run !== "function") {
|
|
139
|
+
throw new PluginLoadError("registration-refused", `command module ${modulePath} does not implement CommandModule`, manifest.id);
|
|
140
|
+
}
|
|
141
|
+
commands.push(command);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const skillsDir = manifest.registers.skills ? join(dir, manifest.registers.skills) : null;
|
|
145
|
+
return { manifest, ctx, commands, skillsDir, dir };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Plugin dependency resolution — refuse-on-conflict across the active set. */
|
|
149
|
+
export function checkPluginDependencyConflicts(manifests: PluginManifest[]): void {
|
|
150
|
+
const versions = new Map<string, { version: string; requiredBy: Array<[string, string]> }>();
|
|
151
|
+
for (const m of manifests) {
|
|
152
|
+
versions.set(m.id, { version: m.version, requiredBy: [] });
|
|
153
|
+
}
|
|
154
|
+
for (const m of manifests) {
|
|
155
|
+
for (const [depId, range] of Object.entries(m.pluginDependencies ?? {})) {
|
|
156
|
+
const dep = versions.get(depId);
|
|
157
|
+
if (!dep) {
|
|
158
|
+
throw new PluginLoadError("dependency-conflict", `plugin "${m.id}" requires absent plugin "${depId}"`, m.id);
|
|
159
|
+
}
|
|
160
|
+
dep.requiredBy.push([m.id, range]);
|
|
161
|
+
if (!semverSatisfies(dep.version, range)) {
|
|
162
|
+
throw new PluginLoadError(
|
|
163
|
+
"dependency-conflict",
|
|
164
|
+
`plugin "${m.id}" requires ${depId} ${range}, active version is ${dep.version} — refuse-on-conflict`,
|
|
165
|
+
m.id,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
package/src/sdk/scan.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
Static-scan executors (Werkstatt RFC-1648) — the honesty of capability declarations
|
|
5
|
+
is itself enforceable: plugin code bypassing SDK ports with raw capability imports
|
|
6
|
+
is a blocking violation. Dependency direction: plugins may depend on the core SDK
|
|
7
|
+
and other plugins — never consumer internals, core internals outside the SDK, or
|
|
8
|
+
scopeless shared packages.
|
|
9
|
+
</purpose>
|
|
10
|
+
<non-goals><item>No runtime sandboxing — auditability only, by design.</item></non-goals>
|
|
11
|
+
<CHANGE_SUMMARY><item>RFC-1648 (WP-5): initial scan executors.</item></CHANGE_SUMMARY>
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
|
|
15
|
+
import { join, extname } from "node:path";
|
|
16
|
+
|
|
17
|
+
export interface ScanViolation {
|
|
18
|
+
ruleId: string;
|
|
19
|
+
message: string;
|
|
20
|
+
severity: "blocking" | "advisory";
|
|
21
|
+
file?: string;
|
|
22
|
+
line?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Raw capability imports that bypass SDK ports. */
|
|
26
|
+
const RAW_IMPORTS: Array<{ pattern: RegExp; capability: string; ruleId: string }> = [
|
|
27
|
+
{ pattern: /from\s+["']node:child_process["']|require\(["']child_process["']\)/, capability: "processSpawn", ruleId: "CAP-SCAN-01" },
|
|
28
|
+
{ pattern: /from\s+["']node:fs\/promises["']|from\s+["']node:fs["']|require\(["']fs["']\)/, capability: "filesystem", ruleId: "CAP-SCAN-02" },
|
|
29
|
+
{ pattern: /from\s+["']node:net["']|from\s+["']node:https?["']|require\(["']https?["']\)/, capability: "network", ruleId: "CAP-SCAN-03" },
|
|
30
|
+
{ pattern: /(?<![\w.])fetch\s*\(/, capability: "network", ruleId: "CAP-SCAN-04" },
|
|
31
|
+
{ pattern: /from\s+["']node:os["'].*\bexec\b/, capability: "processSpawn", ruleId: "CAP-SCAN-05" },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
function* walkSources(dir: string): Generator<string> {
|
|
35
|
+
if (!existsSync(dir)) return;
|
|
36
|
+
for (const entry of readdirSync(dir)) {
|
|
37
|
+
if (entry === "node_modules" || entry === "dist" || entry.startsWith(".")) continue;
|
|
38
|
+
const p = join(dir, entry);
|
|
39
|
+
try {
|
|
40
|
+
if (statSync(p).isDirectory()) yield* walkSources(p);
|
|
41
|
+
else if ([".ts", ".js", ".mts", ".mjs"].includes(extname(entry))) yield p;
|
|
42
|
+
} catch {
|
|
43
|
+
// unreadable entries are not evidence
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function stripCommentsAndStrings(src: string): string {
|
|
49
|
+
return src
|
|
50
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
51
|
+
.replace(/\/\/[^\n]*/g, "")
|
|
52
|
+
.replace(/`(?:\\.|[^`\\])*`/g, "``")
|
|
53
|
+
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
54
|
+
.replace(/'(?:\\.|[^'\\])*'/g, "''");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* CAP-SCAN: scan plugin sources for raw capability imports bypassing the SDK.
|
|
59
|
+
* Import statements survive comment/string stripping because import specifiers
|
|
60
|
+
* are the syntax under test — strip only bodies, keep the import lines.
|
|
61
|
+
*/
|
|
62
|
+
export function scanPluginForRawImports(pluginDir: string): ScanViolation[] {
|
|
63
|
+
const violations: ScanViolation[] = [];
|
|
64
|
+
for (const file of walkSources(pluginDir)) {
|
|
65
|
+
const src = readFileSync(file, "utf8");
|
|
66
|
+
const importLines = src.split("\n").filter((l) => /^\s*(import|export\s+.*from|const\s+\w+\s*=\s*require)/.test(l));
|
|
67
|
+
const bodyStripped = stripCommentsAndStrings(src);
|
|
68
|
+
const lines = src.split("\n");
|
|
69
|
+
|
|
70
|
+
for (const { pattern, capability, ruleId } of RAW_IMPORTS) {
|
|
71
|
+
// Raw import detection against import lines.
|
|
72
|
+
if (ruleId !== "CAP-SCAN-04") {
|
|
73
|
+
for (const line of importLines) {
|
|
74
|
+
if (pattern.test(line)) {
|
|
75
|
+
violations.push({
|
|
76
|
+
ruleId,
|
|
77
|
+
message: `raw ${capability} import bypasses SDK ports — capability honesty is enforceable`,
|
|
78
|
+
severity: "blocking",
|
|
79
|
+
file,
|
|
80
|
+
line: lines.indexOf(line) + 1,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
// Raw fetch() call detection against the stripped body — a bare fetch not
|
|
86
|
+
// reached through ctx.network. ctx.network.fetch( is exempt by receiver shape.
|
|
87
|
+
const withoutCtxFetch = bodyStripped.replace(/\bctx\s*\.\s*network\s*\.\s*fetch\s*\(/g, "");
|
|
88
|
+
if (pattern.test(withoutCtxFetch)) {
|
|
89
|
+
violations.push({
|
|
90
|
+
ruleId,
|
|
91
|
+
message: `raw fetch() bypasses the network port — use ctx.network.fetch`,
|
|
92
|
+
severity: "blocking",
|
|
93
|
+
file,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return violations;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** FORGE-PLUG-DEP: dependency-direction scan over a plugin's package.json. */
|
|
103
|
+
export function scanPluginDependencyDirection(pluginDir: string): ScanViolation[] {
|
|
104
|
+
const pkgPath = join(pluginDir, "package.json");
|
|
105
|
+
if (!existsSync(pkgPath)) return [];
|
|
106
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8")) as { dependencies?: Record<string, string> };
|
|
107
|
+
const violations: ScanViolation[] = [];
|
|
108
|
+
for (const dep of Object.keys(pkg.dependencies ?? {})) {
|
|
109
|
+
// Allowed: the core SDK, other forge plugins.
|
|
110
|
+
if (dep === "@warpgogol/forge" || dep.startsWith("@warpgogol/forge-")) continue;
|
|
111
|
+
// Forbidden: consumer internals and legacy v9 internals.
|
|
112
|
+
if (dep.startsWith("@warpgogol/werkstatt") || dep.includes("consumer") || dep.includes("internal")) {
|
|
113
|
+
violations.push({
|
|
114
|
+
ruleId: "PLUG-DEP-01",
|
|
115
|
+
message: `plugin depends on forbidden internal/consumer package: ${dep}`,
|
|
116
|
+
severity: "blocking",
|
|
117
|
+
file: pkgPath,
|
|
118
|
+
});
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
// Forbidden: scopeless shared packages — none may exist (utility packages are the SDK anti-pattern).
|
|
122
|
+
if (!dep.startsWith("@")) {
|
|
123
|
+
violations.push({
|
|
124
|
+
ruleId: "PLUG-DEP-02",
|
|
125
|
+
message: `plugin depends on scopeless package "${dep}" — shared capability belongs in the SDK, never a utility package`,
|
|
126
|
+
severity: "blocking",
|
|
127
|
+
file: pkgPath,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return violations;
|
|
132
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
Skills generation (Werkstatt RFC-1648) — .agents/skills is generated by resolving
|
|
5
|
+
core skills plus all active plugins' skills into one UNTRACKED tree, content-hashed
|
|
6
|
+
inputs, incremental regeneration. Tracked twins are gone by construction: single
|
|
7
|
+
source, generated view — nothing to drift.
|
|
8
|
+
</purpose>
|
|
9
|
+
<CHANGE_SUMMARY><item>RFC-1648 (WP-5): initial skills generation.</item></CHANGE_SUMMARY>
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { createHash } from "node:crypto";
|
|
13
|
+
import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
|
|
16
|
+
function hashTree(dir: string): string {
|
|
17
|
+
const hash = createHash("sha256");
|
|
18
|
+
const walk = (d: string, prefix: string): void => {
|
|
19
|
+
if (!existsSync(d)) return;
|
|
20
|
+
for (const entry of readdirSync(d).sort()) {
|
|
21
|
+
const p = join(d, entry);
|
|
22
|
+
const rel = prefix ? `${prefix}/${entry}` : entry;
|
|
23
|
+
if (statSync(p).isDirectory()) walk(p, rel);
|
|
24
|
+
else {
|
|
25
|
+
hash.update(rel);
|
|
26
|
+
hash.update(readFileSync(p));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
walk(dir, "");
|
|
31
|
+
return hash.digest("hex");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface SkillsGenResult {
|
|
35
|
+
written: number;
|
|
36
|
+
inputHash: string;
|
|
37
|
+
targetDir: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Generate .agents/skills from core + active plugin skill dirs. The target is
|
|
42
|
+
* wiped and rewritten — it is a generated VIEW, untracked by construction;
|
|
43
|
+
* callers must ensure the path is gitignored.
|
|
44
|
+
*/
|
|
45
|
+
export function generateSkillsTree(targetDir: string, sources: Array<{ pluginId: string; skillsDir: string }>): SkillsGenResult {
|
|
46
|
+
const inputHash = createHash("sha256");
|
|
47
|
+
for (const s of sources) inputHash.update(s.pluginId).update(hashTree(s.skillsDir));
|
|
48
|
+
|
|
49
|
+
rmSync(targetDir, { recursive: true, force: true });
|
|
50
|
+
mkdirSync(targetDir, { recursive: true });
|
|
51
|
+
let written = 0;
|
|
52
|
+
for (const source of sources) {
|
|
53
|
+
const { skillsDir } = source;
|
|
54
|
+
if (!existsSync(skillsDir)) continue;
|
|
55
|
+
// flatten: contents merge at the generated root; otherwise the directory
|
|
56
|
+
// itself becomes a top-level entry (the _shared support contract).
|
|
57
|
+
const rootPrefix = (source as { flatten?: boolean }).flatten === false ? source.skillsDir.split("/").pop()! : "";
|
|
58
|
+
const walk = (d: string, rel: string): void => {
|
|
59
|
+
for (const entry of readdirSync(d)) {
|
|
60
|
+
const p = join(d, entry);
|
|
61
|
+
const r = rel ? join(rel, entry) : entry;
|
|
62
|
+
if (statSync(p).isDirectory()) walk(p, r);
|
|
63
|
+
else {
|
|
64
|
+
const target = join(targetDir, rootPrefix, r);
|
|
65
|
+
mkdirSync(join(target, ".."), { recursive: true });
|
|
66
|
+
copyFileSync(p, target);
|
|
67
|
+
written += 1;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
walk(skillsDir, "");
|
|
72
|
+
}
|
|
73
|
+
const digest = inputHash.digest("hex");
|
|
74
|
+
writeFileSync(join(targetDir, ".generated.json"), JSON.stringify({ inputHash: digest, at: new Date().toISOString() }));
|
|
75
|
+
return { written, inputHash: digest, targetDir };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Canonical forge skill-layout resolution: the canonical tree carries category
|
|
80
|
+
* subtrees (fo/, meta/, shared/) that flatten to the generated root; _shared
|
|
81
|
+
* passes through as-is. One source, one generated view — the v10 layout contract.
|
|
82
|
+
*/
|
|
83
|
+
export interface SkillSource {
|
|
84
|
+
pluginId: string;
|
|
85
|
+
skillsDir: string;
|
|
86
|
+
/** flatten: contents merge at root; false: the dir itself becomes a top-level entry. */
|
|
87
|
+
flatten: boolean;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function resolveCanonicalSkillSources(coreSkillsDir: string): SkillSource[] {
|
|
91
|
+
const sources: SkillSource[] = [];
|
|
92
|
+
for (const category of ["fo", "meta", "shared"]) {
|
|
93
|
+
const dir = join(coreSkillsDir, category);
|
|
94
|
+
if (existsSync(dir)) {
|
|
95
|
+
// Each category subtree flattens: skills/<cat>/<skill>/ -> <skill>/
|
|
96
|
+
sources.push({ pluginId: `core-${category}`, skillsDir: dir, flatten: true });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const sharedSupport = join(coreSkillsDir, "_shared");
|
|
100
|
+
if (existsSync(sharedSupport)) {
|
|
101
|
+
sources.push({ pluginId: "core-_shared", skillsDir: sharedSupport, flatten: false });
|
|
102
|
+
}
|
|
103
|
+
return sources;
|
|
104
|
+
}
|
package/src/sdk/types.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
Plugin SDK types (Werkstatt RFC-1648) — the platform boundary for in-process
|
|
5
|
+
executable plugins: manifest contract, command module contract, and the typed
|
|
6
|
+
PluginContext ports through which ALL platform interaction flows. Plugins never
|
|
7
|
+
touch raw node capabilities.
|
|
8
|
+
</purpose>
|
|
9
|
+
<non-goals><item>No loader or enforcement logic — contracts only.</item></non-goals>
|
|
10
|
+
<CHANGE_SUMMARY><item>RFC-1648 (WP-5): initial SDK contracts.</item></CHANGE_SUMMARY>
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface PluginManifest {
|
|
14
|
+
schema: "forge:plugin-manifest/v1";
|
|
15
|
+
/** e.g. "forge-typescript" — npm name minus scope. */
|
|
16
|
+
id: string;
|
|
17
|
+
version: string;
|
|
18
|
+
/** Required semver range — violation refuses load, fail-closed. */
|
|
19
|
+
forgeRange: string;
|
|
20
|
+
capabilities: {
|
|
21
|
+
filesystem?: "none" | "read" | "readwrite";
|
|
22
|
+
network?: boolean;
|
|
23
|
+
processSpawn?: boolean;
|
|
24
|
+
gitMutation?: boolean;
|
|
25
|
+
envKeys?: string[];
|
|
26
|
+
};
|
|
27
|
+
registers: {
|
|
28
|
+
commands?: string[];
|
|
29
|
+
skills?: string;
|
|
30
|
+
contractNodes?: string[];
|
|
31
|
+
hooks?: string[];
|
|
32
|
+
};
|
|
33
|
+
pluginDependencies?: Record<string, string>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface CommandResult {
|
|
37
|
+
status: "pass" | "fail" | "error";
|
|
38
|
+
violations?: Array<{ ruleId: string; message: string; severity: string; file?: string }>;
|
|
39
|
+
message?: string;
|
|
40
|
+
data?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CommandModule {
|
|
44
|
+
/** Namespaced, e.g. "typescript.validate". */
|
|
45
|
+
id: string;
|
|
46
|
+
scope: "repo" | "workspace" | "system";
|
|
47
|
+
description: string;
|
|
48
|
+
/** zod schema — closed flag vocabulary. */
|
|
49
|
+
flagsSchema?: unknown;
|
|
50
|
+
run(ctx: PluginContext, args: Record<string, unknown>): Promise<CommandResult>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Lifecycle hooks — closed list in v1; new hook points require core minor versions. */
|
|
54
|
+
export type LifecycleHook = "onActivate" | "onDeactivate" | "beforeIntegrate" | "afterIntegrate";
|
|
55
|
+
export const LIFECYCLE_HOOKS: readonly LifecycleHook[] = ["onActivate", "onDeactivate", "beforeIntegrate", "afterIntegrate"];
|
|
56
|
+
|
|
57
|
+
// ---- SDK ports — the ONLY platform access surface for plugin code. ----
|
|
58
|
+
|
|
59
|
+
export interface WorkspaceIOPort {
|
|
60
|
+
readFile(path: string): Promise<string>;
|
|
61
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
62
|
+
exists(path: string): Promise<boolean>;
|
|
63
|
+
list(dir: string, pattern?: string): Promise<string[]>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface EvidenceAccessPort {
|
|
67
|
+
consult(nodeId: string, inputDigest: string): Promise<{ hit: boolean; verdict?: unknown }>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface ContractRegistryPort {
|
|
71
|
+
registerNode(node: unknown): { ok: true } | { ok: false; errors: string[] };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface BindingsResolverPort {
|
|
75
|
+
get<T = unknown>(key: string): T | undefined;
|
|
76
|
+
require<T = unknown>(key: string): T;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface GitPort {
|
|
80
|
+
exec(args: string[]): Promise<string>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ProcessPort {
|
|
84
|
+
spawn(cmd: string, args: string[], opts?: { cwd?: string; timeoutMs?: number }): Promise<{ stdout: string; stderr: string; exitCode: number }>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface NetworkPort {
|
|
88
|
+
fetch(url: string, init?: { method?: string; headers?: Record<string, string>; body?: string }): Promise<{ status: number; body: string }>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface LoggerPort {
|
|
92
|
+
info(msg: string): void;
|
|
93
|
+
warn(msg: string): void;
|
|
94
|
+
error(msg: string): void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface PathResolverPort {
|
|
98
|
+
resolve(...parts: string[]): string;
|
|
99
|
+
root(): string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface PluginContext {
|
|
103
|
+
workspace: WorkspaceIOPort;
|
|
104
|
+
evidence: EvidenceAccessPort;
|
|
105
|
+
contracts: ContractRegistryPort;
|
|
106
|
+
bindings: BindingsResolverPort;
|
|
107
|
+
git: GitPort;
|
|
108
|
+
process: ProcessPort;
|
|
109
|
+
network: NetworkPort;
|
|
110
|
+
log: LoggerPort;
|
|
111
|
+
paths: PathResolverPort;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Typed incompatibility error — fail-closed, no degraded modes. */
|
|
115
|
+
export class PluginLoadError extends Error {
|
|
116
|
+
constructor(
|
|
117
|
+
public readonly kind: "forgerange-violation" | "manifest-invalid" | "capability-unknown" | "dependency-conflict" | "registration-refused",
|
|
118
|
+
message: string,
|
|
119
|
+
public readonly pluginId?: string,
|
|
120
|
+
) {
|
|
121
|
+
super(message);
|
|
122
|
+
this.name = "PluginLoadError";
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export class CapabilityViolation extends Error {
|
|
127
|
+
constructor(
|
|
128
|
+
public readonly capability: string,
|
|
129
|
+
public readonly pluginId: string,
|
|
130
|
+
detail: string,
|
|
131
|
+
) {
|
|
132
|
+
super(`capability violation: plugin "${pluginId}" has no ${capability} grant — ${detail}`);
|
|
133
|
+
this.name = "CapabilityViolation";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC-1517 self-scan regression: the real werkstatt workspace must carry zero
|
|
3
|
+
* PKG-HEALTH-10 violations — any shipped `../` literal resolving outside its
|
|
4
|
+
* package root is either a genuine defect (fix it), a monorepo-bound file
|
|
5
|
+
* (excludePathSegments), or a justified non-path use (same-line suppression /
|
|
6
|
+
* pkgHealth10Suppressions). This file is monorepo-only: it reads the real
|
|
7
|
+
* workspace tree, so it lives in excludePathSegments for the standalone
|
|
8
|
+
* extract.
|
|
9
|
+
*/
|
|
10
|
+
import { test, expect } from "vitest";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import type { ForgeCommandInput, ForgeRuntimeContext } from "../../src/types.ts";
|
|
13
|
+
import { runPackageHealth } from "../../os/core/handlers/package-health.ts";
|
|
14
|
+
|
|
15
|
+
test("PKG-HEALTH-10 reports no violations on the real workspace", async () => {
|
|
16
|
+
const context: ForgeRuntimeContext = {
|
|
17
|
+
workspaceRoot: join(process.cwd(), "..", ".."),
|
|
18
|
+
logger: { section: () => {}, info: () => {}, warn: () => {}, error: () => {}, success: () => {} },
|
|
19
|
+
dryRun: false,
|
|
20
|
+
outputFormat: "json",
|
|
21
|
+
};
|
|
22
|
+
const input: ForgeCommandInput = { argv: [], flags: {} };
|
|
23
|
+
const result = await runPackageHealth(input, context, () => ({ ok: true, detail: "" }));
|
|
24
|
+
const v10 =
|
|
25
|
+
result.data?.violations
|
|
26
|
+
.filter((v) => v.ruleId === "PKG-HEALTH-10")
|
|
27
|
+
.map((v) => `${v.packageName}: ${v.message}`) ?? [];
|
|
28
|
+
expect(v10).toEqual([]);
|
|
29
|
+
}, 120_000);
|