context-mode 2.0.0-next.30 → 2.0.0-next.32
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 +22 -22
- package/SHA256SUMS +15 -15
- package/cli.mjs +325 -155
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +75 -75
- package/opencode/plugin.js +636 -149
- package/package.json +1 -1
- package/pi/index.js +678 -191
- package/qwen-extension.json +1 -1
- package/run.mjs +66 -5
- package/search.mjs +66 -5
- package/server.mjs +665 -178
package/cli.mjs
CHANGED
|
@@ -88,7 +88,7 @@ var require_src = __commonJS({
|
|
|
88
88
|
|
|
89
89
|
// src/entries/cli.ts
|
|
90
90
|
import { spawn as spawn4 } from "node:child_process";
|
|
91
|
-
import { readFileSync as
|
|
91
|
+
import { readFileSync as readFileSync12, realpathSync as realpathSync9 } from "node:fs";
|
|
92
92
|
import path14 from "node:path";
|
|
93
93
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
94
94
|
|
|
@@ -228,6 +228,7 @@ var DECAY_X1000 = Object.freeze([
|
|
|
228
228
|
250
|
|
229
229
|
]);
|
|
230
230
|
var EXEC_TIMEOUT_MS = 6e5;
|
|
231
|
+
var DB_TIMEOUT_MS = 5e3;
|
|
231
232
|
var DB_WAL_SUFFIX = "-wal";
|
|
232
233
|
var DB_SHM_SUFFIX = "-shm";
|
|
233
234
|
var HOOK_TIMEOUT_MS = 5e3;
|
|
@@ -304,17 +305,25 @@ var STATS_EMPTY_LINES = Object.freeze([
|
|
|
304
305
|
"sandbox, and only the short answer goes to the chat."
|
|
305
306
|
]);
|
|
306
307
|
var STATS_KIND_LABELS = Object.freeze([
|
|
307
|
-
|
|
308
|
+
// D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
|
|
308
309
|
["index", "Content indexed"],
|
|
309
310
|
["edit", "File edits"],
|
|
310
|
-
["toolerr", "
|
|
311
|
+
["toolerr", "Issues kept"],
|
|
311
312
|
["decision", "Your decisions"],
|
|
313
|
+
["cmd", "Other tool calls"],
|
|
312
314
|
["prompt", "Your prompts"]
|
|
313
315
|
]);
|
|
314
316
|
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
315
|
-
"ctx_resume brings back your last task, files changed and open
|
|
317
|
+
"ctx_resume brings back your last task, files changed and open issues",
|
|
316
318
|
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
317
319
|
]);
|
|
320
|
+
var STATS_WAYS = Object.freeze([
|
|
321
|
+
["sandbox", "\u2588", "sandbox run"],
|
|
322
|
+
["index", "\u2593", "index + search"],
|
|
323
|
+
["redirect", "\u2592", "hook sent to sandbox"],
|
|
324
|
+
["replace", "\u2591", "hook cut down"]
|
|
325
|
+
]);
|
|
326
|
+
var STATS_INDEX_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
|
|
318
327
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
319
328
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
320
329
|
var RELEASE_BRANCH = "release";
|
|
@@ -491,7 +500,7 @@ var V1_REASON = Object.freeze({
|
|
|
491
500
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
492
501
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
493
502
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
494
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only,
|
|
503
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
495
504
|
});
|
|
496
505
|
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
497
506
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
@@ -527,6 +536,60 @@ var OWN_MCP_ENTRY = Object.freeze({
|
|
|
527
536
|
var REPORT_ENV_ENUMS = Object.freeze({
|
|
528
537
|
NODE_ENV: Object.freeze(["development", "production", "test"])
|
|
529
538
|
});
|
|
539
|
+
var DOCTOR_ENV_PREFIX = "Environment: ";
|
|
540
|
+
var DOCTOR_DOCS_LABEL = "Docs: ";
|
|
541
|
+
var DOCTOR_REPORT_LINE = "Report file: ";
|
|
542
|
+
var DOCTOR_GH_LINE = "File it: ";
|
|
543
|
+
var DOCTOR_URL_LINE = "Or open: ";
|
|
544
|
+
var DOCTOR_GH_NEXT = " --";
|
|
545
|
+
var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
546
|
+
DOCTOR_ENV_PREFIX,
|
|
547
|
+
DOCTOR_DOCS_LABEL,
|
|
548
|
+
DOCTOR_REPORT_LINE,
|
|
549
|
+
DOCTOR_GH_LINE,
|
|
550
|
+
DOCTOR_GH_NEXT.trim(),
|
|
551
|
+
DOCTOR_URL_LINE
|
|
552
|
+
]);
|
|
553
|
+
var ISSUE_REPO_SLUG = "mksglu/context-mode";
|
|
554
|
+
var ISSUE_FORM_FILE = "agent-report.yml";
|
|
555
|
+
var ISSUE_URL_MAX = 8e3;
|
|
556
|
+
var ISSUE_FORM_HEADINGS = Object.freeze([
|
|
557
|
+
"Summary",
|
|
558
|
+
"ctx-report",
|
|
559
|
+
"What happened",
|
|
560
|
+
"Hook errors",
|
|
561
|
+
"Journal rows",
|
|
562
|
+
"Agent config",
|
|
563
|
+
"Expected",
|
|
564
|
+
"Steps",
|
|
565
|
+
"Environment"
|
|
566
|
+
]);
|
|
567
|
+
var DOCTOR_ENV_NAMES = Object.freeze([
|
|
568
|
+
"CODEX_HOME",
|
|
569
|
+
"CLAUDE_CONFIG_DIR",
|
|
570
|
+
"CLAUDE_PLUGIN_ROOT",
|
|
571
|
+
"COPILOT_HOME",
|
|
572
|
+
"KIRO_HOME",
|
|
573
|
+
"OPENCODE_CONFIG_DIR",
|
|
574
|
+
"PI_CODING_AGENT_DIR",
|
|
575
|
+
"XDG_CONFIG_HOME",
|
|
576
|
+
"SHELL"
|
|
577
|
+
]);
|
|
578
|
+
var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
|
|
579
|
+
var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
|
|
580
|
+
var NATIVE_INSTALL = Object.freeze({
|
|
581
|
+
"claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
|
|
582
|
+
codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
|
|
583
|
+
gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
|
|
584
|
+
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
|
|
585
|
+
opencode: ["opencode plugin add context-mode@next"],
|
|
586
|
+
pi: ["pi install npm:context-mode@next"],
|
|
587
|
+
"copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
|
|
588
|
+
vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
|
|
589
|
+
kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
|
|
590
|
+
zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
|
|
591
|
+
});
|
|
592
|
+
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
530
593
|
|
|
531
594
|
// src/adapters/claude-code.ts
|
|
532
595
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -1618,9 +1681,9 @@ Examples:
|
|
|
1618
1681
|
};
|
|
1619
1682
|
|
|
1620
1683
|
// src/cli/commands.ts
|
|
1621
|
-
import { spawnSync as
|
|
1684
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1622
1685
|
import { createHash as createHash2 } from "node:crypto";
|
|
1623
|
-
import { existsSync as
|
|
1686
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1624
1687
|
import os from "node:os";
|
|
1625
1688
|
import path13 from "node:path";
|
|
1626
1689
|
|
|
@@ -4571,12 +4634,116 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4571
4634
|
return agent === "vscode" ? join2(vscodeUserDirOf(env, home), ...file) : join2(home, ...file);
|
|
4572
4635
|
}
|
|
4573
4636
|
|
|
4574
|
-
// src/
|
|
4575
|
-
import
|
|
4637
|
+
// src/core/ops/doctor-issue.ts
|
|
4638
|
+
import { spawnSync } from "node:child_process";
|
|
4639
|
+
import { closeSync, existsSync as existsSync7, fstatSync, mkdirSync as mkdirSync4, openSync, readFileSync as readFileSync4, readSync, realpathSync as realpathSync3, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4640
|
+
import { delimiter, join as join8 } from "node:path";
|
|
4641
|
+
|
|
4642
|
+
// src/core/hooks/fallback.ts
|
|
4643
|
+
import { join as join3, resolve as resolve2 } from "node:path";
|
|
4644
|
+
var fs = process.getBuiltinModule("node:fs");
|
|
4645
|
+
|
|
4646
|
+
// src/core/store/schema.ts
|
|
4647
|
+
var PRAGMAS = `
|
|
4648
|
+
PRAGMA busy_timeout = ${DB_TIMEOUT_MS};
|
|
4649
|
+
PRAGMA journal_mode = WAL;
|
|
4650
|
+
`;
|
|
4651
|
+
var FTS_TOKENIZE = "tokenize = 'porter unicode61 remove_diacritics 2'";
|
|
4652
|
+
var FTS_TOKENIZE_V1 = "tokenize = 'unicode61 remove_diacritics 2'";
|
|
4653
|
+
var DDL = `
|
|
4654
|
+
CREATE TABLE IF NOT EXISTS events (
|
|
4655
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4656
|
+
session_id TEXT NOT NULL,
|
|
4657
|
+
worktree TEXT NOT NULL,
|
|
4658
|
+
agent TEXT NOT NULL,
|
|
4659
|
+
kind TEXT NOT NULL CHECK (kind IN ('prompt','edit','cmd','toolerr','index','cost','decision')),
|
|
4660
|
+
tool TEXT,
|
|
4661
|
+
key TEXT,
|
|
4662
|
+
path TEXT,
|
|
4663
|
+
ok INTEGER,
|
|
4664
|
+
exit_code INTEGER,
|
|
4665
|
+
bytes INTEGER,
|
|
4666
|
+
body TEXT,
|
|
4667
|
+
turn INTEGER NOT NULL,
|
|
4668
|
+
sandbox_bytes INTEGER NOT NULL DEFAULT 0,
|
|
4669
|
+
returned_bytes INTEGER NOT NULL DEFAULT 0,
|
|
4670
|
+
created_at INTEGER NOT NULL,
|
|
4671
|
+
accessed_at INTEGER NOT NULL
|
|
4672
|
+
);
|
|
4673
|
+
CREATE INDEX IF NOT EXISTS idx_events_session_kind_seq ON events(session_id, kind, seq);
|
|
4674
|
+
CREATE INDEX IF NOT EXISTS idx_events_session_kind_key_seq ON events(session_id, kind, key, seq);
|
|
4675
|
+
|
|
4676
|
+
CREATE TABLE IF NOT EXISTS sources (
|
|
4677
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
4678
|
+
session_id TEXT NOT NULL,
|
|
4679
|
+
worktree TEXT NOT NULL,
|
|
4680
|
+
agent TEXT NOT NULL,
|
|
4681
|
+
kind TEXT NOT NULL CHECK (kind IN ('path','content','url')),
|
|
4682
|
+
label TEXT NOT NULL,
|
|
4683
|
+
bytes_total INTEGER NOT NULL,
|
|
4684
|
+
chunk_count INTEGER NOT NULL,
|
|
4685
|
+
created_ts INTEGER NOT NULL,
|
|
4686
|
+
created_at TEXT NOT NULL,
|
|
4687
|
+
accessed_ts INTEGER NOT NULL
|
|
4688
|
+
);
|
|
4689
|
+
CREATE INDEX IF NOT EXISTS idx_sources_accessed ON sources(accessed_ts);
|
|
4690
|
+
|
|
4691
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS chunks USING fts5(
|
|
4692
|
+
source_id UNINDEXED,
|
|
4693
|
+
session_id UNINDEXED,
|
|
4694
|
+
worktree UNINDEXED,
|
|
4695
|
+
agent UNINDEXED,
|
|
4696
|
+
ord UNINDEXED,
|
|
4697
|
+
body,
|
|
4698
|
+
${FTS_TOKENIZE_V1}
|
|
4699
|
+
);
|
|
4700
|
+
|
|
4701
|
+
CREATE TABLE IF NOT EXISTS meta (
|
|
4702
|
+
key TEXT PRIMARY KEY,
|
|
4703
|
+
value TEXT NOT NULL
|
|
4704
|
+
);
|
|
4705
|
+
`;
|
|
4706
|
+
var DDL_V3 = `
|
|
4707
|
+
CREATE VIRTUAL TABLE chunks_v3 USING fts5(
|
|
4708
|
+
source_id UNINDEXED,
|
|
4709
|
+
session_id UNINDEXED,
|
|
4710
|
+
worktree UNINDEXED,
|
|
4711
|
+
agent UNINDEXED,
|
|
4712
|
+
ord UNINDEXED,
|
|
4713
|
+
body,
|
|
4714
|
+
title,
|
|
4715
|
+
${FTS_TOKENIZE}
|
|
4716
|
+
);
|
|
4717
|
+
INSERT INTO chunks_v3(rowid, source_id, session_id, worktree, agent, ord, body, title)
|
|
4718
|
+
SELECT rowid, source_id, session_id, worktree, agent, ord, body, '' FROM chunks;
|
|
4719
|
+
DROP TABLE chunks;
|
|
4720
|
+
ALTER TABLE chunks_v3 RENAME TO chunks;
|
|
4721
|
+
`;
|
|
4722
|
+
var DDL_V5 = `
|
|
4723
|
+
CREATE VIRTUAL TABLE line_units USING fts5(
|
|
4724
|
+
body,
|
|
4725
|
+
source_id UNINDEXED,
|
|
4726
|
+
session_id UNINDEXED,
|
|
4727
|
+
ord UNINDEXED,
|
|
4728
|
+
${FTS_TOKENIZE}
|
|
4729
|
+
);
|
|
4730
|
+
`;
|
|
4731
|
+
|
|
4732
|
+
// src/core/store/db.ts
|
|
4733
|
+
var { existsSync: existsSync2, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4734
|
+
|
|
4735
|
+
// src/core/ops/doctor-config.ts
|
|
4736
|
+
import { existsSync as existsSync6, readdirSync as readdirSync4 } from "node:fs";
|
|
4737
|
+
import { join as join7 } from "node:path";
|
|
4738
|
+
|
|
4739
|
+
// src/core/ops/detect-v1.ts
|
|
4740
|
+
import { existsSync as existsSync4, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
4741
|
+
import { tmpdir } from "node:os";
|
|
4742
|
+
import { join as join5 } from "node:path";
|
|
4576
4743
|
|
|
4577
4744
|
// src/core/ops/host-config.ts
|
|
4578
|
-
import { existsSync as
|
|
4579
|
-
import { dirname as dirname3, join as
|
|
4745
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
4746
|
+
import { dirname as dirname3, join as join4 } from "node:path";
|
|
4580
4747
|
|
|
4581
4748
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4582
4749
|
var KEYS2 = {
|
|
@@ -6622,7 +6789,7 @@ function parseTOML(code, options) {
|
|
|
6622
6789
|
}
|
|
6623
6790
|
|
|
6624
6791
|
// src/core/ops/atomic-file.ts
|
|
6625
|
-
import { mkdirSync as
|
|
6792
|
+
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6626
6793
|
import path2 from "node:path";
|
|
6627
6794
|
function sleepSync(ms) {
|
|
6628
6795
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
@@ -6673,7 +6840,7 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
6673
6840
|
}
|
|
6674
6841
|
}
|
|
6675
6842
|
function atomicWriteFile(file, text2, opts = {}) {
|
|
6676
|
-
|
|
6843
|
+
mkdirSync3(path2.dirname(file), { recursive: true });
|
|
6677
6844
|
const tmp = path2.join(path2.dirname(file), `${ATOMIC_TMP_PREFIX}${path2.basename(file)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
6678
6845
|
try {
|
|
6679
6846
|
writeFileSync(tmp, text2);
|
|
@@ -7078,14 +7245,7 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7078
7245
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7079
7246
|
}
|
|
7080
7247
|
|
|
7081
|
-
// src/core/ops/doctor-config.ts
|
|
7082
|
-
import { existsSync as existsSync5, readdirSync as readdirSync4 } from "node:fs";
|
|
7083
|
-
import { join as join6 } from "node:path";
|
|
7084
|
-
|
|
7085
7248
|
// src/core/ops/detect-v1.ts
|
|
7086
|
-
import { existsSync as existsSync3, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
7087
|
-
import { tmpdir } from "node:os";
|
|
7088
|
-
import { join as join4 } from "node:path";
|
|
7089
7249
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7090
7250
|
var keyPath = (...parts) => parts.join(".");
|
|
7091
7251
|
var finding = (file, path15, reason) => ({ file, path: path15, reason });
|
|
@@ -7192,7 +7352,7 @@ function flatCommands(events2, prefix) {
|
|
|
7192
7352
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7193
7353
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
|
|
7194
7354
|
function dataDir(dir, reason, out2) {
|
|
7195
|
-
if (
|
|
7355
|
+
if (existsSync4(dir)) out2.push(finding(dir, "", reason));
|
|
7196
7356
|
}
|
|
7197
7357
|
function mcpEntry(file, doc, out2) {
|
|
7198
7358
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7200,7 +7360,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7200
7360
|
}
|
|
7201
7361
|
}
|
|
7202
7362
|
function claudeShapeSettings(agentHome, out2) {
|
|
7203
|
-
const file =
|
|
7363
|
+
const file = join5(agentHome, SETTINGS_FILE);
|
|
7204
7364
|
const doc = readJson(file);
|
|
7205
7365
|
for (const c3 of nestedCommands(doc)) {
|
|
7206
7366
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7220,49 +7380,49 @@ function v1HookFile(file, out2) {
|
|
|
7220
7380
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7221
7381
|
claudeShapeSettings(agentHome, out2);
|
|
7222
7382
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7223
|
-
const file =
|
|
7224
|
-
if (
|
|
7383
|
+
const file = join5(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
7384
|
+
if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.cacheHealFile));
|
|
7225
7385
|
}
|
|
7226
|
-
const userFile =
|
|
7386
|
+
const userFile = join5(home, CLAUDE_USER_CONFIG_FILE);
|
|
7227
7387
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7228
|
-
dataDir(
|
|
7388
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7229
7389
|
}
|
|
7230
7390
|
function scanCodex(agentHome, out2) {
|
|
7231
|
-
const hooksFile =
|
|
7391
|
+
const hooksFile = join5(agentHome, HOOKS_JSON_FILE);
|
|
7232
7392
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7233
7393
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7234
7394
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7235
7395
|
}
|
|
7236
7396
|
}
|
|
7237
|
-
const tomlFile =
|
|
7397
|
+
const tomlFile = join5(agentHome, CONFIG_TOML_FILE);
|
|
7238
7398
|
const config = readTomlValue(tomlFile);
|
|
7239
7399
|
for (const span of readTomlTables(tomlFile)) {
|
|
7240
7400
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7241
7401
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7242
7402
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7243
7403
|
}
|
|
7244
|
-
dataDir(
|
|
7404
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7245
7405
|
}
|
|
7246
7406
|
function scanGemini(agentHome, out2) {
|
|
7247
|
-
const file =
|
|
7407
|
+
const file = join5(agentHome, SETTINGS_FILE);
|
|
7248
7408
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7249
7409
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7250
7410
|
}
|
|
7251
|
-
dataDir(
|
|
7411
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7252
7412
|
}
|
|
7253
7413
|
function scanVscode(agentHome, project, out2) {
|
|
7254
7414
|
if (project !== void 0) {
|
|
7255
|
-
v1HookFile(
|
|
7256
|
-
const mcpFile =
|
|
7415
|
+
v1HookFile(join5(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7416
|
+
const mcpFile = join5(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
7257
7417
|
const doc = readJson(mcpFile);
|
|
7258
7418
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7259
7419
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7260
7420
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7261
7421
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7262
7422
|
}
|
|
7263
|
-
dataDir(
|
|
7423
|
+
dataDir(join5(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7264
7424
|
}
|
|
7265
|
-
dataDir(
|
|
7425
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7266
7426
|
}
|
|
7267
7427
|
function jsonFiles(dir) {
|
|
7268
7428
|
try {
|
|
@@ -7272,10 +7432,10 @@ function jsonFiles(dir) {
|
|
|
7272
7432
|
}
|
|
7273
7433
|
}
|
|
7274
7434
|
function scanKiro(agentHome, project, out2) {
|
|
7275
|
-
const agentsDir =
|
|
7276
|
-
const defaultFile =
|
|
7435
|
+
const agentsDir = join5(agentHome, KIRO_AGENTS_DIR);
|
|
7436
|
+
const defaultFile = join5(agentHome, ...KIRO_AGENT_FILE);
|
|
7277
7437
|
for (const name of jsonFiles(agentsDir)) {
|
|
7278
|
-
const file =
|
|
7438
|
+
const file = join5(agentsDir, name);
|
|
7279
7439
|
const doc = readJson(file);
|
|
7280
7440
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7281
7441
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7286,25 +7446,25 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7286
7446
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7287
7447
|
}
|
|
7288
7448
|
}
|
|
7289
|
-
const steeringDocs = [
|
|
7290
|
-
if (project !== void 0) steeringDocs.push(
|
|
7449
|
+
const steeringDocs = [join5(agentHome, ...KIRO_STEERING_FILE)];
|
|
7450
|
+
if (project !== void 0) steeringDocs.push(join5(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
7291
7451
|
for (const file of steeringDocs) {
|
|
7292
|
-
if (
|
|
7452
|
+
if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7293
7453
|
}
|
|
7294
|
-
dataDir(
|
|
7454
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7295
7455
|
}
|
|
7296
7456
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7297
|
-
const file =
|
|
7457
|
+
const file = join5(piAgentDir, SETTINGS_FILE);
|
|
7298
7458
|
const doc = readJson(file);
|
|
7299
7459
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7300
7460
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7301
7461
|
if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7302
7462
|
});
|
|
7303
|
-
dataDir(
|
|
7463
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7304
7464
|
}
|
|
7305
7465
|
function scanOpencode(agentHome, out2) {
|
|
7306
7466
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7307
|
-
const file =
|
|
7467
|
+
const file = join5(agentHome, name);
|
|
7308
7468
|
const doc = readJson(file);
|
|
7309
7469
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7310
7470
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7314,13 +7474,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7314
7474
|
}
|
|
7315
7475
|
}
|
|
7316
7476
|
function scanZcode(agentHome, out2) {
|
|
7317
|
-
const configFile =
|
|
7477
|
+
const configFile = join5(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7318
7478
|
const config = readJson(configFile);
|
|
7319
7479
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7320
7480
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7321
7481
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7322
7482
|
}
|
|
7323
|
-
const hooksFile =
|
|
7483
|
+
const hooksFile = join5(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7324
7484
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7325
7485
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7326
7486
|
}
|
|
@@ -7344,14 +7504,14 @@ function firstTmpMatch(dir) {
|
|
|
7344
7504
|
}
|
|
7345
7505
|
}
|
|
7346
7506
|
function scanAll(home, tmp, out2) {
|
|
7347
|
-
const root =
|
|
7348
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
7507
|
+
const root = join5(home, DATA_ROOT.slice(1));
|
|
7508
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join5(root, name), V1_REASON.dataRoot, out2);
|
|
7349
7509
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7350
7510
|
}
|
|
7351
7511
|
function detectV1(agent, home, scope = {}) {
|
|
7352
7512
|
const out2 = [];
|
|
7353
7513
|
const project = scope.project;
|
|
7354
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
7514
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join5(home, ...AGENT_HOME_DIR[agent]);
|
|
7355
7515
|
switch (agent) {
|
|
7356
7516
|
case "claude-code":
|
|
7357
7517
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7364,11 +7524,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7364
7524
|
break;
|
|
7365
7525
|
case "qwen":
|
|
7366
7526
|
claudeShapeSettings(agentHome, out2);
|
|
7367
|
-
dataDir(
|
|
7527
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7368
7528
|
break;
|
|
7369
7529
|
case "copilot-cli":
|
|
7370
|
-
v1HookFile(
|
|
7371
|
-
dataDir(
|
|
7530
|
+
v1HookFile(join5(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out2);
|
|
7531
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7372
7532
|
break;
|
|
7373
7533
|
case "vscode":
|
|
7374
7534
|
scanVscode(agentHome, project, out2);
|
|
@@ -7377,7 +7537,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7377
7537
|
scanKiro(agentHome, project, out2);
|
|
7378
7538
|
break;
|
|
7379
7539
|
case "pi":
|
|
7380
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
7540
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join5(agentHome, PI_AGENT_DIR), agentHome, out2);
|
|
7381
7541
|
break;
|
|
7382
7542
|
// D-WIN-PIDIR-1: empty is unset
|
|
7383
7543
|
case "opencode":
|
|
@@ -7392,8 +7552,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7392
7552
|
}
|
|
7393
7553
|
|
|
7394
7554
|
// src/core/ops/plugin-root.ts
|
|
7395
|
-
import { existsSync as
|
|
7396
|
-
import { dirname as dirname4, isAbsolute, join as
|
|
7555
|
+
import { existsSync as existsSync5, readdirSync as readdirSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
7556
|
+
import { dirname as dirname4, isAbsolute, join as join6, sep } from "node:path";
|
|
7397
7557
|
import { fileURLToPath } from "node:url";
|
|
7398
7558
|
|
|
7399
7559
|
// src/core/ops/doctor-config.ts
|
|
@@ -7408,6 +7568,16 @@ function composeMatcher(row, event) {
|
|
|
7408
7568
|
}
|
|
7409
7569
|
var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
7410
7570
|
|
|
7571
|
+
// src/core/ops/doctor-issue.ts
|
|
7572
|
+
function formUrl(title, summary) {
|
|
7573
|
+
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
7574
|
+
const full = `${base}&summary=${encodeURIComponent(summary)}`;
|
|
7575
|
+
return full.length < ISSUE_URL_MAX ? full : base;
|
|
7576
|
+
}
|
|
7577
|
+
|
|
7578
|
+
// src/setup/registry.ts
|
|
7579
|
+
import path3 from "node:path";
|
|
7580
|
+
|
|
7411
7581
|
// src/setup/hook-shapes.ts
|
|
7412
7582
|
var MS_PER_SECOND = 1e3;
|
|
7413
7583
|
var TOOL_EVENTS = ["PreToolUse", "PostToolUse"];
|
|
@@ -7703,7 +7873,7 @@ function assertWritable(row, file) {
|
|
|
7703
7873
|
}
|
|
7704
7874
|
|
|
7705
7875
|
// src/setup/gemini-gate.ts
|
|
7706
|
-
import { existsSync as
|
|
7876
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
|
|
7707
7877
|
import path4 from "node:path";
|
|
7708
7878
|
var GEMINI_DIR = ".gemini";
|
|
7709
7879
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -7717,9 +7887,9 @@ function systemSettingsPath(env) {
|
|
|
7717
7887
|
return "/etc/gemini-cli/settings.json";
|
|
7718
7888
|
}
|
|
7719
7889
|
function load(file) {
|
|
7720
|
-
if (!
|
|
7890
|
+
if (!existsSync8(file)) return void 0;
|
|
7721
7891
|
try {
|
|
7722
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
7892
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync5(file, "utf8")), "jsonc") };
|
|
7723
7893
|
} catch {
|
|
7724
7894
|
return void 0;
|
|
7725
7895
|
}
|
|
@@ -7751,7 +7921,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
7751
7921
|
}
|
|
7752
7922
|
|
|
7753
7923
|
// src/setup/zcode-gate.ts
|
|
7754
|
-
import { existsSync as
|
|
7924
|
+
import { existsSync as existsSync9, readFileSync as readFileSync6 } from "node:fs";
|
|
7755
7925
|
import path5 from "node:path";
|
|
7756
7926
|
var OWN_AGENT2 = "zcode";
|
|
7757
7927
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -7843,10 +8013,10 @@ function zcodeSchemaBad(doc) {
|
|
|
7843
8013
|
}
|
|
7844
8014
|
function zcodeConfigGate(home) {
|
|
7845
8015
|
const file = path5.join(home, ".zcode", "cli", "config.json");
|
|
7846
|
-
if (!
|
|
8016
|
+
if (!existsSync9(file)) return void 0;
|
|
7847
8017
|
let doc;
|
|
7848
8018
|
try {
|
|
7849
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8019
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync6(file, "utf8")), "json");
|
|
7850
8020
|
} catch {
|
|
7851
8021
|
return void 0;
|
|
7852
8022
|
}
|
|
@@ -7856,7 +8026,7 @@ function zcodeConfigGate(home) {
|
|
|
7856
8026
|
}
|
|
7857
8027
|
|
|
7858
8028
|
// src/setup/pi-gate.ts
|
|
7859
|
-
import { existsSync as
|
|
8029
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
7860
8030
|
import path6 from "node:path";
|
|
7861
8031
|
var OWN_FILE = "pi/index.js";
|
|
7862
8032
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7865,16 +8035,16 @@ var TRUST_FILE = "trust.json";
|
|
|
7865
8035
|
var ALWAYS = "always";
|
|
7866
8036
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7867
8037
|
function load2(file) {
|
|
7868
|
-
if (!
|
|
8038
|
+
if (!existsSync10(file)) return void 0;
|
|
7869
8039
|
try {
|
|
7870
|
-
return { file, doc: parseHostConfig("pi", file, hostText(
|
|
8040
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
|
|
7871
8041
|
} catch {
|
|
7872
8042
|
return void 0;
|
|
7873
8043
|
}
|
|
7874
8044
|
}
|
|
7875
8045
|
var real = (p3) => {
|
|
7876
8046
|
try {
|
|
7877
|
-
return
|
|
8047
|
+
return realpathSync4(p3);
|
|
7878
8048
|
} catch {
|
|
7879
8049
|
return path6.resolve(p3);
|
|
7880
8050
|
}
|
|
@@ -7956,7 +8126,7 @@ function piSettingsGate(env, home, pkgDir, cwd) {
|
|
|
7956
8126
|
}
|
|
7957
8127
|
|
|
7958
8128
|
// src/setup/vscode-gate.ts
|
|
7959
|
-
import { existsSync as
|
|
8129
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8 } from "node:fs";
|
|
7960
8130
|
import path7 from "node:path";
|
|
7961
8131
|
var SETTINGS_FILE3 = "settings.json";
|
|
7962
8132
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -7965,9 +8135,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
7965
8135
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
7966
8136
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
7967
8137
|
function load3(file) {
|
|
7968
|
-
if (!
|
|
8138
|
+
if (!existsSync11(file)) return void 0;
|
|
7969
8139
|
try {
|
|
7970
|
-
return { file, doc: parseHostConfig("vscode", file, hostText(
|
|
8140
|
+
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
7971
8141
|
} catch {
|
|
7972
8142
|
return void 0;
|
|
7973
8143
|
}
|
|
@@ -8007,7 +8177,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
8007
8177
|
}
|
|
8008
8178
|
|
|
8009
8179
|
// src/setup/qwen-gate.ts
|
|
8010
|
-
import { existsSync as
|
|
8180
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "node:fs";
|
|
8011
8181
|
import path8 from "node:path";
|
|
8012
8182
|
var KEY = "disableAllHooks";
|
|
8013
8183
|
var SETTINGS = "settings.json";
|
|
@@ -8023,10 +8193,10 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8023
8193
|
}
|
|
8024
8194
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8025
8195
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8026
|
-
if (!
|
|
8196
|
+
if (!existsSync12(file)) continue;
|
|
8027
8197
|
let value;
|
|
8028
8198
|
try {
|
|
8029
|
-
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(
|
|
8199
|
+
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
|
|
8030
8200
|
} catch {
|
|
8031
8201
|
continue;
|
|
8032
8202
|
}
|
|
@@ -8037,19 +8207,19 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8037
8207
|
|
|
8038
8208
|
// src/setup/codex-trust.ts
|
|
8039
8209
|
import { createHash } from "node:crypto";
|
|
8040
|
-
import { existsSync as
|
|
8210
|
+
import { existsSync as existsSync13, realpathSync as realpathSync5 } from "node:fs";
|
|
8041
8211
|
import path10 from "node:path";
|
|
8042
|
-
import { spawn, spawnSync as
|
|
8212
|
+
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8043
8213
|
|
|
8044
8214
|
// src/setup/spawn-bin.ts
|
|
8045
|
-
import { spawnSync } from "node:child_process";
|
|
8215
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
8046
8216
|
import { accessSync, constants as fsc, statSync } from "node:fs";
|
|
8047
8217
|
import path9 from "node:path";
|
|
8048
8218
|
|
|
8049
8219
|
// src/core/sandbox/path-entries.ts
|
|
8050
|
-
function pathEntries(value, platform = process.platform,
|
|
8220
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
8051
8221
|
const win = platform === "win32";
|
|
8052
|
-
return value.split(
|
|
8222
|
+
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
8053
8223
|
}
|
|
8054
8224
|
|
|
8055
8225
|
// src/setup/spawn-bin.ts
|
|
@@ -8120,7 +8290,7 @@ function spawnShim(file, args, env, opts, platform = process.platform) {
|
|
|
8120
8290
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
8121
8291
|
return { pid: 0, output: [null, "", error.message], stdout: "", stderr: error.message, status: null, signal: null, error };
|
|
8122
8292
|
}
|
|
8123
|
-
return
|
|
8293
|
+
return spawnSync2(f2.command, f2.args, { ...opts, env, windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
8124
8294
|
}
|
|
8125
8295
|
|
|
8126
8296
|
// src/setup/codex-trust.ts
|
|
@@ -8145,11 +8315,11 @@ function snake(name) {
|
|
|
8145
8315
|
function realFile(file) {
|
|
8146
8316
|
let dir = path10.resolve(file);
|
|
8147
8317
|
const rest = [];
|
|
8148
|
-
while (!
|
|
8318
|
+
while (!existsSync13(dir) && path10.dirname(dir) !== dir) {
|
|
8149
8319
|
rest.unshift(path10.basename(dir));
|
|
8150
8320
|
dir = path10.dirname(dir);
|
|
8151
8321
|
}
|
|
8152
|
-
return path10.join(
|
|
8322
|
+
return path10.join(realpathSync5(dir), ...rest);
|
|
8153
8323
|
}
|
|
8154
8324
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8155
8325
|
var ASK_TRIES = 3;
|
|
@@ -8235,14 +8405,14 @@ async function listPluginHooks(env, pluginId, cwd) {
|
|
|
8235
8405
|
function askPluginHooks(env, pluginId, cwd) {
|
|
8236
8406
|
const bin = whichBin("codex", env);
|
|
8237
8407
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
8238
|
-
return new Promise((
|
|
8408
|
+
return new Promise((resolve3) => {
|
|
8239
8409
|
let asked;
|
|
8240
8410
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
8241
8411
|
let f2;
|
|
8242
8412
|
try {
|
|
8243
8413
|
f2 = spawnForm(bin, ["app-server"], env);
|
|
8244
8414
|
} catch {
|
|
8245
|
-
|
|
8415
|
+
resolve3({ kind: "silent" });
|
|
8246
8416
|
return;
|
|
8247
8417
|
}
|
|
8248
8418
|
const child = spawn(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -8252,7 +8422,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
8252
8422
|
let result;
|
|
8253
8423
|
const settle = () => {
|
|
8254
8424
|
clearTimeout(grace);
|
|
8255
|
-
|
|
8425
|
+
resolve3(done_(result));
|
|
8256
8426
|
};
|
|
8257
8427
|
let grace;
|
|
8258
8428
|
const finish2 = (v) => {
|
|
@@ -8309,7 +8479,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
8309
8479
|
function stopTree(pid, kill) {
|
|
8310
8480
|
if (process.platform === "win32" && pid !== void 0) {
|
|
8311
8481
|
try {
|
|
8312
|
-
|
|
8482
|
+
spawnSync3("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
|
|
8313
8483
|
} catch {
|
|
8314
8484
|
}
|
|
8315
8485
|
}
|
|
@@ -8333,7 +8503,7 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
8333
8503
|
|
|
8334
8504
|
// src/setup/copilot-hooks.ts
|
|
8335
8505
|
import { spawn as spawn2 } from "node:child_process";
|
|
8336
|
-
import { realpathSync as
|
|
8506
|
+
import { realpathSync as realpathSync6 } from "node:fs";
|
|
8337
8507
|
import path11 from "node:path";
|
|
8338
8508
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
8339
8509
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
@@ -8343,7 +8513,7 @@ var USER_ORIGIN = "user";
|
|
|
8343
8513
|
function canon(p3) {
|
|
8344
8514
|
let r2 = path11.resolve(p3);
|
|
8345
8515
|
try {
|
|
8346
|
-
r2 =
|
|
8516
|
+
r2 = realpathSync6(r2);
|
|
8347
8517
|
} catch {
|
|
8348
8518
|
}
|
|
8349
8519
|
return process.platform === "win32" ? r2.toLowerCase() : r2;
|
|
@@ -8376,12 +8546,12 @@ function frame(buf) {
|
|
|
8376
8546
|
function listCopilotHooks(env, file, cwd) {
|
|
8377
8547
|
const bin = whichBin("copilot", env);
|
|
8378
8548
|
if (!bin) return Promise.resolve(void 0);
|
|
8379
|
-
return new Promise((
|
|
8549
|
+
return new Promise((resolve3) => {
|
|
8380
8550
|
let f2;
|
|
8381
8551
|
try {
|
|
8382
8552
|
f2 = spawnForm(bin, ["--server", "--stdio", "--no-auto-update"], env);
|
|
8383
8553
|
} catch {
|
|
8384
|
-
|
|
8554
|
+
resolve3(void 0);
|
|
8385
8555
|
return;
|
|
8386
8556
|
}
|
|
8387
8557
|
const child = spawn2(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -8393,7 +8563,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8393
8563
|
clearTimeout(timer);
|
|
8394
8564
|
child.stdin.destroy();
|
|
8395
8565
|
child.kill();
|
|
8396
|
-
|
|
8566
|
+
resolve3(v);
|
|
8397
8567
|
};
|
|
8398
8568
|
const timer = setTimeout(() => finish2(void 0), ASK_TIMEOUT_MS2);
|
|
8399
8569
|
child.on("error", () => finish2(void 0));
|
|
@@ -8427,8 +8597,8 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8427
8597
|
}
|
|
8428
8598
|
|
|
8429
8599
|
// src/setup/engine.ts
|
|
8430
|
-
import { spawn as spawn3, spawnSync as
|
|
8431
|
-
import { closeSync, existsSync as
|
|
8600
|
+
import { spawn as spawn3, spawnSync as spawnSync4 } from "node:child_process";
|
|
8601
|
+
import { closeSync as closeSync2, existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, openSync as openSync2, readFileSync as readFileSync10, readSync as readSync2, readdirSync as readdirSync5, realpathSync as realpathSync7, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8432
8602
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8433
8603
|
import path12 from "node:path";
|
|
8434
8604
|
|
|
@@ -8502,6 +8672,7 @@ var HOOK_SAMPLES = 9;
|
|
|
8502
8672
|
var HOOK_ROUNDS = 5;
|
|
8503
8673
|
var P95 = 0.95;
|
|
8504
8674
|
var VERIFY_TIMEOUT_MS = 1e4;
|
|
8675
|
+
var INSTALL_TIMEOUT_MS = 12e4;
|
|
8505
8676
|
var MANIFEST = "manifest.json";
|
|
8506
8677
|
var MANIFEST_DONE = "manifest.removed.json";
|
|
8507
8678
|
var FILES = "files";
|
|
@@ -8513,11 +8684,11 @@ var REAL_HOST = Object.freeze({
|
|
|
8513
8684
|
var BINARY_MAGICS = Object.freeze(["cffaedfe", "cefaedfe", "7f454c46", "4d5a"]);
|
|
8514
8685
|
function isNativeBinary(file) {
|
|
8515
8686
|
const head = Buffer.alloc(4);
|
|
8516
|
-
const fd =
|
|
8687
|
+
const fd = openSync2(file, "r");
|
|
8517
8688
|
try {
|
|
8518
|
-
|
|
8689
|
+
readSync2(fd, head, 0, 4, 0);
|
|
8519
8690
|
} finally {
|
|
8520
|
-
|
|
8691
|
+
closeSync2(fd);
|
|
8521
8692
|
}
|
|
8522
8693
|
const hex = head.toString("hex");
|
|
8523
8694
|
return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
|
|
@@ -8525,9 +8696,9 @@ function isNativeBinary(file) {
|
|
|
8525
8696
|
function owningPackage(dir) {
|
|
8526
8697
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8527
8698
|
const f2 = path12.join(d, "package.json");
|
|
8528
|
-
if (
|
|
8699
|
+
if (existsSync14(f2)) {
|
|
8529
8700
|
try {
|
|
8530
|
-
return String(JSON.parse(hostText(
|
|
8701
|
+
return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
|
|
8531
8702
|
} catch {
|
|
8532
8703
|
return void 0;
|
|
8533
8704
|
}
|
|
@@ -8543,8 +8714,8 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8543
8714
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8544
8715
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8545
8716
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8546
|
-
if (!f2 || !
|
|
8547
|
-
const file =
|
|
8717
|
+
if (!f2 || !existsSync14(f2) || !statSync2(f2).isFile()) continue;
|
|
8718
|
+
const file = realpathSync7(f2);
|
|
8548
8719
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8549
8720
|
shims.push(f2);
|
|
8550
8721
|
}
|
|
@@ -8556,14 +8727,14 @@ function installExitOk(status, listed, platform = process.platform) {
|
|
|
8556
8727
|
if (status === 0) return true;
|
|
8557
8728
|
return platform === "win32" && status === WIN_EXIT_CRASH && listed;
|
|
8558
8729
|
}
|
|
8559
|
-
function runBin(bin, args, env, input) {
|
|
8560
|
-
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout
|
|
8730
|
+
function runBin(bin, args, env, input, timeout = VERIFY_TIMEOUT_MS) {
|
|
8731
|
+
return spawnShim(hostBin(bin, env).file ?? bin, args, env, { encoding: "utf8", input, timeout });
|
|
8561
8732
|
}
|
|
8562
8733
|
function readOr(file) {
|
|
8563
|
-
return
|
|
8734
|
+
return existsSync14(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
|
|
8564
8735
|
}
|
|
8565
8736
|
function readRaw(file) {
|
|
8566
|
-
return
|
|
8737
|
+
return existsSync14(file) ? readFileSync10(file, "utf8") : void 0;
|
|
8567
8738
|
}
|
|
8568
8739
|
var atomicWrite = atomicWriteFile;
|
|
8569
8740
|
function pidAlive(pid) {
|
|
@@ -8708,7 +8879,7 @@ function isNativeSpec(e) {
|
|
|
8708
8879
|
function isStaleOwnPlugin(e, entry2) {
|
|
8709
8880
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
8710
8881
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
8711
|
-
if (
|
|
8882
|
+
if (existsSync14(e)) return false;
|
|
8712
8883
|
const seg = e.split("\\").join("/").split("/");
|
|
8713
8884
|
const n3 = seg.length;
|
|
8714
8885
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -8772,8 +8943,8 @@ function planSkills(row, edits) {
|
|
|
8772
8943
|
const s = row.skillInstall;
|
|
8773
8944
|
if (s.kind !== "dir") return;
|
|
8774
8945
|
for (const f2 of s.files) {
|
|
8775
|
-
if (!
|
|
8776
|
-
const after = renderSkill(
|
|
8946
|
+
if (!existsSync14(f2.src)) throw new Error(`preflight: ${f2.src} is missing`);
|
|
8947
|
+
const after = renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes);
|
|
8777
8948
|
const before = readRaw(f2.file);
|
|
8778
8949
|
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" }] });
|
|
8779
8950
|
}
|
|
@@ -8876,7 +9047,7 @@ function hookEnabledCheck(row, status) {
|
|
|
8876
9047
|
}
|
|
8877
9048
|
function packageVersion(pkgDir) {
|
|
8878
9049
|
try {
|
|
8879
|
-
const v = JSON.parse(hostText(
|
|
9050
|
+
const v = JSON.parse(hostText(readFileSync10(path12.join(pkgDir, "package.json"), "utf8"))).version;
|
|
8880
9051
|
return typeof v === "string" ? v : void 0;
|
|
8881
9052
|
} catch {
|
|
8882
9053
|
return void 0;
|
|
@@ -8902,7 +9073,7 @@ function copyCheck(row, pkgDir) {
|
|
|
8902
9073
|
return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${old}, the installed package is ${pkg}; run ${c3.bin} ${c3.refresh.join(" ")}` };
|
|
8903
9074
|
}
|
|
8904
9075
|
function mcpCheck(cmd, env) {
|
|
8905
|
-
return new Promise((
|
|
9076
|
+
return new Promise((resolve3) => {
|
|
8906
9077
|
const child = spawn3(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
8907
9078
|
const reap = () => {
|
|
8908
9079
|
child.kill();
|
|
@@ -8914,7 +9085,7 @@ function mcpCheck(cmd, env) {
|
|
|
8914
9085
|
clearTimeout(timer);
|
|
8915
9086
|
process.off("exit", reap);
|
|
8916
9087
|
child.kill();
|
|
8917
|
-
|
|
9088
|
+
resolve3({ name: "mcp", ok, detail });
|
|
8918
9089
|
};
|
|
8919
9090
|
const timer = setTimeout(() => done(false, "no MCP answer before timeout"), VERIFY_TIMEOUT_MS);
|
|
8920
9091
|
child.on("error", (e) => done(false, e.message));
|
|
@@ -8959,7 +9130,7 @@ function hookRound(row, env) {
|
|
|
8959
9130
|
const bare = [];
|
|
8960
9131
|
for (let i2 = 0; i2 < HOOK_SAMPLES; i2++) {
|
|
8961
9132
|
let t2 = performance.now();
|
|
8962
|
-
const r2 =
|
|
9133
|
+
const r2 = spawnSync4(cmd[0], cmd.slice(1), { env, input, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8963
9134
|
wall.push(performance.now() - t2);
|
|
8964
9135
|
if (r2.status !== 0) return { name: "hook", ok: false, detail: `hook exited ${r2.status}: ${`${r2.stderr}`.trim()}` };
|
|
8965
9136
|
const out2 = `${r2.stdout}`.trim();
|
|
@@ -8972,7 +9143,7 @@ function hookRound(row, env) {
|
|
|
8972
9143
|
if (!isObj5(j2)) return { name: "hook", ok: false, detail: `hook answer is not a JSON object: ${out2.slice(0, 200)}` };
|
|
8973
9144
|
}
|
|
8974
9145
|
t2 = performance.now();
|
|
8975
|
-
|
|
9146
|
+
spawnSync4(cmd[0], ["-e", ""], { env, timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8976
9147
|
bare.push(performance.now() - t2);
|
|
8977
9148
|
}
|
|
8978
9149
|
const wallP95Ms = Math.round(p95(wall));
|
|
@@ -9028,26 +9199,26 @@ function hookRunsCheck(row, env) {
|
|
|
9028
9199
|
try {
|
|
9029
9200
|
const home = path12.join(root, "home");
|
|
9030
9201
|
const proj = path12.join(root, "proj");
|
|
9031
|
-
|
|
9032
|
-
|
|
9202
|
+
mkdirSync5(home);
|
|
9203
|
+
mkdirSync5(proj);
|
|
9033
9204
|
const text2 = sampleText();
|
|
9034
|
-
|
|
9205
|
+
writeFileSync3(path12.join(proj, SAMPLE_FILE), text2);
|
|
9035
9206
|
const { effect, payload } = hookSample(row.id, proj, text2);
|
|
9036
9207
|
const sampleEnv = { ...env, HOME: home, USERPROFILE: home };
|
|
9037
9208
|
delete sampleEnv.CLAUDE_PROJECT_DIR;
|
|
9038
9209
|
const cmd = row.hookRunCommand;
|
|
9039
|
-
const r2 =
|
|
9210
|
+
const r2 = spawnSync4(cmd[0], cmd.slice(1), { env: sampleEnv, cwd: proj, input: JSON.stringify(payload), encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
9040
9211
|
const bad = sampleVerdict(row.id, effect, text2, { status: r2.status, stdout: `${r2.stdout ?? ""}`, stderr: `${r2.stderr ?? ""}` });
|
|
9041
9212
|
return bad === null ? { name: "hook-runs", ok: true } : { name: "hook-runs", ok: false, detail: bad };
|
|
9042
9213
|
} finally {
|
|
9043
|
-
|
|
9214
|
+
rmSync2(root, { recursive: true, force: true });
|
|
9044
9215
|
}
|
|
9045
9216
|
}
|
|
9046
9217
|
var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
9047
9218
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9048
9219
|
function hookSeenCheck(row, home) {
|
|
9049
9220
|
const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
|
|
9050
|
-
const dirs =
|
|
9221
|
+
const dirs = existsSync14(base) ? readdirSync5(base) : [];
|
|
9051
9222
|
let sqlite;
|
|
9052
9223
|
try {
|
|
9053
9224
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9056,7 +9227,7 @@ function hookSeenCheck(row, home) {
|
|
|
9056
9227
|
}
|
|
9057
9228
|
for (const d of dirs) {
|
|
9058
9229
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9059
|
-
if (!sqlite || !
|
|
9230
|
+
if (!sqlite || !existsSync14(file)) continue;
|
|
9060
9231
|
let db;
|
|
9061
9232
|
try {
|
|
9062
9233
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9071,10 +9242,10 @@ function hookSeenCheck(row, home) {
|
|
|
9071
9242
|
function skillsCheck(row, pkgDir) {
|
|
9072
9243
|
const s = row.skillInstall;
|
|
9073
9244
|
if (s.kind === "package") {
|
|
9074
|
-
const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !
|
|
9245
|
+
const miss = COMMAND_SKILLS.map((n3) => path12.join(pkgDir, s.via, n3, SKILL_FILE)).filter((f2) => !existsSync14(f2));
|
|
9075
9246
|
return { name: "skills", ok: miss.length === 0, detail: miss.length ? `missing ${miss.join(", ")}` : void 0 };
|
|
9076
9247
|
}
|
|
9077
|
-
const bad = s.files.filter((f2) => readRaw(f2.file) !== (
|
|
9248
|
+
const bad = s.files.filter((f2) => readRaw(f2.file) !== (existsSync14(f2.src) ? renderSkill(readFileSync10(f2.src, "utf8"), s.prefixes) : void 0));
|
|
9078
9249
|
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 };
|
|
9079
9250
|
}
|
|
9080
9251
|
var PLUGIN_ENABLED = "enabled";
|
|
@@ -9326,26 +9497,26 @@ function undo(dir, entries, env) {
|
|
|
9326
9497
|
continue;
|
|
9327
9498
|
}
|
|
9328
9499
|
if (!e.file) continue;
|
|
9329
|
-
if (e.existed && e.backup) atomicWrite(e.file,
|
|
9500
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync10(path12.join(dir, e.backup), "utf8"));
|
|
9330
9501
|
else unlinkWithRetry(e.file);
|
|
9331
9502
|
}
|
|
9332
9503
|
}
|
|
9333
9504
|
function takeLock(root, runId) {
|
|
9334
9505
|
const file = path12.join(root, LOCK_FILE);
|
|
9335
|
-
|
|
9506
|
+
mkdirSync5(root, { recursive: true });
|
|
9336
9507
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
9337
9508
|
try {
|
|
9338
|
-
|
|
9509
|
+
writeFileSync3(file, JSON.stringify({ pid: process.pid, runId }), { flag: "wx" });
|
|
9339
9510
|
return void 0;
|
|
9340
9511
|
} catch (e) {
|
|
9341
9512
|
if (e.code !== "EEXIST") throw e;
|
|
9342
9513
|
let pid = 0;
|
|
9343
9514
|
try {
|
|
9344
|
-
pid = Number(JSON.parse(
|
|
9515
|
+
pid = Number(JSON.parse(readFileSync10(file, "utf8")).pid);
|
|
9345
9516
|
} catch {
|
|
9346
9517
|
}
|
|
9347
9518
|
if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
|
|
9348
|
-
|
|
9519
|
+
rmSync2(file, { force: true });
|
|
9349
9520
|
}
|
|
9350
9521
|
}
|
|
9351
9522
|
return `setup lock ${file} could not be taken`;
|
|
@@ -9358,14 +9529,14 @@ function agentHomeDir(id, ctx) {
|
|
|
9358
9529
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9359
9530
|
}
|
|
9360
9531
|
function detectAgents(reg, ctx) {
|
|
9361
|
-
return reg.filter((r2) =>
|
|
9532
|
+
return reg.filter((r2) => existsSync14(agentHomeDir(r2.id, ctx)) || r2.listCommand && which(r2.listCommand.bin, ctx.env)).map((r2) => r2.id);
|
|
9362
9533
|
}
|
|
9363
9534
|
async function runSetup(opts) {
|
|
9364
9535
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9365
9536
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9366
9537
|
const reg = buildRegistry(ctx);
|
|
9367
9538
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9368
|
-
if (!
|
|
9539
|
+
if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9369
9540
|
}
|
|
9370
9541
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9371
9542
|
const root = path12.join(ctx.home, STATE_DIR);
|
|
@@ -9378,7 +9549,7 @@ async function runSetup(opts) {
|
|
|
9378
9549
|
let current;
|
|
9379
9550
|
const onAbort = () => {
|
|
9380
9551
|
if (current !== void 0 && !opts.dryRun) run.rollback(current, ctx.env);
|
|
9381
|
-
if (!opts.dryRun)
|
|
9552
|
+
if (!opts.dryRun) rmSync2(path12.join(root, LOCK_FILE), { force: true });
|
|
9382
9553
|
};
|
|
9383
9554
|
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
9384
9555
|
try {
|
|
@@ -9397,7 +9568,7 @@ async function runSetup(opts) {
|
|
|
9397
9568
|
}
|
|
9398
9569
|
} finally {
|
|
9399
9570
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
9400
|
-
if (!opts.dryRun)
|
|
9571
|
+
if (!opts.dryRun) rmSync2(path12.join(root, LOCK_FILE), { force: true });
|
|
9401
9572
|
}
|
|
9402
9573
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents, backupDir: run.manifest ? run.dir : void 0 };
|
|
9403
9574
|
}
|
|
@@ -9431,12 +9602,12 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9431
9602
|
atomicWrite(e.file, e.plain || raw === void 0 ? e.after : withLayout(e.after, hostLayout(raw)));
|
|
9432
9603
|
}
|
|
9433
9604
|
for (const args of plan.cli) {
|
|
9434
|
-
const r2 = runBin(row.cli.bin, args, ctx.env, row.cli.input ?? "");
|
|
9605
|
+
const r2 = runBin(row.cli.bin, args, ctx.env, row.cli.input ?? "", INSTALL_TIMEOUT_MS);
|
|
9435
9606
|
if (!installExitOk(r2.status, r2.status === WIN_EXIT_CRASH && listCheck(row, ctx.env)?.ok === true)) throw new Error(`${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`);
|
|
9436
9607
|
}
|
|
9437
9608
|
if (plan.cli.length) for (const args of row.cli.remove) run.record({ agent: row.id, undo: { bin: row.cli.bin, args } });
|
|
9438
9609
|
for (const args of plan.refresh) {
|
|
9439
|
-
const r2 = runBin(row.cli.bin, args, ctx.env);
|
|
9610
|
+
const r2 = runBin(row.cli.bin, args, ctx.env, void 0, INSTALL_TIMEOUT_MS);
|
|
9440
9611
|
if (r2.status !== 0) throw new Error(`${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`);
|
|
9441
9612
|
run.record({ agent: row.id, ran: { bin: row.cli.bin, args } });
|
|
9442
9613
|
}
|
|
@@ -9456,7 +9627,7 @@ async function runDoctor(opts) {
|
|
|
9456
9627
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9457
9628
|
const reg = buildRegistry(ctx);
|
|
9458
9629
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9459
|
-
if (!
|
|
9630
|
+
if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9460
9631
|
}
|
|
9461
9632
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9462
9633
|
const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
|
|
@@ -9524,26 +9695,26 @@ function runRemove(opts) {
|
|
|
9524
9695
|
const env = opts.env ?? process.env;
|
|
9525
9696
|
const root = path12.join(opts.home, STATE_DIR);
|
|
9526
9697
|
const base = path12.join(root, BACKUP_DIR);
|
|
9527
|
-
if (!
|
|
9698
|
+
if (!existsSync14(base)) return { exitCode: 0, restored: 0 };
|
|
9528
9699
|
const held = takeLock(root, "remove");
|
|
9529
9700
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
9530
9701
|
let restored = 0;
|
|
9531
9702
|
try {
|
|
9532
|
-
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) =>
|
|
9703
|
+
const runs = readdirSync5(base).map((r2) => path12.join(base, r2)).filter((d) => existsSync14(path12.join(d, MANIFEST))).sort().reverse();
|
|
9533
9704
|
for (const dir of runs) {
|
|
9534
|
-
const m3 = JSON.parse(
|
|
9705
|
+
const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
|
|
9535
9706
|
undo(dir, m3.entries, env);
|
|
9536
9707
|
restored += m3.entries.length;
|
|
9537
9708
|
renameWithRetry(path12.join(dir, MANIFEST), path12.join(dir, MANIFEST_DONE));
|
|
9538
9709
|
}
|
|
9539
9710
|
} finally {
|
|
9540
|
-
|
|
9711
|
+
rmSync2(path12.join(root, LOCK_FILE), { force: true });
|
|
9541
9712
|
}
|
|
9542
9713
|
return { exitCode: 0, restored };
|
|
9543
9714
|
}
|
|
9544
9715
|
|
|
9545
9716
|
// src/setup/print.ts
|
|
9546
|
-
import { readFileSync as
|
|
9717
|
+
import { readFileSync as readFileSync11 } from "node:fs";
|
|
9547
9718
|
var SHELL_SAFE_PUNCT = "@%+=:,./-_";
|
|
9548
9719
|
function isShellSafe(s) {
|
|
9549
9720
|
if (s === "") return false;
|
|
@@ -9571,7 +9742,7 @@ function printPlan(row, env) {
|
|
|
9571
9742
|
else if (h2.kind === "plugin-list") steps.push({ kind: "hook", file: h2.file, block: JSON.stringify({ [h2.key[0]]: [h2.entry] }, null, 2) + "\n" });
|
|
9572
9743
|
const sk = row.skillInstall;
|
|
9573
9744
|
if (sk.kind === "dir") {
|
|
9574
|
-
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(
|
|
9745
|
+
for (const f2 of sk.files) steps.push({ kind: "skill", file: f2.file, block: renderSkill(readFileSync11(f2.src, "utf8"), sk.prefixes) });
|
|
9575
9746
|
}
|
|
9576
9747
|
return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
|
|
9577
9748
|
}
|
|
@@ -9732,23 +9903,22 @@ function buildIssueReport(command, res, ui) {
|
|
|
9732
9903
|
return { text: redact(lines.join("\n"), ui.ctx), title };
|
|
9733
9904
|
}
|
|
9734
9905
|
function ghReady(env) {
|
|
9735
|
-
const r2 =
|
|
9906
|
+
const r2 = spawnSync5("gh", ["auth", "status"], { env, stdio: "ignore", timeout: 1e4, windowsHide: true });
|
|
9736
9907
|
return r2.status === 0;
|
|
9737
9908
|
}
|
|
9738
|
-
function issueUrl(title,
|
|
9739
|
-
|
|
9740
|
-
return `https://github.com/${ISSUE_REPO}/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(b3)}`;
|
|
9909
|
+
function issueUrl(title, summary) {
|
|
9910
|
+
return formUrl(title, summary.length > URL_BODY_MAX ? summary.slice(0, URL_BODY_MAX) : summary);
|
|
9741
9911
|
}
|
|
9742
9912
|
async function report(ui, command, res, write) {
|
|
9743
9913
|
const { text: text2, title } = buildIssueReport(command, res, ui);
|
|
9744
9914
|
let file = "";
|
|
9745
9915
|
if (write) {
|
|
9746
9916
|
const dir = path13.join(ui.ctx.home, STATE_DIR, REPORT_DIR);
|
|
9747
|
-
|
|
9917
|
+
mkdirSync6(dir, { recursive: true });
|
|
9748
9918
|
file = path13.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
9749
|
-
|
|
9919
|
+
writeFileSync4(file, text2);
|
|
9750
9920
|
}
|
|
9751
|
-
const gh = `gh issue create --repo ${ISSUE_REPO} --title ${JSON.stringify(title)} --body-file ${JSON.stringify(file || "<report>")}`;
|
|
9921
|
+
const gh = `gh issue create --repo ${ISSUE_REPO} --title ${JSON.stringify(title)} --label bug --body-file ${JSON.stringify(file || "<report>")}`;
|
|
9752
9922
|
const p3 = ui.clack;
|
|
9753
9923
|
if (!p3) {
|
|
9754
9924
|
if (ui.f.debug) err(text2);
|
|
@@ -9763,15 +9933,15 @@ async function report(ui, command, res, write) {
|
|
|
9763
9933
|
return;
|
|
9764
9934
|
}
|
|
9765
9935
|
if (file && ghReady(ui.ctx.env)) {
|
|
9766
|
-
const r2 =
|
|
9936
|
+
const r2 = spawnSync5("gh", ["issue", "create", "--repo", ISSUE_REPO, "--title", title, "--label", "bug", "--body-file", file], { env: ui.ctx.env, encoding: "utf8", timeout: 6e4, windowsHide: true });
|
|
9767
9937
|
if (r2.status === 0) {
|
|
9768
9938
|
p3.log.success(`Issue opened: ${`${r2.stdout}`.trim()}`);
|
|
9769
9939
|
return;
|
|
9770
9940
|
}
|
|
9771
9941
|
p3.log.warn(`gh issue create failed: ${`${r2.stderr}`.trim()}`);
|
|
9772
9942
|
}
|
|
9773
|
-
p3.log.info(`Open this URL to file the issue:
|
|
9774
|
-
${issueUrl(title,
|
|
9943
|
+
p3.log.info(`Open this URL to file the issue (paste the report file into the form):
|
|
9944
|
+
${issueUrl(title, title)}`);
|
|
9775
9945
|
}
|
|
9776
9946
|
async function apply(ui, agents, dryRun) {
|
|
9777
9947
|
const ac = new AbortController();
|
|
@@ -9986,20 +10156,20 @@ async function upgrade(ui) {
|
|
|
9986
10156
|
}
|
|
9987
10157
|
const shell = process.platform === "win32";
|
|
9988
10158
|
progress2(ui, `running ${install}`);
|
|
9989
|
-
const r2 =
|
|
10159
|
+
const r2 = spawnSync5(npm, ["i", "-g", spec], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true });
|
|
9990
10160
|
if (r2.status !== 0) {
|
|
9991
10161
|
const why = (`${r2.stderr ?? ""}`.trim().split("\n").pop() ?? "") || (r2.error?.message ?? "");
|
|
9992
10162
|
err(`FAIL upgrade: ${install} exited ${r2.status ?? "?"}${why ? `: ${why}` : ""}. Fix: ${install}`);
|
|
9993
10163
|
return EXIT_FAIL;
|
|
9994
10164
|
}
|
|
9995
|
-
const root = `${
|
|
10165
|
+
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
9996
10166
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
9997
|
-
if (!root || !
|
|
10167
|
+
if (!root || !existsSync15(cli)) {
|
|
9998
10168
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
9999
10169
|
return EXIT_FAIL;
|
|
10000
10170
|
}
|
|
10001
10171
|
progress2(ui, `running context-mode ${repairArgs.join(" ")}`);
|
|
10002
|
-
const c3 =
|
|
10172
|
+
const c3 = spawnSync5(process.execPath, [cli, ...repairArgs], { env: ui.ctx.env, stdio: "inherit", windowsHide: true });
|
|
10003
10173
|
return c3.status ?? (c3.signal === "SIGINT" ? EXIT_SIGINT : EXIT_FAIL);
|
|
10004
10174
|
}
|
|
10005
10175
|
async function runCommand(cmd, args, env) {
|
|
@@ -10033,12 +10203,12 @@ Run context-mode ${cmd} --help.`);
|
|
|
10033
10203
|
}
|
|
10034
10204
|
|
|
10035
10205
|
// src/entries/is-entry.ts
|
|
10036
|
-
import { realpathSync as
|
|
10206
|
+
import { realpathSync as realpathSync8 } from "node:fs";
|
|
10037
10207
|
function isEntry(main2, argv1, self) {
|
|
10038
10208
|
if (main2 !== void 0) return main2;
|
|
10039
10209
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
10040
10210
|
try {
|
|
10041
|
-
return
|
|
10211
|
+
return realpathSync8(argv1) === realpathSync8(self);
|
|
10042
10212
|
} catch {
|
|
10043
10213
|
return false;
|
|
10044
10214
|
}
|
|
@@ -10089,10 +10259,10 @@ function route(argv, version) {
|
|
|
10089
10259
|
` };
|
|
10090
10260
|
}
|
|
10091
10261
|
function main() {
|
|
10092
|
-
const dir = path14.dirname(
|
|
10262
|
+
const dir = path14.dirname(realpathSync9(fileURLToPath2(import.meta.url)));
|
|
10093
10263
|
let version = "";
|
|
10094
10264
|
try {
|
|
10095
|
-
version = String(JSON.parse(
|
|
10265
|
+
version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
10096
10266
|
} catch (err2) {
|
|
10097
10267
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
10098
10268
|
`);
|