context-mode 2.1.5 → 2.1.6
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 +199 -133
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +98 -98
- package/opencode/plugin.js +575 -341
- package/package.json +1 -1
- package/pi/index.js +491 -336
- package/qwen-extension.json +1 -1
- package/run.mjs +205 -67
- package/search.mjs +205 -67
- package/server.mjs +260 -163
package/server.mjs
CHANGED
|
@@ -7,8 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { dirname as dirname12, join as
|
|
10
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync9 } from "node:fs";
|
|
11
|
+
import { dirname as dirname12, join as join23 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
13
13
|
|
|
14
14
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -28065,7 +28065,14 @@ var REPORT_CAP = 4096;
|
|
|
28065
28065
|
var POINTER_MIN = 640;
|
|
28066
28066
|
var STATE_CLOSE_TAG = "</context_mode_state>";
|
|
28067
28067
|
var INDEX_WRITE_CHUNK = 1048576;
|
|
28068
|
-
var
|
|
28068
|
+
var REPLACE_TRIGGER_BYTES_DEFAULT = 4096;
|
|
28069
|
+
var REPLACE_TRIGGER_ENV = "CTX_REPLACE_TRIGGER_BYTES";
|
|
28070
|
+
function readReplaceTrigger(raw) {
|
|
28071
|
+
if (raw === void 0 || raw.trim() === "") return REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
28072
|
+
const n = Number(raw);
|
|
28073
|
+
return Number.isSafeInteger(n) && n > 0 ? n : REPLACE_TRIGGER_BYTES_DEFAULT;
|
|
28074
|
+
}
|
|
28075
|
+
var REPLACE_TRIGGER_BYTES = readReplaceTrigger(process.env[REPLACE_TRIGGER_ENV]);
|
|
28069
28076
|
var RANGE_READ_TOOLS = Object.freeze(["Read", "view"]);
|
|
28070
28077
|
var READ_RANGE_KEYS = Object.freeze(["offset", "limit", "view_range"]);
|
|
28071
28078
|
var MAX_CHUNK_BYTES = 4096;
|
|
@@ -28276,6 +28283,7 @@ function readHintEvery(raw) {
|
|
|
28276
28283
|
return Number.isSafeInteger(n) && n > 0 ? n : MCP_HINT_EVERY_DEFAULT;
|
|
28277
28284
|
}
|
|
28278
28285
|
var MCP_HINT_EVERY = readHintEvery(process.env.CTX_MCP_HINT_EVERY);
|
|
28286
|
+
var SHARED_SKILLS_DIR = Object.freeze([".agents", "skills"]);
|
|
28279
28287
|
var DENY_WHAT = Object.freeze({
|
|
28280
28288
|
curl: "This curl/wget call",
|
|
28281
28289
|
http: "This inline HTTP call",
|
|
@@ -28345,15 +28353,16 @@ var READ_MEDIA_BY_AGENT = Object.freeze({
|
|
|
28345
28353
|
opencode: READ_IMAGES_AND_PDF,
|
|
28346
28354
|
pi: READ_IMAGES,
|
|
28347
28355
|
vscode: READ_IMAGES,
|
|
28356
|
+
zcode: READ_IMAGES,
|
|
28348
28357
|
"copilot-cli": [],
|
|
28349
28358
|
codex: [],
|
|
28350
|
-
kiro: []
|
|
28351
|
-
zcode: []
|
|
28359
|
+
kiro: []
|
|
28352
28360
|
});
|
|
28353
28361
|
var OWN_TOOL_PREFIX = "ctx_";
|
|
28354
28362
|
var EDIT_TOOLS = Object.freeze(["Write", "Edit"]);
|
|
28355
28363
|
var EDIT_PATH_KEYS = Object.freeze(["file_path", "path"]);
|
|
28356
28364
|
var RECALL_MIN_SCORE = 5;
|
|
28365
|
+
var RECALL_QUERY_MAX_TERMS = 64;
|
|
28357
28366
|
var RECALL_UNIT_CANDIDATES = 64;
|
|
28358
28367
|
var AGENT_ARG = "--agent";
|
|
28359
28368
|
var DECAY_SCALE = 1e3;
|
|
@@ -28434,7 +28443,7 @@ function PURGE_SUMMARY(rows, scope) {
|
|
|
28434
28443
|
var DECISION_SOURCE = "decision";
|
|
28435
28444
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28436
28445
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28437
|
-
var BUNDLE_SHA = true ? "
|
|
28446
|
+
var BUNDLE_SHA = true ? "ee0a1f6058f6abdb5af70b05f825a997bb15615d" : void 0;
|
|
28438
28447
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28439
28448
|
var DOCTOR_LABEL = Object.freeze({
|
|
28440
28449
|
D1: "version",
|
|
@@ -28520,9 +28529,9 @@ var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-ta
|
|
|
28520
28529
|
var D1_PRERELEASE_SEP = "-";
|
|
28521
28530
|
var D1_DEFAULT_TAG = "latest";
|
|
28522
28531
|
var GIT_LS_REMOTE = "ls-remote";
|
|
28523
|
-
var D2_NODE_FIX = `install
|
|
28532
|
+
var D2_NODE_FIX = `nvm install ${NODE_MIN.split(".")[0]}, or install it from https://nodejs.org`;
|
|
28524
28533
|
function D2_NODE_DETAIL(version4) {
|
|
28525
|
-
return `Node ${
|
|
28534
|
+
return `Context Mode needs Node ${NODE_MIN} or newer; you have ${version4}`;
|
|
28526
28535
|
}
|
|
28527
28536
|
var D2_SQLITE_DETAIL = "node:sqlite failed to load";
|
|
28528
28537
|
var D2_SQLITE_FIX = "run ctx_doctor";
|
|
@@ -28691,6 +28700,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
28691
28700
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
28692
28701
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
28693
28702
|
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";
|
|
28703
|
+
var D5_READ_OWN_DETAIL = "PreToolUse Read of a skill file over the one-read limit under the agent's own config dir came back denied: skill and rule files must reach the model whole (#1326)";
|
|
28694
28704
|
var D5_READ_MEDIA_DETAIL = "PreToolUse Read of a PNG over the one-read limit came back denied: an image Read must reach the model as an image block (#1321)";
|
|
28695
28705
|
var D5_READ_SHAPE_DETAIL = `PostToolUse Read replace is not Read's output shape {type:"text", file:{filePath, content, numLines, startLine, totalLines}}: Claude Code drops it and shows a hook warning`;
|
|
28696
28706
|
function D5_SLOW_DETAIL(ms) {
|
|
@@ -28702,6 +28712,11 @@ var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
|
28702
28712
|
function D10_DETAIL(mode) {
|
|
28703
28713
|
return `enforcement mode: ${mode}`;
|
|
28704
28714
|
}
|
|
28715
|
+
function D10_PERMISSION_DETAIL(mode) {
|
|
28716
|
+
return `enforcement mode: ${mode}; OpenCode permission rules apply to ctx_* tools`;
|
|
28717
|
+
}
|
|
28718
|
+
var D10_PERMISSION_MISSING_DETAIL = "this OpenCode build gives plugins no permission check (ctx.permission.assert), so ctx_* tools cannot follow OpenCode permission rules";
|
|
28719
|
+
var D10_PERMISSION_FIX = "opencode upgrade";
|
|
28705
28720
|
var D11_WIN_DETAIL = "Git Bash not found";
|
|
28706
28721
|
var D11_WIN_FIX = "install Git for Windows";
|
|
28707
28722
|
var D11_POSIX_DETAIL = "no sh on PATH";
|
|
@@ -28764,6 +28779,8 @@ var SETTINGS_FILE = "settings.json";
|
|
|
28764
28779
|
var CLAUDE_USER_CONFIG_FILE = ".claude.json";
|
|
28765
28780
|
var HOOKS_JSON_FILE = "hooks.json";
|
|
28766
28781
|
var CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
28782
|
+
var SETUP_BACKUP_DIR_NAME = "backups";
|
|
28783
|
+
var SETUP_MANIFEST_FILE = "manifest.json";
|
|
28767
28784
|
var CODEX_HOME_ENV = "CODEX_HOME";
|
|
28768
28785
|
var COPILOT_HOME_ENV = "COPILOT_HOME";
|
|
28769
28786
|
var GEMINI_CLI_HOME_ENV = "GEMINI_CLI_HOME";
|
|
@@ -28858,6 +28875,7 @@ var HOST_CONFIG_TEXT_PATH = "(given text)";
|
|
|
28858
28875
|
var JSON_INDENT_UNIT = " ";
|
|
28859
28876
|
var MCP_COMMAND_FIELD = "command";
|
|
28860
28877
|
var MCP_ARGS_FIELD = "args";
|
|
28878
|
+
var MCP_ENV_FIELD = "env";
|
|
28861
28879
|
var ZCODE_MCP_FEATURE_KEY = Object.freeze(["features", "mcp"]);
|
|
28862
28880
|
var CODEX_OMIT_TOOLS_FROM_FIELD = "omit_tools_from";
|
|
28863
28881
|
var CODEX_OMIT_DEFERRED = Object.freeze(["deferred"]);
|
|
@@ -28975,7 +28993,8 @@ var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
|
28975
28993
|
|
|
28976
28994
|
// src/core/contracts/errors.ts
|
|
28977
28995
|
var ERROR_TEXT = Object.freeze({
|
|
28978
|
-
NODE_TOO_OLD: "
|
|
28996
|
+
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.",
|
|
28997
|
+
// #1328 D-NODE-OLD-1
|
|
28979
28998
|
NO_SQLITE: "node:sqlite failed to load. Fix: run ctx_doctor.",
|
|
28980
28999
|
DB_GONE: "context.db is gone and its WAL file is still in place. Fix: run ctx_doctor once; it keeps the WAL file in a dated folder and starts a new index.",
|
|
28981
29000
|
// D-ORPHAN-WAL-1
|
|
@@ -29407,7 +29426,7 @@ function installExitGuard(opts) {
|
|
|
29407
29426
|
|
|
29408
29427
|
// src/core/project/config-dir.ts
|
|
29409
29428
|
import { basename, dirname, join, posix, resolve, win32 } from "node:path";
|
|
29410
|
-
var { mkdirSync: mkdirSync2, realpathSync } = process.getBuiltinModule("node:fs");
|
|
29429
|
+
var { existsSync: existsSync2, mkdirSync: mkdirSync2, readFileSync, readdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
29411
29430
|
function homeDirOf(env, platform = process.platform) {
|
|
29412
29431
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
29413
29432
|
if (platform === "win32") {
|
|
@@ -29434,7 +29453,34 @@ function codexPluginHomeOf(bundleDir2) {
|
|
|
29434
29453
|
function codexRunDirOf(env, home, bundleDir2) {
|
|
29435
29454
|
const dir = env[CODEX_HOME_ENV];
|
|
29436
29455
|
if (dir !== void 0 && dir !== "") return dir;
|
|
29437
|
-
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
29456
|
+
return codexPluginHomeOf(bundleDir2) ?? codexSetupHomeOf(env, home) ?? codexDirOf(env, home);
|
|
29457
|
+
}
|
|
29458
|
+
function codexSetupHomeOf(env, home) {
|
|
29459
|
+
if (home === "" && !env[DATA_DIR_ENV]) return null;
|
|
29460
|
+
const base = join(dataRootOf(env, home), SETUP_BACKUP_DIR_NAME);
|
|
29461
|
+
let runs;
|
|
29462
|
+
try {
|
|
29463
|
+
runs = readdirSync(base).sort().reverse();
|
|
29464
|
+
} catch {
|
|
29465
|
+
return null;
|
|
29466
|
+
}
|
|
29467
|
+
for (const run of runs) {
|
|
29468
|
+
const file2 = join(base, run, SETUP_MANIFEST_FILE);
|
|
29469
|
+
if (!existsSync2(file2)) continue;
|
|
29470
|
+
let entries;
|
|
29471
|
+
try {
|
|
29472
|
+
entries = JSON.parse(readFileSync(file2, "utf8")).entries;
|
|
29473
|
+
} catch {
|
|
29474
|
+
continue;
|
|
29475
|
+
}
|
|
29476
|
+
if (!Array.isArray(entries)) continue;
|
|
29477
|
+
for (const e of entries) {
|
|
29478
|
+
if (e?.agent !== "codex" || typeof e.file !== "string") continue;
|
|
29479
|
+
const p = e.file.includes(win32.sep) ? win32 : posix;
|
|
29480
|
+
if (p.basename(e.file) === CONFIG_TOML_FILE) return p.dirname(e.file);
|
|
29481
|
+
}
|
|
29482
|
+
}
|
|
29483
|
+
return null;
|
|
29438
29484
|
}
|
|
29439
29485
|
function copilotDirOf(env, home) {
|
|
29440
29486
|
const dir = env[COPILOT_HOME_ENV];
|
|
@@ -29686,7 +29732,7 @@ function sha256Hex(text) {
|
|
|
29686
29732
|
}
|
|
29687
29733
|
|
|
29688
29734
|
// src/core/project/resolve.ts
|
|
29689
|
-
var { existsSync:
|
|
29735
|
+
var { existsSync: existsSync3, readFileSync: readFileSync2, realpathSync: realpathSync3, statSync } = process.getBuiltinModule("node:fs");
|
|
29690
29736
|
function sourceOf(agent) {
|
|
29691
29737
|
switch (agent) {
|
|
29692
29738
|
case "claude-code":
|
|
@@ -29756,12 +29802,12 @@ function gitDirAt(dotGit) {
|
|
|
29756
29802
|
} catch {
|
|
29757
29803
|
return null;
|
|
29758
29804
|
}
|
|
29759
|
-
return
|
|
29805
|
+
return existsSync3(join3(gitDir, GIT_HEAD_FILE)) ? gitDir : null;
|
|
29760
29806
|
}
|
|
29761
29807
|
function firstLine(file2) {
|
|
29762
29808
|
let text;
|
|
29763
29809
|
try {
|
|
29764
|
-
text =
|
|
29810
|
+
text = readFileSync2(file2, "utf8");
|
|
29765
29811
|
} catch {
|
|
29766
29812
|
return null;
|
|
29767
29813
|
}
|
|
@@ -29814,7 +29860,7 @@ function resolveProject(agent, src) {
|
|
|
29814
29860
|
}
|
|
29815
29861
|
|
|
29816
29862
|
// src/core/store/cleanup.ts
|
|
29817
|
-
import { existsSync as
|
|
29863
|
+
import { existsSync as existsSync4, readdirSync as readdirSync3, rmSync as rmSync3 } from "node:fs";
|
|
29818
29864
|
import { join as join5 } from "node:path";
|
|
29819
29865
|
|
|
29820
29866
|
// src/core/store/snippet.ts
|
|
@@ -32341,8 +32387,25 @@ function listSessionSources(db, sessionId, limit) {
|
|
|
32341
32387
|
const rows = stmt(db.raw, "SELECT id, label, bytes_total FROM sources WHERE session_id = ? ORDER BY id DESC LIMIT ?").all(sessionId, limit);
|
|
32342
32388
|
return rows.map((r) => ({ id: Number(r.id), label: r.label, bytes: Number(r.bytes_total) }));
|
|
32343
32389
|
}
|
|
32344
|
-
function recallQueryText(prompt
|
|
32345
|
-
|
|
32390
|
+
function recallQueryText(prompt) {
|
|
32391
|
+
const kept = /* @__PURE__ */ new Set();
|
|
32392
|
+
const all = /* @__PURE__ */ new Set();
|
|
32393
|
+
const add = (w) => {
|
|
32394
|
+
if (all.size < RECALL_QUERY_MAX_TERMS) all.add(w);
|
|
32395
|
+
if (!STOPWORDS.has(w.toLowerCase())) kept.add(w);
|
|
32396
|
+
};
|
|
32397
|
+
let cur = "";
|
|
32398
|
+
for (const ch of prompt) {
|
|
32399
|
+
if (kept.size >= RECALL_QUERY_MAX_TERMS) break;
|
|
32400
|
+
if (ch.trim() === "" || ch === "\0") {
|
|
32401
|
+
if (cur !== "") add(cur);
|
|
32402
|
+
cur = "";
|
|
32403
|
+
} else {
|
|
32404
|
+
cur += ch;
|
|
32405
|
+
}
|
|
32406
|
+
}
|
|
32407
|
+
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
32408
|
+
return [...kept.size > 0 ? kept : all].join(" ");
|
|
32346
32409
|
}
|
|
32347
32410
|
function queryUnits(db, sessionId, q, limit) {
|
|
32348
32411
|
const match = searchTerms(q).join(" OR ");
|
|
@@ -32354,7 +32417,7 @@ function queryUnits(db, sessionId, q, limit) {
|
|
|
32354
32417
|
}
|
|
32355
32418
|
|
|
32356
32419
|
// src/core/store/owners.ts
|
|
32357
|
-
import { mkdirSync as mkdirSync3, readdirSync, readFileSync as
|
|
32420
|
+
import { mkdirSync as mkdirSync3, readdirSync as readdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, writeFileSync } from "node:fs";
|
|
32358
32421
|
import { basename as basename3, join as join4 } from "node:path";
|
|
32359
32422
|
function ownersDir(configDir, projectKey) {
|
|
32360
32423
|
return join4(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
@@ -32387,7 +32450,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
32387
32450
|
const dir = ownersDir(configDir, projectKey);
|
|
32388
32451
|
let names;
|
|
32389
32452
|
try {
|
|
32390
|
-
names =
|
|
32453
|
+
names = readdirSync2(dir);
|
|
32391
32454
|
} catch (err) {
|
|
32392
32455
|
if (errCode(err) === "ENOENT") return [];
|
|
32393
32456
|
throw err;
|
|
@@ -32398,7 +32461,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
32398
32461
|
const file2 = join4(dir, name);
|
|
32399
32462
|
let text;
|
|
32400
32463
|
try {
|
|
32401
|
-
text =
|
|
32464
|
+
text = readFileSync3(file2, "utf8");
|
|
32402
32465
|
} catch (err) {
|
|
32403
32466
|
if (errCode(err) === "ENOENT") continue;
|
|
32404
32467
|
throw err;
|
|
@@ -32445,7 +32508,7 @@ function userVersion(raw) {
|
|
|
32445
32508
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
32446
32509
|
}
|
|
32447
32510
|
function openForSweep(dbPath, projectKey) {
|
|
32448
|
-
if (!
|
|
32511
|
+
if (!existsSync4(dbPath) && (existsSync4(dbPath + DB_WAL_SUFFIX) || existsSync4(dbPath + DB_SHM_SUFFIX))) {
|
|
32449
32512
|
throw new CtxError("DB_GONE");
|
|
32450
32513
|
}
|
|
32451
32514
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -32480,7 +32543,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
32480
32543
|
function sweepDeadProjects(configDir) {
|
|
32481
32544
|
let entries;
|
|
32482
32545
|
try {
|
|
32483
|
-
entries =
|
|
32546
|
+
entries = readdirSync3(join5(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
32484
32547
|
} catch (err) {
|
|
32485
32548
|
if (err.code === "ENOENT") return [];
|
|
32486
32549
|
throw err;
|
|
@@ -43929,7 +43992,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43929
43992
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43930
43993
|
return { end: start + r.read, written: r.written };
|
|
43931
43994
|
}
|
|
43932
|
-
function merge4(src, blocks,
|
|
43995
|
+
function merge4(src, blocks, join24, cap, lineCut) {
|
|
43933
43996
|
const out = [];
|
|
43934
43997
|
const scratch = new Uint8Array(cap);
|
|
43935
43998
|
let wide;
|
|
@@ -43939,7 +44002,7 @@ function merge4(src, blocks, join23, cap, lineCut) {
|
|
|
43939
44002
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43940
44003
|
};
|
|
43941
44004
|
for (const b of blocks) {
|
|
43942
|
-
if (cur !== void 0 && !
|
|
44005
|
+
if (cur !== void 0 && !join24) {
|
|
43943
44006
|
emit(cur.start, cur.end, curBytes);
|
|
43944
44007
|
cur = void 0;
|
|
43945
44008
|
}
|
|
@@ -44208,7 +44271,7 @@ function runProcess(argv, o) {
|
|
|
44208
44271
|
}
|
|
44209
44272
|
|
|
44210
44273
|
// src/core/index/auto-memory.ts
|
|
44211
|
-
import { readdirSync as
|
|
44274
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
44212
44275
|
import { join as join6 } from "node:path";
|
|
44213
44276
|
var MEMORY_FILES = Object.freeze([
|
|
44214
44277
|
Object.freeze(["CLAUDE.md"]),
|
|
@@ -44223,7 +44286,7 @@ var KIRO_STEERING = Object.freeze([".kiro", "steering"]);
|
|
|
44223
44286
|
var MD = ".md";
|
|
44224
44287
|
function steeringFiles(worktree) {
|
|
44225
44288
|
try {
|
|
44226
|
-
return
|
|
44289
|
+
return readdirSync4(join6(worktree, ...KIRO_STEERING)).filter((n) => n.endsWith(MD)).sort().map((n) => [...KIRO_STEERING, n]);
|
|
44227
44290
|
} catch {
|
|
44228
44291
|
return [];
|
|
44229
44292
|
}
|
|
@@ -44243,7 +44306,7 @@ function readAutoMemory(project) {
|
|
|
44243
44306
|
sourceId: null,
|
|
44244
44307
|
path: path8,
|
|
44245
44308
|
label: segs.join("/"),
|
|
44246
|
-
text:
|
|
44309
|
+
text: readFileSync4(path8, "utf8")
|
|
44247
44310
|
});
|
|
44248
44311
|
} catch {
|
|
44249
44312
|
}
|
|
@@ -44867,8 +44930,8 @@ var ctxBatch = Object.freeze({
|
|
|
44867
44930
|
});
|
|
44868
44931
|
|
|
44869
44932
|
// src/core/tools/doctor.ts
|
|
44870
|
-
import { readdirSync as
|
|
44871
|
-
import { basename as basename5, join as
|
|
44933
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync12, existsSync as existsSync17 } from "node:fs";
|
|
44934
|
+
import { basename as basename5, join as join17 } from "node:path";
|
|
44872
44935
|
|
|
44873
44936
|
// src/adapters/claude-code.ts
|
|
44874
44937
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -45897,15 +45960,15 @@ function getAdapter(id) {
|
|
|
45897
45960
|
}
|
|
45898
45961
|
|
|
45899
45962
|
// src/core/ops/bundle-dir.ts
|
|
45900
|
-
import { existsSync as
|
|
45963
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
45901
45964
|
import { dirname as dirname4, join as join7 } from "node:path";
|
|
45902
45965
|
import { fileURLToPath } from "node:url";
|
|
45903
45966
|
function bundleDirOf(argv1, moduleFile) {
|
|
45904
45967
|
const own4 = dirname4(argv1);
|
|
45905
|
-
if (
|
|
45968
|
+
if (existsSync5(join7(own4, SERVER_ENTRY_FILE))) return own4;
|
|
45906
45969
|
let dir = dirname4(moduleFile);
|
|
45907
45970
|
for (; ; ) {
|
|
45908
|
-
if (
|
|
45971
|
+
if (existsSync5(join7(dir, SERVER_ENTRY_FILE))) return dir;
|
|
45909
45972
|
const up = dirname4(dir);
|
|
45910
45973
|
if (up === dir) return own4;
|
|
45911
45974
|
dir = up;
|
|
@@ -45919,16 +45982,16 @@ function ownBundleDir() {
|
|
|
45919
45982
|
}
|
|
45920
45983
|
|
|
45921
45984
|
// src/core/ops/doctor-config.ts
|
|
45922
|
-
import { existsSync as
|
|
45985
|
+
import { existsSync as existsSync10, readdirSync as readdirSync7 } from "node:fs";
|
|
45923
45986
|
import { join as join11 } from "node:path";
|
|
45924
45987
|
|
|
45925
45988
|
// src/core/ops/detect-v1.ts
|
|
45926
|
-
import { existsSync as
|
|
45989
|
+
import { existsSync as existsSync7, opendirSync, readdirSync as readdirSync5, readFileSync as readFileSync6 } from "node:fs";
|
|
45927
45990
|
import { tmpdir } from "node:os";
|
|
45928
45991
|
import { join as join9 } from "node:path";
|
|
45929
45992
|
|
|
45930
45993
|
// src/core/ops/host-config.ts
|
|
45931
|
-
import { existsSync as
|
|
45994
|
+
import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
|
|
45932
45995
|
import { dirname as dirname5, join as join8 } from "node:path";
|
|
45933
45996
|
|
|
45934
45997
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
@@ -48070,9 +48133,9 @@ function readHostConfig(agent, path8) {
|
|
|
48070
48133
|
let file2 = path8;
|
|
48071
48134
|
if (agent === "opencode") {
|
|
48072
48135
|
const jsonc = join8(dirname5(path8), OPENCODE_CONFIG_FILES[0]);
|
|
48073
|
-
if (
|
|
48136
|
+
if (existsSync6(jsonc)) file2 = jsonc;
|
|
48074
48137
|
}
|
|
48075
|
-
const raw =
|
|
48138
|
+
const raw = existsSync6(file2) ? readFileSync5(file2, "utf8") : "";
|
|
48076
48139
|
return { agent, text: hostText(raw), format: agent === "opencode" && !file2.endsWith(TOML_EXT) ? "jsonc" : formatOf(file2), path: file2, layout: hostLayout(raw) };
|
|
48077
48140
|
}
|
|
48078
48141
|
function stripJsonComments(text) {
|
|
@@ -48544,14 +48607,14 @@ function stripJsonc(text) {
|
|
|
48544
48607
|
}
|
|
48545
48608
|
function readJson(file2) {
|
|
48546
48609
|
try {
|
|
48547
|
-
return JSON.parse(stripJsonc(hostText(
|
|
48610
|
+
return JSON.parse(stripJsonc(hostText(readFileSync6(file2, "utf8"))));
|
|
48548
48611
|
} catch {
|
|
48549
48612
|
return void 0;
|
|
48550
48613
|
}
|
|
48551
48614
|
}
|
|
48552
48615
|
function readText(file2) {
|
|
48553
48616
|
try {
|
|
48554
|
-
return hostText(
|
|
48617
|
+
return hostText(readFileSync6(file2, "utf8"));
|
|
48555
48618
|
} catch {
|
|
48556
48619
|
return "";
|
|
48557
48620
|
}
|
|
@@ -48608,7 +48671,7 @@ function flatCommands(events, prefix) {
|
|
|
48608
48671
|
var isV1Hook = (cmd) => cmd.includes(SERVER_KEY) && (V1_SCRIPT_NAMES.some((name) => cmd.includes(name)) || cmd.includes(V1_HOOK_COMMAND));
|
|
48609
48672
|
var isCodexScript = (cmd) => cmd.includes(V1_SCRIPT_EXT) && V1_PATH_SEPS.some((sep3) => cmd.includes(V1_CODEX_HOOKS_DIR.join(sep3) + sep3));
|
|
48610
48673
|
function dataDir(dir, reason, out) {
|
|
48611
|
-
if (
|
|
48674
|
+
if (existsSync7(dir)) out.push(finding(dir, "", reason));
|
|
48612
48675
|
}
|
|
48613
48676
|
function mcpEntry(file2, doc, out) {
|
|
48614
48677
|
if (isObj(doc) && isObj(doc[MCP_SERVERS_KEY]) && Object.hasOwn(doc[MCP_SERVERS_KEY], SERVER_KEY)) {
|
|
@@ -48637,7 +48700,7 @@ function scanClaudeCode(home, agentHome, out) {
|
|
|
48637
48700
|
claudeShapeSettings(agentHome, out);
|
|
48638
48701
|
for (const ext of V1_CACHE_HEAL_EXTS) {
|
|
48639
48702
|
const file2 = join9(agentHome, V1_HOOKS_DIR_NAME, V1_CACHE_HEAL_NAME + ext);
|
|
48640
|
-
if (
|
|
48703
|
+
if (existsSync7(file2)) out.push(finding(file2, "", V1_REASON.cacheHealFile));
|
|
48641
48704
|
}
|
|
48642
48705
|
const userFile = join9(home, CLAUDE_USER_CONFIG_FILE);
|
|
48643
48706
|
mcpEntry(userFile, readJson(userFile), out);
|
|
@@ -48655,6 +48718,7 @@ function scanCodex(agentHome, out) {
|
|
|
48655
48718
|
for (const span2 of readTomlTables(tomlFile)) {
|
|
48656
48719
|
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
48657
48720
|
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
48721
|
+
if (span2.path.length === 3 && span2.path[2] === MCP_ENV_FIELD && isV2McpTable(hostConfigValueAt(config4, span2.path.slice(0, 2)))) continue;
|
|
48658
48722
|
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
48659
48723
|
}
|
|
48660
48724
|
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
@@ -48683,7 +48747,7 @@ function scanVscode(agentHome, project, out) {
|
|
|
48683
48747
|
}
|
|
48684
48748
|
function jsonFiles(dir) {
|
|
48685
48749
|
try {
|
|
48686
|
-
return
|
|
48750
|
+
return readdirSync5(dir).filter((name) => name.endsWith(KIRO_AGENT_FILE_EXT)).sort();
|
|
48687
48751
|
} catch {
|
|
48688
48752
|
return [];
|
|
48689
48753
|
}
|
|
@@ -48706,7 +48770,7 @@ function scanKiro(agentHome, project, out) {
|
|
|
48706
48770
|
const steeringDocs = [join9(agentHome, ...KIRO_STEERING_FILE)];
|
|
48707
48771
|
if (project !== void 0) steeringDocs.push(join9(project, ...AGENT_HOME_DIR.kiro, ...KIRO_STEERING_FILE));
|
|
48708
48772
|
for (const file2 of steeringDocs) {
|
|
48709
|
-
if (
|
|
48773
|
+
if (existsSync7(file2)) out.push(finding(file2, "", V1_REASON.kiroSteering));
|
|
48710
48774
|
}
|
|
48711
48775
|
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48712
48776
|
}
|
|
@@ -48816,7 +48880,7 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48816
48880
|
}
|
|
48817
48881
|
|
|
48818
48882
|
// src/core/ops/plugin-root.ts
|
|
48819
|
-
import { existsSync as
|
|
48883
|
+
import { existsSync as existsSync8, readdirSync as readdirSync6, readFileSync as readFileSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
48820
48884
|
import { dirname as dirname6, isAbsolute, join as join10, sep as sep2 } from "node:path";
|
|
48821
48885
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
48822
48886
|
function missing(agent, path8) {
|
|
@@ -48858,7 +48922,7 @@ var realOrNull = (path8) => {
|
|
|
48858
48922
|
};
|
|
48859
48923
|
var readOrNull = (file2) => {
|
|
48860
48924
|
try {
|
|
48861
|
-
return
|
|
48925
|
+
return readFileSync7(file2, "utf8");
|
|
48862
48926
|
} catch {
|
|
48863
48927
|
return null;
|
|
48864
48928
|
}
|
|
@@ -48885,7 +48949,7 @@ function marketplaceChoice(env, worktree) {
|
|
|
48885
48949
|
const record6 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
48886
48950
|
const recorded = record6 === null ? [] : recordedInstalls(record6);
|
|
48887
48951
|
if (recorded.length === 0) return { record: false };
|
|
48888
|
-
const live = recorded.filter((r) =>
|
|
48952
|
+
const live = recorded.filter((r) => existsSync8(r.installPath));
|
|
48889
48953
|
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
48890
48954
|
if (mine !== void 0) return { root: mine.installPath };
|
|
48891
48955
|
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
@@ -48913,10 +48977,10 @@ function marketplaceRoot(adapter, env, worktree) {
|
|
|
48913
48977
|
if ("root" in choice) return choice.root;
|
|
48914
48978
|
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
48915
48979
|
const cacheReal = realOrNull(cache);
|
|
48916
|
-
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) &&
|
|
48980
|
+
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep2) && existsSync8(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
48917
48981
|
const pattern = join10(cache, "*", PLUGIN_NAME);
|
|
48918
|
-
if (!
|
|
48919
|
-
const found =
|
|
48982
|
+
if (!existsSync8(cache)) throw missing(adapter.id, pattern);
|
|
48983
|
+
const found = readdirSync6(cache).sort().map((marketplace) => join10(cache, marketplace, PLUGIN_NAME)).filter((dir) => existsSync8(dir));
|
|
48920
48984
|
if (found.length !== 1) throw missing(adapter.id, found.length === 0 ? pattern : found.join(", "));
|
|
48921
48985
|
return found[0];
|
|
48922
48986
|
}
|
|
@@ -48924,7 +48988,7 @@ function configEntryRoot(adapter, env) {
|
|
|
48924
48988
|
const spec = OWN_MCP_ENTRY[adapter.id];
|
|
48925
48989
|
if (spec === void 0) throw missing(adapter.id, SERVER_KEY);
|
|
48926
48990
|
const file2 = ownMcpFileOf(adapter.id, spec.file, env, requireHomeDir(env));
|
|
48927
|
-
if (!
|
|
48991
|
+
if (!existsSync8(file2)) throw missing(adapter.id, file2);
|
|
48928
48992
|
const current = readHostConfig(adapter.id, file2);
|
|
48929
48993
|
const value = parseHostConfig(adapter.id, file2, current.text, current.format);
|
|
48930
48994
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
@@ -48958,7 +49022,7 @@ function resolvePluginRoot(adapter, env, worktree) {
|
|
|
48958
49022
|
}
|
|
48959
49023
|
|
|
48960
49024
|
// src/setup/pi-gate.ts
|
|
48961
|
-
import { existsSync as
|
|
49025
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
48962
49026
|
import path4 from "node:path";
|
|
48963
49027
|
var EXTENSIONS_KEY = "extensions";
|
|
48964
49028
|
var PROJECT_DIR = ".pi";
|
|
@@ -48966,9 +49030,9 @@ var TRUST_FILE = "trust.json";
|
|
|
48966
49030
|
var ALWAYS = "always";
|
|
48967
49031
|
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
48968
49032
|
function load(file2) {
|
|
48969
|
-
if (!
|
|
49033
|
+
if (!existsSync9(file2)) return void 0;
|
|
48970
49034
|
try {
|
|
48971
|
-
return { file: file2, doc: parseHostConfig("pi", file2, hostText(
|
|
49035
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync8(file2, "utf8")), "json") };
|
|
48972
49036
|
} catch {
|
|
48973
49037
|
return void 0;
|
|
48974
49038
|
}
|
|
@@ -49126,14 +49190,14 @@ function codexNativeDir(env, home) {
|
|
|
49126
49190
|
}
|
|
49127
49191
|
if (enabled !== true) return null;
|
|
49128
49192
|
const cache = join11(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
49129
|
-
if (!
|
|
49193
|
+
if (!existsSync10(cache)) return null;
|
|
49130
49194
|
const found = [];
|
|
49131
|
-
for (const market of
|
|
49195
|
+
for (const market of readdirSync7(cache)) {
|
|
49132
49196
|
const plugin = join11(cache, market, SERVER_KEY);
|
|
49133
|
-
if (!
|
|
49134
|
-
for (const version4 of
|
|
49197
|
+
if (!existsSync10(plugin)) continue;
|
|
49198
|
+
for (const version4 of readdirSync7(plugin).sort()) {
|
|
49135
49199
|
const dir = join11(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
49136
|
-
if (
|
|
49200
|
+
if (existsSync10(join11(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
49137
49201
|
}
|
|
49138
49202
|
}
|
|
49139
49203
|
return found.length === 0 ? null : found[found.length - 1];
|
|
@@ -49296,7 +49360,7 @@ function configPaths(row5, env, worktree) {
|
|
|
49296
49360
|
}
|
|
49297
49361
|
|
|
49298
49362
|
// src/core/ops/doctor-db.ts
|
|
49299
|
-
import { existsSync as
|
|
49363
|
+
import { existsSync as existsSync11, statSync as statSync4 } from "node:fs";
|
|
49300
49364
|
var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
49301
49365
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
49302
49366
|
var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -49338,15 +49402,15 @@ function orphanFiles(dbPath) {
|
|
|
49338
49402
|
const files = [];
|
|
49339
49403
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
49340
49404
|
const path8 = dbPath + suffix;
|
|
49341
|
-
if (
|
|
49405
|
+
if (existsSync11(path8)) files.push({ path: path8, bytes: statSync4(path8).size });
|
|
49342
49406
|
}
|
|
49343
|
-
return files.length > 0 && !
|
|
49407
|
+
return files.length > 0 && !existsSync11(dbPath) ? files : [];
|
|
49344
49408
|
}
|
|
49345
49409
|
async function checkDb(project) {
|
|
49346
49410
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
49347
49411
|
const orphan = orphanFiles(project.dbPath);
|
|
49348
49412
|
if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
49349
|
-
if (!
|
|
49413
|
+
if (!existsSync11(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
49350
49414
|
const sqlite = await loadSqlite2();
|
|
49351
49415
|
if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
|
|
49352
49416
|
let raw = null;
|
|
@@ -49372,7 +49436,7 @@ async function checkDb(project) {
|
|
|
49372
49436
|
}
|
|
49373
49437
|
}
|
|
49374
49438
|
async function checkIndex(project) {
|
|
49375
|
-
if (!
|
|
49439
|
+
if (!existsSync11(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
49376
49440
|
const sqlite = await loadSqlite2();
|
|
49377
49441
|
if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
|
|
49378
49442
|
let raw = null;
|
|
@@ -49389,7 +49453,7 @@ async function checkIndex(project) {
|
|
|
49389
49453
|
}
|
|
49390
49454
|
|
|
49391
49455
|
// src/core/ops/doctor-env.ts
|
|
49392
|
-
import { existsSync as
|
|
49456
|
+
import { existsSync as existsSync12, readFileSync as readFileSync9, realpathSync as realpathSync6 } from "node:fs";
|
|
49393
49457
|
import { isAbsolute as isAbsolute2, join as join12, relative as relative2 } from "node:path";
|
|
49394
49458
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
49395
49459
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
@@ -49402,7 +49466,7 @@ function fail3(id, detail, fixCommand) {
|
|
|
49402
49466
|
}
|
|
49403
49467
|
function bundleVersion(bundleDir2) {
|
|
49404
49468
|
try {
|
|
49405
|
-
const v = JSON.parse(
|
|
49469
|
+
const v = JSON.parse(readFileSync9(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
49406
49470
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
49407
49471
|
} catch {
|
|
49408
49472
|
return void 0;
|
|
@@ -49552,7 +49616,7 @@ function checkMcp(ctx) {
|
|
|
49552
49616
|
return named2 || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
|
|
49553
49617
|
}
|
|
49554
49618
|
function piCwdInside(worktree, piCwd) {
|
|
49555
|
-
if (piCwd === void 0 || !
|
|
49619
|
+
if (piCwd === void 0 || !existsSync12(piCwd)) return false;
|
|
49556
49620
|
const rel = relative2(worktree, realpathSync6.native(piCwd));
|
|
49557
49621
|
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
49558
49622
|
}
|
|
@@ -49562,7 +49626,9 @@ function checkProject(i) {
|
|
|
49562
49626
|
if (i.adapter.projectSource === "pi:ctx.cwd" && !piCwdInside(i.project.worktree, i.piCwd)) return bad;
|
|
49563
49627
|
return pass3("D7");
|
|
49564
49628
|
}
|
|
49565
|
-
function checkMode(adapter) {
|
|
49629
|
+
function checkMode(adapter, hostPermission) {
|
|
49630
|
+
if (hostPermission === "missing") return fail3("D10", D10_PERMISSION_MISSING_DETAIL, D10_PERMISSION_FIX);
|
|
49631
|
+
if (hostPermission === "wired") return pass3("D10", D10_PERMISSION_DETAIL(adapter.denyChannel));
|
|
49566
49632
|
return pass3("D10", D10_DETAIL(adapter.denyChannel));
|
|
49567
49633
|
}
|
|
49568
49634
|
function checkShell(env) {
|
|
@@ -49573,7 +49639,7 @@ function checkShell(env) {
|
|
|
49573
49639
|
}
|
|
49574
49640
|
|
|
49575
49641
|
// src/core/ops/doctor-hook.ts
|
|
49576
|
-
import { existsSync as
|
|
49642
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync5, mkdtempSync, readFileSync as readFileSync10, realpathSync as realpathSync8, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49577
49643
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49578
49644
|
import path7 from "node:path";
|
|
49579
49645
|
|
|
@@ -51399,7 +51465,7 @@ function nodeLaunch(env, host = { bun: process.versions.bun, execPath: process.e
|
|
|
51399
51465
|
|
|
51400
51466
|
// src/setup/codex-trust.ts
|
|
51401
51467
|
import { createHash } from "node:crypto";
|
|
51402
|
-
import { existsSync as
|
|
51468
|
+
import { existsSync as existsSync13, realpathSync as realpathSync7 } from "node:fs";
|
|
51403
51469
|
import path6 from "node:path";
|
|
51404
51470
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
51405
51471
|
|
|
@@ -51622,10 +51688,10 @@ function isObject6(v) {
|
|
|
51622
51688
|
}
|
|
51623
51689
|
function loadFixture(bundleDir2, agent) {
|
|
51624
51690
|
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
51625
|
-
if (!
|
|
51691
|
+
if (!existsSync14(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
51626
51692
|
let all;
|
|
51627
51693
|
try {
|
|
51628
|
-
all = JSON.parse(hostText(
|
|
51694
|
+
all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
|
|
51629
51695
|
} catch (err) {
|
|
51630
51696
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
51631
51697
|
}
|
|
@@ -51738,6 +51804,35 @@ async function mediaProbe(i, timeoutMs) {
|
|
|
51738
51804
|
rmSync4(home, { recursive: true, force: true });
|
|
51739
51805
|
}
|
|
51740
51806
|
}
|
|
51807
|
+
async function ownProbe(i, timeoutMs) {
|
|
51808
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-own-"));
|
|
51809
|
+
try {
|
|
51810
|
+
const cfg = path7.join(home, ".claude");
|
|
51811
|
+
const refs = path7.join(cfg, "skills", "d5-probe", "references");
|
|
51812
|
+
mkdirSync5(refs, { recursive: true });
|
|
51813
|
+
const filePath = path7.join(refs, "d5-own-probe.md");
|
|
51814
|
+
writeFileSync3(filePath, "# d5 own probe\n".repeat(Math.ceil((OUTPUT_CAP + 1) / 15)));
|
|
51815
|
+
const node3 = nodeLaunch({ ...i.env, HOME: home, USERPROFILE: home, CLAUDE_CONFIG_DIR: cfg });
|
|
51816
|
+
const r = await runProcess([node3.file, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
51817
|
+
cwd: i.bundleDir,
|
|
51818
|
+
env: node3.env,
|
|
51819
|
+
signal: i.signal,
|
|
51820
|
+
timeoutMs,
|
|
51821
|
+
stdin: JSON.stringify({
|
|
51822
|
+
session_id: "d5-own-probe",
|
|
51823
|
+
transcript_path: "",
|
|
51824
|
+
cwd: home,
|
|
51825
|
+
hook_event_name: "PreToolUse",
|
|
51826
|
+
tool_name: "Read",
|
|
51827
|
+
tool_use_id: "toolu_d5_own_probe",
|
|
51828
|
+
tool_input: { file_path: filePath }
|
|
51829
|
+
})
|
|
51830
|
+
});
|
|
51831
|
+
return r.stdout.toString("utf8");
|
|
51832
|
+
} finally {
|
|
51833
|
+
rmSync4(home, { recursive: true, force: true });
|
|
51834
|
+
}
|
|
51835
|
+
}
|
|
51741
51836
|
function isDeny(stdout) {
|
|
51742
51837
|
if (stdout.trim() === "") return false;
|
|
51743
51838
|
let out;
|
|
@@ -51752,8 +51847,12 @@ async function readProbeDetail(i, timeoutMs) {
|
|
|
51752
51847
|
if (!isReadShape(await readProbe(i, timeoutMs, false))) return D5_READ_SHAPE_DETAIL;
|
|
51753
51848
|
if (!isPassThrough(await readProbe(i, timeoutMs, true))) return D5_READ_RANGE_DETAIL;
|
|
51754
51849
|
if (isDeny(await mediaProbe(i, timeoutMs))) return D5_READ_MEDIA_DETAIL;
|
|
51850
|
+
if (isDeny(await ownProbe(i, timeoutMs))) return D5_READ_OWN_DETAIL;
|
|
51755
51851
|
return null;
|
|
51756
51852
|
}
|
|
51853
|
+
async function mediaProbeDetail(i, timeoutMs) {
|
|
51854
|
+
return isDeny(await mediaProbe(i, timeoutMs)) ? D5_READ_MEDIA_DETAIL : null;
|
|
51855
|
+
}
|
|
51757
51856
|
function codexHookJournaled(db) {
|
|
51758
51857
|
if (db === null) return false;
|
|
51759
51858
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
@@ -51806,7 +51905,7 @@ async function codexStopDetail(i, timeoutMs) {
|
|
|
51806
51905
|
timeoutMs,
|
|
51807
51906
|
stdin: JSON.stringify(codexStopPayload(i.worktree ?? home))
|
|
51808
51907
|
});
|
|
51809
|
-
const logged =
|
|
51908
|
+
const logged = existsSync14(path7.join(home, HOOK_ERROR_LOG_FILE));
|
|
51810
51909
|
return !logged && isNativeShape(i.agent, r.stdout.toString("utf8"), r.exitCode, r.killed, "Stop") ? null : D5_STOP_DETAIL;
|
|
51811
51910
|
} finally {
|
|
51812
51911
|
rmSync4(home, { recursive: true, force: true });
|
|
@@ -51817,7 +51916,7 @@ async function checkHookRoundTrip(i) {
|
|
|
51817
51916
|
const trust = await codexPluginTrust(i);
|
|
51818
51917
|
if (trust !== null) return trust;
|
|
51819
51918
|
}
|
|
51820
|
-
if (i.agent === "codex" &&
|
|
51919
|
+
if (i.agent === "codex" && existsSync14(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
51821
51920
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
51822
51921
|
}
|
|
51823
51922
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -51853,18 +51952,21 @@ async function checkHookRoundTrip(i) {
|
|
|
51853
51952
|
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
51854
51953
|
}
|
|
51855
51954
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
51856
|
-
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
51955
|
+
const readDetail = i.agent === "claude-code" ? await readProbeDetail(i, timeoutMs) : i.agent === "zcode" ? await mediaProbeDetail(i, timeoutMs) : i.agent === "codex" ? await codexStopDetail(i, timeoutMs) : null;
|
|
51857
51956
|
if (readDetail !== null) return row("FAIL", readDetail, D5_FIX);
|
|
51858
51957
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
51859
51958
|
}
|
|
51860
51959
|
|
|
51861
51960
|
// src/core/hooks/fallback.ts
|
|
51862
|
-
import { join as
|
|
51961
|
+
import { join as join14, resolve as resolve4 } from "node:path";
|
|
51863
51962
|
|
|
51864
51963
|
// src/core/policy/read-media.ts
|
|
51865
51964
|
import { extname } from "node:path";
|
|
51866
51965
|
var { closeSync, openSync, readSync } = process.getBuiltinModule("node:fs");
|
|
51867
51966
|
|
|
51967
|
+
// src/core/policy/own-file.ts
|
|
51968
|
+
import { extname as extname2, join as join13 } from "node:path";
|
|
51969
|
+
|
|
51868
51970
|
// src/core/hooks/fallback.ts
|
|
51869
51971
|
var fs = process.getBuiltinModule("node:fs");
|
|
51870
51972
|
function homeOf(env) {
|
|
@@ -51872,9 +51974,9 @@ function homeOf(env) {
|
|
|
51872
51974
|
}
|
|
51873
51975
|
function hookLogPath(env) {
|
|
51874
51976
|
const dir = env[DATA_DIR_ENV];
|
|
51875
|
-
if (dir !== void 0 && dir !== "") return
|
|
51977
|
+
if (dir !== void 0 && dir !== "") return join14(dataRootOf(env, ""), HOOK_ERROR_LOG_FILE);
|
|
51876
51978
|
const home = homeOf(env);
|
|
51877
|
-
return home === "" ? "" :
|
|
51979
|
+
return home === "" ? "" : join14(dataRootOf(env, home), HOOK_ERROR_LOG_FILE);
|
|
51878
51980
|
}
|
|
51879
51981
|
function lastHookError(env) {
|
|
51880
51982
|
try {
|
|
@@ -51904,8 +52006,8 @@ function lastHookError(env) {
|
|
|
51904
52006
|
}
|
|
51905
52007
|
|
|
51906
52008
|
// src/core/ops/db-heal.ts
|
|
51907
|
-
import { existsSync as
|
|
51908
|
-
import { basename as basename4, dirname as dirname7, join as
|
|
52009
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync6, rmSync as rmSync5 } from "node:fs";
|
|
52010
|
+
import { basename as basename4, dirname as dirname7, join as join15 } from "node:path";
|
|
51909
52011
|
function integrityOk2(rows) {
|
|
51910
52012
|
return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
|
|
51911
52013
|
}
|
|
@@ -51939,7 +52041,7 @@ function renameAside(dbPath) {
|
|
|
51939
52041
|
const ts = String(Date.now());
|
|
51940
52042
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
51941
52043
|
const file2 = dbPath + suffix;
|
|
51942
|
-
if (
|
|
52044
|
+
if (existsSync15(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
51943
52045
|
}
|
|
51944
52046
|
return ts;
|
|
51945
52047
|
}
|
|
@@ -51962,11 +52064,11 @@ function utcStamp(now) {
|
|
|
51962
52064
|
return now.toISOString().slice(0, 19).replaceAll("-", "").replaceAll(":", "") + "Z";
|
|
51963
52065
|
}
|
|
51964
52066
|
function makeOrphanDir(projectDir) {
|
|
51965
|
-
const base =
|
|
52067
|
+
const base = join15(projectDir, ORPHAN_DIR_PREFIX + utcStamp(/* @__PURE__ */ new Date()));
|
|
51966
52068
|
for (let n = 1; ; n += 1) {
|
|
51967
52069
|
const dir = n === 1 ? base : base + "-" + String(n);
|
|
51968
52070
|
try {
|
|
51969
|
-
|
|
52071
|
+
mkdirSync6(dir);
|
|
51970
52072
|
return dir;
|
|
51971
52073
|
} catch (err) {
|
|
51972
52074
|
if (err.code !== "EEXIST") throw err;
|
|
@@ -51979,7 +52081,7 @@ async function healOrphan(project, files, row5) {
|
|
|
51979
52081
|
try {
|
|
51980
52082
|
dir = makeOrphanDir(dirname7(project.dbPath));
|
|
51981
52083
|
for (const f of files) {
|
|
51982
|
-
const to =
|
|
52084
|
+
const to = join15(dir, basename4(f.path));
|
|
51983
52085
|
renameWithRetry(f.path, to);
|
|
51984
52086
|
moved.push({ path: to, bytes: f.bytes });
|
|
51985
52087
|
}
|
|
@@ -52046,8 +52148,8 @@ function buildReportHead(input) {
|
|
|
52046
52148
|
|
|
52047
52149
|
// src/core/ops/doctor-issue.ts
|
|
52048
52150
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
52049
|
-
import { closeSync as closeSync2, existsSync as
|
|
52050
|
-
import { delimiter, join as
|
|
52151
|
+
import { closeSync as closeSync2, existsSync as existsSync16, fstatSync, mkdirSync as mkdirSync7, openSync as openSync2, readFileSync as readFileSync11, readSync as readSync2, realpathSync as realpathSync9, writeFileSync as writeFileSync4 } from "node:fs";
|
|
52152
|
+
import { delimiter, join as join16 } from "node:path";
|
|
52051
52153
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
52052
52154
|
function tildeOf(env) {
|
|
52053
52155
|
const home = homeDirOf(env);
|
|
@@ -52088,8 +52190,8 @@ function onPath(env, tool) {
|
|
|
52088
52190
|
const out = [];
|
|
52089
52191
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
52090
52192
|
if (dir === "") continue;
|
|
52091
|
-
for (const n of names) if (
|
|
52092
|
-
out.push(
|
|
52193
|
+
for (const n of names) if (existsSync16(join16(dir, n))) {
|
|
52194
|
+
out.push(join16(dir, n));
|
|
52093
52195
|
break;
|
|
52094
52196
|
}
|
|
52095
52197
|
}
|
|
@@ -52097,7 +52199,7 @@ function onPath(env, tool) {
|
|
|
52097
52199
|
}
|
|
52098
52200
|
function hookLogTail(env) {
|
|
52099
52201
|
const file2 = hookLogPath(env);
|
|
52100
|
-
if (file2 === "" || !
|
|
52202
|
+
if (file2 === "" || !existsSync16(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
52101
52203
|
try {
|
|
52102
52204
|
const fd = openSync2(file2, "r");
|
|
52103
52205
|
try {
|
|
@@ -52117,7 +52219,7 @@ function hookLogTail(env) {
|
|
|
52117
52219
|
}
|
|
52118
52220
|
async function journalRows(ctx) {
|
|
52119
52221
|
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
52120
|
-
if (!
|
|
52222
|
+
if (!existsSync16(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
52121
52223
|
try {
|
|
52122
52224
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
52123
52225
|
try {
|
|
@@ -52135,21 +52237,21 @@ function agentConfig(adapter, env, worktree) {
|
|
|
52135
52237
|
const home = homeDirOf(env);
|
|
52136
52238
|
const files = configPaths(adapter, env, worktree);
|
|
52137
52239
|
if (home !== null) {
|
|
52138
|
-
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path:
|
|
52139
|
-
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path:
|
|
52240
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join16(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
52241
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join16(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
52140
52242
|
}
|
|
52141
52243
|
const out = [];
|
|
52142
52244
|
const seen = /* @__PURE__ */ new Set();
|
|
52143
52245
|
for (const f of files) {
|
|
52144
52246
|
if (seen.has(f.path)) continue;
|
|
52145
52247
|
seen.add(f.path);
|
|
52146
|
-
if (!
|
|
52248
|
+
if (!existsSync16(f.path)) {
|
|
52147
52249
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
52148
52250
|
continue;
|
|
52149
52251
|
}
|
|
52150
52252
|
let text = "";
|
|
52151
52253
|
try {
|
|
52152
|
-
text =
|
|
52254
|
+
text = readFileSync11(f.path, "utf8");
|
|
52153
52255
|
} catch (err) {
|
|
52154
52256
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
52155
52257
|
continue;
|
|
@@ -52219,9 +52321,9 @@ async function buildIssueBody(i) {
|
|
|
52219
52321
|
async function writeIssueReport(i) {
|
|
52220
52322
|
const tilde = tildeOf(i.env);
|
|
52221
52323
|
const body = await buildIssueBody(i);
|
|
52222
|
-
const dir =
|
|
52223
|
-
|
|
52224
|
-
const file2 =
|
|
52324
|
+
const dir = join16(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
52325
|
+
mkdirSync7(dir, { recursive: true });
|
|
52326
|
+
const file2 = join16(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
52225
52327
|
writeFileSync4(file2, body);
|
|
52226
52328
|
const shown2 = tilde(file2);
|
|
52227
52329
|
const title = issueTitle(i.adapter.id, i.rows);
|
|
@@ -52267,7 +52369,7 @@ async function guard(id, run) {
|
|
|
52267
52369
|
}
|
|
52268
52370
|
}
|
|
52269
52371
|
async function codexDb(ctx, adapter) {
|
|
52270
|
-
if (adapter.id !== "codex" || !
|
|
52372
|
+
if (adapter.id !== "codex" || !existsSync17(ctx.project.dbPath)) return null;
|
|
52271
52373
|
try {
|
|
52272
52374
|
return await openDb(ctx.project, { readOnly: true });
|
|
52273
52375
|
} catch {
|
|
@@ -52297,11 +52399,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
52297
52399
|
}
|
|
52298
52400
|
}
|
|
52299
52401
|
function ownServerId(configDir, projectKey) {
|
|
52300
|
-
const dir =
|
|
52301
|
-
if (!
|
|
52302
|
-
for (const name of
|
|
52402
|
+
const dir = join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
52403
|
+
if (!existsSync17(dir)) return "";
|
|
52404
|
+
for (const name of readdirSync8(dir)) {
|
|
52303
52405
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
52304
|
-
if (
|
|
52406
|
+
if (readFileSync12(join17(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
52305
52407
|
}
|
|
52306
52408
|
return "";
|
|
52307
52409
|
}
|
|
@@ -52327,7 +52429,8 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
52327
52429
|
return r.row;
|
|
52328
52430
|
},
|
|
52329
52431
|
D9: () => checkIndex(project),
|
|
52330
|
-
D10: () => checkMode(adapter),
|
|
52432
|
+
D10: () => checkMode(adapter, ctx.hostPermission),
|
|
52433
|
+
// D-1331-OC-PERM-1
|
|
52331
52434
|
D11: () => checkShell(env)
|
|
52332
52435
|
};
|
|
52333
52436
|
const rows = [];
|
|
@@ -52396,9 +52499,9 @@ var ctxDoctor = Object.freeze({
|
|
|
52396
52499
|
});
|
|
52397
52500
|
|
|
52398
52501
|
// src/core/tools/execute.ts
|
|
52399
|
-
import { existsSync as
|
|
52502
|
+
import { existsSync as existsSync18, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
52400
52503
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
52401
|
-
import { dirname as dirname9, join as
|
|
52504
|
+
import { dirname as dirname9, join as join18, parse as parse5, resolve as resolve5 } from "node:path";
|
|
52402
52505
|
|
|
52403
52506
|
// src/core/index/select.ts
|
|
52404
52507
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -52520,7 +52623,7 @@ function schemaLine(issue4) {
|
|
|
52520
52623
|
}
|
|
52521
52624
|
function fileError(given, abs, root) {
|
|
52522
52625
|
let dir = abs;
|
|
52523
|
-
while (!
|
|
52626
|
+
while (!existsSync18(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
52524
52627
|
if (isInside(root, dir)) return null;
|
|
52525
52628
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
52526
52629
|
}
|
|
@@ -52601,8 +52704,8 @@ async function handler3(raw, ctx) {
|
|
|
52601
52704
|
if (takesDashC(input.language, runtime)) {
|
|
52602
52705
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
52603
52706
|
} else {
|
|
52604
|
-
tmpDir = mkdtempSync2(
|
|
52605
|
-
const file2 =
|
|
52707
|
+
tmpDir = mkdtempSync2(join18(tmpdir3(), TMP_PREFIX));
|
|
52708
|
+
const file2 = join18(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
52606
52709
|
writeFileSync5(file2, scriptText(input.language, input.code), "utf8");
|
|
52607
52710
|
argv = scriptArgv(input.language, runtime, file2);
|
|
52608
52711
|
}
|
|
@@ -52638,12 +52741,12 @@ var ctxExecute = {
|
|
|
52638
52741
|
};
|
|
52639
52742
|
|
|
52640
52743
|
// src/core/tools/index.ts
|
|
52641
|
-
import { existsSync as
|
|
52642
|
-
import { dirname as dirname10, extname as
|
|
52744
|
+
import { existsSync as existsSync19, readFileSync as readFileSync14, statSync as statSync7 } from "node:fs";
|
|
52745
|
+
import { dirname as dirname10, extname as extname3, join as join20, relative as relative3, resolve as resolve6 } from "node:path";
|
|
52643
52746
|
|
|
52644
52747
|
// src/core/index/walk.ts
|
|
52645
|
-
import { readdirSync as
|
|
52646
|
-
import { join as
|
|
52748
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync13, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
|
|
52749
|
+
import { join as join19 } from "node:path";
|
|
52647
52750
|
var GITIGNORE = ".gitignore";
|
|
52648
52751
|
var GIT_DIR = ".git";
|
|
52649
52752
|
function walkDir(root, containmentRoot) {
|
|
@@ -52652,19 +52755,19 @@ function walkDir(root, containmentRoot) {
|
|
|
52652
52755
|
const found = [];
|
|
52653
52756
|
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
52654
52757
|
found.sort(compareFound);
|
|
52655
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
52758
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join19(...f.dir, f.name) }));
|
|
52656
52759
|
}
|
|
52657
52760
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
52658
52761
|
let entries;
|
|
52659
52762
|
try {
|
|
52660
|
-
entries =
|
|
52763
|
+
entries = readdirSync9(abs, { withFileTypes: true });
|
|
52661
52764
|
} catch {
|
|
52662
52765
|
return;
|
|
52663
52766
|
}
|
|
52664
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
52767
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join19(abs, GITIGNORE), rel)) : parent;
|
|
52665
52768
|
for (const e of entries) {
|
|
52666
52769
|
if (e.name === GIT_DIR) continue;
|
|
52667
|
-
const path8 =
|
|
52770
|
+
const path8 = join19(abs, e.name);
|
|
52668
52771
|
let isDir = e.isDirectory();
|
|
52669
52772
|
let isFile = e.isFile();
|
|
52670
52773
|
let target = path8;
|
|
@@ -52704,7 +52807,7 @@ function compareFound(a, b) {
|
|
|
52704
52807
|
function readRules(file2, base) {
|
|
52705
52808
|
let body;
|
|
52706
52809
|
try {
|
|
52707
|
-
body =
|
|
52810
|
+
body = readFileSync13(file2, "utf8");
|
|
52708
52811
|
} catch {
|
|
52709
52812
|
return [];
|
|
52710
52813
|
}
|
|
@@ -56823,7 +56926,7 @@ function userLabel(label2) {
|
|
|
56823
56926
|
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
56824
56927
|
}
|
|
56825
56928
|
function kindOfPath(p) {
|
|
56826
|
-
return EXT_KIND[
|
|
56929
|
+
return EXT_KIND[extname3(p).toLowerCase()] ?? "text";
|
|
56827
56930
|
}
|
|
56828
56931
|
function kindOfType(contentType) {
|
|
56829
56932
|
const semi = contentType.indexOf(";");
|
|
@@ -56832,14 +56935,14 @@ function kindOfType(contentType) {
|
|
|
56832
56935
|
}
|
|
56833
56936
|
function readUtf8(absPath) {
|
|
56834
56937
|
try {
|
|
56835
|
-
return utf8.decode(
|
|
56938
|
+
return utf8.decode(readFileSync14(absPath));
|
|
56836
56939
|
} catch {
|
|
56837
56940
|
return void 0;
|
|
56838
56941
|
}
|
|
56839
56942
|
}
|
|
56840
56943
|
function missingOrOutside(given, abs, root) {
|
|
56841
56944
|
let dir = abs;
|
|
56842
|
-
while (!
|
|
56945
|
+
while (!existsSync19(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
56843
56946
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
56844
56947
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
56845
56948
|
}
|
|
@@ -56850,7 +56953,7 @@ function pathItems(input, project) {
|
|
|
56850
56953
|
if (statSync7(abs).isDirectory()) {
|
|
56851
56954
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
56852
56955
|
sourceKind: "path",
|
|
56853
|
-
label: pathLabel(
|
|
56956
|
+
label: pathLabel(join20(base, f.relPath)),
|
|
56854
56957
|
kind: kindOfPath(f.relPath),
|
|
56855
56958
|
read: () => readUtf8(f.absPath)
|
|
56856
56959
|
}));
|
|
@@ -57264,11 +57367,6 @@ function readLastPrompt(db, sessionId) {
|
|
|
57264
57367
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
57265
57368
|
return row5 === void 0 ? "" : row5.body;
|
|
57266
57369
|
}
|
|
57267
|
-
function readFirstPrompt(db, sessionId) {
|
|
57268
|
-
if (sessionId === "") return "";
|
|
57269
|
-
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq ASC LIMIT 1").get(sessionId);
|
|
57270
|
-
return row5 === void 0 ? "" : row5.body;
|
|
57271
|
-
}
|
|
57272
57370
|
|
|
57273
57371
|
// src/core/tools/resume.ts
|
|
57274
57372
|
var ctxResumeSchema = external_exports.object({
|
|
@@ -57294,9 +57392,8 @@ async function handler6(input, ctx) {
|
|
|
57294
57392
|
const newest = rows.at(-1);
|
|
57295
57393
|
if (newest === void 0) return reply3(RESUME_EMPTY_LINE, false);
|
|
57296
57394
|
const sources = listSessionSources(db, sessionId, MAX_CANDIDATES).map((r) => "source " + sourceHandle(r.id) + ": " + r.label + " (" + r.bytes + " B)");
|
|
57297
|
-
const goal = readFirstPrompt(db, sessionId);
|
|
57298
57395
|
const last2 = readLastPrompt(db, sessionId);
|
|
57299
|
-
const units = queryUnits(db, sessionId, recallQueryText(last2
|
|
57396
|
+
const units = queryUnits(db, sessionId, recallQueryText(last2), RECALL_UNIT_CANDIDATES).map((u) => ({ ...u, label: sourceHandle(u.sourceId) }));
|
|
57300
57397
|
const block = renderState(rows, newest.turn, { sources, units });
|
|
57301
57398
|
if (Buffer.byteLength(block, "utf8") > RESUME_CAP) throw new Error("ctx_resume: state block over RESUME_CAP (render bug).");
|
|
57302
57399
|
return reply3(block, false);
|
|
@@ -57655,8 +57752,8 @@ var ctxStats = Object.freeze({
|
|
|
57655
57752
|
});
|
|
57656
57753
|
|
|
57657
57754
|
// src/core/ops/host-write.ts
|
|
57658
|
-
import { copyFileSync, existsSync as
|
|
57659
|
-
import { dirname as dirname11, join as
|
|
57755
|
+
import { copyFileSync, existsSync as existsSync20, mkdirSync as mkdirSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
57756
|
+
import { dirname as dirname11, join as join21 } from "node:path";
|
|
57660
57757
|
function defaultWrite(file2, text) {
|
|
57661
57758
|
writeFileSync6(file2, text, "utf8");
|
|
57662
57759
|
}
|
|
@@ -57665,17 +57762,17 @@ function hostConfigPath(agent, home, env) {
|
|
|
57665
57762
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
57666
57763
|
switch (agent) {
|
|
57667
57764
|
case "opencode":
|
|
57668
|
-
return
|
|
57765
|
+
return join21(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
57669
57766
|
// D-WIN-OPENCODE-DIR-1
|
|
57670
57767
|
case "pi":
|
|
57671
|
-
return
|
|
57768
|
+
return join21(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
57672
57769
|
case "gemini":
|
|
57673
|
-
return
|
|
57770
|
+
return join21(geminiDirOf(env, home), SETTINGS_FILE);
|
|
57674
57771
|
// D-R38-GEMINI-HOME-1
|
|
57675
57772
|
case "copilot-cli":
|
|
57676
57773
|
return null;
|
|
57677
57774
|
default:
|
|
57678
|
-
return
|
|
57775
|
+
return join21(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
57679
57776
|
}
|
|
57680
57777
|
}
|
|
57681
57778
|
function cell3(value) {
|
|
@@ -57687,8 +57784,8 @@ function toRow(file2, edit) {
|
|
|
57687
57784
|
function writeWithRollback(file2, text, write, atomic) {
|
|
57688
57785
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
57689
57786
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
57690
|
-
const had =
|
|
57691
|
-
|
|
57787
|
+
const had = existsSync20(file2);
|
|
57788
|
+
mkdirSync8(dirname11(file2), { recursive: true });
|
|
57692
57789
|
if (had) copyFileSync(file2, trash);
|
|
57693
57790
|
try {
|
|
57694
57791
|
write(tmp, text);
|
|
@@ -57717,7 +57814,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
57717
57814
|
if (requested === null) return [];
|
|
57718
57815
|
const current = readHostConfig(row5.id, requested);
|
|
57719
57816
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
57720
|
-
const exists =
|
|
57817
|
+
const exists = existsSync20(current.path);
|
|
57721
57818
|
if (exists && result.text === current.text) return [];
|
|
57722
57819
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
57723
57820
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -57725,15 +57822,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
57725
57822
|
}
|
|
57726
57823
|
|
|
57727
57824
|
// src/core/ops/uninstall.ts
|
|
57728
|
-
import { existsSync as
|
|
57729
|
-
import { join as
|
|
57825
|
+
import { existsSync as existsSync21, readdirSync as readdirSync10, rmSync as rmSync7, writeFileSync as writeFileSync7 } from "node:fs";
|
|
57826
|
+
import { join as join22 } from "node:path";
|
|
57730
57827
|
function row2(area, before, after) {
|
|
57731
57828
|
return { area, before, after };
|
|
57732
57829
|
}
|
|
57733
57830
|
function stopServers(configDir, projectKey) {
|
|
57734
57831
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
57735
|
-
const dir =
|
|
57736
|
-
for (const serverId of stopped) writeFileSync7(
|
|
57832
|
+
const dir = join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
57833
|
+
for (const serverId of stopped) writeFileSync7(join22(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
57737
57834
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
57738
57835
|
}
|
|
57739
57836
|
function rootOrNull(adapter, env) {
|
|
@@ -57751,15 +57848,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
57751
57848
|
const root = rootOrNull(adapter, env);
|
|
57752
57849
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
57753
57850
|
if (adapter.installMode === "marketplace") {
|
|
57754
|
-
const cache =
|
|
57851
|
+
const cache = join22(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
57755
57852
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
57756
57853
|
}
|
|
57757
57854
|
rmSync7(root, { recursive: true, force: true });
|
|
57758
57855
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
57759
57856
|
}
|
|
57760
57857
|
case "plugin": {
|
|
57761
|
-
const agentDir =
|
|
57762
|
-
if (!
|
|
57858
|
+
const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
57859
|
+
if (!existsSync21(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
57763
57860
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
57764
57861
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
57765
57862
|
}
|
|
@@ -57804,7 +57901,7 @@ function ownEntries2(agent, env) {
|
|
|
57804
57901
|
}
|
|
57805
57902
|
if (agent === "opencode") {
|
|
57806
57903
|
return [{
|
|
57807
|
-
file:
|
|
57904
|
+
file: join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
57808
57905
|
// D-WIN-OPENCODE-DIR-1
|
|
57809
57906
|
key: OPENCODE_PLUGIN_KEY,
|
|
57810
57907
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -57815,7 +57912,7 @@ function ownEntries2(agent, env) {
|
|
|
57815
57912
|
if (agent === "pi") {
|
|
57816
57913
|
const agentDir = piAgentDirOf(env, home);
|
|
57817
57914
|
return [{
|
|
57818
|
-
file:
|
|
57915
|
+
file: join22(agentDir, SETTINGS_FILE),
|
|
57819
57916
|
key: PI_PACKAGES_KEY,
|
|
57820
57917
|
shown: PI_PACKAGES_KEY,
|
|
57821
57918
|
has: (v) => Array.isArray(v) && v.some((x) => piSource2(x) === PI_GIT_PACKAGE),
|
|
@@ -57837,12 +57934,12 @@ function removeOwnEntries(agent, env) {
|
|
|
57837
57934
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
57838
57935
|
}
|
|
57839
57936
|
function removeProjectData(configDir, projectKey) {
|
|
57840
|
-
const projects =
|
|
57841
|
-
const dir =
|
|
57842
|
-
if (!
|
|
57937
|
+
const projects = join22(configDir, PROJECTS_DIR_NAME);
|
|
57938
|
+
const dir = join22(projects, projectKey);
|
|
57939
|
+
if (!existsSync21(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
57843
57940
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
57844
|
-
for (const name of
|
|
57845
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
57941
|
+
for (const name of readdirSync10(dir)) {
|
|
57942
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join22(dir, name), { recursive: true, force: true });
|
|
57846
57943
|
}
|
|
57847
57944
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
57848
57945
|
}
|
|
@@ -57850,12 +57947,12 @@ function runUninstall(input) {
|
|
|
57850
57947
|
const configDir = resolveConfigDir(input.env);
|
|
57851
57948
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
57852
57949
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
57853
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
57950
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join22(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
57854
57951
|
return { rows, stopped: stop.stopped };
|
|
57855
57952
|
}
|
|
57856
57953
|
|
|
57857
57954
|
// src/core/ops/v1-remove.ts
|
|
57858
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
57955
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync22, readFileSync as readFileSync15, rmSync as rmSync8 } from "node:fs";
|
|
57859
57956
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
57860
57957
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
57861
57958
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -57867,7 +57964,7 @@ function moveAside(target, undo) {
|
|
|
57867
57964
|
}
|
|
57868
57965
|
function keepAside(target, undo) {
|
|
57869
57966
|
let aside = target + UPGRADE_ASIDE_SUFFIX;
|
|
57870
|
-
for (let n = 2;
|
|
57967
|
+
for (let n = 2; existsSync22(aside); n += 1) aside = target + UPGRADE_ASIDE_SUFFIX + "-" + n;
|
|
57871
57968
|
renameWithRetry(target, aside);
|
|
57872
57969
|
undo.push({ trash: aside, target, keep: true });
|
|
57873
57970
|
return aside;
|
|
@@ -57906,8 +58003,8 @@ function locate(doc, path8) {
|
|
|
57906
58003
|
return null;
|
|
57907
58004
|
}
|
|
57908
58005
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
57909
|
-
const layout = hostLayout(
|
|
57910
|
-
const text = hostText(
|
|
58006
|
+
const layout = hostLayout(readFileSync15(file2, "utf8"));
|
|
58007
|
+
const text = hostText(readFileSync15(file2, "utf8"));
|
|
57911
58008
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
57912
58009
|
const hit = /* @__PURE__ */ new Set();
|
|
57913
58010
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -57944,20 +58041,20 @@ function removeV1(agent, findings, project) {
|
|
|
57944
58041
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
57945
58042
|
else if (f.path === "") {
|
|
57946
58043
|
if (project !== void 0 && reachedThroughLink(project, f.file)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
57947
|
-
else if (
|
|
57948
|
-
else if (
|
|
58044
|
+
else if (existsSync22(f.file) && UPGRADE_KEEP_ASIDE_REASONS.includes(f.reason)) done.set(f, UPGRADE_MOVED_ASIDE + keepAside(f.file, undo));
|
|
58045
|
+
else if (existsSync22(f.file)) {
|
|
57949
58046
|
moveAside(f.file, undo);
|
|
57950
58047
|
done.set(f, UPGRADE_REMOVED);
|
|
57951
58048
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
57952
58049
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
57953
58050
|
}
|
|
57954
58051
|
for (const [file2, list3] of entries) {
|
|
57955
|
-
if (!
|
|
58052
|
+
if (!existsSync22(file2)) {
|
|
57956
58053
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
57957
58054
|
continue;
|
|
57958
58055
|
}
|
|
57959
58056
|
if (file2.endsWith(TOML_EXT)) {
|
|
57960
|
-
const rawToml =
|
|
58057
|
+
const rawToml = readFileSync15(file2, "utf8");
|
|
57961
58058
|
const tomlLayout = hostLayout(rawToml);
|
|
57962
58059
|
let text = hostText(rawToml);
|
|
57963
58060
|
for (const f of list3) {
|
|
@@ -57985,7 +58082,7 @@ function removeV1(agent, findings, project) {
|
|
|
57985
58082
|
},
|
|
57986
58083
|
rollback() {
|
|
57987
58084
|
for (const u of undo.splice(0).reverse()) {
|
|
57988
|
-
if (!
|
|
58085
|
+
if (!existsSync22(u.trash)) continue;
|
|
57989
58086
|
rmSync8(u.target, { recursive: true, force: true });
|
|
57990
58087
|
renameWithRetry(u.trash, u.target);
|
|
57991
58088
|
}
|
|
@@ -58261,15 +58358,15 @@ async function startServer(argv, env) {
|
|
|
58261
58358
|
opening.catch(() => pending.delete(project.dbPath));
|
|
58262
58359
|
}
|
|
58263
58360
|
const db = await opening;
|
|
58264
|
-
if (!
|
|
58361
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
58265
58362
|
return db;
|
|
58266
58363
|
}
|
|
58267
58364
|
function stopMarker(configDir, projectKey) {
|
|
58268
|
-
return
|
|
58365
|
+
return join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
58269
58366
|
}
|
|
58270
58367
|
function stopRequested() {
|
|
58271
58368
|
const configDir = resolveConfigDir(process.env);
|
|
58272
|
-
return held.some((db) =>
|
|
58369
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
58273
58370
|
}
|
|
58274
58371
|
async function journal(project, ctx, name, reply4) {
|
|
58275
58372
|
const db = await ownDb(project);
|