harnessed 4.43.0 → 4.44.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/README-en.md +618 -0
- package/README.md +273 -275
- package/bin/harnessed-inject-state.mjs +113 -33
- package/bin/harnessed-stop-hook.mjs +67 -22
- package/dist/cli.mjs +1428 -589
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/manifests/SCHEMA.md +1 -1
- package/manifests/optional/perturn-inject-invalidate.yaml +1 -1
- package/package.json +3 -1
package/dist/cli.mjs
CHANGED
|
@@ -13,10 +13,10 @@ import { execFileSync, spawnSync, spawn, execFile, exec } from 'child_process';
|
|
|
13
13
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
14
14
|
import { createHash, verify, createPublicKey } from 'crypto';
|
|
15
15
|
import { promisify } from 'util';
|
|
16
|
-
import { Parser } from 'expr-eval';
|
|
17
16
|
import * as p from '@clack/prompts';
|
|
18
17
|
import { createPatch } from 'diff';
|
|
19
18
|
import pc from 'picocolors';
|
|
19
|
+
import { Parser } from 'expr-eval';
|
|
20
20
|
import { Command, InvalidArgumentError } from 'commander';
|
|
21
21
|
import { stdout, stdin } from 'process';
|
|
22
22
|
import * as readline from 'readline/promises';
|
|
@@ -38,7 +38,7 @@ var init_package = __esm({
|
|
|
38
38
|
"package.json"() {
|
|
39
39
|
package_default = {
|
|
40
40
|
name: "harnessed",
|
|
41
|
-
version: "4.
|
|
41
|
+
version: "4.44.0",
|
|
42
42
|
description: "AI coding harness package manager + composition orchestrator",
|
|
43
43
|
type: "module",
|
|
44
44
|
license: "Apache-2.0",
|
|
@@ -90,6 +90,7 @@ var init_package = __esm({
|
|
|
90
90
|
"config-templates",
|
|
91
91
|
"schemas",
|
|
92
92
|
"README.md",
|
|
93
|
+
"README-en.md",
|
|
93
94
|
"LICENSE",
|
|
94
95
|
"NOTICE",
|
|
95
96
|
"THIRD-PARTY-NOTICES.md"
|
|
@@ -104,6 +105,7 @@ var init_package = __esm({
|
|
|
104
105
|
test: "vitest run --passWithNoTests",
|
|
105
106
|
"test:watch": "vitest",
|
|
106
107
|
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
108
|
+
"test:codex-live": "node ./scripts/codex-live/run.mjs",
|
|
107
109
|
bench: "vitest bench --run",
|
|
108
110
|
lint: "biome check .",
|
|
109
111
|
"lint:fix": "biome check --write .",
|
|
@@ -182,15 +184,15 @@ function codexDescriptor(home = homedir()) {
|
|
|
182
184
|
id: "codex",
|
|
183
185
|
homeDir: codexHome,
|
|
184
186
|
stateRoot: join(codexHome, "harnessed"),
|
|
185
|
-
settingsPath:
|
|
187
|
+
settingsPath: null,
|
|
186
188
|
// SHARED convention dir, NOT <homeDir>/skills.
|
|
187
189
|
skillsDir: join(home, ".agents", "skills"),
|
|
188
190
|
commandsDir: join(codexHome, "prompts"),
|
|
189
191
|
pluginsRegistry: null,
|
|
190
192
|
mcpConfigPath: configToml,
|
|
191
193
|
supportsEnvKeyWrite: false,
|
|
192
|
-
//
|
|
193
|
-
sessionIdEnv:
|
|
194
|
+
// Measured on codex-cli 0.154: codex shells carry it, equal to hook session_id.
|
|
195
|
+
sessionIdEnv: "CODEX_SESSION_ID"
|
|
194
196
|
};
|
|
195
197
|
}
|
|
196
198
|
function descriptorById(id, home) {
|
|
@@ -199,19 +201,27 @@ function descriptorById(id, home) {
|
|
|
199
201
|
return void 0;
|
|
200
202
|
}
|
|
201
203
|
function detectPlatform(home = homedir()) {
|
|
202
|
-
const
|
|
204
|
+
const resolved = resolveHost(home);
|
|
203
205
|
const override = process.env.HARNESSED_ROOT_OVERRIDE;
|
|
204
|
-
if (override !== void 0 && override !== "") return { ...
|
|
206
|
+
if (override !== void 0 && override !== "") return { ...resolved, stateRoot: override };
|
|
207
|
+
return resolved;
|
|
208
|
+
}
|
|
209
|
+
function resolveHost(home) {
|
|
210
|
+
const base = claudeDescriptor(home);
|
|
205
211
|
const envPlatform = process.env.HARNESSED_PLATFORM;
|
|
206
212
|
if (envPlatform !== void 0 && envPlatform !== "") {
|
|
207
213
|
const d = descriptorById(envPlatform, home);
|
|
208
214
|
if (d) return d;
|
|
209
215
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
216
|
+
const inClaude = Boolean(process.env.CLAUDE_CODE_SESSION_ID?.trim());
|
|
217
|
+
const inCodex = Boolean(process.env.CODEX_SESSION_ID?.trim());
|
|
218
|
+
if (inClaude !== inCodex) return inClaude ? base : codexDescriptor(home);
|
|
219
|
+
for (const pinRoot of [codexDescriptor(home).stateRoot, base.stateRoot]) {
|
|
220
|
+
try {
|
|
221
|
+
const d = descriptorById(readFileSync(join(pinRoot, ".platform"), "utf8").trim(), home);
|
|
222
|
+
if (d) return d;
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
215
225
|
}
|
|
216
226
|
try {
|
|
217
227
|
if (existsSync(base.homeDir)) return base;
|
|
@@ -634,9 +644,9 @@ async function writeStoreRaw(store) {
|
|
|
634
644
|
const errs = [...Value.Errors(WorkflowStoreV1, store)].map((e) => e.message).join("; ");
|
|
635
645
|
throw new Error(`workflow-store schema validation failed: ${errs}`);
|
|
636
646
|
}
|
|
637
|
-
const
|
|
638
|
-
await mkdir(dirname(
|
|
639
|
-
await writeFileAtomic(
|
|
647
|
+
const p8 = storePath();
|
|
648
|
+
await mkdir(dirname(p8), { recursive: true });
|
|
649
|
+
await writeFileAtomic(p8, JSON.stringify(store, null, 2));
|
|
640
650
|
}
|
|
641
651
|
async function readIntent(cwd = process.cwd()) {
|
|
642
652
|
const store = await readStoreRaw();
|
|
@@ -879,9 +889,9 @@ function scanPhases(repoRoot, includeTasks) {
|
|
|
879
889
|
function scanTasks(dirPath) {
|
|
880
890
|
for (const fname of ["task_plan.md", "progress.md"]) {
|
|
881
891
|
try {
|
|
882
|
-
const
|
|
883
|
-
if (!existsSync(
|
|
884
|
-
const m = /^[ \t]*- \[ \]\s+(.+)$/m.exec(readFileSync(
|
|
892
|
+
const p8 = join(dirPath, fname);
|
|
893
|
+
if (!existsSync(p8)) continue;
|
|
894
|
+
const m = /^[ \t]*- \[ \]\s+(.+)$/m.exec(readFileSync(p8, "utf8"));
|
|
885
895
|
const task = m?.[1];
|
|
886
896
|
if (task) return { nextUnchecked: task.trim() };
|
|
887
897
|
} catch {
|
|
@@ -1007,7 +1017,7 @@ function deriveNext(snapshot) {
|
|
|
1007
1017
|
reason: `sub '${failed.sub}' failed ${failed.fail_count}x \u2014 resolve before advancing`
|
|
1008
1018
|
};
|
|
1009
1019
|
}
|
|
1010
|
-
const firstIncomplete = snapshot.phases.find((
|
|
1020
|
+
const firstIncomplete = snapshot.phases.find((p8) => !p8.complete);
|
|
1011
1021
|
if (firstIncomplete) {
|
|
1012
1022
|
const task = firstIncomplete.tasks?.nextUnchecked;
|
|
1013
1023
|
if (task) return { kind: "task", phase: firstIncomplete.phase, task };
|
|
@@ -1043,7 +1053,7 @@ function describeUnit(unit) {
|
|
|
1043
1053
|
}
|
|
1044
1054
|
}
|
|
1045
1055
|
function remainingPhases(snapshot) {
|
|
1046
|
-
return snapshot.phases.filter((
|
|
1056
|
+
return snapshot.phases.filter((p8) => !p8.complete).length;
|
|
1047
1057
|
}
|
|
1048
1058
|
function pluralPhases(n) {
|
|
1049
1059
|
return `${n} phase${n === 1 ? "" : "s"} remain`;
|
|
@@ -1718,8 +1728,8 @@ function checkSecurityViolations(doc, filename, lineCounter) {
|
|
|
1718
1728
|
["spec", "harness_overrides", "codex", "install", "cmd"],
|
|
1719
1729
|
["spec", "harness_overrides", "codex", "verify", "cmd"]
|
|
1720
1730
|
];
|
|
1721
|
-
for (const
|
|
1722
|
-
const err2 = checkScalarCmd(doc, lineCounter,
|
|
1731
|
+
for (const p8 of cmdPaths) {
|
|
1732
|
+
const err2 = checkScalarCmd(doc, lineCounter, p8, filename);
|
|
1723
1733
|
if (err2) errors.push(err2);
|
|
1724
1734
|
}
|
|
1725
1735
|
const cleanupNode = doc.getIn(["spec", "uninstall", "cleanup_paths"], true);
|
|
@@ -2421,6 +2431,217 @@ var init_engineHook = __esm({
|
|
|
2421
2431
|
init_template();
|
|
2422
2432
|
}
|
|
2423
2433
|
});
|
|
2434
|
+
function descendantsOf(pid) {
|
|
2435
|
+
const r = spawnSync("pgrep", ["-P", String(pid)], { encoding: "utf8", timeout: 2e3 });
|
|
2436
|
+
if (r.status !== 0 || typeof r.stdout !== "string") return [];
|
|
2437
|
+
const out = [];
|
|
2438
|
+
for (const tok2 of r.stdout.split(/\s+/)) {
|
|
2439
|
+
const child = Number(tok2);
|
|
2440
|
+
if (Number.isInteger(child) && child > 0) out.push(child, ...descendantsOf(child));
|
|
2441
|
+
}
|
|
2442
|
+
return out;
|
|
2443
|
+
}
|
|
2444
|
+
function killProcessTree(child) {
|
|
2445
|
+
const pid = child.pid;
|
|
2446
|
+
if (pid === void 0) {
|
|
2447
|
+
child.kill("SIGKILL");
|
|
2448
|
+
return;
|
|
2449
|
+
}
|
|
2450
|
+
if (process.platform === "win32") {
|
|
2451
|
+
const r = spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
2452
|
+
windowsHide: true,
|
|
2453
|
+
stdio: "ignore",
|
|
2454
|
+
timeout: 5e3
|
|
2455
|
+
});
|
|
2456
|
+
if (r.status === 0) return;
|
|
2457
|
+
child.kill("SIGKILL");
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2460
|
+
const tree = descendantsOf(pid);
|
|
2461
|
+
child.kill("SIGKILL");
|
|
2462
|
+
for (const d of tree) {
|
|
2463
|
+
try {
|
|
2464
|
+
process.kill(d, "SIGKILL");
|
|
2465
|
+
} catch {
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
var init_killTree = __esm({
|
|
2470
|
+
"src/installers/lib/killTree.ts"() {
|
|
2471
|
+
}
|
|
2472
|
+
});
|
|
2473
|
+
function escapeCommand(cmd) {
|
|
2474
|
+
return cmd.replace(META, "^$1");
|
|
2475
|
+
}
|
|
2476
|
+
function escapeArgument(arg, doubleEscape) {
|
|
2477
|
+
let a = `${arg}`;
|
|
2478
|
+
a = a.replace(/(\\*)"/g, '$1$1\\"');
|
|
2479
|
+
a = a.replace(/(\\*)$/, "$1$1");
|
|
2480
|
+
a = `"${a}"`;
|
|
2481
|
+
a = a.replace(META, "^$1");
|
|
2482
|
+
a = a.replace(META, "^$1");
|
|
2483
|
+
return a;
|
|
2484
|
+
}
|
|
2485
|
+
function resolveWindowsBin(bin, env = process.env, isFile = (p8) => existsSync(p8) && statSync(p8).isFile()) {
|
|
2486
|
+
const dirs = (env.PATH ?? env.Path ?? "").split(";").filter(Boolean);
|
|
2487
|
+
const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
2488
|
+
const candidates = extname(bin) ? [""] : exts;
|
|
2489
|
+
for (const dir of dirs) {
|
|
2490
|
+
for (const ext of candidates) {
|
|
2491
|
+
const p8 = join13(dir, `${bin}${ext}`);
|
|
2492
|
+
if (isFile(p8)) return p8;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
return null;
|
|
2496
|
+
}
|
|
2497
|
+
function planWindowsSpawn(bin, args, resolved) {
|
|
2498
|
+
if (!resolved) return { command: bin, args, verbatim: false };
|
|
2499
|
+
const ext = extname(resolved).toLowerCase();
|
|
2500
|
+
if (ext !== ".cmd" && ext !== ".bat") {
|
|
2501
|
+
return { command: resolved, args, verbatim: false };
|
|
2502
|
+
}
|
|
2503
|
+
const line = [escapeCommand(resolved), ...args.map((a) => escapeArgument(a))].join(" ");
|
|
2504
|
+
return { command: "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], verbatim: true };
|
|
2505
|
+
}
|
|
2506
|
+
var extname, join13, META;
|
|
2507
|
+
var init_winSpawn = __esm({
|
|
2508
|
+
"src/installers/lib/winSpawn.ts"() {
|
|
2509
|
+
({ extname, join: join13 } = win32);
|
|
2510
|
+
META = /([()\][%!^"`<>&|;, *?])/g;
|
|
2511
|
+
}
|
|
2512
|
+
});
|
|
2513
|
+
function runHarnessArgs(bin, args, cwd, timeoutMs = 15e3) {
|
|
2514
|
+
return new Promise((resolve23) => {
|
|
2515
|
+
const isWin = process.platform === "win32";
|
|
2516
|
+
const stdio = ["ignore", "pipe", "pipe"];
|
|
2517
|
+
let child;
|
|
2518
|
+
if (isWin) {
|
|
2519
|
+
const plan = planWindowsSpawn(bin, args, resolveWindowsBin(bin));
|
|
2520
|
+
child = spawn(plan.command, plan.args, {
|
|
2521
|
+
cwd,
|
|
2522
|
+
windowsHide: true,
|
|
2523
|
+
stdio,
|
|
2524
|
+
shell: false,
|
|
2525
|
+
windowsVerbatimArguments: plan.verbatim
|
|
2526
|
+
});
|
|
2527
|
+
} else {
|
|
2528
|
+
child = spawn(bin, args, { cwd, shell: false, stdio });
|
|
2529
|
+
}
|
|
2530
|
+
let stdout2 = "";
|
|
2531
|
+
let stderr = "";
|
|
2532
|
+
child.stdout?.setEncoding("utf8").on("data", (c) => {
|
|
2533
|
+
stdout2 += c;
|
|
2534
|
+
});
|
|
2535
|
+
child.stderr?.setEncoding("utf8").on("data", (c) => {
|
|
2536
|
+
stderr += c;
|
|
2537
|
+
});
|
|
2538
|
+
const timer = setTimeout(() => {
|
|
2539
|
+
killProcessTree(child);
|
|
2540
|
+
resolve23({ exitCode: -1, stdout: stdout2, stderr: `${stderr}[timeout after ${timeoutMs}ms]` });
|
|
2541
|
+
}, timeoutMs);
|
|
2542
|
+
child.on("error", (e) => {
|
|
2543
|
+
clearTimeout(timer);
|
|
2544
|
+
const enoent = e.code === "ENOENT";
|
|
2545
|
+
const msg = enoent && bin === "codex" ? "codex CLI not found on PATH \u2014 install Codex CLI or re-run setup on the claude platform" : e.message;
|
|
2546
|
+
resolve23({ exitCode: -1, stdout: stdout2, stderr: `${stderr}${msg}` });
|
|
2547
|
+
});
|
|
2548
|
+
child.on("close", (code) => {
|
|
2549
|
+
clearTimeout(timer);
|
|
2550
|
+
resolve23({ exitCode: code ?? -1, stdout: stdout2, stderr });
|
|
2551
|
+
});
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
function runArgs(claudeArgs, cwd, timeoutMs = 15e3) {
|
|
2555
|
+
return runHarnessArgs("claude", claudeArgs, cwd, timeoutMs);
|
|
2556
|
+
}
|
|
2557
|
+
var init_runClaudeArgs = __esm({
|
|
2558
|
+
"src/installers/lib/runClaudeArgs.ts"() {
|
|
2559
|
+
init_killTree();
|
|
2560
|
+
init_winSpawn();
|
|
2561
|
+
}
|
|
2562
|
+
});
|
|
2563
|
+
function getMcpSpawnCwd() {
|
|
2564
|
+
return homedir();
|
|
2565
|
+
}
|
|
2566
|
+
function getNeutralSpawnCwd() {
|
|
2567
|
+
const override = process.env.HARNESSED_SPAWN_CWD;
|
|
2568
|
+
if (override !== void 0 && override.trim().length > 0) return override.trim();
|
|
2569
|
+
try {
|
|
2570
|
+
const dir = join(detectPlatform().stateRoot, ".spawn");
|
|
2571
|
+
mkdirSync(dir, { recursive: true });
|
|
2572
|
+
const sentinel = join(dir, "package.json");
|
|
2573
|
+
if (!existsSync(sentinel)) writeFileSync(sentinel, NEUTRAL_SENTINEL, "utf8");
|
|
2574
|
+
return dir;
|
|
2575
|
+
} catch {
|
|
2576
|
+
return null;
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
var NEUTRAL_SENTINEL;
|
|
2580
|
+
var init_safeCwd = __esm({
|
|
2581
|
+
"src/installers/lib/safeCwd.ts"() {
|
|
2582
|
+
init_platform();
|
|
2583
|
+
NEUTRAL_SENTINEL = '{\n "name": "harnessed-neutral-spawn",\n "private": true\n}\n';
|
|
2584
|
+
}
|
|
2585
|
+
});
|
|
2586
|
+
|
|
2587
|
+
// src/installers/lib/codexPlugins.ts
|
|
2588
|
+
function parseCodexPluginList(stdout2) {
|
|
2589
|
+
const text = stdout2.trim();
|
|
2590
|
+
if (text.startsWith("{")) {
|
|
2591
|
+
try {
|
|
2592
|
+
const parsed = JSON.parse(text);
|
|
2593
|
+
if (!Array.isArray(parsed.installed)) return null;
|
|
2594
|
+
const ids2 = /* @__PURE__ */ new Set();
|
|
2595
|
+
for (const p8 of parsed.installed) {
|
|
2596
|
+
if (p8?.installed === true && typeof p8.pluginId === "string") ids2.add(p8.pluginId);
|
|
2597
|
+
}
|
|
2598
|
+
return ids2;
|
|
2599
|
+
} catch {
|
|
2600
|
+
return null;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
if (!/^PLUGIN\s+STATUS\b/m.test(text)) return null;
|
|
2604
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2605
|
+
for (const m of text.matchAll(/^(\S+@\S+)\s+installed\b/gm)) if (m[1]) ids.add(m[1]);
|
|
2606
|
+
return ids;
|
|
2607
|
+
}
|
|
2608
|
+
function invalidateCodexPluginCache() {
|
|
2609
|
+
cache2 = null;
|
|
2610
|
+
}
|
|
2611
|
+
async function listOnce() {
|
|
2612
|
+
const cwd = getMcpSpawnCwd();
|
|
2613
|
+
const json2 = await runHarnessArgs("codex", ["plugin", "list", "--json"], cwd, 3e4);
|
|
2614
|
+
const fromJson = json2.exitCode === 0 ? parseCodexPluginList(json2.stdout) : null;
|
|
2615
|
+
if (fromJson) return fromJson;
|
|
2616
|
+
if (json2.exitCode === -1) return null;
|
|
2617
|
+
const table = await runHarnessArgs("codex", ["plugin", "list"], cwd, 3e4);
|
|
2618
|
+
return table.exitCode === 0 ? parseCodexPluginList(table.stdout) : null;
|
|
2619
|
+
}
|
|
2620
|
+
function listInstalledCodexPlugins() {
|
|
2621
|
+
cache2 = cache2 ?? listOnce();
|
|
2622
|
+
return cache2;
|
|
2623
|
+
}
|
|
2624
|
+
async function isCodexPluginInstalled(name) {
|
|
2625
|
+
const ids = await listInstalledCodexPlugins();
|
|
2626
|
+
if (!ids) return false;
|
|
2627
|
+
if (name.includes("@")) return ids.has(name);
|
|
2628
|
+
for (const id of ids) if (id.split("@")[0] === name) return true;
|
|
2629
|
+
return false;
|
|
2630
|
+
}
|
|
2631
|
+
function withCodexPluginLock(fn) {
|
|
2632
|
+
const run = lock.then(fn, fn);
|
|
2633
|
+
lock = run.catch(() => void 0);
|
|
2634
|
+
return run;
|
|
2635
|
+
}
|
|
2636
|
+
var cache2, lock;
|
|
2637
|
+
var init_codexPlugins = __esm({
|
|
2638
|
+
"src/installers/lib/codexPlugins.ts"() {
|
|
2639
|
+
init_runClaudeArgs();
|
|
2640
|
+
init_safeCwd();
|
|
2641
|
+
cache2 = null;
|
|
2642
|
+
lock = Promise.resolve();
|
|
2643
|
+
}
|
|
2644
|
+
});
|
|
2424
2645
|
function getUserClaudeJsonPath() {
|
|
2425
2646
|
return getMcpConfigPath();
|
|
2426
2647
|
}
|
|
@@ -2463,22 +2684,9 @@ async function isMcpServerRegistered(name) {
|
|
|
2463
2684
|
if (!servers || typeof servers !== "object") return false;
|
|
2464
2685
|
return Object.hasOwn(servers, name);
|
|
2465
2686
|
}
|
|
2466
|
-
function isPluginInToml(raw, pluginName) {
|
|
2467
|
-
const esc = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2468
|
-
const [plugin = "", market] = pluginName.split("@");
|
|
2469
|
-
const key = market ? `${esc(plugin)}@${esc(market)}` : `${esc(plugin)}(?:@[^"'\\]]+)?`;
|
|
2470
|
-
const re = new RegExp(`^\\s*\\[plugins\\.(?:"${key}"|'${key}')\\]`, "m");
|
|
2471
|
-
return re.test(raw);
|
|
2472
|
-
}
|
|
2473
2687
|
async function isPluginRegistered(pluginName) {
|
|
2474
2688
|
const platform = detectPlatform();
|
|
2475
|
-
if (platform.id === "codex")
|
|
2476
|
-
try {
|
|
2477
|
-
return isPluginInToml(await readFile(platform.mcpConfigPath, "utf8"), pluginName);
|
|
2478
|
-
} catch {
|
|
2479
|
-
return false;
|
|
2480
|
-
}
|
|
2481
|
-
}
|
|
2689
|
+
if (platform.id === "codex") return isCodexPluginInstalled(pluginName);
|
|
2482
2690
|
const registryPath = getPluginsRegistry();
|
|
2483
2691
|
if (registryPath !== null) {
|
|
2484
2692
|
try {
|
|
@@ -2493,6 +2701,7 @@ async function isPluginRegistered(pluginName) {
|
|
|
2493
2701
|
}
|
|
2494
2702
|
}
|
|
2495
2703
|
for (const path of [getSettingsPath(), getMcpConfigPath()]) {
|
|
2704
|
+
if (path === null) continue;
|
|
2496
2705
|
try {
|
|
2497
2706
|
const raw = await readFile(path, "utf8");
|
|
2498
2707
|
const parsed = JSON.parse(raw);
|
|
@@ -2509,10 +2718,13 @@ async function isPluginRegistered(pluginName) {
|
|
|
2509
2718
|
var init_readClaudeConfig = __esm({
|
|
2510
2719
|
"src/installers/lib/readClaudeConfig.ts"() {
|
|
2511
2720
|
init_platform();
|
|
2721
|
+
init_codexPlugins();
|
|
2512
2722
|
}
|
|
2513
2723
|
});
|
|
2514
2724
|
async function mergeSettingsEnvKey(key, value, opts = {}) {
|
|
2515
2725
|
const path = getSettingsPath();
|
|
2726
|
+
if (path === null)
|
|
2727
|
+
return { outcome: "warn", message: `no settings file on ${detectPlatform().id} \u2014 skipped` };
|
|
2516
2728
|
let raw;
|
|
2517
2729
|
try {
|
|
2518
2730
|
raw = await readFile(path, "utf8");
|
|
@@ -2607,7 +2819,7 @@ __export(guard_exemption_exports, {
|
|
|
2607
2819
|
function defaultProbeDeps() {
|
|
2608
2820
|
return {
|
|
2609
2821
|
registryPath: () => getPluginsRegistry(),
|
|
2610
|
-
readFile: (
|
|
2822
|
+
readFile: (p8) => readFile(p8, "utf8")
|
|
2611
2823
|
};
|
|
2612
2824
|
}
|
|
2613
2825
|
async function probeExemptCapability(deps = {}) {
|
|
@@ -2644,7 +2856,8 @@ function planEnvExemption(existing) {
|
|
|
2644
2856
|
async function readCurrentEnvValue(deps = {}) {
|
|
2645
2857
|
const readSettings = deps.readSettings ?? (async () => {
|
|
2646
2858
|
try {
|
|
2647
|
-
|
|
2859
|
+
const path = getSettingsPath();
|
|
2860
|
+
return path === null ? null : await readFile(path, "utf8");
|
|
2648
2861
|
} catch {
|
|
2649
2862
|
return null;
|
|
2650
2863
|
}
|
|
@@ -2668,7 +2881,7 @@ function previewLines(existing, newValue) {
|
|
|
2668
2881
|
const change = existing === void 0 ? ` + env.${EXEMPT_ENV_KEY} = "${newValue}"` : ` ~ env.${EXEMPT_ENV_KEY}: "${existing}" \u2192 "${newValue}"`;
|
|
2669
2882
|
return [
|
|
2670
2883
|
`[harnessed] GateGuard \u2194 evidence-guard conflict \u2014 sanctioned fix available:`,
|
|
2671
|
-
` file: ${getSettingsPath()}`,
|
|
2884
|
+
` file: ${getSettingsPath() ?? "(no settings file on this platform)"}`,
|
|
2672
2885
|
change,
|
|
2673
2886
|
` backup: settings.json.<timestamp>.bak under the harnessed backups dir (written first)`
|
|
2674
2887
|
];
|
|
@@ -2764,7 +2977,8 @@ function defaultDeps() {
|
|
|
2764
2977
|
env: process.env,
|
|
2765
2978
|
readSettings: async () => {
|
|
2766
2979
|
try {
|
|
2767
|
-
|
|
2980
|
+
const path = getSettingsPath();
|
|
2981
|
+
return path === null ? null : await readFile(path, "utf8");
|
|
2768
2982
|
} catch {
|
|
2769
2983
|
return null;
|
|
2770
2984
|
}
|
|
@@ -2911,7 +3125,7 @@ async function checkArtifacts(sub, packageRoot) {
|
|
|
2911
3125
|
return { status: missing.length === 0 ? "verified" : "missing", found, missing };
|
|
2912
3126
|
}
|
|
2913
3127
|
async function resolveDeclaredArtifact(cwd, rel) {
|
|
2914
|
-
const isFileAt = (
|
|
3128
|
+
const isFileAt = (p8) => stat(p8).then((s) => s.isFile()).catch(() => false);
|
|
2915
3129
|
if (/[\\/]/.test(rel)) {
|
|
2916
3130
|
const abs = resolve(cwd, rel);
|
|
2917
3131
|
return await isFileAt(abs) ? abs : null;
|
|
@@ -3013,9 +3227,9 @@ function realDeps() {
|
|
|
3013
3227
|
return {
|
|
3014
3228
|
env: process.env,
|
|
3015
3229
|
moduleUrl: import.meta.url,
|
|
3016
|
-
exists: (
|
|
3230
|
+
exists: (p8) => {
|
|
3017
3231
|
try {
|
|
3018
|
-
return existsSync(
|
|
3232
|
+
return existsSync(p8);
|
|
3019
3233
|
} catch {
|
|
3020
3234
|
return false;
|
|
3021
3235
|
}
|
|
@@ -3057,8 +3271,8 @@ __export(tddBoundary_exports, {
|
|
|
3057
3271
|
function isTddEvidencePath(path) {
|
|
3058
3272
|
return path.split(/[\\/]/).pop() === TDD_EVIDENCE_ARTIFACT;
|
|
3059
3273
|
}
|
|
3060
|
-
function isTestPath(
|
|
3061
|
-
const s =
|
|
3274
|
+
function isTestPath(p8) {
|
|
3275
|
+
const s = p8.replace(/\\/g, "/");
|
|
3062
3276
|
return /(^|\/)tests?\//.test(s) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(s) || /(^|\/)test_[^/]+\.py$/.test(s) || /_test\.(py|go|rb)$/.test(s);
|
|
3063
3277
|
}
|
|
3064
3278
|
function substantiveBody(text) {
|
|
@@ -3145,8 +3359,8 @@ function assertionDelta(diff) {
|
|
|
3145
3359
|
let removed = 0;
|
|
3146
3360
|
for (const line of diff.split("\n")) {
|
|
3147
3361
|
if (line.startsWith("+++ ")) {
|
|
3148
|
-
const
|
|
3149
|
-
inTest =
|
|
3362
|
+
const p8 = line.slice(4).trim().replace(/^b\//, "");
|
|
3363
|
+
inTest = p8 !== "/dev/null" && isTestPath(p8);
|
|
3150
3364
|
continue;
|
|
3151
3365
|
}
|
|
3152
3366
|
if (line.startsWith("--- ") || line.startsWith("diff --git") || line.startsWith("@@")) continue;
|
|
@@ -3528,10 +3742,10 @@ function learningsPath(repoRoot) {
|
|
|
3528
3742
|
return join(repoRoot, ".planning", "LEARNINGS.md");
|
|
3529
3743
|
}
|
|
3530
3744
|
async function appendLearning(repoRoot, entry) {
|
|
3531
|
-
const
|
|
3532
|
-
await mkdir(dirname(
|
|
3533
|
-
if (!existsSync(
|
|
3534
|
-
await appendFile(
|
|
3745
|
+
const p8 = learningsPath(repoRoot);
|
|
3746
|
+
await mkdir(dirname(p8), { recursive: true });
|
|
3747
|
+
if (!existsSync(p8)) await writeFile(p8, HEADER, "utf8");
|
|
3748
|
+
await appendFile(p8, entry, "utf8");
|
|
3535
3749
|
}
|
|
3536
3750
|
async function captureWorkflowLearnings(ledger, phase) {
|
|
3537
3751
|
const signals = extractLearnings(ledger);
|
|
@@ -3882,15 +4096,15 @@ async function parsePlan(raw) {
|
|
|
3882
4096
|
} catch {
|
|
3883
4097
|
return null;
|
|
3884
4098
|
}
|
|
3885
|
-
const
|
|
3886
|
-
if (!Array.isArray(
|
|
4099
|
+
const p8 = parsed;
|
|
4100
|
+
if (!Array.isArray(p8.fire) && !Array.isArray(p8.skip)) return null;
|
|
3887
4101
|
const plan = {
|
|
3888
|
-
fire: Array.isArray(
|
|
3889
|
-
skip: Array.isArray(
|
|
4102
|
+
fire: Array.isArray(p8.fire) ? p8.fire : [],
|
|
4103
|
+
skip: Array.isArray(p8.skip) ? p8.skip : []
|
|
3890
4104
|
};
|
|
3891
|
-
if (typeof
|
|
3892
|
-
if (
|
|
3893
|
-
plan.parallelism =
|
|
4105
|
+
if (typeof p8.master === "string") plan.master = p8.master;
|
|
4106
|
+
if (p8.parallelism && typeof p8.parallelism === "object" && !Array.isArray(p8.parallelism)) {
|
|
4107
|
+
plan.parallelism = p8.parallelism;
|
|
3894
4108
|
}
|
|
3895
4109
|
return plan;
|
|
3896
4110
|
}
|
|
@@ -3968,13 +4182,13 @@ async function runCheckpointStart(sub, opts, deps = defaultRunDeps) {
|
|
|
3968
4182
|
print: (line) => deps.error(line),
|
|
3969
4183
|
...isTty ? {
|
|
3970
4184
|
confirm: async () => {
|
|
3971
|
-
const
|
|
3972
|
-
const ans = await
|
|
4185
|
+
const p8 = await import('@clack/prompts');
|
|
4186
|
+
const ans = await p8.confirm({
|
|
3973
4187
|
message: 'Apply the GateGuard exemption now? (persists GATEGUARD_EXEMPT_GLOBS=".planning/**" into settings env \u2014 backed up first)',
|
|
3974
4188
|
initialValue: true
|
|
3975
4189
|
// D1 — default YES
|
|
3976
4190
|
});
|
|
3977
|
-
return !
|
|
4191
|
+
return !p8.isCancel(ans) && ans === true;
|
|
3978
4192
|
}
|
|
3979
4193
|
} : {}
|
|
3980
4194
|
});
|
|
@@ -4342,10 +4556,10 @@ var init_checkpoint = __esm({
|
|
|
4342
4556
|
ACTIONS = ["start", "complete", "fail", "reopen", "intent"];
|
|
4343
4557
|
}
|
|
4344
4558
|
});
|
|
4345
|
-
function realProbe(
|
|
4559
|
+
function realProbe(p8) {
|
|
4346
4560
|
try {
|
|
4347
4561
|
if (typeof spawnSync !== "function") return null;
|
|
4348
|
-
const r = spawnSync(
|
|
4562
|
+
const r = spawnSync(p8, ["-c", "echo harnessed-bash-ok"], { encoding: "utf8", timeout: 5e3 });
|
|
4349
4563
|
if (!r || r.error) return null;
|
|
4350
4564
|
return r.status === 0;
|
|
4351
4565
|
} catch {
|
|
@@ -4362,9 +4576,9 @@ function realWhere(name) {
|
|
|
4362
4576
|
return [];
|
|
4363
4577
|
}
|
|
4364
4578
|
}
|
|
4365
|
-
function realExists(
|
|
4579
|
+
function realExists(p8) {
|
|
4366
4580
|
try {
|
|
4367
|
-
return existsSync(
|
|
4581
|
+
return existsSync(p8);
|
|
4368
4582
|
} catch {
|
|
4369
4583
|
return false;
|
|
4370
4584
|
}
|
|
@@ -4379,9 +4593,9 @@ function defaultDeps2() {
|
|
|
4379
4593
|
};
|
|
4380
4594
|
}
|
|
4381
4595
|
function resolveBash(deps) {
|
|
4382
|
-
if (
|
|
4383
|
-
|
|
4384
|
-
return
|
|
4596
|
+
if (cache3) return cache3;
|
|
4597
|
+
cache3 = compute({ ...defaultDeps2(), ...deps });
|
|
4598
|
+
return cache3;
|
|
4385
4599
|
}
|
|
4386
4600
|
function compute(d) {
|
|
4387
4601
|
if (d.platform !== "win32") {
|
|
@@ -4394,14 +4608,14 @@ function compute(d) {
|
|
|
4394
4608
|
const pathLines = d.where("bash");
|
|
4395
4609
|
const first = pathLines[0];
|
|
4396
4610
|
const wslOnPath = first && WSL_STUB_RE.test(first) ? first : void 0;
|
|
4397
|
-
const usable = (
|
|
4611
|
+
const usable = (p8) => !WSL_STUB_RE.test(p8) && d.probe(p8) !== false;
|
|
4398
4612
|
if (first && usable(first)) {
|
|
4399
4613
|
return { path: first, source: "path" };
|
|
4400
4614
|
}
|
|
4401
4615
|
const gitFirst = d.where("git")[0];
|
|
4402
4616
|
if (gitFirst && /git\.exe$/i.test(gitFirst)) {
|
|
4403
4617
|
const root = dirname9(dirname9(gitFirst));
|
|
4404
|
-
for (const cand of [
|
|
4618
|
+
for (const cand of [join22(root, "bin", "bash.exe"), join22(root, "usr", "bin", "bash.exe")]) {
|
|
4405
4619
|
if (d.exists(cand) && usable(cand)) return { path: cand, source: "git-derived", wslOnPath };
|
|
4406
4620
|
}
|
|
4407
4621
|
}
|
|
@@ -4409,13 +4623,13 @@ function compute(d) {
|
|
|
4409
4623
|
d.env.ProgramFiles,
|
|
4410
4624
|
d.env.ProgramW6432,
|
|
4411
4625
|
d.env["ProgramFiles(x86)"],
|
|
4412
|
-
d.env.LOCALAPPDATA ?
|
|
4626
|
+
d.env.LOCALAPPDATA ? join22(d.env.LOCALAPPDATA, "Programs") : void 0
|
|
4413
4627
|
];
|
|
4414
4628
|
for (const base of bases) {
|
|
4415
4629
|
if (!base) continue;
|
|
4416
4630
|
for (const cand of [
|
|
4417
|
-
|
|
4418
|
-
|
|
4631
|
+
join22(base, "Git", "bin", "bash.exe"),
|
|
4632
|
+
join22(base, "Git", "usr", "bin", "bash.exe")
|
|
4419
4633
|
]) {
|
|
4420
4634
|
if (d.exists(cand) && usable(cand))
|
|
4421
4635
|
return { path: cand, source: "standard-location", wslOnPath };
|
|
@@ -4428,12 +4642,12 @@ function compute(d) {
|
|
|
4428
4642
|
}
|
|
4429
4643
|
return { path: "bash", source: "path-fallback" };
|
|
4430
4644
|
}
|
|
4431
|
-
var dirname9,
|
|
4645
|
+
var dirname9, join22, WSL_STUB_RE, cache3;
|
|
4432
4646
|
var init_resolveBash = __esm({
|
|
4433
4647
|
"src/installers/lib/resolveBash.ts"() {
|
|
4434
|
-
({ dirname: dirname9, join:
|
|
4648
|
+
({ dirname: dirname9, join: join22 } = win32);
|
|
4435
4649
|
WSL_STUB_RE = /[\\/](windows[\\/](system32|sysnative|syswow64)|microsoft[\\/]windowsapps)[\\/]bash\.exe$/i;
|
|
4436
|
-
|
|
4650
|
+
cache3 = null;
|
|
4437
4651
|
}
|
|
4438
4652
|
});
|
|
4439
4653
|
|
|
@@ -4600,9 +4814,9 @@ function gstackSkillsDirInstalled(exists) {
|
|
|
4600
4814
|
return null;
|
|
4601
4815
|
}
|
|
4602
4816
|
function probeGstackPrefix(deps) {
|
|
4603
|
-
const exists = deps?.exists ?? ((
|
|
4817
|
+
const exists = deps?.exists ?? ((p8) => {
|
|
4604
4818
|
try {
|
|
4605
|
-
return existsSync(
|
|
4819
|
+
return existsSync(p8);
|
|
4606
4820
|
} catch {
|
|
4607
4821
|
return false;
|
|
4608
4822
|
}
|
|
@@ -4798,7 +5012,7 @@ async function checkAgentTeams() {
|
|
|
4798
5012
|
let settingsOn = false;
|
|
4799
5013
|
try {
|
|
4800
5014
|
const path = getSettingsPath();
|
|
4801
|
-
const raw = await readFile(path, "utf8");
|
|
5015
|
+
const raw = path === null ? "{}" : await readFile(path, "utf8");
|
|
4802
5016
|
const data = JSON.parse(raw);
|
|
4803
5017
|
settingsValue = data.env?.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS;
|
|
4804
5018
|
settingsOn = settingsValue === "1";
|
|
@@ -5015,7 +5229,8 @@ async function probeSearchMcpKey(server) {
|
|
|
5015
5229
|
} catch {
|
|
5016
5230
|
}
|
|
5017
5231
|
try {
|
|
5018
|
-
const
|
|
5232
|
+
const path = getSettingsPath();
|
|
5233
|
+
const raw = path === null ? "{}" : await readFile(path, "utf8");
|
|
5019
5234
|
const parsed = JSON.parse(raw);
|
|
5020
5235
|
if (parsed?.env && nonEmpty(parsed.env[envVar])) {
|
|
5021
5236
|
return { server, envVar, present: true, source: "settings-env" };
|
|
@@ -5366,9 +5581,9 @@ async function auditInstalledSkills(workflows, skillsBase, workflowsDir, opts =
|
|
|
5366
5581
|
}
|
|
5367
5582
|
async function buildCulpritIndex(manifestPaths) {
|
|
5368
5583
|
const index = /* @__PURE__ */ new Map();
|
|
5369
|
-
for (const
|
|
5584
|
+
for (const p8 of manifestPaths) {
|
|
5370
5585
|
try {
|
|
5371
|
-
const parsed = parse(await readFile(
|
|
5586
|
+
const parsed = parse(await readFile(p8, "utf8"));
|
|
5372
5587
|
const pack = parsed?.metadata?.name;
|
|
5373
5588
|
const skills = parsed?.spec?.install?.installs_skills;
|
|
5374
5589
|
if (typeof pack !== "string" || !Array.isArray(skills)) continue;
|
|
@@ -5945,14 +6160,20 @@ __export(check_stale_hooks_exports, {
|
|
|
5945
6160
|
});
|
|
5946
6161
|
function checkStaleHooks(deps) {
|
|
5947
6162
|
const settingsPath = deps?.settingsPath ?? getSettingsPath();
|
|
5948
|
-
const readText = deps?.readText ?? ((
|
|
6163
|
+
const readText = deps?.readText ?? ((p8) => {
|
|
5949
6164
|
try {
|
|
5950
|
-
return readFileSync(
|
|
6165
|
+
return readFileSync(p8, "utf8");
|
|
5951
6166
|
} catch {
|
|
5952
6167
|
return null;
|
|
5953
6168
|
}
|
|
5954
6169
|
});
|
|
5955
6170
|
const exists = deps?.exists ?? existsSync;
|
|
6171
|
+
if (settingsPath === null)
|
|
6172
|
+
return {
|
|
6173
|
+
name: NAME,
|
|
6174
|
+
status: "pass",
|
|
6175
|
+
message: `no settings file on ${detectPlatform().id} \u2014 skipped`
|
|
6176
|
+
};
|
|
5956
6177
|
const raw = readText(settingsPath);
|
|
5957
6178
|
if (raw === null) return { name: NAME, status: "pass", message: "no settings.json" };
|
|
5958
6179
|
let data;
|
|
@@ -6018,17 +6239,17 @@ async function probeChromeDevtools(deps = {}) {
|
|
|
6018
6239
|
if (standaloneStdio) providers.push(`${CHROME_DEVTOOLS_MCP_NAME} stdio MCP server`);
|
|
6019
6240
|
return { ecc, standalonePlugin, standaloneStdio, unknown, providers };
|
|
6020
6241
|
}
|
|
6021
|
-
function chromeDevtoolsAvailable(
|
|
6022
|
-
return
|
|
6242
|
+
function chromeDevtoolsAvailable(p8) {
|
|
6243
|
+
return p8.providers.length > 0 || p8.unknown;
|
|
6023
6244
|
}
|
|
6024
6245
|
async function isChromeDevtoolsAvailable(deps) {
|
|
6025
6246
|
return chromeDevtoolsAvailable(await probeChromeDevtools(deps));
|
|
6026
6247
|
}
|
|
6027
|
-
function chromeDevtoolsFactSource(
|
|
6028
|
-
if (
|
|
6029
|
-
return `chrome-devtools provider registered: ${
|
|
6248
|
+
function chromeDevtoolsFactSource(p8) {
|
|
6249
|
+
if (p8.providers.length > 0) {
|
|
6250
|
+
return `chrome-devtools provider registered: ${p8.providers.join(" + ")}`;
|
|
6030
6251
|
}
|
|
6031
|
-
if (
|
|
6252
|
+
if (p8.unknown) {
|
|
6032
6253
|
return `chrome-devtools provider probe FAULTED (unreadable plugin registry / MCP config) \u2014 availability unknown, reported true so the perf / a11y / memory diagnostic lane is never silently deleted (ADR-0029 fail-soft). To make it definite, ${CHROME_DEVTOOLS_ENABLE_PATHS}`;
|
|
6033
6254
|
}
|
|
6034
6255
|
return `NO chrome-devtools provider registered \u2014 the verify-qa \`05-perf-a11y-diagnostic\` lane (perf / a11y / memory, judgments.web-testing-routing.chrome-devtools-mcp-diagnostic.fires) will NOT run. To turn it on, ${CHROME_DEVTOOLS_ENABLE_PATHS}`;
|
|
@@ -6052,9 +6273,9 @@ var check_ecc_exports = {};
|
|
|
6052
6273
|
__export(check_ecc_exports, {
|
|
6053
6274
|
checkEcc: () => checkEcc
|
|
6054
6275
|
});
|
|
6055
|
-
async function pathExists(
|
|
6276
|
+
async function pathExists(p8) {
|
|
6056
6277
|
try {
|
|
6057
|
-
await stat(
|
|
6278
|
+
await stat(p8);
|
|
6058
6279
|
return true;
|
|
6059
6280
|
} catch {
|
|
6060
6281
|
return false;
|
|
@@ -6138,13 +6359,19 @@ function commandsFor(hooks, event) {
|
|
|
6138
6359
|
}
|
|
6139
6360
|
function checkInjectInvalidate(deps) {
|
|
6140
6361
|
const settingsPath = deps?.settingsPath ?? getSettingsPath();
|
|
6141
|
-
const readText = deps?.readText ?? ((
|
|
6362
|
+
const readText = deps?.readText ?? ((p8) => {
|
|
6142
6363
|
try {
|
|
6143
|
-
return readFileSync(
|
|
6364
|
+
return readFileSync(p8, "utf8");
|
|
6144
6365
|
} catch {
|
|
6145
6366
|
return null;
|
|
6146
6367
|
}
|
|
6147
6368
|
});
|
|
6369
|
+
if (settingsPath === null)
|
|
6370
|
+
return {
|
|
6371
|
+
name: NAME3,
|
|
6372
|
+
status: "pass",
|
|
6373
|
+
message: `no settings file on ${detectPlatform().id} \u2014 skipped`
|
|
6374
|
+
};
|
|
6148
6375
|
const raw = readText(settingsPath);
|
|
6149
6376
|
if (raw === null) return { name: NAME3, status: "pass", message: "no settings.json" };
|
|
6150
6377
|
let hooks;
|
|
@@ -6190,23 +6417,23 @@ function defaultDeps3() {
|
|
|
6190
6417
|
return {
|
|
6191
6418
|
assetsRoot: getAssetsRoot(),
|
|
6192
6419
|
registryPath: getPluginsRegistry(),
|
|
6193
|
-
readText: (
|
|
6420
|
+
readText: (p8) => {
|
|
6194
6421
|
try {
|
|
6195
|
-
return readFileSync(
|
|
6422
|
+
return readFileSync(p8, "utf8");
|
|
6196
6423
|
} catch {
|
|
6197
6424
|
return null;
|
|
6198
6425
|
}
|
|
6199
6426
|
},
|
|
6200
|
-
listDir: (
|
|
6427
|
+
listDir: (p8) => {
|
|
6201
6428
|
try {
|
|
6202
|
-
return readdirSync(
|
|
6429
|
+
return readdirSync(p8);
|
|
6203
6430
|
} catch {
|
|
6204
6431
|
return null;
|
|
6205
6432
|
}
|
|
6206
6433
|
},
|
|
6207
|
-
isDir: (
|
|
6434
|
+
isDir: (p8) => {
|
|
6208
6435
|
try {
|
|
6209
|
-
return statSync(
|
|
6436
|
+
return statSync(p8).isDirectory();
|
|
6210
6437
|
} catch {
|
|
6211
6438
|
return false;
|
|
6212
6439
|
}
|
|
@@ -6337,72 +6564,938 @@ var init_check_ablation = __esm({
|
|
|
6337
6564
|
}
|
|
6338
6565
|
});
|
|
6339
6566
|
|
|
6340
|
-
// src/
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
|
|
6567
|
+
// src/installers/lib/codexHookPlugin.ts
|
|
6568
|
+
function codexHookPluginName(manifestName) {
|
|
6569
|
+
return `harnessed-${manifestName}`;
|
|
6570
|
+
}
|
|
6571
|
+
function codexHookPluginId(manifestName) {
|
|
6572
|
+
return `${codexHookPluginName(manifestName)}@${CODEX_HOOK_MARKETPLACE}`;
|
|
6573
|
+
}
|
|
6574
|
+
function parseHookIdentity(hookCommand) {
|
|
6575
|
+
const id = hookScriptMarker(hookCommand);
|
|
6576
|
+
if (id === null) return null;
|
|
6577
|
+
const tokens = hookCommand.split(/\s+/).filter((t2) => t2.length > 0);
|
|
6578
|
+
const at = tokens.findIndex((t2) => t2.replace(/^"|"$/g, "").includes(id));
|
|
6579
|
+
if (at < 0 || !/^[a-z][a-z-]*$/.test(id)) return null;
|
|
6580
|
+
return { id, args: tokens.slice(at + 1) };
|
|
6581
|
+
}
|
|
6582
|
+
function codexHookCommand(ident, mode) {
|
|
6583
|
+
const host = HOST_AWARE_IDS.has(ident.id) ? ["--platform", "codex"] : [];
|
|
6584
|
+
const head = mode === "npm" ? ["node", '"${PLUGIN_ROOT}/hook.cjs"'] : ["harnessed"];
|
|
6585
|
+
return [...head, ident.id, ...ident.args, ...host].join(" ");
|
|
6586
|
+
}
|
|
6587
|
+
function codexHookTrustKey(pluginName, event) {
|
|
6588
|
+
const snake = event.replace(/([a-z0-9])([A-Z])/g, "$1_$2").toLowerCase();
|
|
6589
|
+
return `${pluginName}@${CODEX_HOOK_MARKETPLACE}:hooks/hooks.json:${snake}:0:0`;
|
|
6590
|
+
}
|
|
6591
|
+
function codexMarketplaceJson(pluginNames) {
|
|
6592
|
+
return {
|
|
6593
|
+
name: CODEX_HOOK_MARKETPLACE,
|
|
6594
|
+
owner: { name: "harnessed" },
|
|
6595
|
+
plugins: [...pluginNames].sort().map((name) => ({
|
|
6596
|
+
name,
|
|
6597
|
+
source: `./plugins/${name}`,
|
|
6598
|
+
policy: { installation: "AVAILABLE", authentication: "ON_INSTALL" },
|
|
6599
|
+
version: CODEX_HOOK_PLUGIN_VERSION
|
|
6600
|
+
}))
|
|
6601
|
+
};
|
|
6602
|
+
}
|
|
6603
|
+
function renderCodexHookPlugin(spec, mode) {
|
|
6604
|
+
const ident = parseHookIdentity(spec.hookCommand);
|
|
6605
|
+
if (ident === null || !PORTABLE_IDS.has(ident.id)) return null;
|
|
6606
|
+
const pluginName = codexHookPluginName(spec.manifestName);
|
|
6607
|
+
const command = codexHookCommand(ident, mode);
|
|
6608
|
+
const group = {
|
|
6609
|
+
...spec.matcher !== void 0 ? { matcher: spec.matcher } : {},
|
|
6610
|
+
hooks: [{ type: "command", command, commandWindows: command }]
|
|
6611
|
+
};
|
|
6612
|
+
const base = `plugins/${pluginName}`;
|
|
6613
|
+
const files = [
|
|
6614
|
+
{
|
|
6615
|
+
path: `${base}/.codex-plugin/plugin.json`,
|
|
6616
|
+
content: json({
|
|
6617
|
+
name: pluginName,
|
|
6618
|
+
description: `harnessed first-party hook (${spec.manifestName}) for codex`,
|
|
6619
|
+
version: CODEX_HOOK_PLUGIN_VERSION,
|
|
6620
|
+
author: { name: "harnessed" }
|
|
6621
|
+
})
|
|
6622
|
+
},
|
|
6623
|
+
{ path: `${base}/hooks/hooks.json`, content: json({ hooks: { [spec.event]: [group] } }) }
|
|
6624
|
+
];
|
|
6625
|
+
if (mode === "npm") files.push({ path: `${base}/hook.cjs`, content: CODEX_HOOK_SHIM });
|
|
6626
|
+
return { pluginName, files };
|
|
6627
|
+
}
|
|
6628
|
+
var CODEX_HOOK_MARKETPLACE, CODEX_HOOK_PLUGIN_VERSION, PORTABLE_IDS, HOST_AWARE_IDS, json, CODEX_HOOK_SHIM;
|
|
6629
|
+
var init_codexHookPlugin = __esm({
|
|
6630
|
+
"src/installers/lib/codexHookPlugin.ts"() {
|
|
6631
|
+
init_hookEntry();
|
|
6632
|
+
CODEX_HOOK_MARKETPLACE = "harnessed-local";
|
|
6633
|
+
CODEX_HOOK_PLUGIN_VERSION = "1.0.0";
|
|
6634
|
+
PORTABLE_IDS = /* @__PURE__ */ new Set(["inject-state", "check-docs"]);
|
|
6635
|
+
HOST_AWARE_IDS = /* @__PURE__ */ new Set(["inject-state", "check-docs"]);
|
|
6636
|
+
json = (v) => `${JSON.stringify(v, null, 2)}
|
|
6637
|
+
`;
|
|
6638
|
+
CODEX_HOOK_SHIM = `#!/usr/bin/env node
|
|
6639
|
+
// harnessed codex hook shim \u2014 GENERATED by \`harnessed install\` (ADR 0041). Do not edit:
|
|
6640
|
+
// the hook command that runs this file is hash-trusted by codex; this file is not.
|
|
6641
|
+
'use strict'
|
|
6642
|
+
const { existsSync, readFileSync } = require('node:fs')
|
|
6643
|
+
const { join } = require('node:path')
|
|
6644
|
+
const { pathToFileURL } = require('node:url')
|
|
6645
|
+
|
|
6646
|
+
function installInfo() {
|
|
6647
|
+
for (const dir of [process.env.PLUGIN_DATA, __dirname]) {
|
|
6648
|
+
if (!dir) continue
|
|
6649
|
+
try {
|
|
6650
|
+
return JSON.parse(readFileSync(join(dir, 'install.json'), 'utf8'))
|
|
6651
|
+
} catch {}
|
|
6652
|
+
}
|
|
6653
|
+
return null
|
|
6654
|
+
}
|
|
6655
|
+
|
|
6656
|
+
const id = process.argv[2]
|
|
6657
|
+
const info = installInfo()
|
|
6658
|
+
if (!info || typeof info.assetsRoot !== 'string' || !/^[a-z][a-z-]*$/.test(id || '')) process.exit(0)
|
|
6659
|
+
const bin = join(info.assetsRoot, 'bin', 'harnessed-' + id + '.mjs')
|
|
6660
|
+
const target = existsSync(bin) ? bin : join(info.assetsRoot, 'dist', 'cli.mjs')
|
|
6661
|
+
import(pathToFileURL(target).href).catch(() => process.exit(0))
|
|
6662
|
+
`;
|
|
6663
|
+
}
|
|
6664
|
+
});
|
|
6665
|
+
function isHarnessedHookKey(key) {
|
|
6666
|
+
return HARNESSED_KEY.test(key);
|
|
6667
|
+
}
|
|
6668
|
+
function spawnCodexAppServer() {
|
|
6669
|
+
const args = ["app-server"];
|
|
6670
|
+
let child;
|
|
6671
|
+
if (process.platform === "win32") {
|
|
6672
|
+
const plan = planWindowsSpawn("codex", args, resolveWindowsBin("codex"));
|
|
6673
|
+
child = spawn(plan.command, plan.args, {
|
|
6674
|
+
windowsHide: true,
|
|
6675
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
6676
|
+
windowsVerbatimArguments: plan.verbatim
|
|
6677
|
+
});
|
|
6678
|
+
} else {
|
|
6679
|
+
child = spawn("codex", args, { stdio: ["pipe", "pipe", "ignore"] });
|
|
6680
|
+
}
|
|
6681
|
+
return {
|
|
6682
|
+
stdin: child.stdin,
|
|
6683
|
+
stdout: child.stdout,
|
|
6684
|
+
kill: () => killProcessTree(child),
|
|
6685
|
+
on: ((event, fn) => child.on(event, fn))
|
|
6686
|
+
};
|
|
6687
|
+
}
|
|
6688
|
+
async function withAppServer(deps, body) {
|
|
6689
|
+
let proc;
|
|
6690
|
+
try {
|
|
6691
|
+
proc = (deps.spawn ?? spawnCodexAppServer)();
|
|
6692
|
+
} catch (e) {
|
|
6693
|
+
return { ok: false, failure: "spawn-failed", detail: e.message };
|
|
6694
|
+
}
|
|
6695
|
+
const timeoutMs = deps.timeoutMs ?? 15e3;
|
|
6696
|
+
const pending = /* @__PURE__ */ new Map();
|
|
6697
|
+
let sawGarbage = false;
|
|
6698
|
+
let closed = null;
|
|
6699
|
+
const failAll = (e) => {
|
|
6700
|
+
closed = closed ?? e;
|
|
6701
|
+
for (const p8 of pending.values()) p8.reject(e);
|
|
6702
|
+
pending.clear();
|
|
6703
|
+
};
|
|
6704
|
+
let buf = "";
|
|
6705
|
+
proc.stdout.setEncoding("utf8");
|
|
6706
|
+
proc.stdout.on("data", (chunk) => {
|
|
6707
|
+
buf += chunk;
|
|
6708
|
+
for (let i = buf.indexOf("\n"); i >= 0; i = buf.indexOf("\n")) {
|
|
6709
|
+
const line = buf.slice(0, i).trim();
|
|
6710
|
+
buf = buf.slice(i + 1);
|
|
6711
|
+
if (!line) continue;
|
|
6712
|
+
let msg;
|
|
6713
|
+
try {
|
|
6714
|
+
msg = JSON.parse(line);
|
|
6715
|
+
} catch {
|
|
6716
|
+
sawGarbage = true;
|
|
6717
|
+
continue;
|
|
6718
|
+
}
|
|
6719
|
+
if (msg.id === void 0 || msg.method !== void 0) continue;
|
|
6720
|
+
const p8 = pending.get(msg.id);
|
|
6721
|
+
if (!p8) continue;
|
|
6722
|
+
pending.delete(msg.id);
|
|
6723
|
+
if (msg.error) {
|
|
6724
|
+
const text = String(msg.error.message ?? "");
|
|
6725
|
+
const missing = msg.error.code === -32601 || /unknown variant/i.test(text);
|
|
6726
|
+
p8.reject(new RpcError(missing ? "method-missing" : "rpc-error", text.slice(0, 300)));
|
|
6727
|
+
} else p8.resolve(msg.result);
|
|
6728
|
+
}
|
|
6729
|
+
});
|
|
6730
|
+
const onGone = () => failAll(
|
|
6731
|
+
new RpcError(
|
|
6732
|
+
sawGarbage ? "bad-output" : "spawn-failed",
|
|
6733
|
+
sawGarbage ? "codex app-server wrote non-JSON output" : "codex app-server exited"
|
|
6734
|
+
)
|
|
6735
|
+
);
|
|
6736
|
+
proc.stdout.on("end", onGone);
|
|
6737
|
+
proc.on("exit", onGone);
|
|
6738
|
+
proc.on("error", (e) => failAll(new RpcError("spawn-failed", e.message)));
|
|
6739
|
+
let nextId = 1;
|
|
6740
|
+
const send = (msg) => proc.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...msg })}
|
|
6741
|
+
`);
|
|
6742
|
+
const call = (method, params) => {
|
|
6743
|
+
if (closed) return Promise.reject(closed);
|
|
6744
|
+
const id = nextId++;
|
|
6745
|
+
return new Promise((resolve23, reject) => {
|
|
6746
|
+
const timer = setTimeout(() => {
|
|
6747
|
+
pending.delete(id);
|
|
6748
|
+
reject(new RpcError("timeout", `${method} timed out after ${timeoutMs}ms`));
|
|
6749
|
+
}, timeoutMs);
|
|
6750
|
+
pending.set(id, {
|
|
6751
|
+
resolve: (v) => {
|
|
6752
|
+
clearTimeout(timer);
|
|
6753
|
+
resolve23(v);
|
|
6754
|
+
},
|
|
6755
|
+
reject: (e) => {
|
|
6756
|
+
clearTimeout(timer);
|
|
6757
|
+
reject(e);
|
|
6758
|
+
}
|
|
6759
|
+
});
|
|
6760
|
+
send({ id, method, params });
|
|
6761
|
+
});
|
|
6762
|
+
};
|
|
6763
|
+
try {
|
|
6764
|
+
await call("initialize", { clientInfo: { name: "harnessed", version: "0" } });
|
|
6765
|
+
send({ method: "initialized", params: {} });
|
|
6766
|
+
return { ok: true, value: await body(call) };
|
|
6767
|
+
} catch (e) {
|
|
6768
|
+
if (e instanceof RpcError) return { ok: false, failure: e.failure, detail: e.message };
|
|
6769
|
+
return { ok: false, failure: "bad-output", detail: e.message };
|
|
6770
|
+
} finally {
|
|
6771
|
+
try {
|
|
6772
|
+
proc.kill();
|
|
6773
|
+
} catch {
|
|
6774
|
+
}
|
|
6775
|
+
}
|
|
6776
|
+
}
|
|
6777
|
+
function parseHooks(result) {
|
|
6778
|
+
const data = result?.data;
|
|
6779
|
+
if (!Array.isArray(data)) throw new RpcError("bad-output", "hooks/list: no data[]");
|
|
6780
|
+
const out = [];
|
|
6781
|
+
for (const d of data) {
|
|
6782
|
+
const hooks = d?.hooks;
|
|
6783
|
+
if (!Array.isArray(hooks)) continue;
|
|
6784
|
+
for (const h of hooks) {
|
|
6785
|
+
if (typeof h?.key !== "string") continue;
|
|
6786
|
+
out.push({
|
|
6787
|
+
key: h.key,
|
|
6788
|
+
eventName: String(h.eventName ?? ""),
|
|
6789
|
+
trustStatus: String(h.trustStatus ?? "unknown"),
|
|
6790
|
+
currentHash: String(h.currentHash ?? ""),
|
|
6791
|
+
...typeof h.pluginId === "string" ? { pluginId: h.pluginId } : {},
|
|
6792
|
+
...typeof h.command === "string" ? { command: h.command } : {}
|
|
6793
|
+
});
|
|
6794
|
+
}
|
|
6795
|
+
}
|
|
6796
|
+
return out;
|
|
6797
|
+
}
|
|
6798
|
+
function listCodexHooks(deps = {}) {
|
|
6799
|
+
return withAppServer(deps, (call) => listIn(call, deps.cwd ?? homedir()));
|
|
6800
|
+
}
|
|
6801
|
+
async function trustCodexHooks(pluginIds, deps = {}) {
|
|
6802
|
+
const foreign = pluginIds.filter((p8) => !HARNESSED_PLUGIN.test(p8));
|
|
6803
|
+
if (foreign.length > 0)
|
|
6804
|
+
return {
|
|
6805
|
+
ok: false,
|
|
6806
|
+
failure: "rpc-error",
|
|
6807
|
+
detail: `refusing non-harnessed plugin(s): ${foreign.join(", ")}`
|
|
6808
|
+
};
|
|
6809
|
+
return withAppServer(deps, async (call) => {
|
|
6810
|
+
const hooks = await listIn(call, deps.cwd ?? homedir());
|
|
6811
|
+
const ours = hooks.filter(
|
|
6812
|
+
(h) => isHarnessedHookKey(h.key) && pluginIds.some((p8) => h.key.startsWith(`${p8}:`))
|
|
6813
|
+
);
|
|
6814
|
+
const todo = ours.filter((h) => h.trustStatus !== "trusted" && h.currentHash);
|
|
6815
|
+
const missing = pluginIds.filter((p8) => !ours.some((h) => h.key.startsWith(`${p8}:`)));
|
|
6816
|
+
if (todo.length > 0) {
|
|
6817
|
+
await call("config/batchWrite", {
|
|
6818
|
+
edits: [
|
|
6819
|
+
{
|
|
6820
|
+
keyPath: "hooks.state",
|
|
6821
|
+
value: Object.fromEntries(todo.map((h) => [h.key, { trusted_hash: h.currentHash }])),
|
|
6822
|
+
mergeStrategy: "upsert"
|
|
6823
|
+
}
|
|
6824
|
+
],
|
|
6825
|
+
reloadUserConfig: true
|
|
6826
|
+
});
|
|
6827
|
+
}
|
|
6828
|
+
return {
|
|
6829
|
+
trusted: todo.map((h) => h.key),
|
|
6830
|
+
already: ours.filter((h) => h.trustStatus === "trusted").map((h) => h.key),
|
|
6831
|
+
missing
|
|
6832
|
+
};
|
|
6833
|
+
});
|
|
6834
|
+
}
|
|
6835
|
+
async function untrustCodexHooks(keys, deps = {}) {
|
|
6836
|
+
const ours = [...new Set(keys.filter(isHarnessedHookKey))];
|
|
6837
|
+
if (ours.length === 0) return { ok: true, value: { removed: [] } };
|
|
6838
|
+
return withAppServer(deps, async (call) => {
|
|
6839
|
+
await call("config/batchWrite", {
|
|
6840
|
+
edits: ours.map((k) => ({
|
|
6841
|
+
keyPath: `hooks.state."${k}"`,
|
|
6842
|
+
value: null,
|
|
6843
|
+
mergeStrategy: "replace"
|
|
6844
|
+
})),
|
|
6845
|
+
reloadUserConfig: true
|
|
6846
|
+
});
|
|
6847
|
+
return { removed: ours };
|
|
6848
|
+
});
|
|
6849
|
+
}
|
|
6850
|
+
var HARNESSED_KEY, HARNESSED_PLUGIN, RpcError, listIn;
|
|
6851
|
+
var init_codexHookTrust = __esm({
|
|
6852
|
+
"src/installers/lib/codexHookTrust.ts"() {
|
|
6853
|
+
init_killTree();
|
|
6854
|
+
init_winSpawn();
|
|
6855
|
+
HARNESSED_KEY = /^harnessed-[a-z0-9][a-z0-9-]*@harnessed-local:[^"\\]+$/;
|
|
6856
|
+
HARNESSED_PLUGIN = /^harnessed-[a-z0-9][a-z0-9-]*@harnessed-local$/;
|
|
6857
|
+
RpcError = class extends Error {
|
|
6858
|
+
constructor(failure, detail) {
|
|
6859
|
+
super(detail);
|
|
6860
|
+
this.failure = failure;
|
|
6861
|
+
}
|
|
6862
|
+
failure;
|
|
6863
|
+
};
|
|
6864
|
+
listIn = (call, cwd) => call("hooks/list", { cwds: [cwd] }).then(parseHooks);
|
|
6865
|
+
}
|
|
6866
|
+
});
|
|
6867
|
+
async function confirmAt(level, ctx) {
|
|
6868
|
+
if (level === "L4" && !ctx.opts.system) {
|
|
6869
|
+
if (!ctx.opts.nonInteractive) {
|
|
6870
|
+
p.note(
|
|
6871
|
+
"this method requires --system flag (e.g. global npm install affects machine PATH); pass --system to opt in.",
|
|
6872
|
+
"L4 system-wide install"
|
|
6873
|
+
);
|
|
6874
|
+
}
|
|
6875
|
+
return { proceed: false, reason: "flag-missing" };
|
|
6876
|
+
}
|
|
6877
|
+
if (ctx.opts.nonInteractive) {
|
|
6878
|
+
return { proceed: ctx.opts.apply };
|
|
6879
|
+
}
|
|
6880
|
+
if (level === "L1") {
|
|
6881
|
+
p.note("will write project-local files only (safe scope).", "L1 confirm");
|
|
6882
|
+
return { proceed: true };
|
|
6883
|
+
}
|
|
6884
|
+
if (level === "L2") {
|
|
6885
|
+
const ans2 = await p.confirm({ message: "Proceed with install?", initialValue: false });
|
|
6886
|
+
if (p.isCancel(ans2)) return { proceed: false, reason: "user-cancel" };
|
|
6887
|
+
return { proceed: ans2 === true };
|
|
6888
|
+
}
|
|
6889
|
+
if (level === "L3") {
|
|
6890
|
+
const first = await p.confirm({ message: "Proceed with install?", initialValue: false });
|
|
6891
|
+
if (p.isCancel(first)) return { proceed: false, reason: "user-cancel" };
|
|
6892
|
+
if (first !== true) return { proceed: false };
|
|
6893
|
+
const second = await p.confirm({
|
|
6894
|
+
// v4.14.0 — wording generalized: the shared user-scope config is
|
|
6895
|
+
// ~/.claude.json on claude, ~/.codex/config.toml on codex.
|
|
6896
|
+
message: "This affects other plugins (the harness user-scope config is shared state). Confirm again?",
|
|
6897
|
+
initialValue: false
|
|
6898
|
+
});
|
|
6899
|
+
if (p.isCancel(second)) return { proceed: false, reason: "user-cancel" };
|
|
6900
|
+
return { proceed: second === true };
|
|
6901
|
+
}
|
|
6902
|
+
const ans = await p.confirm({
|
|
6903
|
+
message: "System-wide install will modify global PATH. Proceed?",
|
|
6904
|
+
initialValue: false
|
|
6905
|
+
});
|
|
6906
|
+
if (p.isCancel(ans)) return { proceed: false, reason: "user-cancel" };
|
|
6907
|
+
return { proceed: ans === true };
|
|
6908
|
+
}
|
|
6909
|
+
var init_confirm = __esm({
|
|
6910
|
+
"src/installers/lib/confirm.ts"() {
|
|
6911
|
+
}
|
|
6912
|
+
});
|
|
6913
|
+
function colorize(line) {
|
|
6914
|
+
if (!pc.isColorSupported) return line;
|
|
6915
|
+
if (line.startsWith("+") && !line.startsWith("+++")) return pc.green(line);
|
|
6916
|
+
if (line.startsWith("-") && !line.startsWith("---")) return pc.red(line);
|
|
6917
|
+
if (line.startsWith("@@")) return pc.cyan(line);
|
|
6918
|
+
return line;
|
|
6919
|
+
}
|
|
6920
|
+
function diffOneFile(file) {
|
|
6921
|
+
const patch = createPatch(file.target, file.oldText, file.newText, "", "", {
|
|
6922
|
+
stripTrailingCr: true
|
|
6923
|
+
});
|
|
6924
|
+
const lines = patch.split("\n");
|
|
6925
|
+
let added = 0;
|
|
6926
|
+
let removed = 0;
|
|
6927
|
+
for (const ln of lines) {
|
|
6928
|
+
if (ln.startsWith("+") && !ln.startsWith("+++")) added++;
|
|
6929
|
+
else if (ln.startsWith("-") && !ln.startsWith("---")) removed++;
|
|
6930
|
+
}
|
|
6931
|
+
return { lines, added, removed };
|
|
6932
|
+
}
|
|
6933
|
+
function renderDiff(plan, ctx) {
|
|
6934
|
+
if (plan.files.length === 0) return "(no file changes)\n";
|
|
6935
|
+
const out = [];
|
|
6936
|
+
let totalAdded = 0;
|
|
6937
|
+
let totalRemoved = 0;
|
|
6938
|
+
for (const file of plan.files) {
|
|
6939
|
+
const { lines, added, removed } = diffOneFile(file);
|
|
6940
|
+
totalAdded += added;
|
|
6941
|
+
totalRemoved += removed;
|
|
6942
|
+
const folded = !ctx.opts.fullDiff && lines.length > FOLD_THRESHOLD;
|
|
6943
|
+
const visible = folded ? lines.slice(0, FOLD_HEAD) : lines;
|
|
6944
|
+
for (const ln of visible) out.push(colorize(ln));
|
|
6945
|
+
if (folded) {
|
|
6946
|
+
const more = lines.length - FOLD_HEAD;
|
|
6947
|
+
out.push(pc.dim(`... ${more} more lines (use --full-diff to expand)`));
|
|
6948
|
+
}
|
|
6949
|
+
}
|
|
6950
|
+
const summary = `will modify ${plan.files.length} file${plan.files.length === 1 ? "" : "s"} (${totalAdded} added, ${totalRemoved} removed)`;
|
|
6951
|
+
out.push("");
|
|
6952
|
+
out.push(pc.bold(summary));
|
|
6953
|
+
return `${out.join("\n")}
|
|
6954
|
+
`;
|
|
6955
|
+
}
|
|
6956
|
+
var FOLD_THRESHOLD, FOLD_HEAD;
|
|
6957
|
+
var init_diff = __esm({
|
|
6958
|
+
"src/installers/lib/diff.ts"() {
|
|
6959
|
+
FOLD_THRESHOLD = 200;
|
|
6960
|
+
FOLD_HEAD = 100;
|
|
6961
|
+
}
|
|
6962
|
+
});
|
|
6963
|
+
|
|
6964
|
+
// src/installers/lib/err.ts
|
|
6965
|
+
function err(ctx, path, message, keyword) {
|
|
6966
|
+
return { file: ctx.manifest.metadata.name, path, message, line: null, column: null, keyword };
|
|
6967
|
+
}
|
|
6968
|
+
var init_err = __esm({
|
|
6969
|
+
"src/installers/lib/err.ts"() {
|
|
6970
|
+
}
|
|
6971
|
+
});
|
|
6972
|
+
function statePath2(_cwd) {
|
|
6973
|
+
return harnessedFile("state.json");
|
|
6974
|
+
}
|
|
6975
|
+
async function readState(cwd) {
|
|
6976
|
+
const path = statePath2();
|
|
6977
|
+
let raw;
|
|
6978
|
+
try {
|
|
6979
|
+
raw = await readFile(path, "utf8");
|
|
6980
|
+
} catch (err2) {
|
|
6981
|
+
if (err2.code === "ENOENT") {
|
|
6982
|
+
return { ...DEFAULT_STATE, installed: {} };
|
|
6983
|
+
}
|
|
6984
|
+
throw err2;
|
|
6985
|
+
}
|
|
6986
|
+
try {
|
|
6987
|
+
const parsed = JSON.parse(raw);
|
|
6988
|
+
if (parsed.version !== "1" || typeof parsed.installed !== "object") {
|
|
6989
|
+
return { ...DEFAULT_STATE, installed: {} };
|
|
6990
|
+
}
|
|
6991
|
+
return parsed;
|
|
6992
|
+
} catch {
|
|
6993
|
+
return { ...DEFAULT_STATE, installed: {} };
|
|
6994
|
+
}
|
|
6995
|
+
}
|
|
6996
|
+
async function writeState(cwd, state) {
|
|
6997
|
+
const path = statePath2();
|
|
6998
|
+
const tmp = `${path}.tmp`;
|
|
6999
|
+
await mkdir(dirname(path), { recursive: true });
|
|
7000
|
+
await writeFile(tmp, `${JSON.stringify(state, null, 2)}
|
|
7001
|
+
`, "utf8");
|
|
7002
|
+
await rename(tmp, path);
|
|
7003
|
+
}
|
|
7004
|
+
async function updateInstalled(cwd, name, version, manifestSha1) {
|
|
7005
|
+
const state = await readState();
|
|
7006
|
+
state.installed[name] = {
|
|
7007
|
+
version,
|
|
7008
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7009
|
+
manifestSha1
|
|
7010
|
+
};
|
|
7011
|
+
await writeState(cwd, state);
|
|
7012
|
+
}
|
|
7013
|
+
async function recordObservedInstall(cwd, name, version, manifestSha1) {
|
|
7014
|
+
try {
|
|
7015
|
+
const state = await readState(cwd);
|
|
7016
|
+
const prev = state.installed[name];
|
|
7017
|
+
if (prev && prev.version === version && prev.manifestSha1 === manifestSha1) return;
|
|
7018
|
+
state.installed[name] = {
|
|
7019
|
+
version,
|
|
7020
|
+
installedAt: prev?.installedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
7021
|
+
manifestSha1
|
|
7022
|
+
};
|
|
7023
|
+
await writeState(cwd, state);
|
|
7024
|
+
} catch {
|
|
7025
|
+
}
|
|
7026
|
+
}
|
|
7027
|
+
var DEFAULT_STATE;
|
|
7028
|
+
var init_state2 = __esm({
|
|
7029
|
+
"src/installers/lib/state.ts"() {
|
|
7030
|
+
init_harnessedRoot();
|
|
7031
|
+
DEFAULT_STATE = { version: "1", installed: {} };
|
|
7032
|
+
}
|
|
7033
|
+
});
|
|
7034
|
+
function resolveCodexHome() {
|
|
7035
|
+
const env = process.env.CODEX_HOME?.trim();
|
|
7036
|
+
return env ? env : detectPlatform().homeDir;
|
|
7037
|
+
}
|
|
7038
|
+
function codexHookPaths(codexHome, manifestName) {
|
|
7039
|
+
const pluginName = codexHookPluginName(manifestName);
|
|
7040
|
+
const marketplaceRoot = join(codexHome, "harnessed", "marketplace");
|
|
7041
|
+
return {
|
|
7042
|
+
pluginName,
|
|
7043
|
+
pluginId: codexHookPluginId(manifestName),
|
|
7044
|
+
marketplaceRoot,
|
|
7045
|
+
marketplaceJson: join(marketplaceRoot, ".agents", "plugins", "marketplace.json"),
|
|
7046
|
+
pluginsDir: join(marketplaceRoot, "plugins"),
|
|
7047
|
+
pluginDir: join(marketplaceRoot, "plugins", pluginName),
|
|
7048
|
+
dataDir: join(codexHome, "plugins", "data", `${pluginName}-${CODEX_HOOK_MARKETPLACE}`),
|
|
7049
|
+
cacheMarketplaceDir: join(codexHome, "plugins", "cache", CODEX_HOOK_MARKETPLACE)
|
|
7050
|
+
};
|
|
7051
|
+
}
|
|
7052
|
+
async function readOr(path) {
|
|
7053
|
+
try {
|
|
7054
|
+
return await readFile(path, "utf8");
|
|
7055
|
+
} catch {
|
|
7056
|
+
return "";
|
|
7057
|
+
}
|
|
7058
|
+
}
|
|
7059
|
+
async function harnessedPluginDirs(pluginsDir) {
|
|
7060
|
+
try {
|
|
7061
|
+
return (await readdir(pluginsDir)).filter((n) => n.startsWith("harnessed-"));
|
|
7062
|
+
} catch {
|
|
7063
|
+
return [];
|
|
7064
|
+
}
|
|
7065
|
+
}
|
|
7066
|
+
async function ensureTrust(ctx, pluginId) {
|
|
7067
|
+
const name = ctx.manifest.metadata.name;
|
|
7068
|
+
const mode = ctx.opts.codexHookTrust ?? "deny";
|
|
7069
|
+
if (mode !== "grant") {
|
|
7070
|
+
const listed = await listCodexHooks();
|
|
7071
|
+
if (!listed.ok) return `${TRUST_HINT(name)} (trust status unknown: ${listed.failure})`;
|
|
7072
|
+
const ours = listed.value.filter((h) => h.key.startsWith(`${pluginId}:`));
|
|
7073
|
+
if (ours.length > 0 && ours.every((h) => h.trustStatus === "trusted")) return void 0;
|
|
7074
|
+
if (mode === "deny") return TRUST_HINT(name);
|
|
7075
|
+
const ans = await p.confirm({
|
|
7076
|
+
message: `Trust harnessed's codex hook plugin ${pluginId}? codex runs trusted hooks on every matching event.`,
|
|
7077
|
+
initialValue: true
|
|
7078
|
+
});
|
|
7079
|
+
if (p.isCancel(ans) || ans !== true) return TRUST_HINT(name);
|
|
7080
|
+
}
|
|
7081
|
+
const r = await trustCodexHooks([pluginId]);
|
|
7082
|
+
if (!r.ok) return `${TRUST_HINT(name)} (trust RPC ${r.failure}: ${r.detail.slice(0, 120)})`;
|
|
7083
|
+
if (r.value.missing.length > 0)
|
|
7084
|
+
return `${TRUST_HINT(name)} (codex did not list the plugin's hooks yet)`;
|
|
7085
|
+
return void 0;
|
|
7086
|
+
}
|
|
7087
|
+
async function installCodexHook(ctx) {
|
|
7088
|
+
const install = ctx.manifest.spec.install;
|
|
7089
|
+
if (install.method !== "cc-hook-add")
|
|
7090
|
+
return {
|
|
7091
|
+
ok: false,
|
|
7092
|
+
phase: "preflight",
|
|
7093
|
+
error: err(
|
|
7094
|
+
ctx,
|
|
7095
|
+
"/spec/install/method",
|
|
7096
|
+
`dispatch bug: ${install.method}`,
|
|
7097
|
+
"dispatch-mismatch"
|
|
7098
|
+
)
|
|
7099
|
+
};
|
|
7100
|
+
const name = ctx.manifest.metadata.name;
|
|
7101
|
+
const mode = isCompiledRuntime() ? "binary" : "npm";
|
|
7102
|
+
const rendered = renderCodexHookPlugin(
|
|
7103
|
+
{
|
|
7104
|
+
manifestName: name,
|
|
7105
|
+
event: install.hook_event,
|
|
7106
|
+
...install.hook_matcher !== void 0 ? { matcher: install.hook_matcher } : {},
|
|
7107
|
+
hookCommand: install.hook_command
|
|
7108
|
+
},
|
|
7109
|
+
mode
|
|
7110
|
+
);
|
|
7111
|
+
if (!rendered) return { aborted: true, reason: "harness-mismatch" };
|
|
7112
|
+
const violation = checkCmdString(install.hook_command);
|
|
7113
|
+
if (violation)
|
|
7114
|
+
return {
|
|
7115
|
+
ok: false,
|
|
7116
|
+
phase: "preflight",
|
|
7117
|
+
error: err(
|
|
7118
|
+
ctx,
|
|
7119
|
+
"/spec/install/hook_command",
|
|
7120
|
+
`shell escape detected in hook_command: ${violation.label} (${violation.hint})`,
|
|
7121
|
+
"security-gate-bypass"
|
|
7122
|
+
)
|
|
7123
|
+
};
|
|
7124
|
+
const paths = codexHookPaths(resolveCodexHome(), name);
|
|
7125
|
+
const others = (await harnessedPluginDirs(paths.pluginsDir)).filter((n) => n !== paths.pluginName);
|
|
7126
|
+
const info = `${JSON.stringify(
|
|
7127
|
+
{ mode, assetsRoot: getAssetsRoot(), harnessedVersion: package_default.version },
|
|
7128
|
+
null,
|
|
7129
|
+
2
|
|
7130
|
+
)}
|
|
7131
|
+
`;
|
|
7132
|
+
const targets = [
|
|
7133
|
+
...rendered.files.map((f) => ({
|
|
7134
|
+
target: join(paths.marketplaceRoot, f.path),
|
|
7135
|
+
content: f.content
|
|
7136
|
+
})),
|
|
7137
|
+
// fallback copy beside the shim (the cached plugin copy) — ${PLUGIN_DATA} wins
|
|
7138
|
+
{ target: join(paths.pluginDir, "install.json"), content: info },
|
|
7139
|
+
{
|
|
7140
|
+
target: paths.marketplaceJson,
|
|
7141
|
+
content: `${JSON.stringify(codexMarketplaceJson([...others, paths.pluginName]), null, 2)}
|
|
7142
|
+
`
|
|
7143
|
+
},
|
|
7144
|
+
{ target: join(paths.dataDir, "install.json"), content: info }
|
|
7145
|
+
];
|
|
7146
|
+
const plan = {
|
|
7147
|
+
files: await Promise.all(
|
|
7148
|
+
targets.map(async (t2) => ({
|
|
7149
|
+
target: t2.target,
|
|
7150
|
+
scope: "HOME",
|
|
7151
|
+
oldText: await readOr(t2.target),
|
|
7152
|
+
newText: t2.content
|
|
7153
|
+
}))
|
|
7154
|
+
)
|
|
7155
|
+
};
|
|
7156
|
+
const changed = plan.files.filter((f) => f.oldText !== f.newText);
|
|
7157
|
+
if (changed.length === 0 && !ctx.opts.dryRun && ctx.opts.updateInstalled !== true) {
|
|
7158
|
+
if (await isCodexPluginInstalled(paths.pluginId)) {
|
|
7159
|
+
await recordObservedInstall(ctx.cwd, name, "", "");
|
|
7160
|
+
const trustPending = await ensureTrust(ctx, paths.pluginId);
|
|
7161
|
+
return {
|
|
7162
|
+
ok: true,
|
|
7163
|
+
alreadyInstalled: true,
|
|
7164
|
+
backupId: "idempotent-skip",
|
|
7165
|
+
...trustPending ? { trustPending } : {}
|
|
7166
|
+
};
|
|
7167
|
+
}
|
|
7168
|
+
}
|
|
7169
|
+
if (!ctx.opts.quiet) process.stdout.write(renderDiff({ files: changed }, ctx));
|
|
7170
|
+
const conf = await confirmAt("L3", { ...ctx});
|
|
7171
|
+
if (!conf.proceed) {
|
|
7172
|
+
return {
|
|
7173
|
+
aborted: true,
|
|
7174
|
+
reason: conf.reason === "flag-missing" ? "level-flag-missing" : "user-cancel"
|
|
7175
|
+
};
|
|
7176
|
+
}
|
|
7177
|
+
if (ctx.opts.dryRun) return { aborted: true, reason: "user-cancel" };
|
|
7178
|
+
return withCodexPluginLock(async () => {
|
|
7179
|
+
const bk = await backup({ files: changed }, ctx);
|
|
7180
|
+
if (!bk.ok) return { ok: false, phase: "preflight", error: bk.error };
|
|
7181
|
+
for (const f of changed) {
|
|
7182
|
+
await mkdir(dirname(f.target), { recursive: true });
|
|
7183
|
+
await writeFile(f.target, f.newText);
|
|
7184
|
+
}
|
|
7185
|
+
const cwd = getMcpSpawnCwd();
|
|
7186
|
+
const steps = [
|
|
7187
|
+
["plugin", "marketplace", "add", paths.marketplaceRoot],
|
|
7188
|
+
["plugin", "add", paths.pluginId]
|
|
7189
|
+
];
|
|
7190
|
+
for (const args of steps) {
|
|
7191
|
+
const r = await runHarnessArgs("codex", args, cwd, 6e4);
|
|
7192
|
+
if (r.exitCode !== 0) {
|
|
7193
|
+
invalidateCodexPluginCache();
|
|
7194
|
+
return {
|
|
7195
|
+
ok: false,
|
|
7196
|
+
phase: "spawn",
|
|
7197
|
+
backupId: bk.backupId,
|
|
7198
|
+
error: err(
|
|
7199
|
+
ctx,
|
|
7200
|
+
"/spec/install/hook_command",
|
|
7201
|
+
formatSpawnFail(`codex ${args.slice(0, -1).join(" ")}`, r.exitCode, r.stdout, r.stderr),
|
|
7202
|
+
"install-failed"
|
|
7203
|
+
)
|
|
7204
|
+
};
|
|
7205
|
+
}
|
|
7206
|
+
}
|
|
7207
|
+
invalidateCodexPluginCache();
|
|
7208
|
+
if (!await isCodexPluginInstalled(paths.pluginId)) {
|
|
7209
|
+
return {
|
|
7210
|
+
ok: false,
|
|
7211
|
+
phase: "verify",
|
|
7212
|
+
backupId: bk.backupId,
|
|
7213
|
+
error: err(
|
|
7214
|
+
ctx,
|
|
7215
|
+
"/spec/install/hook_command",
|
|
7216
|
+
`verify: ${paths.pluginId} not listed as installed by \`codex plugin list\` after add`,
|
|
7217
|
+
"verify-failed"
|
|
7218
|
+
)
|
|
7219
|
+
};
|
|
7220
|
+
}
|
|
7221
|
+
const trustPending = await ensureTrust(ctx, paths.pluginId);
|
|
7222
|
+
await updateInstalled(ctx.cwd, name, "", "");
|
|
7223
|
+
return {
|
|
7224
|
+
ok: true,
|
|
7225
|
+
backupId: bk.backupId,
|
|
7226
|
+
appliedFiles: changed.map((f) => f.target),
|
|
7227
|
+
...trustPending ? { trustPending } : {}
|
|
7228
|
+
};
|
|
7229
|
+
});
|
|
7230
|
+
}
|
|
7231
|
+
async function removeIfEmpty(dir) {
|
|
7232
|
+
try {
|
|
7233
|
+
if ((await readdir(dir)).length === 0) await rm(dir, { recursive: true, force: true });
|
|
7234
|
+
} catch {
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
async function removeCodexHook(manifestName, hookEvent) {
|
|
7238
|
+
const paths = codexHookPaths(resolveCodexHome(), manifestName);
|
|
7239
|
+
return withCodexPluginLock(async () => {
|
|
7240
|
+
const cwd = getMcpSpawnCwd();
|
|
7241
|
+
const keys = /* @__PURE__ */ new Set([codexHookTrustKey(paths.pluginName, hookEvent)]);
|
|
7242
|
+
const listed = await listCodexHooks();
|
|
7243
|
+
if (listed.ok) {
|
|
7244
|
+
for (const h of listed.value) if (h.key.startsWith(`${paths.pluginId}:`)) keys.add(h.key);
|
|
7245
|
+
}
|
|
7246
|
+
if (await isCodexPluginInstalled(paths.pluginId)) {
|
|
7247
|
+
const r = await runHarnessArgs("codex", ["plugin", "remove", paths.pluginId], cwd, 6e4);
|
|
7248
|
+
invalidateCodexPluginCache();
|
|
7249
|
+
if (r.exitCode !== 0)
|
|
7250
|
+
return {
|
|
7251
|
+
ok: false,
|
|
7252
|
+
error: formatSpawnFail("codex plugin remove", r.exitCode, r.stdout, r.stderr)
|
|
7253
|
+
};
|
|
7254
|
+
}
|
|
7255
|
+
await removeIfEmpty(paths.cacheMarketplaceDir);
|
|
7256
|
+
await untrustCodexHooks([...keys]);
|
|
7257
|
+
const removed = [];
|
|
7258
|
+
for (const dir of [paths.pluginDir, paths.dataDir]) {
|
|
7259
|
+
if (existsSync(dir)) {
|
|
7260
|
+
await rm(dir, { recursive: true, force: true });
|
|
7261
|
+
removed.push(dir);
|
|
7262
|
+
}
|
|
7263
|
+
}
|
|
7264
|
+
const remaining = await harnessedPluginDirs(paths.pluginsDir);
|
|
7265
|
+
if (remaining.length > 0) {
|
|
7266
|
+
await writeFile(
|
|
7267
|
+
paths.marketplaceJson,
|
|
7268
|
+
`${JSON.stringify(codexMarketplaceJson(remaining), null, 2)}
|
|
7269
|
+
`
|
|
7270
|
+
);
|
|
7271
|
+
} else if (existsSync(paths.marketplaceRoot)) {
|
|
7272
|
+
const r = await runHarnessArgs(
|
|
7273
|
+
"codex",
|
|
7274
|
+
["plugin", "marketplace", "remove", CODEX_HOOK_MARKETPLACE],
|
|
7275
|
+
cwd,
|
|
7276
|
+
6e4
|
|
7277
|
+
);
|
|
7278
|
+
if (r.exitCode !== 0 && !/not configured/i.test(`${r.stdout}${r.stderr}`))
|
|
7279
|
+
return {
|
|
7280
|
+
ok: false,
|
|
7281
|
+
error: formatSpawnFail("codex plugin marketplace remove", r.exitCode, r.stdout, r.stderr)
|
|
7282
|
+
};
|
|
7283
|
+
await rm(paths.marketplaceRoot, { recursive: true, force: true });
|
|
7284
|
+
removed.push(paths.marketplaceRoot);
|
|
7285
|
+
}
|
|
7286
|
+
return { ok: true, removedPaths: removed };
|
|
7287
|
+
});
|
|
7288
|
+
}
|
|
7289
|
+
var TRUST_HINT;
|
|
7290
|
+
var init_codexHookAdd = __esm({
|
|
7291
|
+
"src/installers/codexHookAdd.ts"() {
|
|
7292
|
+
init_package();
|
|
7293
|
+
init_security();
|
|
7294
|
+
init_assetsRoot();
|
|
7295
|
+
init_platform();
|
|
7296
|
+
init_backup();
|
|
7297
|
+
init_codexHookPlugin();
|
|
7298
|
+
init_codexHookTrust();
|
|
7299
|
+
init_codexPlugins();
|
|
7300
|
+
init_confirm();
|
|
7301
|
+
init_diff();
|
|
7302
|
+
init_err();
|
|
7303
|
+
init_runClaudeArgs();
|
|
7304
|
+
init_safeCwd();
|
|
7305
|
+
init_state2();
|
|
7306
|
+
init_verifyMessage();
|
|
7307
|
+
TRUST_HINT = (name) => `codex hooks installed but NOT trusted yet \u2014 codex skips untrusted hooks. Re-run \`harnessed install ${name} --trust-codex-hooks\`, or trust them in codex's hook review.`;
|
|
7308
|
+
}
|
|
7309
|
+
});
|
|
7310
|
+
|
|
7311
|
+
// src/cli/lib/check-codex-hooks.ts
|
|
7312
|
+
var check_codex_hooks_exports = {};
|
|
7313
|
+
__export(check_codex_hooks_exports, {
|
|
7314
|
+
checkCodexHooks: () => checkCodexHooks
|
|
7315
|
+
});
|
|
7316
|
+
function defaultDeps4() {
|
|
7317
|
+
const codexHome = resolveCodexHome();
|
|
7318
|
+
return {
|
|
7319
|
+
platformId: detectPlatform().id,
|
|
7320
|
+
codexHome,
|
|
7321
|
+
join: join,
|
|
7322
|
+
pluginDirs: async () => {
|
|
7323
|
+
try {
|
|
7324
|
+
return (await readdir(join(codexHome, "harnessed", "marketplace", "plugins"))).filter(
|
|
7325
|
+
(n) => n.startsWith("harnessed-")
|
|
7326
|
+
);
|
|
7327
|
+
} catch {
|
|
7328
|
+
return [];
|
|
7329
|
+
}
|
|
7330
|
+
},
|
|
7331
|
+
installedPlugins: listInstalledCodexPlugins,
|
|
7332
|
+
listHooks: () => listCodexHooks(),
|
|
7333
|
+
readText: (p8) => {
|
|
7334
|
+
try {
|
|
7335
|
+
return readFileSync(p8, "utf8");
|
|
7336
|
+
} catch {
|
|
7337
|
+
return null;
|
|
7338
|
+
}
|
|
7339
|
+
},
|
|
7340
|
+
exists: existsSync,
|
|
7341
|
+
onPath: (bin) => binaryOnPath(bin)
|
|
7342
|
+
};
|
|
7343
|
+
}
|
|
7344
|
+
function hookIdOf(d, pluginName) {
|
|
7345
|
+
const raw = d.readText(
|
|
7346
|
+
d.join(d.codexHome, "harnessed", "marketplace", "plugins", pluginName, "hooks", "hooks.json")
|
|
7347
|
+
);
|
|
7348
|
+
let command = "";
|
|
7349
|
+
try {
|
|
7350
|
+
const hooks = JSON.parse(raw ?? "{}").hooks ?? {};
|
|
7351
|
+
const group = Object.values(hooks)[0]?.[0];
|
|
7352
|
+
command = group?.hooks?.[0]?.command ?? "";
|
|
7353
|
+
} catch {
|
|
7354
|
+
return null;
|
|
7355
|
+
}
|
|
7356
|
+
const m = command.match(/(?:hook\.cjs"|^harnessed) ([a-z][a-z-]*)/);
|
|
7357
|
+
return m?.[1] ?? null;
|
|
7358
|
+
}
|
|
7359
|
+
function chainProblem(d, pluginName, id) {
|
|
7360
|
+
const infoPath = d.join(
|
|
7361
|
+
d.codexHome,
|
|
7362
|
+
"plugins",
|
|
7363
|
+
"data",
|
|
7364
|
+
`${pluginName}-${CODEX_HOOK_MARKETPLACE}`,
|
|
7365
|
+
"install.json"
|
|
7366
|
+
);
|
|
7367
|
+
let info = null;
|
|
7368
|
+
try {
|
|
7369
|
+
info = JSON.parse(d.readText(infoPath) ?? "null");
|
|
7370
|
+
} catch {
|
|
7371
|
+
info = null;
|
|
7372
|
+
}
|
|
7373
|
+
if (!info || typeof info.assetsRoot !== "string") return "shim: install.json missing";
|
|
7374
|
+
if (info.mode === "binary")
|
|
7375
|
+
return d.onPath("harnessed") ? null : "`harnessed` not on PATH (binary-mode hook command)";
|
|
7376
|
+
const bin = id ? d.join(info.assetsRoot, "bin", `harnessed-${id}.mjs`) : null;
|
|
7377
|
+
const cli = d.join(info.assetsRoot, "dist", "cli.mjs");
|
|
7378
|
+
return bin && d.exists(bin) || d.exists(cli) ? null : `shim: no entry under ${info.assetsRoot}`;
|
|
7379
|
+
}
|
|
7380
|
+
async function checkCodexHooks(deps) {
|
|
7381
|
+
const d = { ...defaultDeps4(), ...deps };
|
|
7382
|
+
if (d.platformId !== "codex")
|
|
7383
|
+
return { name: NAME6, status: "pass", message: `not codex (${d.platformId}) \u2014 skipped` };
|
|
7384
|
+
const plugins = await d.pluginDirs();
|
|
7385
|
+
if (plugins.length === 0)
|
|
7386
|
+
return { name: NAME6, status: "pass", message: "no harnessed codex hook plugins installed" };
|
|
7387
|
+
const [installed, listed] = await Promise.all([d.installedPlugins(), d.listHooks()]);
|
|
7388
|
+
const problems = [];
|
|
7389
|
+
const fixes = [];
|
|
7390
|
+
const ok = [];
|
|
7391
|
+
for (const pluginName of plugins.sort()) {
|
|
7392
|
+
const manifest = pluginName.replace(/^harnessed-/, "");
|
|
7393
|
+
const pluginId = `${pluginName}@${CODEX_HOOK_MARKETPLACE}`;
|
|
7394
|
+
const issues = [];
|
|
7395
|
+
if (installed && !installed.has(pluginId)) issues.push("not installed in codex");
|
|
7396
|
+
const hooks = listed.ok ? listed.value.filter((h) => h.key.startsWith(`${pluginId}:`)) : [];
|
|
7397
|
+
const trust = !listed.ok ? "unknown" : hooks.length === 0 ? "unknown" : hooks.find((h) => h.trustStatus !== "trusted")?.trustStatus ?? "trusted";
|
|
7398
|
+
if (trust !== "trusted") issues.push(`trust: ${trust}`);
|
|
7399
|
+
const chain = chainProblem(d, pluginName, hookIdOf(d, pluginName));
|
|
7400
|
+
if (chain) issues.push(chain);
|
|
7401
|
+
if (issues.length === 0) ok.push(manifest);
|
|
7402
|
+
else {
|
|
7403
|
+
problems.push(`${manifest} (${issues.join("; ")})`);
|
|
7404
|
+
fixes.push(`harnessed install ${manifest} --trust-codex-hooks`);
|
|
7405
|
+
}
|
|
7406
|
+
}
|
|
7407
|
+
if (problems.length === 0)
|
|
7408
|
+
return { name: NAME6, status: "pass", message: `installed + trusted: ${ok.join(", ")}` };
|
|
7409
|
+
return {
|
|
7410
|
+
name: NAME6,
|
|
7411
|
+
status: "warn",
|
|
7412
|
+
message: `codex skips hooks that are not installed/trusted \u2014 ${problems.join(", ")}`,
|
|
7413
|
+
fix: fixes.join(" && ")
|
|
7414
|
+
};
|
|
7415
|
+
}
|
|
7416
|
+
var NAME6;
|
|
7417
|
+
var init_check_codex_hooks = __esm({
|
|
7418
|
+
"src/cli/lib/check-codex-hooks.ts"() {
|
|
7419
|
+
init_codexHookAdd();
|
|
7420
|
+
init_binaryProbe();
|
|
7421
|
+
init_codexHookPlugin();
|
|
7422
|
+
init_codexHookTrust();
|
|
7423
|
+
init_codexPlugins();
|
|
7424
|
+
init_platform();
|
|
7425
|
+
NAME6 = "codex hook plugins";
|
|
7426
|
+
}
|
|
7427
|
+
});
|
|
7428
|
+
|
|
7429
|
+
// src/cli/lib/doctor-registry.ts
|
|
7430
|
+
var CHECKS;
|
|
7431
|
+
var init_doctor_registry = __esm({
|
|
7432
|
+
"src/cli/lib/doctor-registry.ts"() {
|
|
7433
|
+
init_check_builtin();
|
|
7434
|
+
CHECKS = [
|
|
7435
|
+
async () => checkNodeVersion(),
|
|
7436
|
+
checkMcpScope,
|
|
7437
|
+
async () => checkJq(),
|
|
7438
|
+
async () => checkWinBash(),
|
|
7439
|
+
async () => {
|
|
7440
|
+
const { checkOrigin: checkOrigin2 } = await Promise.resolve().then(() => (init_origin_check(), origin_check_exports));
|
|
7441
|
+
const r = checkOrigin2(process.cwd(), { allowFork: true });
|
|
7442
|
+
return { name: "origin URL", status: r.status, message: r.detail, fix: r.fix };
|
|
7443
|
+
},
|
|
7444
|
+
async () => {
|
|
7445
|
+
const { probeGstackPrefix: probeGstackPrefix2 } = await Promise.resolve().then(() => (init_probe_gstack(), probe_gstack_exports));
|
|
7446
|
+
const r = probeGstackPrefix2();
|
|
7447
|
+
return { name: "gstack prefix", status: r.status, message: r.detail, fix: r.fix };
|
|
7448
|
+
},
|
|
7449
|
+
async () => (await Promise.resolve().then(() => (init_check_deprecations(), check_deprecations_exports))).checkDeprecations(),
|
|
7450
|
+
async () => (await Promise.resolve().then(() => (init_check_token_budget(), check_token_budget_exports))).checkTokenBudget(),
|
|
7451
|
+
async () => (await Promise.resolve().then(() => (init_check_agent_teams_doctor(), check_agent_teams_doctor_exports))).checkAgentTeamsDoctor(),
|
|
7452
|
+
async () => (await Promise.resolve().then(() => (init_check_planning_with_files(), check_planning_with_files_exports))).checkPlanningWithFiles(),
|
|
7453
|
+
async () => (await Promise.resolve().then(() => (init_check_mattpocock_skills(), check_mattpocock_skills_exports))).checkMattpocockSkills(),
|
|
7454
|
+
async () => (await Promise.resolve().then(() => (init_check_mcp_availability(), check_mcp_availability_exports))).checkMcpAvailability(),
|
|
7455
|
+
// Phase 18 — opt-in CodeGraph semantic-index detect (always 'pass'; absence of an
|
|
7456
|
+
// optional tool is not a health failure).
|
|
7457
|
+
async () => (await Promise.resolve().then(() => (init_check_codegraph(), check_codegraph_exports))).checkCodeGraph(process.cwd()),
|
|
7458
|
+
// v4.16.1 T3 — bun presence (warn-only): gstack's upstream setup hard-requires
|
|
7459
|
+
// bun; missing bun is THE gstack refresh-failure cause on user dogfood machines.
|
|
7460
|
+
async () => (await Promise.resolve().then(() => (init_check_bun(), check_bun_exports))).checkBun(),
|
|
7461
|
+
// 4.22.1 T4 — dual-guard conflict (warn-only): ECC GateGuard's filename policy
|
|
7462
|
+
// vs evidence-guard artifact contract names (subagents cannot fact-retry).
|
|
7463
|
+
async () => (await Promise.resolve().then(() => (init_check_guard_conflict(), check_guard_conflict_exports))).checkGuardConflict(),
|
|
7464
|
+
// 4.23.0 (issue #3) — installed workflow-skill integrity (warn-only): flat
|
|
7465
|
+
// ~/.claude/skills packs can silently shadow shipped workflows; setup self-heals.
|
|
7466
|
+
async () => (await Promise.resolve().then(() => (init_check_skill_integrity(), check_skill_integrity_exports))).checkSkillIntegrity(),
|
|
7467
|
+
// Phase 20 — "update available" version check ('warn' only when behind; 'pass'
|
|
7468
|
+
// when current/ahead/npm-unreachable — fail-soft, never flips the summary).
|
|
7469
|
+
async () => (await Promise.resolve().then(() => (init_check_update(), check_update_exports))).checkUpdate(),
|
|
7470
|
+
// 4.32.4 — dual install-channel conflict (warn-only): npm-global + standalone
|
|
7471
|
+
// binary both present → ambiguous PATH resolution + stale-update trap.
|
|
7472
|
+
async () => (await Promise.resolve().then(() => (init_check_install_channels(), check_install_channels_exports))).checkInstallChannels(),
|
|
7473
|
+
// issue #8 — orphaned harnessed Stop/UserPromptSubmit hooks (warn-only): a hook
|
|
7474
|
+
// pointing at a deleted bin/*.mjs makes Claude Code error MODULE_NOT_FOUND every
|
|
7475
|
+
// prompt; `harnessed uninstall` now strips them.
|
|
7476
|
+
async () => (await Promise.resolve().then(() => (init_check_stale_hooks(), check_stale_hooks_exports))).checkStaleHooks(),
|
|
7477
|
+
// 4.32.22 — ECC per-harness detect (optional; pass unless CC-side ecc overlaps
|
|
7478
|
+
// the official chrome-devtools-mcp plugin → warn). CC plugin registry + codex
|
|
7479
|
+
// sync-clone probed independently.
|
|
7480
|
+
async () => (await Promise.resolve().then(() => (init_check_ecc(), check_ecc_exports))).checkEcc(),
|
|
7481
|
+
// 4.38.0 — half-installed per-turn injection (warn-only): perturn-inject
|
|
7482
|
+
// without perturn-inject-invalidate keeps skipping <project-context> after a
|
|
7483
|
+
// compact/clear has already dropped the copy it is skipping on behalf of.
|
|
7484
|
+
async () => (await Promise.resolve().then(() => (init_check_inject_invalidate(), check_inject_invalidate_exports))).checkInjectInvalidate(),
|
|
7485
|
+
// Phase 56 — silently stale marketplace plugins (warn-only): `claude plugin
|
|
7486
|
+
// install` pins a version into a versioned cache dir and never re-resolves, so
|
|
7487
|
+
// the four cc-plugin-marketplace components drift behind without any signal.
|
|
7488
|
+
// The only comparison in the codebase between a genuinely DETECTED version and
|
|
6400
7489
|
// a recorded one — see the header for why the installer-state layer cannot do it.
|
|
6401
7490
|
async () => (await Promise.resolve().then(() => (init_check_plugin_staleness(), check_plugin_staleness_exports))).checkPluginStaleness(),
|
|
6402
7491
|
// Phase 60 — HARNESSED_OFF left on (warn-only): the kill switch silences every
|
|
6403
7492
|
// first-party hook, so a machine that forgot to unset it looks exactly like a
|
|
6404
7493
|
// broken install. doctor is where that gets said out loud.
|
|
6405
|
-
async () => (await Promise.resolve().then(() => (init_check_ablation(), check_ablation_exports))).checkAblation()
|
|
7494
|
+
async () => (await Promise.resolve().then(() => (init_check_ablation(), check_ablation_exports))).checkAblation(),
|
|
7495
|
+
// v16.0 Phase 64 (ADR 0041) — codex hook plugins (warn-only): codex silently
|
|
7496
|
+
// skips an untrusted / modified hook, so "installed" is not "running". Skipped
|
|
7497
|
+
// (pass) on every non-codex platform.
|
|
7498
|
+
async () => (await Promise.resolve().then(() => (init_check_codex_hooks(), check_codex_hooks_exports))).checkCodexHooks()
|
|
6406
7499
|
];
|
|
6407
7500
|
}
|
|
6408
7501
|
});
|
|
@@ -7006,13 +8099,13 @@ async function gcCompiledArtifacts(opts) {
|
|
|
7006
8099
|
const assetsDir = join(opts.stateRoot, "assets");
|
|
7007
8100
|
for (const e of await readdir(assetsDir, { withFileTypes: true })) {
|
|
7008
8101
|
if (!e.isDirectory()) continue;
|
|
7009
|
-
const
|
|
8102
|
+
const p8 = join(assetsDir, e.name);
|
|
7010
8103
|
if (keep.has(e.name)) {
|
|
7011
|
-
kept.push(
|
|
8104
|
+
kept.push(p8);
|
|
7012
8105
|
continue;
|
|
7013
8106
|
}
|
|
7014
|
-
removed.push(
|
|
7015
|
-
if (!opts.dryRun) await rm(
|
|
8107
|
+
removed.push(p8);
|
|
8108
|
+
if (!opts.dryRun) await rm(p8, { recursive: true, force: true });
|
|
7016
8109
|
}
|
|
7017
8110
|
} catch {
|
|
7018
8111
|
}
|
|
@@ -7020,9 +8113,9 @@ async function gcCompiledArtifacts(opts) {
|
|
|
7020
8113
|
const backupDir = join(opts.stateRoot, "bin-backup");
|
|
7021
8114
|
const vers = (await readdir(backupDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name).sort(byVersion);
|
|
7022
8115
|
for (const v of vers.slice(0, -1)) {
|
|
7023
|
-
const
|
|
7024
|
-
removed.push(
|
|
7025
|
-
if (!opts.dryRun) await rm(
|
|
8116
|
+
const p8 = join(backupDir, v);
|
|
8117
|
+
removed.push(p8);
|
|
8118
|
+
if (!opts.dryRun) await rm(p8, { recursive: true, force: true });
|
|
7026
8119
|
}
|
|
7027
8120
|
const newest = vers[vers.length - 1];
|
|
7028
8121
|
if (newest) kept.push(join(backupDir, newest));
|
|
@@ -7034,9 +8127,9 @@ async function gcCompiledArtifacts(opts) {
|
|
|
7034
8127
|
const base = basename(opts.execPath);
|
|
7035
8128
|
for (const e of await readdir(dir, { withFileTypes: true })) {
|
|
7036
8129
|
if (!e.isFile() || !e.name.startsWith(`${base}.bak-`)) continue;
|
|
7037
|
-
const
|
|
7038
|
-
removed.push(
|
|
7039
|
-
if (!opts.dryRun) await rm(
|
|
8130
|
+
const p8 = join(dir, e.name);
|
|
8131
|
+
removed.push(p8);
|
|
8132
|
+
if (!opts.dryRun) await rm(p8, { force: true });
|
|
7040
8133
|
}
|
|
7041
8134
|
} catch {
|
|
7042
8135
|
}
|
|
@@ -7059,10 +8152,10 @@ async function dirSizeKb(dir) {
|
|
|
7059
8152
|
if (!cur) break;
|
|
7060
8153
|
const entries = await readdir(cur, { withFileTypes: true });
|
|
7061
8154
|
for (const e of entries) {
|
|
7062
|
-
const
|
|
7063
|
-
if (e.isDirectory()) stack.push(
|
|
8155
|
+
const p8 = join(cur, e.name);
|
|
8156
|
+
if (e.isDirectory()) stack.push(p8);
|
|
7064
8157
|
else if (e.isFile()) {
|
|
7065
|
-
const st = await stat(
|
|
8158
|
+
const st = await stat(p8);
|
|
7066
8159
|
total += st.size;
|
|
7067
8160
|
}
|
|
7068
8161
|
}
|
|
@@ -7140,7 +8233,7 @@ ${t("gc.invalid_duration.fix")}`
|
|
|
7140
8233
|
console.log(
|
|
7141
8234
|
` compiled artifacts ${dryRun ? "to remove" : "removed"}: ${r.removed.length}`
|
|
7142
8235
|
);
|
|
7143
|
-
for (const
|
|
8236
|
+
for (const p8 of r.removed) console.log(` ${p8}`);
|
|
7144
8237
|
}
|
|
7145
8238
|
}
|
|
7146
8239
|
} catch {
|
|
@@ -7148,118 +8241,13 @@ ${t("gc.invalid_duration.fix")}`
|
|
|
7148
8241
|
});
|
|
7149
8242
|
}
|
|
7150
8243
|
var DURATION_RE;
|
|
7151
|
-
var init_gc = __esm({
|
|
7152
|
-
"src/cli/gc.ts"() {
|
|
7153
|
-
init_package();
|
|
7154
|
-
init_i18n();
|
|
7155
|
-
init_backup();
|
|
7156
|
-
init_version_check();
|
|
7157
|
-
DURATION_RE = /^(\d+)([dhmw])$/;
|
|
7158
|
-
}
|
|
7159
|
-
});
|
|
7160
|
-
async function confirmAt(level, ctx) {
|
|
7161
|
-
if (level === "L4" && !ctx.opts.system) {
|
|
7162
|
-
if (!ctx.opts.nonInteractive) {
|
|
7163
|
-
p.note(
|
|
7164
|
-
"this method requires --system flag (e.g. global npm install affects machine PATH); pass --system to opt in.",
|
|
7165
|
-
"L4 system-wide install"
|
|
7166
|
-
);
|
|
7167
|
-
}
|
|
7168
|
-
return { proceed: false, reason: "flag-missing" };
|
|
7169
|
-
}
|
|
7170
|
-
if (ctx.opts.nonInteractive) {
|
|
7171
|
-
return { proceed: ctx.opts.apply };
|
|
7172
|
-
}
|
|
7173
|
-
if (level === "L1") {
|
|
7174
|
-
p.note("will write project-local files only (safe scope).", "L1 confirm");
|
|
7175
|
-
return { proceed: true };
|
|
7176
|
-
}
|
|
7177
|
-
if (level === "L2") {
|
|
7178
|
-
const ans2 = await p.confirm({ message: "Proceed with install?", initialValue: false });
|
|
7179
|
-
if (p.isCancel(ans2)) return { proceed: false, reason: "user-cancel" };
|
|
7180
|
-
return { proceed: ans2 === true };
|
|
7181
|
-
}
|
|
7182
|
-
if (level === "L3") {
|
|
7183
|
-
const first = await p.confirm({ message: "Proceed with install?", initialValue: false });
|
|
7184
|
-
if (p.isCancel(first)) return { proceed: false, reason: "user-cancel" };
|
|
7185
|
-
if (first !== true) return { proceed: false };
|
|
7186
|
-
const second = await p.confirm({
|
|
7187
|
-
// v4.14.0 — wording generalized: the shared user-scope config is
|
|
7188
|
-
// ~/.claude.json on claude, ~/.codex/config.toml on codex.
|
|
7189
|
-
message: "This affects other plugins (the harness user-scope config is shared state). Confirm again?",
|
|
7190
|
-
initialValue: false
|
|
7191
|
-
});
|
|
7192
|
-
if (p.isCancel(second)) return { proceed: false, reason: "user-cancel" };
|
|
7193
|
-
return { proceed: second === true };
|
|
7194
|
-
}
|
|
7195
|
-
const ans = await p.confirm({
|
|
7196
|
-
message: "System-wide install will modify global PATH. Proceed?",
|
|
7197
|
-
initialValue: false
|
|
7198
|
-
});
|
|
7199
|
-
if (p.isCancel(ans)) return { proceed: false, reason: "user-cancel" };
|
|
7200
|
-
return { proceed: ans === true };
|
|
7201
|
-
}
|
|
7202
|
-
var init_confirm = __esm({
|
|
7203
|
-
"src/installers/lib/confirm.ts"() {
|
|
7204
|
-
}
|
|
7205
|
-
});
|
|
7206
|
-
function colorize(line) {
|
|
7207
|
-
if (!pc.isColorSupported) return line;
|
|
7208
|
-
if (line.startsWith("+") && !line.startsWith("+++")) return pc.green(line);
|
|
7209
|
-
if (line.startsWith("-") && !line.startsWith("---")) return pc.red(line);
|
|
7210
|
-
if (line.startsWith("@@")) return pc.cyan(line);
|
|
7211
|
-
return line;
|
|
7212
|
-
}
|
|
7213
|
-
function diffOneFile(file) {
|
|
7214
|
-
const patch = createPatch(file.target, file.oldText, file.newText, "", "", {
|
|
7215
|
-
stripTrailingCr: true
|
|
7216
|
-
});
|
|
7217
|
-
const lines = patch.split("\n");
|
|
7218
|
-
let added = 0;
|
|
7219
|
-
let removed = 0;
|
|
7220
|
-
for (const ln of lines) {
|
|
7221
|
-
if (ln.startsWith("+") && !ln.startsWith("+++")) added++;
|
|
7222
|
-
else if (ln.startsWith("-") && !ln.startsWith("---")) removed++;
|
|
7223
|
-
}
|
|
7224
|
-
return { lines, added, removed };
|
|
7225
|
-
}
|
|
7226
|
-
function renderDiff(plan, ctx) {
|
|
7227
|
-
if (plan.files.length === 0) return "(no file changes)\n";
|
|
7228
|
-
const out = [];
|
|
7229
|
-
let totalAdded = 0;
|
|
7230
|
-
let totalRemoved = 0;
|
|
7231
|
-
for (const file of plan.files) {
|
|
7232
|
-
const { lines, added, removed } = diffOneFile(file);
|
|
7233
|
-
totalAdded += added;
|
|
7234
|
-
totalRemoved += removed;
|
|
7235
|
-
const folded = !ctx.opts.fullDiff && lines.length > FOLD_THRESHOLD;
|
|
7236
|
-
const visible = folded ? lines.slice(0, FOLD_HEAD) : lines;
|
|
7237
|
-
for (const ln of visible) out.push(colorize(ln));
|
|
7238
|
-
if (folded) {
|
|
7239
|
-
const more = lines.length - FOLD_HEAD;
|
|
7240
|
-
out.push(pc.dim(`... ${more} more lines (use --full-diff to expand)`));
|
|
7241
|
-
}
|
|
7242
|
-
}
|
|
7243
|
-
const summary = `will modify ${plan.files.length} file${plan.files.length === 1 ? "" : "s"} (${totalAdded} added, ${totalRemoved} removed)`;
|
|
7244
|
-
out.push("");
|
|
7245
|
-
out.push(pc.bold(summary));
|
|
7246
|
-
return `${out.join("\n")}
|
|
7247
|
-
`;
|
|
7248
|
-
}
|
|
7249
|
-
var FOLD_THRESHOLD, FOLD_HEAD;
|
|
7250
|
-
var init_diff = __esm({
|
|
7251
|
-
"src/installers/lib/diff.ts"() {
|
|
7252
|
-
FOLD_THRESHOLD = 200;
|
|
7253
|
-
FOLD_HEAD = 100;
|
|
7254
|
-
}
|
|
7255
|
-
});
|
|
7256
|
-
|
|
7257
|
-
// src/installers/lib/err.ts
|
|
7258
|
-
function err(ctx, path, message, keyword) {
|
|
7259
|
-
return { file: ctx.manifest.metadata.name, path, message, line: null, column: null, keyword };
|
|
7260
|
-
}
|
|
7261
|
-
var init_err = __esm({
|
|
7262
|
-
"src/installers/lib/err.ts"() {
|
|
8244
|
+
var init_gc = __esm({
|
|
8245
|
+
"src/cli/gc.ts"() {
|
|
8246
|
+
init_package();
|
|
8247
|
+
init_i18n();
|
|
8248
|
+
init_backup();
|
|
8249
|
+
init_version_check();
|
|
8250
|
+
DURATION_RE = /^(\d+)([dhmw])$/;
|
|
7263
8251
|
}
|
|
7264
8252
|
});
|
|
7265
8253
|
|
|
@@ -7314,74 +8302,13 @@ var init_preflight = __esm({
|
|
|
7314
8302
|
GIT_REF_SHAPE = /^([a-f0-9]{7,40}|v?\d+\.\d+\.\d+([.-][\w.-]+)?)$/;
|
|
7315
8303
|
}
|
|
7316
8304
|
});
|
|
7317
|
-
function statePath2(_cwd) {
|
|
7318
|
-
return harnessedFile("state.json");
|
|
7319
|
-
}
|
|
7320
|
-
async function readState(cwd) {
|
|
7321
|
-
const path = statePath2();
|
|
7322
|
-
let raw;
|
|
7323
|
-
try {
|
|
7324
|
-
raw = await readFile(path, "utf8");
|
|
7325
|
-
} catch (err2) {
|
|
7326
|
-
if (err2.code === "ENOENT") {
|
|
7327
|
-
return { ...DEFAULT_STATE, installed: {} };
|
|
7328
|
-
}
|
|
7329
|
-
throw err2;
|
|
7330
|
-
}
|
|
7331
|
-
try {
|
|
7332
|
-
const parsed = JSON.parse(raw);
|
|
7333
|
-
if (parsed.version !== "1" || typeof parsed.installed !== "object") {
|
|
7334
|
-
return { ...DEFAULT_STATE, installed: {} };
|
|
7335
|
-
}
|
|
7336
|
-
return parsed;
|
|
7337
|
-
} catch {
|
|
7338
|
-
return { ...DEFAULT_STATE, installed: {} };
|
|
7339
|
-
}
|
|
7340
|
-
}
|
|
7341
|
-
async function writeState(cwd, state) {
|
|
7342
|
-
const path = statePath2();
|
|
7343
|
-
const tmp = `${path}.tmp`;
|
|
7344
|
-
await mkdir(dirname(path), { recursive: true });
|
|
7345
|
-
await writeFile(tmp, `${JSON.stringify(state, null, 2)}
|
|
7346
|
-
`, "utf8");
|
|
7347
|
-
await rename(tmp, path);
|
|
7348
|
-
}
|
|
7349
|
-
async function updateInstalled(cwd, name, version, manifestSha1) {
|
|
7350
|
-
const state = await readState();
|
|
7351
|
-
state.installed[name] = {
|
|
7352
|
-
version,
|
|
7353
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7354
|
-
manifestSha1
|
|
7355
|
-
};
|
|
7356
|
-
await writeState(cwd, state);
|
|
7357
|
-
}
|
|
7358
|
-
async function recordObservedInstall(cwd, name, version, manifestSha1) {
|
|
7359
|
-
try {
|
|
7360
|
-
const state = await readState(cwd);
|
|
7361
|
-
const prev = state.installed[name];
|
|
7362
|
-
if (prev && prev.version === version && prev.manifestSha1 === manifestSha1) return;
|
|
7363
|
-
state.installed[name] = {
|
|
7364
|
-
version,
|
|
7365
|
-
installedAt: prev?.installedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
7366
|
-
manifestSha1
|
|
7367
|
-
};
|
|
7368
|
-
await writeState(cwd, state);
|
|
7369
|
-
} catch {
|
|
7370
|
-
}
|
|
7371
|
-
}
|
|
7372
|
-
var DEFAULT_STATE;
|
|
7373
|
-
var init_state2 = __esm({
|
|
7374
|
-
"src/installers/lib/state.ts"() {
|
|
7375
|
-
init_harnessedRoot();
|
|
7376
|
-
DEFAULT_STATE = { version: "1", installed: {} };
|
|
7377
|
-
}
|
|
7378
|
-
});
|
|
7379
8305
|
var installCcHookAdd;
|
|
7380
8306
|
var init_ccHookAdd2 = __esm({
|
|
7381
8307
|
"src/installers/ccHookAdd.ts"() {
|
|
7382
8308
|
init_security();
|
|
7383
8309
|
init_assetsRoot();
|
|
7384
8310
|
init_platform();
|
|
8311
|
+
init_codexHookAdd();
|
|
7385
8312
|
init_backup();
|
|
7386
8313
|
init_confirm();
|
|
7387
8314
|
init_diff();
|
|
@@ -7410,7 +8337,9 @@ var init_ccHookAdd2 = __esm({
|
|
|
7410
8337
|
const e = pre.errors[0] ?? err(ctx, "/", "preflight failed", "preflight");
|
|
7411
8338
|
return { ok: false, phase: "preflight", error: e };
|
|
7412
8339
|
}
|
|
8340
|
+
if (detectPlatform().id === "codex") return installCodexHook(ctx);
|
|
7413
8341
|
const settingsPath = getSettingsPath();
|
|
8342
|
+
if (settingsPath === null) return { aborted: true, reason: "platform-mismatch" };
|
|
7414
8343
|
let existing;
|
|
7415
8344
|
try {
|
|
7416
8345
|
existing = await readFile(settingsPath, "utf8");
|
|
@@ -7610,56 +8539,17 @@ var init_gitCloneArgs = __esm({
|
|
|
7610
8539
|
CLAUSE_END = /* @__PURE__ */ new Set(["&&", ";", "|", "||"]);
|
|
7611
8540
|
}
|
|
7612
8541
|
});
|
|
7613
|
-
function descendantsOf(pid) {
|
|
7614
|
-
const r = spawnSync("pgrep", ["-P", String(pid)], { encoding: "utf8", timeout: 2e3 });
|
|
7615
|
-
if (r.status !== 0 || typeof r.stdout !== "string") return [];
|
|
7616
|
-
const out = [];
|
|
7617
|
-
for (const tok2 of r.stdout.split(/\s+/)) {
|
|
7618
|
-
const child = Number(tok2);
|
|
7619
|
-
if (Number.isInteger(child) && child > 0) out.push(child, ...descendantsOf(child));
|
|
7620
|
-
}
|
|
7621
|
-
return out;
|
|
7622
|
-
}
|
|
7623
|
-
function killProcessTree(child) {
|
|
7624
|
-
const pid = child.pid;
|
|
7625
|
-
if (pid === void 0) {
|
|
7626
|
-
child.kill("SIGKILL");
|
|
7627
|
-
return;
|
|
7628
|
-
}
|
|
7629
|
-
if (process.platform === "win32") {
|
|
7630
|
-
const r = spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
7631
|
-
windowsHide: true,
|
|
7632
|
-
stdio: "ignore",
|
|
7633
|
-
timeout: 5e3
|
|
7634
|
-
});
|
|
7635
|
-
if (r.status === 0) return;
|
|
7636
|
-
child.kill("SIGKILL");
|
|
7637
|
-
return;
|
|
7638
|
-
}
|
|
7639
|
-
const tree = descendantsOf(pid);
|
|
7640
|
-
child.kill("SIGKILL");
|
|
7641
|
-
for (const d of tree) {
|
|
7642
|
-
try {
|
|
7643
|
-
process.kill(d, "SIGKILL");
|
|
7644
|
-
} catch {
|
|
7645
|
-
}
|
|
7646
|
-
}
|
|
7647
|
-
}
|
|
7648
|
-
var init_killTree = __esm({
|
|
7649
|
-
"src/installers/lib/killTree.ts"() {
|
|
7650
|
-
}
|
|
7651
|
-
});
|
|
7652
8542
|
function evalClause(clause, home) {
|
|
7653
8543
|
const m = clause.match(CLAUSE_RE);
|
|
7654
8544
|
if (!m?.[1] || !m[2]) return null;
|
|
7655
8545
|
const flag = m[1];
|
|
7656
|
-
let
|
|
7657
|
-
if (UNSAFE_PATH_RE.test(
|
|
7658
|
-
if (
|
|
7659
|
-
else if (
|
|
7660
|
-
else if (
|
|
8546
|
+
let p8 = m[2];
|
|
8547
|
+
if (UNSAFE_PATH_RE.test(p8)) return null;
|
|
8548
|
+
if (p8 === "~") p8 = home;
|
|
8549
|
+
else if (p8.startsWith("~/")) p8 = `${home}/${p8.slice(2)}`;
|
|
8550
|
+
else if (p8.startsWith("~")) return null;
|
|
7661
8551
|
try {
|
|
7662
|
-
const st = statSync(
|
|
8552
|
+
const st = statSync(p8);
|
|
7663
8553
|
if (flag === "f") return st.isFile();
|
|
7664
8554
|
if (flag === "d") return st.isDirectory();
|
|
7665
8555
|
return true;
|
|
@@ -7699,29 +8589,6 @@ var init_nativeTest = __esm({
|
|
|
7699
8589
|
UNSAFE_PATH_RE = /[|&;<>()*?"'`$={}[\]]/;
|
|
7700
8590
|
}
|
|
7701
8591
|
});
|
|
7702
|
-
function getMcpSpawnCwd() {
|
|
7703
|
-
return homedir();
|
|
7704
|
-
}
|
|
7705
|
-
function getNeutralSpawnCwd() {
|
|
7706
|
-
const override = process.env.HARNESSED_SPAWN_CWD;
|
|
7707
|
-
if (override !== void 0 && override.trim().length > 0) return override.trim();
|
|
7708
|
-
try {
|
|
7709
|
-
const dir = join(detectPlatform().stateRoot, ".spawn");
|
|
7710
|
-
mkdirSync(dir, { recursive: true });
|
|
7711
|
-
const sentinel = join(dir, "package.json");
|
|
7712
|
-
if (!existsSync(sentinel)) writeFileSync(sentinel, NEUTRAL_SENTINEL, "utf8");
|
|
7713
|
-
return dir;
|
|
7714
|
-
} catch {
|
|
7715
|
-
return null;
|
|
7716
|
-
}
|
|
7717
|
-
}
|
|
7718
|
-
var NEUTRAL_SENTINEL;
|
|
7719
|
-
var init_safeCwd = __esm({
|
|
7720
|
-
"src/installers/lib/safeCwd.ts"() {
|
|
7721
|
-
init_platform();
|
|
7722
|
-
NEUTRAL_SENTINEL = '{\n "name": "harnessed-neutral-spawn",\n "private": true\n}\n';
|
|
7723
|
-
}
|
|
7724
|
-
});
|
|
7725
8592
|
function expandTildeForWindows(cmd) {
|
|
7726
8593
|
const home = homedir().replace(/\\/g, "/");
|
|
7727
8594
|
return cmd.replace(/(^|[\s"'`(])~\//g, `$1${home}/`);
|
|
@@ -7988,11 +8855,16 @@ async function isAlreadyInstalled(ctx, opts = {}) {
|
|
|
7988
8855
|
if (ctx.opts.dryRun) return false;
|
|
7989
8856
|
const installCfg = ctx.manifest.spec.install;
|
|
7990
8857
|
if (installCfg.method === "cc-hook-add") {
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
8858
|
+
if (detectPlatform().id === "codex")
|
|
8859
|
+
return isCodexPluginInstalled(codexHookPluginId(ctx.manifest.metadata.name));
|
|
8860
|
+
const settingsPath = getSettingsPath();
|
|
8861
|
+
let raw = null;
|
|
8862
|
+
if (settingsPath !== null) {
|
|
8863
|
+
try {
|
|
8864
|
+
raw = await readFile(settingsPath, "utf8");
|
|
8865
|
+
} catch {
|
|
8866
|
+
raw = null;
|
|
8867
|
+
}
|
|
7996
8868
|
}
|
|
7997
8869
|
return detectCcHookInstalled(
|
|
7998
8870
|
raw,
|
|
@@ -8021,6 +8893,8 @@ var init_idempotent = __esm({
|
|
|
8021
8893
|
init_assetsRoot();
|
|
8022
8894
|
init_platform();
|
|
8023
8895
|
init_binaryProbe();
|
|
8896
|
+
init_codexHookPlugin();
|
|
8897
|
+
init_codexPlugins();
|
|
8024
8898
|
init_gitCloneArgs();
|
|
8025
8899
|
init_hookEntry();
|
|
8026
8900
|
init_readClaudeConfig();
|
|
@@ -8032,96 +8906,6 @@ var init_idempotent = __esm({
|
|
|
8032
8906
|
};
|
|
8033
8907
|
}
|
|
8034
8908
|
});
|
|
8035
|
-
function escapeCommand(cmd) {
|
|
8036
|
-
return cmd.replace(META, "^$1");
|
|
8037
|
-
}
|
|
8038
|
-
function escapeArgument(arg, doubleEscape) {
|
|
8039
|
-
let a = `${arg}`;
|
|
8040
|
-
a = a.replace(/(\\*)"/g, '$1$1\\"');
|
|
8041
|
-
a = a.replace(/(\\*)$/, "$1$1");
|
|
8042
|
-
a = `"${a}"`;
|
|
8043
|
-
a = a.replace(META, "^$1");
|
|
8044
|
-
a = a.replace(META, "^$1");
|
|
8045
|
-
return a;
|
|
8046
|
-
}
|
|
8047
|
-
function resolveWindowsBin(bin, env = process.env, isFile = (p7) => existsSync(p7) && statSync(p7).isFile()) {
|
|
8048
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(";").filter(Boolean);
|
|
8049
|
-
const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
8050
|
-
const candidates = extname(bin) ? [""] : exts;
|
|
8051
|
-
for (const dir of dirs) {
|
|
8052
|
-
for (const ext of candidates) {
|
|
8053
|
-
const p7 = join40(dir, `${bin}${ext}`);
|
|
8054
|
-
if (isFile(p7)) return p7;
|
|
8055
|
-
}
|
|
8056
|
-
}
|
|
8057
|
-
return null;
|
|
8058
|
-
}
|
|
8059
|
-
function planWindowsSpawn(bin, args, resolved) {
|
|
8060
|
-
if (!resolved) return { command: bin, args, verbatim: false };
|
|
8061
|
-
const ext = extname(resolved).toLowerCase();
|
|
8062
|
-
if (ext !== ".cmd" && ext !== ".bat") {
|
|
8063
|
-
return { command: resolved, args, verbatim: false };
|
|
8064
|
-
}
|
|
8065
|
-
const line = [escapeCommand(resolved), ...args.map((a) => escapeArgument(a))].join(" ");
|
|
8066
|
-
return { command: "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], verbatim: true };
|
|
8067
|
-
}
|
|
8068
|
-
var extname, join40, META;
|
|
8069
|
-
var init_winSpawn = __esm({
|
|
8070
|
-
"src/installers/lib/winSpawn.ts"() {
|
|
8071
|
-
({ extname, join: join40 } = win32);
|
|
8072
|
-
META = /([()\][%!^"`<>&|;, *?])/g;
|
|
8073
|
-
}
|
|
8074
|
-
});
|
|
8075
|
-
function runHarnessArgs(bin, args, cwd, timeoutMs = 15e3) {
|
|
8076
|
-
return new Promise((resolve23) => {
|
|
8077
|
-
const isWin = process.platform === "win32";
|
|
8078
|
-
const stdio = ["ignore", "pipe", "pipe"];
|
|
8079
|
-
let child;
|
|
8080
|
-
if (isWin) {
|
|
8081
|
-
const plan = planWindowsSpawn(bin, args, resolveWindowsBin(bin));
|
|
8082
|
-
child = spawn(plan.command, plan.args, {
|
|
8083
|
-
cwd,
|
|
8084
|
-
windowsHide: true,
|
|
8085
|
-
stdio,
|
|
8086
|
-
shell: false,
|
|
8087
|
-
windowsVerbatimArguments: plan.verbatim
|
|
8088
|
-
});
|
|
8089
|
-
} else {
|
|
8090
|
-
child = spawn(bin, args, { cwd, shell: false, stdio });
|
|
8091
|
-
}
|
|
8092
|
-
let stdout2 = "";
|
|
8093
|
-
let stderr = "";
|
|
8094
|
-
child.stdout?.setEncoding("utf8").on("data", (c) => {
|
|
8095
|
-
stdout2 += c;
|
|
8096
|
-
});
|
|
8097
|
-
child.stderr?.setEncoding("utf8").on("data", (c) => {
|
|
8098
|
-
stderr += c;
|
|
8099
|
-
});
|
|
8100
|
-
const timer = setTimeout(() => {
|
|
8101
|
-
killProcessTree(child);
|
|
8102
|
-
resolve23({ exitCode: -1, stdout: stdout2, stderr: `${stderr}[timeout after ${timeoutMs}ms]` });
|
|
8103
|
-
}, timeoutMs);
|
|
8104
|
-
child.on("error", (e) => {
|
|
8105
|
-
clearTimeout(timer);
|
|
8106
|
-
const enoent = e.code === "ENOENT";
|
|
8107
|
-
const msg = enoent && bin === "codex" ? "codex CLI not found on PATH \u2014 install Codex CLI or re-run setup on the claude platform" : e.message;
|
|
8108
|
-
resolve23({ exitCode: -1, stdout: stdout2, stderr: `${stderr}${msg}` });
|
|
8109
|
-
});
|
|
8110
|
-
child.on("close", (code) => {
|
|
8111
|
-
clearTimeout(timer);
|
|
8112
|
-
resolve23({ exitCode: code ?? -1, stdout: stdout2, stderr });
|
|
8113
|
-
});
|
|
8114
|
-
});
|
|
8115
|
-
}
|
|
8116
|
-
function runArgs(claudeArgs, cwd, timeoutMs = 15e3) {
|
|
8117
|
-
return runHarnessArgs("claude", claudeArgs, cwd, timeoutMs);
|
|
8118
|
-
}
|
|
8119
|
-
var init_runClaudeArgs = __esm({
|
|
8120
|
-
"src/installers/lib/runClaudeArgs.ts"() {
|
|
8121
|
-
init_killTree();
|
|
8122
|
-
init_winSpawn();
|
|
8123
|
-
}
|
|
8124
|
-
});
|
|
8125
8909
|
|
|
8126
8910
|
// src/installers/ccPluginMarketplace.ts
|
|
8127
8911
|
function parseCmd(cmd) {
|
|
@@ -8142,6 +8926,7 @@ var init_ccPluginMarketplace2 = __esm({
|
|
|
8142
8926
|
init_security();
|
|
8143
8927
|
init_platform();
|
|
8144
8928
|
init_backup();
|
|
8929
|
+
init_codexPlugins();
|
|
8145
8930
|
init_confirm();
|
|
8146
8931
|
init_diff();
|
|
8147
8932
|
init_err();
|
|
@@ -8247,7 +9032,7 @@ ${newEntry}
|
|
|
8247
9032
|
return { aborted: true, reason };
|
|
8248
9033
|
}
|
|
8249
9034
|
if (ctx.opts.dryRun) return { aborted: true, reason: "user-cancel" };
|
|
8250
|
-
const bk = await backup(plan, ctx);
|
|
9035
|
+
const bk = await backup(bin === "codex" ? { files: [] } : plan, ctx);
|
|
8251
9036
|
if (!bk.ok) return { ok: false, phase: "preflight", error: bk.error };
|
|
8252
9037
|
const spawnCwd = install.cwd ?? getMcpSpawnCwd();
|
|
8253
9038
|
let stepOneStderr = "";
|
|
@@ -8270,6 +9055,7 @@ ${newEntry}
|
|
|
8270
9055
|
)
|
|
8271
9056
|
};
|
|
8272
9057
|
}
|
|
9058
|
+
if (bin === "codex") invalidateCodexPluginCache();
|
|
8273
9059
|
const registered = await isPluginRegistered(pluginName);
|
|
8274
9060
|
if (!registered) {
|
|
8275
9061
|
const cfgLabel = bin === "codex" ? "`codex plugin list` output" : "enabledPlugins map of ~/.claude.json";
|
|
@@ -9291,7 +10077,7 @@ var init_installers = __esm({
|
|
|
9291
10077
|
// Phase 2.4 W3 T3.1 (D-04 § 3.1) — 7th installer.
|
|
9292
10078
|
"cc-hook-add": installCcHookAdd
|
|
9293
10079
|
};
|
|
9294
|
-
CLAUDE_ONLY_METHODS = /* @__PURE__ */ new Set(["cc-plugin-marketplace"
|
|
10080
|
+
CLAUDE_ONLY_METHODS = /* @__PURE__ */ new Set(["cc-plugin-marketplace"]);
|
|
9295
10081
|
}
|
|
9296
10082
|
});
|
|
9297
10083
|
var PinnedUpstream, KnownGoodV1;
|
|
@@ -9672,7 +10458,7 @@ function forwardPointer(repoRoot, wf) {
|
|
|
9672
10458
|
const snapshot = scanPlanning({ repoRoot, currentWorkflow: wf, includeTasks: false });
|
|
9673
10459
|
const unit = deriveNext(snapshot);
|
|
9674
10460
|
if (unit.kind !== "phase" && unit.kind !== "task") return null;
|
|
9675
|
-
return { unit, remainingPhases: snapshot.phases.filter((
|
|
10461
|
+
return { unit, remainingPhases: snapshot.phases.filter((p8) => !p8.complete).length };
|
|
9676
10462
|
}
|
|
9677
10463
|
var INTENT_TTL_MS, STALE_LEDGER_MS, DEFAULT_INJECT_BUDGET, tok;
|
|
9678
10464
|
var init_injectState = __esm({
|
|
@@ -9695,7 +10481,7 @@ var release_preflight_exports = {};
|
|
|
9695
10481
|
__export(release_preflight_exports, {
|
|
9696
10482
|
anyFailed: () => anyFailed,
|
|
9697
10483
|
collectPreflight: () => collectPreflight,
|
|
9698
|
-
defaultDeps: () =>
|
|
10484
|
+
defaultDeps: () => defaultDeps5
|
|
9699
10485
|
});
|
|
9700
10486
|
function unreleasedSection(changelog) {
|
|
9701
10487
|
const start = changelog.indexOf("## [Unreleased]");
|
|
@@ -9750,7 +10536,7 @@ function collectPreflight(deps) {
|
|
|
9750
10536
|
function anyFailed(checks) {
|
|
9751
10537
|
return checks.some((c) => c.status === "fail");
|
|
9752
10538
|
}
|
|
9753
|
-
function
|
|
10539
|
+
function defaultDeps5(cwd) {
|
|
9754
10540
|
let changelog = "";
|
|
9755
10541
|
let version = "";
|
|
9756
10542
|
try {
|
|
@@ -10094,7 +10880,10 @@ ${pending.length} optional component(s) available (opt-in \u2014 none selected b
|
|
|
10094
10880
|
...PROBE_OPTS,
|
|
10095
10881
|
apply: true,
|
|
10096
10882
|
// see IMPL NOTE header — this confirm IS the L4 opt-in for npm-cli globals.
|
|
10097
|
-
system: manifest.spec.install.method === "npm-cli"
|
|
10883
|
+
system: manifest.spec.install.method === "npm-cli",
|
|
10884
|
+
// v16.0 Phase 64 (R8) — codex hook trust: setup --trust-codex-hooks grants;
|
|
10885
|
+
// otherwise this interactive offer asks per hook (never silently trusts).
|
|
10886
|
+
codexHookTrust: offerOpts.trustCodexHooks ? "grant" : "ask"
|
|
10098
10887
|
};
|
|
10099
10888
|
const r = await runInstall(manifest, opts);
|
|
10100
10889
|
if ("aborted" in r) {
|
|
@@ -10103,6 +10892,7 @@ ${pending.length} optional component(s) available (opt-in \u2014 none selected b
|
|
|
10103
10892
|
} else if (r.ok) {
|
|
10104
10893
|
out.installed.push(name);
|
|
10105
10894
|
console.log(` \u2713 installed ${name}`);
|
|
10895
|
+
if (r.trustPending) console.log(` \u26A0 ${r.trustPending}`);
|
|
10106
10896
|
if (name === "codegraph") {
|
|
10107
10897
|
console.log(" run `codegraph init` in each project to build its index");
|
|
10108
10898
|
}
|
|
@@ -10266,11 +11056,11 @@ function assetNameFor(platform, arch) {
|
|
|
10266
11056
|
const ext = platform === "win32" ? ".exe" : "";
|
|
10267
11057
|
return `harnessed-${plat}-${arch}${ext}`;
|
|
10268
11058
|
}
|
|
10269
|
-
function normalized(
|
|
10270
|
-
return
|
|
11059
|
+
function normalized(p8) {
|
|
11060
|
+
return p8.replace(/\\/g, "/");
|
|
10271
11061
|
}
|
|
10272
|
-
async function sha256File(
|
|
10273
|
-
const buf = await readFile(
|
|
11062
|
+
async function sha256File(p8) {
|
|
11063
|
+
const buf = await readFile(p8);
|
|
10274
11064
|
return createHash("sha256").update(buf).digest("hex");
|
|
10275
11065
|
}
|
|
10276
11066
|
function parseShaText(text) {
|
|
@@ -11040,10 +11830,10 @@ function hasCommitHash(line) {
|
|
|
11040
11830
|
return false;
|
|
11041
11831
|
}
|
|
11042
11832
|
function read(cwd, rel) {
|
|
11043
|
-
const
|
|
11044
|
-
if (!existsSync(
|
|
11833
|
+
const p8 = join(cwd, rel);
|
|
11834
|
+
if (!existsSync(p8)) return null;
|
|
11045
11835
|
try {
|
|
11046
|
-
return readFileSync(
|
|
11836
|
+
return readFileSync(p8, "utf8");
|
|
11047
11837
|
} catch {
|
|
11048
11838
|
return null;
|
|
11049
11839
|
}
|
|
@@ -11127,6 +11917,19 @@ function shouldGateForHookPayload(raw) {
|
|
|
11127
11917
|
const cmd = payload.tool_input?.command;
|
|
11128
11918
|
return typeof cmd === "string" && /\bgit\s+(?:-\S+\s+)*commit\b/.test(cmd);
|
|
11129
11919
|
}
|
|
11920
|
+
function codexHookOutput(code, lines) {
|
|
11921
|
+
const text = lines.join("\n");
|
|
11922
|
+
if (code === 2)
|
|
11923
|
+
return JSON.stringify({
|
|
11924
|
+
hookSpecificOutput: {
|
|
11925
|
+
hookEventName: "PreToolUse",
|
|
11926
|
+
permissionDecision: "deny",
|
|
11927
|
+
permissionDecisionReason: text
|
|
11928
|
+
}
|
|
11929
|
+
});
|
|
11930
|
+
if (code === 1) return JSON.stringify({ systemMessage: text });
|
|
11931
|
+
return null;
|
|
11932
|
+
}
|
|
11130
11933
|
async function readStdin() {
|
|
11131
11934
|
if (process.stdin.isTTY) return "";
|
|
11132
11935
|
try {
|
|
@@ -11140,7 +11943,7 @@ async function readStdin() {
|
|
|
11140
11943
|
function registerCheckDocs(program2) {
|
|
11141
11944
|
program2.command("check-docs").description(
|
|
11142
11945
|
"Documentation-discipline gate over .planning/ (STATE digest limit + archive cadence + ROADMAP pointer-not-narrative). Exits 2 on a blocking violation, 1 on advisory-only."
|
|
11143
|
-
).option("--json", "output JSON instead of human-readable").option("--cwd <dir>", "repo root holding .planning/ (default: current directory)").option("--max-state-lines <n>", `STATE.md digest ceiling (default ${DEFAULT_MAX_STATE_LINES})`).option("--hook", "PreToolUse mode: read the tool payload on stdin, gate only git commit").action(
|
|
11946
|
+
).option("--json", "output JSON instead of human-readable").option("--cwd <dir>", "repo root holding .planning/ (default: current directory)").option("--max-state-lines <n>", `STATE.md digest ceiling (default ${DEFAULT_MAX_STATE_LINES})`).option("--hook", "PreToolUse mode: read the tool payload on stdin, gate only git commit").option("--platform <id>", "(hook) host harness; codex \u2192 verdict as JSON on stdout, exit 0").action(
|
|
11144
11947
|
async (opts) => {
|
|
11145
11948
|
if (opts.hook && isAblated()) process.exit(0);
|
|
11146
11949
|
if (opts.hook && !shouldGateForHookPayload(await readStdin())) process.exit(0);
|
|
@@ -11152,6 +11955,16 @@ function registerCheckDocs(program2) {
|
|
|
11152
11955
|
});
|
|
11153
11956
|
const code = exitCodeFor(violations);
|
|
11154
11957
|
const summary = code === 2 ? "halt" : code === 1 ? "warn" : "pass";
|
|
11958
|
+
if (opts.hook && opts.platform === "codex") {
|
|
11959
|
+
const lines = violations.map((v) => {
|
|
11960
|
+
const where = v.line === void 0 ? v.file : `${v.file}:${v.line}`;
|
|
11961
|
+
return `${v.tier === "halt" ? "\u2717" : "\u26A0"} ${where} [${v.rule}] ${v.message}`;
|
|
11962
|
+
});
|
|
11963
|
+
const verdict = codexHookOutput(code, lines);
|
|
11964
|
+
if (verdict !== null) process.stdout.write(`${verdict}
|
|
11965
|
+
`);
|
|
11966
|
+
process.exit(0);
|
|
11967
|
+
}
|
|
11155
11968
|
if (opts.json) {
|
|
11156
11969
|
console.log(JSON.stringify({ violations, summary, exit_code: code }, null, 2));
|
|
11157
11970
|
} else if (violations.length === 0) {
|
|
@@ -11927,8 +12740,8 @@ function deriveGitFacts(run) {
|
|
|
11927
12740
|
if (out === null) continue;
|
|
11928
12741
|
sawNames = true;
|
|
11929
12742
|
for (const row of out.split(/\r?\n/)) {
|
|
11930
|
-
const
|
|
11931
|
-
if (
|
|
12743
|
+
const p8 = row.trim();
|
|
12744
|
+
if (p8) files.add(p8);
|
|
11932
12745
|
}
|
|
11933
12746
|
}
|
|
11934
12747
|
return {
|
|
@@ -11950,10 +12763,10 @@ var ORCHESTRATION_SURFACE = [
|
|
|
11950
12763
|
"src/checkpoint/ledger.ts"
|
|
11951
12764
|
];
|
|
11952
12765
|
function onOrchestrationSurface(path) {
|
|
11953
|
-
const
|
|
11954
|
-
if (
|
|
11955
|
-
if (/^workflows\/.+\/SKILL(\.[A-Za-z-]+)?\.md$/.test(
|
|
11956
|
-
return ORCHESTRATION_SURFACE.some((s) => s.endsWith("/") ?
|
|
12766
|
+
const p8 = path.split(String.fromCharCode(92)).join("/").trim();
|
|
12767
|
+
if (p8 === "") return false;
|
|
12768
|
+
if (/^workflows\/.+\/SKILL(\.[A-Za-z-]+)?\.md$/.test(p8)) return true;
|
|
12769
|
+
return ORCHESTRATION_SURFACE.some((s) => s.endsWith("/") ? p8.startsWith(s) : p8 === s);
|
|
11957
12770
|
}
|
|
11958
12771
|
function deriveSecondOpinion(run) {
|
|
11959
12772
|
const tagOut = run(["describe", "--tags", "--abbrev=0"]);
|
|
@@ -12145,17 +12958,17 @@ async function runFactsPlan(master, raw, deps = defaultRunDeps, gitRun = default
|
|
|
12145
12958
|
}
|
|
12146
12959
|
};
|
|
12147
12960
|
const envelope = buildFactsEnvelope(master, gated, derived);
|
|
12148
|
-
const
|
|
12961
|
+
const json2 = JSON.stringify(envelope, null, 2);
|
|
12149
12962
|
if (raw.out) {
|
|
12150
12963
|
try {
|
|
12151
|
-
await writeFile(raw.out,
|
|
12964
|
+
await writeFile(raw.out, json2, "utf8");
|
|
12152
12965
|
} catch (err2) {
|
|
12153
12966
|
deps.error(`error: failed to write --out ${raw.out} \u2014 ${err2.message}`);
|
|
12154
12967
|
deps.exit(1);
|
|
12155
12968
|
return;
|
|
12156
12969
|
}
|
|
12157
12970
|
}
|
|
12158
|
-
deps.log(
|
|
12971
|
+
deps.log(json2);
|
|
12159
12972
|
deps.exit(0);
|
|
12160
12973
|
return;
|
|
12161
12974
|
}
|
|
@@ -12174,7 +12987,7 @@ init_gc();
|
|
|
12174
12987
|
// src/cli/injectStateCmd.ts
|
|
12175
12988
|
init_assetsRoot();
|
|
12176
12989
|
function registerInjectState(program2) {
|
|
12177
|
-
program2.command("inject-state").description("(internal) per-turn <workflow-state> hook output \u2014 used by the perturn hook").option("--invalidate", "(internal) drop the per-session <project-context> delta cache").action(async () => {
|
|
12990
|
+
program2.command("inject-state").description("(internal) per-turn <workflow-state> hook output \u2014 used by the perturn hook").option("--invalidate", "(internal) drop the per-session <project-context> delta cache").option("--platform <id>", "(internal) host harness of the calling hook (codex plugin)").action(async () => {
|
|
12178
12991
|
try {
|
|
12179
12992
|
const mjs = join(getAssetsRoot(), "bin", "harnessed-inject-state.mjs");
|
|
12180
12993
|
if (!existsSync(mjs)) return;
|
|
@@ -12203,6 +13016,9 @@ function registerInstall(program2) {
|
|
|
12203
13016
|
program2.command("install <name>").description("Install an upstream (immediate by default \u2014 use --dry-run for preview)").option("--dry-run", "preview only \u2014 do not write to disk (opt-in for advanced users)").option("--system", "allow L4 system-wide install (e.g. global npm install)").option("--non-interactive", "skip all prompts (CI / scripts)").option("--full-diff", "expand diffs longer than 200 lines").option("--no-color", "disable ANSI colors (auto-detected when piped)").option(
|
|
12204
13017
|
"--known-good",
|
|
12205
13018
|
"use known-good version lock from versions/<harnessed-ver>-known-good.yaml"
|
|
13019
|
+
).option(
|
|
13020
|
+
"--trust-codex-hooks",
|
|
13021
|
+
"codex: trust harnessed's own hook plugins without prompting (default: ask when interactive, never when not)"
|
|
12206
13022
|
).action(async (name, raw) => {
|
|
12207
13023
|
const { resolveAlias: resolveAlias2 } = await Promise.resolve().then(() => (init_aliases(), aliases_exports));
|
|
12208
13024
|
const resolvedName = resolveAlias2(name) ?? name;
|
|
@@ -12212,10 +13028,10 @@ function registerInstall(program2) {
|
|
|
12212
13028
|
);
|
|
12213
13029
|
let yamlSrc;
|
|
12214
13030
|
let chosenPath;
|
|
12215
|
-
for (const
|
|
13031
|
+
for (const p8 of candidatePaths) {
|
|
12216
13032
|
try {
|
|
12217
|
-
yamlSrc = await readFile(
|
|
12218
|
-
chosenPath =
|
|
13033
|
+
yamlSrc = await readFile(p8, "utf8");
|
|
13034
|
+
chosenPath = p8;
|
|
12219
13035
|
break;
|
|
12220
13036
|
} catch {
|
|
12221
13037
|
}
|
|
@@ -12240,7 +13056,10 @@ ${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
|
12240
13056
|
system: raw.system === true,
|
|
12241
13057
|
nonInteractive: raw.nonInteractive === true,
|
|
12242
13058
|
fullDiff: raw.fullDiff === true,
|
|
12243
|
-
color: raw.color === false ? false : "auto"
|
|
13059
|
+
color: raw.color === false ? false : "auto",
|
|
13060
|
+
// v16.0 Phase 64 (R8) — codex hook trust is a security decision: explicit
|
|
13061
|
+
// flag → grant; interactive TTY → ask; otherwise never written.
|
|
13062
|
+
codexHookTrust: raw.trustCodexHooks ? "grant" : raw.nonInteractive !== true && process.stdin.isTTY ? "ask" : "deny"
|
|
12244
13063
|
};
|
|
12245
13064
|
if (raw.knownGood) {
|
|
12246
13065
|
const { getPinnedVersion: getPinnedVersion2 } = await Promise.resolve().then(() => (init_knownGood(), knownGood_exports));
|
|
@@ -12262,6 +13081,7 @@ ${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
|
12262
13081
|
console.log(
|
|
12263
13082
|
version ? t(`${keyBase}_with_version`, { name: v.manifest.metadata.name, version }) : t(keyBase, { name: v.manifest.metadata.name })
|
|
12264
13083
|
);
|
|
13084
|
+
if (result.trustPending) console.log(`\u26A0 ${result.trustPending}`);
|
|
12265
13085
|
process.exit(0);
|
|
12266
13086
|
}
|
|
12267
13087
|
console.error(formatError(result.error));
|
|
@@ -13594,10 +14414,10 @@ ${rp.checklist.map((c, i) => ` ${i + 1}. ${c}`).join("\n")}` : "";
|
|
|
13594
14414
|
}
|
|
13595
14415
|
function isRalphLoopOptIn(phase) {
|
|
13596
14416
|
if (!phase || typeof phase !== "object") return false;
|
|
13597
|
-
const
|
|
13598
|
-
if (
|
|
13599
|
-
if (
|
|
13600
|
-
const fb =
|
|
14417
|
+
const p8 = phase;
|
|
14418
|
+
if (p8.max_iterations !== void 0 && p8.max_iterations !== null) return true;
|
|
14419
|
+
if (p8.upstream === "ralph-loop") return true;
|
|
14420
|
+
const fb = p8.fallback;
|
|
13601
14421
|
if (fb?.max_iterations_exceeded !== void 0) return true;
|
|
13602
14422
|
return false;
|
|
13603
14423
|
}
|
|
@@ -14063,8 +14883,8 @@ function registerReleasePreflight(program2) {
|
|
|
14063
14883
|
program2.command("release-preflight").description(
|
|
14064
14884
|
"Read-only release-readiness gate (CHANGELOG / version / git-clean / tag). Exits 1 if not ready."
|
|
14065
14885
|
).action(async () => {
|
|
14066
|
-
const { collectPreflight: collectPreflight2, anyFailed: anyFailed2, defaultDeps:
|
|
14067
|
-
const checks = collectPreflight2(
|
|
14886
|
+
const { collectPreflight: collectPreflight2, anyFailed: anyFailed2, defaultDeps: defaultDeps6 } = await Promise.resolve().then(() => (init_release_preflight(), release_preflight_exports));
|
|
14887
|
+
const checks = collectPreflight2(defaultDeps6(process.cwd()));
|
|
14068
14888
|
console.log("\n release preflight (read-only \u2014 nothing is pushed/published):\n");
|
|
14069
14889
|
for (const c of checks) {
|
|
14070
14890
|
const mark = c.status === "pass" ? "\u2713" : c.status === "warn" ? "\u26A0" : "\u2717";
|
|
@@ -14492,19 +15312,19 @@ async function listWorkflowNames(workflowsDir) {
|
|
|
14492
15312
|
const names = [];
|
|
14493
15313
|
const entries = await readdir(workflowsDir);
|
|
14494
15314
|
for (const e of entries.sort()) {
|
|
14495
|
-
const
|
|
14496
|
-
const s = await stat(
|
|
15315
|
+
const p8 = join(workflowsDir, e);
|
|
15316
|
+
const s = await stat(p8).catch(() => null);
|
|
14497
15317
|
if (!s?.isDirectory()) continue;
|
|
14498
|
-
if (await fileExists(join(
|
|
15318
|
+
if (await fileExists(join(p8, "workflow.yaml"))) {
|
|
14499
15319
|
names.push(e);
|
|
14500
15320
|
continue;
|
|
14501
15321
|
}
|
|
14502
|
-
if (await fileExists(join(
|
|
15322
|
+
if (await fileExists(join(p8, "auto", "workflow.yaml"))) {
|
|
14503
15323
|
names.push(e);
|
|
14504
|
-
const subs = await readdir(
|
|
15324
|
+
const subs = await readdir(p8).catch(() => []);
|
|
14505
15325
|
for (const sub of subs.sort()) {
|
|
14506
15326
|
if (sub === "auto") continue;
|
|
14507
|
-
if (await fileExists(join(
|
|
15327
|
+
if (await fileExists(join(p8, sub, "workflow.yaml"))) {
|
|
14508
15328
|
names.push(`${e}-${sub}`);
|
|
14509
15329
|
}
|
|
14510
15330
|
}
|
|
@@ -14942,7 +15762,7 @@ var V3_4_3_SIGNATURE_MASTER_RX = /\*\*Preferred path\*\*[\s\S]*dispatch to the p
|
|
|
14942
15762
|
function shouldOverwriteFile(content) {
|
|
14943
15763
|
return HARNESSED_MARKER_RX2.test(content) || V3_4_3_SIGNATURE_SUB_RX.test(content) || V3_4_3_SIGNATURE_MASTER_RX.test(content);
|
|
14944
15764
|
}
|
|
14945
|
-
async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabilities, installedPlugins, installedUserSkills, writer, fileExists2 = existsSync,
|
|
15765
|
+
async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabilities, installedPlugins, installedUserSkills, writer, fileExists2 = existsSync, readFileSync25 = (p8) => readFileSync(p8, "utf8")) {
|
|
14946
15766
|
const results = [];
|
|
14947
15767
|
const aggregatedWarnings = /* @__PURE__ */ new Set();
|
|
14948
15768
|
for (const name of slashNames) {
|
|
@@ -14961,7 +15781,7 @@ async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabiliti
|
|
|
14961
15781
|
if (fileExists2(path)) {
|
|
14962
15782
|
let existing = "";
|
|
14963
15783
|
try {
|
|
14964
|
-
existing =
|
|
15784
|
+
existing = readFileSync25(path);
|
|
14965
15785
|
} catch {
|
|
14966
15786
|
existing = "";
|
|
14967
15787
|
}
|
|
@@ -15344,10 +16164,21 @@ async function applyPlatformOption(platform, persist) {
|
|
|
15344
16164
|
}
|
|
15345
16165
|
process.env.HARNESSED_PLATFORM = platform;
|
|
15346
16166
|
if (!persist) return;
|
|
15347
|
-
const
|
|
16167
|
+
const [own, other] = platform === "codex" ? [codexDescriptor().stateRoot, claudeDescriptor().stateRoot] : [claudeDescriptor().stateRoot, codexDescriptor().stateRoot];
|
|
15348
16168
|
try {
|
|
15349
|
-
await mkdir(
|
|
15350
|
-
await writeFile(join(
|
|
16169
|
+
await mkdir(own, { recursive: true });
|
|
16170
|
+
await writeFile(join(own, ".platform"), platform, "utf8");
|
|
16171
|
+
const otherPin = join(other, ".platform");
|
|
16172
|
+
let existing;
|
|
16173
|
+
try {
|
|
16174
|
+
const raw = await readFile(otherPin, "utf8");
|
|
16175
|
+
existing = typeof raw === "string" ? raw.trim() : void 0;
|
|
16176
|
+
} catch {
|
|
16177
|
+
existing = void 0;
|
|
16178
|
+
}
|
|
16179
|
+
if (existing !== void 0 && existing !== platform) {
|
|
16180
|
+
await writeFile(otherPin, platform, "utf8");
|
|
16181
|
+
}
|
|
15351
16182
|
} catch (e) {
|
|
15352
16183
|
console.warn(` [--platform] could not persist .platform pin (${e.message})`);
|
|
15353
16184
|
}
|
|
@@ -15458,6 +16289,9 @@ function registerSetup(program2) {
|
|
|
15458
16289
|
).option("--platform <id>", "target harness platform (claude | codex); default: auto-detect").option("--non-interactive", "skip all confirm prompts (CI / scripted setup)").option("--no-auto-install", "do not prompt to auto-install missing plugins (advisory only)").option(
|
|
15459
16290
|
"--update-installed",
|
|
15460
16291
|
"force re-install already-installed plugins (excludes MCP servers); default: skip if installed"
|
|
16292
|
+
).option(
|
|
16293
|
+
"--trust-codex-hooks",
|
|
16294
|
+
"codex: trust harnessed's own hook plugins chosen in the optional offer without prompting"
|
|
15461
16295
|
).action(async (raw) => {
|
|
15462
16296
|
await printSetupVersionBanner();
|
|
15463
16297
|
const dryRun = raw.dryRun === true;
|
|
@@ -15514,14 +16348,14 @@ installing ${manifestPaths.length} upstream components (MCP serialized, rest par
|
|
|
15514
16348
|
if (!forceFirstPass && !dryRun && raw.nonInteractive !== true && b.alreadyInstalled.length > 0) {
|
|
15515
16349
|
const isTty = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
15516
16350
|
if (isTty) {
|
|
15517
|
-
const { confirm:
|
|
16351
|
+
const { confirm: confirm6, isCancel: isCancel8 } = await import('@clack/prompts');
|
|
15518
16352
|
const mcpExcluded = b.alreadyInstalled.filter((n) => b.componentTypes[n] === "mcp-tool");
|
|
15519
16353
|
const exclusionNote = mcpExcluded.length > 0 ? ` (${mcpExcluded.length} MCP server(s) excluded \u2014 they ignore force-update: ${mcpExcluded.join(", ")})` : "";
|
|
15520
|
-
const ans = await
|
|
16354
|
+
const ans = await confirm6({
|
|
15521
16355
|
message: `Update ${b.alreadyInstalled.length} already-installed plugin(s) listed above?${exclusionNote}`,
|
|
15522
16356
|
initialValue: false
|
|
15523
16357
|
});
|
|
15524
|
-
if (!
|
|
16358
|
+
if (!isCancel8(ans) && ans === true) {
|
|
15525
16359
|
console.log(`
|
|
15526
16360
|
force-updating ${b.alreadyInstalled.length} plugin(s)...`);
|
|
15527
16361
|
const b2 = await runStepBInstall(manifestPaths, {
|
|
@@ -15645,7 +16479,7 @@ Force-update pass complete: ${b2.installed.length} installed / ${b2.keptExisting
|
|
|
15645
16479
|
capabilitiesMap,
|
|
15646
16480
|
installedPlugins,
|
|
15647
16481
|
installedUserSkills,
|
|
15648
|
-
async (
|
|
16482
|
+
async (p8, c) => writeFile(p8, c, "utf8")
|
|
15649
16483
|
);
|
|
15650
16484
|
const writtenCount = cmdResult.results.filter((r) => r.written).length;
|
|
15651
16485
|
const skippedCount = cmdResult.results.filter((r) => !r.written && r.warning).length;
|
|
@@ -15665,7 +16499,8 @@ Force-update pass complete: ${b2.installed.length} installed / ${b2.keptExisting
|
|
|
15665
16499
|
const optIsTty = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
15666
16500
|
const { runOptionalOffer: runOptionalOffer2 } = await Promise.resolve().then(() => (init_optional_offer(), optional_offer_exports));
|
|
15667
16501
|
await runOptionalOffer2(resolve(pkgRoot, "manifests", "optional"), {
|
|
15668
|
-
interactive: optIsTty && raw.nonInteractive !== true
|
|
16502
|
+
interactive: optIsTty && raw.nonInteractive !== true,
|
|
16503
|
+
trustCodexHooks: raw.trustCodexHooks === true
|
|
15669
16504
|
});
|
|
15670
16505
|
}
|
|
15671
16506
|
if (b.failed.length > 0) {
|
|
@@ -15801,6 +16636,7 @@ init_harnessedRoot();
|
|
|
15801
16636
|
init_platform();
|
|
15802
16637
|
|
|
15803
16638
|
// src/uninstallers/ccHookAdd.ts
|
|
16639
|
+
init_codexHookAdd();
|
|
15804
16640
|
init_hookEntry();
|
|
15805
16641
|
init_assetsRoot();
|
|
15806
16642
|
init_platform();
|
|
@@ -15819,7 +16655,12 @@ var uninstallCcHookAdd = async (ctx) => {
|
|
|
15819
16655
|
}
|
|
15820
16656
|
const abort = dryRunGate(ctx);
|
|
15821
16657
|
if (abort) return abort;
|
|
16658
|
+
if (detectPlatform().id === "codex") {
|
|
16659
|
+
const r = await removeCodexHook(ctx.manifest.metadata.name, install.hook_event);
|
|
16660
|
+
return r.ok ? r : { ok: false, phase: "spawn", error: r.error };
|
|
16661
|
+
}
|
|
15822
16662
|
const settingsPath = getSettingsPath();
|
|
16663
|
+
if (settingsPath === null) return { ok: true, removedPaths: [] };
|
|
15823
16664
|
let existing;
|
|
15824
16665
|
try {
|
|
15825
16666
|
existing = await readFile(settingsPath, "utf8");
|
|
@@ -15968,10 +16809,10 @@ init_path_guard();
|
|
|
15968
16809
|
function hasDeclaredUninstall(ctx) {
|
|
15969
16810
|
return ctx.manifest.spec.uninstall != null;
|
|
15970
16811
|
}
|
|
15971
|
-
function expandTilde(
|
|
15972
|
-
if (
|
|
15973
|
-
if (
|
|
15974
|
-
return
|
|
16812
|
+
function expandTilde(p8) {
|
|
16813
|
+
if (p8 === "~") return homedir();
|
|
16814
|
+
if (p8.startsWith("~/") || p8.startsWith("~\\")) return homedir() + p8.slice(1);
|
|
16815
|
+
return p8;
|
|
15975
16816
|
}
|
|
15976
16817
|
function confineCleanupPath(raw) {
|
|
15977
16818
|
checkPathSafe(raw);
|
|
@@ -16178,16 +17019,17 @@ async function discoverCommandFiles(commandsDir) {
|
|
|
16178
17019
|
}
|
|
16179
17020
|
for (const entry of entries) {
|
|
16180
17021
|
if (!entry.endsWith(".md")) continue;
|
|
16181
|
-
const
|
|
17022
|
+
const p8 = join(commandsDir, entry);
|
|
16182
17023
|
try {
|
|
16183
|
-
const content = await readFile(
|
|
16184
|
-
if (shouldOverwriteFile(content)) owned.push(
|
|
17024
|
+
const content = await readFile(p8, "utf8");
|
|
17025
|
+
if (shouldOverwriteFile(content)) owned.push(p8);
|
|
16185
17026
|
} catch {
|
|
16186
17027
|
}
|
|
16187
17028
|
}
|
|
16188
17029
|
return owned;
|
|
16189
17030
|
}
|
|
16190
17031
|
async function checkSettingsEnv(settingsPath) {
|
|
17032
|
+
if (settingsPath === null) return { hasAgentTeams: false, hasUserLang: false, staleHooks: 0 };
|
|
16191
17033
|
try {
|
|
16192
17034
|
const raw = await readFile(settingsPath, "utf8");
|
|
16193
17035
|
const data = JSON.parse(raw);
|
|
@@ -16319,7 +17161,7 @@ async function runUnifiedUninstall(home, dryRun) {
|
|
|
16319
17161
|
}
|
|
16320
17162
|
let removedSettings = false;
|
|
16321
17163
|
let removedHooks = 0;
|
|
16322
|
-
if (hasSettingsChanges || staleHooks > 0) {
|
|
17164
|
+
if (settingsPath !== null && (hasSettingsChanges || staleHooks > 0)) {
|
|
16323
17165
|
try {
|
|
16324
17166
|
const r = await removeSettingsFootprint(settingsPath);
|
|
16325
17167
|
removedSettings = r.envRemoved;
|
|
@@ -16368,27 +17210,24 @@ function registerUninstall(program2) {
|
|
|
16368
17210
|
const { resolveAlias: resolveAlias2 } = await Promise.resolve().then(() => (init_aliases(), aliases_exports));
|
|
16369
17211
|
const resolvedName = resolveAlias2(name) ?? name;
|
|
16370
17212
|
checkPathSafe(resolvedName);
|
|
16371
|
-
const manifestPath = resolve(getAssetsRoot(), `manifests/tools/${resolvedName}.yaml`);
|
|
16372
|
-
const skillPackPath = resolve(
|
|
16373
|
-
getAssetsRoot(),
|
|
16374
|
-
`manifests/skill-packs/${resolvedName}.yaml`
|
|
16375
|
-
);
|
|
16376
17213
|
let yamlSrc;
|
|
16377
|
-
let chosenPath
|
|
16378
|
-
|
|
16379
|
-
|
|
16380
|
-
} catch {
|
|
17214
|
+
let chosenPath;
|
|
17215
|
+
for (const dir of ["tools", "skill-packs", "optional"]) {
|
|
17216
|
+
const candidate = resolve(getAssetsRoot(), `manifests/${dir}/${resolvedName}.yaml`);
|
|
16381
17217
|
try {
|
|
16382
|
-
yamlSrc = await readFile(
|
|
16383
|
-
chosenPath =
|
|
17218
|
+
yamlSrc = await readFile(candidate, "utf8");
|
|
17219
|
+
chosenPath = candidate;
|
|
17220
|
+
break;
|
|
16384
17221
|
} catch {
|
|
16385
|
-
console.error(
|
|
16386
|
-
`${t("install.manifest_not_found", { name: resolvedName })}
|
|
16387
|
-
${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
16388
|
-
);
|
|
16389
|
-
process.exit(1);
|
|
16390
17222
|
}
|
|
16391
17223
|
}
|
|
17224
|
+
if (yamlSrc === void 0 || chosenPath === void 0) {
|
|
17225
|
+
console.error(
|
|
17226
|
+
`${t("install.manifest_not_found", { name: resolvedName })}
|
|
17227
|
+
${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
17228
|
+
);
|
|
17229
|
+
process.exit(1);
|
|
17230
|
+
}
|
|
16392
17231
|
const v = validateManifestFile(yamlSrc, chosenPath);
|
|
16393
17232
|
if (!v.ok) {
|
|
16394
17233
|
for (const e of v.errors) console.error(`error: ${e.message} at ${e.path}`);
|
|
@@ -16510,9 +17349,9 @@ function npmExecutable2() {
|
|
|
16510
17349
|
}
|
|
16511
17350
|
function changelogTop() {
|
|
16512
17351
|
try {
|
|
16513
|
-
const
|
|
16514
|
-
if (!existsSync(
|
|
16515
|
-
const body = readFileSync(
|
|
17352
|
+
const p8 = join(getAssetsRoot(), "CHANGELOG.md");
|
|
17353
|
+
if (!existsSync(p8)) return null;
|
|
17354
|
+
const body = readFileSync(p8, "utf8");
|
|
16516
17355
|
const start = body.indexOf("\n## ");
|
|
16517
17356
|
if (start < 0) return null;
|
|
16518
17357
|
const rest = body.slice(start + 1);
|