context-mode 2.0.0-next.23 → 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 +138 -134
- package/SHA256SUMS +15 -15
- package/cli.mjs +72 -31
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +63 -61
- package/opencode/plugin.js +662 -282
- package/package.json +1 -1
- package/pi/index.js +740 -360
- package/qwen-extension.json +1 -1
- package/run.mjs +30 -24
- package/search.mjs +30 -24
- package/server.mjs +695 -332
package/cli.mjs
CHANGED
|
@@ -242,6 +242,8 @@ var NODE_MIN = "24.15.0";
|
|
|
242
242
|
var DATA_ROOT = "~/.context-mode";
|
|
243
243
|
var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
244
244
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
245
|
+
var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
|
|
246
|
+
var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
|
|
245
247
|
var MCP_HINT_EVERY_DEFAULT = 10;
|
|
246
248
|
function readHintEvery(raw) {
|
|
247
249
|
if (raw === void 0 || raw.trim() === "") return MCP_HINT_EVERY_DEFAULT;
|
|
@@ -1596,7 +1598,7 @@ Examples:
|
|
|
1596
1598
|
};
|
|
1597
1599
|
|
|
1598
1600
|
// src/cli/commands.ts
|
|
1599
|
-
import { spawnSync as
|
|
1601
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
1600
1602
|
import { createHash as createHash2 } from "node:crypto";
|
|
1601
1603
|
import { existsSync as existsSync13, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
1602
1604
|
import os from "node:os";
|
|
@@ -4418,7 +4420,7 @@ ${i2}
|
|
|
4418
4420
|
}).prompt();
|
|
4419
4421
|
|
|
4420
4422
|
// src/core/project/config-dir.ts
|
|
4421
|
-
import { join as join2, posix, win32 } from "node:path";
|
|
4423
|
+
import { basename, dirname as dirname2, join as join2, posix, resolve, win32 } from "node:path";
|
|
4422
4424
|
|
|
4423
4425
|
// src/core/contracts/errors.ts
|
|
4424
4426
|
var ERROR_TEXT = Object.freeze({
|
|
@@ -4554,7 +4556,7 @@ import path3 from "node:path";
|
|
|
4554
4556
|
|
|
4555
4557
|
// src/core/ops/host-config.ts
|
|
4556
4558
|
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
4557
|
-
import { dirname as
|
|
4559
|
+
import { dirname as dirname3, join as join3 } from "node:path";
|
|
4558
4560
|
|
|
4559
4561
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4560
4562
|
var KEYS2 = {
|
|
@@ -7371,7 +7373,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7371
7373
|
|
|
7372
7374
|
// src/core/ops/plugin-root.ts
|
|
7373
7375
|
import { existsSync as existsSync4, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
7374
|
-
import { dirname as
|
|
7376
|
+
import { dirname as dirname4, isAbsolute, join as join5, sep } from "node:path";
|
|
7375
7377
|
import { fileURLToPath } from "node:url";
|
|
7376
7378
|
|
|
7377
7379
|
// src/core/ops/doctor-config.ts
|
|
@@ -8017,7 +8019,7 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8017
8019
|
import { createHash } from "node:crypto";
|
|
8018
8020
|
import { existsSync as existsSync11, realpathSync as realpathSync4 } from "node:fs";
|
|
8019
8021
|
import path10 from "node:path";
|
|
8020
|
-
import { spawn } from "node:child_process";
|
|
8022
|
+
import { spawn, spawnSync as spawnSync2 } from "node:child_process";
|
|
8021
8023
|
|
|
8022
8024
|
// src/setup/spawn-bin.ts
|
|
8023
8025
|
import { spawnSync } from "node:child_process";
|
|
@@ -8155,7 +8157,7 @@ function askCodexHome(env) {
|
|
|
8155
8157
|
}
|
|
8156
8158
|
return void 0;
|
|
8157
8159
|
}
|
|
8158
|
-
function sameDir(a2, b3, platform) {
|
|
8160
|
+
function sameDir(a2, b3, platform = process.platform) {
|
|
8159
8161
|
if (platform !== "win32") return path10.posix.normalize(a2) === path10.posix.normalize(b3);
|
|
8160
8162
|
const norm = (p3) => {
|
|
8161
8163
|
const bare = p3.startsWith(WIN_VERBATIM_PREFIX) ? p3.slice(WIN_VERBATIM_PREFIX.length) : p3;
|
|
@@ -8189,6 +8191,7 @@ function codexTrustEntries(hooksFile, doc, command, env) {
|
|
|
8189
8191
|
return out2;
|
|
8190
8192
|
}
|
|
8191
8193
|
var LIST_TIMEOUT_MS = 15e3;
|
|
8194
|
+
var EXIT_GRACE_MS = 5e3;
|
|
8192
8195
|
var PLUGIN_SOURCE = "plugin";
|
|
8193
8196
|
var TRUSTED = "trusted";
|
|
8194
8197
|
function pluginHooksFromReply(m3, pluginId) {
|
|
@@ -8205,27 +8208,45 @@ function pluginHooksFromReply(m3, pluginId) {
|
|
|
8205
8208
|
}
|
|
8206
8209
|
return out2;
|
|
8207
8210
|
}
|
|
8208
|
-
function listPluginHooks(env, pluginId, cwd) {
|
|
8211
|
+
async function listPluginHooks(env, pluginId, cwd) {
|
|
8212
|
+
const r2 = await askPluginHooks(env, pluginId, cwd);
|
|
8213
|
+
return r2.kind === "list" ? r2.hooks : void 0;
|
|
8214
|
+
}
|
|
8215
|
+
function askPluginHooks(env, pluginId, cwd) {
|
|
8209
8216
|
const bin = whichBin("codex", env);
|
|
8210
|
-
if (!bin) return Promise.resolve(
|
|
8211
|
-
return new Promise((
|
|
8217
|
+
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
8218
|
+
return new Promise((resolve2) => {
|
|
8219
|
+
let asked;
|
|
8220
|
+
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
8212
8221
|
let f2;
|
|
8213
8222
|
try {
|
|
8214
8223
|
f2 = spawnForm(bin, ["app-server"], env);
|
|
8215
8224
|
} catch {
|
|
8216
|
-
|
|
8225
|
+
resolve2({ kind: "silent" });
|
|
8217
8226
|
return;
|
|
8218
8227
|
}
|
|
8219
8228
|
const child = spawn(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
8220
8229
|
let buf = "";
|
|
8221
8230
|
let done = false;
|
|
8231
|
+
let exited = false;
|
|
8232
|
+
let result;
|
|
8233
|
+
const settle = () => {
|
|
8234
|
+
clearTimeout(grace);
|
|
8235
|
+
resolve2(done_(result));
|
|
8236
|
+
};
|
|
8237
|
+
let grace;
|
|
8222
8238
|
const finish2 = (v) => {
|
|
8223
8239
|
if (done) return;
|
|
8224
8240
|
done = true;
|
|
8225
8241
|
clearTimeout(timer);
|
|
8242
|
+
result = v;
|
|
8226
8243
|
child.stdin.destroy();
|
|
8227
|
-
|
|
8228
|
-
|
|
8244
|
+
if (exited) {
|
|
8245
|
+
settle();
|
|
8246
|
+
return;
|
|
8247
|
+
}
|
|
8248
|
+
grace = setTimeout(settle, EXIT_GRACE_MS);
|
|
8249
|
+
stopTree(child.pid, () => child.kill());
|
|
8229
8250
|
};
|
|
8230
8251
|
const timer = setTimeout(() => finish2(void 0), LIST_TIMEOUT_MS);
|
|
8231
8252
|
const send = (o2) => {
|
|
@@ -8236,7 +8257,11 @@ function listPluginHooks(env, pluginId, cwd) {
|
|
|
8236
8257
|
}
|
|
8237
8258
|
};
|
|
8238
8259
|
child.on("error", () => finish2(void 0));
|
|
8239
|
-
child.on("close", () =>
|
|
8260
|
+
child.on("close", () => {
|
|
8261
|
+
exited = true;
|
|
8262
|
+
if (done) settle();
|
|
8263
|
+
else finish2(void 0);
|
|
8264
|
+
});
|
|
8240
8265
|
child.stdin.on("error", () => finish2(void 0));
|
|
8241
8266
|
child.stdout.setEncoding("utf8");
|
|
8242
8267
|
child.stdout.on("data", (d) => {
|
|
@@ -8252,6 +8277,7 @@ function listPluginHooks(env, pluginId, cwd) {
|
|
|
8252
8277
|
}
|
|
8253
8278
|
if (!isObj3(m3)) continue;
|
|
8254
8279
|
if (m3.id === 1) {
|
|
8280
|
+
asked = codexHomeFromReply(line);
|
|
8255
8281
|
send({ method: "initialized" });
|
|
8256
8282
|
send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
|
|
8257
8283
|
} else if (m3.id === 2) finish2(pluginHooksFromReply(m3, pluginId));
|
|
@@ -8260,6 +8286,15 @@ function listPluginHooks(env, pluginId, cwd) {
|
|
|
8260
8286
|
send({ id: 1, method: "initialize", params: { clientInfo: { name: "context-mode-setup", version: "2.0.0" } } });
|
|
8261
8287
|
});
|
|
8262
8288
|
}
|
|
8289
|
+
function stopTree(pid, kill) {
|
|
8290
|
+
if (process.platform === "win32" && pid !== void 0) {
|
|
8291
|
+
try {
|
|
8292
|
+
spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
|
|
8293
|
+
} catch {
|
|
8294
|
+
}
|
|
8295
|
+
}
|
|
8296
|
+
kill();
|
|
8297
|
+
}
|
|
8263
8298
|
var HASH_PART_SEP = "/";
|
|
8264
8299
|
function hookHashOf(currentHash) {
|
|
8265
8300
|
const cut = currentHash.indexOf(HASH_PART_SEP);
|
|
@@ -8268,6 +8303,13 @@ function hookHashOf(currentHash) {
|
|
|
8268
8303
|
function pluginTrustEntries(hooks) {
|
|
8269
8304
|
return hooks.filter((h2) => !h2.trusted).map((h2) => [[...TRUST_KEY, h2.key], { [HASH_FIELD]: hookHashOf(h2.hash) }]);
|
|
8270
8305
|
}
|
|
8306
|
+
var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
8307
|
+
var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
|
|
8308
|
+
function untrustedPluginHooksDetail(hooks) {
|
|
8309
|
+
const bad = hooks.filter((h2) => !h2.trusted);
|
|
8310
|
+
if (!bad.length) return void 0;
|
|
8311
|
+
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
8312
|
+
}
|
|
8271
8313
|
|
|
8272
8314
|
// src/setup/copilot-hooks.ts
|
|
8273
8315
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -8314,12 +8356,12 @@ function frame(buf) {
|
|
|
8314
8356
|
function listCopilotHooks(env, file, cwd) {
|
|
8315
8357
|
const bin = whichBin("copilot", env);
|
|
8316
8358
|
if (!bin) return Promise.resolve(void 0);
|
|
8317
|
-
return new Promise((
|
|
8359
|
+
return new Promise((resolve2) => {
|
|
8318
8360
|
let f2;
|
|
8319
8361
|
try {
|
|
8320
8362
|
f2 = spawnForm(bin, ["--server", "--stdio", "--no-auto-update"], env);
|
|
8321
8363
|
} catch {
|
|
8322
|
-
|
|
8364
|
+
resolve2(void 0);
|
|
8323
8365
|
return;
|
|
8324
8366
|
}
|
|
8325
8367
|
const child = spawn2(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -8331,7 +8373,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8331
8373
|
clearTimeout(timer);
|
|
8332
8374
|
child.stdin.destroy();
|
|
8333
8375
|
child.kill();
|
|
8334
|
-
|
|
8376
|
+
resolve2(v);
|
|
8335
8377
|
};
|
|
8336
8378
|
const timer = setTimeout(() => finish2(void 0), ASK_TIMEOUT_MS2);
|
|
8337
8379
|
child.on("error", () => finish2(void 0));
|
|
@@ -8365,7 +8407,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8365
8407
|
}
|
|
8366
8408
|
|
|
8367
8409
|
// src/setup/engine.ts
|
|
8368
|
-
import { spawn as spawn3, spawnSync as
|
|
8410
|
+
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
8369
8411
|
import { closeSync, existsSync as existsSync12, mkdirSync as mkdirSync3, mkdtempSync, openSync, readFileSync as readFileSync9, readSync, readdirSync as readdirSync5, realpathSync as realpathSync6, rmSync, statSync as statSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
8370
8412
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8371
8413
|
import path12 from "node:path";
|
|
@@ -8840,7 +8882,7 @@ function copyCheck(row, pkgDir) {
|
|
|
8840
8882
|
return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${old}, the installed package is ${pkg}; run ${c3.bin} ${c3.refresh.join(" ")}` };
|
|
8841
8883
|
}
|
|
8842
8884
|
function mcpCheck(cmd, env) {
|
|
8843
|
-
return new Promise((
|
|
8885
|
+
return new Promise((resolve2) => {
|
|
8844
8886
|
const child = spawn3(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
8845
8887
|
const reap = () => {
|
|
8846
8888
|
child.kill();
|
|
@@ -8852,7 +8894,7 @@ function mcpCheck(cmd, env) {
|
|
|
8852
8894
|
clearTimeout(timer);
|
|
8853
8895
|
process.off("exit", reap);
|
|
8854
8896
|
child.kill();
|
|
8855
|
-
|
|
8897
|
+
resolve2({ name: "mcp", ok, detail });
|
|
8856
8898
|
};
|
|
8857
8899
|
const timer = setTimeout(() => done(false, "no MCP answer before timeout"), VERIFY_TIMEOUT_MS);
|
|
8858
8900
|
child.on("error", (e) => done(false, e.message));
|
|
@@ -8897,7 +8939,7 @@ function hookRound(row, env) {
|
|
|
8897
8939
|
const bare = [];
|
|
8898
8940
|
for (let i2 = 0; i2 < HOOK_SAMPLES; i2++) {
|
|
8899
8941
|
let t2 = performance.now();
|
|
8900
|
-
const r2 =
|
|
8942
|
+
const r2 = spawnSync3(cmd[0], cmd.slice(1), { env, input, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8901
8943
|
wall.push(performance.now() - t2);
|
|
8902
8944
|
if (r2.status !== 0) return { name: "hook", ok: false, detail: `hook exited ${r2.status}: ${`${r2.stderr}`.trim()}` };
|
|
8903
8945
|
const out2 = `${r2.stdout}`.trim();
|
|
@@ -8910,7 +8952,7 @@ function hookRound(row, env) {
|
|
|
8910
8952
|
if (!isObj5(j2)) return { name: "hook", ok: false, detail: `hook answer is not a JSON object: ${out2.slice(0, 200)}` };
|
|
8911
8953
|
}
|
|
8912
8954
|
t2 = performance.now();
|
|
8913
|
-
|
|
8955
|
+
spawnSync3(cmd[0], ["-e", ""], { env, timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8914
8956
|
bare.push(performance.now() - t2);
|
|
8915
8957
|
}
|
|
8916
8958
|
const wallP95Ms = Math.round(p95(wall));
|
|
@@ -8974,7 +9016,7 @@ function hookRunsCheck(row, env) {
|
|
|
8974
9016
|
const sampleEnv = { ...env, HOME: home, USERPROFILE: home };
|
|
8975
9017
|
delete sampleEnv.CLAUDE_PROJECT_DIR;
|
|
8976
9018
|
const cmd = row.hookRunCommand;
|
|
8977
|
-
const r2 =
|
|
9019
|
+
const r2 = spawnSync3(cmd[0], cmd.slice(1), { env: sampleEnv, cwd: proj, input: JSON.stringify(payload), encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8978
9020
|
const bad = sampleVerdict(row.id, effect, text2, { status: r2.status, stdout: `${r2.stdout ?? ""}`, stderr: `${r2.stderr ?? ""}` });
|
|
8979
9021
|
return bad === null ? { name: "hook-runs", ok: true } : { name: "hook-runs", ok: false, detail: bad };
|
|
8980
9022
|
} finally {
|
|
@@ -9145,12 +9187,11 @@ function withHookGate(checks, detail) {
|
|
|
9145
9187
|
if (detail === void 0) return checks;
|
|
9146
9188
|
return checks.map((c3) => c3.name === "hook-registered" ? { name: c3.name, ok: false, detail } : c3);
|
|
9147
9189
|
}
|
|
9148
|
-
var UNTRUSTED_FIX =
|
|
9190
|
+
var UNTRUSTED_FIX = CODEX_UNTRUSTED_FIX;
|
|
9149
9191
|
function withHookTrust(checks, hooks, dryRun) {
|
|
9150
9192
|
if (hooks === void 0) return [...checks, { name: "hook-trust", ok: true, warn: true, detail: "codex did not report hook trust (codex app-server hooks/list)" }];
|
|
9151
|
-
const
|
|
9152
|
-
if (
|
|
9153
|
-
const detail = `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${UNTRUSTED_FIX}`;
|
|
9193
|
+
const detail = untrustedPluginHooksDetail(hooks);
|
|
9194
|
+
if (detail === void 0 || dryRun) return checks;
|
|
9154
9195
|
return checks.map((c3) => c3.name === "hook-registered" ? { name: c3.name, ok: false, detail } : c3);
|
|
9155
9196
|
}
|
|
9156
9197
|
async function copilotEnabledCheck(row, ctx) {
|
|
@@ -9671,7 +9712,7 @@ function buildIssueReport(command, res, ui) {
|
|
|
9671
9712
|
return { text: redact(lines.join("\n"), ui.ctx), title };
|
|
9672
9713
|
}
|
|
9673
9714
|
function ghReady(env) {
|
|
9674
|
-
const r2 =
|
|
9715
|
+
const r2 = spawnSync4("gh", ["auth", "status"], { env, stdio: "ignore", timeout: 1e4, windowsHide: true });
|
|
9675
9716
|
return r2.status === 0;
|
|
9676
9717
|
}
|
|
9677
9718
|
function issueUrl(title, body) {
|
|
@@ -9702,7 +9743,7 @@ async function report(ui, command, res, write) {
|
|
|
9702
9743
|
return;
|
|
9703
9744
|
}
|
|
9704
9745
|
if (file && ghReady(ui.ctx.env)) {
|
|
9705
|
-
const r2 =
|
|
9746
|
+
const r2 = spawnSync4("gh", ["issue", "create", "--repo", ISSUE_REPO, "--title", title, "--body-file", file], { env: ui.ctx.env, encoding: "utf8", timeout: 6e4, windowsHide: true });
|
|
9706
9747
|
if (r2.status === 0) {
|
|
9707
9748
|
p3.log.success(`Issue opened: ${`${r2.stdout}`.trim()}`);
|
|
9708
9749
|
return;
|
|
@@ -9925,20 +9966,20 @@ async function upgrade(ui) {
|
|
|
9925
9966
|
}
|
|
9926
9967
|
const shell = process.platform === "win32";
|
|
9927
9968
|
progress2(ui, `running ${install}`);
|
|
9928
|
-
const r2 =
|
|
9969
|
+
const r2 = spawnSync4(npm, ["i", "-g", spec], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true });
|
|
9929
9970
|
if (r2.status !== 0) {
|
|
9930
9971
|
const why = (`${r2.stderr ?? ""}`.trim().split("\n").pop() ?? "") || (r2.error?.message ?? "");
|
|
9931
9972
|
err(`FAIL upgrade: ${install} exited ${r2.status ?? "?"}${why ? `: ${why}` : ""}. Fix: ${install}`);
|
|
9932
9973
|
return EXIT_FAIL;
|
|
9933
9974
|
}
|
|
9934
|
-
const root = `${
|
|
9975
|
+
const root = `${spawnSync4(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
9935
9976
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
9936
9977
|
if (!root || !existsSync13(cli)) {
|
|
9937
9978
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
9938
9979
|
return EXIT_FAIL;
|
|
9939
9980
|
}
|
|
9940
9981
|
progress2(ui, `running context-mode ${repairArgs.join(" ")}`);
|
|
9941
|
-
const c3 =
|
|
9982
|
+
const c3 = spawnSync4(process.execPath, [cli, ...repairArgs], { env: ui.ctx.env, stdio: "inherit", windowsHide: true });
|
|
9942
9983
|
return c3.status ?? (c3.signal === "SIGINT" ? EXIT_SIGINT : EXIT_FAIL);
|
|
9943
9984
|
}
|
|
9944
9985
|
async function runCommand(cmd, args, env) {
|
package/copilot/plugin.json
CHANGED
package/gemini-extension.json
CHANGED