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/pi/index.js
CHANGED
|
@@ -11162,7 +11162,14 @@ var POINTER_MIN = 640;
|
|
|
11162
11162
|
var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
11163
11163
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
11164
11164
|
var SYNC_INDEX_MAX_BYTES = 65536;
|
|
11165
|
-
var
|
|
11165
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
11166
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
11167
|
+
function readReplaceTrigger(raw) {
|
|
11168
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
11169
|
+
const n = Number(raw);
|
|
11170
|
+
return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
11171
|
+
}
|
|
11172
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
11166
11173
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
11167
11174
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
11168
11175
|
var REPLACE_RETURN_BYTES = 96;
|
|
@@ -11320,6 +11327,8 @@ var RRF_K = 60;
|
|
|
11320
11327
|
var SOURCE_HANDLE_MAX_DIGITS = 10;
|
|
11321
11328
|
var EXEC_TIMEOUT_MS = 6e5;
|
|
11322
11329
|
var KILL_GRACE_MS = 1e3;
|
|
11330
|
+
var PIPE_EOF_GRACE_MS = 250;
|
|
11331
|
+
var PIPE_DRAIN_MAX_MS = 2e3;
|
|
11323
11332
|
var DB_TIMEOUT_MS = 5e3;
|
|
11324
11333
|
var DB_WAL_SUFFIX = "-wal";
|
|
11325
11334
|
var DB_SHM_SUFFIX = "-shm";
|
|
@@ -11354,6 +11363,7 @@ var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
|
11354
11363
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
11355
11364
|
var FETCH_MAX_HOPS = 5;
|
|
11356
11365
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
11366
|
+
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.";
|
|
11357
11367
|
var CANCELLED_LINE = "Cancelled.";
|
|
11358
11368
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
11359
11369
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
@@ -11394,6 +11404,7 @@ function readHintEvery(raw) {
|
|
|
11394
11404
|
}
|
|
11395
11405
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
11396
11406
|
var MAX_NEST_DEPTH = 32;
|
|
11407
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
11397
11408
|
var DENY_PREFIX = "context-mode: ";
|
|
11398
11409
|
var DENY_WHAT = Object.freeze({
|
|
11399
11410
|
curl: "This curl/wget call",
|
|
@@ -11487,10 +11498,10 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
11487
11498
|
opencode: READ_IMAGES_AND_PDF,
|
|
11488
11499
|
pi: READ_IMAGES,
|
|
11489
11500
|
vscode: READ_IMAGES,
|
|
11501
|
+
zcode: READ_IMAGES,
|
|
11490
11502
|
"copilot-cli": [],
|
|
11491
11503
|
codex: [],
|
|
11492
|
-
kiro: []
|
|
11493
|
-
zcode: []
|
|
11504
|
+
kiro: []
|
|
11494
11505
|
});
|
|
11495
11506
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
11496
11507
|
var SHELL_TOOL = "Bash";
|
|
@@ -11508,6 +11519,7 @@ var RECALL_MAX_ROWS = 340;
|
|
|
11508
11519
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
11509
11520
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
11510
11521
|
var UNITS_ANCESTOR_FACTOR = 8;
|
|
11522
|
+
var RECALL_QUERY_MAX_TERMS = 64;
|
|
11511
11523
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
11512
11524
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
11513
11525
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -11601,7 +11613,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
11601
11613
|
var DECISION_OPTION_KEY = "option";
|
|
11602
11614
|
var DECISION_LABEL_JOIN = " | ";
|
|
11603
11615
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11604
|
-
var BUNDLE_SHA = true ? "
|
|
11616
|
+
var BUNDLE_SHA = true ? "5539b632975049a99de986448417a10bd246e506" : void 0;
|
|
11605
11617
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11606
11618
|
var DOCTOR_LABEL = Object.freeze({
|
|
11607
11619
|
D1: "version",
|
|
@@ -11687,9 +11699,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
|
|
|
11687
11699
|
var D1_PRERELEASE_SEP = "-";
|
|
11688
11700
|
var D1_DEFAULT_TAG = "latest";
|
|
11689
11701
|
var GIT_LS_REMOTE = "ls-remote";
|
|
11690
|
-
var D2_NODE_FIX = `install
|
|
11702
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
11691
11703
|
function D2_NODE_DETAIL(version4) {
|
|
11692
|
-
return `Node ${
|
|
11704
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version4}`;
|
|
11693
11705
|
}
|
|
11694
11706
|
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
11695
11707
|
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
@@ -11707,6 +11719,7 @@ var D5B_FIX = "disable chat.useClaudeHooks or the Claude Code hooks block";
|
|
|
11707
11719
|
var VSCODE_CLAUDE_HOOKS_SETTING = "chat.useClaudeHooks";
|
|
11708
11720
|
var VSCODE_SETTINGS_FILE = "settings.json";
|
|
11709
11721
|
var D6_UNKNOWN_DETAIL = "no clientInfo or protocolVersion on the request";
|
|
11722
|
+
var D6_IN_PROCESS_DETAIL = "in-process plugin: this call ran inside the agent, no MCP session to read";
|
|
11710
11723
|
function D7_DETAIL(got) {
|
|
11711
11724
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
11712
11725
|
}
|
|
@@ -11823,6 +11836,90 @@ function D3_DETAIL(parts) {
|
|
|
11823
11836
|
function D3_ROOT_DETAIL(paths) {
|
|
11824
11837
|
return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
|
|
11825
11838
|
}
|
|
11839
|
+
var unsupported = (h) => Object.freeze(h);
|
|
11840
|
+
var UNSUPPORTED_HOSTS = Object.freeze([
|
|
11841
|
+
unsupported({
|
|
11842
|
+
id: "antigravity",
|
|
11843
|
+
name: "Antigravity",
|
|
11844
|
+
clientNames: ["antigravity", "antigravity-client", "antigravity-cli", "agy"],
|
|
11845
|
+
envVars: ["ANTIGRAVITY_CLI_ALIAS"],
|
|
11846
|
+
pluginPaths: [[".gemini", "config", "plugins"], [".gemini", "antigravity", "plugins"], [".gemini", "antigravity-cli", "plugins"], [".gemini", "antigravity-ide", "plugins"]],
|
|
11847
|
+
configDirs: [".gemini/antigravity", ".gemini/antigravity-cli", ".gemini/config"],
|
|
11848
|
+
binaries: ["agy"],
|
|
11849
|
+
source: "v1.0.169:src/adapters/client-map.ts:15-17; detect.ts:156,481-483; #1340"
|
|
11850
|
+
}),
|
|
11851
|
+
unsupported({
|
|
11852
|
+
id: "cursor",
|
|
11853
|
+
name: "Cursor",
|
|
11854
|
+
clientNames: ["cursor-vscode"],
|
|
11855
|
+
envVars: ["CURSOR_TRACE_ID", "CURSOR_CLI", "CURSOR_CWD"],
|
|
11856
|
+
pluginPaths: [],
|
|
11857
|
+
configDirs: [".cursor"],
|
|
11858
|
+
binaries: [],
|
|
11859
|
+
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
11860
|
+
}),
|
|
11861
|
+
unsupported({
|
|
11862
|
+
id: "omp",
|
|
11863
|
+
name: "OMP (oh-my-pi)",
|
|
11864
|
+
clientNames: ["omp-coding-agent"],
|
|
11865
|
+
envVars: [],
|
|
11866
|
+
pluginPaths: [],
|
|
11867
|
+
configDirs: [".omp"],
|
|
11868
|
+
binaries: ["omp"],
|
|
11869
|
+
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)"
|
|
11870
|
+
}),
|
|
11871
|
+
unsupported({
|
|
11872
|
+
id: "openclaw",
|
|
11873
|
+
name: "OpenClaw",
|
|
11874
|
+
clientNames: [],
|
|
11875
|
+
envVars: [],
|
|
11876
|
+
pluginPaths: [],
|
|
11877
|
+
configDirs: [".openclaw"],
|
|
11878
|
+
binaries: [],
|
|
11879
|
+
source: "v1.0.169:src/adapters/detect.ts:252,575 (the runtime sets no env var)"
|
|
11880
|
+
}),
|
|
11881
|
+
unsupported({
|
|
11882
|
+
id: "kimi",
|
|
11883
|
+
name: "Kimi Code",
|
|
11884
|
+
clientNames: ["kimi-code", "kimi"],
|
|
11885
|
+
envVars: [],
|
|
11886
|
+
pluginPaths: [],
|
|
11887
|
+
configDirs: [".kimi-code"],
|
|
11888
|
+
binaries: ["kimi"],
|
|
11889
|
+
source: "v1.0.169:src/adapters/client-map.ts:42-44; detect.ts:567; adapters/kimi/index.ts:127"
|
|
11890
|
+
}),
|
|
11891
|
+
unsupported({
|
|
11892
|
+
id: "kilo",
|
|
11893
|
+
name: "Kilo Code",
|
|
11894
|
+
clientNames: ["kilo code"],
|
|
11895
|
+
envVars: ["KILO", "KILO_PID"],
|
|
11896
|
+
pluginPaths: [],
|
|
11897
|
+
configDirs: [".config/kilo"],
|
|
11898
|
+
binaries: [],
|
|
11899
|
+
source: "v1.0.169:src/adapters/client-map.ts:28; detect.ts:170-171,592"
|
|
11900
|
+
}),
|
|
11901
|
+
unsupported({
|
|
11902
|
+
id: "zed",
|
|
11903
|
+
name: "Zed",
|
|
11904
|
+
clientNames: ["zed"],
|
|
11905
|
+
envVars: ["ZED_SESSION_ID", "ZED_TERM"],
|
|
11906
|
+
pluginPaths: [],
|
|
11907
|
+
configDirs: [".config/zed"],
|
|
11908
|
+
binaries: [],
|
|
11909
|
+
source: "v1.0.169:src/adapters/client-map.ts:38-39; detect.ts:189-190,616"
|
|
11910
|
+
}),
|
|
11911
|
+
unsupported({
|
|
11912
|
+
id: "jetbrains-copilot",
|
|
11913
|
+
name: "JetBrains Copilot",
|
|
11914
|
+
clientNames: ["jetbrains client", "intellij idea", "pycharm"],
|
|
11915
|
+
envVars: ["IDEA_INITIAL_DIRECTORY"],
|
|
11916
|
+
pluginPaths: [],
|
|
11917
|
+
configDirs: [".config/JetBrains"],
|
|
11918
|
+
binaries: [],
|
|
11919
|
+
source: "v1.0.169:src/adapters/client-map.ts:23-25; detect.ts:213,600"
|
|
11920
|
+
})
|
|
11921
|
+
]);
|
|
11922
|
+
var SUPPORTED_AGENTS_DOCS_URL = "https://github.com/mksglu/context-mode/blob/main/docs/install/README.md";
|
|
11826
11923
|
var D3_ROOT_FIX_JOIN = " or ";
|
|
11827
11924
|
function D3_ROOT_FIX(installs) {
|
|
11828
11925
|
return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
|
|
@@ -11859,6 +11956,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
11859
11956
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
11860
11957
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
11861
11958
|
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";
|
|
11959
|
+
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)";
|
|
11862
11960
|
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)";
|
|
11863
11961
|
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`;
|
|
11864
11962
|
function D5_SLOW_DETAIL(ms) {
|
|
@@ -11870,6 +11968,11 @@ var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
|
11870
11968
|
function D10_DETAIL(mode) {
|
|
11871
11969
|
return `enforcement mode: ${mode}`;
|
|
11872
11970
|
}
|
|
11971
|
+
function D10_PERMISSION_DETAIL(mode) {
|
|
11972
|
+
return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
|
|
11973
|
+
}
|
|
11974
|
+
var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
|
|
11975
|
+
var D10_PERMISSION_FIX = "opencode upgrade";
|
|
11873
11976
|
var D11_WIN_DETAIL = "Git Bash not found";
|
|
11874
11977
|
var D11_WIN_FIX = "install Git for Windows";
|
|
11875
11978
|
var D11_POSIX_DETAIL = "no sh on PATH";
|
|
@@ -11932,6 +12035,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
11932
12035
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
11933
12036
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
11934
12037
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
12038
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
12039
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
11935
12040
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
11936
12041
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
11937
12042
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -12026,6 +12131,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
12026
12131
|
var JSON_INDENT_UNIT = " ";
|
|
12027
12132
|
var MCP_COMMAND_FIELD = "command";
|
|
12028
12133
|
var MCP_ARGS_FIELD = "args";
|
|
12134
|
+
var MCP_ENV_FIELD = "env";
|
|
12029
12135
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
12030
12136
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
12031
12137
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -12201,7 +12307,8 @@ function checkPermission(out) {
|
|
|
12201
12307
|
|
|
12202
12308
|
// src/core/contracts/errors.ts
|
|
12203
12309
|
var ERROR_TEXT = Object.freeze({
|
|
12204
|
-
NODE_TOO_OLD: "
|
|
12310
|
+
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.",
|
|
12311
|
+
// #1328 D-NODE-OLD-1
|
|
12205
12312
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
12206
12313
|
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.",
|
|
12207
12314
|
// D-ORPHAN-WAL-1
|
|
@@ -12271,7 +12378,7 @@ var CtxError = class extends Error {
|
|
|
12271
12378
|
};
|
|
12272
12379
|
|
|
12273
12380
|
// src/core/hooks/dispatch.ts
|
|
12274
|
-
import { dirname as dirname4, join as
|
|
12381
|
+
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
|
|
12275
12382
|
|
|
12276
12383
|
// src/core/contracts/agents.ts
|
|
12277
12384
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -14562,7 +14669,7 @@ function withLayout(text, layout) {
|
|
|
14562
14669
|
|
|
14563
14670
|
// src/core/project/config-dir.ts
|
|
14564
14671
|
import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
|
|
14565
|
-
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
14672
|
+
var { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
14566
14673
|
function homeDirOf(env, platform = process.platform) {
|
|
14567
14674
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
14568
14675
|
if (platform === "win32") {
|
|
@@ -14589,7 +14696,34 @@ function codexPluginHomeOf(bundleDir2) {
|
|
|
14589
14696
|
function codexRunDirOf(env, home, bundleDir2) {
|
|
14590
14697
|
const dir = env[CODEX_HOME_ENV];
|
|
14591
14698
|
if (dir !== void 0 && dir !== "") return dir;
|
|
14592
|
-
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
14699
|
+
return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
|
|
14700
|
+
}
|
|
14701
|
+
function codexSetupHomeOf(env, home) {
|
|
14702
|
+
if (home === "" && !env[DATA_DIR_ENV]) return null;
|
|
14703
|
+
const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
|
|
14704
|
+
let runs;
|
|
14705
|
+
try {
|
|
14706
|
+
runs = readdirSync(base).sort().reverse();
|
|
14707
|
+
} catch {
|
|
14708
|
+
return null;
|
|
14709
|
+
}
|
|
14710
|
+
for (const run of runs) {
|
|
14711
|
+
const file2 = join(base, run, SETUP_MANIFEST_FILE);
|
|
14712
|
+
if (!existsSync(file2)) continue;
|
|
14713
|
+
let entries;
|
|
14714
|
+
try {
|
|
14715
|
+
entries = JSON.parse(readFileSync(file2, "utf8")).entries;
|
|
14716
|
+
} catch {
|
|
14717
|
+
continue;
|
|
14718
|
+
}
|
|
14719
|
+
if (!Array.isArray(entries)) continue;
|
|
14720
|
+
for (const e of entries) {
|
|
14721
|
+
if (e?.agent !== "codex" || typeof e.file !== "string") continue;
|
|
14722
|
+
const p = e.file.includes(win32.sep) ? win32 : posix;
|
|
14723
|
+
if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
|
|
14724
|
+
}
|
|
14725
|
+
}
|
|
14726
|
+
return null;
|
|
14593
14727
|
}
|
|
14594
14728
|
function copilotDirOf(env, home) {
|
|
14595
14729
|
const dir = env[COPILOT_HOME_ENV];
|
|
@@ -14630,6 +14764,17 @@ function claudeDirOf(env, home) {
|
|
|
14630
14764
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
14631
14765
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["claude-code"]);
|
|
14632
14766
|
}
|
|
14767
|
+
function claudeProfileEnv(env, platform = process.platform) {
|
|
14768
|
+
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
14769
|
+
if (dir === void 0 || dir === "" || platform === "win32") return "";
|
|
14770
|
+
return `${CLAUDE_CONFIG_DIR_ENV}='${dir.split("'").join(`'"'"'`)}' `;
|
|
14771
|
+
}
|
|
14772
|
+
function hostUpdateCommand(agent, env, platform = process.platform) {
|
|
14773
|
+
const cmd = UPGRADE_HOST_COMMAND[agent];
|
|
14774
|
+
if (agent !== "claude-code") return cmd;
|
|
14775
|
+
const profile = claudeProfileEnv(env, platform);
|
|
14776
|
+
return profile === "" ? cmd : cmd.split(" && ").map((c) => profile + c).join(" && ");
|
|
14777
|
+
}
|
|
14633
14778
|
function opencodeDirOf(env, home) {
|
|
14634
14779
|
const own4 = env[OPENCODE_CONFIG_DIR_ENV];
|
|
14635
14780
|
if (own4 !== void 0 && own4 !== "") return own4;
|
|
@@ -14669,7 +14814,7 @@ function resolveConfigDir(env) {
|
|
|
14669
14814
|
}
|
|
14670
14815
|
|
|
14671
14816
|
// src/core/policy/subagent.ts
|
|
14672
|
-
var { readFileSync } = process.getBuiltinModule("node:fs");
|
|
14817
|
+
var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
|
|
14673
14818
|
function isSubagentCall(ev) {
|
|
14674
14819
|
return ev.agentId !== void 0 && ev.agentId !== "";
|
|
14675
14820
|
}
|
|
@@ -14730,7 +14875,7 @@ function readPluginAgent(claudeDir, type) {
|
|
|
14730
14875
|
if (agent.indexOf(PLUGIN_AGENT_SEPARATOR) >= 0) return null;
|
|
14731
14876
|
let parsed;
|
|
14732
14877
|
try {
|
|
14733
|
-
parsed = JSON.parse(hostText(
|
|
14878
|
+
parsed = JSON.parse(hostText(readFileSync2(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
|
|
14734
14879
|
} catch {
|
|
14735
14880
|
return null;
|
|
14736
14881
|
}
|
|
@@ -14753,7 +14898,7 @@ function readPluginAgent(claudeDir, type) {
|
|
|
14753
14898
|
function readAgentFile(path8) {
|
|
14754
14899
|
let text;
|
|
14755
14900
|
try {
|
|
14756
|
-
text =
|
|
14901
|
+
text = readFileSync2(path8, "utf8");
|
|
14757
14902
|
} catch {
|
|
14758
14903
|
return null;
|
|
14759
14904
|
}
|
|
@@ -14961,7 +15106,7 @@ function unwrap(commands) {
|
|
|
14961
15106
|
|
|
14962
15107
|
// src/core/policy/user-deny.ts
|
|
14963
15108
|
import { isAbsolute, join as join3, relative, sep } from "node:path";
|
|
14964
|
-
var { readFileSync:
|
|
15109
|
+
var { readFileSync: readFileSync3 } = process.getBuiltinModule("node:fs");
|
|
14965
15110
|
var CLAUDE_DIR = ".claude";
|
|
14966
15111
|
var LOCAL_SETTINGS = "settings.local.json";
|
|
14967
15112
|
var SETTINGS = "settings.json";
|
|
@@ -14988,7 +15133,7 @@ function isObject2(v) {
|
|
|
14988
15133
|
function readOne(file2) {
|
|
14989
15134
|
let text;
|
|
14990
15135
|
try {
|
|
14991
|
-
text = hostText(
|
|
15136
|
+
text = hostText(readFileSync3(file2, "utf8"));
|
|
14992
15137
|
} catch (err) {
|
|
14993
15138
|
return err.code === "ENOENT" ? { kind: "absent" } : { kind: "bad" };
|
|
14994
15139
|
}
|
|
@@ -15151,6 +15296,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
15151
15296
|
ctx_purge: 'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'
|
|
15152
15297
|
});
|
|
15153
15298
|
var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limit. Run ctx_execute(language, code, file="{path}") and print only the answer.';
|
|
15299
|
+
var READ_DENY_RANGE_TEMPLATE = `context-mode: {size}-byte file, over the one-read limit. Read "{path}" in parts with offset and limit, or sed -n '1,200p'.`;
|
|
15154
15300
|
|
|
15155
15301
|
// src/core/policy/read-deny.ts
|
|
15156
15302
|
var SIZE = "{size}";
|
|
@@ -15158,9 +15304,105 @@ var PATH = "{path}";
|
|
|
15158
15304
|
function READ_DENY_MESSAGE(path8, size, prefix = "") {
|
|
15159
15305
|
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
15160
15306
|
}
|
|
15307
|
+
function READ_DENY_RANGE_MESSAGE(path8, size) {
|
|
15308
|
+
return READ_DENY_RANGE_TEMPLATE.split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
15309
|
+
}
|
|
15310
|
+
|
|
15311
|
+
// src/core/policy/own-file.ts
|
|
15312
|
+
import { extname, join as join5 } from "node:path";
|
|
15313
|
+
|
|
15314
|
+
// src/core/project/contain.ts
|
|
15315
|
+
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
15316
|
+
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
15317
|
+
function real(p) {
|
|
15318
|
+
try {
|
|
15319
|
+
return realpathSync2.native(p);
|
|
15320
|
+
} catch {
|
|
15321
|
+
return void 0;
|
|
15322
|
+
}
|
|
15323
|
+
}
|
|
15324
|
+
function components(p) {
|
|
15325
|
+
return p.split(sep2).filter((c) => c !== "");
|
|
15326
|
+
}
|
|
15327
|
+
function isInside(root, p) {
|
|
15328
|
+
const r = real(root);
|
|
15329
|
+
const q = real(p);
|
|
15330
|
+
if (r === void 0 || q === void 0) return false;
|
|
15331
|
+
const rc = components(r);
|
|
15332
|
+
const qc = components(q);
|
|
15333
|
+
if (qc.length < rc.length) return false;
|
|
15334
|
+
for (let i = 0; i < rc.length; i += 1) {
|
|
15335
|
+
if (rc[i] !== qc[i]) return false;
|
|
15336
|
+
}
|
|
15337
|
+
return true;
|
|
15338
|
+
}
|
|
15339
|
+
var rootReal = /* @__PURE__ */ new Map();
|
|
15340
|
+
function realRoot(root) {
|
|
15341
|
+
const hit = rootReal.get(root);
|
|
15342
|
+
if (hit !== void 0) return hit;
|
|
15343
|
+
const r = real(root);
|
|
15344
|
+
if (r !== void 0) rootReal.set(root, r);
|
|
15345
|
+
return r;
|
|
15346
|
+
}
|
|
15347
|
+
function isInsideAny(roots, p) {
|
|
15348
|
+
if (roots.length === 0) return false;
|
|
15349
|
+
const q = real(p);
|
|
15350
|
+
if (q === void 0) return false;
|
|
15351
|
+
const qc = components(q);
|
|
15352
|
+
return roots.some((root) => {
|
|
15353
|
+
const r = realRoot(root);
|
|
15354
|
+
if (r === void 0) return false;
|
|
15355
|
+
const rc = components(r);
|
|
15356
|
+
return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
|
|
15357
|
+
});
|
|
15358
|
+
}
|
|
15359
|
+
function commonRoot(paths) {
|
|
15360
|
+
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
15361
|
+
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
15362
|
+
const first = reals[0];
|
|
15363
|
+
let n = components(first).length;
|
|
15364
|
+
for (const r of reals) {
|
|
15365
|
+
const rc = components(r);
|
|
15366
|
+
const fc = components(first);
|
|
15367
|
+
let i = 0;
|
|
15368
|
+
while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
|
|
15369
|
+
n = i;
|
|
15370
|
+
}
|
|
15371
|
+
let q = first;
|
|
15372
|
+
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
15373
|
+
return q;
|
|
15374
|
+
}
|
|
15375
|
+
function reachedThroughLink(root, p) {
|
|
15376
|
+
const rel = relative2(root, p);
|
|
15377
|
+
const steps = components(rel);
|
|
15378
|
+
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
15379
|
+
let at2 = root;
|
|
15380
|
+
for (const step of steps) {
|
|
15381
|
+
at2 = join4(at2, step);
|
|
15382
|
+
try {
|
|
15383
|
+
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
15384
|
+
} catch {
|
|
15385
|
+
return false;
|
|
15386
|
+
}
|
|
15387
|
+
}
|
|
15388
|
+
return false;
|
|
15389
|
+
}
|
|
15390
|
+
|
|
15391
|
+
// src/core/policy/own-file.ts
|
|
15392
|
+
function ownDirsOf(agent, env) {
|
|
15393
|
+
const home = homeDirOf(env);
|
|
15394
|
+
if (home === null) return [];
|
|
15395
|
+
const shared = join5(home, ...SHARED_SKILLS_DIR);
|
|
15396
|
+
const own4 = agent === "claude-code" ? [claudeDirOf(env, home)] : agent === "codex" ? [codexDirOf(env, home)] : agent === "gemini" ? [geminiDirOf(env, home)] : agent === "copilot-cli" ? [copilotDirOf(env, home)] : agent === "kiro" ? [kiroDirOf(env, home)] : agent === "opencode" ? [opencodeDirOf(env, home)] : agent === "pi" ? [piAgentDirOf(env, home)] : agent === "vscode" ? [join5(home, ...AGENT_HOME_DIR.vscode), vscodeUserDirOf(env, home)] : [join5(home, ...AGENT_HOME_DIR[agent])];
|
|
15397
|
+
return [...own4, shared];
|
|
15398
|
+
}
|
|
15399
|
+
function isOwnFile(agent, abs, env = process.env) {
|
|
15400
|
+
if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
|
|
15401
|
+
return isInsideAny(ownDirsOf(agent, env), abs);
|
|
15402
|
+
}
|
|
15161
15403
|
|
|
15162
15404
|
// src/core/policy/read-media.ts
|
|
15163
|
-
import { extname } from "node:path";
|
|
15405
|
+
import { extname as extname2 } from "node:path";
|
|
15164
15406
|
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
15165
15407
|
function head(abs) {
|
|
15166
15408
|
let fd = null;
|
|
@@ -15178,7 +15420,7 @@ function head(abs) {
|
|
|
15178
15420
|
function isMediaRead(agent, abs) {
|
|
15179
15421
|
const types = READ_MEDIA_BY_AGENT[agent] ?? [];
|
|
15180
15422
|
if (types.length === 0) return false;
|
|
15181
|
-
const ext =
|
|
15423
|
+
const ext = extname2(abs).toLowerCase();
|
|
15182
15424
|
const named2 = types.filter((t) => READ_MEDIA_TYPES[t].exts.includes(ext));
|
|
15183
15425
|
if (named2.length === 0) return false;
|
|
15184
15426
|
const bytes5 = head(abs);
|
|
@@ -15209,7 +15451,7 @@ var deny = (reason) => ({ kind: "deny", reason });
|
|
|
15209
15451
|
var str = (v) => typeof v === "string" ? v : void 0;
|
|
15210
15452
|
var present = (v) => v !== void 0 && v !== null;
|
|
15211
15453
|
var has = (list4, v) => list4.includes(v);
|
|
15212
|
-
function decide(ev, row5, userDeny) {
|
|
15454
|
+
function decide(ev, row5, userDeny, root = ev.cwd) {
|
|
15213
15455
|
const tool = ev.tool;
|
|
15214
15456
|
if (tool === void 0) return ALLOW;
|
|
15215
15457
|
const canonical = tool.canonicalName;
|
|
@@ -15223,8 +15465,8 @@ function decide(ev, row5, userDeny) {
|
|
|
15223
15465
|
const hit = userDenyHit(canonical, input, ev.cwd, rules);
|
|
15224
15466
|
if (hit !== null) return deny(USER_DENY_REASON_PREFIX + hit);
|
|
15225
15467
|
if (canonical === WEBFETCH) return webFetch(input, row5);
|
|
15226
|
-
if (canonical === BASH) return bash(ev, row5, input, rules);
|
|
15227
|
-
if (canonical === READ) return read(ev, row5, input);
|
|
15468
|
+
if (canonical === BASH) return bash(ev, row5, input, rules, root);
|
|
15469
|
+
if (canonical === READ) return read(ev, row5, input, root);
|
|
15228
15470
|
return ALLOW;
|
|
15229
15471
|
}
|
|
15230
15472
|
function denyMessage(kind, match, row5, intent) {
|
|
@@ -15326,10 +15568,10 @@ function webFetch(input, row5) {
|
|
|
15326
15568
|
const url4 = str(input.url) ?? "";
|
|
15327
15569
|
return neverDenied(url4) ? ALLOW : deny(denyMessage("webfetch", url4, row5));
|
|
15328
15570
|
}
|
|
15329
|
-
function bash(ev, row5, input, rules) {
|
|
15571
|
+
function bash(ev, row5, input, rules, root) {
|
|
15330
15572
|
const cmd = str(input.command) ?? "";
|
|
15331
15573
|
const parsed = parseShell(cmd);
|
|
15332
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd,
|
|
15574
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(ev, cmd, row5, root) ?? ALLOW;
|
|
15333
15575
|
const cmds = unwrap(parsed.commands);
|
|
15334
15576
|
for (const c of cmds) {
|
|
15335
15577
|
const h = segmentHit(c, rules);
|
|
@@ -15341,7 +15583,7 @@ function bash(ev, row5, input, rules) {
|
|
|
15341
15583
|
if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
|
|
15342
15584
|
}
|
|
15343
15585
|
}
|
|
15344
|
-
return shellDump(cmds,
|
|
15586
|
+
return shellDump(ev, cmds, row5, root) ?? psShellDump(ev, cmd, row5, root) ?? ALLOW;
|
|
15345
15587
|
}
|
|
15346
15588
|
function denyKind(c) {
|
|
15347
15589
|
const name = c.argv0.toLowerCase();
|
|
@@ -15384,19 +15626,35 @@ function fileSize(abs) {
|
|
|
15384
15626
|
return -1;
|
|
15385
15627
|
}
|
|
15386
15628
|
}
|
|
15387
|
-
function
|
|
15629
|
+
function bigDeny(ev, row5, abs, size, root) {
|
|
15630
|
+
if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
|
|
15631
|
+
return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
|
|
15632
|
+
}
|
|
15633
|
+
function executeCanOpen(root, abs) {
|
|
15634
|
+
if (typeof root === "string") return isInsideAny([root], abs);
|
|
15635
|
+
if (isInsideAny([root.worktree], abs)) return true;
|
|
15636
|
+
try {
|
|
15637
|
+
return isInsideAny([root.containmentRoot], abs);
|
|
15638
|
+
} catch {
|
|
15639
|
+
return false;
|
|
15640
|
+
}
|
|
15641
|
+
}
|
|
15642
|
+
function read(ev, row5, input, root) {
|
|
15388
15643
|
if (!present(input.offset) && !present(input.limit)) {
|
|
15389
15644
|
for (const p of readPaths(input)) {
|
|
15390
15645
|
const abs = resolve3(ev.cwd, p);
|
|
15391
15646
|
const size = fileSize(abs);
|
|
15392
|
-
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs))
|
|
15647
|
+
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
|
|
15648
|
+
const d = bigDeny(ev, row5, abs, size, root);
|
|
15649
|
+
if (d !== null) return d;
|
|
15650
|
+
}
|
|
15393
15651
|
}
|
|
15394
15652
|
}
|
|
15395
15653
|
return ALLOW;
|
|
15396
15654
|
}
|
|
15397
|
-
function shellDump(cmds,
|
|
15655
|
+
function shellDump(ev, cmds, row5, root) {
|
|
15398
15656
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
15399
|
-
let dir = cwd;
|
|
15657
|
+
let dir = ev.cwd;
|
|
15400
15658
|
let verdict = null;
|
|
15401
15659
|
for (const c of cmds) {
|
|
15402
15660
|
const name = c.argv0.toLowerCase();
|
|
@@ -15410,16 +15668,16 @@ function shellDump(cmds, cwd, row5) {
|
|
|
15410
15668
|
continue;
|
|
15411
15669
|
}
|
|
15412
15670
|
const abs = resolve3(dir, d.file);
|
|
15413
|
-
const
|
|
15414
|
-
if (
|
|
15671
|
+
const big = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
15672
|
+
if (big !== null) return big;
|
|
15415
15673
|
}
|
|
15416
15674
|
return verdict;
|
|
15417
15675
|
}
|
|
15418
|
-
function psShellDump(cmd,
|
|
15676
|
+
function psShellDump(ev, cmd, row5, root) {
|
|
15419
15677
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
15420
|
-
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
15421
|
-
const
|
|
15422
|
-
if (
|
|
15678
|
+
for (const abs of psDumpFiles(cmd, ev.cwd)) {
|
|
15679
|
+
const d = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
15680
|
+
if (d !== null) return d;
|
|
15423
15681
|
}
|
|
15424
15682
|
return null;
|
|
15425
15683
|
}
|
|
@@ -15480,64 +15738,7 @@ function dumpTarget(name, args) {
|
|
|
15480
15738
|
}
|
|
15481
15739
|
|
|
15482
15740
|
// src/core/project/resolve.ts
|
|
15483
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
15484
|
-
|
|
15485
|
-
// src/core/project/contain.ts
|
|
15486
|
-
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
15487
|
-
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
15488
|
-
function real(p) {
|
|
15489
|
-
try {
|
|
15490
|
-
return realpathSync2.native(p);
|
|
15491
|
-
} catch {
|
|
15492
|
-
return void 0;
|
|
15493
|
-
}
|
|
15494
|
-
}
|
|
15495
|
-
function components(p) {
|
|
15496
|
-
return p.split(sep2).filter((c) => c !== "");
|
|
15497
|
-
}
|
|
15498
|
-
function isInside(root, p) {
|
|
15499
|
-
const r = real(root);
|
|
15500
|
-
const q = real(p);
|
|
15501
|
-
if (r === void 0 || q === void 0) return false;
|
|
15502
|
-
const rc = components(r);
|
|
15503
|
-
const qc = components(q);
|
|
15504
|
-
if (qc.length < rc.length) return false;
|
|
15505
|
-
for (let i = 0; i < rc.length; i += 1) {
|
|
15506
|
-
if (rc[i] !== qc[i]) return false;
|
|
15507
|
-
}
|
|
15508
|
-
return true;
|
|
15509
|
-
}
|
|
15510
|
-
function commonRoot(paths) {
|
|
15511
|
-
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
15512
|
-
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
15513
|
-
const first = reals[0];
|
|
15514
|
-
let n = components(first).length;
|
|
15515
|
-
for (const r of reals) {
|
|
15516
|
-
const rc = components(r);
|
|
15517
|
-
const fc = components(first);
|
|
15518
|
-
let i = 0;
|
|
15519
|
-
while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
|
|
15520
|
-
n = i;
|
|
15521
|
-
}
|
|
15522
|
-
let q = first;
|
|
15523
|
-
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
15524
|
-
return q;
|
|
15525
|
-
}
|
|
15526
|
-
function reachedThroughLink(root, p) {
|
|
15527
|
-
const rel = relative2(root, p);
|
|
15528
|
-
const steps = components(rel);
|
|
15529
|
-
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
15530
|
-
let at2 = root;
|
|
15531
|
-
for (const step of steps) {
|
|
15532
|
-
at2 = join4(at2, step);
|
|
15533
|
-
try {
|
|
15534
|
-
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
15535
|
-
} catch {
|
|
15536
|
-
return false;
|
|
15537
|
-
}
|
|
15538
|
-
}
|
|
15539
|
-
return false;
|
|
15540
|
-
}
|
|
15741
|
+
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
|
|
15541
15742
|
|
|
15542
15743
|
// src/core/project/sha256.ts
|
|
15543
15744
|
var K = new Uint32Array([
|
|
@@ -15652,7 +15853,7 @@ function sha256Hex(text) {
|
|
|
15652
15853
|
}
|
|
15653
15854
|
|
|
15654
15855
|
// src/core/project/resolve.ts
|
|
15655
|
-
var { existsSync, readFileSync:
|
|
15856
|
+
var { existsSync: existsSync2, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
|
|
15656
15857
|
function sourceOf(agent) {
|
|
15657
15858
|
switch (agent) {
|
|
15658
15859
|
case "claude-code":
|
|
@@ -15699,9 +15900,9 @@ function gitDirs(dir) {
|
|
|
15699
15900
|
}
|
|
15700
15901
|
const start = cur;
|
|
15701
15902
|
for (; ; ) {
|
|
15702
|
-
const gitDir = gitDirAt(
|
|
15903
|
+
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
15703
15904
|
if (gitDir !== null) {
|
|
15704
|
-
const common = firstLine(
|
|
15905
|
+
const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
|
|
15705
15906
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
15706
15907
|
}
|
|
15707
15908
|
const up = dirname3(cur);
|
|
@@ -15722,12 +15923,12 @@ function gitDirAt(dotGit) {
|
|
|
15722
15923
|
} catch {
|
|
15723
15924
|
return null;
|
|
15724
15925
|
}
|
|
15725
|
-
return
|
|
15926
|
+
return existsSync2(join6(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
15726
15927
|
}
|
|
15727
15928
|
function firstLine(file2) {
|
|
15728
15929
|
let text;
|
|
15729
15930
|
try {
|
|
15730
|
-
text =
|
|
15931
|
+
text = readFileSync4(file2, "utf8");
|
|
15731
15932
|
} catch {
|
|
15732
15933
|
return null;
|
|
15733
15934
|
}
|
|
@@ -15763,11 +15964,11 @@ function resolveProject(agent, src) {
|
|
|
15763
15964
|
return key;
|
|
15764
15965
|
},
|
|
15765
15966
|
get projectDir() {
|
|
15766
|
-
pdir ??=
|
|
15967
|
+
pdir ??= join6(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
15767
15968
|
return pdir;
|
|
15768
15969
|
},
|
|
15769
15970
|
get dbPath() {
|
|
15770
|
-
return
|
|
15971
|
+
return join6(this.projectDir, DB_FILE_NAME);
|
|
15771
15972
|
},
|
|
15772
15973
|
worktree,
|
|
15773
15974
|
get containmentRoot() {
|
|
@@ -15918,7 +16119,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
15918
16119
|
}
|
|
15919
16120
|
|
|
15920
16121
|
// src/core/store/db.ts
|
|
15921
|
-
var { existsSync:
|
|
16122
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
15922
16123
|
function versionParts(v) {
|
|
15923
16124
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
15924
16125
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -15972,7 +16173,7 @@ function createAtomically(sqlite, path8) {
|
|
|
15972
16173
|
function openWritable(sqlite, path8) {
|
|
15973
16174
|
let raw = null;
|
|
15974
16175
|
try {
|
|
15975
|
-
if (!
|
|
16176
|
+
if (!existsSync3(path8)) createAtomically(sqlite, path8);
|
|
15976
16177
|
raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
15977
16178
|
applyMigrations(raw, readUserVersion(raw));
|
|
15978
16179
|
return raw;
|
|
@@ -15997,14 +16198,14 @@ async function openDb(project, opts) {
|
|
|
15997
16198
|
const sqlite = await loadSqlite();
|
|
15998
16199
|
mkdirSync2(project.projectDir, { recursive: true });
|
|
15999
16200
|
const path8 = project.dbPath;
|
|
16000
|
-
const sibling =
|
|
16001
|
-
if (sibling && !
|
|
16201
|
+
const sibling = existsSync3(path8 + DB_WAL_SUFFIX) || existsSync3(path8 + DB_SHM_SUFFIX);
|
|
16202
|
+
if (sibling && !existsSync3(path8)) {
|
|
16002
16203
|
throw new CtxError("DB_GONE");
|
|
16003
16204
|
}
|
|
16004
16205
|
try {
|
|
16005
16206
|
let raw;
|
|
16006
16207
|
if (opts?.readOnly === true) {
|
|
16007
|
-
if (!
|
|
16208
|
+
if (!existsSync3(path8)) openWritable(sqlite, path8).close();
|
|
16008
16209
|
raw = openReadOnly(sqlite, path8);
|
|
16009
16210
|
} else {
|
|
16010
16211
|
raw = openWritable(sqlite, path8);
|
|
@@ -16154,11 +16355,6 @@ function readLastPrompt(db, sessionId) {
|
|
|
16154
16355
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
16155
16356
|
return row5 === void 0 ? "" : row5.body;
|
|
16156
16357
|
}
|
|
16157
|
-
function readFirstPrompt(db, sessionId) {
|
|
16158
|
-
if (sessionId === "") return "";
|
|
16159
|
-
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
|
|
16160
|
-
return row5 === void 0 ? "" : row5.body;
|
|
16161
|
-
}
|
|
16162
16358
|
function readRecallRows(db, sessionId, worktree, limit) {
|
|
16163
16359
|
if (sessionId === "") return [];
|
|
16164
16360
|
return db.raw.prepare("SELECT * FROM events WHERE kind <> 'cost' AND (session_id = ? OR worktree = ?) ORDER BY seq DESC LIMIT ?").all(sessionId, worktree, limit);
|
|
@@ -18726,8 +18922,25 @@ function insertUnits(db, sourceId, sessionId, units) {
|
|
|
18726
18922
|
start = end;
|
|
18727
18923
|
}
|
|
18728
18924
|
}
|
|
18729
|
-
function recallQueryText(prompt
|
|
18730
|
-
|
|
18925
|
+
function recallQueryText(prompt) {
|
|
18926
|
+
const kept = /* @__PURE__ */ new Set();
|
|
18927
|
+
const all = /* @__PURE__ */ new Set();
|
|
18928
|
+
const add = (w) => {
|
|
18929
|
+
if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
|
|
18930
|
+
if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
|
|
18931
|
+
};
|
|
18932
|
+
let cur = "";
|
|
18933
|
+
for (const ch of prompt) {
|
|
18934
|
+
if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
|
|
18935
|
+
if (ch.trim() === "" || ch === "\0") {
|
|
18936
|
+
if (cur !== "") add(cur);
|
|
18937
|
+
cur = "";
|
|
18938
|
+
} else {
|
|
18939
|
+
cur += ch;
|
|
18940
|
+
}
|
|
18941
|
+
}
|
|
18942
|
+
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
18943
|
+
return [...kept.size > 0 ? kept : all].join(" ");
|
|
18731
18944
|
}
|
|
18732
18945
|
function queryUnits(db, sessionId, q, limit) {
|
|
18733
18946
|
const match = searchTerms(q).join(" OR ");
|
|
@@ -19316,7 +19529,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
19316
19529
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
19317
19530
|
return { end: start + r.read, written: r.written };
|
|
19318
19531
|
}
|
|
19319
|
-
function merge2(src, blocks,
|
|
19532
|
+
function merge2(src, blocks, join27, cap, lineCut) {
|
|
19320
19533
|
const out = [];
|
|
19321
19534
|
const scratch = new Uint8Array(cap);
|
|
19322
19535
|
let wide;
|
|
@@ -19326,7 +19539,7 @@ function merge2(src, blocks, join26, cap, lineCut) {
|
|
|
19326
19539
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
19327
19540
|
};
|
|
19328
19541
|
for (const b of blocks) {
|
|
19329
|
-
if (cur !== void 0 && !
|
|
19542
|
+
if (cur !== void 0 && !join27) {
|
|
19330
19543
|
emit(cur.start, cur.end, curBytes);
|
|
19331
19544
|
cur = void 0;
|
|
19332
19545
|
}
|
|
@@ -19768,7 +19981,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
19768
19981
|
}
|
|
19769
19982
|
|
|
19770
19983
|
// src/core/hooks/fallback.ts
|
|
19771
|
-
import { join as
|
|
19984
|
+
import { join as join7, resolve as resolve5 } from "node:path";
|
|
19772
19985
|
var fs = process.getBuiltinModule("node:fs");
|
|
19773
19986
|
function isRec(v) {
|
|
19774
19987
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -19796,9 +20009,9 @@ function homeOf(env) {
|
|
|
19796
20009
|
}
|
|
19797
20010
|
function hookLogPath(env) {
|
|
19798
20011
|
const dir = env[DATA_DIR_ENV];
|
|
19799
|
-
if (dir !== void 0 && dir !== "") return
|
|
20012
|
+
if (dir !== void 0 && dir !== "") return join7(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
19800
20013
|
const home = homeOf(env);
|
|
19801
|
-
return home === "" ? "" :
|
|
20014
|
+
return home === "" ? "" : join7(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
19802
20015
|
}
|
|
19803
20016
|
function errorLabel(err) {
|
|
19804
20017
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -19809,7 +20022,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
19809
20022
|
try {
|
|
19810
20023
|
const file2 = hookLogPath(env);
|
|
19811
20024
|
if (file2 === "") return;
|
|
19812
|
-
fs.mkdirSync(
|
|
20025
|
+
fs.mkdirSync(join7(file2, ".."), { recursive: true });
|
|
19813
20026
|
const line = JSON.stringify({
|
|
19814
20027
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19815
20028
|
agent,
|
|
@@ -19891,7 +20104,7 @@ function bigFile(abs) {
|
|
|
19891
20104
|
function bigRead(agent, input, cwd) {
|
|
19892
20105
|
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
19893
20106
|
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
19894
|
-
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)));
|
|
20107
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)) && !isOwnFile(agent, resolve5(cwd, p)));
|
|
19895
20108
|
}
|
|
19896
20109
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
19897
20110
|
const row5 = getAdapter(agent);
|
|
@@ -19917,7 +20130,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
19917
20130
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
19918
20131
|
|
|
19919
20132
|
// src/core/hooks/dispatch.ts
|
|
19920
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
20133
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync5 } = process.getBuiltinModule("node:fs");
|
|
19921
20134
|
var ALLOW2 = { kind: "allow" };
|
|
19922
20135
|
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
19923
20136
|
var DIGIT_0 = 48;
|
|
@@ -20080,8 +20293,7 @@ async function recall(ev, row5, project, prompt) {
|
|
|
20080
20293
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
20081
20294
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
20082
20295
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
20083
|
-
const
|
|
20084
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt, goal), RECALL_UNIT_CANDIDATES);
|
|
20296
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
20085
20297
|
const picked = pickRecall(readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS), prompt, new Set(seen), units, new Set(seenUnits));
|
|
20086
20298
|
if (picked.text === "") return ALLOW2;
|
|
20087
20299
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
@@ -20153,7 +20365,7 @@ function askDetached(ev, project, tool, text) {
|
|
|
20153
20365
|
}
|
|
20154
20366
|
async function preToolUse(ev, row5, project, env) {
|
|
20155
20367
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
20156
|
-
const decision0 = decide(ev, row5, userDeny);
|
|
20368
|
+
const decision0 = decide(ev, row5, userDeny, project);
|
|
20157
20369
|
let decision = decision0;
|
|
20158
20370
|
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
20159
20371
|
const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
|
|
@@ -20179,7 +20391,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
20179
20391
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
20180
20392
|
const command = tool.input.command;
|
|
20181
20393
|
if (typeof command !== "string") return d0;
|
|
20182
|
-
const wrapper = '"' +
|
|
20394
|
+
const wrapper = '"' + join8(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
20183
20395
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
20184
20396
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
20185
20397
|
}
|
|
@@ -20256,9 +20468,15 @@ async function postToolUse(ev, row5, project, env, settle3) {
|
|
|
20256
20468
|
settle3.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
|
|
20257
20469
|
return decision;
|
|
20258
20470
|
}
|
|
20471
|
+
function ownRead(ev, tool, env) {
|
|
20472
|
+
if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
20473
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
20474
|
+
return p !== void 0 && isOwnFile(ev.agent, resolve6(ev.cwd, p), env);
|
|
20475
|
+
}
|
|
20259
20476
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
20260
20477
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
20261
20478
|
if (boundedRead(tool)) return ALLOW2;
|
|
20479
|
+
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
20262
20480
|
if (result.keep === true) return ALLOW2;
|
|
20263
20481
|
if (!hasReplace(row5)) return ALLOW2;
|
|
20264
20482
|
let label2;
|
|
@@ -20301,7 +20519,7 @@ function replaceBudget(handleLine, more) {
|
|
|
20301
20519
|
}
|
|
20302
20520
|
function hostToolResult(file2, sessionId, env) {
|
|
20303
20521
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
20304
|
-
const projects =
|
|
20522
|
+
const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
20305
20523
|
const steps = relative3(projects, resolve6(file2)).split(sep3);
|
|
20306
20524
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
20307
20525
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -20316,7 +20534,7 @@ function wholeOutput(result, sessionId, env) {
|
|
|
20316
20534
|
logHookError(env, "claude-code", "persisted-output", new Error("persisted output path is outside this session's tool-results dir or too large; kept the head"));
|
|
20317
20535
|
return head2;
|
|
20318
20536
|
}
|
|
20319
|
-
return
|
|
20537
|
+
return readFileSync5(result.persistedPath, "utf8");
|
|
20320
20538
|
} catch {
|
|
20321
20539
|
return head2;
|
|
20322
20540
|
}
|
|
@@ -20508,11 +20726,11 @@ function noRuntimeError(lang) {
|
|
|
20508
20726
|
}
|
|
20509
20727
|
|
|
20510
20728
|
// src/core/sandbox/spawn.ts
|
|
20511
|
-
import { spawn } from "node:child_process";
|
|
20729
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
20512
20730
|
import path2 from "node:path";
|
|
20513
20731
|
|
|
20514
20732
|
// src/core/sandbox/kill.ts
|
|
20515
|
-
import {
|
|
20733
|
+
import { spawn } from "node:child_process";
|
|
20516
20734
|
function signalGroup(pid, signal) {
|
|
20517
20735
|
try {
|
|
20518
20736
|
process.kill(-pid, signal);
|
|
@@ -20526,7 +20744,10 @@ function killTree(pid) {
|
|
|
20526
20744
|
return;
|
|
20527
20745
|
}
|
|
20528
20746
|
try {
|
|
20529
|
-
|
|
20747
|
+
const t = spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
|
|
20748
|
+
t.on("error", () => {
|
|
20749
|
+
});
|
|
20750
|
+
t.unref();
|
|
20530
20751
|
} catch {
|
|
20531
20752
|
}
|
|
20532
20753
|
}
|
|
@@ -20545,7 +20766,7 @@ function runProcess(argv, o) {
|
|
|
20545
20766
|
if (start === null) return resolve10(NOT_STARTED);
|
|
20546
20767
|
let child;
|
|
20547
20768
|
try {
|
|
20548
|
-
child =
|
|
20769
|
+
child = spawn2(start[0], start.slice(1), {
|
|
20549
20770
|
cwd: o.cwd,
|
|
20550
20771
|
env: o.env,
|
|
20551
20772
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -20562,8 +20783,14 @@ function runProcess(argv, o) {
|
|
|
20562
20783
|
const stderrChunks = [];
|
|
20563
20784
|
let killedBy = null;
|
|
20564
20785
|
let settled = false;
|
|
20786
|
+
let held = false;
|
|
20787
|
+
let exited = false;
|
|
20788
|
+
let graceTimer;
|
|
20789
|
+
let drainTimer;
|
|
20790
|
+
let stopTimer;
|
|
20565
20791
|
const kill = () => {
|
|
20566
20792
|
if (child.pid !== void 0) killTree(child.pid);
|
|
20793
|
+
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
|
|
20567
20794
|
};
|
|
20568
20795
|
const onAbort = () => {
|
|
20569
20796
|
if (killedBy !== null || settled) return;
|
|
@@ -20580,17 +20807,46 @@ function runProcess(argv, o) {
|
|
|
20580
20807
|
if (settled) return;
|
|
20581
20808
|
settled = true;
|
|
20582
20809
|
clearTimeout(timer);
|
|
20810
|
+
clearTimeout(graceTimer);
|
|
20811
|
+
clearTimeout(drainTimer);
|
|
20812
|
+
clearTimeout(stopTimer);
|
|
20583
20813
|
o.signal.removeEventListener("abort", onAbort);
|
|
20584
20814
|
resolve10({
|
|
20585
20815
|
stdout: Buffer.concat(stdoutChunks),
|
|
20586
20816
|
stderr: Buffer.concat(stderrChunks),
|
|
20587
20817
|
exitCode,
|
|
20588
|
-
killed: killedBy
|
|
20818
|
+
killed: killedBy,
|
|
20819
|
+
...held ? { held: true } : {}
|
|
20589
20820
|
});
|
|
20590
20821
|
};
|
|
20591
|
-
|
|
20592
|
-
|
|
20822
|
+
const finishHeld = () => {
|
|
20823
|
+
if (settled) return;
|
|
20824
|
+
held = exited && killedBy === null;
|
|
20825
|
+
child.stdout.destroy();
|
|
20826
|
+
child.stderr.destroy();
|
|
20827
|
+
if (child.pid !== void 0) killTree(child.pid);
|
|
20828
|
+
settle3(child.exitCode);
|
|
20829
|
+
};
|
|
20830
|
+
const bump = () => {
|
|
20831
|
+
if (!exited || settled) return;
|
|
20832
|
+
clearTimeout(graceTimer);
|
|
20833
|
+
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
20834
|
+
};
|
|
20835
|
+
child.stdout.on("data", (chunk) => {
|
|
20836
|
+
stdoutChunks.push(chunk);
|
|
20837
|
+
bump();
|
|
20838
|
+
});
|
|
20839
|
+
child.stderr.on("data", (chunk) => {
|
|
20840
|
+
stderrChunks.push(chunk);
|
|
20841
|
+
bump();
|
|
20842
|
+
});
|
|
20593
20843
|
child.on("close", (code) => settle3(code));
|
|
20844
|
+
child.on("exit", () => {
|
|
20845
|
+
if (settled) return;
|
|
20846
|
+
exited = true;
|
|
20847
|
+
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
20848
|
+
drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
|
|
20849
|
+
});
|
|
20594
20850
|
child.on("error", () => settle3(null));
|
|
20595
20851
|
child.stdin.on("error", () => {
|
|
20596
20852
|
});
|
|
@@ -20602,8 +20858,8 @@ function runProcess(argv, o) {
|
|
|
20602
20858
|
}
|
|
20603
20859
|
|
|
20604
20860
|
// src/core/index/auto-memory.ts
|
|
20605
|
-
import { readdirSync, readFileSync as
|
|
20606
|
-
import { join as
|
|
20861
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
|
|
20862
|
+
import { join as join9 } from "node:path";
|
|
20607
20863
|
var MEMORY_FILES = Object.freeze([
|
|
20608
20864
|
Object.freeze(["CLAUDE.md"]),
|
|
20609
20865
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20617,7 +20873,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20617
20873
|
var MD = ".md";
|
|
20618
20874
|
function steeringFiles(worktree) {
|
|
20619
20875
|
try {
|
|
20620
|
-
return
|
|
20876
|
+
return readdirSync2(join9(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20621
20877
|
} catch {
|
|
20622
20878
|
return [];
|
|
20623
20879
|
}
|
|
@@ -20625,7 +20881,7 @@ function steeringFiles(worktree) {
|
|
|
20625
20881
|
function readAutoMemory(project) {
|
|
20626
20882
|
const rows = [];
|
|
20627
20883
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20628
|
-
const path8 =
|
|
20884
|
+
const path8 = join9(project.worktree, ...segs);
|
|
20629
20885
|
if (!isInside(project.worktree, path8)) continue;
|
|
20630
20886
|
try {
|
|
20631
20887
|
const st = statSync4(path8);
|
|
@@ -20637,7 +20893,7 @@ function readAutoMemory(project) {
|
|
|
20637
20893
|
sourceId: null,
|
|
20638
20894
|
path: path8,
|
|
20639
20895
|
label: segs.join("/"),
|
|
20640
|
-
text:
|
|
20896
|
+
text: readFileSync6(path8, "utf8")
|
|
20641
20897
|
});
|
|
20642
20898
|
} catch {
|
|
20643
20899
|
}
|
|
@@ -21207,19 +21463,19 @@ var ctxBatch = Object.freeze({
|
|
|
21207
21463
|
});
|
|
21208
21464
|
|
|
21209
21465
|
// src/core/tools/doctor.ts
|
|
21210
|
-
import { readdirSync as
|
|
21211
|
-
import { basename as basename5, join as
|
|
21466
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync16, existsSync as existsSync16 } from "node:fs";
|
|
21467
|
+
import { basename as basename5, join as join19 } from "node:path";
|
|
21212
21468
|
|
|
21213
21469
|
// src/core/ops/bundle-dir.ts
|
|
21214
|
-
import { existsSync as
|
|
21215
|
-
import { dirname as dirname5, join as
|
|
21470
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
21471
|
+
import { dirname as dirname5, join as join10 } from "node:path";
|
|
21216
21472
|
import { fileURLToPath } from "node:url";
|
|
21217
21473
|
function bundleDirOf(argv1, moduleFile) {
|
|
21218
21474
|
const own4 = dirname5(argv1);
|
|
21219
|
-
if (
|
|
21475
|
+
if (existsSync4(join10(own4, SERVER_ENTRY_FILE))) return own4;
|
|
21220
21476
|
let dir = dirname5(moduleFile);
|
|
21221
21477
|
for (; ; ) {
|
|
21222
|
-
if (
|
|
21478
|
+
if (existsSync4(join10(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21223
21479
|
const up = dirname5(dir);
|
|
21224
21480
|
if (up === dir) return own4;
|
|
21225
21481
|
dir = up;
|
|
@@ -21233,17 +21489,17 @@ function ownBundleDir() {
|
|
|
21233
21489
|
}
|
|
21234
21490
|
|
|
21235
21491
|
// src/core/ops/doctor-config.ts
|
|
21236
|
-
import { existsSync as
|
|
21237
|
-
import { join as
|
|
21492
|
+
import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "node:fs";
|
|
21493
|
+
import { dirname as dirname8, join as join14 } from "node:path";
|
|
21238
21494
|
|
|
21239
21495
|
// src/core/ops/detect-v1.ts
|
|
21240
|
-
import { existsSync as
|
|
21496
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "node:fs";
|
|
21241
21497
|
import { tmpdir } from "node:os";
|
|
21242
|
-
import { join as
|
|
21498
|
+
import { join as join12 } from "node:path";
|
|
21243
21499
|
|
|
21244
21500
|
// src/core/ops/host-config.ts
|
|
21245
|
-
import { existsSync as
|
|
21246
|
-
import { dirname as dirname6, join as
|
|
21501
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
|
|
21502
|
+
import { dirname as dirname6, join as join11 } from "node:path";
|
|
21247
21503
|
|
|
21248
21504
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21249
21505
|
var KEYS2 = {
|
|
@@ -23360,10 +23616,10 @@ function formatOf(path8) {
|
|
|
23360
23616
|
function readHostConfig(agent, path8) {
|
|
23361
23617
|
let file2 = path8;
|
|
23362
23618
|
if (agent === "opencode") {
|
|
23363
|
-
const jsonc =
|
|
23364
|
-
if (
|
|
23619
|
+
const jsonc = join11(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23620
|
+
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23365
23621
|
}
|
|
23366
|
-
const raw =
|
|
23622
|
+
const raw = existsSync5(file2) ? readFileSync7(file2, "utf8") : "";
|
|
23367
23623
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23368
23624
|
}
|
|
23369
23625
|
function stripJsonComments(text) {
|
|
@@ -23708,7 +23964,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23708
23964
|
}
|
|
23709
23965
|
}
|
|
23710
23966
|
function serverScript() {
|
|
23711
|
-
return
|
|
23967
|
+
return join11(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23712
23968
|
}
|
|
23713
23969
|
function isNodeCommand(command) {
|
|
23714
23970
|
if (typeof command !== "string") return false;
|
|
@@ -23835,14 +24091,14 @@ function stripJsonc(text) {
|
|
|
23835
24091
|
}
|
|
23836
24092
|
function readJson(file2) {
|
|
23837
24093
|
try {
|
|
23838
|
-
return JSON.parse(stripJsonc(hostText(
|
|
24094
|
+
return JSON.parse(stripJsonc(hostText(readFileSync8(file2, "utf8"))));
|
|
23839
24095
|
} catch {
|
|
23840
24096
|
return void 0;
|
|
23841
24097
|
}
|
|
23842
24098
|
}
|
|
23843
24099
|
function readText(file2) {
|
|
23844
24100
|
try {
|
|
23845
|
-
return hostText(
|
|
24101
|
+
return hostText(readFileSync8(file2, "utf8"));
|
|
23846
24102
|
} catch {
|
|
23847
24103
|
return "";
|
|
23848
24104
|
}
|
|
@@ -23899,7 +24155,7 @@ function flatCommands(events, prefix) {
|
|
|
23899
24155
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23900
24156
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
|
|
23901
24157
|
function dataDir(dir, reason, out) {
|
|
23902
|
-
if (
|
|
24158
|
+
if (existsSync6(dir)) out.push(finding(dir, "", reason));
|
|
23903
24159
|
}
|
|
23904
24160
|
function mcpEntry(file2, doc, out) {
|
|
23905
24161
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -23907,7 +24163,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23907
24163
|
}
|
|
23908
24164
|
}
|
|
23909
24165
|
function claudeShapeSettings(agentHome, out) {
|
|
23910
|
-
const file2 =
|
|
24166
|
+
const file2 = join12(agentHome, SETTINGS_FILE);
|
|
23911
24167
|
const doc = readJson(file2);
|
|
23912
24168
|
for (const c of nestedCommands(doc)) {
|
|
23913
24169
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23927,63 +24183,64 @@ function v1HookFile(file2, out) {
|
|
|
23927
24183
|
function scanClaudeCode(home, agentHome, out) {
|
|
23928
24184
|
claudeShapeSettings(agentHome, out);
|
|
23929
24185
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23930
|
-
const file2 =
|
|
23931
|
-
if (
|
|
24186
|
+
const file2 = join12(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24187
|
+
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23932
24188
|
}
|
|
23933
|
-
const userFile =
|
|
24189
|
+
const userFile = join12(home, CLAUDE_USER_CONFIG_FILE);
|
|
23934
24190
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23935
|
-
dataDir(
|
|
24191
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23936
24192
|
}
|
|
23937
24193
|
function scanCodex(agentHome, out) {
|
|
23938
|
-
const hooksFile =
|
|
24194
|
+
const hooksFile = join12(agentHome, HOOKS_JSON_FILE);
|
|
23939
24195
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23940
24196
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23941
24197
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23942
24198
|
}
|
|
23943
24199
|
}
|
|
23944
|
-
const tomlFile =
|
|
24200
|
+
const tomlFile = join12(agentHome, CONFIG_TOML_FILE);
|
|
23945
24201
|
const config4 = readTomlValue(tomlFile);
|
|
23946
24202
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23947
24203
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23948
24204
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
24205
|
+
if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config4, span2.path.slice(0, 2)))) continue;
|
|
23949
24206
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23950
24207
|
}
|
|
23951
|
-
dataDir(
|
|
24208
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23952
24209
|
}
|
|
23953
24210
|
function scanGemini(agentHome, out) {
|
|
23954
|
-
const file2 =
|
|
24211
|
+
const file2 = join12(agentHome, SETTINGS_FILE);
|
|
23955
24212
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23956
24213
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23957
24214
|
}
|
|
23958
|
-
dataDir(
|
|
24215
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23959
24216
|
}
|
|
23960
24217
|
function scanVscode(agentHome, project, out) {
|
|
23961
24218
|
if (project !== void 0) {
|
|
23962
|
-
v1HookFile(
|
|
23963
|
-
const mcpFile2 =
|
|
24219
|
+
v1HookFile(join12(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24220
|
+
const mcpFile2 = join12(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
23964
24221
|
const doc = readJson(mcpFile2);
|
|
23965
24222
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23966
24223
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23967
24224
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23968
24225
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23969
24226
|
}
|
|
23970
|
-
const sessions =
|
|
24227
|
+
const sessions = join12(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
23971
24228
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
23972
24229
|
}
|
|
23973
|
-
dataDir(
|
|
24230
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23974
24231
|
}
|
|
23975
24232
|
function jsonFiles(dir) {
|
|
23976
24233
|
try {
|
|
23977
|
-
return
|
|
24234
|
+
return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
23978
24235
|
} catch {
|
|
23979
24236
|
return [];
|
|
23980
24237
|
}
|
|
23981
24238
|
}
|
|
23982
24239
|
function scanKiro(agentHome, project, out) {
|
|
23983
|
-
const agentsDir =
|
|
23984
|
-
const defaultFile =
|
|
24240
|
+
const agentsDir = join12(agentHome, KIRO_AGENTS_DIR);
|
|
24241
|
+
const defaultFile = join12(agentHome, ...KIRO_AGENT_FILE);
|
|
23985
24242
|
for (const name of jsonFiles(agentsDir)) {
|
|
23986
|
-
const file2 =
|
|
24243
|
+
const file2 = join12(agentsDir, name);
|
|
23987
24244
|
const doc = readJson(file2);
|
|
23988
24245
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23989
24246
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23994,31 +24251,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
23994
24251
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23995
24252
|
}
|
|
23996
24253
|
}
|
|
23997
|
-
const steeringDocs = [
|
|
23998
|
-
if (project !== void 0) steeringDocs.push(
|
|
24254
|
+
const steeringDocs = [join12(agentHome, ...KIRO_STEERING_FILE)];
|
|
24255
|
+
if (project !== void 0) steeringDocs.push(join12(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
23999
24256
|
for (const file2 of steeringDocs) {
|
|
24000
|
-
if (
|
|
24257
|
+
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
24001
24258
|
}
|
|
24002
|
-
dataDir(
|
|
24259
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24003
24260
|
}
|
|
24004
24261
|
function piNpmIsCurrent(piAgentDir) {
|
|
24005
|
-
const doc = readJson(
|
|
24262
|
+
const doc = readJson(join12(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
24006
24263
|
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
24007
24264
|
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
24008
24265
|
}
|
|
24009
24266
|
function scanPi(piAgentDir, agentHome, out) {
|
|
24010
|
-
const file2 =
|
|
24267
|
+
const file2 = join12(piAgentDir, SETTINGS_FILE);
|
|
24011
24268
|
const doc = readJson(file2);
|
|
24012
24269
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
24013
24270
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
24014
24271
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
24015
24272
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
24016
24273
|
});
|
|
24017
|
-
dataDir(
|
|
24274
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24018
24275
|
}
|
|
24019
24276
|
function scanOpencode(agentHome, out) {
|
|
24020
24277
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
24021
|
-
const file2 =
|
|
24278
|
+
const file2 = join12(agentHome, name);
|
|
24022
24279
|
const doc = readJson(file2);
|
|
24023
24280
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
24024
24281
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -24029,13 +24286,13 @@ function scanOpencode(agentHome, out) {
|
|
|
24029
24286
|
}
|
|
24030
24287
|
}
|
|
24031
24288
|
function scanZcode(agentHome, out) {
|
|
24032
|
-
const configFile =
|
|
24289
|
+
const configFile = join12(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
24033
24290
|
const config4 = readJson(configFile);
|
|
24034
24291
|
const events = isObj(config4) && isObj(config4[HOOKS_KEY]) ? config4[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
24035
24292
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
24036
24293
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
24037
24294
|
}
|
|
24038
|
-
const hooksFile =
|
|
24295
|
+
const hooksFile = join12(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
24039
24296
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24040
24297
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
24041
24298
|
}
|
|
@@ -24059,14 +24316,14 @@ function firstTmpMatch(dir) {
|
|
|
24059
24316
|
}
|
|
24060
24317
|
}
|
|
24061
24318
|
function scanAll(home, tmp, out) {
|
|
24062
|
-
const root =
|
|
24063
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
24319
|
+
const root = join12(home, DATA_ROOT.slice(1));
|
|
24320
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join12(root, name), V1_REASON.dataRoot, out);
|
|
24064
24321
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
24065
24322
|
}
|
|
24066
24323
|
function detectV1(agent, home, scope = {}) {
|
|
24067
24324
|
const out = [];
|
|
24068
24325
|
const project = scope.project;
|
|
24069
|
-
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir :
|
|
24326
|
+
const agentHome = agent === "claude-code" && scope.claudeDir !== void 0 ? scope.claudeDir : agent === "codex" && scope.codexDir !== void 0 ? scope.codexDir : agent === "gemini" && scope.geminiDir !== void 0 ? scope.geminiDir : agent === "copilot-cli" && scope.copilotDir !== void 0 ? scope.copilotDir : agent === "kiro" && scope.kiroDir !== void 0 ? scope.kiroDir : agent === "opencode" && scope.opencodeDir !== void 0 ? scope.opencodeDir : join12(home, ...AGENT_HOME_DIR[agent]);
|
|
24070
24327
|
switch (agent) {
|
|
24071
24328
|
case "claude-code":
|
|
24072
24329
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -24079,11 +24336,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24079
24336
|
break;
|
|
24080
24337
|
case "qwen":
|
|
24081
24338
|
claudeShapeSettings(agentHome, out);
|
|
24082
|
-
dataDir(
|
|
24339
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24083
24340
|
break;
|
|
24084
24341
|
case "copilot-cli":
|
|
24085
|
-
v1HookFile(
|
|
24086
|
-
dataDir(
|
|
24342
|
+
v1HookFile(join12(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24343
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24087
24344
|
break;
|
|
24088
24345
|
case "vscode":
|
|
24089
24346
|
scanVscode(agentHome, project, out);
|
|
@@ -24092,7 +24349,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24092
24349
|
scanKiro(agentHome, project, out);
|
|
24093
24350
|
break;
|
|
24094
24351
|
case "pi":
|
|
24095
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24352
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join12(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
24096
24353
|
break;
|
|
24097
24354
|
// D-WIN-PIDIR-1: empty is unset
|
|
24098
24355
|
case "opencode":
|
|
@@ -24107,8 +24364,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24107
24364
|
}
|
|
24108
24365
|
|
|
24109
24366
|
// src/core/ops/plugin-root.ts
|
|
24110
|
-
import { existsSync as
|
|
24111
|
-
import { dirname as dirname7, isAbsolute as isAbsolute2, join as
|
|
24367
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
24368
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join13, sep as sep4 } from "node:path";
|
|
24112
24369
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24113
24370
|
function missing(agent, path8) {
|
|
24114
24371
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24149,15 +24406,15 @@ var realOrNull = (path8) => {
|
|
|
24149
24406
|
};
|
|
24150
24407
|
var readOrNull = (file2) => {
|
|
24151
24408
|
try {
|
|
24152
|
-
return
|
|
24409
|
+
return readFileSync9(file2, "utf8");
|
|
24153
24410
|
} catch {
|
|
24154
24411
|
return null;
|
|
24155
24412
|
}
|
|
24156
24413
|
};
|
|
24157
24414
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24158
24415
|
function enabledPlugins(claudeDir, project) {
|
|
24159
|
-
const files = [
|
|
24160
|
-
if (project !== void 0) files.push(
|
|
24416
|
+
const files = [join13(claudeDir, SETTINGS_FILE)];
|
|
24417
|
+
if (project !== void 0) files.push(join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
24161
24418
|
const out = {};
|
|
24162
24419
|
for (const file2 of files) {
|
|
24163
24420
|
const text = readOrNull(file2);
|
|
@@ -24173,10 +24430,10 @@ function marketplaceChoice(env, worktree) {
|
|
|
24173
24430
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24174
24431
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24175
24432
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24176
|
-
const record6 = readOrNull(
|
|
24433
|
+
const record6 = readOrNull(join13(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24177
24434
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
24178
24435
|
if (recorded.length === 0) return { record: false };
|
|
24179
|
-
const live = recorded.filter((r) =>
|
|
24436
|
+
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
24180
24437
|
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
24181
24438
|
if (mine !== void 0) return { root: mine.installPath };
|
|
24182
24439
|
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
@@ -24196,18 +24453,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24196
24453
|
}
|
|
24197
24454
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24198
24455
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24199
|
-
const plugins =
|
|
24200
|
-
const cache =
|
|
24456
|
+
const plugins = join13(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24457
|
+
const cache = join13(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24201
24458
|
const script = process.argv[1];
|
|
24202
24459
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24203
24460
|
const choice = marketplaceChoice(env, worktree);
|
|
24204
24461
|
if ("root" in choice) return choice.root;
|
|
24205
24462
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24206
24463
|
const cacheReal = realOrNull(cache);
|
|
24207
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) &&
|
|
24208
|
-
const pattern =
|
|
24209
|
-
if (!
|
|
24210
|
-
const found =
|
|
24464
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join13(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24465
|
+
const pattern = join13(cache, "*", PLUGIN_NAME);
|
|
24466
|
+
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24467
|
+
const found = readdirSync4(cache).sort().map((marketplace) => join13(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24211
24468
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24212
24469
|
return found[0];
|
|
24213
24470
|
}
|
|
@@ -24215,7 +24472,7 @@ function configEntryRoot(adapter, env) {
|
|
|
24215
24472
|
const spec = OWN_MCP_ENTRY[adapter.id];
|
|
24216
24473
|
if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
|
|
24217
24474
|
const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
|
|
24218
|
-
if (!
|
|
24475
|
+
if (!existsSync7(file2)) throw missing(adapter.id, file2);
|
|
24219
24476
|
const current = readHostConfig(adapter.id, file2);
|
|
24220
24477
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24221
24478
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
@@ -24232,9 +24489,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24232
24489
|
case "hooks+mcp":
|
|
24233
24490
|
return configEntryRoot(adapter, env);
|
|
24234
24491
|
case "extension":
|
|
24235
|
-
return
|
|
24492
|
+
return join13(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join13(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24236
24493
|
case "plugin":
|
|
24237
|
-
return
|
|
24494
|
+
return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24238
24495
|
case "in-process":
|
|
24239
24496
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
24240
24497
|
}
|
|
@@ -24249,7 +24506,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24249
24506
|
}
|
|
24250
24507
|
|
|
24251
24508
|
// src/setup/pi-gate.ts
|
|
24252
|
-
import { existsSync as
|
|
24509
|
+
import { existsSync as existsSync8, readFileSync as readFileSync10, realpathSync as realpathSync5 } from "node:fs";
|
|
24253
24510
|
import path4 from "node:path";
|
|
24254
24511
|
var EXTENSIONS_KEY = "extensions";
|
|
24255
24512
|
var PROJECT_DIR = ".pi";
|
|
@@ -24257,9 +24514,9 @@ var TRUST_FILE = "trust.json";
|
|
|
24257
24514
|
var ALWAYS = "always";
|
|
24258
24515
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
24259
24516
|
function load(file2) {
|
|
24260
|
-
if (!
|
|
24517
|
+
if (!existsSync8(file2)) return void 0;
|
|
24261
24518
|
try {
|
|
24262
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
24519
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync10(file2, "utf8")), "json") };
|
|
24263
24520
|
} catch {
|
|
24264
24521
|
return void 0;
|
|
24265
24522
|
}
|
|
@@ -24394,11 +24651,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24394
24651
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24395
24652
|
function mcpFile(row5, home, env) {
|
|
24396
24653
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24397
|
-
if (row5.id === "codex") return
|
|
24654
|
+
if (row5.id === "codex") return join14(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24398
24655
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24399
|
-
if (row5.id === "opencode") return
|
|
24656
|
+
if (row5.id === "opencode") return join14(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24400
24657
|
if (row5.id === "pi") {
|
|
24401
|
-
return
|
|
24658
|
+
return join14(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24402
24659
|
}
|
|
24403
24660
|
return null;
|
|
24404
24661
|
}
|
|
@@ -24411,27 +24668,27 @@ function codexNativeDir(env, home) {
|
|
|
24411
24668
|
const codexDir = codexDirOf(env, home);
|
|
24412
24669
|
let enabled;
|
|
24413
24670
|
try {
|
|
24414
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24671
|
+
enabled = hostConfigValueAt(readParsed("codex", join14(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24415
24672
|
} catch {
|
|
24416
24673
|
return null;
|
|
24417
24674
|
}
|
|
24418
24675
|
if (enabled !== true) return null;
|
|
24419
|
-
const cache =
|
|
24420
|
-
if (!
|
|
24676
|
+
const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24677
|
+
if (!existsSync9(cache)) return null;
|
|
24421
24678
|
const found = [];
|
|
24422
|
-
for (const market of
|
|
24423
|
-
const plugin =
|
|
24424
|
-
if (!
|
|
24425
|
-
for (const version4 of
|
|
24426
|
-
const dir =
|
|
24427
|
-
if (
|
|
24679
|
+
for (const market of readdirSync5(cache)) {
|
|
24680
|
+
const plugin = join14(cache, market, SERVER_KEY);
|
|
24681
|
+
if (!existsSync9(plugin)) continue;
|
|
24682
|
+
for (const version4 of readdirSync5(plugin).sort()) {
|
|
24683
|
+
const dir = join14(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
24684
|
+
if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24428
24685
|
}
|
|
24429
24686
|
}
|
|
24430
24687
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24431
24688
|
}
|
|
24432
24689
|
function nativeMcpWrong(dir, row5) {
|
|
24433
24690
|
try {
|
|
24434
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
24691
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join14(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24435
24692
|
if (!isObject4(entry)) return true;
|
|
24436
24693
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24437
24694
|
const script = args[0];
|
|
@@ -24441,7 +24698,7 @@ function nativeMcpWrong(dir, row5) {
|
|
|
24441
24698
|
}
|
|
24442
24699
|
}
|
|
24443
24700
|
function isOwnOpencodeEntry(entry, key, own4) {
|
|
24444
|
-
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
|
|
24701
|
+
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : Array.isArray(entry) ? entry[0] : entry;
|
|
24445
24702
|
if (typeof spec !== "string") return false;
|
|
24446
24703
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own4.includes(spec)) return true;
|
|
24447
24704
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
@@ -24452,14 +24709,21 @@ function opencodeMcpOwn(entry) {
|
|
|
24452
24709
|
const [node3, script, flag, agent] = cmd;
|
|
24453
24710
|
return isNodeCommand(node3) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
24454
24711
|
}
|
|
24455
|
-
function
|
|
24456
|
-
|
|
24712
|
+
function opencodeFileValue(file2) {
|
|
24713
|
+
if (!existsSync9(file2)) return {};
|
|
24714
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync11(file2, "utf8")), "jsonc");
|
|
24715
|
+
}
|
|
24716
|
+
function opencodeValueListed(value) {
|
|
24457
24717
|
const bundle = opencodePluginFile();
|
|
24458
|
-
const own4 = [bundle,
|
|
24718
|
+
const own4 = [bundle, join14(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24459
24719
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own4)))) return true;
|
|
24460
24720
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24461
24721
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
24462
24722
|
}
|
|
24723
|
+
function opencodeListed(file2, worktree) {
|
|
24724
|
+
const dirs = [dirname8(file2), worktree];
|
|
24725
|
+
return dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join14(dir, name)))));
|
|
24726
|
+
}
|
|
24463
24727
|
function mcpWrong(row5, home, env, worktree) {
|
|
24464
24728
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24465
24729
|
if (native !== null) return nativeMcpWrong(native, row5);
|
|
@@ -24469,7 +24733,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24469
24733
|
resolvePluginRoot(row5, env, worktree);
|
|
24470
24734
|
return false;
|
|
24471
24735
|
}
|
|
24472
|
-
if (row5.id === "opencode") return !opencodeListed(file2);
|
|
24736
|
+
if (row5.id === "opencode") return !opencodeListed(file2, worktree);
|
|
24473
24737
|
const cur = readHostConfig(row5.id, file2);
|
|
24474
24738
|
return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
|
|
24475
24739
|
} catch {
|
|
@@ -24479,7 +24743,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24479
24743
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24480
24744
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24481
24745
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24482
|
-
const file2 = native !== null ?
|
|
24746
|
+
const file2 = native !== null ? join14(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join14(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join14(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join14(kiroDirOf(env, home), ...spec.file.slice(1)) : join14(root, ...spec.file);
|
|
24483
24747
|
return file2;
|
|
24484
24748
|
}
|
|
24485
24749
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24490,7 +24754,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24490
24754
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24491
24755
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24492
24756
|
if (row5.id === "codex") {
|
|
24493
|
-
const config4 = readParsed(row5.id,
|
|
24757
|
+
const config4 = readParsed(row5.id, join14(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24494
24758
|
if (hostConfigValueAt(config4, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24495
24759
|
}
|
|
24496
24760
|
} catch {
|
|
@@ -24534,7 +24798,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24534
24798
|
function checkPiInstall(env, home, worktree) {
|
|
24535
24799
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24536
24800
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24537
|
-
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
24801
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join14(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24538
24802
|
}
|
|
24539
24803
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24540
24804
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24553,10 +24817,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24553
24817
|
}
|
|
24554
24818
|
function checkDoubleFire(agent, worktree) {
|
|
24555
24819
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24556
|
-
const claude = parsedOrNull(agent,
|
|
24820
|
+
const claude = parsedOrNull(agent, join14(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24557
24821
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24558
24822
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24559
|
-
const vscode = parsedOrNull(agent,
|
|
24823
|
+
const vscode = parsedOrNull(agent, join14(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24560
24824
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24561
24825
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24562
24826
|
}
|
|
@@ -24567,7 +24831,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24567
24831
|
const mcp = mcpFile(row5, home, env);
|
|
24568
24832
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24569
24833
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24570
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
24834
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join14(native, CODEX_PLUGIN_MCP_FILE) });
|
|
24571
24835
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24572
24836
|
if (spec !== null) {
|
|
24573
24837
|
try {
|
|
@@ -24587,7 +24851,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24587
24851
|
}
|
|
24588
24852
|
|
|
24589
24853
|
// src/core/ops/doctor-db.ts
|
|
24590
|
-
import { existsSync as
|
|
24854
|
+
import { existsSync as existsSync10, statSync as statSync5 } from "node:fs";
|
|
24591
24855
|
var unknown2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
24592
24856
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
24593
24857
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -24629,15 +24893,15 @@ function orphanFiles(dbPath) {
|
|
|
24629
24893
|
const files = [];
|
|
24630
24894
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24631
24895
|
const path8 = dbPath + suffix;
|
|
24632
|
-
if (
|
|
24896
|
+
if (existsSync10(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
|
|
24633
24897
|
}
|
|
24634
|
-
return files.length > 0 && !
|
|
24898
|
+
return files.length > 0 && !existsSync10(dbPath) ? files : [];
|
|
24635
24899
|
}
|
|
24636
24900
|
async function checkDb(project) {
|
|
24637
24901
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24638
24902
|
const orphan = orphanFiles(project.dbPath);
|
|
24639
24903
|
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
24640
|
-
if (!
|
|
24904
|
+
if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
24641
24905
|
const sqlite = await loadSqlite2();
|
|
24642
24906
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
24643
24907
|
let raw = null;
|
|
@@ -24663,7 +24927,7 @@ async function checkDb(project) {
|
|
|
24663
24927
|
}
|
|
24664
24928
|
}
|
|
24665
24929
|
async function checkIndex(project) {
|
|
24666
|
-
if (!
|
|
24930
|
+
if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
24667
24931
|
const sqlite = await loadSqlite2();
|
|
24668
24932
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
24669
24933
|
let raw = null;
|
|
@@ -24680,8 +24944,8 @@ async function checkIndex(project) {
|
|
|
24680
24944
|
}
|
|
24681
24945
|
|
|
24682
24946
|
// src/core/ops/doctor-env.ts
|
|
24683
|
-
import { existsSync as
|
|
24684
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24947
|
+
import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
24948
|
+
import { isAbsolute as isAbsolute3, join as join15, relative as relative4 } from "node:path";
|
|
24685
24949
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
24686
24950
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
24687
24951
|
}
|
|
@@ -24691,9 +24955,12 @@ function unknown3(id, detail, fixCommand) {
|
|
|
24691
24955
|
function fail4(id, detail, fixCommand) {
|
|
24692
24956
|
return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
|
|
24693
24957
|
}
|
|
24958
|
+
function warn(id, detail, fixCommand) {
|
|
24959
|
+
return { id, label: DOCTOR_LABEL[id], status: "WARN", detail, fixCommand };
|
|
24960
|
+
}
|
|
24694
24961
|
function bundleVersion(bundleDir2) {
|
|
24695
24962
|
try {
|
|
24696
|
-
const v = JSON.parse(
|
|
24963
|
+
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24697
24964
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24698
24965
|
} catch {
|
|
24699
24966
|
return void 0;
|
|
@@ -24777,20 +25044,21 @@ function highestTag(stdout, tag2) {
|
|
|
24777
25044
|
}
|
|
24778
25045
|
return best;
|
|
24779
25046
|
}
|
|
24780
|
-
function versionRow(head2, installed, tag2, source, latest, tail) {
|
|
25047
|
+
function versionRow(head2, installed, tag2, source, latest, tail, update) {
|
|
24781
25048
|
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
24782
25049
|
if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
|
|
24783
25050
|
if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
24784
|
-
return
|
|
25051
|
+
return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
|
|
24785
25052
|
}
|
|
24786
25053
|
async function checkVersion(i) {
|
|
24787
25054
|
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
24788
25055
|
const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24789
25056
|
if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24790
25057
|
const tag2 = channelOf(i.version);
|
|
25058
|
+
const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
|
|
24791
25059
|
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24792
25060
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24793
|
-
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
25061
|
+
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
|
|
24794
25062
|
let cause = D1_GIT_MISSING;
|
|
24795
25063
|
if (git2 !== null) {
|
|
24796
25064
|
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
@@ -24801,7 +25069,7 @@ async function checkVersion(i) {
|
|
|
24801
25069
|
});
|
|
24802
25070
|
if (r.exitCode === 0 && r.killed === null) {
|
|
24803
25071
|
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
24804
|
-
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
|
|
25072
|
+
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
|
|
24805
25073
|
cause = D1_GIT_NO_TAG(tag2);
|
|
24806
25074
|
} else {
|
|
24807
25075
|
cause = gitCause(r, i.timeoutMs);
|
|
@@ -24837,13 +25105,14 @@ async function checkNode(i) {
|
|
|
24837
25105
|
if (!await sqliteLoads()) return fail4("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
|
|
24838
25106
|
return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
24839
25107
|
}
|
|
24840
|
-
function checkMcp(ctx) {
|
|
25108
|
+
function checkMcp(ctx, adapter) {
|
|
24841
25109
|
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
24842
25110
|
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
24843
|
-
|
|
25111
|
+
if (named2 || versioned) return pass3("D6");
|
|
25112
|
+
return adapter?.installMode === "in-process" ? pass3("D6", D6_IN_PROCESS_DETAIL) : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24844
25113
|
}
|
|
24845
25114
|
function piCwdInside(worktree, piCwd) {
|
|
24846
|
-
if (piCwd === void 0 || !
|
|
25115
|
+
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
24847
25116
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24848
25117
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24849
25118
|
}
|
|
@@ -24853,7 +25122,9 @@ function checkProject(i) {
|
|
|
24853
25122
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
24854
25123
|
return pass3("D7");
|
|
24855
25124
|
}
|
|
24856
|
-
function checkMode(adapter) {
|
|
25125
|
+
function checkMode(adapter, hostPermission) {
|
|
25126
|
+
if (hostPermission === "missing") return fail4("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
25127
|
+
if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
24857
25128
|
return pass3("D10", D10_DETAIL(adapter.denyChannel));
|
|
24858
25129
|
}
|
|
24859
25130
|
function checkShell(env) {
|
|
@@ -24864,7 +25135,7 @@ function checkShell(env) {
|
|
|
24864
25135
|
}
|
|
24865
25136
|
|
|
24866
25137
|
// src/core/ops/doctor-hook.ts
|
|
24867
|
-
import { existsSync as
|
|
25138
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync13, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24868
25139
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24869
25140
|
import path7 from "node:path";
|
|
24870
25141
|
|
|
@@ -26690,9 +26961,9 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
|
|
|
26690
26961
|
|
|
26691
26962
|
// src/setup/codex-trust.ts
|
|
26692
26963
|
import { createHash } from "node:crypto";
|
|
26693
|
-
import { existsSync as
|
|
26964
|
+
import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
|
|
26694
26965
|
import path6 from "node:path";
|
|
26695
|
-
import { spawn as
|
|
26966
|
+
import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
26696
26967
|
|
|
26697
26968
|
// src/setup/spawn-bin.ts
|
|
26698
26969
|
import { spawnSync } from "node:child_process";
|
|
@@ -26817,7 +27088,7 @@ function askPluginHooks(env, pluginId, cwd) {
|
|
|
26817
27088
|
resolve10({ kind: "silent" });
|
|
26818
27089
|
return;
|
|
26819
27090
|
}
|
|
26820
|
-
const child =
|
|
27091
|
+
const child = spawn3(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
26821
27092
|
let buf = "";
|
|
26822
27093
|
let done = false;
|
|
26823
27094
|
let exited = false;
|
|
@@ -26913,10 +27184,10 @@ function isObject6(v) {
|
|
|
26913
27184
|
}
|
|
26914
27185
|
function loadFixture(bundleDir2, agent) {
|
|
26915
27186
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
26916
|
-
if (!
|
|
27187
|
+
if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
26917
27188
|
let all;
|
|
26918
27189
|
try {
|
|
26919
|
-
all = JSON.parse(hostText(
|
|
27190
|
+
all = JSON.parse(hostText(readFileSync13(file2, "utf8")));
|
|
26920
27191
|
} catch (err) {
|
|
26921
27192
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
26922
27193
|
}
|
|
@@ -27029,6 +27300,35 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
27029
27300
|
rmSync2(home, { recursive: true, force: true });
|
|
27030
27301
|
}
|
|
27031
27302
|
}
|
|
27303
|
+
async function ownProbe(i, timeoutMs) {
|
|
27304
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
|
|
27305
|
+
try {
|
|
27306
|
+
const cfg = path7.join(home, ".claude");
|
|
27307
|
+
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27308
|
+
mkdirSync4(refs, { recursive: true });
|
|
27309
|
+
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27310
|
+
writeFileSync2(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27311
|
+
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27312
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27313
|
+
cwd: i.bundleDir,
|
|
27314
|
+
env: node3.env,
|
|
27315
|
+
signal: i.signal,
|
|
27316
|
+
timeoutMs,
|
|
27317
|
+
stdin: JSON.stringify({
|
|
27318
|
+
session_id: "d5-own-probe",
|
|
27319
|
+
transcript_path: "",
|
|
27320
|
+
cwd: home,
|
|
27321
|
+
hook_event_name: "PreToolUse",
|
|
27322
|
+
tool_name: "Read",
|
|
27323
|
+
tool_use_id: "toolu_d5_own_probe",
|
|
27324
|
+
tool_input: { file_path: filePath }
|
|
27325
|
+
})
|
|
27326
|
+
});
|
|
27327
|
+
return r.stdout.toString("utf8");
|
|
27328
|
+
} finally {
|
|
27329
|
+
rmSync2(home, { recursive: true, force: true });
|
|
27330
|
+
}
|
|
27331
|
+
}
|
|
27032
27332
|
function isDeny(stdout) {
|
|
27033
27333
|
if (stdout.trim() === "") return false;
|
|
27034
27334
|
let out;
|
|
@@ -27043,8 +27343,12 @@ async function readProbeDetail(i, timeoutMs) {
|
|
|
27043
27343
|
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
27044
27344
|
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
27045
27345
|
if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
|
|
27346
|
+
if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
|
|
27046
27347
|
return null;
|
|
27047
27348
|
}
|
|
27349
|
+
async function mediaProbeDetail(i, timeoutMs) {
|
|
27350
|
+
return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
|
|
27351
|
+
}
|
|
27048
27352
|
function codexHookJournaled(db) {
|
|
27049
27353
|
if (db === null) return false;
|
|
27050
27354
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -27097,7 +27401,7 @@ async function codexStopDetail(i, timeoutMs) {
|
|
|
27097
27401
|
timeoutMs,
|
|
27098
27402
|
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
27099
27403
|
});
|
|
27100
|
-
const logged =
|
|
27404
|
+
const logged = existsSync13(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
27101
27405
|
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
27102
27406
|
} finally {
|
|
27103
27407
|
rmSync2(home, { recursive: true, force: true });
|
|
@@ -27108,7 +27412,7 @@ async function checkHookRoundTrip(i) {
|
|
|
27108
27412
|
const trust = await codexPluginTrust(i);
|
|
27109
27413
|
if (trust !== null) return trust;
|
|
27110
27414
|
}
|
|
27111
|
-
if (i.agent === "codex" &&
|
|
27415
|
+
if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
27112
27416
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
27113
27417
|
}
|
|
27114
27418
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -27144,29 +27448,29 @@ async function checkHookRoundTrip(i) {
|
|
|
27144
27448
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
27145
27449
|
}
|
|
27146
27450
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
27147
|
-
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
27451
|
+
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;
|
|
27148
27452
|
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
27149
27453
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
27150
27454
|
}
|
|
27151
27455
|
|
|
27152
27456
|
// src/core/ops/db-heal.ts
|
|
27153
|
-
import { existsSync as
|
|
27154
|
-
import { basename as basename4, dirname as
|
|
27457
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
|
|
27458
|
+
import { basename as basename4, dirname as dirname9, join as join17 } from "node:path";
|
|
27155
27459
|
|
|
27156
27460
|
// src/core/store/owners.ts
|
|
27157
|
-
import { mkdirSync as
|
|
27158
|
-
import { basename as basename3, join as
|
|
27461
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync14, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27462
|
+
import { basename as basename3, join as join16 } from "node:path";
|
|
27159
27463
|
function ownersDir(configDir, projectKey) {
|
|
27160
|
-
return
|
|
27464
|
+
return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27161
27465
|
}
|
|
27162
27466
|
function ownerFile(configDir, projectKey, serverId) {
|
|
27163
|
-
return
|
|
27467
|
+
return join16(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
27164
27468
|
}
|
|
27165
27469
|
function errCode2(err) {
|
|
27166
27470
|
return err.code;
|
|
27167
27471
|
}
|
|
27168
27472
|
function writeOwnerPid(configDir, projectKey, serverId) {
|
|
27169
|
-
|
|
27473
|
+
mkdirSync5(ownersDir(configDir, projectKey), { recursive: true });
|
|
27170
27474
|
writeFileSync3(ownerFile(configDir, projectKey, serverId), String(process.pid), "utf8");
|
|
27171
27475
|
}
|
|
27172
27476
|
function removeOwnerPid(configDir, projectKey, serverId) {
|
|
@@ -27187,7 +27491,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27187
27491
|
const dir = ownersDir(configDir, projectKey);
|
|
27188
27492
|
let names;
|
|
27189
27493
|
try {
|
|
27190
|
-
names =
|
|
27494
|
+
names = readdirSync6(dir);
|
|
27191
27495
|
} catch (err) {
|
|
27192
27496
|
if (errCode2(err) === "ENOENT") return [];
|
|
27193
27497
|
throw err;
|
|
@@ -27195,10 +27499,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27195
27499
|
const live = [];
|
|
27196
27500
|
for (const name of names) {
|
|
27197
27501
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27198
|
-
const file2 =
|
|
27502
|
+
const file2 = join16(dir, name);
|
|
27199
27503
|
let text;
|
|
27200
27504
|
try {
|
|
27201
|
-
text =
|
|
27505
|
+
text = readFileSync14(file2, "utf8");
|
|
27202
27506
|
} catch (err) {
|
|
27203
27507
|
if (errCode2(err) === "ENOENT") continue;
|
|
27204
27508
|
throw err;
|
|
@@ -27244,7 +27548,7 @@ function renameAside(dbPath) {
|
|
|
27244
27548
|
const ts = String(Date.now());
|
|
27245
27549
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
27246
27550
|
const file2 = dbPath + suffix;
|
|
27247
|
-
if (
|
|
27551
|
+
if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
27248
27552
|
}
|
|
27249
27553
|
return ts;
|
|
27250
27554
|
}
|
|
@@ -27267,11 +27571,11 @@ function utcStamp(now) {
|
|
|
27267
27571
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
27268
27572
|
}
|
|
27269
27573
|
function makeOrphanDir(projectDir) {
|
|
27270
|
-
const base =
|
|
27574
|
+
const base = join17(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
27271
27575
|
for (let n = 1; ; n += 1) {
|
|
27272
27576
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
27273
27577
|
try {
|
|
27274
|
-
|
|
27578
|
+
mkdirSync6(dir);
|
|
27275
27579
|
return dir;
|
|
27276
27580
|
} catch (err) {
|
|
27277
27581
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -27282,9 +27586,9 @@ async function healOrphan(project, files, row5) {
|
|
|
27282
27586
|
const moved = [];
|
|
27283
27587
|
let dir = "";
|
|
27284
27588
|
try {
|
|
27285
|
-
dir = makeOrphanDir(
|
|
27589
|
+
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
27286
27590
|
for (const f of files) {
|
|
27287
|
-
const to =
|
|
27591
|
+
const to = join17(dir, basename4(f.path));
|
|
27288
27592
|
renameWithRetry(f.path, to);
|
|
27289
27593
|
moved.push({ path: to, bytes: f.bytes });
|
|
27290
27594
|
}
|
|
@@ -27349,10 +27653,41 @@ function buildReportHead(input) {
|
|
|
27349
27653
|
return lines.concat(tail).join("\n");
|
|
27350
27654
|
}
|
|
27351
27655
|
|
|
27656
|
+
// src/core/ops/unsupported-host.ts
|
|
27657
|
+
var SUPPORTED_AGENTS_LINE = `Supported agents: ${AGENT_IDS.join(", ")} (${SUPPORTED_AGENTS_DOCS_URL}).`;
|
|
27658
|
+
function UNSUPPORTED_HOST_LINE(name) {
|
|
27659
|
+
return `${name} is not a supported host today. The MCP server runs here; hooks are not checked. ${SUPPORTED_AGENTS_LINE}`;
|
|
27660
|
+
}
|
|
27661
|
+
function segmentsOf(dir) {
|
|
27662
|
+
let parts = [dir];
|
|
27663
|
+
for (const sep5 of V1_PATH_SEPS) parts = parts.flatMap((p) => p.split(sep5));
|
|
27664
|
+
return parts;
|
|
27665
|
+
}
|
|
27666
|
+
function hasRun(parts, run) {
|
|
27667
|
+
for (let i = 0; i + run.length <= parts.length; i++) if (run.every((seg, k) => parts[i + k] === seg)) return true;
|
|
27668
|
+
return false;
|
|
27669
|
+
}
|
|
27670
|
+
function unsupportedHostOf(sig) {
|
|
27671
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") {
|
|
27672
|
+
const n = sig.clientName.toLowerCase();
|
|
27673
|
+
const hit = UNSUPPORTED_HOSTS.find((h) => h.clientNames.includes(n));
|
|
27674
|
+
if (hit !== void 0) return hit;
|
|
27675
|
+
}
|
|
27676
|
+
if (sig.bundleDir !== void 0) {
|
|
27677
|
+
const parts = segmentsOf(sig.bundleDir);
|
|
27678
|
+
const hit = UNSUPPORTED_HOSTS.find((h) => h.pluginPaths.some((p) => hasRun(parts, p)));
|
|
27679
|
+
if (hit !== void 0) return hit;
|
|
27680
|
+
}
|
|
27681
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") return void 0;
|
|
27682
|
+
const env = sig.env;
|
|
27683
|
+
if (env === void 0) return void 0;
|
|
27684
|
+
return UNSUPPORTED_HOSTS.find((h) => h.envVars.some((v) => env[v] !== void 0 && env[v] !== ""));
|
|
27685
|
+
}
|
|
27686
|
+
|
|
27352
27687
|
// src/core/ops/doctor-issue.ts
|
|
27353
27688
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
27354
|
-
import { closeSync as closeSync2, existsSync as
|
|
27355
|
-
import { delimiter, join as
|
|
27689
|
+
import { closeSync as closeSync2, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync15, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
|
|
27690
|
+
import { delimiter, join as join18 } from "node:path";
|
|
27356
27691
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
27357
27692
|
function tildeOf(env) {
|
|
27358
27693
|
const home = homeDirOf(env);
|
|
@@ -27393,8 +27728,8 @@ function onPath(env, tool) {
|
|
|
27393
27728
|
const out = [];
|
|
27394
27729
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
27395
27730
|
if (dir === "") continue;
|
|
27396
|
-
for (const n of names) if (
|
|
27397
|
-
out.push(
|
|
27731
|
+
for (const n of names) if (existsSync15(join18(dir, n))) {
|
|
27732
|
+
out.push(join18(dir, n));
|
|
27398
27733
|
break;
|
|
27399
27734
|
}
|
|
27400
27735
|
}
|
|
@@ -27402,7 +27737,7 @@ function onPath(env, tool) {
|
|
|
27402
27737
|
}
|
|
27403
27738
|
function hookLogTail(env) {
|
|
27404
27739
|
const file2 = hookLogPath(env);
|
|
27405
|
-
if (file2 === "" || !
|
|
27740
|
+
if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
27406
27741
|
try {
|
|
27407
27742
|
const fd = openSync2(file2, "r");
|
|
27408
27743
|
try {
|
|
@@ -27422,7 +27757,7 @@ function hookLogTail(env) {
|
|
|
27422
27757
|
}
|
|
27423
27758
|
async function journalRows(ctx) {
|
|
27424
27759
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
27425
|
-
if (!
|
|
27760
|
+
if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
27426
27761
|
try {
|
|
27427
27762
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
27428
27763
|
try {
|
|
@@ -27440,21 +27775,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
27440
27775
|
const home = homeDirOf(env);
|
|
27441
27776
|
const files = configPaths(adapter, env, worktree);
|
|
27442
27777
|
if (home !== null) {
|
|
27443
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
27444
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
27778
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join18(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
27779
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join18(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
27445
27780
|
}
|
|
27446
27781
|
const out = [];
|
|
27447
27782
|
const seen = /* @__PURE__ */ new Set();
|
|
27448
27783
|
for (const f of files) {
|
|
27449
27784
|
if (seen.has(f.path)) continue;
|
|
27450
27785
|
seen.add(f.path);
|
|
27451
|
-
if (!
|
|
27786
|
+
if (!existsSync15(f.path)) {
|
|
27452
27787
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
27453
27788
|
continue;
|
|
27454
27789
|
}
|
|
27455
27790
|
let text = "";
|
|
27456
27791
|
try {
|
|
27457
|
-
text =
|
|
27792
|
+
text = readFileSync15(f.path, "utf8");
|
|
27458
27793
|
} catch (err) {
|
|
27459
27794
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
27460
27795
|
continue;
|
|
@@ -27468,12 +27803,13 @@ function agentConfig(adapter, env, worktree) {
|
|
|
27468
27803
|
function failing(rows) {
|
|
27469
27804
|
return rows.filter((r) => r.status === "FAIL");
|
|
27470
27805
|
}
|
|
27471
|
-
function issueTitle(agent, rows) {
|
|
27472
|
-
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
27806
|
+
function issueTitle(agent, rows, other) {
|
|
27807
|
+
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`;
|
|
27473
27808
|
}
|
|
27474
|
-
function summaryOf(agent, rows) {
|
|
27809
|
+
function summaryOf(agent, rows, other) {
|
|
27475
27810
|
const f = failing(rows)[0];
|
|
27476
|
-
|
|
27811
|
+
const tag2 = other === void 0 ? "" : `${other.name} is not a supported host today. `;
|
|
27812
|
+
return tag2 + (f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`);
|
|
27477
27813
|
}
|
|
27478
27814
|
async function buildIssueBody(i) {
|
|
27479
27815
|
const tilde = tildeOf(i.env);
|
|
@@ -27483,7 +27819,7 @@ async function buildIssueBody(i) {
|
|
|
27483
27819
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
27484
27820
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
27485
27821
|
const sections = {
|
|
27486
|
-
"Summary": [summaryOf(agent, i.rows)],
|
|
27822
|
+
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
27487
27823
|
"ctx-report": [i.table],
|
|
27488
27824
|
"What happened": [
|
|
27489
27825
|
"Rows that need a look:",
|
|
@@ -27524,14 +27860,14 @@ async function buildIssueBody(i) {
|
|
|
27524
27860
|
async function writeIssueReport(i) {
|
|
27525
27861
|
const tilde = tildeOf(i.env);
|
|
27526
27862
|
const body = await buildIssueBody(i);
|
|
27527
|
-
const dir =
|
|
27528
|
-
|
|
27529
|
-
const file2 =
|
|
27863
|
+
const dir = join18(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
27864
|
+
mkdirSync7(dir, { recursive: true });
|
|
27865
|
+
const file2 = join18(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
27530
27866
|
writeFileSync4(file2, body);
|
|
27531
27867
|
const shown2 = tilde(file2);
|
|
27532
|
-
const title = issueTitle(i.adapter.id, i.rows);
|
|
27868
|
+
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
27533
27869
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
27534
|
-
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];
|
|
27870
|
+
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];
|
|
27535
27871
|
}
|
|
27536
27872
|
function formUrl(title, summary) {
|
|
27537
27873
|
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
@@ -27553,13 +27889,19 @@ async function guard(id, run) {
|
|
|
27553
27889
|
}
|
|
27554
27890
|
}
|
|
27555
27891
|
async function codexDb(ctx, adapter) {
|
|
27556
|
-
if (adapter.id !== "codex" || !
|
|
27892
|
+
if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
|
|
27557
27893
|
try {
|
|
27558
27894
|
return await openDb(ctx.project, { readOnly: true });
|
|
27559
27895
|
} catch {
|
|
27560
27896
|
return null;
|
|
27561
27897
|
}
|
|
27562
27898
|
}
|
|
27899
|
+
function d1UpdateCommand(agent, env, other) {
|
|
27900
|
+
return other === void 0 ? hostUpdateCommand(agent, env) : UNSUPPORTED_HOST_LINE(other.name);
|
|
27901
|
+
}
|
|
27902
|
+
function unsupportedRow(id, h) {
|
|
27903
|
+
return { id, label: DOCTOR_LABEL[id], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
27904
|
+
}
|
|
27563
27905
|
async function hookRow(ctx, adapter, host) {
|
|
27564
27906
|
const db = await codexDb(ctx, adapter);
|
|
27565
27907
|
const runStart = Date.now();
|
|
@@ -27583,11 +27925,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
27583
27925
|
}
|
|
27584
27926
|
}
|
|
27585
27927
|
function ownServerId(configDir, projectKey) {
|
|
27586
|
-
const dir =
|
|
27587
|
-
if (!
|
|
27588
|
-
for (const name of
|
|
27928
|
+
const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27929
|
+
if (!existsSync16(dir)) return "";
|
|
27930
|
+
for (const name of readdirSync7(dir)) {
|
|
27589
27931
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27590
|
-
if (
|
|
27932
|
+
if (readFileSync16(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
27591
27933
|
}
|
|
27592
27934
|
return "";
|
|
27593
27935
|
}
|
|
@@ -27595,16 +27937,18 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
27595
27937
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
27596
27938
|
const env = host.env;
|
|
27597
27939
|
const project = ctx.project;
|
|
27940
|
+
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
27598
27941
|
let integrityFailed = false;
|
|
27599
27942
|
let orphan = [];
|
|
27600
27943
|
const checks = {
|
|
27601
|
-
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 }),
|
|
27944
|
+
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) }),
|
|
27602
27945
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
27603
|
-
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
27946
|
+
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
27947
|
+
// D-UNSUPPORTED-HOSTS-1
|
|
27604
27948
|
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)) }),
|
|
27605
|
-
D5: () => hookRow(ctx, adapter, host),
|
|
27949
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
27606
27950
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
27607
|
-
D6: () => checkMcp(ctx),
|
|
27951
|
+
D6: () => checkMcp(ctx, adapter),
|
|
27608
27952
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
27609
27953
|
D8: async () => {
|
|
27610
27954
|
const r = await checkDb(project);
|
|
@@ -27613,7 +27957,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
27613
27957
|
return r.row;
|
|
27614
27958
|
},
|
|
27615
27959
|
D9: () => checkIndex(project),
|
|
27616
|
-
D10: () => checkMode(adapter),
|
|
27960
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
27961
|
+
// D-1331-OC-PERM-1
|
|
27617
27962
|
D11: () => checkShell(env)
|
|
27618
27963
|
};
|
|
27619
27964
|
const rows = [];
|
|
@@ -27650,7 +27995,7 @@ async function doctorReply(ctx, host) {
|
|
|
27650
27995
|
let notes = [];
|
|
27651
27996
|
if (failed) {
|
|
27652
27997
|
try {
|
|
27653
|
-
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
27998
|
+
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 });
|
|
27654
27999
|
} catch (err) {
|
|
27655
28000
|
notes = [`Report file: ${lineOf2(err)}`];
|
|
27656
28001
|
}
|
|
@@ -27682,9 +28027,9 @@ var ctxDoctor = Object.freeze({
|
|
|
27682
28027
|
});
|
|
27683
28028
|
|
|
27684
28029
|
// src/core/tools/execute.ts
|
|
27685
|
-
import { existsSync as
|
|
28030
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
27686
28031
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
27687
|
-
import { dirname as
|
|
28032
|
+
import { dirname as dirname11, join as join20, parse as parse3, resolve as resolve8 } from "node:path";
|
|
27688
28033
|
|
|
27689
28034
|
// src/core/sandbox/win-build.ts
|
|
27690
28035
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -27767,7 +28112,7 @@ function schemaLine(issue4) {
|
|
|
27767
28112
|
}
|
|
27768
28113
|
function fileError(given, abs, root) {
|
|
27769
28114
|
let dir = abs;
|
|
27770
|
-
while (!
|
|
28115
|
+
while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
27771
28116
|
if (isInside(root, dir)) return null;
|
|
27772
28117
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
27773
28118
|
}
|
|
@@ -27801,7 +28146,7 @@ function spawnFailed(argv0, cwd) {
|
|
|
27801
28146
|
}
|
|
27802
28147
|
async function finish(input, ctx, r, exitCode, journal) {
|
|
27803
28148
|
const isError = exitCode !== 0 && !(input.language === "shell" && exitCode === SOFT_EXIT && r.stderr.length === 0);
|
|
27804
|
-
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "");
|
|
28149
|
+
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "") + (r.held === true ? "\n" + BACKGROUND_HOLD_NOTE + "\n" : "");
|
|
27805
28150
|
const fullBytes = Buffer.byteLength(combined, "utf8");
|
|
27806
28151
|
const head2 = summaryLine(exitCode, fullBytes);
|
|
27807
28152
|
const intent = input.intent ?? "";
|
|
@@ -27848,8 +28193,8 @@ async function handler3(raw, ctx) {
|
|
|
27848
28193
|
if (takesDashC(input.language, runtime)) {
|
|
27849
28194
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
27850
28195
|
} else {
|
|
27851
|
-
tmpDir = mkdtempSync2(
|
|
27852
|
-
const file2 =
|
|
28196
|
+
tmpDir = mkdtempSync2(join20(tmpdir3(), TMP_PREFIX));
|
|
28197
|
+
const file2 = join20(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
27853
28198
|
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
27854
28199
|
argv = scriptArgv(input.language, runtime, file2);
|
|
27855
28200
|
}
|
|
@@ -27885,12 +28230,12 @@ var ctxExecute = {
|
|
|
27885
28230
|
};
|
|
27886
28231
|
|
|
27887
28232
|
// src/core/tools/index.ts
|
|
27888
|
-
import { existsSync as
|
|
27889
|
-
import { dirname as
|
|
28233
|
+
import { existsSync as existsSync18, readFileSync as readFileSync18, statSync as statSync8 } from "node:fs";
|
|
28234
|
+
import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as resolve9 } from "node:path";
|
|
27890
28235
|
|
|
27891
28236
|
// src/core/index/walk.ts
|
|
27892
|
-
import { readdirSync as
|
|
27893
|
-
import { join as
|
|
28237
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
28238
|
+
import { join as join21 } from "node:path";
|
|
27894
28239
|
var GITIGNORE = ".gitignore";
|
|
27895
28240
|
var GIT_DIR = ".git";
|
|
27896
28241
|
function walkDir(root, containmentRoot) {
|
|
@@ -27899,19 +28244,19 @@ function walkDir(root, containmentRoot) {
|
|
|
27899
28244
|
const found = [];
|
|
27900
28245
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
27901
28246
|
found.sort(compareFound);
|
|
27902
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
28247
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join21(...f.dir, f.name) }));
|
|
27903
28248
|
}
|
|
27904
28249
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
27905
28250
|
let entries;
|
|
27906
28251
|
try {
|
|
27907
|
-
entries =
|
|
28252
|
+
entries = readdirSync8(abs, { withFileTypes: true });
|
|
27908
28253
|
} catch {
|
|
27909
28254
|
return;
|
|
27910
28255
|
}
|
|
27911
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
28256
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join21(abs, GITIGNORE), rel)) : parent;
|
|
27912
28257
|
for (const e of entries) {
|
|
27913
28258
|
if (e.name === GIT_DIR) continue;
|
|
27914
|
-
const path8 =
|
|
28259
|
+
const path8 = join21(abs, e.name);
|
|
27915
28260
|
let isDir = e.isDirectory();
|
|
27916
28261
|
let isFile = e.isFile();
|
|
27917
28262
|
let target = path8;
|
|
@@ -27951,7 +28296,7 @@ function compareFound(a, b) {
|
|
|
27951
28296
|
function readRules(file2, base) {
|
|
27952
28297
|
let body;
|
|
27953
28298
|
try {
|
|
27954
|
-
body =
|
|
28299
|
+
body = readFileSync17(file2, "utf8");
|
|
27955
28300
|
} catch {
|
|
27956
28301
|
return [];
|
|
27957
28302
|
}
|
|
@@ -32070,7 +32415,7 @@ function userLabel(label2) {
|
|
|
32070
32415
|
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
32071
32416
|
}
|
|
32072
32417
|
function kindOfPath(p) {
|
|
32073
|
-
return EXT_KIND[
|
|
32418
|
+
return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
|
|
32074
32419
|
}
|
|
32075
32420
|
function kindOfType(contentType) {
|
|
32076
32421
|
const semi = contentType.indexOf(";");
|
|
@@ -32079,14 +32424,14 @@ function kindOfType(contentType) {
|
|
|
32079
32424
|
}
|
|
32080
32425
|
function readUtf8(absPath) {
|
|
32081
32426
|
try {
|
|
32082
|
-
return utf8.decode(
|
|
32427
|
+
return utf8.decode(readFileSync18(absPath));
|
|
32083
32428
|
} catch {
|
|
32084
32429
|
return void 0;
|
|
32085
32430
|
}
|
|
32086
32431
|
}
|
|
32087
32432
|
function missingOrOutside(given, abs, root) {
|
|
32088
32433
|
let dir = abs;
|
|
32089
|
-
while (!
|
|
32434
|
+
while (!existsSync18(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
|
|
32090
32435
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
32091
32436
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
32092
32437
|
}
|
|
@@ -32097,7 +32442,7 @@ function pathItems(input, project) {
|
|
|
32097
32442
|
if (statSync8(abs).isDirectory()) {
|
|
32098
32443
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32099
32444
|
sourceKind: "path",
|
|
32100
|
-
label: pathLabel(
|
|
32445
|
+
label: pathLabel(join22(base, f.relPath)),
|
|
32101
32446
|
kind: kindOfPath(f.relPath),
|
|
32102
32447
|
read: () => readUtf8(f.absPath)
|
|
32103
32448
|
}));
|
|
@@ -32276,9 +32621,8 @@ async function handler6(input, ctx) {
|
|
|
32276
32621
|
const newest = rows.at(-1);
|
|
32277
32622
|
if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
|
|
32278
32623
|
const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
|
|
32279
|
-
const goal = readFirstPrompt(db, sessionId);
|
|
32280
32624
|
const last2 = readLastPrompt(db, sessionId);
|
|
32281
|
-
const units = queryUnits(db, sessionId, recallQueryText(last2
|
|
32625
|
+
const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
|
|
32282
32626
|
const block = renderState(rows, newest.turn, { sources, units });
|
|
32283
32627
|
if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
|
|
32284
32628
|
return reply3(block, false);
|
|
@@ -32637,8 +32981,8 @@ var ctxStats = Object.freeze({
|
|
|
32637
32981
|
});
|
|
32638
32982
|
|
|
32639
32983
|
// src/core/ops/host-write.ts
|
|
32640
|
-
import { copyFileSync, existsSync as
|
|
32641
|
-
import { dirname as
|
|
32984
|
+
import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
32985
|
+
import { dirname as dirname13, join as join23 } from "node:path";
|
|
32642
32986
|
function defaultWrite(file2, text) {
|
|
32643
32987
|
writeFileSync6(file2, text, "utf8");
|
|
32644
32988
|
}
|
|
@@ -32647,17 +32991,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
32647
32991
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
32648
32992
|
switch (agent) {
|
|
32649
32993
|
case "opencode":
|
|
32650
|
-
return
|
|
32994
|
+
return join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
32651
32995
|
// D-WIN-OPENCODE-DIR-1
|
|
32652
32996
|
case "pi":
|
|
32653
|
-
return
|
|
32997
|
+
return join23(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
32654
32998
|
case "gemini":
|
|
32655
|
-
return
|
|
32999
|
+
return join23(geminiDirOf(env, home), SETTINGS_FILE);
|
|
32656
33000
|
// D-R38-GEMINI-HOME-1
|
|
32657
33001
|
case "copilot-cli":
|
|
32658
33002
|
return null;
|
|
32659
33003
|
default:
|
|
32660
|
-
return
|
|
33004
|
+
return join23(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
32661
33005
|
}
|
|
32662
33006
|
}
|
|
32663
33007
|
function cell3(value) {
|
|
@@ -32669,8 +33013,8 @@ function toRow(file2, edit) {
|
|
|
32669
33013
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
32670
33014
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
32671
33015
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
32672
|
-
const had =
|
|
32673
|
-
|
|
33016
|
+
const had = existsSync19(file2);
|
|
33017
|
+
mkdirSync8(dirname13(file2), { recursive: true });
|
|
32674
33018
|
if (had) copyFileSync(file2, trash);
|
|
32675
33019
|
try {
|
|
32676
33020
|
write2(tmp, text);
|
|
@@ -32699,7 +33043,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
32699
33043
|
if (requested === null) return [];
|
|
32700
33044
|
const current = readHostConfig(row5.id, requested);
|
|
32701
33045
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
32702
|
-
const exists =
|
|
33046
|
+
const exists = existsSync19(current.path);
|
|
32703
33047
|
if (exists && result.text === current.text) return [];
|
|
32704
33048
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
32705
33049
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -32707,15 +33051,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
32707
33051
|
}
|
|
32708
33052
|
|
|
32709
33053
|
// src/core/ops/uninstall.ts
|
|
32710
|
-
import { existsSync as
|
|
32711
|
-
import { join as
|
|
33054
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33055
|
+
import { join as join24 } from "node:path";
|
|
32712
33056
|
function row2(area, before, after) {
|
|
32713
33057
|
return { area, before, after };
|
|
32714
33058
|
}
|
|
32715
33059
|
function stopServers(configDir, projectKey) {
|
|
32716
33060
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
32717
|
-
const dir =
|
|
32718
|
-
for (const serverId of stopped) writeFileSync7(
|
|
33061
|
+
const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33062
|
+
for (const serverId of stopped) writeFileSync7(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
32719
33063
|
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 };
|
|
32720
33064
|
}
|
|
32721
33065
|
function rootOrNull(adapter, env) {
|
|
@@ -32733,15 +33077,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
32733
33077
|
const root = rootOrNull(adapter, env);
|
|
32734
33078
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
32735
33079
|
if (adapter.installMode === "marketplace") {
|
|
32736
|
-
const cache =
|
|
33080
|
+
const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
32737
33081
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
32738
33082
|
}
|
|
32739
33083
|
rmSync6(root, { recursive: true, force: true });
|
|
32740
33084
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
32741
33085
|
}
|
|
32742
33086
|
case "plugin": {
|
|
32743
|
-
const agentDir =
|
|
32744
|
-
if (!
|
|
33087
|
+
const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33088
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
32745
33089
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
32746
33090
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
32747
33091
|
}
|
|
@@ -32786,7 +33130,7 @@ function ownEntries2(agent, env) {
|
|
|
32786
33130
|
}
|
|
32787
33131
|
if (agent === "opencode") {
|
|
32788
33132
|
return [{
|
|
32789
|
-
file:
|
|
33133
|
+
file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
32790
33134
|
// D-WIN-OPENCODE-DIR-1
|
|
32791
33135
|
key: OPENCODE_PLUGIN_KEY,
|
|
32792
33136
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -32797,7 +33141,7 @@ function ownEntries2(agent, env) {
|
|
|
32797
33141
|
if (agent === "pi") {
|
|
32798
33142
|
const agentDir = piAgentDirOf(env, home);
|
|
32799
33143
|
return [{
|
|
32800
|
-
file:
|
|
33144
|
+
file: join24(agentDir, SETTINGS_FILE),
|
|
32801
33145
|
key: PI_PACKAGES_KEY,
|
|
32802
33146
|
shown: PI_PACKAGES_KEY,
|
|
32803
33147
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -32819,12 +33163,12 @@ function removeOwnEntries(agent, env) {
|
|
|
32819
33163
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
32820
33164
|
}
|
|
32821
33165
|
function removeProjectData(configDir, projectKey) {
|
|
32822
|
-
const projects =
|
|
32823
|
-
const dir =
|
|
32824
|
-
if (!
|
|
33166
|
+
const projects = join24(configDir, PROJECTS_DIR_NAME);
|
|
33167
|
+
const dir = join24(projects, projectKey);
|
|
33168
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
32825
33169
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
32826
|
-
for (const name of
|
|
32827
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
33170
|
+
for (const name of readdirSync9(dir)) {
|
|
33171
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
|
|
32828
33172
|
}
|
|
32829
33173
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
32830
33174
|
}
|
|
@@ -32832,12 +33176,12 @@ function runUninstall(input) {
|
|
|
32832
33176
|
const configDir = resolveConfigDir(input.env);
|
|
32833
33177
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
32834
33178
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
32835
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
33179
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
32836
33180
|
return { rows, stopped: stop.stopped };
|
|
32837
33181
|
}
|
|
32838
33182
|
|
|
32839
33183
|
// src/core/ops/v1-remove.ts
|
|
32840
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
33184
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync19, rmSync as rmSync7 } from "node:fs";
|
|
32841
33185
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
32842
33186
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
32843
33187
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -32849,7 +33193,7 @@ function moveAside(target, undo) {
|
|
|
32849
33193
|
}
|
|
32850
33194
|
function keepAside(target, undo) {
|
|
32851
33195
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
32852
|
-
for (let n = 2;
|
|
33196
|
+
for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
32853
33197
|
renameWithRetry(target, aside);
|
|
32854
33198
|
undo.push({ trash: aside, target, keep: true });
|
|
32855
33199
|
return aside;
|
|
@@ -32888,8 +33232,8 @@ function locate(doc, path8) {
|
|
|
32888
33232
|
return null;
|
|
32889
33233
|
}
|
|
32890
33234
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
32891
|
-
const layout = hostLayout(
|
|
32892
|
-
const text = hostText(
|
|
33235
|
+
const layout = hostLayout(readFileSync19(file2, "utf8"));
|
|
33236
|
+
const text = hostText(readFileSync19(file2, "utf8"));
|
|
32893
33237
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
32894
33238
|
const hit = /* @__PURE__ */ new Set();
|
|
32895
33239
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -32926,20 +33270,20 @@ function removeV1(agent, findings, project) {
|
|
|
32926
33270
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
32927
33271
|
else if (f.path === "") {
|
|
32928
33272
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
32929
|
-
else if (
|
|
32930
|
-
else if (
|
|
33273
|
+
else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
33274
|
+
else if (existsSync21(f.file)) {
|
|
32931
33275
|
moveAside(f.file, undo);
|
|
32932
33276
|
done.set(f, UPGRADE_REMOVED);
|
|
32933
33277
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
32934
33278
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
32935
33279
|
}
|
|
32936
33280
|
for (const [file2, list4] of entries) {
|
|
32937
|
-
if (!
|
|
33281
|
+
if (!existsSync21(file2)) {
|
|
32938
33282
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
32939
33283
|
continue;
|
|
32940
33284
|
}
|
|
32941
33285
|
if (file2.endsWith(TOML_EXT)) {
|
|
32942
|
-
const rawToml =
|
|
33286
|
+
const rawToml = readFileSync19(file2, "utf8");
|
|
32943
33287
|
const tomlLayout = hostLayout(rawToml);
|
|
32944
33288
|
let text = hostText(rawToml);
|
|
32945
33289
|
for (const f of list4) {
|
|
@@ -32967,7 +33311,7 @@ function removeV1(agent, findings, project) {
|
|
|
32967
33311
|
},
|
|
32968
33312
|
rollback() {
|
|
32969
33313
|
for (const u of undo.splice(0).reverse()) {
|
|
32970
|
-
if (!
|
|
33314
|
+
if (!existsSync21(u.trash)) continue;
|
|
32971
33315
|
rmSync7(u.target, { recursive: true, force: true });
|
|
32972
33316
|
renameWithRetry(u.trash, u.target);
|
|
32973
33317
|
}
|
|
@@ -32997,8 +33341,8 @@ function pluginRootRow(adapter, env) {
|
|
|
32997
33341
|
}
|
|
32998
33342
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
32999
33343
|
}
|
|
33000
|
-
function hostRow(adapter) {
|
|
33001
|
-
return row4(UPGRADE_HOST_AREA, "",
|
|
33344
|
+
function hostRow(adapter, env) {
|
|
33345
|
+
return row4(UPGRADE_HOST_AREA, "", hostUpdateCommand(adapter.id, env));
|
|
33002
33346
|
}
|
|
33003
33347
|
function upgrade(adapter, deps, home) {
|
|
33004
33348
|
let removal = null;
|
|
@@ -33006,7 +33350,7 @@ function upgrade(adapter, deps, home) {
|
|
|
33006
33350
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
33007
33351
|
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) });
|
|
33008
33352
|
removal = removeV1(adapter.id, findings, deps.project.worktree);
|
|
33009
|
-
const rows = [hostRow(adapter), ...step5, ...removal.rows];
|
|
33353
|
+
const rows = [hostRow(adapter, deps.env), ...step5, ...removal.rows];
|
|
33010
33354
|
removal.commit();
|
|
33011
33355
|
return rows;
|
|
33012
33356
|
} catch (err) {
|
|
@@ -33098,8 +33442,8 @@ function checkCall(tool, input) {
|
|
|
33098
33442
|
|
|
33099
33443
|
// src/entries/server.ts
|
|
33100
33444
|
import { randomUUID } from "node:crypto";
|
|
33101
|
-
import { existsSync as
|
|
33102
|
-
import { dirname as
|
|
33445
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
33446
|
+
import { dirname as dirname14, join as join26 } from "node:path";
|
|
33103
33447
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
33104
33448
|
|
|
33105
33449
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -50696,7 +51040,7 @@ var PROPERTY_KEYS_BY_TYPE = {
|
|
|
50696
51040
|
array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
|
|
50697
51041
|
};
|
|
50698
51042
|
var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
|
|
50699
|
-
function walkProperty(node3, path8, vendor,
|
|
51043
|
+
function walkProperty(node3, path8, vendor, unsupported2) {
|
|
50700
51044
|
if (!isJsonObject(node3)) return node3;
|
|
50701
51045
|
const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
|
|
50702
51046
|
if (allowedKeys === void 0) return node3;
|
|
@@ -50704,17 +51048,17 @@ function walkProperty(node3, path8, vendor, unsupported) {
|
|
|
50704
51048
|
for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
|
|
50705
51049
|
else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
|
|
50706
51050
|
if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
|
|
50707
|
-
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor))
|
|
50708
|
-
} else
|
|
51051
|
+
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported2.push(`${path8}.${key}`);
|
|
51052
|
+
} else unsupported2.push(`${path8}.${key}`);
|
|
50709
51053
|
return pruned;
|
|
50710
51054
|
}
|
|
50711
51055
|
function walkRequestedSchema(converted, vendor) {
|
|
50712
51056
|
const pruned = {};
|
|
50713
|
-
const
|
|
50714
|
-
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,
|
|
51057
|
+
const unsupported2 = [];
|
|
51058
|
+
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)]));
|
|
50715
51059
|
else if (ROOT_KEYS.has(key)) pruned[key] = value;
|
|
50716
|
-
else if (!isAnnotationOnlyJsonSchemaKeyword(key))
|
|
50717
|
-
if (
|
|
51060
|
+
else if (!isAnnotationOnlyJsonSchemaKeyword(key)) unsupported2.push(key);
|
|
51061
|
+
if (unsupported2.length > 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Elicitation requestedSchema contains unsupported JSON Schema constraint(s) after Standard Schema conversion: ${unsupported2.join(", ")}`);
|
|
50718
51062
|
return pruned;
|
|
50719
51063
|
}
|
|
50720
51064
|
function describeUnsupportedProperties(pruned, fallback) {
|
|
@@ -61164,8 +61508,8 @@ function installExitGuard(opts) {
|
|
|
61164
61508
|
}
|
|
61165
61509
|
|
|
61166
61510
|
// src/core/store/cleanup.ts
|
|
61167
|
-
import { existsSync as
|
|
61168
|
-
import { join as
|
|
61511
|
+
import { existsSync as existsSync22, readdirSync as readdirSync10, rmSync as rmSync8 } from "node:fs";
|
|
61512
|
+
import { join as join25 } from "node:path";
|
|
61169
61513
|
function deleteSource(raw, id) {
|
|
61170
61514
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
61171
61515
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -61200,7 +61544,7 @@ function userVersion(raw) {
|
|
|
61200
61544
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
61201
61545
|
}
|
|
61202
61546
|
function openForSweep(dbPath, projectKey) {
|
|
61203
|
-
if (!
|
|
61547
|
+
if (!existsSync22(dbPath) && (existsSync22(dbPath + DB_WAL_SUFFIX) || existsSync22(dbPath + DB_SHM_SUFFIX))) {
|
|
61204
61548
|
throw new CtxError("DB_GONE");
|
|
61205
61549
|
}
|
|
61206
61550
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -61221,8 +61565,8 @@ function lastAccess(raw) {
|
|
|
61221
61565
|
return row5.t;
|
|
61222
61566
|
}
|
|
61223
61567
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
61224
|
-
const dir =
|
|
61225
|
-
const db = openForSweep(
|
|
61568
|
+
const dir = join25(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
61569
|
+
const db = openForSweep(join25(dir, DB_FILE_NAME), projectKey);
|
|
61226
61570
|
let dead;
|
|
61227
61571
|
try {
|
|
61228
61572
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
@@ -61235,7 +61579,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
61235
61579
|
function sweepDeadProjects(configDir) {
|
|
61236
61580
|
let entries;
|
|
61237
61581
|
try {
|
|
61238
|
-
entries =
|
|
61582
|
+
entries = readdirSync10(join25(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
61239
61583
|
} catch (err) {
|
|
61240
61584
|
if (err.code === "ENOENT") return [];
|
|
61241
61585
|
throw err;
|
|
@@ -61361,7 +61705,7 @@ function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
|
61361
61705
|
const fromHost = workspaceFromMeta(meta3);
|
|
61362
61706
|
if (fromHost !== void 0) return fromHost;
|
|
61363
61707
|
if (script === void 0 || script === "") return spawnCwd;
|
|
61364
|
-
return realOrSame(spawnCwd) === realOrSame(
|
|
61708
|
+
return realOrSame(spawnCwd) === realOrSame(dirname14(script)) ? "" : spawnCwd;
|
|
61365
61709
|
}
|
|
61366
61710
|
function errorReply(err) {
|
|
61367
61711
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
@@ -61400,15 +61744,15 @@ async function startServer(argv, env) {
|
|
|
61400
61744
|
opening.catch(() => pending.delete(project.dbPath));
|
|
61401
61745
|
}
|
|
61402
61746
|
const db = await opening;
|
|
61403
|
-
if (!
|
|
61747
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
61404
61748
|
return db;
|
|
61405
61749
|
}
|
|
61406
61750
|
function stopMarker(configDir, projectKey) {
|
|
61407
|
-
return
|
|
61751
|
+
return join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
61408
61752
|
}
|
|
61409
61753
|
function stopRequested() {
|
|
61410
61754
|
const configDir = resolveConfigDir(process.env);
|
|
61411
|
-
return held.some((db) =>
|
|
61755
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
61412
61756
|
}
|
|
61413
61757
|
async function journal(project, ctx, name, reply4) {
|
|
61414
61758
|
const db = await ownDb(project);
|