harnessed 4.43.1 → 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 +45 -3
- package/dist/cli.mjs +1382 -586
- 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 .",
|
|
@@ -642,9 +644,9 @@ async function writeStoreRaw(store) {
|
|
|
642
644
|
const errs = [...Value.Errors(WorkflowStoreV1, store)].map((e) => e.message).join("; ");
|
|
643
645
|
throw new Error(`workflow-store schema validation failed: ${errs}`);
|
|
644
646
|
}
|
|
645
|
-
const
|
|
646
|
-
await mkdir(dirname(
|
|
647
|
-
await writeFileAtomic(
|
|
647
|
+
const p8 = storePath();
|
|
648
|
+
await mkdir(dirname(p8), { recursive: true });
|
|
649
|
+
await writeFileAtomic(p8, JSON.stringify(store, null, 2));
|
|
648
650
|
}
|
|
649
651
|
async function readIntent(cwd = process.cwd()) {
|
|
650
652
|
const store = await readStoreRaw();
|
|
@@ -887,9 +889,9 @@ function scanPhases(repoRoot, includeTasks) {
|
|
|
887
889
|
function scanTasks(dirPath) {
|
|
888
890
|
for (const fname of ["task_plan.md", "progress.md"]) {
|
|
889
891
|
try {
|
|
890
|
-
const
|
|
891
|
-
if (!existsSync(
|
|
892
|
-
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"));
|
|
893
895
|
const task = m?.[1];
|
|
894
896
|
if (task) return { nextUnchecked: task.trim() };
|
|
895
897
|
} catch {
|
|
@@ -1015,7 +1017,7 @@ function deriveNext(snapshot) {
|
|
|
1015
1017
|
reason: `sub '${failed.sub}' failed ${failed.fail_count}x \u2014 resolve before advancing`
|
|
1016
1018
|
};
|
|
1017
1019
|
}
|
|
1018
|
-
const firstIncomplete = snapshot.phases.find((
|
|
1020
|
+
const firstIncomplete = snapshot.phases.find((p8) => !p8.complete);
|
|
1019
1021
|
if (firstIncomplete) {
|
|
1020
1022
|
const task = firstIncomplete.tasks?.nextUnchecked;
|
|
1021
1023
|
if (task) return { kind: "task", phase: firstIncomplete.phase, task };
|
|
@@ -1051,7 +1053,7 @@ function describeUnit(unit) {
|
|
|
1051
1053
|
}
|
|
1052
1054
|
}
|
|
1053
1055
|
function remainingPhases(snapshot) {
|
|
1054
|
-
return snapshot.phases.filter((
|
|
1056
|
+
return snapshot.phases.filter((p8) => !p8.complete).length;
|
|
1055
1057
|
}
|
|
1056
1058
|
function pluralPhases(n) {
|
|
1057
1059
|
return `${n} phase${n === 1 ? "" : "s"} remain`;
|
|
@@ -1726,8 +1728,8 @@ function checkSecurityViolations(doc, filename, lineCounter) {
|
|
|
1726
1728
|
["spec", "harness_overrides", "codex", "install", "cmd"],
|
|
1727
1729
|
["spec", "harness_overrides", "codex", "verify", "cmd"]
|
|
1728
1730
|
];
|
|
1729
|
-
for (const
|
|
1730
|
-
const err2 = checkScalarCmd(doc, lineCounter,
|
|
1731
|
+
for (const p8 of cmdPaths) {
|
|
1732
|
+
const err2 = checkScalarCmd(doc, lineCounter, p8, filename);
|
|
1731
1733
|
if (err2) errors.push(err2);
|
|
1732
1734
|
}
|
|
1733
1735
|
const cleanupNode = doc.getIn(["spec", "uninstall", "cleanup_paths"], true);
|
|
@@ -2429,6 +2431,217 @@ var init_engineHook = __esm({
|
|
|
2429
2431
|
init_template();
|
|
2430
2432
|
}
|
|
2431
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
|
+
});
|
|
2432
2645
|
function getUserClaudeJsonPath() {
|
|
2433
2646
|
return getMcpConfigPath();
|
|
2434
2647
|
}
|
|
@@ -2471,22 +2684,9 @@ async function isMcpServerRegistered(name) {
|
|
|
2471
2684
|
if (!servers || typeof servers !== "object") return false;
|
|
2472
2685
|
return Object.hasOwn(servers, name);
|
|
2473
2686
|
}
|
|
2474
|
-
function isPluginInToml(raw, pluginName) {
|
|
2475
|
-
const esc = (v) => v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2476
|
-
const [plugin = "", market] = pluginName.split("@");
|
|
2477
|
-
const key = market ? `${esc(plugin)}@${esc(market)}` : `${esc(plugin)}(?:@[^"'\\]]+)?`;
|
|
2478
|
-
const re = new RegExp(`^\\s*\\[plugins\\.(?:"${key}"|'${key}')\\]`, "m");
|
|
2479
|
-
return re.test(raw);
|
|
2480
|
-
}
|
|
2481
2687
|
async function isPluginRegistered(pluginName) {
|
|
2482
2688
|
const platform = detectPlatform();
|
|
2483
|
-
if (platform.id === "codex")
|
|
2484
|
-
try {
|
|
2485
|
-
return isPluginInToml(await readFile(platform.mcpConfigPath, "utf8"), pluginName);
|
|
2486
|
-
} catch {
|
|
2487
|
-
return false;
|
|
2488
|
-
}
|
|
2489
|
-
}
|
|
2689
|
+
if (platform.id === "codex") return isCodexPluginInstalled(pluginName);
|
|
2490
2690
|
const registryPath = getPluginsRegistry();
|
|
2491
2691
|
if (registryPath !== null) {
|
|
2492
2692
|
try {
|
|
@@ -2518,6 +2718,7 @@ async function isPluginRegistered(pluginName) {
|
|
|
2518
2718
|
var init_readClaudeConfig = __esm({
|
|
2519
2719
|
"src/installers/lib/readClaudeConfig.ts"() {
|
|
2520
2720
|
init_platform();
|
|
2721
|
+
init_codexPlugins();
|
|
2521
2722
|
}
|
|
2522
2723
|
});
|
|
2523
2724
|
async function mergeSettingsEnvKey(key, value, opts = {}) {
|
|
@@ -2618,7 +2819,7 @@ __export(guard_exemption_exports, {
|
|
|
2618
2819
|
function defaultProbeDeps() {
|
|
2619
2820
|
return {
|
|
2620
2821
|
registryPath: () => getPluginsRegistry(),
|
|
2621
|
-
readFile: (
|
|
2822
|
+
readFile: (p8) => readFile(p8, "utf8")
|
|
2622
2823
|
};
|
|
2623
2824
|
}
|
|
2624
2825
|
async function probeExemptCapability(deps = {}) {
|
|
@@ -2924,7 +3125,7 @@ async function checkArtifacts(sub, packageRoot) {
|
|
|
2924
3125
|
return { status: missing.length === 0 ? "verified" : "missing", found, missing };
|
|
2925
3126
|
}
|
|
2926
3127
|
async function resolveDeclaredArtifact(cwd, rel) {
|
|
2927
|
-
const isFileAt = (
|
|
3128
|
+
const isFileAt = (p8) => stat(p8).then((s) => s.isFile()).catch(() => false);
|
|
2928
3129
|
if (/[\\/]/.test(rel)) {
|
|
2929
3130
|
const abs = resolve(cwd, rel);
|
|
2930
3131
|
return await isFileAt(abs) ? abs : null;
|
|
@@ -3026,9 +3227,9 @@ function realDeps() {
|
|
|
3026
3227
|
return {
|
|
3027
3228
|
env: process.env,
|
|
3028
3229
|
moduleUrl: import.meta.url,
|
|
3029
|
-
exists: (
|
|
3230
|
+
exists: (p8) => {
|
|
3030
3231
|
try {
|
|
3031
|
-
return existsSync(
|
|
3232
|
+
return existsSync(p8);
|
|
3032
3233
|
} catch {
|
|
3033
3234
|
return false;
|
|
3034
3235
|
}
|
|
@@ -3070,8 +3271,8 @@ __export(tddBoundary_exports, {
|
|
|
3070
3271
|
function isTddEvidencePath(path) {
|
|
3071
3272
|
return path.split(/[\\/]/).pop() === TDD_EVIDENCE_ARTIFACT;
|
|
3072
3273
|
}
|
|
3073
|
-
function isTestPath(
|
|
3074
|
-
const s =
|
|
3274
|
+
function isTestPath(p8) {
|
|
3275
|
+
const s = p8.replace(/\\/g, "/");
|
|
3075
3276
|
return /(^|\/)tests?\//.test(s) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(s) || /(^|\/)test_[^/]+\.py$/.test(s) || /_test\.(py|go|rb)$/.test(s);
|
|
3076
3277
|
}
|
|
3077
3278
|
function substantiveBody(text) {
|
|
@@ -3158,8 +3359,8 @@ function assertionDelta(diff) {
|
|
|
3158
3359
|
let removed = 0;
|
|
3159
3360
|
for (const line of diff.split("\n")) {
|
|
3160
3361
|
if (line.startsWith("+++ ")) {
|
|
3161
|
-
const
|
|
3162
|
-
inTest =
|
|
3362
|
+
const p8 = line.slice(4).trim().replace(/^b\//, "");
|
|
3363
|
+
inTest = p8 !== "/dev/null" && isTestPath(p8);
|
|
3163
3364
|
continue;
|
|
3164
3365
|
}
|
|
3165
3366
|
if (line.startsWith("--- ") || line.startsWith("diff --git") || line.startsWith("@@")) continue;
|
|
@@ -3541,10 +3742,10 @@ function learningsPath(repoRoot) {
|
|
|
3541
3742
|
return join(repoRoot, ".planning", "LEARNINGS.md");
|
|
3542
3743
|
}
|
|
3543
3744
|
async function appendLearning(repoRoot, entry) {
|
|
3544
|
-
const
|
|
3545
|
-
await mkdir(dirname(
|
|
3546
|
-
if (!existsSync(
|
|
3547
|
-
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");
|
|
3548
3749
|
}
|
|
3549
3750
|
async function captureWorkflowLearnings(ledger, phase) {
|
|
3550
3751
|
const signals = extractLearnings(ledger);
|
|
@@ -3895,15 +4096,15 @@ async function parsePlan(raw) {
|
|
|
3895
4096
|
} catch {
|
|
3896
4097
|
return null;
|
|
3897
4098
|
}
|
|
3898
|
-
const
|
|
3899
|
-
if (!Array.isArray(
|
|
4099
|
+
const p8 = parsed;
|
|
4100
|
+
if (!Array.isArray(p8.fire) && !Array.isArray(p8.skip)) return null;
|
|
3900
4101
|
const plan = {
|
|
3901
|
-
fire: Array.isArray(
|
|
3902
|
-
skip: Array.isArray(
|
|
4102
|
+
fire: Array.isArray(p8.fire) ? p8.fire : [],
|
|
4103
|
+
skip: Array.isArray(p8.skip) ? p8.skip : []
|
|
3903
4104
|
};
|
|
3904
|
-
if (typeof
|
|
3905
|
-
if (
|
|
3906
|
-
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;
|
|
3907
4108
|
}
|
|
3908
4109
|
return plan;
|
|
3909
4110
|
}
|
|
@@ -3981,13 +4182,13 @@ async function runCheckpointStart(sub, opts, deps = defaultRunDeps) {
|
|
|
3981
4182
|
print: (line) => deps.error(line),
|
|
3982
4183
|
...isTty ? {
|
|
3983
4184
|
confirm: async () => {
|
|
3984
|
-
const
|
|
3985
|
-
const ans = await
|
|
4185
|
+
const p8 = await import('@clack/prompts');
|
|
4186
|
+
const ans = await p8.confirm({
|
|
3986
4187
|
message: 'Apply the GateGuard exemption now? (persists GATEGUARD_EXEMPT_GLOBS=".planning/**" into settings env \u2014 backed up first)',
|
|
3987
4188
|
initialValue: true
|
|
3988
4189
|
// D1 — default YES
|
|
3989
4190
|
});
|
|
3990
|
-
return !
|
|
4191
|
+
return !p8.isCancel(ans) && ans === true;
|
|
3991
4192
|
}
|
|
3992
4193
|
} : {}
|
|
3993
4194
|
});
|
|
@@ -4355,10 +4556,10 @@ var init_checkpoint = __esm({
|
|
|
4355
4556
|
ACTIONS = ["start", "complete", "fail", "reopen", "intent"];
|
|
4356
4557
|
}
|
|
4357
4558
|
});
|
|
4358
|
-
function realProbe(
|
|
4559
|
+
function realProbe(p8) {
|
|
4359
4560
|
try {
|
|
4360
4561
|
if (typeof spawnSync !== "function") return null;
|
|
4361
|
-
const r = spawnSync(
|
|
4562
|
+
const r = spawnSync(p8, ["-c", "echo harnessed-bash-ok"], { encoding: "utf8", timeout: 5e3 });
|
|
4362
4563
|
if (!r || r.error) return null;
|
|
4363
4564
|
return r.status === 0;
|
|
4364
4565
|
} catch {
|
|
@@ -4375,9 +4576,9 @@ function realWhere(name) {
|
|
|
4375
4576
|
return [];
|
|
4376
4577
|
}
|
|
4377
4578
|
}
|
|
4378
|
-
function realExists(
|
|
4579
|
+
function realExists(p8) {
|
|
4379
4580
|
try {
|
|
4380
|
-
return existsSync(
|
|
4581
|
+
return existsSync(p8);
|
|
4381
4582
|
} catch {
|
|
4382
4583
|
return false;
|
|
4383
4584
|
}
|
|
@@ -4392,9 +4593,9 @@ function defaultDeps2() {
|
|
|
4392
4593
|
};
|
|
4393
4594
|
}
|
|
4394
4595
|
function resolveBash(deps) {
|
|
4395
|
-
if (
|
|
4396
|
-
|
|
4397
|
-
return
|
|
4596
|
+
if (cache3) return cache3;
|
|
4597
|
+
cache3 = compute({ ...defaultDeps2(), ...deps });
|
|
4598
|
+
return cache3;
|
|
4398
4599
|
}
|
|
4399
4600
|
function compute(d) {
|
|
4400
4601
|
if (d.platform !== "win32") {
|
|
@@ -4407,14 +4608,14 @@ function compute(d) {
|
|
|
4407
4608
|
const pathLines = d.where("bash");
|
|
4408
4609
|
const first = pathLines[0];
|
|
4409
4610
|
const wslOnPath = first && WSL_STUB_RE.test(first) ? first : void 0;
|
|
4410
|
-
const usable = (
|
|
4611
|
+
const usable = (p8) => !WSL_STUB_RE.test(p8) && d.probe(p8) !== false;
|
|
4411
4612
|
if (first && usable(first)) {
|
|
4412
4613
|
return { path: first, source: "path" };
|
|
4413
4614
|
}
|
|
4414
4615
|
const gitFirst = d.where("git")[0];
|
|
4415
4616
|
if (gitFirst && /git\.exe$/i.test(gitFirst)) {
|
|
4416
4617
|
const root = dirname9(dirname9(gitFirst));
|
|
4417
|
-
for (const cand of [
|
|
4618
|
+
for (const cand of [join22(root, "bin", "bash.exe"), join22(root, "usr", "bin", "bash.exe")]) {
|
|
4418
4619
|
if (d.exists(cand) && usable(cand)) return { path: cand, source: "git-derived", wslOnPath };
|
|
4419
4620
|
}
|
|
4420
4621
|
}
|
|
@@ -4422,13 +4623,13 @@ function compute(d) {
|
|
|
4422
4623
|
d.env.ProgramFiles,
|
|
4423
4624
|
d.env.ProgramW6432,
|
|
4424
4625
|
d.env["ProgramFiles(x86)"],
|
|
4425
|
-
d.env.LOCALAPPDATA ?
|
|
4626
|
+
d.env.LOCALAPPDATA ? join22(d.env.LOCALAPPDATA, "Programs") : void 0
|
|
4426
4627
|
];
|
|
4427
4628
|
for (const base of bases) {
|
|
4428
4629
|
if (!base) continue;
|
|
4429
4630
|
for (const cand of [
|
|
4430
|
-
|
|
4431
|
-
|
|
4631
|
+
join22(base, "Git", "bin", "bash.exe"),
|
|
4632
|
+
join22(base, "Git", "usr", "bin", "bash.exe")
|
|
4432
4633
|
]) {
|
|
4433
4634
|
if (d.exists(cand) && usable(cand))
|
|
4434
4635
|
return { path: cand, source: "standard-location", wslOnPath };
|
|
@@ -4441,12 +4642,12 @@ function compute(d) {
|
|
|
4441
4642
|
}
|
|
4442
4643
|
return { path: "bash", source: "path-fallback" };
|
|
4443
4644
|
}
|
|
4444
|
-
var dirname9,
|
|
4645
|
+
var dirname9, join22, WSL_STUB_RE, cache3;
|
|
4445
4646
|
var init_resolveBash = __esm({
|
|
4446
4647
|
"src/installers/lib/resolveBash.ts"() {
|
|
4447
|
-
({ dirname: dirname9, join:
|
|
4648
|
+
({ dirname: dirname9, join: join22 } = win32);
|
|
4448
4649
|
WSL_STUB_RE = /[\\/](windows[\\/](system32|sysnative|syswow64)|microsoft[\\/]windowsapps)[\\/]bash\.exe$/i;
|
|
4449
|
-
|
|
4650
|
+
cache3 = null;
|
|
4450
4651
|
}
|
|
4451
4652
|
});
|
|
4452
4653
|
|
|
@@ -4613,9 +4814,9 @@ function gstackSkillsDirInstalled(exists) {
|
|
|
4613
4814
|
return null;
|
|
4614
4815
|
}
|
|
4615
4816
|
function probeGstackPrefix(deps) {
|
|
4616
|
-
const exists = deps?.exists ?? ((
|
|
4817
|
+
const exists = deps?.exists ?? ((p8) => {
|
|
4617
4818
|
try {
|
|
4618
|
-
return existsSync(
|
|
4819
|
+
return existsSync(p8);
|
|
4619
4820
|
} catch {
|
|
4620
4821
|
return false;
|
|
4621
4822
|
}
|
|
@@ -5380,9 +5581,9 @@ async function auditInstalledSkills(workflows, skillsBase, workflowsDir, opts =
|
|
|
5380
5581
|
}
|
|
5381
5582
|
async function buildCulpritIndex(manifestPaths) {
|
|
5382
5583
|
const index = /* @__PURE__ */ new Map();
|
|
5383
|
-
for (const
|
|
5584
|
+
for (const p8 of manifestPaths) {
|
|
5384
5585
|
try {
|
|
5385
|
-
const parsed = parse(await readFile(
|
|
5586
|
+
const parsed = parse(await readFile(p8, "utf8"));
|
|
5386
5587
|
const pack = parsed?.metadata?.name;
|
|
5387
5588
|
const skills = parsed?.spec?.install?.installs_skills;
|
|
5388
5589
|
if (typeof pack !== "string" || !Array.isArray(skills)) continue;
|
|
@@ -5959,9 +6160,9 @@ __export(check_stale_hooks_exports, {
|
|
|
5959
6160
|
});
|
|
5960
6161
|
function checkStaleHooks(deps) {
|
|
5961
6162
|
const settingsPath = deps?.settingsPath ?? getSettingsPath();
|
|
5962
|
-
const readText = deps?.readText ?? ((
|
|
6163
|
+
const readText = deps?.readText ?? ((p8) => {
|
|
5963
6164
|
try {
|
|
5964
|
-
return readFileSync(
|
|
6165
|
+
return readFileSync(p8, "utf8");
|
|
5965
6166
|
} catch {
|
|
5966
6167
|
return null;
|
|
5967
6168
|
}
|
|
@@ -6038,17 +6239,17 @@ async function probeChromeDevtools(deps = {}) {
|
|
|
6038
6239
|
if (standaloneStdio) providers.push(`${CHROME_DEVTOOLS_MCP_NAME} stdio MCP server`);
|
|
6039
6240
|
return { ecc, standalonePlugin, standaloneStdio, unknown, providers };
|
|
6040
6241
|
}
|
|
6041
|
-
function chromeDevtoolsAvailable(
|
|
6042
|
-
return
|
|
6242
|
+
function chromeDevtoolsAvailable(p8) {
|
|
6243
|
+
return p8.providers.length > 0 || p8.unknown;
|
|
6043
6244
|
}
|
|
6044
6245
|
async function isChromeDevtoolsAvailable(deps) {
|
|
6045
6246
|
return chromeDevtoolsAvailable(await probeChromeDevtools(deps));
|
|
6046
6247
|
}
|
|
6047
|
-
function chromeDevtoolsFactSource(
|
|
6048
|
-
if (
|
|
6049
|
-
return `chrome-devtools provider registered: ${
|
|
6248
|
+
function chromeDevtoolsFactSource(p8) {
|
|
6249
|
+
if (p8.providers.length > 0) {
|
|
6250
|
+
return `chrome-devtools provider registered: ${p8.providers.join(" + ")}`;
|
|
6050
6251
|
}
|
|
6051
|
-
if (
|
|
6252
|
+
if (p8.unknown) {
|
|
6052
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}`;
|
|
6053
6254
|
}
|
|
6054
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}`;
|
|
@@ -6072,9 +6273,9 @@ var check_ecc_exports = {};
|
|
|
6072
6273
|
__export(check_ecc_exports, {
|
|
6073
6274
|
checkEcc: () => checkEcc
|
|
6074
6275
|
});
|
|
6075
|
-
async function pathExists(
|
|
6276
|
+
async function pathExists(p8) {
|
|
6076
6277
|
try {
|
|
6077
|
-
await stat(
|
|
6278
|
+
await stat(p8);
|
|
6078
6279
|
return true;
|
|
6079
6280
|
} catch {
|
|
6080
6281
|
return false;
|
|
@@ -6158,9 +6359,9 @@ function commandsFor(hooks, event) {
|
|
|
6158
6359
|
}
|
|
6159
6360
|
function checkInjectInvalidate(deps) {
|
|
6160
6361
|
const settingsPath = deps?.settingsPath ?? getSettingsPath();
|
|
6161
|
-
const readText = deps?.readText ?? ((
|
|
6362
|
+
const readText = deps?.readText ?? ((p8) => {
|
|
6162
6363
|
try {
|
|
6163
|
-
return readFileSync(
|
|
6364
|
+
return readFileSync(p8, "utf8");
|
|
6164
6365
|
} catch {
|
|
6165
6366
|
return null;
|
|
6166
6367
|
}
|
|
@@ -6216,23 +6417,23 @@ function defaultDeps3() {
|
|
|
6216
6417
|
return {
|
|
6217
6418
|
assetsRoot: getAssetsRoot(),
|
|
6218
6419
|
registryPath: getPluginsRegistry(),
|
|
6219
|
-
readText: (
|
|
6420
|
+
readText: (p8) => {
|
|
6220
6421
|
try {
|
|
6221
|
-
return readFileSync(
|
|
6422
|
+
return readFileSync(p8, "utf8");
|
|
6222
6423
|
} catch {
|
|
6223
6424
|
return null;
|
|
6224
6425
|
}
|
|
6225
6426
|
},
|
|
6226
|
-
listDir: (
|
|
6427
|
+
listDir: (p8) => {
|
|
6227
6428
|
try {
|
|
6228
|
-
return readdirSync(
|
|
6429
|
+
return readdirSync(p8);
|
|
6229
6430
|
} catch {
|
|
6230
6431
|
return null;
|
|
6231
6432
|
}
|
|
6232
6433
|
},
|
|
6233
|
-
isDir: (
|
|
6434
|
+
isDir: (p8) => {
|
|
6234
6435
|
try {
|
|
6235
|
-
return statSync(
|
|
6436
|
+
return statSync(p8).isDirectory();
|
|
6236
6437
|
} catch {
|
|
6237
6438
|
return false;
|
|
6238
6439
|
}
|
|
@@ -6363,81 +6564,947 @@ var init_check_ablation = __esm({
|
|
|
6363
6564
|
}
|
|
6364
6565
|
});
|
|
6365
6566
|
|
|
6366
|
-
// src/
|
|
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
|
-
|
|
6400
|
-
|
|
6401
|
-
// 4.23.0 (issue #3) — installed workflow-skill integrity (warn-only): flat
|
|
6402
|
-
// ~/.claude/skills packs can silently shadow shipped workflows; setup self-heals.
|
|
6403
|
-
async () => (await Promise.resolve().then(() => (init_check_skill_integrity(), check_skill_integrity_exports))).checkSkillIntegrity(),
|
|
6404
|
-
// Phase 20 — "update available" version check ('warn' only when behind; 'pass'
|
|
6405
|
-
// when current/ahead/npm-unreachable — fail-soft, never flips the summary).
|
|
6406
|
-
async () => (await Promise.resolve().then(() => (init_check_update(), check_update_exports))).checkUpdate(),
|
|
6407
|
-
// 4.32.4 — dual install-channel conflict (warn-only): npm-global + standalone
|
|
6408
|
-
// binary both present → ambiguous PATH resolution + stale-update trap.
|
|
6409
|
-
async () => (await Promise.resolve().then(() => (init_check_install_channels(), check_install_channels_exports))).checkInstallChannels(),
|
|
6410
|
-
// issue #8 — orphaned harnessed Stop/UserPromptSubmit hooks (warn-only): a hook
|
|
6411
|
-
// pointing at a deleted bin/*.mjs makes Claude Code error MODULE_NOT_FOUND every
|
|
6412
|
-
// prompt; `harnessed uninstall` now strips them.
|
|
6413
|
-
async () => (await Promise.resolve().then(() => (init_check_stale_hooks(), check_stale_hooks_exports))).checkStaleHooks(),
|
|
6414
|
-
// 4.32.22 — ECC per-harness detect (optional; pass unless CC-side ecc overlaps
|
|
6415
|
-
// the official chrome-devtools-mcp plugin → warn). CC plugin registry + codex
|
|
6416
|
-
// sync-clone probed independently.
|
|
6417
|
-
async () => (await Promise.resolve().then(() => (init_check_ecc(), check_ecc_exports))).checkEcc(),
|
|
6418
|
-
// 4.38.0 — half-installed per-turn injection (warn-only): perturn-inject
|
|
6419
|
-
// without perturn-inject-invalidate keeps skipping <project-context> after a
|
|
6420
|
-
// compact/clear has already dropped the copy it is skipping on behalf of.
|
|
6421
|
-
async () => (await Promise.resolve().then(() => (init_check_inject_invalidate(), check_inject_invalidate_exports))).checkInjectInvalidate(),
|
|
6422
|
-
// Phase 56 — silently stale marketplace plugins (warn-only): `claude plugin
|
|
6423
|
-
// install` pins a version into a versioned cache dir and never re-resolves, so
|
|
6424
|
-
// the four cc-plugin-marketplace components drift behind without any signal.
|
|
6425
|
-
// The only comparison in the codebase between a genuinely DETECTED version and
|
|
6426
|
-
// a recorded one — see the header for why the installer-state layer cannot do it.
|
|
6427
|
-
async () => (await Promise.resolve().then(() => (init_check_plugin_staleness(), check_plugin_staleness_exports))).checkPluginStaleness(),
|
|
6428
|
-
// Phase 60 — HARNESSED_OFF left on (warn-only): the kill switch silences every
|
|
6429
|
-
// first-party hook, so a machine that forgot to unset it looks exactly like a
|
|
6430
|
-
// broken install. doctor is where that gets said out loud.
|
|
6431
|
-
async () => (await Promise.resolve().then(() => (init_check_ablation(), check_ablation_exports))).checkAblation()
|
|
6432
|
-
];
|
|
6433
|
-
}
|
|
6434
|
-
});
|
|
6435
|
-
function isUndefinedVariableError(e) {
|
|
6436
|
-
return e instanceof GateEvalError && /undefined variable/i.test(e.message);
|
|
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
|
+
};
|
|
6437
6602
|
}
|
|
6438
|
-
function
|
|
6439
|
-
|
|
6440
|
-
|
|
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
|
|
7489
|
+
// a recorded one — see the header for why the installer-state layer cannot do it.
|
|
7490
|
+
async () => (await Promise.resolve().then(() => (init_check_plugin_staleness(), check_plugin_staleness_exports))).checkPluginStaleness(),
|
|
7491
|
+
// Phase 60 — HARNESSED_OFF left on (warn-only): the kill switch silences every
|
|
7492
|
+
// first-party hook, so a machine that forgot to unset it looks exactly like a
|
|
7493
|
+
// broken install. doctor is where that gets said out loud.
|
|
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()
|
|
7499
|
+
];
|
|
7500
|
+
}
|
|
7501
|
+
});
|
|
7502
|
+
function isUndefinedVariableError(e) {
|
|
7503
|
+
return e instanceof GateEvalError && /undefined variable/i.test(e.message);
|
|
7504
|
+
}
|
|
7505
|
+
function evalGate(expression, context) {
|
|
7506
|
+
try {
|
|
7507
|
+
const parsed = _parserSingleton.parse(expression);
|
|
6441
7508
|
const result = parsed.evaluate(context);
|
|
6442
7509
|
if (typeof result !== "boolean") {
|
|
6443
7510
|
throw new GateEvalError(
|
|
@@ -7032,13 +8099,13 @@ async function gcCompiledArtifacts(opts) {
|
|
|
7032
8099
|
const assetsDir = join(opts.stateRoot, "assets");
|
|
7033
8100
|
for (const e of await readdir(assetsDir, { withFileTypes: true })) {
|
|
7034
8101
|
if (!e.isDirectory()) continue;
|
|
7035
|
-
const
|
|
8102
|
+
const p8 = join(assetsDir, e.name);
|
|
7036
8103
|
if (keep.has(e.name)) {
|
|
7037
|
-
kept.push(
|
|
8104
|
+
kept.push(p8);
|
|
7038
8105
|
continue;
|
|
7039
8106
|
}
|
|
7040
|
-
removed.push(
|
|
7041
|
-
if (!opts.dryRun) await rm(
|
|
8107
|
+
removed.push(p8);
|
|
8108
|
+
if (!opts.dryRun) await rm(p8, { recursive: true, force: true });
|
|
7042
8109
|
}
|
|
7043
8110
|
} catch {
|
|
7044
8111
|
}
|
|
@@ -7046,9 +8113,9 @@ async function gcCompiledArtifacts(opts) {
|
|
|
7046
8113
|
const backupDir = join(opts.stateRoot, "bin-backup");
|
|
7047
8114
|
const vers = (await readdir(backupDir, { withFileTypes: true })).filter((e) => e.isDirectory()).map((e) => e.name).sort(byVersion);
|
|
7048
8115
|
for (const v of vers.slice(0, -1)) {
|
|
7049
|
-
const
|
|
7050
|
-
removed.push(
|
|
7051
|
-
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 });
|
|
7052
8119
|
}
|
|
7053
8120
|
const newest = vers[vers.length - 1];
|
|
7054
8121
|
if (newest) kept.push(join(backupDir, newest));
|
|
@@ -7060,9 +8127,9 @@ async function gcCompiledArtifacts(opts) {
|
|
|
7060
8127
|
const base = basename(opts.execPath);
|
|
7061
8128
|
for (const e of await readdir(dir, { withFileTypes: true })) {
|
|
7062
8129
|
if (!e.isFile() || !e.name.startsWith(`${base}.bak-`)) continue;
|
|
7063
|
-
const
|
|
7064
|
-
removed.push(
|
|
7065
|
-
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 });
|
|
7066
8133
|
}
|
|
7067
8134
|
} catch {
|
|
7068
8135
|
}
|
|
@@ -7085,10 +8152,10 @@ async function dirSizeKb(dir) {
|
|
|
7085
8152
|
if (!cur) break;
|
|
7086
8153
|
const entries = await readdir(cur, { withFileTypes: true });
|
|
7087
8154
|
for (const e of entries) {
|
|
7088
|
-
const
|
|
7089
|
-
if (e.isDirectory()) stack.push(
|
|
8155
|
+
const p8 = join(cur, e.name);
|
|
8156
|
+
if (e.isDirectory()) stack.push(p8);
|
|
7090
8157
|
else if (e.isFile()) {
|
|
7091
|
-
const st = await stat(
|
|
8158
|
+
const st = await stat(p8);
|
|
7092
8159
|
total += st.size;
|
|
7093
8160
|
}
|
|
7094
8161
|
}
|
|
@@ -7164,128 +8231,23 @@ ${t("gc.invalid_duration.fix")}`
|
|
|
7164
8231
|
});
|
|
7165
8232
|
if (r.removed.length > 0) {
|
|
7166
8233
|
console.log(
|
|
7167
|
-
` compiled artifacts ${dryRun ? "to remove" : "removed"}: ${r.removed.length}`
|
|
7168
|
-
);
|
|
7169
|
-
for (const
|
|
7170
|
-
}
|
|
7171
|
-
}
|
|
7172
|
-
} catch {
|
|
7173
|
-
}
|
|
7174
|
-
});
|
|
7175
|
-
}
|
|
7176
|
-
var DURATION_RE;
|
|
7177
|
-
var init_gc = __esm({
|
|
7178
|
-
"src/cli/gc.ts"() {
|
|
7179
|
-
init_package();
|
|
7180
|
-
init_i18n();
|
|
7181
|
-
init_backup();
|
|
7182
|
-
init_version_check();
|
|
7183
|
-
DURATION_RE = /^(\d+)([dhmw])$/;
|
|
7184
|
-
}
|
|
7185
|
-
});
|
|
7186
|
-
async function confirmAt(level, ctx) {
|
|
7187
|
-
if (level === "L4" && !ctx.opts.system) {
|
|
7188
|
-
if (!ctx.opts.nonInteractive) {
|
|
7189
|
-
p.note(
|
|
7190
|
-
"this method requires --system flag (e.g. global npm install affects machine PATH); pass --system to opt in.",
|
|
7191
|
-
"L4 system-wide install"
|
|
7192
|
-
);
|
|
7193
|
-
}
|
|
7194
|
-
return { proceed: false, reason: "flag-missing" };
|
|
7195
|
-
}
|
|
7196
|
-
if (ctx.opts.nonInteractive) {
|
|
7197
|
-
return { proceed: ctx.opts.apply };
|
|
7198
|
-
}
|
|
7199
|
-
if (level === "L1") {
|
|
7200
|
-
p.note("will write project-local files only (safe scope).", "L1 confirm");
|
|
7201
|
-
return { proceed: true };
|
|
7202
|
-
}
|
|
7203
|
-
if (level === "L2") {
|
|
7204
|
-
const ans2 = await p.confirm({ message: "Proceed with install?", initialValue: false });
|
|
7205
|
-
if (p.isCancel(ans2)) return { proceed: false, reason: "user-cancel" };
|
|
7206
|
-
return { proceed: ans2 === true };
|
|
7207
|
-
}
|
|
7208
|
-
if (level === "L3") {
|
|
7209
|
-
const first = await p.confirm({ message: "Proceed with install?", initialValue: false });
|
|
7210
|
-
if (p.isCancel(first)) return { proceed: false, reason: "user-cancel" };
|
|
7211
|
-
if (first !== true) return { proceed: false };
|
|
7212
|
-
const second = await p.confirm({
|
|
7213
|
-
// v4.14.0 — wording generalized: the shared user-scope config is
|
|
7214
|
-
// ~/.claude.json on claude, ~/.codex/config.toml on codex.
|
|
7215
|
-
message: "This affects other plugins (the harness user-scope config is shared state). Confirm again?",
|
|
7216
|
-
initialValue: false
|
|
7217
|
-
});
|
|
7218
|
-
if (p.isCancel(second)) return { proceed: false, reason: "user-cancel" };
|
|
7219
|
-
return { proceed: second === true };
|
|
7220
|
-
}
|
|
7221
|
-
const ans = await p.confirm({
|
|
7222
|
-
message: "System-wide install will modify global PATH. Proceed?",
|
|
7223
|
-
initialValue: false
|
|
7224
|
-
});
|
|
7225
|
-
if (p.isCancel(ans)) return { proceed: false, reason: "user-cancel" };
|
|
7226
|
-
return { proceed: ans === true };
|
|
7227
|
-
}
|
|
7228
|
-
var init_confirm = __esm({
|
|
7229
|
-
"src/installers/lib/confirm.ts"() {
|
|
7230
|
-
}
|
|
7231
|
-
});
|
|
7232
|
-
function colorize(line) {
|
|
7233
|
-
if (!pc.isColorSupported) return line;
|
|
7234
|
-
if (line.startsWith("+") && !line.startsWith("+++")) return pc.green(line);
|
|
7235
|
-
if (line.startsWith("-") && !line.startsWith("---")) return pc.red(line);
|
|
7236
|
-
if (line.startsWith("@@")) return pc.cyan(line);
|
|
7237
|
-
return line;
|
|
7238
|
-
}
|
|
7239
|
-
function diffOneFile(file) {
|
|
7240
|
-
const patch = createPatch(file.target, file.oldText, file.newText, "", "", {
|
|
7241
|
-
stripTrailingCr: true
|
|
7242
|
-
});
|
|
7243
|
-
const lines = patch.split("\n");
|
|
7244
|
-
let added = 0;
|
|
7245
|
-
let removed = 0;
|
|
7246
|
-
for (const ln of lines) {
|
|
7247
|
-
if (ln.startsWith("+") && !ln.startsWith("+++")) added++;
|
|
7248
|
-
else if (ln.startsWith("-") && !ln.startsWith("---")) removed++;
|
|
7249
|
-
}
|
|
7250
|
-
return { lines, added, removed };
|
|
7251
|
-
}
|
|
7252
|
-
function renderDiff(plan, ctx) {
|
|
7253
|
-
if (plan.files.length === 0) return "(no file changes)\n";
|
|
7254
|
-
const out = [];
|
|
7255
|
-
let totalAdded = 0;
|
|
7256
|
-
let totalRemoved = 0;
|
|
7257
|
-
for (const file of plan.files) {
|
|
7258
|
-
const { lines, added, removed } = diffOneFile(file);
|
|
7259
|
-
totalAdded += added;
|
|
7260
|
-
totalRemoved += removed;
|
|
7261
|
-
const folded = !ctx.opts.fullDiff && lines.length > FOLD_THRESHOLD;
|
|
7262
|
-
const visible = folded ? lines.slice(0, FOLD_HEAD) : lines;
|
|
7263
|
-
for (const ln of visible) out.push(colorize(ln));
|
|
7264
|
-
if (folded) {
|
|
7265
|
-
const more = lines.length - FOLD_HEAD;
|
|
7266
|
-
out.push(pc.dim(`... ${more} more lines (use --full-diff to expand)`));
|
|
7267
|
-
}
|
|
7268
|
-
}
|
|
7269
|
-
const summary = `will modify ${plan.files.length} file${plan.files.length === 1 ? "" : "s"} (${totalAdded} added, ${totalRemoved} removed)`;
|
|
7270
|
-
out.push("");
|
|
7271
|
-
out.push(pc.bold(summary));
|
|
7272
|
-
return `${out.join("\n")}
|
|
7273
|
-
`;
|
|
7274
|
-
}
|
|
7275
|
-
var FOLD_THRESHOLD, FOLD_HEAD;
|
|
7276
|
-
var init_diff = __esm({
|
|
7277
|
-
"src/installers/lib/diff.ts"() {
|
|
7278
|
-
FOLD_THRESHOLD = 200;
|
|
7279
|
-
FOLD_HEAD = 100;
|
|
7280
|
-
}
|
|
7281
|
-
});
|
|
7282
|
-
|
|
7283
|
-
// src/installers/lib/err.ts
|
|
7284
|
-
function err(ctx, path, message, keyword) {
|
|
7285
|
-
return { file: ctx.manifest.metadata.name, path, message, line: null, column: null, keyword };
|
|
8234
|
+
` compiled artifacts ${dryRun ? "to remove" : "removed"}: ${r.removed.length}`
|
|
8235
|
+
);
|
|
8236
|
+
for (const p8 of r.removed) console.log(` ${p8}`);
|
|
8237
|
+
}
|
|
8238
|
+
}
|
|
8239
|
+
} catch {
|
|
8240
|
+
}
|
|
8241
|
+
});
|
|
7286
8242
|
}
|
|
7287
|
-
var
|
|
7288
|
-
|
|
8243
|
+
var DURATION_RE;
|
|
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])$/;
|
|
7289
8251
|
}
|
|
7290
8252
|
});
|
|
7291
8253
|
|
|
@@ -7340,74 +8302,13 @@ var init_preflight = __esm({
|
|
|
7340
8302
|
GIT_REF_SHAPE = /^([a-f0-9]{7,40}|v?\d+\.\d+\.\d+([.-][\w.-]+)?)$/;
|
|
7341
8303
|
}
|
|
7342
8304
|
});
|
|
7343
|
-
function statePath2(_cwd) {
|
|
7344
|
-
return harnessedFile("state.json");
|
|
7345
|
-
}
|
|
7346
|
-
async function readState(cwd) {
|
|
7347
|
-
const path = statePath2();
|
|
7348
|
-
let raw;
|
|
7349
|
-
try {
|
|
7350
|
-
raw = await readFile(path, "utf8");
|
|
7351
|
-
} catch (err2) {
|
|
7352
|
-
if (err2.code === "ENOENT") {
|
|
7353
|
-
return { ...DEFAULT_STATE, installed: {} };
|
|
7354
|
-
}
|
|
7355
|
-
throw err2;
|
|
7356
|
-
}
|
|
7357
|
-
try {
|
|
7358
|
-
const parsed = JSON.parse(raw);
|
|
7359
|
-
if (parsed.version !== "1" || typeof parsed.installed !== "object") {
|
|
7360
|
-
return { ...DEFAULT_STATE, installed: {} };
|
|
7361
|
-
}
|
|
7362
|
-
return parsed;
|
|
7363
|
-
} catch {
|
|
7364
|
-
return { ...DEFAULT_STATE, installed: {} };
|
|
7365
|
-
}
|
|
7366
|
-
}
|
|
7367
|
-
async function writeState(cwd, state) {
|
|
7368
|
-
const path = statePath2();
|
|
7369
|
-
const tmp = `${path}.tmp`;
|
|
7370
|
-
await mkdir(dirname(path), { recursive: true });
|
|
7371
|
-
await writeFile(tmp, `${JSON.stringify(state, null, 2)}
|
|
7372
|
-
`, "utf8");
|
|
7373
|
-
await rename(tmp, path);
|
|
7374
|
-
}
|
|
7375
|
-
async function updateInstalled(cwd, name, version, manifestSha1) {
|
|
7376
|
-
const state = await readState();
|
|
7377
|
-
state.installed[name] = {
|
|
7378
|
-
version,
|
|
7379
|
-
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7380
|
-
manifestSha1
|
|
7381
|
-
};
|
|
7382
|
-
await writeState(cwd, state);
|
|
7383
|
-
}
|
|
7384
|
-
async function recordObservedInstall(cwd, name, version, manifestSha1) {
|
|
7385
|
-
try {
|
|
7386
|
-
const state = await readState(cwd);
|
|
7387
|
-
const prev = state.installed[name];
|
|
7388
|
-
if (prev && prev.version === version && prev.manifestSha1 === manifestSha1) return;
|
|
7389
|
-
state.installed[name] = {
|
|
7390
|
-
version,
|
|
7391
|
-
installedAt: prev?.installedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
7392
|
-
manifestSha1
|
|
7393
|
-
};
|
|
7394
|
-
await writeState(cwd, state);
|
|
7395
|
-
} catch {
|
|
7396
|
-
}
|
|
7397
|
-
}
|
|
7398
|
-
var DEFAULT_STATE;
|
|
7399
|
-
var init_state2 = __esm({
|
|
7400
|
-
"src/installers/lib/state.ts"() {
|
|
7401
|
-
init_harnessedRoot();
|
|
7402
|
-
DEFAULT_STATE = { version: "1", installed: {} };
|
|
7403
|
-
}
|
|
7404
|
-
});
|
|
7405
8305
|
var installCcHookAdd;
|
|
7406
8306
|
var init_ccHookAdd2 = __esm({
|
|
7407
8307
|
"src/installers/ccHookAdd.ts"() {
|
|
7408
8308
|
init_security();
|
|
7409
8309
|
init_assetsRoot();
|
|
7410
8310
|
init_platform();
|
|
8311
|
+
init_codexHookAdd();
|
|
7411
8312
|
init_backup();
|
|
7412
8313
|
init_confirm();
|
|
7413
8314
|
init_diff();
|
|
@@ -7436,6 +8337,7 @@ var init_ccHookAdd2 = __esm({
|
|
|
7436
8337
|
const e = pre.errors[0] ?? err(ctx, "/", "preflight failed", "preflight");
|
|
7437
8338
|
return { ok: false, phase: "preflight", error: e };
|
|
7438
8339
|
}
|
|
8340
|
+
if (detectPlatform().id === "codex") return installCodexHook(ctx);
|
|
7439
8341
|
const settingsPath = getSettingsPath();
|
|
7440
8342
|
if (settingsPath === null) return { aborted: true, reason: "platform-mismatch" };
|
|
7441
8343
|
let existing;
|
|
@@ -7637,56 +8539,17 @@ var init_gitCloneArgs = __esm({
|
|
|
7637
8539
|
CLAUSE_END = /* @__PURE__ */ new Set(["&&", ";", "|", "||"]);
|
|
7638
8540
|
}
|
|
7639
8541
|
});
|
|
7640
|
-
function descendantsOf(pid) {
|
|
7641
|
-
const r = spawnSync("pgrep", ["-P", String(pid)], { encoding: "utf8", timeout: 2e3 });
|
|
7642
|
-
if (r.status !== 0 || typeof r.stdout !== "string") return [];
|
|
7643
|
-
const out = [];
|
|
7644
|
-
for (const tok2 of r.stdout.split(/\s+/)) {
|
|
7645
|
-
const child = Number(tok2);
|
|
7646
|
-
if (Number.isInteger(child) && child > 0) out.push(child, ...descendantsOf(child));
|
|
7647
|
-
}
|
|
7648
|
-
return out;
|
|
7649
|
-
}
|
|
7650
|
-
function killProcessTree(child) {
|
|
7651
|
-
const pid = child.pid;
|
|
7652
|
-
if (pid === void 0) {
|
|
7653
|
-
child.kill("SIGKILL");
|
|
7654
|
-
return;
|
|
7655
|
-
}
|
|
7656
|
-
if (process.platform === "win32") {
|
|
7657
|
-
const r = spawnSync("taskkill", ["/PID", String(pid), "/T", "/F"], {
|
|
7658
|
-
windowsHide: true,
|
|
7659
|
-
stdio: "ignore",
|
|
7660
|
-
timeout: 5e3
|
|
7661
|
-
});
|
|
7662
|
-
if (r.status === 0) return;
|
|
7663
|
-
child.kill("SIGKILL");
|
|
7664
|
-
return;
|
|
7665
|
-
}
|
|
7666
|
-
const tree = descendantsOf(pid);
|
|
7667
|
-
child.kill("SIGKILL");
|
|
7668
|
-
for (const d of tree) {
|
|
7669
|
-
try {
|
|
7670
|
-
process.kill(d, "SIGKILL");
|
|
7671
|
-
} catch {
|
|
7672
|
-
}
|
|
7673
|
-
}
|
|
7674
|
-
}
|
|
7675
|
-
var init_killTree = __esm({
|
|
7676
|
-
"src/installers/lib/killTree.ts"() {
|
|
7677
|
-
}
|
|
7678
|
-
});
|
|
7679
8542
|
function evalClause(clause, home) {
|
|
7680
8543
|
const m = clause.match(CLAUSE_RE);
|
|
7681
8544
|
if (!m?.[1] || !m[2]) return null;
|
|
7682
8545
|
const flag = m[1];
|
|
7683
|
-
let
|
|
7684
|
-
if (UNSAFE_PATH_RE.test(
|
|
7685
|
-
if (
|
|
7686
|
-
else if (
|
|
7687
|
-
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;
|
|
7688
8551
|
try {
|
|
7689
|
-
const st = statSync(
|
|
8552
|
+
const st = statSync(p8);
|
|
7690
8553
|
if (flag === "f") return st.isFile();
|
|
7691
8554
|
if (flag === "d") return st.isDirectory();
|
|
7692
8555
|
return true;
|
|
@@ -7726,29 +8589,6 @@ var init_nativeTest = __esm({
|
|
|
7726
8589
|
UNSAFE_PATH_RE = /[|&;<>()*?"'`$={}[\]]/;
|
|
7727
8590
|
}
|
|
7728
8591
|
});
|
|
7729
|
-
function getMcpSpawnCwd() {
|
|
7730
|
-
return homedir();
|
|
7731
|
-
}
|
|
7732
|
-
function getNeutralSpawnCwd() {
|
|
7733
|
-
const override = process.env.HARNESSED_SPAWN_CWD;
|
|
7734
|
-
if (override !== void 0 && override.trim().length > 0) return override.trim();
|
|
7735
|
-
try {
|
|
7736
|
-
const dir = join(detectPlatform().stateRoot, ".spawn");
|
|
7737
|
-
mkdirSync(dir, { recursive: true });
|
|
7738
|
-
const sentinel = join(dir, "package.json");
|
|
7739
|
-
if (!existsSync(sentinel)) writeFileSync(sentinel, NEUTRAL_SENTINEL, "utf8");
|
|
7740
|
-
return dir;
|
|
7741
|
-
} catch {
|
|
7742
|
-
return null;
|
|
7743
|
-
}
|
|
7744
|
-
}
|
|
7745
|
-
var NEUTRAL_SENTINEL;
|
|
7746
|
-
var init_safeCwd = __esm({
|
|
7747
|
-
"src/installers/lib/safeCwd.ts"() {
|
|
7748
|
-
init_platform();
|
|
7749
|
-
NEUTRAL_SENTINEL = '{\n "name": "harnessed-neutral-spawn",\n "private": true\n}\n';
|
|
7750
|
-
}
|
|
7751
|
-
});
|
|
7752
8592
|
function expandTildeForWindows(cmd) {
|
|
7753
8593
|
const home = homedir().replace(/\\/g, "/");
|
|
7754
8594
|
return cmd.replace(/(^|[\s"'`(])~\//g, `$1${home}/`);
|
|
@@ -8015,6 +8855,8 @@ async function isAlreadyInstalled(ctx, opts = {}) {
|
|
|
8015
8855
|
if (ctx.opts.dryRun) return false;
|
|
8016
8856
|
const installCfg = ctx.manifest.spec.install;
|
|
8017
8857
|
if (installCfg.method === "cc-hook-add") {
|
|
8858
|
+
if (detectPlatform().id === "codex")
|
|
8859
|
+
return isCodexPluginInstalled(codexHookPluginId(ctx.manifest.metadata.name));
|
|
8018
8860
|
const settingsPath = getSettingsPath();
|
|
8019
8861
|
let raw = null;
|
|
8020
8862
|
if (settingsPath !== null) {
|
|
@@ -8051,6 +8893,8 @@ var init_idempotent = __esm({
|
|
|
8051
8893
|
init_assetsRoot();
|
|
8052
8894
|
init_platform();
|
|
8053
8895
|
init_binaryProbe();
|
|
8896
|
+
init_codexHookPlugin();
|
|
8897
|
+
init_codexPlugins();
|
|
8054
8898
|
init_gitCloneArgs();
|
|
8055
8899
|
init_hookEntry();
|
|
8056
8900
|
init_readClaudeConfig();
|
|
@@ -8062,96 +8906,6 @@ var init_idempotent = __esm({
|
|
|
8062
8906
|
};
|
|
8063
8907
|
}
|
|
8064
8908
|
});
|
|
8065
|
-
function escapeCommand(cmd) {
|
|
8066
|
-
return cmd.replace(META, "^$1");
|
|
8067
|
-
}
|
|
8068
|
-
function escapeArgument(arg, doubleEscape) {
|
|
8069
|
-
let a = `${arg}`;
|
|
8070
|
-
a = a.replace(/(\\*)"/g, '$1$1\\"');
|
|
8071
|
-
a = a.replace(/(\\*)$/, "$1$1");
|
|
8072
|
-
a = `"${a}"`;
|
|
8073
|
-
a = a.replace(META, "^$1");
|
|
8074
|
-
a = a.replace(META, "^$1");
|
|
8075
|
-
return a;
|
|
8076
|
-
}
|
|
8077
|
-
function resolveWindowsBin(bin, env = process.env, isFile = (p7) => existsSync(p7) && statSync(p7).isFile()) {
|
|
8078
|
-
const dirs = (env.PATH ?? env.Path ?? "").split(";").filter(Boolean);
|
|
8079
|
-
const exts = (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
8080
|
-
const candidates = extname(bin) ? [""] : exts;
|
|
8081
|
-
for (const dir of dirs) {
|
|
8082
|
-
for (const ext of candidates) {
|
|
8083
|
-
const p7 = join40(dir, `${bin}${ext}`);
|
|
8084
|
-
if (isFile(p7)) return p7;
|
|
8085
|
-
}
|
|
8086
|
-
}
|
|
8087
|
-
return null;
|
|
8088
|
-
}
|
|
8089
|
-
function planWindowsSpawn(bin, args, resolved) {
|
|
8090
|
-
if (!resolved) return { command: bin, args, verbatim: false };
|
|
8091
|
-
const ext = extname(resolved).toLowerCase();
|
|
8092
|
-
if (ext !== ".cmd" && ext !== ".bat") {
|
|
8093
|
-
return { command: resolved, args, verbatim: false };
|
|
8094
|
-
}
|
|
8095
|
-
const line = [escapeCommand(resolved), ...args.map((a) => escapeArgument(a))].join(" ");
|
|
8096
|
-
return { command: "cmd.exe", args: ["/d", "/s", "/c", `"${line}"`], verbatim: true };
|
|
8097
|
-
}
|
|
8098
|
-
var extname, join40, META;
|
|
8099
|
-
var init_winSpawn = __esm({
|
|
8100
|
-
"src/installers/lib/winSpawn.ts"() {
|
|
8101
|
-
({ extname, join: join40 } = win32);
|
|
8102
|
-
META = /([()\][%!^"`<>&|;, *?])/g;
|
|
8103
|
-
}
|
|
8104
|
-
});
|
|
8105
|
-
function runHarnessArgs(bin, args, cwd, timeoutMs = 15e3) {
|
|
8106
|
-
return new Promise((resolve23) => {
|
|
8107
|
-
const isWin = process.platform === "win32";
|
|
8108
|
-
const stdio = ["ignore", "pipe", "pipe"];
|
|
8109
|
-
let child;
|
|
8110
|
-
if (isWin) {
|
|
8111
|
-
const plan = planWindowsSpawn(bin, args, resolveWindowsBin(bin));
|
|
8112
|
-
child = spawn(plan.command, plan.args, {
|
|
8113
|
-
cwd,
|
|
8114
|
-
windowsHide: true,
|
|
8115
|
-
stdio,
|
|
8116
|
-
shell: false,
|
|
8117
|
-
windowsVerbatimArguments: plan.verbatim
|
|
8118
|
-
});
|
|
8119
|
-
} else {
|
|
8120
|
-
child = spawn(bin, args, { cwd, shell: false, stdio });
|
|
8121
|
-
}
|
|
8122
|
-
let stdout2 = "";
|
|
8123
|
-
let stderr = "";
|
|
8124
|
-
child.stdout?.setEncoding("utf8").on("data", (c) => {
|
|
8125
|
-
stdout2 += c;
|
|
8126
|
-
});
|
|
8127
|
-
child.stderr?.setEncoding("utf8").on("data", (c) => {
|
|
8128
|
-
stderr += c;
|
|
8129
|
-
});
|
|
8130
|
-
const timer = setTimeout(() => {
|
|
8131
|
-
killProcessTree(child);
|
|
8132
|
-
resolve23({ exitCode: -1, stdout: stdout2, stderr: `${stderr}[timeout after ${timeoutMs}ms]` });
|
|
8133
|
-
}, timeoutMs);
|
|
8134
|
-
child.on("error", (e) => {
|
|
8135
|
-
clearTimeout(timer);
|
|
8136
|
-
const enoent = e.code === "ENOENT";
|
|
8137
|
-
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;
|
|
8138
|
-
resolve23({ exitCode: -1, stdout: stdout2, stderr: `${stderr}${msg}` });
|
|
8139
|
-
});
|
|
8140
|
-
child.on("close", (code) => {
|
|
8141
|
-
clearTimeout(timer);
|
|
8142
|
-
resolve23({ exitCode: code ?? -1, stdout: stdout2, stderr });
|
|
8143
|
-
});
|
|
8144
|
-
});
|
|
8145
|
-
}
|
|
8146
|
-
function runArgs(claudeArgs, cwd, timeoutMs = 15e3) {
|
|
8147
|
-
return runHarnessArgs("claude", claudeArgs, cwd, timeoutMs);
|
|
8148
|
-
}
|
|
8149
|
-
var init_runClaudeArgs = __esm({
|
|
8150
|
-
"src/installers/lib/runClaudeArgs.ts"() {
|
|
8151
|
-
init_killTree();
|
|
8152
|
-
init_winSpawn();
|
|
8153
|
-
}
|
|
8154
|
-
});
|
|
8155
8909
|
|
|
8156
8910
|
// src/installers/ccPluginMarketplace.ts
|
|
8157
8911
|
function parseCmd(cmd) {
|
|
@@ -8172,6 +8926,7 @@ var init_ccPluginMarketplace2 = __esm({
|
|
|
8172
8926
|
init_security();
|
|
8173
8927
|
init_platform();
|
|
8174
8928
|
init_backup();
|
|
8929
|
+
init_codexPlugins();
|
|
8175
8930
|
init_confirm();
|
|
8176
8931
|
init_diff();
|
|
8177
8932
|
init_err();
|
|
@@ -8277,7 +9032,7 @@ ${newEntry}
|
|
|
8277
9032
|
return { aborted: true, reason };
|
|
8278
9033
|
}
|
|
8279
9034
|
if (ctx.opts.dryRun) return { aborted: true, reason: "user-cancel" };
|
|
8280
|
-
const bk = await backup(plan, ctx);
|
|
9035
|
+
const bk = await backup(bin === "codex" ? { files: [] } : plan, ctx);
|
|
8281
9036
|
if (!bk.ok) return { ok: false, phase: "preflight", error: bk.error };
|
|
8282
9037
|
const spawnCwd = install.cwd ?? getMcpSpawnCwd();
|
|
8283
9038
|
let stepOneStderr = "";
|
|
@@ -8300,6 +9055,7 @@ ${newEntry}
|
|
|
8300
9055
|
)
|
|
8301
9056
|
};
|
|
8302
9057
|
}
|
|
9058
|
+
if (bin === "codex") invalidateCodexPluginCache();
|
|
8303
9059
|
const registered = await isPluginRegistered(pluginName);
|
|
8304
9060
|
if (!registered) {
|
|
8305
9061
|
const cfgLabel = bin === "codex" ? "`codex plugin list` output" : "enabledPlugins map of ~/.claude.json";
|
|
@@ -9321,7 +10077,7 @@ var init_installers = __esm({
|
|
|
9321
10077
|
// Phase 2.4 W3 T3.1 (D-04 § 3.1) — 7th installer.
|
|
9322
10078
|
"cc-hook-add": installCcHookAdd
|
|
9323
10079
|
};
|
|
9324
|
-
CLAUDE_ONLY_METHODS = /* @__PURE__ */ new Set(["cc-plugin-marketplace"
|
|
10080
|
+
CLAUDE_ONLY_METHODS = /* @__PURE__ */ new Set(["cc-plugin-marketplace"]);
|
|
9325
10081
|
}
|
|
9326
10082
|
});
|
|
9327
10083
|
var PinnedUpstream, KnownGoodV1;
|
|
@@ -9702,7 +10458,7 @@ function forwardPointer(repoRoot, wf) {
|
|
|
9702
10458
|
const snapshot = scanPlanning({ repoRoot, currentWorkflow: wf, includeTasks: false });
|
|
9703
10459
|
const unit = deriveNext(snapshot);
|
|
9704
10460
|
if (unit.kind !== "phase" && unit.kind !== "task") return null;
|
|
9705
|
-
return { unit, remainingPhases: snapshot.phases.filter((
|
|
10461
|
+
return { unit, remainingPhases: snapshot.phases.filter((p8) => !p8.complete).length };
|
|
9706
10462
|
}
|
|
9707
10463
|
var INTENT_TTL_MS, STALE_LEDGER_MS, DEFAULT_INJECT_BUDGET, tok;
|
|
9708
10464
|
var init_injectState = __esm({
|
|
@@ -9725,7 +10481,7 @@ var release_preflight_exports = {};
|
|
|
9725
10481
|
__export(release_preflight_exports, {
|
|
9726
10482
|
anyFailed: () => anyFailed,
|
|
9727
10483
|
collectPreflight: () => collectPreflight,
|
|
9728
|
-
defaultDeps: () =>
|
|
10484
|
+
defaultDeps: () => defaultDeps5
|
|
9729
10485
|
});
|
|
9730
10486
|
function unreleasedSection(changelog) {
|
|
9731
10487
|
const start = changelog.indexOf("## [Unreleased]");
|
|
@@ -9780,7 +10536,7 @@ function collectPreflight(deps) {
|
|
|
9780
10536
|
function anyFailed(checks) {
|
|
9781
10537
|
return checks.some((c) => c.status === "fail");
|
|
9782
10538
|
}
|
|
9783
|
-
function
|
|
10539
|
+
function defaultDeps5(cwd) {
|
|
9784
10540
|
let changelog = "";
|
|
9785
10541
|
let version = "";
|
|
9786
10542
|
try {
|
|
@@ -10124,7 +10880,10 @@ ${pending.length} optional component(s) available (opt-in \u2014 none selected b
|
|
|
10124
10880
|
...PROBE_OPTS,
|
|
10125
10881
|
apply: true,
|
|
10126
10882
|
// see IMPL NOTE header — this confirm IS the L4 opt-in for npm-cli globals.
|
|
10127
|
-
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"
|
|
10128
10887
|
};
|
|
10129
10888
|
const r = await runInstall(manifest, opts);
|
|
10130
10889
|
if ("aborted" in r) {
|
|
@@ -10133,6 +10892,7 @@ ${pending.length} optional component(s) available (opt-in \u2014 none selected b
|
|
|
10133
10892
|
} else if (r.ok) {
|
|
10134
10893
|
out.installed.push(name);
|
|
10135
10894
|
console.log(` \u2713 installed ${name}`);
|
|
10895
|
+
if (r.trustPending) console.log(` \u26A0 ${r.trustPending}`);
|
|
10136
10896
|
if (name === "codegraph") {
|
|
10137
10897
|
console.log(" run `codegraph init` in each project to build its index");
|
|
10138
10898
|
}
|
|
@@ -10296,11 +11056,11 @@ function assetNameFor(platform, arch) {
|
|
|
10296
11056
|
const ext = platform === "win32" ? ".exe" : "";
|
|
10297
11057
|
return `harnessed-${plat}-${arch}${ext}`;
|
|
10298
11058
|
}
|
|
10299
|
-
function normalized(
|
|
10300
|
-
return
|
|
11059
|
+
function normalized(p8) {
|
|
11060
|
+
return p8.replace(/\\/g, "/");
|
|
10301
11061
|
}
|
|
10302
|
-
async function sha256File(
|
|
10303
|
-
const buf = await readFile(
|
|
11062
|
+
async function sha256File(p8) {
|
|
11063
|
+
const buf = await readFile(p8);
|
|
10304
11064
|
return createHash("sha256").update(buf).digest("hex");
|
|
10305
11065
|
}
|
|
10306
11066
|
function parseShaText(text) {
|
|
@@ -11070,10 +11830,10 @@ function hasCommitHash(line) {
|
|
|
11070
11830
|
return false;
|
|
11071
11831
|
}
|
|
11072
11832
|
function read(cwd, rel) {
|
|
11073
|
-
const
|
|
11074
|
-
if (!existsSync(
|
|
11833
|
+
const p8 = join(cwd, rel);
|
|
11834
|
+
if (!existsSync(p8)) return null;
|
|
11075
11835
|
try {
|
|
11076
|
-
return readFileSync(
|
|
11836
|
+
return readFileSync(p8, "utf8");
|
|
11077
11837
|
} catch {
|
|
11078
11838
|
return null;
|
|
11079
11839
|
}
|
|
@@ -11157,6 +11917,19 @@ function shouldGateForHookPayload(raw) {
|
|
|
11157
11917
|
const cmd = payload.tool_input?.command;
|
|
11158
11918
|
return typeof cmd === "string" && /\bgit\s+(?:-\S+\s+)*commit\b/.test(cmd);
|
|
11159
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
|
+
}
|
|
11160
11933
|
async function readStdin() {
|
|
11161
11934
|
if (process.stdin.isTTY) return "";
|
|
11162
11935
|
try {
|
|
@@ -11170,7 +11943,7 @@ async function readStdin() {
|
|
|
11170
11943
|
function registerCheckDocs(program2) {
|
|
11171
11944
|
program2.command("check-docs").description(
|
|
11172
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."
|
|
11173
|
-
).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(
|
|
11174
11947
|
async (opts) => {
|
|
11175
11948
|
if (opts.hook && isAblated()) process.exit(0);
|
|
11176
11949
|
if (opts.hook && !shouldGateForHookPayload(await readStdin())) process.exit(0);
|
|
@@ -11182,6 +11955,16 @@ function registerCheckDocs(program2) {
|
|
|
11182
11955
|
});
|
|
11183
11956
|
const code = exitCodeFor(violations);
|
|
11184
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
|
+
}
|
|
11185
11968
|
if (opts.json) {
|
|
11186
11969
|
console.log(JSON.stringify({ violations, summary, exit_code: code }, null, 2));
|
|
11187
11970
|
} else if (violations.length === 0) {
|
|
@@ -11957,8 +12740,8 @@ function deriveGitFacts(run) {
|
|
|
11957
12740
|
if (out === null) continue;
|
|
11958
12741
|
sawNames = true;
|
|
11959
12742
|
for (const row of out.split(/\r?\n/)) {
|
|
11960
|
-
const
|
|
11961
|
-
if (
|
|
12743
|
+
const p8 = row.trim();
|
|
12744
|
+
if (p8) files.add(p8);
|
|
11962
12745
|
}
|
|
11963
12746
|
}
|
|
11964
12747
|
return {
|
|
@@ -11980,10 +12763,10 @@ var ORCHESTRATION_SURFACE = [
|
|
|
11980
12763
|
"src/checkpoint/ledger.ts"
|
|
11981
12764
|
];
|
|
11982
12765
|
function onOrchestrationSurface(path) {
|
|
11983
|
-
const
|
|
11984
|
-
if (
|
|
11985
|
-
if (/^workflows\/.+\/SKILL(\.[A-Za-z-]+)?\.md$/.test(
|
|
11986
|
-
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);
|
|
11987
12770
|
}
|
|
11988
12771
|
function deriveSecondOpinion(run) {
|
|
11989
12772
|
const tagOut = run(["describe", "--tags", "--abbrev=0"]);
|
|
@@ -12175,17 +12958,17 @@ async function runFactsPlan(master, raw, deps = defaultRunDeps, gitRun = default
|
|
|
12175
12958
|
}
|
|
12176
12959
|
};
|
|
12177
12960
|
const envelope = buildFactsEnvelope(master, gated, derived);
|
|
12178
|
-
const
|
|
12961
|
+
const json2 = JSON.stringify(envelope, null, 2);
|
|
12179
12962
|
if (raw.out) {
|
|
12180
12963
|
try {
|
|
12181
|
-
await writeFile(raw.out,
|
|
12964
|
+
await writeFile(raw.out, json2, "utf8");
|
|
12182
12965
|
} catch (err2) {
|
|
12183
12966
|
deps.error(`error: failed to write --out ${raw.out} \u2014 ${err2.message}`);
|
|
12184
12967
|
deps.exit(1);
|
|
12185
12968
|
return;
|
|
12186
12969
|
}
|
|
12187
12970
|
}
|
|
12188
|
-
deps.log(
|
|
12971
|
+
deps.log(json2);
|
|
12189
12972
|
deps.exit(0);
|
|
12190
12973
|
return;
|
|
12191
12974
|
}
|
|
@@ -12204,7 +12987,7 @@ init_gc();
|
|
|
12204
12987
|
// src/cli/injectStateCmd.ts
|
|
12205
12988
|
init_assetsRoot();
|
|
12206
12989
|
function registerInjectState(program2) {
|
|
12207
|
-
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 () => {
|
|
12208
12991
|
try {
|
|
12209
12992
|
const mjs = join(getAssetsRoot(), "bin", "harnessed-inject-state.mjs");
|
|
12210
12993
|
if (!existsSync(mjs)) return;
|
|
@@ -12233,6 +13016,9 @@ function registerInstall(program2) {
|
|
|
12233
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(
|
|
12234
13017
|
"--known-good",
|
|
12235
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)"
|
|
12236
13022
|
).action(async (name, raw) => {
|
|
12237
13023
|
const { resolveAlias: resolveAlias2 } = await Promise.resolve().then(() => (init_aliases(), aliases_exports));
|
|
12238
13024
|
const resolvedName = resolveAlias2(name) ?? name;
|
|
@@ -12242,10 +13028,10 @@ function registerInstall(program2) {
|
|
|
12242
13028
|
);
|
|
12243
13029
|
let yamlSrc;
|
|
12244
13030
|
let chosenPath;
|
|
12245
|
-
for (const
|
|
13031
|
+
for (const p8 of candidatePaths) {
|
|
12246
13032
|
try {
|
|
12247
|
-
yamlSrc = await readFile(
|
|
12248
|
-
chosenPath =
|
|
13033
|
+
yamlSrc = await readFile(p8, "utf8");
|
|
13034
|
+
chosenPath = p8;
|
|
12249
13035
|
break;
|
|
12250
13036
|
} catch {
|
|
12251
13037
|
}
|
|
@@ -12270,7 +13056,10 @@ ${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
|
12270
13056
|
system: raw.system === true,
|
|
12271
13057
|
nonInteractive: raw.nonInteractive === true,
|
|
12272
13058
|
fullDiff: raw.fullDiff === true,
|
|
12273
|
-
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"
|
|
12274
13063
|
};
|
|
12275
13064
|
if (raw.knownGood) {
|
|
12276
13065
|
const { getPinnedVersion: getPinnedVersion2 } = await Promise.resolve().then(() => (init_knownGood(), knownGood_exports));
|
|
@@ -12292,6 +13081,7 @@ ${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
|
12292
13081
|
console.log(
|
|
12293
13082
|
version ? t(`${keyBase}_with_version`, { name: v.manifest.metadata.name, version }) : t(keyBase, { name: v.manifest.metadata.name })
|
|
12294
13083
|
);
|
|
13084
|
+
if (result.trustPending) console.log(`\u26A0 ${result.trustPending}`);
|
|
12295
13085
|
process.exit(0);
|
|
12296
13086
|
}
|
|
12297
13087
|
console.error(formatError(result.error));
|
|
@@ -13624,10 +14414,10 @@ ${rp.checklist.map((c, i) => ` ${i + 1}. ${c}`).join("\n")}` : "";
|
|
|
13624
14414
|
}
|
|
13625
14415
|
function isRalphLoopOptIn(phase) {
|
|
13626
14416
|
if (!phase || typeof phase !== "object") return false;
|
|
13627
|
-
const
|
|
13628
|
-
if (
|
|
13629
|
-
if (
|
|
13630
|
-
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;
|
|
13631
14421
|
if (fb?.max_iterations_exceeded !== void 0) return true;
|
|
13632
14422
|
return false;
|
|
13633
14423
|
}
|
|
@@ -14093,8 +14883,8 @@ function registerReleasePreflight(program2) {
|
|
|
14093
14883
|
program2.command("release-preflight").description(
|
|
14094
14884
|
"Read-only release-readiness gate (CHANGELOG / version / git-clean / tag). Exits 1 if not ready."
|
|
14095
14885
|
).action(async () => {
|
|
14096
|
-
const { collectPreflight: collectPreflight2, anyFailed: anyFailed2, defaultDeps:
|
|
14097
|
-
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()));
|
|
14098
14888
|
console.log("\n release preflight (read-only \u2014 nothing is pushed/published):\n");
|
|
14099
14889
|
for (const c of checks) {
|
|
14100
14890
|
const mark = c.status === "pass" ? "\u2713" : c.status === "warn" ? "\u26A0" : "\u2717";
|
|
@@ -14522,19 +15312,19 @@ async function listWorkflowNames(workflowsDir) {
|
|
|
14522
15312
|
const names = [];
|
|
14523
15313
|
const entries = await readdir(workflowsDir);
|
|
14524
15314
|
for (const e of entries.sort()) {
|
|
14525
|
-
const
|
|
14526
|
-
const s = await stat(
|
|
15315
|
+
const p8 = join(workflowsDir, e);
|
|
15316
|
+
const s = await stat(p8).catch(() => null);
|
|
14527
15317
|
if (!s?.isDirectory()) continue;
|
|
14528
|
-
if (await fileExists(join(
|
|
15318
|
+
if (await fileExists(join(p8, "workflow.yaml"))) {
|
|
14529
15319
|
names.push(e);
|
|
14530
15320
|
continue;
|
|
14531
15321
|
}
|
|
14532
|
-
if (await fileExists(join(
|
|
15322
|
+
if (await fileExists(join(p8, "auto", "workflow.yaml"))) {
|
|
14533
15323
|
names.push(e);
|
|
14534
|
-
const subs = await readdir(
|
|
15324
|
+
const subs = await readdir(p8).catch(() => []);
|
|
14535
15325
|
for (const sub of subs.sort()) {
|
|
14536
15326
|
if (sub === "auto") continue;
|
|
14537
|
-
if (await fileExists(join(
|
|
15327
|
+
if (await fileExists(join(p8, sub, "workflow.yaml"))) {
|
|
14538
15328
|
names.push(`${e}-${sub}`);
|
|
14539
15329
|
}
|
|
14540
15330
|
}
|
|
@@ -14972,7 +15762,7 @@ var V3_4_3_SIGNATURE_MASTER_RX = /\*\*Preferred path\*\*[\s\S]*dispatch to the p
|
|
|
14972
15762
|
function shouldOverwriteFile(content) {
|
|
14973
15763
|
return HARNESSED_MARKER_RX2.test(content) || V3_4_3_SIGNATURE_SUB_RX.test(content) || V3_4_3_SIGNATURE_MASTER_RX.test(content);
|
|
14974
15764
|
}
|
|
14975
|
-
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")) {
|
|
14976
15766
|
const results = [];
|
|
14977
15767
|
const aggregatedWarnings = /* @__PURE__ */ new Set();
|
|
14978
15768
|
for (const name of slashNames) {
|
|
@@ -14991,7 +15781,7 @@ async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabiliti
|
|
|
14991
15781
|
if (fileExists2(path)) {
|
|
14992
15782
|
let existing = "";
|
|
14993
15783
|
try {
|
|
14994
|
-
existing =
|
|
15784
|
+
existing = readFileSync25(path);
|
|
14995
15785
|
} catch {
|
|
14996
15786
|
existing = "";
|
|
14997
15787
|
}
|
|
@@ -15499,6 +16289,9 @@ function registerSetup(program2) {
|
|
|
15499
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(
|
|
15500
16290
|
"--update-installed",
|
|
15501
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"
|
|
15502
16295
|
).action(async (raw) => {
|
|
15503
16296
|
await printSetupVersionBanner();
|
|
15504
16297
|
const dryRun = raw.dryRun === true;
|
|
@@ -15555,14 +16348,14 @@ installing ${manifestPaths.length} upstream components (MCP serialized, rest par
|
|
|
15555
16348
|
if (!forceFirstPass && !dryRun && raw.nonInteractive !== true && b.alreadyInstalled.length > 0) {
|
|
15556
16349
|
const isTty = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
15557
16350
|
if (isTty) {
|
|
15558
|
-
const { confirm:
|
|
16351
|
+
const { confirm: confirm6, isCancel: isCancel8 } = await import('@clack/prompts');
|
|
15559
16352
|
const mcpExcluded = b.alreadyInstalled.filter((n) => b.componentTypes[n] === "mcp-tool");
|
|
15560
16353
|
const exclusionNote = mcpExcluded.length > 0 ? ` (${mcpExcluded.length} MCP server(s) excluded \u2014 they ignore force-update: ${mcpExcluded.join(", ")})` : "";
|
|
15561
|
-
const ans = await
|
|
16354
|
+
const ans = await confirm6({
|
|
15562
16355
|
message: `Update ${b.alreadyInstalled.length} already-installed plugin(s) listed above?${exclusionNote}`,
|
|
15563
16356
|
initialValue: false
|
|
15564
16357
|
});
|
|
15565
|
-
if (!
|
|
16358
|
+
if (!isCancel8(ans) && ans === true) {
|
|
15566
16359
|
console.log(`
|
|
15567
16360
|
force-updating ${b.alreadyInstalled.length} plugin(s)...`);
|
|
15568
16361
|
const b2 = await runStepBInstall(manifestPaths, {
|
|
@@ -15686,7 +16479,7 @@ Force-update pass complete: ${b2.installed.length} installed / ${b2.keptExisting
|
|
|
15686
16479
|
capabilitiesMap,
|
|
15687
16480
|
installedPlugins,
|
|
15688
16481
|
installedUserSkills,
|
|
15689
|
-
async (
|
|
16482
|
+
async (p8, c) => writeFile(p8, c, "utf8")
|
|
15690
16483
|
);
|
|
15691
16484
|
const writtenCount = cmdResult.results.filter((r) => r.written).length;
|
|
15692
16485
|
const skippedCount = cmdResult.results.filter((r) => !r.written && r.warning).length;
|
|
@@ -15706,7 +16499,8 @@ Force-update pass complete: ${b2.installed.length} installed / ${b2.keptExisting
|
|
|
15706
16499
|
const optIsTty = process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
15707
16500
|
const { runOptionalOffer: runOptionalOffer2 } = await Promise.resolve().then(() => (init_optional_offer(), optional_offer_exports));
|
|
15708
16501
|
await runOptionalOffer2(resolve(pkgRoot, "manifests", "optional"), {
|
|
15709
|
-
interactive: optIsTty && raw.nonInteractive !== true
|
|
16502
|
+
interactive: optIsTty && raw.nonInteractive !== true,
|
|
16503
|
+
trustCodexHooks: raw.trustCodexHooks === true
|
|
15710
16504
|
});
|
|
15711
16505
|
}
|
|
15712
16506
|
if (b.failed.length > 0) {
|
|
@@ -15842,6 +16636,7 @@ init_harnessedRoot();
|
|
|
15842
16636
|
init_platform();
|
|
15843
16637
|
|
|
15844
16638
|
// src/uninstallers/ccHookAdd.ts
|
|
16639
|
+
init_codexHookAdd();
|
|
15845
16640
|
init_hookEntry();
|
|
15846
16641
|
init_assetsRoot();
|
|
15847
16642
|
init_platform();
|
|
@@ -15860,6 +16655,10 @@ var uninstallCcHookAdd = async (ctx) => {
|
|
|
15860
16655
|
}
|
|
15861
16656
|
const abort = dryRunGate(ctx);
|
|
15862
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
|
+
}
|
|
15863
16662
|
const settingsPath = getSettingsPath();
|
|
15864
16663
|
if (settingsPath === null) return { ok: true, removedPaths: [] };
|
|
15865
16664
|
let existing;
|
|
@@ -16010,10 +16809,10 @@ init_path_guard();
|
|
|
16010
16809
|
function hasDeclaredUninstall(ctx) {
|
|
16011
16810
|
return ctx.manifest.spec.uninstall != null;
|
|
16012
16811
|
}
|
|
16013
|
-
function expandTilde(
|
|
16014
|
-
if (
|
|
16015
|
-
if (
|
|
16016
|
-
return
|
|
16812
|
+
function expandTilde(p8) {
|
|
16813
|
+
if (p8 === "~") return homedir();
|
|
16814
|
+
if (p8.startsWith("~/") || p8.startsWith("~\\")) return homedir() + p8.slice(1);
|
|
16815
|
+
return p8;
|
|
16017
16816
|
}
|
|
16018
16817
|
function confineCleanupPath(raw) {
|
|
16019
16818
|
checkPathSafe(raw);
|
|
@@ -16220,10 +17019,10 @@ async function discoverCommandFiles(commandsDir) {
|
|
|
16220
17019
|
}
|
|
16221
17020
|
for (const entry of entries) {
|
|
16222
17021
|
if (!entry.endsWith(".md")) continue;
|
|
16223
|
-
const
|
|
17022
|
+
const p8 = join(commandsDir, entry);
|
|
16224
17023
|
try {
|
|
16225
|
-
const content = await readFile(
|
|
16226
|
-
if (shouldOverwriteFile(content)) owned.push(
|
|
17024
|
+
const content = await readFile(p8, "utf8");
|
|
17025
|
+
if (shouldOverwriteFile(content)) owned.push(p8);
|
|
16227
17026
|
} catch {
|
|
16228
17027
|
}
|
|
16229
17028
|
}
|
|
@@ -16411,27 +17210,24 @@ function registerUninstall(program2) {
|
|
|
16411
17210
|
const { resolveAlias: resolveAlias2 } = await Promise.resolve().then(() => (init_aliases(), aliases_exports));
|
|
16412
17211
|
const resolvedName = resolveAlias2(name) ?? name;
|
|
16413
17212
|
checkPathSafe(resolvedName);
|
|
16414
|
-
const manifestPath = resolve(getAssetsRoot(), `manifests/tools/${resolvedName}.yaml`);
|
|
16415
|
-
const skillPackPath = resolve(
|
|
16416
|
-
getAssetsRoot(),
|
|
16417
|
-
`manifests/skill-packs/${resolvedName}.yaml`
|
|
16418
|
-
);
|
|
16419
17213
|
let yamlSrc;
|
|
16420
|
-
let chosenPath
|
|
16421
|
-
|
|
16422
|
-
|
|
16423
|
-
} catch {
|
|
17214
|
+
let chosenPath;
|
|
17215
|
+
for (const dir of ["tools", "skill-packs", "optional"]) {
|
|
17216
|
+
const candidate = resolve(getAssetsRoot(), `manifests/${dir}/${resolvedName}.yaml`);
|
|
16424
17217
|
try {
|
|
16425
|
-
yamlSrc = await readFile(
|
|
16426
|
-
chosenPath =
|
|
17218
|
+
yamlSrc = await readFile(candidate, "utf8");
|
|
17219
|
+
chosenPath = candidate;
|
|
17220
|
+
break;
|
|
16427
17221
|
} catch {
|
|
16428
|
-
console.error(
|
|
16429
|
-
`${t("install.manifest_not_found", { name: resolvedName })}
|
|
16430
|
-
${t("install.manifest_not_found.fix", { name: resolvedName })}`
|
|
16431
|
-
);
|
|
16432
|
-
process.exit(1);
|
|
16433
17222
|
}
|
|
16434
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
|
+
}
|
|
16435
17231
|
const v = validateManifestFile(yamlSrc, chosenPath);
|
|
16436
17232
|
if (!v.ok) {
|
|
16437
17233
|
for (const e of v.errors) console.error(`error: ${e.message} at ${e.path}`);
|
|
@@ -16553,9 +17349,9 @@ function npmExecutable2() {
|
|
|
16553
17349
|
}
|
|
16554
17350
|
function changelogTop() {
|
|
16555
17351
|
try {
|
|
16556
|
-
const
|
|
16557
|
-
if (!existsSync(
|
|
16558
|
-
const body = readFileSync(
|
|
17352
|
+
const p8 = join(getAssetsRoot(), "CHANGELOG.md");
|
|
17353
|
+
if (!existsSync(p8)) return null;
|
|
17354
|
+
const body = readFileSync(p8, "utf8");
|
|
16559
17355
|
const start = body.indexOf("\n## ");
|
|
16560
17356
|
if (start < 0) return null;
|
|
16561
17357
|
const rest = body.slice(start + 1);
|