context-mode 2.0.0-next.23 → 2.0.0-next.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +138 -134
- package/SHA256SUMS +15 -15
- package/cli.mjs +72 -31
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +63 -61
- package/opencode/plugin.js +662 -282
- package/package.json +1 -1
- package/pi/index.js +740 -360
- package/qwen-extension.json +1 -1
- package/run.mjs +30 -24
- package/search.mjs +30 -24
- package/server.mjs +695 -332
package/opencode/plugin.js
CHANGED
|
@@ -15,6 +15,7 @@ function prefixToolNames(text, prefix) {
|
|
|
15
15
|
return out;
|
|
16
16
|
}
|
|
17
17
|
var OUTPUT_CAP = 16384;
|
|
18
|
+
var EXEC_PREVIEW_BYTES = 4096;
|
|
18
19
|
var STATE_BUDGET = 2048;
|
|
19
20
|
var RESUME_CAP = 2048;
|
|
20
21
|
var REPORT_CAP = 4096;
|
|
@@ -188,7 +189,7 @@ var HOOK_P95_MS = 40;
|
|
|
188
189
|
var HOOK_TIMEOUT_MS = 5e3;
|
|
189
190
|
var IN_PROCESS_TIMEOUT_MS = 0;
|
|
190
191
|
var PROJECT_KEY_HEX_LEN = 16;
|
|
191
|
-
var SCHEMA_VERSION =
|
|
192
|
+
var SCHEMA_VERSION = 6;
|
|
192
193
|
var RETENTION_SIZE_CAP_BYTES = 524288e3;
|
|
193
194
|
var PROJECTS_DIR_NAME = "projects";
|
|
194
195
|
var DB_FILE_NAME = "context.db";
|
|
@@ -219,6 +220,13 @@ var HOST_PLUGINS_DIR_NAME = "plugins";
|
|
|
219
220
|
var INSTALLED_PLUGINS_FILE = "installed_plugins.json";
|
|
220
221
|
var PLUGIN_AGENT_SEPARATOR = ":";
|
|
221
222
|
var PLUGIN_KEY_SEPARATOR = "@";
|
|
223
|
+
var CLAUDE_PLUGIN_ROOT_ENV = "CLAUDE_PLUGIN_ROOT";
|
|
224
|
+
var CLAUDE_PROJECT_DIR_ENV = "CLAUDE_PROJECT_DIR";
|
|
225
|
+
var ENABLED_PLUGINS_KEY = "enabledPlugins";
|
|
226
|
+
var SETTINGS_LOCAL_FILE = "settings.local.json";
|
|
227
|
+
var DEFAULT_PLUGIN_SCOPE = "user";
|
|
228
|
+
var PROJECT_PLUGIN_SCOPES = Object.freeze(["local", "project"]);
|
|
229
|
+
var PLUGIN_SCOPE_RANK = Object.freeze({ local: 0, project: 1, user: 2, managed: 2 });
|
|
222
230
|
var FRONTMATTER_FENCE = "---";
|
|
223
231
|
var FRONTMATTER_TOOLS_KEY = "tools";
|
|
224
232
|
var FRONTMATTER_DISALLOWED_KEY = "disallowedTools";
|
|
@@ -362,7 +370,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
362
370
|
var DECISION_LABEL_JOIN = " | ";
|
|
363
371
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
364
372
|
var RELEASE_BRANCH = "release";
|
|
365
|
-
var BUNDLE_SHA = true ? "
|
|
373
|
+
var BUNDLE_SHA = true ? "58d6b744f8c640e9f43f03516d8bc50dc1292ae0" : void 0;
|
|
366
374
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
367
375
|
var DOCTOR_LABEL = Object.freeze({
|
|
368
376
|
D1: "version",
|
|
@@ -518,6 +526,13 @@ var D3_PART_JOIN = ", ";
|
|
|
518
526
|
function D3_DETAIL(parts) {
|
|
519
527
|
return `wrong: ${parts.join(D3_PART_JOIN)}`;
|
|
520
528
|
}
|
|
529
|
+
function D3_ROOT_DETAIL(paths) {
|
|
530
|
+
return `pick one install for this project: ${paths.join(D3_PART_JOIN)}`;
|
|
531
|
+
}
|
|
532
|
+
var D3_ROOT_FIX_JOIN = " or ";
|
|
533
|
+
function D3_ROOT_FIX(installs) {
|
|
534
|
+
return `remove the extra install: ${installs.map((i) => `claude plugin uninstall ${i.key} --scope ${i.scope}`).join(D3_ROOT_FIX_JOIN)}`;
|
|
535
|
+
}
|
|
521
536
|
var HOOK_HOST_FILE = Object.freeze({
|
|
522
537
|
"claude-code": { root: "plugin", file: ["hooks", "claude-code.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
|
|
523
538
|
codex: { root: "home", file: [".codex", "hooks.json"], key: ["hooks"], shape: "nested", timeoutKey: "timeout", matcher: true },
|
|
@@ -789,7 +804,7 @@ var CtxError = class extends Error {
|
|
|
789
804
|
};
|
|
790
805
|
|
|
791
806
|
// src/core/hooks/dispatch.ts
|
|
792
|
-
import { dirname as
|
|
807
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
793
808
|
|
|
794
809
|
// src/core/contracts/agents.ts
|
|
795
810
|
var AGENT_IDS = ["claude-code", "codex", "gemini", "qwen", "copilot-cli", "vscode", "kiro", "zcode", "pi", "opencode"];
|
|
@@ -1689,7 +1704,7 @@ function getAdapter(id2) {
|
|
|
1689
1704
|
}
|
|
1690
1705
|
|
|
1691
1706
|
// src/core/policy/decide.ts
|
|
1692
|
-
import { resolve as
|
|
1707
|
+
import { resolve as resolve3 } from "node:path";
|
|
1693
1708
|
|
|
1694
1709
|
// src/core/policy/lexer.ts
|
|
1695
1710
|
var OPS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")"];
|
|
@@ -2994,7 +3009,7 @@ function withLayout(text, layout) {
|
|
|
2994
3009
|
}
|
|
2995
3010
|
|
|
2996
3011
|
// src/core/project/config-dir.ts
|
|
2997
|
-
import { join, posix, win32 } from "node:path";
|
|
3012
|
+
import { basename, dirname, join, posix, resolve as resolve2, win32 } from "node:path";
|
|
2998
3013
|
var { mkdirSync, realpathSync } = process.getBuiltinModule("node:fs");
|
|
2999
3014
|
function homeDirOf(env, platform = process.platform) {
|
|
3000
3015
|
const set3 = (v) => v !== void 0 && v !== "";
|
|
@@ -3010,6 +3025,20 @@ function codexDirOf(env, home) {
|
|
|
3010
3025
|
const dir = env[CODEX_HOME_ENV];
|
|
3011
3026
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR.codex);
|
|
3012
3027
|
}
|
|
3028
|
+
function codexPluginHomeOf(bundleDir2) {
|
|
3029
|
+
let dir = resolve2(bundleDir2);
|
|
3030
|
+
while (dirname(dir) !== dir) {
|
|
3031
|
+
const up = dirname(dir);
|
|
3032
|
+
if (basename(dir) === PLUGIN_CACHE_DIR_NAME && basename(up) === HOST_PLUGINS_DIR_NAME) return dirname(up);
|
|
3033
|
+
dir = up;
|
|
3034
|
+
}
|
|
3035
|
+
return null;
|
|
3036
|
+
}
|
|
3037
|
+
function codexRunDirOf(env, home, bundleDir2) {
|
|
3038
|
+
const dir = env[CODEX_HOME_ENV];
|
|
3039
|
+
if (dir !== void 0 && dir !== "") return dir;
|
|
3040
|
+
return codexPluginHomeOf(bundleDir2) ?? codexDirOf(env, home);
|
|
3041
|
+
}
|
|
3013
3042
|
function copilotDirOf(env, home) {
|
|
3014
3043
|
const dir = env[COPILOT_HOME_ENV];
|
|
3015
3044
|
return dir !== void 0 && dir !== "" ? dir : join(home, ...AGENT_HOME_DIR["copilot-cli"]);
|
|
@@ -3145,10 +3174,10 @@ function readPluginAgent(claudeDir, type) {
|
|
|
3145
3174
|
}
|
|
3146
3175
|
return null;
|
|
3147
3176
|
}
|
|
3148
|
-
function readAgentFile(
|
|
3177
|
+
function readAgentFile(path7) {
|
|
3149
3178
|
let text;
|
|
3150
3179
|
try {
|
|
3151
|
-
text = readFileSync(
|
|
3180
|
+
text = readFileSync(path7, "utf8");
|
|
3152
3181
|
} catch {
|
|
3153
3182
|
return null;
|
|
3154
3183
|
}
|
|
@@ -3411,12 +3440,12 @@ function readUserDeny(projectDir, agent) {
|
|
|
3411
3440
|
}
|
|
3412
3441
|
return out;
|
|
3413
3442
|
}
|
|
3414
|
-
function tokenize(glob,
|
|
3443
|
+
function tokenize(glob, path7) {
|
|
3415
3444
|
const toks = [];
|
|
3416
3445
|
let i = 0;
|
|
3417
3446
|
while (i < glob.length) {
|
|
3418
3447
|
const c = glob[i];
|
|
3419
|
-
if (c === "*" &&
|
|
3448
|
+
if (c === "*" && path7 && glob[i + 1] === "*") {
|
|
3420
3449
|
const dir = glob[i + "**".length] === "/";
|
|
3421
3450
|
toks.push({ t: dir ? "globstarDir" : "globstar" });
|
|
3422
3451
|
i += dir ? "**/".length : "**".length;
|
|
@@ -3430,8 +3459,8 @@ function tokenize(glob, path5) {
|
|
|
3430
3459
|
}
|
|
3431
3460
|
return toks;
|
|
3432
3461
|
}
|
|
3433
|
-
function globMatch(glob, text,
|
|
3434
|
-
const toks = tokenize(glob,
|
|
3462
|
+
function globMatch(glob, text, path7) {
|
|
3463
|
+
const toks = tokenize(glob, path7);
|
|
3435
3464
|
const n = text.length;
|
|
3436
3465
|
let next = new Uint8Array(n + 1);
|
|
3437
3466
|
next[n] = 1;
|
|
@@ -3447,10 +3476,10 @@ function globMatch(glob, text, path5) {
|
|
|
3447
3476
|
cur[j] = has3 && ch === tok.c ? next[j + 1] : 0;
|
|
3448
3477
|
break;
|
|
3449
3478
|
case "any1":
|
|
3450
|
-
cur[j] = has3 && !(
|
|
3479
|
+
cur[j] = has3 && !(path7 && ch === "/") ? next[j + 1] : 0;
|
|
3451
3480
|
break;
|
|
3452
3481
|
case "star":
|
|
3453
|
-
cur[j] = next[j] || (has3 && !(
|
|
3482
|
+
cur[j] = next[j] || (has3 && !(path7 && ch === "/") ? cur[j + 1] : 0);
|
|
3454
3483
|
break;
|
|
3455
3484
|
case "globstar":
|
|
3456
3485
|
cur[j] = next[j] || (has3 ? cur[j + 1] : 0);
|
|
@@ -3530,8 +3559,8 @@ var READ_DENY_TEMPLATE = 'context-mode: {size}-byte file, over the one-read limi
|
|
|
3530
3559
|
// src/core/policy/read-deny.ts
|
|
3531
3560
|
var SIZE = "{size}";
|
|
3532
3561
|
var PATH = "{path}";
|
|
3533
|
-
function READ_DENY_MESSAGE(
|
|
3534
|
-
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(
|
|
3562
|
+
function READ_DENY_MESSAGE(path7, size, prefix = "") {
|
|
3563
|
+
return prefixToolNames(READ_DENY_TEMPLATE, prefix).split(SIZE).join(String(size)).split(PATH).join(path7);
|
|
3535
3564
|
}
|
|
3536
3565
|
|
|
3537
3566
|
// src/core/policy/decide.ts
|
|
@@ -3589,7 +3618,7 @@ function readPath(input) {
|
|
|
3589
3618
|
}
|
|
3590
3619
|
function userDenyHit(canonical, input, cwd, rules) {
|
|
3591
3620
|
if (rules.length === 0) return null;
|
|
3592
|
-
const readRule = (p) => matchesAnyDenyPattern(
|
|
3621
|
+
const readRule = (p) => matchesAnyDenyPattern(resolve3(cwd, p), rules, { tool: READ, projectDir: cwd });
|
|
3593
3622
|
if (canonical === BASH) {
|
|
3594
3623
|
const cmd = str(input.command);
|
|
3595
3624
|
return cmd === void 0 ? null : matchesAnyDenyPattern(cmd, rules);
|
|
@@ -3700,7 +3729,7 @@ function read(ev, row5, input) {
|
|
|
3700
3729
|
if (!present(input.offset) && !present(input.limit)) {
|
|
3701
3730
|
const p = readPath(input);
|
|
3702
3731
|
if (p !== void 0) {
|
|
3703
|
-
const abs =
|
|
3732
|
+
const abs = resolve3(ev.cwd, p);
|
|
3704
3733
|
const size = fileSize(abs);
|
|
3705
3734
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3706
3735
|
}
|
|
@@ -3713,7 +3742,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3713
3742
|
let verdict = null;
|
|
3714
3743
|
for (const c of cmds) {
|
|
3715
3744
|
const name = c.argv0.toLowerCase();
|
|
3716
|
-
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir =
|
|
3745
|
+
if (name === CD_COMMAND && c.args.length === 1 && c.insideConstruct === void 0) dir = resolve3(dir, c.args[0]);
|
|
3717
3746
|
if (c.redirectsToFile || c.endsInBoundedSink || c.pipesOut === true || c.insideConstruct !== void 0) continue;
|
|
3718
3747
|
if (!has(SHELL_DUMP_COMMANDS, name)) continue;
|
|
3719
3748
|
const d = dumpTarget(name, c.args);
|
|
@@ -3722,7 +3751,7 @@ function shellDump(cmds, cwd, row5) {
|
|
|
3722
3751
|
verdict = ALLOW;
|
|
3723
3752
|
continue;
|
|
3724
3753
|
}
|
|
3725
|
-
const abs =
|
|
3754
|
+
const abs = resolve3(dir, d.file);
|
|
3726
3755
|
const size = fileSize(abs);
|
|
3727
3756
|
if (size > OUTPUT_CAP) return deny(READ_DENY_MESSAGE(abs, size, row5.toolNamePrefix));
|
|
3728
3757
|
}
|
|
@@ -3793,10 +3822,10 @@ function dumpTarget(name, args) {
|
|
|
3793
3822
|
}
|
|
3794
3823
|
|
|
3795
3824
|
// src/core/project/resolve.ts
|
|
3796
|
-
import { basename, dirname as
|
|
3825
|
+
import { basename as basename2, dirname as dirname3, join as join4, resolve as resolve4 } from "node:path";
|
|
3797
3826
|
|
|
3798
3827
|
// src/core/project/contain.ts
|
|
3799
|
-
import { dirname, sep as sep2 } from "node:path";
|
|
3828
|
+
import { dirname as dirname2, sep as sep2 } from "node:path";
|
|
3800
3829
|
var { realpathSync: realpathSync2 } = process.getBuiltinModule("node:fs");
|
|
3801
3830
|
function real(p) {
|
|
3802
3831
|
try {
|
|
@@ -3833,7 +3862,7 @@ function commonRoot(paths) {
|
|
|
3833
3862
|
n = i;
|
|
3834
3863
|
}
|
|
3835
3864
|
let q = first;
|
|
3836
|
-
while (components(q).length > n &&
|
|
3865
|
+
while (components(q).length > n && dirname2(q) !== q) q = dirname2(q);
|
|
3837
3866
|
return q;
|
|
3838
3867
|
}
|
|
3839
3868
|
|
|
@@ -4000,9 +4029,9 @@ function gitDirs(dir) {
|
|
|
4000
4029
|
const gitDir = gitDirAt(join4(cur, GIT_DIR_NAME));
|
|
4001
4030
|
if (gitDir !== null) {
|
|
4002
4031
|
const common = firstLine(join4(gitDir, GIT_COMMONDIR_FILE));
|
|
4003
|
-
return { commonDir: realpathSync3.native(common === null ? gitDir :
|
|
4032
|
+
return { commonDir: realpathSync3.native(common === null ? gitDir : resolve4(gitDir, common)), worktree: cur, start };
|
|
4004
4033
|
}
|
|
4005
|
-
const up =
|
|
4034
|
+
const up = dirname3(cur);
|
|
4006
4035
|
if (up === cur) return { commonDir: null, start };
|
|
4007
4036
|
cur = up;
|
|
4008
4037
|
}
|
|
@@ -4015,7 +4044,7 @@ function gitDirAt(dotGit) {
|
|
|
4015
4044
|
} else {
|
|
4016
4045
|
const line = firstLine(dotGit);
|
|
4017
4046
|
if (line === null || !line.startsWith(GITDIR_FILE_PREFIX)) return null;
|
|
4018
|
-
gitDir =
|
|
4047
|
+
gitDir = resolve4(dirname3(dotGit), line.slice(GITDIR_FILE_PREFIX.length));
|
|
4019
4048
|
}
|
|
4020
4049
|
} catch {
|
|
4021
4050
|
return null;
|
|
@@ -4034,15 +4063,15 @@ function firstLine(file2) {
|
|
|
4034
4063
|
return line === "" ? null : line;
|
|
4035
4064
|
}
|
|
4036
4065
|
function git(dir, args) {
|
|
4037
|
-
const { spawnSync } = process.getBuiltinModule("node:child_process");
|
|
4038
|
-
const r =
|
|
4066
|
+
const { spawnSync: spawnSync3 } = process.getBuiltinModule("node:child_process");
|
|
4067
|
+
const r = spawnSync3("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
4039
4068
|
if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
4040
4069
|
return r.stdout.split("\n").filter((l) => l !== "");
|
|
4041
4070
|
}
|
|
4042
4071
|
function containmentRootOf(dir, commonDir) {
|
|
4043
|
-
const repoDir =
|
|
4072
|
+
const repoDir = basename2(commonDir) === GIT_DIR_NAME ? dirname3(commonDir) : commonDir;
|
|
4044
4073
|
const worktrees = git(dir, ["worktree", "list", "--porcelain"]).filter((l) => l.startsWith(GIT_WORKTREE_LINE_PREFIX)).map((l) => l.slice(GIT_WORKTREE_LINE_PREFIX.length));
|
|
4045
|
-
return commonRoot([
|
|
4074
|
+
return commonRoot([dirname3(repoDir), ...worktrees]);
|
|
4046
4075
|
}
|
|
4047
4076
|
function resolveProject(agent, src) {
|
|
4048
4077
|
const source = sourceOf(agent);
|
|
@@ -4176,12 +4205,16 @@ CREATE VIRTUAL TABLE line_units USING fts5(
|
|
|
4176
4205
|
${FTS_TOKENIZE}
|
|
4177
4206
|
);
|
|
4178
4207
|
`;
|
|
4208
|
+
var DDL_V6 = `
|
|
4209
|
+
UPDATE sources SET label = replace(label, char(92), '/') WHERE kind = 'path' AND instr(label, char(92)) > 0;
|
|
4210
|
+
`;
|
|
4179
4211
|
var MIGRATIONS = [
|
|
4180
4212
|
{ version: 1, sql: DDL },
|
|
4181
4213
|
{ version: 2, sql: DDL_V2 },
|
|
4182
4214
|
{ version: 3, sql: DDL_V3 },
|
|
4183
4215
|
{ version: 4, sql: DDL_V4 },
|
|
4184
|
-
{ version: 5, sql: DDL_V5 }
|
|
4216
|
+
{ version: 5, sql: DDL_V5 },
|
|
4217
|
+
{ version: 6, sql: DDL_V6 }
|
|
4185
4218
|
];
|
|
4186
4219
|
function applyMigrations(db, fromVersion) {
|
|
4187
4220
|
if (fromVersion === SCHEMA_VERSION2) return;
|
|
@@ -4235,9 +4268,9 @@ function readUserVersion(raw) {
|
|
|
4235
4268
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
4236
4269
|
return row5.user_version;
|
|
4237
4270
|
}
|
|
4238
|
-
function createAtomically(sqlite,
|
|
4271
|
+
function createAtomically(sqlite, path7) {
|
|
4239
4272
|
const { randomUUID } = process.getBuiltinModule("node:crypto");
|
|
4240
|
-
const tmp =
|
|
4273
|
+
const tmp = path7 + "." + randomUUID() + DB_TMP_SUFFIX;
|
|
4241
4274
|
try {
|
|
4242
4275
|
const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
|
|
4243
4276
|
try {
|
|
@@ -4246,7 +4279,7 @@ function createAtomically(sqlite, path5) {
|
|
|
4246
4279
|
raw.close();
|
|
4247
4280
|
}
|
|
4248
4281
|
try {
|
|
4249
|
-
linkSync(tmp,
|
|
4282
|
+
linkSync(tmp, path7);
|
|
4250
4283
|
} catch (err) {
|
|
4251
4284
|
if (err.code !== "EEXIST") throw err;
|
|
4252
4285
|
}
|
|
@@ -4254,11 +4287,11 @@ function createAtomically(sqlite, path5) {
|
|
|
4254
4287
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
4255
4288
|
}
|
|
4256
4289
|
}
|
|
4257
|
-
function openWritable(sqlite,
|
|
4290
|
+
function openWritable(sqlite, path7) {
|
|
4258
4291
|
let raw = null;
|
|
4259
4292
|
try {
|
|
4260
|
-
if (!existsSync2(
|
|
4261
|
-
raw = new sqlite.DatabaseSync(
|
|
4293
|
+
if (!existsSync2(path7)) createAtomically(sqlite, path7);
|
|
4294
|
+
raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS });
|
|
4262
4295
|
applyMigrations(raw, readUserVersion(raw));
|
|
4263
4296
|
return raw;
|
|
4264
4297
|
} catch (err) {
|
|
@@ -4266,8 +4299,8 @@ function openWritable(sqlite, path5) {
|
|
|
4266
4299
|
throw err;
|
|
4267
4300
|
}
|
|
4268
4301
|
}
|
|
4269
|
-
function openReadOnly(sqlite,
|
|
4270
|
-
const raw = new sqlite.DatabaseSync(
|
|
4302
|
+
function openReadOnly(sqlite, path7) {
|
|
4303
|
+
const raw = new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
4271
4304
|
try {
|
|
4272
4305
|
const found = readUserVersion(raw);
|
|
4273
4306
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -4281,20 +4314,20 @@ async function openDb(project, opts) {
|
|
|
4281
4314
|
if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
|
|
4282
4315
|
const sqlite = await loadSqlite();
|
|
4283
4316
|
mkdirSync2(project.projectDir, { recursive: true });
|
|
4284
|
-
const
|
|
4285
|
-
const sibling = existsSync2(
|
|
4286
|
-
if (sibling && !existsSync2(
|
|
4317
|
+
const path7 = project.dbPath;
|
|
4318
|
+
const sibling = existsSync2(path7 + DB_WAL_SUFFIX) || existsSync2(path7 + DB_SHM_SUFFIX);
|
|
4319
|
+
if (sibling && !existsSync2(path7)) {
|
|
4287
4320
|
throw new CtxError("DB_GONE");
|
|
4288
4321
|
}
|
|
4289
4322
|
try {
|
|
4290
4323
|
let raw;
|
|
4291
4324
|
if (opts?.readOnly === true) {
|
|
4292
|
-
if (!existsSync2(
|
|
4293
|
-
raw = openReadOnly(sqlite,
|
|
4325
|
+
if (!existsSync2(path7)) openWritable(sqlite, path7).close();
|
|
4326
|
+
raw = openReadOnly(sqlite, path7);
|
|
4294
4327
|
} else {
|
|
4295
|
-
raw = openWritable(sqlite,
|
|
4328
|
+
raw = openWritable(sqlite, path7);
|
|
4296
4329
|
}
|
|
4297
|
-
return { raw, projectKey: project.projectKey, path:
|
|
4330
|
+
return { raw, projectKey: project.projectKey, path: path7, ...opts?.readOnly === true ? { readOnly: true } : {} };
|
|
4298
4331
|
} catch (err) {
|
|
4299
4332
|
if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
|
|
4300
4333
|
throw err;
|
|
@@ -6718,7 +6751,7 @@ function ftsQuery(db, q, scope, ctx, sessionId, limit, offset, source) {
|
|
|
6718
6751
|
}
|
|
6719
6752
|
return page2.map((e) => {
|
|
6720
6753
|
const r = rows.get(Number(e.r.rid));
|
|
6721
|
-
return { sourceId: Number(r.source_id), label: r.label, ord: Number(r.ord), snippet: highlight(r.body, q, SNIPPET_MAX_BYTES), score: e.s };
|
|
6754
|
+
return { sourceId: Number(r.source_id), label: r.label, ord: Number(r.ord), snippet: highlight(r.body, q, SNIPPET_MAX_BYTES), score: e.s, full: e.full === 1 };
|
|
6722
6755
|
});
|
|
6723
6756
|
}
|
|
6724
6757
|
var LIST = `
|
|
@@ -6887,17 +6920,29 @@ function parseSourceHandle(s) {
|
|
|
6887
6920
|
}
|
|
6888
6921
|
return n > 0 && sourceHandle(n) === s ? n : null;
|
|
6889
6922
|
}
|
|
6923
|
+
function pathLabel(p) {
|
|
6924
|
+
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
6925
|
+
}
|
|
6926
|
+
function labelStored(db, label) {
|
|
6927
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label) !== void 0;
|
|
6928
|
+
}
|
|
6929
|
+
function storedLabel(db, source) {
|
|
6930
|
+
if (labelStored(db, source)) return source;
|
|
6931
|
+
const canon = pathLabel(source);
|
|
6932
|
+
return canon !== source && labelStored(db, canon) ? canon : source;
|
|
6933
|
+
}
|
|
6890
6934
|
function resolveSourceLabel(db, source) {
|
|
6891
6935
|
const id2 = parseSourceHandle(source);
|
|
6892
6936
|
if (id2 !== null) {
|
|
6893
6937
|
const row5 = stmt(db.raw, "SELECT label FROM sources WHERE id = ?").get(id2);
|
|
6894
6938
|
if (row5 !== void 0) return row5.label;
|
|
6895
6939
|
}
|
|
6896
|
-
|
|
6897
|
-
|
|
6940
|
+
const named = storedLabel(db, source);
|
|
6941
|
+
if (labelStored(db, named)) return named;
|
|
6942
|
+
const prefix = named + LABEL_SUFFIX_SEP;
|
|
6898
6943
|
const rows = stmt(db.raw, "SELECT label FROM sources WHERE substr(label, 1, ?) = ? ORDER BY id DESC").all(prefix.length, prefix);
|
|
6899
6944
|
for (const r of rows) {
|
|
6900
|
-
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) ===
|
|
6945
|
+
if (r.label.lastIndexOf(LABEL_SUFFIX_SEP) === named.length) return r.label;
|
|
6901
6946
|
}
|
|
6902
6947
|
return source;
|
|
6903
6948
|
}
|
|
@@ -7003,8 +7048,8 @@ function buildCandidates(rows, sessionId) {
|
|
|
7003
7048
|
edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
|
|
7004
7049
|
}
|
|
7005
7050
|
const changedFiles = [];
|
|
7006
|
-
for (const [
|
|
7007
|
-
const c = make("changed_files", e.row, "edited " +
|
|
7051
|
+
for (const [path7, e] of edits) {
|
|
7052
|
+
const c = make("changed_files", e.row, "edited " + path7 + " x" + e.count, e.count, path7);
|
|
7008
7053
|
changedFiles.push({ ...c, editCount: e.count });
|
|
7009
7054
|
}
|
|
7010
7055
|
changedFiles.sort((a, b) => a.seq - b.seq);
|
|
@@ -7956,7 +8001,7 @@ function shouldHint(db, sessionId, onceKey, everyN) {
|
|
|
7956
8001
|
}
|
|
7957
8002
|
|
|
7958
8003
|
// src/core/hooks/fallback.ts
|
|
7959
|
-
import { join as join5, resolve as
|
|
8004
|
+
import { join as join5, resolve as resolve5 } from "node:path";
|
|
7960
8005
|
var fs = process.getBuiltinModule("node:fs");
|
|
7961
8006
|
function isRec(v) {
|
|
7962
8007
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -8071,7 +8116,7 @@ function bigRead(input, cwd) {
|
|
|
8071
8116
|
const p = firstString(input, READ_PATH_KEYS);
|
|
8072
8117
|
if (p === "") return false;
|
|
8073
8118
|
try {
|
|
8074
|
-
const st = fs.statSync(
|
|
8119
|
+
const st = fs.statSync(resolve5(cwd, p));
|
|
8075
8120
|
return st.isFile() && st.size > OUTPUT_CAP;
|
|
8076
8121
|
} catch {
|
|
8077
8122
|
return false;
|
|
@@ -8142,20 +8187,24 @@ async function handleHook(agent, raw, env) {
|
|
|
8142
8187
|
return fail7("project", err, "hooks: no project: " + String(err.code ?? "ERROR") + " " + message(err) + "\n");
|
|
8143
8188
|
}
|
|
8144
8189
|
let decision;
|
|
8190
|
+
const settle = {};
|
|
8145
8191
|
try {
|
|
8146
8192
|
fault(env, "policy");
|
|
8147
|
-
decision = await dispatch(ev, row5, project, env);
|
|
8193
|
+
decision = await dispatch(ev, row5, project, env, settle);
|
|
8148
8194
|
} catch (err) {
|
|
8149
8195
|
return fail7("store", err);
|
|
8150
8196
|
}
|
|
8151
8197
|
try {
|
|
8152
8198
|
fault(env, "encode");
|
|
8153
|
-
|
|
8199
|
+
const out = row5.encode(ev, decision);
|
|
8200
|
+
settle.run?.(true);
|
|
8201
|
+
return out;
|
|
8154
8202
|
} catch (err) {
|
|
8203
|
+
settle.run?.(false);
|
|
8155
8204
|
return fail7("encode", err);
|
|
8156
8205
|
}
|
|
8157
8206
|
}
|
|
8158
|
-
function dispatch(ev, row5, project, env) {
|
|
8207
|
+
function dispatch(ev, row5, project, env, settle) {
|
|
8159
8208
|
switch (ev.event) {
|
|
8160
8209
|
case "SessionStart":
|
|
8161
8210
|
return sessionStart(ev, row5, project);
|
|
@@ -8164,7 +8213,7 @@ function dispatch(ev, row5, project, env) {
|
|
|
8164
8213
|
case "PreToolUse":
|
|
8165
8214
|
return preToolUse(ev, row5, project, env);
|
|
8166
8215
|
case "PostToolUse":
|
|
8167
|
-
return postToolUse(ev, row5, project, env);
|
|
8216
|
+
return postToolUse(ev, row5, project, env, settle);
|
|
8168
8217
|
case "PreCompact":
|
|
8169
8218
|
return preCompact(ev, row5, project);
|
|
8170
8219
|
case "Usage":
|
|
@@ -8354,7 +8403,7 @@ function caseB(ev, row5, d0, userDeny) {
|
|
|
8354
8403
|
if (tool === void 0 || !isShell(tool, row5) || isUserPolicyDeny(d0.reason, row5)) return d0;
|
|
8355
8404
|
const command = tool.input.command;
|
|
8356
8405
|
if (typeof command !== "string") return d0;
|
|
8357
|
-
const wrapper = '"' + join6(
|
|
8406
|
+
const wrapper = '"' + join6(dirname4(process.argv[1] ?? ""), RUN_WRAPPER_FILE) + '"';
|
|
8358
8407
|
const rewritten = [RUN_WRAPPER_NODE, wrapper, b64(command), b64(JSON.stringify(userDeny ?? [])), b64(str2(tool.input.description))].join(" ");
|
|
8359
8408
|
return { kind: "deny", reason: SUBAGENT_RUN_DENY, rewritten };
|
|
8360
8409
|
}
|
|
@@ -8391,7 +8440,7 @@ function pathOf(input) {
|
|
|
8391
8440
|
for (const k of EDIT_PATH_KEYS) if (typeof input[k] === "string") return input[k];
|
|
8392
8441
|
return null;
|
|
8393
8442
|
}
|
|
8394
|
-
async function postToolUse(ev, row5, project, env) {
|
|
8443
|
+
async function postToolUse(ev, row5, project, env, settle) {
|
|
8395
8444
|
const tool = ev.tool;
|
|
8396
8445
|
if (tool === void 0 || tool.canonicalName.startsWith(OWN_TOOL_PREFIX)) return ALLOW2;
|
|
8397
8446
|
const result = ev.result ?? { isError: false, bytes: 0 };
|
|
@@ -8399,7 +8448,8 @@ async function postToolUse(ev, row5, project, env) {
|
|
|
8399
8448
|
if (result.persistedPath !== void 0) result.bytes = Buffer.byteLength(text);
|
|
8400
8449
|
if (tool.canonicalName === DECISION_TOOL) askDetached(ev, project, tool, text);
|
|
8401
8450
|
const kind = journalKind(tool, row5, result.isError);
|
|
8402
|
-
|
|
8451
|
+
const journal = (returned) => {
|
|
8452
|
+
if (kind === null) return;
|
|
8403
8453
|
const key = kind === "cmd" ? canonicalKey(tool.canonicalName, str2(tool.input.command)) : kind === "toolerr" ? tool.canonicalName + ":" + stableJson(tool.input) : null;
|
|
8404
8454
|
appendDetached(project, ev.sessionId, {
|
|
8405
8455
|
// step 4; body is the whole text (D-M3-H2-6)
|
|
@@ -8416,18 +8466,30 @@ async function postToolUse(ev, row5, project, env) {
|
|
|
8416
8466
|
body: text,
|
|
8417
8467
|
turn: ev.turn ?? 0,
|
|
8418
8468
|
sandbox_bytes: result.bytes,
|
|
8419
|
-
returned_bytes:
|
|
8469
|
+
returned_bytes: returned
|
|
8420
8470
|
});
|
|
8471
|
+
};
|
|
8472
|
+
let decision;
|
|
8473
|
+
try {
|
|
8474
|
+
decision = await postReplace(ev, row5, project, env, tool, result, text);
|
|
8475
|
+
} catch (err) {
|
|
8476
|
+
journal(result.bytes);
|
|
8477
|
+
throw err;
|
|
8421
8478
|
}
|
|
8479
|
+
const decided = decision;
|
|
8480
|
+
settle.run = (encoded) => journal(encoded && decided.kind === "replace" ? Buffer.byteLength(decided.output) : result.bytes);
|
|
8481
|
+
return decision;
|
|
8482
|
+
}
|
|
8483
|
+
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
8422
8484
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
8423
8485
|
if (result.keep === true) return ALLOW2;
|
|
8486
|
+
if (!hasReplace(row5)) return ALLOW2;
|
|
8424
8487
|
let label;
|
|
8425
8488
|
if (isSubagentCall(ev)) {
|
|
8426
8489
|
const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
|
|
8427
8490
|
if (subCase === "A") return ALLOW2;
|
|
8428
8491
|
label = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
|
|
8429
8492
|
} else {
|
|
8430
|
-
if (!hasReplace(row5)) return ALLOW2;
|
|
8431
8493
|
label = mainLabel(tool, ev);
|
|
8432
8494
|
}
|
|
8433
8495
|
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ?? "";
|
|
@@ -9185,10 +9247,10 @@ function assignProp(target, prop, value) {
|
|
|
9185
9247
|
configurable: true
|
|
9186
9248
|
});
|
|
9187
9249
|
}
|
|
9188
|
-
function getElementAtPath(obj,
|
|
9189
|
-
if (!
|
|
9250
|
+
function getElementAtPath(obj, path7) {
|
|
9251
|
+
if (!path7)
|
|
9190
9252
|
return obj;
|
|
9191
|
-
return
|
|
9253
|
+
return path7.reduce((acc, key) => acc?.[key], obj);
|
|
9192
9254
|
}
|
|
9193
9255
|
function promiseAllObject(promisesObj) {
|
|
9194
9256
|
const keys = Object.keys(promisesObj);
|
|
@@ -9508,11 +9570,11 @@ function aborted(x, startIndex = 0) {
|
|
|
9508
9570
|
}
|
|
9509
9571
|
return false;
|
|
9510
9572
|
}
|
|
9511
|
-
function prefixIssues(
|
|
9573
|
+
function prefixIssues(path7, issues) {
|
|
9512
9574
|
return issues.map((iss) => {
|
|
9513
9575
|
var _a;
|
|
9514
9576
|
(_a = iss).path ?? (_a.path = []);
|
|
9515
|
-
iss.path.unshift(
|
|
9577
|
+
iss.path.unshift(path7);
|
|
9516
9578
|
return iss;
|
|
9517
9579
|
});
|
|
9518
9580
|
}
|
|
@@ -9649,7 +9711,7 @@ function treeifyError(error40, _mapper) {
|
|
|
9649
9711
|
return issue2.message;
|
|
9650
9712
|
};
|
|
9651
9713
|
const result = { errors: [] };
|
|
9652
|
-
const processError = (error41,
|
|
9714
|
+
const processError = (error41, path7 = []) => {
|
|
9653
9715
|
var _a, _b;
|
|
9654
9716
|
for (const issue2 of error41.issues) {
|
|
9655
9717
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
@@ -9659,7 +9721,7 @@ function treeifyError(error40, _mapper) {
|
|
|
9659
9721
|
} else if (issue2.code === "invalid_element") {
|
|
9660
9722
|
processError({ issues: issue2.issues }, issue2.path);
|
|
9661
9723
|
} else {
|
|
9662
|
-
const fullpath = [...
|
|
9724
|
+
const fullpath = [...path7, ...issue2.path];
|
|
9663
9725
|
if (fullpath.length === 0) {
|
|
9664
9726
|
result.errors.push(mapper(issue2));
|
|
9665
9727
|
continue;
|
|
@@ -9689,9 +9751,9 @@ function treeifyError(error40, _mapper) {
|
|
|
9689
9751
|
processError(error40);
|
|
9690
9752
|
return result;
|
|
9691
9753
|
}
|
|
9692
|
-
function toDotPath(
|
|
9754
|
+
function toDotPath(path7) {
|
|
9693
9755
|
const segs = [];
|
|
9694
|
-
for (const seg of
|
|
9756
|
+
for (const seg of path7) {
|
|
9695
9757
|
if (typeof seg === "number")
|
|
9696
9758
|
segs.push(`[${seg}]`);
|
|
9697
9759
|
else if (typeof seg === "symbol")
|
|
@@ -19823,10 +19885,10 @@ function startArgv(argv) {
|
|
|
19823
19885
|
return sh === null ? null : [sh, ...argv];
|
|
19824
19886
|
}
|
|
19825
19887
|
function runProcess(argv, o) {
|
|
19826
|
-
return new Promise((
|
|
19888
|
+
return new Promise((resolve8) => {
|
|
19827
19889
|
const isWin2 = process.platform === "win32";
|
|
19828
19890
|
const start = startArgv(argv);
|
|
19829
|
-
if (start === null) return
|
|
19891
|
+
if (start === null) return resolve8(NOT_STARTED);
|
|
19830
19892
|
let child;
|
|
19831
19893
|
try {
|
|
19832
19894
|
child = spawn(start[0], start.slice(1), {
|
|
@@ -19840,7 +19902,7 @@ function runProcess(argv, o) {
|
|
|
19840
19902
|
windowsHide: true
|
|
19841
19903
|
});
|
|
19842
19904
|
} catch {
|
|
19843
|
-
return
|
|
19905
|
+
return resolve8(NOT_STARTED);
|
|
19844
19906
|
}
|
|
19845
19907
|
const stdoutChunks = [];
|
|
19846
19908
|
const stderrChunks = [];
|
|
@@ -19865,7 +19927,7 @@ function runProcess(argv, o) {
|
|
|
19865
19927
|
settled = true;
|
|
19866
19928
|
clearTimeout(timer);
|
|
19867
19929
|
o.signal.removeEventListener("abort", onAbort);
|
|
19868
|
-
|
|
19930
|
+
resolve8({
|
|
19869
19931
|
stdout: Buffer.concat(stdoutChunks),
|
|
19870
19932
|
stderr: Buffer.concat(stderrChunks),
|
|
19871
19933
|
exitCode,
|
|
@@ -19897,19 +19959,19 @@ function readAutoMemory(project) {
|
|
|
19897
19959
|
if (project.agent !== "claude-code") return [];
|
|
19898
19960
|
const rows = [];
|
|
19899
19961
|
for (const segs of CLAUDE_CODE_MEMORY_FILES) {
|
|
19900
|
-
const
|
|
19901
|
-
if (!isInside(project.worktree,
|
|
19962
|
+
const path7 = join7(project.worktree, ...segs);
|
|
19963
|
+
if (!isInside(project.worktree, path7)) continue;
|
|
19902
19964
|
try {
|
|
19903
|
-
const st = statSync4(
|
|
19965
|
+
const st = statSync4(path7);
|
|
19904
19966
|
if (!st.isFile()) continue;
|
|
19905
19967
|
rows.push({
|
|
19906
19968
|
origin: "memory",
|
|
19907
19969
|
ts: Math.trunc(st.mtimeMs),
|
|
19908
19970
|
seq: null,
|
|
19909
19971
|
sourceId: null,
|
|
19910
|
-
path:
|
|
19972
|
+
path: path7,
|
|
19911
19973
|
label: segs.join("/"),
|
|
19912
|
-
text: readFileSync5(
|
|
19974
|
+
text: readFileSync5(path7, "utf8")
|
|
19913
19975
|
});
|
|
19914
19976
|
} catch {
|
|
19915
19977
|
}
|
|
@@ -20025,12 +20087,20 @@ function sourceBytes(db, ids) {
|
|
|
20025
20087
|
}
|
|
20026
20088
|
return out;
|
|
20027
20089
|
}
|
|
20090
|
+
var LEAN_HITS = 3;
|
|
20091
|
+
function replyHits(hits, size) {
|
|
20092
|
+
if (hits.length === 0 || hits[0].full !== true) return Math.min(size, hits.length);
|
|
20093
|
+
let n = Math.min(LEAN_HITS, size, hits.length);
|
|
20094
|
+
while (n < size && n < hits.length && hits[n].full === true) n++;
|
|
20095
|
+
return n;
|
|
20096
|
+
}
|
|
20028
20097
|
function relevance(db, given, scope, ctx) {
|
|
20029
20098
|
const input = { ...given, queries: decisionQueries(given) };
|
|
20030
20099
|
const offset = input.offset ?? 0;
|
|
20031
20100
|
const size = pageSize(input);
|
|
20032
20101
|
const fetched = input.queries.map((q) => page(db, q, input, scope, ctx, offset, 1));
|
|
20033
|
-
const
|
|
20102
|
+
const take = fetched.map((h) => replyHits(h, size));
|
|
20103
|
+
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
20034
20104
|
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source);
|
|
20035
20105
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, input.source, "offset:" + pos);
|
|
20036
20106
|
let reserve = 0;
|
|
@@ -20045,7 +20115,7 @@ function relevance(db, given, scope, ctx) {
|
|
|
20045
20115
|
input.queries.forEach((q, qi) => {
|
|
20046
20116
|
const hits = pages[qi];
|
|
20047
20117
|
if (stopped) {
|
|
20048
|
-
more.push(
|
|
20118
|
+
more.push({ q, pos: offset });
|
|
20049
20119
|
return;
|
|
20050
20120
|
}
|
|
20051
20121
|
const head = "Query " + JSON.stringify(q) + ":";
|
|
@@ -20083,10 +20153,14 @@ function relevance(db, given, scope, ctx) {
|
|
|
20083
20153
|
lines.push(line);
|
|
20084
20154
|
used += bytes2(line) + 1;
|
|
20085
20155
|
}
|
|
20086
|
-
if (cut >= 0) more.push(
|
|
20087
|
-
else if (fetched[qi].length >
|
|
20156
|
+
if (cut >= 0) more.push({ q, pos: cut });
|
|
20157
|
+
else if (fetched[qi].length > take[qi]) more.push({ q, pos: offset + take[qi] });
|
|
20088
20158
|
});
|
|
20089
|
-
|
|
20159
|
+
const moreLines = [];
|
|
20160
|
+
const byPos = /* @__PURE__ */ new Map();
|
|
20161
|
+
for (const m of more) byPos.set(m.pos, [...byPos.get(m.pos) ?? [], m.q]);
|
|
20162
|
+
for (const [pos, qs] of byPos) moreLines.push("More: " + callText(qs, scope, input.source, "offset:" + pos));
|
|
20163
|
+
return reply(lines.concat(moreLines).join("\n"), false);
|
|
20090
20164
|
}
|
|
20091
20165
|
function timelineLine(r) {
|
|
20092
20166
|
const nl = r.text.indexOf("\n");
|
|
@@ -20226,6 +20300,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20226
20300
|
const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
|
|
20227
20301
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
20228
20302
|
const bodies = /* @__PURE__ */ new Map();
|
|
20303
|
+
const raw = /* @__PURE__ */ new Map();
|
|
20229
20304
|
let total = 0;
|
|
20230
20305
|
for (const c of chunks) total += c.bytes;
|
|
20231
20306
|
let indexed = 0;
|
|
@@ -20246,7 +20321,10 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20246
20321
|
chunkCount: group.length,
|
|
20247
20322
|
createdAt: Date.now()
|
|
20248
20323
|
}, group);
|
|
20249
|
-
for (const c of group)
|
|
20324
|
+
for (const c of group) {
|
|
20325
|
+
bodies.set(chunkKey(id2, c.ord), display[c.ord]);
|
|
20326
|
+
raw.set(chunkKey(id2, c.ord), c.text);
|
|
20327
|
+
}
|
|
20250
20328
|
indexed += groupBytes;
|
|
20251
20329
|
group = [];
|
|
20252
20330
|
groupBytes = 0;
|
|
@@ -20255,15 +20333,15 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20255
20333
|
for (const c of chunks) {
|
|
20256
20334
|
if (queued + c.bytes > budgetBytes) {
|
|
20257
20335
|
const stop2 = flush() ? "budget" : "deadline";
|
|
20258
|
-
return { bodies, indexed, total, stop: stop2 };
|
|
20336
|
+
return { bodies, raw, indexed, total, stop: stop2 };
|
|
20259
20337
|
}
|
|
20260
|
-
if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, indexed, total, stop: "deadline" };
|
|
20338
|
+
if (group.length > 0 && groupBytes + c.bytes > INDEX_WRITE_CHUNK && !flush()) return { bodies, raw, indexed, total, stop: "deadline" };
|
|
20261
20339
|
group.push(c);
|
|
20262
20340
|
groupBytes += c.bytes;
|
|
20263
20341
|
queued += c.bytes;
|
|
20264
20342
|
}
|
|
20265
20343
|
const stop = flush() ? null : "deadline";
|
|
20266
|
-
return { bodies, indexed, total, stop };
|
|
20344
|
+
return { bodies, raw, indexed, total, stop };
|
|
20267
20345
|
}
|
|
20268
20346
|
function bytes3(s) {
|
|
20269
20347
|
return Buffer.byteLength(s, "utf8");
|
|
@@ -20296,7 +20374,7 @@ function answer(db, ctx, label, queries, share, own2) {
|
|
|
20296
20374
|
else if (body.length === 0) body.push("No new section.");
|
|
20297
20375
|
lines.push(head, ...body);
|
|
20298
20376
|
}
|
|
20299
|
-
return lines;
|
|
20377
|
+
return { lines, seen };
|
|
20300
20378
|
}
|
|
20301
20379
|
async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
20302
20380
|
const parsed = ctxBatchSchema.safeParse(input);
|
|
@@ -20317,9 +20395,10 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20317
20395
|
const db = await openDb(ctx.project);
|
|
20318
20396
|
let sections;
|
|
20319
20397
|
let idx;
|
|
20320
|
-
const
|
|
20398
|
+
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
20321
20399
|
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label) + "})";
|
|
20322
20400
|
let notice;
|
|
20401
|
+
let showMore;
|
|
20323
20402
|
try {
|
|
20324
20403
|
idx = indexCombined(db, ctx, label, ran, deadline, budgetBytes);
|
|
20325
20404
|
const stop = last2.error;
|
|
@@ -20327,13 +20406,21 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20327
20406
|
const timeout = formatError("TIMEOUT", { ms: boundMs });
|
|
20328
20407
|
const cause = stop ?? (ctx.signal.aborted ? CANCELLED_LINE : idx.stop === "deadline" ? timeout : null);
|
|
20329
20408
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20330
|
-
const fixed = bytes3(
|
|
20409
|
+
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20331
20410
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20332
|
-
|
|
20411
|
+
const answered = answer(db, ctx, label, queries, share, idx.bodies);
|
|
20412
|
+
sections = answered.lines;
|
|
20413
|
+
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20414
|
+
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
20415
|
+
if (unseen.length === 0 && cut === null) showMore = false;
|
|
20416
|
+
else if (cut === null && unseenBytes <= bytes3(footer) + 1) {
|
|
20417
|
+
showMore = false;
|
|
20418
|
+
sections = [...sections, ...unseen.map((t) => t.endsWith(LINE_SEP) ? t.slice(0, -1) : t)];
|
|
20419
|
+
} else showMore = true;
|
|
20333
20420
|
} finally {
|
|
20334
20421
|
closeDb(db);
|
|
20335
20422
|
}
|
|
20336
|
-
const lines = [
|
|
20423
|
+
const lines = [...exitLine === null ? [] : [exitLine], ...notice === null ? [] : [notice], ...sections, ...showMore ? [footer] : []];
|
|
20337
20424
|
return {
|
|
20338
20425
|
text: capBytes(lines.join(LINE_SEP), OUTPUT_CAP).text,
|
|
20339
20426
|
// step 10: final bound (D-M2-6)
|
|
@@ -20357,8 +20444,8 @@ var ctxBatch = Object.freeze({
|
|
|
20357
20444
|
});
|
|
20358
20445
|
|
|
20359
20446
|
// src/core/tools/doctor.ts
|
|
20360
|
-
import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as
|
|
20361
|
-
import { basename as
|
|
20447
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync11, existsSync as existsSync12 } from "node:fs";
|
|
20448
|
+
import { basename as basename4, dirname as dirname7, join as join13 } from "node:path";
|
|
20362
20449
|
|
|
20363
20450
|
// src/core/ops/doctor-config.ts
|
|
20364
20451
|
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -20371,7 +20458,7 @@ import { join as join9 } from "node:path";
|
|
|
20371
20458
|
|
|
20372
20459
|
// src/core/ops/host-config.ts
|
|
20373
20460
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "node:fs";
|
|
20374
|
-
import { dirname as
|
|
20461
|
+
import { dirname as dirname5, join as join8 } from "node:path";
|
|
20375
20462
|
|
|
20376
20463
|
// node_modules/eslint-visitor-keys/lib/visitor-keys.js
|
|
20377
20464
|
var KEYS2 = {
|
|
@@ -22480,15 +22567,15 @@ function atomicWriteFile(file2, text, opts = {}) {
|
|
|
22480
22567
|
}
|
|
22481
22568
|
|
|
22482
22569
|
// src/core/ops/host-config.ts
|
|
22483
|
-
function formatOf(
|
|
22484
|
-
if (
|
|
22485
|
-
if (
|
|
22570
|
+
function formatOf(path7) {
|
|
22571
|
+
if (path7.endsWith(JSONC_EXT)) return "jsonc";
|
|
22572
|
+
if (path7.endsWith(TOML_EXT)) return "toml";
|
|
22486
22573
|
return "json";
|
|
22487
22574
|
}
|
|
22488
|
-
function readHostConfig(agent,
|
|
22489
|
-
let file2 =
|
|
22575
|
+
function readHostConfig(agent, path7) {
|
|
22576
|
+
let file2 = path7;
|
|
22490
22577
|
if (agent === "opencode") {
|
|
22491
|
-
const jsonc = join8(
|
|
22578
|
+
const jsonc = join8(dirname5(path7), OPENCODE_CONFIG_FILES[0]);
|
|
22492
22579
|
if (existsSync3(jsonc)) file2 = jsonc;
|
|
22493
22580
|
}
|
|
22494
22581
|
const raw = existsSync3(file2) ? readFileSync6(file2, "utf8") : "";
|
|
@@ -22652,14 +22739,14 @@ function scanToml(text) {
|
|
|
22652
22739
|
continue;
|
|
22653
22740
|
}
|
|
22654
22741
|
if (!node.resolvedKey.every((seg) => typeof seg === "string")) continue;
|
|
22655
|
-
const
|
|
22656
|
-
for (const kv of node.body) addKey(
|
|
22742
|
+
const path7 = node.resolvedKey;
|
|
22743
|
+
for (const kv of node.body) addKey(path7, kv);
|
|
22657
22744
|
if (node.kind !== "standard") continue;
|
|
22658
22745
|
const start = lineStartOf(text, node.range[0]);
|
|
22659
22746
|
const headEnd = lineEndOf(text, node.key.range[1]);
|
|
22660
22747
|
const last2 = node.body[node.body.length - 1];
|
|
22661
22748
|
tables.push({
|
|
22662
|
-
path:
|
|
22749
|
+
path: path7,
|
|
22663
22750
|
header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
|
|
22664
22751
|
start,
|
|
22665
22752
|
end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
|
|
@@ -22670,16 +22757,16 @@ function scanToml(text) {
|
|
|
22670
22757
|
function tomlTableSpans(text) {
|
|
22671
22758
|
return scanToml(text).tables;
|
|
22672
22759
|
}
|
|
22673
|
-
function parseHostConfig(agent,
|
|
22760
|
+
function parseHostConfig(agent, path7, text, format) {
|
|
22674
22761
|
try {
|
|
22675
22762
|
return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
|
|
22676
22763
|
} catch {
|
|
22677
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
22764
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
|
|
22678
22765
|
}
|
|
22679
22766
|
}
|
|
22680
|
-
function hostConfigValueAt(value,
|
|
22767
|
+
function hostConfigValueAt(value, path7) {
|
|
22681
22768
|
let cur = value;
|
|
22682
|
-
for (const seg of
|
|
22769
|
+
for (const seg of path7) {
|
|
22683
22770
|
if (!isPlainObject3(cur)) return void 0;
|
|
22684
22771
|
cur = cur[seg];
|
|
22685
22772
|
}
|
|
@@ -22712,32 +22799,32 @@ function indentUnit(root, clean) {
|
|
|
22712
22799
|
function render(value, unit, base) {
|
|
22713
22800
|
return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
|
|
22714
22801
|
}
|
|
22715
|
-
function nest(
|
|
22802
|
+
function nest(path7, value) {
|
|
22716
22803
|
let out = value;
|
|
22717
|
-
for (let k =
|
|
22804
|
+
for (let k = path7.length - 1; k >= 0; k -= 1) out = { [path7[k]]: out };
|
|
22718
22805
|
return out;
|
|
22719
22806
|
}
|
|
22720
|
-
function setJsonText(text, format,
|
|
22807
|
+
function setJsonText(text, format, path7, value) {
|
|
22721
22808
|
const doc = scanJson(text, format);
|
|
22722
22809
|
const unit = indentUnit(doc.root, doc.clean);
|
|
22723
|
-
if (doc.root === null) return render(nest(
|
|
22810
|
+
if (doc.root === null) return render(nest(path7, value), unit, "") + "\n";
|
|
22724
22811
|
let node = doc.root;
|
|
22725
22812
|
let depth = 0;
|
|
22726
|
-
while (depth <
|
|
22727
|
-
const hit = node.members.find((m) => m.key ===
|
|
22813
|
+
while (depth < path7.length && node.kind === "object") {
|
|
22814
|
+
const hit = node.members.find((m) => m.key === path7[depth]);
|
|
22728
22815
|
if (hit === void 0) break;
|
|
22729
22816
|
node = hit.node;
|
|
22730
22817
|
depth += 1;
|
|
22731
22818
|
}
|
|
22732
|
-
if (depth ===
|
|
22819
|
+
if (depth === path7.length) {
|
|
22733
22820
|
return text.slice(0, node.start) + render(value, unit, lineIndent(doc.clean, node.start)) + text.slice(node.end);
|
|
22734
22821
|
}
|
|
22735
|
-
if (node.kind !== "object") throw new SyntaxError("not an object at " +
|
|
22736
|
-
const rest = nest(
|
|
22822
|
+
if (node.kind !== "object") throw new SyntaxError("not an object at " + path7.slice(0, depth).join("."));
|
|
22823
|
+
const rest = nest(path7.slice(depth + 1), value);
|
|
22737
22824
|
const last2 = node.members[node.members.length - 1];
|
|
22738
22825
|
if (last2 === void 0) {
|
|
22739
22826
|
const base2 = lineIndent(doc.clean, node.start);
|
|
22740
|
-
const member2 = "\n" + base2 + unit + JSON.stringify(
|
|
22827
|
+
const member2 = "\n" + base2 + unit + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
|
|
22741
22828
|
return text.slice(0, node.start + 1) + member2 + text.slice(node.end - 1);
|
|
22742
22829
|
}
|
|
22743
22830
|
const base = lineIndent(doc.clean, last2.keyStart);
|
|
@@ -22745,7 +22832,7 @@ function setJsonText(text, format, path5, value) {
|
|
|
22745
22832
|
while (" \r\n".includes(doc.clean[at2])) at2 += 1;
|
|
22746
22833
|
const trailing = doc.clean[at2] === ",";
|
|
22747
22834
|
const insertAt = trailing ? at2 + 1 : last2.node.end;
|
|
22748
|
-
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(
|
|
22835
|
+
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path7[depth]) + ": " + render(rest, unit, base);
|
|
22749
22836
|
return text.slice(0, insertAt) + member + text.slice(insertAt);
|
|
22750
22837
|
}
|
|
22751
22838
|
function tomlScalar(v) {
|
|
@@ -22763,17 +22850,17 @@ function tomlHeaderKey(seg) {
|
|
|
22763
22850
|
}
|
|
22764
22851
|
return seg;
|
|
22765
22852
|
}
|
|
22766
|
-
function tomlBlock(
|
|
22767
|
-
let out = "[" +
|
|
22853
|
+
function tomlBlock(path7, value) {
|
|
22854
|
+
let out = "[" + path7.map(tomlHeaderKey).join(".") + "]\n";
|
|
22768
22855
|
const subs = [];
|
|
22769
22856
|
for (const [k, v] of Object.entries(value)) {
|
|
22770
|
-
if (isPlainObject3(v)) subs.push(tomlBlock([...
|
|
22857
|
+
if (isPlainObject3(v)) subs.push(tomlBlock([...path7, k], v));
|
|
22771
22858
|
else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
|
|
22772
22859
|
}
|
|
22773
22860
|
return [out, ...subs].join("\n");
|
|
22774
22861
|
}
|
|
22775
|
-
function under(
|
|
22776
|
-
return
|
|
22862
|
+
function under(path7, prefix) {
|
|
22863
|
+
return path7.length >= prefix.length && prefix.every((seg, k) => path7[k] === seg);
|
|
22777
22864
|
}
|
|
22778
22865
|
function keyLineRange(text, k) {
|
|
22779
22866
|
const ls = lineStartOf(text, k.start);
|
|
@@ -22790,10 +22877,10 @@ function withValueAt(root, rel, value) {
|
|
|
22790
22877
|
else base[rel[0]] = next;
|
|
22791
22878
|
return base;
|
|
22792
22879
|
}
|
|
22793
|
-
function replaceToml(text, doc,
|
|
22794
|
-
const block = value === void 0 ? "" : tomlBlock(
|
|
22795
|
-
const owned = doc.tables.filter((t) => under(t.path,
|
|
22796
|
-
const cuts = doc.keys.filter((k) => under(k.full,
|
|
22880
|
+
function replaceToml(text, doc, path7, value) {
|
|
22881
|
+
const block = value === void 0 ? "" : tomlBlock(path7, value);
|
|
22882
|
+
const owned = doc.tables.filter((t) => under(t.path, path7));
|
|
22883
|
+
const cuts = doc.keys.filter((k) => under(k.full, path7) && !under(k.base, path7)).map((k) => [...keyLineRange(text, k), ""]);
|
|
22797
22884
|
owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
|
|
22798
22885
|
cuts.sort((a, b) => b[0] - a[0]);
|
|
22799
22886
|
let out = text;
|
|
@@ -22803,27 +22890,27 @@ function replaceToml(text, doc, path5, value) {
|
|
|
22803
22890
|
return out + sep4 + block;
|
|
22804
22891
|
}
|
|
22805
22892
|
var tableLike = (v) => v === void 0 || isPlainObject3(v);
|
|
22806
|
-
function setTomlText(text,
|
|
22893
|
+
function setTomlText(text, path7, value) {
|
|
22807
22894
|
if (value !== void 0 && !isPlainObject3(value)) throw new SyntaxError("TOML edits replace a whole table");
|
|
22808
22895
|
const doc = scanToml(text);
|
|
22809
|
-
const cur = hostConfigValueAt(doc.value,
|
|
22896
|
+
const cur = hostConfigValueAt(doc.value, path7);
|
|
22810
22897
|
if (sameValue(cur, value)) return text;
|
|
22811
|
-
const inline = doc.keys.find((k) => k.inline && k.full.length <
|
|
22898
|
+
const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
|
|
22812
22899
|
if (inline !== void 0) {
|
|
22813
|
-
const whole = withValueAt(hostConfigValueAt(doc.value, inline.full),
|
|
22900
|
+
const whole = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
|
|
22814
22901
|
return replaceToml(text, doc, inline.full, whole);
|
|
22815
22902
|
}
|
|
22816
22903
|
if (isPlainObject3(cur) && isPlainObject3(value)) {
|
|
22817
22904
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
22818
22905
|
if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
|
|
22819
22906
|
let out = text;
|
|
22820
|
-
for (const k of names) out = setTomlText(out, [...
|
|
22907
|
+
for (const k of names) out = setTomlText(out, [...path7, k], value[k]);
|
|
22821
22908
|
return out;
|
|
22822
22909
|
}
|
|
22823
22910
|
}
|
|
22824
|
-
return replaceToml(text, doc,
|
|
22911
|
+
return replaceToml(text, doc, path7, value);
|
|
22825
22912
|
}
|
|
22826
|
-
function setText(agent,
|
|
22913
|
+
function setText(agent, path7, text, format, key, value) {
|
|
22827
22914
|
try {
|
|
22828
22915
|
if (format !== "toml") return setJsonText(text, format, key, value);
|
|
22829
22916
|
const out = setTomlText(text, key, value);
|
|
@@ -22832,11 +22919,11 @@ function setText(agent, path5, text, format, key, value) {
|
|
|
22832
22919
|
if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
|
|
22833
22920
|
return out;
|
|
22834
22921
|
} catch {
|
|
22835
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
22922
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path7, format });
|
|
22836
22923
|
}
|
|
22837
22924
|
}
|
|
22838
22925
|
function serverScript() {
|
|
22839
|
-
return join8(
|
|
22926
|
+
return join8(dirname5(process.argv[1] ?? ""), SERVER_ENTRY_FILE);
|
|
22840
22927
|
}
|
|
22841
22928
|
function isNodeCommand(command) {
|
|
22842
22929
|
if (typeof command !== "string") return false;
|
|
@@ -22852,7 +22939,7 @@ function ownMcpValue(agent, node, server2) {
|
|
|
22852
22939
|
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node, [MCP_ARGS_FIELD]: [server2, AGENT_ARG, agent, ...tail] };
|
|
22853
22940
|
}
|
|
22854
22941
|
function opencodePluginFile() {
|
|
22855
|
-
return
|
|
22942
|
+
return dirname5(process.argv[1] ?? "");
|
|
22856
22943
|
}
|
|
22857
22944
|
function listTarget(key, own2, v1, alt = []) {
|
|
22858
22945
|
return {
|
|
@@ -22879,14 +22966,14 @@ function ownTargets(agent, accept) {
|
|
|
22879
22966
|
if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
|
|
22880
22967
|
return [];
|
|
22881
22968
|
}
|
|
22882
|
-
function applyEdits(agent,
|
|
22883
|
-
const parsed = parseHostConfig(agent,
|
|
22969
|
+
function applyEdits(agent, path7, text, format, wanted) {
|
|
22970
|
+
const parsed = parseHostConfig(agent, path7, text, format);
|
|
22884
22971
|
let out = text;
|
|
22885
22972
|
const edits = [];
|
|
22886
22973
|
for (const [key, after] of wanted) {
|
|
22887
22974
|
const before = hostConfigValueAt(parsed, key);
|
|
22888
22975
|
if (sameValue(before, after)) continue;
|
|
22889
|
-
out = setText(agent,
|
|
22976
|
+
out = setText(agent, path7, out, format, key, after);
|
|
22890
22977
|
edits.push({ path: key.join("."), before, after });
|
|
22891
22978
|
}
|
|
22892
22979
|
return { text: out, format, edits };
|
|
@@ -22907,7 +22994,7 @@ function writeHostConfigEdit(_requested, current, patch) {
|
|
|
22907
22994
|
// src/core/ops/detect-v1.ts
|
|
22908
22995
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
22909
22996
|
var keyPath = (...parts) => parts.join(".");
|
|
22910
|
-
var finding = (file2,
|
|
22997
|
+
var finding = (file2, path7, reason) => ({ file: file2, path: path7, reason });
|
|
22911
22998
|
function stripJsonc(text) {
|
|
22912
22999
|
let out = "";
|
|
22913
23000
|
let inStr = false;
|
|
@@ -23212,20 +23299,23 @@ function detectV1(agent, home, scope = {}) {
|
|
|
23212
23299
|
|
|
23213
23300
|
// src/core/ops/plugin-root.ts
|
|
23214
23301
|
import { existsSync as existsSync5, readdirSync as readdirSync2, readFileSync as readFileSync8, realpathSync as realpathSync4 } from "node:fs";
|
|
23215
|
-
import { dirname as
|
|
23302
|
+
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join10, sep as sep3 } from "node:path";
|
|
23216
23303
|
import { fileURLToPath } from "node:url";
|
|
23217
|
-
function missing(agent,
|
|
23218
|
-
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path:
|
|
23304
|
+
function missing(agent, path7) {
|
|
23305
|
+
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path7 });
|
|
23219
23306
|
}
|
|
23220
|
-
|
|
23221
|
-
let parsed;
|
|
23307
|
+
var parseOrNull = (text) => {
|
|
23222
23308
|
try {
|
|
23223
|
-
|
|
23309
|
+
return JSON.parse(hostText(text));
|
|
23224
23310
|
} catch {
|
|
23225
|
-
return
|
|
23311
|
+
return null;
|
|
23226
23312
|
}
|
|
23227
|
-
|
|
23228
|
-
|
|
23313
|
+
};
|
|
23314
|
+
var isRecord3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23315
|
+
function recordedInstalls(text) {
|
|
23316
|
+
const parsed = parseOrNull(text);
|
|
23317
|
+
const plugins = isRecord3(parsed) ? parsed.plugins : void 0;
|
|
23318
|
+
if (!isRecord3(plugins)) return [];
|
|
23229
23319
|
const out = [];
|
|
23230
23320
|
for (const key of Object.keys(plugins)) {
|
|
23231
23321
|
const at2 = key.indexOf(PLUGIN_KEY_SEPARATOR);
|
|
@@ -23233,39 +23323,77 @@ function recordedInstallPaths(text) {
|
|
|
23233
23323
|
const entries = plugins[key];
|
|
23234
23324
|
if (!Array.isArray(entries)) continue;
|
|
23235
23325
|
for (const e of entries) {
|
|
23236
|
-
|
|
23237
|
-
|
|
23326
|
+
if (!isRecord3(e) || typeof e.installPath !== "string" || e.installPath === "") continue;
|
|
23327
|
+
const scope = typeof e.scope === "string" ? e.scope : DEFAULT_PLUGIN_SCOPE;
|
|
23328
|
+
const projectPath = typeof e.projectPath === "string" ? e.projectPath : void 0;
|
|
23329
|
+
out.push({ key, scope, projectPath, installPath: e.installPath });
|
|
23238
23330
|
}
|
|
23239
23331
|
}
|
|
23240
23332
|
return out;
|
|
23241
23333
|
}
|
|
23242
|
-
var realOrNull = (
|
|
23334
|
+
var realOrNull = (path7) => {
|
|
23243
23335
|
try {
|
|
23244
|
-
return realpathSync4.native(
|
|
23336
|
+
return realpathSync4.native(path7);
|
|
23245
23337
|
} catch {
|
|
23246
23338
|
return null;
|
|
23247
23339
|
}
|
|
23248
23340
|
};
|
|
23249
|
-
|
|
23250
|
-
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23251
|
-
const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
23252
|
-
const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23253
|
-
const script = process.argv[1];
|
|
23254
|
-
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname5(script));
|
|
23255
|
-
let record4 = null;
|
|
23341
|
+
var readOrNull = (file2) => {
|
|
23256
23342
|
try {
|
|
23257
|
-
|
|
23343
|
+
return readFileSync8(file2, "utf8");
|
|
23258
23344
|
} catch {
|
|
23259
|
-
|
|
23345
|
+
return null;
|
|
23260
23346
|
}
|
|
23261
|
-
|
|
23262
|
-
|
|
23263
|
-
|
|
23264
|
-
|
|
23265
|
-
|
|
23266
|
-
|
|
23267
|
-
|
|
23347
|
+
};
|
|
23348
|
+
var samePath = (a, b) => a === b || (realOrNull(a) ?? a) === (realOrNull(b) ?? b);
|
|
23349
|
+
function enabledPlugins(claudeDir, project) {
|
|
23350
|
+
const files = [join10(claudeDir, SETTINGS_FILE)];
|
|
23351
|
+
if (project !== void 0) files.push(join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_FILE), join10(project, HOST_CONFIG_DIR_NAME, SETTINGS_LOCAL_FILE));
|
|
23352
|
+
const out = {};
|
|
23353
|
+
for (const file2 of files) {
|
|
23354
|
+
const text = readOrNull(file2);
|
|
23355
|
+
const doc = text === null ? null : parseOrNull(text);
|
|
23356
|
+
const on = isRecord3(doc) ? doc[ENABLED_PLUGINS_KEY] : void 0;
|
|
23357
|
+
if (isRecord3(on)) Object.assign(out, on);
|
|
23268
23358
|
}
|
|
23359
|
+
return out;
|
|
23360
|
+
}
|
|
23361
|
+
function marketplaceChoice(env, worktree) {
|
|
23362
|
+
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23363
|
+
const script = process.argv[1];
|
|
23364
|
+
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
|
|
23365
|
+
const hostRoot = env[CLAUDE_PLUGIN_ROOT_ENV];
|
|
23366
|
+
if (ownReal !== null && hostRoot !== void 0 && hostRoot !== "" && realOrNull(hostRoot) === ownReal) return { root: ownReal };
|
|
23367
|
+
const record4 = readOrNull(join10(claudeDir, HOST_PLUGINS_DIR_NAME, INSTALLED_PLUGINS_FILE));
|
|
23368
|
+
const recorded = record4 === null ? [] : recordedInstalls(record4);
|
|
23369
|
+
if (recorded.length === 0) return { record: false };
|
|
23370
|
+
const live = recorded.filter((r) => existsSync5(r.installPath));
|
|
23371
|
+
const mine = live.find((r) => realOrNull(r.installPath) === ownReal);
|
|
23372
|
+
if (mine !== void 0) return { root: mine.installPath };
|
|
23373
|
+
const dirs = live.filter((r, i) => live.findIndex((o) => samePath(o.installPath, r.installPath)) === i);
|
|
23374
|
+
if (dirs.length === 1) return { root: dirs[0].installPath };
|
|
23375
|
+
const projectEnv = env[CLAUDE_PROJECT_DIR_ENV];
|
|
23376
|
+
const project = worktree ?? (projectEnv === void 0 || projectEnv === "" ? void 0 : projectEnv);
|
|
23377
|
+
const on = enabledPlugins(claudeDir, project);
|
|
23378
|
+
const applies = (r) => !PROJECT_PLUGIN_SCOPES.includes(r.scope) || project !== void 0 && r.projectPath !== void 0 && samePath(r.projectPath, project);
|
|
23379
|
+
const rank = (r) => PLUGIN_SCOPE_RANK[r.scope] ?? PLUGIN_SCOPE_RANK[DEFAULT_PLUGIN_SCOPE];
|
|
23380
|
+
const used = live.filter((r) => on[r.key] === true && applies(r));
|
|
23381
|
+
if (used.length > 0) {
|
|
23382
|
+
const best = Math.min(...used.map(rank));
|
|
23383
|
+
const top = used.filter((r) => rank(r) === best);
|
|
23384
|
+
if (top.every((r) => samePath(r.installPath, top[0].installPath))) return { root: top[0].installPath };
|
|
23385
|
+
}
|
|
23386
|
+
return { installs: live.length === 0 ? recorded : live };
|
|
23387
|
+
}
|
|
23388
|
+
function marketplaceRoot(adapter, env, worktree) {
|
|
23389
|
+
const claudeDir = claudeDirOf(env, requireHomeDir(env));
|
|
23390
|
+
const plugins = join10(claudeDir, HOST_PLUGINS_DIR_NAME);
|
|
23391
|
+
const cache = join10(plugins, PLUGIN_CACHE_DIR_NAME);
|
|
23392
|
+
const script = process.argv[1];
|
|
23393
|
+
const ownReal = script === void 0 || script === "" ? null : realOrNull(dirname6(script));
|
|
23394
|
+
const choice = marketplaceChoice(env, worktree);
|
|
23395
|
+
if ("root" in choice) return choice.root;
|
|
23396
|
+
if ("installs" in choice) throw missing(adapter.id, choice.installs.map((r) => r.installPath).join(", "));
|
|
23269
23397
|
const cacheReal = realOrNull(cache);
|
|
23270
23398
|
if (ownReal !== null && cacheReal !== null && ownReal.startsWith(cacheReal + sep3) && existsSync5(join10(ownReal, SERVER_ENTRY_FILE))) return ownReal;
|
|
23271
23399
|
const pattern = join10(cache, "*", PLUGIN_NAME);
|
|
@@ -23284,12 +23412,12 @@ function configEntryRoot(adapter, env) {
|
|
|
23284
23412
|
const args = hostConfigValueAt(value, [...spec.key, MCP_ARGS_FIELD]);
|
|
23285
23413
|
const script = Array.isArray(args) ? args[0] : void 0;
|
|
23286
23414
|
if (typeof script !== "string" || !isAbsolute2(script)) throw missing(adapter.id, file2);
|
|
23287
|
-
return
|
|
23415
|
+
return dirname6(script);
|
|
23288
23416
|
}
|
|
23289
|
-
function candidate(adapter, env) {
|
|
23417
|
+
function candidate(adapter, env, worktree) {
|
|
23290
23418
|
switch (adapter.installMode) {
|
|
23291
23419
|
case "marketplace":
|
|
23292
|
-
return marketplaceRoot(adapter, env);
|
|
23420
|
+
return marketplaceRoot(adapter, env, worktree);
|
|
23293
23421
|
case "config-mcp":
|
|
23294
23422
|
case "mcp-entry":
|
|
23295
23423
|
case "hooks+mcp":
|
|
@@ -23299,15 +23427,15 @@ function candidate(adapter, env) {
|
|
|
23299
23427
|
case "plugin":
|
|
23300
23428
|
return join10(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, adapter.id, PLUGIN_CURRENT_LINK);
|
|
23301
23429
|
case "in-process":
|
|
23302
|
-
return
|
|
23430
|
+
return dirname6(fileURLToPath(import.meta.url));
|
|
23303
23431
|
}
|
|
23304
23432
|
}
|
|
23305
|
-
function resolvePluginRoot(adapter, env) {
|
|
23306
|
-
const
|
|
23433
|
+
function resolvePluginRoot(adapter, env, worktree) {
|
|
23434
|
+
const path7 = candidate(adapter, env, worktree);
|
|
23307
23435
|
try {
|
|
23308
|
-
return realpathSync4.native(
|
|
23436
|
+
return realpathSync4.native(path7);
|
|
23309
23437
|
} catch {
|
|
23310
|
-
throw missing(adapter.id,
|
|
23438
|
+
throw missing(adapter.id, path7);
|
|
23311
23439
|
}
|
|
23312
23440
|
}
|
|
23313
23441
|
|
|
@@ -23434,13 +23562,13 @@ function nativeMcpWrong(dir, row5) {
|
|
|
23434
23562
|
return true;
|
|
23435
23563
|
}
|
|
23436
23564
|
}
|
|
23437
|
-
function mcpWrong(row5, home, env) {
|
|
23565
|
+
function mcpWrong(row5, home, env, worktree) {
|
|
23438
23566
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23439
23567
|
if (native !== null) return nativeMcpWrong(native, row5);
|
|
23440
23568
|
const file2 = mcpFile(row5, home, env);
|
|
23441
23569
|
try {
|
|
23442
23570
|
if (file2 === null) {
|
|
23443
|
-
resolvePluginRoot(row5, env);
|
|
23571
|
+
resolvePluginRoot(row5, env, worktree);
|
|
23444
23572
|
return false;
|
|
23445
23573
|
}
|
|
23446
23574
|
const cur = readHostConfig(row5.id, file2);
|
|
@@ -23454,7 +23582,7 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23454
23582
|
if (spec === null) return [];
|
|
23455
23583
|
let block;
|
|
23456
23584
|
try {
|
|
23457
|
-
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
23585
|
+
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
23458
23586
|
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23459
23587
|
const file2 = native !== null ? join11(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join11(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join11(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join11(kiroDirOf(env, home), ...spec.file.slice(1)) : join11(root, ...spec.file);
|
|
23460
23588
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
@@ -23489,7 +23617,11 @@ function hookParts(row5, home, env, worktree) {
|
|
|
23489
23617
|
function checkHostConfig(row5, env, worktree) {
|
|
23490
23618
|
const home = homeDirOf(env);
|
|
23491
23619
|
if (home === null) return fail2("D3", D3_DETAIL(D3_PARTS), DOCTOR_FIX_UPGRADE);
|
|
23492
|
-
|
|
23620
|
+
if (row5.installMode === "marketplace") {
|
|
23621
|
+
const choice = marketplaceChoice(env, worktree);
|
|
23622
|
+
if ("installs" in choice) return fail2("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
23623
|
+
}
|
|
23624
|
+
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
23493
23625
|
const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
23494
23626
|
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
23495
23627
|
const detail = D3_DETAIL(parts);
|
|
@@ -23538,8 +23670,8 @@ async function loadSqlite2() {
|
|
|
23538
23670
|
return null;
|
|
23539
23671
|
}
|
|
23540
23672
|
}
|
|
23541
|
-
function openRead(sqlite,
|
|
23542
|
-
return new sqlite.DatabaseSync(
|
|
23673
|
+
function openRead(sqlite, path7) {
|
|
23674
|
+
return new sqlite.DatabaseSync(path7, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
23543
23675
|
}
|
|
23544
23676
|
var cell = (row5) => Object.values(row5)[0];
|
|
23545
23677
|
function readSchema(raw) {
|
|
@@ -23681,17 +23813,229 @@ function checkShell(env) {
|
|
|
23681
23813
|
}
|
|
23682
23814
|
|
|
23683
23815
|
// src/core/ops/doctor-hook.ts
|
|
23684
|
-
import { existsSync as
|
|
23816
|
+
import { existsSync as existsSync10, readFileSync as readFileSync9, realpathSync as realpathSync7 } from "node:fs";
|
|
23817
|
+
import path6 from "node:path";
|
|
23818
|
+
|
|
23819
|
+
// src/setup/codex-trust.ts
|
|
23820
|
+
import { createHash } from "node:crypto";
|
|
23821
|
+
import { existsSync as existsSync9, realpathSync as realpathSync6 } from "node:fs";
|
|
23822
|
+
import path5 from "node:path";
|
|
23823
|
+
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
23824
|
+
|
|
23825
|
+
// src/setup/spawn-bin.ts
|
|
23826
|
+
import { spawnSync } from "node:child_process";
|
|
23827
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync5 } from "node:fs";
|
|
23685
23828
|
import path4 from "node:path";
|
|
23829
|
+
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
23830
|
+
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
23831
|
+
var DEFAULT_COMSPEC = "cmd.exe";
|
|
23832
|
+
function envGet(env, k) {
|
|
23833
|
+
return env[Object.keys(env).find((x) => x.toUpperCase() === k) ?? k];
|
|
23834
|
+
}
|
|
23835
|
+
function whichBin(bin, env, platform = process.platform) {
|
|
23836
|
+
const get = (k) => envGet(env, k);
|
|
23837
|
+
const win = platform === "win32";
|
|
23838
|
+
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
23839
|
+
const names = win && path4.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
23840
|
+
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
23841
|
+
for (const n of names) {
|
|
23842
|
+
const f = path4.join(dir, n);
|
|
23843
|
+
try {
|
|
23844
|
+
accessSync2(f, fsc.X_OK);
|
|
23845
|
+
if (statSync5(f).isFile()) return f;
|
|
23846
|
+
} catch {
|
|
23847
|
+
}
|
|
23848
|
+
}
|
|
23849
|
+
}
|
|
23850
|
+
return void 0;
|
|
23851
|
+
}
|
|
23852
|
+
var CMD_QUOTE_CHARS = '"&|<>^()!';
|
|
23853
|
+
var CMD_PERCENT = "%";
|
|
23854
|
+
var CMD_SUBSTRING_MARK = ":";
|
|
23855
|
+
var CMD_DYNAMIC_VARS = Object.freeze(["CD", "DATE", "TIME", "RANDOM", "ERRORLEVEL", "CMDEXTVERSION", "CMDCMDLINE", "HIGHESTNUMANODENUMBER"]);
|
|
23856
|
+
function needsCmdQuotes(a) {
|
|
23857
|
+
if (a === "") return true;
|
|
23858
|
+
for (const c of a) if (c.trim() === "" || CMD_QUOTE_CHARS.includes(c)) return true;
|
|
23859
|
+
return false;
|
|
23860
|
+
}
|
|
23861
|
+
function expandablePercent(text, env) {
|
|
23862
|
+
const names = new Set(CMD_DYNAMIC_VARS);
|
|
23863
|
+
for (const k of Object.keys(env)) names.add(k.toUpperCase());
|
|
23864
|
+
for (let i = text.indexOf(CMD_PERCENT); i >= 0; i = text.indexOf(CMD_PERCENT, i + 1)) {
|
|
23865
|
+
for (let j = text.indexOf(CMD_PERCENT, i + 1); j >= 0; j = text.indexOf(CMD_PERCENT, j + 1)) {
|
|
23866
|
+
const inner = text.slice(i + 1, j);
|
|
23867
|
+
const cut = inner.indexOf(CMD_SUBSTRING_MARK);
|
|
23868
|
+
const name = cut < 0 ? inner : inner.slice(0, cut);
|
|
23869
|
+
if (name !== "" && names.has(name.toUpperCase())) return `${CMD_PERCENT}${inner}${CMD_PERCENT}`;
|
|
23870
|
+
}
|
|
23871
|
+
}
|
|
23872
|
+
return void 0;
|
|
23873
|
+
}
|
|
23874
|
+
function winCmdLine(file2, args, env = {}) {
|
|
23875
|
+
for (const a of [file2, ...args]) {
|
|
23876
|
+
const hit = expandablePercent(a, env);
|
|
23877
|
+
if (hit !== void 0) throw new Error(`cannot run ${file2} through cmd.exe: cmd.exe expands ${hit} inside quotes, so the value ${JSON.stringify(a)} would change. Use a path and arguments without it`);
|
|
23878
|
+
}
|
|
23879
|
+
const q = (a) => needsCmdQuotes(a) ? `"${a.split('"').join('""')}"` : a;
|
|
23880
|
+
return `"${[file2, ...args].map(q).join(" ")}"`;
|
|
23881
|
+
}
|
|
23882
|
+
function spawnForm(file2, args, env, platform = process.platform) {
|
|
23883
|
+
if (platform === "win32" && WIN_SHIM_EXTS.includes(path4.extname(file2).toLowerCase())) {
|
|
23884
|
+
return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
|
|
23885
|
+
}
|
|
23886
|
+
return { command: file2, args, windowsVerbatimArguments: false };
|
|
23887
|
+
}
|
|
23888
|
+
|
|
23889
|
+
// src/setup/codex-trust.ts
|
|
23890
|
+
var isObj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23891
|
+
var TRUST_KEY = ["hooks", "state"];
|
|
23892
|
+
var CODEX_TRUST_PATH = TRUST_KEY.join(".") + ".";
|
|
23893
|
+
var WIN_VERBATIM_PREFIX = "\\\\?\\";
|
|
23894
|
+
function codexHomeFromReply(out) {
|
|
23895
|
+
for (const line of out.split("\n")) {
|
|
23896
|
+
let m;
|
|
23897
|
+
try {
|
|
23898
|
+
m = JSON.parse(line);
|
|
23899
|
+
} catch {
|
|
23900
|
+
continue;
|
|
23901
|
+
}
|
|
23902
|
+
if (isObj2(m) && isObj2(m.result) && typeof m.result.codexHome === "string" && m.result.codexHome !== "") return m.result.codexHome;
|
|
23903
|
+
}
|
|
23904
|
+
return void 0;
|
|
23905
|
+
}
|
|
23906
|
+
function sameDir(a, b, platform = process.platform) {
|
|
23907
|
+
if (platform !== "win32") return path5.posix.normalize(a) === path5.posix.normalize(b);
|
|
23908
|
+
const norm2 = (p) => {
|
|
23909
|
+
const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
|
|
23910
|
+
const n = path5.win32.normalize(bare2).toLowerCase();
|
|
23911
|
+
return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
|
|
23912
|
+
};
|
|
23913
|
+
return norm2(a) === norm2(b);
|
|
23914
|
+
}
|
|
23915
|
+
var LIST_TIMEOUT_MS = 15e3;
|
|
23916
|
+
var EXIT_GRACE_MS = 5e3;
|
|
23917
|
+
var PLUGIN_SOURCE = "plugin";
|
|
23918
|
+
var TRUSTED = "trusted";
|
|
23919
|
+
function pluginHooksFromReply(m, pluginId) {
|
|
23920
|
+
const out = [];
|
|
23921
|
+
if (!isObj2(m) || !isObj2(m.result) || !Array.isArray(m.result.data)) return out;
|
|
23922
|
+
for (const d of m.result.data) {
|
|
23923
|
+
if (!isObj2(d) || !Array.isArray(d.hooks)) continue;
|
|
23924
|
+
for (const h of d.hooks) {
|
|
23925
|
+
if (!isObj2(h) || h.source !== PLUGIN_SOURCE || h.pluginId !== pluginId) continue;
|
|
23926
|
+
if (typeof h.key !== "string" || typeof h.currentHash !== "string") continue;
|
|
23927
|
+
if (out.some((x) => x.key === h.key)) continue;
|
|
23928
|
+
out.push({ key: h.key, hash: h.currentHash, trusted: h.trustStatus === TRUSTED });
|
|
23929
|
+
}
|
|
23930
|
+
}
|
|
23931
|
+
return out;
|
|
23932
|
+
}
|
|
23933
|
+
function askPluginHooks(env, pluginId, cwd) {
|
|
23934
|
+
const bin = whichBin("codex", env);
|
|
23935
|
+
if (!bin) return Promise.resolve({ kind: "absent" });
|
|
23936
|
+
return new Promise((resolve8) => {
|
|
23937
|
+
let asked;
|
|
23938
|
+
const done_ = (hooks) => hooks === void 0 ? { kind: "silent" } : { kind: "list", hooks, codexHome: asked };
|
|
23939
|
+
let f;
|
|
23940
|
+
try {
|
|
23941
|
+
f = spawnForm(bin, ["app-server"], env);
|
|
23942
|
+
} catch {
|
|
23943
|
+
resolve8({ kind: "silent" });
|
|
23944
|
+
return;
|
|
23945
|
+
}
|
|
23946
|
+
const child = spawn2(f.command, f.args, { env, cwd, stdio: ["pipe", "pipe", "ignore"], windowsVerbatimArguments: f.windowsVerbatimArguments, windowsHide: true });
|
|
23947
|
+
let buf = "";
|
|
23948
|
+
let done = false;
|
|
23949
|
+
let exited = false;
|
|
23950
|
+
let result;
|
|
23951
|
+
const settle = () => {
|
|
23952
|
+
clearTimeout(grace);
|
|
23953
|
+
resolve8(done_(result));
|
|
23954
|
+
};
|
|
23955
|
+
let grace;
|
|
23956
|
+
const finish2 = (v) => {
|
|
23957
|
+
if (done) return;
|
|
23958
|
+
done = true;
|
|
23959
|
+
clearTimeout(timer);
|
|
23960
|
+
result = v;
|
|
23961
|
+
child.stdin.destroy();
|
|
23962
|
+
if (exited) {
|
|
23963
|
+
settle();
|
|
23964
|
+
return;
|
|
23965
|
+
}
|
|
23966
|
+
grace = setTimeout(settle, EXIT_GRACE_MS);
|
|
23967
|
+
stopTree(child.pid, () => child.kill());
|
|
23968
|
+
};
|
|
23969
|
+
const timer = setTimeout(() => finish2(void 0), LIST_TIMEOUT_MS);
|
|
23970
|
+
const send = (o) => {
|
|
23971
|
+
try {
|
|
23972
|
+
child.stdin.write(JSON.stringify(o) + "\n");
|
|
23973
|
+
} catch {
|
|
23974
|
+
finish2(void 0);
|
|
23975
|
+
}
|
|
23976
|
+
};
|
|
23977
|
+
child.on("error", () => finish2(void 0));
|
|
23978
|
+
child.on("close", () => {
|
|
23979
|
+
exited = true;
|
|
23980
|
+
if (done) settle();
|
|
23981
|
+
else finish2(void 0);
|
|
23982
|
+
});
|
|
23983
|
+
child.stdin.on("error", () => finish2(void 0));
|
|
23984
|
+
child.stdout.setEncoding("utf8");
|
|
23985
|
+
child.stdout.on("data", (d) => {
|
|
23986
|
+
buf += d;
|
|
23987
|
+
const lines = buf.split("\n");
|
|
23988
|
+
buf = lines.pop() ?? "";
|
|
23989
|
+
for (const line of lines) {
|
|
23990
|
+
let m;
|
|
23991
|
+
try {
|
|
23992
|
+
m = JSON.parse(line);
|
|
23993
|
+
} catch {
|
|
23994
|
+
continue;
|
|
23995
|
+
}
|
|
23996
|
+
if (!isObj2(m)) continue;
|
|
23997
|
+
if (m.id === 1) {
|
|
23998
|
+
asked = codexHomeFromReply(line);
|
|
23999
|
+
send({ method: "initialized" });
|
|
24000
|
+
send({ id: 2, method: "hooks/list", params: { cwds: [cwd] } });
|
|
24001
|
+
} else if (m.id === 2) finish2(pluginHooksFromReply(m, pluginId));
|
|
24002
|
+
}
|
|
24003
|
+
});
|
|
24004
|
+
send({ id: 1, method: "initialize", params: { clientInfo: { name: "context-mode-setup", version: "2.0.0" } } });
|
|
24005
|
+
});
|
|
24006
|
+
}
|
|
24007
|
+
function stopTree(pid, kill) {
|
|
24008
|
+
if (process.platform === "win32" && pid !== void 0) {
|
|
24009
|
+
try {
|
|
24010
|
+
spawnSync2("taskkill", ["/pid", String(pid), "/T", "/F"], { windowsHide: true, stdio: "ignore", timeout: 5e3 });
|
|
24011
|
+
} catch {
|
|
24012
|
+
}
|
|
24013
|
+
}
|
|
24014
|
+
kill();
|
|
24015
|
+
}
|
|
24016
|
+
var CODEX_PLUGIN_ID = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
24017
|
+
var CODEX_UNTRUSTED_FIX = "run: context-mode setup";
|
|
24018
|
+
function untrustedPluginHooksDetail(hooks) {
|
|
24019
|
+
const bad = hooks.filter((h) => !h.trusted);
|
|
24020
|
+
if (!bad.length) return void 0;
|
|
24021
|
+
return `codex lists ${bad.length} of ${hooks.length} context-mode plugin hooks untrusted, so they do not run; ${CODEX_UNTRUSTED_FIX}`;
|
|
24022
|
+
}
|
|
24023
|
+
|
|
24024
|
+
// src/core/ops/doctor-hook.ts
|
|
23686
24025
|
var D5_MIN_PAIRS = 3;
|
|
23687
24026
|
var D5_MAX_PAIRS = 9;
|
|
24027
|
+
var D5_CODEX_TRUST_FIX = "context-mode setup --agents codex";
|
|
24028
|
+
var D5_CODEX_ABSENT_DETAIL = (home) => `codex is not on PATH, so the trust of the context-mode plugin hooks in ${home} is not known`;
|
|
24029
|
+
var D5_CODEX_SILENT_DETAIL = (home) => `codex app-server gave no hooks/list answer for ${home} in time, so the context-mode plugin hooks are not known to run`;
|
|
24030
|
+
var D5_CODEX_OTHER_HOME_DETAIL = (asked, home) => `codex answers for ${asked}, but the context-mode plugin runs from ${home}`;
|
|
24031
|
+
var D5_CODEX_NONE_DETAIL = (home) => `codex lists no context-mode plugin hooks in ${home}, so they do not run`;
|
|
23688
24032
|
var row = (status, detail, fixCommand) => fixCommand === void 0 ? { id: "D5", label: DOCTOR_LABEL.D5, status, detail } : { id: "D5", label: DOCTOR_LABEL.D5, status, detail, fixCommand };
|
|
23689
24033
|
function isObject5(v) {
|
|
23690
24034
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
23691
24035
|
}
|
|
23692
24036
|
function loadFixture(bundleDir2, agent) {
|
|
23693
|
-
const file2 =
|
|
23694
|
-
if (!
|
|
24037
|
+
const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
24038
|
+
if (!existsSync10(file2)) return null;
|
|
23695
24039
|
let all;
|
|
23696
24040
|
try {
|
|
23697
24041
|
all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
|
|
@@ -23721,8 +24065,36 @@ function codexHookJournaled(db) {
|
|
|
23721
24065
|
if (db === null) return false;
|
|
23722
24066
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
23723
24067
|
}
|
|
24068
|
+
function realDir(p) {
|
|
24069
|
+
try {
|
|
24070
|
+
return realpathSync7(p);
|
|
24071
|
+
} catch {
|
|
24072
|
+
return p;
|
|
24073
|
+
}
|
|
24074
|
+
}
|
|
24075
|
+
async function codexPluginTrust(i) {
|
|
24076
|
+
const home = i.codexConfigDir;
|
|
24077
|
+
const plugin = codexPluginHomeOf(i.bundleDir) !== null;
|
|
24078
|
+
const reply4 = await askPluginHooks({ ...i.env, CODEX_HOME: home }, CODEX_PLUGIN_ID, i.worktree ?? i.bundleDir);
|
|
24079
|
+
if (reply4.kind === "list") {
|
|
24080
|
+
const detail = untrustedPluginHooksDetail(reply4.hooks);
|
|
24081
|
+
if (detail !== void 0) return row("FAIL", detail, D5_CODEX_TRUST_FIX);
|
|
24082
|
+
}
|
|
24083
|
+
if (!plugin) return null;
|
|
24084
|
+
if (reply4.kind === "absent") return row("UNKNOWN", D5_CODEX_ABSENT_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
24085
|
+
if (reply4.kind === "silent") return row("FAIL", D5_CODEX_SILENT_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
24086
|
+
if (reply4.codexHome !== void 0 && !sameDir(realDir(reply4.codexHome), realDir(home))) {
|
|
24087
|
+
return row("FAIL", D5_CODEX_OTHER_HOME_DETAIL(reply4.codexHome, home), D5_CODEX_TRUST_FIX);
|
|
24088
|
+
}
|
|
24089
|
+
if (reply4.hooks.length === 0) return row("FAIL", D5_CODEX_NONE_DETAIL(home), D5_CODEX_TRUST_FIX);
|
|
24090
|
+
return null;
|
|
24091
|
+
}
|
|
23724
24092
|
async function checkHookRoundTrip(i) {
|
|
23725
|
-
if (i.agent === "codex"
|
|
24093
|
+
if (i.agent === "codex") {
|
|
24094
|
+
const trust = await codexPluginTrust(i);
|
|
24095
|
+
if (trust !== null) return trust;
|
|
24096
|
+
}
|
|
24097
|
+
if (i.agent === "codex" && existsSync10(path6.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
23726
24098
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
23727
24099
|
}
|
|
23728
24100
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -23741,7 +24113,7 @@ async function checkHookRoundTrip(i) {
|
|
|
23741
24113
|
let ms = 0;
|
|
23742
24114
|
for (let n = 1; n <= maxPairs; n++) {
|
|
23743
24115
|
const start = now();
|
|
23744
|
-
const r = await runProcess([process.execPath,
|
|
24116
|
+
const r = await runProcess([process.execPath, path6.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
23745
24117
|
cwd: i.bundleDir,
|
|
23746
24118
|
env: i.env,
|
|
23747
24119
|
signal: i.signal,
|
|
@@ -23759,11 +24131,11 @@ async function checkHookRoundTrip(i) {
|
|
|
23759
24131
|
}
|
|
23760
24132
|
|
|
23761
24133
|
// src/core/ops/db-heal.ts
|
|
23762
|
-
import { existsSync as
|
|
24134
|
+
import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
|
|
23763
24135
|
|
|
23764
24136
|
// src/core/store/owners.ts
|
|
23765
24137
|
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync10, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
23766
|
-
import { basename as
|
|
24138
|
+
import { basename as basename3, join as join12 } from "node:path";
|
|
23767
24139
|
function ownersDir(configDir, projectKey) {
|
|
23768
24140
|
return join12(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23769
24141
|
}
|
|
@@ -23801,7 +24173,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
23801
24173
|
if (errCode2(err) === "ENOENT") continue;
|
|
23802
24174
|
throw err;
|
|
23803
24175
|
}
|
|
23804
|
-
const serverId =
|
|
24176
|
+
const serverId = basename3(name, OWNER_PID_EXT);
|
|
23805
24177
|
if (isLive(Number(text.trim()))) live.push(serverId);
|
|
23806
24178
|
else rmSync2(file2, { force: true });
|
|
23807
24179
|
}
|
|
@@ -23842,7 +24214,7 @@ function renameAside(dbPath) {
|
|
|
23842
24214
|
const ts = String(Date.now());
|
|
23843
24215
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
23844
24216
|
const file2 = dbPath + suffix;
|
|
23845
|
-
if (
|
|
24217
|
+
if (existsSync11(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
23846
24218
|
}
|
|
23847
24219
|
return ts;
|
|
23848
24220
|
}
|
|
@@ -23923,7 +24295,7 @@ async function guard(id2, run) {
|
|
|
23923
24295
|
}
|
|
23924
24296
|
}
|
|
23925
24297
|
async function codexDb(ctx, adapter) {
|
|
23926
|
-
if (adapter.id !== "codex" || !
|
|
24298
|
+
if (adapter.id !== "codex" || !existsSync12(ctx.project.dbPath)) return null;
|
|
23927
24299
|
try {
|
|
23928
24300
|
return await openDb(ctx.project, { readOnly: true });
|
|
23929
24301
|
} catch {
|
|
@@ -23941,7 +24313,7 @@ async function hookRow(ctx, adapter, host) {
|
|
|
23941
24313
|
env: buildChildEnv(host.env),
|
|
23942
24314
|
signal: ctx.signal,
|
|
23943
24315
|
codexConfigDir: codexDirOf(host.env, requireHomeDir(host.env)),
|
|
23944
|
-
//
|
|
24316
|
+
// = codexRunDirOf: runDoctorChecks sets CODEX_HOME for codex (D-CODEX-HOME-RUN-1)
|
|
23945
24317
|
db
|
|
23946
24318
|
});
|
|
23947
24319
|
const last2 = lastHookError(host.env);
|
|
@@ -23954,14 +24326,15 @@ async function hookRow(ctx, adapter, host) {
|
|
|
23954
24326
|
}
|
|
23955
24327
|
function ownServerId(configDir, projectKey) {
|
|
23956
24328
|
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
23957
|
-
if (!
|
|
24329
|
+
if (!existsSync12(dir)) return "";
|
|
23958
24330
|
for (const name of readdirSync5(dir)) {
|
|
23959
24331
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
23960
|
-
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return
|
|
24332
|
+
if (readFileSync11(join13(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
23961
24333
|
}
|
|
23962
24334
|
return "";
|
|
23963
24335
|
}
|
|
23964
|
-
async function runDoctorChecks(ctx, adapter,
|
|
24336
|
+
async function runDoctorChecks(ctx, adapter, host0) {
|
|
24337
|
+
const host = adapter.id === "codex" ? { ...host0, env: { ...host0.env, CODEX_HOME: codexRunDirOf(host0.env, homeDirOf(host0.env) ?? "", host0.bundleDir) } } : host0;
|
|
23965
24338
|
const env = host.env;
|
|
23966
24339
|
const project = ctx.project;
|
|
23967
24340
|
let integrityFailed = false;
|
|
@@ -24003,7 +24376,7 @@ function reportEnv(env) {
|
|
|
24003
24376
|
}
|
|
24004
24377
|
async function handler2(_input, ctx) {
|
|
24005
24378
|
const adapter = getAdapter(ctx.project.agent);
|
|
24006
|
-
const host = { env: process.env, bundleDir:
|
|
24379
|
+
const host = { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 };
|
|
24007
24380
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
24008
24381
|
const command = `context-mode ${rows.some((r) => r.status === "FAIL") ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
24009
24382
|
const input = { agent: adapter.id, rows, env: reportEnv(process.env), command };
|
|
@@ -24029,9 +24402,9 @@ var ctxDoctor = Object.freeze({
|
|
|
24029
24402
|
});
|
|
24030
24403
|
|
|
24031
24404
|
// src/core/tools/execute.ts
|
|
24032
|
-
import { existsSync as
|
|
24405
|
+
import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24033
24406
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24034
|
-
import { dirname as
|
|
24407
|
+
import { dirname as dirname8, join as join14, parse as parse3, resolve as resolve6 } from "node:path";
|
|
24035
24408
|
|
|
24036
24409
|
// src/core/sandbox/win-build.ts
|
|
24037
24410
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -24115,7 +24488,7 @@ function schemaLine(issue2) {
|
|
|
24115
24488
|
}
|
|
24116
24489
|
function fileError(given, abs, root) {
|
|
24117
24490
|
let dir = abs;
|
|
24118
|
-
while (!
|
|
24491
|
+
while (!existsSync13(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
24119
24492
|
if (isInside(root, dir)) return null;
|
|
24120
24493
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
24121
24494
|
}
|
|
@@ -24153,12 +24526,14 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
24153
24526
|
const fullBytes = Buffer.byteLength(combined, "utf8");
|
|
24154
24527
|
const head = summaryLine(exitCode, fullBytes);
|
|
24155
24528
|
const intent = input.intent ?? "";
|
|
24156
|
-
const
|
|
24157
|
-
|
|
24529
|
+
const bare2 = exitCode === 0 && input.summary !== true && combined !== "";
|
|
24530
|
+
const direct = (bare2 ? "" : head + "\n") + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined;
|
|
24531
|
+
const fits = Buffer.byteLength(head + "\n" + (input.summary === true ? echoBlock(input.language, input.code) + "\n" : "") + combined, "utf8") <= OUTPUT_CAP;
|
|
24532
|
+
if (intent === "" && fits) {
|
|
24158
24533
|
return { text: direct, isError, sandboxBytes: fullBytes, journal };
|
|
24159
24534
|
}
|
|
24160
24535
|
const label = sourceLabel(input.code);
|
|
24161
|
-
const budget = OUTPUT_CAP - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
|
|
24536
|
+
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label);
|
|
24162
24537
|
const db = await openDb(ctx.project);
|
|
24163
24538
|
let picked;
|
|
24164
24539
|
try {
|
|
@@ -24177,7 +24552,7 @@ async function handler3(raw, ctx) {
|
|
|
24177
24552
|
const cwd = ctx.project.worktree;
|
|
24178
24553
|
const extra = { ...PLAIN_OUTPUT_ENV2 };
|
|
24179
24554
|
if (input.file !== void 0) {
|
|
24180
|
-
const abs =
|
|
24555
|
+
const abs = resolve6(cwd, input.file);
|
|
24181
24556
|
const bad = fileError(input.file, abs, ctx.project.containmentRoot);
|
|
24182
24557
|
if (bad !== null) return fail5(bad);
|
|
24183
24558
|
extra.CTX_FILE = abs;
|
|
@@ -24230,16 +24605,16 @@ var ctxExecute = {
|
|
|
24230
24605
|
};
|
|
24231
24606
|
|
|
24232
24607
|
// src/core/tools/index.ts
|
|
24233
|
-
import { existsSync as
|
|
24234
|
-
import { dirname as
|
|
24608
|
+
import { existsSync as existsSync14, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
|
|
24609
|
+
import { dirname as dirname9, extname, join as join16, relative as relative3, resolve as resolve7 } from "node:path";
|
|
24235
24610
|
|
|
24236
24611
|
// src/core/index/walk.ts
|
|
24237
|
-
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as
|
|
24612
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync8, statSync as statSync6 } from "node:fs";
|
|
24238
24613
|
import { join as join15 } from "node:path";
|
|
24239
24614
|
var GITIGNORE = ".gitignore";
|
|
24240
24615
|
var GIT_DIR = ".git";
|
|
24241
24616
|
function walkDir(root, containmentRoot) {
|
|
24242
|
-
const real2 =
|
|
24617
|
+
const real2 = realpathSync8(root);
|
|
24243
24618
|
if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
24244
24619
|
const found = [];
|
|
24245
24620
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
@@ -24256,19 +24631,19 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24256
24631
|
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join15(abs, GITIGNORE), rel)) : parent;
|
|
24257
24632
|
for (const e of entries) {
|
|
24258
24633
|
if (e.name === GIT_DIR) continue;
|
|
24259
|
-
const
|
|
24634
|
+
const path7 = join15(abs, e.name);
|
|
24260
24635
|
let isDir = e.isDirectory();
|
|
24261
24636
|
let isFile = e.isFile();
|
|
24262
|
-
let target =
|
|
24637
|
+
let target = path7;
|
|
24263
24638
|
if (e.isSymbolicLink()) {
|
|
24264
24639
|
let resolved;
|
|
24265
24640
|
try {
|
|
24266
|
-
resolved =
|
|
24641
|
+
resolved = realpathSync8(path7);
|
|
24267
24642
|
} catch {
|
|
24268
24643
|
continue;
|
|
24269
24644
|
}
|
|
24270
24645
|
if (!isInside(contain, resolved)) continue;
|
|
24271
|
-
const st =
|
|
24646
|
+
const st = statSync6(resolved);
|
|
24272
24647
|
isDir = st.isDirectory();
|
|
24273
24648
|
isFile = st.isFile();
|
|
24274
24649
|
target = resolved;
|
|
@@ -24276,12 +24651,12 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24276
24651
|
const segs = rel.concat(e.name);
|
|
24277
24652
|
if (ignored(rules, segs, isDir)) continue;
|
|
24278
24653
|
if (isFile) {
|
|
24279
|
-
found.push({ dir: rel, name: e.name, absPath:
|
|
24654
|
+
found.push({ dir: rel, name: e.name, absPath: path7 });
|
|
24280
24655
|
} else if (isDir) {
|
|
24281
|
-
const key = e.isSymbolicLink() ? target :
|
|
24656
|
+
const key = e.isSymbolicLink() ? target : realpathSync8(path7);
|
|
24282
24657
|
if (seen.has(key)) continue;
|
|
24283
24658
|
seen.add(key);
|
|
24284
|
-
visit(
|
|
24659
|
+
visit(path7, segs, rules, contain, seen, found);
|
|
24285
24660
|
}
|
|
24286
24661
|
}
|
|
24287
24662
|
}
|
|
@@ -24472,19 +24847,19 @@ function tlsName(host) {
|
|
|
24472
24847
|
function request(u, conn, proxy, signal) {
|
|
24473
24848
|
const host = bare(u.hostname);
|
|
24474
24849
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
24475
|
-
const
|
|
24476
|
-
return new Promise((
|
|
24850
|
+
const path7 = u.pathname + u.search;
|
|
24851
|
+
return new Promise((resolve8, reject) => {
|
|
24477
24852
|
const onErr = (err) => reject(fail6(causeCode(err)));
|
|
24478
24853
|
if (proxy === void 0) {
|
|
24479
24854
|
const mod = u.protocol === "https:" ? https : http;
|
|
24480
|
-
const req = mod.request({ host: conn.address, port, path:
|
|
24481
|
-
req.on("response",
|
|
24855
|
+
const req = mod.request({ host: conn.address, port, path: path7, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
24856
|
+
req.on("response", resolve8).on("error", onErr).end();
|
|
24482
24857
|
return;
|
|
24483
24858
|
}
|
|
24484
24859
|
const proxyHeaders = proxy.auth === void 0 ? {} : { "proxy-authorization": proxy.auth };
|
|
24485
24860
|
if (u.protocol === "http:") {
|
|
24486
24861
|
const req = http.request({ host: conn.address, port: conn.port, path: u.href, signal, headers: { host: u.host, ...proxyHeaders } });
|
|
24487
|
-
req.on("response",
|
|
24862
|
+
req.on("response", resolve8).on("error", onErr).end();
|
|
24488
24863
|
return;
|
|
24489
24864
|
}
|
|
24490
24865
|
const authority = (isIP(host) === 6 ? "[" + host + "]" : host) + ":" + port;
|
|
@@ -24499,21 +24874,21 @@ function request(u, conn, proxy, signal) {
|
|
|
24499
24874
|
const req = https.request({
|
|
24500
24875
|
host,
|
|
24501
24876
|
port,
|
|
24502
|
-
path:
|
|
24877
|
+
path: path7,
|
|
24503
24878
|
signal,
|
|
24504
24879
|
headers: { host: u.host },
|
|
24505
24880
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
24506
24881
|
});
|
|
24507
|
-
req.on("response",
|
|
24882
|
+
req.on("response", resolve8).on("error", onErr).end();
|
|
24508
24883
|
});
|
|
24509
24884
|
tunnel.end();
|
|
24510
24885
|
});
|
|
24511
24886
|
}
|
|
24512
24887
|
function readBody(res) {
|
|
24513
|
-
return new Promise((
|
|
24888
|
+
return new Promise((resolve8, reject) => {
|
|
24514
24889
|
const parts = [];
|
|
24515
24890
|
res.on("data", (b) => parts.push(b));
|
|
24516
|
-
res.on("end", () =>
|
|
24891
|
+
res.on("end", () => resolve8(Buffer.concat(parts)));
|
|
24517
24892
|
res.on("error", (err) => reject(fail6(causeCode(err))));
|
|
24518
24893
|
res.on("aborted", () => reject(fail6("ECONNRESET")));
|
|
24519
24894
|
});
|
|
@@ -28386,23 +28761,23 @@ function readUtf8(absPath) {
|
|
|
28386
28761
|
}
|
|
28387
28762
|
function missingOrOutside(given, abs, root) {
|
|
28388
28763
|
let dir = abs;
|
|
28389
|
-
while (!
|
|
28764
|
+
while (!existsSync14(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
28390
28765
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
28391
28766
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
28392
28767
|
}
|
|
28393
28768
|
function pathItems(input, project) {
|
|
28394
|
-
const abs =
|
|
28769
|
+
const abs = resolve7(project.worktree, input.path);
|
|
28395
28770
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
28396
28771
|
const base = relative3(project.worktree, abs);
|
|
28397
|
-
if (
|
|
28772
|
+
if (statSync7(abs).isDirectory()) {
|
|
28398
28773
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
28399
28774
|
sourceKind: "path",
|
|
28400
|
-
label: join16(base, f.relPath),
|
|
28775
|
+
label: pathLabel(join16(base, f.relPath)),
|
|
28401
28776
|
kind: kindOfPath(f.relPath),
|
|
28402
28777
|
read: () => readUtf8(f.absPath)
|
|
28403
28778
|
}));
|
|
28404
28779
|
}
|
|
28405
|
-
return [{ sourceKind: "path", label: base === "" ? input.path : base, kind: kindOfPath(abs), read: () => readUtf8(abs) }];
|
|
28780
|
+
return [{ sourceKind: "path", label: pathLabel(base === "" ? input.path : base), kind: kindOfPath(abs), read: () => readUtf8(abs) }];
|
|
28406
28781
|
}
|
|
28407
28782
|
async function itemsOf(input, ctx) {
|
|
28408
28783
|
if (input.content !== void 0) {
|
|
@@ -28413,7 +28788,7 @@ async function itemsOf(input, ctx) {
|
|
|
28413
28788
|
}
|
|
28414
28789
|
if (input.path !== void 0) {
|
|
28415
28790
|
const items = pathItems({ ...input, path: input.path }, ctx.project);
|
|
28416
|
-
return { items, from: items.length === 1 ? items[0].label : input.path };
|
|
28791
|
+
return { items, from: items.length === 1 ? items[0].label : pathLabel(input.path) };
|
|
28417
28792
|
}
|
|
28418
28793
|
const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
|
|
28419
28794
|
const text = res.body.toString("utf8");
|
|
@@ -28510,10 +28885,11 @@ function scopesOf(input) {
|
|
|
28510
28885
|
function changes(raw, sql, ...args) {
|
|
28511
28886
|
return Number(raw.prepare(sql).run(...args).changes);
|
|
28512
28887
|
}
|
|
28513
|
-
function purgeScope(
|
|
28888
|
+
function purgeScope(db, scope, input) {
|
|
28889
|
+
const raw = db.raw;
|
|
28514
28890
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
28515
28891
|
if (scope === "source") {
|
|
28516
|
-
const label = input.source;
|
|
28892
|
+
const label = storedLabel(db, input.source);
|
|
28517
28893
|
return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?", label);
|
|
28518
28894
|
}
|
|
28519
28895
|
const chunks = deleteChunkRows(raw, "all");
|
|
@@ -28531,7 +28907,7 @@ async function handler5(input, ctx) {
|
|
|
28531
28907
|
try {
|
|
28532
28908
|
const db = await openDb(ctx.project);
|
|
28533
28909
|
try {
|
|
28534
|
-
const rows = withWrite(db, (h) => purgeScope(h
|
|
28910
|
+
const rows = withWrite(db, (h) => purgeScope(h, scope, input));
|
|
28535
28911
|
return reply2(PURGE_SUMMARY(rows, scope), false);
|
|
28536
28912
|
} finally {
|
|
28537
28913
|
closeDb(db);
|
|
@@ -28653,12 +29029,12 @@ var ctxStats = Object.freeze({
|
|
|
28653
29029
|
});
|
|
28654
29030
|
|
|
28655
29031
|
// src/core/tools/upgrade.ts
|
|
28656
|
-
import { existsSync as
|
|
28657
|
-
import { basename as
|
|
29032
|
+
import { existsSync as existsSync20, realpathSync as realpathSync9, rmSync as rmSync9 } from "node:fs";
|
|
29033
|
+
import { basename as basename6, dirname as dirname11, join as join22 } from "node:path";
|
|
28658
29034
|
|
|
28659
29035
|
// src/core/ops/host-write.ts
|
|
28660
|
-
import { copyFileSync, existsSync as
|
|
28661
|
-
import { dirname as
|
|
29036
|
+
import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
29037
|
+
import { dirname as dirname10, join as join17 } from "node:path";
|
|
28662
29038
|
function defaultWrite(file2, text) {
|
|
28663
29039
|
writeFileSync4(file2, text, "utf8");
|
|
28664
29040
|
}
|
|
@@ -28686,8 +29062,8 @@ function toRow(file2, edit) {
|
|
|
28686
29062
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
28687
29063
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
28688
29064
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
28689
|
-
const had =
|
|
28690
|
-
mkdirSync5(
|
|
29065
|
+
const had = existsSync15(file2);
|
|
29066
|
+
mkdirSync5(dirname10(file2), { recursive: true });
|
|
28691
29067
|
if (had) copyFileSync(file2, trash);
|
|
28692
29068
|
try {
|
|
28693
29069
|
write2(tmp, text);
|
|
@@ -28716,7 +29092,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28716
29092
|
if (requested === null) return [];
|
|
28717
29093
|
const current = readHostConfig(row5.id, requested);
|
|
28718
29094
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
28719
|
-
const exists =
|
|
29095
|
+
const exists = existsSync15(current.path);
|
|
28720
29096
|
if (exists && result.text === current.text) return [];
|
|
28721
29097
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
28722
29098
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -28724,15 +29100,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
28724
29100
|
}
|
|
28725
29101
|
|
|
28726
29102
|
// src/core/ops/plugin-swap.ts
|
|
28727
|
-
import { existsSync as
|
|
28728
|
-
import { basename as
|
|
28729
|
-
function linkTarget(
|
|
28730
|
-
if (!isLink(
|
|
28731
|
-
const target = readlinkSync(
|
|
29103
|
+
import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
29104
|
+
import { basename as basename5, join as join18, win32 as win322 } from "node:path";
|
|
29105
|
+
function linkTarget(path7, win) {
|
|
29106
|
+
if (!isLink(path7)) return null;
|
|
29107
|
+
const target = readlinkSync(path7);
|
|
28732
29108
|
return win ? win322.basename(target) : target;
|
|
28733
29109
|
}
|
|
28734
|
-
function isLink(
|
|
28735
|
-
return lstatSync(
|
|
29110
|
+
function isLink(path7) {
|
|
29111
|
+
return lstatSync(path7, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
28736
29112
|
}
|
|
28737
29113
|
function generations(agentDir) {
|
|
28738
29114
|
return readdirSync7(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
|
|
@@ -28745,8 +29121,8 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
28745
29121
|
}
|
|
28746
29122
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
28747
29123
|
const next = join18(agentDir, sha);
|
|
28748
|
-
if (!
|
|
28749
|
-
throw new CtxError("PLUGIN_ROOT_MISSING", { agent:
|
|
29124
|
+
if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
|
|
29125
|
+
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
28750
29126
|
}
|
|
28751
29127
|
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
28752
29128
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
@@ -28765,12 +29141,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
28765
29141
|
if (before !== null) keep.add(before);
|
|
28766
29142
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
28767
29143
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
28768
|
-
const previous = before !== null &&
|
|
29144
|
+
const previous = before !== null && existsSync16(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
28769
29145
|
return { current: next, previous, removed };
|
|
28770
29146
|
}
|
|
28771
29147
|
|
|
28772
29148
|
// src/core/ops/release-fetch.ts
|
|
28773
|
-
import { existsSync as
|
|
29149
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync6, rmSync as rmSync6 } from "node:fs";
|
|
28774
29150
|
import { join as join19 } from "node:path";
|
|
28775
29151
|
function failed(r) {
|
|
28776
29152
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -28794,7 +29170,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
28794
29170
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url2, fetchDir], agentDir, childEnv, signal);
|
|
28795
29171
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
28796
29172
|
const dir = join19(agentDir, sha);
|
|
28797
|
-
if (
|
|
29173
|
+
if (existsSync17(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
28798
29174
|
else renameWithRetry(fetchDir, dir, opts);
|
|
28799
29175
|
return { sha, dir };
|
|
28800
29176
|
} catch (e) {
|
|
@@ -28804,7 +29180,7 @@ async function fetchRelease(agent, url2, env, signal, opts = {}) {
|
|
|
28804
29180
|
}
|
|
28805
29181
|
|
|
28806
29182
|
// src/core/ops/uninstall.ts
|
|
28807
|
-
import { existsSync as
|
|
29183
|
+
import { existsSync as existsSync18, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
28808
29184
|
import { join as join20 } from "node:path";
|
|
28809
29185
|
function row2(area, before, after) {
|
|
28810
29186
|
return { area, before, after };
|
|
@@ -28829,12 +29205,16 @@ function removeCache(adapter, env, configDir) {
|
|
|
28829
29205
|
case "extension": {
|
|
28830
29206
|
const root = rootOrNull(adapter, env);
|
|
28831
29207
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29208
|
+
if (adapter.installMode === "marketplace") {
|
|
29209
|
+
const cache = join20(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
29210
|
+
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
29211
|
+
}
|
|
28832
29212
|
rmSync7(root, { recursive: true, force: true });
|
|
28833
29213
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
28834
29214
|
}
|
|
28835
29215
|
case "plugin": {
|
|
28836
29216
|
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
28837
|
-
if (!
|
|
29217
|
+
if (!existsSync18(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
28838
29218
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
28839
29219
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
28840
29220
|
}
|
|
@@ -28847,11 +29227,11 @@ function removeCache(adapter, env, configDir) {
|
|
|
28847
29227
|
}
|
|
28848
29228
|
}
|
|
28849
29229
|
}
|
|
28850
|
-
function
|
|
29230
|
+
function isObj3(v) {
|
|
28851
29231
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
28852
29232
|
}
|
|
28853
29233
|
function piSource(entry) {
|
|
28854
|
-
return
|
|
29234
|
+
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
28855
29235
|
}
|
|
28856
29236
|
function ownEntries(agent, env) {
|
|
28857
29237
|
const home = requireHomeDir(env);
|
|
@@ -28860,11 +29240,11 @@ function ownEntries(agent, env) {
|
|
|
28860
29240
|
const top = mcp.key[0];
|
|
28861
29241
|
const inner = mcp.key.slice(1, -1);
|
|
28862
29242
|
const own2 = mcp.key[mcp.key.length - 1];
|
|
28863
|
-
const holder = (v) => inner.reduce((cur, k) =>
|
|
28864
|
-
const without = (v,
|
|
29243
|
+
const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
|
|
29244
|
+
const without = (v, path7) => {
|
|
28865
29245
|
const o = v;
|
|
28866
|
-
if (
|
|
28867
|
-
return { ...o, [
|
|
29246
|
+
if (path7.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own2));
|
|
29247
|
+
return { ...o, [path7[0]]: without(o[path7[0]], path7.slice(1)) };
|
|
28868
29248
|
};
|
|
28869
29249
|
return [{
|
|
28870
29250
|
file: ownMcpFileOf(agent, mcp.file, env, home),
|
|
@@ -28872,7 +29252,7 @@ function ownEntries(agent, env) {
|
|
|
28872
29252
|
shown: mcp.key.join(V1_KEY_PATH_SEP),
|
|
28873
29253
|
has: (v) => {
|
|
28874
29254
|
const h = holder(v);
|
|
28875
|
-
return
|
|
29255
|
+
return isObj3(h) && Object.hasOwn(h, own2);
|
|
28876
29256
|
},
|
|
28877
29257
|
drop: (v) => without(v, inner)
|
|
28878
29258
|
}];
|
|
@@ -28914,7 +29294,7 @@ function removeOwnEntries(agent, env) {
|
|
|
28914
29294
|
function removeProjectData(configDir, projectKey) {
|
|
28915
29295
|
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
28916
29296
|
const dir = join20(projects, projectKey);
|
|
28917
|
-
if (!
|
|
29297
|
+
if (!existsSync18(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
28918
29298
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
28919
29299
|
for (const name of readdirSync8(dir)) {
|
|
28920
29300
|
if (name !== OWNERS_DIR_NAME) rmSync7(join20(dir, name), { recursive: true, force: true });
|
|
@@ -28930,8 +29310,8 @@ function runUninstall(input) {
|
|
|
28930
29310
|
}
|
|
28931
29311
|
|
|
28932
29312
|
// src/core/ops/v1-remove.ts
|
|
28933
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
28934
|
-
var
|
|
29313
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync19, readFileSync as readFileSync14, rmSync as rmSync8 } from "node:fs";
|
|
29314
|
+
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
28935
29315
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
28936
29316
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
28937
29317
|
function moveAside(target, undo) {
|
|
@@ -28960,17 +29340,17 @@ function cutTomlTable(text, header) {
|
|
|
28960
29340
|
function writeAtomic(file2, text) {
|
|
28961
29341
|
atomicWriteFile(file2, text);
|
|
28962
29342
|
}
|
|
28963
|
-
function locate(doc,
|
|
28964
|
-
const segs =
|
|
29343
|
+
function locate(doc, path7) {
|
|
29344
|
+
const segs = path7.split(V1_KEY_PATH_SEP);
|
|
28965
29345
|
let cur = doc;
|
|
28966
29346
|
for (const seg of segs.slice(0, -1)) {
|
|
28967
29347
|
if (Array.isArray(cur)) cur = cur[Number(seg)];
|
|
28968
|
-
else if (
|
|
29348
|
+
else if (isObj4(cur)) cur = cur[seg];
|
|
28969
29349
|
else return null;
|
|
28970
29350
|
}
|
|
28971
29351
|
const last2 = segs[segs.length - 1];
|
|
28972
29352
|
if (Array.isArray(cur)) return Number(last2) < cur.length ? [cur, last2] : null;
|
|
28973
|
-
if (
|
|
29353
|
+
if (isObj4(cur)) return Object.hasOwn(cur, last2) ? [cur, last2] : null;
|
|
28974
29354
|
return null;
|
|
28975
29355
|
}
|
|
28976
29356
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
@@ -29011,14 +29391,14 @@ function removeV1(agent, findings) {
|
|
|
29011
29391
|
for (const f of findings) {
|
|
29012
29392
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
29013
29393
|
else if (f.path === "") {
|
|
29014
|
-
if (
|
|
29394
|
+
if (existsSync19(f.file)) {
|
|
29015
29395
|
moveAside(f.file, undo);
|
|
29016
29396
|
done.set(f, UPGRADE_REMOVED);
|
|
29017
29397
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
29018
29398
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
29019
29399
|
}
|
|
29020
29400
|
for (const [file2, list4] of entries) {
|
|
29021
|
-
if (!
|
|
29401
|
+
if (!existsSync19(file2)) {
|
|
29022
29402
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
29023
29403
|
continue;
|
|
29024
29404
|
}
|
|
@@ -29051,7 +29431,7 @@ function removeV1(agent, findings) {
|
|
|
29051
29431
|
},
|
|
29052
29432
|
rollback() {
|
|
29053
29433
|
for (const u of undo.splice(0).reverse()) {
|
|
29054
|
-
if (!
|
|
29434
|
+
if (!existsSync19(u.trash)) continue;
|
|
29055
29435
|
rmSync8(u.target, { recursive: true, force: true });
|
|
29056
29436
|
renameWithRetry(u.trash, u.target);
|
|
29057
29437
|
}
|
|
@@ -29060,7 +29440,7 @@ function removeV1(agent, findings) {
|
|
|
29060
29440
|
}
|
|
29061
29441
|
|
|
29062
29442
|
// src/core/ops/verify-sums.ts
|
|
29063
|
-
import { createHash } from "node:crypto";
|
|
29443
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
29064
29444
|
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync15 } from "node:fs";
|
|
29065
29445
|
import { join as join21 } from "node:path";
|
|
29066
29446
|
function mismatch() {
|
|
@@ -29100,7 +29480,7 @@ function verifySums(dir) {
|
|
|
29100
29480
|
for (const [rel, abs] of files) {
|
|
29101
29481
|
const want = sums.get(rel);
|
|
29102
29482
|
if (want === void 0) throw mismatch();
|
|
29103
|
-
const got =
|
|
29483
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync15(abs)).digest(HASH_ENCODING);
|
|
29104
29484
|
if (got !== want) throw mismatch();
|
|
29105
29485
|
}
|
|
29106
29486
|
}
|
|
@@ -29114,7 +29494,7 @@ function row4(area, before, after) {
|
|
|
29114
29494
|
return { area, before, after };
|
|
29115
29495
|
}
|
|
29116
29496
|
function bundleDir() {
|
|
29117
|
-
return
|
|
29497
|
+
return dirname11(process.argv[1] ?? "");
|
|
29118
29498
|
}
|
|
29119
29499
|
function pluginRootRow(adapter, env) {
|
|
29120
29500
|
const own2 = bundleDir();
|
|
@@ -29129,11 +29509,11 @@ function pluginRootRow(adapter, env) {
|
|
|
29129
29509
|
}
|
|
29130
29510
|
function isCurrent(agentDir, dir) {
|
|
29131
29511
|
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
29132
|
-
return
|
|
29512
|
+
return existsSync20(link) && realpathSync9.native(link) === realpathSync9.native(dir);
|
|
29133
29513
|
}
|
|
29134
29514
|
async function checkout(adapter, deps) {
|
|
29135
29515
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
29136
|
-
const agentDir =
|
|
29516
|
+
const agentDir = dirname11(fetched.dir);
|
|
29137
29517
|
try {
|
|
29138
29518
|
verifySums(fetched.dir);
|
|
29139
29519
|
} catch (err) {
|
|
@@ -29161,7 +29541,7 @@ async function upgrade(adapter, deps, home) {
|
|
|
29161
29541
|
return rows;
|
|
29162
29542
|
} catch (err) {
|
|
29163
29543
|
removal?.rollback();
|
|
29164
|
-
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir,
|
|
29544
|
+
if (done !== null && done.swap.previous !== null) swapPluginCurrent(done.agentDir, basename6(done.swap.previous));
|
|
29165
29545
|
throw err;
|
|
29166
29546
|
}
|
|
29167
29547
|
}
|