context-mode 2.0.0-next.24 → 2.0.0-next.25
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/README.md +41 -41
- package/SHA256SUMS +15 -15
- package/cli.mjs +23 -14
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +60 -60
- package/opencode/plugin.js +259 -112
- package/package.json +1 -1
- package/pi/index.js +290 -143
- package/qwen-extension.json +1 -1
- package/run.mjs +24 -22
- package/search.mjs +24 -22
- package/server.mjs +257 -127
package/opencode/plugin.js
CHANGED
|
@@ -220,6 +220,13 @@ var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
|
220
220
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
221
221
|
var PLUGIN_AGENT_SEPARATOR = ":";
|
|
222
222
|
var PLUGIN_KEY_SEPARATOR = "@";
|
|
223
|
+
var CLAUDE_PLUGIN_ROOT_ENV = "CLAUDE_PLUGIN_ROOT";
|
|
224
|
+
var CLAUDE_PROJECT_DIR_ENV = "CLAUDE_PROJECT_DIR";
|
|
225
|
+
var ENABLED_PLUGINS_KEY = "enabledPlugins";
|
|
226
|
+
var SETTINGS_LOCAL_FILE = "settings.local.json";
|
|
227
|
+
var DEFAULT_PLUGIN_SCOPE = "user";
|
|
228
|
+
var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
|
|
229
|
+
var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
|
|
223
230
|
var FRONTMATTER_FENCE = "---";
|
|
224
231
|
var FRONTMATTER_TOOLS_KEY = "tools";
|
|
225
232
|
var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
|
|
@@ -363,7 +370,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
363
370
|
var DECISION_LABEL_JOIN = " | ";
|
|
364
371
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
365
372
|
var RELEASE_BRANCH = "release";
|
|
366
|
-
var BUNDLE_SHA = true ? "
|
|
373
|
+
var BUNDLE_SHA = true ? "58d6b744f8c640e9f43f03516d8bc50dc1292ae0" : void 0;
|
|
367
374
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
368
375
|
var DOCTOR_LABEL = Object.freeze({
|
|
369
376
|
D1: "version",
|
|
@@ -519,6 +526,13 @@ var D3_PART_JOIN = ", ";
|
|
|
519
526
|
function D3_DETAIL(parts) {
|
|
520
527
|
return `wrong: ${parts.join(D3_PART_JOIN)}`;
|
|
521
528
|
}
|
|
529
|
+
function D3_ROOT_DETAIL(paths) {
|
|
530
|
+
return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
|
|
531
|
+
}
|
|
532
|
+
var D3_ROOT_FIX_JOIN = " or ";
|
|
533
|
+
function D3_ROOT_FIX(installs) {
|
|
534
|
+
return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
|
|
535
|
+
}
|
|
522
536
|
var HOOK_HOST_FILE = Object.freeze({
|
|
523
537
|
"claude-code": { root: "plugin", file: ["hooks", "claude-code.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
|
|
524
538
|
codex: { root: "home", file: [".codex", "hooks.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
|
|
@@ -790,7 +804,7 @@ var CtxError = class extends Error {
|
|
|
790
804
|
};
|
|
791
805
|
|
|
792
806
|
// src/core/hooks/dispatch.ts
|
|
793
|
-
import { dirname as
|
|
807
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
794
808
|
|
|
795
809
|
// src/core/contracts/agents.ts
|
|
796
810
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -1690,7 +1704,7 @@ function getAdapter(id2) {
|
|
|
1690
1704
|
}
|
|
1691
1705
|
|
|
1692
1706
|
// src/core/policy/decide.ts
|
|
1693
|
-
import { resolve as
|
|
1707
|
+
import { resolve as resolve3 } from "node:path";
|
|
1694
1708
|
|
|
1695
1709
|
// src/core/policy/lexer.ts
|
|
1696
1710
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -2995,7 +3009,7 @@ function withLayout(text, layout) {
|
|
|
2995
3009
|
}
|
|
2996
3010
|
|
|
2997
3011
|
// src/core/project/config-dir.ts
|
|
2998
|
-
import { join, posix, win32 } from "node:path";
|
|
3012
|
+
import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
|
|
2999
3013
|
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
3000
3014
|
function homeDirOf(env, platform = process.platform) {
|
|
3001
3015
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
@@ -3011,6 +3025,20 @@ function codexDirOf(env, home) {
|
|
|
3011
3025
|
const dir = env[CODEX_HOME_ENV];
|
|
3012
3026
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR.codex);
|
|
3013
3027
|
}
|
|
3028
|
+
function codexPluginHomeOf(bundleDir2) {
|
|
3029
|
+
let dir = resolve2(bundleDir2);
|
|
3030
|
+
while (dirname(dir) !== dir) {
|
|
3031
|
+
const up = dirname(dir);
|
|
3032
|
+
if (basename(dir) === PLUGIN_CACHE_DIR_NAME && basename(up) === HOST_PLUGINS_DIR_NAME) return dirname(up);
|
|
3033
|
+
dir = up;
|
|
3034
|
+
}
|
|
3035
|
+
return null;
|
|
3036
|
+
}
|
|
3037
|
+
function codexRunDirOf(env, home, bundleDir2) {
|
|
3038
|
+
const dir = env[CODEX_HOME_ENV];
|
|
3039
|
+
if (dir !== void 0 && dir !== "") return dir;
|
|
3040
|
+
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
3041
|
+
}
|
|
3014
3042
|
function copilotDirOf(env, home) {
|
|
3015
3043
|
const dir = env[COPILOT_HOME_ENV];
|
|
3016
3044
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
@@ -3590,7 +3618,7 @@ function readPath(input) {
|
|
|
3590
3618
|
}
|
|
3591
3619
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
3592
3620
|
if (rules.length === 0) return null;
|
|
3593
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
3621
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
3594
3622
|
if (canonical === BASH) {
|
|
3595
3623
|
const cmd = str(input.command);
|
|
3596
3624
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -3701,7 +3729,7 @@ function read(ev, row5, input) {
|
|
|
3701
3729
|
if (!present(input.offset) && !present(input.limit)) {
|
|
3702
3730
|
const p = readPath(input);
|
|
3703
3731
|
if (p !== void 0) {
|
|
3704
|
-
const abs =
|
|
3732
|
+
const abs = resolve3(ev.cwd, p);
|
|
3705
3733
|
const size = fileSize(abs);
|
|
3706
3734
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3707
3735
|
}
|
|
@@ -3714,7 +3742,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3714
3742
|
let verdict = null;
|
|
3715
3743
|
for (const c of cmds) {
|
|
3716
3744
|
const name = c.argv0.toLowerCase();
|
|
3717
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
3745
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve3(dir, c.args[0]);
|
|
3718
3746
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
3719
3747
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
3720
3748
|
const d = dumpTarget(name, c.args);
|
|
@@ -3723,7 +3751,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3723
3751
|
verdict = ALLOW;
|
|
3724
3752
|
continue;
|
|
3725
3753
|
}
|
|
3726
|
-
const abs =
|
|
3754
|
+
const abs = resolve3(dir, d.file);
|
|
3727
3755
|
const size = fileSize(abs);
|
|
3728
3756
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3729
3757
|
}
|
|
@@ -3794,10 +3822,10 @@ function dumpTarget(name, args) {
|
|
|
3794
3822
|
}
|
|
3795
3823
|
|
|
3796
3824
|
// src/core/project/resolve.ts
|
|
3797
|
-
import { basename, dirname as
|
|
3825
|
+
import { basename as basename2, dirname as dirname3, join as join4, resolve as resolve4 } from "node:path";
|
|
3798
3826
|
|
|
3799
3827
|
// src/core/project/contain.ts
|
|
3800
|
-
import { dirname, sep as sep2 } from "node:path";
|
|
3828
|
+
import { dirname as dirname2, sep as sep2 } from "node:path";
|
|
3801
3829
|
var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
3802
3830
|
function real(p) {
|
|
3803
3831
|
try {
|
|
@@ -3834,7 +3862,7 @@ function commonRoot(paths) {
|
|
|
3834
3862
|
n = i;
|
|
3835
3863
|
}
|
|
3836
3864
|
let q = first;
|
|
3837
|
-
while (components(q).length > n &&
|
|
3865
|
+
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
3838
3866
|
return q;
|
|
3839
3867
|
}
|
|
3840
3868
|
|
|
@@ -4001,9 +4029,9 @@ function gitDirs(dir) {
|
|
|
4001
4029
|
const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
|
|
4002
4030
|
if (gitDir !== null) {
|
|
4003
4031
|
const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
|
|
4004
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
4032
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
4005
4033
|
}
|
|
4006
|
-
const up =
|
|
4034
|
+
const up = dirname3(cur);
|
|
4007
4035
|
if (up === cur) return { commonDir: null, start };
|
|
4008
4036
|
cur = up;
|
|
4009
4037
|
}
|
|
@@ -4016,7 +4044,7 @@ function gitDirAt(dotGit) {
|
|
|
4016
4044
|
} else {
|
|
4017
4045
|
const line = firstLine(dotGit);
|
|
4018
4046
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
4019
|
-
gitDir =
|
|
4047
|
+
gitDir = resolve4(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
4020
4048
|
}
|
|
4021
4049
|
} catch {
|
|
4022
4050
|
return null;
|
|
@@ -4041,9 +4069,9 @@ function git(dir, args) {
|
|
|
4041
4069
|
return r.stdout.split("\n").filter((l) => l !== "");
|
|
4042
4070
|
}
|
|
4043
4071
|
function containmentRootOf(dir, commonDir) {
|
|
4044
|
-
const repoDir =
|
|
4072
|
+
const repoDir = basename2(commonDir) === GIT_DIR_NAME ? dirname3(commonDir) : commonDir;
|
|
4045
4073
|
const worktrees = git(dir, ["worktree", "list", "--porcelain"]).filter((l) => l.startsWith(GIT_WORKTREE_LINE_PREFIX)).map((l) => l.slice(GIT_WORKTREE_LINE_PREFIX.length));
|
|
4046
|
-
return commonRoot([
|
|
4074
|
+
return commonRoot([dirname3(repoDir), ...worktrees]);
|
|
4047
4075
|
}
|
|
4048
4076
|
function resolveProject(agent, src) {
|
|
4049
4077
|
const source = sourceOf(agent);
|
|
@@ -7973,7 +8001,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
7973
8001
|
}
|
|
7974
8002
|
|
|
7975
8003
|
// src/core/hooks/fallback.ts
|
|
7976
|
-
import { join as join5, resolve as
|
|
8004
|
+
import { join as join5, resolve as resolve5 } from "node:path";
|
|
7977
8005
|
var fs = process.getBuiltinModule("node:fs");
|
|
7978
8006
|
function isRec(v) {
|
|
7979
8007
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8088,7 +8116,7 @@ function bigRead(input, cwd) {
|
|
|
8088
8116
|
const p = firstString(input, READ_PATH_KEYS);
|
|
8089
8117
|
if (p === "") return false;
|
|
8090
8118
|
try {
|
|
8091
|
-
const st = fs.statSync(
|
|
8119
|
+
const st = fs.statSync(resolve5(cwd, p));
|
|
8092
8120
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
8093
8121
|
} catch {
|
|
8094
8122
|
return false;
|
|
@@ -8159,20 +8187,24 @@ async function handleHook(agent, raw, env) {
|
|
|
8159
8187
|
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
|
|
8160
8188
|
}
|
|
8161
8189
|
let decision;
|
|
8190
|
+
const settle = {};
|
|
8162
8191
|
try {
|
|
8163
8192
|
fault(env, "policy");
|
|
8164
|
-
decision = await dispatch(ev, row5, project, env);
|
|
8193
|
+
decision = await dispatch(ev, row5, project, env, settle);
|
|
8165
8194
|
} catch (err) {
|
|
8166
8195
|
return fail7("store", err);
|
|
8167
8196
|
}
|
|
8168
8197
|
try {
|
|
8169
8198
|
fault(env, "encode");
|
|
8170
|
-
|
|
8199
|
+
const out = row5.encode(ev, decision);
|
|
8200
|
+
settle.run?.(true);
|
|
8201
|
+
return out;
|
|
8171
8202
|
} catch (err) {
|
|
8203
|
+
settle.run?.(false);
|
|
8172
8204
|
return fail7("encode", err);
|
|
8173
8205
|
}
|
|
8174
8206
|
}
|
|
8175
|
-
function dispatch(ev, row5, project, env) {
|
|
8207
|
+
function dispatch(ev, row5, project, env, settle) {
|
|
8176
8208
|
switch (ev.event) {
|
|
8177
8209
|
case "SessionStart":
|
|
8178
8210
|
return sessionStart(ev, row5, project);
|
|
@@ -8181,7 +8213,7 @@ function dispatch(ev, row5, project, env) {
|
|
|
8181
8213
|
case "PreToolUse":
|
|
8182
8214
|
return preToolUse(ev, row5, project, env);
|
|
8183
8215
|
case "PostToolUse":
|
|
8184
|
-
return postToolUse(ev, row5, project, env);
|
|
8216
|
+
return postToolUse(ev, row5, project, env, settle);
|
|
8185
8217
|
case "PreCompact":
|
|
8186
8218
|
return preCompact(ev, row5, project);
|
|
8187
8219
|
case "Usage":
|
|
@@ -8371,7 +8403,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
8371
8403
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
8372
8404
|
const command = tool.input.command;
|
|
8373
8405
|
if (typeof command !== "string") return d0;
|
|
8374
|
-
const wrapper = '"' + join6(
|
|
8406
|
+
const wrapper = '"' + join6(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
8375
8407
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
8376
8408
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
8377
8409
|
}
|
|
@@ -8408,7 +8440,7 @@ function pathOf(input) {
|
|
|
8408
8440
|
for (const k of EDIT_PATH_KEYS) if (typeof input[k] === "string") return input[k];
|
|
8409
8441
|
return null;
|
|
8410
8442
|
}
|
|
8411
|
-
async function postToolUse(ev, row5, project, env) {
|
|
8443
|
+
async function postToolUse(ev, row5, project, env, settle) {
|
|
8412
8444
|
const tool = ev.tool;
|
|
8413
8445
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
8414
8446
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
@@ -8416,7 +8448,8 @@ async function postToolUse(ev, row5, project, env) {
|
|
|
8416
8448
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
8417
8449
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
8418
8450
|
const kind = journalKind(tool, row5, result.isError);
|
|
8419
|
-
|
|
8451
|
+
const journal = (returned) => {
|
|
8452
|
+
if (kind === null) return;
|
|
8420
8453
|
const key = kind === "cmd" ? canonicalKey(tool.canonicalName, str2(tool.input.command)) : kind === "toolerr" ? tool.canonicalName + ":" + stableJson(tool.input) : null;
|
|
8421
8454
|
appendDetached(project, ev.sessionId, {
|
|
8422
8455
|
// step 4; body is the whole text (D-M3-H2-6)
|
|
@@ -8433,18 +8466,30 @@ async function postToolUse(ev, row5, project, env) {
|
|
|
8433
8466
|
body: text,
|
|
8434
8467
|
turn: ev.turn ?? 0,
|
|
8435
8468
|
sandbox_bytes: result.bytes,
|
|
8436
|
-
returned_bytes:
|
|
8469
|
+
returned_bytes: returned
|
|
8437
8470
|
});
|
|
8471
|
+
};
|
|
8472
|
+
let decision;
|
|
8473
|
+
try {
|
|
8474
|
+
decision = await postReplace(ev, row5, project, env, tool, result, text);
|
|
8475
|
+
} catch (err) {
|
|
8476
|
+
journal(result.bytes);
|
|
8477
|
+
throw err;
|
|
8438
8478
|
}
|
|
8479
|
+
const decided = decision;
|
|
8480
|
+
settle.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
|
|
8481
|
+
return decision;
|
|
8482
|
+
}
|
|
8483
|
+
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
8439
8484
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
8440
8485
|
if (result.keep === true) return ALLOW2;
|
|
8486
|
+
if (!hasReplace(row5)) return ALLOW2;
|
|
8441
8487
|
let label;
|
|
8442
8488
|
if (isSubagentCall(ev)) {
|
|
8443
8489
|
const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
|
|
8444
8490
|
if (subCase === "A") return ALLOW2;
|
|
8445
8491
|
label = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
|
|
8446
8492
|
} else {
|
|
8447
|
-
if (!hasReplace(row5)) return ALLOW2;
|
|
8448
8493
|
label = mainLabel(tool, ev);
|
|
8449
8494
|
}
|
|
8450
8495
|
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ?? "";
|
|
@@ -19840,10 +19885,10 @@ function startArgv(argv) {
|
|
|
19840
19885
|
return sh === null ? null : [sh, ...argv];
|
|
19841
19886
|
}
|
|
19842
19887
|
function runProcess(argv, o) {
|
|
19843
|
-
return new Promise((
|
|
19888
|
+
return new Promise((resolve8) => {
|
|
19844
19889
|
const isWin2 = process.platform === "win32";
|
|
19845
19890
|
const start = startArgv(argv);
|
|
19846
|
-
if (start === null) return
|
|
19891
|
+
if (start === null) return resolve8(NOT_STARTED);
|
|
19847
19892
|
let child;
|
|
19848
19893
|
try {
|
|
19849
19894
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -19857,7 +19902,7 @@ function runProcess(argv, o) {
|
|
|
19857
19902
|
windowsHide: true
|
|
19858
19903
|
});
|
|
19859
19904
|
} catch {
|
|
19860
|
-
return
|
|
19905
|
+
return resolve8(NOT_STARTED);
|
|
19861
19906
|
}
|
|
19862
19907
|
const stdoutChunks = [];
|
|
19863
19908
|
const stderrChunks = [];
|
|
@@ -19882,7 +19927,7 @@ function runProcess(argv, o) {
|
|
|
19882
19927
|
settled = true;
|
|
19883
19928
|
clearTimeout(timer);
|
|
19884
19929
|
o.signal.removeEventListener("abort", onAbort);
|
|
19885
|
-
|
|
19930
|
+
resolve8({
|
|
19886
19931
|
stdout: Buffer.concat(stdoutChunks),
|
|
19887
19932
|
stderr: Buffer.concat(stderrChunks),
|
|
19888
19933
|
exitCode,
|
|
@@ -20400,7 +20445,7 @@ var ctxBatch = Object.freeze({
|
|
|
20400
20445
|
|
|
20401
20446
|
// src/core/tools/doctor.ts
|
|
20402
20447
|
import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync12 } from "node:fs";
|
|
20403
|
-
import { basename as
|
|
20448
|
+
import { basename as basename4, dirname as dirname7, join as join13 } from "node:path";
|
|
20404
20449
|
|
|
20405
20450
|
// src/core/ops/doctor-config.ts
|
|
20406
20451
|
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -20413,7 +20458,7 @@ import { join as join9 } from "node:path";
|
|
|
20413
20458
|
|
|
20414
20459
|
// src/core/ops/host-config.ts
|
|
20415
20460
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
20416
|
-
import { dirname as
|
|
20461
|
+
import { dirname as dirname5, join as join8 } from "node:path";
|
|
20417
20462
|
|
|
20418
20463
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20419
20464
|
var KEYS2 = {
|
|
@@ -22530,7 +22575,7 @@ function formatOf(path7) {
|
|
|
22530
22575
|
function readHostConfig(agent, path7) {
|
|
22531
22576
|
let file2 = path7;
|
|
22532
22577
|
if (agent === "opencode") {
|
|
22533
|
-
const jsonc = join8(
|
|
22578
|
+
const jsonc = join8(dirname5(path7), OPENCODE_CONFIG_FILES[0]);
|
|
22534
22579
|
if (existsSync3(jsonc)) file2 = jsonc;
|
|
22535
22580
|
}
|
|
22536
22581
|
const raw = existsSync3(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -22878,7 +22923,7 @@ function setText(agent, path7, text, format, key, value) {
|
|
|
22878
22923
|
}
|
|
22879
22924
|
}
|
|
22880
22925
|
function serverScript() {
|
|
22881
|
-
return join8(
|
|
22926
|
+
return join8(dirname5(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
22882
22927
|
}
|
|
22883
22928
|
function isNodeCommand(command) {
|
|
22884
22929
|
if (typeof command !== "string") return false;
|
|
@@ -22894,7 +22939,7 @@ function ownMcpValue(agent, node, server2) {
|
|
|
22894
22939
|
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent, ...tail] };
|
|
22895
22940
|
}
|
|
22896
22941
|
function opencodePluginFile() {
|
|
22897
|
-
return
|
|
22942
|
+
return dirname5(process.argv[1] ?? "");
|
|
22898
22943
|
}
|
|
22899
22944
|
function listTarget(key, own2, v1, alt = []) {
|
|
22900
22945
|
return {
|
|
@@ -23254,20 +23299,23 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23254
23299
|
|
|
23255
23300
|
// src/core/ops/plugin-root.ts
|
|
23256
23301
|
import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23257
|
-
import { dirname as
|
|
23302
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
|
|
23258
23303
|
import { fileURLToPath } from "node:url";
|
|
23259
23304
|
function missing(agent, path7) {
|
|
23260
23305
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
|
|
23261
23306
|
}
|
|
23262
|
-
|
|
23263
|
-
let parsed;
|
|
23307
|
+
var parseOrNull = (text) => {
|
|
23264
23308
|
try {
|
|
23265
|
-
|
|
23309
|
+
return JSON.parse(hostText(text));
|
|
23266
23310
|
} catch {
|
|
23267
|
-
return
|
|
23311
|
+
return null;
|
|
23268
23312
|
}
|
|
23269
|
-
|
|
23270
|
-
|
|
23313
|
+
};
|
|
23314
|
+
var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23315
|
+
function recordedInstalls(text) {
|
|
23316
|
+
const parsed = parseOrNull(text);
|
|
23317
|
+
const plugins = isRecord3(parsed) ? parsed.plugins : void 0;
|
|
23318
|
+
if (!isRecord3(plugins)) return [];
|
|
23271
23319
|
const out = [];
|
|
23272
23320
|
for (const key of Object.keys(plugins)) {
|
|
23273
23321
|
const at2 = key.indexOf(PLUGIN_KEY_SEPARATOR);
|
|
@@ -23275,8 +23323,10 @@ function recordedInstallPaths(text) {
|
|
|
23275
23323
|
const entries = plugins[key];
|
|
23276
23324
|
if (!Array.isArray(entries)) continue;
|
|
23277
23325
|
for (const e of entries) {
|
|
23278
|
-
|
|
23279
|
-
|
|
23326
|
+
if (!isRecord3(e) || typeof e.installPath !== "string" || e.installPath === "") continue;
|
|
23327
|
+
const scope = typeof e.scope === "string" ? e.scope : DEFAULT_PLUGIN_SCOPE;
|
|
23328
|
+
const projectPath = typeof e.projectPath === "string" ? e.projectPath : void 0;
|
|
23329
|
+
out.push({ key, scope, projectPath, installPath: e.installPath });
|
|
23280
23330
|
}
|
|
23281
23331
|
}
|
|
23282
23332
|
return out;
|
|
@@ -23288,26 +23338,62 @@ var realOrNull = (path7) => {
|
|
|
23288
23338
|
return null;
|
|
23289
23339
|
}
|
|
23290
23340
|
};
|
|
23291
|
-
|
|
23292
|
-
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23293
|
-
const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
23294
|
-
const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23295
|
-
const script = process.argv[1];
|
|
23296
|
-
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
|
|
23297
|
-
let record4 = null;
|
|
23341
|
+
var readOrNull = (file2) => {
|
|
23298
23342
|
try {
|
|
23299
|
-
|
|
23343
|
+
return readFileSync8(file2, "utf8");
|
|
23300
23344
|
} catch {
|
|
23301
|
-
|
|
23345
|
+
return null;
|
|
23302
23346
|
}
|
|
23303
|
-
|
|
23304
|
-
|
|
23305
|
-
|
|
23306
|
-
|
|
23307
|
-
|
|
23308
|
-
|
|
23309
|
-
|
|
23347
|
+
};
|
|
23348
|
+
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23349
|
+
function enabledPlugins(claudeDir, project) {
|
|
23350
|
+
const files = [join10(claudeDir, SETTINGS_FILE)];
|
|
23351
|
+
if (project !== void 0) files.push(join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
23352
|
+
const out = {};
|
|
23353
|
+
for (const file2 of files) {
|
|
23354
|
+
const text = readOrNull(file2);
|
|
23355
|
+
const doc = text === null ? null : parseOrNull(text);
|
|
23356
|
+
const on = isRecord3(doc) ? doc[ENABLED_PLUGINS_KEY] : void 0;
|
|
23357
|
+
if (isRecord3(on)) Object.assign(out, on);
|
|
23310
23358
|
}
|
|
23359
|
+
return out;
|
|
23360
|
+
}
|
|
23361
|
+
function marketplaceChoice(env, worktree) {
|
|
23362
|
+
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23363
|
+
const script = process.argv[1];
|
|
23364
|
+
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
|
|
23365
|
+
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23366
|
+
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23367
|
+
const record4 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23368
|
+
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
23369
|
+
if (recorded.length === 0) return { record: false };
|
|
23370
|
+
const live = recorded.filter((r) => existsSync5(r.installPath));
|
|
23371
|
+
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
23372
|
+
if (mine !== void 0) return { root: mine.installPath };
|
|
23373
|
+
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
23374
|
+
if (dirs.length === 1) return { root: dirs[0].installPath };
|
|
23375
|
+
const projectEnv = env[CLAUDE_PROJECT_DIR_ENV];
|
|
23376
|
+
const project = worktree ?? (projectEnv === void 0 || projectEnv === "" ? void 0 : projectEnv);
|
|
23377
|
+
const on = enabledPlugins(claudeDir, project);
|
|
23378
|
+
const applies = (r) => !PROJECT_PLUGIN_SCOPES.includes(r.scope) || project !== void 0 && r.projectPath !== void 0 && samePath(r.projectPath, project);
|
|
23379
|
+
const rank = (r) => PLUGIN_SCOPE_RANK[r.scope] ?? PLUGIN_SCOPE_RANK[DEFAULT_PLUGIN_SCOPE];
|
|
23380
|
+
const used = live.filter((r) => on[r.key] === true && applies(r));
|
|
23381
|
+
if (used.length > 0) {
|
|
23382
|
+
const best = Math.min(...used.map(rank));
|
|
23383
|
+
const top = used.filter((r) => rank(r) === best);
|
|
23384
|
+
if (top.every((r) => samePath(r.installPath, top[0].installPath))) return { root: top[0].installPath };
|
|
23385
|
+
}
|
|
23386
|
+
return { installs: live.length === 0 ? recorded : live };
|
|
23387
|
+
}
|
|
23388
|
+
function marketplaceRoot(adapter, env, worktree) {
|
|
23389
|
+
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23390
|
+
const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
23391
|
+
const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23392
|
+
const script = process.argv[1];
|
|
23393
|
+
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
|
|
23394
|
+
const choice = marketplaceChoice(env, worktree);
|
|
23395
|
+
if ("root" in choice) return choice.root;
|
|
23396
|
+
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23311
23397
|
const cacheReal = realOrNull(cache);
|
|
23312
23398
|
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
23313
23399
|
const pattern = join10(cache, "*", PLUGIN_NAME);
|
|
@@ -23326,12 +23412,12 @@ function configEntryRoot(adapter, env) {
|
|
|
23326
23412
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
23327
23413
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
23328
23414
|
if (typeof script !== "string" || !isAbsolute2(script)) throw missing(adapter.id, file2);
|
|
23329
|
-
return
|
|
23415
|
+
return dirname6(script);
|
|
23330
23416
|
}
|
|
23331
|
-
function candidate(adapter, env) {
|
|
23417
|
+
function candidate(adapter, env, worktree) {
|
|
23332
23418
|
switch (adapter.installMode) {
|
|
23333
23419
|
case "marketplace":
|
|
23334
|
-
return marketplaceRoot(adapter, env);
|
|
23420
|
+
return marketplaceRoot(adapter, env, worktree);
|
|
23335
23421
|
case "config-mcp":
|
|
23336
23422
|
case "mcp-entry":
|
|
23337
23423
|
case "hooks+mcp":
|
|
@@ -23341,11 +23427,11 @@ function candidate(adapter, env) {
|
|
|
23341
23427
|
case "plugin":
|
|
23342
23428
|
return join10(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23343
23429
|
case "in-process":
|
|
23344
|
-
return
|
|
23430
|
+
return dirname6(fileURLToPath(import.meta.url));
|
|
23345
23431
|
}
|
|
23346
23432
|
}
|
|
23347
|
-
function resolvePluginRoot(adapter, env) {
|
|
23348
|
-
const path7 = candidate(adapter, env);
|
|
23433
|
+
function resolvePluginRoot(adapter, env, worktree) {
|
|
23434
|
+
const path7 = candidate(adapter, env, worktree);
|
|
23349
23435
|
try {
|
|
23350
23436
|
return realpathSync4.native(path7);
|
|
23351
23437
|
} catch {
|
|
@@ -23476,13 +23562,13 @@ function nativeMcpWrong(dir, row5) {
|
|
|
23476
23562
|
return true;
|
|
23477
23563
|
}
|
|
23478
23564
|
}
|
|
23479
|
-
function mcpWrong(row5, home, env) {
|
|
23565
|
+
function mcpWrong(row5, home, env, worktree) {
|
|
23480
23566
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23481
23567
|
if (native !== null) return nativeMcpWrong(native, row5);
|
|
23482
23568
|
const file2 = mcpFile(row5, home, env);
|
|
23483
23569
|
try {
|
|
23484
23570
|
if (file2 === null) {
|
|
23485
|
-
resolvePluginRoot(row5, env);
|
|
23571
|
+
resolvePluginRoot(row5, env, worktree);
|
|
23486
23572
|
return false;
|
|
23487
23573
|
}
|
|
23488
23574
|
const cur = readHostConfig(row5.id, file2);
|
|
@@ -23496,7 +23582,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23496
23582
|
if (spec === null) return [];
|
|
23497
23583
|
let block;
|
|
23498
23584
|
try {
|
|
23499
|
-
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
23585
|
+
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
23500
23586
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23501
23587
|
const file2 = native !== null ? join11(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
|
|
23502
23588
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
@@ -23531,7 +23617,11 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23531
23617
|
function checkHostConfig(row5, env, worktree) {
|
|
23532
23618
|
const home = homeDirOf(env);
|
|
23533
23619
|
if (home === null) return fail2("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
|
|
23534
|
-
|
|
23620
|
+
if (row5.installMode === "marketplace") {
|
|
23621
|
+
const choice = marketplaceChoice(env, worktree);
|
|
23622
|
+
if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
23623
|
+
}
|
|
23624
|
+
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
23535
23625
|
const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
23536
23626
|
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
23537
23627
|
const detail = D3_DETAIL(parts);
|
|
@@ -23723,7 +23813,7 @@ function checkShell(env) {
|
|
|
23723
23813
|
}
|
|
23724
23814
|
|
|
23725
23815
|
// src/core/ops/doctor-hook.ts
|
|
23726
|
-
import { existsSync as existsSync10, readFileSync as readFileSync9 } from "node:fs";
|
|
23816
|
+
import { existsSync as existsSync10, readFileSync as readFileSync9, realpathSync as realpathSync7 } from "node:fs";
|
|
23727
23817
|
import path6 from "node:path";
|
|
23728
23818
|
|
|
23729
23819
|
// src/setup/codex-trust.ts
|
|
@@ -23800,6 +23890,28 @@ function spawnForm(file2, args, env, platform = process.platform) {
|
|
|
23800
23890
|
var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23801
23891
|
var TRUST_KEY = ["hooks", "state"];
|
|
23802
23892
|
var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
|
|
23893
|
+
var WIN_VERBATIM_PREFIX = "\\\\?\\";
|
|
23894
|
+
function codexHomeFromReply(out) {
|
|
23895
|
+
for (const line of out.split("\n")) {
|
|
23896
|
+
let m;
|
|
23897
|
+
try {
|
|
23898
|
+
m = JSON.parse(line);
|
|
23899
|
+
} catch {
|
|
23900
|
+
continue;
|
|
23901
|
+
}
|
|
23902
|
+
if (isObj2(m) && isObj2(m.result) && typeof m.result.codexHome === "string" && m.result.codexHome !== "") return m.result.codexHome;
|
|
23903
|
+
}
|
|
23904
|
+
return void 0;
|
|
23905
|
+
}
|
|
23906
|
+
function sameDir(a, b, platform = process.platform) {
|
|
23907
|
+
if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
|
|
23908
|
+
const norm2 = (p) => {
|
|
23909
|
+
const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
|
|
23910
|
+
const n = path5.win32.normalize(bare2).toLowerCase();
|
|
23911
|
+
return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
|
|
23912
|
+
};
|
|
23913
|
+
return norm2(a) === norm2(b);
|
|
23914
|
+
}
|
|
23803
23915
|
var LIST_TIMEOUT_MS = 15e3;
|
|
23804
23916
|
var EXIT_GRACE_MS = 5e3;
|
|
23805
23917
|
var PLUGIN_SOURCE = "plugin";
|
|
@@ -23818,15 +23930,17 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
23818
23930
|
}
|
|
23819
23931
|
return out;
|
|
23820
23932
|
}
|
|
23821
|
-
function
|
|
23933
|
+
function askPluginHooks(env, pluginId, cwd) {
|
|
23822
23934
|
const bin = whichBin("codex", env);
|
|
23823
|
-
if (!bin) return Promise.resolve(
|
|
23824
|
-
return new Promise((
|
|
23935
|
+
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
23936
|
+
return new Promise((resolve8) => {
|
|
23937
|
+
let asked;
|
|
23938
|
+
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
23825
23939
|
let f;
|
|
23826
23940
|
try {
|
|
23827
23941
|
f = spawnForm(bin, ["app-server"], env);
|
|
23828
23942
|
} catch {
|
|
23829
|
-
|
|
23943
|
+
resolve8({ kind: "silent" });
|
|
23830
23944
|
return;
|
|
23831
23945
|
}
|
|
23832
23946
|
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -23836,7 +23950,7 @@ function listPluginHooks(env, pluginId, cwd) {
|
|
|
23836
23950
|
let result;
|
|
23837
23951
|
const settle = () => {
|
|
23838
23952
|
clearTimeout(grace);
|
|
23839
|
-
|
|
23953
|
+
resolve8(done_(result));
|
|
23840
23954
|
};
|
|
23841
23955
|
let grace;
|
|
23842
23956
|
const finish2 = (v) => {
|
|
@@ -23881,6 +23995,7 @@ function listPluginHooks(env, pluginId, cwd) {
|
|
|
23881
23995
|
}
|
|
23882
23996
|
if (!isObj2(m)) continue;
|
|
23883
23997
|
if (m.id === 1) {
|
|
23998
|
+
asked = codexHomeFromReply(line);
|
|
23884
23999
|
send({ method: "initialized" });
|
|
23885
24000
|
send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
|
|
23886
24001
|
} else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
|
|
@@ -23910,6 +24025,10 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
23910
24025
|
var D5_MIN_PAIRS = 3;
|
|
23911
24026
|
var D5_MAX_PAIRS = 9;
|
|
23912
24027
|
var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
|
|
24028
|
+
var D5_CODEX_ABSENT_DETAIL = (home) => `codex is not on PATH, so the trust of the context-mode plugin hooks in ${home} is not known`;
|
|
24029
|
+
var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answer for ${home} in time, so the context-mode plugin hooks are not known to run`;
|
|
24030
|
+
var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
|
|
24031
|
+
var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
|
|
23913
24032
|
var row = (status, detail, fixCommand) => fixCommand === void 0 ? { id: "D5", label: DOCTOR_LABEL.D5, status, detail } : { id: "D5", label: DOCTOR_LABEL.D5, status, detail, fixCommand };
|
|
23914
24033
|
function isObject5(v) {
|
|
23915
24034
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -23946,11 +24065,34 @@ function codexHookJournaled(db) {
|
|
|
23946
24065
|
if (db === null) return false;
|
|
23947
24066
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
23948
24067
|
}
|
|
24068
|
+
function realDir(p) {
|
|
24069
|
+
try {
|
|
24070
|
+
return realpathSync7(p);
|
|
24071
|
+
} catch {
|
|
24072
|
+
return p;
|
|
24073
|
+
}
|
|
24074
|
+
}
|
|
24075
|
+
async function codexPluginTrust(i) {
|
|
24076
|
+
const home = i.codexConfigDir;
|
|
24077
|
+
const plugin = codexPluginHomeOf(i.bundleDir) !== null;
|
|
24078
|
+
const reply4 = await askPluginHooks({ ...i.env, CODEX_HOME: home }, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
|
|
24079
|
+
if (reply4.kind === "list") {
|
|
24080
|
+
const detail = untrustedPluginHooksDetail(reply4.hooks);
|
|
24081
|
+
if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
|
|
24082
|
+
}
|
|
24083
|
+
if (!plugin) return null;
|
|
24084
|
+
if (reply4.kind === "absent") return row("UNKNOWN", D5_CODEX_ABSENT_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
24085
|
+
if (reply4.kind === "silent") return row("FAIL", D5_CODEX_SILENT_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
24086
|
+
if (reply4.codexHome !== void 0 && !sameDir(realDir(reply4.codexHome), realDir(home))) {
|
|
24087
|
+
return row("FAIL", D5_CODEX_OTHER_HOME_DETAIL(reply4.codexHome, home), D5_CODEX_TRUST_FIX);
|
|
24088
|
+
}
|
|
24089
|
+
if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
24090
|
+
return null;
|
|
24091
|
+
}
|
|
23949
24092
|
async function checkHookRoundTrip(i) {
|
|
23950
24093
|
if (i.agent === "codex") {
|
|
23951
|
-
const
|
|
23952
|
-
|
|
23953
|
-
if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
|
|
24094
|
+
const trust = await codexPluginTrust(i);
|
|
24095
|
+
if (trust !== null) return trust;
|
|
23954
24096
|
}
|
|
23955
24097
|
if (i.agent === "codex" && existsSync10(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
23956
24098
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
@@ -23993,7 +24135,7 @@ import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
|
|
|
23993
24135
|
|
|
23994
24136
|
// src/core/store/owners.ts
|
|
23995
24137
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23996
|
-
import { basename as
|
|
24138
|
+
import { basename as basename3, join as join12 } from "node:path";
|
|
23997
24139
|
function ownersDir(configDir, projectKey) {
|
|
23998
24140
|
return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23999
24141
|
}
|
|
@@ -24031,7 +24173,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
24031
24173
|
if (errCode2(err) === "ENOENT") continue;
|
|
24032
24174
|
throw err;
|
|
24033
24175
|
}
|
|
24034
|
-
const serverId =
|
|
24176
|
+
const serverId = basename3(name, OWNER_PID_EXT);
|
|
24035
24177
|
if (isLive(Number(text.trim()))) live.push(serverId);
|
|
24036
24178
|
else rmSync2(file2, { force: true });
|
|
24037
24179
|
}
|
|
@@ -24171,7 +24313,7 @@ async function hookRow(ctx, adapter, host) {
|
|
|
24171
24313
|
env: buildChildEnv(host.env),
|
|
24172
24314
|
signal: ctx.signal,
|
|
24173
24315
|
codexConfigDir: codexDirOf(host.env, requireHomeDir(host.env)),
|
|
24174
|
-
//
|
|
24316
|
+
// = codexRunDirOf: runDoctorChecks sets CODEX_HOME for codex (D-CODEX-HOME-RUN-1)
|
|
24175
24317
|
db
|
|
24176
24318
|
});
|
|
24177
24319
|
const last2 = lastHookError(host.env);
|
|
@@ -24187,11 +24329,12 @@ function ownServerId(configDir, projectKey) {
|
|
|
24187
24329
|
if (!existsSync12(dir)) return "";
|
|
24188
24330
|
for (const name of readdirSync5(dir)) {
|
|
24189
24331
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24190
|
-
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return
|
|
24332
|
+
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
24191
24333
|
}
|
|
24192
24334
|
return "";
|
|
24193
24335
|
}
|
|
24194
|
-
async function runDoctorChecks(ctx, adapter,
|
|
24336
|
+
async function runDoctorChecks(ctx, adapter, host0) {
|
|
24337
|
+
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
24195
24338
|
const env = host.env;
|
|
24196
24339
|
const project = ctx.project;
|
|
24197
24340
|
let integrityFailed = false;
|
|
@@ -24233,7 +24376,7 @@ function reportEnv(env) {
|
|
|
24233
24376
|
}
|
|
24234
24377
|
async function handler2(_input, ctx) {
|
|
24235
24378
|
const adapter = getAdapter(ctx.project.agent);
|
|
24236
|
-
const host = { env: process.env, bundleDir:
|
|
24379
|
+
const host = { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 };
|
|
24237
24380
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
24238
24381
|
const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
24239
24382
|
const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
|
|
@@ -24261,7 +24404,7 @@ var ctxDoctor = Object.freeze({
|
|
|
24261
24404
|
// src/core/tools/execute.ts
|
|
24262
24405
|
import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24263
24406
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24264
|
-
import { dirname as
|
|
24407
|
+
import { dirname as dirname8, join as join14, parse as parse3, resolve as resolve6 } from "node:path";
|
|
24265
24408
|
|
|
24266
24409
|
// src/core/sandbox/win-build.ts
|
|
24267
24410
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -24345,7 +24488,7 @@ function schemaLine(issue2) {
|
|
|
24345
24488
|
}
|
|
24346
24489
|
function fileError(given, abs, root) {
|
|
24347
24490
|
let dir = abs;
|
|
24348
|
-
while (!existsSync13(dir) &&
|
|
24491
|
+
while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
24349
24492
|
if (isInside(root, dir)) return null;
|
|
24350
24493
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
24351
24494
|
}
|
|
@@ -24409,7 +24552,7 @@ async function handler3(raw, ctx) {
|
|
|
24409
24552
|
const cwd = ctx.project.worktree;
|
|
24410
24553
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
24411
24554
|
if (input.file !== void 0) {
|
|
24412
|
-
const abs =
|
|
24555
|
+
const abs = resolve6(cwd, input.file);
|
|
24413
24556
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
24414
24557
|
if (bad !== null) return fail5(bad);
|
|
24415
24558
|
extra.CTX_FILE = abs;
|
|
@@ -24463,15 +24606,15 @@ var ctxExecute = {
|
|
|
24463
24606
|
|
|
24464
24607
|
// src/core/tools/index.ts
|
|
24465
24608
|
import { existsSync as existsSync14, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
|
|
24466
|
-
import { dirname as
|
|
24609
|
+
import { dirname as dirname9, extname, join as join16, relative as relative3, resolve as resolve7 } from "node:path";
|
|
24467
24610
|
|
|
24468
24611
|
// src/core/index/walk.ts
|
|
24469
|
-
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as
|
|
24612
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync8, statSync as statSync6 } from "node:fs";
|
|
24470
24613
|
import { join as join15 } from "node:path";
|
|
24471
24614
|
var GITIGNORE = ".gitignore";
|
|
24472
24615
|
var GIT_DIR = ".git";
|
|
24473
24616
|
function walkDir(root, containmentRoot) {
|
|
24474
|
-
const real2 =
|
|
24617
|
+
const real2 = realpathSync8(root);
|
|
24475
24618
|
if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
24476
24619
|
const found = [];
|
|
24477
24620
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
@@ -24495,7 +24638,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24495
24638
|
if (e.isSymbolicLink()) {
|
|
24496
24639
|
let resolved;
|
|
24497
24640
|
try {
|
|
24498
|
-
resolved =
|
|
24641
|
+
resolved = realpathSync8(path7);
|
|
24499
24642
|
} catch {
|
|
24500
24643
|
continue;
|
|
24501
24644
|
}
|
|
@@ -24510,7 +24653,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24510
24653
|
if (isFile) {
|
|
24511
24654
|
found.push({ dir: rel, name: e.name, absPath: path7 });
|
|
24512
24655
|
} else if (isDir) {
|
|
24513
|
-
const key = e.isSymbolicLink() ? target :
|
|
24656
|
+
const key = e.isSymbolicLink() ? target : realpathSync8(path7);
|
|
24514
24657
|
if (seen.has(key)) continue;
|
|
24515
24658
|
seen.add(key);
|
|
24516
24659
|
visit(path7, segs, rules, contain, seen, found);
|
|
@@ -24705,18 +24848,18 @@ function request(u, conn, proxy, signal) {
|
|
|
24705
24848
|
const host = bare(u.hostname);
|
|
24706
24849
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
24707
24850
|
const path7 = u.pathname + u.search;
|
|
24708
|
-
return new Promise((
|
|
24851
|
+
return new Promise((resolve8, reject) => {
|
|
24709
24852
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
24710
24853
|
if (proxy === void 0) {
|
|
24711
24854
|
const mod = u.protocol === "https:" ? https : http;
|
|
24712
24855
|
const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
24713
|
-
req.on("response",
|
|
24856
|
+
req.on("response", resolve8).on("error", onErr).end();
|
|
24714
24857
|
return;
|
|
24715
24858
|
}
|
|
24716
24859
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
24717
24860
|
if (u.protocol === "http:") {
|
|
24718
24861
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
24719
|
-
req.on("response",
|
|
24862
|
+
req.on("response", resolve8).on("error", onErr).end();
|
|
24720
24863
|
return;
|
|
24721
24864
|
}
|
|
24722
24865
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -24736,16 +24879,16 @@ function request(u, conn, proxy, signal) {
|
|
|
24736
24879
|
headers: { host: u.host },
|
|
24737
24880
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
24738
24881
|
});
|
|
24739
|
-
req.on("response",
|
|
24882
|
+
req.on("response", resolve8).on("error", onErr).end();
|
|
24740
24883
|
});
|
|
24741
24884
|
tunnel.end();
|
|
24742
24885
|
});
|
|
24743
24886
|
}
|
|
24744
24887
|
function readBody(res) {
|
|
24745
|
-
return new Promise((
|
|
24888
|
+
return new Promise((resolve8, reject) => {
|
|
24746
24889
|
const parts = [];
|
|
24747
24890
|
res.on("data", (b) => parts.push(b));
|
|
24748
|
-
res.on("end", () =>
|
|
24891
|
+
res.on("end", () => resolve8(Buffer.concat(parts)));
|
|
24749
24892
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
24750
24893
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
24751
24894
|
});
|
|
@@ -28618,12 +28761,12 @@ function readUtf8(absPath) {
|
|
|
28618
28761
|
}
|
|
28619
28762
|
function missingOrOutside(given, abs, root) {
|
|
28620
28763
|
let dir = abs;
|
|
28621
|
-
while (!existsSync14(dir) &&
|
|
28764
|
+
while (!existsSync14(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
28622
28765
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
28623
28766
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
28624
28767
|
}
|
|
28625
28768
|
function pathItems(input, project) {
|
|
28626
|
-
const abs =
|
|
28769
|
+
const abs = resolve7(project.worktree, input.path);
|
|
28627
28770
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
28628
28771
|
const base = relative3(project.worktree, abs);
|
|
28629
28772
|
if (statSync7(abs).isDirectory()) {
|
|
@@ -28886,12 +29029,12 @@ var ctxStats = Object.freeze({
|
|
|
28886
29029
|
});
|
|
28887
29030
|
|
|
28888
29031
|
// src/core/tools/upgrade.ts
|
|
28889
|
-
import { existsSync as existsSync20, realpathSync as
|
|
28890
|
-
import { basename as
|
|
29032
|
+
import { existsSync as existsSync20, realpathSync as realpathSync9, rmSync as rmSync9 } from "node:fs";
|
|
29033
|
+
import { basename as basename6, dirname as dirname11, join as join22 } from "node:path";
|
|
28891
29034
|
|
|
28892
29035
|
// src/core/ops/host-write.ts
|
|
28893
29036
|
import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
28894
|
-
import { dirname as
|
|
29037
|
+
import { dirname as dirname10, join as join17 } from "node:path";
|
|
28895
29038
|
function defaultWrite(file2, text) {
|
|
28896
29039
|
writeFileSync4(file2, text, "utf8");
|
|
28897
29040
|
}
|
|
@@ -28920,7 +29063,7 @@ function writeWithRollback(file2, text, write2, atomic) {
|
|
|
28920
29063
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
28921
29064
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
28922
29065
|
const had = existsSync15(file2);
|
|
28923
|
-
mkdirSync5(
|
|
29066
|
+
mkdirSync5(dirname10(file2), { recursive: true });
|
|
28924
29067
|
if (had) copyFileSync(file2, trash);
|
|
28925
29068
|
try {
|
|
28926
29069
|
write2(tmp, text);
|
|
@@ -28958,7 +29101,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28958
29101
|
|
|
28959
29102
|
// src/core/ops/plugin-swap.ts
|
|
28960
29103
|
import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
28961
|
-
import { basename as
|
|
29104
|
+
import { basename as basename5, join as join18, win32 as win322 } from "node:path";
|
|
28962
29105
|
function linkTarget(path7, win) {
|
|
28963
29106
|
if (!isLink(path7)) return null;
|
|
28964
29107
|
const target = readlinkSync(path7);
|
|
@@ -28979,7 +29122,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
28979
29122
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
28980
29123
|
const next = join18(agentDir, sha);
|
|
28981
29124
|
if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
|
|
28982
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent:
|
|
29125
|
+
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
28983
29126
|
}
|
|
28984
29127
|
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
28985
29128
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
@@ -29062,6 +29205,10 @@ function removeCache(adapter, env, configDir) {
|
|
|
29062
29205
|
case "extension": {
|
|
29063
29206
|
const root = rootOrNull(adapter, env);
|
|
29064
29207
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29208
|
+
if (adapter.installMode === "marketplace") {
|
|
29209
|
+
const cache = join20(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
29210
|
+
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
29211
|
+
}
|
|
29065
29212
|
rmSync7(root, { recursive: true, force: true });
|
|
29066
29213
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
29067
29214
|
}
|
|
@@ -29347,7 +29494,7 @@ function row4(area, before, after) {
|
|
|
29347
29494
|
return { area, before, after };
|
|
29348
29495
|
}
|
|
29349
29496
|
function bundleDir() {
|
|
29350
|
-
return
|
|
29497
|
+
return dirname11(process.argv[1] ?? "");
|
|
29351
29498
|
}
|
|
29352
29499
|
function pluginRootRow(adapter, env) {
|
|
29353
29500
|
const own2 = bundleDir();
|
|
@@ -29362,11 +29509,11 @@ function pluginRootRow(adapter, env) {
|
|
|
29362
29509
|
}
|
|
29363
29510
|
function isCurrent(agentDir, dir) {
|
|
29364
29511
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
29365
|
-
return existsSync20(link) &&
|
|
29512
|
+
return existsSync20(link) && realpathSync9.native(link) === realpathSync9.native(dir);
|
|
29366
29513
|
}
|
|
29367
29514
|
async function checkout(adapter, deps) {
|
|
29368
29515
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
29369
|
-
const agentDir =
|
|
29516
|
+
const agentDir = dirname11(fetched.dir);
|
|
29370
29517
|
try {
|
|
29371
29518
|
verifySums(fetched.dir);
|
|
29372
29519
|
} catch (err) {
|
|
@@ -29394,7 +29541,7 @@ async function upgrade(adapter, deps, home) {
|
|
|
29394
29541
|
return rows;
|
|
29395
29542
|
} catch (err) {
|
|
29396
29543
|
removal?.rollback();
|
|
29397
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir,
|
|
29544
|
+
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename6(done.swap.previous));
|
|
29398
29545
|
throw err;
|
|
29399
29546
|
}
|
|
29400
29547
|
}
|