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/opencode/plugin.js
CHANGED
|
@@ -23,7 +23,14 @@ var POINTER_MIN = 640;
|
|
|
23
23
|
var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
24
24
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
25
25
|
var SYNC_INDEX_MAX_BYTES = 65536;
|
|
26
|
-
var
|
|
26
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
27
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
28
|
+
function readReplaceTrigger(raw) {
|
|
29
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
30
|
+
const n = Number(raw);
|
|
31
|
+
return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
32
|
+
}
|
|
33
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
27
34
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
28
35
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
29
36
|
var REPLACE_RETURN_BYTES = 96;
|
|
@@ -181,6 +188,8 @@ var RRF_K = 60;
|
|
|
181
188
|
var SOURCE_HANDLE_MAX_DIGITS = 10;
|
|
182
189
|
var EXEC_TIMEOUT_MS = 6e5;
|
|
183
190
|
var KILL_GRACE_MS = 1e3;
|
|
191
|
+
var PIPE_EOF_GRACE_MS = 250;
|
|
192
|
+
var PIPE_DRAIN_MAX_MS = 2e3;
|
|
184
193
|
var DB_TIMEOUT_MS = 5e3;
|
|
185
194
|
var DB_WAL_SUFFIX = "-wal";
|
|
186
195
|
var DB_SHM_SUFFIX = "-shm";
|
|
@@ -210,6 +219,7 @@ var SHELL_FAMILY = Object.freeze(["sh", "bash", "zsh", "dash", "ksh", "fish"]);
|
|
|
210
219
|
var PATHEXT_DEFAULT = ".COM;.EXE;.BAT;.CMD";
|
|
211
220
|
var FETCH_MAX_HOPS = 5;
|
|
212
221
|
var SOURCE_LABEL_MAX_CHARS = 80;
|
|
222
|
+
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.";
|
|
213
223
|
var CANCELLED_LINE = "Cancelled.";
|
|
214
224
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
215
225
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
@@ -249,6 +259,7 @@ function readHintEvery(raw) {
|
|
|
249
259
|
}
|
|
250
260
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
251
261
|
var MAX_NEST_DEPTH = 32;
|
|
262
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
252
263
|
var DENY_PREFIX = "context-mode: ";
|
|
253
264
|
var DENY_WHAT = Object.freeze({
|
|
254
265
|
curl: "This curl/wget call",
|
|
@@ -342,10 +353,10 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
342
353
|
opencode: READ_IMAGES_AND_PDF,
|
|
343
354
|
pi: READ_IMAGES,
|
|
344
355
|
vscode: READ_IMAGES,
|
|
356
|
+
zcode: READ_IMAGES,
|
|
345
357
|
"copilot-cli": [],
|
|
346
358
|
codex: [],
|
|
347
|
-
kiro: []
|
|
348
|
-
zcode: []
|
|
359
|
+
kiro: []
|
|
349
360
|
});
|
|
350
361
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
351
362
|
var SHELL_TOOL = "Bash";
|
|
@@ -363,6 +374,7 @@ var RECALL_MAX_ROWS = 340;
|
|
|
363
374
|
var COMPACTED_META_PREFIX = "compacted:";
|
|
364
375
|
var RECALL_UNITS_SEEN_META_PREFIX = "recall_units_seen:";
|
|
365
376
|
var UNITS_ANCESTOR_FACTOR = 8;
|
|
377
|
+
var RECALL_QUERY_MAX_TERMS = 64;
|
|
366
378
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
367
379
|
var RECALL_SEEN_META_PREFIX = "recall_seen:";
|
|
368
380
|
var RECALL_OPEN_TAG = "<context_mode_recall>";
|
|
@@ -456,7 +468,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
456
468
|
var DECISION_OPTION_KEY = "option";
|
|
457
469
|
var DECISION_LABEL_JOIN = " | ";
|
|
458
470
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
459
|
-
var BUNDLE_SHA = true ? "
|
|
471
|
+
var BUNDLE_SHA = true ? "5539b632975049a99de986448417a10bd246e506" : void 0;
|
|
460
472
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
461
473
|
var DOCTOR_LABEL = Object.freeze({
|
|
462
474
|
D1: "version",
|
|
@@ -542,9 +554,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
|
|
|
542
554
|
var D1_PRERELEASE_SEP = "-";
|
|
543
555
|
var D1_DEFAULT_TAG = "latest";
|
|
544
556
|
var GIT_LS_REMOTE = "ls-remote";
|
|
545
|
-
var D2_NODE_FIX = `install
|
|
557
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
546
558
|
function D2_NODE_DETAIL(version2) {
|
|
547
|
-
return `Node ${
|
|
559
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version2}`;
|
|
548
560
|
}
|
|
549
561
|
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
550
562
|
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
@@ -562,6 +574,7 @@ var D5B_FIX = "disable chat.useClaudeHooks or the Claude Code hooks block";
|
|
|
562
574
|
var VSCODE_CLAUDE_HOOKS_SETTING = "chat.useClaudeHooks";
|
|
563
575
|
var VSCODE_SETTINGS_FILE = "settings.json";
|
|
564
576
|
var D6_UNKNOWN_DETAIL = "no clientInfo or protocolVersion on the request";
|
|
577
|
+
var D6_IN_PROCESS_DETAIL = "in-process plugin: this call ran inside the agent, no MCP session to read";
|
|
565
578
|
function D7_DETAIL(got) {
|
|
566
579
|
return `resolved project source ${got} does not match the host's actual cwd`;
|
|
567
580
|
}
|
|
@@ -673,6 +686,90 @@ function D3_DETAIL(parts) {
|
|
|
673
686
|
function D3_ROOT_DETAIL(paths) {
|
|
674
687
|
return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
|
|
675
688
|
}
|
|
689
|
+
var unsupported = (h) => Object.freeze(h);
|
|
690
|
+
var UNSUPPORTED_HOSTS = Object.freeze([
|
|
691
|
+
unsupported({
|
|
692
|
+
id: "antigravity",
|
|
693
|
+
name: "Antigravity",
|
|
694
|
+
clientNames: ["antigravity", "antigravity-client", "antigravity-cli", "agy"],
|
|
695
|
+
envVars: ["ANTIGRAVITY_CLI_ALIAS"],
|
|
696
|
+
pluginPaths: [[".gemini", "config", "plugins"], [".gemini", "antigravity", "plugins"], [".gemini", "antigravity-cli", "plugins"], [".gemini", "antigravity-ide", "plugins"]],
|
|
697
|
+
configDirs: [".gemini/antigravity", ".gemini/antigravity-cli", ".gemini/config"],
|
|
698
|
+
binaries: ["agy"],
|
|
699
|
+
source: "v1.0.169:src/adapters/client-map.ts:15-17; detect.ts:156,481-483; #1340"
|
|
700
|
+
}),
|
|
701
|
+
unsupported({
|
|
702
|
+
id: "cursor",
|
|
703
|
+
name: "Cursor",
|
|
704
|
+
clientNames: ["cursor-vscode"],
|
|
705
|
+
envVars: ["CURSOR_TRACE_ID", "CURSOR_CLI", "CURSOR_CWD"],
|
|
706
|
+
pluginPaths: [],
|
|
707
|
+
configDirs: [".cursor"],
|
|
708
|
+
binaries: [],
|
|
709
|
+
source: "v1.0.169:src/adapters/client-map.ts:18; detect.ts:163-165,584"
|
|
710
|
+
}),
|
|
711
|
+
unsupported({
|
|
712
|
+
id: "omp",
|
|
713
|
+
name: "OMP (oh-my-pi)",
|
|
714
|
+
clientNames: ["omp-coding-agent"],
|
|
715
|
+
envVars: [],
|
|
716
|
+
pluginPaths: [],
|
|
717
|
+
configDirs: [".omp"],
|
|
718
|
+
binaries: ["omp"],
|
|
719
|
+
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)"
|
|
720
|
+
}),
|
|
721
|
+
unsupported({
|
|
722
|
+
id: "openclaw",
|
|
723
|
+
name: "OpenClaw",
|
|
724
|
+
clientNames: [],
|
|
725
|
+
envVars: [],
|
|
726
|
+
pluginPaths: [],
|
|
727
|
+
configDirs: [".openclaw"],
|
|
728
|
+
binaries: [],
|
|
729
|
+
source: "v1.0.169:src/adapters/detect.ts:252,575 (the runtime sets no env var)"
|
|
730
|
+
}),
|
|
731
|
+
unsupported({
|
|
732
|
+
id: "kimi",
|
|
733
|
+
name: "Kimi Code",
|
|
734
|
+
clientNames: ["kimi-code", "kimi"],
|
|
735
|
+
envVars: [],
|
|
736
|
+
pluginPaths: [],
|
|
737
|
+
configDirs: [".kimi-code"],
|
|
738
|
+
binaries: ["kimi"],
|
|
739
|
+
source: "v1.0.169:src/adapters/client-map.ts:42-44; detect.ts:567; adapters/kimi/index.ts:127"
|
|
740
|
+
}),
|
|
741
|
+
unsupported({
|
|
742
|
+
id: "kilo",
|
|
743
|
+
name: "Kilo Code",
|
|
744
|
+
clientNames: ["kilo code"],
|
|
745
|
+
envVars: ["KILO", "KILO_PID"],
|
|
746
|
+
pluginPaths: [],
|
|
747
|
+
configDirs: [".config/kilo"],
|
|
748
|
+
binaries: [],
|
|
749
|
+
source: "v1.0.169:src/adapters/client-map.ts:28; detect.ts:170-171,592"
|
|
750
|
+
}),
|
|
751
|
+
unsupported({
|
|
752
|
+
id: "zed",
|
|
753
|
+
name: "Zed",
|
|
754
|
+
clientNames: ["zed"],
|
|
755
|
+
envVars: ["ZED_SESSION_ID", "ZED_TERM"],
|
|
756
|
+
pluginPaths: [],
|
|
757
|
+
configDirs: [".config/zed"],
|
|
758
|
+
binaries: [],
|
|
759
|
+
source: "v1.0.169:src/adapters/client-map.ts:38-39; detect.ts:189-190,616"
|
|
760
|
+
}),
|
|
761
|
+
unsupported({
|
|
762
|
+
id: "jetbrains-copilot",
|
|
763
|
+
name: "JetBrains Copilot",
|
|
764
|
+
clientNames: ["jetbrains client", "intellij idea", "pycharm"],
|
|
765
|
+
envVars: ["IDEA_INITIAL_DIRECTORY"],
|
|
766
|
+
pluginPaths: [],
|
|
767
|
+
configDirs: [".config/JetBrains"],
|
|
768
|
+
binaries: [],
|
|
769
|
+
source: "v1.0.169:src/adapters/client-map.ts:23-25; detect.ts:213,600"
|
|
770
|
+
})
|
|
771
|
+
]);
|
|
772
|
+
var SUPPORTED_AGENTS_DOCS_URL = "https://github.com/mksglu/context-mode/blob/main/docs/install/README.md";
|
|
676
773
|
var D3_ROOT_FIX_JOIN = " or ";
|
|
677
774
|
function D3_ROOT_FIX(installs) {
|
|
678
775
|
return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
|
|
@@ -709,6 +806,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
709
806
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
710
807
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
711
808
|
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";
|
|
809
|
+
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)";
|
|
712
810
|
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)";
|
|
713
811
|
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`;
|
|
714
812
|
function D5_SLOW_DETAIL(ms) {
|
|
@@ -720,6 +818,16 @@ var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
|
720
818
|
function D10_DETAIL(mode) {
|
|
721
819
|
return `enforcement mode: ${mode}`;
|
|
722
820
|
}
|
|
821
|
+
function D10_PERMISSION_DETAIL(mode) {
|
|
822
|
+
return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
|
|
823
|
+
}
|
|
824
|
+
var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
|
|
825
|
+
var D10_PERMISSION_FIX = "opencode upgrade";
|
|
826
|
+
var OC_SHELL_ACTION = "shell";
|
|
827
|
+
var OC_LEGACY_SHELL_ACTION = "bash";
|
|
828
|
+
var OC_READ_ACTION = "read";
|
|
829
|
+
var OC_WEBFETCH_ACTION = "webfetch";
|
|
830
|
+
var OC_ANY_RESOURCE = "*";
|
|
723
831
|
var D11_WIN_DETAIL = "Git Bash not found";
|
|
724
832
|
var D11_WIN_FIX = "install Git for Windows";
|
|
725
833
|
var D11_POSIX_DETAIL = "no sh on PATH";
|
|
@@ -782,6 +890,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
782
890
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
783
891
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
784
892
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
893
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
894
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
785
895
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
786
896
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
787
897
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -875,6 +985,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
875
985
|
var JSON_INDENT_UNIT = " ";
|
|
876
986
|
var MCP_COMMAND_FIELD = "command";
|
|
877
987
|
var MCP_ARGS_FIELD = "args";
|
|
988
|
+
var MCP_ENV_FIELD = "env";
|
|
878
989
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
879
990
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
880
991
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -992,7 +1103,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
|
992
1103
|
|
|
993
1104
|
// src/core/contracts/errors.ts
|
|
994
1105
|
var ERROR_TEXT = Object.freeze({
|
|
995
|
-
NODE_TOO_OLD: "
|
|
1106
|
+
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.",
|
|
1107
|
+
// #1328 D-NODE-OLD-1
|
|
996
1108
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
997
1109
|
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.",
|
|
998
1110
|
// D-ORPHAN-WAL-1
|
|
@@ -1062,7 +1174,7 @@ var CtxError = class extends Error {
|
|
|
1062
1174
|
};
|
|
1063
1175
|
|
|
1064
1176
|
// src/core/hooks/dispatch.ts
|
|
1065
|
-
import { dirname as dirname4, join as
|
|
1177
|
+
import { dirname as dirname4, join as join8, relative as relative3, resolve as resolve6, sep as sep3 } from "node:path";
|
|
1066
1178
|
|
|
1067
1179
|
// src/core/contracts/agents.ts
|
|
1068
1180
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -3411,7 +3523,7 @@ function withLayout(text, layout) {
|
|
|
3411
3523
|
|
|
3412
3524
|
// src/core/project/config-dir.ts
|
|
3413
3525
|
import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
|
|
3414
|
-
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
3526
|
+
var { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
3415
3527
|
function homeDirOf(env, platform = process.platform) {
|
|
3416
3528
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
3417
3529
|
if (platform === "win32") {
|
|
@@ -3438,7 +3550,34 @@ function codexPluginHomeOf(bundleDir2) {
|
|
|
3438
3550
|
function codexRunDirOf(env, home, bundleDir2) {
|
|
3439
3551
|
const dir = env[CODEX_HOME_ENV];
|
|
3440
3552
|
if (dir !== void 0 && dir !== "") return dir;
|
|
3441
|
-
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
3553
|
+
return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
|
|
3554
|
+
}
|
|
3555
|
+
function codexSetupHomeOf(env, home) {
|
|
3556
|
+
if (home === "" && !env[DATA_DIR_ENV]) return null;
|
|
3557
|
+
const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
|
|
3558
|
+
let runs;
|
|
3559
|
+
try {
|
|
3560
|
+
runs = readdirSync(base).sort().reverse();
|
|
3561
|
+
} catch {
|
|
3562
|
+
return null;
|
|
3563
|
+
}
|
|
3564
|
+
for (const run of runs) {
|
|
3565
|
+
const file2 = join(base, run, SETUP_MANIFEST_FILE);
|
|
3566
|
+
if (!existsSync(file2)) continue;
|
|
3567
|
+
let entries;
|
|
3568
|
+
try {
|
|
3569
|
+
entries = JSON.parse(readFileSync(file2, "utf8")).entries;
|
|
3570
|
+
} catch {
|
|
3571
|
+
continue;
|
|
3572
|
+
}
|
|
3573
|
+
if (!Array.isArray(entries)) continue;
|
|
3574
|
+
for (const e of entries) {
|
|
3575
|
+
if (e?.agent !== "codex" || typeof e.file !== "string") continue;
|
|
3576
|
+
const p = e.file.includes(win32.sep) ? win32 : posix;
|
|
3577
|
+
if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
|
|
3578
|
+
}
|
|
3579
|
+
}
|
|
3580
|
+
return null;
|
|
3442
3581
|
}
|
|
3443
3582
|
function copilotDirOf(env, home) {
|
|
3444
3583
|
const dir = env[COPILOT_HOME_ENV];
|
|
@@ -3479,6 +3618,17 @@ function claudeDirOf(env, home) {
|
|
|
3479
3618
|
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
3480
3619
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["claude-code"]);
|
|
3481
3620
|
}
|
|
3621
|
+
function claudeProfileEnv(env, platform = process.platform) {
|
|
3622
|
+
const dir = env[CLAUDE_CONFIG_DIR_ENV];
|
|
3623
|
+
if (dir === void 0 || dir === "" || platform === "win32") return "";
|
|
3624
|
+
return `${CLAUDE_CONFIG_DIR_ENV}='${dir.split("'").join(`'"'"'`)}' `;
|
|
3625
|
+
}
|
|
3626
|
+
function hostUpdateCommand(agent, env, platform = process.platform) {
|
|
3627
|
+
const cmd = UPGRADE_HOST_COMMAND[agent];
|
|
3628
|
+
if (agent !== "claude-code") return cmd;
|
|
3629
|
+
const profile = claudeProfileEnv(env, platform);
|
|
3630
|
+
return profile === "" ? cmd : cmd.split(" && ").map((c) => profile + c).join(" && ");
|
|
3631
|
+
}
|
|
3482
3632
|
function opencodeDirOf(env, home) {
|
|
3483
3633
|
const own2 = env[OPENCODE_CONFIG_DIR_ENV];
|
|
3484
3634
|
if (own2 !== void 0 && own2 !== "") return own2;
|
|
@@ -3518,7 +3668,7 @@ function resolveConfigDir(env) {
|
|
|
3518
3668
|
}
|
|
3519
3669
|
|
|
3520
3670
|
// src/core/policy/subagent.ts
|
|
3521
|
-
var { readFileSync } = process.getBuiltinModule("node:fs");
|
|
3671
|
+
var { readFileSync: readFileSync2 } = process.getBuiltinModule("node:fs");
|
|
3522
3672
|
function isSubagentCall(ev) {
|
|
3523
3673
|
return ev.agentId !== void 0 && ev.agentId !== "";
|
|
3524
3674
|
}
|
|
@@ -3579,7 +3729,7 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3579
3729
|
if (agent.indexOf(PLUGIN_AGENT_SEPARATOR) >= 0) return null;
|
|
3580
3730
|
let parsed;
|
|
3581
3731
|
try {
|
|
3582
|
-
parsed = JSON.parse(hostText(
|
|
3732
|
+
parsed = JSON.parse(hostText(readFileSync2(join2(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE), "utf8")));
|
|
3583
3733
|
} catch {
|
|
3584
3734
|
return null;
|
|
3585
3735
|
}
|
|
@@ -3602,7 +3752,7 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3602
3752
|
function readAgentFile(path8) {
|
|
3603
3753
|
let text;
|
|
3604
3754
|
try {
|
|
3605
|
-
text =
|
|
3755
|
+
text = readFileSync2(path8, "utf8");
|
|
3606
3756
|
} catch {
|
|
3607
3757
|
return null;
|
|
3608
3758
|
}
|
|
@@ -3810,7 +3960,7 @@ function unwrap(commands) {
|
|
|
3810
3960
|
|
|
3811
3961
|
// src/core/policy/user-deny.ts
|
|
3812
3962
|
import { isAbsolute, join as join3, relative, sep } from "node:path";
|
|
3813
|
-
var { readFileSync:
|
|
3963
|
+
var { readFileSync: readFileSync3 } = process.getBuiltinModule("node:fs");
|
|
3814
3964
|
var CLAUDE_DIR = ".claude";
|
|
3815
3965
|
var LOCAL_SETTINGS = "settings.local.json";
|
|
3816
3966
|
var SETTINGS = "settings.json";
|
|
@@ -3837,7 +3987,7 @@ function isObject(v) {
|
|
|
3837
3987
|
function readOne(file2) {
|
|
3838
3988
|
let text;
|
|
3839
3989
|
try {
|
|
3840
|
-
text = hostText(
|
|
3990
|
+
text = hostText(readFileSync3(file2, "utf8"));
|
|
3841
3991
|
} catch (err) {
|
|
3842
3992
|
return err.code === "ENOENT" ? { kind: "absent" } : { kind: "bad" };
|
|
3843
3993
|
}
|
|
@@ -4000,6 +4150,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
4000
4150
|
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.'
|
|
4001
4151
|
});
|
|
4002
4152
|
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.';
|
|
4153
|
+
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'.`;
|
|
4003
4154
|
|
|
4004
4155
|
// src/core/policy/read-deny.ts
|
|
4005
4156
|
var SIZE = "{size}";
|
|
@@ -4007,9 +4158,105 @@ var PATH = "{path}";
|
|
|
4007
4158
|
function READ_DENY_MESSAGE(path8, size, prefix = "") {
|
|
4008
4159
|
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
4009
4160
|
}
|
|
4161
|
+
function READ_DENY_RANGE_MESSAGE(path8, size) {
|
|
4162
|
+
return READ_DENY_RANGE_TEMPLATE.split(SIZE).join(String(size)).split(PATH).join(path8);
|
|
4163
|
+
}
|
|
4164
|
+
|
|
4165
|
+
// src/core/policy/own-file.ts
|
|
4166
|
+
import { extname, join as join5 } from "node:path";
|
|
4167
|
+
|
|
4168
|
+
// src/core/project/contain.ts
|
|
4169
|
+
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
4170
|
+
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4171
|
+
function real(p) {
|
|
4172
|
+
try {
|
|
4173
|
+
return realpathSync2.native(p);
|
|
4174
|
+
} catch {
|
|
4175
|
+
return void 0;
|
|
4176
|
+
}
|
|
4177
|
+
}
|
|
4178
|
+
function components(p) {
|
|
4179
|
+
return p.split(sep2).filter((c) => c !== "");
|
|
4180
|
+
}
|
|
4181
|
+
function isInside(root, p) {
|
|
4182
|
+
const r = real(root);
|
|
4183
|
+
const q = real(p);
|
|
4184
|
+
if (r === void 0 || q === void 0) return false;
|
|
4185
|
+
const rc = components(r);
|
|
4186
|
+
const qc = components(q);
|
|
4187
|
+
if (qc.length < rc.length) return false;
|
|
4188
|
+
for (let i = 0; i < rc.length; i += 1) {
|
|
4189
|
+
if (rc[i] !== qc[i]) return false;
|
|
4190
|
+
}
|
|
4191
|
+
return true;
|
|
4192
|
+
}
|
|
4193
|
+
var rootReal = /* @__PURE__ */ new Map();
|
|
4194
|
+
function realRoot(root) {
|
|
4195
|
+
const hit = rootReal.get(root);
|
|
4196
|
+
if (hit !== void 0) return hit;
|
|
4197
|
+
const r = real(root);
|
|
4198
|
+
if (r !== void 0) rootReal.set(root, r);
|
|
4199
|
+
return r;
|
|
4200
|
+
}
|
|
4201
|
+
function isInsideAny(roots, p) {
|
|
4202
|
+
if (roots.length === 0) return false;
|
|
4203
|
+
const q = real(p);
|
|
4204
|
+
if (q === void 0) return false;
|
|
4205
|
+
const qc = components(q);
|
|
4206
|
+
return roots.some((root) => {
|
|
4207
|
+
const r = realRoot(root);
|
|
4208
|
+
if (r === void 0) return false;
|
|
4209
|
+
const rc = components(r);
|
|
4210
|
+
return qc.length >= rc.length && rc.every((c, i) => c === qc[i]);
|
|
4211
|
+
});
|
|
4212
|
+
}
|
|
4213
|
+
function commonRoot(paths) {
|
|
4214
|
+
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
4215
|
+
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
4216
|
+
const first = reals[0];
|
|
4217
|
+
let n = components(first).length;
|
|
4218
|
+
for (const r of reals) {
|
|
4219
|
+
const rc = components(r);
|
|
4220
|
+
const fc = components(first);
|
|
4221
|
+
let i = 0;
|
|
4222
|
+
while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
|
|
4223
|
+
n = i;
|
|
4224
|
+
}
|
|
4225
|
+
let q = first;
|
|
4226
|
+
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
4227
|
+
return q;
|
|
4228
|
+
}
|
|
4229
|
+
function reachedThroughLink(root, p) {
|
|
4230
|
+
const rel = relative2(root, p);
|
|
4231
|
+
const steps = components(rel);
|
|
4232
|
+
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
4233
|
+
let at2 = root;
|
|
4234
|
+
for (const step of steps) {
|
|
4235
|
+
at2 = join4(at2, step);
|
|
4236
|
+
try {
|
|
4237
|
+
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
4238
|
+
} catch {
|
|
4239
|
+
return false;
|
|
4240
|
+
}
|
|
4241
|
+
}
|
|
4242
|
+
return false;
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4245
|
+
// src/core/policy/own-file.ts
|
|
4246
|
+
function ownDirsOf(agent, env) {
|
|
4247
|
+
const home = homeDirOf(env);
|
|
4248
|
+
if (home === null) return [];
|
|
4249
|
+
const shared = join5(home, ...SHARED_SKILLS_DIR);
|
|
4250
|
+
const own2 = 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])];
|
|
4251
|
+
return [...own2, shared];
|
|
4252
|
+
}
|
|
4253
|
+
function isOwnFile(agent, abs, env = process.env) {
|
|
4254
|
+
if (extname(abs).toLowerCase() !== AGENT_FILE_EXT) return false;
|
|
4255
|
+
return isInsideAny(ownDirsOf(agent, env), abs);
|
|
4256
|
+
}
|
|
4010
4257
|
|
|
4011
4258
|
// src/core/policy/read-media.ts
|
|
4012
|
-
import { extname } from "node:path";
|
|
4259
|
+
import { extname as extname2 } from "node:path";
|
|
4013
4260
|
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
4014
4261
|
function head(abs) {
|
|
4015
4262
|
let fd = null;
|
|
@@ -4027,7 +4274,7 @@ function head(abs) {
|
|
|
4027
4274
|
function isMediaRead(agent, abs) {
|
|
4028
4275
|
const types = READ_MEDIA_BY_AGENT[agent] ?? [];
|
|
4029
4276
|
if (types.length === 0) return false;
|
|
4030
|
-
const ext =
|
|
4277
|
+
const ext = extname2(abs).toLowerCase();
|
|
4031
4278
|
const named2 = types.filter((t) => READ_MEDIA_TYPES[t].exts.includes(ext));
|
|
4032
4279
|
if (named2.length === 0) return false;
|
|
4033
4280
|
const bytes5 = head(abs);
|
|
@@ -4058,7 +4305,7 @@ var deny = (reason) => ({ kind: "deny", reason });
|
|
|
4058
4305
|
var str = (v) => typeof v === "string" ? v : void 0;
|
|
4059
4306
|
var present = (v) => v !== void 0 && v !== null;
|
|
4060
4307
|
var has = (list4, v) => list4.includes(v);
|
|
4061
|
-
function decide(ev, row5, userDeny) {
|
|
4308
|
+
function decide(ev, row5, userDeny, root = ev.cwd) {
|
|
4062
4309
|
const tool = ev.tool;
|
|
4063
4310
|
if (tool === void 0) return ALLOW;
|
|
4064
4311
|
const canonical = tool.canonicalName;
|
|
@@ -4072,8 +4319,8 @@ function decide(ev, row5, userDeny) {
|
|
|
4072
4319
|
const hit = userDenyHit(canonical, input, ev.cwd, rules);
|
|
4073
4320
|
if (hit !== null) return deny(USER_DENY_REASON_PREFIX + hit);
|
|
4074
4321
|
if (canonical === WEBFETCH) return webFetch(input, row5);
|
|
4075
|
-
if (canonical === BASH) return bash(ev, row5, input, rules);
|
|
4076
|
-
if (canonical === READ) return read(ev, row5, input);
|
|
4322
|
+
if (canonical === BASH) return bash(ev, row5, input, rules, root);
|
|
4323
|
+
if (canonical === READ) return read(ev, row5, input, root);
|
|
4077
4324
|
return ALLOW;
|
|
4078
4325
|
}
|
|
4079
4326
|
function denyMessage(kind, match, row5, intent) {
|
|
@@ -4126,8 +4373,8 @@ function userDenyHit(canonical, input, cwd, rules) {
|
|
|
4126
4373
|
function isShellLanguage(language) {
|
|
4127
4374
|
if (typeof language !== "string") return false;
|
|
4128
4375
|
let name = language.toLowerCase();
|
|
4129
|
-
const
|
|
4130
|
-
if (
|
|
4376
|
+
const slash2 = Math.max(name.lastIndexOf("/"), name.lastIndexOf("\\"));
|
|
4377
|
+
if (slash2 >= 0) name = name.slice(slash2 + 1);
|
|
4131
4378
|
if (name.endsWith(EXE_SUFFIX2)) name = name.slice(0, name.length - EXE_SUFFIX2.length);
|
|
4132
4379
|
return name === SHELL_LANGUAGE || has(SHELL_FAMILY, name);
|
|
4133
4380
|
}
|
|
@@ -4175,10 +4422,10 @@ function webFetch(input, row5) {
|
|
|
4175
4422
|
const url2 = str(input.url) ?? "";
|
|
4176
4423
|
return neverDenied(url2) ? ALLOW : deny(denyMessage("webfetch", url2, row5));
|
|
4177
4424
|
}
|
|
4178
|
-
function bash(ev, row5, input, rules) {
|
|
4425
|
+
function bash(ev, row5, input, rules, root) {
|
|
4179
4426
|
const cmd = str(input.command) ?? "";
|
|
4180
4427
|
const parsed = parseShell(cmd);
|
|
4181
|
-
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(cmd,
|
|
4428
|
+
if (!parsed.ok) return couldMatch(cmd, rules) ? deny(prefixToolNames(PARSE_ERROR_DENY_LINE, row5.toolNamePrefix)) : psShellDump(ev, cmd, row5, root) ?? ALLOW;
|
|
4182
4429
|
const cmds = unwrap(parsed.commands);
|
|
4183
4430
|
for (const c of cmds) {
|
|
4184
4431
|
const h = segmentHit(c, rules);
|
|
@@ -4190,7 +4437,7 @@ function bash(ev, row5, input, rules) {
|
|
|
4190
4437
|
if (kind !== null) return deny(denyMessage(kind, cmd, row5, str(input.description)));
|
|
4191
4438
|
}
|
|
4192
4439
|
}
|
|
4193
|
-
return shellDump(cmds,
|
|
4440
|
+
return shellDump(ev, cmds, row5, root) ?? psShellDump(ev, cmd, row5, root) ?? ALLOW;
|
|
4194
4441
|
}
|
|
4195
4442
|
function denyKind(c) {
|
|
4196
4443
|
const name = c.argv0.toLowerCase();
|
|
@@ -4233,19 +4480,35 @@ function fileSize(abs) {
|
|
|
4233
4480
|
return -1;
|
|
4234
4481
|
}
|
|
4235
4482
|
}
|
|
4236
|
-
function
|
|
4483
|
+
function bigDeny(ev, row5, abs, size, root) {
|
|
4484
|
+
if (size <= OUTPUT_CAP || isOwnFile(ev.agent, abs)) return null;
|
|
4485
|
+
return deny(executeCanOpen(root, abs) ? READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix) : READ_DENY_RANGE_MESSAGE(abs, size));
|
|
4486
|
+
}
|
|
4487
|
+
function executeCanOpen(root, abs) {
|
|
4488
|
+
if (typeof root === "string") return isInsideAny([root], abs);
|
|
4489
|
+
if (isInsideAny([root.worktree], abs)) return true;
|
|
4490
|
+
try {
|
|
4491
|
+
return isInsideAny([root.containmentRoot], abs);
|
|
4492
|
+
} catch {
|
|
4493
|
+
return false;
|
|
4494
|
+
}
|
|
4495
|
+
}
|
|
4496
|
+
function read(ev, row5, input, root) {
|
|
4237
4497
|
if (!present(input.offset) && !present(input.limit)) {
|
|
4238
4498
|
for (const p of readPaths(input)) {
|
|
4239
4499
|
const abs = resolve3(ev.cwd, p);
|
|
4240
4500
|
const size = fileSize(abs);
|
|
4241
|
-
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs))
|
|
4501
|
+
if (size > OUTPUT_CAP && !isMediaRead(ev.agent, abs)) {
|
|
4502
|
+
const d = bigDeny(ev, row5, abs, size, root);
|
|
4503
|
+
if (d !== null) return d;
|
|
4504
|
+
}
|
|
4242
4505
|
}
|
|
4243
4506
|
}
|
|
4244
4507
|
return ALLOW;
|
|
4245
4508
|
}
|
|
4246
|
-
function shellDump(cmds,
|
|
4509
|
+
function shellDump(ev, cmds, row5, root) {
|
|
4247
4510
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
4248
|
-
let dir = cwd;
|
|
4511
|
+
let dir = ev.cwd;
|
|
4249
4512
|
let verdict = null;
|
|
4250
4513
|
for (const c of cmds) {
|
|
4251
4514
|
const name = c.argv0.toLowerCase();
|
|
@@ -4259,16 +4522,16 @@ function shellDump(cmds, cwd, row5) {
|
|
|
4259
4522
|
continue;
|
|
4260
4523
|
}
|
|
4261
4524
|
const abs = resolve3(dir, d.file);
|
|
4262
|
-
const
|
|
4263
|
-
if (
|
|
4525
|
+
const big = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
4526
|
+
if (big !== null) return big;
|
|
4264
4527
|
}
|
|
4265
4528
|
return verdict;
|
|
4266
4529
|
}
|
|
4267
|
-
function psShellDump(cmd,
|
|
4530
|
+
function psShellDump(ev, cmd, row5, root) {
|
|
4268
4531
|
if (row5.nativeTools.read !== void 0 && row5.nativeTools.read.length > 0 && dumpRunsThenReplaces(row5)) return null;
|
|
4269
|
-
for (const abs of psDumpFiles(cmd, cwd)) {
|
|
4270
|
-
const
|
|
4271
|
-
if (
|
|
4532
|
+
for (const abs of psDumpFiles(cmd, ev.cwd)) {
|
|
4533
|
+
const d = bigDeny(ev, row5, abs, fileSize(abs), root);
|
|
4534
|
+
if (d !== null) return d;
|
|
4272
4535
|
}
|
|
4273
4536
|
return null;
|
|
4274
4537
|
}
|
|
@@ -4329,64 +4592,7 @@ function dumpTarget(name, args) {
|
|
|
4329
4592
|
}
|
|
4330
4593
|
|
|
4331
4594
|
// src/core/project/resolve.ts
|
|
4332
|
-
import { basename as basename2, dirname as dirname3, join as
|
|
4333
|
-
|
|
4334
|
-
// src/core/project/contain.ts
|
|
4335
|
-
import { dirname as dirname2, join as join4, relative as relative2, sep as sep2 } from "node:path";
|
|
4336
|
-
var { lstatSync, realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
4337
|
-
function real(p) {
|
|
4338
|
-
try {
|
|
4339
|
-
return realpathSync2.native(p);
|
|
4340
|
-
} catch {
|
|
4341
|
-
return void 0;
|
|
4342
|
-
}
|
|
4343
|
-
}
|
|
4344
|
-
function components(p) {
|
|
4345
|
-
return p.split(sep2).filter((c) => c !== "");
|
|
4346
|
-
}
|
|
4347
|
-
function isInside(root, p) {
|
|
4348
|
-
const r = real(root);
|
|
4349
|
-
const q = real(p);
|
|
4350
|
-
if (r === void 0 || q === void 0) return false;
|
|
4351
|
-
const rc = components(r);
|
|
4352
|
-
const qc = components(q);
|
|
4353
|
-
if (qc.length < rc.length) return false;
|
|
4354
|
-
for (let i = 0; i < rc.length; i += 1) {
|
|
4355
|
-
if (rc[i] !== qc[i]) return false;
|
|
4356
|
-
}
|
|
4357
|
-
return true;
|
|
4358
|
-
}
|
|
4359
|
-
function commonRoot(paths) {
|
|
4360
|
-
const reals = paths.map(real).filter((r) => r !== void 0);
|
|
4361
|
-
if (reals.length === 0) throw new RangeError("commonRoot needs at least one existing path");
|
|
4362
|
-
const first = reals[0];
|
|
4363
|
-
let n = components(first).length;
|
|
4364
|
-
for (const r of reals) {
|
|
4365
|
-
const rc = components(r);
|
|
4366
|
-
const fc = components(first);
|
|
4367
|
-
let i = 0;
|
|
4368
|
-
while (i < n && i < rc.length && rc[i] === fc[i]) i += 1;
|
|
4369
|
-
n = i;
|
|
4370
|
-
}
|
|
4371
|
-
let q = first;
|
|
4372
|
-
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
4373
|
-
return q;
|
|
4374
|
-
}
|
|
4375
|
-
function reachedThroughLink(root, p) {
|
|
4376
|
-
const rel = relative2(root, p);
|
|
4377
|
-
const steps = components(rel);
|
|
4378
|
-
if (rel === "" || steps[0] === ".." || rel === p) return false;
|
|
4379
|
-
let at2 = root;
|
|
4380
|
-
for (const step of steps) {
|
|
4381
|
-
at2 = join4(at2, step);
|
|
4382
|
-
try {
|
|
4383
|
-
if (lstatSync(at2).isSymbolicLink()) return true;
|
|
4384
|
-
} catch {
|
|
4385
|
-
return false;
|
|
4386
|
-
}
|
|
4387
|
-
}
|
|
4388
|
-
return false;
|
|
4389
|
-
}
|
|
4595
|
+
import { basename as basename2, dirname as dirname3, join as join6, resolve as resolve4 } from "node:path";
|
|
4390
4596
|
|
|
4391
4597
|
// src/core/project/sha256.ts
|
|
4392
4598
|
var K = new Uint32Array([
|
|
@@ -4501,7 +4707,7 @@ function sha256Hex(text) {
|
|
|
4501
4707
|
}
|
|
4502
4708
|
|
|
4503
4709
|
// src/core/project/resolve.ts
|
|
4504
|
-
var { existsSync, readFileSync:
|
|
4710
|
+
var { existsSync: existsSync2, readFileSync: readFileSync4, realpathSync: realpathSync3, statSync: statSync2 } = process.getBuiltinModule("node:fs");
|
|
4505
4711
|
function sourceOf(agent) {
|
|
4506
4712
|
switch (agent) {
|
|
4507
4713
|
case "claude-code":
|
|
@@ -4548,9 +4754,9 @@ function gitDirs(dir) {
|
|
|
4548
4754
|
}
|
|
4549
4755
|
const start = cur;
|
|
4550
4756
|
for (; ; ) {
|
|
4551
|
-
const gitDir = gitDirAt(
|
|
4757
|
+
const gitDir = gitDirAt(join6(cur, GIT_DIR_NAME));
|
|
4552
4758
|
if (gitDir !== null) {
|
|
4553
|
-
const common = firstLine(
|
|
4759
|
+
const common = firstLine(join6(gitDir, GIT_COMMONDIR_FILE));
|
|
4554
4760
|
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
4555
4761
|
}
|
|
4556
4762
|
const up = dirname3(cur);
|
|
@@ -4571,12 +4777,12 @@ function gitDirAt(dotGit) {
|
|
|
4571
4777
|
} catch {
|
|
4572
4778
|
return null;
|
|
4573
4779
|
}
|
|
4574
|
-
return
|
|
4780
|
+
return existsSync2(join6(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
4575
4781
|
}
|
|
4576
4782
|
function firstLine(file2) {
|
|
4577
4783
|
let text;
|
|
4578
4784
|
try {
|
|
4579
|
-
text =
|
|
4785
|
+
text = readFileSync4(file2, "utf8");
|
|
4580
4786
|
} catch {
|
|
4581
4787
|
return null;
|
|
4582
4788
|
}
|
|
@@ -4612,11 +4818,11 @@ function resolveProject(agent, src) {
|
|
|
4612
4818
|
return key;
|
|
4613
4819
|
},
|
|
4614
4820
|
get projectDir() {
|
|
4615
|
-
pdir ??=
|
|
4821
|
+
pdir ??= join6(resolveConfigDir(process.env), PROJECTS_DIR_NAME, this.projectKey);
|
|
4616
4822
|
return pdir;
|
|
4617
4823
|
},
|
|
4618
4824
|
get dbPath() {
|
|
4619
|
-
return
|
|
4825
|
+
return join6(this.projectDir, DB_FILE_NAME);
|
|
4620
4826
|
},
|
|
4621
4827
|
worktree,
|
|
4622
4828
|
get containmentRoot() {
|
|
@@ -4767,7 +4973,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
4767
4973
|
}
|
|
4768
4974
|
|
|
4769
4975
|
// src/core/store/db.ts
|
|
4770
|
-
var { existsSync:
|
|
4976
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
4771
4977
|
function versionParts(v) {
|
|
4772
4978
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
4773
4979
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -4821,7 +5027,7 @@ function createAtomically(sqlite, path8) {
|
|
|
4821
5027
|
function openWritable(sqlite, path8) {
|
|
4822
5028
|
let raw = null;
|
|
4823
5029
|
try {
|
|
4824
|
-
if (!
|
|
5030
|
+
if (!existsSync3(path8)) createAtomically(sqlite, path8);
|
|
4825
5031
|
raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
4826
5032
|
applyMigrations(raw, readUserVersion(raw));
|
|
4827
5033
|
return raw;
|
|
@@ -4846,14 +5052,14 @@ async function openDb(project, opts) {
|
|
|
4846
5052
|
const sqlite = await loadSqlite();
|
|
4847
5053
|
mkdirSync2(project.projectDir, { recursive: true });
|
|
4848
5054
|
const path8 = project.dbPath;
|
|
4849
|
-
const sibling =
|
|
4850
|
-
if (sibling && !
|
|
5055
|
+
const sibling = existsSync3(path8 + DB_WAL_SUFFIX) || existsSync3(path8 + DB_SHM_SUFFIX);
|
|
5056
|
+
if (sibling && !existsSync3(path8)) {
|
|
4851
5057
|
throw new CtxError("DB_GONE");
|
|
4852
5058
|
}
|
|
4853
5059
|
try {
|
|
4854
5060
|
let raw;
|
|
4855
5061
|
if (opts?.readOnly === true) {
|
|
4856
|
-
if (!
|
|
5062
|
+
if (!existsSync3(path8)) openWritable(sqlite, path8).close();
|
|
4857
5063
|
raw = openReadOnly(sqlite, path8);
|
|
4858
5064
|
} else {
|
|
4859
5065
|
raw = openWritable(sqlite, path8);
|
|
@@ -5003,11 +5209,6 @@ function readLastPrompt(db, sessionId) {
|
|
|
5003
5209
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
5004
5210
|
return row5 === void 0 ? "" : row5.body;
|
|
5005
5211
|
}
|
|
5006
|
-
function readFirstPrompt(db, sessionId) {
|
|
5007
|
-
if (sessionId === "") return "";
|
|
5008
|
-
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
|
|
5009
|
-
return row5 === void 0 ? "" : row5.body;
|
|
5010
|
-
}
|
|
5011
5212
|
function readRecallRows(db, sessionId, worktree, limit) {
|
|
5012
5213
|
if (sessionId === "") return [];
|
|
5013
5214
|
return db.raw.prepare("SELECT * FROM events WHERE kind <> 'cost' AND (session_id = ? OR worktree = ?) ORDER BY seq DESC LIMIT ?").all(sessionId, worktree, limit);
|
|
@@ -7575,8 +7776,25 @@ function insertUnits(db, sourceId, sessionId, units) {
|
|
|
7575
7776
|
start = end;
|
|
7576
7777
|
}
|
|
7577
7778
|
}
|
|
7578
|
-
function recallQueryText(prompt
|
|
7579
|
-
|
|
7779
|
+
function recallQueryText(prompt) {
|
|
7780
|
+
const kept = /* @__PURE__ */ new Set();
|
|
7781
|
+
const all = /* @__PURE__ */ new Set();
|
|
7782
|
+
const add = (w) => {
|
|
7783
|
+
if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
|
|
7784
|
+
if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
|
|
7785
|
+
};
|
|
7786
|
+
let cur = "";
|
|
7787
|
+
for (const ch of prompt) {
|
|
7788
|
+
if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
|
|
7789
|
+
if (ch.trim() === "" || ch === "\0") {
|
|
7790
|
+
if (cur !== "") add(cur);
|
|
7791
|
+
cur = "";
|
|
7792
|
+
} else {
|
|
7793
|
+
cur += ch;
|
|
7794
|
+
}
|
|
7795
|
+
}
|
|
7796
|
+
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
7797
|
+
return [...kept.size > 0 ? kept : all].join(" ");
|
|
7580
7798
|
}
|
|
7581
7799
|
function queryUnits(db, sessionId, q, limit) {
|
|
7582
7800
|
const match = searchTerms(q).join(" OR ");
|
|
@@ -8165,7 +8383,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
8165
8383
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
8166
8384
|
return { end: start + r.read, written: r.written };
|
|
8167
8385
|
}
|
|
8168
|
-
function merge(src, blocks,
|
|
8386
|
+
function merge(src, blocks, join25, cap, lineCut) {
|
|
8169
8387
|
const out = [];
|
|
8170
8388
|
const scratch = new Uint8Array(cap);
|
|
8171
8389
|
let wide;
|
|
@@ -8175,7 +8393,7 @@ function merge(src, blocks, join24, cap, lineCut) {
|
|
|
8175
8393
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
8176
8394
|
};
|
|
8177
8395
|
for (const b of blocks) {
|
|
8178
|
-
if (cur !== void 0 && !
|
|
8396
|
+
if (cur !== void 0 && !join25) {
|
|
8179
8397
|
emit(cur.start, cur.end, curBytes);
|
|
8180
8398
|
cur = void 0;
|
|
8181
8399
|
}
|
|
@@ -8617,7 +8835,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
8617
8835
|
}
|
|
8618
8836
|
|
|
8619
8837
|
// src/core/hooks/fallback.ts
|
|
8620
|
-
import { join as
|
|
8838
|
+
import { join as join7, resolve as resolve5 } from "node:path";
|
|
8621
8839
|
var fs = process.getBuiltinModule("node:fs");
|
|
8622
8840
|
function isRec(v) {
|
|
8623
8841
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8645,9 +8863,9 @@ function homeOf(env) {
|
|
|
8645
8863
|
}
|
|
8646
8864
|
function hookLogPath(env) {
|
|
8647
8865
|
const dir = env[DATA_DIR_ENV];
|
|
8648
|
-
if (dir !== void 0 && dir !== "") return
|
|
8866
|
+
if (dir !== void 0 && dir !== "") return join7(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
8649
8867
|
const home = homeOf(env);
|
|
8650
|
-
return home === "" ? "" :
|
|
8868
|
+
return home === "" ? "" : join7(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
8651
8869
|
}
|
|
8652
8870
|
function errorLabel(err) {
|
|
8653
8871
|
const code = isRec(err) ? err.code : void 0;
|
|
@@ -8658,7 +8876,7 @@ function logHookError(env, agent, stage, err) {
|
|
|
8658
8876
|
try {
|
|
8659
8877
|
const file2 = hookLogPath(env);
|
|
8660
8878
|
if (file2 === "") return;
|
|
8661
|
-
fs.mkdirSync(
|
|
8879
|
+
fs.mkdirSync(join7(file2, ".."), { recursive: true });
|
|
8662
8880
|
const line = JSON.stringify({
|
|
8663
8881
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8664
8882
|
agent,
|
|
@@ -8740,7 +8958,7 @@ function bigFile(abs) {
|
|
|
8740
8958
|
function bigRead(agent, input, cwd) {
|
|
8741
8959
|
if ((input.offset ?? null) !== null || (input.limit ?? null) !== null) return false;
|
|
8742
8960
|
const many = Array.isArray(input[READ_PATH_LIST_KEY]) ? input[READ_PATH_LIST_KEY].filter((x) => typeof x === "string") : [];
|
|
8743
|
-
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)));
|
|
8961
|
+
return [firstString(input, READ_PATH_KEYS), ...many].some((p) => p !== "" && bigFile(resolve5(cwd, p)) && !isMediaRead(agent, resolve5(cwd, p)) && !isOwnFile(agent, resolve5(cwd, p)));
|
|
8744
8962
|
}
|
|
8745
8963
|
function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
8746
8964
|
const row5 = getAdapter(agent);
|
|
@@ -8766,7 +8984,7 @@ function failureOutput(agent, raw, err, cwdFallback = "") {
|
|
|
8766
8984
|
var { read: read2, writeSync } = process.getBuiltinModule("node:fs");
|
|
8767
8985
|
|
|
8768
8986
|
// src/core/hooks/dispatch.ts
|
|
8769
|
-
var { lstatSync: lstatSync2, readFileSync:
|
|
8987
|
+
var { lstatSync: lstatSync2, readFileSync: readFileSync5 } = process.getBuiltinModule("node:fs");
|
|
8770
8988
|
var ALLOW2 = { kind: "allow" };
|
|
8771
8989
|
var EMPTY5 = { stdout: "", exitCode: 0 };
|
|
8772
8990
|
var DIGIT_0 = 48;
|
|
@@ -8929,8 +9147,7 @@ async function recall(ev, row5, project, prompt) {
|
|
|
8929
9147
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
8930
9148
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
8931
9149
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
8932
|
-
const
|
|
8933
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt, goal), RECALL_UNIT_CANDIDATES);
|
|
9150
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
8934
9151
|
const picked = pickRecall(readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS), prompt, new Set(seen), units, new Set(seenUnits));
|
|
8935
9152
|
if (picked.text === "") return ALLOW2;
|
|
8936
9153
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
@@ -9002,7 +9219,7 @@ function askDetached(ev, project, tool, text) {
|
|
|
9002
9219
|
}
|
|
9003
9220
|
async function preToolUse(ev, row5, project, env) {
|
|
9004
9221
|
const userDeny = readUserDeny(project.worktree, ev.agent);
|
|
9005
|
-
const decision0 = decide(ev, row5, userDeny);
|
|
9222
|
+
const decision0 = decide(ev, row5, userDeny, project);
|
|
9006
9223
|
let decision = decision0;
|
|
9007
9224
|
if (decision0.kind === "deny" && isSubagentCall(ev) && !isUserPolicyDeny(decision0.reason, row5)) {
|
|
9008
9225
|
const set3 = toolSetForAgentType(ev, { projectDir: project.worktree, env });
|
|
@@ -9028,7 +9245,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
9028
9245
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
9029
9246
|
const command = tool.input.command;
|
|
9030
9247
|
if (typeof command !== "string") return d0;
|
|
9031
|
-
const wrapper = '"' +
|
|
9248
|
+
const wrapper = '"' + join8(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
9032
9249
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
9033
9250
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
9034
9251
|
}
|
|
@@ -9105,9 +9322,15 @@ async function postToolUse(ev, row5, project, env, settle) {
|
|
|
9105
9322
|
settle.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
|
|
9106
9323
|
return decision;
|
|
9107
9324
|
}
|
|
9325
|
+
function ownRead(ev, tool, env) {
|
|
9326
|
+
if (!RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9327
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9328
|
+
return p !== void 0 && isOwnFile(ev.agent, resolve6(ev.cwd, p), env);
|
|
9329
|
+
}
|
|
9108
9330
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9109
9331
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9110
9332
|
if (boundedRead(tool)) return ALLOW2;
|
|
9333
|
+
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
9111
9334
|
if (result.keep === true) return ALLOW2;
|
|
9112
9335
|
if (!hasReplace(row5)) return ALLOW2;
|
|
9113
9336
|
let label2;
|
|
@@ -9150,7 +9373,7 @@ function replaceBudget(handleLine, more) {
|
|
|
9150
9373
|
}
|
|
9151
9374
|
function hostToolResult(file2, sessionId, env) {
|
|
9152
9375
|
if (sessionId === "" || sessionId.includes(sep3) || sessionId.includes("/")) return false;
|
|
9153
|
-
const projects =
|
|
9376
|
+
const projects = join8(claudeDirOf(env, homeDirOf(env) ?? ""), PROJECTS_DIR_NAME);
|
|
9154
9377
|
const steps = relative3(projects, resolve6(file2)).split(sep3);
|
|
9155
9378
|
if (steps.length !== 4 || steps.includes("..") || steps.includes("")) return false;
|
|
9156
9379
|
if (steps[1] !== sessionId || steps[2] !== CLAUDE_TOOL_RESULTS_DIR_NAME) return false;
|
|
@@ -9165,7 +9388,7 @@ function wholeOutput(result, sessionId, env) {
|
|
|
9165
9388
|
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"));
|
|
9166
9389
|
return head2;
|
|
9167
9390
|
}
|
|
9168
|
-
return
|
|
9391
|
+
return readFileSync5(result.persistedPath, "utf8");
|
|
9169
9392
|
} catch {
|
|
9170
9393
|
return head2;
|
|
9171
9394
|
}
|
|
@@ -20496,11 +20719,11 @@ function noRuntimeError(lang) {
|
|
|
20496
20719
|
}
|
|
20497
20720
|
|
|
20498
20721
|
// src/core/sandbox/spawn.ts
|
|
20499
|
-
import { spawn } from "node:child_process";
|
|
20722
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
20500
20723
|
import path2 from "node:path";
|
|
20501
20724
|
|
|
20502
20725
|
// src/core/sandbox/kill.ts
|
|
20503
|
-
import {
|
|
20726
|
+
import { spawn } from "node:child_process";
|
|
20504
20727
|
function signalGroup(pid, signal) {
|
|
20505
20728
|
try {
|
|
20506
20729
|
process.kill(-pid, signal);
|
|
@@ -20514,7 +20737,10 @@ function killTree(pid) {
|
|
|
20514
20737
|
return;
|
|
20515
20738
|
}
|
|
20516
20739
|
try {
|
|
20517
|
-
|
|
20740
|
+
const t = spawn("taskkill", ["/F", "/T", "/PID", String(pid)], { stdio: "ignore", windowsHide: true });
|
|
20741
|
+
t.on("error", () => {
|
|
20742
|
+
});
|
|
20743
|
+
t.unref();
|
|
20518
20744
|
} catch {
|
|
20519
20745
|
}
|
|
20520
20746
|
}
|
|
@@ -20527,13 +20753,13 @@ function startArgv(argv) {
|
|
|
20527
20753
|
return sh === null ? null : [sh, ...argv];
|
|
20528
20754
|
}
|
|
20529
20755
|
function runProcess(argv, o) {
|
|
20530
|
-
return new Promise((
|
|
20756
|
+
return new Promise((resolve11) => {
|
|
20531
20757
|
const isWin2 = process.platform === "win32";
|
|
20532
20758
|
const start = startArgv(argv);
|
|
20533
|
-
if (start === null) return
|
|
20759
|
+
if (start === null) return resolve11(NOT_STARTED);
|
|
20534
20760
|
let child;
|
|
20535
20761
|
try {
|
|
20536
|
-
child =
|
|
20762
|
+
child = spawn2(start[0], start.slice(1), {
|
|
20537
20763
|
cwd: o.cwd,
|
|
20538
20764
|
env: o.env,
|
|
20539
20765
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -20544,14 +20770,20 @@ function runProcess(argv, o) {
|
|
|
20544
20770
|
windowsHide: true
|
|
20545
20771
|
});
|
|
20546
20772
|
} catch {
|
|
20547
|
-
return
|
|
20773
|
+
return resolve11(NOT_STARTED);
|
|
20548
20774
|
}
|
|
20549
20775
|
const stdoutChunks = [];
|
|
20550
20776
|
const stderrChunks = [];
|
|
20551
20777
|
let killedBy = null;
|
|
20552
20778
|
let settled = false;
|
|
20779
|
+
let held = false;
|
|
20780
|
+
let exited = false;
|
|
20781
|
+
let graceTimer;
|
|
20782
|
+
let drainTimer;
|
|
20783
|
+
let stopTimer;
|
|
20553
20784
|
const kill = () => {
|
|
20554
20785
|
if (child.pid !== void 0) killTree(child.pid);
|
|
20786
|
+
if (stopTimer === void 0) stopTimer = setTimeout(() => finishHeld(), KILL_GRACE_MS);
|
|
20555
20787
|
};
|
|
20556
20788
|
const onAbort = () => {
|
|
20557
20789
|
if (killedBy !== null || settled) return;
|
|
@@ -20568,17 +20800,46 @@ function runProcess(argv, o) {
|
|
|
20568
20800
|
if (settled) return;
|
|
20569
20801
|
settled = true;
|
|
20570
20802
|
clearTimeout(timer);
|
|
20803
|
+
clearTimeout(graceTimer);
|
|
20804
|
+
clearTimeout(drainTimer);
|
|
20805
|
+
clearTimeout(stopTimer);
|
|
20571
20806
|
o.signal.removeEventListener("abort", onAbort);
|
|
20572
|
-
|
|
20807
|
+
resolve11({
|
|
20573
20808
|
stdout: Buffer.concat(stdoutChunks),
|
|
20574
20809
|
stderr: Buffer.concat(stderrChunks),
|
|
20575
20810
|
exitCode,
|
|
20576
|
-
killed: killedBy
|
|
20811
|
+
killed: killedBy,
|
|
20812
|
+
...held ? { held: true } : {}
|
|
20577
20813
|
});
|
|
20578
20814
|
};
|
|
20579
|
-
|
|
20580
|
-
|
|
20815
|
+
const finishHeld = () => {
|
|
20816
|
+
if (settled) return;
|
|
20817
|
+
held = exited && killedBy === null;
|
|
20818
|
+
child.stdout.destroy();
|
|
20819
|
+
child.stderr.destroy();
|
|
20820
|
+
if (child.pid !== void 0) killTree(child.pid);
|
|
20821
|
+
settle(child.exitCode);
|
|
20822
|
+
};
|
|
20823
|
+
const bump = () => {
|
|
20824
|
+
if (!exited || settled) return;
|
|
20825
|
+
clearTimeout(graceTimer);
|
|
20826
|
+
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
20827
|
+
};
|
|
20828
|
+
child.stdout.on("data", (chunk) => {
|
|
20829
|
+
stdoutChunks.push(chunk);
|
|
20830
|
+
bump();
|
|
20831
|
+
});
|
|
20832
|
+
child.stderr.on("data", (chunk) => {
|
|
20833
|
+
stderrChunks.push(chunk);
|
|
20834
|
+
bump();
|
|
20835
|
+
});
|
|
20581
20836
|
child.on("close", (code) => settle(code));
|
|
20837
|
+
child.on("exit", () => {
|
|
20838
|
+
if (settled) return;
|
|
20839
|
+
exited = true;
|
|
20840
|
+
graceTimer = setTimeout(finishHeld, PIPE_EOF_GRACE_MS);
|
|
20841
|
+
drainTimer = setTimeout(finishHeld, PIPE_DRAIN_MAX_MS);
|
|
20842
|
+
});
|
|
20582
20843
|
child.on("error", () => settle(null));
|
|
20583
20844
|
child.stdin.on("error", () => {
|
|
20584
20845
|
});
|
|
@@ -20590,8 +20851,8 @@ function runProcess(argv, o) {
|
|
|
20590
20851
|
}
|
|
20591
20852
|
|
|
20592
20853
|
// src/core/index/auto-memory.ts
|
|
20593
|
-
import { readdirSync, readFileSync as
|
|
20594
|
-
import { join as
|
|
20854
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync6, statSync as statSync4 } from "node:fs";
|
|
20855
|
+
import { join as join9 } from "node:path";
|
|
20595
20856
|
var MEMORY_FILES = Object.freeze([
|
|
20596
20857
|
Object.freeze(["CLAUDE.md"]),
|
|
20597
20858
|
Object.freeze(["CLAUDE.local.md"]),
|
|
@@ -20605,7 +20866,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
20605
20866
|
var MD = ".md";
|
|
20606
20867
|
function steeringFiles(worktree) {
|
|
20607
20868
|
try {
|
|
20608
|
-
return
|
|
20869
|
+
return readdirSync2(join9(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
20609
20870
|
} catch {
|
|
20610
20871
|
return [];
|
|
20611
20872
|
}
|
|
@@ -20613,7 +20874,7 @@ function steeringFiles(worktree) {
|
|
|
20613
20874
|
function readAutoMemory(project) {
|
|
20614
20875
|
const rows = [];
|
|
20615
20876
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
20616
|
-
const path8 =
|
|
20877
|
+
const path8 = join9(project.worktree, ...segs);
|
|
20617
20878
|
if (!isInside(project.worktree, path8)) continue;
|
|
20618
20879
|
try {
|
|
20619
20880
|
const st = statSync4(path8);
|
|
@@ -20625,7 +20886,7 @@ function readAutoMemory(project) {
|
|
|
20625
20886
|
sourceId: null,
|
|
20626
20887
|
path: path8,
|
|
20627
20888
|
label: segs.join("/"),
|
|
20628
|
-
text:
|
|
20889
|
+
text: readFileSync6(path8, "utf8")
|
|
20629
20890
|
});
|
|
20630
20891
|
} catch {
|
|
20631
20892
|
}
|
|
@@ -21195,19 +21456,19 @@ var ctxBatch = Object.freeze({
|
|
|
21195
21456
|
});
|
|
21196
21457
|
|
|
21197
21458
|
// src/core/tools/doctor.ts
|
|
21198
|
-
import { readdirSync as
|
|
21199
|
-
import { basename as basename5, join as
|
|
21459
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync16, existsSync as existsSync16 } from "node:fs";
|
|
21460
|
+
import { basename as basename5, join as join19 } from "node:path";
|
|
21200
21461
|
|
|
21201
21462
|
// src/core/ops/bundle-dir.ts
|
|
21202
|
-
import { existsSync as
|
|
21203
|
-
import { dirname as dirname5, join as
|
|
21463
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
21464
|
+
import { dirname as dirname5, join as join10 } from "node:path";
|
|
21204
21465
|
import { fileURLToPath } from "node:url";
|
|
21205
21466
|
function bundleDirOf(argv1, moduleFile) {
|
|
21206
21467
|
const own2 = dirname5(argv1);
|
|
21207
|
-
if (
|
|
21468
|
+
if (existsSync4(join10(own2, SERVER_ENTRY_FILE))) return own2;
|
|
21208
21469
|
let dir = dirname5(moduleFile);
|
|
21209
21470
|
for (; ; ) {
|
|
21210
|
-
if (
|
|
21471
|
+
if (existsSync4(join10(dir, SERVER_ENTRY_FILE))) return dir;
|
|
21211
21472
|
const up = dirname5(dir);
|
|
21212
21473
|
if (up === dir) return own2;
|
|
21213
21474
|
dir = up;
|
|
@@ -21221,17 +21482,17 @@ function ownBundleDir() {
|
|
|
21221
21482
|
}
|
|
21222
21483
|
|
|
21223
21484
|
// src/core/ops/doctor-config.ts
|
|
21224
|
-
import { existsSync as
|
|
21225
|
-
import { join as
|
|
21485
|
+
import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync11 } from "node:fs";
|
|
21486
|
+
import { dirname as dirname8, join as join14 } from "node:path";
|
|
21226
21487
|
|
|
21227
21488
|
// src/core/ops/detect-v1.ts
|
|
21228
|
-
import { existsSync as
|
|
21489
|
+
import { existsSync as existsSync6, opendirSync, readdirSync as readdirSync3, readFileSync as readFileSync8 } from "node:fs";
|
|
21229
21490
|
import { tmpdir } from "node:os";
|
|
21230
|
-
import { join as
|
|
21491
|
+
import { join as join12 } from "node:path";
|
|
21231
21492
|
|
|
21232
21493
|
// src/core/ops/host-config.ts
|
|
21233
|
-
import { existsSync as
|
|
21234
|
-
import { dirname as dirname6, join as
|
|
21494
|
+
import { existsSync as existsSync5, readFileSync as readFileSync7 } from "node:fs";
|
|
21495
|
+
import { dirname as dirname6, join as join11 } from "node:path";
|
|
21235
21496
|
|
|
21236
21497
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
21237
21498
|
var KEYS2 = {
|
|
@@ -23348,10 +23609,10 @@ function formatOf(path8) {
|
|
|
23348
23609
|
function readHostConfig(agent, path8) {
|
|
23349
23610
|
let file2 = path8;
|
|
23350
23611
|
if (agent === "opencode") {
|
|
23351
|
-
const jsonc =
|
|
23352
|
-
if (
|
|
23612
|
+
const jsonc = join11(dirname6(path8), OPENCODE_CONFIG_FILES[0]);
|
|
23613
|
+
if (existsSync5(jsonc)) file2 = jsonc;
|
|
23353
23614
|
}
|
|
23354
|
-
const raw =
|
|
23615
|
+
const raw = existsSync5(file2) ? readFileSync7(file2, "utf8") : "";
|
|
23355
23616
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
23356
23617
|
}
|
|
23357
23618
|
function stripJsonComments(text) {
|
|
@@ -23696,7 +23957,7 @@ function setText(agent, path8, text, format, key, value) {
|
|
|
23696
23957
|
}
|
|
23697
23958
|
}
|
|
23698
23959
|
function serverScript() {
|
|
23699
|
-
return
|
|
23960
|
+
return join11(dirname6(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
23700
23961
|
}
|
|
23701
23962
|
function isNodeCommand(command) {
|
|
23702
23963
|
if (typeof command !== "string") return false;
|
|
@@ -23823,14 +24084,14 @@ function stripJsonc(text) {
|
|
|
23823
24084
|
}
|
|
23824
24085
|
function readJson(file2) {
|
|
23825
24086
|
try {
|
|
23826
|
-
return JSON.parse(stripJsonc(hostText(
|
|
24087
|
+
return JSON.parse(stripJsonc(hostText(readFileSync8(file2, "utf8"))));
|
|
23827
24088
|
} catch {
|
|
23828
24089
|
return void 0;
|
|
23829
24090
|
}
|
|
23830
24091
|
}
|
|
23831
24092
|
function readText(file2) {
|
|
23832
24093
|
try {
|
|
23833
|
-
return hostText(
|
|
24094
|
+
return hostText(readFileSync8(file2, "utf8"));
|
|
23834
24095
|
} catch {
|
|
23835
24096
|
return "";
|
|
23836
24097
|
}
|
|
@@ -23887,7 +24148,7 @@ function flatCommands(events, prefix) {
|
|
|
23887
24148
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
23888
24149
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep5) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep5) + sep5));
|
|
23889
24150
|
function dataDir(dir, reason, out) {
|
|
23890
|
-
if (
|
|
24151
|
+
if (existsSync6(dir)) out.push(finding(dir, "", reason));
|
|
23891
24152
|
}
|
|
23892
24153
|
function mcpEntry(file2, doc, out) {
|
|
23893
24154
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -23895,7 +24156,7 @@ function mcpEntry(file2, doc, out) {
|
|
|
23895
24156
|
}
|
|
23896
24157
|
}
|
|
23897
24158
|
function claudeShapeSettings(agentHome, out) {
|
|
23898
|
-
const file2 =
|
|
24159
|
+
const file2 = join12(agentHome, SETTINGS_FILE);
|
|
23899
24160
|
const doc = readJson(file2);
|
|
23900
24161
|
for (const c of nestedCommands(doc)) {
|
|
23901
24162
|
if (c.command.includes(V1_CACHE_HEAL_NAME)) out.push(finding(file2, c.path, V1_REASON.cacheHealHook));
|
|
@@ -23915,63 +24176,64 @@ function v1HookFile(file2, out) {
|
|
|
23915
24176
|
function scanClaudeCode(home, agentHome, out) {
|
|
23916
24177
|
claudeShapeSettings(agentHome, out);
|
|
23917
24178
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
23918
|
-
const file2 =
|
|
23919
|
-
if (
|
|
24179
|
+
const file2 = join12(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
24180
|
+
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
23920
24181
|
}
|
|
23921
|
-
const userFile =
|
|
24182
|
+
const userFile = join12(home, CLAUDE_USER_CONFIG_FILE);
|
|
23922
24183
|
mcpEntry(userFile, readJson(userFile), out);
|
|
23923
|
-
dataDir(
|
|
24184
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23924
24185
|
}
|
|
23925
24186
|
function scanCodex(agentHome, out) {
|
|
23926
|
-
const hooksFile =
|
|
24187
|
+
const hooksFile = join12(agentHome, HOOKS_JSON_FILE);
|
|
23927
24188
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
23928
24189
|
if (c.command.includes(V1_CODEX_HOOK_COMMAND) || isCodexScript(c.command)) {
|
|
23929
24190
|
out.push(finding(hooksFile, c.path, V1_REASON.codexHook));
|
|
23930
24191
|
}
|
|
23931
24192
|
}
|
|
23932
|
-
const tomlFile =
|
|
24193
|
+
const tomlFile = join12(agentHome, CONFIG_TOML_FILE);
|
|
23933
24194
|
const config2 = readTomlValue(tomlFile);
|
|
23934
24195
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
23935
24196
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23936
24197
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config2, span2.path))) continue;
|
|
24198
|
+
if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config2, span2.path.slice(0, 2)))) continue;
|
|
23937
24199
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23938
24200
|
}
|
|
23939
|
-
dataDir(
|
|
24201
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23940
24202
|
}
|
|
23941
24203
|
function scanGemini(agentHome, out) {
|
|
23942
|
-
const file2 =
|
|
24204
|
+
const file2 = join12(agentHome, SETTINGS_FILE);
|
|
23943
24205
|
for (const c of nestedCommands(readJson(file2))) {
|
|
23944
24206
|
if (c.command.includes(SERVER_KEY)) out.push(finding(file2, c.path, V1_REASON.hook));
|
|
23945
24207
|
}
|
|
23946
|
-
dataDir(
|
|
24208
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDirShared, out);
|
|
23947
24209
|
}
|
|
23948
24210
|
function scanVscode(agentHome, project, out) {
|
|
23949
24211
|
if (project !== void 0) {
|
|
23950
|
-
v1HookFile(
|
|
23951
|
-
const mcpFile2 =
|
|
24212
|
+
v1HookFile(join12(project, GITHUB_DIR_NAME, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24213
|
+
const mcpFile2 = join12(project, VSCODE_DIR_NAME, VSCODE_MCP_FILE);
|
|
23952
24214
|
const doc = readJson(mcpFile2);
|
|
23953
24215
|
const servers = isObj(doc) && isObj(doc[VSCODE_MCP_SERVERS_KEY]) ? doc[VSCODE_MCP_SERVERS_KEY] : {};
|
|
23954
24216
|
const entry = Object.hasOwn(servers, SERVER_KEY) ? servers[SERVER_KEY] : void 0;
|
|
23955
24217
|
if (isObj(entry) && (entry.command === V1_BIN_COMMAND || listOf(entry.args).some((a) => a === V1_BIN_COMMAND))) {
|
|
23956
24218
|
out.push(finding(mcpFile2, keyPath(VSCODE_MCP_SERVERS_KEY, SERVER_KEY), V1_REASON.vscodeMcp));
|
|
23957
24219
|
}
|
|
23958
|
-
const sessions =
|
|
24220
|
+
const sessions = join12(project, GITHUB_DIR_NAME, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME);
|
|
23959
24221
|
dataDir(sessions, reachedThroughLink(project, sessions) ? V1_REASON.projectLink : V1_REASON.dataDir, out);
|
|
23960
24222
|
}
|
|
23961
|
-
dataDir(
|
|
24223
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME, V1_SESSIONS_DIR_NAME), V1_REASON.dataDir, out);
|
|
23962
24224
|
}
|
|
23963
24225
|
function jsonFiles(dir) {
|
|
23964
24226
|
try {
|
|
23965
|
-
return
|
|
24227
|
+
return readdirSync3(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
23966
24228
|
} catch {
|
|
23967
24229
|
return [];
|
|
23968
24230
|
}
|
|
23969
24231
|
}
|
|
23970
24232
|
function scanKiro(agentHome, project, out) {
|
|
23971
|
-
const agentsDir =
|
|
23972
|
-
const defaultFile =
|
|
24233
|
+
const agentsDir = join12(agentHome, KIRO_AGENTS_DIR);
|
|
24234
|
+
const defaultFile = join12(agentHome, ...KIRO_AGENT_FILE);
|
|
23973
24235
|
for (const name of jsonFiles(agentsDir)) {
|
|
23974
|
-
const file2 =
|
|
24236
|
+
const file2 = join12(agentsDir, name);
|
|
23975
24237
|
const doc = readJson(file2);
|
|
23976
24238
|
if (isObj(doc) && doc[KIRO_AGENT_NAME_KEY] === SERVER_KEY) {
|
|
23977
24239
|
out.push(finding(file2, "", V1_REASON.kiroAgentFile));
|
|
@@ -23982,31 +24244,31 @@ function scanKiro(agentHome, project, out) {
|
|
|
23982
24244
|
if (isV1Hook(c.command)) out.push(finding(file2, c.path, V1_REASON.kiroHook));
|
|
23983
24245
|
}
|
|
23984
24246
|
}
|
|
23985
|
-
const steeringDocs = [
|
|
23986
|
-
if (project !== void 0) steeringDocs.push(
|
|
24247
|
+
const steeringDocs = [join12(agentHome, ...KIRO_STEERING_FILE)];
|
|
24248
|
+
if (project !== void 0) steeringDocs.push(join12(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
23987
24249
|
for (const file2 of steeringDocs) {
|
|
23988
|
-
if (
|
|
24250
|
+
if (existsSync6(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
23989
24251
|
}
|
|
23990
|
-
dataDir(
|
|
24252
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23991
24253
|
}
|
|
23992
24254
|
function piNpmIsCurrent(piAgentDir) {
|
|
23993
|
-
const doc = readJson(
|
|
24255
|
+
const doc = readJson(join12(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
23994
24256
|
const version2 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
23995
24257
|
return Number.parseInt(version2, 10) >= PI_CURRENT_MAJOR;
|
|
23996
24258
|
}
|
|
23997
24259
|
function scanPi(piAgentDir, agentHome, out) {
|
|
23998
|
-
const file2 =
|
|
24260
|
+
const file2 = join12(piAgentDir, SETTINGS_FILE);
|
|
23999
24261
|
const doc = readJson(file2);
|
|
24000
24262
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
24001
24263
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
24002
24264
|
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
24003
24265
|
if (spec === PI_GIT_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piGit));
|
|
24004
24266
|
});
|
|
24005
|
-
dataDir(
|
|
24267
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24006
24268
|
}
|
|
24007
24269
|
function scanOpencode(agentHome, out) {
|
|
24008
24270
|
for (const name of OPENCODE_CONFIG_FILES) {
|
|
24009
|
-
const file2 =
|
|
24271
|
+
const file2 = join12(agentHome, name);
|
|
24010
24272
|
const doc = readJson(file2);
|
|
24011
24273
|
if (!isObj(doc) || !Array.isArray(doc[OPENCODE_PLUGIN_KEY])) continue;
|
|
24012
24274
|
doc[OPENCODE_PLUGIN_KEY].forEach((spec, i) => {
|
|
@@ -24017,13 +24279,13 @@ function scanOpencode(agentHome, out) {
|
|
|
24017
24279
|
}
|
|
24018
24280
|
}
|
|
24019
24281
|
function scanZcode(agentHome, out) {
|
|
24020
|
-
const configFile =
|
|
24282
|
+
const configFile = join12(agentHome, ZCODE_CLI_DIR, CONFIG_JSON_FILE);
|
|
24021
24283
|
const config2 = readJson(configFile);
|
|
24022
24284
|
const events = isObj(config2) && isObj(config2[HOOKS_KEY]) ? config2[HOOKS_KEY][ZCODE_EVENTS_KEY] : void 0;
|
|
24023
24285
|
for (const c of flatCommands(events, [HOOKS_KEY, ZCODE_EVENTS_KEY])) {
|
|
24024
24286
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(configFile, c.path, V1_REASON.zcodeHook));
|
|
24025
24287
|
}
|
|
24026
|
-
const hooksFile =
|
|
24288
|
+
const hooksFile = join12(agentHome, ZCODE_CLI_DIR, HOOKS_JSON_FILE);
|
|
24027
24289
|
for (const c of nestedCommands(readJson(hooksFile))) {
|
|
24028
24290
|
if (c.command.includes(V1_HOOK_COMMAND)) out.push(finding(hooksFile, c.path, V1_REASON.zcodeHook));
|
|
24029
24291
|
}
|
|
@@ -24047,14 +24309,14 @@ function firstTmpMatch(dir) {
|
|
|
24047
24309
|
}
|
|
24048
24310
|
}
|
|
24049
24311
|
function scanAll(home, tmp, out) {
|
|
24050
|
-
const root =
|
|
24051
|
-
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(
|
|
24312
|
+
const root = join12(home, DATA_ROOT.slice(1));
|
|
24313
|
+
for (const name of V1_DATA_ROOT_ENTRIES) dataDir(join12(root, name), V1_REASON.dataRoot, out);
|
|
24052
24314
|
if (firstTmpMatch(tmp) !== null) out.push(finding(tmp, V1_TMP_PREFIX + "*", V1_REASON.tmpFile));
|
|
24053
24315
|
}
|
|
24054
24316
|
function detectV1(agent, home, scope = {}) {
|
|
24055
24317
|
const out = [];
|
|
24056
24318
|
const project = scope.project;
|
|
24057
|
-
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 :
|
|
24319
|
+
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]);
|
|
24058
24320
|
switch (agent) {
|
|
24059
24321
|
case "claude-code":
|
|
24060
24322
|
scanClaudeCode(home, agentHome, out);
|
|
@@ -24067,11 +24329,11 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24067
24329
|
break;
|
|
24068
24330
|
case "qwen":
|
|
24069
24331
|
claudeShapeSettings(agentHome, out);
|
|
24070
|
-
dataDir(
|
|
24332
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24071
24333
|
break;
|
|
24072
24334
|
case "copilot-cli":
|
|
24073
|
-
v1HookFile(
|
|
24074
|
-
dataDir(
|
|
24335
|
+
v1HookFile(join12(agentHome, V1_HOOKS_DIR_NAME, OWN_HOOK_FILE), out);
|
|
24336
|
+
dataDir(join12(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
24075
24337
|
break;
|
|
24076
24338
|
case "vscode":
|
|
24077
24339
|
scanVscode(agentHome, project, out);
|
|
@@ -24080,7 +24342,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24080
24342
|
scanKiro(agentHome, project, out);
|
|
24081
24343
|
break;
|
|
24082
24344
|
case "pi":
|
|
24083
|
-
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir :
|
|
24345
|
+
scanPi(scope.piAgentDir !== void 0 && scope.piAgentDir !== "" ? scope.piAgentDir : join12(agentHome, PI_AGENT_DIR), agentHome, out);
|
|
24084
24346
|
break;
|
|
24085
24347
|
// D-WIN-PIDIR-1: empty is unset
|
|
24086
24348
|
case "opencode":
|
|
@@ -24095,8 +24357,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
24095
24357
|
}
|
|
24096
24358
|
|
|
24097
24359
|
// src/core/ops/plugin-root.ts
|
|
24098
|
-
import { existsSync as
|
|
24099
|
-
import { dirname as dirname7, isAbsolute as isAbsolute2, join as
|
|
24360
|
+
import { existsSync as existsSync7, readdirSync as readdirSync4, readFileSync as readFileSync9, realpathSync as realpathSync4 } from "node:fs";
|
|
24361
|
+
import { dirname as dirname7, isAbsolute as isAbsolute2, join as join13, sep as sep4 } from "node:path";
|
|
24100
24362
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
24101
24363
|
function missing(agent, path8) {
|
|
24102
24364
|
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
@@ -24137,15 +24399,15 @@ var realOrNull = (path8) => {
|
|
|
24137
24399
|
};
|
|
24138
24400
|
var readOrNull = (file2) => {
|
|
24139
24401
|
try {
|
|
24140
|
-
return
|
|
24402
|
+
return readFileSync9(file2, "utf8");
|
|
24141
24403
|
} catch {
|
|
24142
24404
|
return null;
|
|
24143
24405
|
}
|
|
24144
24406
|
};
|
|
24145
24407
|
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
24146
24408
|
function enabledPlugins(claudeDir, project) {
|
|
24147
|
-
const files = [
|
|
24148
|
-
if (project !== void 0) files.push(
|
|
24409
|
+
const files = [join13(claudeDir, SETTINGS_FILE)];
|
|
24410
|
+
if (project !== void 0) files.push(join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join13(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
24149
24411
|
const out = {};
|
|
24150
24412
|
for (const file2 of files) {
|
|
24151
24413
|
const text = readOrNull(file2);
|
|
@@ -24161,10 +24423,10 @@ function marketplaceChoice(env, worktree) {
|
|
|
24161
24423
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24162
24424
|
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
24163
24425
|
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
24164
|
-
const record4 = readOrNull(
|
|
24426
|
+
const record4 = readOrNull(join13(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
24165
24427
|
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
24166
24428
|
if (recorded.length === 0) return { record: false };
|
|
24167
|
-
const live = recorded.filter((r) =>
|
|
24429
|
+
const live = recorded.filter((r) => existsSync7(r.installPath));
|
|
24168
24430
|
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
24169
24431
|
if (mine !== void 0) return { root: mine.installPath };
|
|
24170
24432
|
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
@@ -24184,18 +24446,18 @@ function marketplaceChoice(env, worktree) {
|
|
|
24184
24446
|
}
|
|
24185
24447
|
function marketplaceRoot(adapter, env, worktree) {
|
|
24186
24448
|
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
24187
|
-
const plugins =
|
|
24188
|
-
const cache =
|
|
24449
|
+
const plugins = join13(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
24450
|
+
const cache = join13(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
24189
24451
|
const script = process.argv[1];
|
|
24190
24452
|
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname7(script));
|
|
24191
24453
|
const choice = marketplaceChoice(env, worktree);
|
|
24192
24454
|
if ("root" in choice) return choice.root;
|
|
24193
24455
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
24194
24456
|
const cacheReal = realOrNull(cache);
|
|
24195
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) &&
|
|
24196
|
-
const pattern =
|
|
24197
|
-
if (!
|
|
24198
|
-
const found =
|
|
24457
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep4) && existsSync7(join13(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
24458
|
+
const pattern = join13(cache, "*", PLUGIN_NAME);
|
|
24459
|
+
if (!existsSync7(cache)) throw missing(adapter.id, pattern);
|
|
24460
|
+
const found = readdirSync4(cache).sort().map((marketplace) => join13(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync7(dir));
|
|
24199
24461
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
24200
24462
|
return found[0];
|
|
24201
24463
|
}
|
|
@@ -24203,7 +24465,7 @@ function configEntryRoot(adapter, env) {
|
|
|
24203
24465
|
const spec = OWN_MCP_ENTRY[adapter.id];
|
|
24204
24466
|
if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
|
|
24205
24467
|
const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
|
|
24206
|
-
if (!
|
|
24468
|
+
if (!existsSync7(file2)) throw missing(adapter.id, file2);
|
|
24207
24469
|
const current = readHostConfig(adapter.id, file2);
|
|
24208
24470
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
24209
24471
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
@@ -24220,9 +24482,9 @@ function candidate(adapter, env, worktree) {
|
|
|
24220
24482
|
case "hooks+mcp":
|
|
24221
24483
|
return configEntryRoot(adapter, env);
|
|
24222
24484
|
case "extension":
|
|
24223
|
-
return
|
|
24485
|
+
return join13(adapter.id === "gemini" ? geminiDirOf(env, requireHomeDir(env)) : join13(requireHomeDir(env), ...AGENT_HOME_DIR[adapter.id]), EXTENSIONS_DIR_NAME, PLUGIN_NAME);
|
|
24224
24486
|
case "plugin":
|
|
24225
|
-
return
|
|
24487
|
+
return join13(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
24226
24488
|
case "in-process":
|
|
24227
24489
|
return dirname7(fileURLToPath2(import.meta.url));
|
|
24228
24490
|
}
|
|
@@ -24237,7 +24499,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
24237
24499
|
}
|
|
24238
24500
|
|
|
24239
24501
|
// src/setup/pi-gate.ts
|
|
24240
|
-
import { existsSync as
|
|
24502
|
+
import { existsSync as existsSync8, readFileSync as readFileSync10, realpathSync as realpathSync5 } from "node:fs";
|
|
24241
24503
|
import path4 from "node:path";
|
|
24242
24504
|
var EXTENSIONS_KEY = "extensions";
|
|
24243
24505
|
var PROJECT_DIR = ".pi";
|
|
@@ -24245,9 +24507,9 @@ var TRUST_FILE = "trust.json";
|
|
|
24245
24507
|
var ALWAYS = "always";
|
|
24246
24508
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
24247
24509
|
function load(file2) {
|
|
24248
|
-
if (!
|
|
24510
|
+
if (!existsSync8(file2)) return void 0;
|
|
24249
24511
|
try {
|
|
24250
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
24512
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync10(file2, "utf8")), "json") };
|
|
24251
24513
|
} catch {
|
|
24252
24514
|
return void 0;
|
|
24253
24515
|
}
|
|
@@ -24382,11 +24644,11 @@ function ownHooks(block, shape, timeoutKey, native, agent) {
|
|
|
24382
24644
|
var validTimeout = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
|
|
24383
24645
|
function mcpFile(row5, home, env) {
|
|
24384
24646
|
const spec = OWN_MCP_ENTRY[row5.id];
|
|
24385
|
-
if (row5.id === "codex") return
|
|
24647
|
+
if (row5.id === "codex") return join14(codexDirOf(env, home), CONFIG_TOML_FILE);
|
|
24386
24648
|
if (spec !== void 0) return ownMcpFileOf(row5.id, spec.file, env, home);
|
|
24387
|
-
if (row5.id === "opencode") return
|
|
24649
|
+
if (row5.id === "opencode") return join14(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
24388
24650
|
if (row5.id === "pi") {
|
|
24389
|
-
return
|
|
24651
|
+
return join14(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
24390
24652
|
}
|
|
24391
24653
|
return null;
|
|
24392
24654
|
}
|
|
@@ -24399,27 +24661,27 @@ function codexNativeDir(env, home) {
|
|
|
24399
24661
|
const codexDir = codexDirOf(env, home);
|
|
24400
24662
|
let enabled;
|
|
24401
24663
|
try {
|
|
24402
|
-
enabled = hostConfigValueAt(readParsed("codex",
|
|
24664
|
+
enabled = hostConfigValueAt(readParsed("codex", join14(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
24403
24665
|
} catch {
|
|
24404
24666
|
return null;
|
|
24405
24667
|
}
|
|
24406
24668
|
if (enabled !== true) return null;
|
|
24407
|
-
const cache =
|
|
24408
|
-
if (!
|
|
24669
|
+
const cache = join14(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
24670
|
+
if (!existsSync9(cache)) return null;
|
|
24409
24671
|
const found = [];
|
|
24410
|
-
for (const market of
|
|
24411
|
-
const plugin =
|
|
24412
|
-
if (!
|
|
24413
|
-
for (const version2 of
|
|
24414
|
-
const dir =
|
|
24415
|
-
if (
|
|
24672
|
+
for (const market of readdirSync5(cache)) {
|
|
24673
|
+
const plugin = join14(cache, market, SERVER_KEY);
|
|
24674
|
+
if (!existsSync9(plugin)) continue;
|
|
24675
|
+
for (const version2 of readdirSync5(plugin).sort()) {
|
|
24676
|
+
const dir = join14(plugin, version2, CODEX_PLUGIN_SUBDIR);
|
|
24677
|
+
if (existsSync9(join14(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
24416
24678
|
}
|
|
24417
24679
|
}
|
|
24418
24680
|
return found.length === 0 ? null : found[found.length - 1];
|
|
24419
24681
|
}
|
|
24420
24682
|
function nativeMcpWrong(dir, row5) {
|
|
24421
24683
|
try {
|
|
24422
|
-
const entry = hostConfigValueAt(readParsed(row5.id,
|
|
24684
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join14(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
24423
24685
|
if (!isObject4(entry)) return true;
|
|
24424
24686
|
const args = list2(entry[MCP_ARGS_FIELD]);
|
|
24425
24687
|
const script = args[0];
|
|
@@ -24429,7 +24691,7 @@ function nativeMcpWrong(dir, row5) {
|
|
|
24429
24691
|
}
|
|
24430
24692
|
}
|
|
24431
24693
|
function isOwnOpencodeEntry(entry, key, own2) {
|
|
24432
|
-
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : entry;
|
|
24694
|
+
const spec = isObject4(entry) ? entry[OPENCODE_PACKAGE_FIELD] : Array.isArray(entry) ? entry[0] : entry;
|
|
24433
24695
|
if (typeof spec !== "string") return false;
|
|
24434
24696
|
if (spec === OPENCODE_GIT_SPEC || spec.startsWith(OPENCODE_NPM_SPEC_PREFIX) || own2.includes(spec)) return true;
|
|
24435
24697
|
return key === OPENCODE_PLUGINS_KEY && spec === SERVER_KEY;
|
|
@@ -24440,14 +24702,21 @@ function opencodeMcpOwn(entry) {
|
|
|
24440
24702
|
const [node, script, flag, agent] = cmd;
|
|
24441
24703
|
return isNodeCommand(node) && typeof script === "string" && lastSegment(script) === SERVER_ENTRY_FILE && flag === AGENT_ARG && agent === "opencode";
|
|
24442
24704
|
}
|
|
24443
|
-
function
|
|
24444
|
-
|
|
24705
|
+
function opencodeFileValue(file2) {
|
|
24706
|
+
if (!existsSync9(file2)) return {};
|
|
24707
|
+
return parseHostConfig("opencode", file2, hostText(readFileSync11(file2, "utf8")), "jsonc");
|
|
24708
|
+
}
|
|
24709
|
+
function opencodeValueListed(value) {
|
|
24445
24710
|
const bundle = opencodePluginFile();
|
|
24446
|
-
const own2 = [bundle,
|
|
24711
|
+
const own2 = [bundle, join14(bundle, ...OPENCODE_PLUGIN_PATH)];
|
|
24447
24712
|
if ([OPENCODE_PLUGIN_KEY, OPENCODE_PLUGINS_KEY].some((key) => list2(isObject4(value) ? value[key] : void 0).some((e) => isOwnOpencodeEntry(e, key, own2)))) return true;
|
|
24448
24713
|
const mcp = isObject4(value) && isObject4(value.mcp) ? value.mcp : {};
|
|
24449
24714
|
return opencodeMcpOwn(mcp[SERVER_KEY]) || isObject4(mcp.servers) && opencodeMcpOwn(mcp.servers[SERVER_KEY]);
|
|
24450
24715
|
}
|
|
24716
|
+
function opencodeListed(file2, worktree) {
|
|
24717
|
+
const dirs = [dirname8(file2), worktree];
|
|
24718
|
+
return dirs.some((dir) => OPENCODE_CONFIG_FILES.some((name) => opencodeValueListed(opencodeFileValue(join14(dir, name)))));
|
|
24719
|
+
}
|
|
24451
24720
|
function mcpWrong(row5, home, env, worktree) {
|
|
24452
24721
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24453
24722
|
if (native !== null) return nativeMcpWrong(native, row5);
|
|
@@ -24457,7 +24726,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24457
24726
|
resolvePluginRoot(row5, env, worktree);
|
|
24458
24727
|
return false;
|
|
24459
24728
|
}
|
|
24460
|
-
if (row5.id === "opencode") return !opencodeListed(file2);
|
|
24729
|
+
if (row5.id === "opencode") return !opencodeListed(file2, worktree);
|
|
24461
24730
|
const cur = readHostConfig(row5.id, file2);
|
|
24462
24731
|
return mergeOwnEntries(row5.id, cur.text, cur.format, row5, { nodePath: true, listEntries: [opencodePluginFile()] }).edits.length > 0;
|
|
24463
24732
|
} catch {
|
|
@@ -24467,7 +24736,7 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
24467
24736
|
function hookFile(row5, spec, home, env, worktree) {
|
|
24468
24737
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
24469
24738
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24470
|
-
const file2 = native !== null ?
|
|
24739
|
+
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);
|
|
24471
24740
|
return file2;
|
|
24472
24741
|
}
|
|
24473
24742
|
function hookParts(row5, home, env, worktree) {
|
|
@@ -24478,7 +24747,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
24478
24747
|
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
24479
24748
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
24480
24749
|
if (row5.id === "codex") {
|
|
24481
|
-
const config2 = readParsed(row5.id,
|
|
24750
|
+
const config2 = readParsed(row5.id, join14(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
24482
24751
|
if (hostConfigValueAt(config2, CODEX_FEATURES_HOOKS_KEY) === false) return [PART_HOOKS];
|
|
24483
24752
|
}
|
|
24484
24753
|
} catch {
|
|
@@ -24522,7 +24791,7 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
24522
24791
|
function checkPiInstall(env, home, worktree) {
|
|
24523
24792
|
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
24524
24793
|
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
24525
|
-
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN +
|
|
24794
|
+
return fail2("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join14(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
24526
24795
|
}
|
|
24527
24796
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
24528
24797
|
const findings = detectV1(agent, home, scope);
|
|
@@ -24541,10 +24810,10 @@ function parsedOrNull(agent, file2, jsonc) {
|
|
|
24541
24810
|
}
|
|
24542
24811
|
function checkDoubleFire(agent, worktree) {
|
|
24543
24812
|
if (agent !== "claude-code" && agent !== "vscode") return pass("D5b");
|
|
24544
|
-
const claude = parsedOrNull(agent,
|
|
24813
|
+
const claude = parsedOrNull(agent, join14(worktree, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), false);
|
|
24545
24814
|
const hooks = isObject4(claude) ? claude[HOOKS_KEY] : void 0;
|
|
24546
24815
|
const hooksOn = isObject4(hooks) && Object.keys(hooks).length > 0;
|
|
24547
|
-
const vscode = parsedOrNull(agent,
|
|
24816
|
+
const vscode = parsedOrNull(agent, join14(worktree, VSCODE_DIR_NAME, VSCODE_SETTINGS_FILE), true);
|
|
24548
24817
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
24549
24818
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
24550
24819
|
}
|
|
@@ -24555,7 +24824,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24555
24824
|
const mcp = mcpFile(row5, home, env);
|
|
24556
24825
|
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
24557
24826
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
24558
|
-
if (native !== null) out.push({ label: "Codex plugin MCP", path:
|
|
24827
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join14(native, CODEX_PLUGIN_MCP_FILE) });
|
|
24559
24828
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
24560
24829
|
if (spec !== null) {
|
|
24561
24830
|
try {
|
|
@@ -24575,7 +24844,7 @@ function configPaths(row5, env, worktree) {
|
|
|
24575
24844
|
}
|
|
24576
24845
|
|
|
24577
24846
|
// src/core/ops/doctor-db.ts
|
|
24578
|
-
import { existsSync as
|
|
24847
|
+
import { existsSync as existsSync10, statSync as statSync5 } from "node:fs";
|
|
24579
24848
|
var unknown2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
24580
24849
|
var pass2 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
24581
24850
|
var fail3 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -24617,15 +24886,15 @@ function orphanFiles(dbPath) {
|
|
|
24617
24886
|
const files = [];
|
|
24618
24887
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
24619
24888
|
const path8 = dbPath + suffix;
|
|
24620
|
-
if (
|
|
24889
|
+
if (existsSync10(path8)) files.push({ path: path8, bytes: statSync5(path8).size });
|
|
24621
24890
|
}
|
|
24622
|
-
return files.length > 0 && !
|
|
24891
|
+
return files.length > 0 && !existsSync10(dbPath) ? files : [];
|
|
24623
24892
|
}
|
|
24624
24893
|
async function checkDb(project) {
|
|
24625
24894
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
24626
24895
|
const orphan = orphanFiles(project.dbPath);
|
|
24627
24896
|
if (orphan.length > 0) return { row: fail3(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
24628
|
-
if (!
|
|
24897
|
+
if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
24629
24898
|
const sqlite = await loadSqlite2();
|
|
24630
24899
|
if (sqlite === null) return { row: unknown2("D8", D2_SQLITE_DETAIL), ...clean };
|
|
24631
24900
|
let raw = null;
|
|
@@ -24651,7 +24920,7 @@ async function checkDb(project) {
|
|
|
24651
24920
|
}
|
|
24652
24921
|
}
|
|
24653
24922
|
async function checkIndex(project) {
|
|
24654
|
-
if (!
|
|
24923
|
+
if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
24655
24924
|
const sqlite = await loadSqlite2();
|
|
24656
24925
|
if (sqlite === null) return unknown2("D9", D2_SQLITE_DETAIL);
|
|
24657
24926
|
let raw = null;
|
|
@@ -24668,8 +24937,8 @@ async function checkIndex(project) {
|
|
|
24668
24937
|
}
|
|
24669
24938
|
|
|
24670
24939
|
// src/core/ops/doctor-env.ts
|
|
24671
|
-
import { existsSync as
|
|
24672
|
-
import { isAbsolute as isAbsolute3, join as
|
|
24940
|
+
import { existsSync as existsSync11, readFileSync as readFileSync12, realpathSync as realpathSync6 } from "node:fs";
|
|
24941
|
+
import { isAbsolute as isAbsolute3, join as join15, relative as relative4 } from "node:path";
|
|
24673
24942
|
function pass3(id2, detail = DOCTOR_PASS_DETAIL) {
|
|
24674
24943
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail };
|
|
24675
24944
|
}
|
|
@@ -24679,9 +24948,12 @@ function unknown3(id2, detail, fixCommand) {
|
|
|
24679
24948
|
function fail4(id2, detail, fixCommand) {
|
|
24680
24949
|
return { id: id2, label: DOCTOR_LABEL[id2], status: "FAIL", detail, fixCommand };
|
|
24681
24950
|
}
|
|
24951
|
+
function warn(id2, detail, fixCommand) {
|
|
24952
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail, fixCommand };
|
|
24953
|
+
}
|
|
24682
24954
|
function bundleVersion(bundleDir2) {
|
|
24683
24955
|
try {
|
|
24684
|
-
const v = JSON.parse(
|
|
24956
|
+
const v = JSON.parse(readFileSync12(join15(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
24685
24957
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
24686
24958
|
} catch {
|
|
24687
24959
|
return void 0;
|
|
@@ -24765,20 +25037,21 @@ function highestTag(stdout, tag2) {
|
|
|
24765
25037
|
}
|
|
24766
25038
|
return best;
|
|
24767
25039
|
}
|
|
24768
|
-
function versionRow(head2, installed, tag2, source, latest, tail) {
|
|
25040
|
+
function versionRow(head2, installed, tag2, source, latest, tail, update) {
|
|
24769
25041
|
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
24770
25042
|
if (cmp === 0) return pass3("D1", head2 + D1_LATEST_PASS(tag2, source) + tail);
|
|
24771
25043
|
if (cmp > 0) return pass3("D1", head2 + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
24772
|
-
return
|
|
25044
|
+
return warn("D1", head2 + D1_LATEST_UPDATE(tag2, source, latest) + tail, update);
|
|
24773
25045
|
}
|
|
24774
25046
|
async function checkVersion(i) {
|
|
24775
25047
|
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
24776
25048
|
const head2 = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24777
25049
|
if (i.version === void 0) return unknown3("D1", head2 + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24778
25050
|
const tag2 = channelOf(i.version);
|
|
25051
|
+
const update = i.updateCommand ?? DOCTOR_FIX_UPGRADE;
|
|
24779
25052
|
const git2 = findRuntime(GIT_BIN, i.env);
|
|
24780
25053
|
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24781
|
-
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
25054
|
+
if (npm.ok) return versionRow(head2, i.version, tag2, D1_SOURCE_NPM, npm.version, "", update);
|
|
24782
25055
|
let cause = D1_GIT_MISSING;
|
|
24783
25056
|
if (git2 !== null) {
|
|
24784
25057
|
const r = await runProcess([git2, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
@@ -24789,7 +25062,7 @@ async function checkVersion(i) {
|
|
|
24789
25062
|
});
|
|
24790
25063
|
if (r.exitCode === 0 && r.killed === null) {
|
|
24791
25064
|
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
24792
|
-
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
|
|
25065
|
+
if (latest !== void 0) return versionRow(head2, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause, update);
|
|
24793
25066
|
cause = D1_GIT_NO_TAG(tag2);
|
|
24794
25067
|
} else {
|
|
24795
25068
|
cause = gitCause(r, i.timeoutMs);
|
|
@@ -24825,13 +25098,14 @@ async function checkNode(i) {
|
|
|
24825
25098
|
if (!await sqliteLoads()) return fail4("D2", withBun(D2_SQLITE_DETAIL), D2_SQLITE_FIX);
|
|
24826
25099
|
return pass3("D2", bun.length === 0 ? DOCTOR_PASS_DETAIL : bun.join(D4_REASON_JOIN));
|
|
24827
25100
|
}
|
|
24828
|
-
function checkMcp(ctx) {
|
|
25101
|
+
function checkMcp(ctx, adapter) {
|
|
24829
25102
|
const named2 = ctx.clientInfo !== void 0 && ctx.clientInfo.name !== "";
|
|
24830
25103
|
const versioned = ctx.protocolVersion !== void 0 && ctx.protocolVersion !== "";
|
|
24831
|
-
|
|
25104
|
+
if (named2 || versioned) return pass3("D6");
|
|
25105
|
+
return adapter?.installMode === "in-process" ? pass3("D6", D6_IN_PROCESS_DETAIL) : unknown3("D6", D6_UNKNOWN_DETAIL);
|
|
24832
25106
|
}
|
|
24833
25107
|
function piCwdInside(worktree, piCwd) {
|
|
24834
|
-
if (piCwd === void 0 || !
|
|
25108
|
+
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
24835
25109
|
const rel = relative4(worktree, realpathSync6.native(piCwd));
|
|
24836
25110
|
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
24837
25111
|
}
|
|
@@ -24841,7 +25115,9 @@ function checkProject(i) {
|
|
|
24841
25115
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
24842
25116
|
return pass3("D7");
|
|
24843
25117
|
}
|
|
24844
|
-
function checkMode(adapter) {
|
|
25118
|
+
function checkMode(adapter, hostPermission) {
|
|
25119
|
+
if (hostPermission === "missing") return fail4("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
25120
|
+
if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
24845
25121
|
return pass3("D10", D10_DETAIL(adapter.denyChannel));
|
|
24846
25122
|
}
|
|
24847
25123
|
function checkShell(env) {
|
|
@@ -24852,7 +25128,7 @@ function checkShell(env) {
|
|
|
24852
25128
|
}
|
|
24853
25129
|
|
|
24854
25130
|
// src/core/ops/doctor-hook.ts
|
|
24855
|
-
import { existsSync as
|
|
25131
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync4, mkdtempSync, readFileSync as readFileSync13, realpathSync as realpathSync8, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24856
25132
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24857
25133
|
import path7 from "node:path";
|
|
24858
25134
|
|
|
@@ -26678,9 +26954,9 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
|
|
|
26678
26954
|
|
|
26679
26955
|
// src/setup/codex-trust.ts
|
|
26680
26956
|
import { createHash } from "node:crypto";
|
|
26681
|
-
import { existsSync as
|
|
26957
|
+
import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
|
|
26682
26958
|
import path6 from "node:path";
|
|
26683
|
-
import { spawn as
|
|
26959
|
+
import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
26684
26960
|
|
|
26685
26961
|
// src/setup/spawn-bin.ts
|
|
26686
26962
|
import { spawnSync } from "node:child_process";
|
|
@@ -26795,24 +27071,24 @@ function pluginHooksFromReply(m, pluginId) {
|
|
|
26795
27071
|
function askPluginHooks(env, pluginId, cwd) {
|
|
26796
27072
|
const bin = whichBin("codex", env);
|
|
26797
27073
|
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
26798
|
-
return new Promise((
|
|
27074
|
+
return new Promise((resolve11) => {
|
|
26799
27075
|
let asked;
|
|
26800
27076
|
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
26801
27077
|
let f;
|
|
26802
27078
|
try {
|
|
26803
27079
|
f = spawnForm(bin, ["app-server"], env);
|
|
26804
27080
|
} catch {
|
|
26805
|
-
|
|
27081
|
+
resolve11({ kind: "silent" });
|
|
26806
27082
|
return;
|
|
26807
27083
|
}
|
|
26808
|
-
const child =
|
|
27084
|
+
const child = spawn3(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
26809
27085
|
let buf = "";
|
|
26810
27086
|
let done = false;
|
|
26811
27087
|
let exited = false;
|
|
26812
27088
|
let result;
|
|
26813
27089
|
const settle = () => {
|
|
26814
27090
|
clearTimeout(grace);
|
|
26815
|
-
|
|
27091
|
+
resolve11(done_(result));
|
|
26816
27092
|
};
|
|
26817
27093
|
let grace;
|
|
26818
27094
|
const finish2 = (v) => {
|
|
@@ -26901,10 +27177,10 @@ function isObject6(v) {
|
|
|
26901
27177
|
}
|
|
26902
27178
|
function loadFixture(bundleDir2, agent) {
|
|
26903
27179
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
26904
|
-
if (!
|
|
27180
|
+
if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
26905
27181
|
let all;
|
|
26906
27182
|
try {
|
|
26907
|
-
all = JSON.parse(hostText(
|
|
27183
|
+
all = JSON.parse(hostText(readFileSync13(file2, "utf8")));
|
|
26908
27184
|
} catch (err) {
|
|
26909
27185
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
26910
27186
|
}
|
|
@@ -27017,6 +27293,35 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
27017
27293
|
rmSync2(home, { recursive: true, force: true });
|
|
27018
27294
|
}
|
|
27019
27295
|
}
|
|
27296
|
+
async function ownProbe(i, timeoutMs) {
|
|
27297
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
|
|
27298
|
+
try {
|
|
27299
|
+
const cfg = path7.join(home, ".claude");
|
|
27300
|
+
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
27301
|
+
mkdirSync4(refs, { recursive: true });
|
|
27302
|
+
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
27303
|
+
writeFileSync2(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
27304
|
+
const node = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
27305
|
+
const r = await runProcess([node.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
27306
|
+
cwd: i.bundleDir,
|
|
27307
|
+
env: node.env,
|
|
27308
|
+
signal: i.signal,
|
|
27309
|
+
timeoutMs,
|
|
27310
|
+
stdin: JSON.stringify({
|
|
27311
|
+
session_id: "d5-own-probe",
|
|
27312
|
+
transcript_path: "",
|
|
27313
|
+
cwd: home,
|
|
27314
|
+
hook_event_name: "PreToolUse",
|
|
27315
|
+
tool_name: "Read",
|
|
27316
|
+
tool_use_id: "toolu_d5_own_probe",
|
|
27317
|
+
tool_input: { file_path: filePath }
|
|
27318
|
+
})
|
|
27319
|
+
});
|
|
27320
|
+
return r.stdout.toString("utf8");
|
|
27321
|
+
} finally {
|
|
27322
|
+
rmSync2(home, { recursive: true, force: true });
|
|
27323
|
+
}
|
|
27324
|
+
}
|
|
27020
27325
|
function isDeny(stdout) {
|
|
27021
27326
|
if (stdout.trim() === "") return false;
|
|
27022
27327
|
let out;
|
|
@@ -27031,8 +27336,12 @@ async function readProbeDetail(i, timeoutMs) {
|
|
|
27031
27336
|
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
27032
27337
|
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
27033
27338
|
if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
|
|
27339
|
+
if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
|
|
27034
27340
|
return null;
|
|
27035
27341
|
}
|
|
27342
|
+
async function mediaProbeDetail(i, timeoutMs) {
|
|
27343
|
+
return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
|
|
27344
|
+
}
|
|
27036
27345
|
function codexHookJournaled(db) {
|
|
27037
27346
|
if (db === null) return false;
|
|
27038
27347
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -27085,7 +27394,7 @@ async function codexStopDetail(i, timeoutMs) {
|
|
|
27085
27394
|
timeoutMs,
|
|
27086
27395
|
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
27087
27396
|
});
|
|
27088
|
-
const logged =
|
|
27397
|
+
const logged = existsSync13(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
27089
27398
|
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
27090
27399
|
} finally {
|
|
27091
27400
|
rmSync2(home, { recursive: true, force: true });
|
|
@@ -27096,7 +27405,7 @@ async function checkHookRoundTrip(i) {
|
|
|
27096
27405
|
const trust = await codexPluginTrust(i);
|
|
27097
27406
|
if (trust !== null) return trust;
|
|
27098
27407
|
}
|
|
27099
|
-
if (i.agent === "codex" &&
|
|
27408
|
+
if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
27100
27409
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
27101
27410
|
}
|
|
27102
27411
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -27132,20 +27441,20 @@ async function checkHookRoundTrip(i) {
|
|
|
27132
27441
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
27133
27442
|
}
|
|
27134
27443
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
27135
|
-
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
27444
|
+
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;
|
|
27136
27445
|
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
27137
27446
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
27138
27447
|
}
|
|
27139
27448
|
|
|
27140
27449
|
// src/core/ops/db-heal.ts
|
|
27141
|
-
import { existsSync as
|
|
27142
|
-
import { basename as basename4, dirname as
|
|
27450
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync6, rmSync as rmSync4 } from "node:fs";
|
|
27451
|
+
import { basename as basename4, dirname as dirname9, join as join17 } from "node:path";
|
|
27143
27452
|
|
|
27144
27453
|
// src/core/store/owners.ts
|
|
27145
|
-
import { mkdirSync as
|
|
27146
|
-
import { basename as basename3, join as
|
|
27454
|
+
import { mkdirSync as mkdirSync5, readdirSync as readdirSync6, readFileSync as readFileSync14, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27455
|
+
import { basename as basename3, join as join16 } from "node:path";
|
|
27147
27456
|
function ownersDir(configDir, projectKey) {
|
|
27148
|
-
return
|
|
27457
|
+
return join16(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27149
27458
|
}
|
|
27150
27459
|
function errCode2(err) {
|
|
27151
27460
|
return err.code;
|
|
@@ -27165,7 +27474,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27165
27474
|
const dir = ownersDir(configDir, projectKey);
|
|
27166
27475
|
let names;
|
|
27167
27476
|
try {
|
|
27168
|
-
names =
|
|
27477
|
+
names = readdirSync6(dir);
|
|
27169
27478
|
} catch (err) {
|
|
27170
27479
|
if (errCode2(err) === "ENOENT") return [];
|
|
27171
27480
|
throw err;
|
|
@@ -27173,10 +27482,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27173
27482
|
const live = [];
|
|
27174
27483
|
for (const name of names) {
|
|
27175
27484
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27176
|
-
const file2 =
|
|
27485
|
+
const file2 = join16(dir, name);
|
|
27177
27486
|
let text;
|
|
27178
27487
|
try {
|
|
27179
|
-
text =
|
|
27488
|
+
text = readFileSync14(file2, "utf8");
|
|
27180
27489
|
} catch (err) {
|
|
27181
27490
|
if (errCode2(err) === "ENOENT") continue;
|
|
27182
27491
|
throw err;
|
|
@@ -27222,7 +27531,7 @@ function renameAside(dbPath) {
|
|
|
27222
27531
|
const ts = String(Date.now());
|
|
27223
27532
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
27224
27533
|
const file2 = dbPath + suffix;
|
|
27225
|
-
if (
|
|
27534
|
+
if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
27226
27535
|
}
|
|
27227
27536
|
return ts;
|
|
27228
27537
|
}
|
|
@@ -27245,11 +27554,11 @@ function utcStamp(now) {
|
|
|
27245
27554
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
27246
27555
|
}
|
|
27247
27556
|
function makeOrphanDir(projectDir) {
|
|
27248
|
-
const base =
|
|
27557
|
+
const base = join17(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
27249
27558
|
for (let n = 1; ; n += 1) {
|
|
27250
27559
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
27251
27560
|
try {
|
|
27252
|
-
|
|
27561
|
+
mkdirSync6(dir);
|
|
27253
27562
|
return dir;
|
|
27254
27563
|
} catch (err) {
|
|
27255
27564
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -27260,9 +27569,9 @@ async function healOrphan(project, files, row5) {
|
|
|
27260
27569
|
const moved = [];
|
|
27261
27570
|
let dir = "";
|
|
27262
27571
|
try {
|
|
27263
|
-
dir = makeOrphanDir(
|
|
27572
|
+
dir = makeOrphanDir(dirname9(project.dbPath));
|
|
27264
27573
|
for (const f of files) {
|
|
27265
|
-
const to =
|
|
27574
|
+
const to = join17(dir, basename4(f.path));
|
|
27266
27575
|
renameWithRetry(f.path, to);
|
|
27267
27576
|
moved.push({ path: to, bytes: f.bytes });
|
|
27268
27577
|
}
|
|
@@ -27327,10 +27636,41 @@ function buildReportHead(input) {
|
|
|
27327
27636
|
return lines.concat(tail).join("\n");
|
|
27328
27637
|
}
|
|
27329
27638
|
|
|
27639
|
+
// src/core/ops/unsupported-host.ts
|
|
27640
|
+
var SUPPORTED_AGENTS_LINE = `Supported agents: ${AGENT_IDS.join(", ")} (${SUPPORTED_AGENTS_DOCS_URL}).`;
|
|
27641
|
+
function UNSUPPORTED_HOST_LINE(name) {
|
|
27642
|
+
return `${name} is not a supported host today. The MCP server runs here; hooks are not checked. ${SUPPORTED_AGENTS_LINE}`;
|
|
27643
|
+
}
|
|
27644
|
+
function segmentsOf(dir) {
|
|
27645
|
+
let parts = [dir];
|
|
27646
|
+
for (const sep5 of V1_PATH_SEPS) parts = parts.flatMap((p) => p.split(sep5));
|
|
27647
|
+
return parts;
|
|
27648
|
+
}
|
|
27649
|
+
function hasRun(parts, run) {
|
|
27650
|
+
for (let i = 0; i + run.length <= parts.length; i++) if (run.every((seg, k) => parts[i + k] === seg)) return true;
|
|
27651
|
+
return false;
|
|
27652
|
+
}
|
|
27653
|
+
function unsupportedHostOf(sig) {
|
|
27654
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") {
|
|
27655
|
+
const n = sig.clientName.toLowerCase();
|
|
27656
|
+
const hit = UNSUPPORTED_HOSTS.find((h) => h.clientNames.includes(n));
|
|
27657
|
+
if (hit !== void 0) return hit;
|
|
27658
|
+
}
|
|
27659
|
+
if (sig.bundleDir !== void 0) {
|
|
27660
|
+
const parts = segmentsOf(sig.bundleDir);
|
|
27661
|
+
const hit = UNSUPPORTED_HOSTS.find((h) => h.pluginPaths.some((p) => hasRun(parts, p)));
|
|
27662
|
+
if (hit !== void 0) return hit;
|
|
27663
|
+
}
|
|
27664
|
+
if (sig.clientName !== void 0 && sig.clientName !== "") return void 0;
|
|
27665
|
+
const env = sig.env;
|
|
27666
|
+
if (env === void 0) return void 0;
|
|
27667
|
+
return UNSUPPORTED_HOSTS.find((h) => h.envVars.some((v) => env[v] !== void 0 && env[v] !== ""));
|
|
27668
|
+
}
|
|
27669
|
+
|
|
27330
27670
|
// src/core/ops/doctor-issue.ts
|
|
27331
27671
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
27332
|
-
import { closeSync as closeSync2, existsSync as
|
|
27333
|
-
import { delimiter, join as
|
|
27672
|
+
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";
|
|
27673
|
+
import { delimiter, join as join18 } from "node:path";
|
|
27334
27674
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
27335
27675
|
function tildeOf(env) {
|
|
27336
27676
|
const home = homeDirOf(env);
|
|
@@ -27342,8 +27682,8 @@ function tildeOf(env) {
|
|
|
27342
27682
|
} catch {
|
|
27343
27683
|
}
|
|
27344
27684
|
homes.sort((a, b) => b.length - a.length);
|
|
27345
|
-
const
|
|
27346
|
-
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece :
|
|
27685
|
+
const slash2 = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
|
|
27686
|
+
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash2(piece)).join("~"), t);
|
|
27347
27687
|
}
|
|
27348
27688
|
function maskLine(line) {
|
|
27349
27689
|
const lower = line.toLowerCase();
|
|
@@ -27371,8 +27711,8 @@ function onPath(env, tool) {
|
|
|
27371
27711
|
const out = [];
|
|
27372
27712
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
27373
27713
|
if (dir === "") continue;
|
|
27374
|
-
for (const n of names) if (
|
|
27375
|
-
out.push(
|
|
27714
|
+
for (const n of names) if (existsSync15(join18(dir, n))) {
|
|
27715
|
+
out.push(join18(dir, n));
|
|
27376
27716
|
break;
|
|
27377
27717
|
}
|
|
27378
27718
|
}
|
|
@@ -27380,7 +27720,7 @@ function onPath(env, tool) {
|
|
|
27380
27720
|
}
|
|
27381
27721
|
function hookLogTail(env) {
|
|
27382
27722
|
const file2 = hookLogPath(env);
|
|
27383
|
-
if (file2 === "" || !
|
|
27723
|
+
if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
27384
27724
|
try {
|
|
27385
27725
|
const fd = openSync2(file2, "r");
|
|
27386
27726
|
try {
|
|
@@ -27400,7 +27740,7 @@ function hookLogTail(env) {
|
|
|
27400
27740
|
}
|
|
27401
27741
|
async function journalRows(ctx) {
|
|
27402
27742
|
const head2 = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
27403
|
-
if (!
|
|
27743
|
+
if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
27404
27744
|
try {
|
|
27405
27745
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
27406
27746
|
try {
|
|
@@ -27418,21 +27758,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
27418
27758
|
const home = homeDirOf(env);
|
|
27419
27759
|
const files = configPaths(adapter, env, worktree);
|
|
27420
27760
|
if (home !== null) {
|
|
27421
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
27422
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
27761
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join18(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
27762
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join18(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
27423
27763
|
}
|
|
27424
27764
|
const out = [];
|
|
27425
27765
|
const seen = /* @__PURE__ */ new Set();
|
|
27426
27766
|
for (const f of files) {
|
|
27427
27767
|
if (seen.has(f.path)) continue;
|
|
27428
27768
|
seen.add(f.path);
|
|
27429
|
-
if (!
|
|
27769
|
+
if (!existsSync15(f.path)) {
|
|
27430
27770
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
27431
27771
|
continue;
|
|
27432
27772
|
}
|
|
27433
27773
|
let text = "";
|
|
27434
27774
|
try {
|
|
27435
|
-
text =
|
|
27775
|
+
text = readFileSync15(f.path, "utf8");
|
|
27436
27776
|
} catch (err) {
|
|
27437
27777
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
27438
27778
|
continue;
|
|
@@ -27446,12 +27786,13 @@ function agentConfig(adapter, env, worktree) {
|
|
|
27446
27786
|
function failing(rows) {
|
|
27447
27787
|
return rows.filter((r) => r.status === "FAIL");
|
|
27448
27788
|
}
|
|
27449
|
-
function issueTitle(agent, rows) {
|
|
27450
|
-
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
27789
|
+
function issueTitle(agent, rows, other) {
|
|
27790
|
+
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`;
|
|
27451
27791
|
}
|
|
27452
|
-
function summaryOf(agent, rows) {
|
|
27792
|
+
function summaryOf(agent, rows, other) {
|
|
27453
27793
|
const f = failing(rows)[0];
|
|
27454
|
-
|
|
27794
|
+
const tag2 = other === void 0 ? "" : `${other.name} is not a supported host today. `;
|
|
27795
|
+
return tag2 + (f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`);
|
|
27455
27796
|
}
|
|
27456
27797
|
async function buildIssueBody(i) {
|
|
27457
27798
|
const tilde = tildeOf(i.env);
|
|
@@ -27461,7 +27802,7 @@ async function buildIssueBody(i) {
|
|
|
27461
27802
|
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
27462
27803
|
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
27463
27804
|
const sections = {
|
|
27464
|
-
"Summary": [summaryOf(agent, i.rows)],
|
|
27805
|
+
"Summary": [summaryOf(agent, i.rows, i.unsupported)],
|
|
27465
27806
|
"ctx-report": [i.table],
|
|
27466
27807
|
"What happened": [
|
|
27467
27808
|
"Rows that need a look:",
|
|
@@ -27502,14 +27843,14 @@ async function buildIssueBody(i) {
|
|
|
27502
27843
|
async function writeIssueReport(i) {
|
|
27503
27844
|
const tilde = tildeOf(i.env);
|
|
27504
27845
|
const body = await buildIssueBody(i);
|
|
27505
|
-
const dir =
|
|
27506
|
-
|
|
27507
|
-
const file2 =
|
|
27846
|
+
const dir = join18(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
27847
|
+
mkdirSync7(dir, { recursive: true });
|
|
27848
|
+
const file2 = join18(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
27508
27849
|
writeFileSync4(file2, body);
|
|
27509
27850
|
const shown2 = tilde(file2);
|
|
27510
|
-
const title = issueTitle(i.adapter.id, i.rows);
|
|
27851
|
+
const title = issueTitle(i.adapter.id, i.rows, i.unsupported);
|
|
27511
27852
|
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
27512
|
-
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];
|
|
27853
|
+
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];
|
|
27513
27854
|
}
|
|
27514
27855
|
function formUrl(title, summary) {
|
|
27515
27856
|
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
@@ -27531,13 +27872,19 @@ async function guard(id2, run) {
|
|
|
27531
27872
|
}
|
|
27532
27873
|
}
|
|
27533
27874
|
async function codexDb(ctx, adapter) {
|
|
27534
|
-
if (adapter.id !== "codex" || !
|
|
27875
|
+
if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
|
|
27535
27876
|
try {
|
|
27536
27877
|
return await openDb(ctx.project, { readOnly: true });
|
|
27537
27878
|
} catch {
|
|
27538
27879
|
return null;
|
|
27539
27880
|
}
|
|
27540
27881
|
}
|
|
27882
|
+
function d1UpdateCommand(agent, env, other) {
|
|
27883
|
+
return other === void 0 ? hostUpdateCommand(agent, env) : UNSUPPORTED_HOST_LINE(other.name);
|
|
27884
|
+
}
|
|
27885
|
+
function unsupportedRow(id2, h) {
|
|
27886
|
+
return { id: id2, label: DOCTOR_LABEL[id2], status: "WARN", detail: UNSUPPORTED_HOST_LINE(h.name) };
|
|
27887
|
+
}
|
|
27541
27888
|
async function hookRow(ctx, adapter, host) {
|
|
27542
27889
|
const db = await codexDb(ctx, adapter);
|
|
27543
27890
|
const runStart = Date.now();
|
|
@@ -27561,11 +27908,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
27561
27908
|
}
|
|
27562
27909
|
}
|
|
27563
27910
|
function ownServerId(configDir, projectKey) {
|
|
27564
|
-
const dir =
|
|
27565
|
-
if (!
|
|
27566
|
-
for (const name of
|
|
27911
|
+
const dir = join19(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27912
|
+
if (!existsSync16(dir)) return "";
|
|
27913
|
+
for (const name of readdirSync7(dir)) {
|
|
27567
27914
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
27568
|
-
if (
|
|
27915
|
+
if (readFileSync16(join19(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
27569
27916
|
}
|
|
27570
27917
|
return "";
|
|
27571
27918
|
}
|
|
@@ -27573,16 +27920,18 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
27573
27920
|
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
27574
27921
|
const env = host.env;
|
|
27575
27922
|
const project = ctx.project;
|
|
27923
|
+
const other = adapter.installMode === "in-process" ? void 0 : unsupportedHostOf({ clientName: ctx.clientInfo?.name, bundleDir: host.bundleDir, env });
|
|
27576
27924
|
let integrityFailed = false;
|
|
27577
27925
|
let orphan = [];
|
|
27578
27926
|
const checks = {
|
|
27579
|
-
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 }),
|
|
27927
|
+
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) }),
|
|
27580
27928
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
27581
|
-
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
27929
|
+
D3: () => other !== void 0 ? unsupportedRow("D3", other) : checkHostConfig(adapter, env, project.worktree),
|
|
27930
|
+
// D-UNSUPPORTED-HOSTS-1
|
|
27582
27931
|
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)) }),
|
|
27583
|
-
D5: () => hookRow(ctx, adapter, host),
|
|
27932
|
+
D5: () => other !== void 0 ? unsupportedRow("D5", other) : hookRow(ctx, adapter, host),
|
|
27584
27933
|
D5b: () => checkDoubleFire(adapter.id, project.worktree),
|
|
27585
|
-
D6: () => checkMcp(ctx),
|
|
27934
|
+
D6: () => checkMcp(ctx, adapter),
|
|
27586
27935
|
D7: () => checkProject({ project, adapter, piCwd: host.piCwd }),
|
|
27587
27936
|
D8: async () => {
|
|
27588
27937
|
const r = await checkDb(project);
|
|
@@ -27591,7 +27940,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
27591
27940
|
return r.row;
|
|
27592
27941
|
},
|
|
27593
27942
|
D9: () => checkIndex(project),
|
|
27594
|
-
D10: () => checkMode(adapter),
|
|
27943
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
27944
|
+
// D-1331-OC-PERM-1
|
|
27595
27945
|
D11: () => checkShell(env)
|
|
27596
27946
|
};
|
|
27597
27947
|
const rows = [];
|
|
@@ -27628,7 +27978,7 @@ async function doctorReply(ctx, host) {
|
|
|
27628
27978
|
let notes = [];
|
|
27629
27979
|
if (failed) {
|
|
27630
27980
|
try {
|
|
27631
|
-
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
27981
|
+
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 });
|
|
27632
27982
|
} catch (err) {
|
|
27633
27983
|
notes = [`Report file: ${lineOf2(err)}`];
|
|
27634
27984
|
}
|
|
@@ -27660,9 +28010,9 @@ var ctxDoctor = Object.freeze({
|
|
|
27660
28010
|
});
|
|
27661
28011
|
|
|
27662
28012
|
// src/core/tools/execute.ts
|
|
27663
|
-
import { existsSync as
|
|
28013
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
27664
28014
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
27665
|
-
import { dirname as
|
|
28015
|
+
import { dirname as dirname11, join as join20, parse as parse3, resolve as resolve8 } from "node:path";
|
|
27666
28016
|
|
|
27667
28017
|
// src/core/sandbox/win-build.ts
|
|
27668
28018
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -27745,7 +28095,7 @@ function schemaLine(issue2) {
|
|
|
27745
28095
|
}
|
|
27746
28096
|
function fileError(given, abs, root) {
|
|
27747
28097
|
let dir = abs;
|
|
27748
|
-
while (!
|
|
28098
|
+
while (!existsSync17(dir) && dirname11(dir) !== dir) dir = dirname11(dir);
|
|
27749
28099
|
if (isInside(root, dir)) return null;
|
|
27750
28100
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
27751
28101
|
}
|
|
@@ -27779,7 +28129,7 @@ function spawnFailed(argv0, cwd) {
|
|
|
27779
28129
|
}
|
|
27780
28130
|
async function finish(input, ctx, r, exitCode, journal) {
|
|
27781
28131
|
const isError = exitCode !== 0 && !(input.language === "shell" && exitCode === SOFT_EXIT && r.stderr.length === 0);
|
|
27782
|
-
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "");
|
|
28132
|
+
const combined = r.stdout.toString("utf8") + (exitCode !== 0 ? r.stderr.toString("utf8") : "") + (r.held === true ? "\n" + BACKGROUND_HOLD_NOTE + "\n" : "");
|
|
27783
28133
|
const fullBytes = Buffer.byteLength(combined, "utf8");
|
|
27784
28134
|
const head2 = summaryLine(exitCode, fullBytes);
|
|
27785
28135
|
const intent = input.intent ?? "";
|
|
@@ -27826,8 +28176,8 @@ async function handler3(raw, ctx) {
|
|
|
27826
28176
|
if (takesDashC(input.language, runtime)) {
|
|
27827
28177
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
27828
28178
|
} else {
|
|
27829
|
-
tmpDir = mkdtempSync2(
|
|
27830
|
-
const file2 =
|
|
28179
|
+
tmpDir = mkdtempSync2(join20(tmpdir3(), TMP_PREFIX));
|
|
28180
|
+
const file2 = join20(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
27831
28181
|
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
27832
28182
|
argv = scriptArgv(input.language, runtime, file2);
|
|
27833
28183
|
}
|
|
@@ -27863,12 +28213,12 @@ var ctxExecute = {
|
|
|
27863
28213
|
};
|
|
27864
28214
|
|
|
27865
28215
|
// src/core/tools/index.ts
|
|
27866
|
-
import { existsSync as
|
|
27867
|
-
import { dirname as
|
|
28216
|
+
import { existsSync as existsSync18, readFileSync as readFileSync18, statSync as statSync8 } from "node:fs";
|
|
28217
|
+
import { dirname as dirname12, extname as extname3, join as join22, relative as relative5, resolve as resolve9 } from "node:path";
|
|
27868
28218
|
|
|
27869
28219
|
// src/core/index/walk.ts
|
|
27870
|
-
import { readdirSync as
|
|
27871
|
-
import { join as
|
|
28220
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync17, realpathSync as realpathSync10, statSync as statSync7 } from "node:fs";
|
|
28221
|
+
import { join as join21 } from "node:path";
|
|
27872
28222
|
var GITIGNORE = ".gitignore";
|
|
27873
28223
|
var GIT_DIR = ".git";
|
|
27874
28224
|
function walkDir(root, containmentRoot) {
|
|
@@ -27877,19 +28227,19 @@ function walkDir(root, containmentRoot) {
|
|
|
27877
28227
|
const found = [];
|
|
27878
28228
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
27879
28229
|
found.sort(compareFound);
|
|
27880
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
28230
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join21(...f.dir, f.name) }));
|
|
27881
28231
|
}
|
|
27882
28232
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
27883
28233
|
let entries;
|
|
27884
28234
|
try {
|
|
27885
|
-
entries =
|
|
28235
|
+
entries = readdirSync8(abs, { withFileTypes: true });
|
|
27886
28236
|
} catch {
|
|
27887
28237
|
return;
|
|
27888
28238
|
}
|
|
27889
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
28239
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join21(abs, GITIGNORE), rel)) : parent;
|
|
27890
28240
|
for (const e of entries) {
|
|
27891
28241
|
if (e.name === GIT_DIR) continue;
|
|
27892
|
-
const path8 =
|
|
28242
|
+
const path8 = join21(abs, e.name);
|
|
27893
28243
|
let isDir = e.isDirectory();
|
|
27894
28244
|
let isFile = e.isFile();
|
|
27895
28245
|
let target = path8;
|
|
@@ -27929,7 +28279,7 @@ function compareFound(a, b) {
|
|
|
27929
28279
|
function readRules(file2, base) {
|
|
27930
28280
|
let body;
|
|
27931
28281
|
try {
|
|
27932
|
-
body =
|
|
28282
|
+
body = readFileSync17(file2, "utf8");
|
|
27933
28283
|
} catch {
|
|
27934
28284
|
return [];
|
|
27935
28285
|
}
|
|
@@ -28151,18 +28501,18 @@ function request(u, conn, proxy, signal) {
|
|
|
28151
28501
|
const host = bare(u.hostname);
|
|
28152
28502
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
28153
28503
|
const path8 = u.pathname + u.search;
|
|
28154
|
-
return new Promise((
|
|
28504
|
+
return new Promise((resolve11, reject) => {
|
|
28155
28505
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
28156
28506
|
if (proxy === void 0) {
|
|
28157
28507
|
const mod = u.protocol === "https:" ? https : http;
|
|
28158
28508
|
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
28159
|
-
req.on("response",
|
|
28509
|
+
req.on("response", resolve11).on("error", onErr).end();
|
|
28160
28510
|
return;
|
|
28161
28511
|
}
|
|
28162
28512
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
28163
28513
|
if (u.protocol === "http:") {
|
|
28164
28514
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
28165
|
-
req.on("response",
|
|
28515
|
+
req.on("response", resolve11).on("error", onErr).end();
|
|
28166
28516
|
return;
|
|
28167
28517
|
}
|
|
28168
28518
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -28182,16 +28532,16 @@ function request(u, conn, proxy, signal) {
|
|
|
28182
28532
|
headers: { host: u.host },
|
|
28183
28533
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
28184
28534
|
});
|
|
28185
|
-
req.on("response",
|
|
28535
|
+
req.on("response", resolve11).on("error", onErr).end();
|
|
28186
28536
|
});
|
|
28187
28537
|
tunnel.end();
|
|
28188
28538
|
});
|
|
28189
28539
|
}
|
|
28190
28540
|
function readBody(res) {
|
|
28191
|
-
return new Promise((
|
|
28541
|
+
return new Promise((resolve11, reject) => {
|
|
28192
28542
|
const parts = [];
|
|
28193
28543
|
res.on("data", (b) => parts.push(b));
|
|
28194
|
-
res.on("end", () =>
|
|
28544
|
+
res.on("end", () => resolve11(Buffer.concat(parts)));
|
|
28195
28545
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
28196
28546
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
28197
28547
|
});
|
|
@@ -32048,7 +32398,7 @@ function userLabel(label2) {
|
|
|
32048
32398
|
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
32049
32399
|
}
|
|
32050
32400
|
function kindOfPath(p) {
|
|
32051
|
-
return EXT_KIND[
|
|
32401
|
+
return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
|
|
32052
32402
|
}
|
|
32053
32403
|
function kindOfType(contentType) {
|
|
32054
32404
|
const semi = contentType.indexOf(";");
|
|
@@ -32057,14 +32407,14 @@ function kindOfType(contentType) {
|
|
|
32057
32407
|
}
|
|
32058
32408
|
function readUtf8(absPath) {
|
|
32059
32409
|
try {
|
|
32060
|
-
return utf8.decode(
|
|
32410
|
+
return utf8.decode(readFileSync18(absPath));
|
|
32061
32411
|
} catch {
|
|
32062
32412
|
return void 0;
|
|
32063
32413
|
}
|
|
32064
32414
|
}
|
|
32065
32415
|
function missingOrOutside(given, abs, root) {
|
|
32066
32416
|
let dir = abs;
|
|
32067
|
-
while (!
|
|
32417
|
+
while (!existsSync18(dir) && dirname12(dir) !== dir) dir = dirname12(dir);
|
|
32068
32418
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
32069
32419
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
32070
32420
|
}
|
|
@@ -32075,7 +32425,7 @@ function pathItems(input, project) {
|
|
|
32075
32425
|
if (statSync8(abs).isDirectory()) {
|
|
32076
32426
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32077
32427
|
sourceKind: "path",
|
|
32078
|
-
label: pathLabel(
|
|
32428
|
+
label: pathLabel(join22(base, f.relPath)),
|
|
32079
32429
|
kind: kindOfPath(f.relPath),
|
|
32080
32430
|
read: () => readUtf8(f.absPath)
|
|
32081
32431
|
}));
|
|
@@ -32254,9 +32604,8 @@ async function handler6(input, ctx) {
|
|
|
32254
32604
|
const newest = rows.at(-1);
|
|
32255
32605
|
if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
|
|
32256
32606
|
const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
|
|
32257
|
-
const goal = readFirstPrompt(db, sessionId);
|
|
32258
32607
|
const last2 = readLastPrompt(db, sessionId);
|
|
32259
|
-
const units = queryUnits(db, sessionId, recallQueryText(last2
|
|
32608
|
+
const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
|
|
32260
32609
|
const block = renderState(rows, newest.turn, { sources, units });
|
|
32261
32610
|
if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
|
|
32262
32611
|
return reply3(block, false);
|
|
@@ -32615,8 +32964,8 @@ var ctxStats = Object.freeze({
|
|
|
32615
32964
|
});
|
|
32616
32965
|
|
|
32617
32966
|
// src/core/ops/host-write.ts
|
|
32618
|
-
import { copyFileSync, existsSync as
|
|
32619
|
-
import { dirname as
|
|
32967
|
+
import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
32968
|
+
import { dirname as dirname13, join as join23 } from "node:path";
|
|
32620
32969
|
function defaultWrite(file2, text) {
|
|
32621
32970
|
writeFileSync6(file2, text, "utf8");
|
|
32622
32971
|
}
|
|
@@ -32625,17 +32974,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
32625
32974
|
if (own2 !== void 0) return ownMcpFileOf(agent, own2.file, env, home);
|
|
32626
32975
|
switch (agent) {
|
|
32627
32976
|
case "opencode":
|
|
32628
|
-
return
|
|
32977
|
+
return join23(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
32629
32978
|
// D-WIN-OPENCODE-DIR-1
|
|
32630
32979
|
case "pi":
|
|
32631
|
-
return
|
|
32980
|
+
return join23(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
32632
32981
|
case "gemini":
|
|
32633
|
-
return
|
|
32982
|
+
return join23(geminiDirOf(env, home), SETTINGS_FILE);
|
|
32634
32983
|
// D-R38-GEMINI-HOME-1
|
|
32635
32984
|
case "copilot-cli":
|
|
32636
32985
|
return null;
|
|
32637
32986
|
default:
|
|
32638
|
-
return
|
|
32987
|
+
return join23(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
32639
32988
|
}
|
|
32640
32989
|
}
|
|
32641
32990
|
function cell3(value) {
|
|
@@ -32647,8 +32996,8 @@ function toRow(file2, edit) {
|
|
|
32647
32996
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
32648
32997
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
32649
32998
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
32650
|
-
const had =
|
|
32651
|
-
|
|
32999
|
+
const had = existsSync19(file2);
|
|
33000
|
+
mkdirSync8(dirname13(file2), { recursive: true });
|
|
32652
33001
|
if (had) copyFileSync(file2, trash);
|
|
32653
33002
|
try {
|
|
32654
33003
|
write2(tmp, text);
|
|
@@ -32677,7 +33026,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
32677
33026
|
if (requested === null) return [];
|
|
32678
33027
|
const current = readHostConfig(row5.id, requested);
|
|
32679
33028
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
32680
|
-
const exists =
|
|
33029
|
+
const exists = existsSync19(current.path);
|
|
32681
33030
|
if (exists && result.text === current.text) return [];
|
|
32682
33031
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
32683
33032
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -32685,15 +33034,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
32685
33034
|
}
|
|
32686
33035
|
|
|
32687
33036
|
// src/core/ops/uninstall.ts
|
|
32688
|
-
import { existsSync as
|
|
32689
|
-
import { join as
|
|
33037
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
33038
|
+
import { join as join24 } from "node:path";
|
|
32690
33039
|
function row2(area, before, after) {
|
|
32691
33040
|
return { area, before, after };
|
|
32692
33041
|
}
|
|
32693
33042
|
function stopServers(configDir, projectKey) {
|
|
32694
33043
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
32695
|
-
const dir =
|
|
32696
|
-
for (const serverId of stopped) writeFileSync7(
|
|
33044
|
+
const dir = join24(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
33045
|
+
for (const serverId of stopped) writeFileSync7(join24(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
32697
33046
|
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 };
|
|
32698
33047
|
}
|
|
32699
33048
|
function rootOrNull(adapter, env) {
|
|
@@ -32711,15 +33060,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
32711
33060
|
const root = rootOrNull(adapter, env);
|
|
32712
33061
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
32713
33062
|
if (adapter.installMode === "marketplace") {
|
|
32714
|
-
const cache =
|
|
33063
|
+
const cache = join24(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
32715
33064
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
32716
33065
|
}
|
|
32717
33066
|
rmSync6(root, { recursive: true, force: true });
|
|
32718
33067
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
32719
33068
|
}
|
|
32720
33069
|
case "plugin": {
|
|
32721
|
-
const agentDir =
|
|
32722
|
-
if (!
|
|
33070
|
+
const agentDir = join24(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
33071
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
32723
33072
|
rmSync6(agentDir, { recursive: true, force: true });
|
|
32724
33073
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
32725
33074
|
}
|
|
@@ -32764,7 +33113,7 @@ function ownEntries2(agent, env) {
|
|
|
32764
33113
|
}
|
|
32765
33114
|
if (agent === "opencode") {
|
|
32766
33115
|
return [{
|
|
32767
|
-
file:
|
|
33116
|
+
file: join24(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
32768
33117
|
// D-WIN-OPENCODE-DIR-1
|
|
32769
33118
|
key: OPENCODE_PLUGIN_KEY,
|
|
32770
33119
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -32775,7 +33124,7 @@ function ownEntries2(agent, env) {
|
|
|
32775
33124
|
if (agent === "pi") {
|
|
32776
33125
|
const agentDir = piAgentDirOf(env, home);
|
|
32777
33126
|
return [{
|
|
32778
|
-
file:
|
|
33127
|
+
file: join24(agentDir, SETTINGS_FILE),
|
|
32779
33128
|
key: PI_PACKAGES_KEY,
|
|
32780
33129
|
shown: PI_PACKAGES_KEY,
|
|
32781
33130
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -32797,12 +33146,12 @@ function removeOwnEntries(agent, env) {
|
|
|
32797
33146
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
32798
33147
|
}
|
|
32799
33148
|
function removeProjectData(configDir, projectKey) {
|
|
32800
|
-
const projects =
|
|
32801
|
-
const dir =
|
|
32802
|
-
if (!
|
|
33149
|
+
const projects = join24(configDir, PROJECTS_DIR_NAME);
|
|
33150
|
+
const dir = join24(projects, projectKey);
|
|
33151
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
32803
33152
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
32804
|
-
for (const name of
|
|
32805
|
-
if (name !== OWNERS_DIR_NAME) rmSync6(
|
|
33153
|
+
for (const name of readdirSync9(dir)) {
|
|
33154
|
+
if (name !== OWNERS_DIR_NAME) rmSync6(join24(dir, name), { recursive: true, force: true });
|
|
32806
33155
|
}
|
|
32807
33156
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
32808
33157
|
}
|
|
@@ -32810,12 +33159,12 @@ function runUninstall(input) {
|
|
|
32810
33159
|
const configDir = resolveConfigDir(input.env);
|
|
32811
33160
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
32812
33161
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
32813
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
33162
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join24(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
32814
33163
|
return { rows, stopped: stop.stopped };
|
|
32815
33164
|
}
|
|
32816
33165
|
|
|
32817
33166
|
// src/core/ops/v1-remove.ts
|
|
32818
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
33167
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync19, rmSync as rmSync7 } from "node:fs";
|
|
32819
33168
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
32820
33169
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
32821
33170
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -32827,7 +33176,7 @@ function moveAside(target, undo) {
|
|
|
32827
33176
|
}
|
|
32828
33177
|
function keepAside(target, undo) {
|
|
32829
33178
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
32830
|
-
for (let n = 2;
|
|
33179
|
+
for (let n = 2; existsSync21(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
32831
33180
|
renameWithRetry(target, aside);
|
|
32832
33181
|
undo.push({ trash: aside, target, keep: true });
|
|
32833
33182
|
return aside;
|
|
@@ -32866,8 +33215,8 @@ function locate(doc, path8) {
|
|
|
32866
33215
|
return null;
|
|
32867
33216
|
}
|
|
32868
33217
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
32869
|
-
const layout = hostLayout(
|
|
32870
|
-
const text = hostText(
|
|
33218
|
+
const layout = hostLayout(readFileSync19(file2, "utf8"));
|
|
33219
|
+
const text = hostText(readFileSync19(file2, "utf8"));
|
|
32871
33220
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
32872
33221
|
const hit = /* @__PURE__ */ new Set();
|
|
32873
33222
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -32904,20 +33253,20 @@ function removeV1(agent, findings, project) {
|
|
|
32904
33253
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
32905
33254
|
else if (f.path === "") {
|
|
32906
33255
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
32907
|
-
else if (
|
|
32908
|
-
else if (
|
|
33256
|
+
else if (existsSync21(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
33257
|
+
else if (existsSync21(f.file)) {
|
|
32909
33258
|
moveAside(f.file, undo);
|
|
32910
33259
|
done.set(f, UPGRADE_REMOVED);
|
|
32911
33260
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
32912
33261
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
32913
33262
|
}
|
|
32914
33263
|
for (const [file2, list4] of entries) {
|
|
32915
|
-
if (!
|
|
33264
|
+
if (!existsSync21(file2)) {
|
|
32916
33265
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
32917
33266
|
continue;
|
|
32918
33267
|
}
|
|
32919
33268
|
if (file2.endsWith(TOML_EXT)) {
|
|
32920
|
-
const rawToml =
|
|
33269
|
+
const rawToml = readFileSync19(file2, "utf8");
|
|
32921
33270
|
const tomlLayout = hostLayout(rawToml);
|
|
32922
33271
|
let text = hostText(rawToml);
|
|
32923
33272
|
for (const f of list4) {
|
|
@@ -32945,7 +33294,7 @@ function removeV1(agent, findings, project) {
|
|
|
32945
33294
|
},
|
|
32946
33295
|
rollback() {
|
|
32947
33296
|
for (const u of undo.splice(0).reverse()) {
|
|
32948
|
-
if (!
|
|
33297
|
+
if (!existsSync21(u.trash)) continue;
|
|
32949
33298
|
rmSync7(u.target, { recursive: true, force: true });
|
|
32950
33299
|
renameWithRetry(u.trash, u.target);
|
|
32951
33300
|
}
|
|
@@ -32975,8 +33324,8 @@ function pluginRootRow(adapter, env) {
|
|
|
32975
33324
|
}
|
|
32976
33325
|
return root === own2 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own2)];
|
|
32977
33326
|
}
|
|
32978
|
-
function hostRow(adapter) {
|
|
32979
|
-
return row4(UPGRADE_HOST_AREA, "",
|
|
33327
|
+
function hostRow(adapter, env) {
|
|
33328
|
+
return row4(UPGRADE_HOST_AREA, "", hostUpdateCommand(adapter.id, env));
|
|
32980
33329
|
}
|
|
32981
33330
|
function upgrade(adapter, deps, home) {
|
|
32982
33331
|
let removal = null;
|
|
@@ -32984,7 +33333,7 @@ function upgrade(adapter, deps, home) {
|
|
|
32984
33333
|
const step5 = regenerateHostConfig(adapter, home, { env: deps.env, write: deps.write });
|
|
32985
33334
|
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) });
|
|
32986
33335
|
removal = removeV1(adapter.id, findings, deps.project.worktree);
|
|
32987
|
-
const rows = [hostRow(adapter), ...step5, ...removal.rows];
|
|
33336
|
+
const rows = [hostRow(adapter, deps.env), ...step5, ...removal.rows];
|
|
32988
33337
|
removal.commit();
|
|
32989
33338
|
return rows;
|
|
32990
33339
|
} catch (err) {
|
|
@@ -33075,7 +33424,55 @@ function checkCall(tool, input) {
|
|
|
33075
33424
|
}
|
|
33076
33425
|
|
|
33077
33426
|
// src/entries/opencode.ts
|
|
33427
|
+
import { resolve as resolve10 } from "node:path";
|
|
33078
33428
|
var AGENT = "opencode";
|
|
33429
|
+
var slash = (p) => p.replaceAll("\\", "/");
|
|
33430
|
+
function shellRequest(commands) {
|
|
33431
|
+
const resources = [];
|
|
33432
|
+
for (const cmd of commands) {
|
|
33433
|
+
const parsed = parseShell(cmd);
|
|
33434
|
+
const raws = parsed.ok ? parsed.commands.map((c) => c.raw.trim()).filter((r) => r !== "") : [];
|
|
33435
|
+
resources.push(...raws.length > 0 ? raws : [cmd.trim()]);
|
|
33436
|
+
}
|
|
33437
|
+
return { action: OC_SHELL_ACTION, resources, save: resources };
|
|
33438
|
+
}
|
|
33439
|
+
function permissionRequests(tool, input, base) {
|
|
33440
|
+
const i = input ?? {};
|
|
33441
|
+
const str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
33442
|
+
const out = [];
|
|
33443
|
+
const read3 = (p) => {
|
|
33444
|
+
const abs = slash(resolve10(base, p));
|
|
33445
|
+
return { action: OC_READ_ACTION, resources: [abs], save: [abs] };
|
|
33446
|
+
};
|
|
33447
|
+
if (tool === "ctx_execute") {
|
|
33448
|
+
const language = str3(i.language) ?? OC_ANY_RESOURCE;
|
|
33449
|
+
out.push({ action: tool, resources: [language], save: [language] });
|
|
33450
|
+
if (isShellLanguage(language) && typeof i.code === "string") out.push(shellRequest([i.code]));
|
|
33451
|
+
const file2 = str3(i.file);
|
|
33452
|
+
if (file2 !== void 0) out.push(read3(file2));
|
|
33453
|
+
return out;
|
|
33454
|
+
}
|
|
33455
|
+
if (tool === "ctx_batch") {
|
|
33456
|
+
const commands = Array.isArray(i.commands) ? i.commands.filter((c) => typeof c === "string") : [];
|
|
33457
|
+
out.push({ action: tool, resources: commands, save: commands });
|
|
33458
|
+
if (commands.length > 0) out.push(shellRequest(commands));
|
|
33459
|
+
return out;
|
|
33460
|
+
}
|
|
33461
|
+
if (tool === "ctx_index") {
|
|
33462
|
+
const path8 = str3(i.path);
|
|
33463
|
+
const url2 = str3(i.url);
|
|
33464
|
+
const what = path8 ?? url2 ?? OC_ANY_RESOURCE;
|
|
33465
|
+
out.push({ action: tool, resources: [what], save: [what] });
|
|
33466
|
+
if (path8 !== void 0) out.push(read3(path8));
|
|
33467
|
+
if (url2 !== void 0) out.push({ action: OC_WEBFETCH_ACTION, resources: [url2], save: [OC_ANY_RESOURCE] });
|
|
33468
|
+
return out;
|
|
33469
|
+
}
|
|
33470
|
+
return [{ action: tool, resources: [OC_ANY_RESOURCE], save: [OC_ANY_RESOURCE] }];
|
|
33471
|
+
}
|
|
33472
|
+
async function legacyAsk(req, toolCtx) {
|
|
33473
|
+
const permission = req.action === OC_SHELL_ACTION ? OC_LEGACY_SHELL_ACTION : req.action;
|
|
33474
|
+
await toolCtx.ask?.({ permission, patterns: req.resources, always: req.save, metadata: {} });
|
|
33475
|
+
}
|
|
33079
33476
|
var id = PLUGIN_ID;
|
|
33080
33477
|
async function setupLegacy(app) {
|
|
33081
33478
|
const cwd = app.directory;
|
|
@@ -33115,6 +33512,17 @@ async function setupLegacy(app) {
|
|
|
33115
33512
|
signal: toolCtx.abort ?? new AbortController().signal,
|
|
33116
33513
|
protocolVersion: ""
|
|
33117
33514
|
};
|
|
33515
|
+
const permission = app.permission ?? (typeof toolCtx.ask === "function" ? "wired" : void 0);
|
|
33516
|
+
if (permission !== void 0) ctx.hostPermission = permission;
|
|
33517
|
+
if (permission === "wired") {
|
|
33518
|
+
let base = cwd ?? "";
|
|
33519
|
+
try {
|
|
33520
|
+
base = ctx.project.worktree;
|
|
33521
|
+
} catch {
|
|
33522
|
+
}
|
|
33523
|
+
const check2 = app.assert ?? legacyAsk;
|
|
33524
|
+
for (const req of permissionRequests(tool.name, checked.data, base)) await check2(req, toolCtx);
|
|
33525
|
+
}
|
|
33118
33526
|
let reply4;
|
|
33119
33527
|
try {
|
|
33120
33528
|
reply4 = await tool.handler(checked.data, ctx);
|
|
@@ -33189,8 +33597,21 @@ function oc2Text(content) {
|
|
|
33189
33597
|
}
|
|
33190
33598
|
async function setup(ctx) {
|
|
33191
33599
|
const tools = /* @__PURE__ */ new Map();
|
|
33600
|
+
const assert2 = ctx.permission?.assert;
|
|
33192
33601
|
const hooks = await setupLegacy({
|
|
33193
33602
|
directory: ctx.location.directory,
|
|
33603
|
+
// D-1331-OC-PERM-1: ctx.permission.assert is the 2.x plugin check (anomalyco/opencode#50652); "missing" feeds D10.
|
|
33604
|
+
permission: typeof assert2 === "function" ? "wired" : "missing",
|
|
33605
|
+
assert: async (req, t) => {
|
|
33606
|
+
await assert2?.({
|
|
33607
|
+
sessionID: t.sessionID ?? "",
|
|
33608
|
+
...t.agent === void 0 ? {} : { agent: t.agent },
|
|
33609
|
+
action: req.action,
|
|
33610
|
+
resources: req.resources,
|
|
33611
|
+
save: req.save,
|
|
33612
|
+
...t.messageID === void 0 || t.callID === void 0 ? {} : { source: { type: "tool", messageID: t.messageID, id: t.callID } }
|
|
33613
|
+
});
|
|
33614
|
+
},
|
|
33194
33615
|
tool(name, def) {
|
|
33195
33616
|
tools.set(name, {
|
|
33196
33617
|
name,
|
|
@@ -33199,7 +33620,8 @@ async function setup(ctx) {
|
|
|
33199
33620
|
options: { codemode: false },
|
|
33200
33621
|
// a ctx_* tool is listed to the model by name, not behind the host's code tool
|
|
33201
33622
|
async execute(input, context) {
|
|
33202
|
-
|
|
33623
|
+
const t = { sessionID: context.sessionID, abort: context.signal, agent: context.agent, messageID: context.messageID, callID: context.id };
|
|
33624
|
+
return { content: await def.execute(input, t) };
|
|
33203
33625
|
}
|
|
33204
33626
|
});
|
|
33205
33627
|
}
|
|
@@ -33250,6 +33672,7 @@ var opencode_default2 = { id: PLUGIN_ID, server, setup };
|
|
|
33250
33672
|
export {
|
|
33251
33673
|
opencode_default2 as default,
|
|
33252
33674
|
id,
|
|
33675
|
+
permissionRequests,
|
|
33253
33676
|
server,
|
|
33254
33677
|
setup,
|
|
33255
33678
|
setupLegacy
|