@warpgogol/forge 10.0.0 → 10.1.1
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/CHANGELOG.md +27 -0
- package/bin/cli.ts +17 -0
- package/dist/bin/cli.js +17 -0
- package/dist/bin/cli.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/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/integration/drain.d.ts +37 -0
- package/dist/src/integration/drain.d.ts.map +1 -0
- package/dist/src/integration/drain.js +235 -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/init.d.ts.map +1 -1
- package/dist/src/onboarding/init.js +4 -0
- package/dist/src/onboarding/init.js.map +1 -1
- package/dist/src/onboarding/upgrade.d.ts.map +1 -1
- package/dist/src/onboarding/upgrade.js +77 -2
- package/dist/src/onboarding/upgrade.js.map +1 -1
- package/dist/src/sdk/cli-bridge.d.ts +26 -0
- package/dist/src/sdk/cli-bridge.d.ts.map +1 -0
- package/dist/src/sdk/cli-bridge.js +89 -0
- package/dist/src/sdk/cli-bridge.js.map +1 -0
- 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/hooks.d.ts +14 -0
- package/dist/src/sdk/hooks.d.ts.map +1 -0
- package/dist/src/sdk/hooks.js +35 -0
- package/dist/src/sdk/hooks.js.map +1 -0
- package/dist/src/sdk/loader.d.ts +26 -0
- package/dist/src/sdk/loader.d.ts.map +1 -0
- package/dist/src/sdk/loader.js +170 -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 +141 -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/gitignore-entry.d.ts +3 -0
- package/dist/src/utils/gitignore-entry.d.ts.map +1 -0
- package/dist/src/utils/gitignore-entry.js +24 -0
- package/dist/src/utils/gitignore-entry.js.map +1 -0
- package/dist/src/utils/verifier-git.d.ts.map +1 -1
- package/dist/src/utils/verifier-git.js +18 -2
- package/dist/src/utils/verifier-git.js.map +1 -1
- package/os/rfc/probe-batch.ts +13 -6
- package/package.json +17 -1
- 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/integration/drain.ts +323 -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/init.ts +4 -0
- package/src/onboarding/upgrade.ts +84 -1
- package/src/sdk/cli-bridge.ts +94 -0
- package/src/sdk/context.ts +135 -0
- package/src/sdk/hooks.ts +51 -0
- package/src/sdk/loader.ts +187 -0
- package/src/sdk/scan.ts +132 -0
- package/src/sdk/skills-gen.ts +104 -0
- package/src/sdk/types.ts +158 -0
- package/src/utils/gitignore-entry.ts +24 -0
- package/src/utils/verifier-git.ts +17 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type PluginContext, type PluginManifest } from "./types.ts";
|
|
2
|
+
export interface ContextHostServices {
|
|
3
|
+
/** Repo/workspace root the plugin is scoped to. */
|
|
4
|
+
workspaceRoot: string;
|
|
5
|
+
bindings?: Record<string, unknown>;
|
|
6
|
+
hooks?: {
|
|
7
|
+
evidenceConsult?: PluginContext["evidence"]["consult"];
|
|
8
|
+
registerNode?: PluginContext["contracts"]["registerNode"];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Build a capability-enforcing PluginContext for one activated plugin. */
|
|
12
|
+
export declare function createPluginContext(manifest: PluginManifest, host: ContextHostServices): PluginContext;
|
|
13
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/sdk/context.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAI1F,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,KAAK,CAAC,EAAE;QACN,eAAe,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,CAAC;QACvD,YAAY,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,CAAC;KAC3D,CAAC;CACH;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,mBAAmB,GAAG,aAAa,CAsGtG"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
import { access, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
13
|
+
import { execFile } from "node:child_process";
|
|
14
|
+
import { dirname, resolve as pathResolve } from "node:path";
|
|
15
|
+
import { promisify } from "node:util";
|
|
16
|
+
import { CapabilityViolation } from "./types.js";
|
|
17
|
+
const execFileAsync = promisify(execFile);
|
|
18
|
+
/** Build a capability-enforcing PluginContext for one activated plugin. */
|
|
19
|
+
export function createPluginContext(manifest, host) {
|
|
20
|
+
const caps = manifest.capabilities ?? {};
|
|
21
|
+
const pid = manifest.id;
|
|
22
|
+
const fsGrant = caps.filesystem ?? "none";
|
|
23
|
+
const deny = (capability, detail) => {
|
|
24
|
+
throw new CapabilityViolation(capability, pid, detail);
|
|
25
|
+
};
|
|
26
|
+
const scoped = (path) => {
|
|
27
|
+
const resolved = pathResolve(host.workspaceRoot, path);
|
|
28
|
+
if (!resolved.startsWith(pathResolve(host.workspaceRoot))) {
|
|
29
|
+
deny("filesystem", `path escape outside workspace root: ${path}`);
|
|
30
|
+
}
|
|
31
|
+
return resolved;
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
workspace: {
|
|
35
|
+
async readFile(path) {
|
|
36
|
+
if (fsGrant === "none")
|
|
37
|
+
deny("filesystem", "readFile with filesystem:none");
|
|
38
|
+
return readFile(scoped(path), "utf8");
|
|
39
|
+
},
|
|
40
|
+
async writeFile(path, content) {
|
|
41
|
+
if (fsGrant !== "readwrite")
|
|
42
|
+
deny("filesystem", `writeFile with filesystem:${fsGrant}`);
|
|
43
|
+
const target = scoped(path);
|
|
44
|
+
await mkdir(dirname(target), { recursive: true });
|
|
45
|
+
await writeFile(target, content);
|
|
46
|
+
},
|
|
47
|
+
async exists(path) {
|
|
48
|
+
if (fsGrant === "none")
|
|
49
|
+
return false;
|
|
50
|
+
try {
|
|
51
|
+
await access(scoped(path));
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
async list(dir) {
|
|
59
|
+
if (fsGrant === "none")
|
|
60
|
+
deny("filesystem", "list with filesystem:none");
|
|
61
|
+
return readdir(scoped(dir));
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
evidence: {
|
|
65
|
+
consult: host.hooks?.evidenceConsult ?? (async () => ({ hit: false })),
|
|
66
|
+
},
|
|
67
|
+
contracts: {
|
|
68
|
+
registerNode: host.hooks?.registerNode ?? (() => ({ ok: false, errors: ["contract registration unavailable in this host"] })),
|
|
69
|
+
},
|
|
70
|
+
bindings: {
|
|
71
|
+
get(key) {
|
|
72
|
+
return host.bindings?.[key];
|
|
73
|
+
},
|
|
74
|
+
require(key) {
|
|
75
|
+
const v = host.bindings?.[key];
|
|
76
|
+
if (v === undefined)
|
|
77
|
+
throw new Error(`required binding missing: ${key}`);
|
|
78
|
+
return v;
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
git: {
|
|
82
|
+
async exec(args) {
|
|
83
|
+
if (!caps.gitMutation && ["commit", "push", "update-ref", "checkout", "reset", "rebase", "merge", "cherry-pick", "apply"].some((m) => args[0] === m)) {
|
|
84
|
+
deny("gitMutation", `mutating git op refused: git ${args[0]}`);
|
|
85
|
+
}
|
|
86
|
+
const { stdout } = await execFileAsync("git", args, { cwd: host.workspaceRoot });
|
|
87
|
+
return stdout;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
process: {
|
|
91
|
+
async spawn(cmd, args, opts) {
|
|
92
|
+
if (!caps.processSpawn)
|
|
93
|
+
deny("processSpawn", `spawn refused: ${cmd}`);
|
|
94
|
+
const timeoutMs = opts?.timeoutMs ?? 120_000; // mandatory timeouts — hanging commands die as executor error
|
|
95
|
+
try {
|
|
96
|
+
const { stdout, stderr } = await execFileAsync(cmd, args, {
|
|
97
|
+
cwd: opts?.cwd ?? host.workspaceRoot,
|
|
98
|
+
timeout: timeoutMs,
|
|
99
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
100
|
+
});
|
|
101
|
+
return { stdout, stderr, exitCode: 0 };
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
const e = err;
|
|
105
|
+
return { stdout: e.stdout ?? "", stderr: e.stderr ?? "", exitCode: typeof e.code === "number" ? e.code : 1 };
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
network: {
|
|
110
|
+
async fetch(url, init) {
|
|
111
|
+
if (!caps.network)
|
|
112
|
+
deny("network", `fetch refused: ${url}`);
|
|
113
|
+
const res = await fetch(url, init);
|
|
114
|
+
return { status: res.status, body: await res.text() };
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
log: {
|
|
118
|
+
info: (msg) => console.log(`[${pid}] ${msg}`),
|
|
119
|
+
warn: (msg) => console.warn(`[${pid}] ${msg}`),
|
|
120
|
+
error: (msg) => console.error(`[${pid}] ${msg}`),
|
|
121
|
+
},
|
|
122
|
+
paths: {
|
|
123
|
+
resolve: (...parts) => pathResolve(host.workspaceRoot, ...parts),
|
|
124
|
+
root: () => host.workspaceRoot,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/sdk/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAA2C,MAAM,YAAY,CAAC;AAE1F,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAY1C,2EAA2E;AAC3E,MAAM,UAAU,mBAAmB,CAAC,QAAwB,EAAE,IAAyB;IACrF,MAAM,IAAI,GAAG,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC;IACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC;IACxB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC;IAE1C,MAAM,IAAI,GAAG,CAAC,UAAkB,EAAE,MAAc,EAAS,EAAE;QACzD,MAAM,IAAI,mBAAmB,CAAC,UAAU,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC,CAAC;IAEF,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE;QACtC,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,QAAQ,CAAC,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AE,IAAI,CAAC,CAAC;gBACnC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YACxD,CAAC;SACF;QACD,GAAG,EAAE;YACH,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;YAC7C,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;YAC9C,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;SACjD;QACD,KAAK,EAAE;YACL,OAAO,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,aAAa,EAAE,GAAG,KAAK,CAAC;YAChE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa;SAC/B;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HookPayload, LifecycleHook } from "./types.ts";
|
|
2
|
+
import type { LoadedPlugin } from "./loader.ts";
|
|
3
|
+
export interface HookInvocationError {
|
|
4
|
+
pluginId: string;
|
|
5
|
+
hook: LifecycleHook;
|
|
6
|
+
error: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HookInvocationResult {
|
|
9
|
+
ran: number;
|
|
10
|
+
errors: HookInvocationError[];
|
|
11
|
+
}
|
|
12
|
+
/** Invoke one lifecycle hook across all active plugins — deterministic load order, isolated failures. */
|
|
13
|
+
export declare function invokeLifecycleHook(plugins: LoadedPlugin[], hook: LifecycleHook, payload?: HookPayload): Promise<HookInvocationResult>;
|
|
14
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/sdk/hooks.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,mBAAmB,EAAE,CAAC;CAC/B;AAED,yGAAyG;AACzG,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,YAAY,EAAE,EACvB,IAAI,EAAE,aAAa,EACnB,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAmB/B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>
|
|
4
|
+
Lifecycle-hook invocation surface (RFC-1648) — the only path through which plugin
|
|
5
|
+
hooks execute. Fail-loud per hook: a throwing hook surfaces as an error result,
|
|
6
|
+
never silently swallowed; one hook's failure does not prevent the remaining
|
|
7
|
+
implementations of the same hook from running (each is isolated, all errors
|
|
8
|
+
collected). Hook execution order is plugin load order — deterministic.
|
|
9
|
+
</purpose>
|
|
10
|
+
<CHANGE_SUMMARY><item>RFC-1648 WP-5 completion: initial invocation surface.</item></CHANGE_SUMMARY>
|
|
11
|
+
*/
|
|
12
|
+
/** Invoke one lifecycle hook across all active plugins — deterministic load order, isolated failures. */
|
|
13
|
+
export async function invokeLifecycleHook(plugins, hook, payload = {}) {
|
|
14
|
+
let ran = 0;
|
|
15
|
+
const errors = [];
|
|
16
|
+
for (const plugin of plugins) {
|
|
17
|
+
for (const hookModule of plugin.hooks) {
|
|
18
|
+
if (hookModule.hook !== hook)
|
|
19
|
+
continue;
|
|
20
|
+
ran += 1;
|
|
21
|
+
try {
|
|
22
|
+
await hookModule.run(plugin.ctx, payload);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
errors.push({
|
|
26
|
+
pluginId: plugin.manifest.id,
|
|
27
|
+
hook,
|
|
28
|
+
error: err instanceof Error ? err.message : String(err),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { ran, errors };
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/sdk/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAgBF,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAAuB,EACvB,IAAmB,EACnB,UAAuB,EAAE;IAEzB,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,MAAM,MAAM,GAA0B,EAAE,CAAC;IACzC,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACtC,IAAI,UAAU,CAAC,IAAI,KAAK,IAAI;gBAAE,SAAS;YACvC,GAAG,IAAI,CAAC,CAAC;YACT,IAAI,CAAC;gBACH,MAAM,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,GAAoB,EAAE,OAAO,CAAC,CAAC;YAC7D,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,IAAI,CAAC;oBACV,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE;oBAC5B,IAAI;oBACJ,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;iBACxD,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ContextHostServices } from "./context.ts";
|
|
2
|
+
import { type CommandModule, type HookModule, type PluginContext, type PluginManifest } from "./types.ts";
|
|
3
|
+
/** The running core version — plugins' forgeRange is checked against this. */
|
|
4
|
+
export declare function coreVersion(): string;
|
|
5
|
+
export declare function verifyManifest(raw: unknown, pluginDir: string): PluginManifest;
|
|
6
|
+
export interface LoadedPlugin {
|
|
7
|
+
manifest: PluginManifest;
|
|
8
|
+
ctx: PluginContext;
|
|
9
|
+
commands: CommandModule[];
|
|
10
|
+
hooks: HookModule[];
|
|
11
|
+
skillsDir: string | null;
|
|
12
|
+
dir: string;
|
|
13
|
+
}
|
|
14
|
+
export interface LoadResult {
|
|
15
|
+
ok: true;
|
|
16
|
+
plugins: LoadedPlugin[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a plugin entry — npm package name or project-local path — to its
|
|
20
|
+
* directory. One code path for both species: locality is discovery, never capability.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolvePluginDir(entry: string, consumerRoot: string): string;
|
|
23
|
+
export declare function loadPlugin(entry: string, consumerRoot: string, host: ContextHostServices): Promise<LoadedPlugin>;
|
|
24
|
+
/** Plugin dependency resolution — refuse-on-conflict across the active set. */
|
|
25
|
+
export declare function checkPluginDependencyConflicts(manifests: PluginManifest[]): void;
|
|
26
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/sdk/loader.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAuB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAoC,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5I,8EAA8E;AAC9E,wBAAgB,WAAW,IAAI,MAAM,CAOpC;AA0BD,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAc9E;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,cAAc,CAAC;IACzB,GAAG,EAAE,aAAa,CAAC;IACnB,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,IAAI,CAAC;IACT,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAY5E;AAED,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CA0DtH;AAED,+EAA+E;AAC/E,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,IAAI,CAqBhF"}
|
|
@@ -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
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
14
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
15
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
16
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return path;
|
|
20
|
+
};
|
|
21
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
22
|
+
import { join, resolve } from "node:path";
|
|
23
|
+
import { pathToFileURL } from "node:url";
|
|
24
|
+
import { parse as parseYaml } from "yaml";
|
|
25
|
+
import { createPluginContext } from "./context.js";
|
|
26
|
+
import { LIFECYCLE_HOOKS, PluginLoadError } from "./types.js";
|
|
27
|
+
/** The running core version — plugins' forgeRange is checked against this. */
|
|
28
|
+
export function coreVersion() {
|
|
29
|
+
try {
|
|
30
|
+
const pkg = JSON.parse(readFileSync(join(import.meta.dirname ?? __dirname, "../../package.json"), "utf8"));
|
|
31
|
+
return pkg.version;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return "10.0.0";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function semverSatisfies(version, range) {
|
|
38
|
+
// Minimal honest semver: caret ranges and exact pins — the vocabulary forgeRange uses.
|
|
39
|
+
const parse = (v) => {
|
|
40
|
+
const m = v.match(/^(\d+)\.(\d+)\.(\d+)/);
|
|
41
|
+
if (!m)
|
|
42
|
+
throw new Error(`unparseable version: ${v}`);
|
|
43
|
+
return [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
44
|
+
};
|
|
45
|
+
const [maj, min, pat] = parse(version);
|
|
46
|
+
if (range.startsWith("^")) {
|
|
47
|
+
const [rMaj, rMin, rPat] = parse(range.slice(1));
|
|
48
|
+
if (maj !== rMaj)
|
|
49
|
+
return false;
|
|
50
|
+
if (maj === 0)
|
|
51
|
+
return min === rMin && pat >= rPat;
|
|
52
|
+
return min > rMin || (min === rMin && pat >= rPat);
|
|
53
|
+
}
|
|
54
|
+
if (range.startsWith(">=")) {
|
|
55
|
+
const [rMaj, rMin, rPat] = parse(range.slice(2));
|
|
56
|
+
return maj > rMaj || (maj === rMaj && (min > rMin || (min === rMin && pat >= rPat)));
|
|
57
|
+
}
|
|
58
|
+
const [eMaj, eMin, ePat] = parse(range);
|
|
59
|
+
return maj === eMaj && min === eMin && pat === ePat;
|
|
60
|
+
}
|
|
61
|
+
const KNOWN_CAPABILITIES = new Set(["filesystem", "network", "processSpawn", "gitMutation", "envKeys"]);
|
|
62
|
+
export function verifyManifest(raw, pluginDir) {
|
|
63
|
+
const m = raw;
|
|
64
|
+
if (!m || typeof m !== "object")
|
|
65
|
+
throw new PluginLoadError("manifest-invalid", "manifest is not an object");
|
|
66
|
+
if (!m.id || typeof m.id !== "string")
|
|
67
|
+
throw new PluginLoadError("manifest-invalid", "manifest.id missing");
|
|
68
|
+
if (!m.version)
|
|
69
|
+
throw new PluginLoadError("manifest-invalid", `manifest.version missing`, m.id);
|
|
70
|
+
if (!m.forgeRange)
|
|
71
|
+
throw new PluginLoadError("manifest-invalid", "manifest.forgeRange missing — strict compatibility is required", m.id);
|
|
72
|
+
for (const key of Object.keys(m.capabilities ?? {})) {
|
|
73
|
+
if (!KNOWN_CAPABILITIES.has(key)) {
|
|
74
|
+
throw new PluginLoadError("capability-unknown", `unknown capability declared: ${key}`, m.id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// registers.hooks entries are module paths — validated at load, not here.
|
|
78
|
+
void pluginDir;
|
|
79
|
+
return { schema: "forge:plugin-manifest/v1", ...m };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resolve a plugin entry — npm package name or project-local path — to its
|
|
83
|
+
* directory. One code path for both species: locality is discovery, never capability.
|
|
84
|
+
*/
|
|
85
|
+
export function resolvePluginDir(entry, consumerRoot) {
|
|
86
|
+
// Project-local: path entries starting with ./ or packages/.
|
|
87
|
+
if (entry.startsWith("./") || entry.startsWith("packages/") || entry.startsWith("/")) {
|
|
88
|
+
const p = resolve(consumerRoot, entry);
|
|
89
|
+
if (existsSync(join(p, "forge.plugin.yaml")) || existsSync(join(p, "package.json")))
|
|
90
|
+
return p;
|
|
91
|
+
}
|
|
92
|
+
// npm species: node_modules resolution — scoped or bare name.
|
|
93
|
+
const nm = join(consumerRoot, "node_modules", entry);
|
|
94
|
+
if (existsSync(nm))
|
|
95
|
+
return nm;
|
|
96
|
+
const scopedNm = join(consumerRoot, "node_modules", "@warpgogol", entry);
|
|
97
|
+
if (existsSync(scopedNm))
|
|
98
|
+
return scopedNm;
|
|
99
|
+
throw new PluginLoadError("manifest-invalid", `plugin entry unresolvable: ${entry}`, entry);
|
|
100
|
+
}
|
|
101
|
+
export async function loadPlugin(entry, consumerRoot, host) {
|
|
102
|
+
const dir = resolvePluginDir(entry, consumerRoot);
|
|
103
|
+
const manifestPath = join(dir, "forge.plugin.yaml");
|
|
104
|
+
if (!existsSync(manifestPath)) {
|
|
105
|
+
throw new PluginLoadError("manifest-invalid", `forge.plugin.yaml missing in ${dir}`, entry);
|
|
106
|
+
}
|
|
107
|
+
const manifest = verifyManifest(parseYaml(readFileSync(manifestPath, "utf8")), dir);
|
|
108
|
+
// Strict compatibility — fail-closed, no degraded modes.
|
|
109
|
+
const core = coreVersion();
|
|
110
|
+
if (!semverSatisfies(core, manifest.forgeRange)) {
|
|
111
|
+
throw new PluginLoadError("forgerange-violation", `plugin "${manifest.id}" requires forge ${manifest.forgeRange}, running core is ${core}`, manifest.id);
|
|
112
|
+
}
|
|
113
|
+
const ctx = createPluginContext(manifest, host);
|
|
114
|
+
// Register command modules — fail-closed: any violation, the plugin is entirely absent.
|
|
115
|
+
const commands = [];
|
|
116
|
+
for (const modulePath of manifest.registers.commands ?? []) {
|
|
117
|
+
const abs = join(dir, modulePath);
|
|
118
|
+
if (!existsSync(abs)) {
|
|
119
|
+
throw new PluginLoadError("registration-refused", `command module missing: ${modulePath}`, manifest.id);
|
|
120
|
+
}
|
|
121
|
+
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(abs).href)));
|
|
122
|
+
const command = mod.default ?? mod.command;
|
|
123
|
+
if (!command || typeof command.id !== "string" || typeof command.run !== "function") {
|
|
124
|
+
throw new PluginLoadError("registration-refused", `command module ${modulePath} does not implement CommandModule`, manifest.id);
|
|
125
|
+
}
|
|
126
|
+
commands.push(command);
|
|
127
|
+
}
|
|
128
|
+
// Register lifecycle-hook modules — fail-closed: each module's declared hook
|
|
129
|
+
// must be in the closed vocabulary; duplicates within one plugin refuse.
|
|
130
|
+
const hooks = [];
|
|
131
|
+
const seenHooks = new Set();
|
|
132
|
+
for (const hookPath of manifest.registers.hooks ?? []) {
|
|
133
|
+
const abs = join(dir, hookPath);
|
|
134
|
+
if (!existsSync(abs)) {
|
|
135
|
+
throw new PluginLoadError("registration-refused", `hook module missing: ${hookPath}`, manifest.id);
|
|
136
|
+
}
|
|
137
|
+
const mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(abs).href)));
|
|
138
|
+
const hookMod = mod.default ?? mod.hook;
|
|
139
|
+
if (!hookMod || typeof hookMod.run !== "function" || !LIFECYCLE_HOOKS.includes(hookMod.hook)) {
|
|
140
|
+
throw new PluginLoadError("registration-refused", `hook module ${hookPath} does not implement HookModule`, manifest.id);
|
|
141
|
+
}
|
|
142
|
+
if (seenHooks.has(hookMod.hook)) {
|
|
143
|
+
throw new PluginLoadError("registration-refused", `duplicate hook implementation: ${hookMod.hook}`, manifest.id);
|
|
144
|
+
}
|
|
145
|
+
seenHooks.add(hookMod.hook);
|
|
146
|
+
hooks.push(hookMod);
|
|
147
|
+
}
|
|
148
|
+
const skillsDir = manifest.registers.skills ? join(dir, manifest.registers.skills) : null;
|
|
149
|
+
return { manifest, ctx, commands, hooks, skillsDir, dir };
|
|
150
|
+
}
|
|
151
|
+
/** Plugin dependency resolution — refuse-on-conflict across the active set. */
|
|
152
|
+
export function checkPluginDependencyConflicts(manifests) {
|
|
153
|
+
const versions = new Map();
|
|
154
|
+
for (const m of manifests) {
|
|
155
|
+
versions.set(m.id, { version: m.version, requiredBy: [] });
|
|
156
|
+
}
|
|
157
|
+
for (const m of manifests) {
|
|
158
|
+
for (const [depId, range] of Object.entries(m.pluginDependencies ?? {})) {
|
|
159
|
+
const dep = versions.get(depId);
|
|
160
|
+
if (!dep) {
|
|
161
|
+
throw new PluginLoadError("dependency-conflict", `plugin "${m.id}" requires absent plugin "${depId}"`, m.id);
|
|
162
|
+
}
|
|
163
|
+
dep.requiredBy.push([m.id, range]);
|
|
164
|
+
if (!semverSatisfies(dep.version, range)) {
|
|
165
|
+
throw new PluginLoadError("dependency-conflict", `plugin "${m.id}" requires ${depId} ${range}, active version is ${dep.version} — refuse-on-conflict`, m.id);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/sdk/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;;;;;;;;;AAEF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAA4B,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,eAAe,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AAC,IAAI,SAAS,EAAE,CAAC;QAC1B,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,IAAI,EAAE,CAAC,EAAE,CAAC;YACxE,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,eAAe,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC,EAAE,6BAA6B,KAAK,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAC/G,CAAC;YACD,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;YACnC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC;gBACzC,MAAM,IAAI,eAAe,CACvB,qBAAqB,EACrB,WAAW,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,KAAK,uBAAuB,GAAG,CAAC,OAAO,uBAAuB,EACpG,CAAC,CAAC,EAAE,CACL,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ScanViolation {
|
|
2
|
+
ruleId: string;
|
|
3
|
+
message: string;
|
|
4
|
+
severity: "blocking" | "advisory";
|
|
5
|
+
file?: string;
|
|
6
|
+
line?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* CAP-SCAN: scan plugin sources for raw capability imports bypassing the SDK.
|
|
10
|
+
* Import statements survive comment/string stripping because import specifiers
|
|
11
|
+
* are the syntax under test — strip only bodies, keep the import lines.
|
|
12
|
+
*/
|
|
13
|
+
export declare function scanPluginForRawImports(pluginDir: string): ScanViolation[];
|
|
14
|
+
/** FORGE-PLUG-DEP: dependency-direction scan over a plugin's package.json. */
|
|
15
|
+
export declare function scanPluginDependencyDirection(pluginDir: string): ScanViolation[];
|
|
16
|
+
//# sourceMappingURL=scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../../../src/sdk/scan.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,UAAU,GAAG,UAAU,CAAC;IAClC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAkCD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CAsC1E;AAED,8EAA8E;AAC9E,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,EAAE,CA6BhF"}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
import { readFileSync, readdirSync, statSync, existsSync } from "node:fs";
|
|
14
|
+
import { join, extname } from "node:path";
|
|
15
|
+
/** Raw capability imports that bypass SDK ports. */
|
|
16
|
+
const RAW_IMPORTS = [
|
|
17
|
+
{ pattern: /from\s+["']node:child_process["']|require\(["']child_process["']\)/, capability: "processSpawn", ruleId: "CAP-SCAN-01" },
|
|
18
|
+
{ pattern: /from\s+["']node:fs\/promises["']|from\s+["']node:fs["']|require\(["']fs["']\)/, capability: "filesystem", ruleId: "CAP-SCAN-02" },
|
|
19
|
+
{ pattern: /from\s+["']node:net["']|from\s+["']node:https?["']|require\(["']https?["']\)/, capability: "network", ruleId: "CAP-SCAN-03" },
|
|
20
|
+
{ pattern: /(?<![\w.])fetch\s*\(/, capability: "network", ruleId: "CAP-SCAN-04" },
|
|
21
|
+
{ pattern: /from\s+["']node:os["'].*\bexec\b/, capability: "processSpawn", ruleId: "CAP-SCAN-05" },
|
|
22
|
+
];
|
|
23
|
+
function* walkSources(dir) {
|
|
24
|
+
if (!existsSync(dir))
|
|
25
|
+
return;
|
|
26
|
+
for (const entry of readdirSync(dir)) {
|
|
27
|
+
if (entry === "node_modules" || entry === "dist" || entry.startsWith("."))
|
|
28
|
+
continue;
|
|
29
|
+
const p = join(dir, entry);
|
|
30
|
+
try {
|
|
31
|
+
if (statSync(p).isDirectory())
|
|
32
|
+
yield* walkSources(p);
|
|
33
|
+
else if ([".ts", ".js", ".mts", ".mjs"].includes(extname(entry)))
|
|
34
|
+
yield p;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// unreadable entries are not evidence
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function stripCommentsAndStrings(src) {
|
|
42
|
+
return src
|
|
43
|
+
.replace(/\/\*[\s\S]*?\*\//g, "")
|
|
44
|
+
.replace(/\/\/[^\n]*/g, "")
|
|
45
|
+
.replace(/`(?:\\.|[^`\\])*`/g, "``")
|
|
46
|
+
.replace(/"(?:\\.|[^"\\])*"/g, '""')
|
|
47
|
+
.replace(/'(?:\\.|[^'\\])*'/g, "''");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* CAP-SCAN: scan plugin sources for raw capability imports bypassing the SDK.
|
|
51
|
+
* Import statements survive comment/string stripping because import specifiers
|
|
52
|
+
* are the syntax under test — strip only bodies, keep the import lines.
|
|
53
|
+
*/
|
|
54
|
+
export function scanPluginForRawImports(pluginDir) {
|
|
55
|
+
const violations = [];
|
|
56
|
+
for (const file of walkSources(pluginDir)) {
|
|
57
|
+
const src = readFileSync(file, "utf8");
|
|
58
|
+
const importLines = src.split("\n").filter((l) => /^\s*(import|export\s+.*from|const\s+\w+\s*=\s*require)/.test(l));
|
|
59
|
+
const bodyStripped = stripCommentsAndStrings(src);
|
|
60
|
+
const lines = src.split("\n");
|
|
61
|
+
for (const { pattern, capability, ruleId } of RAW_IMPORTS) {
|
|
62
|
+
// Raw import detection against import lines.
|
|
63
|
+
if (ruleId !== "CAP-SCAN-04") {
|
|
64
|
+
for (const line of importLines) {
|
|
65
|
+
if (pattern.test(line)) {
|
|
66
|
+
violations.push({
|
|
67
|
+
ruleId,
|
|
68
|
+
message: `raw ${capability} import bypasses SDK ports — capability honesty is enforceable`,
|
|
69
|
+
severity: "blocking",
|
|
70
|
+
file,
|
|
71
|
+
line: lines.indexOf(line) + 1,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Raw fetch() call detection against the stripped body — a bare fetch not
|
|
78
|
+
// reached through ctx.network. ctx.network.fetch( is exempt by receiver shape.
|
|
79
|
+
const withoutCtxFetch = bodyStripped.replace(/\bctx\s*\.\s*network\s*\.\s*fetch\s*\(/g, "");
|
|
80
|
+
if (pattern.test(withoutCtxFetch)) {
|
|
81
|
+
violations.push({
|
|
82
|
+
ruleId,
|
|
83
|
+
message: `raw fetch() bypasses the network port — use ctx.network.fetch`,
|
|
84
|
+
severity: "blocking",
|
|
85
|
+
file,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return violations;
|
|
92
|
+
}
|
|
93
|
+
/** FORGE-PLUG-DEP: dependency-direction scan over a plugin's package.json. */
|
|
94
|
+
export function scanPluginDependencyDirection(pluginDir) {
|
|
95
|
+
const pkgPath = join(pluginDir, "package.json");
|
|
96
|
+
if (!existsSync(pkgPath))
|
|
97
|
+
return [];
|
|
98
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
99
|
+
const violations = [];
|
|
100
|
+
for (const dep of Object.keys(pkg.dependencies ?? {})) {
|
|
101
|
+
// Allowed: the core SDK, other forge plugins.
|
|
102
|
+
if (dep === "@warpgogol/forge" || dep.startsWith("@warpgogol/forge-"))
|
|
103
|
+
continue;
|
|
104
|
+
// Forbidden: consumer internals and legacy v9 internals.
|
|
105
|
+
if (dep.startsWith("@warpgogol/werkstatt") || dep.includes("consumer") || dep.includes("internal")) {
|
|
106
|
+
violations.push({
|
|
107
|
+
ruleId: "PLUG-DEP-01",
|
|
108
|
+
message: `plugin depends on forbidden internal/consumer package: ${dep}`,
|
|
109
|
+
severity: "blocking",
|
|
110
|
+
file: pkgPath,
|
|
111
|
+
});
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
// Forbidden: scopeless shared packages — none may exist (utility packages are the SDK anti-pattern).
|
|
115
|
+
if (!dep.startsWith("@")) {
|
|
116
|
+
violations.push({
|
|
117
|
+
ruleId: "PLUG-DEP-02",
|
|
118
|
+
message: `plugin depends on scopeless package "${dep}" — shared capability belongs in the SDK, never a utility package`,
|
|
119
|
+
severity: "blocking",
|
|
120
|
+
file: pkgPath,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return violations;
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scan.js","sourceRoot":"","sources":["../../../src/sdk/scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;EAWE;AAEF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC1E,O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D,GAAG,EAAE;gBACxE,QAAQ,EAAE,UAAU;gBACpB,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;YACH,SAAS;QACX,CAAC;QACD,qGAAqG;QACrG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,UAAU,CAAC,IAAI,CAAC;gBACd,MAAM,EAAE,aAAa;gBACrB,OAAO,EAAE,wCAAwC,GAAG,mEAAmE;gBACvH,QAAQ,EAAE,UAAU;gBACpB,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface SkillsGenResult {
|
|
2
|
+
written: number;
|
|
3
|
+
inputHash: string;
|
|
4
|
+
targetDir: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generate .agents/skills from core + active plugin skill dirs. The target is
|
|
8
|
+
* wiped and rewritten — it is a generated VIEW, untracked by construction;
|
|
9
|
+
* callers must ensure the path is gitignored.
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateSkillsTree(targetDir: string, sources: Array<{
|
|
12
|
+
pluginId: string;
|
|
13
|
+
skillsDir: string;
|
|
14
|
+
}>): SkillsGenResult;
|
|
15
|
+
/**
|
|
16
|
+
* Canonical forge skill-layout resolution: the canonical tree carries category
|
|
17
|
+
* subtrees (fo/, meta/, shared/) that flatten to the generated root; _shared
|
|
18
|
+
* passes through as-is. One source, one generated view — the v10 layout contract.
|
|
19
|
+
*/
|
|
20
|
+
export interface SkillSource {
|
|
21
|
+
pluginId: string;
|
|
22
|
+
skillsDir: string;
|
|
23
|
+
/** flatten: contents merge at root; false: the dir itself becomes a top-level entry. */
|
|
24
|
+
flatten: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare function resolveCanonicalSkillSources(coreSkillsDir: string): SkillSource[];
|
|
27
|
+
//# sourceMappingURL=skills-gen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skills-gen.d.ts","sourceRoot":"","sources":["../../../src/sdk/skills-gen.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,eAAe,CA+B9H;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,4BAA4B,CAAC,aAAa,EAAE,MAAM,GAAG,WAAW,EAAE,CAcjF"}
|