context-mode 2.0.0-next.17 → 2.0.0-next.20
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/SHA256SUMS +15 -15
- package/cli.mjs +59 -43
- package/copilot/plugin.json +1 -1
- package/fixtures/hook-roundtrip.json +20 -3
- package/gemini-extension.json +1 -1
- package/hook.mjs +92 -88
- package/opencode/plugin.js +583 -111
- package/package.json +5 -1
- package/pi/index.js +583 -138
- package/qwen-extension.json +1 -1
- package/run.mjs +371 -23
- package/search.mjs +371 -23
- package/server.mjs +172 -71
package/server.mjs
CHANGED
|
@@ -7,8 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { join as join21 } from "node:path";
|
|
10
|
+
import { existsSync as existsSync21, realpathSync as realpathSync9, rmSync as rmSync11 } from "node:fs";
|
|
11
|
+
import { dirname as dirname10, join as join21 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13
13
|
|
|
14
14
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -28291,6 +28291,9 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
28291
28291
|
function D5_LAST_HOOK_ERROR(ts, stage, label) {
|
|
28292
28292
|
return `; last hook error ${ts} at ${stage} (${label}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
28293
28293
|
}
|
|
28294
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label) {
|
|
28295
|
+
return `; past hook error ${ts} at ${stage} (${label}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
28296
|
+
}
|
|
28294
28297
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
28295
28298
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
28296
28299
|
var VERSION_PROBE_FLAGS = Object.freeze(["--version", "-v"]);
|
|
@@ -28340,7 +28343,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28340
28343
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28341
28344
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28342
28345
|
var RELEASE_BRANCH = "release";
|
|
28343
|
-
var BUNDLE_SHA = true ? "
|
|
28346
|
+
var BUNDLE_SHA = true ? "efe519b1d2f8b002ada6ef542af2df61e2abc20f" : void 0;
|
|
28344
28347
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28345
28348
|
var DOCTOR_LABEL = Object.freeze({
|
|
28346
28349
|
D1: "version",
|
|
@@ -28529,7 +28532,7 @@ var REGEX_ESCAPE = "\\";
|
|
|
28529
28532
|
var CODEX_FEATURES_HOOKS_KEY = Object.freeze(["features", "hooks"]);
|
|
28530
28533
|
var D5_SHAPE_DETAIL = "hook output is not the agent's native shape";
|
|
28531
28534
|
function D5_SLOW_DETAIL(ms) {
|
|
28532
|
-
return `hook round trip took ${ms} ms, over ${HOOK_P95_MS} ms`;
|
|
28535
|
+
return `hook round trip took ${ms} ms over bare node, over ${HOOK_P95_MS} ms`;
|
|
28533
28536
|
}
|
|
28534
28537
|
var D5_FIX = "run ctx_upgrade";
|
|
28535
28538
|
var PRAGMA_INTEGRITY_CHECK = "PRAGMA integrity_check";
|
|
@@ -44278,7 +44281,7 @@ var ctxBatch = Object.freeze({
|
|
|
44278
44281
|
});
|
|
44279
44282
|
|
|
44280
44283
|
// src/core/tools/doctor.ts
|
|
44281
|
-
import { readdirSync as
|
|
44284
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync8, existsSync as existsSync12 } from "node:fs";
|
|
44282
44285
|
import { basename as basename3, dirname as dirname5, join as join11 } from "node:path";
|
|
44283
44286
|
|
|
44284
44287
|
// src/adapters/claude-code.ts
|
|
@@ -44557,7 +44560,8 @@ var RESULT_SUCCESS = "success";
|
|
|
44557
44560
|
function isRecord(v) {
|
|
44558
44561
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
44559
44562
|
}
|
|
44560
|
-
var
|
|
44563
|
+
var SHELL_TOOL_NAMES = Object.freeze(["bash", "powershell"]);
|
|
44564
|
+
var NATIVE_TO_CANONICAL3 = Object.fromEntries(SHELL_TOOL_NAMES.map((n) => [n, "Bash"]));
|
|
44561
44565
|
function canonicalName3(name) {
|
|
44562
44566
|
if (name.startsWith(TOOL_NAME_PREFIX5)) return name.slice(TOOL_NAME_PREFIX5.length);
|
|
44563
44567
|
if (Object.hasOwn(NATIVE_TO_CANONICAL3, name)) return NATIVE_TO_CANONICAL3[name];
|
|
@@ -44638,11 +44642,11 @@ var VSCODE_EVENTS = ["SessionStart", "UserPromptSubmit", "PreToolUse", "PostTool
|
|
|
44638
44642
|
var MCP_PREFIX2 = "mcp_";
|
|
44639
44643
|
var MCP_SEP2 = "_";
|
|
44640
44644
|
var SESSION_START_NEW = "new";
|
|
44641
|
-
var
|
|
44645
|
+
var SHELL_TOOL_NAMES2 = Object.freeze(["run_in_terminal", "runTerminalCommand", "bash", "powershell"]);
|
|
44642
44646
|
var READ_TOOL_NAMES = Object.freeze(["read_file", "view"]);
|
|
44643
44647
|
var WEBFETCH_TOOL_NAMES = Object.freeze(["fetch_webpage", "web_fetch"]);
|
|
44644
44648
|
var NATIVE_TO_CANONICAL4 = Object.fromEntries([
|
|
44645
|
-
...
|
|
44649
|
+
...SHELL_TOOL_NAMES2.map((n) => [n, "Bash"]),
|
|
44646
44650
|
...READ_TOOL_NAMES.map((n) => [n, "Read"]),
|
|
44647
44651
|
...WEBFETCH_TOOL_NAMES.map((n) => [n, "WebFetch"])
|
|
44648
44652
|
]);
|
|
@@ -44770,8 +44774,8 @@ var KIRO_EVENTS = {
|
|
|
44770
44774
|
};
|
|
44771
44775
|
var PROMPT_ENV = "USER_PROMPT";
|
|
44772
44776
|
var MCP_PREFIX3 = "mcp_";
|
|
44773
|
-
var
|
|
44774
|
-
var NATIVE_TO_CANONICAL5 = Object.fromEntries(
|
|
44777
|
+
var SHELL_TOOL_NAMES3 = Object.freeze(["execute_bash", "execute_pwsh", "shell"]);
|
|
44778
|
+
var NATIVE_TO_CANONICAL5 = Object.fromEntries(SHELL_TOOL_NAMES3.map((n) => [n, "Bash"]));
|
|
44775
44779
|
var MCP_SEP3 = "_";
|
|
44776
44780
|
var KIRO_SOURCES = { startup: "startup", resume: "resume", clear: "clear", compact: "compact" };
|
|
44777
44781
|
function canonicalName5(name) {
|
|
@@ -44913,7 +44917,8 @@ var OPENCODE_EVENTS = {
|
|
|
44913
44917
|
"step-finish": "Usage"
|
|
44914
44918
|
};
|
|
44915
44919
|
var SHELL_TOOL_NAME = "bash";
|
|
44916
|
-
var
|
|
44920
|
+
var SHELL_TOOL_NAMES4 = Object.freeze([SHELL_TOOL_NAME, "shell"]);
|
|
44921
|
+
var NATIVE_TO_CANONICAL7 = { webfetch: "WebFetch", ...Object.fromEntries(SHELL_TOOL_NAMES4.map((n) => [n, "Bash"])) };
|
|
44917
44922
|
function toCanonicalTool(name) {
|
|
44918
44923
|
if (name.startsWith(OWN_WIRE_PREFIX)) return name.slice(OWN_WIRE_PREFIX.length);
|
|
44919
44924
|
return Object.prototype.hasOwnProperty.call(NATIVE_TO_CANONICAL7, name) ? NATIVE_TO_CANONICAL7[name] : name;
|
|
@@ -45043,8 +45048,9 @@ var ADAPTERS = Object.freeze([
|
|
|
45043
45048
|
installMode: "plugin",
|
|
45044
45049
|
projectSource: "arg:--agent+cwd",
|
|
45045
45050
|
toolNamePrefix: TOOL_NAME_PREFIX5,
|
|
45046
|
-
nativeTools: { shell: [
|
|
45051
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES] },
|
|
45047
45052
|
execReadOnlyHint: false,
|
|
45053
|
+
// D-PWSH-DUMP-1
|
|
45048
45054
|
eventMap: { SessionStart: "sessionStart", UserPromptSubmit: "userPromptSubmitted", PreToolUse: "preToolUse", PostToolUse: "postToolUse" },
|
|
45049
45055
|
compactDelivery: "pending-flag",
|
|
45050
45056
|
compactSummary: "none",
|
|
@@ -45062,7 +45068,7 @@ var ADAPTERS = Object.freeze([
|
|
|
45062
45068
|
projectSource: "arg:workspaceFolder",
|
|
45063
45069
|
toolNamePrefix: TOOL_NAME_PREFIX6,
|
|
45064
45070
|
// PreCompact sets the pending flag (ADR-0009 §6, DEVIATIONS D-M3-A4-1).
|
|
45065
|
-
nativeTools: { shell: [...
|
|
45071
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES2], read: [...READ_TOOL_NAMES], webfetch: [...WEBFETCH_TOOL_NAMES] },
|
|
45066
45072
|
// D-HF-VSCODE-PROJECT-1, D-N7-VSCODE-TOOLS-1
|
|
45067
45073
|
execReadOnlyHint: false,
|
|
45068
45074
|
eventMap: { ...CLAUDE_EVENTS, PreCompact: "PreCompact" },
|
|
@@ -45081,7 +45087,7 @@ var ADAPTERS = Object.freeze([
|
|
|
45081
45087
|
installMode: "mcp-entry",
|
|
45082
45088
|
projectSource: "arg:--agent+cwd",
|
|
45083
45089
|
toolNamePrefix: TOOL_NAME_PREFIX7,
|
|
45084
|
-
nativeTools: { shell: [...
|
|
45090
|
+
nativeTools: { shell: [...SHELL_TOOL_NAMES3] },
|
|
45085
45091
|
execReadOnlyHint: false,
|
|
45086
45092
|
// D-HF-KIRO-SHELL-1, D-N7-KIRO-1
|
|
45087
45093
|
eventMap: { SessionStart: "SessionStart", UserPromptSubmit: "UserPromptSubmit", PreToolUse: "PreToolUse", PostToolUse: "PostToolUse" },
|
|
@@ -45165,6 +45171,7 @@ function getAdapter(id) {
|
|
|
45165
45171
|
}
|
|
45166
45172
|
|
|
45167
45173
|
// src/core/ops/doctor-config.ts
|
|
45174
|
+
import { existsSync as existsSync7, readdirSync as readdirSync5 } from "node:fs";
|
|
45168
45175
|
import { join as join9 } from "node:path";
|
|
45169
45176
|
|
|
45170
45177
|
// src/core/ops/detect-v1.ts
|
|
@@ -47678,7 +47685,7 @@ function ownMcpValue(agent, node3, server) {
|
|
|
47678
47685
|
return { ...mcp.fields, [MCP_COMMAND_FIELD]: node3, [MCP_ARGS_FIELD]: [server, AGENT_ARG, agent, ...tail] };
|
|
47679
47686
|
}
|
|
47680
47687
|
function opencodePluginFile() {
|
|
47681
|
-
return
|
|
47688
|
+
return dirname3(process.argv[1] ?? "");
|
|
47682
47689
|
}
|
|
47683
47690
|
function listTarget(key, own4, v1, alt = []) {
|
|
47684
47691
|
return {
|
|
@@ -48222,7 +48229,47 @@ function mcpFile(row5, home, env) {
|
|
|
48222
48229
|
}
|
|
48223
48230
|
return null;
|
|
48224
48231
|
}
|
|
48232
|
+
var CODEX_PLUGIN_KEY = `${SERVER_KEY}@${SERVER_KEY}`;
|
|
48233
|
+
var CODEX_PLUGIN_SUBDIR = ".codex-plugin";
|
|
48234
|
+
var CODEX_PLUGIN_MCP_FILE = "mcp.json";
|
|
48235
|
+
var CODEX_PLUGIN_HOOKS_FILE = "hooks.json";
|
|
48236
|
+
var MCP_SERVERS_FIELD = "mcpServers";
|
|
48237
|
+
function codexNativeDir(env, home) {
|
|
48238
|
+
const codexDir = codexDirOf(env, home);
|
|
48239
|
+
let enabled;
|
|
48240
|
+
try {
|
|
48241
|
+
enabled = hostConfigValueAt(readParsed("codex", join9(codexDir, CONFIG_TOML_FILE)).value, ["plugins", CODEX_PLUGIN_KEY, "enabled"]);
|
|
48242
|
+
} catch {
|
|
48243
|
+
return null;
|
|
48244
|
+
}
|
|
48245
|
+
if (enabled !== true) return null;
|
|
48246
|
+
const cache = join9(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
48247
|
+
if (!existsSync7(cache)) return null;
|
|
48248
|
+
const found = [];
|
|
48249
|
+
for (const market of readdirSync5(cache)) {
|
|
48250
|
+
const plugin = join9(cache, market, SERVER_KEY);
|
|
48251
|
+
if (!existsSync7(plugin)) continue;
|
|
48252
|
+
for (const version4 of readdirSync5(plugin).sort()) {
|
|
48253
|
+
const dir = join9(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
48254
|
+
if (existsSync7(join9(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
48255
|
+
}
|
|
48256
|
+
}
|
|
48257
|
+
return found.length === 0 ? null : found[found.length - 1];
|
|
48258
|
+
}
|
|
48259
|
+
function nativeMcpWrong(dir, row5) {
|
|
48260
|
+
try {
|
|
48261
|
+
const entry = hostConfigValueAt(readParsed(row5.id, join9(dir, CODEX_PLUGIN_MCP_FILE)).value, [MCP_SERVERS_FIELD, SERVER_KEY]);
|
|
48262
|
+
if (!isObject4(entry)) return true;
|
|
48263
|
+
const args = list(entry[MCP_ARGS_FIELD]);
|
|
48264
|
+
const script = args[0];
|
|
48265
|
+
return entry.command !== HOST_NODE_COMMAND || typeof script !== "string" || !script.endsWith(SERVER_ENTRY_FILE) || args[1] !== AGENT_ARG || args[2] !== row5.id || args.length !== 3;
|
|
48266
|
+
} catch {
|
|
48267
|
+
return true;
|
|
48268
|
+
}
|
|
48269
|
+
}
|
|
48225
48270
|
function mcpWrong(row5, home, env) {
|
|
48271
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48272
|
+
if (native !== null) return nativeMcpWrong(native, row5);
|
|
48226
48273
|
const file2 = mcpFile(row5, home, env);
|
|
48227
48274
|
try {
|
|
48228
48275
|
if (file2 === null) {
|
|
@@ -48241,7 +48288,8 @@ function hookParts(row5, home, env, worktree) {
|
|
|
48241
48288
|
let block;
|
|
48242
48289
|
try {
|
|
48243
48290
|
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env) : spec.root === "home" ? home : worktree;
|
|
48244
|
-
const
|
|
48291
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48292
|
+
const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
|
|
48245
48293
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
48246
48294
|
if (row5.id === "codex") {
|
|
48247
48295
|
const config4 = readParsed(row5.id, join9(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -48304,7 +48352,7 @@ function checkDoubleFire(agent, worktree) {
|
|
|
48304
48352
|
}
|
|
48305
48353
|
|
|
48306
48354
|
// src/core/ops/doctor-db.ts
|
|
48307
|
-
import { existsSync as
|
|
48355
|
+
import { existsSync as existsSync8 } from "node:fs";
|
|
48308
48356
|
var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
48309
48357
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
48310
48358
|
var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -48344,7 +48392,7 @@ function failsOnCorrupt(step) {
|
|
|
48344
48392
|
}
|
|
48345
48393
|
async function checkDb(project) {
|
|
48346
48394
|
const clean = { schemaStale: false, integrityFailed: false };
|
|
48347
|
-
if (!
|
|
48395
|
+
if (!existsSync8(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
48348
48396
|
const sqlite = await loadSqlite2();
|
|
48349
48397
|
if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
|
|
48350
48398
|
let raw = null;
|
|
@@ -48370,7 +48418,7 @@ async function checkDb(project) {
|
|
|
48370
48418
|
}
|
|
48371
48419
|
}
|
|
48372
48420
|
async function checkIndex(project) {
|
|
48373
|
-
if (!
|
|
48421
|
+
if (!existsSync8(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
48374
48422
|
const sqlite = await loadSqlite2();
|
|
48375
48423
|
if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
|
|
48376
48424
|
let raw = null;
|
|
@@ -48387,7 +48435,7 @@ async function checkIndex(project) {
|
|
|
48387
48435
|
}
|
|
48388
48436
|
|
|
48389
48437
|
// src/core/ops/doctor-env.ts
|
|
48390
|
-
import { existsSync as
|
|
48438
|
+
import { existsSync as existsSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
48391
48439
|
import { isAbsolute as isAbsolute2, relative } from "node:path";
|
|
48392
48440
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
48393
48441
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
@@ -48445,7 +48493,7 @@ function checkMcp(ctx) {
|
|
|
48445
48493
|
return named || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
|
|
48446
48494
|
}
|
|
48447
48495
|
function piCwdInside(worktree, piCwd) {
|
|
48448
|
-
if (piCwd === void 0 || !
|
|
48496
|
+
if (piCwd === void 0 || !existsSync9(piCwd)) return false;
|
|
48449
48497
|
const rel = relative(worktree, realpathSync5.native(piCwd));
|
|
48450
48498
|
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
48451
48499
|
}
|
|
@@ -48466,15 +48514,17 @@ function checkShell(env) {
|
|
|
48466
48514
|
}
|
|
48467
48515
|
|
|
48468
48516
|
// src/core/ops/doctor-hook.ts
|
|
48469
|
-
import { existsSync as
|
|
48517
|
+
import { existsSync as existsSync10, readFileSync as readFileSync7 } from "node:fs";
|
|
48470
48518
|
import path4 from "node:path";
|
|
48519
|
+
var D5_MIN_PAIRS = 3;
|
|
48520
|
+
var D5_MAX_PAIRS = 9;
|
|
48471
48521
|
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 };
|
|
48472
48522
|
function isObject5(v) {
|
|
48473
48523
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
48474
48524
|
}
|
|
48475
48525
|
function loadFixture(bundleDir2, agent) {
|
|
48476
48526
|
const file2 = path4.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
48477
|
-
if (!
|
|
48527
|
+
if (!existsSync10(file2)) return null;
|
|
48478
48528
|
let all;
|
|
48479
48529
|
try {
|
|
48480
48530
|
all = JSON.parse(hostText(readFileSync7(file2, "utf8")));
|
|
@@ -48486,6 +48536,9 @@ function loadFixture(bundleDir2, agent) {
|
|
|
48486
48536
|
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) return null;
|
|
48487
48537
|
return { event: e.event, payload: e.payload };
|
|
48488
48538
|
}
|
|
48539
|
+
function payloadFor(payload, worktree) {
|
|
48540
|
+
return worktree !== void 0 && isObject5(payload) ? { ...payload, cwd: worktree } : payload;
|
|
48541
|
+
}
|
|
48489
48542
|
function isNativeShape(stdout, exitCode, killed, event) {
|
|
48490
48543
|
if (killed !== null || exitCode !== 0 && exitCode !== 2) return false;
|
|
48491
48544
|
if (stdout.length === 0) return true;
|
|
@@ -48502,22 +48555,38 @@ function codexHookJournaled(db) {
|
|
|
48502
48555
|
return db.raw.prepare("SELECT 1 FROM events WHERE agent = ? LIMIT 1").get("codex") !== void 0;
|
|
48503
48556
|
}
|
|
48504
48557
|
async function checkHookRoundTrip(i) {
|
|
48505
|
-
if (i.agent === "codex" &&
|
|
48558
|
+
if (i.agent === "codex" && existsSync10(path4.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
48506
48559
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
48507
48560
|
}
|
|
48508
48561
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
48509
48562
|
if (fixture === null) return row("UNKNOWN", D5_NO_FIXTURE_DETAIL(i.agent));
|
|
48510
48563
|
const now = i.now ?? (() => performance.now());
|
|
48511
|
-
const
|
|
48512
|
-
const
|
|
48513
|
-
|
|
48514
|
-
|
|
48515
|
-
|
|
48516
|
-
timeoutMs: HOOK_TIMEOUT_MS
|
|
48517
|
-
|
|
48518
|
-
});
|
|
48519
|
-
const
|
|
48520
|
-
|
|
48564
|
+
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
48565
|
+
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
48566
|
+
const minPairs = fixed ?? D5_MIN_PAIRS;
|
|
48567
|
+
const bareMs = i.bareMs ?? (async () => {
|
|
48568
|
+
const t = performance.now();
|
|
48569
|
+
await runProcess([process.execPath, "-e", ""], { cwd: i.bundleDir, env: i.env, signal: i.signal, timeoutMs: HOOK_TIMEOUT_MS });
|
|
48570
|
+
return performance.now() - t;
|
|
48571
|
+
});
|
|
48572
|
+
const hookWalls = [];
|
|
48573
|
+
const bareWalls = [];
|
|
48574
|
+
let ms = 0;
|
|
48575
|
+
for (let n = 1; n <= maxPairs; n++) {
|
|
48576
|
+
const start = now();
|
|
48577
|
+
const r = await runProcess([process.execPath, path4.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
48578
|
+
cwd: i.bundleDir,
|
|
48579
|
+
env: i.env,
|
|
48580
|
+
signal: i.signal,
|
|
48581
|
+
timeoutMs: HOOK_TIMEOUT_MS,
|
|
48582
|
+
stdin: JSON.stringify(payloadFor(fixture.payload, i.worktree))
|
|
48583
|
+
});
|
|
48584
|
+
hookWalls.push(now() - start);
|
|
48585
|
+
if (!isNativeShape(r.stdout.toString("utf8"), r.exitCode, r.killed, fixture.event)) return row("FAIL", D5_SHAPE_DETAIL, D5_FIX);
|
|
48586
|
+
bareWalls.push(await bareMs());
|
|
48587
|
+
ms = Math.max(0, Math.round(Math.min(...hookWalls) - Math.min(...bareWalls)));
|
|
48588
|
+
if (n >= minPairs && ms <= HOOK_P95_MS) break;
|
|
48589
|
+
}
|
|
48521
48590
|
if (ms > HOOK_P95_MS) return row("FAIL", D5_SLOW_DETAIL(ms), D5_FIX);
|
|
48522
48591
|
return row("PASS", DOCTOR_PASS_DETAIL);
|
|
48523
48592
|
}
|
|
@@ -48560,7 +48629,7 @@ function lastHookError(env) {
|
|
|
48560
48629
|
}
|
|
48561
48630
|
|
|
48562
48631
|
// src/core/ops/db-heal.ts
|
|
48563
|
-
import { existsSync as
|
|
48632
|
+
import { existsSync as existsSync11, rmSync as rmSync4 } from "node:fs";
|
|
48564
48633
|
function integrityOk2(rows) {
|
|
48565
48634
|
return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
|
|
48566
48635
|
}
|
|
@@ -48594,7 +48663,7 @@ function renameAside(dbPath) {
|
|
|
48594
48663
|
const ts = String(Date.now());
|
|
48595
48664
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
48596
48665
|
const file2 = dbPath + suffix;
|
|
48597
|
-
if (
|
|
48666
|
+
if (existsSync11(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
48598
48667
|
}
|
|
48599
48668
|
return ts;
|
|
48600
48669
|
}
|
|
@@ -48694,7 +48763,7 @@ async function guard(id, run) {
|
|
|
48694
48763
|
}
|
|
48695
48764
|
}
|
|
48696
48765
|
async function codexDb(ctx, adapter) {
|
|
48697
|
-
if (adapter.id !== "codex" || !
|
|
48766
|
+
if (adapter.id !== "codex" || !existsSync12(ctx.project.dbPath)) return null;
|
|
48698
48767
|
try {
|
|
48699
48768
|
return await openDb(ctx.project, { readOnly: true });
|
|
48700
48769
|
} catch {
|
|
@@ -48703,8 +48772,10 @@ async function codexDb(ctx, adapter) {
|
|
|
48703
48772
|
}
|
|
48704
48773
|
async function hookRow(ctx, adapter, host) {
|
|
48705
48774
|
const db = await codexDb(ctx, adapter);
|
|
48775
|
+
const runStart = Date.now();
|
|
48706
48776
|
try {
|
|
48707
48777
|
const row5 = await checkHookRoundTrip({
|
|
48778
|
+
worktree: ctx.project.worktree,
|
|
48708
48779
|
agent: adapter.id,
|
|
48709
48780
|
bundleDir: host.bundleDir,
|
|
48710
48781
|
env: buildChildEnv(host.env),
|
|
@@ -48714,15 +48785,17 @@ async function hookRow(ctx, adapter, host) {
|
|
|
48714
48785
|
db
|
|
48715
48786
|
});
|
|
48716
48787
|
const last2 = lastHookError(host.env);
|
|
48717
|
-
|
|
48788
|
+
if (last2 === null) return row5;
|
|
48789
|
+
const text = Date.parse(last2.ts) >= runStart ? D5_LAST_HOOK_ERROR : D5_PAST_HOOK_ERROR;
|
|
48790
|
+
return { ...row5, detail: row5.detail + text(last2.ts, last2.stage, last2.label) };
|
|
48718
48791
|
} finally {
|
|
48719
48792
|
if (db !== null) closeDb(db);
|
|
48720
48793
|
}
|
|
48721
48794
|
}
|
|
48722
48795
|
function ownServerId(configDir, projectKey) {
|
|
48723
48796
|
const dir = join11(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
48724
|
-
if (!
|
|
48725
|
-
for (const name of
|
|
48797
|
+
if (!existsSync12(dir)) return "";
|
|
48798
|
+
for (const name of readdirSync6(dir)) {
|
|
48726
48799
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
48727
48800
|
if (readFileSync8(join11(dir, name), "utf8").trim() === String(process.pid)) return basename3(name, OWNER_PID_EXT);
|
|
48728
48801
|
}
|
|
@@ -48796,7 +48869,7 @@ var ctxDoctor = Object.freeze({
|
|
|
48796
48869
|
});
|
|
48797
48870
|
|
|
48798
48871
|
// src/core/tools/execute.ts
|
|
48799
|
-
import { existsSync as
|
|
48872
|
+
import { existsSync as existsSync13, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
48800
48873
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
48801
48874
|
import { dirname as dirname6, join as join12, parse as parse5, resolve as resolve3 } from "node:path";
|
|
48802
48875
|
|
|
@@ -48921,7 +48994,7 @@ function schemaLine(issue4) {
|
|
|
48921
48994
|
}
|
|
48922
48995
|
function fileError(given, abs, root) {
|
|
48923
48996
|
let dir = abs;
|
|
48924
|
-
while (!
|
|
48997
|
+
while (!existsSync13(dir) && dirname6(dir) !== dir) dir = dirname6(dir);
|
|
48925
48998
|
if (isInside(root, dir)) return null;
|
|
48926
48999
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
48927
49000
|
}
|
|
@@ -49036,11 +49109,11 @@ var ctxExecute = {
|
|
|
49036
49109
|
};
|
|
49037
49110
|
|
|
49038
49111
|
// src/core/tools/index.ts
|
|
49039
|
-
import { existsSync as
|
|
49112
|
+
import { existsSync as existsSync14, readFileSync as readFileSync10, statSync as statSync5 } from "node:fs";
|
|
49040
49113
|
import { dirname as dirname7, extname, join as join14, relative as relative2, resolve as resolve4 } from "node:path";
|
|
49041
49114
|
|
|
49042
49115
|
// src/core/index/walk.ts
|
|
49043
|
-
import { readdirSync as
|
|
49116
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync9, realpathSync as realpathSync6, statSync as statSync4 } from "node:fs";
|
|
49044
49117
|
import { join as join13 } from "node:path";
|
|
49045
49118
|
var GITIGNORE = ".gitignore";
|
|
49046
49119
|
var GIT_DIR = ".git";
|
|
@@ -49055,7 +49128,7 @@ function walkDir(root, containmentRoot) {
|
|
|
49055
49128
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
49056
49129
|
let entries;
|
|
49057
49130
|
try {
|
|
49058
|
-
entries =
|
|
49131
|
+
entries = readdirSync7(abs, { withFileTypes: true });
|
|
49059
49132
|
} catch {
|
|
49060
49133
|
return;
|
|
49061
49134
|
}
|
|
@@ -53192,7 +53265,7 @@ function readUtf8(absPath) {
|
|
|
53192
53265
|
}
|
|
53193
53266
|
function missingOrOutside(given, abs, root) {
|
|
53194
53267
|
let dir = abs;
|
|
53195
|
-
while (!
|
|
53268
|
+
while (!existsSync14(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
|
|
53196
53269
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
53197
53270
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
53198
53271
|
}
|
|
@@ -53724,11 +53797,11 @@ var ctxStats = Object.freeze({
|
|
|
53724
53797
|
});
|
|
53725
53798
|
|
|
53726
53799
|
// src/core/tools/upgrade.ts
|
|
53727
|
-
import { existsSync as
|
|
53800
|
+
import { existsSync as existsSync20, realpathSync as realpathSync7, rmSync as rmSync10 } from "node:fs";
|
|
53728
53801
|
import { basename as basename5, dirname as dirname9, join as join20 } from "node:path";
|
|
53729
53802
|
|
|
53730
53803
|
// src/core/ops/host-write.ts
|
|
53731
|
-
import { copyFileSync, existsSync as
|
|
53804
|
+
import { copyFileSync, existsSync as existsSync15, mkdirSync as mkdirSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
53732
53805
|
import { dirname as dirname8, join as join15 } from "node:path";
|
|
53733
53806
|
function defaultWrite(file2, text) {
|
|
53734
53807
|
writeFileSync4(file2, text, "utf8");
|
|
@@ -53757,7 +53830,7 @@ function toRow(file2, edit) {
|
|
|
53757
53830
|
function writeWithRollback(file2, text, write, atomic) {
|
|
53758
53831
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
53759
53832
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
53760
|
-
const had =
|
|
53833
|
+
const had = existsSync15(file2);
|
|
53761
53834
|
mkdirSync5(dirname8(file2), { recursive: true });
|
|
53762
53835
|
if (had) copyFileSync(file2, trash);
|
|
53763
53836
|
try {
|
|
@@ -53787,7 +53860,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
53787
53860
|
if (requested === null) return [];
|
|
53788
53861
|
const current = readHostConfig(row5.id, requested);
|
|
53789
53862
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
53790
|
-
const exists =
|
|
53863
|
+
const exists = existsSync15(current.path);
|
|
53791
53864
|
if (exists && result.text === current.text) return [];
|
|
53792
53865
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
53793
53866
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -53795,7 +53868,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
53795
53868
|
}
|
|
53796
53869
|
|
|
53797
53870
|
// src/core/ops/plugin-swap.ts
|
|
53798
|
-
import { existsSync as
|
|
53871
|
+
import { existsSync as existsSync16, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
53799
53872
|
import { basename as basename4, join as join16, win32 as win322 } from "node:path";
|
|
53800
53873
|
function linkTarget(path5, win) {
|
|
53801
53874
|
if (!isLink(path5)) return null;
|
|
@@ -53806,7 +53879,7 @@ function isLink(path5) {
|
|
|
53806
53879
|
return lstatSync(path5, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
53807
53880
|
}
|
|
53808
53881
|
function generations(agentDir) {
|
|
53809
|
-
return
|
|
53882
|
+
return readdirSync8(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();
|
|
53810
53883
|
}
|
|
53811
53884
|
function settleLinks(link, tmp, old, opts) {
|
|
53812
53885
|
if (isLink(tmp)) unlinkSync2(tmp);
|
|
@@ -53816,7 +53889,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
53816
53889
|
}
|
|
53817
53890
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
53818
53891
|
const next = join16(agentDir, sha);
|
|
53819
|
-
if (!
|
|
53892
|
+
if (!existsSync16(next) || !lstatSync(next).isDirectory()) {
|
|
53820
53893
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename4(agentDir), path: next });
|
|
53821
53894
|
}
|
|
53822
53895
|
const link = join16(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -53836,12 +53909,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
53836
53909
|
if (before !== null) keep.add(before);
|
|
53837
53910
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join16(agentDir, name));
|
|
53838
53911
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
53839
|
-
const previous = before !== null &&
|
|
53912
|
+
const previous = before !== null && existsSync16(join16(agentDir, before)) ? join16(agentDir, before) : null;
|
|
53840
53913
|
return { current: next, previous, removed };
|
|
53841
53914
|
}
|
|
53842
53915
|
|
|
53843
53916
|
// src/core/ops/release-fetch.ts
|
|
53844
|
-
import { existsSync as
|
|
53917
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync6, rmSync as rmSync7 } from "node:fs";
|
|
53845
53918
|
import { join as join17 } from "node:path";
|
|
53846
53919
|
function failed(r) {
|
|
53847
53920
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -53865,7 +53938,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
53865
53938
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
53866
53939
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
53867
53940
|
const dir = join17(agentDir, sha);
|
|
53868
|
-
if (
|
|
53941
|
+
if (existsSync17(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
53869
53942
|
else renameWithRetry(fetchDir, dir, opts);
|
|
53870
53943
|
return { sha, dir };
|
|
53871
53944
|
} catch (e) {
|
|
@@ -53875,7 +53948,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
53875
53948
|
}
|
|
53876
53949
|
|
|
53877
53950
|
// src/core/ops/uninstall.ts
|
|
53878
|
-
import { existsSync as
|
|
53951
|
+
import { existsSync as existsSync18, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
53879
53952
|
import { join as join18 } from "node:path";
|
|
53880
53953
|
function row2(area, before, after) {
|
|
53881
53954
|
return { area, before, after };
|
|
@@ -53905,7 +53978,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
53905
53978
|
}
|
|
53906
53979
|
case "plugin": {
|
|
53907
53980
|
const agentDir = join18(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
53908
|
-
if (!
|
|
53981
|
+
if (!existsSync18(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
53909
53982
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
53910
53983
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
53911
53984
|
}
|
|
@@ -53985,9 +54058,9 @@ function removeOwnEntries(agent, env) {
|
|
|
53985
54058
|
function removeProjectData(configDir, projectKey) {
|
|
53986
54059
|
const projects = join18(configDir, PROJECTS_DIR_NAME);
|
|
53987
54060
|
const dir = join18(projects, projectKey);
|
|
53988
|
-
if (!
|
|
54061
|
+
if (!existsSync18(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
53989
54062
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
53990
|
-
for (const name of
|
|
54063
|
+
for (const name of readdirSync9(dir)) {
|
|
53991
54064
|
if (name !== OWNERS_DIR_NAME) rmSync8(join18(dir, name), { recursive: true, force: true });
|
|
53992
54065
|
}
|
|
53993
54066
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
@@ -54001,7 +54074,7 @@ function runUninstall(input) {
|
|
|
54001
54074
|
}
|
|
54002
54075
|
|
|
54003
54076
|
// src/core/ops/v1-remove.ts
|
|
54004
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
54077
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync19, readFileSync as readFileSync11, rmSync as rmSync9 } from "node:fs";
|
|
54005
54078
|
var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54006
54079
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
54007
54080
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -54082,14 +54155,14 @@ function removeV1(agent, findings) {
|
|
|
54082
54155
|
for (const f of findings) {
|
|
54083
54156
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
54084
54157
|
else if (f.path === "") {
|
|
54085
|
-
if (
|
|
54158
|
+
if (existsSync19(f.file)) {
|
|
54086
54159
|
moveAside(f.file, undo);
|
|
54087
54160
|
done.set(f, UPGRADE_REMOVED);
|
|
54088
54161
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
54089
54162
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
54090
54163
|
}
|
|
54091
54164
|
for (const [file2, list3] of entries) {
|
|
54092
|
-
if (!
|
|
54165
|
+
if (!existsSync19(file2)) {
|
|
54093
54166
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
54094
54167
|
continue;
|
|
54095
54168
|
}
|
|
@@ -54122,7 +54195,7 @@ function removeV1(agent, findings) {
|
|
|
54122
54195
|
},
|
|
54123
54196
|
rollback() {
|
|
54124
54197
|
for (const u of undo.splice(0).reverse()) {
|
|
54125
|
-
if (!
|
|
54198
|
+
if (!existsSync19(u.trash)) continue;
|
|
54126
54199
|
rmSync9(u.target, { recursive: true, force: true });
|
|
54127
54200
|
renameWithRetry(u.trash, u.target);
|
|
54128
54201
|
}
|
|
@@ -54132,7 +54205,7 @@ function removeV1(agent, findings) {
|
|
|
54132
54205
|
|
|
54133
54206
|
// src/core/ops/verify-sums.ts
|
|
54134
54207
|
import { createHash } from "node:crypto";
|
|
54135
|
-
import { lstatSync as lstatSync2, readdirSync as
|
|
54208
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync12 } from "node:fs";
|
|
54136
54209
|
import { join as join19 } from "node:path";
|
|
54137
54210
|
function mismatch() {
|
|
54138
54211
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -54151,7 +54224,7 @@ function parseSums(text) {
|
|
|
54151
54224
|
return sums;
|
|
54152
54225
|
}
|
|
54153
54226
|
function walk2(dir, prefix, out) {
|
|
54154
|
-
for (const entry of
|
|
54227
|
+
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
54155
54228
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
54156
54229
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
54157
54230
|
const abs = join19(dir, entry.name);
|
|
@@ -54200,7 +54273,7 @@ function pluginRootRow(adapter, env) {
|
|
|
54200
54273
|
}
|
|
54201
54274
|
function isCurrent(agentDir, dir) {
|
|
54202
54275
|
const link = join20(agentDir, PLUGIN_CURRENT_LINK);
|
|
54203
|
-
return
|
|
54276
|
+
return existsSync20(link) && realpathSync7.native(link) === realpathSync7.native(dir);
|
|
54204
54277
|
}
|
|
54205
54278
|
async function checkout(adapter, deps) {
|
|
54206
54279
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -54385,6 +54458,32 @@ function sessionIdOf(meta3, agent, env, serverId) {
|
|
|
54385
54458
|
if (typeof fromHost === "string" && fromHost !== "") return fromHost;
|
|
54386
54459
|
return RUN_SESSION_PREFIX + serverId;
|
|
54387
54460
|
}
|
|
54461
|
+
var CODEX_SANDBOX_STATE_META = "codex/sandbox-state-meta";
|
|
54462
|
+
var FILE_URL_PREFIX = "file:";
|
|
54463
|
+
function workspaceFromMeta(meta3) {
|
|
54464
|
+
const state = meta3?.[CODEX_SANDBOX_STATE_META];
|
|
54465
|
+
const cwd = typeof state === "object" && state !== null ? state.sandboxCwd : void 0;
|
|
54466
|
+
if (typeof cwd !== "string" || cwd === "") return void 0;
|
|
54467
|
+
if (!cwd.startsWith(FILE_URL_PREFIX)) return cwd;
|
|
54468
|
+
try {
|
|
54469
|
+
return fileURLToPath2(cwd);
|
|
54470
|
+
} catch {
|
|
54471
|
+
return void 0;
|
|
54472
|
+
}
|
|
54473
|
+
}
|
|
54474
|
+
function realOrSame(p) {
|
|
54475
|
+
try {
|
|
54476
|
+
return realpathSync9.native(p);
|
|
54477
|
+
} catch {
|
|
54478
|
+
return p;
|
|
54479
|
+
}
|
|
54480
|
+
}
|
|
54481
|
+
function workspaceCwdOf(meta3, spawnCwd, script) {
|
|
54482
|
+
const fromHost = workspaceFromMeta(meta3);
|
|
54483
|
+
if (fromHost !== void 0) return fromHost;
|
|
54484
|
+
if (script === void 0 || script === "") return spawnCwd;
|
|
54485
|
+
return realOrSame(spawnCwd) === realOrSame(dirname10(script)) ? "" : spawnCwd;
|
|
54486
|
+
}
|
|
54388
54487
|
function errorReply(err) {
|
|
54389
54488
|
if (err instanceof CtxError) return { text: err.toLine(), isError: true, sandboxBytes: 0 };
|
|
54390
54489
|
console.error(err);
|
|
@@ -54422,7 +54521,7 @@ async function startServer(argv, env) {
|
|
|
54422
54521
|
opening.catch(() => pending.delete(project.dbPath));
|
|
54423
54522
|
}
|
|
54424
54523
|
const db = await opening;
|
|
54425
|
-
if (!
|
|
54524
|
+
if (!existsSync21(db.path)) throw new CtxError("DB_GONE");
|
|
54426
54525
|
return db;
|
|
54427
54526
|
}
|
|
54428
54527
|
function stopMarker(configDir, projectKey) {
|
|
@@ -54430,7 +54529,7 @@ async function startServer(argv, env) {
|
|
|
54430
54529
|
}
|
|
54431
54530
|
function stopRequested() {
|
|
54432
54531
|
const configDir = resolveConfigDir(process.env);
|
|
54433
|
-
return held.some((db) =>
|
|
54532
|
+
return held.some((db) => existsSync21(stopMarker(configDir, db.projectKey)));
|
|
54434
54533
|
}
|
|
54435
54534
|
async function journal(project, ctx, name, reply4) {
|
|
54436
54535
|
const db = await ownDb(project);
|
|
@@ -54443,7 +54542,7 @@ async function startServer(argv, env) {
|
|
|
54443
54542
|
let project;
|
|
54444
54543
|
const projectOf = () => {
|
|
54445
54544
|
if (agent === void 0) throw new CtxError("NO_PROJECT", { kind: "--agent" });
|
|
54446
|
-
project ??= resolveProject(agent, { env, argv, cwd: process.cwd(), piCwd: void 0 });
|
|
54545
|
+
project ??= resolveProject(agent, { env, argv, cwd: workspaceCwdOf(meta3, process.cwd(), process.argv[1]), piCwd: void 0 });
|
|
54447
54546
|
return project;
|
|
54448
54547
|
};
|
|
54449
54548
|
const ctx = {
|
|
@@ -54495,6 +54594,7 @@ async function startServer(argv, env) {
|
|
|
54495
54594
|
// DEVIATIONS: no version constant in contracts yet
|
|
54496
54595
|
{
|
|
54497
54596
|
instructions: INSTRUCTIONS,
|
|
54597
|
+
capabilities: { experimental: { [CODEX_SANDBOX_STATE_META]: {} } },
|
|
54498
54598
|
cacheHints: {
|
|
54499
54599
|
"tools/list": { ttlMs: TOOLS_TTL_MS, cacheScope: "public" },
|
|
54500
54600
|
"server/discover": { ttlMs: TOOLS_TTL_MS, cacheScope: "public" }
|
|
@@ -54545,7 +54645,8 @@ if (isEntry(import.meta.main, process.argv[1], fileURLToPath2(import.meta.url)))
|
|
|
54545
54645
|
export {
|
|
54546
54646
|
INSTRUCTIONS,
|
|
54547
54647
|
sessionIdOf,
|
|
54548
|
-
startServer
|
|
54648
|
+
startServer,
|
|
54649
|
+
workspaceCwdOf
|
|
54549
54650
|
};
|
|
54550
54651
|
/*! Bundled license information:
|
|
54551
54652
|
|