context-mode 2.0.0-next.29 → 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 +84 -83
- package/SHA256SUMS +19 -19
- package/claude-code/skills/ctx-stats/SKILL.md +2 -2
- package/cli.mjs +342 -152
- package/codex/skills/ctx-stats/SKILL.md +2 -2
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +75 -75
- package/opencode/plugin.js +1063 -309
- package/package.json +1 -1
- package/pi/index.js +1178 -425
- package/pi/skills/ctx-stats/SKILL.md +2 -2
- package/qwen-extension.json +1 -1
- package/run.mjs +84 -3
- package/search.mjs +84 -3
- package/server.mjs +1118 -365
- package/skills/ctx-stats/SKILL.md +2 -2
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;
|
|
@@ -298,7 +299,34 @@ var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
|
298
299
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
299
300
|
var AGENT_ARG = "--agent";
|
|
300
301
|
var STATS_COLUMNS = Object.freeze(["Scope", "Produced", "Returned", "Saved", "Reduction %"]);
|
|
302
|
+
var STATS_EMPTY_LINES = Object.freeze([
|
|
303
|
+
"Ready. Your savings show up here after the first tool call.",
|
|
304
|
+
"Large outputs from ctx_execute, ctx_batch and ctx_index stay in the",
|
|
305
|
+
"sandbox, and only the short answer goes to the chat."
|
|
306
|
+
]);
|
|
307
|
+
var STATS_KIND_LABELS = Object.freeze([
|
|
308
|
+
// D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
|
|
309
|
+
["index", "Content indexed"],
|
|
310
|
+
["edit", "File edits"],
|
|
311
|
+
["toolerr", "Issues kept"],
|
|
312
|
+
["decision", "Your decisions"],
|
|
313
|
+
["cmd", "Other tool calls"],
|
|
314
|
+
["prompt", "Your prompts"]
|
|
315
|
+
]);
|
|
316
|
+
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
317
|
+
"ctx_resume brings back your last task, files changed and open issues",
|
|
318
|
+
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
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"]);
|
|
301
327
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
328
|
+
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
329
|
+
var RELEASE_BRANCH = "release";
|
|
302
330
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
303
331
|
var DOCTOR_LABEL = Object.freeze({
|
|
304
332
|
D1: "version",
|
|
@@ -316,6 +344,7 @@ var DOCTOR_LABEL = Object.freeze({
|
|
|
316
344
|
});
|
|
317
345
|
var REPORT_SOURCE_LABEL = "ctx_doctor:report";
|
|
318
346
|
var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(REPORT_SOURCE_LABEL)}})`;
|
|
347
|
+
var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
|
|
319
348
|
var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
|
|
320
349
|
var D3_PARTS = Object.freeze(["MCP entry", "hook entries", "hook timeout"]);
|
|
321
350
|
var AGENT_HOME_DIR = Object.freeze({
|
|
@@ -471,7 +500,7 @@ var V1_REASON = Object.freeze({
|
|
|
471
500
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
472
501
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
473
502
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
474
|
-
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"
|
|
475
504
|
});
|
|
476
505
|
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
477
506
|
var OPENCODE_TOOL_PREFIX = SERVER_KEY + "_";
|
|
@@ -507,6 +536,60 @@ var OWN_MCP_ENTRY = Object.freeze({
|
|
|
507
536
|
var REPORT_ENV_ENUMS = Object.freeze({
|
|
508
537
|
NODE_ENV: Object.freeze(["development", "production", "test"])
|
|
509
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}`;
|
|
510
593
|
|
|
511
594
|
// src/adapters/claude-code.ts
|
|
512
595
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -1598,9 +1681,9 @@ Examples:
|
|
|
1598
1681
|
};
|
|
1599
1682
|
|
|
1600
1683
|
// src/cli/commands.ts
|
|
1601
|
-
import { spawnSync as
|
|
1684
|
+
import { spawnSync as spawnSync5 } from "node:child_process";
|
|
1602
1685
|
import { createHash as createHash2 } from "node:crypto";
|
|
1603
|
-
import { existsSync as
|
|
1686
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
1604
1687
|
import os from "node:os";
|
|
1605
1688
|
import path13 from "node:path";
|
|
1606
1689
|
|
|
@@ -4551,12 +4634,116 @@ function ownMcpFileOf(agent, file, env, home) {
|
|
|
4551
4634
|
return agent === "vscode" ? join2(vscodeUserDirOf(env, home), ...file) : join2(home, ...file);
|
|
4552
4635
|
}
|
|
4553
4636
|
|
|
4554
|
-
// src/
|
|
4555
|
-
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";
|
|
4556
4743
|
|
|
4557
4744
|
// src/core/ops/host-config.ts
|
|
4558
|
-
import { existsSync as
|
|
4559
|
-
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";
|
|
4560
4747
|
|
|
4561
4748
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
4562
4749
|
var KEYS2 = {
|
|
@@ -6602,7 +6789,7 @@ function parseTOML(code, options) {
|
|
|
6602
6789
|
}
|
|
6603
6790
|
|
|
6604
6791
|
// src/core/ops/atomic-file.ts
|
|
6605
|
-
import { mkdirSync as
|
|
6792
|
+
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6606
6793
|
import path2 from "node:path";
|
|
6607
6794
|
function sleepSync(ms) {
|
|
6608
6795
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
@@ -6653,7 +6840,7 @@ function removeTmpFile(tmp, opts = {}) {
|
|
|
6653
6840
|
}
|
|
6654
6841
|
}
|
|
6655
6842
|
function atomicWriteFile(file, text2, opts = {}) {
|
|
6656
|
-
|
|
6843
|
+
mkdirSync3(path2.dirname(file), { recursive: true });
|
|
6657
6844
|
const tmp = path2.join(path2.dirname(file), `${ATOMIC_TMP_PREFIX}${path2.basename(file)}${ATOMIC_TMP_MARK}${process.pid}`);
|
|
6658
6845
|
try {
|
|
6659
6846
|
writeFileSync(tmp, text2);
|
|
@@ -7058,14 +7245,7 @@ function editHostConfigText(agent, path15, text2, format, wanted) {
|
|
|
7058
7245
|
return applyEdits(agent, path15, text2, format, wanted);
|
|
7059
7246
|
}
|
|
7060
7247
|
|
|
7061
|
-
// src/core/ops/doctor-config.ts
|
|
7062
|
-
import { existsSync as existsSync5, readdirSync as readdirSync4 } from "node:fs";
|
|
7063
|
-
import { join as join6 } from "node:path";
|
|
7064
|
-
|
|
7065
7248
|
// src/core/ops/detect-v1.ts
|
|
7066
|
-
import { existsSync as existsSync3, opendirSync, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
|
|
7067
|
-
import { tmpdir } from "node:os";
|
|
7068
|
-
import { join as join4 } from "node:path";
|
|
7069
7249
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
7070
7250
|
var keyPath = (...parts) => parts.join(".");
|
|
7071
7251
|
var finding = (file, path15, reason) => ({ file, path: path15, reason });
|
|
@@ -7172,7 +7352,7 @@ function flatCommands(events2, prefix) {
|
|
|
7172
7352
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
7173
7353
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep2) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep2) + sep2));
|
|
7174
7354
|
function dataDir(dir, reason, out2) {
|
|
7175
|
-
if (
|
|
7355
|
+
if (existsSync4(dir)) out2.push(finding(dir, "", reason));
|
|
7176
7356
|
}
|
|
7177
7357
|
function mcpEntry(file, doc, out2) {
|
|
7178
7358
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -7180,7 +7360,7 @@ function mcpEntry(file, doc, out2) {
|
|
|
7180
7360
|
}
|
|
7181
7361
|
}
|
|
7182
7362
|
function claudeShapeSettings(agentHome, out2) {
|
|
7183
|
-
const file =
|
|
7363
|
+
const file = join5(agentHome, SETTINGS_FILE);
|
|
7184
7364
|
const doc = readJson(file);
|
|
7185
7365
|
for (const c3 of nestedCommands(doc)) {
|
|
7186
7366
|
if (c3.command.includes(V1_CACHE_HEAL_NAME)) out2.push(finding(file, c3.path, V1_REASON.cacheHealHook));
|
|
@@ -7200,49 +7380,49 @@ function v1HookFile(file, out2) {
|
|
|
7200
7380
|
function scanClaudeCode(home, agentHome, out2) {
|
|
7201
7381
|
claudeShapeSettings(agentHome, out2);
|
|
7202
7382
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
7203
|
-
const file =
|
|
7204
|
-
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));
|
|
7205
7385
|
}
|
|
7206
|
-
const userFile =
|
|
7386
|
+
const userFile = join5(home, CLAUDE_USER_CONFIG_FILE);
|
|
7207
7387
|
mcpEntry(userFile, readJson(userFile), out2);
|
|
7208
|
-
dataDir(
|
|
7388
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7209
7389
|
}
|
|
7210
7390
|
function scanCodex(agentHome, out2) {
|
|
7211
|
-
const hooksFile =
|
|
7391
|
+
const hooksFile = join5(agentHome, HOOKS_JSON_FILE);
|
|
7212
7392
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7213
7393
|
if (c3.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c3.command)) {
|
|
7214
7394
|
out2.push(finding(hooksFile, c3.path, V1_REASON.codexHook));
|
|
7215
7395
|
}
|
|
7216
7396
|
}
|
|
7217
|
-
const tomlFile =
|
|
7397
|
+
const tomlFile = join5(agentHome, CONFIG_TOML_FILE);
|
|
7218
7398
|
const config = readTomlValue(tomlFile);
|
|
7219
7399
|
for (const span of readTomlTables(tomlFile)) {
|
|
7220
7400
|
if (span.path[0] !== V1_TOML_SECTION_ROOT || span.path[1] !== SERVER_KEY) continue;
|
|
7221
7401
|
if (span.path.length === 2 && isV2McpTable(hostConfigValueAt(config, span.path))) continue;
|
|
7222
7402
|
out2.push(finding(tomlFile, span.header.trim(), V1_REASON.codexToml));
|
|
7223
7403
|
}
|
|
7224
|
-
dataDir(
|
|
7404
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7225
7405
|
}
|
|
7226
7406
|
function scanGemini(agentHome, out2) {
|
|
7227
|
-
const file =
|
|
7407
|
+
const file = join5(agentHome, SETTINGS_FILE);
|
|
7228
7408
|
for (const c3 of nestedCommands(readJson(file))) {
|
|
7229
7409
|
if (c3.command.includes(SERVER_KEY)) out2.push(finding(file, c3.path, V1_REASON.hook));
|
|
7230
7410
|
}
|
|
7231
|
-
dataDir(
|
|
7411
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out2);
|
|
7232
7412
|
}
|
|
7233
7413
|
function scanVscode(agentHome, project, out2) {
|
|
7234
7414
|
if (project !== void 0) {
|
|
7235
|
-
v1HookFile(
|
|
7236
|
-
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);
|
|
7237
7417
|
const doc = readJson(mcpFile);
|
|
7238
7418
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
7239
7419
|
const entry2 = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
7240
7420
|
if (isObj(entry2) && (entry2.command === V1_BIN_COMMAND || listOf(entry2.args).some((a2) => a2 === V1_BIN_COMMAND))) {
|
|
7241
7421
|
out2.push(finding(mcpFile, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
7242
7422
|
}
|
|
7243
|
-
dataDir(
|
|
7423
|
+
dataDir(join5(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7244
7424
|
}
|
|
7245
|
-
dataDir(
|
|
7425
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7246
7426
|
}
|
|
7247
7427
|
function jsonFiles(dir) {
|
|
7248
7428
|
try {
|
|
@@ -7252,10 +7432,10 @@ function jsonFiles(dir) {
|
|
|
7252
7432
|
}
|
|
7253
7433
|
}
|
|
7254
7434
|
function scanKiro(agentHome, project, out2) {
|
|
7255
|
-
const agentsDir =
|
|
7256
|
-
const defaultFile =
|
|
7435
|
+
const agentsDir = join5(agentHome, KIRO_AGENTS_DIR);
|
|
7436
|
+
const defaultFile = join5(agentHome, ...KIRO_AGENT_FILE);
|
|
7257
7437
|
for (const name of jsonFiles(agentsDir)) {
|
|
7258
|
-
const file =
|
|
7438
|
+
const file = join5(agentsDir, name);
|
|
7259
7439
|
const doc = readJson(file);
|
|
7260
7440
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
7261
7441
|
out2.push(finding(file, "", V1_REASON.kiroAgentFile));
|
|
@@ -7266,25 +7446,25 @@ function scanKiro(agentHome, project, out2) {
|
|
|
7266
7446
|
if (isV1Hook(c3.command)) out2.push(finding(file, c3.path, V1_REASON.kiroHook));
|
|
7267
7447
|
}
|
|
7268
7448
|
}
|
|
7269
|
-
const steeringDocs = [
|
|
7270
|
-
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));
|
|
7271
7451
|
for (const file of steeringDocs) {
|
|
7272
|
-
if (
|
|
7452
|
+
if (existsSync4(file)) out2.push(finding(file, "", V1_REASON.kiroSteering));
|
|
7273
7453
|
}
|
|
7274
|
-
dataDir(
|
|
7454
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7275
7455
|
}
|
|
7276
7456
|
function scanPi(piAgentDir, agentHome, out2) {
|
|
7277
|
-
const file =
|
|
7457
|
+
const file = join5(piAgentDir, SETTINGS_FILE);
|
|
7278
7458
|
const doc = readJson(file);
|
|
7279
7459
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i2) => {
|
|
7280
7460
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
7281
7461
|
if (spec === V1_PI_PACKAGE) out2.push(finding(file, keyPath(PI_PACKAGES_KEY, i2), V1_REASON.piNpm));
|
|
7282
7462
|
});
|
|
7283
|
-
dataDir(
|
|
7463
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7284
7464
|
}
|
|
7285
7465
|
function scanOpencode(agentHome, out2) {
|
|
7286
7466
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
7287
|
-
const file =
|
|
7467
|
+
const file = join5(agentHome, name);
|
|
7288
7468
|
const doc = readJson(file);
|
|
7289
7469
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
7290
7470
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i2) => {
|
|
@@ -7294,13 +7474,13 @@ function scanOpencode(agentHome, out2) {
|
|
|
7294
7474
|
}
|
|
7295
7475
|
}
|
|
7296
7476
|
function scanZcode(agentHome, out2) {
|
|
7297
|
-
const configFile =
|
|
7477
|
+
const configFile = join5(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
7298
7478
|
const config = readJson(configFile);
|
|
7299
7479
|
const events2 = isObj(config) && isObj(config[HOOKS_KEY]) ? config[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
7300
7480
|
for (const c3 of flatCommands(events2, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
7301
7481
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(configFile, c3.path, V1_REASON.zcodeHook));
|
|
7302
7482
|
}
|
|
7303
|
-
const hooksFile =
|
|
7483
|
+
const hooksFile = join5(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
7304
7484
|
for (const c3 of nestedCommands(readJson(hooksFile))) {
|
|
7305
7485
|
if (c3.command.includes(V1_HOOK_COMMAND)) out2.push(finding(hooksFile, c3.path, V1_REASON.zcodeHook));
|
|
7306
7486
|
}
|
|
@@ -7324,14 +7504,14 @@ function firstTmpMatch(dir) {
|
|
|
7324
7504
|
}
|
|
7325
7505
|
}
|
|
7326
7506
|
function scanAll(home, tmp, out2) {
|
|
7327
|
-
const root =
|
|
7328
|
-
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);
|
|
7329
7509
|
if (firstTmpMatch(tmp) !== null) out2.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
7330
7510
|
}
|
|
7331
7511
|
function detectV1(agent, home, scope = {}) {
|
|
7332
7512
|
const out2 = [];
|
|
7333
7513
|
const project = scope.project;
|
|
7334
|
-
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]);
|
|
7335
7515
|
switch (agent) {
|
|
7336
7516
|
case "claude-code":
|
|
7337
7517
|
scanClaudeCode(home, agentHome, out2);
|
|
@@ -7344,11 +7524,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7344
7524
|
break;
|
|
7345
7525
|
case "qwen":
|
|
7346
7526
|
claudeShapeSettings(agentHome, out2);
|
|
7347
|
-
dataDir(
|
|
7527
|
+
dataDir(join5(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out2);
|
|
7348
7528
|
break;
|
|
7349
7529
|
case "copilot-cli":
|
|
7350
|
-
v1HookFile(
|
|
7351
|
-
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);
|
|
7352
7532
|
break;
|
|
7353
7533
|
case "vscode":
|
|
7354
7534
|
scanVscode(agentHome, project, out2);
|
|
@@ -7357,7 +7537,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7357
7537
|
scanKiro(agentHome, project, out2);
|
|
7358
7538
|
break;
|
|
7359
7539
|
case "pi":
|
|
7360
|
-
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);
|
|
7361
7541
|
break;
|
|
7362
7542
|
// D-WIN-PIDIR-1: empty is unset
|
|
7363
7543
|
case "opencode":
|
|
@@ -7372,8 +7552,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
7372
7552
|
}
|
|
7373
7553
|
|
|
7374
7554
|
// src/core/ops/plugin-root.ts
|
|
7375
|
-
import { existsSync as
|
|
7376
|
-
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";
|
|
7377
7557
|
import { fileURLToPath } from "node:url";
|
|
7378
7558
|
|
|
7379
7559
|
// src/core/ops/doctor-config.ts
|
|
@@ -7388,6 +7568,16 @@ function composeMatcher(row, event) {
|
|
|
7388
7568
|
}
|
|
7389
7569
|
var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
7390
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
|
+
|
|
7391
7581
|
// src/setup/hook-shapes.ts
|
|
7392
7582
|
var MS_PER_SECOND = 1e3;
|
|
7393
7583
|
var TOOL_EVENTS = ["PreToolUse", "PostToolUse"];
|
|
@@ -7683,7 +7873,7 @@ function assertWritable(row, file) {
|
|
|
7683
7873
|
}
|
|
7684
7874
|
|
|
7685
7875
|
// src/setup/gemini-gate.ts
|
|
7686
|
-
import { existsSync as
|
|
7876
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
|
|
7687
7877
|
import path4 from "node:path";
|
|
7688
7878
|
var GEMINI_DIR = ".gemini";
|
|
7689
7879
|
var SETTINGS_FILE2 = "settings.json";
|
|
@@ -7697,9 +7887,9 @@ function systemSettingsPath(env) {
|
|
|
7697
7887
|
return "/etc/gemini-cli/settings.json";
|
|
7698
7888
|
}
|
|
7699
7889
|
function load(file) {
|
|
7700
|
-
if (!
|
|
7890
|
+
if (!existsSync8(file)) return void 0;
|
|
7701
7891
|
try {
|
|
7702
|
-
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(
|
|
7892
|
+
return { file, doc: parseHostConfig(OWN_AGENT, file, hostText(readFileSync5(file, "utf8")), "jsonc") };
|
|
7703
7893
|
} catch {
|
|
7704
7894
|
return void 0;
|
|
7705
7895
|
}
|
|
@@ -7731,7 +7921,7 @@ function geminiSettingsGate(env, home, cwd) {
|
|
|
7731
7921
|
}
|
|
7732
7922
|
|
|
7733
7923
|
// src/setup/zcode-gate.ts
|
|
7734
|
-
import { existsSync as
|
|
7924
|
+
import { existsSync as existsSync9, readFileSync as readFileSync6 } from "node:fs";
|
|
7735
7925
|
import path5 from "node:path";
|
|
7736
7926
|
var OWN_AGENT2 = "zcode";
|
|
7737
7927
|
var EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "PostToolUse", "PostToolUseFailure", "Stop"];
|
|
@@ -7823,10 +8013,10 @@ function zcodeSchemaBad(doc) {
|
|
|
7823
8013
|
}
|
|
7824
8014
|
function zcodeConfigGate(home) {
|
|
7825
8015
|
const file = path5.join(home, ".zcode", "cli", "config.json");
|
|
7826
|
-
if (!
|
|
8016
|
+
if (!existsSync9(file)) return void 0;
|
|
7827
8017
|
let doc;
|
|
7828
8018
|
try {
|
|
7829
|
-
doc = parseHostConfig(OWN_AGENT2, file, hostText(
|
|
8019
|
+
doc = parseHostConfig(OWN_AGENT2, file, hostText(readFileSync6(file, "utf8")), "json");
|
|
7830
8020
|
} catch {
|
|
7831
8021
|
return void 0;
|
|
7832
8022
|
}
|
|
@@ -7836,7 +8026,7 @@ function zcodeConfigGate(home) {
|
|
|
7836
8026
|
}
|
|
7837
8027
|
|
|
7838
8028
|
// src/setup/pi-gate.ts
|
|
7839
|
-
import { existsSync as
|
|
8029
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
7840
8030
|
import path6 from "node:path";
|
|
7841
8031
|
var OWN_FILE = "pi/index.js";
|
|
7842
8032
|
var EXTENSIONS_KEY = "extensions";
|
|
@@ -7845,16 +8035,16 @@ var TRUST_FILE = "trust.json";
|
|
|
7845
8035
|
var ALWAYS = "always";
|
|
7846
8036
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
7847
8037
|
function load2(file) {
|
|
7848
|
-
if (!
|
|
8038
|
+
if (!existsSync10(file)) return void 0;
|
|
7849
8039
|
try {
|
|
7850
|
-
return { file, doc: parseHostConfig("pi", file, hostText(
|
|
8040
|
+
return { file, doc: parseHostConfig("pi", file, hostText(readFileSync7(file, "utf8")), "json") };
|
|
7851
8041
|
} catch {
|
|
7852
8042
|
return void 0;
|
|
7853
8043
|
}
|
|
7854
8044
|
}
|
|
7855
8045
|
var real = (p3) => {
|
|
7856
8046
|
try {
|
|
7857
|
-
return
|
|
8047
|
+
return realpathSync4(p3);
|
|
7858
8048
|
} catch {
|
|
7859
8049
|
return path6.resolve(p3);
|
|
7860
8050
|
}
|
|
@@ -7936,7 +8126,7 @@ function piSettingsGate(env, home, pkgDir, cwd) {
|
|
|
7936
8126
|
}
|
|
7937
8127
|
|
|
7938
8128
|
// src/setup/vscode-gate.ts
|
|
7939
|
-
import { existsSync as
|
|
8129
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8 } from "node:fs";
|
|
7940
8130
|
import path7 from "node:path";
|
|
7941
8131
|
var SETTINGS_FILE3 = "settings.json";
|
|
7942
8132
|
var WORKSPACE_DIR = ".vscode";
|
|
@@ -7945,9 +8135,9 @@ var LOCATIONS_KEY = "chat.hookFilesLocations";
|
|
|
7945
8135
|
var OWN_LOCATION = "~/.copilot/hooks";
|
|
7946
8136
|
var MANAGED_KEYS = ["allowManagedHooksOnly", "strictPluginOnlyCustomization"];
|
|
7947
8137
|
function load3(file) {
|
|
7948
|
-
if (!
|
|
8138
|
+
if (!existsSync11(file)) return void 0;
|
|
7949
8139
|
try {
|
|
7950
|
-
return { file, doc: parseHostConfig("vscode", file, hostText(
|
|
8140
|
+
return { file, doc: parseHostConfig("vscode", file, hostText(readFileSync8(file, "utf8")), "jsonc") };
|
|
7951
8141
|
} catch {
|
|
7952
8142
|
return void 0;
|
|
7953
8143
|
}
|
|
@@ -7987,7 +8177,7 @@ function vscodeSettingsGate(env, home, cwd, managedFile = managedSettingsPath(en
|
|
|
7987
8177
|
}
|
|
7988
8178
|
|
|
7989
8179
|
// src/setup/qwen-gate.ts
|
|
7990
|
-
import { existsSync as
|
|
8180
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9 } from "node:fs";
|
|
7991
8181
|
import path8 from "node:path";
|
|
7992
8182
|
var KEY = "disableAllHooks";
|
|
7993
8183
|
var SETTINGS = "settings.json";
|
|
@@ -8003,10 +8193,10 @@ function settingsFiles(env, home, cwd, platform) {
|
|
|
8003
8193
|
}
|
|
8004
8194
|
function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platform) {
|
|
8005
8195
|
for (const file of settingsFiles(env, home, cwd, platform)) {
|
|
8006
|
-
if (!
|
|
8196
|
+
if (!existsSync12(file)) continue;
|
|
8007
8197
|
let value;
|
|
8008
8198
|
try {
|
|
8009
|
-
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(
|
|
8199
|
+
value = hostConfigValueAt(parseHostConfig("qwen", file, hostText(readFileSync9(file, "utf8")), "jsonc"), [KEY]);
|
|
8010
8200
|
} catch {
|
|
8011
8201
|
continue;
|
|
8012
8202
|
}
|
|
@@ -8017,19 +8207,19 @@ function qwenHooksOff(env, home, cwd = process.cwd(), platform = process.platfor
|
|
|
8017
8207
|
|
|
8018
8208
|
// src/setup/codex-trust.ts
|
|
8019
8209
|
import { createHash } from "node:crypto";
|
|
8020
|
-
import { existsSync as
|
|
8210
|
+
import { existsSync as existsSync13, realpathSync as realpathSync5 } from "node:fs";
|
|
8021
8211
|
import path10 from "node:path";
|
|
8022
|
-
import { spawn, spawnSync as
|
|
8212
|
+
import { spawn, spawnSync as spawnSync3 } from "node:child_process";
|
|
8023
8213
|
|
|
8024
8214
|
// src/setup/spawn-bin.ts
|
|
8025
|
-
import { spawnSync } from "node:child_process";
|
|
8215
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
8026
8216
|
import { accessSync, constants as fsc, statSync } from "node:fs";
|
|
8027
8217
|
import path9 from "node:path";
|
|
8028
8218
|
|
|
8029
8219
|
// src/core/sandbox/path-entries.ts
|
|
8030
|
-
function pathEntries(value, platform = process.platform,
|
|
8220
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
8031
8221
|
const win = platform === "win32";
|
|
8032
|
-
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);
|
|
8033
8223
|
}
|
|
8034
8224
|
|
|
8035
8225
|
// src/setup/spawn-bin.ts
|
|
@@ -8100,7 +8290,7 @@ function spawnShim(file, args, env, opts, platform = process.platform) {
|
|
|
8100
8290
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
8101
8291
|
return { pid: 0, output: [null, "", error.message], stdout: "", stderr: error.message, status: null, signal: null, error };
|
|
8102
8292
|
}
|
|
8103
|
-
return
|
|
8293
|
+
return spawnSync2(f2.command, f2.args, { ...opts, env, windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
8104
8294
|
}
|
|
8105
8295
|
|
|
8106
8296
|
// src/setup/codex-trust.ts
|
|
@@ -8125,11 +8315,11 @@ function snake(name) {
|
|
|
8125
8315
|
function realFile(file) {
|
|
8126
8316
|
let dir = path10.resolve(file);
|
|
8127
8317
|
const rest = [];
|
|
8128
|
-
while (!
|
|
8318
|
+
while (!existsSync13(dir) && path10.dirname(dir) !== dir) {
|
|
8129
8319
|
rest.unshift(path10.basename(dir));
|
|
8130
8320
|
dir = path10.dirname(dir);
|
|
8131
8321
|
}
|
|
8132
|
-
return path10.join(
|
|
8322
|
+
return path10.join(realpathSync5(dir), ...rest);
|
|
8133
8323
|
}
|
|
8134
8324
|
var ASK_TIMEOUT_MS = 1e4;
|
|
8135
8325
|
var ASK_TRIES = 3;
|
|
@@ -8215,14 +8405,14 @@ async function listPluginHooks(env, pluginId, cwd) {
|
|
|
8215
8405
|
function askPluginHooks(env, pluginId, cwd) {
|
|
8216
8406
|
const bin = whichBin("codex", env);
|
|
8217
8407
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
8218
|
-
return new Promise((
|
|
8408
|
+
return new Promise((resolve3) => {
|
|
8219
8409
|
let asked;
|
|
8220
8410
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
8221
8411
|
let f2;
|
|
8222
8412
|
try {
|
|
8223
8413
|
f2 = spawnForm(bin, ["app-server"], env);
|
|
8224
8414
|
} catch {
|
|
8225
|
-
|
|
8415
|
+
resolve3({ kind: "silent" });
|
|
8226
8416
|
return;
|
|
8227
8417
|
}
|
|
8228
8418
|
const child = spawn(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -8232,7 +8422,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
8232
8422
|
let result;
|
|
8233
8423
|
const settle = () => {
|
|
8234
8424
|
clearTimeout(grace);
|
|
8235
|
-
|
|
8425
|
+
resolve3(done_(result));
|
|
8236
8426
|
};
|
|
8237
8427
|
let grace;
|
|
8238
8428
|
const finish2 = (v) => {
|
|
@@ -8289,7 +8479,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
8289
8479
|
function stopTree(pid, kill) {
|
|
8290
8480
|
if (process.platform === "win32" && pid !== void 0) {
|
|
8291
8481
|
try {
|
|
8292
|
-
|
|
8482
|
+
spawnSync3("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
|
|
8293
8483
|
} catch {
|
|
8294
8484
|
}
|
|
8295
8485
|
}
|
|
@@ -8313,7 +8503,7 @@ function untrustedPluginHooksDetail(hooks) {
|
|
|
8313
8503
|
|
|
8314
8504
|
// src/setup/copilot-hooks.ts
|
|
8315
8505
|
import { spawn as spawn2 } from "node:child_process";
|
|
8316
|
-
import { realpathSync as
|
|
8506
|
+
import { realpathSync as realpathSync6 } from "node:fs";
|
|
8317
8507
|
import path11 from "node:path";
|
|
8318
8508
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
8319
8509
|
var ASK_TIMEOUT_MS2 = 15e3;
|
|
@@ -8323,7 +8513,7 @@ var USER_ORIGIN = "user";
|
|
|
8323
8513
|
function canon(p3) {
|
|
8324
8514
|
let r2 = path11.resolve(p3);
|
|
8325
8515
|
try {
|
|
8326
|
-
r2 =
|
|
8516
|
+
r2 = realpathSync6(r2);
|
|
8327
8517
|
} catch {
|
|
8328
8518
|
}
|
|
8329
8519
|
return process.platform === "win32" ? r2.toLowerCase() : r2;
|
|
@@ -8356,12 +8546,12 @@ function frame(buf) {
|
|
|
8356
8546
|
function listCopilotHooks(env, file, cwd) {
|
|
8357
8547
|
const bin = whichBin("copilot", env);
|
|
8358
8548
|
if (!bin) return Promise.resolve(void 0);
|
|
8359
|
-
return new Promise((
|
|
8549
|
+
return new Promise((resolve3) => {
|
|
8360
8550
|
let f2;
|
|
8361
8551
|
try {
|
|
8362
8552
|
f2 = spawnForm(bin, ["--server", "--stdio", "--no-auto-update"], env);
|
|
8363
8553
|
} catch {
|
|
8364
|
-
|
|
8554
|
+
resolve3(void 0);
|
|
8365
8555
|
return;
|
|
8366
8556
|
}
|
|
8367
8557
|
const child = spawn2(f2.command, f2.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f2.windowsVerbatimArguments, windowsHide: true });
|
|
@@ -8373,7 +8563,7 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8373
8563
|
clearTimeout(timer);
|
|
8374
8564
|
child.stdin.destroy();
|
|
8375
8565
|
child.kill();
|
|
8376
|
-
|
|
8566
|
+
resolve3(v);
|
|
8377
8567
|
};
|
|
8378
8568
|
const timer = setTimeout(() => finish2(void 0), ASK_TIMEOUT_MS2);
|
|
8379
8569
|
child.on("error", () => finish2(void 0));
|
|
@@ -8407,8 +8597,8 @@ function listCopilotHooks(env, file, cwd) {
|
|
|
8407
8597
|
}
|
|
8408
8598
|
|
|
8409
8599
|
// src/setup/engine.ts
|
|
8410
|
-
import { spawn as spawn3, spawnSync as
|
|
8411
|
-
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";
|
|
8412
8602
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
8413
8603
|
import path12 from "node:path";
|
|
8414
8604
|
|
|
@@ -8482,6 +8672,7 @@ var HOOK_SAMPLES = 9;
|
|
|
8482
8672
|
var HOOK_ROUNDS = 5;
|
|
8483
8673
|
var P95 = 0.95;
|
|
8484
8674
|
var VERIFY_TIMEOUT_MS = 1e4;
|
|
8675
|
+
var INSTALL_TIMEOUT_MS = 12e4;
|
|
8485
8676
|
var MANIFEST = "manifest.json";
|
|
8486
8677
|
var MANIFEST_DONE = "manifest.removed.json";
|
|
8487
8678
|
var FILES = "files";
|
|
@@ -8493,11 +8684,11 @@ var REAL_HOST = Object.freeze({
|
|
|
8493
8684
|
var BINARY_MAGICS = Object.freeze(["cffaedfe", "cefaedfe", "7f454c46", "4d5a"]);
|
|
8494
8685
|
function isNativeBinary(file) {
|
|
8495
8686
|
const head = Buffer.alloc(4);
|
|
8496
|
-
const fd =
|
|
8687
|
+
const fd = openSync2(file, "r");
|
|
8497
8688
|
try {
|
|
8498
|
-
|
|
8689
|
+
readSync2(fd, head, 0, 4, 0);
|
|
8499
8690
|
} finally {
|
|
8500
|
-
|
|
8691
|
+
closeSync2(fd);
|
|
8501
8692
|
}
|
|
8502
8693
|
const hex = head.toString("hex");
|
|
8503
8694
|
return BINARY_MAGICS.some((m3) => hex.startsWith(m3));
|
|
@@ -8505,9 +8696,9 @@ function isNativeBinary(file) {
|
|
|
8505
8696
|
function owningPackage(dir) {
|
|
8506
8697
|
for (let d = dir; ; d = path12.dirname(d)) {
|
|
8507
8698
|
const f2 = path12.join(d, "package.json");
|
|
8508
|
-
if (
|
|
8699
|
+
if (existsSync14(f2)) {
|
|
8509
8700
|
try {
|
|
8510
|
-
return String(JSON.parse(hostText(
|
|
8701
|
+
return String(JSON.parse(hostText(readFileSync10(f2, "utf8"))).name);
|
|
8511
8702
|
} catch {
|
|
8512
8703
|
return void 0;
|
|
8513
8704
|
}
|
|
@@ -8523,8 +8714,8 @@ function hostBin(bin, env, platform = process.platform) {
|
|
|
8523
8714
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
8524
8715
|
const own2 = which(bin, { PATH: dir, ...get("PATHEXT") ? { PATHEXT: get("PATHEXT") } : {} }, platform);
|
|
8525
8716
|
for (const f2 of [own2, ...real2.extra.map((p3) => path12.join(dir, ...p3))]) {
|
|
8526
|
-
if (!f2 || !
|
|
8527
|
-
const file =
|
|
8717
|
+
if (!f2 || !existsSync14(f2) || !statSync2(f2).isFile()) continue;
|
|
8718
|
+
const file = realpathSync7(f2);
|
|
8528
8719
|
if (isNativeBinary(file) || owningPackage(path12.dirname(file)) === real2.pkg) return { file, shims };
|
|
8529
8720
|
shims.push(f2);
|
|
8530
8721
|
}
|
|
@@ -8536,14 +8727,14 @@ function installExitOk(status, listed, platform = process.platform) {
|
|
|
8536
8727
|
if (status === 0) return true;
|
|
8537
8728
|
return platform === "win32" && status === WIN_EXIT_CRASH && listed;
|
|
8538
8729
|
}
|
|
8539
|
-
function runBin(bin, args, env, input) {
|
|
8540
|
-
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 });
|
|
8541
8732
|
}
|
|
8542
8733
|
function readOr(file) {
|
|
8543
|
-
return
|
|
8734
|
+
return existsSync14(file) ? hostText(readFileSync10(file, "utf8")) : void 0;
|
|
8544
8735
|
}
|
|
8545
8736
|
function readRaw(file) {
|
|
8546
|
-
return
|
|
8737
|
+
return existsSync14(file) ? readFileSync10(file, "utf8") : void 0;
|
|
8547
8738
|
}
|
|
8548
8739
|
var atomicWrite = atomicWriteFile;
|
|
8549
8740
|
function pidAlive(pid) {
|
|
@@ -8688,7 +8879,7 @@ function isNativeSpec(e) {
|
|
|
8688
8879
|
function isStaleOwnPlugin(e, entry2) {
|
|
8689
8880
|
if (typeof e !== "string" || e === entry2 || !path12.isAbsolute(e)) return false;
|
|
8690
8881
|
if (e === path12.join(entry2, ...OPENCODE_PLUGIN_PATH)) return true;
|
|
8691
|
-
if (
|
|
8882
|
+
if (existsSync14(e)) return false;
|
|
8692
8883
|
const seg = e.split("\\").join("/").split("/");
|
|
8693
8884
|
const n3 = seg.length;
|
|
8694
8885
|
if (n3 >= 3 && seg[n3 - 1] === "plugin.js" && seg[n3 - 2] === "opencode" && seg[n3 - 3] === "context-mode") return true;
|
|
@@ -8752,8 +8943,8 @@ function planSkills(row, edits) {
|
|
|
8752
8943
|
const s = row.skillInstall;
|
|
8753
8944
|
if (s.kind !== "dir") return;
|
|
8754
8945
|
for (const f2 of s.files) {
|
|
8755
|
-
if (!
|
|
8756
|
-
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);
|
|
8757
8948
|
const before = readRaw(f2.file);
|
|
8758
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" }] });
|
|
8759
8950
|
}
|
|
@@ -8856,7 +9047,7 @@ function hookEnabledCheck(row, status) {
|
|
|
8856
9047
|
}
|
|
8857
9048
|
function packageVersion(pkgDir) {
|
|
8858
9049
|
try {
|
|
8859
|
-
const v = JSON.parse(hostText(
|
|
9050
|
+
const v = JSON.parse(hostText(readFileSync10(path12.join(pkgDir, "package.json"), "utf8"))).version;
|
|
8860
9051
|
return typeof v === "string" ? v : void 0;
|
|
8861
9052
|
} catch {
|
|
8862
9053
|
return void 0;
|
|
@@ -8882,7 +9073,7 @@ function copyCheck(row, pkgDir) {
|
|
|
8882
9073
|
return { name: "copy", ok: false, detail: `${c3.host} runs context-mode ${old}, the installed package is ${pkg}; run ${c3.bin} ${c3.refresh.join(" ")}` };
|
|
8883
9074
|
}
|
|
8884
9075
|
function mcpCheck(cmd, env) {
|
|
8885
|
-
return new Promise((
|
|
9076
|
+
return new Promise((resolve3) => {
|
|
8886
9077
|
const child = spawn3(cmd[0], cmd.slice(1), { env, stdio: ["pipe", "pipe", "ignore"], detached: process.platform !== "win32", windowsHide: true });
|
|
8887
9078
|
const reap = () => {
|
|
8888
9079
|
child.kill();
|
|
@@ -8894,7 +9085,7 @@ function mcpCheck(cmd, env) {
|
|
|
8894
9085
|
clearTimeout(timer);
|
|
8895
9086
|
process.off("exit", reap);
|
|
8896
9087
|
child.kill();
|
|
8897
|
-
|
|
9088
|
+
resolve3({ name: "mcp", ok, detail });
|
|
8898
9089
|
};
|
|
8899
9090
|
const timer = setTimeout(() => done(false, "no MCP answer before timeout"), VERIFY_TIMEOUT_MS);
|
|
8900
9091
|
child.on("error", (e) => done(false, e.message));
|
|
@@ -8939,7 +9130,7 @@ function hookRound(row, env) {
|
|
|
8939
9130
|
const bare = [];
|
|
8940
9131
|
for (let i2 = 0; i2 < HOOK_SAMPLES; i2++) {
|
|
8941
9132
|
let t2 = performance.now();
|
|
8942
|
-
const r2 =
|
|
9133
|
+
const r2 = spawnSync4(cmd[0], cmd.slice(1), { env, input, encoding: "utf8", timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8943
9134
|
wall.push(performance.now() - t2);
|
|
8944
9135
|
if (r2.status !== 0) return { name: "hook", ok: false, detail: `hook exited ${r2.status}: ${`${r2.stderr}`.trim()}` };
|
|
8945
9136
|
const out2 = `${r2.stdout}`.trim();
|
|
@@ -8952,7 +9143,7 @@ function hookRound(row, env) {
|
|
|
8952
9143
|
if (!isObj5(j2)) return { name: "hook", ok: false, detail: `hook answer is not a JSON object: ${out2.slice(0, 200)}` };
|
|
8953
9144
|
}
|
|
8954
9145
|
t2 = performance.now();
|
|
8955
|
-
|
|
9146
|
+
spawnSync4(cmd[0], ["-e", ""], { env, timeout: VERIFY_TIMEOUT_MS, windowsHide: true });
|
|
8956
9147
|
bare.push(performance.now() - t2);
|
|
8957
9148
|
}
|
|
8958
9149
|
const wallP95Ms = Math.round(p95(wall));
|
|
@@ -9008,26 +9199,26 @@ function hookRunsCheck(row, env) {
|
|
|
9008
9199
|
try {
|
|
9009
9200
|
const home = path12.join(root, "home");
|
|
9010
9201
|
const proj = path12.join(root, "proj");
|
|
9011
|
-
|
|
9012
|
-
|
|
9202
|
+
mkdirSync5(home);
|
|
9203
|
+
mkdirSync5(proj);
|
|
9013
9204
|
const text2 = sampleText();
|
|
9014
|
-
|
|
9205
|
+
writeFileSync3(path12.join(proj, SAMPLE_FILE), text2);
|
|
9015
9206
|
const { effect, payload } = hookSample(row.id, proj, text2);
|
|
9016
9207
|
const sampleEnv = { ...env, HOME: home, USERPROFILE: home };
|
|
9017
9208
|
delete sampleEnv.CLAUDE_PROJECT_DIR;
|
|
9018
9209
|
const cmd = row.hookRunCommand;
|
|
9019
|
-
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 });
|
|
9020
9211
|
const bad = sampleVerdict(row.id, effect, text2, { status: r2.status, stdout: `${r2.stdout ?? ""}`, stderr: `${r2.stderr ?? ""}` });
|
|
9021
9212
|
return bad === null ? { name: "hook-runs", ok: true } : { name: "hook-runs", ok: false, detail: bad };
|
|
9022
9213
|
} finally {
|
|
9023
|
-
|
|
9214
|
+
rmSync2(root, { recursive: true, force: true });
|
|
9024
9215
|
}
|
|
9025
9216
|
}
|
|
9026
9217
|
var SEEN_SQL = "SELECT 1 FROM events WHERE agent = ? LIMIT 1";
|
|
9027
9218
|
var NOT_SEEN_LINE = "not seen yet, run one tool call";
|
|
9028
9219
|
function hookSeenCheck(row, home) {
|
|
9029
9220
|
const base = path12.join(home, STATE_DIR, PROJECTS_DIR_NAME);
|
|
9030
|
-
const dirs =
|
|
9221
|
+
const dirs = existsSync14(base) ? readdirSync5(base) : [];
|
|
9031
9222
|
let sqlite;
|
|
9032
9223
|
try {
|
|
9033
9224
|
sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -9036,7 +9227,7 @@ function hookSeenCheck(row, home) {
|
|
|
9036
9227
|
}
|
|
9037
9228
|
for (const d of dirs) {
|
|
9038
9229
|
const file = path12.join(base, d, DB_FILE_NAME);
|
|
9039
|
-
if (!sqlite || !
|
|
9230
|
+
if (!sqlite || !existsSync14(file)) continue;
|
|
9040
9231
|
let db;
|
|
9041
9232
|
try {
|
|
9042
9233
|
db = new sqlite.DatabaseSync(file, { readOnly: true });
|
|
@@ -9051,10 +9242,10 @@ function hookSeenCheck(row, home) {
|
|
|
9051
9242
|
function skillsCheck(row, pkgDir) {
|
|
9052
9243
|
const s = row.skillInstall;
|
|
9053
9244
|
if (s.kind === "package") {
|
|
9054
|
-
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));
|
|
9055
9246
|
return { name: "skills", ok: miss.length === 0, detail: miss.length ? `missing ${miss.join(", ")}` : void 0 };
|
|
9056
9247
|
}
|
|
9057
|
-
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));
|
|
9058
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 };
|
|
9059
9250
|
}
|
|
9060
9251
|
var PLUGIN_ENABLED = "enabled";
|
|
@@ -9306,26 +9497,26 @@ function undo(dir, entries, env) {
|
|
|
9306
9497
|
continue;
|
|
9307
9498
|
}
|
|
9308
9499
|
if (!e.file) continue;
|
|
9309
|
-
if (e.existed && e.backup) atomicWrite(e.file,
|
|
9500
|
+
if (e.existed && e.backup) atomicWrite(e.file, readFileSync10(path12.join(dir, e.backup), "utf8"));
|
|
9310
9501
|
else unlinkWithRetry(e.file);
|
|
9311
9502
|
}
|
|
9312
9503
|
}
|
|
9313
9504
|
function takeLock(root, runId) {
|
|
9314
9505
|
const file = path12.join(root, LOCK_FILE);
|
|
9315
|
-
|
|
9506
|
+
mkdirSync5(root, { recursive: true });
|
|
9316
9507
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
9317
9508
|
try {
|
|
9318
|
-
|
|
9509
|
+
writeFileSync3(file, JSON.stringify({ pid: process.pid, runId }), { flag: "wx" });
|
|
9319
9510
|
return void 0;
|
|
9320
9511
|
} catch (e) {
|
|
9321
9512
|
if (e.code !== "EEXIST") throw e;
|
|
9322
9513
|
let pid = 0;
|
|
9323
9514
|
try {
|
|
9324
|
-
pid = Number(JSON.parse(
|
|
9515
|
+
pid = Number(JSON.parse(readFileSync10(file, "utf8")).pid);
|
|
9325
9516
|
} catch {
|
|
9326
9517
|
}
|
|
9327
9518
|
if (pid && pidAlive(pid)) return `setup lock ${file} is held by pid ${pid}; wait for that run or remove the lock`;
|
|
9328
|
-
|
|
9519
|
+
rmSync2(file, { force: true });
|
|
9329
9520
|
}
|
|
9330
9521
|
}
|
|
9331
9522
|
return `setup lock ${file} could not be taken`;
|
|
@@ -9338,14 +9529,14 @@ function agentHomeDir(id, ctx) {
|
|
|
9338
9529
|
return path12.join(ctx.home, ...AGENT_HOME_DIR[id]);
|
|
9339
9530
|
}
|
|
9340
9531
|
function detectAgents(reg, ctx) {
|
|
9341
|
-
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);
|
|
9342
9533
|
}
|
|
9343
9534
|
async function runSetup(opts) {
|
|
9344
9535
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9345
9536
|
const runId = opts.runId ?? (/* @__PURE__ */ new Date()).toISOString().split(":").join("-").split(".").join("-");
|
|
9346
9537
|
const reg = buildRegistry(ctx);
|
|
9347
9538
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9348
|
-
if (!
|
|
9539
|
+
if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9349
9540
|
}
|
|
9350
9541
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9351
9542
|
const root = path12.join(ctx.home, STATE_DIR);
|
|
@@ -9358,7 +9549,7 @@ async function runSetup(opts) {
|
|
|
9358
9549
|
let current;
|
|
9359
9550
|
const onAbort = () => {
|
|
9360
9551
|
if (current !== void 0 && !opts.dryRun) run.rollback(current, ctx.env);
|
|
9361
|
-
if (!opts.dryRun)
|
|
9552
|
+
if (!opts.dryRun) rmSync2(path12.join(root, LOCK_FILE), { force: true });
|
|
9362
9553
|
};
|
|
9363
9554
|
opts.signal?.addEventListener("abort", onAbort, { once: true });
|
|
9364
9555
|
try {
|
|
@@ -9377,7 +9568,7 @@ async function runSetup(opts) {
|
|
|
9377
9568
|
}
|
|
9378
9569
|
} finally {
|
|
9379
9570
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
9380
|
-
if (!opts.dryRun)
|
|
9571
|
+
if (!opts.dryRun) rmSync2(path12.join(root, LOCK_FILE), { force: true });
|
|
9381
9572
|
}
|
|
9382
9573
|
return { exitCode: agents.some((a2) => a2.status === "FAIL") ? 1 : 0, agents, backupDir: run.manifest ? run.dir : void 0 };
|
|
9383
9574
|
}
|
|
@@ -9411,12 +9602,12 @@ async function setupRow(row, ctx, run, dryRun) {
|
|
|
9411
9602
|
atomicWrite(e.file, e.plain || raw === void 0 ? e.after : withLayout(e.after, hostLayout(raw)));
|
|
9412
9603
|
}
|
|
9413
9604
|
for (const args of plan.cli) {
|
|
9414
|
-
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);
|
|
9415
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()}`);
|
|
9416
9607
|
}
|
|
9417
9608
|
if (plan.cli.length) for (const args of row.cli.remove) run.record({ agent: row.id, undo: { bin: row.cli.bin, args } });
|
|
9418
9609
|
for (const args of plan.refresh) {
|
|
9419
|
-
const r2 = runBin(row.cli.bin, args, ctx.env);
|
|
9610
|
+
const r2 = runBin(row.cli.bin, args, ctx.env, void 0, INSTALL_TIMEOUT_MS);
|
|
9420
9611
|
if (r2.status !== 0) throw new Error(`${row.cli.bin} ${args.join(" ")} exited ${r2.status}: ${`${r2.stderr}`.trim()}`);
|
|
9421
9612
|
run.record({ agent: row.id, ran: { bin: row.cli.bin, args } });
|
|
9422
9613
|
}
|
|
@@ -9436,7 +9627,7 @@ async function runDoctor(opts) {
|
|
|
9436
9627
|
const ctx = { home: opts.home, pkgDir: opts.pkgDir, env: opts.env };
|
|
9437
9628
|
const reg = buildRegistry(ctx);
|
|
9438
9629
|
for (const f2 of ["server.mjs", "hook.mjs"]) {
|
|
9439
|
-
if (!
|
|
9630
|
+
if (!existsSync14(path12.join(ctx.pkgDir, f2))) return { exitCode: 1, agents: [], error: `preflight: ${path12.join(ctx.pkgDir, f2)} is missing` };
|
|
9440
9631
|
}
|
|
9441
9632
|
const ids = opts.agents ?? detectAgents(reg, ctx);
|
|
9442
9633
|
const run = new Run(path12.join(ctx.home, STATE_DIR), "doctor");
|
|
@@ -9504,26 +9695,26 @@ function runRemove(opts) {
|
|
|
9504
9695
|
const env = opts.env ?? process.env;
|
|
9505
9696
|
const root = path12.join(opts.home, STATE_DIR);
|
|
9506
9697
|
const base = path12.join(root, BACKUP_DIR);
|
|
9507
|
-
if (!
|
|
9698
|
+
if (!existsSync14(base)) return { exitCode: 0, restored: 0 };
|
|
9508
9699
|
const held = takeLock(root, "remove");
|
|
9509
9700
|
if (held) return { exitCode: 1, restored: 0, error: held };
|
|
9510
9701
|
let restored = 0;
|
|
9511
9702
|
try {
|
|
9512
|
-
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();
|
|
9513
9704
|
for (const dir of runs) {
|
|
9514
|
-
const m3 = JSON.parse(
|
|
9705
|
+
const m3 = JSON.parse(readFileSync10(path12.join(dir, MANIFEST), "utf8"));
|
|
9515
9706
|
undo(dir, m3.entries, env);
|
|
9516
9707
|
restored += m3.entries.length;
|
|
9517
9708
|
renameWithRetry(path12.join(dir, MANIFEST), path12.join(dir, MANIFEST_DONE));
|
|
9518
9709
|
}
|
|
9519
9710
|
} finally {
|
|
9520
|
-
|
|
9711
|
+
rmSync2(path12.join(root, LOCK_FILE), { force: true });
|
|
9521
9712
|
}
|
|
9522
9713
|
return { exitCode: 0, restored };
|
|
9523
9714
|
}
|
|
9524
9715
|
|
|
9525
9716
|
// src/setup/print.ts
|
|
9526
|
-
import { readFileSync as
|
|
9717
|
+
import { readFileSync as readFileSync11 } from "node:fs";
|
|
9527
9718
|
var SHELL_SAFE_PUNCT = "@%+=:,./-_";
|
|
9528
9719
|
function isShellSafe(s) {
|
|
9529
9720
|
if (s === "") return false;
|
|
@@ -9551,7 +9742,7 @@ function printPlan(row, env) {
|
|
|
9551
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" });
|
|
9552
9743
|
const sk = row.skillInstall;
|
|
9553
9744
|
if (sk.kind === "dir") {
|
|
9554
|
-
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) });
|
|
9555
9746
|
}
|
|
9556
9747
|
return { agent: row.id, steps, verify: `context-mode doctor --agents ${row.id}` };
|
|
9557
9748
|
}
|
|
@@ -9712,23 +9903,22 @@ function buildIssueReport(command, res, ui) {
|
|
|
9712
9903
|
return { text: redact(lines.join("\n"), ui.ctx), title };
|
|
9713
9904
|
}
|
|
9714
9905
|
function ghReady(env) {
|
|
9715
|
-
const r2 =
|
|
9906
|
+
const r2 = spawnSync5("gh", ["auth", "status"], { env, stdio: "ignore", timeout: 1e4, windowsHide: true });
|
|
9716
9907
|
return r2.status === 0;
|
|
9717
9908
|
}
|
|
9718
|
-
function issueUrl(title,
|
|
9719
|
-
|
|
9720
|
-
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);
|
|
9721
9911
|
}
|
|
9722
9912
|
async function report(ui, command, res, write) {
|
|
9723
9913
|
const { text: text2, title } = buildIssueReport(command, res, ui);
|
|
9724
9914
|
let file = "";
|
|
9725
9915
|
if (write) {
|
|
9726
9916
|
const dir = path13.join(ui.ctx.home, STATE_DIR, REPORT_DIR);
|
|
9727
|
-
|
|
9917
|
+
mkdirSync6(dir, { recursive: true });
|
|
9728
9918
|
file = path13.join(dir, `${command}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
9729
|
-
|
|
9919
|
+
writeFileSync4(file, text2);
|
|
9730
9920
|
}
|
|
9731
|
-
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>")}`;
|
|
9732
9922
|
const p3 = ui.clack;
|
|
9733
9923
|
if (!p3) {
|
|
9734
9924
|
if (ui.f.debug) err(text2);
|
|
@@ -9743,15 +9933,15 @@ async function report(ui, command, res, write) {
|
|
|
9743
9933
|
return;
|
|
9744
9934
|
}
|
|
9745
9935
|
if (file && ghReady(ui.ctx.env)) {
|
|
9746
|
-
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 });
|
|
9747
9937
|
if (r2.status === 0) {
|
|
9748
9938
|
p3.log.success(`Issue opened: ${`${r2.stdout}`.trim()}`);
|
|
9749
9939
|
return;
|
|
9750
9940
|
}
|
|
9751
9941
|
p3.log.warn(`gh issue create failed: ${`${r2.stderr}`.trim()}`);
|
|
9752
9942
|
}
|
|
9753
|
-
p3.log.info(`Open this URL to file the issue:
|
|
9754
|
-
${issueUrl(title,
|
|
9943
|
+
p3.log.info(`Open this URL to file the issue (paste the report file into the form):
|
|
9944
|
+
${issueUrl(title, title)}`);
|
|
9755
9945
|
}
|
|
9756
9946
|
async function apply(ui, agents, dryRun) {
|
|
9757
9947
|
const ac = new AbortController();
|
|
@@ -9966,20 +10156,20 @@ async function upgrade(ui) {
|
|
|
9966
10156
|
}
|
|
9967
10157
|
const shell = process.platform === "win32";
|
|
9968
10158
|
progress2(ui, `running ${install}`);
|
|
9969
|
-
const r2 =
|
|
10159
|
+
const r2 = spawnSync5(npm, ["i", "-g", spec], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true });
|
|
9970
10160
|
if (r2.status !== 0) {
|
|
9971
10161
|
const why = (`${r2.stderr ?? ""}`.trim().split("\n").pop() ?? "") || (r2.error?.message ?? "");
|
|
9972
10162
|
err(`FAIL upgrade: ${install} exited ${r2.status ?? "?"}${why ? `: ${why}` : ""}. Fix: ${install}`);
|
|
9973
10163
|
return EXIT_FAIL;
|
|
9974
10164
|
}
|
|
9975
|
-
const root = `${
|
|
10165
|
+
const root = `${spawnSync5(npm, ["root", "-g"], { env: ui.ctx.env, encoding: "utf8", shell, windowsHide: true }).stdout ?? ""}`.trim();
|
|
9976
10166
|
const cli = path13.join(root, "context-mode", "cli.mjs");
|
|
9977
|
-
if (!root || !
|
|
10167
|
+
if (!root || !existsSync15(cli)) {
|
|
9978
10168
|
err(`FAIL upgrade: ${cli} not found after ${install}. Fix: ${install}`);
|
|
9979
10169
|
return EXIT_FAIL;
|
|
9980
10170
|
}
|
|
9981
10171
|
progress2(ui, `running context-mode ${repairArgs.join(" ")}`);
|
|
9982
|
-
const c3 =
|
|
10172
|
+
const c3 = spawnSync5(process.execPath, [cli, ...repairArgs], { env: ui.ctx.env, stdio: "inherit", windowsHide: true });
|
|
9983
10173
|
return c3.status ?? (c3.signal === "SIGINT" ? EXIT_SIGINT : EXIT_FAIL);
|
|
9984
10174
|
}
|
|
9985
10175
|
async function runCommand(cmd, args, env) {
|
|
@@ -10013,12 +10203,12 @@ Run context-mode ${cmd} --help.`);
|
|
|
10013
10203
|
}
|
|
10014
10204
|
|
|
10015
10205
|
// src/entries/is-entry.ts
|
|
10016
|
-
import { realpathSync as
|
|
10206
|
+
import { realpathSync as realpathSync8 } from "node:fs";
|
|
10017
10207
|
function isEntry(main2, argv1, self) {
|
|
10018
10208
|
if (main2 !== void 0) return main2;
|
|
10019
10209
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
10020
10210
|
try {
|
|
10021
|
-
return
|
|
10211
|
+
return realpathSync8(argv1) === realpathSync8(self);
|
|
10022
10212
|
} catch {
|
|
10023
10213
|
return false;
|
|
10024
10214
|
}
|
|
@@ -10069,10 +10259,10 @@ function route(argv, version) {
|
|
|
10069
10259
|
` };
|
|
10070
10260
|
}
|
|
10071
10261
|
function main() {
|
|
10072
|
-
const dir = path14.dirname(
|
|
10262
|
+
const dir = path14.dirname(realpathSync9(fileURLToPath2(import.meta.url)));
|
|
10073
10263
|
let version = "";
|
|
10074
10264
|
try {
|
|
10075
|
-
version = String(JSON.parse(
|
|
10265
|
+
version = String(JSON.parse(readFileSync12(path14.join(dir, PACKAGE_FILE), "utf8")).version);
|
|
10076
10266
|
} catch (err2) {
|
|
10077
10267
|
process.stderr.write(`${SERVER_KEY}: cannot read ${PACKAGE_FILE}: ${err2.message}
|
|
10078
10268
|
`);
|