@codyswann/lisa 4.101.4 → 4.101.6
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/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +24 -5
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/dist/opencode/hooks-installer.d.ts.map +1 -1
- package/dist/opencode/hooks-installer.js +8 -0
- package/dist/opencode/hooks-installer.js.map +1 -1
- package/dist/opencode/plugin-catalog.d.ts.map +1 -1
- package/dist/opencode/plugin-catalog.js +5 -0
- package/dist/opencode/plugin-catalog.js.map +1 -1
- package/dist/opencode/plugin-templates/block-host-name-leak.mjs +511 -0
- package/dist/opencode/plugin-templates/block-host-name-leak.sh +69 -0
- package/dist/opencode/plugin-templates/host-name-command-context.mjs +455 -0
- package/dist/opencode/plugin-templates/lisa-block-host-name-leak.ts +62 -0
- package/package.json +4 -4
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/scripts/automation-run-record.mjs +678 -0
- package/plugins/lisa/.codex-plugin/scripts/blocker-edge-resolution.mjs +150 -0
- package/plugins/lisa/.codex-plugin/scripts/intake-blocker-reprobe.mjs +1379 -0
- package/plugins/lisa/.codex-plugin/scripts/intake-prework-denominator.mjs +249 -0
- package/plugins/lisa/.codex-plugin/scripts/operator-id-kinds.mjs +120 -0
- package/plugins/lisa/.codex-plugin/scripts/qa-signal-lifecycle.mjs +523 -0
- package/plugins/lisa/.codex-plugin/scripts/ready-queue-order.mjs +549 -0
- package/plugins/lisa/.codex-plugin/scripts/resolve-lifecycle-role.mjs +347 -0
- package/plugins/lisa/hooks/block-host-name-leak.mjs +11 -5
- package/plugins/lisa/hooks/host-name-command-context.mjs +45 -2
- package/plugins/lisa-agy/hooks/block-host-name-leak.mjs +11 -5
- package/plugins/lisa-agy/hooks/host-name-command-context.mjs +45 -2
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/hooks/block-host-name-leak.mjs +11 -5
- package/plugins/lisa-copilot/hooks/host-name-command-context.mjs +45 -2
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/hooks/block-host-name-leak.mjs +11 -5
- package/plugins/lisa-cursor/hooks/host-name-command-context.mjs +45 -2
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/hooks/block-host-name-leak.mjs +11 -5
- package/plugins/lisa-devin/hooks/host-name-command-context.mjs +45 -2
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/hooks/block-host-name-leak.mjs +11 -5
- package/plugins/src/base/hooks/host-name-command-context.mjs +45 -2
- package/scripts/copy-opencode-plugin-templates.mjs +3 -0
- package/scripts/generate-codex-plugin-artifacts.mjs +6 -0
- package/scripts/lib/codex-shared-scripts.mjs +156 -0
- package/scripts/lib/host-name-launcher-cases.mjs +280 -0
- package/scripts/verify-host-name-target-scope.mjs +9 -0
|
@@ -47,11 +47,13 @@
|
|
|
47
47
|
* `dist/` ships to npm, so **this** repository may not name its hosts. A host
|
|
48
48
|
* naming itself carries none of that.
|
|
49
49
|
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
50
|
+
* Claude, Codex, Cursor, Antigravity, Copilot and Devin register the canonical
|
|
51
|
+
* plugin guard. OpenCode installs a native tool.execute.before adapter beside
|
|
52
|
+
* the same wrapper/classifier/helper; its package staging adds only the normal
|
|
53
|
+
* ownership banner. It preserves exit0 warnings and exit2 refusals. All seven
|
|
54
|
+
* surfaces therefore share target-scoped policy, rather than refusing a host
|
|
55
|
+
* project's own name. The generic dispatcher copy-overwrite roster remains
|
|
56
|
+
* separate; this guard is not added to that roster.
|
|
55
57
|
*
|
|
56
58
|
* WHERE IT APPLIES: THE TARGET, NOT THE CHECKOUT (#4462)
|
|
57
59
|
*
|
|
@@ -70,6 +72,10 @@
|
|
|
70
72
|
* routing. Unsupported shell syntax, unresolved expansions and ambiguous
|
|
71
73
|
* repositories earn no host exemption. This is bounded command inspection,
|
|
72
74
|
* not shell execution or a claim to close every shell/identity leak class.
|
|
75
|
+
* Literal one-level sh -c and bash -c executable-script operands reuse that
|
|
76
|
+
* inspection with the inherited directory/environment. No other quoted argv
|
|
77
|
+
* is interpreted as code. Dynamic scripts, deeper nesting, other interpreters
|
|
78
|
+
* and other launcher options remain outside this recognition contract.
|
|
73
79
|
*
|
|
74
80
|
* FAILING OPEN, LOUDLY
|
|
75
81
|
*
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Bounded command/target resolution; submitted scripts are never executed.
|
|
3
|
+
* One literal sh/bash -c script operand is parsed once. Dynamic scripts,
|
|
4
|
+
* deeper launchers, other interpreters and other launcher options are outside
|
|
5
|
+
* this recognition contract, not proof that an unrecognized command is safe.
|
|
6
|
+
*/
|
|
2
7
|
import { execFileSync } from "node:child_process";
|
|
3
8
|
import { statSync } from "node:fs";
|
|
4
9
|
import path from "node:path";
|
|
@@ -204,11 +209,30 @@ export function repositoryFromSpec(spec) {
|
|
|
204
209
|
* @returns {object[]} Active gh calls with their bounded command contexts.
|
|
205
210
|
*/
|
|
206
211
|
export function ghCommands(command, initialCwd, env = process.env) {
|
|
212
|
+
return commandContexts(command, initialCwd, env, true, false);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Parse a command list, permitting at most one literal executable script slot.
|
|
217
|
+
* @param {string} command Command text, never evaluated.
|
|
218
|
+
* @param {string|undefined} initialCwd Inherited literal directory, if known.
|
|
219
|
+
* @param {object} env Inherited environment.
|
|
220
|
+
* @param {boolean} launcherAllowed Whether one launcher remains in scope.
|
|
221
|
+
* @param {boolean} initialUncertain Whether the parent context is unresolved.
|
|
222
|
+
* @returns {object[]} Active gh calls and their isolated command contexts.
|
|
223
|
+
*/
|
|
224
|
+
function commandContexts(
|
|
225
|
+
command,
|
|
226
|
+
initialCwd,
|
|
227
|
+
env,
|
|
228
|
+
launcherAllowed,
|
|
229
|
+
initialUncertain
|
|
230
|
+
) {
|
|
207
231
|
const calls = [];
|
|
208
232
|
const inherited = { ...env };
|
|
209
233
|
let cwd = initialCwd,
|
|
210
234
|
segment = [],
|
|
211
|
-
uncertain =
|
|
235
|
+
uncertain = initialUncertain;
|
|
212
236
|
const consume = () => {
|
|
213
237
|
if (segment.length === 0) return;
|
|
214
238
|
const local = { ...inherited };
|
|
@@ -263,6 +287,25 @@ export function ghCommands(command, initialCwd, env = process.env) {
|
|
|
263
287
|
env: local,
|
|
264
288
|
certainContext: !uncertain,
|
|
265
289
|
});
|
|
290
|
+
} else if (
|
|
291
|
+
launcherAllowed &&
|
|
292
|
+
segment[index]?.literal &&
|
|
293
|
+
["sh", "bash"].includes(path.basename(executable ?? "")) &&
|
|
294
|
+
segment[index + 1]?.literal &&
|
|
295
|
+
segment[index + 1].value === "-c" &&
|
|
296
|
+
segment[index + 2]?.literal
|
|
297
|
+
) {
|
|
298
|
+
// Only this operand is executable text. Later argv words are $0/$1/etc,
|
|
299
|
+
// not scripts. Child cd/export changes cannot mutate the outer shell.
|
|
300
|
+
calls.push(
|
|
301
|
+
...commandContexts(
|
|
302
|
+
segment[index + 2].value,
|
|
303
|
+
cwd,
|
|
304
|
+
local,
|
|
305
|
+
false,
|
|
306
|
+
uncertain
|
|
307
|
+
)
|
|
308
|
+
);
|
|
266
309
|
} else {
|
|
267
310
|
// A function/source/pushd or unsupported launcher may change the shell
|
|
268
311
|
// context. Do not grant later writes an exemption based on the old cwd.
|
|
@@ -23,6 +23,9 @@ const canonicalHookDir = path.join(repoRoot, "plugins", "src", "base", "hooks");
|
|
|
23
23
|
// that list is what the installer copies into a host, this one is what makes
|
|
24
24
|
// the files reachable from `dist/` for a packaged install.
|
|
25
25
|
const canonicalSupportFiles = [
|
|
26
|
+
"block-host-name-leak.sh",
|
|
27
|
+
"block-host-name-leak.mjs",
|
|
28
|
+
"host-name-command-context.mjs",
|
|
26
29
|
"discharge-work-item-gates.sh",
|
|
27
30
|
"block-managed-file-edits.sh",
|
|
28
31
|
"block-no-verify.sh",
|
|
@@ -38,8 +38,11 @@ import fs from "node:fs";
|
|
|
38
38
|
import path from "node:path";
|
|
39
39
|
import { fileURLToPath } from "node:url";
|
|
40
40
|
|
|
41
|
+
import { emitCodexSharedScripts } from "./lib/codex-shared-scripts.mjs";
|
|
41
42
|
import { invokedAsScript } from "./lib/invoked-as-script.mjs";
|
|
42
43
|
|
|
44
|
+
export { emitCodexSharedScripts };
|
|
45
|
+
|
|
43
46
|
// Literals named once — each was repeated enough times that a typo in one
|
|
44
47
|
// copy would diverge silently.
|
|
45
48
|
const CODEX_PLUGIN_DIR = ".codex-plugin";
|
|
@@ -787,6 +790,9 @@ function main() {
|
|
|
787
790
|
emitCodexHooks(pluginDir, claudeManifest);
|
|
788
791
|
emitCodexSkillVariants(pluginDir);
|
|
789
792
|
emitCommandSkills(pluginDir);
|
|
793
|
+
// After every skill is in `.codex-plugin/skills/`: their `../../../scripts/`
|
|
794
|
+
// imports land on `.codex-plugin/scripts/`, which only this step writes.
|
|
795
|
+
emitCodexSharedScripts(pluginDir);
|
|
790
796
|
writeCodexManifest(pluginDir, claudeManifest, pluginName, versionArg);
|
|
791
797
|
writeSkillAgents(pluginDir);
|
|
792
798
|
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit the shared plugin scripts that Codex skill scripts import
|
|
3
|
+
* (CodySwannGT/lisa#4730).
|
|
4
|
+
*
|
|
5
|
+
* Codex loads a plugin's skills from `.codex-plugin/skills/`, a copy of the
|
|
6
|
+
* plugin's authored `skills/`. Skill scripts reach shared modules with
|
|
7
|
+
* `../../../scripts/<m>.mjs`, which from the authored tree lands on the
|
|
8
|
+
* plugin's own `scripts/` but from the Codex copy lands on
|
|
9
|
+
* `.codex-plugin/scripts/`. This module follows every relative import of every
|
|
10
|
+
* emitted skill module, transitively, and copies each target that falls
|
|
11
|
+
* outside `.codex-plugin/skills/` from `<plugin>/<rel>` to
|
|
12
|
+
* `<plugin>/.codex-plugin/<rel>` — the place the unchanged specifier resolves.
|
|
13
|
+
* Specifiers are never rewritten, so the Claude tree and the Codex tree run
|
|
14
|
+
* byte-identical skill scripts.
|
|
15
|
+
*
|
|
16
|
+
* The specifier parse mirrors `src/opencode/relative-imports.ts` (a `.mjs`
|
|
17
|
+
* build script cannot import TypeScript); the guard test uses that TypeScript
|
|
18
|
+
* checker as an independent oracle over what this module emits.
|
|
19
|
+
* @module scripts/lib/codex-shared-scripts
|
|
20
|
+
*/
|
|
21
|
+
import fs from "node:fs";
|
|
22
|
+
import path from "node:path";
|
|
23
|
+
|
|
24
|
+
const CODEX_PLUGIN_DIR = ".codex-plugin";
|
|
25
|
+
const SCRIPT_MODULE_EXTENSIONS = new Set([".mjs", ".js", ".cjs"]);
|
|
26
|
+
const RELATIVE_SPECIFIER_PATTERN =
|
|
27
|
+
/\b(?:from|import\(?|require\()\s*(["'])(\.\.?\/[^"'\n]*)\1/g;
|
|
28
|
+
const LINE_OPENING_BLOCK_COMMENT = /^[ \t]*\/\*[\s\S]*?\*\//gm;
|
|
29
|
+
const LINE_OPENING_LINE_COMMENT = /^[ \t]*\/\/.*$/gm;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extract every static relative specifier from module source text. Exported
|
|
33
|
+
* so a parity test can hold it equal to the TypeScript checker's parse.
|
|
34
|
+
* @param {string} source JavaScript module source.
|
|
35
|
+
* @returns {string[]} Unique relative specifiers in first-seen order.
|
|
36
|
+
*/
|
|
37
|
+
export function extractRelativeSpecifiers(source) {
|
|
38
|
+
const stripped = source
|
|
39
|
+
.replace(LINE_OPENING_BLOCK_COMMENT, "")
|
|
40
|
+
.replace(LINE_OPENING_LINE_COMMENT, "");
|
|
41
|
+
const specifiers = Array.from(
|
|
42
|
+
stripped.matchAll(RELATIVE_SPECIFIER_PATTERN),
|
|
43
|
+
match => match[2]
|
|
44
|
+
);
|
|
45
|
+
return [...new Set(specifiers)];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Predicate: is `candidate` the directory `root` or somewhere beneath it?
|
|
50
|
+
* @param {string} root Absolute directory.
|
|
51
|
+
* @param {string} candidate Absolute path.
|
|
52
|
+
* @returns {boolean} True when `candidate` does not escape `root`.
|
|
53
|
+
*/
|
|
54
|
+
function isWithin(root, candidate) {
|
|
55
|
+
const rel = path.relative(root, candidate);
|
|
56
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* List every script module beneath a directory, sorted for determinism.
|
|
61
|
+
* @param {string} dir Absolute directory.
|
|
62
|
+
* @returns {string[]} Absolute module paths.
|
|
63
|
+
*/
|
|
64
|
+
function listScriptModules(dir) {
|
|
65
|
+
if (!fs.existsSync(dir)) return [];
|
|
66
|
+
return fs
|
|
67
|
+
.readdirSync(dir, { recursive: true, withFileTypes: true })
|
|
68
|
+
.filter(
|
|
69
|
+
entry =>
|
|
70
|
+
entry.isFile() && SCRIPT_MODULE_EXTENSIONS.has(path.extname(entry.name))
|
|
71
|
+
)
|
|
72
|
+
.map(entry => path.join(entry.parentPath, entry.name))
|
|
73
|
+
.sort();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Resolve the shared targets one emitted module imports. A target outside
|
|
78
|
+
* `.codex-plugin/skills/` must lie inside `.codex-plugin/scripts/`: that is
|
|
79
|
+
* the only directory this step clears, so it is the only one it may write —
|
|
80
|
+
* it can never overwrite `hooks.json`, `plugin.json`, or anything else.
|
|
81
|
+
* @param {string} codexDir Absolute `.codex-plugin/` directory.
|
|
82
|
+
* @param {string} importer Absolute emitted module path.
|
|
83
|
+
* @returns {{ specifier: string, target: string }[]} Imports whose absolute
|
|
84
|
+
* target lies inside `.codex-plugin/scripts/`.
|
|
85
|
+
*/
|
|
86
|
+
function sharedTargetsOf(codexDir, importer) {
|
|
87
|
+
const skillsDir = path.join(codexDir, "skills");
|
|
88
|
+
const scriptsDir = path.join(codexDir, "scripts");
|
|
89
|
+
return extractRelativeSpecifiers(fs.readFileSync(importer, "utf8"))
|
|
90
|
+
.map(specifier => ({
|
|
91
|
+
specifier,
|
|
92
|
+
target: path.resolve(path.dirname(importer), specifier),
|
|
93
|
+
}))
|
|
94
|
+
.filter(({ specifier, target }) => {
|
|
95
|
+
if (isWithin(skillsDir, target)) return false;
|
|
96
|
+
if (!isWithin(scriptsDir, target)) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`${path.relative(codexDir, importer)} imports "${specifier}", which resolves outside ${CODEX_PLUGIN_DIR}/scripts/ and cannot be emitted`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Copy one shared module from the plugin root into `.codex-plugin/`.
|
|
107
|
+
* @param {string} pluginDir Built plugin directory.
|
|
108
|
+
* @param {string} codexDir Absolute `.codex-plugin/` directory.
|
|
109
|
+
* @param {string} importer Absolute module that imports `target`.
|
|
110
|
+
* @param {{ specifier: string, target: string }} edge The import being emitted.
|
|
111
|
+
*/
|
|
112
|
+
function copySharedModule(
|
|
113
|
+
pluginDir,
|
|
114
|
+
codexDir,
|
|
115
|
+
importer,
|
|
116
|
+
{ specifier, target }
|
|
117
|
+
) {
|
|
118
|
+
const rel = path.relative(codexDir, target);
|
|
119
|
+
const source = path.join(pluginDir, rel);
|
|
120
|
+
if (!fs.existsSync(source)) {
|
|
121
|
+
throw new Error(
|
|
122
|
+
`${path.relative(codexDir, importer)} imports "${specifier}", but its source ${rel} does not exist in the plugin`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
126
|
+
fs.copyFileSync(source, target);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Emit every shared module the plugin's Codex skill scripts import,
|
|
131
|
+
* transitively, into `<plugin>/.codex-plugin/`. Must run after the skill
|
|
132
|
+
* variants are emitted. Stale emitted shared modules are removed first.
|
|
133
|
+
* @param {string} pluginDir Built plugin directory.
|
|
134
|
+
* @returns {string[]} Emitted paths relative to `.codex-plugin/`, sorted.
|
|
135
|
+
*/
|
|
136
|
+
export function emitCodexSharedScripts(pluginDir) {
|
|
137
|
+
const codexDir = path.join(pluginDir, CODEX_PLUGIN_DIR);
|
|
138
|
+
fs.rmSync(path.join(codexDir, "scripts"), { force: true, recursive: true });
|
|
139
|
+
const emitted = new Set();
|
|
140
|
+
const pending = listScriptModules(path.join(codexDir, "skills"));
|
|
141
|
+
while (pending.length > 0) {
|
|
142
|
+
const importer = pending.shift();
|
|
143
|
+
for (const edge of sharedTargetsOf(codexDir, importer)) {
|
|
144
|
+
const { target } = edge;
|
|
145
|
+
if (emitted.has(target)) continue;
|
|
146
|
+
copySharedModule(pluginDir, codexDir, importer, edge);
|
|
147
|
+
emitted.add(target);
|
|
148
|
+
if (SCRIPT_MODULE_EXTENSIONS.has(path.extname(target))) {
|
|
149
|
+
pending.push(target);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return [...emitted]
|
|
154
|
+
.map(target => path.relative(codexDir, target).split(path.sep).join("/"))
|
|
155
|
+
.sort();
|
|
156
|
+
}
|