context-mode 2.1.5 → 2.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +72 -72
- package/SHA256SUMS +16 -16
- package/cli.mjs +411 -168
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +800 -377
- package/package.json +1 -1
- package/pi/index.js +724 -380
- package/qwen-extension.json +1 -1
- package/run.mjs +335 -74
- package/search.mjs +335 -74
- package/server.mjs +517 -231
package/server.mjs
CHANGED
|
@@ -7,8 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { dirname as
|
|
10
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
11
|
+
import { dirname as dirname13, join as join23 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
13
13
|
|
|
14
14
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -17605,7 +17605,7 @@ var PROPERTY_KEYS_BY_TYPE = {
|
|
|
17605
17605
|
array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
|
|
17606
17606
|
};
|
|
17607
17607
|
var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
|
|
17608
|
-
function walkProperty(node3, path8, vendor,
|
|
17608
|
+
function walkProperty(node3, path8, vendor, unsupported2) {
|
|
17609
17609
|
if (!isJsonObject(node3)) return node3;
|
|
17610
17610
|
const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
|
|
17611
17611
|
if (allowedKeys === void 0) return node3;
|
|
@@ -17613,17 +17613,17 @@ function walkProperty(node3, path8, vendor, unsupported) {
|
|
|
17613
17613
|
for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
|
|
17614
17614
|
else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
|
|
17615
17615
|
if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
|
|
17616
|
-
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor))
|
|
17617
|
-
} else
|
|
17616
|
+
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported2.push(`${path8}.${key}`);
|
|
17617
|
+
} else unsupported2.push(`${path8}.${key}`);
|
|
17618
17618
|
return pruned;
|
|
17619
17619
|
}
|
|
17620
17620
|
function walkRequestedSchema(converted, vendor) {
|
|
17621
17621
|
const pruned = {};
|
|
17622
|
-
const
|
|
17623
|
-
for (const [key, value] of Object.entries(converted)) if (key === "properties" && isJsonObject(value)) pruned[key] = Object.fromEntries(Object.entries(value).map(([name, node3]) => [name, walkProperty(node3, `properties.${name}`, vendor,
|
|
17622
|
+
const unsupported2 = [];
|
|
17623
|
+
for (const [key, value] of Object.entries(converted)) if (key === "properties" && isJsonObject(value)) pruned[key] = Object.fromEntries(Object.entries(value).map(([name, node3]) => [name, walkProperty(node3, `properties.${name}`, vendor, unsupported2)]));
|
|
17624
17624
|
else if (ROOT_KEYS.has(key)) pruned[key] = value;
|
|
17625
|
-
else if (!isAnnotationOnlyJsonSchemaKeyword(key))
|
|
17626
|
-
if (
|
|
17625
|
+
else if (!isAnnotationOnlyJsonSchemaKeyword(key)) unsupported2.push(key);
|
|
17626
|
+
if (unsupported2.length > 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Elicitation requestedSchema contains unsupported JSON Schema constraint(s) after Standard Schema conversion: ${unsupported2.join(", ")}`);
|
|
17627
17627
|
return pruned;
|
|
17628
17628
|
}
|
|
17629
17629
|
function describeUnsupportedProperties(pruned, fallback) {
|
|
@@ -28065,7 +28065,14 @@ var REPORT_CAP = 4096;
|
|
|
28065
28065
|
var POINTER_MIN = 640;
|
|
28066
28066
|
var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
28067
28067
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
28068
|
-
var
|
|
28068
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
28069
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
28070
|
+
function readReplaceTrigger(raw) {
|
|
28071
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
28072
|
+
const n = Number(raw);
|
|
28073
|
+
return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
28074
|
+
}
|
|
28075
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
28069
28076
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
28070
28077
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
28071
28078
|
var MAX_CHUNK_BYTES = 4096;
|
|
@@ -28214,6 +28221,8 @@ var RRF_K = 60;
|
|
|
28214
28221
|
var SOURCE_HANDLE_MAX_DIGITS = 10;
|
|
28215
28222
|
var EXEC_TIMEOUT_MS = 6e5;
|
|
28216
28223
|
var KILL_GRACE_MS = 1e3;
|
|
28224
|
+
var PIPE_EOF_GRACE_MS = 250;
|
|
28225
|
+
var PIPE_DRAIN_MAX_MS = 2e3;
|
|
28217
28226
|
var DB_TIMEOUT_MS = 5e3;
|
|
28218
28227
|
var DB_WAL_SUFFIX = "-wal";
|
|
28219
28228
|
var DB_SHM_SUFFIX = "-shm";
|
|
@@ -28248,6 +28257,7 @@ var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
|
28248
28257
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
28249
28258
|
var FETCH_MAX_HOPS = 5;
|
|
28250
28259
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
28260
|
+
var BACKGROUND_HOLD_NOTE = "note: the command ended while a background process still held its output; that process was stopped, so output it would write later does not exist.";
|
|
28251
28261
|
var CANCELLED_LINE = "Cancelled.";
|
|
28252
28262
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
28253
28263
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
@@ -28276,6 +28286,7 @@ function readHintEvery(raw) {
|
|
|
28276
28286
|
return Number.isSafeInteger(n) && n > 0 ? n : MCP_HINT_EVERY_DEFAULT;
|
|
28277
28287
|
}
|
|
28278
28288
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
28289
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
28279
28290
|
var DENY_WHAT = Object.freeze({
|
|
28280
28291
|
curl: "This curl/wget call",
|
|
28281
28292
|
http: "This inline HTTP call",
|
|
@@ -28345,15 +28356,16 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
28345
28356
|
opencode: READ_IMAGES_AND_PDF,
|
|
28346
28357
|
pi: READ_IMAGES,
|
|
28347
28358
|
vscode: READ_IMAGES,
|
|
28359
|
+
zcode: READ_IMAGES,
|
|
28348
28360
|
"copilot-cli": [],
|
|
28349
28361
|
codex: [],
|
|
28350
|
-
kiro: []
|
|
28351
|
-
zcode: []
|
|
28362
|
+
kiro: []
|
|
28352
28363
|
});
|
|
28353
28364
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
28354
28365
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
28355
28366
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
28356
28367
|
var RECALL_MIN_SCORE = 5;
|
|
28368
|
+
var RECALL_QUERY_MAX_TERMS = 64;
|
|
28357
28369
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
28358
28370
|
var AGENT_ARG = "--agent";
|
|
28359
28371
|
var DECAY_SCALE = 1e3;
|
|
@@ -28434,7 +28446,7 @@ function PURGE_SUMMARY(rows, scope) {
|
|
|
28434
28446
|
var DECISION_SOURCE = "decision";
|
|
28435
28447
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28436
28448
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28437
|
-
var BUNDLE_SHA = true ? "
|
|
28449
|
+
var BUNDLE_SHA = true ? "5539b632975049a99de986448417a10bd246e506" : void 0;
|
|
28438
28450
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28439
28451
|
var DOCTOR_LABEL = Object.freeze({
|
|
28440
28452
|
D1: "version",
|
|
@@ -28520,9 +28532,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
|
|
|
28520
28532
|
var D1_PRERELEASE_SEP = "-";
|
|
28521
28533
|
var D1_DEFAULT_TAG = "latest";
|
|
28522
28534
|
var GIT_LS_REMOTE = "ls-remote";
|
|
28523
|
-
var D2_NODE_FIX = `install
|
|
28535
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
28524
28536
|
function D2_NODE_DETAIL(version4) {
|
|
28525
|
-
return `Node ${
|
|
28537
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version4}`;
|
|
28526
28538
|
}
|
|
28527
28539
|
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
28528
28540
|
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
@@ -28540,6 +28552,7 @@ var D5B_FIX = "disable chat.useClaudeHooks or the Claude Code hooks block";
|
|
|
28540
28552
|
var VSCODE_CLAUDE_HOOKS_SETTING = "chat.useClaudeHooks";
|
|
28541
28553
|
var VSCODE_SETTINGS_FILE = "settings.json";
|
|
28542
28554
|
var D6_UNKNOWN_DETAIL = "no clientInfo or protocolVersion on the request";
|
|
28555
|
+
var D6_IN_PROCESS_DETAIL = "in-process plugin: this call ran inside the agent, no MCP session to read";
|
|
28543
28556
|
function D7_DETAIL(got) {
|
|
28544
28557
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
28545
28558
|
}
|
|
@@ -28655,6 +28668,90 @@ function D3_DETAIL(parts) {
|
|
|
28655
28668
|
function D3_ROOT_DETAIL(paths) {
|
|
28656
28669
|
return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
|
|
28657
28670
|
}
|
|
28671
|
+
var unsupported = (h) => Object.freeze(h);
|
|
28672
|
+
var UNSUPPORTED_HOSTS = Object.freeze([
|
|
28673
|
+
unsupported({
|
|
28674
|
+
id: "antigravity",
|
|
28675
|
+
name: "Antigravity",
|
|
28676
|
+
clientNames: ["antigravity", "antigravity-client", "antigravity-cli", "agy"],
|
|
28677
|
+
envVars: ["ANTIGRAVITY_CLI_ALIAS"],
|
|
28678
|
+
pluginPaths: [[".gemini", "config", "plugins"], [".gemini", "antigravity", "plugins"], [".gemini", "antigravity-cli", "plugins"], [".gemini", "antigravity-ide", "plugins"]],
|
|
28679
|
+
configDirs: [".gemini/antigravity", ".gemini/antigravity-cli", ".gemini/config"],
|
|
28680
|
+
binaries: ["agy"],
|
|
28681
|
+
source: "v1.0.169:src/adapters/client-map.ts:15-17; detect.ts:156,481-483; #1340"
|
|
28682
|
+
}),
|
|
28683
|
+
unsupported({
|
|
28684
|
+
id: "cursor",
|
|
28685
|
+
name: "Cursor",
|
|
28686
|
+
clientNames: ["cursor-vscode"],
|
|
28687
|
+
envVars: ["CURSOR_TRACE_ID", "CURSOR_CLI", "CURSOR_CWD"],
|
|
28688
|
+
pluginPaths: [],
|
|
28689
|
+
configDirs: [".cursor"],
|
|
28690
|
+
binaries: [],
|
|
28691
|
+
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
28692
|
+
}),
|
|
28693
|
+
unsupported({
|
|
28694
|
+
id: "omp",
|
|
28695
|
+
name: "OMP (oh-my-pi)",
|
|
28696
|
+
clientNames: ["omp-coding-agent"],
|
|
28697
|
+
envVars: [],
|
|
28698
|
+
pluginPaths: [],
|
|
28699
|
+
configDirs: [".omp"],
|
|
28700
|
+
binaries: ["omp"],
|
|
28701
|
+
source: "v1.0.169:src/adapters/client-map.ts:37; detect.ts:543 (PI_CODING_AGENT_DIR is not a signal: supported Pi reads it too)"
|
|
28702
|
+
}),
|
|
28703
|
+
unsupported({
|
|
28704
|
+
id: "openclaw",
|
|
28705
|
+
name: "OpenClaw",
|
|
28706
|
+
clientNames: [],
|
|
28707
|
+
envVars: [],
|
|
28708
|
+
pluginPaths: [],
|
|
28709
|
+
configDirs: [".openclaw"],
|
|
28710
|
+
binaries: [],
|
|
28711
|
+
source: "v1.0.169:src/adapters/detect.ts:252,575 (the runtime sets no env var)"
|
|
28712
|
+
}),
|
|
28713
|
+
unsupported({
|
|
28714
|
+
id: "kimi",
|
|
28715
|
+
name: "Kimi Code",
|
|
28716
|
+
clientNames: ["kimi-code", "kimi"],
|
|
28717
|
+
envVars: [],
|
|
28718
|
+
pluginPaths: [],
|
|
28719
|
+
configDirs: [".kimi-code"],
|
|
28720
|
+
binaries: ["kimi"],
|
|
28721
|
+
source: "v1.0.169:src/adapters/client-map.ts:42-44; detect.ts:567; adapters/kimi/index.ts:127"
|
|
28722
|
+
}),
|
|
28723
|
+
unsupported({
|
|
28724
|
+
id: "kilo",
|
|
28725
|
+
name: "Kilo Code",
|
|
28726
|
+
clientNames: ["kilo code"],
|
|
28727
|
+
envVars: ["KILO", "KILO_PID"],
|
|
28728
|
+
pluginPaths: [],
|
|
28729
|
+
configDirs: [".config/kilo"],
|
|
28730
|
+
binaries: [],
|
|
28731
|
+
source: "v1.0.169:src/adapters/client-map.ts:28; detect.ts:170-171,592"
|
|
28732
|
+
}),
|
|
28733
|
+
unsupported({
|
|
28734
|
+
id: "zed",
|
|
28735
|
+
name: "Zed",
|
|
28736
|
+
clientNames: ["zed"],
|
|
28737
|
+
envVars: ["ZED_SESSION_ID", "ZED_TERM"],
|
|
28738
|
+
pluginPaths: [],
|
|
28739
|
+
configDirs: [".config/zed"],
|
|
28740
|
+
binaries: [],
|
|
28741
|
+
source: "v1.0.169:src/adapters/client-map.ts:38-39; detect.ts:189-190,616"
|
|
28742
|
+
}),
|
|
28743
|
+
unsupported({
|
|
28744
|
+
id: "jetbrains-copilot",
|
|
28745
|
+
name: "JetBrains Copilot",
|
|
28746
|
+
clientNames: ["jetbrains client", "intellij idea", "pycharm"],
|
|
28747
|
+
envVars: ["IDEA_INITIAL_DIRECTORY"],
|
|
28748
|
+
pluginPaths: [],
|
|
28749
|
+
configDirs: [".config/JetBrains"],
|
|
28750
|
+
binaries: [],
|
|
28751
|
+
source: "v1.0.169:src/adapters/client-map.ts:23-25; detect.ts:213,600"
|
|
28752
|
+
})
|
|
28753
|
+
]);
|
|
28754
|
+
var SUPPORTED_AGENTS_DOCS_URL = "https://github.com/mksglu/context-mode/blob/main/docs/install/README.md";
|
|
28658
28755
|
var D3_ROOT_FIX_JOIN = " or ";
|
|
28659
28756
|
function D3_ROOT_FIX(installs) {
|
|
28660
28757
|
return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
|
|
@@ -28691,6 +28788,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
28691
28788
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
28692
28789
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
28693
28790
|
var D5_READ_RANGE_DETAIL = "PostToolUse Read with offset/limit over the replace trigger came back replaced: a bounded Read must reach the model whole";
|
|
28791
|
+
var D5_READ_OWN_DETAIL = "PreToolUse Read of a skill file over the one-read limit under the agent's own config dir came back denied: skill and rule files must reach the model whole (#1326)";
|
|
28694
28792
|
var D5_READ_MEDIA_DETAIL = "PreToolUse Read of a PNG over the one-read limit came back denied: an image Read must reach the model as an image block (#1321)";
|
|
28695
28793
|
var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
|
|
28696
28794
|
function D5_SLOW_DETAIL(ms) {
|
|
@@ -28702,6 +28800,11 @@ var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
|
28702
28800
|
function D10_DETAIL(mode) {
|
|
28703
28801
|
return `enforcement mode: ${mode}`;
|
|
28704
28802
|
}
|
|
28803
|
+
function D10_PERMISSION_DETAIL(mode) {
|
|
28804
|
+
return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
|
|
28805
|
+
}
|
|
28806
|
+
var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
|
|
28807
|
+
var D10_PERMISSION_FIX = "opencode upgrade";
|
|
28705
28808
|
var D11_WIN_DETAIL = "Git Bash not found";
|
|
28706
28809
|
var D11_WIN_FIX = "install Git for Windows";
|
|
28707
28810
|
var D11_POSIX_DETAIL = "no sh on PATH";
|
|
@@ -28764,6 +28867,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
28764
28867
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
28765
28868
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
28766
28869
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
28870
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
28871
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
28767
28872
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
28768
28873
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
28769
28874
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -28858,6 +28963,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
28858
28963
|
var JSON_INDENT_UNIT = " ";
|
|
28859
28964
|
var MCP_COMMAND_FIELD = "command";
|
|
28860
28965
|
var MCP_ARGS_FIELD = "args";
|
|
28966
|
+
var MCP_ENV_FIELD = "env";
|
|
28861
28967
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
28862
28968
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
28863
28969
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -28975,7 +29081,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
|
28975
29081
|
|
|
28976
29082
|
// src/core/contracts/errors.ts
|
|
28977
29083
|
var ERROR_TEXT = Object.freeze({
|
|
28978
|
-
NODE_TOO_OLD: "
|
|
29084
|
+
NODE_TOO_OLD: "Context Mode needs Node 24.15.0 or newer; you have <v>. Fix: nvm install 24, or install it from https://nodejs.org.",
|
|
29085
|
+
// #1328 D-NODE-OLD-1
|
|
28979
29086
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
28980
29087
|
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
28981
29088
|
// D-ORPHAN-WAL-1
|
|
@@ -29407,7 +29514,7 @@ function installExitGuard(opts) {
|
|
|
29407
29514
|
|
|
29408
29515
|
// src/core/project/config-dir.ts
|
|
29409
29516
|
import { basename, dirname, join, posix, resolve, win32 } from "node:path";
|
|
29410
|
-
var { mkdirSync: mkdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
|
|
29517
|
+
var { existsSync: existsSync2, mkdirSync: mkdirSync2, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
29411
29518
|
function homeDirOf(env, platform = process.platform) {
|
|
29412
29519
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
29413
29520
|
if (platform === "win32") {
|
|
@@ -29434,7 +29541,34 @@ function codexPluginHomeOf(bundleDir2) {
|
|
|
29434
29541
|
function codexRunDirOf(env, home, bundleDir2) {
|
|
29435
29542
|
const dir = env[CODEX_HOME_ENV];
|
|
29436
29543
|
if (dir !== void 0 && dir !== "") return dir;
|
|
29437
|
-
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
29544
|
+
return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
|
|
29545
|
+
}
|
|
29546
|
+
function codexSetupHomeOf(env, home) {
|
|
29547
|
+
if (home === "" && !env[DATA_DIR_ENV]) return null;
|
|
29548
|
+
const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
|
|
29549
|
+
let runs;
|
|
29550
|
+
try {
|
|
29551
|
+
runs = readdirSync(base).sort().reverse();
|
|
29552
|
+
} catch {
|
|
29553
|
+
return null;
|
|
29554
|
+
}
|
|
29555
|
+
for (const run of runs) {
|
|
29556
|
+
const file2 = join(base, run, SETUP_MANIFEST_FILE);
|
|
29557
|
+
if (!existsSync2(file2)) continue;
|
|
29558
|
+
let entries;
|
|
29559
|
+
try {
|
|
29560
|
+
entries = JSON.parse(readFileSync(file2, "utf8")).entries;
|
|
29561
|
+
} catch {
|
|
29562
|
+
continue;
|
|
29563
|
+
}
|
|
29564
|
+
if (!Array.isArray(entries)) continue;
|
|
29565
|
+
for (const e of entries) {
|
|
29566
|
+
if (e?.agent !== "codex" || typeof e.file !== "string") continue;
|
|
29567
|
+
const p = e.file.includes(win32.sep) ? win32 : posix;
|
|
29568
|
+
if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
|
|
29569
|
+
}
|
|
29570
|
+
}
|
|
29571
|
+
return null;
|
|
29438
29572
|
}
|
|
29439
29573
|
function copilotDirOf(env, home) {
|
|
29440
29574
|
const dir = env[COPILOT_HOME_ENV];
|
|
@@ -29475,6 +29609,17 @@ function claudeDirOf(env, home) {
|
|
|
29475
29609
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
29476
29610
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["claude-code"]);
|
|
29477
29611
|
}
|
|
29612
|
+
function claudeProfileEnv(env, platform = process.platform) {
|
|
29613
|
+
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
29614
|
+
if (dir === void 0 || dir === "" || platform === "win32") return "";
|
|
29615
|
+
return `${CLAUDE_CONFIG_DIR_ENV}='${dir.split("'").join(`'"'"'`)}' `;
|
|
29616
|
+
}
|
|
29617
|
+
function hostUpdateCommand(agent, env, platform = process.platform) {
|
|
29618
|
+
const cmd = UPGRADE_HOST_COMMAND[agent];
|
|
29619
|
+
if (agent !== "claude-code") return cmd;
|
|
29620
|
+
const profile = claudeProfileEnv(env, platform);
|
|
29621
|
+
return profile === "" ? cmd : cmd.split(" && ").map((c) => profile + c).join(" && ");
|
|
29622
|
+
}
|
|
29478
29623
|
function opencodeDirOf(env, home) {
|
|
29479
29624
|
const own4 = env[OPENCODE_CONFIG_DIR_ENV];
|
|
29480
29625
|
if (own4 !== void 0 && own4 !== "") return own4;
|
|
@@ -29686,7 +29831,7 @@ function sha256Hex(text) {
|
|
|
29686
29831
|
}
|
|
29687
29832
|
|
|
29688
29833
|
// src/core/project/resolve.ts
|
|
29689
|
-
var { existsSync:
|
|
29834
|
+
var { existsSync: existsSync3, readFileSync: readFileSync2, realpathSync: realpathSync3, statSync } = process.getBuiltinModule("node:fs");
|
|
29690
29835
|
function sourceOf(agent) {
|
|
29691
29836
|
switch (agent) {
|
|
29692
29837
|
case "claude-code":
|
|
@@ -29756,12 +29901,12 @@ function gitDirAt(dotGit) {
|
|
|
29756
29901
|
} catch {
|
|
29757
29902
|
return null;
|
|
29758
29903
|
}
|
|
29759
|
-
return
|
|
29904
|
+
return existsSync3(join3(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
29760
29905
|
}
|
|
29761
29906
|
function firstLine(file2) {
|
|
29762
29907
|
let text;
|
|
29763
29908
|
try {
|
|
29764
|
-
text =
|
|
29909
|
+
text = readFileSync2(file2, "utf8");
|
|
29765
29910
|
} catch {
|
|
29766
29911
|
return null;
|
|
29767
29912
|
}
|
|
@@ -29814,7 +29959,7 @@ function resolveProject(agent, src) {
|
|
|
29814
29959
|
}
|
|
29815
29960
|
|
|
29816
29961
|
// src/core/store/cleanup.ts
|
|
29817
|
-
import { existsSync as
|
|
29962
|
+
import { existsSync as existsSync4, readdirSync as readdirSync3, rmSync as rmSync3 } from "node:fs";
|
|
29818
29963
|
import { join as join5 } from "node:path";
|
|
29819
29964
|
|
|
29820
29965
|
// src/core/store/snippet.ts
|
|
@@ -32341,8 +32486,25 @@ function listSessionSources(db, sessionId, limit) {
|
|
|
32341
32486
|
const rows = stmt(db.raw, "SELECT id, label, bytes_total FROM sources WHERE session_id = ? ORDER BY id DESC LIMIT ?").all(sessionId, limit);
|
|
32342
32487
|
return rows.map((r) => ({ id: Number(r.id), label: r.label, bytes: Number(r.bytes_total) }));
|
|
32343
32488
|
}
|
|
32344
|
-
function recallQueryText(prompt
|
|
32345
|
-
|
|
32489
|
+
function recallQueryText(prompt) {
|
|
32490
|
+
const kept = /* @__PURE__ */ new Set();
|
|
32491
|
+
const all = /* @__PURE__ */ new Set();
|
|
32492
|
+
const add = (w) => {
|
|
32493
|
+
if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
|
|
32494
|
+
if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
|
|
32495
|
+
};
|
|
32496
|
+
let cur = "";
|
|
32497
|
+
for (const ch of prompt) {
|
|
32498
|
+
if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
|
|
32499
|
+
if (ch.trim() === "" || ch === "\0") {
|
|
32500
|
+
if (cur !== "") add(cur);
|
|
32501
|
+
cur = "";
|
|
32502
|
+
} else {
|
|
32503
|
+
cur += ch;
|
|
32504
|
+
}
|
|
32505
|
+
}
|
|
32506
|
+
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
32507
|
+
return [...kept.size > 0 ? kept : all].join(" ");
|
|
32346
32508
|
}
|
|
32347
32509
|
function queryUnits(db, sessionId, q, limit) {
|
|
32348
32510
|
const match = searchTerms(q).join(" OR ");
|
|
@@ -32354,7 +32516,7 @@ function queryUnits(db, sessionId, q, limit) {
|
|
|
32354
32516
|
}
|
|
32355
32517
|
|
|
32356
32518
|
// src/core/store/owners.ts
|
|
32357
|
-
import { mkdirSync as mkdirSync3, readdirSync, readFileSync as
|
|
32519
|
+
import { mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync } from "node:fs";
|
|
32358
32520
|
import { basename as basename3, join as join4 } from "node:path";
|
|
32359
32521
|
function ownersDir(configDir, projectKey) {
|
|
32360
32522
|
return join4(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -32387,7 +32549,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
32387
32549
|
const dir = ownersDir(configDir, projectKey);
|
|
32388
32550
|
let names;
|
|
32389
32551
|
try {
|
|
32390
|
-
names =
|
|
32552
|
+
names = readdirSync2(dir);
|
|
32391
32553
|
} catch (err) {
|
|
32392
32554
|
if (errCode(err) === "ENOENT") return [];
|
|
32393
32555
|
throw err;
|
|
@@ -32398,7 +32560,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
32398
32560
|
const file2 = join4(dir, name);
|
|
32399
32561
|
let text;
|
|
32400
32562
|
try {
|
|
32401
|
-
text =
|
|
32563
|
+
text = readFileSync3(file2, "utf8");
|
|
32402
32564
|
} catch (err) {
|
|
32403
32565
|
if (errCode(err) === "ENOENT") continue;
|
|
32404
32566
|
throw err;
|
|
@@ -32445,7 +32607,7 @@ function userVersion(raw) {
|
|
|
32445
32607
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
32446
32608
|
}
|
|
32447
32609
|
function openForSweep(dbPath, projectKey) {
|
|
32448
|
-
if (!
|
|
32610
|
+
if (!existsSync4(dbPath) && (existsSync4(dbPath + DB_WAL_SUFFIX) || existsSync4(dbPath + DB_SHM_SUFFIX))) {
|
|
32449
32611
|
throw new CtxError("DB_GONE");
|
|
32450
32612
|
}
|
|
32451
32613
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -32480,7 +32642,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
32480
32642
|
function sweepDeadProjects(configDir) {
|
|
32481
32643
|
let entries;
|
|
32482
32644
|
try {
|
|
32483
|
-
entries =
|
|
32645
|
+
entries = readdirSync3(join5(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
32484
32646
|
} catch (err) {
|
|
32485
32647
|
if (err.code === "ENOENT") return [];
|
|
32486
32648
|
throw err;
|
|
@@ -43929,7 +44091,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43929
44091
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43930
44092
|
return { end: start + r.read, written: r.written };
|
|
43931
44093
|
}
|
|
43932
|
-
function merge4(src, blocks,
|
|
44094
|
+
function merge4(src, blocks, join24, cap, lineCut) {
|
|
43933
44095
|
const out = [];
|
|
43934
44096
|
const scratch = new Uint8Array(cap);
|
|
43935
44097
|
let wide;
|
|
@@ -43939,7 +44101,7 @@ function merge4(src, blocks, join23, cap, lineCut) {
|
|
|
43939
44101
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43940
44102
|
};
|
|
43941
44103
|
for (const b of blocks) {
|
|
43942
|
-
if (cur !== void 0 && !
|
|
44104
|
+
if (cur !== void 0 && !join24) {
|
|
43943
44105
|
emit(cur.start, cur.end, curBytes);
|
|
43944
44106
|
cur = void 0;
|
|
43945
44107
|
}
|
|
@@ -44114,11 +44276,11 @@ function noRuntimeError(lang) {
|
|
|
44114
44276
|
}
|
|
44115
44277
|
|
|
44116
44278
|
// src/core/sandbox/spawn.ts
|
|
44117
|
-
import { spawn } from "node:child_process";
|
|
44279
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
44118
44280
|
import path2 from "node:path";
|
|
44119
44281
|
|
|
44120
44282
|
// src/core/sandbox/kill.ts
|
|
44121
|
-
import {
|
|
44283
|
+
import { spawn } from "node:child_process";
|
|
44122
44284
|
function signalGroup(pid, signal) {
|
|
44123
44285
|
try {
|
|
44124
44286
|
process.kill(-pid, signal);
|
|
@@ -44132,7 +44294,10 @@ function killTree(pid) {
|
|
|
44132
44294
|
return;
|
|
44133
44295
|
}
|
|
44134
44296
|
try {
|
|
44135
|
-
|
|
44297
|
+
const t = spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
|
|
44298
|
+
t.on("error", () => {
|
|
44299
|
+
});
|
|
44300
|
+
t.unref();
|
|
44136
44301
|
} catch {
|
|
44137
44302
|
}
|
|
44138
44303
|
}
|
|
@@ -44151,7 +44316,7 @@ function runProcess(argv, o) {
|
|
|
44151
44316
|
if (start === null) return resolve7(NOT_STARTED);
|
|
44152
44317
|
let child;
|
|
44153
44318
|
try {
|
|
44154
|
-
child =
|
|
44319
|
+
child = spawn2(start[0], start.slice(1), {
|
|
44155
44320
|
cwd: o.cwd,
|
|
44156
44321
|
env: o.env,
|
|
44157
44322
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -44168,8 +44333,14 @@ function runProcess(argv, o) {
|
|
|
44168
44333
|
const stderrChunks = [];
|
|
44169
44334
|
let killedBy = null;
|
|
44170
44335
|
let settled = false;
|
|
44336
|
+
let held = false;
|
|
44337
|
+
let exited = false;
|
|
44338
|
+
let graceTimer;
|
|
44339
|
+
let drainTimer;
|
|
44340
|
+
let stopTimer;
|
|
44171
44341
|
const kill = () => {
|
|
44172
44342
|
if (child.pid !== void 0) killTree(child.pid);
|
|
44343
|
+
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
|
|
44173
44344
|
};
|
|
44174
44345
|
const onAbort = () => {
|
|
44175
44346
|
if (killedBy !== null || settled) return;
|
|
@@ -44186,17 +44357,46 @@ function runProcess(argv, o) {
|
|
|
44186
44357
|
if (settled) return;
|
|
44187
44358
|
settled = true;
|
|
44188
44359
|
clearTimeout(timer);
|
|
44360
|
+
clearTimeout(graceTimer);
|
|
44361
|
+
clearTimeout(drainTimer);
|
|
44362
|
+
clearTimeout(stopTimer);
|
|
44189
44363
|
o.signal.removeEventListener("abort", onAbort);
|
|
44190
44364
|
resolve7({
|
|
44191
44365
|
stdout: Buffer.concat(stdoutChunks),
|
|
44192
44366
|
stderr: Buffer.concat(stderrChunks),
|
|
44193
44367
|
exitCode,
|
|
44194
|
-
killed: killedBy
|
|
44368
|
+
killed: killedBy,
|
|
44369
|
+
...held ? { held: true } : {}
|
|
44195
44370
|
});
|
|
44196
44371
|
};
|
|
44197
|
-
|
|
44198
|
-
|
|
44372
|
+
const finishHeld = () => {
|
|
44373
|
+
if (settled) return;
|
|
44374
|
+
held = exited && killedBy === null;
|
|
44375
|
+
child.stdout.destroy();
|
|
44376
|
+
child.stderr.destroy();
|
|
44377
|
+
if (child.pid !== void 0) killTree(child.pid);
|
|
44378
|
+
settle3(child.exitCode);
|
|
44379
|
+
};
|
|
44380
|
+
const bump = () => {
|
|
44381
|
+
if (!exited || settled) return;
|
|
44382
|
+
clearTimeout(graceTimer);
|
|
44383
|
+
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
44384
|
+
};
|
|
44385
|
+
child.stdout.on("data", (chunk) => {
|
|
44386
|
+
stdoutChunks.push(chunk);
|
|
44387
|
+
bump();
|
|
44388
|
+
});
|
|
44389
|
+
child.stderr.on("data", (chunk) => {
|
|
44390
|
+
stderrChunks.push(chunk);
|
|
44391
|
+
bump();
|
|
44392
|
+
});
|
|
44199
44393
|
child.on("close", (code) => settle3(code));
|
|
44394
|
+
child.on("exit", () => {
|
|
44395
|
+
if (settled) return;
|
|
44396
|
+
exited = true;
|
|
44397
|
+
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
44398
|
+
drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
|
|
44399
|
+
});
|
|
44200
44400
|
child.on("error", () => settle3(null));
|
|
44201
44401
|
child.stdin.on("error", () => {
|
|
44202
44402
|
});
|
|
@@ -44208,7 +44408,7 @@ function runProcess(argv, o) {
|
|
|
44208
44408
|
}
|
|
44209
44409
|
|
|
44210
44410
|
// src/core/index/auto-memory.ts
|
|
44211
|
-
import { readdirSync as
|
|
44411
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
44212
44412
|
import { join as join6 } from "node:path";
|
|
44213
44413
|
var MEMORY_FILES = Object.freeze([
|
|
44214
44414
|
Object.freeze(["CLAUDE.md"]),
|
|
@@ -44223,7 +44423,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
44223
44423
|
var MD = ".md";
|
|
44224
44424
|
function steeringFiles(worktree) {
|
|
44225
44425
|
try {
|
|
44226
|
-
return
|
|
44426
|
+
return readdirSync4(join6(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
44227
44427
|
} catch {
|
|
44228
44428
|
return [];
|
|
44229
44429
|
}
|
|
@@ -44243,7 +44443,7 @@ function readAutoMemory(project) {
|
|
|
44243
44443
|
sourceId: null,
|
|
44244
44444
|
path: path8,
|
|
44245
44445
|
label: segs.join("/"),
|
|
44246
|
-
text:
|
|
44446
|
+
text: readFileSync4(path8, "utf8")
|
|
44247
44447
|
});
|
|
44248
44448
|
} catch {
|
|
44249
44449
|
}
|
|
@@ -44867,8 +45067,8 @@ var ctxBatch = Object.freeze({
|
|
|
44867
45067
|
});
|
|
44868
45068
|
|
|
44869
45069
|
// src/core/tools/doctor.ts
|
|
44870
|
-
import { readdirSync as
|
|
44871
|
-
import { basename as basename5, join as
|
|
45070
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync13, existsSync as existsSync17 } from "node:fs";
|
|
45071
|
+
import { basename as basename5, join as join17 } from "node:path";
|
|
44872
45072
|
|
|
44873
45073
|
// src/adapters/claude-code.ts
|
|
44874
45074
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -45897,15 +46097,15 @@ function getAdapter(id) {
|
|
|
45897
46097
|
}
|
|
45898
46098
|
|
|
45899
46099
|
// src/core/ops/bundle-dir.ts
|
|
45900
|
-
import { existsSync as
|
|
46100
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
45901
46101
|
import { dirname as dirname4, join as join7 } from "node:path";
|
|
45902
46102
|
import { fileURLToPath } from "node:url";
|
|
45903
46103
|
function bundleDirOf(argv1, moduleFile) {
|
|
45904
46104
|
const own4 = dirname4(argv1);
|
|
45905
|
-
if (
|
|
46105
|
+
if (existsSync5(join7(own4, SERVER_ENTRY_FILE))) return own4;
|
|
45906
46106
|
let dir = dirname4(moduleFile);
|
|
45907
46107
|
for (; ; ) {
|
|
45908
|
-
if (
|
|
46108
|
+
if (existsSync5(join7(dir, SERVER_ENTRY_FILE))) return dir;
|
|
45909
46109
|
const up = dirname4(dir);
|
|
45910
46110
|
if (up === dir) return own4;
|
|
45911
46111
|
dir = up;
|
|
@@ -45919,16 +46119,39 @@ function ownBundleDir() {
|
|
|
45919
46119
|
}
|
|
45920
46120
|
|
|
45921
46121
|
// src/core/ops/doctor-config.ts
|
|
45922
|
-
import { existsSync as
|
|
45923
|
-
import { join as join11 } from "node:path";
|
|
46122
|
+
import { existsSync as existsSync10, readdirSync as readdirSync7, readFileSync as readFileSync9 } from "node:fs";
|
|
46123
|
+
import { dirname as dirname7, join as join11 } from "node:path";
|
|
46124
|
+
|
|
46125
|
+
// src/core/ops/host-text.ts
|
|
46126
|
+
var BOM_CODE = 65279;
|
|
46127
|
+
var CR_CODE = 13;
|
|
46128
|
+
var CRLF = "\r\n";
|
|
46129
|
+
var LF = "\n";
|
|
46130
|
+
function hostLayout(raw) {
|
|
46131
|
+
let crlf = 0;
|
|
46132
|
+
let lf = 0;
|
|
46133
|
+
for (let i = raw.indexOf(LF); i >= 0; i = raw.indexOf(LF, i + 1)) {
|
|
46134
|
+
if (i > 0 && raw.charCodeAt(i - 1) === CR_CODE) crlf += 1;
|
|
46135
|
+
else lf += 1;
|
|
46136
|
+
}
|
|
46137
|
+
return { bom: raw.length > 0 && raw.charCodeAt(0) === BOM_CODE, crlf: crlf > 0 && crlf >= lf };
|
|
46138
|
+
}
|
|
46139
|
+
function hostText(raw) {
|
|
46140
|
+
const bare2 = raw.length > 0 && raw.charCodeAt(0) === BOM_CODE ? raw.slice(1) : raw;
|
|
46141
|
+
return bare2.indexOf(CRLF) < 0 ? bare2 : bare2.split(CRLF).join(LF);
|
|
46142
|
+
}
|
|
46143
|
+
function withLayout(text, layout) {
|
|
46144
|
+
const eol = layout.crlf ? text.split(LF).join(CRLF) : text;
|
|
46145
|
+
return layout.bom ? String.fromCharCode(BOM_CODE) + eol : eol;
|
|
46146
|
+
}
|
|
45924
46147
|
|
|
45925
46148
|
// src/core/ops/detect-v1.ts
|
|
45926
|
-
import { existsSync as
|
|
46149
|
+
import { existsSync as existsSync7, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync6 } from "node:fs";
|
|
45927
46150
|
import { tmpdir } from "node:os";
|
|
45928
46151
|
import { join as join9 } from "node:path";
|
|
45929
46152
|
|
|
45930
46153
|
// src/core/ops/host-config.ts
|
|
45931
|
-
import { existsSync as
|
|
46154
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
45932
46155
|
import { dirname as dirname5, join as join8 } from "node:path";
|
|
45933
46156
|
|
|
45934
46157
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
@@ -48037,29 +48260,6 @@ function atomicWriteFile(file2, text, opts = {}) {
|
|
|
48037
48260
|
}
|
|
48038
48261
|
}
|
|
48039
48262
|
|
|
48040
|
-
// src/core/ops/host-text.ts
|
|
48041
|
-
var BOM_CODE = 65279;
|
|
48042
|
-
var CR_CODE = 13;
|
|
48043
|
-
var CRLF = "\r\n";
|
|
48044
|
-
var LF = "\n";
|
|
48045
|
-
function hostLayout(raw) {
|
|
48046
|
-
let crlf = 0;
|
|
48047
|
-
let lf = 0;
|
|
48048
|
-
for (let i = raw.indexOf(LF); i >= 0; i = raw.indexOf(LF, i + 1)) {
|
|
48049
|
-
if (i > 0 && raw.charCodeAt(i - 1) === CR_CODE) crlf += 1;
|
|
48050
|
-
else lf += 1;
|
|
48051
|
-
}
|
|
48052
|
-
return { bom: raw.length > 0 && raw.charCodeAt(0) === BOM_CODE, crlf: crlf > 0 && crlf >= lf };
|
|
48053
|
-
}
|
|
48054
|
-
function hostText(raw) {
|
|
48055
|
-
const bare2 = raw.length > 0 && raw.charCodeAt(0) === BOM_CODE ? raw.slice(1) : raw;
|
|
48056
|
-
return bare2.indexOf(CRLF) < 0 ? bare2 : bare2.split(CRLF).join(LF);
|
|
48057
|
-
}
|
|
48058
|
-
function withLayout(text, layout) {
|
|
48059
|
-
const eol = layout.crlf ? text.split(LF).join(CRLF) : text;
|
|
48060
|
-
return layout.bom ? String.fromCharCode(BOM_CODE) + eol : eol;
|
|
48061
|
-
}
|
|
48062
|
-
|
|
48063
48263
|
// src/core/ops/host-config.ts
|
|
48064
48264
|
function formatOf(path8) {
|
|
48065
48265
|
if (path8.endsWith(JSONC_EXT)) return "jsonc";
|
|
@@ -48070,9 +48270,9 @@ function readHostConfig(agent, path8) {
|
|
|
48070
48270
|
let file2 = path8;
|
|
48071
48271
|
if (agent === "opencode") {
|
|
48072
48272
|
const jsonc = join8(dirname5(path8), OPENCODE_CONFIG_FILES[0]);
|
|
48073
|
-
if (
|
|
48273
|
+
if (existsSync6(jsonc)) file2 = jsonc;
|
|
48074
48274
|
}
|
|
48075
|
-
const raw =
|
|
48275
|
+
const raw = existsSync6(file2) ? readFileSync5(file2, "utf8") : "";
|
|
48076
48276
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
48077
48277
|
}
|
|
48078
48278
|
function stripJsonComments(text) {
|
|
@@ -48544,14 +48744,14 @@ function stripJsonc(text) {
|
|
|
48544
48744
|
}
|
|
48545
48745
|
function readJson(file2) {
|
|
48546
48746
|
try {
|
|
48547
|
-
return JSON.parse(stripJsonc(hostText(
|
|
48747
|
+
return JSON.parse(stripJsonc(hostText(readFileSync6(file2, "utf8"))));
|
|
48548
48748
|
} catch {
|
|
48549
48749
|
return void 0;
|
|
48550
48750
|
}
|
|
48551
48751
|
}
|
|
48552
48752
|
function readText(file2) {
|
|
48553
48753
|
try {
|
|
48554
|
-
return hostText(
|
|
48754
|
+
return hostText(readFileSync6(file2, "utf8"));
|
|
48555
48755
|
} catch {
|
|
48556
48756
|
return "";
|
|
48557
48757
|
}
|
|
@@ -48608,7 +48808,7 @@ function flatCommands(events, prefix) {
|
|
|
48608
48808
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
48609
48809
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
48610
48810
|
function dataDir(dir, reason, out) {
|
|
48611
|
-
if (
|
|
48811
|
+
if (existsSync7(dir)) out.push(finding(dir, "", reason));
|
|
48612
48812
|
}
|
|
48613
48813
|
function mcpEntry(file2, doc, out) {
|
|
48614
48814
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -48637,7 +48837,7 @@ function scanClaudeCode(home, agentHome, out) {
|
|
|
48637
48837
|
claudeShapeSettings(agentHome, out);
|
|
48638
48838
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
48639
48839
|
const file2 = join9(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
48640
|
-
if (
|
|
48840
|
+
if (existsSync7(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
48641
48841
|
}
|
|
48642
48842
|
const userFile = join9(home, CLAUDE_USER_CONFIG_FILE);
|
|
48643
48843
|
mcpEntry(userFile, readJson(userFile), out);
|
|
@@ -48655,6 +48855,7 @@ function scanCodex(agentHome, out) {
|
|
|
48655
48855
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
48656
48856
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
48657
48857
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
48858
|
+
if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config4, span2.path.slice(0, 2)))) continue;
|
|
48658
48859
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
48659
48860
|
}
|
|
48660
48861
|
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
@@ -48683,7 +48884,7 @@ function scanVscode(agentHome, project, out) {
|
|
|
48683
48884
|
}
|
|
48684
48885
|
function jsonFiles(dir) {
|
|
48685
48886
|
try {
|
|
48686
|
-
return
|
|
48887
|
+
return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
48687
48888
|
} catch {
|
|
48688
48889
|
return [];
|
|
48689
48890
|
}
|
|
@@ -48706,7 +48907,7 @@ function scanKiro(agentHome, project, out) {
|
|
|
48706
48907
|
const steeringDocs = [join9(agentHome, ...KIRO_STEERING_FILE)];
|
|
48707
48908
|
if (project !== void 0) steeringDocs.push(join9(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
48708
48909
|
for (const file2 of steeringDocs) {
|
|
48709
|
-
if (
|
|
48910
|
+
if (existsSync7(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
48710
48911
|
}
|
|
48711
48912
|
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48712
48913
|
}
|
|
@@ -48816,7 +49017,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48816
49017
|
}
|
|
48817
49018
|
|
|
48818
49019
|
// src/core/ops/plugin-root.ts
|
|
48819
|
-
import { existsSync as
|
|
49020
|
+
import { existsSync as existsSync8, readdirSync as readdirSync6, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
48820
49021
|
import { dirname as dirname6, isAbsolute, join as join10, sep as sep2 } from "node:path";
|
|
48821
49022
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
48822
49023
|
function missing(agent, path8) {
|
|
@@ -48858,7 +49059,7 @@ var realOrNull = (path8) => {
|
|
|
48858
49059
|
};
|
|
48859
49060
|
var readOrNull = (file2) => {
|
|
48860
49061
|
try {
|
|
48861
|
-
return
|
|
49062
|
+
return readFileSync7(file2, "utf8");
|
|
48862
49063
|
} catch {
|
|
48863
49064
|
return null;
|
|
48864
49065
|
}
|
|
@@ -48885,7 +49086,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
48885
49086
|
const record6 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
48886
49087
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
48887
49088
|
if (recorded.length === 0) return { record: false };
|
|
48888
|
-
const live = recorded.filter((r) =>
|
|
49089
|
+
const live = recorded.filter((r) => existsSync8(r.installPath));
|
|
48889
49090
|
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
48890
49091
|
if (mine !== void 0) return { root: mine.installPath };
|
|
48891
49092
|
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
@@ -48913,10 +49114,10 @@ function marketplaceRoot(adapter, env, worktree) {
|
|
|
48913
49114
|
if ("root" in choice) return choice.root;
|
|
48914
49115
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
48915
49116
|
const cacheReal = realOrNull(cache);
|
|
48916
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) &&
|
|
49117
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync8(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
48917
49118
|
const pattern = join10(cache, "*", PLUGIN_NAME);
|
|
48918
|
-
if (!
|
|
48919
|
-
const found =
|
|
49119
|
+
if (!existsSync8(cache)) throw missing(adapter.id, pattern);
|
|
49120
|
+
const found = readdirSync6(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync8(dir));
|
|
48920
49121
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
48921
49122
|
return found[0];
|
|
48922
49123
|
}
|
|
@@ -48924,7 +49125,7 @@ function configEntryRoot(adapter, env) {
|
|
|
48924
49125
|
const spec = OWN_MCP_ENTRY[adapter.id];
|
|
48925
49126
|
if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
|
|
48926
49127
|
const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
|
|
48927
|
-
if (!
|
|
49128
|
+
if (!existsSync8(file2)) throw missing(adapter.id, file2);
|
|
48928
49129
|
const current = readHostConfig(adapter.id, file2);
|
|
48929
49130
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
48930
49131
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
@@ -48958,7 +49159,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
48958
49159
|
}
|
|
48959
49160
|
|
|
48960
49161
|
// src/setup/pi-gate.ts
|
|
48961
|
-
import { existsSync as
|
|
49162
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
48962
49163
|
import path4 from "node:path";
|
|
48963
49164
|
var EXTENSIONS_KEY = "extensions";
|
|
48964
49165
|
var PROJECT_DIR = ".pi";
|
|
@@ -48966,9 +49167,9 @@ var TRUST_FILE = "trust.json";
|
|
|
48966
49167
|
var ALWAYS = "always";
|
|
48967
49168
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
48968
49169
|
function load(file2) {
|
|
48969
|
-
if (!
|
|
49170
|
+
if (!existsSync9(file2)) return void 0;
|
|
48970
49171
|
try {
|
|
48971
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
49172
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync8(file2, "utf8")), "json") };
|
|
48972
49173
|
} catch {
|
|
48973
49174
|
return void 0;
|
|
48974
49175
|
}
|
|
@@ -49126,14 +49327,14 @@ function codexNativeDir(env, home) {
|
|
|
49126
49327
|
}
|
|
49127
49328
|
if (enabled !== true) return null;
|
|
49128
49329
|
const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
49129
|
-
if (!
|
|
49330
|
+
if (!existsSync10(cache)) return null;
|
|
49130
49331
|
const found = [];
|
|
49131
|
-
for (const market of
|
|
49332
|
+
for (const market of readdirSync7(cache)) {
|
|
49132
49333
|
const plugin = join11(cache, market, SERVER_KEY);
|
|
49133
|
-
if (!
|
|
49134
|
-
for (const version4 of
|
|
49334
|
+
if (!existsSync10(plugin)) continue;
|
|
49335
|
+
for (const version4 of readdirSync7(plugin).sort()) {
|
|
49135
49336
|
const dir = join11(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
49136
|
-
if (
|
|
49337
|
+
if (existsSync10(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
49137
49338
|
}
|
|
49138
49339
|
}
|
|
49139
49340
|
return found.length === 0 ? null : found[found.length - 1];
|
|
@@ -49150,7 +49351,7 @@ function nativeMcpWrong(dir, row5) {
|
|
|
49150
49351
|
}
|
|
49151
49352
|
}
|
|
49152
49353
|
function isOwnOpencodeEntry(entry, key, own4) {
|
|
49153
|
-
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
|
|
49354
|
+
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : Array.isArray(entry) ? entry[0] : entry;
|
|
49154
49355
|
if (typeof spec !== "string") return false;
|
|
49155
49356
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own4.includes(spec)) return true;
|
|
49156
49357
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
@@ -49161,14 +49362,21 @@ function opencodeMcpOwn(entry) {
|
|
|
49161
49362
|
const [node3, script, flag, agent] = cmd;
|
|
49162
49363
|
return isNodeCommand(node3) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
49163
49364
|
}
|
|
49164
|
-
function
|
|
49165
|
-
|
|
49365
|
+
function opencodeFileValue(file2) {
|
|
49366
|
+
if (!existsSync10(file2)) return {};
|
|
49367
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync9(file2, "utf8")), "jsonc");
|
|
49368
|
+
}
|
|
49369
|
+
function opencodeValueListed(value) {
|
|
49166
49370
|
const bundle = opencodePluginFile();
|
|
49167
49371
|
const own4 = [bundle, join11(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
49168
49372
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)))) return true;
|
|
49169
49373
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
49170
49374
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
49171
49375
|
}
|
|
49376
|
+
function opencodeListed(file2, worktree) {
|
|
49377
|
+
const dirs = [dirname7(file2), worktree];
|
|
49378
|
+
return dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join11(dir, name)))));
|
|
49379
|
+
}
|
|
49172
49380
|
function mcpWrong(row5, home, env, worktree) {
|
|
49173
49381
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
49174
49382
|
if (native !== null) return nativeMcpWrong(native, row5);
|
|
@@ -49178,7 +49386,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
49178
49386
|
resolvePluginRoot(row5, env, worktree);
|
|
49179
49387
|
return false;
|
|
49180
49388
|
}
|
|
49181
|
-
if (row5.id === "opencode") return !opencodeListed(file2);
|
|
49389
|
+
if (row5.id === "opencode") return !opencodeListed(file2, worktree);
|
|
49182
49390
|
const cur = readHostConfig(row5.id, file2);
|
|
49183
49391
|
return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
|
|
49184
49392
|
} catch {
|
|
@@ -49296,7 +49504,7 @@ function configPaths(row5, env, worktree) {
|
|
|
49296
49504
|
}
|
|
49297
49505
|
|
|
49298
49506
|
// src/core/ops/doctor-db.ts
|
|
49299
|
-
import { existsSync as
|
|
49507
|
+
import { existsSync as existsSync11, statSync as statSync4 } from "node:fs";
|
|
49300
49508
|
var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
49301
49509
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
49302
49510
|
var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -49338,15 +49546,15 @@ function orphanFiles(dbPath) {
|
|
|
49338
49546
|
const files = [];
|
|
49339
49547
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
49340
49548
|
const path8 = dbPath + suffix;
|
|
49341
|
-
if (
|
|
49549
|
+
if (existsSync11(path8)) files.push({ path: path8, bytes: statSync4(path8).size });
|
|
49342
49550
|
}
|
|
49343
|
-
return files.length > 0 && !
|
|
49551
|
+
return files.length > 0 && !existsSync11(dbPath) ? files : [];
|
|
49344
49552
|
}
|
|
49345
49553
|
async function checkDb(project) {
|
|
49346
49554
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
49347
49555
|
const orphan = orphanFiles(project.dbPath);
|
|
49348
49556
|
if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
49349
|
-
if (!
|
|
49557
|
+
if (!existsSync11(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
49350
49558
|
const sqlite = await loadSqlite2();
|
|
49351
49559
|
if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
|
|
49352
49560
|
let raw = null;
|
|
@@ -49372,7 +49580,7 @@ async function checkDb(project) {
|
|
|
49372
49580
|
}
|
|
49373
49581
|
}
|
|
49374
49582
|
async function checkIndex(project) {
|
|
49375
|
-
if (!
|
|
49583
|
+
if (!existsSync11(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
49376
49584
|
const sqlite = await loadSqlite2();
|
|
49377
49585
|
if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
|
|
49378
49586
|
let raw = null;
|
|
@@ -49389,7 +49597,7 @@ async function checkIndex(project) {
|
|
|
49389
49597
|
}
|
|
49390
49598
|
|
|
49391
49599
|
// src/core/ops/doctor-env.ts
|
|
49392
|
-
import { existsSync as
|
|
49600
|
+
import { existsSync as existsSync12, readFileSync as readFileSync10, realpathSync as realpathSync6 } from "node:fs";
|
|
49393
49601
|
import { isAbsolute as isAbsolute2, join as join12, relative as relative2 } from "node:path";
|
|
49394
49602
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
49395
49603
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
@@ -49400,9 +49608,12 @@ function unknown5(id, detail, fixCommand) {
|
|
|
49400
49608
|
function fail3(id, detail, fixCommand) {
|
|
49401
49609
|
return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
|
|
49402
49610
|
}
|
|
49611
|
+
function warn(id, detail, fixCommand) {
|
|
49612
|
+
return { id, label: DOCTOR_LABEL[id], status: "WARN", detail, fixCommand };
|
|
49613
|
+
}
|
|
49403
49614
|
function bundleVersion(bundleDir2) {
|
|
49404
49615
|
try {
|
|
49405
|
-
const v = JSON.parse(
|
|
49616
|
+
const v = JSON.parse(readFileSync10(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
49406
49617
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
49407
49618
|
} catch {
|
|
49408
49619
|
return void 0;
|
|
@@ -49486,20 +49697,21 @@ function highestTag(stdout, tag) {
|
|
|
49486
49697
|
}
|
|
49487
49698
|
return best;
|
|
49488
49699
|
}
|
|
49489
|
-
function versionRow(head, installed, tag, source, latest, tail) {
|
|
49700
|
+
function versionRow(head, installed, tag, source, latest, tail, update) {
|
|
49490
49701
|
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
49491
49702
|
if (cmp === 0) return pass3("D1", head + D1_LATEST_PASS(tag, source) + tail);
|
|
49492
49703
|
if (cmp > 0) return pass3("D1", head + D1_LATEST_AHEAD(tag, source, latest) + tail);
|
|
49493
|
-
return
|
|
49704
|
+
return warn("D1", head + D1_LATEST_UPDATE(tag, source, latest) + tail, update);
|
|
49494
49705
|
}
|
|
49495
49706
|
async function checkVersion(i) {
|
|
49496
49707
|
if (i.bundleSha === void 0) return unknown5("D1", D1_DEV_BUILD_DETAIL);
|
|
49497
49708
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
49498
49709
|
if (i.version === void 0) return unknown5("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
49499
49710
|
const tag = channelOf(i.version);
|
|
49711
|
+
const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
|
|
49500
49712
|
const git2 = findRuntime(GIT_BIN, i.env);
|
|
49501
49713
|
const npm = await npmLatest(i.registryUrl, tag, i.signal, i.timeoutMs);
|
|
49502
|
-
if (npm.ok) return versionRow(head, i.version, tag, D1_SOURCE_NPM, npm.version, "");
|
|
49714
|
+
if (npm.ok) return versionRow(head, i.version, tag, D1_SOURCE_NPM, npm.version, "", update);
|
|
49503
49715
|
let cause = D1_GIT_MISSING;
|
|
49504
49716
|
if (git2 !== null) {
|
|
49505
49717
|
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
@@ -49510,7 +49722,7 @@ async function checkVersion(i) {
|
|
|
49510
49722
|
});
|
|
49511
49723
|
if (r.exitCode === 0 && r.killed === null) {
|
|
49512
49724
|
const latest = highestTag(r.stdout.toString("utf8"), tag);
|
|
49513
|
-
if (latest !== void 0) return versionRow(head, i.version, tag, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
|
|
49725
|
+
if (latest !== void 0) return versionRow(head, i.version, tag, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
|
|
49514
49726
|
cause = D1_GIT_NO_TAG(tag);
|
|
49515
49727
|
} else {
|
|
49516
49728
|
cause = gitCause(r, i.timeoutMs);
|
|
@@ -49546,13 +49758,14 @@ async function checkNode(i) {
|
|
|
49546
49758
|
if (!await sqliteLoads()) return fail3("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
|
|
49547
49759
|
return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
49548
49760
|
}
|
|
49549
|
-
function checkMcp(ctx) {
|
|
49761
|
+
function checkMcp(ctx, adapter) {
|
|
49550
49762
|
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
49551
49763
|
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
49552
|
-
|
|
49764
|
+
if (named2 || versioned) return pass3("D6");
|
|
49765
|
+
return adapter?.installMode === "in-process" ? pass3("D6", D6_IN_PROCESS_DETAIL) : unknown5("D6", D6_UNKNOWN_DETAIL);
|
|
49553
49766
|
}
|
|
49554
49767
|
function piCwdInside(worktree, piCwd) {
|
|
49555
|
-
if (piCwd === void 0 || !
|
|
49768
|
+
if (piCwd === void 0 || !existsSync12(piCwd)) return false;
|
|
49556
49769
|
const rel = relative2(worktree, realpathSync6.native(piCwd));
|
|
49557
49770
|
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
49558
49771
|
}
|
|
@@ -49562,7 +49775,9 @@ function checkProject(i) {
|
|
|
49562
49775
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
49563
49776
|
return pass3("D7");
|
|
49564
49777
|
}
|
|
49565
|
-
function checkMode(adapter) {
|
|
49778
|
+
function checkMode(adapter, hostPermission) {
|
|
49779
|
+
if (hostPermission === "missing") return fail3("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
49780
|
+
if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
49566
49781
|
return pass3("D10", D10_DETAIL(adapter.denyChannel));
|
|
49567
49782
|
}
|
|
49568
49783
|
function checkShell(env) {
|
|
@@ -49573,7 +49788,7 @@ function checkShell(env) {
|
|
|
49573
49788
|
}
|
|
49574
49789
|
|
|
49575
49790
|
// src/core/ops/doctor-hook.ts
|
|
49576
|
-
import { existsSync as
|
|
49791
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync11, realpathSync as realpathSync8, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49577
49792
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49578
49793
|
import path7 from "node:path";
|
|
49579
49794
|
|
|
@@ -51399,9 +51614,9 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
|
|
|
51399
51614
|
|
|
51400
51615
|
// src/setup/codex-trust.ts
|
|
51401
51616
|
import { createHash } from "node:crypto";
|
|
51402
|
-
import { existsSync as
|
|
51617
|
+
import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
|
|
51403
51618
|
import path6 from "node:path";
|
|
51404
|
-
import { spawn as
|
|
51619
|
+
import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
51405
51620
|
|
|
51406
51621
|
// src/setup/spawn-bin.ts
|
|
51407
51622
|
import { spawnSync } from "node:child_process";
|
|
@@ -51526,7 +51741,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
51526
51741
|
resolve7({ kind: "silent" });
|
|
51527
51742
|
return;
|
|
51528
51743
|
}
|
|
51529
|
-
const child =
|
|
51744
|
+
const child = spawn3(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
51530
51745
|
let buf = "";
|
|
51531
51746
|
let done = false;
|
|
51532
51747
|
let exited = false;
|
|
@@ -51622,10 +51837,10 @@ function isObject6(v) {
|
|
|
51622
51837
|
}
|
|
51623
51838
|
function loadFixture(bundleDir2, agent) {
|
|
51624
51839
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
51625
|
-
if (!
|
|
51840
|
+
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
51626
51841
|
let all;
|
|
51627
51842
|
try {
|
|
51628
|
-
all = JSON.parse(hostText(
|
|
51843
|
+
all = JSON.parse(hostText(readFileSync11(file2, "utf8")));
|
|
51629
51844
|
} catch (err) {
|
|
51630
51845
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
51631
51846
|
}
|
|
@@ -51738,6 +51953,35 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
51738
51953
|
rmSync4(home, { recursive: true, force: true });
|
|
51739
51954
|
}
|
|
51740
51955
|
}
|
|
51956
|
+
async function ownProbe(i, timeoutMs) {
|
|
51957
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
|
|
51958
|
+
try {
|
|
51959
|
+
const cfg = path7.join(home, ".claude");
|
|
51960
|
+
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
51961
|
+
mkdirSync5(refs, { recursive: true });
|
|
51962
|
+
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
51963
|
+
writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
51964
|
+
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
51965
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
51966
|
+
cwd: i.bundleDir,
|
|
51967
|
+
env: node3.env,
|
|
51968
|
+
signal: i.signal,
|
|
51969
|
+
timeoutMs,
|
|
51970
|
+
stdin: JSON.stringify({
|
|
51971
|
+
session_id: "d5-own-probe",
|
|
51972
|
+
transcript_path: "",
|
|
51973
|
+
cwd: home,
|
|
51974
|
+
hook_event_name: "PreToolUse",
|
|
51975
|
+
tool_name: "Read",
|
|
51976
|
+
tool_use_id: "toolu_d5_own_probe",
|
|
51977
|
+
tool_input: { file_path: filePath }
|
|
51978
|
+
})
|
|
51979
|
+
});
|
|
51980
|
+
return r.stdout.toString("utf8");
|
|
51981
|
+
} finally {
|
|
51982
|
+
rmSync4(home, { recursive: true, force: true });
|
|
51983
|
+
}
|
|
51984
|
+
}
|
|
51741
51985
|
function isDeny(stdout) {
|
|
51742
51986
|
if (stdout.trim() === "") return false;
|
|
51743
51987
|
let out;
|
|
@@ -51752,8 +51996,12 @@ async function readProbeDetail(i, timeoutMs) {
|
|
|
51752
51996
|
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
51753
51997
|
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
51754
51998
|
if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
|
|
51999
|
+
if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
|
|
51755
52000
|
return null;
|
|
51756
52001
|
}
|
|
52002
|
+
async function mediaProbeDetail(i, timeoutMs) {
|
|
52003
|
+
return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
|
|
52004
|
+
}
|
|
51757
52005
|
function codexHookJournaled(db) {
|
|
51758
52006
|
if (db === null) return false;
|
|
51759
52007
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -51806,7 +52054,7 @@ async function codexStopDetail(i, timeoutMs) {
|
|
|
51806
52054
|
timeoutMs,
|
|
51807
52055
|
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
51808
52056
|
});
|
|
51809
|
-
const logged =
|
|
52057
|
+
const logged = existsSync14(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
51810
52058
|
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
51811
52059
|
} finally {
|
|
51812
52060
|
rmSync4(home, { recursive: true, force: true });
|
|
@@ -51817,7 +52065,7 @@ async function checkHookRoundTrip(i) {
|
|
|
51817
52065
|
const trust = await codexPluginTrust(i);
|
|
51818
52066
|
if (trust !== null) return trust;
|
|
51819
52067
|
}
|
|
51820
|
-
if (i.agent === "codex" &&
|
|
52068
|
+
if (i.agent === "codex" && existsSync14(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
51821
52069
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
51822
52070
|
}
|
|
51823
52071
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -51853,18 +52101,21 @@ async function checkHookRoundTrip(i) {
|
|
|
51853
52101
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
51854
52102
|
}
|
|
51855
52103
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
51856
|
-
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
52104
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "zcode" ? await mediaProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
51857
52105
|
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
51858
52106
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
51859
52107
|
}
|
|
51860
52108
|
|
|
51861
52109
|
// src/core/hooks/fallback.ts
|
|
51862
|
-
import { join as
|
|
52110
|
+
import { join as join14, resolve as resolve4 } from "node:path";
|
|
51863
52111
|
|
|
51864
52112
|
// src/core/policy/read-media.ts
|
|
51865
52113
|
import { extname } from "node:path";
|
|
51866
52114
|
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
51867
52115
|
|
|
52116
|
+
// src/core/policy/own-file.ts
|
|
52117
|
+
import { extname as extname2, join as join13 } from "node:path";
|
|
52118
|
+
|
|
51868
52119
|
// src/core/hooks/fallback.ts
|
|
51869
52120
|
var fs = process.getBuiltinModule("node:fs");
|
|
51870
52121
|
function homeOf(env) {
|
|
@@ -51872,9 +52123,9 @@ function homeOf(env) {
|
|
|
51872
52123
|
}
|
|
51873
52124
|
function hookLogPath(env) {
|
|
51874
52125
|
const dir = env[DATA_DIR_ENV];
|
|
51875
|
-
if (dir !== void 0 && dir !== "") return
|
|
52126
|
+
if (dir !== void 0 && dir !== "") return join14(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
51876
52127
|
const home = homeOf(env);
|
|
51877
|
-
return home === "" ? "" :
|
|
52128
|
+
return home === "" ? "" : join14(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
51878
52129
|
}
|
|
51879
52130
|
function lastHookError(env) {
|
|
51880
52131
|
try {
|
|
@@ -51904,8 +52155,8 @@ function lastHookError(env) {
|
|
|
51904
52155
|
}
|
|
51905
52156
|
|
|
51906
52157
|
// src/core/ops/db-heal.ts
|
|
51907
|
-
import { existsSync as
|
|
51908
|
-
import { basename as basename4, dirname as
|
|
52158
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync5 } from "node:fs";
|
|
52159
|
+
import { basename as basename4, dirname as dirname8, join as join15 } from "node:path";
|
|
51909
52160
|
function integrityOk2(rows) {
|
|
51910
52161
|
return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
|
|
51911
52162
|
}
|
|
@@ -51939,7 +52190,7 @@ function renameAside(dbPath) {
|
|
|
51939
52190
|
const ts = String(Date.now());
|
|
51940
52191
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
51941
52192
|
const file2 = dbPath + suffix;
|
|
51942
|
-
if (
|
|
52193
|
+
if (existsSync15(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
51943
52194
|
}
|
|
51944
52195
|
return ts;
|
|
51945
52196
|
}
|
|
@@ -51962,11 +52213,11 @@ function utcStamp(now) {
|
|
|
51962
52213
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
51963
52214
|
}
|
|
51964
52215
|
function makeOrphanDir(projectDir) {
|
|
51965
|
-
const base =
|
|
52216
|
+
const base = join15(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
51966
52217
|
for (let n = 1; ; n += 1) {
|
|
51967
52218
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
51968
52219
|
try {
|
|
51969
|
-
|
|
52220
|
+
mkdirSync6(dir);
|
|
51970
52221
|
return dir;
|
|
51971
52222
|
} catch (err) {
|
|
51972
52223
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -51977,9 +52228,9 @@ async function healOrphan(project, files, row5) {
|
|
|
51977
52228
|
const moved = [];
|
|
51978
52229
|
let dir = "";
|
|
51979
52230
|
try {
|
|
51980
|
-
dir = makeOrphanDir(
|
|
52231
|
+
dir = makeOrphanDir(dirname8(project.dbPath));
|
|
51981
52232
|
for (const f of files) {
|
|
51982
|
-
const to =
|
|
52233
|
+
const to = join15(dir, basename4(f.path));
|
|
51983
52234
|
renameWithRetry(f.path, to);
|
|
51984
52235
|
moved.push({ path: to, bytes: f.bytes });
|
|
51985
52236
|
}
|
|
@@ -52044,10 +52295,41 @@ function buildReportHead(input) {
|
|
|
52044
52295
|
return lines.concat(tail).join("\n");
|
|
52045
52296
|
}
|
|
52046
52297
|
|
|
52298
|
+
// src/core/ops/unsupported-host.ts
|
|
52299
|
+
var SUPPORTED_AGENTS_LINE = `Supported agents: ${AGENT_IDS.join(", ")} (${SUPPORTED_AGENTS_DOCS_URL}).`;
|
|
52300
|
+
function UNSUPPORTED_HOST_LINE(name) {
|
|
52301
|
+
return `${name} is not a supported host today. The MCP server runs here; hooks are not checked. ${SUPPORTED_AGENTS_LINE}`;
|
|
52302
|
+
}
|
|
52303
|
+
function segmentsOf(dir) {
|
|
52304
|
+
let parts = [dir];
|
|
52305
|
+
for (const sep3 of V1_PATH_SEPS) parts = parts.flatMap((p) => p.split(sep3));
|
|
52306
|
+
return parts;
|
|
52307
|
+
}
|
|
52308
|
+
function hasRun(parts, run) {
|
|
52309
|
+
for (let i = 0; i + run.length <= parts.length; i++) if (run.every((seg, k) => parts[i + k] === seg)) return true;
|
|
52310
|
+
return false;
|
|
52311
|
+
}
|
|
52312
|
+
function unsupportedHostOf(sig) {
|
|
52313
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") {
|
|
52314
|
+
const n = sig.clientName.toLowerCase();
|
|
52315
|
+
const hit = UNSUPPORTED_HOSTS.find((h) => h.clientNames.includes(n));
|
|
52316
|
+
if (hit !== void 0) return hit;
|
|
52317
|
+
}
|
|
52318
|
+
if (sig.bundleDir !== void 0) {
|
|
52319
|
+
const parts = segmentsOf(sig.bundleDir);
|
|
52320
|
+
const hit = UNSUPPORTED_HOSTS.find((h) => h.pluginPaths.some((p) => hasRun(parts, p)));
|
|
52321
|
+
if (hit !== void 0) return hit;
|
|
52322
|
+
}
|
|
52323
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") return void 0;
|
|
52324
|
+
const env = sig.env;
|
|
52325
|
+
if (env === void 0) return void 0;
|
|
52326
|
+
return UNSUPPORTED_HOSTS.find((h) => h.envVars.some((v) => env[v] !== void 0 && env[v] !== ""));
|
|
52327
|
+
}
|
|
52328
|
+
|
|
52047
52329
|
// src/core/ops/doctor-issue.ts
|
|
52048
52330
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
52049
|
-
import { closeSync as closeSync2, existsSync as
|
|
52050
|
-
import { delimiter, join as
|
|
52331
|
+
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync12, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
|
|
52332
|
+
import { delimiter, join as join16 } from "node:path";
|
|
52051
52333
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
52052
52334
|
function tildeOf(env) {
|
|
52053
52335
|
const home = homeDirOf(env);
|
|
@@ -52088,8 +52370,8 @@ function onPath(env, tool) {
|
|
|
52088
52370
|
const out = [];
|
|
52089
52371
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
52090
52372
|
if (dir === "") continue;
|
|
52091
|
-
for (const n of names) if (
|
|
52092
|
-
out.push(
|
|
52373
|
+
for (const n of names) if (existsSync16(join16(dir, n))) {
|
|
52374
|
+
out.push(join16(dir, n));
|
|
52093
52375
|
break;
|
|
52094
52376
|
}
|
|
52095
52377
|
}
|
|
@@ -52097,7 +52379,7 @@ function onPath(env, tool) {
|
|
|
52097
52379
|
}
|
|
52098
52380
|
function hookLogTail(env) {
|
|
52099
52381
|
const file2 = hookLogPath(env);
|
|
52100
|
-
if (file2 === "" || !
|
|
52382
|
+
if (file2 === "" || !existsSync16(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
52101
52383
|
try {
|
|
52102
52384
|
const fd = openSync2(file2, "r");
|
|
52103
52385
|
try {
|
|
@@ -52117,7 +52399,7 @@ function hookLogTail(env) {
|
|
|
52117
52399
|
}
|
|
52118
52400
|
async function journalRows(ctx) {
|
|
52119
52401
|
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
52120
|
-
if (!
|
|
52402
|
+
if (!existsSync16(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
52121
52403
|
try {
|
|
52122
52404
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
52123
52405
|
try {
|
|
@@ -52135,21 +52417,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
52135
52417
|
const home = homeDirOf(env);
|
|
52136
52418
|
const files = configPaths(adapter, env, worktree);
|
|
52137
52419
|
if (home !== null) {
|
|
52138
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
52139
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
52420
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join16(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
52421
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join16(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
52140
52422
|
}
|
|
52141
52423
|
const out = [];
|
|
52142
52424
|
const seen = /* @__PURE__ */ new Set();
|
|
52143
52425
|
for (const f of files) {
|
|
52144
52426
|
if (seen.has(f.path)) continue;
|
|
52145
52427
|
seen.add(f.path);
|
|
52146
|
-
if (!
|
|
52428
|
+
if (!existsSync16(f.path)) {
|
|
52147
52429
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
52148
52430
|
continue;
|
|
52149
52431
|
}
|
|
52150
52432
|
let text = "";
|
|
52151
52433
|
try {
|
|
52152
|
-
text =
|
|
52434
|
+
text = readFileSync12(f.path, "utf8");
|
|
52153
52435
|
} catch (err) {
|
|
52154
52436
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
52155
52437
|
continue;
|
|
@@ -52163,12 +52445,13 @@ function agentConfig(adapter, env, worktree) {
|
|
|
52163
52445
|
function failing(rows) {
|
|
52164
52446
|
return rows.filter((r) => r.status === "FAIL");
|
|
52165
52447
|
}
|
|
52166
|
-
function issueTitle(agent, rows) {
|
|
52167
|
-
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
52448
|
+
function issueTitle(agent, rows, other) {
|
|
52449
|
+
return `ctx_doctor ${agent}${other === void 0 ? "" : ` (${other.name} is not a supported host today)`}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
52168
52450
|
}
|
|
52169
|
-
function summaryOf(agent, rows) {
|
|
52451
|
+
function summaryOf(agent, rows, other) {
|
|
52170
52452
|
const f = failing(rows)[0];
|
|
52171
|
-
|
|
52453
|
+
const tag = other === void 0 ? "" : `${other.name} is not a supported host today. `;
|
|
52454
|
+
return tag + (f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`);
|
|
52172
52455
|
}
|
|
52173
52456
|
async function buildIssueBody(i) {
|
|
52174
52457
|
const tilde = tildeOf(i.env);
|
|
@@ -52178,7 +52461,7 @@ async function buildIssueBody(i) {
|
|
|
52178
52461
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
52179
52462
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
52180
52463
|
const sections = {
|
|
52181
|
-
"Summary": [summaryOf(agent, i.rows)],
|
|
52464
|
+
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
52182
52465
|
"ctx-report": [i.table],
|
|
52183
52466
|
"What happened": [
|
|
52184
52467
|
"Rows that need a look:",
|
|
@@ -52219,14 +52502,14 @@ async function buildIssueBody(i) {
|
|
|
52219
52502
|
async function writeIssueReport(i) {
|
|
52220
52503
|
const tilde = tildeOf(i.env);
|
|
52221
52504
|
const body = await buildIssueBody(i);
|
|
52222
|
-
const dir =
|
|
52223
|
-
|
|
52224
|
-
const file2 =
|
|
52505
|
+
const dir = join16(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
52506
|
+
mkdirSync7(dir, { recursive: true });
|
|
52507
|
+
const file2 = join16(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
52225
52508
|
writeFileSync4(file2, body);
|
|
52226
52509
|
const shown2 = tilde(file2);
|
|
52227
|
-
const title = issueTitle(i.adapter.id, i.rows);
|
|
52510
|
+
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
52228
52511
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
52229
|
-
return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows)), DOCTOR_RULES_LINE + ISSUE_GUIDE_URL];
|
|
52512
|
+
return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows, i.unsupported)), DOCTOR_RULES_LINE + ISSUE_GUIDE_URL];
|
|
52230
52513
|
}
|
|
52231
52514
|
function formUrl(title, summary) {
|
|
52232
52515
|
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
@@ -52267,13 +52550,19 @@ async function guard(id, run) {
|
|
|
52267
52550
|
}
|
|
52268
52551
|
}
|
|
52269
52552
|
async function codexDb(ctx, adapter) {
|
|
52270
|
-
if (adapter.id !== "codex" || !
|
|
52553
|
+
if (adapter.id !== "codex" || !existsSync17(ctx.project.dbPath)) return null;
|
|
52271
52554
|
try {
|
|
52272
52555
|
return await openDb(ctx.project, { readOnly: true });
|
|
52273
52556
|
} catch {
|
|
52274
52557
|
return null;
|
|
52275
52558
|
}
|
|
52276
52559
|
}
|
|
52560
|
+
function d1UpdateCommand(agent, env, other) {
|
|
52561
|
+
return other === void 0 ? hostUpdateCommand(agent, env) : UNSUPPORTED_HOST_LINE(other.name);
|
|
52562
|
+
}
|
|
52563
|
+
function unsupportedRow(id, h) {
|
|
52564
|
+
return { id, label: DOCTOR_LABEL[id], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
52565
|
+
}
|
|
52277
52566
|
async function hookRow(ctx, adapter, host) {
|
|
52278
52567
|
const db = await codexDb(ctx, adapter);
|
|
52279
52568
|
const runStart = Date.now();
|
|
@@ -52297,11 +52586,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
52297
52586
|
}
|
|
52298
52587
|
}
|
|
52299
52588
|
function ownServerId(configDir, projectKey) {
|
|
52300
|
-
const dir =
|
|
52301
|
-
if (!
|
|
52302
|
-
for (const name of
|
|
52589
|
+
const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
52590
|
+
if (!existsSync17(dir)) return "";
|
|
52591
|
+
for (const name of readdirSync8(dir)) {
|
|
52303
52592
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
52304
|
-
if (
|
|
52593
|
+
if (readFileSync13(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
52305
52594
|
}
|
|
52306
52595
|
return "";
|
|
52307
52596
|
}
|
|
@@ -52309,16 +52598,18 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
52309
52598
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
52310
52599
|
const env = host.env;
|
|
52311
52600
|
const project = ctx.project;
|
|
52601
|
+
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
52312
52602
|
let integrityFailed = false;
|
|
52313
52603
|
let orphan = [];
|
|
52314
52604
|
const checks = {
|
|
52315
|
-
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
52605
|
+
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal, updateCommand: d1UpdateCommand(adapter.id, env, other) }),
|
|
52316
52606
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
52317
|
-
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
52607
|
+
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
52608
|
+
// D-UNSUPPORTED-HOSTS-1
|
|
52318
52609
|
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), geminiDir: geminiDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
52319
|
-
D5: () => hookRow(ctx, adapter, host),
|
|
52610
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
52320
52611
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
52321
|
-
D6: () => checkMcp(ctx),
|
|
52612
|
+
D6: () => checkMcp(ctx, adapter),
|
|
52322
52613
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
52323
52614
|
D8: async () => {
|
|
52324
52615
|
const r = await checkDb(project);
|
|
@@ -52327,7 +52618,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
52327
52618
|
return r.row;
|
|
52328
52619
|
},
|
|
52329
52620
|
D9: () => checkIndex(project),
|
|
52330
|
-
D10: () => checkMode(adapter),
|
|
52621
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
52622
|
+
// D-1331-OC-PERM-1
|
|
52331
52623
|
D11: () => checkShell(env)
|
|
52332
52624
|
};
|
|
52333
52625
|
const rows = [];
|
|
@@ -52364,7 +52656,7 @@ async function doctorReply(ctx, host) {
|
|
|
52364
52656
|
let notes = [];
|
|
52365
52657
|
if (failed) {
|
|
52366
52658
|
try {
|
|
52367
|
-
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
52659
|
+
notes = await writeIssueReport({ unsupported: adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env: host.env }), ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
52368
52660
|
} catch (err) {
|
|
52369
52661
|
notes = [`Report file: ${lineOf(err)}`];
|
|
52370
52662
|
}
|
|
@@ -52396,9 +52688,9 @@ var ctxDoctor = Object.freeze({
|
|
|
52396
52688
|
});
|
|
52397
52689
|
|
|
52398
52690
|
// src/core/tools/execute.ts
|
|
52399
|
-
import { existsSync as
|
|
52691
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
52400
52692
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
52401
|
-
import { dirname as
|
|
52693
|
+
import { dirname as dirname10, join as join18, parse as parse5, resolve as resolve5 } from "node:path";
|
|
52402
52694
|
|
|
52403
52695
|
// src/core/index/select.ts
|
|
52404
52696
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -52520,7 +52812,7 @@ function schemaLine(issue4) {
|
|
|
52520
52812
|
}
|
|
52521
52813
|
function fileError(given, abs, root) {
|
|
52522
52814
|
let dir = abs;
|
|
52523
|
-
while (!
|
|
52815
|
+
while (!existsSync18(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
52524
52816
|
if (isInside(root, dir)) return null;
|
|
52525
52817
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
52526
52818
|
}
|
|
@@ -52554,7 +52846,7 @@ function spawnFailed(argv0, cwd) {
|
|
|
52554
52846
|
}
|
|
52555
52847
|
async function finish(input, ctx, r, exitCode, journal) {
|
|
52556
52848
|
const isError = exitCode !== 0 && !(input.language === "shell" && exitCode === SOFT_EXIT && r.stderr.length === 0);
|
|
52557
|
-
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "");
|
|
52849
|
+
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "") + (r.held === true ? "\n" + BACKGROUND_HOLD_NOTE + "\n" : "");
|
|
52558
52850
|
const fullBytes = Buffer.byteLength(combined, "utf8");
|
|
52559
52851
|
const head = summaryLine(exitCode, fullBytes);
|
|
52560
52852
|
const intent = input.intent ?? "";
|
|
@@ -52601,8 +52893,8 @@ async function handler3(raw, ctx) {
|
|
|
52601
52893
|
if (takesDashC(input.language, runtime)) {
|
|
52602
52894
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
52603
52895
|
} else {
|
|
52604
|
-
tmpDir = mkdtempSync2(
|
|
52605
|
-
const file2 =
|
|
52896
|
+
tmpDir = mkdtempSync2(join18(tmpdir3(), TMP_PREFIX));
|
|
52897
|
+
const file2 = join18(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
52606
52898
|
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
52607
52899
|
argv = scriptArgv(input.language, runtime, file2);
|
|
52608
52900
|
}
|
|
@@ -52638,12 +52930,12 @@ var ctxExecute = {
|
|
|
52638
52930
|
};
|
|
52639
52931
|
|
|
52640
52932
|
// src/core/tools/index.ts
|
|
52641
|
-
import { existsSync as
|
|
52642
|
-
import { dirname as
|
|
52933
|
+
import { existsSync as existsSync19, readFileSync as readFileSync15, statSync as statSync7 } from "node:fs";
|
|
52934
|
+
import { dirname as dirname11, extname as extname3, join as join20, relative as relative3, resolve as resolve6 } from "node:path";
|
|
52643
52935
|
|
|
52644
52936
|
// src/core/index/walk.ts
|
|
52645
|
-
import { readdirSync as
|
|
52646
|
-
import { join as
|
|
52937
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync14, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
|
|
52938
|
+
import { join as join19 } from "node:path";
|
|
52647
52939
|
var GITIGNORE = ".gitignore";
|
|
52648
52940
|
var GIT_DIR = ".git";
|
|
52649
52941
|
function walkDir(root, containmentRoot) {
|
|
@@ -52652,19 +52944,19 @@ function walkDir(root, containmentRoot) {
|
|
|
52652
52944
|
const found = [];
|
|
52653
52945
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
52654
52946
|
found.sort(compareFound);
|
|
52655
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
52947
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
|
|
52656
52948
|
}
|
|
52657
52949
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
52658
52950
|
let entries;
|
|
52659
52951
|
try {
|
|
52660
|
-
entries =
|
|
52952
|
+
entries = readdirSync9(abs, { withFileTypes: true });
|
|
52661
52953
|
} catch {
|
|
52662
52954
|
return;
|
|
52663
52955
|
}
|
|
52664
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
52956
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
|
|
52665
52957
|
for (const e of entries) {
|
|
52666
52958
|
if (e.name === GIT_DIR) continue;
|
|
52667
|
-
const path8 =
|
|
52959
|
+
const path8 = join19(abs, e.name);
|
|
52668
52960
|
let isDir = e.isDirectory();
|
|
52669
52961
|
let isFile = e.isFile();
|
|
52670
52962
|
let target = path8;
|
|
@@ -52704,7 +52996,7 @@ function compareFound(a, b) {
|
|
|
52704
52996
|
function readRules(file2, base) {
|
|
52705
52997
|
let body;
|
|
52706
52998
|
try {
|
|
52707
|
-
body =
|
|
52999
|
+
body = readFileSync14(file2, "utf8");
|
|
52708
53000
|
} catch {
|
|
52709
53001
|
return [];
|
|
52710
53002
|
}
|
|
@@ -56823,7 +57115,7 @@ function userLabel(label2) {
|
|
|
56823
57115
|
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
56824
57116
|
}
|
|
56825
57117
|
function kindOfPath(p) {
|
|
56826
|
-
return EXT_KIND[
|
|
57118
|
+
return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
|
|
56827
57119
|
}
|
|
56828
57120
|
function kindOfType(contentType) {
|
|
56829
57121
|
const semi = contentType.indexOf(";");
|
|
@@ -56832,14 +57124,14 @@ function kindOfType(contentType) {
|
|
|
56832
57124
|
}
|
|
56833
57125
|
function readUtf8(absPath) {
|
|
56834
57126
|
try {
|
|
56835
|
-
return utf8.decode(
|
|
57127
|
+
return utf8.decode(readFileSync15(absPath));
|
|
56836
57128
|
} catch {
|
|
56837
57129
|
return void 0;
|
|
56838
57130
|
}
|
|
56839
57131
|
}
|
|
56840
57132
|
function missingOrOutside(given, abs, root) {
|
|
56841
57133
|
let dir = abs;
|
|
56842
|
-
while (!
|
|
57134
|
+
while (!existsSync19(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
56843
57135
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
56844
57136
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
56845
57137
|
}
|
|
@@ -56850,7 +57142,7 @@ function pathItems(input, project) {
|
|
|
56850
57142
|
if (statSync7(abs).isDirectory()) {
|
|
56851
57143
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
56852
57144
|
sourceKind: "path",
|
|
56853
|
-
label: pathLabel(
|
|
57145
|
+
label: pathLabel(join20(base, f.relPath)),
|
|
56854
57146
|
kind: kindOfPath(f.relPath),
|
|
56855
57147
|
read: () => readUtf8(f.absPath)
|
|
56856
57148
|
}));
|
|
@@ -57264,11 +57556,6 @@ function readLastPrompt(db, sessionId) {
|
|
|
57264
57556
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
57265
57557
|
return row5 === void 0 ? "" : row5.body;
|
|
57266
57558
|
}
|
|
57267
|
-
function readFirstPrompt(db, sessionId) {
|
|
57268
|
-
if (sessionId === "") return "";
|
|
57269
|
-
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
|
|
57270
|
-
return row5 === void 0 ? "" : row5.body;
|
|
57271
|
-
}
|
|
57272
57559
|
|
|
57273
57560
|
// src/core/tools/resume.ts
|
|
57274
57561
|
var ctxResumeSchema = external_exports.object({
|
|
@@ -57294,9 +57581,8 @@ async function handler6(input, ctx) {
|
|
|
57294
57581
|
const newest = rows.at(-1);
|
|
57295
57582
|
if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
|
|
57296
57583
|
const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
|
|
57297
|
-
const goal = readFirstPrompt(db, sessionId);
|
|
57298
57584
|
const last2 = readLastPrompt(db, sessionId);
|
|
57299
|
-
const units = queryUnits(db, sessionId, recallQueryText(last2
|
|
57585
|
+
const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
|
|
57300
57586
|
const block = renderState(rows, newest.turn, { sources, units });
|
|
57301
57587
|
if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
|
|
57302
57588
|
return reply3(block, false);
|
|
@@ -57655,8 +57941,8 @@ var ctxStats = Object.freeze({
|
|
|
57655
57941
|
});
|
|
57656
57942
|
|
|
57657
57943
|
// src/core/ops/host-write.ts
|
|
57658
|
-
import { copyFileSync, existsSync as
|
|
57659
|
-
import { dirname as
|
|
57944
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
57945
|
+
import { dirname as dirname12, join as join21 } from "node:path";
|
|
57660
57946
|
function defaultWrite(file2, text) {
|
|
57661
57947
|
writeFileSync6(file2, text, "utf8");
|
|
57662
57948
|
}
|
|
@@ -57665,17 +57951,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
57665
57951
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
57666
57952
|
switch (agent) {
|
|
57667
57953
|
case "opencode":
|
|
57668
|
-
return
|
|
57954
|
+
return join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
57669
57955
|
// D-WIN-OPENCODE-DIR-1
|
|
57670
57956
|
case "pi":
|
|
57671
|
-
return
|
|
57957
|
+
return join21(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
57672
57958
|
case "gemini":
|
|
57673
|
-
return
|
|
57959
|
+
return join21(geminiDirOf(env, home), SETTINGS_FILE);
|
|
57674
57960
|
// D-R38-GEMINI-HOME-1
|
|
57675
57961
|
case "copilot-cli":
|
|
57676
57962
|
return null;
|
|
57677
57963
|
default:
|
|
57678
|
-
return
|
|
57964
|
+
return join21(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
57679
57965
|
}
|
|
57680
57966
|
}
|
|
57681
57967
|
function cell3(value) {
|
|
@@ -57687,8 +57973,8 @@ function toRow(file2, edit) {
|
|
|
57687
57973
|
function writeWithRollback(file2, text, write, atomic) {
|
|
57688
57974
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
57689
57975
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
57690
|
-
const had =
|
|
57691
|
-
|
|
57976
|
+
const had = existsSync20(file2);
|
|
57977
|
+
mkdirSync8(dirname12(file2), { recursive: true });
|
|
57692
57978
|
if (had) copyFileSync(file2, trash);
|
|
57693
57979
|
try {
|
|
57694
57980
|
write(tmp, text);
|
|
@@ -57717,7 +58003,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
57717
58003
|
if (requested === null) return [];
|
|
57718
58004
|
const current = readHostConfig(row5.id, requested);
|
|
57719
58005
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
57720
|
-
const exists =
|
|
58006
|
+
const exists = existsSync20(current.path);
|
|
57721
58007
|
if (exists && result.text === current.text) return [];
|
|
57722
58008
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
57723
58009
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -57725,15 +58011,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
57725
58011
|
}
|
|
57726
58012
|
|
|
57727
58013
|
// src/core/ops/uninstall.ts
|
|
57728
|
-
import { existsSync as
|
|
57729
|
-
import { join as
|
|
58014
|
+
import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync7, writeFileSync as writeFileSync7 } from "node:fs";
|
|
58015
|
+
import { join as join22 } from "node:path";
|
|
57730
58016
|
function row2(area, before, after) {
|
|
57731
58017
|
return { area, before, after };
|
|
57732
58018
|
}
|
|
57733
58019
|
function stopServers(configDir, projectKey) {
|
|
57734
58020
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
57735
|
-
const dir =
|
|
57736
|
-
for (const serverId of stopped) writeFileSync7(
|
|
58021
|
+
const dir = join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
58022
|
+
for (const serverId of stopped) writeFileSync7(join22(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
57737
58023
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
57738
58024
|
}
|
|
57739
58025
|
function rootOrNull(adapter, env) {
|
|
@@ -57751,15 +58037,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
57751
58037
|
const root = rootOrNull(adapter, env);
|
|
57752
58038
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
57753
58039
|
if (adapter.installMode === "marketplace") {
|
|
57754
|
-
const cache =
|
|
58040
|
+
const cache = join22(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
57755
58041
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
57756
58042
|
}
|
|
57757
58043
|
rmSync7(root, { recursive: true, force: true });
|
|
57758
58044
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
57759
58045
|
}
|
|
57760
58046
|
case "plugin": {
|
|
57761
|
-
const agentDir =
|
|
57762
|
-
if (!
|
|
58047
|
+
const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
58048
|
+
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
57763
58049
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
57764
58050
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
57765
58051
|
}
|
|
@@ -57804,7 +58090,7 @@ function ownEntries2(agent, env) {
|
|
|
57804
58090
|
}
|
|
57805
58091
|
if (agent === "opencode") {
|
|
57806
58092
|
return [{
|
|
57807
|
-
file:
|
|
58093
|
+
file: join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
57808
58094
|
// D-WIN-OPENCODE-DIR-1
|
|
57809
58095
|
key: OPENCODE_PLUGIN_KEY,
|
|
57810
58096
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -57815,7 +58101,7 @@ function ownEntries2(agent, env) {
|
|
|
57815
58101
|
if (agent === "pi") {
|
|
57816
58102
|
const agentDir = piAgentDirOf(env, home);
|
|
57817
58103
|
return [{
|
|
57818
|
-
file:
|
|
58104
|
+
file: join22(agentDir, SETTINGS_FILE),
|
|
57819
58105
|
key: PI_PACKAGES_KEY,
|
|
57820
58106
|
shown: PI_PACKAGES_KEY,
|
|
57821
58107
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -57837,12 +58123,12 @@ function removeOwnEntries(agent, env) {
|
|
|
57837
58123
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
57838
58124
|
}
|
|
57839
58125
|
function removeProjectData(configDir, projectKey) {
|
|
57840
|
-
const projects =
|
|
57841
|
-
const dir =
|
|
57842
|
-
if (!
|
|
58126
|
+
const projects = join22(configDir, PROJECTS_DIR_NAME);
|
|
58127
|
+
const dir = join22(projects, projectKey);
|
|
58128
|
+
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
57843
58129
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
57844
|
-
for (const name of
|
|
57845
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
58130
|
+
for (const name of readdirSync10(dir)) {
|
|
58131
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join22(dir, name), { recursive: true, force: true });
|
|
57846
58132
|
}
|
|
57847
58133
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
57848
58134
|
}
|
|
@@ -57850,12 +58136,12 @@ function runUninstall(input) {
|
|
|
57850
58136
|
const configDir = resolveConfigDir(input.env);
|
|
57851
58137
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
57852
58138
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
57853
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
58139
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join22(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
57854
58140
|
return { rows, stopped: stop.stopped };
|
|
57855
58141
|
}
|
|
57856
58142
|
|
|
57857
58143
|
// src/core/ops/v1-remove.ts
|
|
57858
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
58144
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync16, rmSync as rmSync8 } from "node:fs";
|
|
57859
58145
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
57860
58146
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
57861
58147
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -57867,7 +58153,7 @@ function moveAside(target, undo) {
|
|
|
57867
58153
|
}
|
|
57868
58154
|
function keepAside(target, undo) {
|
|
57869
58155
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
57870
|
-
for (let n = 2;
|
|
58156
|
+
for (let n = 2; existsSync22(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
57871
58157
|
renameWithRetry(target, aside);
|
|
57872
58158
|
undo.push({ trash: aside, target, keep: true });
|
|
57873
58159
|
return aside;
|
|
@@ -57906,8 +58192,8 @@ function locate(doc, path8) {
|
|
|
57906
58192
|
return null;
|
|
57907
58193
|
}
|
|
57908
58194
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
57909
|
-
const layout = hostLayout(
|
|
57910
|
-
const text = hostText(
|
|
58195
|
+
const layout = hostLayout(readFileSync16(file2, "utf8"));
|
|
58196
|
+
const text = hostText(readFileSync16(file2, "utf8"));
|
|
57911
58197
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
57912
58198
|
const hit = /* @__PURE__ */ new Set();
|
|
57913
58199
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -57944,20 +58230,20 @@ function removeV1(agent, findings, project) {
|
|
|
57944
58230
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
57945
58231
|
else if (f.path === "") {
|
|
57946
58232
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
57947
|
-
else if (
|
|
57948
|
-
else if (
|
|
58233
|
+
else if (existsSync22(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
58234
|
+
else if (existsSync22(f.file)) {
|
|
57949
58235
|
moveAside(f.file, undo);
|
|
57950
58236
|
done.set(f, UPGRADE_REMOVED);
|
|
57951
58237
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
57952
58238
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
57953
58239
|
}
|
|
57954
58240
|
for (const [file2, list3] of entries) {
|
|
57955
|
-
if (!
|
|
58241
|
+
if (!existsSync22(file2)) {
|
|
57956
58242
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
57957
58243
|
continue;
|
|
57958
58244
|
}
|
|
57959
58245
|
if (file2.endsWith(TOML_EXT)) {
|
|
57960
|
-
const rawToml =
|
|
58246
|
+
const rawToml = readFileSync16(file2, "utf8");
|
|
57961
58247
|
const tomlLayout = hostLayout(rawToml);
|
|
57962
58248
|
let text = hostText(rawToml);
|
|
57963
58249
|
for (const f of list3) {
|
|
@@ -57985,7 +58271,7 @@ function removeV1(agent, findings, project) {
|
|
|
57985
58271
|
},
|
|
57986
58272
|
rollback() {
|
|
57987
58273
|
for (const u of undo.splice(0).reverse()) {
|
|
57988
|
-
if (!
|
|
58274
|
+
if (!existsSync22(u.trash)) continue;
|
|
57989
58275
|
rmSync8(u.target, { recursive: true, force: true });
|
|
57990
58276
|
renameWithRetry(u.trash, u.target);
|
|
57991
58277
|
}
|
|
@@ -58015,8 +58301,8 @@ function pluginRootRow(adapter, env) {
|
|
|
58015
58301
|
}
|
|
58016
58302
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
58017
58303
|
}
|
|
58018
|
-
function hostRow(adapter) {
|
|
58019
|
-
return row4(UPGRADE_HOST_AREA, "",
|
|
58304
|
+
function hostRow(adapter, env) {
|
|
58305
|
+
return row4(UPGRADE_HOST_AREA, "", hostUpdateCommand(adapter.id, env));
|
|
58020
58306
|
}
|
|
58021
58307
|
function upgrade(adapter, deps, home) {
|
|
58022
58308
|
let removal = null;
|
|
@@ -58024,7 +58310,7 @@ function upgrade(adapter, deps, home) {
|
|
|
58024
58310
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
58025
58311
|
const findings = detectV1(adapter.id, home, { project: deps.project.worktree, piAgentDir: piAgentDirOf(deps.env, home), claudeDir: claudeDirOf(deps.env, home), geminiDir: geminiDirOf(deps.env, home), copilotDir: copilotDirOf(deps.env, home), kiroDir: kiroDirOf(deps.env, home), opencodeDir: opencodeDirOf(deps.env, home) });
|
|
58026
58312
|
removal = removeV1(adapter.id, findings, deps.project.worktree);
|
|
58027
|
-
const rows = [hostRow(adapter), ...step5, ...removal.rows];
|
|
58313
|
+
const rows = [hostRow(adapter, deps.env), ...step5, ...removal.rows];
|
|
58028
58314
|
removal.commit();
|
|
58029
58315
|
return rows;
|
|
58030
58316
|
} catch (err) {
|
|
@@ -58222,7 +58508,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
|
58222
58508
|
const fromHost = workspaceFromMeta(meta3);
|
|
58223
58509
|
if (fromHost !== void 0) return fromHost;
|
|
58224
58510
|
if (script === void 0 || script === "") return spawnCwd;
|
|
58225
|
-
return realOrSame(spawnCwd) === realOrSame(
|
|
58511
|
+
return realOrSame(spawnCwd) === realOrSame(dirname13(script)) ? "" : spawnCwd;
|
|
58226
58512
|
}
|
|
58227
58513
|
function errorReply(err) {
|
|
58228
58514
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
@@ -58261,15 +58547,15 @@ async function startServer(argv, env) {
|
|
|
58261
58547
|
opening.catch(() => pending.delete(project.dbPath));
|
|
58262
58548
|
}
|
|
58263
58549
|
const db = await opening;
|
|
58264
|
-
if (!
|
|
58550
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
58265
58551
|
return db;
|
|
58266
58552
|
}
|
|
58267
58553
|
function stopMarker(configDir, projectKey) {
|
|
58268
|
-
return
|
|
58554
|
+
return join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
58269
58555
|
}
|
|
58270
58556
|
function stopRequested() {
|
|
58271
58557
|
const configDir = resolveConfigDir(process.env);
|
|
58272
|
-
return held.some((db) =>
|
|
58558
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
58273
58559
|
}
|
|
58274
58560
|
async function journal(project, ctx, name, reply4) {
|
|
58275
58561
|
const db = await ownDb(project);
|