context-mode 2.0.0-next.30 → 2.0.0-next.33
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 +23 -23
- package/SHA256SUMS +15 -15
- package/cli.mjs +328 -157
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +75 -75
- package/opencode/plugin.js +720 -182
- package/package.json +1 -1
- package/pi/index.js +762 -224
- package/qwen-extension.json +1 -1
- package/run.mjs +69 -7
- package/search.mjs +69 -7
- package/server.mjs +746 -208
package/pi/index.js
CHANGED
|
@@ -11353,6 +11353,7 @@ var SOURCE_LABEL_MAX_CHARS = 80;
|
|
|
11353
11353
|
var CANCELLED_LINE = "Cancelled.";
|
|
11354
11354
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
11355
11355
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
11356
|
+
var RUN_LABEL_PREFIX = "run.mjs:";
|
|
11356
11357
|
var RUN_SESSION_PREFIX = "mcp:";
|
|
11357
11358
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
11358
11359
|
var NODE_MIN = "24.15.0";
|
|
@@ -11526,17 +11527,34 @@ var STATS_EMPTY_LINES = Object.freeze([
|
|
|
11526
11527
|
"sandbox, and only the short answer goes to the chat."
|
|
11527
11528
|
]);
|
|
11528
11529
|
var STATS_KIND_LABELS = Object.freeze([
|
|
11529
|
-
|
|
11530
|
+
// D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
|
|
11530
11531
|
["index", "Content indexed"],
|
|
11531
11532
|
["edit", "File edits"],
|
|
11532
|
-
["toolerr", "
|
|
11533
|
+
["toolerr", "Issues kept"],
|
|
11533
11534
|
["decision", "Your decisions"],
|
|
11535
|
+
["cmd", "Other tool calls"],
|
|
11534
11536
|
["prompt", "Your prompts"]
|
|
11535
11537
|
]);
|
|
11536
11538
|
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
11537
|
-
"ctx_resume brings back your last task, files changed and open
|
|
11539
|
+
"ctx_resume brings back your last task, files changed and open issues",
|
|
11538
11540
|
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
11539
11541
|
]);
|
|
11542
|
+
var STATS_WINDOW_TOKENS = 2e5;
|
|
11543
|
+
var STATS_THOUSAND = 1e3;
|
|
11544
|
+
var STATS_WHOLE_FROM = 10;
|
|
11545
|
+
var STATS_DAYS = 7;
|
|
11546
|
+
var STATS_TOP_OUTPUTS = 3;
|
|
11547
|
+
var STATS_CARD_W = 19;
|
|
11548
|
+
var STATS_DAY_BAR = 48;
|
|
11549
|
+
var STATS_TOKEN_NOTE = " (at 4 bytes per token; a Claude context window is 200K tokens)";
|
|
11550
|
+
var STATS_WAYS = Object.freeze([
|
|
11551
|
+
["sandbox", "\u2588", "sandbox run"],
|
|
11552
|
+
["index", "\u2593", "index + search"],
|
|
11553
|
+
["redirect", "\u2592", "hook sent to sandbox"],
|
|
11554
|
+
["replace", "\u2591", "hook cut down"]
|
|
11555
|
+
]);
|
|
11556
|
+
var STATS_INDEX_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
|
|
11557
|
+
var STATS_FOOTER_URL = "https://contextmode.ai/?utm_source=ctx_stats&utm_medium=stats&utm_content=footer";
|
|
11540
11558
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
11541
11559
|
var PURGE_NO_SCOPE_LINE = "ctx_purge: pick one scope \u2014 session, source, or project.";
|
|
11542
11560
|
var PURGE_MANY_SCOPES_LINE = "ctx_purge: pick only one scope \u2014 session, source, or project.";
|
|
@@ -11552,7 +11570,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
11552
11570
|
var DECISION_LABEL_JOIN = " | ";
|
|
11553
11571
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11554
11572
|
var RELEASE_BRANCH = "release";
|
|
11555
|
-
var BUNDLE_SHA = true ? "
|
|
11573
|
+
var BUNDLE_SHA = true ? "a65cd5ad387fe1dc95f9320783843d566440d57c" : void 0;
|
|
11556
11574
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11557
11575
|
var DOCTOR_LABEL = Object.freeze({
|
|
11558
11576
|
D1: "version",
|
|
@@ -11582,20 +11600,25 @@ function DOCTOR_FAIL_LINE(host, check2, cause, command) {
|
|
|
11582
11600
|
return `FAIL ${host}: ${check2} \u2014 ${cause}. Fix: ${command}`;
|
|
11583
11601
|
}
|
|
11584
11602
|
var DOCTOR_FIX_UPGRADE = "run ctx_upgrade";
|
|
11585
|
-
var D1_DEV_BUILD_DETAIL = "dev build";
|
|
11603
|
+
var D1_DEV_BUILD_DETAIL = "dev build: source checkout; release builds stamp the sha";
|
|
11586
11604
|
var D1_UPDATE_DETAIL = "update available";
|
|
11587
11605
|
var D1_SHORT_SHA_LEN = 7;
|
|
11588
11606
|
var D1_PACKAGE_FILE = "package.json";
|
|
11589
11607
|
function D1_PREFIX(version4, sha) {
|
|
11590
11608
|
return `${version4 ?? "bundle"} (${sha.slice(0, D1_SHORT_SHA_LEN)})`;
|
|
11591
11609
|
}
|
|
11592
|
-
var
|
|
11593
|
-
|
|
11594
|
-
|
|
11610
|
+
var D1_SOURCE_NPM = "npm";
|
|
11611
|
+
var D1_SOURCE_TAGS = "GitHub tags";
|
|
11612
|
+
function D1_LATEST_PASS(tag2, source) {
|
|
11613
|
+
return `latest ${tag2} on ${source}`;
|
|
11614
|
+
}
|
|
11615
|
+
function D1_LATEST_UPDATE(tag2, source, latest) {
|
|
11616
|
+
return `${D1_UPDATE_DETAIL}, ${tag2} on ${source} is ${latest}`;
|
|
11595
11617
|
}
|
|
11596
|
-
function
|
|
11597
|
-
return
|
|
11618
|
+
function D1_LATEST_AHEAD(tag2, source, latest) {
|
|
11619
|
+
return `ahead of ${tag2} on ${source} (${latest})`;
|
|
11598
11620
|
}
|
|
11621
|
+
var D1_NO_VERSION = "no version in package.json";
|
|
11599
11622
|
var D1_LATEST_UNKNOWN = "latest unknown";
|
|
11600
11623
|
var D1_GIT_MISSING = "git not found on PATH";
|
|
11601
11624
|
function D1_GIT_EXIT(code, stderrLine) {
|
|
@@ -11606,7 +11629,9 @@ function D1_GIT_TIMEOUT(ms) {
|
|
|
11606
11629
|
}
|
|
11607
11630
|
var D1_GIT_CANCEL = "git stopped by cancel";
|
|
11608
11631
|
var D1_GIT_NO_START = "git did not start";
|
|
11609
|
-
|
|
11632
|
+
function D1_GIT_NO_TAG(tag2) {
|
|
11633
|
+
return `git answered no ${tag2} tag`;
|
|
11634
|
+
}
|
|
11610
11635
|
function D1_NPM_TIMEOUT(ms) {
|
|
11611
11636
|
return `npm registry timed out after ${ms} ms`;
|
|
11612
11637
|
}
|
|
@@ -11620,7 +11645,10 @@ function D1_NPM_NO_TAG(tag2) {
|
|
|
11620
11645
|
return `npm registry answered no ${tag2} version`;
|
|
11621
11646
|
}
|
|
11622
11647
|
var D1_CAUSE_JOIN = "; ";
|
|
11623
|
-
var
|
|
11648
|
+
var GIT_LS_REMOTE_TAG_ARGS = Object.freeze(["--tags", "--refs"]);
|
|
11649
|
+
var RELEASE_TAG_PATTERN = "v*";
|
|
11650
|
+
var RELEASE_TAG_REF_PREFIX = "refs/tags/v";
|
|
11651
|
+
var D1_GIT_CHECK_FIX = `git ls-remote --tags --refs ${RELEASE_REPO_URL} "${RELEASE_TAG_PATTERN}"`;
|
|
11624
11652
|
var D1_NPM_CHECK_FIX = "npm view context-mode dist-tags";
|
|
11625
11653
|
var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-tags";
|
|
11626
11654
|
var D1_PRERELEASE_SEP = "-";
|
|
@@ -11913,7 +11941,7 @@ var V1_REASON = Object.freeze({
|
|
|
11913
11941
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
11914
11942
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
11915
11943
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
11916
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only,
|
|
11944
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
11917
11945
|
});
|
|
11918
11946
|
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
11919
11947
|
var PLUGIN_NAME = SERVER_KEY;
|
|
@@ -11954,6 +11982,85 @@ var REPORT_ENV_PREFIX = "env.";
|
|
|
11954
11982
|
var REPORT_ENV_ENUMS = Object.freeze({
|
|
11955
11983
|
NODE_ENV: Object.freeze(["development", "production", "test"])
|
|
11956
11984
|
});
|
|
11985
|
+
var DOCTOR_ENV_PREFIX = "Environment: ";
|
|
11986
|
+
var DOCTOR_DOCS_URL = "https://contextmode.ai/docs/engine/doctor";
|
|
11987
|
+
var DOCTOR_DOCS_ANCHOR = "checks";
|
|
11988
|
+
function DOCTOR_DOCS_LINK(check2) {
|
|
11989
|
+
return `${DOCTOR_DOCS_URL}?utm_source=ctx_doctor&utm_medium=doctor&utm_content=${check2}#${DOCTOR_DOCS_ANCHOR}`;
|
|
11990
|
+
}
|
|
11991
|
+
var DOCTOR_DOCS_LABEL = "Docs: ";
|
|
11992
|
+
function D3_NO_SETUP_FIX(agent) {
|
|
11993
|
+
return `context-mode setup --agents ${agent}`;
|
|
11994
|
+
}
|
|
11995
|
+
function D5_FIXTURE_FILE_ABSENT(file2) {
|
|
11996
|
+
return `hook fixture ${file2} is absent: the round trip needs it`;
|
|
11997
|
+
}
|
|
11998
|
+
function D5_FIXTURE_PARSE(file2, cause) {
|
|
11999
|
+
return `the hook fixture file ${file2} failed to parse: ${cause}`;
|
|
12000
|
+
}
|
|
12001
|
+
function D5_FIXTURE_AGENT_ABSENT(file2, keys) {
|
|
12002
|
+
return `the hook fixture file ${file2} records payloads for ${keys.join(", ") || "zero agents"} only`;
|
|
12003
|
+
}
|
|
12004
|
+
var DOCTOR_REPORTS_DIR = "reports";
|
|
12005
|
+
var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
|
|
12006
|
+
var DOCTOR_REPORT_LINE = "Report file: ";
|
|
12007
|
+
var DOCTOR_GH_LINE = "File it: ";
|
|
12008
|
+
var DOCTOR_URL_LINE = "Or open: ";
|
|
12009
|
+
var DOCTOR_GH_NEXT = " --";
|
|
12010
|
+
var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
12011
|
+
DOCTOR_ENV_PREFIX,
|
|
12012
|
+
DOCTOR_DOCS_LABEL,
|
|
12013
|
+
DOCTOR_REPORT_LINE,
|
|
12014
|
+
DOCTOR_GH_LINE,
|
|
12015
|
+
DOCTOR_GH_NEXT.trim(),
|
|
12016
|
+
DOCTOR_URL_LINE
|
|
12017
|
+
]);
|
|
12018
|
+
var ISSUE_REPO_SLUG = "mksglu/context-mode";
|
|
12019
|
+
var ISSUE_FORM_FILE = "agent-report.yml";
|
|
12020
|
+
var ISSUE_URL_MAX = 8e3;
|
|
12021
|
+
var ISSUE_FORM_HEADINGS = Object.freeze([
|
|
12022
|
+
"Summary",
|
|
12023
|
+
"ctx-report",
|
|
12024
|
+
"What happened",
|
|
12025
|
+
"Hook errors",
|
|
12026
|
+
"Journal rows",
|
|
12027
|
+
"Agent config",
|
|
12028
|
+
"Expected",
|
|
12029
|
+
"Steps",
|
|
12030
|
+
"Environment"
|
|
12031
|
+
]);
|
|
12032
|
+
var DOCTOR_HOOK_LOG_LINES = 50;
|
|
12033
|
+
var DOCTOR_JOURNAL_ROWS = 30;
|
|
12034
|
+
var DOCTOR_CONFIG_LINES = 40;
|
|
12035
|
+
var DOCTOR_ENV_NAMES = Object.freeze([
|
|
12036
|
+
"CODEX_HOME",
|
|
12037
|
+
"CLAUDE_CONFIG_DIR",
|
|
12038
|
+
"CLAUDE_PLUGIN_ROOT",
|
|
12039
|
+
"COPILOT_HOME",
|
|
12040
|
+
"KIRO_HOME",
|
|
12041
|
+
"OPENCODE_CONFIG_DIR",
|
|
12042
|
+
"PI_CODING_AGENT_DIR",
|
|
12043
|
+
"XDG_CONFIG_HOME",
|
|
12044
|
+
"SHELL"
|
|
12045
|
+
]);
|
|
12046
|
+
var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
|
|
12047
|
+
var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
|
|
12048
|
+
var DOCTOR_MASK = "<masked>";
|
|
12049
|
+
var NATIVE_INSTALL = Object.freeze({
|
|
12050
|
+
"claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
|
|
12051
|
+
codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
|
|
12052
|
+
gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
|
|
12053
|
+
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
|
|
12054
|
+
opencode: ["opencode plugin add context-mode@next"],
|
|
12055
|
+
pi: ["pi install npm:context-mode@next"],
|
|
12056
|
+
"copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
|
|
12057
|
+
vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
|
|
12058
|
+
kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
|
|
12059
|
+
zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
|
|
12060
|
+
});
|
|
12061
|
+
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
12062
|
+
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
12063
|
+
var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
11957
12064
|
|
|
11958
12065
|
// src/adapters/pi.ts
|
|
11959
12066
|
var TOOL_NAME_PREFIX = "";
|
|
@@ -12415,8 +12522,8 @@ function decode6(raw) {
|
|
|
12415
12522
|
if (event === "SessionStart" && typeof raw.source === "string" && COPILOT_SOURCES[raw.source] !== void 0) ev.source = COPILOT_SOURCES[raw.source];
|
|
12416
12523
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
12417
12524
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
12418
|
-
const
|
|
12419
|
-
const tool = { name:
|
|
12525
|
+
const toolName2 = String(raw[k.tool] ?? "");
|
|
12526
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
12420
12527
|
ev.tool = tool;
|
|
12421
12528
|
}
|
|
12422
12529
|
if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
|
|
@@ -12530,9 +12637,9 @@ function decodeCamel(p, name) {
|
|
|
12530
12637
|
if (event === "SessionStart" && typeof p.source === "string" && SESSION_SOURCES[p.source] !== void 0) ev.source = SESSION_SOURCES[p.source];
|
|
12531
12638
|
if (event === "UserPromptSubmit" && typeof p.prompt === "string") ev.prompt = p.prompt;
|
|
12532
12639
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
12533
|
-
const
|
|
12534
|
-
const canonical = canonicalName4(
|
|
12535
|
-
ev.tool = { name:
|
|
12640
|
+
const toolName2 = String(p.toolName ?? "");
|
|
12641
|
+
const canonical = canonicalName4(toolName2);
|
|
12642
|
+
ev.tool = { name: toolName2, canonicalName: canonical, input: policyInput(toolName2, canonical, readArgs2(p.toolArgs)) };
|
|
12536
12643
|
}
|
|
12537
12644
|
if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
|
|
12538
12645
|
return ev;
|
|
@@ -13325,10 +13432,10 @@ function lexSpan(st, from, inParen, depth, out, bodies) {
|
|
|
13325
13432
|
}
|
|
13326
13433
|
function scan(cmd) {
|
|
13327
13434
|
const st = { s: cmd, n: cmd.length, end: "complete" };
|
|
13328
|
-
const
|
|
13435
|
+
const tokens2 = [];
|
|
13329
13436
|
const heredocBodies = [];
|
|
13330
|
-
lexSpan(st, 0, false, 0,
|
|
13331
|
-
return { tokens, heredocBodies, end: st.end };
|
|
13437
|
+
lexSpan(st, 0, false, 0, tokens2, heredocBodies);
|
|
13438
|
+
return { tokens: tokens2, heredocBodies, end: st.end };
|
|
13332
13439
|
}
|
|
13333
13440
|
function dequote(word) {
|
|
13334
13441
|
let out = "";
|
|
@@ -14772,7 +14879,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
14772
14879
|
ctx_search: 'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. When nothing matches, the reply states the scope and how many sources are indexed.',
|
|
14773
14880
|
ctx_resume: "Example: `ctx_resume({})`. Required: none.\nReturns a summary of up to 2 KB for this session: the last task and user request, files changed, open errors, and search terms for ctx_search. A large row is shown as a pointer line instead of its full text; call `ctx_resume(seq: N)` with that line's number to read the full row. Call it with no `seq` to get the state block on demand. Use it after the conversation was compacted or resumed, before you repeat earlier work.",
|
|
14774
14881
|
ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports the bytes context-mode kept out of the chat: a text report (bars, per tool, per agent) and a Markdown table. Show the text block to the user unchanged, in a code block. Use it when the user asks what it saved.",
|
|
14775
|
-
ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause
|
|
14882
|
+
ctx_doctor: "Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",
|
|
14776
14883
|
ctx_upgrade: "Example: `ctx_upgrade({})`. Required: none.\nUpdates context-mode to the latest release for this agent and rewrites only context-mode's own entries in the host config. User entries and user settings such as hook timeouts are kept, and old entries are erased. Returns a table of what changed and whether a restart is needed. Use it only when the user asks to update context-mode.",
|
|
14777
14884
|
ctx_purge: 'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'
|
|
14778
14885
|
});
|
|
@@ -15285,8 +15392,8 @@ function firstLine(file2) {
|
|
|
15285
15392
|
return line === "" ? null : line;
|
|
15286
15393
|
}
|
|
15287
15394
|
function git(dir, args) {
|
|
15288
|
-
const { spawnSync:
|
|
15289
|
-
const r =
|
|
15395
|
+
const { spawnSync: spawnSync4 } = process.getBuiltinModule("node:child_process");
|
|
15396
|
+
const r = spawnSync4("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
15290
15397
|
if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
15291
15398
|
return r.stdout.split("\n").filter((l) => l !== "");
|
|
15292
15399
|
}
|
|
@@ -17864,8 +17971,8 @@ function trigramMatch(q) {
|
|
|
17864
17971
|
const words = blankTokens(q);
|
|
17865
17972
|
const kept = words.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
17866
17973
|
const parts = new Set((kept.length > 0 ? kept : words).filter((w) => [...w].length >= 3));
|
|
17867
|
-
const
|
|
17868
|
-
if (words.length > 1 && [...
|
|
17974
|
+
const whole2 = words.join(" ");
|
|
17975
|
+
if (words.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
17869
17976
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
17870
17977
|
}
|
|
17871
17978
|
function editDistance(a, b, max) {
|
|
@@ -18212,15 +18319,15 @@ function indentOf(line) {
|
|
|
18212
18319
|
}
|
|
18213
18320
|
function buildUnits(text) {
|
|
18214
18321
|
const lines = text.split("\n");
|
|
18215
|
-
const
|
|
18322
|
+
const stack2 = [];
|
|
18216
18323
|
const out = [];
|
|
18217
18324
|
for (let i = 0; i < lines.length; i++) {
|
|
18218
18325
|
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
18219
18326
|
const indent = indentOf(line);
|
|
18220
18327
|
if (indent === line.length) continue;
|
|
18221
|
-
while (
|
|
18222
|
-
out.push({ ord: i, body: [...
|
|
18223
|
-
|
|
18328
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
18329
|
+
out.push({ ord: i, body: [...stack2.map((s) => s.line), line].join("\n") });
|
|
18330
|
+
stack2.push({ indent, line });
|
|
18224
18331
|
}
|
|
18225
18332
|
return out;
|
|
18226
18333
|
}
|
|
@@ -18522,7 +18629,7 @@ function chunkText(text, kind, maxBytes = MAX_CHUNK_BYTES) {
|
|
|
18522
18629
|
}
|
|
18523
18630
|
function mdChunks(src, cap, lineCut) {
|
|
18524
18631
|
const out = [];
|
|
18525
|
-
const
|
|
18632
|
+
const stack2 = [];
|
|
18526
18633
|
let title = "";
|
|
18527
18634
|
let run = [];
|
|
18528
18635
|
const push2 = (text, bytes5) => {
|
|
@@ -18536,9 +18643,9 @@ function mdChunks(src, cap, lineCut) {
|
|
|
18536
18643
|
for (const b of lineBlocks(src, true)) {
|
|
18537
18644
|
if (b.heading !== void 0) {
|
|
18538
18645
|
flush();
|
|
18539
|
-
while (
|
|
18540
|
-
|
|
18541
|
-
title =
|
|
18646
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].level >= b.heading.level) stack2.pop();
|
|
18647
|
+
stack2.push(b.heading);
|
|
18648
|
+
title = stack2.map((h) => h.text).join(" > ");
|
|
18542
18649
|
}
|
|
18543
18650
|
if (b.fence !== void 0 && utf8Bytes(src.slice(b.start, b.end)) > cap) {
|
|
18544
18651
|
const pieces = fencePieces(src, b, b.fence, cap);
|
|
@@ -18771,7 +18878,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
18771
18878
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
18772
18879
|
return { end: start + r.read, written: r.written };
|
|
18773
18880
|
}
|
|
18774
|
-
function merge2(src, blocks,
|
|
18881
|
+
function merge2(src, blocks, join27, cap, lineCut) {
|
|
18775
18882
|
const out = [];
|
|
18776
18883
|
const scratch = new Uint8Array(cap);
|
|
18777
18884
|
let wide;
|
|
@@ -18781,7 +18888,7 @@ function merge2(src, blocks, join26, cap, lineCut) {
|
|
|
18781
18888
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
18782
18889
|
};
|
|
18783
18890
|
for (const b of blocks) {
|
|
18784
|
-
if (cur !== void 0 && !
|
|
18891
|
+
if (cur !== void 0 && !join27) {
|
|
18785
18892
|
emit(cur.start, cur.end, curBytes);
|
|
18786
18893
|
cur = void 0;
|
|
18787
18894
|
}
|
|
@@ -18993,8 +19100,8 @@ function renderRow(i, row5, skewed, named, budget) {
|
|
|
18993
19100
|
return body === null ? null : prefix + body;
|
|
18994
19101
|
}
|
|
18995
19102
|
function fitRow(row5, skewed, named, budget) {
|
|
18996
|
-
const
|
|
18997
|
-
if (bytes(
|
|
19103
|
+
const whole2 = JSON.stringify(row5);
|
|
19104
|
+
if (bytes(whole2) <= budget) return whole2;
|
|
18998
19105
|
const own4 = Object.keys(row5);
|
|
18999
19106
|
const tier = (k) => skewed.includes(k) ? 0 : named.has(k) ? 1 : typeof row5[k] !== "object" || row5[k] === null ? 2 : 3;
|
|
19000
19107
|
const order = [...own4].sort((a, b) => tier(a) - tier(b) || own4.indexOf(a) - own4.indexOf(b));
|
|
@@ -19649,14 +19756,14 @@ function exitCodeOf(text) {
|
|
|
19649
19756
|
const first = nl < 0 ? text : text.slice(0, nl);
|
|
19650
19757
|
if (!first.startsWith(EXIT_CODE_LINE_PREFIX)) return null;
|
|
19651
19758
|
let n = 0;
|
|
19652
|
-
let
|
|
19759
|
+
let digits2 = 0;
|
|
19653
19760
|
for (const ch of first.slice(EXIT_CODE_LINE_PREFIX.length)) {
|
|
19654
19761
|
const d = ch.charCodeAt(0) - DIGIT_0;
|
|
19655
19762
|
if (d < 0 || d > 9) break;
|
|
19656
19763
|
n = n * 10 + d;
|
|
19657
|
-
|
|
19764
|
+
digits2++;
|
|
19658
19765
|
}
|
|
19659
|
-
return
|
|
19766
|
+
return digits2 === 0 ? null : n;
|
|
19660
19767
|
}
|
|
19661
19768
|
function pathOf(input) {
|
|
19662
19769
|
for (const k of EDIT_PATH_KEYS) if (typeof input[k] === "string") return input[k];
|
|
@@ -19860,9 +19967,9 @@ import { accessSync, constants as fsConstants, statSync as statSync3 } from "nod
|
|
|
19860
19967
|
import path from "node:path";
|
|
19861
19968
|
|
|
19862
19969
|
// src/core/sandbox/path-entries.ts
|
|
19863
|
-
function pathEntries(value, platform = process.platform,
|
|
19970
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
19864
19971
|
const win = platform === "win32";
|
|
19865
|
-
return value.split(
|
|
19972
|
+
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
19866
19973
|
}
|
|
19867
19974
|
|
|
19868
19975
|
// src/core/sandbox/runtimes.ts
|
|
@@ -20527,8 +20634,8 @@ var ctxBatch = Object.freeze({
|
|
|
20527
20634
|
});
|
|
20528
20635
|
|
|
20529
20636
|
// src/core/tools/doctor.ts
|
|
20530
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
20531
|
-
import { basename as basename4, dirname as dirname7, join as
|
|
20637
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync13, existsSync as existsSync13 } from "node:fs";
|
|
20638
|
+
import { basename as basename4, dirname as dirname7, join as join15 } from "node:path";
|
|
20532
20639
|
|
|
20533
20640
|
// src/core/ops/doctor-config.ts
|
|
20534
20641
|
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -21384,9 +21491,9 @@ var Tokenizer = class {
|
|
|
21384
21491
|
}
|
|
21385
21492
|
NUMBER(cp) {
|
|
21386
21493
|
const start = this.text[this.tokenStart];
|
|
21387
|
-
const
|
|
21494
|
+
const sign2 = start === "+" ? CodePoint.PLUS_SIGN : start === "-" ? CodePoint.DASH : CodePoint.NULL;
|
|
21388
21495
|
if (cp === CodePoint.DIGIT_0) {
|
|
21389
|
-
if (
|
|
21496
|
+
if (sign2 === CodePoint.NULL) {
|
|
21390
21497
|
const startPos = this.codePointIterator.start;
|
|
21391
21498
|
const nextCp$1 = this.nextCode();
|
|
21392
21499
|
if (isDigit4(nextCp$1)) {
|
|
@@ -21425,19 +21532,19 @@ var Tokenizer = class {
|
|
|
21425
21532
|
}
|
|
21426
21533
|
cp = this.nextCode();
|
|
21427
21534
|
if (cp === CodePoint.LATIN_SMALL_X || cp === CodePoint.LATIN_SMALL_O || cp === CodePoint.LATIN_SMALL_B) {
|
|
21428
|
-
if (
|
|
21535
|
+
if (sign2 !== CodePoint.NULL) return this.reportParseError("unexpected-char");
|
|
21429
21536
|
return cp === CodePoint.LATIN_SMALL_X ? "HEX" : cp === CodePoint.LATIN_SMALL_O ? "OCTAL" : "BINARY";
|
|
21430
21537
|
}
|
|
21431
21538
|
if (cp === CodePoint.LATIN_SMALL_E || cp === CodePoint.LATIN_CAPITAL_E) {
|
|
21432
21539
|
this.data = {
|
|
21433
|
-
minus:
|
|
21540
|
+
minus: sign2 === CodePoint.DASH,
|
|
21434
21541
|
left: [CodePoint.DIGIT_0]
|
|
21435
21542
|
};
|
|
21436
21543
|
return "EXPONENT_RIGHT";
|
|
21437
21544
|
}
|
|
21438
21545
|
if (cp === CodePoint.DOT) {
|
|
21439
21546
|
this.data = {
|
|
21440
|
-
minus:
|
|
21547
|
+
minus: sign2 === CodePoint.DASH,
|
|
21441
21548
|
absInt: [CodePoint.DIGIT_0]
|
|
21442
21549
|
};
|
|
21443
21550
|
return "FRACTIONAL_RIGHT";
|
|
@@ -21446,7 +21553,7 @@ var Tokenizer = class {
|
|
|
21446
21553
|
return this.back("DATA");
|
|
21447
21554
|
}
|
|
21448
21555
|
const { out, nextCp, hasUnderscore } = this.parseDigits(cp, isDigit4);
|
|
21449
|
-
if (nextCp === CodePoint.DASH &&
|
|
21556
|
+
if (nextCp === CodePoint.DASH && sign2 === CodePoint.NULL && !hasUnderscore && out.length === 4) {
|
|
21450
21557
|
this.data = {
|
|
21451
21558
|
hasDate: true,
|
|
21452
21559
|
year: Number(String.fromCodePoint(...out)),
|
|
@@ -21458,7 +21565,7 @@ var Tokenizer = class {
|
|
|
21458
21565
|
};
|
|
21459
21566
|
return "DATE_MONTH";
|
|
21460
21567
|
}
|
|
21461
|
-
if (nextCp === CodePoint.COLON &&
|
|
21568
|
+
if (nextCp === CodePoint.COLON && sign2 === CodePoint.NULL && !hasUnderscore && out.length === 2) {
|
|
21462
21569
|
this.data = {
|
|
21463
21570
|
hasDate: false,
|
|
21464
21571
|
year: 0,
|
|
@@ -21472,19 +21579,19 @@ var Tokenizer = class {
|
|
|
21472
21579
|
}
|
|
21473
21580
|
if (nextCp === CodePoint.LATIN_SMALL_E || nextCp === CodePoint.LATIN_CAPITAL_E) {
|
|
21474
21581
|
this.data = {
|
|
21475
|
-
minus:
|
|
21582
|
+
minus: sign2 === CodePoint.DASH,
|
|
21476
21583
|
left: out
|
|
21477
21584
|
};
|
|
21478
21585
|
return "EXPONENT_RIGHT";
|
|
21479
21586
|
}
|
|
21480
21587
|
if (nextCp === CodePoint.DOT) {
|
|
21481
21588
|
this.data = {
|
|
21482
|
-
minus:
|
|
21589
|
+
minus: sign2 === CodePoint.DASH,
|
|
21483
21590
|
absInt: out
|
|
21484
21591
|
};
|
|
21485
21592
|
return "FRACTIONAL_RIGHT";
|
|
21486
21593
|
}
|
|
21487
|
-
this.endToken("Integer", "start",
|
|
21594
|
+
this.endToken("Integer", "start", sign2 === CodePoint.DASH ? String.fromCodePoint(CodePoint.DASH, ...out) : String.fromCodePoint(...out), 10);
|
|
21488
21595
|
return this.back("DATA");
|
|
21489
21596
|
}
|
|
21490
21597
|
HEX(cp) {
|
|
@@ -22980,8 +23087,8 @@ function setTomlText(text, path7, value) {
|
|
|
22980
23087
|
if (sameValue(cur, value)) return text;
|
|
22981
23088
|
const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
|
|
22982
23089
|
if (inline !== void 0) {
|
|
22983
|
-
const
|
|
22984
|
-
return replaceToml(text, doc, inline.full,
|
|
23090
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
|
|
23091
|
+
return replaceToml(text, doc, inline.full, whole2);
|
|
22985
23092
|
}
|
|
22986
23093
|
if (isPlainObject3(cur) && isPlainObject3(value)) {
|
|
22987
23094
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
@@ -23660,14 +23767,18 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
23660
23767
|
return true;
|
|
23661
23768
|
}
|
|
23662
23769
|
}
|
|
23770
|
+
function hookFile(row5, spec, home, env, worktree) {
|
|
23771
|
+
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
23772
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23773
|
+
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);
|
|
23774
|
+
return file2;
|
|
23775
|
+
}
|
|
23663
23776
|
function hookParts(row5, home, env, worktree) {
|
|
23664
23777
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
23665
23778
|
if (spec === null) return [];
|
|
23666
23779
|
let block;
|
|
23667
23780
|
try {
|
|
23668
|
-
const
|
|
23669
|
-
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23670
|
-
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);
|
|
23781
|
+
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
23671
23782
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
23672
23783
|
if (row5.id === "codex") {
|
|
23673
23784
|
const config4 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -23708,12 +23819,15 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
23708
23819
|
const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
23709
23820
|
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
23710
23821
|
const detail = D3_DETAIL(parts);
|
|
23711
|
-
|
|
23822
|
+
const fix = parts.includes(PART_MCP) && parts.includes(PART_HOOKS) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
23823
|
+
return fail2("D3", read3 === null ? detail : detail + D4_REASON_JOIN + read3, fix);
|
|
23712
23824
|
}
|
|
23713
23825
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
23714
23826
|
const findings = detectV1(agent, home, scope);
|
|
23715
23827
|
if (findings.length === 0) return pass("D4");
|
|
23716
|
-
|
|
23828
|
+
const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
|
|
23829
|
+
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass("D4"), detail };
|
|
23830
|
+
return fail2("D4", detail, DOCTOR_FIX_UPGRADE);
|
|
23717
23831
|
}
|
|
23718
23832
|
function parsedOrNull(agent, file2, jsonc) {
|
|
23719
23833
|
try {
|
|
@@ -23732,6 +23846,31 @@ function checkDoubleFire(agent, worktree) {
|
|
|
23732
23846
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
23733
23847
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
23734
23848
|
}
|
|
23849
|
+
function configPaths(row5, env, worktree) {
|
|
23850
|
+
const home = homeDirOf(env);
|
|
23851
|
+
if (home === null) return [];
|
|
23852
|
+
const out = [];
|
|
23853
|
+
const mcp = mcpFile(row5, home, env);
|
|
23854
|
+
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
23855
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23856
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join11(native, CODEX_PLUGIN_MCP_FILE) });
|
|
23857
|
+
const spec = HOOK_HOST_FILE[row5.id];
|
|
23858
|
+
if (spec !== null) {
|
|
23859
|
+
try {
|
|
23860
|
+
out.push({ label: "hook entries", path: hookFile(row5, spec, home, env, worktree) });
|
|
23861
|
+
} catch (err) {
|
|
23862
|
+
out.push({ label: "hook entries", path: err instanceof Error ? err.message : String(err) });
|
|
23863
|
+
}
|
|
23864
|
+
}
|
|
23865
|
+
if (spec !== null && spec.root === "plugin" || row5.installMode === "marketplace" || row5.installMode === "plugin") {
|
|
23866
|
+
try {
|
|
23867
|
+
out.push({ label: "plugin root", path: resolvePluginRoot(row5, env, worktree) });
|
|
23868
|
+
} catch (err) {
|
|
23869
|
+
out.push({ label: "plugin root", path: err instanceof Error ? err.message : String(err) });
|
|
23870
|
+
}
|
|
23871
|
+
}
|
|
23872
|
+
return out.filter((e, i) => out.findIndex((o) => o.path === e.path) === i);
|
|
23873
|
+
}
|
|
23735
23874
|
|
|
23736
23875
|
// src/core/ops/doctor-db.ts
|
|
23737
23876
|
import { existsSync as existsSync7 } from "node:fs";
|
|
@@ -23874,35 +24013,76 @@ async function npmLatest(url4, tag2, signal, timeoutMs) {
|
|
|
23874
24013
|
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
23875
24014
|
}
|
|
23876
24015
|
}
|
|
24016
|
+
function digits(s) {
|
|
24017
|
+
if (s === "") return false;
|
|
24018
|
+
for (const ch of s) if (ch < "0" || ch > "9") return false;
|
|
24019
|
+
return true;
|
|
24020
|
+
}
|
|
24021
|
+
function parseVersion(v) {
|
|
24022
|
+
const at2 = v.indexOf(D1_PRERELEASE_SEP);
|
|
24023
|
+
const core = (at2 < 0 ? v : v.slice(0, at2)).split(NODE_VERSION_SEP);
|
|
24024
|
+
if (core.length !== 3 || !core.every(digits)) return null;
|
|
24025
|
+
const nums = [Number(core[0]), Number(core[1]), Number(core[2])];
|
|
24026
|
+
if (at2 < 0) return { core: nums, pre: [] };
|
|
24027
|
+
const pre = v.slice(at2 + 1).split(NODE_VERSION_SEP);
|
|
24028
|
+
if (pre[0] === "" || digits(pre[0]) || pre.length > 2) return null;
|
|
24029
|
+
if (pre.length === 1) return { core: nums, pre: [pre[0]] };
|
|
24030
|
+
return digits(pre[1]) ? { core: nums, pre: [pre[0], Number(pre[1])] } : null;
|
|
24031
|
+
}
|
|
24032
|
+
function sign(n) {
|
|
24033
|
+
return n < 0 ? -1 : n > 0 ? 1 : 0;
|
|
24034
|
+
}
|
|
24035
|
+
function compareVersions(a, b) {
|
|
24036
|
+
const x = parseVersion(a);
|
|
24037
|
+
const y = parseVersion(b);
|
|
24038
|
+
if (x === null || y === null) return null;
|
|
24039
|
+
for (let k = 0; k < 3; k++) if (x.core[k] !== y.core[k]) return sign(x.core[k] - y.core[k]);
|
|
24040
|
+
if (x.pre.length === 0 || y.pre.length === 0) return sign(y.pre.length - x.pre.length);
|
|
24041
|
+
if (x.pre[0] !== y.pre[0]) return x.pre[0] < y.pre[0] ? -1 : 1;
|
|
24042
|
+
return sign((x.pre[1] ?? -1) - (y.pre[1] ?? -1));
|
|
24043
|
+
}
|
|
24044
|
+
function highestTag(stdout, tag2) {
|
|
24045
|
+
let best;
|
|
24046
|
+
for (const line of stdout.split("\n")) {
|
|
24047
|
+
const [sha, ref] = line.trim().split(LS_REMOTE_FIELD_SEP);
|
|
24048
|
+
if (sha === void 0 || sha.length !== GIT_SHA_HEX_LEN || ref === void 0 || !ref.startsWith(RELEASE_TAG_REF_PREFIX)) continue;
|
|
24049
|
+
const v = ref.slice(RELEASE_TAG_REF_PREFIX.length);
|
|
24050
|
+
if (parseVersion(v) === null || channelOf(v) !== tag2) continue;
|
|
24051
|
+
if (best === void 0 || compareVersions(v, best) === 1) best = v;
|
|
24052
|
+
}
|
|
24053
|
+
return best;
|
|
24054
|
+
}
|
|
24055
|
+
function versionRow(head, installed, tag2, source, latest, tail) {
|
|
24056
|
+
const cmp = compareVersions(installed, latest) ?? (installed === latest ? 0 : -1);
|
|
24057
|
+
if (cmp === 0) return pass3("D1", head + D1_LATEST_PASS(tag2, source) + tail);
|
|
24058
|
+
if (cmp > 0) return pass3("D1", head + D1_LATEST_AHEAD(tag2, source, latest) + tail);
|
|
24059
|
+
return fail4("D1", head + D1_LATEST_UPDATE(tag2, source, latest) + tail, DOCTOR_FIX_UPGRADE);
|
|
24060
|
+
}
|
|
23877
24061
|
async function checkVersion(i) {
|
|
23878
24062
|
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
23879
24063
|
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24064
|
+
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + D1_NO_VERSION, D1_NPM_CHECK_FIX);
|
|
24065
|
+
const tag2 = channelOf(i.version);
|
|
23880
24066
|
const git3 = findRuntime(GIT_BIN, i.env);
|
|
24067
|
+
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24068
|
+
if (npm.ok) return versionRow(head, i.version, tag2, D1_SOURCE_NPM, npm.version, "");
|
|
23881
24069
|
let cause = D1_GIT_MISSING;
|
|
23882
24070
|
if (git3 !== null) {
|
|
23883
|
-
const r = await runProcess([git3, GIT_LS_REMOTE, RELEASE_REPO_URL,
|
|
24071
|
+
const r = await runProcess([git3, GIT_LS_REMOTE, ...GIT_LS_REMOTE_TAG_ARGS, RELEASE_REPO_URL, RELEASE_TAG_PATTERN], {
|
|
23884
24072
|
cwd: i.cwd,
|
|
23885
24073
|
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
23886
24074
|
signal: i.signal,
|
|
23887
24075
|
timeoutMs: i.timeoutMs
|
|
23888
24076
|
});
|
|
23889
24077
|
if (r.exitCode === 0 && r.killed === null) {
|
|
23890
|
-
const latest = r.stdout.toString("utf8")
|
|
23891
|
-
if (latest.
|
|
23892
|
-
|
|
23893
|
-
}
|
|
23894
|
-
cause = D1_GIT_NO_SHA;
|
|
24078
|
+
const latest = highestTag(r.stdout.toString("utf8"), tag2);
|
|
24079
|
+
if (latest !== void 0) return versionRow(head, i.version, tag2, D1_SOURCE_TAGS, latest, D1_CAUSE_JOIN + npm.cause);
|
|
24080
|
+
cause = D1_GIT_NO_TAG(tag2);
|
|
23895
24081
|
} else {
|
|
23896
24082
|
cause = gitCause(r, i.timeoutMs);
|
|
23897
24083
|
}
|
|
23898
24084
|
}
|
|
23899
|
-
|
|
23900
|
-
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + cause, handFix);
|
|
23901
|
-
const tag2 = channelOf(i.version);
|
|
23902
|
-
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
23903
|
-
if (!npm.ok) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + cause + D1_CAUSE_JOIN + npm.cause, handFix);
|
|
23904
|
-
if (npm.version === i.version) return pass3("D1", head + D1_NPM_PASS(tag2) + D1_CAUSE_JOIN + cause);
|
|
23905
|
-
return fail4("D1", head + D1_NPM_UPDATE(tag2, npm.version) + D1_CAUSE_JOIN + cause, DOCTOR_FIX_UPGRADE);
|
|
24085
|
+
return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + npm.cause + D1_CAUSE_JOIN + cause, git3 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX);
|
|
23906
24086
|
}
|
|
23907
24087
|
function numbers(v) {
|
|
23908
24088
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -24181,16 +24361,19 @@ function isObject5(v) {
|
|
|
24181
24361
|
}
|
|
24182
24362
|
function loadFixture(bundleDir2, agent) {
|
|
24183
24363
|
const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
24184
|
-
if (!existsSync10(file2)) return
|
|
24364
|
+
if (!existsSync10(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
24185
24365
|
let all;
|
|
24186
24366
|
try {
|
|
24187
24367
|
all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
|
|
24188
|
-
} catch {
|
|
24189
|
-
return
|
|
24368
|
+
} catch (err) {
|
|
24369
|
+
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
24190
24370
|
}
|
|
24191
|
-
if (!isObject5(all)
|
|
24371
|
+
if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
|
|
24372
|
+
if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
|
|
24192
24373
|
const e = all[agent];
|
|
24193
|
-
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload"))
|
|
24374
|
+
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
|
|
24375
|
+
return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
|
|
24376
|
+
}
|
|
24194
24377
|
return { event: e.event, payload: e.payload };
|
|
24195
24378
|
}
|
|
24196
24379
|
function payloadFor(payload, worktree) {
|
|
@@ -24244,7 +24427,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24244
24427
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
24245
24428
|
}
|
|
24246
24429
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
24247
|
-
if (
|
|
24430
|
+
if ("cause" in fixture) return row("UNKNOWN", fixture.cause);
|
|
24248
24431
|
const now = i.now ?? (() => performance.now());
|
|
24249
24432
|
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
24250
24433
|
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
@@ -24406,8 +24589,13 @@ function envLine(key, value) {
|
|
|
24406
24589
|
const typedValue = allowed !== void 0 && allowed.includes(value) ? value : REPORT_INVALID;
|
|
24407
24590
|
return REPORT_ENV_PREFIX + typedKey + ": " + typedValue;
|
|
24408
24591
|
}
|
|
24592
|
+
function fixCell(agent, row5) {
|
|
24593
|
+
if (row5.status === "PASS") return "";
|
|
24594
|
+
if (row5.status === "FAIL") return DOCTOR_FAIL_LINE(agent, row5.id, row5.detail, row5.fixCommand ?? "");
|
|
24595
|
+
return row5.fixCommand === void 0 ? "" : "Fix: " + row5.fixCommand;
|
|
24596
|
+
}
|
|
24409
24597
|
function rowLine(agent, row5) {
|
|
24410
|
-
const fix =
|
|
24598
|
+
const fix = fixCell(agent, row5);
|
|
24411
24599
|
return "| " + [row5.id + " " + row5.label, row5.status, row5.detail, fix].join(" | ") + " |";
|
|
24412
24600
|
}
|
|
24413
24601
|
function buildReport(input) {
|
|
@@ -24437,6 +24625,196 @@ function buildReportHead(input) {
|
|
|
24437
24625
|
return lines.concat(tail).join("\n");
|
|
24438
24626
|
}
|
|
24439
24627
|
|
|
24628
|
+
// src/core/ops/doctor-issue.ts
|
|
24629
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
24630
|
+
import { closeSync, existsSync as existsSync12, fstatSync, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24631
|
+
import { delimiter, join as join14 } from "node:path";
|
|
24632
|
+
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
24633
|
+
function tildeOf(env) {
|
|
24634
|
+
const home = homeDirOf(env);
|
|
24635
|
+
if (home === null || home === "") return (t) => t;
|
|
24636
|
+
const homes = [home];
|
|
24637
|
+
try {
|
|
24638
|
+
const real2 = realpathSync8.native(home);
|
|
24639
|
+
if (real2 !== home) homes.push(real2);
|
|
24640
|
+
} catch {
|
|
24641
|
+
}
|
|
24642
|
+
homes.sort((a, b) => b.length - a.length);
|
|
24643
|
+
const slash = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
|
|
24644
|
+
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash(piece)).join("~"), t);
|
|
24645
|
+
}
|
|
24646
|
+
function maskLine(line) {
|
|
24647
|
+
const lower = line.toLowerCase();
|
|
24648
|
+
const named = DOCTOR_SECRET_WORDS.some((w) => lower.includes(w));
|
|
24649
|
+
const token = TOKEN_PREFIXES.some((p) => line.includes(p));
|
|
24650
|
+
if (!named && !token) return line;
|
|
24651
|
+
const at2 = Math.max(line.indexOf(":"), line.indexOf("="));
|
|
24652
|
+
return at2 === -1 ? DOCTOR_MASK : line.slice(0, at2 + 1) + " " + DOCTOR_MASK;
|
|
24653
|
+
}
|
|
24654
|
+
function environmentLine(ctx, adapter, env, version4) {
|
|
24655
|
+
const sha = BUNDLE_SHA === void 0 ? "dev build" : BUNDLE_SHA.slice(0, 7);
|
|
24656
|
+
const client = ctx.clientInfo;
|
|
24657
|
+
const agent = client === void 0 ? adapter.id : client.name === adapter.id ? `${adapter.id} ${client.version}` : `${adapter.id} ${client.version} (client ${client.name})`;
|
|
24658
|
+
const shell = env.SHELL ?? env.ComSpec ?? "sh";
|
|
24659
|
+
return `${DOCTOR_ENV_PREFIX}context-mode ${version4 ?? "source checkout"} (${sha}), agent ${agent}
|
|
24660
|
+
${DOCTOR_ENV_PREFIX}${process.platform}-${process.arch}, Node ${process.version}, shell ${shell}`;
|
|
24661
|
+
}
|
|
24662
|
+
function gitVersion(env) {
|
|
24663
|
+
const r = spawnSync3("git", ["--version"], { env, encoding: "utf8", timeout: DOCTOR_GIT_VERSION_TIMEOUT_MS, windowsHide: true });
|
|
24664
|
+
if (r.status === 0) return `${r.stdout}`.trim();
|
|
24665
|
+
return `git --version: ${r.error ? r.error.message : `exit ${r.status}`}`;
|
|
24666
|
+
}
|
|
24667
|
+
function onPath(env, tool) {
|
|
24668
|
+
const names = process.platform === "win32" ? [tool + EXE_SUFFIX, tool + ".cmd", tool] : [tool];
|
|
24669
|
+
const out = [];
|
|
24670
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
24671
|
+
if (dir === "") continue;
|
|
24672
|
+
for (const n of names) if (existsSync12(join14(dir, n))) {
|
|
24673
|
+
out.push(join14(dir, n));
|
|
24674
|
+
break;
|
|
24675
|
+
}
|
|
24676
|
+
}
|
|
24677
|
+
return out;
|
|
24678
|
+
}
|
|
24679
|
+
function hookLogTail(env) {
|
|
24680
|
+
const file2 = hookLogPath(env);
|
|
24681
|
+
if (file2 === "" || !existsSync12(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
24682
|
+
try {
|
|
24683
|
+
const fd = openSync(file2, "r");
|
|
24684
|
+
try {
|
|
24685
|
+
const size = fstatSync(fd).size;
|
|
24686
|
+
const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
|
|
24687
|
+
const buf = Buffer.alloc(size - start);
|
|
24688
|
+
readSync(fd, buf, 0, buf.length, start);
|
|
24689
|
+
const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
|
|
24690
|
+
if (start > 0) lines.shift();
|
|
24691
|
+
return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
|
|
24692
|
+
} finally {
|
|
24693
|
+
closeSync(fd);
|
|
24694
|
+
}
|
|
24695
|
+
} catch (err) {
|
|
24696
|
+
return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
|
|
24697
|
+
}
|
|
24698
|
+
}
|
|
24699
|
+
async function journalRows(ctx) {
|
|
24700
|
+
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
24701
|
+
if (!existsSync12(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
24702
|
+
try {
|
|
24703
|
+
const db = await openDb(ctx.project, { readOnly: true });
|
|
24704
|
+
try {
|
|
24705
|
+
const rows = db.raw.prepare(`SELECT kind, tool, bytes, ok, exit_code, created_at FROM events ORDER BY seq DESC LIMIT ${DOCTOR_JOURNAL_ROWS}`).all();
|
|
24706
|
+
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
24707
|
+
return head.concat(rows.map((r) => `| ${cell5(r.kind)} | ${cell5(r.tool)} | ${cell5(r.bytes)} | ${cell5(r.ok)} | ${cell5(r.exit_code)} | ${typeof r.created_at === "number" ? new Date(r.created_at).toISOString() : cell5(r.created_at)} |`));
|
|
24708
|
+
} finally {
|
|
24709
|
+
closeDb(db);
|
|
24710
|
+
}
|
|
24711
|
+
} catch (err) {
|
|
24712
|
+
return [`journal read: ${err instanceof Error ? err.message : String(err)}`];
|
|
24713
|
+
}
|
|
24714
|
+
}
|
|
24715
|
+
function agentConfig(adapter, env, worktree) {
|
|
24716
|
+
const home = homeDirOf(env);
|
|
24717
|
+
const files = configPaths(adapter, env, worktree);
|
|
24718
|
+
if (home !== null) {
|
|
24719
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join14(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
24720
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join14(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
24721
|
+
}
|
|
24722
|
+
const out = [];
|
|
24723
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24724
|
+
for (const f of files) {
|
|
24725
|
+
if (seen.has(f.path)) continue;
|
|
24726
|
+
seen.add(f.path);
|
|
24727
|
+
if (!existsSync12(f.path)) {
|
|
24728
|
+
out.push(`${f.label}: ${f.path} (absent)`);
|
|
24729
|
+
continue;
|
|
24730
|
+
}
|
|
24731
|
+
let text = "";
|
|
24732
|
+
try {
|
|
24733
|
+
text = readFileSync12(f.path, "utf8");
|
|
24734
|
+
} catch (err) {
|
|
24735
|
+
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
24736
|
+
continue;
|
|
24737
|
+
}
|
|
24738
|
+
const hit = text.split("\n").filter((l) => l.includes("context-mode") || l.includes("hook.mjs") || adapter.id === "codex" && l.includes("trust"));
|
|
24739
|
+
out.push(`${f.label}: ${f.path} (${hit.length} matching lines)`);
|
|
24740
|
+
for (const l of hit.slice(0, DOCTOR_CONFIG_LINES)) out.push(" " + maskLine(l.trimEnd()));
|
|
24741
|
+
}
|
|
24742
|
+
return out;
|
|
24743
|
+
}
|
|
24744
|
+
function failing(rows) {
|
|
24745
|
+
return rows.filter((r) => r.status === "FAIL");
|
|
24746
|
+
}
|
|
24747
|
+
function issueTitle(agent, rows) {
|
|
24748
|
+
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
24749
|
+
}
|
|
24750
|
+
function summaryOf(agent, rows) {
|
|
24751
|
+
const f = failing(rows)[0];
|
|
24752
|
+
return f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`;
|
|
24753
|
+
}
|
|
24754
|
+
async function buildIssueBody(i) {
|
|
24755
|
+
const tilde = tildeOf(i.env);
|
|
24756
|
+
const agent = i.adapter.id;
|
|
24757
|
+
const install = NATIVE_INSTALL[agent] ?? [];
|
|
24758
|
+
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
24759
|
+
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
24760
|
+
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
24761
|
+
const sections = {
|
|
24762
|
+
"Summary": [summaryOf(agent, i.rows)],
|
|
24763
|
+
"ctx-report": [i.table],
|
|
24764
|
+
"What happened": [
|
|
24765
|
+
"Rows that need a look:",
|
|
24766
|
+
...failRows.map((r) => `- ${r.id} ${r.label} ${r.status}: ${r.detail}${r.fixCommand ? ` (Fix: ${r.fixCommand})` : ""}`),
|
|
24767
|
+
"Error code and text: <the agent fills this in: the exact error the user saw>"
|
|
24768
|
+
],
|
|
24769
|
+
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
24770
|
+
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
24771
|
+
"Agent config": agentConfig(i.adapter, i.env, i.ctx.project.worktree),
|
|
24772
|
+
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
24773
|
+
"Steps": [
|
|
24774
|
+
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
24775
|
+
"Prompt or command: <the agent fills this in: the exact prompt or command>",
|
|
24776
|
+
"Actual: <the agent fills this in: what context-mode did, with the byte count>",
|
|
24777
|
+
"Repro script (fresh HOME, native install for " + agent + "):",
|
|
24778
|
+
"```sh",
|
|
24779
|
+
'export HOME="$(mktemp -d)"',
|
|
24780
|
+
'cd "$HOME"',
|
|
24781
|
+
...install,
|
|
24782
|
+
"<the command or prompt above>",
|
|
24783
|
+
"```"
|
|
24784
|
+
],
|
|
24785
|
+
"Environment": [
|
|
24786
|
+
i.envLine,
|
|
24787
|
+
`context-mode bundle: ${i.bundleDir}`,
|
|
24788
|
+
`Install route: ${install.join(" && ")}`,
|
|
24789
|
+
`git: ${gitVersion(i.env)}`,
|
|
24790
|
+
...pathTools,
|
|
24791
|
+
...envNames,
|
|
24792
|
+
`Project: ${i.ctx.project.worktree} (key ${i.ctx.project.projectKey})`,
|
|
24793
|
+
"Filed by: <your agent name, version, model id>"
|
|
24794
|
+
]
|
|
24795
|
+
};
|
|
24796
|
+
const out = [];
|
|
24797
|
+
for (const h of ISSUE_FORM_HEADINGS) out.push(`### ${h}`, "", ...sections[h] ?? [], "");
|
|
24798
|
+
return tilde(out.join("\n"));
|
|
24799
|
+
}
|
|
24800
|
+
async function writeIssueReport(i) {
|
|
24801
|
+
const tilde = tildeOf(i.env);
|
|
24802
|
+
const body = await buildIssueBody(i);
|
|
24803
|
+
const dir = join14(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
24804
|
+
mkdirSync5(dir, { recursive: true });
|
|
24805
|
+
const file2 = join14(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
24806
|
+
writeFileSync3(file2, body);
|
|
24807
|
+
const shown2 = tilde(file2);
|
|
24808
|
+
const title = issueTitle(i.adapter.id, i.rows);
|
|
24809
|
+
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
24810
|
+
return [DOCTOR_REPORT_LINE + shown2, DOCTOR_GH_LINE + gh[0], gh[1], gh[2], DOCTOR_URL_LINE + formUrl(title, summaryOf(i.adapter.id, i.rows))];
|
|
24811
|
+
}
|
|
24812
|
+
function formUrl(title, summary) {
|
|
24813
|
+
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
24814
|
+
const full = `${base}&summary=${encodeURIComponent(summary)}`;
|
|
24815
|
+
return full.length < ISSUE_URL_MAX ? full : base;
|
|
24816
|
+
}
|
|
24817
|
+
|
|
24440
24818
|
// src/core/tools/doctor.ts
|
|
24441
24819
|
var ctxDoctorSchema = external_exports.object({}).strict();
|
|
24442
24820
|
function lineOf2(err) {
|
|
@@ -24451,7 +24829,7 @@ async function guard(id, run) {
|
|
|
24451
24829
|
}
|
|
24452
24830
|
}
|
|
24453
24831
|
async function codexDb(ctx, adapter) {
|
|
24454
|
-
if (adapter.id !== "codex" || !
|
|
24832
|
+
if (adapter.id !== "codex" || !existsSync13(ctx.project.dbPath)) return null;
|
|
24455
24833
|
try {
|
|
24456
24834
|
return await openDb(ctx.project, { readOnly: true });
|
|
24457
24835
|
} catch {
|
|
@@ -24481,11 +24859,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
24481
24859
|
}
|
|
24482
24860
|
}
|
|
24483
24861
|
function ownServerId(configDir, projectKey) {
|
|
24484
|
-
const dir =
|
|
24485
|
-
if (!
|
|
24862
|
+
const dir = join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24863
|
+
if (!existsSync13(dir)) return "";
|
|
24486
24864
|
for (const name of readdirSync5(dir)) {
|
|
24487
24865
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24488
|
-
if (
|
|
24866
|
+
if (readFileSync13(join15(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
24489
24867
|
}
|
|
24490
24868
|
return "";
|
|
24491
24869
|
}
|
|
@@ -24530,24 +24908,39 @@ function reportEnv(env) {
|
|
|
24530
24908
|
}
|
|
24531
24909
|
return out;
|
|
24532
24910
|
}
|
|
24533
|
-
async function
|
|
24911
|
+
async function doctorReply(ctx, host) {
|
|
24534
24912
|
const adapter = getAdapter(ctx.project.agent);
|
|
24535
|
-
const host = { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 };
|
|
24536
24913
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
24537
|
-
const
|
|
24538
|
-
const
|
|
24539
|
-
const
|
|
24540
|
-
const
|
|
24541
|
-
|
|
24914
|
+
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
24915
|
+
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
24916
|
+
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
24917
|
+
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
24918
|
+
const table3 = buildReport(input);
|
|
24919
|
+
let notes = [];
|
|
24920
|
+
if (failed2) {
|
|
24921
|
+
try {
|
|
24922
|
+
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
24923
|
+
} catch (err) {
|
|
24924
|
+
notes = [`Report file: ${lineOf2(err)}`];
|
|
24925
|
+
}
|
|
24926
|
+
}
|
|
24927
|
+
const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
|
|
24928
|
+
const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
|
|
24929
|
+
const whole2 = [envLine2, table3, ...docs, ...notes].join("\n");
|
|
24930
|
+
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
24931
|
+
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
24542
24932
|
const db = await openDb(ctx.project);
|
|
24543
24933
|
try {
|
|
24544
|
-
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL,
|
|
24934
|
+
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
24545
24935
|
} finally {
|
|
24546
24936
|
closeDb(db);
|
|
24547
24937
|
}
|
|
24548
|
-
const text = buildReportHead(input);
|
|
24938
|
+
const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
|
|
24549
24939
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
24550
24940
|
}
|
|
24941
|
+
async function handler2(_input, ctx) {
|
|
24942
|
+
return doctorReply(ctx, { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 });
|
|
24943
|
+
}
|
|
24551
24944
|
var ctxDoctor = Object.freeze({
|
|
24552
24945
|
name: "ctx_doctor",
|
|
24553
24946
|
schema: ctxDoctorSchema,
|
|
@@ -24558,9 +24951,9 @@ var ctxDoctor = Object.freeze({
|
|
|
24558
24951
|
});
|
|
24559
24952
|
|
|
24560
24953
|
// src/core/tools/execute.ts
|
|
24561
|
-
import { existsSync as
|
|
24954
|
+
import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
24562
24955
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24563
|
-
import { dirname as dirname8, join as
|
|
24956
|
+
import { dirname as dirname8, join as join16, parse as parse3, resolve as resolve6 } from "node:path";
|
|
24564
24957
|
|
|
24565
24958
|
// src/core/sandbox/win-build.ts
|
|
24566
24959
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -24644,7 +25037,7 @@ function schemaLine(issue4) {
|
|
|
24644
25037
|
}
|
|
24645
25038
|
function fileError(given, abs, root) {
|
|
24646
25039
|
let dir = abs;
|
|
24647
|
-
while (!
|
|
25040
|
+
while (!existsSync14(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
24648
25041
|
if (isInside(root, dir)) return null;
|
|
24649
25042
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
24650
25043
|
}
|
|
@@ -24725,9 +25118,9 @@ async function handler3(raw, ctx) {
|
|
|
24725
25118
|
if (takesDashC(input.language, runtime)) {
|
|
24726
25119
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
24727
25120
|
} else {
|
|
24728
|
-
tmpDir = mkdtempSync(
|
|
24729
|
-
const file2 =
|
|
24730
|
-
|
|
25121
|
+
tmpDir = mkdtempSync(join16(tmpdir2(), TMP_PREFIX));
|
|
25122
|
+
const file2 = join16(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25123
|
+
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
24731
25124
|
argv = scriptArgv(input.language, runtime, file2);
|
|
24732
25125
|
}
|
|
24733
25126
|
if (input.background === true) {
|
|
@@ -24761,21 +25154,21 @@ var ctxExecute = {
|
|
|
24761
25154
|
};
|
|
24762
25155
|
|
|
24763
25156
|
// src/core/tools/index.ts
|
|
24764
|
-
import { existsSync as
|
|
24765
|
-
import { dirname as dirname9, extname, join as
|
|
25157
|
+
import { existsSync as existsSync15, readFileSync as readFileSync15, statSync as statSync7 } from "node:fs";
|
|
25158
|
+
import { dirname as dirname9, extname, join as join18, relative as relative3, resolve as resolve7 } from "node:path";
|
|
24766
25159
|
|
|
24767
25160
|
// src/core/index/walk.ts
|
|
24768
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
24769
|
-
import { join as
|
|
25161
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync6 } from "node:fs";
|
|
25162
|
+
import { join as join17 } from "node:path";
|
|
24770
25163
|
var GITIGNORE = ".gitignore";
|
|
24771
25164
|
var GIT_DIR = ".git";
|
|
24772
25165
|
function walkDir(root, containmentRoot) {
|
|
24773
|
-
const real2 =
|
|
25166
|
+
const real2 = realpathSync9(root);
|
|
24774
25167
|
if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
24775
25168
|
const found = [];
|
|
24776
25169
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
24777
25170
|
found.sort(compareFound);
|
|
24778
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25171
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join17(...f.dir, f.name) }));
|
|
24779
25172
|
}
|
|
24780
25173
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
24781
25174
|
let entries;
|
|
@@ -24784,17 +25177,17 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24784
25177
|
} catch {
|
|
24785
25178
|
return;
|
|
24786
25179
|
}
|
|
24787
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
25180
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join17(abs, GITIGNORE), rel)) : parent;
|
|
24788
25181
|
for (const e of entries) {
|
|
24789
25182
|
if (e.name === GIT_DIR) continue;
|
|
24790
|
-
const path7 =
|
|
25183
|
+
const path7 = join17(abs, e.name);
|
|
24791
25184
|
let isDir = e.isDirectory();
|
|
24792
25185
|
let isFile = e.isFile();
|
|
24793
25186
|
let target = path7;
|
|
24794
25187
|
if (e.isSymbolicLink()) {
|
|
24795
25188
|
let resolved;
|
|
24796
25189
|
try {
|
|
24797
|
-
resolved =
|
|
25190
|
+
resolved = realpathSync9(path7);
|
|
24798
25191
|
} catch {
|
|
24799
25192
|
continue;
|
|
24800
25193
|
}
|
|
@@ -24809,7 +25202,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24809
25202
|
if (isFile) {
|
|
24810
25203
|
found.push({ dir: rel, name: e.name, absPath: path7 });
|
|
24811
25204
|
} else if (isDir) {
|
|
24812
|
-
const key = e.isSymbolicLink() ? target :
|
|
25205
|
+
const key = e.isSymbolicLink() ? target : realpathSync9(path7);
|
|
24813
25206
|
if (seen.has(key)) continue;
|
|
24814
25207
|
seen.add(key);
|
|
24815
25208
|
visit(path7, segs, rules, contain, seen, found);
|
|
@@ -24827,7 +25220,7 @@ function compareFound(a, b) {
|
|
|
24827
25220
|
function readRules(file2, base) {
|
|
24828
25221
|
let body;
|
|
24829
25222
|
try {
|
|
24830
|
-
body =
|
|
25223
|
+
body = readFileSync14(file2, "utf8");
|
|
24831
25224
|
} catch {
|
|
24832
25225
|
return [];
|
|
24833
25226
|
}
|
|
@@ -28910,14 +29303,14 @@ function kindOfType(contentType) {
|
|
|
28910
29303
|
}
|
|
28911
29304
|
function readUtf8(absPath) {
|
|
28912
29305
|
try {
|
|
28913
|
-
return utf8.decode(
|
|
29306
|
+
return utf8.decode(readFileSync15(absPath));
|
|
28914
29307
|
} catch {
|
|
28915
29308
|
return void 0;
|
|
28916
29309
|
}
|
|
28917
29310
|
}
|
|
28918
29311
|
function missingOrOutside(given, abs, root) {
|
|
28919
29312
|
let dir = abs;
|
|
28920
|
-
while (!
|
|
29313
|
+
while (!existsSync15(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
28921
29314
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
28922
29315
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
28923
29316
|
}
|
|
@@ -28928,7 +29321,7 @@ function pathItems(input, project) {
|
|
|
28928
29321
|
if (statSync7(abs).isDirectory()) {
|
|
28929
29322
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
28930
29323
|
sourceKind: "path",
|
|
28931
|
-
label: pathLabel(
|
|
29324
|
+
label: pathLabel(join18(base, f.relPath)),
|
|
28932
29325
|
kind: kindOfPath(f.relPath),
|
|
28933
29326
|
read: () => readUtf8(f.absPath)
|
|
28934
29327
|
}));
|
|
@@ -29135,6 +29528,43 @@ var KINDS = "SELECT kind, COALESCE(SUM(session_id = ?), 0) AS s, COUNT(*) AS p F
|
|
|
29135
29528
|
var META = `SELECT COUNT(DISTINCT session_id) AS sessions, COUNT(DISTINCT agent) AS agents, COUNT(DISTINCT created_at / ${MS_PER_DAY}) AS days FROM events WHERE ${CALLS}`;
|
|
29136
29529
|
var SPAN = "SELECT COALESCE(MAX(created_at) - MIN(created_at), 0) AS span FROM events WHERE session_id = ? AND kind <> 'cost'";
|
|
29137
29530
|
var SOURCES = "SELECT COUNT(*) AS n, COALESCE(SUM(chunk_count), 0) AS chunks, COALESCE(SUM(bytes_total), 0) AS bytes FROM sources";
|
|
29531
|
+
var HOST = "tool NOT LIKE 'ctx\\_%' ESCAPE '\\'";
|
|
29532
|
+
var REPLACED = `SELECT COUNT(*) AS n FROM events WHERE ${CALLS} AND ${HOST} AND returned_bytes < sandbox_bytes`;
|
|
29533
|
+
var RUNS = "FROM sources WHERE substr(label, 1, ?) = ?";
|
|
29534
|
+
var REDIRECTED = `SELECT COUNT(*) AS n, COALESCE(MAX(created_ts), 0) AS last ${RUNS}`;
|
|
29535
|
+
var LAST = `SELECT COALESCE(MAX(created_at), 0) AS last FROM events WHERE ${CALLS}`;
|
|
29536
|
+
var WEEK = `SELECT created_at / ${MS_PER_DAY} AS day, tool, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} AND created_at >= ? GROUP BY day, tool`;
|
|
29537
|
+
var WEEK_RUNS = `SELECT created_ts / ${MS_PER_DAY} AS day, COUNT(*) AS calls, COALESCE(SUM(MAX(0, bytes_total - ${OUTPUT_CAP})), 0) AS saved ${RUNS} AND created_ts >= ? GROUP BY day`;
|
|
29538
|
+
var TOP = `SELECT tool, 1 AS calls, sandbox_bytes AS produced, returned_bytes AS returned FROM events WHERE ${CALLS} AND sandbox_bytes > 0 ORDER BY sandbox_bytes DESC, seq ASC LIMIT ${STATS_TOP_OUTPUTS}`;
|
|
29539
|
+
function wayOf(tool) {
|
|
29540
|
+
if (STATS_INDEX_TOOLS.includes(tool)) return "index";
|
|
29541
|
+
return tool.startsWith("ctx_") ? "sandbox" : "replace";
|
|
29542
|
+
}
|
|
29543
|
+
function readWeek(raw, lastMs) {
|
|
29544
|
+
const last2 = Math.floor(lastMs / MS_PER_DAY);
|
|
29545
|
+
const first = last2 - STATS_DAYS + 1;
|
|
29546
|
+
const days = Array.from({ length: STATS_DAYS }, (_, i) => ({
|
|
29547
|
+
day: first + i,
|
|
29548
|
+
calls: 0,
|
|
29549
|
+
ways: { sandbox: 0, index: 0, redirect: 0, replace: 0 }
|
|
29550
|
+
}));
|
|
29551
|
+
const net = /* @__PURE__ */ new Map();
|
|
29552
|
+
for (const r of raw.prepare(WEEK).all(first * MS_PER_DAY)) {
|
|
29553
|
+
const d = days[Number(r.day) - first];
|
|
29554
|
+
if (d === void 0) continue;
|
|
29555
|
+
d.calls += Number(r.calls);
|
|
29556
|
+
const key = `${d.day}:${wayOf(String(r.tool))}`;
|
|
29557
|
+
net.set(key, (net.get(key) ?? 0) + Number(r.produced) - Number(r.returned));
|
|
29558
|
+
}
|
|
29559
|
+
for (const d of days) for (const [way] of STATS_WAYS) d.ways[way] = Math.max(0, net.get(`${d.day}:${way}`) ?? 0);
|
|
29560
|
+
for (const r of raw.prepare(WEEK_RUNS).all(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX, first * MS_PER_DAY)) {
|
|
29561
|
+
const d = days[Number(r.day) - first];
|
|
29562
|
+
if (d === void 0) continue;
|
|
29563
|
+
d.calls += Number(r.calls);
|
|
29564
|
+
d.ways.redirect += Number(r.saved);
|
|
29565
|
+
}
|
|
29566
|
+
return days;
|
|
29567
|
+
}
|
|
29138
29568
|
var EMPTY5 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
29139
29569
|
function totals(r) {
|
|
29140
29570
|
const produced = Number(r.produced);
|
|
@@ -29149,6 +29579,8 @@ function readFacts(raw, sessionId) {
|
|
|
29149
29579
|
const meta3 = raw.prepare(META).get();
|
|
29150
29580
|
const span2 = Number(raw.prepare(SPAN).get(sessionId).span);
|
|
29151
29581
|
const src = raw.prepare(SOURCES).get();
|
|
29582
|
+
const runs = raw.prepare(REDIRECTED).get(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX);
|
|
29583
|
+
const last2 = Math.max(Number(raw.prepare(LAST).get().last), Number(runs.last));
|
|
29152
29584
|
const pages = raw.prepare("PRAGMA page_count").get();
|
|
29153
29585
|
const size = raw.prepare("PRAGMA page_size").get();
|
|
29154
29586
|
return {
|
|
@@ -29160,7 +29592,11 @@ function readFacts(raw, sessionId) {
|
|
|
29160
29592
|
agents: Number(meta3.agents),
|
|
29161
29593
|
days: Number(meta3.days),
|
|
29162
29594
|
sources: { count: Number(src.n), chunks: Number(src.chunks), bytes: Number(src.bytes) },
|
|
29163
|
-
dbBytes: Number(pages.page_count) * Number(size.page_size)
|
|
29595
|
+
dbBytes: Number(pages.page_count) * Number(size.page_size),
|
|
29596
|
+
top: raw.prepare(TOP).all().map((r) => ({ name: String(r.tool), ...totals(r) })),
|
|
29597
|
+
replaced: Number(raw.prepare(REPLACED).get().n),
|
|
29598
|
+
redirected: Number(runs.n),
|
|
29599
|
+
week: readWeek(raw, last2)
|
|
29164
29600
|
};
|
|
29165
29601
|
}
|
|
29166
29602
|
function sum(groups) {
|
|
@@ -29191,6 +29627,7 @@ function count(n) {
|
|
|
29191
29627
|
return n < STATS_MILLION ? int2(n) : (n / STATS_MILLION).toFixed(1) + "M";
|
|
29192
29628
|
}
|
|
29193
29629
|
function bytes4(n) {
|
|
29630
|
+
if (n < 0) return "-" + bytes4(-n);
|
|
29194
29631
|
if (n < STATS_KIB) return int2(n) + " B";
|
|
29195
29632
|
let v = n / STATS_KIB;
|
|
29196
29633
|
let u = 0;
|
|
@@ -29223,17 +29660,105 @@ function plural(n, word) {
|
|
|
29223
29660
|
}
|
|
29224
29661
|
function table2(title, rows) {
|
|
29225
29662
|
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
29226
|
-
const head = " " + title.padEnd(LABEL_W) + "Calls".padStart(STATS_CALLS_W) + "
|
|
29663
|
+
const head = " " + title.padEnd(LABEL_W) + "Calls".padStart(STATS_CALLS_W) + "Made".padStart(NUM_W) + "Sent".padStart(NUM_W) + "Kept out".padStart(NUM_W) + "%".padStart(PCT_W);
|
|
29227
29664
|
return [head, ...rows.map((r) => (" " + label(r.name) + count(r.calls).padStart(STATS_CALLS_W) + bytes4(r.produced).padStart(NUM_W) + bytes4(r.returned).padStart(NUM_W) + bytes4(r.saved).padStart(NUM_W) + pct(r).padStart(PCT_W) + " " + bar(r.saved, max, STATS_ROW_BAR)).trimEnd())];
|
|
29228
29665
|
}
|
|
29229
29666
|
function bySaved(a, b) {
|
|
29230
29667
|
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
29231
29668
|
}
|
|
29669
|
+
function toolName(tool) {
|
|
29670
|
+
return tool.startsWith("ctx_") ? tool : "hook " + tool;
|
|
29671
|
+
}
|
|
29672
|
+
function joinIndex(tools) {
|
|
29673
|
+
const idx = tools.filter((t2) => STATS_INDEX_TOOLS.includes(t2.name));
|
|
29674
|
+
if (idx.length <= 1) return tools;
|
|
29675
|
+
const t = sum(idx);
|
|
29676
|
+
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: t.produced - t.returned };
|
|
29677
|
+
return [...tools.filter((x) => !idx.includes(x)), one];
|
|
29678
|
+
}
|
|
29232
29679
|
function toolRows(tools) {
|
|
29233
|
-
const named = tools.map((t) => ({ ...t,
|
|
29234
|
-
|
|
29235
|
-
const
|
|
29236
|
-
|
|
29680
|
+
const named = joinIndex(tools.map((t) => ({ ...t, saved: t.produced - t.returned }))).map((t) => ({ ...t, name: toolName(t.name) })).sort(bySaved);
|
|
29681
|
+
const zero = named.filter((t) => t.saved <= 0);
|
|
29682
|
+
const fold2 = zero.length > 1 ? zero : [];
|
|
29683
|
+
const keep = named.filter((t) => !fold2.includes(t));
|
|
29684
|
+
const room = fold2.length > 0 ? STATS_MAX_TOOL_ROWS - 1 : STATS_MAX_TOOL_ROWS;
|
|
29685
|
+
const over = keep.length > room;
|
|
29686
|
+
const shown2 = over ? keep.slice(0, STATS_MAX_TOOL_ROWS - 1) : keep;
|
|
29687
|
+
const rest = over ? [...keep.slice(STATS_MAX_TOOL_ROWS - 1), ...fold2] : fold2;
|
|
29688
|
+
return rest.length === 0 ? shown2 : [...shown2, { name: `other (${plural(rest.length, "tool")})`, ...sum(rest) }];
|
|
29689
|
+
}
|
|
29690
|
+
var TOKEN_UNITS = ["K", "M", "B", "T"];
|
|
29691
|
+
function whole(v) {
|
|
29692
|
+
return v >= STATS_WHOLE_FROM ? int2(v) : v.toFixed(1);
|
|
29693
|
+
}
|
|
29694
|
+
function tokens(n) {
|
|
29695
|
+
if (n < STATS_THOUSAND) return int2(n);
|
|
29696
|
+
let v = n / STATS_THOUSAND;
|
|
29697
|
+
let u = 0;
|
|
29698
|
+
while (v >= STATS_THOUSAND && u < TOKEN_UNITS.length - 1) {
|
|
29699
|
+
v /= STATS_THOUSAND;
|
|
29700
|
+
u++;
|
|
29701
|
+
}
|
|
29702
|
+
return whole(v) + TOKEN_UNITS[u];
|
|
29703
|
+
}
|
|
29704
|
+
function windowLine(saved) {
|
|
29705
|
+
const t = saved / STATS_BYTES_PER_TOKEN;
|
|
29706
|
+
const share = t / STATS_WINDOW_TOKENS;
|
|
29707
|
+
const win = `a ${tokens(STATS_WINDOW_TOKENS)} window`;
|
|
29708
|
+
const head = ` about ${tokens(t)} tokens kept out`;
|
|
29709
|
+
if (share >= 1) return `${head}, ${whole(share)} times ${win}`;
|
|
29710
|
+
const p = share * PERCENT_SCALE;
|
|
29711
|
+
return p * STATS_WHOLE_FROM < 1 ? head : `${head}, ${whole(p)}% of ${win}`;
|
|
29712
|
+
}
|
|
29713
|
+
function ymd(day) {
|
|
29714
|
+
return new Date(day * MS_PER_DAY).toISOString().slice(0, "yyyy-mm-dd".length);
|
|
29715
|
+
}
|
|
29716
|
+
function mmdd(day) {
|
|
29717
|
+
return ymd(day).slice("yyyy-".length);
|
|
29718
|
+
}
|
|
29719
|
+
function stack(parts, max, width) {
|
|
29720
|
+
let total = 0;
|
|
29721
|
+
let at2 = 0;
|
|
29722
|
+
let out = "";
|
|
29723
|
+
parts.forEach((v, i) => {
|
|
29724
|
+
total += v;
|
|
29725
|
+
const end = max <= 0 ? 0 : Math.round(total / max * width);
|
|
29726
|
+
if (end > at2) {
|
|
29727
|
+
out += STATS_WAYS[i][1].repeat(end - at2);
|
|
29728
|
+
at2 = end;
|
|
29729
|
+
}
|
|
29730
|
+
});
|
|
29731
|
+
if (out === "" && total > 0) out = STATS_WAYS[parts.indexOf(Math.max(...parts))][1];
|
|
29732
|
+
return out;
|
|
29733
|
+
}
|
|
29734
|
+
function cards(cells) {
|
|
29735
|
+
return (" " + cells.map((c) => c.padEnd(STATS_CARD_W)).join("")).trimEnd();
|
|
29736
|
+
}
|
|
29737
|
+
function lastDays(week, allCalls) {
|
|
29738
|
+
const saved = week.map((d) => STATS_WAYS.reduce((t, [w]) => t + d.ways[w], 0));
|
|
29739
|
+
const all = saved.reduce((a, b) => a + b, 0);
|
|
29740
|
+
const calls = week.reduce((a, d) => a + d.calls, 0);
|
|
29741
|
+
const max = Math.max(0, ...saved);
|
|
29742
|
+
const head = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
|
|
29743
|
+
const card = calls < allCalls ? [
|
|
29744
|
+
cards(["Kept out", "Tokens kept out", "Calls", "Kept out per call"]),
|
|
29745
|
+
cards([bytes4(all), "about " + tokens(all / STATS_BYTES_PER_TOKEN), count(calls), bytes4(calls > 0 ? all / calls : 0)]),
|
|
29746
|
+
""
|
|
29747
|
+
] : [];
|
|
29748
|
+
return [
|
|
29749
|
+
head,
|
|
29750
|
+
...card,
|
|
29751
|
+
...week.flatMap((d, i) => saved[i] > 0 ? [" " + mmdd(d.day) + " " + stack(STATS_WAYS.map(([w]) => d.ways[w]), max, STATS_DAY_BAR).padEnd(STATS_DAY_BAR) + bytes4(saved[i]).padStart(NUM_W)] : []),
|
|
29752
|
+
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
29753
|
+
""
|
|
29754
|
+
];
|
|
29755
|
+
}
|
|
29756
|
+
function hookLine(redirected, replaced) {
|
|
29757
|
+
const all = redirected + replaced;
|
|
29758
|
+
if (all === 0) return [];
|
|
29759
|
+
const parts = [...redirected > 0 ? [`${int2(redirected)} sent to the sandbox`] : [], ...replaced > 0 ? [`${int2(replaced)} cut down`] : []];
|
|
29760
|
+
const what = plural(all, "large output");
|
|
29761
|
+
return [parts.length === 1 ? ` Project hooks: ${what} ${parts[0].replace(/^[\d,]+ /, "")}` : ` Project hooks: ${what} kept out \xB7 ${parts.join(", ")}`];
|
|
29237
29762
|
}
|
|
29238
29763
|
function fit(line) {
|
|
29239
29764
|
const chars = [...line];
|
|
@@ -29250,20 +29775,30 @@ function report(f, sessionId, agent) {
|
|
|
29250
29775
|
const lines = [
|
|
29251
29776
|
...head,
|
|
29252
29777
|
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
29778
|
+
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
29253
29779
|
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced).padStart(NUM_W),
|
|
29254
29780
|
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned).padStart(NUM_W),
|
|
29255
|
-
|
|
29781
|
+
...focus.saved > 0 ? [windowLine(focus.saved), STATS_TOKEN_NOTE] : [],
|
|
29782
|
+
...hookLine(f.redirected, f.replaced),
|
|
29256
29783
|
"",
|
|
29257
|
-
...
|
|
29784
|
+
...lastDays(f.week, project.calls + f.redirected),
|
|
29785
|
+
// D-STATS-FIX-1 (5): one DB per project holds every session of it, so project and all-time are one row.
|
|
29786
|
+
"By scope",
|
|
29787
|
+
...table2("Scope", [{ name: "session", ...session }, { name: "project (all-time)", ...project }]),
|
|
29258
29788
|
"",
|
|
29259
|
-
"
|
|
29789
|
+
"By tool (this project)",
|
|
29260
29790
|
...table2("Tool", toolRows(f.tools)),
|
|
29261
|
-
""
|
|
29791
|
+
"",
|
|
29792
|
+
...f.top.length > 0 ? [
|
|
29793
|
+
"Largest single outputs (made \u2192 sent to the chat)",
|
|
29794
|
+
...f.top.map((t) => " " + label(toolName(t.name)) + bytes4(t.produced).padStart(NUM_W) + " \u2192 " + bytes4(t.returned).padStart(NUM_W)),
|
|
29795
|
+
""
|
|
29796
|
+
] : []
|
|
29262
29797
|
];
|
|
29263
29798
|
const agents = /* @__PURE__ */ new Map();
|
|
29264
29799
|
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY5, g]));
|
|
29265
29800
|
if (!agents.has(agent)) agents.set(agent, EMPTY5);
|
|
29266
|
-
lines.push(...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
29801
|
+
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
29267
29802
|
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
29268
29803
|
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session".padStart(STATS_KIND_W) + "Project".padStart(STATS_KIND_W));
|
|
29269
29804
|
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
@@ -29272,9 +29807,12 @@ function report(f, sessionId, agent) {
|
|
|
29272
29807
|
}
|
|
29273
29808
|
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
29274
29809
|
lines.push(
|
|
29275
|
-
" " + "
|
|
29810
|
+
" " + "Index and search".padEnd(LABEL_W) + `${plural(f.sources.count, "source")} \xB7 ${plural(f.sources.chunks, "chunk")} \xB7 ${bytes4(f.sources.bytes)} \xB7 ${plural(f.tools.find((t) => t.name === "ctx_search")?.calls ?? 0, "ctx_search call")}`,
|
|
29276
29811
|
" " + "Database file".padEnd(LABEL_W) + bytes4(f.dbBytes),
|
|
29277
|
-
" " + "Sessions".padEnd(LABEL_W) + `${int2(f.sessions)} \xB7 agents ${int2(f.agents)} \xB7 active days ${int2(f.days)}
|
|
29812
|
+
" " + "Sessions".padEnd(LABEL_W) + `${int2(f.sessions)} \xB7 agents ${int2(f.agents)} \xB7 active days ${int2(f.days)}`,
|
|
29813
|
+
"",
|
|
29814
|
+
STATS_FOOTER_URL,
|
|
29815
|
+
"github.com/" + ISSUE_REPO_SLUG
|
|
29278
29816
|
);
|
|
29279
29817
|
return lines.map(fit).join("\n");
|
|
29280
29818
|
}
|
|
@@ -29312,28 +29850,28 @@ var ctxStats = Object.freeze({
|
|
|
29312
29850
|
});
|
|
29313
29851
|
|
|
29314
29852
|
// src/core/tools/upgrade.ts
|
|
29315
|
-
import { existsSync as
|
|
29316
|
-
import { basename as basename6, dirname as dirname11, join as
|
|
29853
|
+
import { existsSync as existsSync21, realpathSync as realpathSync10, rmSync as rmSync9 } from "node:fs";
|
|
29854
|
+
import { basename as basename6, dirname as dirname11, join as join24 } from "node:path";
|
|
29317
29855
|
|
|
29318
29856
|
// src/core/ops/host-write.ts
|
|
29319
|
-
import { copyFileSync, existsSync as
|
|
29320
|
-
import { dirname as dirname10, join as
|
|
29857
|
+
import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
29858
|
+
import { dirname as dirname10, join as join19 } from "node:path";
|
|
29321
29859
|
function defaultWrite(file2, text) {
|
|
29322
|
-
|
|
29860
|
+
writeFileSync5(file2, text, "utf8");
|
|
29323
29861
|
}
|
|
29324
29862
|
function hostConfigPath(agent, home, env) {
|
|
29325
29863
|
const own4 = OWN_MCP_ENTRY[agent];
|
|
29326
29864
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
29327
29865
|
switch (agent) {
|
|
29328
29866
|
case "opencode":
|
|
29329
|
-
return
|
|
29867
|
+
return join19(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
29330
29868
|
// D-WIN-OPENCODE-DIR-1
|
|
29331
29869
|
case "pi":
|
|
29332
|
-
return
|
|
29870
|
+
return join19(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
29333
29871
|
case "copilot-cli":
|
|
29334
29872
|
return null;
|
|
29335
29873
|
default:
|
|
29336
|
-
return
|
|
29874
|
+
return join19(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
29337
29875
|
}
|
|
29338
29876
|
}
|
|
29339
29877
|
function cell3(value) {
|
|
@@ -29345,8 +29883,8 @@ function toRow(file2, edit) {
|
|
|
29345
29883
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
29346
29884
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
29347
29885
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
29348
|
-
const had =
|
|
29349
|
-
|
|
29886
|
+
const had = existsSync16(file2);
|
|
29887
|
+
mkdirSync6(dirname10(file2), { recursive: true });
|
|
29350
29888
|
if (had) copyFileSync(file2, trash);
|
|
29351
29889
|
try {
|
|
29352
29890
|
write2(tmp, text);
|
|
@@ -29375,7 +29913,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
29375
29913
|
if (requested === null) return [];
|
|
29376
29914
|
const current = readHostConfig(row5.id, requested);
|
|
29377
29915
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
29378
|
-
const exists =
|
|
29916
|
+
const exists = existsSync16(current.path);
|
|
29379
29917
|
if (exists && result.text === current.text) return [];
|
|
29380
29918
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
29381
29919
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -29383,8 +29921,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
29383
29921
|
}
|
|
29384
29922
|
|
|
29385
29923
|
// src/core/ops/plugin-swap.ts
|
|
29386
|
-
import { existsSync as
|
|
29387
|
-
import { basename as basename5, join as
|
|
29924
|
+
import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
29925
|
+
import { basename as basename5, join as join20, win32 as win322 } from "node:path";
|
|
29388
29926
|
function linkTarget(path7, win) {
|
|
29389
29927
|
if (!isLink(path7)) return null;
|
|
29390
29928
|
const target = readlinkSync(path7);
|
|
@@ -29403,11 +29941,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
29403
29941
|
else renameWithRetry(old, link, opts);
|
|
29404
29942
|
}
|
|
29405
29943
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
29406
|
-
const next =
|
|
29407
|
-
if (!
|
|
29944
|
+
const next = join20(agentDir, sha);
|
|
29945
|
+
if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
|
|
29408
29946
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
29409
29947
|
}
|
|
29410
|
-
const link =
|
|
29948
|
+
const link = join20(agentDir, PLUGIN_CURRENT_LINK);
|
|
29411
29949
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
29412
29950
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
29413
29951
|
settleLinks(link, tmp, old, opts);
|
|
@@ -29422,15 +29960,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
29422
29960
|
if (before !== null) unlinkSync2(old);
|
|
29423
29961
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
29424
29962
|
if (before !== null) keep.add(before);
|
|
29425
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
29963
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join20(agentDir, name));
|
|
29426
29964
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
29427
|
-
const previous = before !== null &&
|
|
29965
|
+
const previous = before !== null && existsSync17(join20(agentDir, before)) ? join20(agentDir, before) : null;
|
|
29428
29966
|
return { current: next, previous, removed };
|
|
29429
29967
|
}
|
|
29430
29968
|
|
|
29431
29969
|
// src/core/ops/release-fetch.ts
|
|
29432
|
-
import { existsSync as
|
|
29433
|
-
import { join as
|
|
29970
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync7, rmSync as rmSync6 } from "node:fs";
|
|
29971
|
+
import { join as join21 } from "node:path";
|
|
29434
29972
|
function failed(r) {
|
|
29435
29973
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
29436
29974
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -29442,9 +29980,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
29442
29980
|
return r.stdout.toString().trim();
|
|
29443
29981
|
}
|
|
29444
29982
|
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
29445
|
-
const agentDir =
|
|
29446
|
-
|
|
29447
|
-
const fetchDir =
|
|
29983
|
+
const agentDir = join21(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
29984
|
+
mkdirSync7(agentDir, { recursive: true });
|
|
29985
|
+
const fetchDir = join21(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
29448
29986
|
rmSync6(fetchDir, { recursive: true, force: true });
|
|
29449
29987
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
29450
29988
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -29452,8 +29990,8 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
29452
29990
|
try {
|
|
29453
29991
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
29454
29992
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
29455
|
-
const dir =
|
|
29456
|
-
if (
|
|
29993
|
+
const dir = join21(agentDir, sha);
|
|
29994
|
+
if (existsSync18(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
29457
29995
|
else renameWithRetry(fetchDir, dir, opts);
|
|
29458
29996
|
return { sha, dir };
|
|
29459
29997
|
} catch (e) {
|
|
@@ -29463,15 +30001,15 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
29463
30001
|
}
|
|
29464
30002
|
|
|
29465
30003
|
// src/core/ops/uninstall.ts
|
|
29466
|
-
import { existsSync as
|
|
29467
|
-
import { join as
|
|
30004
|
+
import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
|
|
30005
|
+
import { join as join22 } from "node:path";
|
|
29468
30006
|
function row2(area, before, after) {
|
|
29469
30007
|
return { area, before, after };
|
|
29470
30008
|
}
|
|
29471
30009
|
function stopServers(configDir, projectKey) {
|
|
29472
30010
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
29473
|
-
const dir =
|
|
29474
|
-
for (const serverId of stopped)
|
|
30011
|
+
const dir = join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
30012
|
+
for (const serverId of stopped) writeFileSync6(join22(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
29475
30013
|
return stopped.length === 0 ? { row: row2(UPGRADE_SERVER_AREA, "", UPGRADE_NOT_FOUND), stopped } : { row: row2(UPGRADE_SERVER_AREA, UPGRADE_SERVER_RUNNING, UPGRADE_SERVER_STOPPED), stopped };
|
|
29476
30014
|
}
|
|
29477
30015
|
function rootOrNull(adapter, env) {
|
|
@@ -29489,15 +30027,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
29489
30027
|
const root = rootOrNull(adapter, env);
|
|
29490
30028
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29491
30029
|
if (adapter.installMode === "marketplace") {
|
|
29492
|
-
const cache =
|
|
30030
|
+
const cache = join22(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
29493
30031
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
29494
30032
|
}
|
|
29495
30033
|
rmSync7(root, { recursive: true, force: true });
|
|
29496
30034
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
29497
30035
|
}
|
|
29498
30036
|
case "plugin": {
|
|
29499
|
-
const agentDir =
|
|
29500
|
-
if (!
|
|
30037
|
+
const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
30038
|
+
if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29501
30039
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
29502
30040
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
29503
30041
|
}
|
|
@@ -29542,7 +30080,7 @@ function ownEntries(agent, env) {
|
|
|
29542
30080
|
}
|
|
29543
30081
|
if (agent === "opencode") {
|
|
29544
30082
|
return [{
|
|
29545
|
-
file:
|
|
30083
|
+
file: join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
29546
30084
|
// D-WIN-OPENCODE-DIR-1
|
|
29547
30085
|
key: OPENCODE_PLUGIN_KEY,
|
|
29548
30086
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -29553,7 +30091,7 @@ function ownEntries(agent, env) {
|
|
|
29553
30091
|
if (agent === "pi") {
|
|
29554
30092
|
const agentDir = piAgentDirOf(env, home);
|
|
29555
30093
|
return [{
|
|
29556
|
-
file:
|
|
30094
|
+
file: join22(agentDir, SETTINGS_FILE),
|
|
29557
30095
|
key: PI_PACKAGES_KEY,
|
|
29558
30096
|
shown: PI_PACKAGES_KEY,
|
|
29559
30097
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -29575,12 +30113,12 @@ function removeOwnEntries(agent, env) {
|
|
|
29575
30113
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
29576
30114
|
}
|
|
29577
30115
|
function removeProjectData(configDir, projectKey) {
|
|
29578
|
-
const projects =
|
|
29579
|
-
const dir =
|
|
29580
|
-
if (!
|
|
30116
|
+
const projects = join22(configDir, PROJECTS_DIR_NAME);
|
|
30117
|
+
const dir = join22(projects, projectKey);
|
|
30118
|
+
if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
29581
30119
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
29582
30120
|
for (const name of readdirSync8(dir)) {
|
|
29583
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
30121
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join22(dir, name), { recursive: true, force: true });
|
|
29584
30122
|
}
|
|
29585
30123
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
29586
30124
|
}
|
|
@@ -29588,12 +30126,12 @@ function runUninstall(input) {
|
|
|
29588
30126
|
const configDir = resolveConfigDir(input.env);
|
|
29589
30127
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
29590
30128
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
29591
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
30129
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join22(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
29592
30130
|
return { rows, stopped: stop.stopped };
|
|
29593
30131
|
}
|
|
29594
30132
|
|
|
29595
30133
|
// src/core/ops/v1-remove.ts
|
|
29596
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30134
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync16, rmSync as rmSync8 } from "node:fs";
|
|
29597
30135
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
29598
30136
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
29599
30137
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -29637,8 +30175,8 @@ function locate(doc, path7) {
|
|
|
29637
30175
|
return null;
|
|
29638
30176
|
}
|
|
29639
30177
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
29640
|
-
const layout = hostLayout(
|
|
29641
|
-
const text = hostText(
|
|
30178
|
+
const layout = hostLayout(readFileSync16(file2, "utf8"));
|
|
30179
|
+
const text = hostText(readFileSync16(file2, "utf8"));
|
|
29642
30180
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
29643
30181
|
const hit = /* @__PURE__ */ new Set();
|
|
29644
30182
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -29674,19 +30212,19 @@ function removeV1(agent, findings) {
|
|
|
29674
30212
|
for (const f of findings) {
|
|
29675
30213
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
29676
30214
|
else if (f.path === "") {
|
|
29677
|
-
if (
|
|
30215
|
+
if (existsSync20(f.file)) {
|
|
29678
30216
|
moveAside(f.file, undo);
|
|
29679
30217
|
done.set(f, UPGRADE_REMOVED);
|
|
29680
30218
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
29681
30219
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
29682
30220
|
}
|
|
29683
30221
|
for (const [file2, list4] of entries) {
|
|
29684
|
-
if (!
|
|
30222
|
+
if (!existsSync20(file2)) {
|
|
29685
30223
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
29686
30224
|
continue;
|
|
29687
30225
|
}
|
|
29688
30226
|
if (file2.endsWith(TOML_EXT)) {
|
|
29689
|
-
const rawToml =
|
|
30227
|
+
const rawToml = readFileSync16(file2, "utf8");
|
|
29690
30228
|
const tomlLayout = hostLayout(rawToml);
|
|
29691
30229
|
let text = hostText(rawToml);
|
|
29692
30230
|
for (const f of list4) {
|
|
@@ -29714,7 +30252,7 @@ function removeV1(agent, findings) {
|
|
|
29714
30252
|
},
|
|
29715
30253
|
rollback() {
|
|
29716
30254
|
for (const u of undo.splice(0).reverse()) {
|
|
29717
|
-
if (!
|
|
30255
|
+
if (!existsSync20(u.trash)) continue;
|
|
29718
30256
|
rmSync8(u.target, { recursive: true, force: true });
|
|
29719
30257
|
renameWithRetry(u.trash, u.target);
|
|
29720
30258
|
}
|
|
@@ -29724,8 +30262,8 @@ function removeV1(agent, findings) {
|
|
|
29724
30262
|
|
|
29725
30263
|
// src/core/ops/verify-sums.ts
|
|
29726
30264
|
import { createHash as createHash2 } from "node:crypto";
|
|
29727
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as
|
|
29728
|
-
import { join as
|
|
30265
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync17 } from "node:fs";
|
|
30266
|
+
import { join as join23 } from "node:path";
|
|
29729
30267
|
function mismatch() {
|
|
29730
30268
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
29731
30269
|
}
|
|
@@ -29746,24 +30284,24 @@ function walk3(dir, prefix, out) {
|
|
|
29746
30284
|
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
29747
30285
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
29748
30286
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
29749
|
-
const abs =
|
|
30287
|
+
const abs = join23(dir, entry.name);
|
|
29750
30288
|
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
29751
30289
|
else if (entry.isFile()) out.set(rel, abs);
|
|
29752
30290
|
else throw mismatch();
|
|
29753
30291
|
}
|
|
29754
30292
|
}
|
|
29755
30293
|
function verifySums(dir) {
|
|
29756
|
-
const sumsPath =
|
|
30294
|
+
const sumsPath = join23(dir, RELEASE_SUMS_FILE);
|
|
29757
30295
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
29758
30296
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
29759
|
-
const sums = parseSums(
|
|
30297
|
+
const sums = parseSums(readFileSync17(sumsPath, "utf8"));
|
|
29760
30298
|
const files = /* @__PURE__ */ new Map();
|
|
29761
30299
|
walk3(dir, "", files);
|
|
29762
30300
|
if (files.size !== sums.size) throw mismatch();
|
|
29763
30301
|
for (const [rel, abs] of files) {
|
|
29764
30302
|
const want = sums.get(rel);
|
|
29765
30303
|
if (want === void 0) throw mismatch();
|
|
29766
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
30304
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync17(abs)).digest(HASH_ENCODING);
|
|
29767
30305
|
if (got !== want) throw mismatch();
|
|
29768
30306
|
}
|
|
29769
30307
|
}
|
|
@@ -29791,8 +30329,8 @@ function pluginRootRow(adapter, env) {
|
|
|
29791
30329
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
29792
30330
|
}
|
|
29793
30331
|
function isCurrent(agentDir, dir) {
|
|
29794
|
-
const link =
|
|
29795
|
-
return
|
|
30332
|
+
const link = join24(agentDir, PLUGIN_CURRENT_LINK);
|
|
30333
|
+
return existsSync21(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
29796
30334
|
}
|
|
29797
30335
|
async function checkout(adapter, deps) {
|
|
29798
30336
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -29912,8 +30450,8 @@ function checkCall(tool, input) {
|
|
|
29912
30450
|
|
|
29913
30451
|
// src/entries/server.ts
|
|
29914
30452
|
import { randomUUID } from "node:crypto";
|
|
29915
|
-
import { existsSync as
|
|
29916
|
-
import { dirname as dirname12, join as
|
|
30453
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync11 } from "node:fs";
|
|
30454
|
+
import { dirname as dirname12, join as join26 } from "node:path";
|
|
29917
30455
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29918
30456
|
|
|
29919
30457
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -33392,17 +33930,17 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
33392
33930
|
var NONE3 = 0;
|
|
33393
33931
|
var ASSUMED = 1;
|
|
33394
33932
|
var PROVEN = 2;
|
|
33395
|
-
function isRecursive(inst,
|
|
33933
|
+
function isRecursive(inst, stack2, resolve8) {
|
|
33396
33934
|
const cached4 = recursive.get(inst);
|
|
33397
33935
|
if (cached4 !== void 0)
|
|
33398
33936
|
return cached4 ? PROVEN : NONE3;
|
|
33399
|
-
if (
|
|
33937
|
+
if (stack2.has(inst))
|
|
33400
33938
|
return PROVEN;
|
|
33401
|
-
|
|
33939
|
+
stack2.add(inst);
|
|
33402
33940
|
let result = NONE3;
|
|
33403
33941
|
const check2 = (child) => {
|
|
33404
33942
|
if (result !== PROVEN && child?._zod) {
|
|
33405
|
-
const answer2 = isRecursive(child,
|
|
33943
|
+
const answer2 = isRecursive(child, stack2, resolve8);
|
|
33406
33944
|
if (answer2 > result)
|
|
33407
33945
|
result = answer2;
|
|
33408
33946
|
}
|
|
@@ -33413,7 +33951,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
33413
33951
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
33414
33952
|
if (spread && !desc.enumerable)
|
|
33415
33953
|
continue;
|
|
33416
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value,
|
|
33954
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve8) : NONE3;
|
|
33417
33955
|
if (child > answer2)
|
|
33418
33956
|
answer2 = child;
|
|
33419
33957
|
}
|
|
@@ -33478,7 +34016,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
33478
34016
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
33479
34017
|
case "lazy": {
|
|
33480
34018
|
const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
|
|
33481
|
-
merge5(inner ? isRecursive(inner,
|
|
34019
|
+
merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
|
|
33482
34020
|
break;
|
|
33483
34021
|
}
|
|
33484
34022
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -33521,7 +34059,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
33521
34059
|
}
|
|
33522
34060
|
}
|
|
33523
34061
|
}
|
|
33524
|
-
|
|
34062
|
+
stack2.delete(inst);
|
|
33525
34063
|
return settle(inst, result);
|
|
33526
34064
|
}
|
|
33527
34065
|
function settle(inst, answer2) {
|
|
@@ -40921,17 +41459,17 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
40921
41459
|
var NONE4 = 0;
|
|
40922
41460
|
var ASSUMED2 = 1;
|
|
40923
41461
|
var PROVEN2 = 2;
|
|
40924
|
-
function isRecursive2(inst,
|
|
41462
|
+
function isRecursive2(inst, stack2, resolve8) {
|
|
40925
41463
|
const cached4 = recursive2.get(inst);
|
|
40926
41464
|
if (cached4 !== void 0)
|
|
40927
41465
|
return cached4 ? PROVEN2 : NONE4;
|
|
40928
|
-
if (
|
|
41466
|
+
if (stack2.has(inst))
|
|
40929
41467
|
return PROVEN2;
|
|
40930
|
-
|
|
41468
|
+
stack2.add(inst);
|
|
40931
41469
|
let result = NONE4;
|
|
40932
41470
|
const check2 = (child) => {
|
|
40933
41471
|
if (result !== PROVEN2 && child?._zod) {
|
|
40934
|
-
const answer2 = isRecursive2(child,
|
|
41472
|
+
const answer2 = isRecursive2(child, stack2, resolve8);
|
|
40935
41473
|
if (answer2 > result)
|
|
40936
41474
|
result = answer2;
|
|
40937
41475
|
}
|
|
@@ -40942,7 +41480,7 @@ function isRecursive2(inst, stack, resolve8) {
|
|
|
40942
41480
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
40943
41481
|
if (spread && !desc.enumerable)
|
|
40944
41482
|
continue;
|
|
40945
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value,
|
|
41483
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve8) : NONE4;
|
|
40946
41484
|
if (child > answer2)
|
|
40947
41485
|
answer2 = child;
|
|
40948
41486
|
}
|
|
@@ -41007,7 +41545,7 @@ function isRecursive2(inst, stack, resolve8) {
|
|
|
41007
41545
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
41008
41546
|
case "lazy": {
|
|
41009
41547
|
const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
|
|
41010
|
-
merge5(inner ? isRecursive2(inner,
|
|
41548
|
+
merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
|
|
41011
41549
|
break;
|
|
41012
41550
|
}
|
|
41013
41551
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -41050,7 +41588,7 @@ function isRecursive2(inst, stack, resolve8) {
|
|
|
41050
41588
|
}
|
|
41051
41589
|
}
|
|
41052
41590
|
}
|
|
41053
|
-
|
|
41591
|
+
stack2.delete(inst);
|
|
41054
41592
|
return settle2(inst, result);
|
|
41055
41593
|
}
|
|
41056
41594
|
function settle2(inst, answer2) {
|
|
@@ -56814,19 +57352,19 @@ function discoverAdvertisedCapabilities(capabilities) {
|
|
|
56814
57352
|
}
|
|
56815
57353
|
function toolInputElementCount(value, max) {
|
|
56816
57354
|
let count2 = 0;
|
|
56817
|
-
const
|
|
56818
|
-
while (
|
|
56819
|
-
const node3 =
|
|
57355
|
+
const stack2 = [value];
|
|
57356
|
+
while (stack2.length > 0) {
|
|
57357
|
+
const node3 = stack2.pop();
|
|
56820
57358
|
if (node3 === null || typeof node3 !== "object") continue;
|
|
56821
57359
|
if (Array.isArray(node3)) for (const child of node3) {
|
|
56822
57360
|
if (++count2 > max) return count2;
|
|
56823
|
-
if (child !== null && typeof child === "object")
|
|
57361
|
+
if (child !== null && typeof child === "object") stack2.push(child);
|
|
56824
57362
|
}
|
|
56825
57363
|
else for (const key in node3) {
|
|
56826
57364
|
if (!Object.prototype.hasOwnProperty.call(node3, key)) continue;
|
|
56827
57365
|
if (++count2 > max) return count2;
|
|
56828
57366
|
const child = node3[key];
|
|
56829
|
-
if (child !== null && typeof child === "object")
|
|
57367
|
+
if (child !== null && typeof child === "object") stack2.push(child);
|
|
56830
57368
|
}
|
|
56831
57369
|
}
|
|
56832
57370
|
return count2;
|
|
@@ -56902,9 +57440,9 @@ var McpServer = class {
|
|
|
56902
57440
|
resolveScopeChallenge = (context) => {
|
|
56903
57441
|
switch (context.request.method) {
|
|
56904
57442
|
case "tools/call": {
|
|
56905
|
-
const
|
|
56906
|
-
if (typeof
|
|
56907
|
-
const tool = this._registeredTools[
|
|
57443
|
+
const toolName2 = context.request.params?.name;
|
|
57444
|
+
if (typeof toolName2 !== "string") return;
|
|
57445
|
+
const tool = this._registeredTools[toolName2];
|
|
56908
57446
|
if (tool === void 0 || !tool.enabled) return;
|
|
56909
57447
|
return tool.scopeChallenge?.(context);
|
|
56910
57448
|
}
|
|
@@ -56988,23 +57526,23 @@ var McpServer = class {
|
|
|
56988
57526
|
/**
|
|
56989
57527
|
* Validates tool input arguments against the tool's input schema.
|
|
56990
57528
|
*/
|
|
56991
|
-
async validateToolInput(tool, args,
|
|
56992
|
-
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${
|
|
57529
|
+
async validateToolInput(tool, args, toolName2) {
|
|
57530
|
+
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${toolName2}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
|
|
56993
57531
|
if (!tool.inputSchema) return;
|
|
56994
57532
|
const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});
|
|
56995
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${
|
|
57533
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName2}: ${parseResult.error}`);
|
|
56996
57534
|
return parseResult.data;
|
|
56997
57535
|
}
|
|
56998
57536
|
/**
|
|
56999
57537
|
* Validates tool output against the tool's output schema.
|
|
57000
57538
|
*/
|
|
57001
|
-
async validateToolOutput(tool, result,
|
|
57539
|
+
async validateToolOutput(tool, result, toolName2) {
|
|
57002
57540
|
if (!tool.outputSchema) return;
|
|
57003
57541
|
if (isInputRequiredResult(result)) return;
|
|
57004
57542
|
if (result.isError) return;
|
|
57005
|
-
if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${
|
|
57543
|
+
if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${toolName2} has an output schema but no structured content was provided`);
|
|
57006
57544
|
const parseResult = await validateStandardSchema(tool.outputSchema, result.structuredContent);
|
|
57007
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${
|
|
57545
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName2}: ${parseResult.error}`);
|
|
57008
57546
|
}
|
|
57009
57547
|
/**
|
|
57010
57548
|
* Executes a tool handler.
|
|
@@ -57978,8 +58516,8 @@ function installExitGuard(opts) {
|
|
|
57978
58516
|
}
|
|
57979
58517
|
|
|
57980
58518
|
// src/core/store/cleanup.ts
|
|
57981
|
-
import { existsSync as
|
|
57982
|
-
import { join as
|
|
58519
|
+
import { existsSync as existsSync22, readdirSync as readdirSync10, rmSync as rmSync10 } from "node:fs";
|
|
58520
|
+
import { join as join25 } from "node:path";
|
|
57983
58521
|
function deleteSource(raw, id) {
|
|
57984
58522
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
57985
58523
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -58014,7 +58552,7 @@ function userVersion(raw) {
|
|
|
58014
58552
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
58015
58553
|
}
|
|
58016
58554
|
function openForSweep(dbPath, projectKey) {
|
|
58017
|
-
if (!
|
|
58555
|
+
if (!existsSync22(dbPath) && (existsSync22(dbPath + DB_WAL_SUFFIX) || existsSync22(dbPath + DB_SHM_SUFFIX))) {
|
|
58018
58556
|
throw new CtxError("DB_GONE");
|
|
58019
58557
|
}
|
|
58020
58558
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -58035,8 +58573,8 @@ function lastAccess(raw) {
|
|
|
58035
58573
|
return row5.t;
|
|
58036
58574
|
}
|
|
58037
58575
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
58038
|
-
const dir =
|
|
58039
|
-
const db = openForSweep(
|
|
58576
|
+
const dir = join25(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
58577
|
+
const db = openForSweep(join25(dir, DB_FILE_NAME), projectKey);
|
|
58040
58578
|
let dead;
|
|
58041
58579
|
try {
|
|
58042
58580
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
@@ -58049,7 +58587,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
58049
58587
|
function sweepDeadProjects(configDir) {
|
|
58050
58588
|
let entries;
|
|
58051
58589
|
try {
|
|
58052
|
-
entries = readdirSync10(
|
|
58590
|
+
entries = readdirSync10(join25(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
58053
58591
|
} catch (err) {
|
|
58054
58592
|
if (err.code === "ENOENT") return [];
|
|
58055
58593
|
throw err;
|
|
@@ -58068,12 +58606,12 @@ function sweepDeadProjects(configDir) {
|
|
|
58068
58606
|
}
|
|
58069
58607
|
|
|
58070
58608
|
// src/entries/is-entry.ts
|
|
58071
|
-
import { realpathSync as
|
|
58609
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
58072
58610
|
function isEntry(main, argv1, self) {
|
|
58073
58611
|
if (main !== void 0) return main;
|
|
58074
58612
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
58075
58613
|
try {
|
|
58076
|
-
return
|
|
58614
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
58077
58615
|
} catch {
|
|
58078
58616
|
return false;
|
|
58079
58617
|
}
|
|
@@ -58149,7 +58687,7 @@ function workspaceFromMeta(meta3) {
|
|
|
58149
58687
|
}
|
|
58150
58688
|
function realOrSame(p) {
|
|
58151
58689
|
try {
|
|
58152
|
-
return
|
|
58690
|
+
return realpathSync12.native(p);
|
|
58153
58691
|
} catch {
|
|
58154
58692
|
return p;
|
|
58155
58693
|
}
|
|
@@ -58197,15 +58735,15 @@ async function startServer(argv, env) {
|
|
|
58197
58735
|
opening.catch(() => pending.delete(project.dbPath));
|
|
58198
58736
|
}
|
|
58199
58737
|
const db = await opening;
|
|
58200
|
-
if (!
|
|
58738
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
58201
58739
|
return db;
|
|
58202
58740
|
}
|
|
58203
58741
|
function stopMarker(configDir, projectKey) {
|
|
58204
|
-
return
|
|
58742
|
+
return join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
58205
58743
|
}
|
|
58206
58744
|
function stopRequested() {
|
|
58207
58745
|
const configDir = resolveConfigDir(process.env);
|
|
58208
|
-
return held.some((db) =>
|
|
58746
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
58209
58747
|
}
|
|
58210
58748
|
async function journal(project, ctx, name, reply4) {
|
|
58211
58749
|
const db = await ownDb(project);
|