context-mode 2.1.8 → 2.1.10
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +72 -72
- package/SHA256SUMS +16 -16
- package/cli.mjs +198 -178
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +168 -62
- package/package.json +1 -1
- package/pi/index.js +168 -64
- package/qwen-extension.json +1 -1
- package/run.mjs +43 -8
- package/search.mjs +43 -8
- package/server.mjs +62 -27
package/cli.mjs
CHANGED
|
@@ -7,9 +7,9 @@ var __export = (target, all) => {
|
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
// src/entries/cli.ts
|
|
10
|
-
import { spawn as
|
|
10
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
11
11
|
import { readFileSync as readFileSync14, realpathSync as realpathSync11 } from "node:fs";
|
|
12
|
-
import
|
|
12
|
+
import path16 from "node:path";
|
|
13
13
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
14
14
|
|
|
15
15
|
// src/core/contracts/constants.ts
|
|
@@ -1971,7 +1971,7 @@ import { spawnSync as spawnSync5 } from "node:child_process";
|
|
|
1971
1971
|
import { createHash as createHash2 } from "node:crypto";
|
|
1972
1972
|
import { existsSync as existsSync18, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1973
1973
|
import os from "node:os";
|
|
1974
|
-
import
|
|
1974
|
+
import path15 from "node:path";
|
|
1975
1975
|
|
|
1976
1976
|
// node_modules/@clack/prompts/dist/index.mjs
|
|
1977
1977
|
var dist_exports = {};
|
|
@@ -4980,14 +4980,14 @@ function kiroDirOf(env, home, platform = process.platform) {
|
|
|
4980
4980
|
if (!p3.isAbsolute(up) && up.split(p3.sep)[0] !== "..") return fallback;
|
|
4981
4981
|
return abs;
|
|
4982
4982
|
}
|
|
4983
|
-
function realOrSelf(
|
|
4983
|
+
function realOrSelf(path17) {
|
|
4984
4984
|
const tail = [];
|
|
4985
|
-
for (let at =
|
|
4985
|
+
for (let at = path17; ; ) {
|
|
4986
4986
|
try {
|
|
4987
4987
|
return join2(realpathSync.native(at), ...tail.reverse());
|
|
4988
4988
|
} catch {
|
|
4989
4989
|
const up = dirname2(at);
|
|
4990
|
-
if (up === at) return
|
|
4990
|
+
if (up === at) return path17;
|
|
4991
4991
|
tail.push(basename(at));
|
|
4992
4992
|
at = up;
|
|
4993
4993
|
}
|
|
@@ -5032,7 +5032,7 @@ function dataRootOf(env, home) {
|
|
|
5032
5032
|
// src/core/ops/doctor-issue.ts
|
|
5033
5033
|
import { spawnSync } from "node:child_process";
|
|
5034
5034
|
import { closeSync as closeSync2, existsSync as existsSync10, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync7, readSync as readSync2, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5035
|
-
import { delimiter, join as join11 } from "node:path";
|
|
5035
|
+
import { delimiter, dirname as dirname8, join as join11 } from "node:path";
|
|
5036
5036
|
|
|
5037
5037
|
// src/core/hooks/fallback.ts
|
|
5038
5038
|
import { join as join5, resolve as resolve4 } from "node:path";
|
|
@@ -5079,6 +5079,34 @@ function nodeTooOld(version) {
|
|
|
5079
5079
|
return false;
|
|
5080
5080
|
}
|
|
5081
5081
|
|
|
5082
|
+
// src/core/sandbox/path-entries.ts
|
|
5083
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
5084
|
+
const win = platform === "win32";
|
|
5085
|
+
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
5086
|
+
}
|
|
5087
|
+
function envValue(env, name, platform = process.platform) {
|
|
5088
|
+
const exact = env[name];
|
|
5089
|
+
if (exact !== void 0 || platform !== "win32") return exact;
|
|
5090
|
+
const upper = name.toUpperCase();
|
|
5091
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === upper);
|
|
5092
|
+
return key === void 0 ? void 0 : env[key];
|
|
5093
|
+
}
|
|
5094
|
+
|
|
5095
|
+
// src/core/sandbox/runtimes.ts
|
|
5096
|
+
import { accessSync, constants as fsConstants, statSync } from "node:fs";
|
|
5097
|
+
import path2 from "node:path";
|
|
5098
|
+
var WIN_STARTABLE_EXT = Object.freeze([".exe", ".com"]);
|
|
5099
|
+
|
|
5100
|
+
// src/core/sandbox/spawn.ts
|
|
5101
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
5102
|
+
import path3 from "node:path";
|
|
5103
|
+
|
|
5104
|
+
// src/core/sandbox/kill.ts
|
|
5105
|
+
import { spawn } from "node:child_process";
|
|
5106
|
+
|
|
5107
|
+
// src/core/sandbox/spawn.ts
|
|
5108
|
+
var NOT_STARTED = Object.freeze({ stdout: Buffer.alloc(0), stderr: Buffer.alloc(0), exitCode: null, killed: null });
|
|
5109
|
+
|
|
5082
5110
|
// src/core/store/schema.ts
|
|
5083
5111
|
var PRAGMAS = `
|
|
5084
5112
|
PRAGMA busy_timeout = ${DB_TIMEOUT_MS};
|
|
@@ -7249,7 +7277,7 @@ function parseTOML(code, options) {
|
|
|
7249
7277
|
|
|
7250
7278
|
// src/core/ops/atomic-file.ts
|
|
7251
7279
|
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7252
|
-
import
|
|
7280
|
+
import path4 from "node:path";
|
|
7253
7281
|
function sleepSync(ms) {
|
|
7254
7282
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
7255
7283
|
}
|
|
@@ -7299,8 +7327,8 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
7299
7327
|
}
|
|
7300
7328
|
}
|
|
7301
7329
|
function atomicWriteFile(file, text2, opts = {}) {
|
|
7302
|
-
mkdirSync3(
|
|
7303
|
-
const tmp =
|
|
7330
|
+
mkdirSync3(path4.dirname(file), { recursive: true });
|
|
7331
|
+
const tmp = path4.join(path4.dirname(file), `${ATOMIC_TMP_PREFIX}${path4.basename(file)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
7304
7332
|
try {
|
|
7305
7333
|
writeFileSync(tmp, text2);
|
|
7306
7334
|
renameWithRetry(tmp, file, opts);
|
|
@@ -7491,14 +7519,14 @@ function scanToml(text2) {
|
|
|
7491
7519
|
continue;
|
|
7492
7520
|
}
|
|
7493
7521
|
if (!node.resolvedKey.every((seg) => typeof seg === "string")) continue;
|
|
7494
|
-
const
|
|
7495
|
-
for (const kv of node.body) addKey(
|
|
7522
|
+
const path17 = node.resolvedKey;
|
|
7523
|
+
for (const kv of node.body) addKey(path17, kv);
|
|
7496
7524
|
if (node.kind !== "standard") continue;
|
|
7497
7525
|
const start = lineStartOf(text2, node.range[0]);
|
|
7498
7526
|
const headEnd = lineEndOf(text2, node.key.range[1]);
|
|
7499
7527
|
const last2 = node.body[node.body.length - 1];
|
|
7500
7528
|
tables.push({
|
|
7501
|
-
path:
|
|
7529
|
+
path: path17,
|
|
7502
7530
|
header: text2.slice(start, text2[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
|
|
7503
7531
|
start,
|
|
7504
7532
|
end: last2 === void 0 ? headEnd : lineEndOf(text2, last2.range[1])
|
|
@@ -7509,16 +7537,16 @@ function scanToml(text2) {
|
|
|
7509
7537
|
function tomlTableSpans(text2) {
|
|
7510
7538
|
return scanToml(text2).tables;
|
|
7511
7539
|
}
|
|
7512
|
-
function parseHostConfig(agent,
|
|
7540
|
+
function parseHostConfig(agent, path17, text2, format) {
|
|
7513
7541
|
try {
|
|
7514
7542
|
return format === "toml" ? scanToml(text2).value : scanJson(text2, format).value;
|
|
7515
7543
|
} catch {
|
|
7516
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
7544
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path17, format });
|
|
7517
7545
|
}
|
|
7518
7546
|
}
|
|
7519
|
-
function hostConfigValueAt(value,
|
|
7547
|
+
function hostConfigValueAt(value, path17) {
|
|
7520
7548
|
let cur = value;
|
|
7521
|
-
for (const seg of
|
|
7549
|
+
for (const seg of path17) {
|
|
7522
7550
|
if (!isPlainObject(cur)) return void 0;
|
|
7523
7551
|
cur = cur[seg];
|
|
7524
7552
|
}
|
|
@@ -7551,32 +7579,32 @@ function indentUnit(root, clean) {
|
|
|
7551
7579
|
function render(value, unit, base) {
|
|
7552
7580
|
return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
|
|
7553
7581
|
}
|
|
7554
|
-
function nest(
|
|
7582
|
+
function nest(path17, value) {
|
|
7555
7583
|
let out2 = value;
|
|
7556
|
-
for (let k =
|
|
7584
|
+
for (let k = path17.length - 1; k >= 0; k -= 1) out2 = { [path17[k]]: out2 };
|
|
7557
7585
|
return out2;
|
|
7558
7586
|
}
|
|
7559
|
-
function setJsonText(text2, format,
|
|
7587
|
+
function setJsonText(text2, format, path17, value) {
|
|
7560
7588
|
const doc = scanJson(text2, format);
|
|
7561
7589
|
const unit = indentUnit(doc.root, doc.clean);
|
|
7562
|
-
if (doc.root === null) return render(nest(
|
|
7590
|
+
if (doc.root === null) return render(nest(path17, value), unit, "") + "\n";
|
|
7563
7591
|
let node = doc.root;
|
|
7564
7592
|
let depth = 0;
|
|
7565
|
-
while (depth <
|
|
7566
|
-
const hit = node.members.find((m3) => m3.key ===
|
|
7593
|
+
while (depth < path17.length && node.kind === "object") {
|
|
7594
|
+
const hit = node.members.find((m3) => m3.key === path17[depth]);
|
|
7567
7595
|
if (hit === void 0) break;
|
|
7568
7596
|
node = hit.node;
|
|
7569
7597
|
depth += 1;
|
|
7570
7598
|
}
|
|
7571
|
-
if (depth ===
|
|
7599
|
+
if (depth === path17.length) {
|
|
7572
7600
|
return text2.slice(0, node.start) + render(value, unit, lineIndent(doc.clean, node.start)) + text2.slice(node.end);
|
|
7573
7601
|
}
|
|
7574
|
-
if (node.kind !== "object") throw new SyntaxError("not an object at " +
|
|
7575
|
-
const rest = nest(
|
|
7602
|
+
if (node.kind !== "object") throw new SyntaxError("not an object at " + path17.slice(0, depth).join("."));
|
|
7603
|
+
const rest = nest(path17.slice(depth + 1), value);
|
|
7576
7604
|
const last2 = node.members[node.members.length - 1];
|
|
7577
7605
|
if (last2 === void 0) {
|
|
7578
7606
|
const base2 = lineIndent(doc.clean, node.start);
|
|
7579
|
-
const member2 = "\n" + base2 + unit + JSON.stringify(
|
|
7607
|
+
const member2 = "\n" + base2 + unit + JSON.stringify(path17[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
|
|
7580
7608
|
return text2.slice(0, node.start + 1) + member2 + text2.slice(node.end - 1);
|
|
7581
7609
|
}
|
|
7582
7610
|
const base = lineIndent(doc.clean, last2.keyStart);
|
|
@@ -7584,7 +7612,7 @@ function setJsonText(text2, format, path15, value) {
|
|
|
7584
7612
|
while (" \r\n".includes(doc.clean[at])) at += 1;
|
|
7585
7613
|
const trailing = doc.clean[at] === ",";
|
|
7586
7614
|
const insertAt = trailing ? at + 1 : last2.node.end;
|
|
7587
|
-
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(
|
|
7615
|
+
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path17[depth]) + ": " + render(rest, unit, base);
|
|
7588
7616
|
return text2.slice(0, insertAt) + member + text2.slice(insertAt);
|
|
7589
7617
|
}
|
|
7590
7618
|
function tomlScalar(v) {
|
|
@@ -7602,17 +7630,17 @@ function tomlHeaderKey(seg) {
|
|
|
7602
7630
|
}
|
|
7603
7631
|
return seg;
|
|
7604
7632
|
}
|
|
7605
|
-
function tomlBlock(
|
|
7606
|
-
let out2 = "[" +
|
|
7633
|
+
function tomlBlock(path17, value) {
|
|
7634
|
+
let out2 = "[" + path17.map(tomlHeaderKey).join(".") + "]\n";
|
|
7607
7635
|
const subs = [];
|
|
7608
7636
|
for (const [k, v] of Object.entries(value)) {
|
|
7609
|
-
if (isPlainObject(v)) subs.push(tomlBlock([...
|
|
7637
|
+
if (isPlainObject(v)) subs.push(tomlBlock([...path17, k], v));
|
|
7610
7638
|
else out2 += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
|
|
7611
7639
|
}
|
|
7612
7640
|
return [out2, ...subs].join("\n");
|
|
7613
7641
|
}
|
|
7614
|
-
function under(
|
|
7615
|
-
return
|
|
7642
|
+
function under(path17, prefix) {
|
|
7643
|
+
return path17.length >= prefix.length && prefix.every((seg, k) => path17[k] === seg);
|
|
7616
7644
|
}
|
|
7617
7645
|
function keyLineRange(text2, k) {
|
|
7618
7646
|
const ls = lineStartOf(text2, k.start);
|
|
@@ -7629,10 +7657,10 @@ function withValueAt(root, rel, value) {
|
|
|
7629
7657
|
else base[rel[0]] = next;
|
|
7630
7658
|
return base;
|
|
7631
7659
|
}
|
|
7632
|
-
function replaceToml(text2, doc,
|
|
7633
|
-
const block2 = value === void 0 ? "" : tomlBlock(
|
|
7634
|
-
const owned = doc.tables.filter((t2) => under(t2.path,
|
|
7635
|
-
const cuts = doc.keys.filter((k) => under(k.full,
|
|
7660
|
+
function replaceToml(text2, doc, path17, value) {
|
|
7661
|
+
const block2 = value === void 0 ? "" : tomlBlock(path17, value);
|
|
7662
|
+
const owned = doc.tables.filter((t2) => under(t2.path, path17));
|
|
7663
|
+
const cuts = doc.keys.filter((k) => under(k.full, path17) && !under(k.base, path17)).map((k) => [...keyLineRange(text2, k), ""]);
|
|
7636
7664
|
owned.forEach((t2, n3) => cuts.push([t2.start, t2.end, n3 === 0 ? block2 : ""]));
|
|
7637
7665
|
cuts.sort((a2, b3) => b3[0] - a2[0]);
|
|
7638
7666
|
let out2 = text2;
|
|
@@ -7642,27 +7670,27 @@ function replaceToml(text2, doc, path15, value) {
|
|
|
7642
7670
|
return out2 + sep3 + block2;
|
|
7643
7671
|
}
|
|
7644
7672
|
var tableLike = (v) => v === void 0 || isPlainObject(v);
|
|
7645
|
-
function setTomlText(text2,
|
|
7673
|
+
function setTomlText(text2, path17, value) {
|
|
7646
7674
|
if (value !== void 0 && !isPlainObject(value)) throw new SyntaxError("TOML edits replace a whole table");
|
|
7647
7675
|
const doc = scanToml(text2);
|
|
7648
|
-
const cur = hostConfigValueAt(doc.value,
|
|
7676
|
+
const cur = hostConfigValueAt(doc.value, path17);
|
|
7649
7677
|
if (sameValue(cur, value)) return text2;
|
|
7650
|
-
const inline = doc.keys.find((k) => k.inline && k.full.length <
|
|
7678
|
+
const inline = doc.keys.find((k) => k.inline && k.full.length < path17.length && under(path17, k.full));
|
|
7651
7679
|
if (inline !== void 0) {
|
|
7652
|
-
const whole = withValueAt(hostConfigValueAt(doc.value, inline.full),
|
|
7680
|
+
const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path17.slice(inline.full.length), value);
|
|
7653
7681
|
return replaceToml(text2, doc, inline.full, whole);
|
|
7654
7682
|
}
|
|
7655
7683
|
if (isPlainObject(cur) && isPlainObject(value)) {
|
|
7656
7684
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
7657
7685
|
if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
|
|
7658
7686
|
let out2 = text2;
|
|
7659
|
-
for (const k of names) out2 = setTomlText(out2, [...
|
|
7687
|
+
for (const k of names) out2 = setTomlText(out2, [...path17, k], value[k]);
|
|
7660
7688
|
return out2;
|
|
7661
7689
|
}
|
|
7662
7690
|
}
|
|
7663
|
-
return replaceToml(text2, doc,
|
|
7691
|
+
return replaceToml(text2, doc, path17, value);
|
|
7664
7692
|
}
|
|
7665
|
-
function setText(agent,
|
|
7693
|
+
function setText(agent, path17, text2, format, key, value) {
|
|
7666
7694
|
try {
|
|
7667
7695
|
if (format !== "toml") return setJsonText(text2, format, key, value);
|
|
7668
7696
|
const out2 = setTomlText(text2, key, value);
|
|
@@ -7671,7 +7699,7 @@ function setText(agent, path15, text2, format, key, value) {
|
|
|
7671
7699
|
if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
|
|
7672
7700
|
return out2;
|
|
7673
7701
|
} catch {
|
|
7674
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
7702
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path17, format });
|
|
7675
7703
|
}
|
|
7676
7704
|
}
|
|
7677
7705
|
function isNodeCommand(command) {
|
|
@@ -7689,26 +7717,26 @@ function ownMcpValue(agent, node, server) {
|
|
|
7689
7717
|
function opencodePluginFile() {
|
|
7690
7718
|
return ownBundleDir();
|
|
7691
7719
|
}
|
|
7692
|
-
function applyEdits(agent,
|
|
7693
|
-
const parsed = parseHostConfig(agent,
|
|
7720
|
+
function applyEdits(agent, path17, text2, format, wanted) {
|
|
7721
|
+
const parsed = parseHostConfig(agent, path17, text2, format);
|
|
7694
7722
|
let out2 = text2;
|
|
7695
7723
|
const edits = [];
|
|
7696
7724
|
for (const [key, after] of wanted) {
|
|
7697
7725
|
const before = hostConfigValueAt(parsed, key);
|
|
7698
7726
|
if (sameValue(before, after)) continue;
|
|
7699
|
-
out2 = setText(agent,
|
|
7727
|
+
out2 = setText(agent, path17, out2, format, key, after);
|
|
7700
7728
|
edits.push({ path: key.join("."), before, after });
|
|
7701
7729
|
}
|
|
7702
7730
|
return { text: out2, format, edits };
|
|
7703
7731
|
}
|
|
7704
|
-
function editHostConfigText(agent,
|
|
7705
|
-
return applyEdits(agent,
|
|
7732
|
+
function editHostConfigText(agent, path17, text2, format, wanted) {
|
|
7733
|
+
return applyEdits(agent, path17, text2, format, wanted);
|
|
7706
7734
|
}
|
|
7707
7735
|
|
|
7708
7736
|
// src/core/ops/detect-v1.ts
|
|
7709
7737
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7710
7738
|
var keyPath = (...parts) => parts.join(".");
|
|
7711
|
-
var finding = (file,
|
|
7739
|
+
var finding = (file, path17, reason) => ({ file, path: path17, reason });
|
|
7712
7740
|
function stripJsonc(text2) {
|
|
7713
7741
|
let out2 = "";
|
|
7714
7742
|
let inStr = false;
|
|
@@ -8026,7 +8054,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
8026
8054
|
|
|
8027
8055
|
// src/setup/pi-gate.ts
|
|
8028
8056
|
import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
8029
|
-
import
|
|
8057
|
+
import path5 from "node:path";
|
|
8030
8058
|
var OWN_FILE = "pi/index.js";
|
|
8031
8059
|
var EXTENSIONS_KEY = "extensions";
|
|
8032
8060
|
var PROJECT_DIR = ".pi";
|
|
@@ -8045,7 +8073,7 @@ var real = (p3) => {
|
|
|
8045
8073
|
try {
|
|
8046
8074
|
return realpathSync4(p3);
|
|
8047
8075
|
} catch {
|
|
8048
|
-
return
|
|
8076
|
+
return path5.resolve(p3);
|
|
8049
8077
|
}
|
|
8050
8078
|
};
|
|
8051
8079
|
function sourceName(source) {
|
|
@@ -8073,14 +8101,14 @@ function ownEntries(src, pkgDir) {
|
|
|
8073
8101
|
return out2;
|
|
8074
8102
|
}
|
|
8075
8103
|
function matchesAny(patterns, pkgDir) {
|
|
8076
|
-
const abs =
|
|
8104
|
+
const abs = path5.join(pkgDir, OWN_FILE).split(path5.sep).join("/");
|
|
8077
8105
|
return patterns.some((p3) => {
|
|
8078
8106
|
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8079
|
-
return [OWN_FILE,
|
|
8107
|
+
return [OWN_FILE, path5.posix.basename(OWN_FILE), abs].some((c3) => path5.posix.matchesGlob(c3, g2));
|
|
8080
8108
|
});
|
|
8081
8109
|
}
|
|
8082
8110
|
var exactAny = (patterns, pkgDir) => {
|
|
8083
|
-
const abs =
|
|
8111
|
+
const abs = path5.join(pkgDir, OWN_FILE).split(path5.sep).join("/");
|
|
8084
8112
|
return patterns.some((p3) => {
|
|
8085
8113
|
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8086
8114
|
return g2 === OWN_FILE || g2 === abs;
|
|
@@ -8097,14 +8125,14 @@ function loads(patterns, pkgDir) {
|
|
|
8097
8125
|
return on;
|
|
8098
8126
|
}
|
|
8099
8127
|
function projectTrusted(agentDir, userDoc, cwd) {
|
|
8100
|
-
const trust = load(
|
|
8128
|
+
const trust = load(path5.join(agentDir, TRUST_FILE));
|
|
8101
8129
|
const entries = /* @__PURE__ */ new Map();
|
|
8102
8130
|
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real(k), v);
|
|
8103
8131
|
let dir = real(cwd);
|
|
8104
8132
|
for (; ; ) {
|
|
8105
8133
|
const v = entries.get(dir);
|
|
8106
8134
|
if (v === true || v === false) return v;
|
|
8107
|
-
const up =
|
|
8135
|
+
const up = path5.dirname(dir);
|
|
8108
8136
|
if (up === dir) break;
|
|
8109
8137
|
dir = up;
|
|
8110
8138
|
}
|
|
@@ -8112,8 +8140,8 @@ function projectTrusted(agentDir, userDoc, cwd) {
|
|
|
8112
8140
|
}
|
|
8113
8141
|
function piSettingsGate(env, home, pkgDir, cwd) {
|
|
8114
8142
|
const agentDir = piAgentDirOf(env, home);
|
|
8115
|
-
const user = load(
|
|
8116
|
-
const project = load(
|
|
8143
|
+
const user = load(path5.join(agentDir, SETTINGS_FILE));
|
|
8144
|
+
const project = load(path5.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
8117
8145
|
const projectOwn = project && projectTrusted(agentDir, user?.doc, cwd) ? ownEntries(project, pkgDir) : [];
|
|
8118
8146
|
const effective = projectOwn.length ? projectOwn : user ? ownEntries(user, pkgDir) : [];
|
|
8119
8147
|
for (const e of effective) {
|
|
@@ -8258,7 +8286,7 @@ function formUrl(title, summary) {
|
|
|
8258
8286
|
|
|
8259
8287
|
// src/setup/registry.ts
|
|
8260
8288
|
import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
8261
|
-
import
|
|
8289
|
+
import path6 from "node:path";
|
|
8262
8290
|
|
|
8263
8291
|
// src/setup/hook-shapes.ts
|
|
8264
8292
|
var MS_PER_SECOND = 1e3;
|
|
@@ -8343,11 +8371,11 @@ var OPENCODE_HOME_SEGS = AGENT_HOME_DIR.opencode;
|
|
|
8343
8371
|
function agentPath(ctx, id, rel) {
|
|
8344
8372
|
const segs = typeof rel === "string" ? rel.split("/") : [...rel];
|
|
8345
8373
|
const codexHome = ctx.env[CODEX_HOME_ENV2];
|
|
8346
|
-
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return
|
|
8347
|
-
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return
|
|
8348
|
-
if (id === "kiro" && segs[0] === KIRO_DIR) return
|
|
8349
|
-
if (id === "opencode" && segs[0] === OPENCODE_HOME_SEGS[0] && segs[1] === OPENCODE_HOME_SEGS[1]) return
|
|
8350
|
-
return
|
|
8374
|
+
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return path6.join(codexHome, ...segs.slice(1));
|
|
8375
|
+
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return path6.join(copilotDirOf(ctx.env, ctx.home), ...segs.slice(1));
|
|
8376
|
+
if (id === "kiro" && segs[0] === KIRO_DIR) return path6.join(kiroDirOf(ctx.env, ctx.home), ...segs.slice(1));
|
|
8377
|
+
if (id === "opencode" && segs[0] === OPENCODE_HOME_SEGS[0] && segs[1] === OPENCODE_HOME_SEGS[1]) return path6.join(opencodeDirOf(ctx.env, ctx.home), ...segs.slice(2));
|
|
8378
|
+
return path6.join(ctx.home, ...segs);
|
|
8351
8379
|
}
|
|
8352
8380
|
function renderSkill(text2, prefix) {
|
|
8353
8381
|
const prefixes = typeof prefix === "string" ? [prefix] : prefix;
|
|
@@ -8377,7 +8405,7 @@ function extensionPlugin(bin, id) {
|
|
|
8377
8405
|
};
|
|
8378
8406
|
}
|
|
8379
8407
|
var NATIVE_PLUGIN = {
|
|
8380
|
-
codex: { bin: "codex", args: ["plugin", "list", "--json"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia:
|
|
8408
|
+
codex: { bin: "codex", args: ["plugin", "list", "--json"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path6.join("codex", SKILLS_DIR_NAME), format: "codex-json", hookTrust: true },
|
|
8381
8409
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
8382
8410
|
gemini: extensionPlugin("gemini", "gemini"),
|
|
8383
8411
|
// D-R44-ZCODE-NATIVE-1 (host audit zcode-1/2): `zcode plugins install context-mode@context-mode` lists as JSON; ZCode loads
|
|
@@ -8411,7 +8439,7 @@ function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
|
8411
8439
|
}
|
|
8412
8440
|
var SETUP_NODE = stableNodePath(process.execPath);
|
|
8413
8441
|
function serverCmd(ctx, id) {
|
|
8414
|
-
return [SETUP_NODE,
|
|
8442
|
+
return [SETUP_NODE, path6.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
8415
8443
|
}
|
|
8416
8444
|
function hookCommandString(row) {
|
|
8417
8445
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -8441,7 +8469,7 @@ function configFor(ctx, id) {
|
|
|
8441
8469
|
}
|
|
8442
8470
|
if (id === "opencode") {
|
|
8443
8471
|
return {
|
|
8444
|
-
file:
|
|
8472
|
+
file: path6.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
8445
8473
|
format: "jsonc",
|
|
8446
8474
|
key: ["mcp", SERVER_KEY],
|
|
8447
8475
|
value: { type: "local", command: [node, server, flag, agent], enabled: true }
|
|
@@ -8470,7 +8498,7 @@ function cliFor(ctx, id) {
|
|
|
8470
8498
|
}
|
|
8471
8499
|
function copyFor(ctx, id) {
|
|
8472
8500
|
if (id !== "claude-code") return void 0;
|
|
8473
|
-
const file =
|
|
8501
|
+
const file = path6.join(claudeDirOf(ctx.env, ctx.home), HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE);
|
|
8474
8502
|
return {
|
|
8475
8503
|
host: "Claude Code",
|
|
8476
8504
|
bin: "claude",
|
|
@@ -8500,12 +8528,12 @@ function hookFilesFor(ctx, id) {
|
|
|
8500
8528
|
case "copilot-cli":
|
|
8501
8529
|
return [{ file: agentPath(ctx, id, [COPILOT_DIR, "hooks", "context-mode.json"]), mode: "rewrite" }];
|
|
8502
8530
|
case "claude-code":
|
|
8503
|
-
return [{ file:
|
|
8531
|
+
return [{ file: path6.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
8504
8532
|
case "gemini":
|
|
8505
|
-
return [{ file:
|
|
8533
|
+
return [{ file: path6.join(geminiDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
8506
8534
|
// D-R38-GEMINI-HOME-1
|
|
8507
8535
|
case "qwen":
|
|
8508
|
-
return [{ file:
|
|
8536
|
+
return [{ file: path6.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
8509
8537
|
default:
|
|
8510
8538
|
return [];
|
|
8511
8539
|
}
|
|
@@ -8516,13 +8544,13 @@ function hookInstallFor(ctx, row, command) {
|
|
|
8516
8544
|
const shape = HOOK_SHAPES[row.id];
|
|
8517
8545
|
if (!shape) throw new Error(`setup: ${row.id} has a home-file hook channel and no hook shape`);
|
|
8518
8546
|
const file = agentPath(ctx, row.id, ch.path);
|
|
8519
|
-
if (row.id === "codex") return { kind: "file", file, shape: shape(row, command), command, trust:
|
|
8547
|
+
if (row.id === "codex") return { kind: "file", file, shape: shape(row, command), command, trust: path6.join(path6.dirname(file), CODEX_CONFIG_FILE) };
|
|
8520
8548
|
return { kind: "file", file, shape: shape(row, command), command };
|
|
8521
8549
|
}
|
|
8522
8550
|
if (row.id === "opencode") {
|
|
8523
8551
|
return {
|
|
8524
8552
|
kind: "plugin-list",
|
|
8525
|
-
file:
|
|
8553
|
+
file: path6.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
8526
8554
|
key: ["plugin"],
|
|
8527
8555
|
worktree: ctx.cwd ?? process.cwd(),
|
|
8528
8556
|
// D-R54-OC-PLUGINS-DIR-1: <project>/.opencode/plugins
|
|
@@ -8540,11 +8568,11 @@ function skillInstallFor(ctx, row) {
|
|
|
8540
8568
|
const ch = row.skillChannel;
|
|
8541
8569
|
if (ch.kind === "package") return { kind: "package", via: ch.path };
|
|
8542
8570
|
const dir = agentPath(ctx, row.id, ch.path);
|
|
8543
|
-
const src =
|
|
8571
|
+
const src = path6.join(ctx.pkgDir, bareSkillDir());
|
|
8544
8572
|
return { kind: "dir", dir, prefixes: skillDirPrefixes(ch.path), files: COMMAND_SKILLS.map((name) => ({
|
|
8545
8573
|
name,
|
|
8546
|
-
src:
|
|
8547
|
-
file:
|
|
8574
|
+
src: path6.join(src, name, SKILL_FILE),
|
|
8575
|
+
file: path6.join(dir, name, SKILL_FILE)
|
|
8548
8576
|
})) };
|
|
8549
8577
|
}
|
|
8550
8578
|
function buildRegistry(ctx) {
|
|
@@ -8552,7 +8580,7 @@ function buildRegistry(ctx) {
|
|
|
8552
8580
|
const id = row.id;
|
|
8553
8581
|
const config = configFor(ctx, id);
|
|
8554
8582
|
const hookFiles = hookFilesFor(ctx, id);
|
|
8555
|
-
const runCommand2 = [SETUP_NODE,
|
|
8583
|
+
const runCommand2 = [SETUP_NODE, path6.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
8556
8584
|
const bareNode = (id === "codex" || id === "qwen") && (ctx.platform ?? process.platform) === "win32";
|
|
8557
8585
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
8558
8586
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
@@ -8578,7 +8606,7 @@ function buildRegistry(ctx) {
|
|
|
8578
8606
|
hookInstall,
|
|
8579
8607
|
skillInstall,
|
|
8580
8608
|
hookRunCommand: runCommand2,
|
|
8581
|
-
allowedWrites: [...new Set(writes.map((f2) =>
|
|
8609
|
+
allowedWrites: [...new Set(writes.map((f2) => path6.resolve(f2)))],
|
|
8582
8610
|
goldenPayload: golden(row, ctx.home)
|
|
8583
8611
|
};
|
|
8584
8612
|
if (copilotSettings) out2.copilotSettings = copilotSettings;
|
|
@@ -8591,15 +8619,15 @@ function buildRegistry(ctx) {
|
|
|
8591
8619
|
});
|
|
8592
8620
|
}
|
|
8593
8621
|
function assertWritable(row, file) {
|
|
8594
|
-
const abs =
|
|
8595
|
-
if (INSTRUCTION_FILES.includes(
|
|
8622
|
+
const abs = path6.resolve(file);
|
|
8623
|
+
if (INSTRUCTION_FILES.includes(path6.basename(abs)) || !row.allowedWrites.includes(abs)) {
|
|
8596
8624
|
throw new Error(`setup: write to ${abs} is not allowed for ${row.id}`);
|
|
8597
8625
|
}
|
|
8598
8626
|
}
|
|
8599
8627
|
|
|
8600
8628
|
// src/setup/gemini-gate.ts
|
|
8601
8629
|
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8602
|
-
import
|
|
8630
|
+
import path7 from "node:path";
|
|
8603
8631
|
var GEMINI_DIR = ".gemini";
|
|
8604
8632
|
var SETTINGS_FILE2 = "settings.json";
|
|
8605
8633
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
@@ -8615,7 +8643,7 @@ function systemSettingsPath(env) {
|
|
|
8615
8643
|
}
|
|
8616
8644
|
function systemDefaultsPath(env) {
|
|
8617
8645
|
const set2 = env[SYSTEM_DEFAULTS_ENV];
|
|
8618
|
-
return set2 ? set2 :
|
|
8646
|
+
return set2 ? set2 : path7.join(path7.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8619
8647
|
}
|
|
8620
8648
|
function load2(file) {
|
|
8621
8649
|
if (!existsSync12(file)) return void 0;
|
|
@@ -8626,7 +8654,7 @@ function load2(file) {
|
|
|
8626
8654
|
}
|
|
8627
8655
|
}
|
|
8628
8656
|
function sources(env, home, cwd) {
|
|
8629
|
-
return [systemDefaultsPath(env),
|
|
8657
|
+
return [systemDefaultsPath(env), path7.join(geminiDirOf(env, home), SETTINGS_FILE2), path7.join(cwd, GEMINI_DIR, SETTINGS_FILE2), systemSettingsPath(env)].map(load2).filter((s) => s !== void 0);
|
|
8630
8658
|
}
|
|
8631
8659
|
function ownHookEntry(entry2) {
|
|
8632
8660
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -8653,7 +8681,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8653
8681
|
|
|
8654
8682
|
// src/setup/zcode-gate.ts
|
|
8655
8683
|
import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
|
|
8656
|
-
import
|
|
8684
|
+
import path8 from "node:path";
|
|
8657
8685
|
var OWN_AGENT2 = "zcode";
|
|
8658
8686
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
8659
8687
|
var HOOK_TYPES = ["process", "command"];
|
|
@@ -8743,7 +8771,7 @@ function zcodeSchemaBad(doc) {
|
|
|
8743
8771
|
);
|
|
8744
8772
|
}
|
|
8745
8773
|
function zcodeConfigGate(home) {
|
|
8746
|
-
const file =
|
|
8774
|
+
const file = path8.join(home, ".zcode", "cli", "config.json");
|
|
8747
8775
|
if (!existsSync13(file)) return void 0;
|
|
8748
8776
|
let doc;
|
|
8749
8777
|
try {
|
|
@@ -8758,7 +8786,7 @@ function zcodeConfigGate(home) {
|
|
|
8758
8786
|
|
|
8759
8787
|
// src/setup/vscode-gate.ts
|
|
8760
8788
|
import { existsSync as existsSync14, readFileSync as readFileSync10 } from "node:fs";
|
|
8761
|
-
import
|
|
8789
|
+
import path9 from "node:path";
|
|
8762
8790
|
var SETTINGS_FILE3 = "settings.json";
|
|
8763
8791
|
var WORKSPACE_DIR = ".vscode";
|
|
8764
8792
|
var USE_HOOKS_KEY = "chat.useHooks";
|
|
@@ -8775,7 +8803,7 @@ function load3(file) {
|
|
|
8775
8803
|
}
|
|
8776
8804
|
function managedSettingsPath(env) {
|
|
8777
8805
|
if (process.platform === "darwin") return "/Library/Application Support/GitHubCopilot/managed-settings.json";
|
|
8778
|
-
if (process.platform === "win32") return
|
|
8806
|
+
if (process.platform === "win32") return path9.join(env.ProgramFiles || "C:\\Program Files", "GitHubCopilot", "managed-settings.json");
|
|
8779
8807
|
return "/etc/github-copilot/managed-settings.json";
|
|
8780
8808
|
}
|
|
8781
8809
|
function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(env)) {
|
|
@@ -8787,7 +8815,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8787
8815
|
}
|
|
8788
8816
|
}
|
|
8789
8817
|
}
|
|
8790
|
-
const srcs = [
|
|
8818
|
+
const srcs = [path9.join(vscodeUserDirOf(env, home), SETTINGS_FILE3), path9.join(cwd, WORKSPACE_DIR, SETTINGS_FILE3)].map(load3).filter((s) => s !== void 0);
|
|
8791
8819
|
let hooks;
|
|
8792
8820
|
let locations;
|
|
8793
8821
|
for (const s of srcs) {
|
|
@@ -8809,7 +8837,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8809
8837
|
|
|
8810
8838
|
// src/setup/qwen-gate.ts
|
|
8811
8839
|
import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
8812
|
-
import
|
|
8840
|
+
import path10 from "node:path";
|
|
8813
8841
|
var KEY = "disableAllHooks";
|
|
8814
8842
|
var SETTINGS = "settings.json";
|
|
8815
8843
|
var SYSTEM_ENV = "QWEN_CODE_SYSTEM_SETTINGS_PATH";
|
|
@@ -8819,8 +8847,8 @@ var WIN_SYSTEM = "C:\\ProgramData\\qwen-code\\settings.json";
|
|
|
8819
8847
|
var LINUX_SYSTEM = "/etc/qwen-code/settings.json";
|
|
8820
8848
|
function settingsFiles(env, home, cwd, platform) {
|
|
8821
8849
|
const sys = env[SYSTEM_ENV] || (platform === "darwin" ? DARWIN_SYSTEM : platform === "win32" ? WIN_SYSTEM : LINUX_SYSTEM);
|
|
8822
|
-
const userDir = env[HOME_ENV] ||
|
|
8823
|
-
return [sys,
|
|
8850
|
+
const userDir = env[HOME_ENV] || path10.join(home, ".qwen");
|
|
8851
|
+
return [sys, path10.join(userDir, SETTINGS), path10.join(cwd, ".qwen", SETTINGS)];
|
|
8824
8852
|
}
|
|
8825
8853
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8826
8854
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
@@ -8839,38 +8867,30 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8839
8867
|
// src/setup/codex-trust.ts
|
|
8840
8868
|
import { createHash } from "node:crypto";
|
|
8841
8869
|
import { existsSync as existsSync16, realpathSync as realpathSync7 } from "node:fs";
|
|
8842
|
-
import
|
|
8843
|
-
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8870
|
+
import path12 from "node:path";
|
|
8871
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
8844
8872
|
|
|
8845
8873
|
// src/setup/spawn-bin.ts
|
|
8846
8874
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
8847
|
-
import { accessSync, constants as fsc, statSync } from "node:fs";
|
|
8848
|
-
import
|
|
8849
|
-
|
|
8850
|
-
// src/core/sandbox/path-entries.ts
|
|
8851
|
-
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
8852
|
-
const win = platform === "win32";
|
|
8853
|
-
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
8854
|
-
}
|
|
8855
|
-
|
|
8856
|
-
// src/setup/spawn-bin.ts
|
|
8875
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync2 } from "node:fs";
|
|
8876
|
+
import path11 from "node:path";
|
|
8857
8877
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
8858
8878
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
8859
8879
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
8860
8880
|
function envGet(env, k) {
|
|
8861
|
-
return
|
|
8881
|
+
return envValue(env, k, "win32");
|
|
8862
8882
|
}
|
|
8863
8883
|
function whichBin(bin, env, platform = process.platform) {
|
|
8864
8884
|
const get = (k) => envGet(env, k);
|
|
8865
8885
|
const win = platform === "win32";
|
|
8866
8886
|
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
8867
|
-
const names = win &&
|
|
8887
|
+
const names = win && path11.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
8868
8888
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8869
8889
|
for (const n3 of names) {
|
|
8870
|
-
const f2 =
|
|
8890
|
+
const f2 = path11.join(dir, n3);
|
|
8871
8891
|
try {
|
|
8872
|
-
|
|
8873
|
-
if (
|
|
8892
|
+
accessSync2(f2, fsc.X_OK);
|
|
8893
|
+
if (statSync2(f2).isFile()) return f2;
|
|
8874
8894
|
} catch {
|
|
8875
8895
|
}
|
|
8876
8896
|
}
|
|
@@ -8908,7 +8928,7 @@ function winCmdLine(file, args, env = {}) {
|
|
|
8908
8928
|
return `"${[file, ...args].map(q).join(" ")}"`;
|
|
8909
8929
|
}
|
|
8910
8930
|
function spawnForm(file, args, env, platform = process.platform) {
|
|
8911
|
-
if (platform === "win32" && WIN_SHIM_EXTS.includes(
|
|
8931
|
+
if (platform === "win32" && WIN_SHIM_EXTS.includes(path11.extname(file).toLowerCase())) {
|
|
8912
8932
|
return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file, args, env)], windowsVerbatimArguments: true };
|
|
8913
8933
|
}
|
|
8914
8934
|
return { command: file, args, windowsVerbatimArguments: false };
|
|
@@ -8945,13 +8965,13 @@ function snake(name) {
|
|
|
8945
8965
|
return out2;
|
|
8946
8966
|
}
|
|
8947
8967
|
function realFile(file) {
|
|
8948
|
-
let dir =
|
|
8968
|
+
let dir = path12.resolve(file);
|
|
8949
8969
|
const rest = [];
|
|
8950
|
-
while (!existsSync16(dir) &&
|
|
8951
|
-
rest.unshift(
|
|
8952
|
-
dir =
|
|
8970
|
+
while (!existsSync16(dir) && path12.dirname(dir) !== dir) {
|
|
8971
|
+
rest.unshift(path12.basename(dir));
|
|
8972
|
+
dir = path12.dirname(dir);
|
|
8953
8973
|
}
|
|
8954
|
-
return
|
|
8974
|
+
return path12.join(realpathSync7(dir), ...rest);
|
|
8955
8975
|
}
|
|
8956
8976
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8957
8977
|
var ASK_TRIES = 3;
|
|
@@ -8980,10 +9000,10 @@ function askCodexHome(env) {
|
|
|
8980
9000
|
return void 0;
|
|
8981
9001
|
}
|
|
8982
9002
|
function sameDir(a2, b3, platform = process.platform) {
|
|
8983
|
-
if (platform !== "win32") return
|
|
9003
|
+
if (platform !== "win32") return path12.posix.normalize(a2) === path12.posix.normalize(b3);
|
|
8984
9004
|
const norm = (p3) => {
|
|
8985
9005
|
const bare = p3.startsWith(WIN_VERBATIM_PREFIX) ? p3.slice(WIN_VERBATIM_PREFIX.length) : p3;
|
|
8986
|
-
const n3 =
|
|
9006
|
+
const n3 = path12.win32.normalize(bare).toLowerCase();
|
|
8987
9007
|
return n3.length > 3 && n3.endsWith("\\") ? n3.slice(0, -1) : n3;
|
|
8988
9008
|
};
|
|
8989
9009
|
return norm(a2) === norm(b3);
|
|
@@ -8994,9 +9014,9 @@ function codexKeyDir(o2, platform = process.platform) {
|
|
|
8994
9014
|
function codexTrustEntries(hooksFile, doc, command, env) {
|
|
8995
9015
|
const out2 = [];
|
|
8996
9016
|
if (!isObj3(doc) || !isObj3(doc.hooks)) return out2;
|
|
8997
|
-
const abs =
|
|
8998
|
-
const dir = codexKeyDir({ dir:
|
|
8999
|
-
const real2 = (dir.startsWith(WIN_VERBATIM_PREFIX) ?
|
|
9017
|
+
const abs = path12.resolve(hooksFile);
|
|
9018
|
+
const dir = codexKeyDir({ dir: path12.dirname(abs), asked: env ? askCodexHome(env) : void 0, real: env && !env.CODEX_HOME ? (p3) => path12.resolve(p3) : realFile });
|
|
9019
|
+
const real2 = (dir.startsWith(WIN_VERBATIM_PREFIX) ? path12.win32 : path12).join(dir, path12.basename(abs));
|
|
9000
9020
|
for (const [event, groups] of Object.entries(doc.hooks)) {
|
|
9001
9021
|
if (!Array.isArray(groups)) continue;
|
|
9002
9022
|
groups.forEach((g2, gi) => {
|
|
@@ -9049,7 +9069,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
9049
9069
|
resolve6({ kind: "silent" });
|
|
9050
9070
|
return;
|
|
9051
9071
|
}
|
|
9052
|
-
const child =
|
|
9072
|
+
const child = spawn3(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
9053
9073
|
let buf = "";
|
|
9054
9074
|
let done = false;
|
|
9055
9075
|
let exited = false;
|
|
@@ -9151,16 +9171,16 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
9151
9171
|
}
|
|
9152
9172
|
|
|
9153
9173
|
// src/setup/copilot-hooks.ts
|
|
9154
|
-
import { spawn as
|
|
9174
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
9155
9175
|
import { realpathSync as realpathSync8 } from "node:fs";
|
|
9156
|
-
import
|
|
9176
|
+
import path13 from "node:path";
|
|
9157
9177
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9158
9178
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
9159
9179
|
var HEADER_END = "\r\n\r\n";
|
|
9160
9180
|
var LENGTH_HEADER = "content-length";
|
|
9161
9181
|
var USER_ORIGIN = "user";
|
|
9162
9182
|
function canon(p3) {
|
|
9163
|
-
let r2 =
|
|
9183
|
+
let r2 = path13.resolve(p3);
|
|
9164
9184
|
try {
|
|
9165
9185
|
r2 = realpathSync8(r2);
|
|
9166
9186
|
} catch {
|
|
@@ -9171,10 +9191,10 @@ function copilotHooksFromReply(m3, file) {
|
|
|
9171
9191
|
const out2 = [];
|
|
9172
9192
|
if (!isObj4(m3) || !isObj4(m3.result) || !Array.isArray(m3.result.hooks)) return out2;
|
|
9173
9193
|
const want = canon(file);
|
|
9174
|
-
const base =
|
|
9194
|
+
const base = path13.dirname(path13.dirname(path13.resolve(file)));
|
|
9175
9195
|
for (const h2 of m3.result.hooks) {
|
|
9176
9196
|
if (!isObj4(h2) || h2.origin !== USER_ORIGIN || typeof h2.source !== "string" || typeof h2.hookType !== "string" || typeof h2.enabled !== "boolean") continue;
|
|
9177
|
-
if (canon(
|
|
9197
|
+
if (canon(path13.isAbsolute(h2.source) ? h2.source : path13.join(base, h2.source)) !== want) continue;
|
|
9178
9198
|
out2.push({ event: h2.hookType, source: h2.source, enabled: h2.enabled, ...typeof h2.disableKey === "string" ? { disableKey: h2.disableKey } : {} });
|
|
9179
9199
|
}
|
|
9180
9200
|
return out2;
|
|
@@ -9203,7 +9223,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
9203
9223
|
resolve6(void 0);
|
|
9204
9224
|
return;
|
|
9205
9225
|
}
|
|
9206
|
-
const child =
|
|
9226
|
+
const child = spawn4(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
9207
9227
|
let buf = Buffer.alloc(0);
|
|
9208
9228
|
let done = false;
|
|
9209
9229
|
const finish2 = (v) => {
|
|
@@ -9246,10 +9266,10 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
9246
9266
|
}
|
|
9247
9267
|
|
|
9248
9268
|
// src/setup/engine.ts
|
|
9249
|
-
import { spawn as
|
|
9250
|
-
import { closeSync as closeSync3, existsSync as existsSync17, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync12, readSync as readSync3, readdirSync as readdirSync6, realpathSync as realpathSync9, rmSync as rmSync2, statSync as
|
|
9269
|
+
import { spawn as spawn5, spawnSync as spawnSync4 } from "node:child_process";
|
|
9270
|
+
import { closeSync as closeSync3, existsSync as existsSync17, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync12, readSync as readSync3, readdirSync as readdirSync6, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
9251
9271
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
9252
|
-
import
|
|
9272
|
+
import path14 from "node:path";
|
|
9253
9273
|
|
|
9254
9274
|
// src/setup/hook-sample.ts
|
|
9255
9275
|
var SAMPLE_FILE = "big.log";
|
|
@@ -9343,8 +9363,8 @@ function isNativeBinary(file) {
|
|
|
9343
9363
|
return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
|
|
9344
9364
|
}
|
|
9345
9365
|
function owningPackage(dir) {
|
|
9346
|
-
for (let d = dir; ; d =
|
|
9347
|
-
const f2 =
|
|
9366
|
+
for (let d = dir; ; d = path14.dirname(d)) {
|
|
9367
|
+
const f2 = path14.join(d, "package.json");
|
|
9348
9368
|
if (existsSync17(f2)) {
|
|
9349
9369
|
try {
|
|
9350
9370
|
return String(JSON.parse(hostText(readFileSync12(f2, "utf8"))).name);
|
|
@@ -9352,20 +9372,20 @@ function owningPackage(dir) {
|
|
|
9352
9372
|
return void 0;
|
|
9353
9373
|
}
|
|
9354
9374
|
}
|
|
9355
|
-
if (
|
|
9375
|
+
if (path14.dirname(d) === d) return void 0;
|
|
9356
9376
|
}
|
|
9357
9377
|
}
|
|
9358
9378
|
function hostBin(bin, env, platform = process.platform) {
|
|
9359
9379
|
const real2 = REAL_HOST[bin];
|
|
9360
9380
|
if (!real2) return { file: which(bin, env, platform), shims: [] };
|
|
9361
|
-
const get = (k) =>
|
|
9381
|
+
const get = (k) => envValue(env, k, "win32");
|
|
9362
9382
|
const shims = [];
|
|
9363
9383
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
9364
9384
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
9365
|
-
for (const f2 of [own2, ...real2.extra.map((p3) =>
|
|
9366
|
-
if (!f2 || !existsSync17(f2) || !
|
|
9385
|
+
for (const f2 of [own2, ...real2.extra.map((p3) => path14.join(dir, ...p3))]) {
|
|
9386
|
+
if (!f2 || !existsSync17(f2) || !statSync3(f2).isFile()) continue;
|
|
9367
9387
|
const file = realpathSync9(f2);
|
|
9368
|
-
if (isNativeBinary(file) || owningPackage(
|
|
9388
|
+
if (isNativeBinary(file) || owningPackage(path14.dirname(file)) === real2.pkg) return { file: f2, shims };
|
|
9369
9389
|
shims.push(f2);
|
|
9370
9390
|
}
|
|
9371
9391
|
}
|
|
@@ -9525,8 +9545,8 @@ function isNativeSpec(e) {
|
|
|
9525
9545
|
return isNativeOpencodeEntry(e, OPENCODE_PLUGIN_KEY);
|
|
9526
9546
|
}
|
|
9527
9547
|
function isStaleOwnPlugin(e, entry2) {
|
|
9528
|
-
if (typeof e !== "string" || e === entry2 || !
|
|
9529
|
-
if (e ===
|
|
9548
|
+
if (typeof e !== "string" || e === entry2 || !path14.isAbsolute(e)) return false;
|
|
9549
|
+
if (e === path14.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9530
9550
|
if (existsSync17(e)) return false;
|
|
9531
9551
|
const seg = e.split("\\").join("/").split("/");
|
|
9532
9552
|
const n3 = seg.length;
|
|
@@ -9544,8 +9564,8 @@ function nativePluginsKey(doc, file) {
|
|
|
9544
9564
|
return Array.isArray(v) && v.some((e) => isNativeOpencodeEntry(e, k));
|
|
9545
9565
|
});
|
|
9546
9566
|
if (native(doc)) return true;
|
|
9547
|
-
if (opencodeDirPlugin([
|
|
9548
|
-
return OPENCODE_CONFIG_FILES.map((n3) =>
|
|
9567
|
+
if (opencodeDirPlugin([path14.dirname(file)]) !== void 0) return true;
|
|
9568
|
+
return OPENCODE_CONFIG_FILES.map((n3) => path14.join(path14.dirname(file), n3)).filter((f2) => f2 !== file).some((f2) => {
|
|
9549
9569
|
const text2 = readOr(f2);
|
|
9550
9570
|
if (text2 === void 0 || text2.trim() === "") return false;
|
|
9551
9571
|
try {
|
|
@@ -9735,10 +9755,10 @@ var SETTINGS_FILES = ["settings.json", "settings.local.json"];
|
|
|
9735
9755
|
function disabledBySettings(row) {
|
|
9736
9756
|
const c3 = row.copy;
|
|
9737
9757
|
if (!c3) return void 0;
|
|
9738
|
-
const dirs = [
|
|
9758
|
+
const dirs = [path14.dirname(path14.dirname(c3.file)), path14.join(process.cwd(), ".claude")];
|
|
9739
9759
|
for (const dir of dirs) {
|
|
9740
9760
|
for (const name of SETTINGS_FILES) {
|
|
9741
|
-
const file =
|
|
9761
|
+
const file = path14.join(dir, name);
|
|
9742
9762
|
const text2 = readOr(file);
|
|
9743
9763
|
if (text2 === void 0) continue;
|
|
9744
9764
|
let doc;
|
|
@@ -9762,7 +9782,7 @@ function hookEnabledCheck(row, status) {
|
|
|
9762
9782
|
}
|
|
9763
9783
|
function packageVersion(pkgDir) {
|
|
9764
9784
|
try {
|
|
9765
|
-
const v = JSON.parse(hostText(readFileSync12(
|
|
9785
|
+
const v = JSON.parse(hostText(readFileSync12(path14.join(pkgDir, "package.json"), "utf8"))).version;
|
|
9766
9786
|
return typeof v === "string" ? v : void 0;
|
|
9767
9787
|
} catch {
|
|
9768
9788
|
return void 0;
|
|
@@ -9810,7 +9830,7 @@ function degradedDetail(node, env) {
|
|
|
9810
9830
|
}
|
|
9811
9831
|
function mcpCheck(cmd, env) {
|
|
9812
9832
|
return new Promise((resolve6) => {
|
|
9813
|
-
const child =
|
|
9833
|
+
const child = spawn5(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
9814
9834
|
const reap = () => {
|
|
9815
9835
|
child.kill();
|
|
9816
9836
|
};
|
|
@@ -9951,14 +9971,14 @@ function hookRegisteredCheck(row, env, list2) {
|
|
|
9951
9971
|
return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode" : ""}` };
|
|
9952
9972
|
}
|
|
9953
9973
|
function hookRunsCheck(row, env) {
|
|
9954
|
-
const root = mkdtempSync(
|
|
9974
|
+
const root = mkdtempSync(path14.join(tmpdir2(), "cm-doctor-runs-"));
|
|
9955
9975
|
try {
|
|
9956
|
-
const home =
|
|
9957
|
-
const proj =
|
|
9976
|
+
const home = path14.join(root, "home");
|
|
9977
|
+
const proj = path14.join(root, "proj");
|
|
9958
9978
|
mkdirSync5(home);
|
|
9959
9979
|
mkdirSync5(proj);
|
|
9960
9980
|
const text2 = sampleText();
|
|
9961
|
-
writeFileSync3(
|
|
9981
|
+
writeFileSync3(path14.join(proj, SAMPLE_FILE), text2);
|
|
9962
9982
|
const { effect, payload } = hookSample(row.id, proj, text2);
|
|
9963
9983
|
const sampleEnv = { ...env, HOME: home, USERPROFILE: home };
|
|
9964
9984
|
delete sampleEnv.CLAUDE_PROJECT_DIR;
|
|
@@ -9973,7 +9993,7 @@ function hookRunsCheck(row, env) {
|
|
|
9973
9993
|
var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
9974
9994
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9975
9995
|
function hookSeenCheck(row, dataRoot) {
|
|
9976
|
-
const base =
|
|
9996
|
+
const base = path14.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9977
9997
|
const dirs = existsSync17(base) ? readdirSync6(base) : [];
|
|
9978
9998
|
let sqlite;
|
|
9979
9999
|
try {
|
|
@@ -9982,7 +10002,7 @@ function hookSeenCheck(row, dataRoot) {
|
|
|
9982
10002
|
sqlite = void 0;
|
|
9983
10003
|
}
|
|
9984
10004
|
for (const d of dirs) {
|
|
9985
|
-
const file =
|
|
10005
|
+
const file = path14.join(base, d, DB_FILE_NAME);
|
|
9986
10006
|
if (!sqlite || !existsSync17(file)) continue;
|
|
9987
10007
|
let db;
|
|
9988
10008
|
try {
|
|
@@ -9999,7 +10019,7 @@ var SKILL_TOOL_STEM = "ctx_";
|
|
|
9999
10019
|
function skillsCheck(row, pkgDir) {
|
|
10000
10020
|
const s = row.skillInstall;
|
|
10001
10021
|
if (s.kind === "package") {
|
|
10002
|
-
const files = COMMAND_SKILLS.map((n3) =>
|
|
10022
|
+
const files = COMMAND_SKILLS.map((n3) => path14.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
10003
10023
|
const miss = files.filter((f2) => !existsSync17(f2));
|
|
10004
10024
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
10005
10025
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
@@ -10140,7 +10160,7 @@ async function nativeResult(row, ctx, apply2) {
|
|
|
10140
10160
|
return res;
|
|
10141
10161
|
}
|
|
10142
10162
|
function trustPluginHooks(row, ctx, apply2, hooks) {
|
|
10143
|
-
const file =
|
|
10163
|
+
const file = path14.join(codexDirOf(ctx.env, ctx.home), CODEX_CONFIG_FILE2);
|
|
10144
10164
|
const text2 = readOr(file);
|
|
10145
10165
|
let edit;
|
|
10146
10166
|
try {
|
|
@@ -10261,16 +10281,16 @@ var Run = class {
|
|
|
10261
10281
|
this.runId = runId;
|
|
10262
10282
|
}
|
|
10263
10283
|
get dir() {
|
|
10264
|
-
return
|
|
10284
|
+
return path14.join(this.root, BACKUP_DIR, this.runId);
|
|
10265
10285
|
}
|
|
10266
10286
|
save() {
|
|
10267
|
-
if (this.manifest) atomicWrite(
|
|
10287
|
+
if (this.manifest) atomicWrite(path14.join(this.dir, MANIFEST), JSON.stringify(this.manifest, null, 2));
|
|
10268
10288
|
}
|
|
10269
10289
|
record(e, bytes) {
|
|
10270
10290
|
if (!this.manifest) this.manifest = { runId: this.runId, path: this.dir, entries: [] };
|
|
10271
10291
|
if (bytes !== void 0) {
|
|
10272
|
-
const rel =
|
|
10273
|
-
atomicWrite(
|
|
10292
|
+
const rel = path14.join(FILES, String(this.manifest.entries.length));
|
|
10293
|
+
atomicWrite(path14.join(this.dir, rel), bytes);
|
|
10274
10294
|
e.backup = rel;
|
|
10275
10295
|
}
|
|
10276
10296
|
this.manifest.entries.push(e);
|
|
@@ -10290,12 +10310,12 @@ function undo(dir, entries, env) {
|
|
|
10290
10310
|
continue;
|
|
10291
10311
|
}
|
|
10292
10312
|
if (!e.file) continue;
|
|
10293
|
-
if (e.existed && e.backup) atomicWrite(e.file, readFileSync12(
|
|
10313
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync12(path14.join(dir, e.backup), "utf8"));
|
|
10294
10314
|
else unlinkWithRetry(e.file);
|
|
10295
10315
|
}
|
|
10296
10316
|
}
|
|
10297
10317
|
function takeLock(root, runId) {
|
|
10298
|
-
const file =
|
|
10318
|
+
const file = path14.join(root, LOCK_FILE);
|
|
10299
10319
|
mkdirSync5(root, { recursive: true });
|
|
10300
10320
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
10301
10321
|
try {
|
|
@@ -10320,7 +10340,7 @@ function agentHomeDir(id, ctx) {
|
|
|
10320
10340
|
if (id === "kiro") return kiroDirOf(ctx.env, ctx.home);
|
|
10321
10341
|
if (id === "opencode") return opencodeDirOf(ctx.env, ctx.home);
|
|
10322
10342
|
if (id === "gemini") return geminiDirOf(ctx.env, ctx.home);
|
|
10323
|
-
return
|
|
10343
|
+
return path14.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
10324
10344
|
}
|
|
10325
10345
|
function detectAgents(reg, ctx) {
|
|
10326
10346
|
return reg.filter((r2) => existsSync17(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
@@ -10332,7 +10352,7 @@ async function runSetup(opts) {
|
|
|
10332
10352
|
const nodeVersion = opts.nodeVersion ?? process.version;
|
|
10333
10353
|
if (nodeTooOld(nodeVersion)) return { exitCode: 1, agents: [], error: formatError("NODE_TOO_OLD", { v: nodeVersion }) };
|
|
10334
10354
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10335
|
-
if (!existsSync17(
|
|
10355
|
+
if (!existsSync17(path14.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path14.join(ctx.pkgDir, f2)} is missing` };
|
|
10336
10356
|
}
|
|
10337
10357
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10338
10358
|
const root = dataRootOf(ctx.env, ctx.home);
|
|
@@ -10345,7 +10365,7 @@ async function runSetup(opts) {
|
|
|
10345
10365
|
let current;
|
|
10346
10366
|
const onAbort = () => {
|
|
10347
10367
|
if (current !== void 0 && !opts.dryRun) run.rollback(current, ctx.env);
|
|
10348
|
-
if (!opts.dryRun) rmSync2(
|
|
10368
|
+
if (!opts.dryRun) rmSync2(path14.join(root, LOCK_FILE), { force: true });
|
|
10349
10369
|
};
|
|
10350
10370
|
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
10351
10371
|
try {
|
|
@@ -10364,7 +10384,7 @@ async function runSetup(opts) {
|
|
|
10364
10384
|
}
|
|
10365
10385
|
} finally {
|
|
10366
10386
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
10367
|
-
if (!opts.dryRun) rmSync2(
|
|
10387
|
+
if (!opts.dryRun) rmSync2(path14.join(root, LOCK_FILE), { force: true });
|
|
10368
10388
|
}
|
|
10369
10389
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents, backupDir: run.manifest ? run.dir : void 0 };
|
|
10370
10390
|
}
|
|
@@ -10439,7 +10459,7 @@ async function runDoctor(opts) {
|
|
|
10439
10459
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env, cwd: opts.cwd };
|
|
10440
10460
|
const reg = buildRegistry(ctx);
|
|
10441
10461
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10442
|
-
if (!existsSync17(
|
|
10462
|
+
if (!existsSync17(path14.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path14.join(ctx.pkgDir, f2)} is missing` };
|
|
10443
10463
|
}
|
|
10444
10464
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10445
10465
|
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
@@ -10485,7 +10505,7 @@ function notSetUpReason(row, res, env) {
|
|
|
10485
10505
|
const h2 = row.hookInstall;
|
|
10486
10506
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
10487
10507
|
const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
10488
|
-
const dead = missing ? opencodeDirPlugins(opencodePluginDirs(
|
|
10508
|
+
const dead = missing ? opencodeDirPlugins(opencodePluginDirs(path14.dirname(h2.file), h2.worktree)).find((p3) => !p3.loads) : void 0;
|
|
10489
10509
|
const hint = dead ? `; ${dead.file} loads context-mode once ${OPENCODE_PACKAGE_DIR_HINT} is next to it or above it` : "";
|
|
10490
10510
|
if (oc2) return `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode${hint}`;
|
|
10491
10511
|
if (hint) return NOT_SET_UP_REASON + hint;
|
|
@@ -10518,21 +10538,21 @@ function isTrust(row, c3) {
|
|
|
10518
10538
|
function runRemove(opts) {
|
|
10519
10539
|
const env = opts.env ?? process.env;
|
|
10520
10540
|
const root = dataRootOf(env, opts.home);
|
|
10521
|
-
const base =
|
|
10541
|
+
const base = path14.join(root, BACKUP_DIR);
|
|
10522
10542
|
if (!existsSync17(base)) return { exitCode: 0, restored: 0 };
|
|
10523
10543
|
const held = takeLock(root, "remove");
|
|
10524
10544
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
10525
10545
|
let restored = 0;
|
|
10526
10546
|
try {
|
|
10527
|
-
const runs = readdirSync6(base).map((r2) =>
|
|
10547
|
+
const runs = readdirSync6(base).map((r2) => path14.join(base, r2)).filter((d) => existsSync17(path14.join(d, MANIFEST))).sort().reverse();
|
|
10528
10548
|
for (const dir of runs) {
|
|
10529
|
-
const m3 = JSON.parse(readFileSync12(
|
|
10549
|
+
const m3 = JSON.parse(readFileSync12(path14.join(dir, MANIFEST), "utf8"));
|
|
10530
10550
|
undo(dir, m3.entries, env);
|
|
10531
10551
|
restored += m3.entries.length;
|
|
10532
|
-
renameWithRetry(
|
|
10552
|
+
renameWithRetry(path14.join(dir, MANIFEST), path14.join(dir, MANIFEST_DONE));
|
|
10533
10553
|
}
|
|
10534
10554
|
} finally {
|
|
10535
|
-
rmSync2(
|
|
10555
|
+
rmSync2(path14.join(root, LOCK_FILE), { force: true });
|
|
10536
10556
|
}
|
|
10537
10557
|
return { exitCode: 0, restored };
|
|
10538
10558
|
}
|
|
@@ -10737,9 +10757,9 @@ async function report(ui, command, res, write) {
|
|
|
10737
10757
|
const { text: text2, title } = buildIssueReport(command, res, ui);
|
|
10738
10758
|
let file = "";
|
|
10739
10759
|
if (write) {
|
|
10740
|
-
const dir =
|
|
10760
|
+
const dir = path15.join(dataRootOf(ui.ctx.env, ui.ctx.home), REPORT_DIR);
|
|
10741
10761
|
mkdirSync6(dir, { recursive: true });
|
|
10742
|
-
file =
|
|
10762
|
+
file = path15.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
10743
10763
|
writeFileSync4(file, text2);
|
|
10744
10764
|
}
|
|
10745
10765
|
const gh = `gh issue create --repo ${ISSUE_REPO} --title ${JSON.stringify(title)} --label bug --body-file ${JSON.stringify(file || "<report>")}`;
|
|
@@ -10848,7 +10868,7 @@ async function remove(ui) {
|
|
|
10848
10868
|
}
|
|
10849
10869
|
}
|
|
10850
10870
|
if (ui.f.dryRun) {
|
|
10851
|
-
out(`Would restore every file recorded under ${
|
|
10871
|
+
out(`Would restore every file recorded under ${path15.join(dataRootOf(ui.ctx.env, ui.ctx.home), "backups")}`);
|
|
10852
10872
|
return EXIT_OK;
|
|
10853
10873
|
}
|
|
10854
10874
|
const r2 = runRemove({ home: ui.ctx.home, env: ui.ctx.env });
|
|
@@ -10993,7 +11013,7 @@ async function upgrade(ui) {
|
|
|
10993
11013
|
return EXIT_FAIL;
|
|
10994
11014
|
}
|
|
10995
11015
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10996
|
-
const cli =
|
|
11016
|
+
const cli = path15.join(root, "context-mode", "cli.mjs");
|
|
10997
11017
|
if (!root || !existsSync18(cli)) {
|
|
10998
11018
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10999
11019
|
return EXIT_FAIL;
|
|
@@ -11089,10 +11109,10 @@ function route(argv, version) {
|
|
|
11089
11109
|
` };
|
|
11090
11110
|
}
|
|
11091
11111
|
function main() {
|
|
11092
|
-
const dir =
|
|
11112
|
+
const dir = path16.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
11093
11113
|
let version = "";
|
|
11094
11114
|
try {
|
|
11095
|
-
version = String(JSON.parse(readFileSync14(
|
|
11115
|
+
version = String(JSON.parse(readFileSync14(path16.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
11096
11116
|
} catch (err2) {
|
|
11097
11117
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
11098
11118
|
`);
|
|
@@ -11116,7 +11136,7 @@ function main() {
|
|
|
11116
11136
|
process.exitCode = r2.code;
|
|
11117
11137
|
return;
|
|
11118
11138
|
}
|
|
11119
|
-
const child =
|
|
11139
|
+
const child = spawn6(process.execPath, [path16.join(dir, r2.file), ...r2.args], { stdio: "inherit", windowsHide: true });
|
|
11120
11140
|
process.on("SIGINT", () => {
|
|
11121
11141
|
});
|
|
11122
11142
|
child.on("error", (err2) => {
|