context-mode 2.1.8 → 2.1.9
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 +16 -11
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +123 -45
- package/package.json +1 -1
- package/pi/index.js +121 -45
- package/qwen-extension.json +1 -1
- package/run.mjs +43 -8
- package/search.mjs +43 -8
- package/server.mjs +15 -8
package/opencode/plugin.js
CHANGED
|
@@ -40,6 +40,15 @@ function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
|
|
|
40
40
|
const queries = asked === "" ? [intent] : [intent, asked];
|
|
41
41
|
return prefix + "ctx_search({queries:[" + queries.map((q) => JSON.stringify(q)).join(",") + "], source:" + JSON.stringify(handle) + "}) searches the whole output (" + bytes5 + " B).";
|
|
42
42
|
}
|
|
43
|
+
function SUBAGENT_HANDLE_LINE(handle, bytes5, read3) {
|
|
44
|
+
return "The full output (" + bytes5 + " B) is stored as " + handle + "; above is the best-matching part." + (read3 ? " Read the file with offset and limit for other lines." : "");
|
|
45
|
+
}
|
|
46
|
+
function SEARCH_TWIN_LINE(searchPath, handle, terms, projectDir) {
|
|
47
|
+
return " Or run: node " + shellWord(searchPath) + " " + handle + " " + shellWord(terms) + " " + shellWord(projectDir);
|
|
48
|
+
}
|
|
49
|
+
function shellWord(s) {
|
|
50
|
+
return "'" + s.split("'").join("'\\''") + "'";
|
|
51
|
+
}
|
|
43
52
|
var HANDLE_PROMPT_WORDS = 3;
|
|
44
53
|
var MAX_CHUNK_BYTES = 4096;
|
|
45
54
|
var SEARCH_PAGE_SIZE = 20;
|
|
@@ -224,6 +233,8 @@ var CANCELLED_LINE = "Cancelled.";
|
|
|
224
233
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
225
234
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
226
235
|
var RUN_LABEL_PREFIX = "run.mjs:";
|
|
236
|
+
var SEARCH_WRAPPER_FILE = "search.mjs";
|
|
237
|
+
var RUN_WRAPPER_AGENT = "claude-code";
|
|
227
238
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
228
239
|
var NODE_MIN = "24.15.0";
|
|
229
240
|
var DATA_ROOT = "~/.context-mode";
|
|
@@ -233,6 +244,7 @@ var REQUIRE_SECURITY_ENV = "CONTEXT_MODE_REQUIRE_SECURITY";
|
|
|
233
244
|
var HOST_CONFIG_DIR_NAME = ".claude";
|
|
234
245
|
var AGENTS_DIR_NAME = "agents";
|
|
235
246
|
var AGENT_FILE_EXT = ".md";
|
|
247
|
+
var SYNCED_PLUGINS_DIR_NAME = "synced";
|
|
236
248
|
var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
237
249
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
238
250
|
var PLUGIN_AGENT_SEPARATOR = ":";
|
|
@@ -468,7 +480,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
468
480
|
var DECISION_OPTION_KEY = "option";
|
|
469
481
|
var DECISION_LABEL_JOIN = " | ";
|
|
470
482
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
471
|
-
var BUNDLE_SHA = true ? "
|
|
483
|
+
var BUNDLE_SHA = true ? "9c0c8a6d580cf4a310ff2d3138ad3c24f6a1dcde" : void 0;
|
|
472
484
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
473
485
|
var DOCTOR_LABEL = Object.freeze({
|
|
474
486
|
D1: "version",
|
|
@@ -3680,7 +3692,15 @@ function resolveConfigDir(env) {
|
|
|
3680
3692
|
}
|
|
3681
3693
|
|
|
3682
3694
|
// src/core/policy/subagent.ts
|
|
3683
|
-
var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
|
|
3695
|
+
var { readFileSync: readFileSync2, readdirSync: readdirSync2 } = process.getBuiltinModule("node:fs");
|
|
3696
|
+
var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments", "ArtifactData", "ArtifactCheck", "ExitPlanMode", "Edit", "Write", "NotebookEdit"]);
|
|
3697
|
+
var CLAUDE_CODE_BUILT_INS = Object.freeze({
|
|
3698
|
+
"general-purpose": { tools: null, disallowed: [] },
|
|
3699
|
+
fork: { tools: null, disallowed: [] },
|
|
3700
|
+
Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3701
|
+
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
|
|
3702
|
+
});
|
|
3703
|
+
var BUILT_IN_AGENT = "claude-code";
|
|
3684
3704
|
function isSubagentCall(ev) {
|
|
3685
3705
|
return ev.agentId !== void 0 && ev.agentId !== "";
|
|
3686
3706
|
}
|
|
@@ -3697,7 +3717,7 @@ function toolSetForAgentType(ev, src) {
|
|
|
3697
3717
|
const row5 = getAdapter(ev.agent);
|
|
3698
3718
|
if (src.manifestTools !== void 0) return unique(src.manifestTools.map((n) => norm(row5, n)));
|
|
3699
3719
|
const type = ev.agentType ?? "";
|
|
3700
|
-
const def = findDef(type, src);
|
|
3720
|
+
const def = findDef(type, src) ?? builtIn(ev.agent, type);
|
|
3701
3721
|
if (def === null) return null;
|
|
3702
3722
|
const tools = (def.tools ?? allKnownToolNames(row5)).map((n) => norm(row5, n));
|
|
3703
3723
|
const deny2 = def.disallowed.map((n) => norm(row5, n));
|
|
@@ -3725,6 +3745,11 @@ function findDef(type, src) {
|
|
|
3725
3745
|
}
|
|
3726
3746
|
return null;
|
|
3727
3747
|
}
|
|
3748
|
+
function builtIn(agent, type) {
|
|
3749
|
+
if (agent !== BUILT_IN_AGENT || !Object.prototype.hasOwnProperty.call(CLAUDE_CODE_BUILT_INS, type)) return null;
|
|
3750
|
+
const d = CLAUDE_CODE_BUILT_INS[type];
|
|
3751
|
+
return { tools: d.tools, disallowed: [...d.disallowed] };
|
|
3752
|
+
}
|
|
3728
3753
|
function safeType(type) {
|
|
3729
3754
|
if (type === "" || type === "." || type === "..") return false;
|
|
3730
3755
|
if (type.indexOf("/") >= 0 || type.indexOf("\\") >= 0) return false;
|
|
@@ -3739,6 +3764,9 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3739
3764
|
const plugin = type.slice(0, cut);
|
|
3740
3765
|
const agent = type.slice(cut + PLUGIN_AGENT_SEPARATOR.length);
|
|
3741
3766
|
if (agent.indexOf(PLUGIN_AGENT_SEPARATOR) >= 0) return null;
|
|
3767
|
+
return installedPluginAgent(claudeDir, plugin, agent) ?? syncedPluginAgent(claudeDir, plugin, agent);
|
|
3768
|
+
}
|
|
3769
|
+
function installedPluginAgent(claudeDir, plugin, agent) {
|
|
3742
3770
|
let parsed;
|
|
3743
3771
|
try {
|
|
3744
3772
|
parsed = JSON.parse(hostText(readFileSync2(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
|
|
@@ -3761,6 +3789,21 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3761
3789
|
}
|
|
3762
3790
|
return null;
|
|
3763
3791
|
}
|
|
3792
|
+
function syncedPluginAgent(claudeDir, plugin, agent) {
|
|
3793
|
+
const root = join2(claudeDir, HOST_PLUGINS_DIR_NAME, SYNCED_PLUGINS_DIR_NAME);
|
|
3794
|
+
let ids;
|
|
3795
|
+
try {
|
|
3796
|
+
ids = readdirSync2(root).sort();
|
|
3797
|
+
} catch {
|
|
3798
|
+
return null;
|
|
3799
|
+
}
|
|
3800
|
+
for (const id2 of ids) {
|
|
3801
|
+
if (id2.startsWith(".")) continue;
|
|
3802
|
+
const d = readAgentFile(join2(root, id2, plugin, AGENTS_DIR_NAME, agent + AGENT_FILE_EXT));
|
|
3803
|
+
if (d !== null) return d;
|
|
3804
|
+
}
|
|
3805
|
+
return null;
|
|
3806
|
+
}
|
|
3764
3807
|
function readAgentFile(path8) {
|
|
3765
3808
|
let text;
|
|
3766
3809
|
try {
|
|
@@ -8998,18 +9041,24 @@ function bigRead(agent, input, cwd) {
|
|
|
8998
9041
|
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
8999
9042
|
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve7(cwd, p)) && !isMediaRead(agent, resolve7(cwd, p)) && !isOwnFile(agent, cwd, p));
|
|
9000
9043
|
}
|
|
9044
|
+
function allowOutput(agent) {
|
|
9045
|
+
try {
|
|
9046
|
+
return getAdapter(agent).encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
9047
|
+
} catch {
|
|
9048
|
+
return { stdout: "", exitCode: 0 };
|
|
9049
|
+
}
|
|
9050
|
+
}
|
|
9001
9051
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
9002
9052
|
const row5 = getAdapter(agent);
|
|
9003
|
-
const allow = () => row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd: "", turn: 0 }, { kind: "allow" });
|
|
9004
9053
|
try {
|
|
9005
|
-
if (!isRec(raw)) return
|
|
9006
|
-
if (!isPreTool(row5, firstString(raw, HOOK_FAIL_EVENT_KEYS))) return
|
|
9054
|
+
if (!isRec(raw)) return allowOutput(agent);
|
|
9055
|
+
if (!isPreTool(row5, firstString(raw, HOOK_FAIL_EVENT_KEYS))) return allowOutput(agent);
|
|
9007
9056
|
const name = firstString(raw, HOOK_FAIL_TOOL_KEYS);
|
|
9008
|
-
if (name === "" || name.includes(OWN_TOOL_PREFIX)) return
|
|
9057
|
+
if (name === "" || name.includes(OWN_TOOL_PREFIX)) return allowOutput(agent);
|
|
9009
9058
|
const kind = kindOf(row5, name);
|
|
9010
|
-
if (kind === null) return
|
|
9059
|
+
if (kind === null) return allowOutput(agent);
|
|
9011
9060
|
const cwd = firstString(raw, HOOK_FAIL_CWD_KEYS) || cwdFallback;
|
|
9012
|
-
if (kind === "read" && !bigRead(agent, inputOf(raw), cwd)) return
|
|
9061
|
+
if (kind === "read" && !bigRead(agent, inputOf(raw), cwd)) return allowOutput(agent);
|
|
9013
9062
|
const redirect = kind === "read" ? HOOK_FAIL_REDIRECT.read : HOOK_FAIL_REDIRECT[kind];
|
|
9014
9063
|
const reason = prefixToolNames(redirect, row5.toolNamePrefix) + "\n" + HOOK_FAIL_LINE(errorLabel(err), row5.toolNamePrefix);
|
|
9015
9064
|
return row5.encode({ event: "PreToolUse", agent, sessionId: "", cwd, turn: 0 }, { kind: "deny", reason });
|
|
@@ -9041,12 +9090,20 @@ async function handleHook(agent, raw, env) {
|
|
|
9041
9090
|
return EMPTY5;
|
|
9042
9091
|
}
|
|
9043
9092
|
const row5 = getAdapter(agent);
|
|
9044
|
-
const
|
|
9093
|
+
const report2 = (stage, err, line) => {
|
|
9045
9094
|
logHookError(env, agent, stage, err);
|
|
9046
9095
|
process.stderr.write(line ?? "hooks: " + stage + " failed: " + message(err) + "\n");
|
|
9096
|
+
};
|
|
9097
|
+
const fail7 = (stage, err, line) => {
|
|
9098
|
+
report2(stage, err, line);
|
|
9047
9099
|
return failureOutput(agent, raw, err);
|
|
9048
9100
|
};
|
|
9049
|
-
if (nodeTooOld(process.version))
|
|
9101
|
+
if (nodeTooOld(process.version)) {
|
|
9102
|
+
const err = new CtxError("NODE_TOO_OLD", { v: process.version });
|
|
9103
|
+
if (row5.installMode === "in-process") return fail7("node", err);
|
|
9104
|
+
report2("node", err);
|
|
9105
|
+
return allowOutput(agent);
|
|
9106
|
+
}
|
|
9050
9107
|
let ev;
|
|
9051
9108
|
try {
|
|
9052
9109
|
fault(env, "decode");
|
|
@@ -9377,14 +9434,21 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9377
9434
|
if (result.keep === true) return ALLOW2;
|
|
9378
9435
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9379
9436
|
let label2;
|
|
9437
|
+
let caller = { ctx: true, shell: true, read: false };
|
|
9380
9438
|
if (isSubagentCall(ev)) {
|
|
9381
|
-
const
|
|
9382
|
-
|
|
9383
|
-
|
|
9439
|
+
const set3 = toolSetForAgentType(ev, toolSetSources(ev, project, env));
|
|
9440
|
+
const subCase = pickSubagentCase(ev, set3);
|
|
9441
|
+
const has3 = (names) => set3 !== null && names.some((n) => set3.includes(n));
|
|
9442
|
+
caller = {
|
|
9443
|
+
ctx: subCase === "A",
|
|
9444
|
+
shell: has3(row5.nativeTools.shell),
|
|
9445
|
+
read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
|
|
9446
|
+
};
|
|
9447
|
+
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9384
9448
|
} else {
|
|
9385
9449
|
label2 = mainLabel(tool, ev);
|
|
9386
9450
|
}
|
|
9387
|
-
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ??
|
|
9451
|
+
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url, tool.name].map(str2).find((v) => v.trim() !== "") ?? tool.canonicalName;
|
|
9388
9452
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
9389
9453
|
const db = await openDb(project);
|
|
9390
9454
|
let sourceId;
|
|
@@ -9398,12 +9462,17 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9398
9462
|
const handle = sourceHandle(sourceId);
|
|
9399
9463
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
9400
9464
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
9401
|
-
const handleLine = REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text));
|
|
9465
|
+
const handleLine = caller.ctx ? REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text)) : SUBAGENT_HANDLE_LINE(handle, result.bytes, caller.read);
|
|
9402
9466
|
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
9467
|
+
const pointer = handleLine + (caller.shell && ev.agent === RUN_WRAPPER_AGENT ? searchTwin(handle, intent, project) : "");
|
|
9403
9468
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
9404
|
-
if (digest !== null) return { kind: "replace", output: replaceOutput(digest,
|
|
9469
|
+
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, pointer) };
|
|
9405
9470
|
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
9406
|
-
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text,
|
|
9471
|
+
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, pointer) : selected.text };
|
|
9472
|
+
}
|
|
9473
|
+
function searchTwin(handle, intent, project) {
|
|
9474
|
+
const terms = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "" : intent;
|
|
9475
|
+
return SEARCH_TWIN_LINE(join8(dirname4(process.argv[1] ?? ""), SEARCH_WRAPPER_FILE), handle, terms, project.worktree);
|
|
9407
9476
|
}
|
|
9408
9477
|
function boundedRead(tool) {
|
|
9409
9478
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
@@ -20689,6 +20758,13 @@ function pathEntries(value, platform = process.platform, delimiter2 = platform =
|
|
|
20689
20758
|
const win = platform === "win32";
|
|
20690
20759
|
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
20691
20760
|
}
|
|
20761
|
+
function envValue(env, name, platform = process.platform) {
|
|
20762
|
+
const exact = env[name];
|
|
20763
|
+
if (exact !== void 0 || platform !== "win32") return exact;
|
|
20764
|
+
const upper = name.toUpperCase();
|
|
20765
|
+
const key = Object.keys(env).find((k) => k.toUpperCase() === upper);
|
|
20766
|
+
return key === void 0 ? void 0 : env[key];
|
|
20767
|
+
}
|
|
20692
20768
|
|
|
20693
20769
|
// src/core/sandbox/runtimes.ts
|
|
20694
20770
|
var PATHEXT_SEPARATOR = ";";
|
|
@@ -20732,8 +20808,8 @@ function isRunnable(full) {
|
|
|
20732
20808
|
}
|
|
20733
20809
|
function findRuntime(lang, env = process.env) {
|
|
20734
20810
|
if (isWin() && WIN_SHELL_LANGS.includes(lang)) return findGitBash(env);
|
|
20735
|
-
const dirs = pathEntries(env
|
|
20736
|
-
const pathExt = isWin() ? (env
|
|
20811
|
+
const dirs = pathEntries(envValue(env, "PATH") ?? "", process.platform, path.delimiter);
|
|
20812
|
+
const pathExt = isWin() ? (envValue(env, "PATHEXT") ?? PATHEXT_DEFAULT).split(PATHEXT_SEPARATOR).filter((e) => e !== "") : [];
|
|
20737
20813
|
const names = candidates(lang);
|
|
20738
20814
|
let shim = null;
|
|
20739
20815
|
for (const dir of dirs) {
|
|
@@ -20894,7 +20970,7 @@ function runProcess(argv, o) {
|
|
|
20894
20970
|
}
|
|
20895
20971
|
|
|
20896
20972
|
// src/core/index/auto-memory.ts
|
|
20897
|
-
import { readdirSync as
|
|
20973
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
|
|
20898
20974
|
import { join as join9 } from "node:path";
|
|
20899
20975
|
var MEMORY_FILES = Object.freeze([
|
|
20900
20976
|
Object.freeze(["CLAUDE.md"]),
|
|
@@ -20909,7 +20985,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20909
20985
|
var MD = ".md";
|
|
20910
20986
|
function steeringFiles(worktree) {
|
|
20911
20987
|
try {
|
|
20912
|
-
return
|
|
20988
|
+
return readdirSync3(join9(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20913
20989
|
} catch {
|
|
20914
20990
|
return [];
|
|
20915
20991
|
}
|
|
@@ -21503,7 +21579,7 @@ var ctxBatch = Object.freeze({
|
|
|
21503
21579
|
});
|
|
21504
21580
|
|
|
21505
21581
|
// src/core/tools/doctor.ts
|
|
21506
|
-
import { readdirSync as
|
|
21582
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync16, existsSync as existsSync16 } from "node:fs";
|
|
21507
21583
|
import { basename as basename5, join as join19 } from "node:path";
|
|
21508
21584
|
|
|
21509
21585
|
// src/core/ops/bundle-dir.ts
|
|
@@ -21529,11 +21605,11 @@ function ownBundleDir() {
|
|
|
21529
21605
|
}
|
|
21530
21606
|
|
|
21531
21607
|
// src/core/ops/doctor-config.ts
|
|
21532
|
-
import { existsSync as existsSync9, readdirSync as
|
|
21608
|
+
import { existsSync as existsSync9, readdirSync as readdirSync6, readFileSync as readFileSync11 } from "node:fs";
|
|
21533
21609
|
import { dirname as dirname8, isAbsolute as isAbsolute4, join as join14, resolve as resolve9 } from "node:path";
|
|
21534
21610
|
|
|
21535
21611
|
// src/core/ops/detect-v1.ts
|
|
21536
|
-
import { existsSync as existsSync6, opendirSync, readdirSync as
|
|
21612
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync4, readFileSync as readFileSync8 } from "node:fs";
|
|
21537
21613
|
import { tmpdir } from "node:os";
|
|
21538
21614
|
import { join as join12 } from "node:path";
|
|
21539
21615
|
|
|
@@ -24270,7 +24346,7 @@ function scanVscode(agentHome, project, out) {
|
|
|
24270
24346
|
}
|
|
24271
24347
|
function jsonFiles(dir) {
|
|
24272
24348
|
try {
|
|
24273
|
-
return
|
|
24349
|
+
return readdirSync4(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
24274
24350
|
} catch {
|
|
24275
24351
|
return [];
|
|
24276
24352
|
}
|
|
@@ -24403,7 +24479,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24403
24479
|
}
|
|
24404
24480
|
|
|
24405
24481
|
// src/core/ops/plugin-root.ts
|
|
24406
|
-
import { existsSync as existsSync7, readdirSync as
|
|
24482
|
+
import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
24407
24483
|
import { dirname as dirname7, isAbsolute as isAbsolute3, join as join13, sep as sep4 } from "node:path";
|
|
24408
24484
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24409
24485
|
function missing(agent, path8) {
|
|
@@ -24503,7 +24579,7 @@ function marketplaceRoot(adapter, env, worktree) {
|
|
|
24503
24579
|
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join13(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24504
24580
|
const pattern = join13(cache, "*", PLUGIN_NAME);
|
|
24505
24581
|
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24506
|
-
const found =
|
|
24582
|
+
const found = readdirSync5(cache).sort().map((marketplace) => join13(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24507
24583
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24508
24584
|
return found[0];
|
|
24509
24585
|
}
|
|
@@ -24715,10 +24791,10 @@ function codexNativeDir(env, home) {
|
|
|
24715
24791
|
const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24716
24792
|
if (!existsSync9(cache)) return null;
|
|
24717
24793
|
const found = [];
|
|
24718
|
-
for (const market of
|
|
24794
|
+
for (const market of readdirSync6(cache)) {
|
|
24719
24795
|
const plugin = join14(cache, market, SERVER_KEY);
|
|
24720
24796
|
if (!existsSync9(plugin)) continue;
|
|
24721
|
-
for (const version2 of
|
|
24797
|
+
for (const version2 of readdirSync6(plugin).sort()) {
|
|
24722
24798
|
const dir = join14(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24723
24799
|
if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24724
24800
|
}
|
|
@@ -24821,7 +24897,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
24821
24897
|
const pdir = join14(dir, OPENCODE_PLUGINS_DIR);
|
|
24822
24898
|
let names;
|
|
24823
24899
|
try {
|
|
24824
|
-
names =
|
|
24900
|
+
names = readdirSync6(pdir);
|
|
24825
24901
|
} catch {
|
|
24826
24902
|
continue;
|
|
24827
24903
|
}
|
|
@@ -27124,7 +27200,7 @@ var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
|
27124
27200
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
27125
27201
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
27126
27202
|
function envGet(env, k) {
|
|
27127
|
-
return
|
|
27203
|
+
return envValue(env, k, "win32");
|
|
27128
27204
|
}
|
|
27129
27205
|
function whichBin(bin, env, platform = process.platform) {
|
|
27130
27206
|
const get = (k) => envGet(env, k);
|
|
@@ -27609,7 +27685,7 @@ import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4
|
|
|
27609
27685
|
import { basename as basename4, dirname as dirname9, join as join17 } from "node:path";
|
|
27610
27686
|
|
|
27611
27687
|
// src/core/store/owners.ts
|
|
27612
|
-
import { mkdirSync as mkdirSync5, readdirSync as
|
|
27688
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync7, readFileSync as readFileSync14, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27613
27689
|
import { basename as basename3, join as join16 } from "node:path";
|
|
27614
27690
|
function ownersDir(configDir, projectKey) {
|
|
27615
27691
|
return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -27632,7 +27708,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27632
27708
|
const dir = ownersDir(configDir, projectKey);
|
|
27633
27709
|
let names;
|
|
27634
27710
|
try {
|
|
27635
|
-
names =
|
|
27711
|
+
names = readdirSync7(dir);
|
|
27636
27712
|
} catch (err) {
|
|
27637
27713
|
if (errCode2(err) === "ENOENT") return [];
|
|
27638
27714
|
throw err;
|
|
@@ -27867,7 +27943,7 @@ function gitVersion(env) {
|
|
|
27867
27943
|
function onPath(env, tool) {
|
|
27868
27944
|
const names = process.platform === "win32" ? [tool + EXE_SUFFIX, tool + ".cmd", tool] : [tool];
|
|
27869
27945
|
const out = [];
|
|
27870
|
-
for (const dir of (env
|
|
27946
|
+
for (const dir of (envValue(env, "PATH") ?? "").split(delimiter)) {
|
|
27871
27947
|
if (dir === "") continue;
|
|
27872
27948
|
for (const n of names) if (existsSync15(join18(dir, n))) {
|
|
27873
27949
|
out.push(join18(dir, n));
|
|
@@ -28068,7 +28144,7 @@ async function hookRow(ctx, adapter, host) {
|
|
|
28068
28144
|
function ownServerId(configDir, projectKey) {
|
|
28069
28145
|
const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
28070
28146
|
if (!existsSync16(dir)) return "";
|
|
28071
|
-
for (const name of
|
|
28147
|
+
for (const name of readdirSync8(dir)) {
|
|
28072
28148
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
28073
28149
|
if (readFileSync16(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
28074
28150
|
}
|
|
@@ -28375,7 +28451,7 @@ import { existsSync as existsSync18, readFileSync as readFileSync18, statSync as
|
|
|
28375
28451
|
import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28376
28452
|
|
|
28377
28453
|
// src/core/index/walk.ts
|
|
28378
|
-
import { readdirSync as
|
|
28454
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
28379
28455
|
import { join as join21 } from "node:path";
|
|
28380
28456
|
var GITIGNORE = ".gitignore";
|
|
28381
28457
|
var GIT_DIR = ".git";
|
|
@@ -28390,7 +28466,7 @@ function walkDir(root, containmentRoot) {
|
|
|
28390
28466
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
28391
28467
|
let entries;
|
|
28392
28468
|
try {
|
|
28393
|
-
entries =
|
|
28469
|
+
entries = readdirSync9(abs, { withFileTypes: true });
|
|
28394
28470
|
} catch {
|
|
28395
28471
|
return;
|
|
28396
28472
|
}
|
|
@@ -28583,15 +28659,15 @@ function parseUrl(raw) {
|
|
|
28583
28659
|
if (u.protocol !== "http:" && u.protocol !== "https:") throw fail6("ERR_INVALID_PROTOCOL");
|
|
28584
28660
|
return u;
|
|
28585
28661
|
}
|
|
28586
|
-
function
|
|
28662
|
+
function envValue2(upper) {
|
|
28587
28663
|
const v = process.env[upper] ?? process.env[upper.toLowerCase()];
|
|
28588
28664
|
return v === void 0 || v.trim() === "" ? void 0 : v.trim();
|
|
28589
28665
|
}
|
|
28590
28666
|
function pickProxy(u) {
|
|
28591
|
-
const raw =
|
|
28667
|
+
const raw = envValue2(u.protocol === "https:" ? "HTTPS_PROXY" : "HTTP_PROXY");
|
|
28592
28668
|
if (raw === void 0) return void 0;
|
|
28593
28669
|
const host = bare(u.hostname).toLowerCase();
|
|
28594
|
-
for (const item of (
|
|
28670
|
+
for (const item of (envValue2("NO_PROXY") ?? "").split(",")) {
|
|
28595
28671
|
let entry = item.trim().toLowerCase();
|
|
28596
28672
|
if (entry.startsWith(".")) entry = entry.slice(1);
|
|
28597
28673
|
if (entry !== "" && (host === entry || host.endsWith("." + entry))) return void 0;
|
|
@@ -33193,7 +33269,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
33193
33269
|
}
|
|
33194
33270
|
|
|
33195
33271
|
// src/core/ops/uninstall.ts
|
|
33196
|
-
import { existsSync as existsSync20, readdirSync as
|
|
33272
|
+
import { existsSync as existsSync20, readdirSync as readdirSync10, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33197
33273
|
import { join as join24 } from "node:path";
|
|
33198
33274
|
function row2(area, before, after) {
|
|
33199
33275
|
return { area, before, after };
|
|
@@ -33309,7 +33385,7 @@ function removeProjectData(configDir, projectKey) {
|
|
|
33309
33385
|
const dir = join24(projects, projectKey);
|
|
33310
33386
|
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
33311
33387
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
33312
|
-
for (const name of
|
|
33388
|
+
for (const name of readdirSync10(dir)) {
|
|
33313
33389
|
if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
|
|
33314
33390
|
}
|
|
33315
33391
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
@@ -33853,11 +33929,13 @@ async function setup(ctx) {
|
|
|
33853
33929
|
await ctx.session.hook("prompt", async (p) => {
|
|
33854
33930
|
await hooks["chat.message"]({ sessionID: p.sessionID }, { parts: [{ type: "text", text: p.prompt?.text ?? "" }] });
|
|
33855
33931
|
});
|
|
33856
|
-
|
|
33932
|
+
const injectSystem = async (c) => {
|
|
33857
33933
|
const system = [];
|
|
33858
33934
|
await hooks["experimental.chat.system.transform"]({ sessionID: c.sessionID }, { system });
|
|
33859
33935
|
for (const text of system) if (!c.system.some((p) => p.text === text)) c.system.push({ type: "text", text });
|
|
33860
|
-
}
|
|
33936
|
+
};
|
|
33937
|
+
await ctx.session.hook("context", injectSystem);
|
|
33938
|
+
await ctx.session.hook("generate", injectSystem);
|
|
33861
33939
|
await ctx.session.hook("compaction", async (c) => {
|
|
33862
33940
|
await hooks["experimental.session.compacting"]({ sessionID: c.sessionID });
|
|
33863
33941
|
});
|
package/package.json
CHANGED