context-mode 2.1.4 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.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 +277 -163
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +2670 -517
- package/package.json +1 -1
- package/pi/index.js +2813 -739
- package/qwen-extension.json +1 -1
- package/run.mjs +300 -97
- package/search.mjs +300 -97
- package/server.mjs +2261 -268
package/cli.mjs
CHANGED
|
@@ -88,7 +88,7 @@ var require_src = __commonJS({
|
|
|
88
88
|
|
|
89
89
|
// src/entries/cli.ts
|
|
90
90
|
import { spawn as spawn4 } from "node:child_process";
|
|
91
|
-
import { readFileSync as
|
|
91
|
+
import { readFileSync as readFileSync13, realpathSync as realpathSync11 } from "node:fs";
|
|
92
92
|
import path14 from "node:path";
|
|
93
93
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
94
94
|
|
|
@@ -96,6 +96,14 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
96
96
|
var SERVER_KEY = "context-mode";
|
|
97
97
|
var TOOL_ORDER = Object.freeze(["ctx_execute", "ctx_batch", "ctx_index", "ctx_search", "ctx_resume", "ctx_stats", "ctx_doctor", "ctx_upgrade", "ctx_purge"]);
|
|
98
98
|
var OUTPUT_CAP = 16384;
|
|
99
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
100
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
101
|
+
function readReplaceTrigger(raw) {
|
|
102
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
103
|
+
const n3 = Number(raw);
|
|
104
|
+
return Number.isSafeInteger(n3) && n3 > 0 ? n3 : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
105
|
+
}
|
|
106
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
99
107
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
100
108
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
101
109
|
var WEIGHT = Object.freeze({ toolerr: 900, decision: 700, prompt: 500, edit: 400, index: 200 });
|
|
@@ -255,6 +263,7 @@ function readHintEvery(raw) {
|
|
|
255
263
|
return Number.isSafeInteger(n3) && n3 > 0 ? n3 : MCP_HINT_EVERY_DEFAULT;
|
|
256
264
|
}
|
|
257
265
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
266
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
258
267
|
var DENY_WHAT = Object.freeze({
|
|
259
268
|
curl: "This curl/wget call",
|
|
260
269
|
http: "This inline HTTP call",
|
|
@@ -297,6 +306,30 @@ var DUMP_COUNT_COMMANDS = Object.freeze(["head", "tail"]);
|
|
|
297
306
|
var DUMP_COUNT_FLAGS = Object.freeze(["-n", "-c", "--lines", "--bytes"]);
|
|
298
307
|
var SED_QUIET_FLAGS = Object.freeze(["-n", "--quiet", "--silent"]);
|
|
299
308
|
var READ_PATH_KEYS = Object.freeze(["file_path", "absolute_path", "path", "filePath"]);
|
|
309
|
+
var READ_MEDIA_TYPES = Object.freeze({
|
|
310
|
+
png: { exts: [".png"], sig: [{ at: 0, bytes: [137, 80, 78, 71, 13, 10, 26, 10] }] },
|
|
311
|
+
jpeg: { exts: [".jpg", ".jpeg"], sig: [{ at: 0, bytes: [255, 216, 255] }] },
|
|
312
|
+
gif: { exts: [".gif"], sig: [{ at: 0, bytes: [71, 73, 70, 56] }] },
|
|
313
|
+
// "GIF8"
|
|
314
|
+
webp: { exts: [".webp"], sig: [{ at: 0, bytes: [82, 73, 70, 70] }, { at: 8, bytes: [87, 69, 66, 80] }] },
|
|
315
|
+
// "RIFF" .... "WEBP"
|
|
316
|
+
pdf: { exts: [".pdf"], sig: [{ at: 0, bytes: [37, 80, 68, 70, 45] }] }
|
|
317
|
+
// "%PDF-"
|
|
318
|
+
});
|
|
319
|
+
var READ_IMAGES = Object.freeze(["png", "jpeg", "gif", "webp"]);
|
|
320
|
+
var READ_IMAGES_AND_PDF = Object.freeze([...READ_IMAGES, "pdf"]);
|
|
321
|
+
var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
322
|
+
"claude-code": READ_IMAGES_AND_PDF,
|
|
323
|
+
gemini: READ_IMAGES_AND_PDF,
|
|
324
|
+
qwen: READ_IMAGES_AND_PDF,
|
|
325
|
+
opencode: READ_IMAGES_AND_PDF,
|
|
326
|
+
pi: READ_IMAGES,
|
|
327
|
+
vscode: READ_IMAGES,
|
|
328
|
+
zcode: READ_IMAGES,
|
|
329
|
+
"copilot-cli": [],
|
|
330
|
+
codex: [],
|
|
331
|
+
kiro: []
|
|
332
|
+
});
|
|
300
333
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
301
334
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
302
335
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
@@ -349,7 +382,12 @@ var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JS
|
|
|
349
382
|
var GIT_LS_REMOTE_TAG_ARGS = Object.freeze(["--tags", "--refs"]);
|
|
350
383
|
var RELEASE_TAG_PATTERN = "v*";
|
|
351
384
|
var D1_GIT_CHECK_FIX = `git ls-remote --tags --refs ${RELEASE_REPO_URL} "${RELEASE_TAG_PATTERN}"`;
|
|
352
|
-
var D2_NODE_FIX = `install
|
|
385
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
386
|
+
function D2_NODE_DETAIL(version) {
|
|
387
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version}`;
|
|
388
|
+
}
|
|
389
|
+
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
390
|
+
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
353
391
|
var D3_PARTS = Object.freeze(["MCP entry", "hook entries", "hook timeout"]);
|
|
354
392
|
var AGENT_HOME_DIR = Object.freeze({
|
|
355
393
|
"claude-code": [".claude"],
|
|
@@ -456,6 +494,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
456
494
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
457
495
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
458
496
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
497
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
498
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
459
499
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
460
500
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
461
501
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -540,6 +580,8 @@ var ATOMIC_TMP_MARK = ".cm-tmp-";
|
|
|
540
580
|
var JSON_INDENT_UNIT = " ";
|
|
541
581
|
var MCP_COMMAND_FIELD = "command";
|
|
542
582
|
var MCP_ARGS_FIELD = "args";
|
|
583
|
+
var MCP_ENV_FIELD = "env";
|
|
584
|
+
var MCP_ENV_VARS_FIELD = "env_vars";
|
|
543
585
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
544
586
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
545
587
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -823,10 +865,17 @@ function encode(ev, d, _extra) {
|
|
|
823
865
|
// src/adapters/codex.ts
|
|
824
866
|
var TOOL_NAME_PREFIX2 = "mcp__context_mode__";
|
|
825
867
|
var CODEX_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact", fork: "resume" };
|
|
868
|
+
var STOP_EVENT = "Stop";
|
|
869
|
+
var EMPTY = { stdout: "", exitCode: 0 };
|
|
826
870
|
function decode2(raw) {
|
|
871
|
+
if (typeof raw === "object" && raw !== null && !Array.isArray(raw) && raw.hook_event_name === STOP_EVENT) {
|
|
872
|
+
const p3 = raw;
|
|
873
|
+
return { event: STOP_EVENT, agent: "codex", sessionId: String(p3.session_id ?? ""), cwd: String(p3.cwd ?? "") };
|
|
874
|
+
}
|
|
827
875
|
return decodeClaudeShape(raw, "codex", TOOL_NAME_PREFIX2, CODEX_SOURCES);
|
|
828
876
|
}
|
|
829
877
|
function encode2(ev, d, _extra) {
|
|
878
|
+
if (ev.event === STOP_EVENT) return EMPTY;
|
|
830
879
|
return encodeClaudeShape(ev, d, false);
|
|
831
880
|
}
|
|
832
881
|
|
|
@@ -842,7 +891,7 @@ var GEMINI_EVENTS = {
|
|
|
842
891
|
var GEMINI_SOURCES = { startup: "startup", resume: "resume", clear: "clear" };
|
|
843
892
|
var HINT_EVENTS = ["SessionStart", "UserPromptSubmit", "PostToolUse"];
|
|
844
893
|
var DENY_EVENTS = ["UserPromptSubmit", "PreToolUse"];
|
|
845
|
-
var
|
|
894
|
+
var EMPTY2 = { stdout: "", exitCode: 0 };
|
|
846
895
|
var GEMINI_REPLACE_LEAD = "the tool ran and succeeded; context-mode indexed its full output, and this is the part that answers the call:\n";
|
|
847
896
|
function own(p3, key) {
|
|
848
897
|
return Object.hasOwn(p3, key) ? p3[key] : void 0;
|
|
@@ -883,7 +932,13 @@ function readResult2(resp) {
|
|
|
883
932
|
const llm = obj === void 0 ? void 0 : own(obj, "llmContent");
|
|
884
933
|
const text2 = resp === void 0 ? "" : typeof resp === "string" ? resp : typeof llm === "string" ? llm : partsText(llm) ?? JSON.stringify(resp);
|
|
885
934
|
const err2 = obj === void 0 ? void 0 : own(obj, "error");
|
|
886
|
-
|
|
935
|
+
const info = { isError: err2 !== void 0 && err2 !== null, bytes: Buffer.byteLength(text2), text: text2 };
|
|
936
|
+
if (hasMediaPart(llm)) info.keep = true;
|
|
937
|
+
return info;
|
|
938
|
+
}
|
|
939
|
+
function hasMediaPart(llm) {
|
|
940
|
+
const parts = Array.isArray(llm) ? llm : [llm];
|
|
941
|
+
return parts.some((p3) => typeof p3 === "object" && p3 !== null && (Object.hasOwn(p3, "inlineData") || Object.hasOwn(p3, "fileData")));
|
|
887
942
|
}
|
|
888
943
|
var URL_STARTS = ["https://", "http://"];
|
|
889
944
|
var URL_TRAIL = `.,;:!?)]}>'"`;
|
|
@@ -950,15 +1005,15 @@ function decode3(raw) {
|
|
|
950
1005
|
function encode3(ev, d, _extra) {
|
|
951
1006
|
switch (d.kind) {
|
|
952
1007
|
case "allow":
|
|
953
|
-
return
|
|
1008
|
+
return EMPTY2;
|
|
954
1009
|
case "hint":
|
|
955
|
-
if (!HINT_EVENTS.includes(ev.event)) return
|
|
1010
|
+
if (!HINT_EVENTS.includes(ev.event)) return EMPTY2;
|
|
956
1011
|
return { stdout: JSON.stringify({ hookSpecificOutput: { additionalContext: d.text } }), exitCode: 0 };
|
|
957
1012
|
case "deny":
|
|
958
|
-
if (!DENY_EVENTS.includes(ev.event)) return
|
|
1013
|
+
if (!DENY_EVENTS.includes(ev.event)) return EMPTY2;
|
|
959
1014
|
return { stdout: JSON.stringify({ decision: "deny", reason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }), exitCode: 0 };
|
|
960
1015
|
case "replace":
|
|
961
|
-
if (ev.event !== "PostToolUse") return
|
|
1016
|
+
if (ev.event !== "PostToolUse") return EMPTY2;
|
|
962
1017
|
return { stdout: JSON.stringify({ decision: "deny", reason: GEMINI_REPLACE_LEAD + d.output }), exitCode: 0 };
|
|
963
1018
|
}
|
|
964
1019
|
}
|
|
@@ -1078,21 +1133,21 @@ function decode5(raw) {
|
|
|
1078
1133
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
1079
1134
|
return ev;
|
|
1080
1135
|
}
|
|
1081
|
-
var
|
|
1136
|
+
var EMPTY3 = { stdout: "", exitCode: 0 };
|
|
1082
1137
|
function encode5(ev, d, _extra) {
|
|
1083
1138
|
switch (d.kind) {
|
|
1084
1139
|
case "allow":
|
|
1085
|
-
return
|
|
1140
|
+
return EMPTY3;
|
|
1086
1141
|
case "hint":
|
|
1087
|
-
return ev.event === "PostToolUse" ?
|
|
1142
|
+
return ev.event === "PostToolUse" ? EMPTY3 : { stdout: JSON.stringify({ additionalContext: d.text }), exitCode: 0 };
|
|
1088
1143
|
case "deny":
|
|
1089
|
-
if (ev.event !== "PreToolUse") return
|
|
1144
|
+
if (ev.event !== "PreToolUse") return EMPTY3;
|
|
1090
1145
|
return {
|
|
1091
1146
|
stdout: JSON.stringify({ permissionDecision: "deny", permissionDecisionReason: d.rewritten === void 0 ? d.reason : d.rewritten + "\n" + d.reason }),
|
|
1092
1147
|
exitCode: 0
|
|
1093
1148
|
};
|
|
1094
1149
|
case "replace":
|
|
1095
|
-
if (ev.event !== "PostToolUse") return
|
|
1150
|
+
if (ev.event !== "PostToolUse") return EMPTY3;
|
|
1096
1151
|
return { stdout: JSON.stringify({ modifiedResult: { resultType: RESULT_SUCCESS, textResultForLlm: d.output } }), exitCode: 0 };
|
|
1097
1152
|
}
|
|
1098
1153
|
}
|
|
@@ -1847,7 +1902,7 @@ Examples:
|
|
|
1847
1902
|
// src/cli/commands.ts
|
|
1848
1903
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1849
1904
|
import { createHash as createHash2 } from "node:crypto";
|
|
1850
|
-
import { existsSync as
|
|
1905
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1851
1906
|
import os from "node:os";
|
|
1852
1907
|
import path13 from "node:path";
|
|
1853
1908
|
|
|
@@ -4671,7 +4726,8 @@ import { basename, dirname as dirname2, join as join2, posix, resolve, win32 } f
|
|
|
4671
4726
|
|
|
4672
4727
|
// src/core/contracts/errors.ts
|
|
4673
4728
|
var ERROR_TEXT = Object.freeze({
|
|
4674
|
-
NODE_TOO_OLD: "
|
|
4729
|
+
NODE_TOO_OLD: "Context Mode needs Node 24.15.0 or newer; you have <v>. Fix: nvm install 24, or install it from https://nodejs.org.",
|
|
4730
|
+
// #1328 D-NODE-OLD-1
|
|
4675
4731
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
4676
4732
|
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
4677
4733
|
// D-ORPHAN-WAL-1
|
|
@@ -4741,7 +4797,7 @@ var CtxError = class extends Error {
|
|
|
4741
4797
|
};
|
|
4742
4798
|
|
|
4743
4799
|
// src/core/project/config-dir.ts
|
|
4744
|
-
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
4800
|
+
var { existsSync: existsSync2, mkdirSync, readFileSync, readdirSync: readdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
|
|
4745
4801
|
function homeDirOf(env, platform = process.platform) {
|
|
4746
4802
|
const set2 = (v) => v !== void 0 && v !== "";
|
|
4747
4803
|
if (platform === "win32") {
|
|
@@ -4824,12 +4880,53 @@ function dataRootOf(env, home) {
|
|
|
4824
4880
|
|
|
4825
4881
|
// src/core/ops/doctor-issue.ts
|
|
4826
4882
|
import { spawnSync } from "node:child_process";
|
|
4827
|
-
import { closeSync, existsSync as
|
|
4828
|
-
import { delimiter, join as
|
|
4883
|
+
import { closeSync as closeSync2, existsSync as existsSync10, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync6, readSync as readSync2, realpathSync as realpathSync5, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4884
|
+
import { delimiter, join as join11 } from "node:path";
|
|
4885
|
+
|
|
4886
|
+
// src/core/hooks/fallback.ts
|
|
4887
|
+
import { join as join5, resolve as resolve2 } from "node:path";
|
|
4888
|
+
|
|
4889
|
+
// src/core/policy/read-media.ts
|
|
4890
|
+
import { extname } from "node:path";
|
|
4891
|
+
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
4892
|
+
|
|
4893
|
+
// src/core/policy/own-file.ts
|
|
4894
|
+
import { extname as extname2, join as join4 } from "node:path";
|
|
4895
|
+
|
|
4896
|
+
// src/core/project/contain.ts
|
|
4897
|
+
import { dirname as dirname3, join as join3, relative, sep } from "node:path";
|
|
4898
|
+
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4899
|
+
function components(p3) {
|
|
4900
|
+
return p3.split(sep).filter((c3) => c3 !== "");
|
|
4901
|
+
}
|
|
4902
|
+
function reachedThroughLink(root, p3) {
|
|
4903
|
+
const rel = relative(root, p3);
|
|
4904
|
+
const steps = components(rel);
|
|
4905
|
+
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
4906
|
+
let at = root;
|
|
4907
|
+
for (const step of steps) {
|
|
4908
|
+
at = join3(at, step);
|
|
4909
|
+
try {
|
|
4910
|
+
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
4911
|
+
} catch {
|
|
4912
|
+
return false;
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4915
|
+
return false;
|
|
4916
|
+
}
|
|
4829
4917
|
|
|
4830
4918
|
// src/core/hooks/fallback.ts
|
|
4831
|
-
import { join as join3, resolve as resolve2 } from "node:path";
|
|
4832
4919
|
var fs = process.getBuiltinModule("node:fs");
|
|
4920
|
+
function nodeTooOld(version) {
|
|
4921
|
+
const a2 = (version.startsWith("v") ? version.slice(1) : version).split(".");
|
|
4922
|
+
const b3 = NODE_MIN.split(".");
|
|
4923
|
+
for (let i2 = 0; i2 < b3.length; i2++) {
|
|
4924
|
+
const x2 = Number(a2[i2] ?? 0) || 0;
|
|
4925
|
+
const y2 = Number(b3[i2]);
|
|
4926
|
+
if (x2 !== y2) return x2 < y2;
|
|
4927
|
+
}
|
|
4928
|
+
return false;
|
|
4929
|
+
}
|
|
4833
4930
|
|
|
4834
4931
|
// src/core/store/schema.ts
|
|
4835
4932
|
var PRAGMAS = `
|
|
@@ -4918,20 +5015,20 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4918
5015
|
`;
|
|
4919
5016
|
|
|
4920
5017
|
// src/core/store/db.ts
|
|
4921
|
-
var { existsSync:
|
|
5018
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4922
5019
|
|
|
4923
5020
|
// src/core/ops/doctor-config.ts
|
|
4924
|
-
import { existsSync as
|
|
4925
|
-
import { join as
|
|
5021
|
+
import { existsSync as existsSync9, readdirSync as readdirSync5 } from "node:fs";
|
|
5022
|
+
import { join as join10 } from "node:path";
|
|
4926
5023
|
|
|
4927
5024
|
// src/core/ops/detect-v1.ts
|
|
4928
|
-
import { existsSync as
|
|
5025
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
4929
5026
|
import { tmpdir } from "node:os";
|
|
4930
|
-
import { join as
|
|
5027
|
+
import { join as join8 } from "node:path";
|
|
4931
5028
|
|
|
4932
5029
|
// src/core/ops/host-config.ts
|
|
4933
|
-
import { existsSync as
|
|
4934
|
-
import { dirname as
|
|
5030
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
5031
|
+
import { dirname as dirname5, join as join7 } from "node:path";
|
|
4935
5032
|
|
|
4936
5033
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4937
5034
|
var KEYS2 = {
|
|
@@ -7040,8 +7137,8 @@ function atomicWriteFile(file, text2, opts = {}) {
|
|
|
7040
7137
|
}
|
|
7041
7138
|
|
|
7042
7139
|
// src/core/ops/bundle-dir.ts
|
|
7043
|
-
import { existsSync as
|
|
7044
|
-
import { dirname as
|
|
7140
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
7141
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
7045
7142
|
import { fileURLToPath } from "node:url";
|
|
7046
7143
|
|
|
7047
7144
|
// src/core/ops/host-text.ts
|
|
@@ -7437,28 +7534,6 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7437
7534
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7438
7535
|
}
|
|
7439
7536
|
|
|
7440
|
-
// src/core/project/contain.ts
|
|
7441
|
-
import { dirname as dirname5, join as join6, relative, sep } from "node:path";
|
|
7442
|
-
var { lstatSync: lstatSync2, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
7443
|
-
function components(p3) {
|
|
7444
|
-
return p3.split(sep).filter((c3) => c3 !== "");
|
|
7445
|
-
}
|
|
7446
|
-
function reachedThroughLink(root, p3) {
|
|
7447
|
-
const rel = relative(root, p3);
|
|
7448
|
-
const steps = components(rel);
|
|
7449
|
-
if (rel === "" || steps[0] === ".." || rel === p3) return false;
|
|
7450
|
-
let at = root;
|
|
7451
|
-
for (const step of steps) {
|
|
7452
|
-
at = join6(at, step);
|
|
7453
|
-
try {
|
|
7454
|
-
if (lstatSync2(at).isSymbolicLink()) return true;
|
|
7455
|
-
} catch {
|
|
7456
|
-
return false;
|
|
7457
|
-
}
|
|
7458
|
-
}
|
|
7459
|
-
return false;
|
|
7460
|
-
}
|
|
7461
|
-
|
|
7462
7537
|
// src/core/ops/detect-v1.ts
|
|
7463
7538
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7464
7539
|
var keyPath = (...parts) => parts.join(".");
|
|
@@ -7502,14 +7577,14 @@ function stripJsonc(text2) {
|
|
|
7502
7577
|
}
|
|
7503
7578
|
function readJson(file) {
|
|
7504
7579
|
try {
|
|
7505
|
-
return JSON.parse(stripJsonc(hostText(
|
|
7580
|
+
return JSON.parse(stripJsonc(hostText(readFileSync3(file, "utf8"))));
|
|
7506
7581
|
} catch {
|
|
7507
7582
|
return void 0;
|
|
7508
7583
|
}
|
|
7509
7584
|
}
|
|
7510
7585
|
function readText(file) {
|
|
7511
7586
|
try {
|
|
7512
|
-
return hostText(
|
|
7587
|
+
return hostText(readFileSync3(file, "utf8"));
|
|
7513
7588
|
} catch {
|
|
7514
7589
|
return "";
|
|
7515
7590
|
}
|
|
@@ -7566,7 +7641,7 @@ function flatCommands(events2, prefix) {
|
|
|
7566
7641
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7567
7642
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
7568
7643
|
function dataDir(dir, reason, out2) {
|
|
7569
|
-
if (
|
|
7644
|
+
if (existsSync6(dir)) out2.push(finding(dir, "", reason));
|
|
7570
7645
|
}
|
|
7571
7646
|
function mcpEntry(file, doc, out2) {
|
|
7572
7647
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7574,7 +7649,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7574
7649
|
}
|
|
7575
7650
|
}
|
|
7576
7651
|
function claudeShapeSettings(agentHome, out2) {
|
|
7577
|
-
const file =
|
|
7652
|
+
const file = join8(agentHome, SETTINGS_FILE);
|
|
7578
7653
|
const doc = readJson(file);
|
|
7579
7654
|
for (const c3 of nestedCommands(doc)) {
|
|
7580
7655
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7594,63 +7669,64 @@ function v1HookFile(file, out2) {
|
|
|
7594
7669
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7595
7670
|
claudeShapeSettings(agentHome, out2);
|
|
7596
7671
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7597
|
-
const file =
|
|
7598
|
-
if (
|
|
7672
|
+
const file = join8(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7673
|
+
if (existsSync6(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7599
7674
|
}
|
|
7600
|
-
const userFile =
|
|
7675
|
+
const userFile = join8(home, CLAUDE_USER_CONFIG_FILE);
|
|
7601
7676
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7602
|
-
dataDir(
|
|
7677
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7603
7678
|
}
|
|
7604
7679
|
function scanCodex(agentHome, out2) {
|
|
7605
|
-
const hooksFile =
|
|
7680
|
+
const hooksFile = join8(agentHome, HOOKS_JSON_FILE);
|
|
7606
7681
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7607
7682
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7608
7683
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7609
7684
|
}
|
|
7610
7685
|
}
|
|
7611
|
-
const tomlFile =
|
|
7686
|
+
const tomlFile = join8(agentHome, CONFIG_TOML_FILE);
|
|
7612
7687
|
const config = readTomlValue(tomlFile);
|
|
7613
7688
|
for (const span of readTomlTables(tomlFile)) {
|
|
7614
7689
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7615
7690
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7691
|
+
if (span.path.length === 3 && span.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config, span.path.slice(0, 2)))) continue;
|
|
7616
7692
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7617
7693
|
}
|
|
7618
|
-
dataDir(
|
|
7694
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7619
7695
|
}
|
|
7620
7696
|
function scanGemini(agentHome, out2) {
|
|
7621
|
-
const file =
|
|
7697
|
+
const file = join8(agentHome, SETTINGS_FILE);
|
|
7622
7698
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7623
7699
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7624
7700
|
}
|
|
7625
|
-
dataDir(
|
|
7701
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7626
7702
|
}
|
|
7627
7703
|
function scanVscode(agentHome, project, out2) {
|
|
7628
7704
|
if (project !== void 0) {
|
|
7629
|
-
v1HookFile(
|
|
7630
|
-
const mcpFile =
|
|
7705
|
+
v1HookFile(join8(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7706
|
+
const mcpFile = join8(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7631
7707
|
const doc = readJson(mcpFile);
|
|
7632
7708
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7633
7709
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7634
7710
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7635
7711
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7636
7712
|
}
|
|
7637
|
-
const sessions =
|
|
7713
|
+
const sessions = join8(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
7638
7714
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out2);
|
|
7639
7715
|
}
|
|
7640
|
-
dataDir(
|
|
7716
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7641
7717
|
}
|
|
7642
7718
|
function jsonFiles(dir) {
|
|
7643
7719
|
try {
|
|
7644
|
-
return
|
|
7720
|
+
return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
7645
7721
|
} catch {
|
|
7646
7722
|
return [];
|
|
7647
7723
|
}
|
|
7648
7724
|
}
|
|
7649
7725
|
function scanKiro(agentHome, project, out2) {
|
|
7650
|
-
const agentsDir =
|
|
7651
|
-
const defaultFile =
|
|
7726
|
+
const agentsDir = join8(agentHome, KIRO_AGENTS_DIR);
|
|
7727
|
+
const defaultFile = join8(agentHome, ...KIRO_AGENT_FILE);
|
|
7652
7728
|
for (const name of jsonFiles(agentsDir)) {
|
|
7653
|
-
const file =
|
|
7729
|
+
const file = join8(agentsDir, name);
|
|
7654
7730
|
const doc = readJson(file);
|
|
7655
7731
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7656
7732
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7661,31 +7737,31 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7661
7737
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7662
7738
|
}
|
|
7663
7739
|
}
|
|
7664
|
-
const steeringDocs = [
|
|
7665
|
-
if (project !== void 0) steeringDocs.push(
|
|
7740
|
+
const steeringDocs = [join8(agentHome, ...KIRO_STEERING_FILE)];
|
|
7741
|
+
if (project !== void 0) steeringDocs.push(join8(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7666
7742
|
for (const file of steeringDocs) {
|
|
7667
|
-
if (
|
|
7743
|
+
if (existsSync6(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7668
7744
|
}
|
|
7669
|
-
dataDir(
|
|
7745
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7670
7746
|
}
|
|
7671
7747
|
function piNpmIsCurrent(piAgentDir) {
|
|
7672
|
-
const doc = readJson(
|
|
7748
|
+
const doc = readJson(join8(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
7673
7749
|
const version = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
7674
7750
|
return Number.parseInt(version, 10) >= PI_CURRENT_MAJOR;
|
|
7675
7751
|
}
|
|
7676
7752
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7677
|
-
const file =
|
|
7753
|
+
const file = join8(piAgentDir, SETTINGS_FILE);
|
|
7678
7754
|
const doc = readJson(file);
|
|
7679
7755
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7680
7756
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7681
7757
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7682
7758
|
if (spec === PI_GIT_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piGit));
|
|
7683
7759
|
});
|
|
7684
|
-
dataDir(
|
|
7760
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7685
7761
|
}
|
|
7686
7762
|
function scanOpencode(agentHome, out2) {
|
|
7687
7763
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7688
|
-
const file =
|
|
7764
|
+
const file = join8(agentHome, name);
|
|
7689
7765
|
const doc = readJson(file);
|
|
7690
7766
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7691
7767
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7696,13 +7772,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7696
7772
|
}
|
|
7697
7773
|
}
|
|
7698
7774
|
function scanZcode(agentHome, out2) {
|
|
7699
|
-
const configFile =
|
|
7775
|
+
const configFile = join8(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7700
7776
|
const config = readJson(configFile);
|
|
7701
7777
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7702
7778
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7703
7779
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7704
7780
|
}
|
|
7705
|
-
const hooksFile =
|
|
7781
|
+
const hooksFile = join8(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7706
7782
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7707
7783
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7708
7784
|
}
|
|
@@ -7726,14 +7802,14 @@ function firstTmpMatch(dir) {
|
|
|
7726
7802
|
}
|
|
7727
7803
|
}
|
|
7728
7804
|
function scanAll(home, tmp, out2) {
|
|
7729
|
-
const root =
|
|
7730
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7805
|
+
const root = join8(home, DATA_ROOT.slice(1));
|
|
7806
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join8(root, name), V1_REASON.dataRoot, out2);
|
|
7731
7807
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7732
7808
|
}
|
|
7733
7809
|
function detectV1(agent, home, scope = {}) {
|
|
7734
7810
|
const out2 = [];
|
|
7735
7811
|
const project = scope.project;
|
|
7736
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
7812
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join8(home, ...AGENT_HOME_DIR[agent]);
|
|
7737
7813
|
switch (agent) {
|
|
7738
7814
|
case "claude-code":
|
|
7739
7815
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7746,11 +7822,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7746
7822
|
break;
|
|
7747
7823
|
case "qwen":
|
|
7748
7824
|
claudeShapeSettings(agentHome, out2);
|
|
7749
|
-
dataDir(
|
|
7825
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7750
7826
|
break;
|
|
7751
7827
|
case "copilot-cli":
|
|
7752
|
-
v1HookFile(
|
|
7753
|
-
dataDir(
|
|
7828
|
+
v1HookFile(join8(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7829
|
+
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7754
7830
|
break;
|
|
7755
7831
|
case "vscode":
|
|
7756
7832
|
scanVscode(agentHome, project, out2);
|
|
@@ -7759,7 +7835,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7759
7835
|
scanKiro(agentHome, project, out2);
|
|
7760
7836
|
break;
|
|
7761
7837
|
case "pi":
|
|
7762
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7838
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join8(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7763
7839
|
break;
|
|
7764
7840
|
// D-WIN-PIDIR-1: empty is unset
|
|
7765
7841
|
case "opencode":
|
|
@@ -7774,12 +7850,12 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7774
7850
|
}
|
|
7775
7851
|
|
|
7776
7852
|
// src/core/ops/plugin-root.ts
|
|
7777
|
-
import { existsSync as
|
|
7778
|
-
import { dirname as dirname6, isAbsolute, join as
|
|
7853
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
7854
|
+
import { dirname as dirname6, isAbsolute, join as join9, sep as sep2 } from "node:path";
|
|
7779
7855
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
7780
7856
|
|
|
7781
7857
|
// src/setup/pi-gate.ts
|
|
7782
|
-
import { existsSync as
|
|
7858
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync4 } from "node:fs";
|
|
7783
7859
|
import path3 from "node:path";
|
|
7784
7860
|
var OWN_FILE = "pi/index.js";
|
|
7785
7861
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7788,9 +7864,9 @@ var TRUST_FILE = "trust.json";
|
|
|
7788
7864
|
var ALWAYS = "always";
|
|
7789
7865
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7790
7866
|
function load(file) {
|
|
7791
|
-
if (!
|
|
7867
|
+
if (!existsSync8(file)) return void 0;
|
|
7792
7868
|
try {
|
|
7793
|
-
return { file, doc: parseHostConfig("pi", file, hostText(
|
|
7869
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync5(file, "utf8")), "json") };
|
|
7794
7870
|
} catch {
|
|
7795
7871
|
return void 0;
|
|
7796
7872
|
}
|
|
@@ -7898,7 +7974,7 @@ function formUrl(title, summary) {
|
|
|
7898
7974
|
}
|
|
7899
7975
|
|
|
7900
7976
|
// src/setup/registry.ts
|
|
7901
|
-
import { existsSync as
|
|
7977
|
+
import { existsSync as existsSync11, realpathSync as realpathSync6 } from "node:fs";
|
|
7902
7978
|
import path4 from "node:path";
|
|
7903
7979
|
|
|
7904
7980
|
// src/setup/hook-shapes.ts
|
|
@@ -7958,7 +8034,7 @@ var SERVER_BUNDLE = "server.mjs";
|
|
|
7958
8034
|
var HOOK_BUNDLE = "hook.mjs";
|
|
7959
8035
|
var AGENT_FLAG = "--agent";
|
|
7960
8036
|
var LOCK_FILE = "setup.lock";
|
|
7961
|
-
var BACKUP_DIR =
|
|
8037
|
+
var BACKUP_DIR = SETUP_BACKUP_DIR_NAME;
|
|
7962
8038
|
var PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
7963
8039
|
var SKILLS_DIR_NAME = "skills";
|
|
7964
8040
|
var INSTRUCTION_FILES = Object.freeze([
|
|
@@ -8018,7 +8094,7 @@ function extensionPlugin(bin, id) {
|
|
|
8018
8094
|
};
|
|
8019
8095
|
}
|
|
8020
8096
|
var NATIVE_PLUGIN = {
|
|
8021
|
-
codex: { bin: "codex", args: ["plugin", "list"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "
|
|
8097
|
+
codex: { bin: "codex", args: ["plugin", "list", "--json"], plugin: PLUGIN_ID, hooksVia: ".codex-plugin", skillsVia: path4.join("codex", SKILLS_DIR_NAME), format: "codex-json", hookTrust: true },
|
|
8022
8098
|
qwen: extensionPlugin("qwen", "qwen"),
|
|
8023
8099
|
gemini: extensionPlugin("gemini", "gemini"),
|
|
8024
8100
|
// D-R44-ZCODE-NATIVE-1 (host audit zcode-1/2): `zcode plugins install context-mode@context-mode` lists as JSON; ZCode loads
|
|
@@ -8035,7 +8111,7 @@ var NATIVE_PLUGIN = {
|
|
|
8035
8111
|
};
|
|
8036
8112
|
var CELLAR_SEGMENT = "/Cellar/";
|
|
8037
8113
|
var NODE_BIN = ["bin", "node"];
|
|
8038
|
-
var REAL_FS = { exists:
|
|
8114
|
+
var REAL_FS = { exists: existsSync11, real: (p3) => realpathSync6.native(p3) };
|
|
8039
8115
|
function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
8040
8116
|
const at = execPath.indexOf(CELLAR_SEGMENT);
|
|
8041
8117
|
if (at < 0) return execPath;
|
|
@@ -8075,7 +8151,10 @@ function configFor(ctx, id) {
|
|
|
8075
8151
|
const file = id === "vscode" ? ownMcpFileOf(id, own2.file, ctx.env, ctx.home) : agentPath(ctx, id, own2.file);
|
|
8076
8152
|
const format = file.endsWith(".toml") ? "toml" : id === "vscode" ? "jsonc" : "json";
|
|
8077
8153
|
const also = own2.also?.map(([k, v]) => [k, v]);
|
|
8078
|
-
|
|
8154
|
+
const codexHome = id === "codex" ? ctx.env[CODEX_HOME_ENV2] : void 0;
|
|
8155
|
+
const base = ownMcpValue(id, node, server);
|
|
8156
|
+
const value = codexHome !== void 0 && codexHome !== "" ? { ...base, [MCP_ENV_FIELD]: { [CODEX_HOME_ENV2]: codexHome } } : base;
|
|
8157
|
+
return { file, format, key: own2.key, value, ...also ? { also } : {} };
|
|
8079
8158
|
}
|
|
8080
8159
|
if (id === "opencode") {
|
|
8081
8160
|
return {
|
|
@@ -8225,7 +8304,7 @@ function assertWritable(row, file) {
|
|
|
8225
8304
|
}
|
|
8226
8305
|
|
|
8227
8306
|
// src/setup/gemini-gate.ts
|
|
8228
|
-
import { existsSync as
|
|
8307
|
+
import { existsSync as existsSync12, readFileSync as readFileSync7 } from "node:fs";
|
|
8229
8308
|
import path5 from "node:path";
|
|
8230
8309
|
var GEMINI_DIR = ".gemini";
|
|
8231
8310
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -8245,9 +8324,9 @@ function systemDefaultsPath(env) {
|
|
|
8245
8324
|
return set2 ? set2 : path5.join(path5.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8246
8325
|
}
|
|
8247
8326
|
function load2(file) {
|
|
8248
|
-
if (!
|
|
8327
|
+
if (!existsSync12(file)) return void 0;
|
|
8249
8328
|
try {
|
|
8250
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8329
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync7(file, "utf8")), "jsonc") };
|
|
8251
8330
|
} catch {
|
|
8252
8331
|
return void 0;
|
|
8253
8332
|
}
|
|
@@ -8279,7 +8358,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8279
8358
|
}
|
|
8280
8359
|
|
|
8281
8360
|
// src/setup/zcode-gate.ts
|
|
8282
|
-
import { existsSync as
|
|
8361
|
+
import { existsSync as existsSync13, readFileSync as readFileSync8 } from "node:fs";
|
|
8283
8362
|
import path6 from "node:path";
|
|
8284
8363
|
var OWN_AGENT2 = "zcode";
|
|
8285
8364
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8371,10 +8450,10 @@ function zcodeSchemaBad(doc) {
|
|
|
8371
8450
|
}
|
|
8372
8451
|
function zcodeConfigGate(home) {
|
|
8373
8452
|
const file = path6.join(home, ".zcode", "cli", "config.json");
|
|
8374
|
-
if (!
|
|
8453
|
+
if (!existsSync13(file)) return void 0;
|
|
8375
8454
|
let doc;
|
|
8376
8455
|
try {
|
|
8377
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8456
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync8(file, "utf8")), "json");
|
|
8378
8457
|
} catch {
|
|
8379
8458
|
return void 0;
|
|
8380
8459
|
}
|
|
@@ -8384,7 +8463,7 @@ function zcodeConfigGate(home) {
|
|
|
8384
8463
|
}
|
|
8385
8464
|
|
|
8386
8465
|
// src/setup/vscode-gate.ts
|
|
8387
|
-
import { existsSync as
|
|
8466
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
8388
8467
|
import path7 from "node:path";
|
|
8389
8468
|
var SETTINGS_FILE3 = "settings.json";
|
|
8390
8469
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8393,9 +8472,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8393
8472
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8394
8473
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8395
8474
|
function load3(file) {
|
|
8396
|
-
if (!
|
|
8475
|
+
if (!existsSync14(file)) return void 0;
|
|
8397
8476
|
try {
|
|
8398
|
-
return { file, doc: parseHostConfig("vscode", file, hostText(
|
|
8477
|
+
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync9(file, "utf8")), "jsonc") };
|
|
8399
8478
|
} catch {
|
|
8400
8479
|
return void 0;
|
|
8401
8480
|
}
|
|
@@ -8435,7 +8514,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8435
8514
|
}
|
|
8436
8515
|
|
|
8437
8516
|
// src/setup/qwen-gate.ts
|
|
8438
|
-
import { existsSync as
|
|
8517
|
+
import { existsSync as existsSync15, readFileSync as readFileSync10 } from "node:fs";
|
|
8439
8518
|
import path8 from "node:path";
|
|
8440
8519
|
var KEY = "disableAllHooks";
|
|
8441
8520
|
var SETTINGS = "settings.json";
|
|
@@ -8451,10 +8530,10 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8451
8530
|
}
|
|
8452
8531
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8453
8532
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8454
|
-
if (!
|
|
8533
|
+
if (!existsSync15(file)) continue;
|
|
8455
8534
|
let value;
|
|
8456
8535
|
try {
|
|
8457
|
-
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(
|
|
8536
|
+
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync10(file, "utf8")), "jsonc"), [KEY]);
|
|
8458
8537
|
} catch {
|
|
8459
8538
|
continue;
|
|
8460
8539
|
}
|
|
@@ -8465,7 +8544,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8465
8544
|
|
|
8466
8545
|
// src/setup/codex-trust.ts
|
|
8467
8546
|
import { createHash } from "node:crypto";
|
|
8468
|
-
import { existsSync as
|
|
8547
|
+
import { existsSync as existsSync16, realpathSync as realpathSync7 } from "node:fs";
|
|
8469
8548
|
import path10 from "node:path";
|
|
8470
8549
|
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8471
8550
|
|
|
@@ -8574,7 +8653,7 @@ function snake(name) {
|
|
|
8574
8653
|
function realFile(file) {
|
|
8575
8654
|
let dir = path10.resolve(file);
|
|
8576
8655
|
const rest = [];
|
|
8577
|
-
while (!
|
|
8656
|
+
while (!existsSync16(dir) && path10.dirname(dir) !== dir) {
|
|
8578
8657
|
rest.unshift(path10.basename(dir));
|
|
8579
8658
|
dir = path10.dirname(dir);
|
|
8580
8659
|
}
|
|
@@ -8874,7 +8953,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8874
8953
|
|
|
8875
8954
|
// src/setup/engine.ts
|
|
8876
8955
|
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8877
|
-
import { closeSync as
|
|
8956
|
+
import { closeSync as closeSync3, existsSync as existsSync17, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync11, readSync as readSync3, readdirSync as readdirSync6, realpathSync as realpathSync9, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8878
8957
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8879
8958
|
import path12 from "node:path";
|
|
8880
8959
|
|
|
@@ -8949,7 +9028,7 @@ var HOOK_ROUNDS = 5;
|
|
|
8949
9028
|
var P95 = 0.95;
|
|
8950
9029
|
var VERIFY_TIMEOUT_MS = 1e4;
|
|
8951
9030
|
var INSTALL_TIMEOUT_MS = 12e4;
|
|
8952
|
-
var MANIFEST =
|
|
9031
|
+
var MANIFEST = SETUP_MANIFEST_FILE;
|
|
8953
9032
|
var MANIFEST_DONE = "manifest.removed.json";
|
|
8954
9033
|
var FILES = "files";
|
|
8955
9034
|
var V1_HOOK_MARK = "context-mode hook";
|
|
@@ -8960,11 +9039,11 @@ var REAL_HOST = Object.freeze({
|
|
|
8960
9039
|
var BINARY_MAGICS = Object.freeze(["cffaedfe", "cefaedfe", "7f454c46", "4d5a"]);
|
|
8961
9040
|
function isNativeBinary(file) {
|
|
8962
9041
|
const head = Buffer.alloc(4);
|
|
8963
|
-
const fd =
|
|
9042
|
+
const fd = openSync3(file, "r");
|
|
8964
9043
|
try {
|
|
8965
|
-
|
|
9044
|
+
readSync3(fd, head, 0, 4, 0);
|
|
8966
9045
|
} finally {
|
|
8967
|
-
|
|
9046
|
+
closeSync3(fd);
|
|
8968
9047
|
}
|
|
8969
9048
|
const hex = head.toString("hex");
|
|
8970
9049
|
return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
|
|
@@ -8972,9 +9051,9 @@ function isNativeBinary(file) {
|
|
|
8972
9051
|
function owningPackage(dir) {
|
|
8973
9052
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8974
9053
|
const f2 = path12.join(d, "package.json");
|
|
8975
|
-
if (
|
|
9054
|
+
if (existsSync17(f2)) {
|
|
8976
9055
|
try {
|
|
8977
|
-
return String(JSON.parse(hostText(
|
|
9056
|
+
return String(JSON.parse(hostText(readFileSync11(f2, "utf8"))).name);
|
|
8978
9057
|
} catch {
|
|
8979
9058
|
return void 0;
|
|
8980
9059
|
}
|
|
@@ -8990,7 +9069,7 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8990
9069
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8991
9070
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8992
9071
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8993
|
-
if (!f2 || !
|
|
9072
|
+
if (!f2 || !existsSync17(f2) || !statSync2(f2).isFile()) continue;
|
|
8994
9073
|
const file = realpathSync9(f2);
|
|
8995
9074
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8996
9075
|
shims.push(f2);
|
|
@@ -9004,13 +9083,13 @@ function installExitOk(status, listed, platform = process.platform) {
|
|
|
9004
9083
|
return platform === "win32" && status === WIN_EXIT_CRASH && listed;
|
|
9005
9084
|
}
|
|
9006
9085
|
function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
9007
|
-
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
|
|
9086
|
+
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout, maxBuffer: Infinity });
|
|
9008
9087
|
}
|
|
9009
9088
|
function readOr(file) {
|
|
9010
|
-
return
|
|
9089
|
+
return existsSync17(file) ? hostText(readFileSync11(file, "utf8")) : void 0;
|
|
9011
9090
|
}
|
|
9012
9091
|
function readRaw(file) {
|
|
9013
|
-
return
|
|
9092
|
+
return existsSync17(file) ? readFileSync11(file, "utf8") : void 0;
|
|
9014
9093
|
}
|
|
9015
9094
|
var atomicWrite = atomicWriteFile;
|
|
9016
9095
|
function pidAlive(pid) {
|
|
@@ -9155,7 +9234,7 @@ function isNativeSpec(e) {
|
|
|
9155
9234
|
function isStaleOwnPlugin(e, entry2) {
|
|
9156
9235
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
9157
9236
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9158
|
-
if (
|
|
9237
|
+
if (existsSync17(e)) return false;
|
|
9159
9238
|
const seg = e.split("\\").join("/").split("/");
|
|
9160
9239
|
const n3 = seg.length;
|
|
9161
9240
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -9219,8 +9298,8 @@ function planSkills(row, edits) {
|
|
|
9219
9298
|
const s = row.skillInstall;
|
|
9220
9299
|
if (s.kind !== "dir") return;
|
|
9221
9300
|
for (const f2 of s.files) {
|
|
9222
|
-
if (!
|
|
9223
|
-
const after = renderSkill(
|
|
9301
|
+
if (!existsSync17(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
9302
|
+
const after = renderSkill(readFileSync11(f2.src, "utf8"), s.prefixes);
|
|
9224
9303
|
const before = readRaw(f2.file);
|
|
9225
9304
|
if (before !== after) edits.push({ plain: true, file: f2.file, before, after, changes: [{ file: f2.file, path: f2.name, before: before === void 0 ? null : "old", after: "SKILL.md" }] });
|
|
9226
9305
|
}
|
|
@@ -9232,7 +9311,7 @@ function planRow(row, listed, stale, env, disabled = false) {
|
|
|
9232
9311
|
const before = readOr(c3.file);
|
|
9233
9312
|
let res;
|
|
9234
9313
|
try {
|
|
9235
|
-
res = editHostConfigText(row.id, c3.file, before ?? "", c3.format,
|
|
9314
|
+
res = editHostConfigText(row.id, c3.file, before ?? "", c3.format, ownConfigEdits(row, c3, before ?? ""));
|
|
9236
9315
|
} catch (e) {
|
|
9237
9316
|
if (e instanceof CtxError) throw new Error(parseFail(row, c3.file));
|
|
9238
9317
|
throw e;
|
|
@@ -9354,7 +9433,7 @@ function hookEnabledCheck(row, status) {
|
|
|
9354
9433
|
}
|
|
9355
9434
|
function packageVersion(pkgDir) {
|
|
9356
9435
|
try {
|
|
9357
|
-
const v = JSON.parse(hostText(
|
|
9436
|
+
const v = JSON.parse(hostText(readFileSync11(path12.join(pkgDir, "package.json"), "utf8"))).version;
|
|
9358
9437
|
return typeof v === "string" ? v : void 0;
|
|
9359
9438
|
} catch {
|
|
9360
9439
|
return void 0;
|
|
@@ -9379,6 +9458,12 @@ function copyCheck(row, pkgDir) {
|
|
|
9379
9458
|
if (old === void 0) return { name: "copy", ok: true };
|
|
9380
9459
|
return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${old}, the installed package is ${pkg}; run ${c3.bin} ${c3.refresh.join(" ")}` };
|
|
9381
9460
|
}
|
|
9461
|
+
function degradedDetail(node, env) {
|
|
9462
|
+
const r2 = spawnSync4(node, ["-p", "process.version"], { env, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
9463
|
+
const v = `${r2.stdout ?? ""}`.trim();
|
|
9464
|
+
if (v && nodeTooOld(v)) return `Node too old: ${D2_NODE_DETAIL(v)}. Fix: ${D2_NODE_FIX}`;
|
|
9465
|
+
return `only ctx_doctor is served: ${D2_SQLITE_DETAIL} under ${node}${v ? ` ${v}` : ""}. Fix: ${D2_SQLITE_FIX}`;
|
|
9466
|
+
}
|
|
9382
9467
|
function mcpCheck(cmd, env) {
|
|
9383
9468
|
return new Promise((resolve3) => {
|
|
9384
9469
|
const child = spawn3(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
@@ -9419,7 +9504,7 @@ function mcpCheck(cmd, env) {
|
|
|
9419
9504
|
const want = [...TOOL_ORDER].sort();
|
|
9420
9505
|
const got = [...tools].sort();
|
|
9421
9506
|
const ok = JSON.stringify(got) === JSON.stringify(want);
|
|
9422
|
-
done(ok, ok ? void 0 : `tools/list returned ${got.join(",")}, expected ${want.join(",")}`);
|
|
9507
|
+
done(ok, ok ? void 0 : got.length === 1 && got[0] === "ctx_doctor" ? degradedDetail(cmd[0], env) : `tools/list returned ${got.join(",")}, expected ${want.join(",")}`);
|
|
9423
9508
|
}
|
|
9424
9509
|
}
|
|
9425
9510
|
});
|
|
@@ -9470,11 +9555,29 @@ function hookCheck(row, env) {
|
|
|
9470
9555
|
}
|
|
9471
9556
|
return best;
|
|
9472
9557
|
}
|
|
9558
|
+
function ownConfigEdits(row, c3, text2) {
|
|
9559
|
+
const edits = configEdits(c3);
|
|
9560
|
+
if (row.id !== "codex" || !isObj5(c3.value)) return edits;
|
|
9561
|
+
let cur;
|
|
9562
|
+
try {
|
|
9563
|
+
cur = hostConfigValueAt(parseHostConfig(row.id, c3.file, text2, c3.format), c3.key);
|
|
9564
|
+
} catch {
|
|
9565
|
+
return edits;
|
|
9566
|
+
}
|
|
9567
|
+
if (!isObj5(cur)) return edits;
|
|
9568
|
+
const value = { ...c3.value };
|
|
9569
|
+
const userEnv = cur[MCP_ENV_FIELD];
|
|
9570
|
+
const ownEnv = value[MCP_ENV_FIELD];
|
|
9571
|
+
if (isObj5(userEnv) || isObj5(ownEnv)) value[MCP_ENV_FIELD] = { ...isObj5(userEnv) ? userEnv : {}, ...isObj5(ownEnv) ? ownEnv : {} };
|
|
9572
|
+
if (Array.isArray(cur[MCP_ENV_VARS_FIELD])) value[MCP_ENV_VARS_FIELD] = cur[MCP_ENV_VARS_FIELD];
|
|
9573
|
+
return [[c3.key, value], ...edits.slice(1)];
|
|
9574
|
+
}
|
|
9473
9575
|
function parseCheck(row) {
|
|
9474
9576
|
const c3 = row.config;
|
|
9475
9577
|
if (!c3) return { name: "parse", ok: true };
|
|
9476
9578
|
try {
|
|
9477
|
-
const
|
|
9579
|
+
const text2 = readOr(c3.file) ?? "";
|
|
9580
|
+
const r2 = editHostConfigText(row.id, c3.file, text2, c3.format, ownConfigEdits(row, c3, text2));
|
|
9478
9581
|
return { name: "parse", ok: r2.edits.length === 0, detail: r2.edits.length ? "entry differs after write" : void 0 };
|
|
9479
9582
|
} catch (e) {
|
|
9480
9583
|
return { name: "parse", ok: false, detail: e.message };
|
|
@@ -9525,7 +9628,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
|
9525
9628
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9526
9629
|
function hookSeenCheck(row, dataRoot) {
|
|
9527
9630
|
const base = path12.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9528
|
-
const dirs =
|
|
9631
|
+
const dirs = existsSync17(base) ? readdirSync6(base) : [];
|
|
9529
9632
|
let sqlite;
|
|
9530
9633
|
try {
|
|
9531
9634
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9534,7 +9637,7 @@ function hookSeenCheck(row, dataRoot) {
|
|
|
9534
9637
|
}
|
|
9535
9638
|
for (const d of dirs) {
|
|
9536
9639
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9537
|
-
if (!sqlite || !
|
|
9640
|
+
if (!sqlite || !existsSync17(file)) continue;
|
|
9538
9641
|
let db;
|
|
9539
9642
|
try {
|
|
9540
9643
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9551,29 +9654,34 @@ function skillsCheck(row, pkgDir) {
|
|
|
9551
9654
|
const s = row.skillInstall;
|
|
9552
9655
|
if (s.kind === "package") {
|
|
9553
9656
|
const files = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
9554
|
-
const miss = files.filter((f2) => !
|
|
9657
|
+
const miss = files.filter((f2) => !existsSync17(f2));
|
|
9555
9658
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
9556
9659
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
9557
9660
|
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
9558
9661
|
const bad2 = files.filter((f2) => {
|
|
9559
|
-
const t2 =
|
|
9662
|
+
const t2 = readFileSync11(f2, "utf8");
|
|
9560
9663
|
return !t2.includes(own2) && foreign.some((n3) => t2.includes(n3));
|
|
9561
9664
|
});
|
|
9562
9665
|
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
9563
9666
|
}
|
|
9564
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9667
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync17(f2.src) ? renderSkill(readFileSync11(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9565
9668
|
return { name: "skills", ok: bad.length === 0, detail: bad.length ? `${bad.map((f2) => f2.file).join(", ")} missing or without the ${s.prefixes.join(" / ") || "plain"} tool prefix` : void 0 };
|
|
9566
9669
|
}
|
|
9567
|
-
var PLUGIN_ENABLED = "enabled";
|
|
9568
|
-
var WORD_TRIM = ",;";
|
|
9569
9670
|
var CODEX_CONFIG_FILE2 = "config.toml";
|
|
9570
9671
|
var EXT_ENABLED_USER = "Enabled (User):";
|
|
9571
9672
|
var EXT_ENABLED_WORKSPACE = "Enabled (Workspace):";
|
|
9572
9673
|
var EXT_TRUE = "true";
|
|
9573
|
-
function
|
|
9574
|
-
|
|
9575
|
-
|
|
9576
|
-
|
|
9674
|
+
function codexJsonState(n3, text2) {
|
|
9675
|
+
let doc;
|
|
9676
|
+
try {
|
|
9677
|
+
doc = JSON.parse(text2);
|
|
9678
|
+
} catch {
|
|
9679
|
+
return void 0;
|
|
9680
|
+
}
|
|
9681
|
+
const list2 = isObj5(doc) && Array.isArray(doc.installed) ? doc.installed : [];
|
|
9682
|
+
const mine = list2.find((p3) => isObj5(p3) && p3.pluginId === n3.plugin);
|
|
9683
|
+
if (!isObj5(mine)) return void 0;
|
|
9684
|
+
return mine.enabled === true ? "enabled" : "disabled";
|
|
9577
9685
|
}
|
|
9578
9686
|
function extensionState(n3, text2) {
|
|
9579
9687
|
let mine = false;
|
|
@@ -9618,9 +9726,15 @@ function nativeState(row, env) {
|
|
|
9618
9726
|
const n3 = row.nativePlugin;
|
|
9619
9727
|
if (!n3 || !hostBin(n3.bin, env).file) return none;
|
|
9620
9728
|
const r2 = runBin(n3.bin, n3.args, env);
|
|
9729
|
+
const why = r2.error?.code ?? r2.signal;
|
|
9730
|
+
if (why && `${r2.stdout}`.includes(n3.plugin)) {
|
|
9731
|
+
const cmd = [n3.bin, ...n3.args].join(" ");
|
|
9732
|
+
return { ...none, stopped: `${cmd} stopped before it finished (${why}); it names ${n3.plugin}, run ${cmd} in a terminal` };
|
|
9733
|
+
}
|
|
9621
9734
|
if (r2.status !== 0) return none;
|
|
9622
9735
|
if (n3.format === "json") return jsonState(n3, `${r2.stdout}`);
|
|
9623
|
-
|
|
9736
|
+
if (n3.format === "codex-json") return { state: codexJsonState(n3, `${r2.stdout}`), workspaceOff: false };
|
|
9737
|
+
return extensionState(n3, `${r2.stdout}${r2.stderr}`);
|
|
9624
9738
|
}
|
|
9625
9739
|
function nativeRow(row, n3) {
|
|
9626
9740
|
return {
|
|
@@ -9634,18 +9748,12 @@ function nativeRow(row, n3) {
|
|
|
9634
9748
|
skillInstall: { kind: "package", via: n3.skillsVia }
|
|
9635
9749
|
};
|
|
9636
9750
|
}
|
|
9637
|
-
function trimChars(w, chars) {
|
|
9638
|
-
let a2 = 0;
|
|
9639
|
-
let b3 = w.length;
|
|
9640
|
-
while (a2 < b3 && chars.includes(w.charAt(a2))) a2++;
|
|
9641
|
-
while (b3 > a2 && chars.includes(w.charAt(b3 - 1))) b3--;
|
|
9642
|
-
return w.slice(a2, b3);
|
|
9643
|
-
}
|
|
9644
9751
|
async function nativeResult(row, ctx, apply2) {
|
|
9645
9752
|
const n3 = row.nativePlugin;
|
|
9646
|
-
const { state, workspaceOff, hookGate } = nativeState(row, ctx.env);
|
|
9753
|
+
const { state, workspaceOff, hookGate, stopped } = nativeState(row, ctx.env);
|
|
9754
|
+
const bin = n3 ? hostBin(n3.bin, ctx.env).file : void 0;
|
|
9755
|
+
if (stopped) return { id: row.id, status: "FAIL", v1: [], changes: [], checks: [], bin, reason: stopped };
|
|
9647
9756
|
if (!n3 || state === void 0) return void 0;
|
|
9648
|
-
const bin = hostBin(n3.bin, ctx.env).file;
|
|
9649
9757
|
if (state === "disabled") {
|
|
9650
9758
|
if (!n3.enable) return void 0;
|
|
9651
9759
|
return {
|
|
@@ -9836,7 +9944,7 @@ function undo(dir, entries, env) {
|
|
|
9836
9944
|
continue;
|
|
9837
9945
|
}
|
|
9838
9946
|
if (!e.file) continue;
|
|
9839
|
-
if (e.existed && e.backup) atomicWrite(e.file,
|
|
9947
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync11(path12.join(dir, e.backup), "utf8"));
|
|
9840
9948
|
else unlinkWithRetry(e.file);
|
|
9841
9949
|
}
|
|
9842
9950
|
}
|
|
@@ -9851,7 +9959,7 @@ function takeLock(root, runId) {
|
|
|
9851
9959
|
if (e.code !== "EEXIST") throw e;
|
|
9852
9960
|
let pid = 0;
|
|
9853
9961
|
try {
|
|
9854
|
-
pid = Number(JSON.parse(
|
|
9962
|
+
pid = Number(JSON.parse(readFileSync11(file, "utf8")).pid);
|
|
9855
9963
|
} catch {
|
|
9856
9964
|
}
|
|
9857
9965
|
if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
|
|
@@ -9869,14 +9977,16 @@ function agentHomeDir(id, ctx) {
|
|
|
9869
9977
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9870
9978
|
}
|
|
9871
9979
|
function detectAgents(reg, ctx) {
|
|
9872
|
-
return reg.filter((r2) =>
|
|
9980
|
+
return reg.filter((r2) => existsSync17(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9873
9981
|
}
|
|
9874
9982
|
async function runSetup(opts) {
|
|
9875
9983
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9876
9984
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9877
9985
|
const reg = buildRegistry(ctx);
|
|
9986
|
+
const nodeVersion = opts.nodeVersion ?? process.version;
|
|
9987
|
+
if (nodeTooOld(nodeVersion)) return { exitCode: 1, agents: [], error: formatError("NODE_TOO_OLD", { v: nodeVersion }) };
|
|
9878
9988
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9879
|
-
if (!
|
|
9989
|
+
if (!existsSync17(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9880
9990
|
}
|
|
9881
9991
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9882
9992
|
const root = dataRootOf(ctx.env, ctx.home);
|
|
@@ -9970,7 +10080,7 @@ async function runDoctor(opts) {
|
|
|
9970
10080
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9971
10081
|
const reg = buildRegistry(ctx);
|
|
9972
10082
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9973
|
-
if (!
|
|
10083
|
+
if (!existsSync17(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9974
10084
|
}
|
|
9975
10085
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9976
10086
|
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
@@ -10040,14 +10150,14 @@ function runRemove(opts) {
|
|
|
10040
10150
|
const env = opts.env ?? process.env;
|
|
10041
10151
|
const root = dataRootOf(env, opts.home);
|
|
10042
10152
|
const base = path12.join(root, BACKUP_DIR);
|
|
10043
|
-
if (!
|
|
10153
|
+
if (!existsSync17(base)) return { exitCode: 0, restored: 0 };
|
|
10044
10154
|
const held = takeLock(root, "remove");
|
|
10045
10155
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
10046
10156
|
let restored = 0;
|
|
10047
10157
|
try {
|
|
10048
|
-
const runs =
|
|
10158
|
+
const runs = readdirSync6(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync17(path12.join(d, MANIFEST))).sort().reverse();
|
|
10049
10159
|
for (const dir of runs) {
|
|
10050
|
-
const m3 = JSON.parse(
|
|
10160
|
+
const m3 = JSON.parse(readFileSync11(path12.join(dir, MANIFEST), "utf8"));
|
|
10051
10161
|
undo(dir, m3.entries, env);
|
|
10052
10162
|
restored += m3.entries.length;
|
|
10053
10163
|
renameWithRetry(path12.join(dir, MANIFEST), path12.join(dir, MANIFEST_DONE));
|
|
@@ -10059,7 +10169,7 @@ function runRemove(opts) {
|
|
|
10059
10169
|
}
|
|
10060
10170
|
|
|
10061
10171
|
// src/setup/print.ts
|
|
10062
|
-
import { readFileSync as
|
|
10172
|
+
import { readFileSync as readFileSync12 } from "node:fs";
|
|
10063
10173
|
var SHELL_SAFE_PUNCT = "@%+=:,./-_";
|
|
10064
10174
|
function isShellSafe(s) {
|
|
10065
10175
|
if (s === "") return false;
|
|
@@ -10087,7 +10197,7 @@ function printPlan(row, env) {
|
|
|
10087
10197
|
else if (h2.kind === "plugin-list") steps.push({ kind: "hook", file: h2.file, block: JSON.stringify({ [h2.key[0]]: [h2.entry] }, null, 2) + "\n" });
|
|
10088
10198
|
const sk = row.skillInstall;
|
|
10089
10199
|
if (sk.kind === "dir") {
|
|
10090
|
-
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(
|
|
10200
|
+
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync12(f2.src, "utf8"), sk.prefixes) });
|
|
10091
10201
|
}
|
|
10092
10202
|
return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
|
|
10093
10203
|
}
|
|
@@ -10390,6 +10500,10 @@ async function setup(ui) {
|
|
|
10390
10500
|
if (f2.print) return printManual(ui, f2.print);
|
|
10391
10501
|
if (f2.list) return list(ui);
|
|
10392
10502
|
if (f2.remove) return remove(ui);
|
|
10503
|
+
if (nodeTooOld(process.version)) {
|
|
10504
|
+
err(`context-mode: ${formatError("NODE_TOO_OLD", { v: process.version })}`);
|
|
10505
|
+
return EXIT_FAIL;
|
|
10506
|
+
}
|
|
10393
10507
|
if (f2.dryRun) {
|
|
10394
10508
|
const plan = await apply(ui, f2.agents, true);
|
|
10395
10509
|
if (f2.json) out(JSON.stringify({ command: "setup", dryRun: true, ...plan }));
|
|
@@ -10509,7 +10623,7 @@ async function upgrade(ui) {
|
|
|
10509
10623
|
}
|
|
10510
10624
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
10511
10625
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
10512
|
-
if (!root || !
|
|
10626
|
+
if (!root || !existsSync18(cli)) {
|
|
10513
10627
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
10514
10628
|
return EXIT_FAIL;
|
|
10515
10629
|
}
|
|
@@ -10607,7 +10721,7 @@ function main() {
|
|
|
10607
10721
|
const dir = path14.dirname(realpathSync11(fileURLToPath3(import.meta.url)));
|
|
10608
10722
|
let version = "";
|
|
10609
10723
|
try {
|
|
10610
|
-
version = String(JSON.parse(
|
|
10724
|
+
version = String(JSON.parse(readFileSync13(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
10611
10725
|
} catch (err2) {
|
|
10612
10726
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
10613
10727
|
`);
|