context-mode 2.1.9 → 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 +13 -13
- package/cli.mjs +183 -168
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/opencode/plugin.js +46 -18
- package/package.json +1 -1
- package/pi/index.js +48 -20
- package/qwen-extension.json +1 -1
- package/server.mjs +48 -20
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";
|
|
@@ -5092,6 +5092,21 @@ function envValue(env, name, platform = process.platform) {
|
|
|
5092
5092
|
return key === void 0 ? void 0 : env[key];
|
|
5093
5093
|
}
|
|
5094
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
|
+
|
|
5095
5110
|
// src/core/store/schema.ts
|
|
5096
5111
|
var PRAGMAS = `
|
|
5097
5112
|
PRAGMA busy_timeout = ${DB_TIMEOUT_MS};
|
|
@@ -7262,7 +7277,7 @@ function parseTOML(code, options) {
|
|
|
7262
7277
|
|
|
7263
7278
|
// src/core/ops/atomic-file.ts
|
|
7264
7279
|
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7265
|
-
import
|
|
7280
|
+
import path4 from "node:path";
|
|
7266
7281
|
function sleepSync(ms) {
|
|
7267
7282
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
7268
7283
|
}
|
|
@@ -7312,8 +7327,8 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
7312
7327
|
}
|
|
7313
7328
|
}
|
|
7314
7329
|
function atomicWriteFile(file, text2, opts = {}) {
|
|
7315
|
-
mkdirSync3(
|
|
7316
|
-
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}`);
|
|
7317
7332
|
try {
|
|
7318
7333
|
writeFileSync(tmp, text2);
|
|
7319
7334
|
renameWithRetry(tmp, file, opts);
|
|
@@ -7504,14 +7519,14 @@ function scanToml(text2) {
|
|
|
7504
7519
|
continue;
|
|
7505
7520
|
}
|
|
7506
7521
|
if (!node.resolvedKey.every((seg) => typeof seg === "string")) continue;
|
|
7507
|
-
const
|
|
7508
|
-
for (const kv of node.body) addKey(
|
|
7522
|
+
const path17 = node.resolvedKey;
|
|
7523
|
+
for (const kv of node.body) addKey(path17, kv);
|
|
7509
7524
|
if (node.kind !== "standard") continue;
|
|
7510
7525
|
const start = lineStartOf(text2, node.range[0]);
|
|
7511
7526
|
const headEnd = lineEndOf(text2, node.key.range[1]);
|
|
7512
7527
|
const last2 = node.body[node.body.length - 1];
|
|
7513
7528
|
tables.push({
|
|
7514
|
-
path:
|
|
7529
|
+
path: path17,
|
|
7515
7530
|
header: text2.slice(start, text2[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
|
|
7516
7531
|
start,
|
|
7517
7532
|
end: last2 === void 0 ? headEnd : lineEndOf(text2, last2.range[1])
|
|
@@ -7522,16 +7537,16 @@ function scanToml(text2) {
|
|
|
7522
7537
|
function tomlTableSpans(text2) {
|
|
7523
7538
|
return scanToml(text2).tables;
|
|
7524
7539
|
}
|
|
7525
|
-
function parseHostConfig(agent,
|
|
7540
|
+
function parseHostConfig(agent, path17, text2, format) {
|
|
7526
7541
|
try {
|
|
7527
7542
|
return format === "toml" ? scanToml(text2).value : scanJson(text2, format).value;
|
|
7528
7543
|
} catch {
|
|
7529
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
7544
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path17, format });
|
|
7530
7545
|
}
|
|
7531
7546
|
}
|
|
7532
|
-
function hostConfigValueAt(value,
|
|
7547
|
+
function hostConfigValueAt(value, path17) {
|
|
7533
7548
|
let cur = value;
|
|
7534
|
-
for (const seg of
|
|
7549
|
+
for (const seg of path17) {
|
|
7535
7550
|
if (!isPlainObject(cur)) return void 0;
|
|
7536
7551
|
cur = cur[seg];
|
|
7537
7552
|
}
|
|
@@ -7564,32 +7579,32 @@ function indentUnit(root, clean) {
|
|
|
7564
7579
|
function render(value, unit, base) {
|
|
7565
7580
|
return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
|
|
7566
7581
|
}
|
|
7567
|
-
function nest(
|
|
7582
|
+
function nest(path17, value) {
|
|
7568
7583
|
let out2 = value;
|
|
7569
|
-
for (let k =
|
|
7584
|
+
for (let k = path17.length - 1; k >= 0; k -= 1) out2 = { [path17[k]]: out2 };
|
|
7570
7585
|
return out2;
|
|
7571
7586
|
}
|
|
7572
|
-
function setJsonText(text2, format,
|
|
7587
|
+
function setJsonText(text2, format, path17, value) {
|
|
7573
7588
|
const doc = scanJson(text2, format);
|
|
7574
7589
|
const unit = indentUnit(doc.root, doc.clean);
|
|
7575
|
-
if (doc.root === null) return render(nest(
|
|
7590
|
+
if (doc.root === null) return render(nest(path17, value), unit, "") + "\n";
|
|
7576
7591
|
let node = doc.root;
|
|
7577
7592
|
let depth = 0;
|
|
7578
|
-
while (depth <
|
|
7579
|
-
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]);
|
|
7580
7595
|
if (hit === void 0) break;
|
|
7581
7596
|
node = hit.node;
|
|
7582
7597
|
depth += 1;
|
|
7583
7598
|
}
|
|
7584
|
-
if (depth ===
|
|
7599
|
+
if (depth === path17.length) {
|
|
7585
7600
|
return text2.slice(0, node.start) + render(value, unit, lineIndent(doc.clean, node.start)) + text2.slice(node.end);
|
|
7586
7601
|
}
|
|
7587
|
-
if (node.kind !== "object") throw new SyntaxError("not an object at " +
|
|
7588
|
-
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);
|
|
7589
7604
|
const last2 = node.members[node.members.length - 1];
|
|
7590
7605
|
if (last2 === void 0) {
|
|
7591
7606
|
const base2 = lineIndent(doc.clean, node.start);
|
|
7592
|
-
const member2 = "\n" + base2 + unit + JSON.stringify(
|
|
7607
|
+
const member2 = "\n" + base2 + unit + JSON.stringify(path17[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
|
|
7593
7608
|
return text2.slice(0, node.start + 1) + member2 + text2.slice(node.end - 1);
|
|
7594
7609
|
}
|
|
7595
7610
|
const base = lineIndent(doc.clean, last2.keyStart);
|
|
@@ -7597,7 +7612,7 @@ function setJsonText(text2, format, path15, value) {
|
|
|
7597
7612
|
while (" \r\n".includes(doc.clean[at])) at += 1;
|
|
7598
7613
|
const trailing = doc.clean[at] === ",";
|
|
7599
7614
|
const insertAt = trailing ? at + 1 : last2.node.end;
|
|
7600
|
-
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(
|
|
7615
|
+
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path17[depth]) + ": " + render(rest, unit, base);
|
|
7601
7616
|
return text2.slice(0, insertAt) + member + text2.slice(insertAt);
|
|
7602
7617
|
}
|
|
7603
7618
|
function tomlScalar(v) {
|
|
@@ -7615,17 +7630,17 @@ function tomlHeaderKey(seg) {
|
|
|
7615
7630
|
}
|
|
7616
7631
|
return seg;
|
|
7617
7632
|
}
|
|
7618
|
-
function tomlBlock(
|
|
7619
|
-
let out2 = "[" +
|
|
7633
|
+
function tomlBlock(path17, value) {
|
|
7634
|
+
let out2 = "[" + path17.map(tomlHeaderKey).join(".") + "]\n";
|
|
7620
7635
|
const subs = [];
|
|
7621
7636
|
for (const [k, v] of Object.entries(value)) {
|
|
7622
|
-
if (isPlainObject(v)) subs.push(tomlBlock([...
|
|
7637
|
+
if (isPlainObject(v)) subs.push(tomlBlock([...path17, k], v));
|
|
7623
7638
|
else out2 += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
|
|
7624
7639
|
}
|
|
7625
7640
|
return [out2, ...subs].join("\n");
|
|
7626
7641
|
}
|
|
7627
|
-
function under(
|
|
7628
|
-
return
|
|
7642
|
+
function under(path17, prefix) {
|
|
7643
|
+
return path17.length >= prefix.length && prefix.every((seg, k) => path17[k] === seg);
|
|
7629
7644
|
}
|
|
7630
7645
|
function keyLineRange(text2, k) {
|
|
7631
7646
|
const ls = lineStartOf(text2, k.start);
|
|
@@ -7642,10 +7657,10 @@ function withValueAt(root, rel, value) {
|
|
|
7642
7657
|
else base[rel[0]] = next;
|
|
7643
7658
|
return base;
|
|
7644
7659
|
}
|
|
7645
|
-
function replaceToml(text2, doc,
|
|
7646
|
-
const block2 = value === void 0 ? "" : tomlBlock(
|
|
7647
|
-
const owned = doc.tables.filter((t2) => under(t2.path,
|
|
7648
|
-
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), ""]);
|
|
7649
7664
|
owned.forEach((t2, n3) => cuts.push([t2.start, t2.end, n3 === 0 ? block2 : ""]));
|
|
7650
7665
|
cuts.sort((a2, b3) => b3[0] - a2[0]);
|
|
7651
7666
|
let out2 = text2;
|
|
@@ -7655,27 +7670,27 @@ function replaceToml(text2, doc, path15, value) {
|
|
|
7655
7670
|
return out2 + sep3 + block2;
|
|
7656
7671
|
}
|
|
7657
7672
|
var tableLike = (v) => v === void 0 || isPlainObject(v);
|
|
7658
|
-
function setTomlText(text2,
|
|
7673
|
+
function setTomlText(text2, path17, value) {
|
|
7659
7674
|
if (value !== void 0 && !isPlainObject(value)) throw new SyntaxError("TOML edits replace a whole table");
|
|
7660
7675
|
const doc = scanToml(text2);
|
|
7661
|
-
const cur = hostConfigValueAt(doc.value,
|
|
7676
|
+
const cur = hostConfigValueAt(doc.value, path17);
|
|
7662
7677
|
if (sameValue(cur, value)) return text2;
|
|
7663
|
-
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));
|
|
7664
7679
|
if (inline !== void 0) {
|
|
7665
|
-
const whole = withValueAt(hostConfigValueAt(doc.value, inline.full),
|
|
7680
|
+
const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path17.slice(inline.full.length), value);
|
|
7666
7681
|
return replaceToml(text2, doc, inline.full, whole);
|
|
7667
7682
|
}
|
|
7668
7683
|
if (isPlainObject(cur) && isPlainObject(value)) {
|
|
7669
7684
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
7670
7685
|
if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
|
|
7671
7686
|
let out2 = text2;
|
|
7672
|
-
for (const k of names) out2 = setTomlText(out2, [...
|
|
7687
|
+
for (const k of names) out2 = setTomlText(out2, [...path17, k], value[k]);
|
|
7673
7688
|
return out2;
|
|
7674
7689
|
}
|
|
7675
7690
|
}
|
|
7676
|
-
return replaceToml(text2, doc,
|
|
7691
|
+
return replaceToml(text2, doc, path17, value);
|
|
7677
7692
|
}
|
|
7678
|
-
function setText(agent,
|
|
7693
|
+
function setText(agent, path17, text2, format, key, value) {
|
|
7679
7694
|
try {
|
|
7680
7695
|
if (format !== "toml") return setJsonText(text2, format, key, value);
|
|
7681
7696
|
const out2 = setTomlText(text2, key, value);
|
|
@@ -7684,7 +7699,7 @@ function setText(agent, path15, text2, format, key, value) {
|
|
|
7684
7699
|
if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
|
|
7685
7700
|
return out2;
|
|
7686
7701
|
} catch {
|
|
7687
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
7702
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path17, format });
|
|
7688
7703
|
}
|
|
7689
7704
|
}
|
|
7690
7705
|
function isNodeCommand(command) {
|
|
@@ -7702,26 +7717,26 @@ function ownMcpValue(agent, node, server) {
|
|
|
7702
7717
|
function opencodePluginFile() {
|
|
7703
7718
|
return ownBundleDir();
|
|
7704
7719
|
}
|
|
7705
|
-
function applyEdits(agent,
|
|
7706
|
-
const parsed = parseHostConfig(agent,
|
|
7720
|
+
function applyEdits(agent, path17, text2, format, wanted) {
|
|
7721
|
+
const parsed = parseHostConfig(agent, path17, text2, format);
|
|
7707
7722
|
let out2 = text2;
|
|
7708
7723
|
const edits = [];
|
|
7709
7724
|
for (const [key, after] of wanted) {
|
|
7710
7725
|
const before = hostConfigValueAt(parsed, key);
|
|
7711
7726
|
if (sameValue(before, after)) continue;
|
|
7712
|
-
out2 = setText(agent,
|
|
7727
|
+
out2 = setText(agent, path17, out2, format, key, after);
|
|
7713
7728
|
edits.push({ path: key.join("."), before, after });
|
|
7714
7729
|
}
|
|
7715
7730
|
return { text: out2, format, edits };
|
|
7716
7731
|
}
|
|
7717
|
-
function editHostConfigText(agent,
|
|
7718
|
-
return applyEdits(agent,
|
|
7732
|
+
function editHostConfigText(agent, path17, text2, format, wanted) {
|
|
7733
|
+
return applyEdits(agent, path17, text2, format, wanted);
|
|
7719
7734
|
}
|
|
7720
7735
|
|
|
7721
7736
|
// src/core/ops/detect-v1.ts
|
|
7722
7737
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7723
7738
|
var keyPath = (...parts) => parts.join(".");
|
|
7724
|
-
var finding = (file,
|
|
7739
|
+
var finding = (file, path17, reason) => ({ file, path: path17, reason });
|
|
7725
7740
|
function stripJsonc(text2) {
|
|
7726
7741
|
let out2 = "";
|
|
7727
7742
|
let inStr = false;
|
|
@@ -8039,7 +8054,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
8039
8054
|
|
|
8040
8055
|
// src/setup/pi-gate.ts
|
|
8041
8056
|
import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
8042
|
-
import
|
|
8057
|
+
import path5 from "node:path";
|
|
8043
8058
|
var OWN_FILE = "pi/index.js";
|
|
8044
8059
|
var EXTENSIONS_KEY = "extensions";
|
|
8045
8060
|
var PROJECT_DIR = ".pi";
|
|
@@ -8058,7 +8073,7 @@ var real = (p3) => {
|
|
|
8058
8073
|
try {
|
|
8059
8074
|
return realpathSync4(p3);
|
|
8060
8075
|
} catch {
|
|
8061
|
-
return
|
|
8076
|
+
return path5.resolve(p3);
|
|
8062
8077
|
}
|
|
8063
8078
|
};
|
|
8064
8079
|
function sourceName(source) {
|
|
@@ -8086,14 +8101,14 @@ function ownEntries(src, pkgDir) {
|
|
|
8086
8101
|
return out2;
|
|
8087
8102
|
}
|
|
8088
8103
|
function matchesAny(patterns, pkgDir) {
|
|
8089
|
-
const abs =
|
|
8104
|
+
const abs = path5.join(pkgDir, OWN_FILE).split(path5.sep).join("/");
|
|
8090
8105
|
return patterns.some((p3) => {
|
|
8091
8106
|
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8092
|
-
return [OWN_FILE,
|
|
8107
|
+
return [OWN_FILE, path5.posix.basename(OWN_FILE), abs].some((c3) => path5.posix.matchesGlob(c3, g2));
|
|
8093
8108
|
});
|
|
8094
8109
|
}
|
|
8095
8110
|
var exactAny = (patterns, pkgDir) => {
|
|
8096
|
-
const abs =
|
|
8111
|
+
const abs = path5.join(pkgDir, OWN_FILE).split(path5.sep).join("/");
|
|
8097
8112
|
return patterns.some((p3) => {
|
|
8098
8113
|
const g2 = p3.startsWith("./") ? p3.slice(2) : p3;
|
|
8099
8114
|
return g2 === OWN_FILE || g2 === abs;
|
|
@@ -8110,14 +8125,14 @@ function loads(patterns, pkgDir) {
|
|
|
8110
8125
|
return on;
|
|
8111
8126
|
}
|
|
8112
8127
|
function projectTrusted(agentDir, userDoc, cwd) {
|
|
8113
|
-
const trust = load(
|
|
8128
|
+
const trust = load(path5.join(agentDir, TRUST_FILE));
|
|
8114
8129
|
const entries = /* @__PURE__ */ new Map();
|
|
8115
8130
|
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real(k), v);
|
|
8116
8131
|
let dir = real(cwd);
|
|
8117
8132
|
for (; ; ) {
|
|
8118
8133
|
const v = entries.get(dir);
|
|
8119
8134
|
if (v === true || v === false) return v;
|
|
8120
|
-
const up =
|
|
8135
|
+
const up = path5.dirname(dir);
|
|
8121
8136
|
if (up === dir) break;
|
|
8122
8137
|
dir = up;
|
|
8123
8138
|
}
|
|
@@ -8125,8 +8140,8 @@ function projectTrusted(agentDir, userDoc, cwd) {
|
|
|
8125
8140
|
}
|
|
8126
8141
|
function piSettingsGate(env, home, pkgDir, cwd) {
|
|
8127
8142
|
const agentDir = piAgentDirOf(env, home);
|
|
8128
|
-
const user = load(
|
|
8129
|
-
const project = load(
|
|
8143
|
+
const user = load(path5.join(agentDir, SETTINGS_FILE));
|
|
8144
|
+
const project = load(path5.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
8130
8145
|
const projectOwn = project && projectTrusted(agentDir, user?.doc, cwd) ? ownEntries(project, pkgDir) : [];
|
|
8131
8146
|
const effective = projectOwn.length ? projectOwn : user ? ownEntries(user, pkgDir) : [];
|
|
8132
8147
|
for (const e of effective) {
|
|
@@ -8271,7 +8286,7 @@ function formUrl(title, summary) {
|
|
|
8271
8286
|
|
|
8272
8287
|
// src/setup/registry.ts
|
|
8273
8288
|
import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
8274
|
-
import
|
|
8289
|
+
import path6 from "node:path";
|
|
8275
8290
|
|
|
8276
8291
|
// src/setup/hook-shapes.ts
|
|
8277
8292
|
var MS_PER_SECOND = 1e3;
|
|
@@ -8356,11 +8371,11 @@ var OPENCODE_HOME_SEGS = AGENT_HOME_DIR.opencode;
|
|
|
8356
8371
|
function agentPath(ctx, id, rel) {
|
|
8357
8372
|
const segs = typeof rel === "string" ? rel.split("/") : [...rel];
|
|
8358
8373
|
const codexHome = ctx.env[CODEX_HOME_ENV2];
|
|
8359
|
-
if (id === "codex" && segs[0] === CODEX_DIR && codexHome !== void 0 && codexHome !== "") return
|
|
8360
|
-
if (id === "copilot-cli" && segs[0] === COPILOT_DIR) return
|
|
8361
|
-
if (id === "kiro" && segs[0] === KIRO_DIR) return
|
|
8362
|
-
if (id === "opencode" && segs[0] === OPENCODE_HOME_SEGS[0] && segs[1] === OPENCODE_HOME_SEGS[1]) return
|
|
8363
|
-
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);
|
|
8364
8379
|
}
|
|
8365
8380
|
function renderSkill(text2, prefix) {
|
|
8366
8381
|
const prefixes = typeof prefix === "string" ? [prefix] : prefix;
|
|
@@ -8390,7 +8405,7 @@ function extensionPlugin(bin, id) {
|
|
|
8390
8405
|
};
|
|
8391
8406
|
}
|
|
8392
8407
|
var NATIVE_PLUGIN = {
|
|
8393
|
-
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 },
|
|
8394
8409
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
8395
8410
|
gemini: extensionPlugin("gemini", "gemini"),
|
|
8396
8411
|
// D-R44-ZCODE-NATIVE-1 (host audit zcode-1/2): `zcode plugins install context-mode@context-mode` lists as JSON; ZCode loads
|
|
@@ -8424,7 +8439,7 @@ function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
|
8424
8439
|
}
|
|
8425
8440
|
var SETUP_NODE = stableNodePath(process.execPath);
|
|
8426
8441
|
function serverCmd(ctx, id) {
|
|
8427
|
-
return [SETUP_NODE,
|
|
8442
|
+
return [SETUP_NODE, path6.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
8428
8443
|
}
|
|
8429
8444
|
function hookCommandString(row) {
|
|
8430
8445
|
const [node, file, flag, id] = row.hookCommand ?? [];
|
|
@@ -8454,7 +8469,7 @@ function configFor(ctx, id) {
|
|
|
8454
8469
|
}
|
|
8455
8470
|
if (id === "opencode") {
|
|
8456
8471
|
return {
|
|
8457
|
-
file:
|
|
8472
|
+
file: path6.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
8458
8473
|
format: "jsonc",
|
|
8459
8474
|
key: ["mcp", SERVER_KEY],
|
|
8460
8475
|
value: { type: "local", command: [node, server, flag, agent], enabled: true }
|
|
@@ -8483,7 +8498,7 @@ function cliFor(ctx, id) {
|
|
|
8483
8498
|
}
|
|
8484
8499
|
function copyFor(ctx, id) {
|
|
8485
8500
|
if (id !== "claude-code") return void 0;
|
|
8486
|
-
const file =
|
|
8501
|
+
const file = path6.join(claudeDirOf(ctx.env, ctx.home), HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE);
|
|
8487
8502
|
return {
|
|
8488
8503
|
host: "Claude Code",
|
|
8489
8504
|
bin: "claude",
|
|
@@ -8513,12 +8528,12 @@ function hookFilesFor(ctx, id) {
|
|
|
8513
8528
|
case "copilot-cli":
|
|
8514
8529
|
return [{ file: agentPath(ctx, id, [COPILOT_DIR, "hooks", "context-mode.json"]), mode: "rewrite" }];
|
|
8515
8530
|
case "claude-code":
|
|
8516
|
-
return [{ file:
|
|
8531
|
+
return [{ file: path6.join(claudeDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
8517
8532
|
case "gemini":
|
|
8518
|
-
return [{ file:
|
|
8533
|
+
return [{ file: path6.join(geminiDirOf(ctx.env, home), "settings.json"), mode: "drop" }];
|
|
8519
8534
|
// D-R38-GEMINI-HOME-1
|
|
8520
8535
|
case "qwen":
|
|
8521
|
-
return [{ file:
|
|
8536
|
+
return [{ file: path6.join(home, ".qwen", "settings.json"), mode: "drop" }];
|
|
8522
8537
|
default:
|
|
8523
8538
|
return [];
|
|
8524
8539
|
}
|
|
@@ -8529,13 +8544,13 @@ function hookInstallFor(ctx, row, command) {
|
|
|
8529
8544
|
const shape = HOOK_SHAPES[row.id];
|
|
8530
8545
|
if (!shape) throw new Error(`setup: ${row.id} has a home-file hook channel and no hook shape`);
|
|
8531
8546
|
const file = agentPath(ctx, row.id, ch.path);
|
|
8532
|
-
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) };
|
|
8533
8548
|
return { kind: "file", file, shape: shape(row, command), command };
|
|
8534
8549
|
}
|
|
8535
8550
|
if (row.id === "opencode") {
|
|
8536
8551
|
return {
|
|
8537
8552
|
kind: "plugin-list",
|
|
8538
|
-
file:
|
|
8553
|
+
file: path6.join(opencodeDirOf(ctx.env, ctx.home), OPENCODE_BASE_CONFIG_FILE),
|
|
8539
8554
|
key: ["plugin"],
|
|
8540
8555
|
worktree: ctx.cwd ?? process.cwd(),
|
|
8541
8556
|
// D-R54-OC-PLUGINS-DIR-1: <project>/.opencode/plugins
|
|
@@ -8553,11 +8568,11 @@ function skillInstallFor(ctx, row) {
|
|
|
8553
8568
|
const ch = row.skillChannel;
|
|
8554
8569
|
if (ch.kind === "package") return { kind: "package", via: ch.path };
|
|
8555
8570
|
const dir = agentPath(ctx, row.id, ch.path);
|
|
8556
|
-
const src =
|
|
8571
|
+
const src = path6.join(ctx.pkgDir, bareSkillDir());
|
|
8557
8572
|
return { kind: "dir", dir, prefixes: skillDirPrefixes(ch.path), files: COMMAND_SKILLS.map((name) => ({
|
|
8558
8573
|
name,
|
|
8559
|
-
src:
|
|
8560
|
-
file:
|
|
8574
|
+
src: path6.join(src, name, SKILL_FILE),
|
|
8575
|
+
file: path6.join(dir, name, SKILL_FILE)
|
|
8561
8576
|
})) };
|
|
8562
8577
|
}
|
|
8563
8578
|
function buildRegistry(ctx) {
|
|
@@ -8565,7 +8580,7 @@ function buildRegistry(ctx) {
|
|
|
8565
8580
|
const id = row.id;
|
|
8566
8581
|
const config = configFor(ctx, id);
|
|
8567
8582
|
const hookFiles = hookFilesFor(ctx, id);
|
|
8568
|
-
const runCommand2 = [SETUP_NODE,
|
|
8583
|
+
const runCommand2 = [SETUP_NODE, path6.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
8569
8584
|
const bareNode = (id === "codex" || id === "qwen") && (ctx.platform ?? process.platform) === "win32";
|
|
8570
8585
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
8571
8586
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
@@ -8591,7 +8606,7 @@ function buildRegistry(ctx) {
|
|
|
8591
8606
|
hookInstall,
|
|
8592
8607
|
skillInstall,
|
|
8593
8608
|
hookRunCommand: runCommand2,
|
|
8594
|
-
allowedWrites: [...new Set(writes.map((f2) =>
|
|
8609
|
+
allowedWrites: [...new Set(writes.map((f2) => path6.resolve(f2)))],
|
|
8595
8610
|
goldenPayload: golden(row, ctx.home)
|
|
8596
8611
|
};
|
|
8597
8612
|
if (copilotSettings) out2.copilotSettings = copilotSettings;
|
|
@@ -8604,15 +8619,15 @@ function buildRegistry(ctx) {
|
|
|
8604
8619
|
});
|
|
8605
8620
|
}
|
|
8606
8621
|
function assertWritable(row, file) {
|
|
8607
|
-
const abs =
|
|
8608
|
-
if (INSTRUCTION_FILES.includes(
|
|
8622
|
+
const abs = path6.resolve(file);
|
|
8623
|
+
if (INSTRUCTION_FILES.includes(path6.basename(abs)) || !row.allowedWrites.includes(abs)) {
|
|
8609
8624
|
throw new Error(`setup: write to ${abs} is not allowed for ${row.id}`);
|
|
8610
8625
|
}
|
|
8611
8626
|
}
|
|
8612
8627
|
|
|
8613
8628
|
// src/setup/gemini-gate.ts
|
|
8614
8629
|
import { existsSync as existsSync12, readFileSync as readFileSync8 } from "node:fs";
|
|
8615
|
-
import
|
|
8630
|
+
import path7 from "node:path";
|
|
8616
8631
|
var GEMINI_DIR = ".gemini";
|
|
8617
8632
|
var SETTINGS_FILE2 = "settings.json";
|
|
8618
8633
|
var SYSTEM_PATH_ENV = "GEMINI_CLI_SYSTEM_SETTINGS_PATH";
|
|
@@ -8628,7 +8643,7 @@ function systemSettingsPath(env) {
|
|
|
8628
8643
|
}
|
|
8629
8644
|
function systemDefaultsPath(env) {
|
|
8630
8645
|
const set2 = env[SYSTEM_DEFAULTS_ENV];
|
|
8631
|
-
return set2 ? set2 :
|
|
8646
|
+
return set2 ? set2 : path7.join(path7.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8632
8647
|
}
|
|
8633
8648
|
function load2(file) {
|
|
8634
8649
|
if (!existsSync12(file)) return void 0;
|
|
@@ -8639,7 +8654,7 @@ function load2(file) {
|
|
|
8639
8654
|
}
|
|
8640
8655
|
}
|
|
8641
8656
|
function sources(env, home, cwd) {
|
|
8642
|
-
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);
|
|
8643
8658
|
}
|
|
8644
8659
|
function ownHookEntry(entry2) {
|
|
8645
8660
|
return typeof entry2 === "string" && entry2.includes(HOOK_BUNDLE) && entry2.includes(`${AGENT_FLAG} ${OWN_AGENT}`);
|
|
@@ -8666,7 +8681,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8666
8681
|
|
|
8667
8682
|
// src/setup/zcode-gate.ts
|
|
8668
8683
|
import { existsSync as existsSync13, readFileSync as readFileSync9 } from "node:fs";
|
|
8669
|
-
import
|
|
8684
|
+
import path8 from "node:path";
|
|
8670
8685
|
var OWN_AGENT2 = "zcode";
|
|
8671
8686
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
8672
8687
|
var HOOK_TYPES = ["process", "command"];
|
|
@@ -8756,7 +8771,7 @@ function zcodeSchemaBad(doc) {
|
|
|
8756
8771
|
);
|
|
8757
8772
|
}
|
|
8758
8773
|
function zcodeConfigGate(home) {
|
|
8759
|
-
const file =
|
|
8774
|
+
const file = path8.join(home, ".zcode", "cli", "config.json");
|
|
8760
8775
|
if (!existsSync13(file)) return void 0;
|
|
8761
8776
|
let doc;
|
|
8762
8777
|
try {
|
|
@@ -8771,7 +8786,7 @@ function zcodeConfigGate(home) {
|
|
|
8771
8786
|
|
|
8772
8787
|
// src/setup/vscode-gate.ts
|
|
8773
8788
|
import { existsSync as existsSync14, readFileSync as readFileSync10 } from "node:fs";
|
|
8774
|
-
import
|
|
8789
|
+
import path9 from "node:path";
|
|
8775
8790
|
var SETTINGS_FILE3 = "settings.json";
|
|
8776
8791
|
var WORKSPACE_DIR = ".vscode";
|
|
8777
8792
|
var USE_HOOKS_KEY = "chat.useHooks";
|
|
@@ -8788,7 +8803,7 @@ function load3(file) {
|
|
|
8788
8803
|
}
|
|
8789
8804
|
function managedSettingsPath(env) {
|
|
8790
8805
|
if (process.platform === "darwin") return "/Library/Application Support/GitHubCopilot/managed-settings.json";
|
|
8791
|
-
if (process.platform === "win32") return
|
|
8806
|
+
if (process.platform === "win32") return path9.join(env.ProgramFiles || "C:\\Program Files", "GitHubCopilot", "managed-settings.json");
|
|
8792
8807
|
return "/etc/github-copilot/managed-settings.json";
|
|
8793
8808
|
}
|
|
8794
8809
|
function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(env)) {
|
|
@@ -8800,7 +8815,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8800
8815
|
}
|
|
8801
8816
|
}
|
|
8802
8817
|
}
|
|
8803
|
-
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);
|
|
8804
8819
|
let hooks;
|
|
8805
8820
|
let locations;
|
|
8806
8821
|
for (const s of srcs) {
|
|
@@ -8822,7 +8837,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8822
8837
|
|
|
8823
8838
|
// src/setup/qwen-gate.ts
|
|
8824
8839
|
import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
8825
|
-
import
|
|
8840
|
+
import path10 from "node:path";
|
|
8826
8841
|
var KEY = "disableAllHooks";
|
|
8827
8842
|
var SETTINGS = "settings.json";
|
|
8828
8843
|
var SYSTEM_ENV = "QWEN_CODE_SYSTEM_SETTINGS_PATH";
|
|
@@ -8832,8 +8847,8 @@ var WIN_SYSTEM = "C:\\ProgramData\\qwen-code\\settings.json";
|
|
|
8832
8847
|
var LINUX_SYSTEM = "/etc/qwen-code/settings.json";
|
|
8833
8848
|
function settingsFiles(env, home, cwd, platform) {
|
|
8834
8849
|
const sys = env[SYSTEM_ENV] || (platform === "darwin" ? DARWIN_SYSTEM : platform === "win32" ? WIN_SYSTEM : LINUX_SYSTEM);
|
|
8835
|
-
const userDir = env[HOME_ENV] ||
|
|
8836
|
-
return [sys,
|
|
8850
|
+
const userDir = env[HOME_ENV] || path10.join(home, ".qwen");
|
|
8851
|
+
return [sys, path10.join(userDir, SETTINGS), path10.join(cwd, ".qwen", SETTINGS)];
|
|
8837
8852
|
}
|
|
8838
8853
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8839
8854
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
@@ -8852,13 +8867,13 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8852
8867
|
// src/setup/codex-trust.ts
|
|
8853
8868
|
import { createHash } from "node:crypto";
|
|
8854
8869
|
import { existsSync as existsSync16, realpathSync as realpathSync7 } from "node:fs";
|
|
8855
|
-
import
|
|
8856
|
-
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";
|
|
8857
8872
|
|
|
8858
8873
|
// src/setup/spawn-bin.ts
|
|
8859
8874
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
8860
|
-
import { accessSync, constants as fsc, statSync } from "node:fs";
|
|
8861
|
-
import
|
|
8875
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync2 } from "node:fs";
|
|
8876
|
+
import path11 from "node:path";
|
|
8862
8877
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
8863
8878
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
8864
8879
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
@@ -8869,13 +8884,13 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
8869
8884
|
const get = (k) => envGet(env, k);
|
|
8870
8885
|
const win = platform === "win32";
|
|
8871
8886
|
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
8872
|
-
const names = win &&
|
|
8887
|
+
const names = win && path11.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
8873
8888
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8874
8889
|
for (const n3 of names) {
|
|
8875
|
-
const f2 =
|
|
8890
|
+
const f2 = path11.join(dir, n3);
|
|
8876
8891
|
try {
|
|
8877
|
-
|
|
8878
|
-
if (
|
|
8892
|
+
accessSync2(f2, fsc.X_OK);
|
|
8893
|
+
if (statSync2(f2).isFile()) return f2;
|
|
8879
8894
|
} catch {
|
|
8880
8895
|
}
|
|
8881
8896
|
}
|
|
@@ -8913,7 +8928,7 @@ function winCmdLine(file, args, env = {}) {
|
|
|
8913
8928
|
return `"${[file, ...args].map(q).join(" ")}"`;
|
|
8914
8929
|
}
|
|
8915
8930
|
function spawnForm(file, args, env, platform = process.platform) {
|
|
8916
|
-
if (platform === "win32" && WIN_SHIM_EXTS.includes(
|
|
8931
|
+
if (platform === "win32" && WIN_SHIM_EXTS.includes(path11.extname(file).toLowerCase())) {
|
|
8917
8932
|
return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file, args, env)], windowsVerbatimArguments: true };
|
|
8918
8933
|
}
|
|
8919
8934
|
return { command: file, args, windowsVerbatimArguments: false };
|
|
@@ -8950,13 +8965,13 @@ function snake(name) {
|
|
|
8950
8965
|
return out2;
|
|
8951
8966
|
}
|
|
8952
8967
|
function realFile(file) {
|
|
8953
|
-
let dir =
|
|
8968
|
+
let dir = path12.resolve(file);
|
|
8954
8969
|
const rest = [];
|
|
8955
|
-
while (!existsSync16(dir) &&
|
|
8956
|
-
rest.unshift(
|
|
8957
|
-
dir =
|
|
8970
|
+
while (!existsSync16(dir) && path12.dirname(dir) !== dir) {
|
|
8971
|
+
rest.unshift(path12.basename(dir));
|
|
8972
|
+
dir = path12.dirname(dir);
|
|
8958
8973
|
}
|
|
8959
|
-
return
|
|
8974
|
+
return path12.join(realpathSync7(dir), ...rest);
|
|
8960
8975
|
}
|
|
8961
8976
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8962
8977
|
var ASK_TRIES = 3;
|
|
@@ -8985,10 +9000,10 @@ function askCodexHome(env) {
|
|
|
8985
9000
|
return void 0;
|
|
8986
9001
|
}
|
|
8987
9002
|
function sameDir(a2, b3, platform = process.platform) {
|
|
8988
|
-
if (platform !== "win32") return
|
|
9003
|
+
if (platform !== "win32") return path12.posix.normalize(a2) === path12.posix.normalize(b3);
|
|
8989
9004
|
const norm = (p3) => {
|
|
8990
9005
|
const bare = p3.startsWith(WIN_VERBATIM_PREFIX) ? p3.slice(WIN_VERBATIM_PREFIX.length) : p3;
|
|
8991
|
-
const n3 =
|
|
9006
|
+
const n3 = path12.win32.normalize(bare).toLowerCase();
|
|
8992
9007
|
return n3.length > 3 && n3.endsWith("\\") ? n3.slice(0, -1) : n3;
|
|
8993
9008
|
};
|
|
8994
9009
|
return norm(a2) === norm(b3);
|
|
@@ -8999,9 +9014,9 @@ function codexKeyDir(o2, platform = process.platform) {
|
|
|
8999
9014
|
function codexTrustEntries(hooksFile, doc, command, env) {
|
|
9000
9015
|
const out2 = [];
|
|
9001
9016
|
if (!isObj3(doc) || !isObj3(doc.hooks)) return out2;
|
|
9002
|
-
const abs =
|
|
9003
|
-
const dir = codexKeyDir({ dir:
|
|
9004
|
-
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));
|
|
9005
9020
|
for (const [event, groups] of Object.entries(doc.hooks)) {
|
|
9006
9021
|
if (!Array.isArray(groups)) continue;
|
|
9007
9022
|
groups.forEach((g2, gi) => {
|
|
@@ -9054,7 +9069,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
9054
9069
|
resolve6({ kind: "silent" });
|
|
9055
9070
|
return;
|
|
9056
9071
|
}
|
|
9057
|
-
const child =
|
|
9072
|
+
const child = spawn3(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
9058
9073
|
let buf = "";
|
|
9059
9074
|
let done = false;
|
|
9060
9075
|
let exited = false;
|
|
@@ -9156,16 +9171,16 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
9156
9171
|
}
|
|
9157
9172
|
|
|
9158
9173
|
// src/setup/copilot-hooks.ts
|
|
9159
|
-
import { spawn as
|
|
9174
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
9160
9175
|
import { realpathSync as realpathSync8 } from "node:fs";
|
|
9161
|
-
import
|
|
9176
|
+
import path13 from "node:path";
|
|
9162
9177
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9163
9178
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
9164
9179
|
var HEADER_END = "\r\n\r\n";
|
|
9165
9180
|
var LENGTH_HEADER = "content-length";
|
|
9166
9181
|
var USER_ORIGIN = "user";
|
|
9167
9182
|
function canon(p3) {
|
|
9168
|
-
let r2 =
|
|
9183
|
+
let r2 = path13.resolve(p3);
|
|
9169
9184
|
try {
|
|
9170
9185
|
r2 = realpathSync8(r2);
|
|
9171
9186
|
} catch {
|
|
@@ -9176,10 +9191,10 @@ function copilotHooksFromReply(m3, file) {
|
|
|
9176
9191
|
const out2 = [];
|
|
9177
9192
|
if (!isObj4(m3) || !isObj4(m3.result) || !Array.isArray(m3.result.hooks)) return out2;
|
|
9178
9193
|
const want = canon(file);
|
|
9179
|
-
const base =
|
|
9194
|
+
const base = path13.dirname(path13.dirname(path13.resolve(file)));
|
|
9180
9195
|
for (const h2 of m3.result.hooks) {
|
|
9181
9196
|
if (!isObj4(h2) || h2.origin !== USER_ORIGIN || typeof h2.source !== "string" || typeof h2.hookType !== "string" || typeof h2.enabled !== "boolean") continue;
|
|
9182
|
-
if (canon(
|
|
9197
|
+
if (canon(path13.isAbsolute(h2.source) ? h2.source : path13.join(base, h2.source)) !== want) continue;
|
|
9183
9198
|
out2.push({ event: h2.hookType, source: h2.source, enabled: h2.enabled, ...typeof h2.disableKey === "string" ? { disableKey: h2.disableKey } : {} });
|
|
9184
9199
|
}
|
|
9185
9200
|
return out2;
|
|
@@ -9208,7 +9223,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
9208
9223
|
resolve6(void 0);
|
|
9209
9224
|
return;
|
|
9210
9225
|
}
|
|
9211
|
-
const child =
|
|
9226
|
+
const child = spawn4(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
9212
9227
|
let buf = Buffer.alloc(0);
|
|
9213
9228
|
let done = false;
|
|
9214
9229
|
const finish2 = (v) => {
|
|
@@ -9251,10 +9266,10 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
9251
9266
|
}
|
|
9252
9267
|
|
|
9253
9268
|
// src/setup/engine.ts
|
|
9254
|
-
import { spawn as
|
|
9255
|
-
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";
|
|
9256
9271
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
9257
|
-
import
|
|
9272
|
+
import path14 from "node:path";
|
|
9258
9273
|
|
|
9259
9274
|
// src/setup/hook-sample.ts
|
|
9260
9275
|
var SAMPLE_FILE = "big.log";
|
|
@@ -9348,8 +9363,8 @@ function isNativeBinary(file) {
|
|
|
9348
9363
|
return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
|
|
9349
9364
|
}
|
|
9350
9365
|
function owningPackage(dir) {
|
|
9351
|
-
for (let d = dir; ; d =
|
|
9352
|
-
const f2 =
|
|
9366
|
+
for (let d = dir; ; d = path14.dirname(d)) {
|
|
9367
|
+
const f2 = path14.join(d, "package.json");
|
|
9353
9368
|
if (existsSync17(f2)) {
|
|
9354
9369
|
try {
|
|
9355
9370
|
return String(JSON.parse(hostText(readFileSync12(f2, "utf8"))).name);
|
|
@@ -9357,7 +9372,7 @@ function owningPackage(dir) {
|
|
|
9357
9372
|
return void 0;
|
|
9358
9373
|
}
|
|
9359
9374
|
}
|
|
9360
|
-
if (
|
|
9375
|
+
if (path14.dirname(d) === d) return void 0;
|
|
9361
9376
|
}
|
|
9362
9377
|
}
|
|
9363
9378
|
function hostBin(bin, env, platform = process.platform) {
|
|
@@ -9367,10 +9382,10 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
9367
9382
|
const shims = [];
|
|
9368
9383
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
9369
9384
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
9370
|
-
for (const f2 of [own2, ...real2.extra.map((p3) =>
|
|
9371
|
-
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;
|
|
9372
9387
|
const file = realpathSync9(f2);
|
|
9373
|
-
if (isNativeBinary(file) || owningPackage(
|
|
9388
|
+
if (isNativeBinary(file) || owningPackage(path14.dirname(file)) === real2.pkg) return { file: f2, shims };
|
|
9374
9389
|
shims.push(f2);
|
|
9375
9390
|
}
|
|
9376
9391
|
}
|
|
@@ -9530,8 +9545,8 @@ function isNativeSpec(e) {
|
|
|
9530
9545
|
return isNativeOpencodeEntry(e, OPENCODE_PLUGIN_KEY);
|
|
9531
9546
|
}
|
|
9532
9547
|
function isStaleOwnPlugin(e, entry2) {
|
|
9533
|
-
if (typeof e !== "string" || e === entry2 || !
|
|
9534
|
-
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;
|
|
9535
9550
|
if (existsSync17(e)) return false;
|
|
9536
9551
|
const seg = e.split("\\").join("/").split("/");
|
|
9537
9552
|
const n3 = seg.length;
|
|
@@ -9549,8 +9564,8 @@ function nativePluginsKey(doc, file) {
|
|
|
9549
9564
|
return Array.isArray(v) && v.some((e) => isNativeOpencodeEntry(e, k));
|
|
9550
9565
|
});
|
|
9551
9566
|
if (native(doc)) return true;
|
|
9552
|
-
if (opencodeDirPlugin([
|
|
9553
|
-
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) => {
|
|
9554
9569
|
const text2 = readOr(f2);
|
|
9555
9570
|
if (text2 === void 0 || text2.trim() === "") return false;
|
|
9556
9571
|
try {
|
|
@@ -9740,10 +9755,10 @@ var SETTINGS_FILES = ["settings.json", "settings.local.json"];
|
|
|
9740
9755
|
function disabledBySettings(row) {
|
|
9741
9756
|
const c3 = row.copy;
|
|
9742
9757
|
if (!c3) return void 0;
|
|
9743
|
-
const dirs = [
|
|
9758
|
+
const dirs = [path14.dirname(path14.dirname(c3.file)), path14.join(process.cwd(), ".claude")];
|
|
9744
9759
|
for (const dir of dirs) {
|
|
9745
9760
|
for (const name of SETTINGS_FILES) {
|
|
9746
|
-
const file =
|
|
9761
|
+
const file = path14.join(dir, name);
|
|
9747
9762
|
const text2 = readOr(file);
|
|
9748
9763
|
if (text2 === void 0) continue;
|
|
9749
9764
|
let doc;
|
|
@@ -9767,7 +9782,7 @@ function hookEnabledCheck(row, status) {
|
|
|
9767
9782
|
}
|
|
9768
9783
|
function packageVersion(pkgDir) {
|
|
9769
9784
|
try {
|
|
9770
|
-
const v = JSON.parse(hostText(readFileSync12(
|
|
9785
|
+
const v = JSON.parse(hostText(readFileSync12(path14.join(pkgDir, "package.json"), "utf8"))).version;
|
|
9771
9786
|
return typeof v === "string" ? v : void 0;
|
|
9772
9787
|
} catch {
|
|
9773
9788
|
return void 0;
|
|
@@ -9815,7 +9830,7 @@ function degradedDetail(node, env) {
|
|
|
9815
9830
|
}
|
|
9816
9831
|
function mcpCheck(cmd, env) {
|
|
9817
9832
|
return new Promise((resolve6) => {
|
|
9818
|
-
const child =
|
|
9833
|
+
const child = spawn5(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
9819
9834
|
const reap = () => {
|
|
9820
9835
|
child.kill();
|
|
9821
9836
|
};
|
|
@@ -9956,14 +9971,14 @@ function hookRegisteredCheck(row, env, list2) {
|
|
|
9956
9971
|
return { name: "hook-registered", ok: false, detail: issue ?? `${h2.file} lacks the context-mode hook entry${oc2 ? "; run: opencode plugin add context-mode" : ""}` };
|
|
9957
9972
|
}
|
|
9958
9973
|
function hookRunsCheck(row, env) {
|
|
9959
|
-
const root = mkdtempSync(
|
|
9974
|
+
const root = mkdtempSync(path14.join(tmpdir2(), "cm-doctor-runs-"));
|
|
9960
9975
|
try {
|
|
9961
|
-
const home =
|
|
9962
|
-
const proj =
|
|
9976
|
+
const home = path14.join(root, "home");
|
|
9977
|
+
const proj = path14.join(root, "proj");
|
|
9963
9978
|
mkdirSync5(home);
|
|
9964
9979
|
mkdirSync5(proj);
|
|
9965
9980
|
const text2 = sampleText();
|
|
9966
|
-
writeFileSync3(
|
|
9981
|
+
writeFileSync3(path14.join(proj, SAMPLE_FILE), text2);
|
|
9967
9982
|
const { effect, payload } = hookSample(row.id, proj, text2);
|
|
9968
9983
|
const sampleEnv = { ...env, HOME: home, USERPROFILE: home };
|
|
9969
9984
|
delete sampleEnv.CLAUDE_PROJECT_DIR;
|
|
@@ -9978,7 +9993,7 @@ function hookRunsCheck(row, env) {
|
|
|
9978
9993
|
var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
9979
9994
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9980
9995
|
function hookSeenCheck(row, dataRoot) {
|
|
9981
|
-
const base =
|
|
9996
|
+
const base = path14.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9982
9997
|
const dirs = existsSync17(base) ? readdirSync6(base) : [];
|
|
9983
9998
|
let sqlite;
|
|
9984
9999
|
try {
|
|
@@ -9987,7 +10002,7 @@ function hookSeenCheck(row, dataRoot) {
|
|
|
9987
10002
|
sqlite = void 0;
|
|
9988
10003
|
}
|
|
9989
10004
|
for (const d of dirs) {
|
|
9990
|
-
const file =
|
|
10005
|
+
const file = path14.join(base, d, DB_FILE_NAME);
|
|
9991
10006
|
if (!sqlite || !existsSync17(file)) continue;
|
|
9992
10007
|
let db;
|
|
9993
10008
|
try {
|
|
@@ -10004,7 +10019,7 @@ var SKILL_TOOL_STEM = "ctx_";
|
|
|
10004
10019
|
function skillsCheck(row, pkgDir) {
|
|
10005
10020
|
const s = row.skillInstall;
|
|
10006
10021
|
if (s.kind === "package") {
|
|
10007
|
-
const files = COMMAND_SKILLS.map((n3) =>
|
|
10022
|
+
const files = COMMAND_SKILLS.map((n3) => path14.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
10008
10023
|
const miss = files.filter((f2) => !existsSync17(f2));
|
|
10009
10024
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
10010
10025
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
@@ -10145,7 +10160,7 @@ async function nativeResult(row, ctx, apply2) {
|
|
|
10145
10160
|
return res;
|
|
10146
10161
|
}
|
|
10147
10162
|
function trustPluginHooks(row, ctx, apply2, hooks) {
|
|
10148
|
-
const file =
|
|
10163
|
+
const file = path14.join(codexDirOf(ctx.env, ctx.home), CODEX_CONFIG_FILE2);
|
|
10149
10164
|
const text2 = readOr(file);
|
|
10150
10165
|
let edit;
|
|
10151
10166
|
try {
|
|
@@ -10266,16 +10281,16 @@ var Run = class {
|
|
|
10266
10281
|
this.runId = runId;
|
|
10267
10282
|
}
|
|
10268
10283
|
get dir() {
|
|
10269
|
-
return
|
|
10284
|
+
return path14.join(this.root, BACKUP_DIR, this.runId);
|
|
10270
10285
|
}
|
|
10271
10286
|
save() {
|
|
10272
|
-
if (this.manifest) atomicWrite(
|
|
10287
|
+
if (this.manifest) atomicWrite(path14.join(this.dir, MANIFEST), JSON.stringify(this.manifest, null, 2));
|
|
10273
10288
|
}
|
|
10274
10289
|
record(e, bytes) {
|
|
10275
10290
|
if (!this.manifest) this.manifest = { runId: this.runId, path: this.dir, entries: [] };
|
|
10276
10291
|
if (bytes !== void 0) {
|
|
10277
|
-
const rel =
|
|
10278
|
-
atomicWrite(
|
|
10292
|
+
const rel = path14.join(FILES, String(this.manifest.entries.length));
|
|
10293
|
+
atomicWrite(path14.join(this.dir, rel), bytes);
|
|
10279
10294
|
e.backup = rel;
|
|
10280
10295
|
}
|
|
10281
10296
|
this.manifest.entries.push(e);
|
|
@@ -10295,12 +10310,12 @@ function undo(dir, entries, env) {
|
|
|
10295
10310
|
continue;
|
|
10296
10311
|
}
|
|
10297
10312
|
if (!e.file) continue;
|
|
10298
|
-
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"));
|
|
10299
10314
|
else unlinkWithRetry(e.file);
|
|
10300
10315
|
}
|
|
10301
10316
|
}
|
|
10302
10317
|
function takeLock(root, runId) {
|
|
10303
|
-
const file =
|
|
10318
|
+
const file = path14.join(root, LOCK_FILE);
|
|
10304
10319
|
mkdirSync5(root, { recursive: true });
|
|
10305
10320
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
10306
10321
|
try {
|
|
@@ -10325,7 +10340,7 @@ function agentHomeDir(id, ctx) {
|
|
|
10325
10340
|
if (id === "kiro") return kiroDirOf(ctx.env, ctx.home);
|
|
10326
10341
|
if (id === "opencode") return opencodeDirOf(ctx.env, ctx.home);
|
|
10327
10342
|
if (id === "gemini") return geminiDirOf(ctx.env, ctx.home);
|
|
10328
|
-
return
|
|
10343
|
+
return path14.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
10329
10344
|
}
|
|
10330
10345
|
function detectAgents(reg, ctx) {
|
|
10331
10346
|
return reg.filter((r2) => existsSync17(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
@@ -10337,7 +10352,7 @@ async function runSetup(opts) {
|
|
|
10337
10352
|
const nodeVersion = opts.nodeVersion ?? process.version;
|
|
10338
10353
|
if (nodeTooOld(nodeVersion)) return { exitCode: 1, agents: [], error: formatError("NODE_TOO_OLD", { v: nodeVersion }) };
|
|
10339
10354
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10340
|
-
if (!existsSync17(
|
|
10355
|
+
if (!existsSync17(path14.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path14.join(ctx.pkgDir, f2)} is missing` };
|
|
10341
10356
|
}
|
|
10342
10357
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10343
10358
|
const root = dataRootOf(ctx.env, ctx.home);
|
|
@@ -10350,7 +10365,7 @@ async function runSetup(opts) {
|
|
|
10350
10365
|
let current;
|
|
10351
10366
|
const onAbort = () => {
|
|
10352
10367
|
if (current !== void 0 && !opts.dryRun) run.rollback(current, ctx.env);
|
|
10353
|
-
if (!opts.dryRun) rmSync2(
|
|
10368
|
+
if (!opts.dryRun) rmSync2(path14.join(root, LOCK_FILE), { force: true });
|
|
10354
10369
|
};
|
|
10355
10370
|
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
10356
10371
|
try {
|
|
@@ -10369,7 +10384,7 @@ async function runSetup(opts) {
|
|
|
10369
10384
|
}
|
|
10370
10385
|
} finally {
|
|
10371
10386
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
10372
|
-
if (!opts.dryRun) rmSync2(
|
|
10387
|
+
if (!opts.dryRun) rmSync2(path14.join(root, LOCK_FILE), { force: true });
|
|
10373
10388
|
}
|
|
10374
10389
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents, backupDir: run.manifest ? run.dir : void 0 };
|
|
10375
10390
|
}
|
|
@@ -10444,7 +10459,7 @@ async function runDoctor(opts) {
|
|
|
10444
10459
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env, cwd: opts.cwd };
|
|
10445
10460
|
const reg = buildRegistry(ctx);
|
|
10446
10461
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10447
|
-
if (!existsSync17(
|
|
10462
|
+
if (!existsSync17(path14.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path14.join(ctx.pkgDir, f2)} is missing` };
|
|
10448
10463
|
}
|
|
10449
10464
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10450
10465
|
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
@@ -10490,7 +10505,7 @@ function notSetUpReason(row, res, env) {
|
|
|
10490
10505
|
const h2 = row.hookInstall;
|
|
10491
10506
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
10492
10507
|
const oc2 = missing && hostBin("opencode", env).file !== void 0 && opencodeMajor("opencode", env) >= 2;
|
|
10493
|
-
const dead = missing ? opencodeDirPlugins(opencodePluginDirs(
|
|
10508
|
+
const dead = missing ? opencodeDirPlugins(opencodePluginDirs(path14.dirname(h2.file), h2.worktree)).find((p3) => !p3.loads) : void 0;
|
|
10494
10509
|
const hint = dead ? `; ${dead.file} loads context-mode once ${OPENCODE_PACKAGE_DIR_HINT} is next to it or above it` : "";
|
|
10495
10510
|
if (oc2) return `${NOT_SET_UP_REASON}, or run: opencode plugin add context-mode${hint}`;
|
|
10496
10511
|
if (hint) return NOT_SET_UP_REASON + hint;
|
|
@@ -10523,21 +10538,21 @@ function isTrust(row, c3) {
|
|
|
10523
10538
|
function runRemove(opts) {
|
|
10524
10539
|
const env = opts.env ?? process.env;
|
|
10525
10540
|
const root = dataRootOf(env, opts.home);
|
|
10526
|
-
const base =
|
|
10541
|
+
const base = path14.join(root, BACKUP_DIR);
|
|
10527
10542
|
if (!existsSync17(base)) return { exitCode: 0, restored: 0 };
|
|
10528
10543
|
const held = takeLock(root, "remove");
|
|
10529
10544
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
10530
10545
|
let restored = 0;
|
|
10531
10546
|
try {
|
|
10532
|
-
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();
|
|
10533
10548
|
for (const dir of runs) {
|
|
10534
|
-
const m3 = JSON.parse(readFileSync12(
|
|
10549
|
+
const m3 = JSON.parse(readFileSync12(path14.join(dir, MANIFEST), "utf8"));
|
|
10535
10550
|
undo(dir, m3.entries, env);
|
|
10536
10551
|
restored += m3.entries.length;
|
|
10537
|
-
renameWithRetry(
|
|
10552
|
+
renameWithRetry(path14.join(dir, MANIFEST), path14.join(dir, MANIFEST_DONE));
|
|
10538
10553
|
}
|
|
10539
10554
|
} finally {
|
|
10540
|
-
rmSync2(
|
|
10555
|
+
rmSync2(path14.join(root, LOCK_FILE), { force: true });
|
|
10541
10556
|
}
|
|
10542
10557
|
return { exitCode: 0, restored };
|
|
10543
10558
|
}
|
|
@@ -10742,9 +10757,9 @@ async function report(ui, command, res, write) {
|
|
|
10742
10757
|
const { text: text2, title } = buildIssueReport(command, res, ui);
|
|
10743
10758
|
let file = "";
|
|
10744
10759
|
if (write) {
|
|
10745
|
-
const dir =
|
|
10760
|
+
const dir = path15.join(dataRootOf(ui.ctx.env, ui.ctx.home), REPORT_DIR);
|
|
10746
10761
|
mkdirSync6(dir, { recursive: true });
|
|
10747
|
-
file =
|
|
10762
|
+
file = path15.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
10748
10763
|
writeFileSync4(file, text2);
|
|
10749
10764
|
}
|
|
10750
10765
|
const gh = `gh issue create --repo ${ISSUE_REPO} --title ${JSON.stringify(title)} --label bug --body-file ${JSON.stringify(file || "<report>")}`;
|
|
@@ -10853,7 +10868,7 @@ async function remove(ui) {
|
|
|
10853
10868
|
}
|
|
10854
10869
|
}
|
|
10855
10870
|
if (ui.f.dryRun) {
|
|
10856
|
-
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")}`);
|
|
10857
10872
|
return EXIT_OK;
|
|
10858
10873
|
}
|
|
10859
10874
|
const r2 = runRemove({ home: ui.ctx.home, env: ui.ctx.env });
|
|
@@ -10998,7 +11013,7 @@ async function upgrade(ui) {
|
|
|
10998
11013
|
return EXIT_FAIL;
|
|
10999
11014
|
}
|
|
11000
11015
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
11001
|
-
const cli =
|
|
11016
|
+
const cli = path15.join(root, "context-mode", "cli.mjs");
|
|
11002
11017
|
if (!root || !existsSync18(cli)) {
|
|
11003
11018
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
11004
11019
|
return EXIT_FAIL;
|
|
@@ -11094,10 +11109,10 @@ function route(argv, version) {
|
|
|
11094
11109
|
` };
|
|
11095
11110
|
}
|
|
11096
11111
|
function main() {
|
|
11097
|
-
const dir =
|
|
11112
|
+
const dir = path16.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
11098
11113
|
let version = "";
|
|
11099
11114
|
try {
|
|
11100
|
-
version = String(JSON.parse(readFileSync14(
|
|
11115
|
+
version = String(JSON.parse(readFileSync14(path16.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
11101
11116
|
} catch (err2) {
|
|
11102
11117
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
11103
11118
|
`);
|
|
@@ -11121,7 +11136,7 @@ function main() {
|
|
|
11121
11136
|
process.exitCode = r2.code;
|
|
11122
11137
|
return;
|
|
11123
11138
|
}
|
|
11124
|
-
const child =
|
|
11139
|
+
const child = spawn6(process.execPath, [path16.join(dir, r2.file), ...r2.args], { stdio: "inherit", windowsHide: true });
|
|
11125
11140
|
process.on("SIGINT", () => {
|
|
11126
11141
|
});
|
|
11127
11142
|
child.on("error", (err2) => {
|