context-mode 2.1.10 → 2.2.1
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 +3 -3
- package/.claude-plugin/plugin.json +2 -2
- package/.codex-plugin/plugin.json +2 -2
- package/.zcode-plugin/plugin.json +2 -2
- package/README.md +98 -79
- package/SHA256SUMS +21 -20
- package/cli.mjs +438 -99
- package/copilot/plugin.json +2 -2
- package/fixtures/hook-roundtrip.json +13 -0
- package/gemini-extension.json +2 -2
- package/hook.mjs +97 -97
- package/omp/index.js +5 -0
- package/opencode/plugin.js +823 -438
- package/package.json +9 -2
- package/pi/index.js +888 -465
- package/qwen-extension.json +2 -2
- package/run.mjs +136 -47
- package/search.mjs +136 -47
- package/server.mjs +704 -419
- package/skills/ctx-doctor/SKILL.md +1 -1
- package/skills/ctx-stats/SKILL.md +1 -1
- package/skills/ctx-upgrade/SKILL.md +1 -1
package/cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
|
|
9
9
|
// src/entries/cli.ts
|
|
10
10
|
import { spawn as spawn6 } from "node:child_process";
|
|
11
|
-
import { readFileSync as
|
|
11
|
+
import { readFileSync as readFileSync16, realpathSync as realpathSync12 } from "node:fs";
|
|
12
12
|
import path16 from "node:path";
|
|
13
13
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
14
14
|
|
|
@@ -244,6 +244,7 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
244
244
|
qwen: READ_IMAGES_AND_PDF,
|
|
245
245
|
opencode: READ_IMAGES_AND_PDF,
|
|
246
246
|
pi: READ_IMAGES,
|
|
247
|
+
omp: READ_IMAGES,
|
|
247
248
|
vscode: READ_IMAGES,
|
|
248
249
|
zcode: READ_IMAGES,
|
|
249
250
|
"copilot-cli": [],
|
|
@@ -309,6 +310,7 @@ function D2_NODE_DETAIL(version) {
|
|
|
309
310
|
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
310
311
|
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
311
312
|
var D3_PARTS = Object.freeze(["MCP entry", "hook entries", "hook timeout"]);
|
|
313
|
+
var PLUGIN_CACHE_DIR_NAME = "cache";
|
|
312
314
|
var PLUGIN_MARKETPLACE_NAME = "context-mode";
|
|
313
315
|
var AGENT_HOME_DIR = Object.freeze({
|
|
314
316
|
"claude-code": [".claude"],
|
|
@@ -320,7 +322,9 @@ var AGENT_HOME_DIR = Object.freeze({
|
|
|
320
322
|
kiro: [".kiro"],
|
|
321
323
|
zcode: [".zcode"],
|
|
322
324
|
pi: [".pi"],
|
|
323
|
-
opencode: [".config", "opencode"]
|
|
325
|
+
opencode: [".config", "opencode"],
|
|
326
|
+
omp: [".omp"]
|
|
327
|
+
// ADR-0026: OMP data and plugins live under ~/.omp
|
|
324
328
|
});
|
|
325
329
|
var UPGRADE_MODES = Object.freeze(["upgrade", "uninstall"]);
|
|
326
330
|
var GIT_CLONE_ARGS = Object.freeze(["clone", "--depth", "1", "--branch"]);
|
|
@@ -364,16 +368,6 @@ var UNSUPPORTED_HOSTS = Object.freeze([
|
|
|
364
368
|
binaries: [],
|
|
365
369
|
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
366
370
|
}),
|
|
367
|
-
unsupported({
|
|
368
|
-
id: "omp",
|
|
369
|
-
name: "OMP (oh-my-pi)",
|
|
370
|
-
clientNames: ["omp-coding-agent"],
|
|
371
|
-
envVars: [],
|
|
372
|
-
pluginPaths: [],
|
|
373
|
-
configDirs: [".omp"],
|
|
374
|
-
binaries: ["omp"],
|
|
375
|
-
source: "v1.0.169:src/adapters/client-map.ts:37; detect.ts:543 (PI_CODING_AGENT_DIR is not a signal: supported Pi reads it too)"
|
|
376
|
-
}),
|
|
377
371
|
unsupported({
|
|
378
372
|
id: "openclaw",
|
|
379
373
|
name: "OpenClaw",
|
|
@@ -436,7 +430,9 @@ var HOOK_HOST_FILE = Object.freeze({
|
|
|
436
430
|
kiro: { root: "home", file: [".kiro", "hooks", "context-mode.json"], key: ["hooks"], shape: "kiro", timeoutKey: "timeout", matcher: false },
|
|
437
431
|
zcode: { root: "home", file: [".zcode", "cli", "config.json"], key: ["hooks", "events"], shape: "zcode", timeoutKey: "timeoutMs", matcher: true },
|
|
438
432
|
pi: null,
|
|
439
|
-
opencode: null
|
|
433
|
+
opencode: null,
|
|
434
|
+
omp: null
|
|
435
|
+
// ADR-0026: in-process, no hook file
|
|
440
436
|
});
|
|
441
437
|
var TOOL_HOOK_EVENTS = Object.freeze(["PreToolUse", "PostToolUse"]);
|
|
442
438
|
var KIRO_TOOL_MATCHERS = Object.freeze([["@mcp", "mcp"], ["shell", "shell"]]);
|
|
@@ -456,6 +452,8 @@ var UPGRADE_HOST_COMMAND = Object.freeze({
|
|
|
456
452
|
gemini: "gemini extensions update context-mode",
|
|
457
453
|
qwen: "qwen extensions update context-mode",
|
|
458
454
|
pi: "pi update --extensions",
|
|
455
|
+
omp: "omp plugin upgrade context-mode",
|
|
456
|
+
// ADR-0026 decision 4: OMP native update
|
|
459
457
|
opencode: "opencode plugin update",
|
|
460
458
|
"copilot-cli": "npm i -g context-mode && context-mode setup --agents copilot-cli",
|
|
461
459
|
vscode: "npm i -g context-mode && context-mode setup --agents vscode",
|
|
@@ -678,6 +676,8 @@ var NATIVE_INSTALL = Object.freeze({
|
|
|
678
676
|
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode"],
|
|
679
677
|
opencode: ["opencode plugin add context-mode"],
|
|
680
678
|
pi: ["pi install npm:context-mode"],
|
|
679
|
+
omp: ["omp plugin install context-mode"],
|
|
680
|
+
// ADR-0026 decision 4: OMP native install
|
|
681
681
|
"copilot-cli": ["npm i -g context-mode", "context-mode setup --agents copilot-cli"],
|
|
682
682
|
vscode: ["npm i -g context-mode", "context-mode setup --agents vscode"],
|
|
683
683
|
kiro: ["npm i -g context-mode", "context-mode setup --agents kiro"],
|
|
@@ -1405,6 +1405,9 @@ function readResult6(p3) {
|
|
|
1405
1405
|
if (p3.keep === true) info.keep = true;
|
|
1406
1406
|
return info;
|
|
1407
1407
|
}
|
|
1408
|
+
function decodeOmp(raw) {
|
|
1409
|
+
return { ...decode9(raw), agent: "omp" };
|
|
1410
|
+
}
|
|
1408
1411
|
function decode9(raw) {
|
|
1409
1412
|
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) throw new Error("pi: hook payload is not an object");
|
|
1410
1413
|
const p3 = raw;
|
|
@@ -1706,10 +1709,32 @@ var ADAPTERS = Object.freeze([
|
|
|
1706
1709
|
decode: decode10,
|
|
1707
1710
|
encode: encode10,
|
|
1708
1711
|
toCanonicalTool
|
|
1712
|
+
},
|
|
1713
|
+
{
|
|
1714
|
+
// ADR-0026 (D-OMP-ROW-1): OMP runs the Pi extension API in-process, so the row reuses the Pi decode, encode and
|
|
1715
|
+
// permission check; tool names stay bare. Only the entry path and the skills folder are its own.
|
|
1716
|
+
id: "omp",
|
|
1717
|
+
installMode: "in-process",
|
|
1718
|
+
projectSource: "pi:ctx.cwd",
|
|
1719
|
+
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
1720
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
1721
|
+
execReadOnlyHint: false,
|
|
1722
|
+
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
1723
|
+
compactDelivery: "pi-flag",
|
|
1724
|
+
compactSummary: "none",
|
|
1725
|
+
hookTimeoutMs: IN_PROCESS_TIMEOUT_MS,
|
|
1726
|
+
denyChannel: "deny-reason",
|
|
1727
|
+
hookChannel: { kind: "in-process", path: "omp/index.js" },
|
|
1728
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
1729
|
+
// D-OMP-SKILLS-1
|
|
1730
|
+
decode: decodeOmp,
|
|
1731
|
+
encode: encode9,
|
|
1732
|
+
checkPermission
|
|
1733
|
+
// D-OMP-FIRE-1: agent omp in rows
|
|
1709
1734
|
}
|
|
1710
1735
|
]);
|
|
1711
1736
|
var BY_ID = new Map(ADAPTERS.map((r2) => [r2.id, r2]));
|
|
1712
|
-
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode"]);
|
|
1737
|
+
var REPLACE_ROWS = /* @__PURE__ */ new Set(["claude-code", "gemini", "copilot-cli", "pi", "opencode", "omp"]);
|
|
1713
1738
|
function hasReplace(row) {
|
|
1714
1739
|
return REPLACE_ROWS.has(row.id);
|
|
1715
1740
|
}
|
|
@@ -1718,7 +1743,7 @@ function getAdapter(id) {
|
|
|
1718
1743
|
}
|
|
1719
1744
|
|
|
1720
1745
|
// src/core/contracts/agents.ts
|
|
1721
|
-
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
1746
|
+
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode", "omp"];
|
|
1722
1747
|
|
|
1723
1748
|
// src/core/ops/unsupported-host.ts
|
|
1724
1749
|
var SUPPORTED_AGENTS_LINE = `Supported agents: ${AGENT_IDS.join(", ")} (${SUPPORTED_AGENTS_DOCS_URL}).`;
|
|
@@ -1969,7 +1994,7 @@ Examples:
|
|
|
1969
1994
|
// src/cli/commands.ts
|
|
1970
1995
|
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1971
1996
|
import { createHash as createHash2 } from "node:crypto";
|
|
1972
|
-
import { existsSync as
|
|
1997
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1973
1998
|
import os from "node:os";
|
|
1974
1999
|
import path15 from "node:path";
|
|
1975
2000
|
|
|
@@ -4958,6 +4983,15 @@ function codexDirOf(env, home) {
|
|
|
4958
4983
|
const dir = env[CODEX_HOME_ENV];
|
|
4959
4984
|
return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR.codex);
|
|
4960
4985
|
}
|
|
4986
|
+
function codexPluginHomeOf(bundleDir) {
|
|
4987
|
+
let dir = resolve(bundleDir);
|
|
4988
|
+
while (dirname2(dir) !== dir) {
|
|
4989
|
+
const up = dirname2(dir);
|
|
4990
|
+
if (basename(dir) === PLUGIN_CACHE_DIR_NAME && basename(up) === HOST_PLUGINS_DIR_NAME) return dirname2(up);
|
|
4991
|
+
dir = up;
|
|
4992
|
+
}
|
|
4993
|
+
return null;
|
|
4994
|
+
}
|
|
4961
4995
|
function copilotDirOf(env, home) {
|
|
4962
4996
|
const dir = env[COPILOT_HOME_ENV];
|
|
4963
4997
|
return dir !== void 0 && dir !== "" ? dir : join2(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
@@ -5031,8 +5065,8 @@ function dataRootOf(env, home) {
|
|
|
5031
5065
|
|
|
5032
5066
|
// src/core/ops/doctor-issue.ts
|
|
5033
5067
|
import { spawnSync } from "node:child_process";
|
|
5034
|
-
import { closeSync as closeSync2, existsSync as
|
|
5035
|
-
import { delimiter, dirname as dirname8, join as
|
|
5068
|
+
import { closeSync as closeSync2, existsSync as existsSync12, fstatSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync9, readSync as readSync2, realpathSync as realpathSync6, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5069
|
+
import { delimiter, dirname as dirname8, join as join13 } from "node:path";
|
|
5036
5070
|
|
|
5037
5071
|
// src/core/hooks/fallback.ts
|
|
5038
5072
|
import { join as join5, resolve as resolve4 } from "node:path";
|
|
@@ -5194,11 +5228,11 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
5194
5228
|
`;
|
|
5195
5229
|
|
|
5196
5230
|
// src/core/store/db.ts
|
|
5197
|
-
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
5231
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, renameSync, rmSync, statSync: statSync2 } = process.getBuiltinModule("node:fs");
|
|
5198
5232
|
|
|
5199
5233
|
// src/core/ops/doctor-config.ts
|
|
5200
|
-
import { existsSync as
|
|
5201
|
-
import { dirname as dirname7, isAbsolute as
|
|
5234
|
+
import { existsSync as existsSync11, readdirSync as readdirSync5, readFileSync as readFileSync8 } from "node:fs";
|
|
5235
|
+
import { dirname as dirname7, isAbsolute as isAbsolute4, join as join12, resolve as resolve5 } from "node:path";
|
|
5202
5236
|
|
|
5203
5237
|
// src/core/ops/host-text.ts
|
|
5204
5238
|
var BOM_CODE = 65279;
|
|
@@ -7276,7 +7310,7 @@ function parseTOML(code, options) {
|
|
|
7276
7310
|
}
|
|
7277
7311
|
|
|
7278
7312
|
// src/core/ops/atomic-file.ts
|
|
7279
|
-
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7313
|
+
import { mkdirSync as mkdirSync3, renameSync as renameSync2, unlinkSync, writeFileSync } from "node:fs";
|
|
7280
7314
|
import path4 from "node:path";
|
|
7281
7315
|
function sleepSync(ms) {
|
|
7282
7316
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
@@ -7285,7 +7319,7 @@ function errCode(e) {
|
|
|
7285
7319
|
return e.code;
|
|
7286
7320
|
}
|
|
7287
7321
|
function renameWithRetry(from, to, opts = {}) {
|
|
7288
|
-
const rename = opts.rename ??
|
|
7322
|
+
const rename = opts.rename ?? renameSync2;
|
|
7289
7323
|
const sleep = opts.sleep ?? sleepSync;
|
|
7290
7324
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
7291
7325
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -8152,6 +8186,77 @@ function piSettingsGate(env, home, pkgDir, cwd) {
|
|
|
8152
8186
|
return void 0;
|
|
8153
8187
|
}
|
|
8154
8188
|
|
|
8189
|
+
// src/core/ops/doctor-env.ts
|
|
8190
|
+
import { existsSync as existsSync9, readFileSync as readFileSync6, realpathSync as realpathSync5 } from "node:fs";
|
|
8191
|
+
import { isAbsolute as isAbsolute3, join as join10, relative as relative2 } from "node:path";
|
|
8192
|
+
|
|
8193
|
+
// src/core/ops/omp-import.ts
|
|
8194
|
+
import { join as join11 } from "node:path";
|
|
8195
|
+
var { existsSync: existsSync10, readFileSync: readFileSync7 } = process.getBuiltinModule("node:fs");
|
|
8196
|
+
var OMP_DISABLED_SERVERS_KEY = "disabledServers";
|
|
8197
|
+
var OMP_MCP_FILE = "mcp.json";
|
|
8198
|
+
var OMP_CONFIG_FILE = "config.yml";
|
|
8199
|
+
var ENABLED_PROVIDERS = "enabledProviders";
|
|
8200
|
+
var DISABLED_PROVIDERS = "disabledProviders";
|
|
8201
|
+
var CLAUDE_PROVIDER = "claude";
|
|
8202
|
+
var ALL_PROVIDERS = ["*", "all"];
|
|
8203
|
+
function ompImportFiles(home) {
|
|
8204
|
+
const agentDir = join11(home, ...AGENT_HOME_DIR.omp, PI_AGENT_DIR);
|
|
8205
|
+
return { config: join11(agentDir, OMP_CONFIG_FILE), mcp: join11(agentDir, OMP_MCP_FILE), claude: join11(home, CLAUDE_USER_CONFIG_FILE) };
|
|
8206
|
+
}
|
|
8207
|
+
function readText2(file) {
|
|
8208
|
+
try {
|
|
8209
|
+
return existsSync10(file) ? hostText(readFileSync7(file, "utf8")) : void 0;
|
|
8210
|
+
} catch {
|
|
8211
|
+
return void 0;
|
|
8212
|
+
}
|
|
8213
|
+
}
|
|
8214
|
+
var unquote = (s) => {
|
|
8215
|
+
const t2 = s.trim();
|
|
8216
|
+
const q = t2[0];
|
|
8217
|
+
return (q === '"' || q === "'") && t2.endsWith(q) && t2.length > 1 ? t2.slice(1, -1) : t2;
|
|
8218
|
+
};
|
|
8219
|
+
var withoutComment = (s) => {
|
|
8220
|
+
const at = s.indexOf(" #");
|
|
8221
|
+
return at === -1 ? s : s.slice(0, at);
|
|
8222
|
+
};
|
|
8223
|
+
function yamlTopList(text2, key) {
|
|
8224
|
+
const lines = text2.split("\n").map((l) => l.endsWith("\r") ? l.slice(0, -1) : l);
|
|
8225
|
+
const head = `${key}:`;
|
|
8226
|
+
const at = lines.findIndex((l) => l.startsWith(head));
|
|
8227
|
+
if (at === -1) return [];
|
|
8228
|
+
const rest = withoutComment(lines[at].slice(head.length)).trim();
|
|
8229
|
+
if (rest.startsWith("[")) {
|
|
8230
|
+
const end = rest.indexOf("]");
|
|
8231
|
+
return (end === -1 ? rest.slice(1) : rest.slice(1, end)).split(",").map(unquote).filter((x2) => x2 !== "");
|
|
8232
|
+
}
|
|
8233
|
+
if (rest !== "") return [];
|
|
8234
|
+
const out2 = [];
|
|
8235
|
+
for (const line of lines.slice(at + 1)) {
|
|
8236
|
+
const t2 = line.trim();
|
|
8237
|
+
if (t2 === "" || t2.startsWith("#")) continue;
|
|
8238
|
+
if (line === line.trimStart() && !t2.startsWith("-")) break;
|
|
8239
|
+
if (!t2.startsWith("-")) break;
|
|
8240
|
+
out2.push(unquote(withoutComment(t2.slice(1))));
|
|
8241
|
+
}
|
|
8242
|
+
return out2;
|
|
8243
|
+
}
|
|
8244
|
+
function ompImportsUs(files, env) {
|
|
8245
|
+
const config = readText2(files.config) ?? "";
|
|
8246
|
+
if (yamlTopList(config, DISABLED_PROVIDERS).includes(CLAUDE_PROVIDER)) return false;
|
|
8247
|
+
const enabled = yamlTopList(config, ENABLED_PROVIDERS);
|
|
8248
|
+
const dirSet = env[CLAUDE_CONFIG_DIR_ENV] !== void 0 && env[CLAUDE_CONFIG_DIR_ENV] !== "";
|
|
8249
|
+
if (!dirSet && !enabled.some((p3) => p3 === CLAUDE_PROVIDER || ALL_PROVIDERS.includes(p3))) return false;
|
|
8250
|
+
const claude = readText2(files.claude);
|
|
8251
|
+
if (claude === void 0) return false;
|
|
8252
|
+
try {
|
|
8253
|
+
const servers = JSON.parse(claude)[MCP_SERVERS_KEY];
|
|
8254
|
+
return typeof servers === "object" && servers !== null && Object.hasOwn(servers, SERVER_KEY);
|
|
8255
|
+
} catch {
|
|
8256
|
+
return false;
|
|
8257
|
+
}
|
|
8258
|
+
}
|
|
8259
|
+
|
|
8155
8260
|
// src/core/ops/doctor-config.ts
|
|
8156
8261
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
8157
8262
|
var isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8221,17 +8326,17 @@ function opencodePluginDirs(configDir, worktree) {
|
|
|
8221
8326
|
return [configDir, opencodeProjectDir(worktree)];
|
|
8222
8327
|
}
|
|
8223
8328
|
function opencodeProjectDir(worktree) {
|
|
8224
|
-
return
|
|
8329
|
+
return join12(worktree, OPENCODE_PROJECT_DIR);
|
|
8225
8330
|
}
|
|
8226
8331
|
function packageResolves(fromDir) {
|
|
8227
8332
|
for (let d = fromDir; ; d = dirname7(d)) {
|
|
8228
|
-
if (
|
|
8333
|
+
if (existsSync11(join12(d, NODE_MODULES_DIR, SERVER_KEY, PACKAGE_JSON_FILE))) return true;
|
|
8229
8334
|
if (dirname7(d) === d) return false;
|
|
8230
8335
|
}
|
|
8231
8336
|
}
|
|
8232
8337
|
function opencodeDirPlugins(dirs) {
|
|
8233
8338
|
const bundle = opencodePluginFile();
|
|
8234
|
-
const ownFile =
|
|
8339
|
+
const ownFile = join12(bundle, ...OPENCODE_PLUGIN_PATH).split("\\").join("/");
|
|
8235
8340
|
const isModule = (p3) => OWN_PLUGIN_MODULES.includes(p3);
|
|
8236
8341
|
const isPath = (p3) => {
|
|
8237
8342
|
if (p3 === ownFile || p3 === `${FILE_URL_PREFIX}${ownFile}`) return true;
|
|
@@ -8241,7 +8346,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
8241
8346
|
};
|
|
8242
8347
|
const out2 = [];
|
|
8243
8348
|
for (const dir of dirs) {
|
|
8244
|
-
const pdir =
|
|
8349
|
+
const pdir = join12(dir, OPENCODE_PLUGINS_DIR);
|
|
8245
8350
|
let names;
|
|
8246
8351
|
try {
|
|
8247
8352
|
names = readdirSync5(pdir);
|
|
@@ -8249,12 +8354,12 @@ function opencodeDirPlugins(dirs) {
|
|
|
8249
8354
|
continue;
|
|
8250
8355
|
}
|
|
8251
8356
|
for (const name of names) {
|
|
8252
|
-
const loose = OPENCODE_PLUGIN_EXTS.some((x2) => name.endsWith(x2)) ? [
|
|
8253
|
-
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x2) =>
|
|
8357
|
+
const loose = OPENCODE_PLUGIN_EXTS.some((x2) => name.endsWith(x2)) ? [join12(pdir, name)] : [];
|
|
8358
|
+
const files = [...loose, ...OPENCODE_PLUGIN_EXTS.map((x2) => join12(pdir, name, `${OPENCODE_PLUGIN_INDEX}${x2}`))];
|
|
8254
8359
|
for (const f2 of files) {
|
|
8255
8360
|
let text2;
|
|
8256
8361
|
try {
|
|
8257
|
-
const b3 =
|
|
8362
|
+
const b3 = readFileSync8(f2);
|
|
8258
8363
|
if (b3.length > OPENCODE_DIR_FILE_MAX) continue;
|
|
8259
8364
|
text2 = b3.toString("utf8");
|
|
8260
8365
|
} catch {
|
|
@@ -8265,7 +8370,7 @@ function opencodeDirPlugins(dirs) {
|
|
|
8265
8370
|
const loads2 = lits.some((p3) => {
|
|
8266
8371
|
if (isModule(p3)) return packageResolves(dirname7(f2));
|
|
8267
8372
|
const bare = p3.startsWith(FILE_URL_PREFIX) ? p3.slice(FILE_URL_PREFIX.length) : p3;
|
|
8268
|
-
return
|
|
8373
|
+
return existsSync11(isAbsolute4(bare) ? bare : resolve5(dirname7(f2), bare));
|
|
8269
8374
|
});
|
|
8270
8375
|
out2.push({ file: f2, loads: loads2 });
|
|
8271
8376
|
}
|
|
@@ -8285,7 +8390,7 @@ function formUrl(title, summary) {
|
|
|
8285
8390
|
}
|
|
8286
8391
|
|
|
8287
8392
|
// src/setup/registry.ts
|
|
8288
|
-
import { existsSync as
|
|
8393
|
+
import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
|
|
8289
8394
|
import path6 from "node:path";
|
|
8290
8395
|
|
|
8291
8396
|
// src/setup/hook-shapes.ts
|
|
@@ -8337,7 +8442,9 @@ var HOOK_SHAPES = {
|
|
|
8337
8442
|
kiro: kiroShape,
|
|
8338
8443
|
zcode: zcodeShape,
|
|
8339
8444
|
pi: null,
|
|
8340
|
-
opencode: null
|
|
8445
|
+
opencode: null,
|
|
8446
|
+
omp: null
|
|
8447
|
+
// ADR-0026: in-process like pi
|
|
8341
8448
|
};
|
|
8342
8449
|
|
|
8343
8450
|
// src/setup/registry.ts
|
|
@@ -8422,7 +8529,7 @@ var NATIVE_PLUGIN = {
|
|
|
8422
8529
|
};
|
|
8423
8530
|
var CELLAR_SEGMENT = "/Cellar/";
|
|
8424
8531
|
var NODE_BIN = ["bin", "node"];
|
|
8425
|
-
var REAL_FS = { exists:
|
|
8532
|
+
var REAL_FS = { exists: existsSync13, real: (p3) => realpathSync7.native(p3) };
|
|
8426
8533
|
function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
8427
8534
|
const at = execPath.indexOf(CELLAR_SEGMENT);
|
|
8428
8535
|
if (at < 0) return execPath;
|
|
@@ -8437,6 +8544,7 @@ function stableNodePath(execPath, fs2 = REAL_FS) {
|
|
|
8437
8544
|
}
|
|
8438
8545
|
return execPath;
|
|
8439
8546
|
}
|
|
8547
|
+
var BARE_NODE_ON_WINDOWS = ["codex", "qwen", "copilot-cli", "vscode"];
|
|
8440
8548
|
var SETUP_NODE = stableNodePath(process.execPath);
|
|
8441
8549
|
function serverCmd(ctx, id) {
|
|
8442
8550
|
return [SETUP_NODE, path6.join(ctx.pkgDir, SERVER_BUNDLE), AGENT_FLAG, id];
|
|
@@ -8492,6 +8600,9 @@ function cliFor(ctx, id) {
|
|
|
8492
8600
|
return { bin: "copilot", install: [["mcp", "add", SERVER_KEY, "--", ...s]], remove: [["mcp", "remove", SERVER_KEY]] };
|
|
8493
8601
|
case "pi":
|
|
8494
8602
|
return { bin: "pi", install: [["install", ctx.pkgDir]], remove: [["remove", ctx.pkgDir]] };
|
|
8603
|
+
// ADR-0026 decision 4: OMP installs from its own plugin store by name (T23, T24).
|
|
8604
|
+
case "omp":
|
|
8605
|
+
return { bin: "omp", install: [["plugin", "install", SERVER_KEY]], remove: [["plugin", "uninstall", SERVER_KEY]] };
|
|
8495
8606
|
default:
|
|
8496
8607
|
return void 0;
|
|
8497
8608
|
}
|
|
@@ -8517,6 +8628,8 @@ var LIST = {
|
|
|
8517
8628
|
qwen: { bin: "qwen", args: ["extensions", "list"] },
|
|
8518
8629
|
"copilot-cli": { bin: "copilot", args: ["mcp", "list"] },
|
|
8519
8630
|
pi: { bin: "pi", args: ["list"] },
|
|
8631
|
+
omp: { bin: "omp", args: ["plugin", "list"] },
|
|
8632
|
+
// ADR-0026
|
|
8520
8633
|
// D-HF-OPENCODE-LIST-1: --pure skips external plugins, so a fresh HOME does not wait on the @opencode-ai/plugin install.
|
|
8521
8634
|
opencode: { bin: "opencode", args: ["mcp", "list", "--pure"] }
|
|
8522
8635
|
};
|
|
@@ -8581,7 +8694,7 @@ function buildRegistry(ctx) {
|
|
|
8581
8694
|
const config = configFor(ctx, id);
|
|
8582
8695
|
const hookFiles = hookFilesFor(ctx, id);
|
|
8583
8696
|
const runCommand2 = [SETUP_NODE, path6.join(ctx.pkgDir, HOOK_BUNDLE), AGENT_FLAG, id];
|
|
8584
|
-
const bareNode = (id
|
|
8697
|
+
const bareNode = BARE_NODE_ON_WINDOWS.includes(id) && (ctx.platform ?? process.platform) === "win32";
|
|
8585
8698
|
const hookCommand = bareNode ? [HOST_NODE_COMMAND, ...runCommand2.slice(1)] : runCommand2;
|
|
8586
8699
|
const command = `${bareNode ? HOST_NODE_COMMAND : `"${hookCommand[0]}"`} "${hookCommand[1]}" ${AGENT_FLAG} ${id}`;
|
|
8587
8700
|
const hookInstall = hookInstallFor(ctx, getAdapter(id), command);
|
|
@@ -8593,7 +8706,9 @@ function buildRegistry(ctx) {
|
|
|
8593
8706
|
...hookFiles.map((h2) => h2.file),
|
|
8594
8707
|
...hookInstall.kind === "package" ? [] : [hookInstall.file],
|
|
8595
8708
|
...hookInstall.kind === "file" && hookInstall.trust ? [hookInstall.trust] : [],
|
|
8596
|
-
...skillInstall.kind === "dir" ? skillInstall.files.map((f2) => f2.file) : []
|
|
8709
|
+
...skillInstall.kind === "dir" ? skillInstall.files.map((f2) => f2.file) : [],
|
|
8710
|
+
...id === "omp" ? [ompImportFiles(ctx.home).mcp] : []
|
|
8711
|
+
// ADR-0026 decision 11: disabledServers, only when OMP imports us
|
|
8597
8712
|
];
|
|
8598
8713
|
const out2 = {
|
|
8599
8714
|
id,
|
|
@@ -8626,7 +8741,7 @@ function assertWritable(row, file) {
|
|
|
8626
8741
|
}
|
|
8627
8742
|
|
|
8628
8743
|
// src/setup/gemini-gate.ts
|
|
8629
|
-
import { existsSync as
|
|
8744
|
+
import { existsSync as existsSync14, readFileSync as readFileSync10 } from "node:fs";
|
|
8630
8745
|
import path7 from "node:path";
|
|
8631
8746
|
var GEMINI_DIR = ".gemini";
|
|
8632
8747
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -8646,9 +8761,9 @@ function systemDefaultsPath(env) {
|
|
|
8646
8761
|
return set2 ? set2 : path7.join(path7.dirname(systemSettingsPath(env)), SYSTEM_DEFAULTS_FILE);
|
|
8647
8762
|
}
|
|
8648
8763
|
function load2(file) {
|
|
8649
|
-
if (!
|
|
8764
|
+
if (!existsSync14(file)) return void 0;
|
|
8650
8765
|
try {
|
|
8651
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
8766
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync10(file, "utf8")), "jsonc") };
|
|
8652
8767
|
} catch {
|
|
8653
8768
|
return void 0;
|
|
8654
8769
|
}
|
|
@@ -8680,7 +8795,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
8680
8795
|
}
|
|
8681
8796
|
|
|
8682
8797
|
// src/setup/zcode-gate.ts
|
|
8683
|
-
import { existsSync as
|
|
8798
|
+
import { existsSync as existsSync15, readFileSync as readFileSync11 } from "node:fs";
|
|
8684
8799
|
import path8 from "node:path";
|
|
8685
8800
|
var OWN_AGENT2 = "zcode";
|
|
8686
8801
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -8772,10 +8887,10 @@ function zcodeSchemaBad(doc) {
|
|
|
8772
8887
|
}
|
|
8773
8888
|
function zcodeConfigGate(home) {
|
|
8774
8889
|
const file = path8.join(home, ".zcode", "cli", "config.json");
|
|
8775
|
-
if (!
|
|
8890
|
+
if (!existsSync15(file)) return void 0;
|
|
8776
8891
|
let doc;
|
|
8777
8892
|
try {
|
|
8778
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8893
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync11(file, "utf8")), "json");
|
|
8779
8894
|
} catch {
|
|
8780
8895
|
return void 0;
|
|
8781
8896
|
}
|
|
@@ -8785,7 +8900,7 @@ function zcodeConfigGate(home) {
|
|
|
8785
8900
|
}
|
|
8786
8901
|
|
|
8787
8902
|
// src/setup/vscode-gate.ts
|
|
8788
|
-
import { existsSync as
|
|
8903
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12 } from "node:fs";
|
|
8789
8904
|
import path9 from "node:path";
|
|
8790
8905
|
var SETTINGS_FILE3 = "settings.json";
|
|
8791
8906
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -8794,9 +8909,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
8794
8909
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
8795
8910
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
8796
8911
|
function load3(file) {
|
|
8797
|
-
if (!
|
|
8912
|
+
if (!existsSync16(file)) return void 0;
|
|
8798
8913
|
try {
|
|
8799
|
-
return { file, doc: parseHostConfig("vscode", file, hostText(
|
|
8914
|
+
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync12(file, "utf8")), "jsonc") };
|
|
8800
8915
|
} catch {
|
|
8801
8916
|
return void 0;
|
|
8802
8917
|
}
|
|
@@ -8836,7 +8951,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8836
8951
|
}
|
|
8837
8952
|
|
|
8838
8953
|
// src/setup/qwen-gate.ts
|
|
8839
|
-
import { existsSync as
|
|
8954
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13 } from "node:fs";
|
|
8840
8955
|
import path10 from "node:path";
|
|
8841
8956
|
var KEY = "disableAllHooks";
|
|
8842
8957
|
var SETTINGS = "settings.json";
|
|
@@ -8852,10 +8967,10 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8852
8967
|
}
|
|
8853
8968
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8854
8969
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8855
|
-
if (!
|
|
8970
|
+
if (!existsSync17(file)) continue;
|
|
8856
8971
|
let value;
|
|
8857
8972
|
try {
|
|
8858
|
-
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(
|
|
8973
|
+
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync13(file, "utf8")), "jsonc"), [KEY]);
|
|
8859
8974
|
} catch {
|
|
8860
8975
|
continue;
|
|
8861
8976
|
}
|
|
@@ -8866,13 +8981,13 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8866
8981
|
|
|
8867
8982
|
// src/setup/codex-trust.ts
|
|
8868
8983
|
import { createHash } from "node:crypto";
|
|
8869
|
-
import { existsSync as
|
|
8984
|
+
import { existsSync as existsSync18, realpathSync as realpathSync8 } from "node:fs";
|
|
8870
8985
|
import path12 from "node:path";
|
|
8871
8986
|
import { spawn as spawn3, spawnSync as spawnSync3 } from "node:child_process";
|
|
8872
8987
|
|
|
8873
8988
|
// src/setup/spawn-bin.ts
|
|
8874
8989
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
8875
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
8990
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync3 } from "node:fs";
|
|
8876
8991
|
import path11 from "node:path";
|
|
8877
8992
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
8878
8993
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -8890,7 +9005,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
8890
9005
|
const f2 = path11.join(dir, n3);
|
|
8891
9006
|
try {
|
|
8892
9007
|
accessSync2(f2, fsc.X_OK);
|
|
8893
|
-
if (
|
|
9008
|
+
if (statSync3(f2).isFile()) return f2;
|
|
8894
9009
|
} catch {
|
|
8895
9010
|
}
|
|
8896
9011
|
}
|
|
@@ -8967,11 +9082,11 @@ function snake(name) {
|
|
|
8967
9082
|
function realFile(file) {
|
|
8968
9083
|
let dir = path12.resolve(file);
|
|
8969
9084
|
const rest = [];
|
|
8970
|
-
while (!
|
|
9085
|
+
while (!existsSync18(dir) && path12.dirname(dir) !== dir) {
|
|
8971
9086
|
rest.unshift(path12.basename(dir));
|
|
8972
9087
|
dir = path12.dirname(dir);
|
|
8973
9088
|
}
|
|
8974
|
-
return path12.join(
|
|
9089
|
+
return path12.join(realpathSync8(dir), ...rest);
|
|
8975
9090
|
}
|
|
8976
9091
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8977
9092
|
var ASK_TRIES = 3;
|
|
@@ -9172,7 +9287,7 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
9172
9287
|
|
|
9173
9288
|
// src/setup/copilot-hooks.ts
|
|
9174
9289
|
import { spawn as spawn4 } from "node:child_process";
|
|
9175
|
-
import { realpathSync as
|
|
9290
|
+
import { realpathSync as realpathSync9 } from "node:fs";
|
|
9176
9291
|
import path13 from "node:path";
|
|
9177
9292
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
9178
9293
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
@@ -9182,7 +9297,7 @@ var USER_ORIGIN = "user";
|
|
|
9182
9297
|
function canon(p3) {
|
|
9183
9298
|
let r2 = path13.resolve(p3);
|
|
9184
9299
|
try {
|
|
9185
|
-
r2 =
|
|
9300
|
+
r2 = realpathSync9(r2);
|
|
9186
9301
|
} catch {
|
|
9187
9302
|
}
|
|
9188
9303
|
return process.platform === "win32" ? r2.toLowerCase() : r2;
|
|
@@ -9267,7 +9382,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
9267
9382
|
|
|
9268
9383
|
// src/setup/engine.ts
|
|
9269
9384
|
import { spawn as spawn5, spawnSync as spawnSync4 } from "node:child_process";
|
|
9270
|
-
import { closeSync as closeSync3, existsSync as
|
|
9385
|
+
import { closeSync as closeSync3, existsSync as existsSync19, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync3, readFileSync as readFileSync14, readSync as readSync3, readdirSync as readdirSync6, realpathSync as realpathSync10, rmSync as rmSync2, statSync as statSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
9271
9386
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
9272
9387
|
import path14 from "node:path";
|
|
9273
9388
|
|
|
@@ -9306,6 +9421,7 @@ function hookSample(id, cwd, text2) {
|
|
|
9306
9421
|
case "copilot-cli":
|
|
9307
9422
|
return { effect, payload: { sessionId: SAMPLE_SESSION, timestamp: Date.now(), cwd, toolName: tool, toolArgs: JSON.stringify(command), toolResult: { resultType: "success", textResultForLlm: text2 } } };
|
|
9308
9423
|
case "pi":
|
|
9424
|
+
case "omp":
|
|
9309
9425
|
return { effect, payload: { type: event, sessionId: SAMPLE_SESSION, cwd, toolName: tool, input: command, content: text2, isError: false } };
|
|
9310
9426
|
case "opencode":
|
|
9311
9427
|
return { effect, payload: { type: event, sessionID: SAMPLE_SESSION, directory: cwd, tool, args: command, ...effect === "replace" ? { output: text2 } : {} } };
|
|
@@ -9365,9 +9481,9 @@ function isNativeBinary(file) {
|
|
|
9365
9481
|
function owningPackage(dir) {
|
|
9366
9482
|
for (let d = dir; ; d = path14.dirname(d)) {
|
|
9367
9483
|
const f2 = path14.join(d, "package.json");
|
|
9368
|
-
if (
|
|
9484
|
+
if (existsSync19(f2)) {
|
|
9369
9485
|
try {
|
|
9370
|
-
return String(JSON.parse(hostText(
|
|
9486
|
+
return String(JSON.parse(hostText(readFileSync14(f2, "utf8"))).name);
|
|
9371
9487
|
} catch {
|
|
9372
9488
|
return void 0;
|
|
9373
9489
|
}
|
|
@@ -9383,8 +9499,8 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
9383
9499
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
9384
9500
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
9385
9501
|
for (const f2 of [own2, ...real2.extra.map((p3) => path14.join(dir, ...p3))]) {
|
|
9386
|
-
if (!f2 || !
|
|
9387
|
-
const file =
|
|
9502
|
+
if (!f2 || !existsSync19(f2) || !statSync4(f2).isFile()) continue;
|
|
9503
|
+
const file = realpathSync10(f2);
|
|
9388
9504
|
if (isNativeBinary(file) || owningPackage(path14.dirname(file)) === real2.pkg) return { file: f2, shims };
|
|
9389
9505
|
shims.push(f2);
|
|
9390
9506
|
}
|
|
@@ -9400,10 +9516,10 @@ function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
|
9400
9516
|
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout, maxBuffer: Infinity });
|
|
9401
9517
|
}
|
|
9402
9518
|
function readOr(file) {
|
|
9403
|
-
return
|
|
9519
|
+
return existsSync19(file) ? hostText(readFileSync14(file, "utf8")) : void 0;
|
|
9404
9520
|
}
|
|
9405
9521
|
function readRaw(file) {
|
|
9406
|
-
return
|
|
9522
|
+
return existsSync19(file) ? readFileSync14(file, "utf8") : void 0;
|
|
9407
9523
|
}
|
|
9408
9524
|
var atomicWrite = atomicWriteFile;
|
|
9409
9525
|
function pidAlive(pid) {
|
|
@@ -9547,7 +9663,7 @@ function isNativeSpec(e) {
|
|
|
9547
9663
|
function isStaleOwnPlugin(e, entry2) {
|
|
9548
9664
|
if (typeof e !== "string" || e === entry2 || !path14.isAbsolute(e)) return false;
|
|
9549
9665
|
if (e === path14.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
9550
|
-
if (
|
|
9666
|
+
if (existsSync19(e)) return false;
|
|
9551
9667
|
const seg = e.split("\\").join("/").split("/");
|
|
9552
9668
|
const n3 = seg.length;
|
|
9553
9669
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -9635,12 +9751,20 @@ function planSkills(row, edits) {
|
|
|
9635
9751
|
const s = row.skillInstall;
|
|
9636
9752
|
if (s.kind !== "dir") return;
|
|
9637
9753
|
for (const f2 of s.files) {
|
|
9638
|
-
if (!
|
|
9639
|
-
const after = renderSkill(
|
|
9754
|
+
if (!existsSync19(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
9755
|
+
const after = renderSkill(readFileSync14(f2.src, "utf8"), s.prefixes);
|
|
9640
9756
|
const before = readRaw(f2.file);
|
|
9641
9757
|
if (before !== after) edits.push({ plain: true, file: f2.file, before, after, changes: [{ file: f2.file, path: f2.name, before: before === void 0 ? null : "old", after: "SKILL.md" }] });
|
|
9642
9758
|
}
|
|
9643
9759
|
}
|
|
9760
|
+
function planOmpImport(row, edits, ctx) {
|
|
9761
|
+
const files = ompImportFiles(ctx.home);
|
|
9762
|
+
if (!ompImportsUs(files, ctx.env)) return;
|
|
9763
|
+
planJsonKeys(row, edits, files.mcp, "json", (doc) => {
|
|
9764
|
+
const cur = Array.isArray(doc[OMP_DISABLED_SERVERS_KEY]) ? doc[OMP_DISABLED_SERVERS_KEY] : [];
|
|
9765
|
+
return cur.includes(SERVER_KEY) ? [] : [[[OMP_DISABLED_SERVERS_KEY], [...cur, SERVER_KEY]]];
|
|
9766
|
+
});
|
|
9767
|
+
}
|
|
9644
9768
|
function planRow(row, listed, stale, env, disabled = false) {
|
|
9645
9769
|
const edits = [];
|
|
9646
9770
|
if (row.config) {
|
|
@@ -9712,7 +9836,10 @@ function opencodeListCheck(bin, major, env) {
|
|
|
9712
9836
|
} catch {
|
|
9713
9837
|
out2 = void 0;
|
|
9714
9838
|
}
|
|
9715
|
-
if (r2.status !== 0)
|
|
9839
|
+
if (r2.status !== 0) {
|
|
9840
|
+
const host = `${r2.stderr}`.split("\n").map((l) => l.trim()).filter(Boolean).slice(0, 3).join(" ");
|
|
9841
|
+
return { name: "list", ok: true, warn: true, detail: `${what} exited ${r2.status}: ${host}; doctor checked the entry and hooks on disk` };
|
|
9842
|
+
}
|
|
9716
9843
|
if (major >= 2) {
|
|
9717
9844
|
if (!Array.isArray(out2)) return { name: "list", ok: false, detail: `${what} printed no config list: ${first(r2.stdout)}` };
|
|
9718
9845
|
const listed2 = out2.some((d) => isObj5(d) && isObj5(d.info) && isObj5(d.info.mcp) && isObj5(d.info.mcp.servers) && isObj5(d.info.mcp.servers[SERVER_KEY]));
|
|
@@ -9782,7 +9909,7 @@ function hookEnabledCheck(row, status) {
|
|
|
9782
9909
|
}
|
|
9783
9910
|
function packageVersion(pkgDir) {
|
|
9784
9911
|
try {
|
|
9785
|
-
const v = JSON.parse(hostText(
|
|
9912
|
+
const v = JSON.parse(hostText(readFileSync14(path14.join(pkgDir, "package.json"), "utf8"))).version;
|
|
9786
9913
|
return typeof v === "string" ? v : void 0;
|
|
9787
9914
|
} catch {
|
|
9788
9915
|
return void 0;
|
|
@@ -9994,7 +10121,7 @@ var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
|
9994
10121
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9995
10122
|
function hookSeenCheck(row, dataRoot) {
|
|
9996
10123
|
const base = path14.join(dataRoot, PROJECTS_DIR_NAME);
|
|
9997
|
-
const dirs =
|
|
10124
|
+
const dirs = existsSync19(base) ? readdirSync6(base) : [];
|
|
9998
10125
|
let sqlite;
|
|
9999
10126
|
try {
|
|
10000
10127
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -10003,7 +10130,7 @@ function hookSeenCheck(row, dataRoot) {
|
|
|
10003
10130
|
}
|
|
10004
10131
|
for (const d of dirs) {
|
|
10005
10132
|
const file = path14.join(base, d, DB_FILE_NAME);
|
|
10006
|
-
if (!sqlite || !
|
|
10133
|
+
if (!sqlite || !existsSync19(file)) continue;
|
|
10007
10134
|
let db;
|
|
10008
10135
|
try {
|
|
10009
10136
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -10020,17 +10147,17 @@ function skillsCheck(row, pkgDir) {
|
|
|
10020
10147
|
const s = row.skillInstall;
|
|
10021
10148
|
if (s.kind === "package") {
|
|
10022
10149
|
const files = COMMAND_SKILLS.map((n3) => path14.join(pkgDir, s.via, n3, SKILL_FILE));
|
|
10023
|
-
const miss = files.filter((f2) => !
|
|
10150
|
+
const miss = files.filter((f2) => !existsSync19(f2));
|
|
10024
10151
|
if (miss.length) return { name: "skills", ok: false, detail: `missing ${miss.join(", ")}` };
|
|
10025
10152
|
const own2 = getAdapter(row.id).toolNamePrefix + SKILL_TOOL_STEM;
|
|
10026
10153
|
const foreign = [...new Set(ADAPTERS.map((r2) => r2.toolNamePrefix + SKILL_TOOL_STEM))].filter((n3) => n3 !== SKILL_TOOL_STEM && n3 !== own2);
|
|
10027
10154
|
const bad2 = files.filter((f2) => {
|
|
10028
|
-
const t2 =
|
|
10155
|
+
const t2 = readFileSync14(f2, "utf8");
|
|
10029
10156
|
return !t2.includes(own2) && foreign.some((n3) => t2.includes(n3));
|
|
10030
10157
|
});
|
|
10031
10158
|
return { name: "skills", ok: bad2.length === 0, detail: bad2.length ? `${bad2.join(", ")} without the ${own2}* tool name` : void 0 };
|
|
10032
10159
|
}
|
|
10033
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
10160
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync19(f2.src) ? renderSkill(readFileSync14(f2.src, "utf8"), s.prefixes) : void 0));
|
|
10034
10161
|
return { name: "skills", ok: bad.length === 0, detail: bad.length ? `${bad.map((f2) => f2.file).join(", ")} missing or without the ${s.prefixes.join(" / ") || "plain"} tool prefix` : void 0 };
|
|
10035
10162
|
}
|
|
10036
10163
|
var CODEX_CONFIG_FILE2 = "config.toml";
|
|
@@ -10087,7 +10214,70 @@ function jsonState(n3, text2) {
|
|
|
10087
10214
|
const hookGate = hooks.some((h2) => isObj5(h2) && typeof h2.command === "string" && h2.command.includes(own2)) ? void 0 : `the installed ${n3.plugin} runs no ${own2} hook; run: ${n3.bin} plugins update ${n3.plugin}`;
|
|
10088
10215
|
return { state: "enabled", workspaceOff: false, hookGate };
|
|
10089
10216
|
}
|
|
10090
|
-
function
|
|
10217
|
+
function unlistedExtension(n3, env, home, out2, status) {
|
|
10218
|
+
if (n3.bin !== "gemini") return void 0;
|
|
10219
|
+
const dir = path14.join(geminiDirOf(env, home), "extensions", n3.plugin);
|
|
10220
|
+
if (!existsSync19(path14.join(dir, "gemini-extension.json"))) return void 0;
|
|
10221
|
+
const cmd = [n3.bin, ...n3.args].join(" ");
|
|
10222
|
+
const first = out2.split("\n").map((l) => l.trim()).find((l) => l.length)?.slice(0, 300) ?? `exit ${status}`;
|
|
10223
|
+
return { dir, note: `context-mode is installed in ${dir}, and ${cmd} answered "${first}" in place of the extension list; run ${cmd} in a terminal and fix that answer (gemini auth)` };
|
|
10224
|
+
}
|
|
10225
|
+
var EXT_ENABLEMENT_FILE = "extension-enablement.json";
|
|
10226
|
+
function slashDir(p3) {
|
|
10227
|
+
let r2 = p3.split("\\").join("/");
|
|
10228
|
+
if (!r2.startsWith("/")) r2 = `/${r2}`;
|
|
10229
|
+
return r2.endsWith("/") ? r2 : `${r2}/`;
|
|
10230
|
+
}
|
|
10231
|
+
function geminiEnablement(n3, env, home, cwd) {
|
|
10232
|
+
const file = path14.join(geminiDirOf(env, home), "extensions", EXT_ENABLEMENT_FILE);
|
|
10233
|
+
const text2 = readOr(file);
|
|
10234
|
+
if (text2 === void 0) return { file, on: true };
|
|
10235
|
+
let doc;
|
|
10236
|
+
try {
|
|
10237
|
+
doc = JSON.parse(text2);
|
|
10238
|
+
} catch {
|
|
10239
|
+
return { file, on: false, bad: true };
|
|
10240
|
+
}
|
|
10241
|
+
const mine = isObj5(doc) ? doc[n3.plugin] : void 0;
|
|
10242
|
+
const rules = isObj5(mine) && Array.isArray(mine.overrides) ? mine.overrides : [];
|
|
10243
|
+
const here = slashDir(cwd);
|
|
10244
|
+
let on = true;
|
|
10245
|
+
for (const rule of rules) {
|
|
10246
|
+
if (typeof rule !== "string") continue;
|
|
10247
|
+
const off = rule.startsWith("!");
|
|
10248
|
+
let base = off ? rule.slice(1) : rule;
|
|
10249
|
+
const subdirs = base.endsWith("*");
|
|
10250
|
+
if (subdirs) base = base.slice(0, -1);
|
|
10251
|
+
base = slashDir(base);
|
|
10252
|
+
if (subdirs ? here.startsWith(base) : here === base) on = !off;
|
|
10253
|
+
}
|
|
10254
|
+
return { file, on };
|
|
10255
|
+
}
|
|
10256
|
+
function diskHookCheck(row, n3, dir) {
|
|
10257
|
+
const name = "hook-registered";
|
|
10258
|
+
const file = path14.join(dir, n3.hooksVia);
|
|
10259
|
+
const text2 = readOr(file);
|
|
10260
|
+
if (text2 === void 0) return { name, ok: false, detail: `${file} is missing; run: ${NATIVE_INSTALL.gemini[0]}` };
|
|
10261
|
+
let doc;
|
|
10262
|
+
try {
|
|
10263
|
+
doc = JSON.parse(text2);
|
|
10264
|
+
} catch {
|
|
10265
|
+
return { name, ok: false, detail: `${file} is not valid JSON; run: ${NATIVE_INSTALL.gemini[0]}` };
|
|
10266
|
+
}
|
|
10267
|
+
return holdsOwn(doc, row.id) ? { name, ok: true } : { name, ok: false, detail: `${file} holds no ${AGENT_FLAG} ${row.id} hook; run: ${NATIVE_INSTALL.gemini[0]}` };
|
|
10268
|
+
}
|
|
10269
|
+
var EXT_BUNDLE_DIR = ["plugins", "claude-code"];
|
|
10270
|
+
function diskRow(row, n3, dir) {
|
|
10271
|
+
const bundle = (f2) => path14.join(dir, ...EXT_BUNDLE_DIR, f2);
|
|
10272
|
+
return {
|
|
10273
|
+
...nativeRow(row, n3),
|
|
10274
|
+
listCommand: void 0,
|
|
10275
|
+
serverCommand: [row.serverCommand[0], bundle(SERVER_BUNDLE), AGENT_FLAG, row.id],
|
|
10276
|
+
hookRunCommand: [row.hookRunCommand[0], bundle(HOOK_BUNDLE), AGENT_FLAG, row.id],
|
|
10277
|
+
...row.hookCommand ? { hookCommand: [row.hookRunCommand[0], bundle(HOOK_BUNDLE), AGENT_FLAG, row.id] } : {}
|
|
10278
|
+
};
|
|
10279
|
+
}
|
|
10280
|
+
function nativeState(row, env, home) {
|
|
10091
10281
|
const none = { state: void 0, workspaceOff: false };
|
|
10092
10282
|
const n3 = row.nativePlugin;
|
|
10093
10283
|
if (!n3 || !hostBin(n3.bin, env).file) return none;
|
|
@@ -10097,10 +10287,19 @@ function nativeState(row, env) {
|
|
|
10097
10287
|
const cmd = [n3.bin, ...n3.args].join(" ");
|
|
10098
10288
|
return { ...none, stopped: `${cmd} stopped before it finished (${why}); it names ${n3.plugin}, run ${cmd} in a terminal` };
|
|
10099
10289
|
}
|
|
10290
|
+
if (n3.format === "extension") {
|
|
10291
|
+
const out2 = `${r2.stdout}${r2.stderr}`;
|
|
10292
|
+
const st = r2.status === 0 ? extensionState(n3, out2) : none;
|
|
10293
|
+
if (st.state !== void 0) return st;
|
|
10294
|
+
const unlisted = unlistedExtension(n3, env, home, out2, r2.status);
|
|
10295
|
+
if (!unlisted) return st;
|
|
10296
|
+
const en = geminiEnablement(n3, env, home, process.cwd());
|
|
10297
|
+
if (en.bad) return { ...none, stopped: `${en.file} is not valid JSON, so gemini cannot read which projects enable context-mode; fix that file. ${unlisted.note}` };
|
|
10298
|
+
return { state: en.on ? "enabled" : "disabled", workspaceOff: false, disk: { ...unlisted, enablement: en.file } };
|
|
10299
|
+
}
|
|
10100
10300
|
if (r2.status !== 0) return none;
|
|
10101
10301
|
if (n3.format === "json") return jsonState(n3, `${r2.stdout}`);
|
|
10102
|
-
|
|
10103
|
-
return extensionState(n3, `${r2.stdout}${r2.stderr}`);
|
|
10302
|
+
return { state: codexJsonState(n3, `${r2.stdout}`), workspaceOff: false };
|
|
10104
10303
|
}
|
|
10105
10304
|
function nativeRow(row, n3) {
|
|
10106
10305
|
return {
|
|
@@ -10116,12 +10315,22 @@ function nativeRow(row, n3) {
|
|
|
10116
10315
|
}
|
|
10117
10316
|
async function nativeResult(row, ctx, apply2) {
|
|
10118
10317
|
const n3 = row.nativePlugin;
|
|
10119
|
-
const { state, workspaceOff, hookGate, stopped } = nativeState(row, ctx.env);
|
|
10318
|
+
const { state, workspaceOff, hookGate, stopped, disk } = nativeState(row, ctx.env, ctx.home);
|
|
10120
10319
|
const bin = n3 ? hostBin(n3.bin, ctx.env).file : void 0;
|
|
10121
10320
|
if (stopped) return { id: row.id, status: "FAIL", v1: [], changes: [], checks: [], bin, reason: stopped };
|
|
10321
|
+
if (n3?.format === "codex-json" && !bin && codexPluginHomeOf(ctx.pkgDir) !== null) return codexCacheResult(row, ctx, apply2);
|
|
10122
10322
|
if (!n3 || state === void 0) return void 0;
|
|
10123
10323
|
if (state === "disabled") {
|
|
10124
10324
|
if (!n3.enable) return void 0;
|
|
10325
|
+
if (disk) return {
|
|
10326
|
+
id: row.id,
|
|
10327
|
+
status: "FAIL",
|
|
10328
|
+
v1: [],
|
|
10329
|
+
changes: [],
|
|
10330
|
+
checks: [],
|
|
10331
|
+
bin,
|
|
10332
|
+
reason: `context-mode is installed in ${disk.dir} but disabled for ${process.cwd()} in ${disk.enablement}, run ${n3.bin} ${n3.enable.join(" ")}`
|
|
10333
|
+
};
|
|
10125
10334
|
return {
|
|
10126
10335
|
id: row.id,
|
|
10127
10336
|
status: "FAIL",
|
|
@@ -10144,7 +10353,10 @@ async function nativeResult(row, ctx, apply2) {
|
|
|
10144
10353
|
return { ...res, status: "FAIL", reason: e.message, rolledBack: true };
|
|
10145
10354
|
}
|
|
10146
10355
|
}
|
|
10147
|
-
|
|
10356
|
+
if (disk) {
|
|
10357
|
+
res.checks = (await verifyRow(diskRow(row, n3, disk.dir), { ...ctx, pkgDir: disk.dir })).map((c3) => c3.name === "hook-registered" ? diskHookCheck(row, n3, disk.dir) : c3);
|
|
10358
|
+
res.checks.push({ name: "list", ok: true, warn: true, detail: `${disk.note}; doctor checked the extension files on disk` });
|
|
10359
|
+
} else res.checks = await verifyRow(nativeRow(row, n3), ctx);
|
|
10148
10360
|
if (n3.hookTrust) res.checks = withHookTrust(res.checks, hooks, !!apply2?.dryRun);
|
|
10149
10361
|
if (n3.format === "extension") res.checks = withHookGate(res.checks, geminiGate(n3, ctx, workspaceOff));
|
|
10150
10362
|
if (n3.format === "json") res.checks = withHookGate(res.checks, hookGate);
|
|
@@ -10159,6 +10371,81 @@ async function nativeResult(row, ctx, apply2) {
|
|
|
10159
10371
|
}
|
|
10160
10372
|
return res;
|
|
10161
10373
|
}
|
|
10374
|
+
function codexCacheEdits(row, found) {
|
|
10375
|
+
const edits = [];
|
|
10376
|
+
const c3 = row.config;
|
|
10377
|
+
const text2 = c3 ? readOr(c3.file) : void 0;
|
|
10378
|
+
if (c3 && text2 !== void 0) {
|
|
10379
|
+
let cur;
|
|
10380
|
+
try {
|
|
10381
|
+
cur = hostConfigValueAt(parseHostConfig(row.id, c3.file, text2, c3.format), c3.key);
|
|
10382
|
+
} catch {
|
|
10383
|
+
throw new Error(parseFail(row, c3.file));
|
|
10384
|
+
}
|
|
10385
|
+
if (cur !== void 0) {
|
|
10386
|
+
const res = editHostConfigText(row.id, c3.file, text2, c3.format, [[c3.key, void 0]]);
|
|
10387
|
+
const run = isObj5(cur) ? [cur.command, ...Array.isArray(cur.args) ? cur.args : []].filter((x2) => typeof x2 === "string").join(" ") : "";
|
|
10388
|
+
found.push(`${c3.file}: [${c3.key.join(".")}] runs ${run}`);
|
|
10389
|
+
if (res.edits.length) edits.push({ file: c3.file, before: text2, after: res.text, changes: res.edits.map((e) => ({ file: c3.file, ...e })) });
|
|
10390
|
+
}
|
|
10391
|
+
}
|
|
10392
|
+
const h2 = row.hookInstall;
|
|
10393
|
+
if (h2.kind === "file") planJsonKeys(row, edits, h2.file, "json", (doc) => {
|
|
10394
|
+
if (!isObj5(doc.hooks)) return [];
|
|
10395
|
+
const own2 = (x2) => {
|
|
10396
|
+
const hit = isObj5(x2) && isOwnHookCommand(x2.command, row.id);
|
|
10397
|
+
if (hit) found.push(`${h2.file}: ${String(x2.command)}`);
|
|
10398
|
+
return hit;
|
|
10399
|
+
};
|
|
10400
|
+
const hooks = {};
|
|
10401
|
+
for (const [ev, groups] of Object.entries(doc.hooks)) {
|
|
10402
|
+
if (!Array.isArray(groups)) {
|
|
10403
|
+
hooks[ev] = groups;
|
|
10404
|
+
continue;
|
|
10405
|
+
}
|
|
10406
|
+
const kept = groups.flatMap((g2) => {
|
|
10407
|
+
if (own2(g2)) return [];
|
|
10408
|
+
if (!isObj5(g2) || !Array.isArray(g2.hooks) || !g2.hooks.length) return [g2];
|
|
10409
|
+
const inner = g2.hooks.filter((x2) => !own2(x2));
|
|
10410
|
+
return inner.length ? [{ ...g2, hooks: inner }] : [];
|
|
10411
|
+
});
|
|
10412
|
+
if (kept.length || !groups.length) hooks[ev] = kept;
|
|
10413
|
+
}
|
|
10414
|
+
return [[["hooks"], hooks]];
|
|
10415
|
+
});
|
|
10416
|
+
return edits;
|
|
10417
|
+
}
|
|
10418
|
+
async function codexCacheResult(row, ctx, apply2) {
|
|
10419
|
+
const res = { id: row.id, status: "PASS", v1: [], changes: [], checks: [] };
|
|
10420
|
+
const found = [];
|
|
10421
|
+
let edits;
|
|
10422
|
+
try {
|
|
10423
|
+
edits = codexCacheEdits(row, found);
|
|
10424
|
+
} catch (e) {
|
|
10425
|
+
return { ...res, status: "FAIL", reason: e.message };
|
|
10426
|
+
}
|
|
10427
|
+
res.changes = edits.flatMap((e) => e.changes);
|
|
10428
|
+
const plugin = `the codex plugin in ${codexPluginHomeOf(ctx.pkgDir)} runs the MCP server and the hooks`;
|
|
10429
|
+
if (!apply2 && found.length) {
|
|
10430
|
+
res.checks = found.map((f2) => ({ name: "pinned-entry", ok: false, detail: `${f2}; ${plugin}, this entry runs a second copy and its path goes away on a plugin update; run: context-mode setup` }));
|
|
10431
|
+
return { ...res, status: "FAIL", reason: res.checks.map((c3) => `${c3.name}: ${c3.detail}`).join("; ") };
|
|
10432
|
+
}
|
|
10433
|
+
if (apply2 && !apply2.dryRun) {
|
|
10434
|
+
try {
|
|
10435
|
+
for (const e of edits) {
|
|
10436
|
+
assertWritable(row, e.file);
|
|
10437
|
+
const raw = readRaw(e.file);
|
|
10438
|
+
apply2.run.record({ agent: row.id, file: e.file, existed: raw !== void 0 }, raw);
|
|
10439
|
+
atomicWrite(e.file, raw === void 0 ? e.after : withLayout(e.after, hostLayout(raw)));
|
|
10440
|
+
}
|
|
10441
|
+
} catch (e) {
|
|
10442
|
+
apply2.run.rollback(row.id, ctx.env);
|
|
10443
|
+
return { ...res, status: "FAIL", reason: e.message, rolledBack: true };
|
|
10444
|
+
}
|
|
10445
|
+
}
|
|
10446
|
+
res.checks = [{ name: "hook-registered", ok: true, warn: true, detail: `${plugin}; codex is not on PATH, so check them with: codex plugin list` }];
|
|
10447
|
+
return res;
|
|
10448
|
+
}
|
|
10162
10449
|
function trustPluginHooks(row, ctx, apply2, hooks) {
|
|
10163
10450
|
const file = path14.join(codexDirOf(ctx.env, ctx.home), CODEX_CONFIG_FILE2);
|
|
10164
10451
|
const text2 = readOr(file);
|
|
@@ -10253,10 +10540,14 @@ async function enableCopilotHooks(row, ctx, run) {
|
|
|
10253
10540
|
return edit.edits.map((e) => ({ file: settings2, ...e }));
|
|
10254
10541
|
}
|
|
10255
10542
|
var isObjSetup = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
10256
|
-
|
|
10543
|
+
function listOnce(row, env) {
|
|
10544
|
+
let ls;
|
|
10545
|
+
return () => ls ??= listState(row, env);
|
|
10546
|
+
}
|
|
10547
|
+
async function verifyRow(row, ctx, list2 = () => listState(row, ctx.env)) {
|
|
10257
10548
|
const env = ctx.env;
|
|
10258
10549
|
const checks = [parseCheck(row)];
|
|
10259
|
-
const ls =
|
|
10550
|
+
const ls = list2();
|
|
10260
10551
|
const l = ls.check;
|
|
10261
10552
|
if (l) checks.push(l);
|
|
10262
10553
|
const cp = copyCheck(row, ctx.pkgDir);
|
|
@@ -10310,7 +10601,7 @@ function undo(dir, entries, env) {
|
|
|
10310
10601
|
continue;
|
|
10311
10602
|
}
|
|
10312
10603
|
if (!e.file) continue;
|
|
10313
|
-
if (e.existed && e.backup) atomicWrite(e.file,
|
|
10604
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync14(path14.join(dir, e.backup), "utf8"));
|
|
10314
10605
|
else unlinkWithRetry(e.file);
|
|
10315
10606
|
}
|
|
10316
10607
|
}
|
|
@@ -10325,7 +10616,7 @@ function takeLock(root, runId) {
|
|
|
10325
10616
|
if (e.code !== "EEXIST") throw e;
|
|
10326
10617
|
let pid = 0;
|
|
10327
10618
|
try {
|
|
10328
|
-
pid = Number(JSON.parse(
|
|
10619
|
+
pid = Number(JSON.parse(readFileSync14(file, "utf8")).pid);
|
|
10329
10620
|
} catch {
|
|
10330
10621
|
}
|
|
10331
10622
|
if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
|
|
@@ -10343,7 +10634,7 @@ function agentHomeDir(id, ctx) {
|
|
|
10343
10634
|
return path14.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
10344
10635
|
}
|
|
10345
10636
|
function detectAgents(reg, ctx) {
|
|
10346
|
-
return reg.filter((r2) =>
|
|
10637
|
+
return reg.filter((r2) => existsSync19(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
10347
10638
|
}
|
|
10348
10639
|
async function runSetup(opts) {
|
|
10349
10640
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env, cwd: opts.cwd };
|
|
@@ -10352,7 +10643,7 @@ async function runSetup(opts) {
|
|
|
10352
10643
|
const nodeVersion = opts.nodeVersion ?? process.version;
|
|
10353
10644
|
if (nodeTooOld(nodeVersion)) return { exitCode: 1, agents: [], error: formatError("NODE_TOO_OLD", { v: nodeVersion }) };
|
|
10354
10645
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10355
|
-
if (!
|
|
10646
|
+
if (!existsSync19(path14.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path14.join(ctx.pkgDir, f2)} is missing` };
|
|
10356
10647
|
}
|
|
10357
10648
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10358
10649
|
const root = dataRootOf(ctx.env, ctx.home);
|
|
@@ -10388,7 +10679,7 @@ async function runSetup(opts) {
|
|
|
10388
10679
|
}
|
|
10389
10680
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents, backupDir: run.manifest ? run.dir : void 0 };
|
|
10390
10681
|
}
|
|
10391
|
-
async function setupRow(row, ctx, run, dryRun) {
|
|
10682
|
+
async function setupRow(row, ctx, run, dryRun, list2 = () => listState(row, ctx.env)) {
|
|
10392
10683
|
const res = { id: row.id, status: "PASS", v1: [], changes: [], checks: [] };
|
|
10393
10684
|
const needsBin = !row.config && row.cli;
|
|
10394
10685
|
if (needsBin) {
|
|
@@ -10400,10 +10691,11 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
10400
10691
|
if (!row.config && !row.cli) return { ...res, status: "SKIPPED", reason: `${row.id}: no setup path in the registry` };
|
|
10401
10692
|
let plan;
|
|
10402
10693
|
try {
|
|
10403
|
-
const ls = needsBin ?
|
|
10694
|
+
const ls = needsBin ? list2() : { status: void 0, check: void 0, broken: void 0 };
|
|
10404
10695
|
if (ls.broken) return { ...res, status: "SKIPPED", reason: ls.broken };
|
|
10405
10696
|
const listed = ls.check?.ok === true;
|
|
10406
10697
|
plan = planRow(row, listed, copyCheck(row, ctx.pkgDir)?.ok === false, ctx.env, listed && ls.status === "disabled");
|
|
10698
|
+
if (row.id === "omp") planOmpImport(row, plan.edits, ctx);
|
|
10407
10699
|
} catch (e) {
|
|
10408
10700
|
return { ...res, status: "FAIL", reason: e.message };
|
|
10409
10701
|
}
|
|
@@ -10459,7 +10751,7 @@ async function runDoctor(opts) {
|
|
|
10459
10751
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env, cwd: opts.cwd };
|
|
10460
10752
|
const reg = buildRegistry(ctx);
|
|
10461
10753
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
10462
|
-
if (!
|
|
10754
|
+
if (!existsSync19(path14.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path14.join(ctx.pkgDir, f2)} is missing` };
|
|
10463
10755
|
}
|
|
10464
10756
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
10465
10757
|
const run = new Run(dataRootOf(ctx.env, ctx.home), "doctor");
|
|
@@ -10477,16 +10769,23 @@ async function runDoctor(opts) {
|
|
|
10477
10769
|
opts.onAgent?.(id, "done", native);
|
|
10478
10770
|
continue;
|
|
10479
10771
|
}
|
|
10480
|
-
const
|
|
10772
|
+
const list2 = listOnce(row, ctx.env);
|
|
10773
|
+
const res = await setupRow(row, ctx, run, true, list2);
|
|
10774
|
+
const gone = row.id === "codex" ? missingPinnedChecks(row) : [];
|
|
10775
|
+
if (gone.length) {
|
|
10776
|
+
res.status = "FAIL";
|
|
10777
|
+
res.checks = [...gone, ...res.checks];
|
|
10778
|
+
res.reason = gone.map((c3) => `${c3.name}: ${c3.detail}`).join("; ");
|
|
10779
|
+
}
|
|
10481
10780
|
if (res.status === "PASS") {
|
|
10482
|
-
if (res.v1.some((f2) => !UPGRADE_REPORT_ONLY_REASONS.includes(f2.reason))) {
|
|
10781
|
+
if (res.v1.some((f2) => !UPGRADE_REPORT_ONLY_REASONS.includes(f2.reason) && !UPGRADE_KEEP_ASIDE_REASONS.includes(f2.reason))) {
|
|
10483
10782
|
res.status = "FAIL";
|
|
10484
10783
|
res.reason = V1_FORM_REASON;
|
|
10485
10784
|
} else if (res.changes.length && !onlyTrust(row, res.changes) && !hasPluginIssue(row)) {
|
|
10486
10785
|
res.status = "FAIL";
|
|
10487
10786
|
res.reason = notSetUpReason(row, res, ctx.env);
|
|
10488
10787
|
} else {
|
|
10489
|
-
res.checks = await verifyRow(row, ctx);
|
|
10788
|
+
res.checks = await verifyRow(row, ctx, list2);
|
|
10490
10789
|
const bad = res.checks.filter((c3) => !c3.ok);
|
|
10491
10790
|
if (bad.length) {
|
|
10492
10791
|
res.status = "FAIL";
|
|
@@ -10501,6 +10800,46 @@ async function runDoctor(opts) {
|
|
|
10501
10800
|
}
|
|
10502
10801
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents };
|
|
10503
10802
|
}
|
|
10803
|
+
function missingPinnedChecks(row) {
|
|
10804
|
+
const paths = [];
|
|
10805
|
+
const c3 = row.config;
|
|
10806
|
+
const text2 = c3 ? readOr(c3.file) : void 0;
|
|
10807
|
+
if (c3 && text2 !== void 0) {
|
|
10808
|
+
let cur;
|
|
10809
|
+
try {
|
|
10810
|
+
cur = hostConfigValueAt(parseHostConfig(row.id, c3.file, text2, c3.format), c3.key);
|
|
10811
|
+
} catch {
|
|
10812
|
+
cur = void 0;
|
|
10813
|
+
}
|
|
10814
|
+
if (isObj5(cur) && Array.isArray(cur.args)) {
|
|
10815
|
+
for (const a2 of cur.args) if (typeof a2 === "string" && path14.basename(a2) === "server.mjs") paths.push(a2);
|
|
10816
|
+
}
|
|
10817
|
+
}
|
|
10818
|
+
const h2 = row.hookInstall;
|
|
10819
|
+
const hooksText = h2.kind === "file" ? readOr(h2.file) : void 0;
|
|
10820
|
+
if (hooksText !== void 0) {
|
|
10821
|
+
let doc;
|
|
10822
|
+
try {
|
|
10823
|
+
doc = JSON.parse(hooksText);
|
|
10824
|
+
} catch {
|
|
10825
|
+
doc = void 0;
|
|
10826
|
+
}
|
|
10827
|
+
const walk = (v) => {
|
|
10828
|
+
if (typeof v === "string") {
|
|
10829
|
+
if (isOwnHookCommand(v, row.id)) paths.push(hookPathOf(v));
|
|
10830
|
+
} else if (Array.isArray(v)) v.forEach(walk);
|
|
10831
|
+
else if (isObj5(v)) Object.values(v).forEach(walk);
|
|
10832
|
+
};
|
|
10833
|
+
if (isObj5(doc)) walk(doc.hooks);
|
|
10834
|
+
}
|
|
10835
|
+
return [...new Set(paths)].filter((f2) => path14.isAbsolute(f2) && !existsSync19(f2)).map((f2) => ({ name: "missing-file", ok: false, detail: `${f2} does not exist (a Codex plugin update replaces its version dir); run: context-mode setup` }));
|
|
10836
|
+
}
|
|
10837
|
+
function hookPathOf(cmd) {
|
|
10838
|
+
const at = cmd.lastIndexOf(HOOK_BUNDLE);
|
|
10839
|
+
const end = at + HOOK_BUNDLE.length;
|
|
10840
|
+
const start = cmd[end] === '"' ? cmd.lastIndexOf('"', at) + 1 : cmd.lastIndexOf(" ", at) + 1;
|
|
10841
|
+
return cmd.slice(start, end);
|
|
10842
|
+
}
|
|
10504
10843
|
function notSetUpReason(row, res, env) {
|
|
10505
10844
|
const h2 = row.hookInstall;
|
|
10506
10845
|
const missing = row.id === "opencode" && h2.kind === "plugin-list" && res.changes.some((c3) => c3.path === h2.key[0]);
|
|
@@ -10539,14 +10878,14 @@ function runRemove(opts) {
|
|
|
10539
10878
|
const env = opts.env ?? process.env;
|
|
10540
10879
|
const root = dataRootOf(env, opts.home);
|
|
10541
10880
|
const base = path14.join(root, BACKUP_DIR);
|
|
10542
|
-
if (!
|
|
10881
|
+
if (!existsSync19(base)) return { exitCode: 0, restored: 0 };
|
|
10543
10882
|
const held = takeLock(root, "remove");
|
|
10544
10883
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
10545
10884
|
let restored = 0;
|
|
10546
10885
|
try {
|
|
10547
|
-
const runs = readdirSync6(base).map((r2) => path14.join(base, r2)).filter((d) =>
|
|
10886
|
+
const runs = readdirSync6(base).map((r2) => path14.join(base, r2)).filter((d) => existsSync19(path14.join(d, MANIFEST))).sort().reverse();
|
|
10548
10887
|
for (const dir of runs) {
|
|
10549
|
-
const m3 = JSON.parse(
|
|
10888
|
+
const m3 = JSON.parse(readFileSync14(path14.join(dir, MANIFEST), "utf8"));
|
|
10550
10889
|
undo(dir, m3.entries, env);
|
|
10551
10890
|
restored += m3.entries.length;
|
|
10552
10891
|
renameWithRetry(path14.join(dir, MANIFEST), path14.join(dir, MANIFEST_DONE));
|
|
@@ -10558,7 +10897,7 @@ function runRemove(opts) {
|
|
|
10558
10897
|
}
|
|
10559
10898
|
|
|
10560
10899
|
// src/setup/print.ts
|
|
10561
|
-
import { readFileSync as
|
|
10900
|
+
import { readFileSync as readFileSync15 } from "node:fs";
|
|
10562
10901
|
var SHELL_SAFE_PUNCT = "@%+=:,./-_";
|
|
10563
10902
|
function isShellSafe(s) {
|
|
10564
10903
|
if (s === "") return false;
|
|
@@ -10586,7 +10925,7 @@ function printPlan(row, env) {
|
|
|
10586
10925
|
else if (h2.kind === "plugin-list") steps.push({ kind: "hook", file: h2.file, block: JSON.stringify({ [h2.key[0]]: [h2.entry] }, null, 2) + "\n" });
|
|
10587
10926
|
const sk = row.skillInstall;
|
|
10588
10927
|
if (sk.kind === "dir") {
|
|
10589
|
-
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(
|
|
10928
|
+
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync15(f2.src, "utf8"), sk.prefixes) });
|
|
10590
10929
|
}
|
|
10591
10930
|
return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
|
|
10592
10931
|
}
|
|
@@ -11014,7 +11353,7 @@ async function upgrade(ui) {
|
|
|
11014
11353
|
}
|
|
11015
11354
|
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
11016
11355
|
const cli = path15.join(root, "context-mode", "cli.mjs");
|
|
11017
|
-
if (!root || !
|
|
11356
|
+
if (!root || !existsSync20(cli)) {
|
|
11018
11357
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
11019
11358
|
return EXIT_FAIL;
|
|
11020
11359
|
}
|
|
@@ -11053,12 +11392,12 @@ Run context-mode ${cmd} --help.`);
|
|
|
11053
11392
|
}
|
|
11054
11393
|
|
|
11055
11394
|
// src/entries/is-entry.ts
|
|
11056
|
-
import { realpathSync as
|
|
11395
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
11057
11396
|
function isEntry(main2, argv1, self) {
|
|
11058
11397
|
if (main2 !== void 0) return main2;
|
|
11059
11398
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
11060
11399
|
try {
|
|
11061
|
-
return
|
|
11400
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
11062
11401
|
} catch {
|
|
11063
11402
|
return false;
|
|
11064
11403
|
}
|
|
@@ -11109,10 +11448,10 @@ function route(argv, version) {
|
|
|
11109
11448
|
` };
|
|
11110
11449
|
}
|
|
11111
11450
|
function main() {
|
|
11112
|
-
const dir = path16.dirname(
|
|
11451
|
+
const dir = path16.dirname(realpathSync12(fileURLToPath3(import.meta.url)));
|
|
11113
11452
|
let version = "";
|
|
11114
11453
|
try {
|
|
11115
|
-
version = String(JSON.parse(
|
|
11454
|
+
version = String(JSON.parse(readFileSync16(path16.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
11116
11455
|
} catch (err2) {
|
|
11117
11456
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
11118
11457
|
`);
|