context-mode 2.0.0-next.29 → 2.0.0-next.32
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 +84 -83
- package/SHA256SUMS +19 -19
- package/claude-code/skills/ctx-stats/SKILL.md +2 -2
- package/cli.mjs +342 -152
- package/codex/skills/ctx-stats/SKILL.md +2 -2
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +75 -75
- package/opencode/plugin.js +1063 -309
- package/package.json +1 -1
- package/pi/index.js +1178 -425
- package/pi/skills/ctx-stats/SKILL.md +2 -2
- package/qwen-extension.json +1 -1
- package/run.mjs +84 -3
- package/search.mjs +84 -3
- package/server.mjs +1118 -365
- package/skills/ctx-stats/SKILL.md +2 -2
package/pi/index.js
CHANGED
|
@@ -3840,8 +3840,8 @@ function az_default() {
|
|
|
3840
3840
|
}
|
|
3841
3841
|
|
|
3842
3842
|
// node_modules/zod/v4/locales/be.js
|
|
3843
|
-
function getBelarusianPlural(
|
|
3844
|
-
const absCount = Math.abs(
|
|
3843
|
+
function getBelarusianPlural(count2, one, few, many) {
|
|
3844
|
+
const absCount = Math.abs(count2);
|
|
3845
3845
|
const lastDigit = absCount % 10;
|
|
3846
3846
|
const lastTwoDigits = absCount % 100;
|
|
3847
3847
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -6986,8 +6986,8 @@ function pt_default() {
|
|
|
6986
6986
|
}
|
|
6987
6987
|
|
|
6988
6988
|
// node_modules/zod/v4/locales/ru.js
|
|
6989
|
-
function getRussianPlural(
|
|
6990
|
-
const absCount = Math.abs(
|
|
6989
|
+
function getRussianPlural(count2, one, few, many) {
|
|
6990
|
+
const absCount = Math.abs(count2);
|
|
6991
6991
|
const lastDigit = absCount % 10;
|
|
6992
6992
|
const lastTwoDigits = absCount % 100;
|
|
6993
6993
|
if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
|
|
@@ -11166,9 +11166,9 @@ var REPLACE_TRIGGER_BYTES = 4096;
|
|
|
11166
11166
|
var REPLACE_RETURN_BYTES = 96;
|
|
11167
11167
|
var SHAPE_RETURN_BYTES = 256;
|
|
11168
11168
|
var REPLACE_CHUNK_BYTES = 48;
|
|
11169
|
-
function REPLACE_HANDLE_LINE(intent, handle,
|
|
11169
|
+
function REPLACE_HANDLE_LINE(intent, handle, bytes5, prefix = "", asked = "") {
|
|
11170
11170
|
const queries = asked === "" ? [intent] : [intent, asked];
|
|
11171
|
-
return prefix + "ctx_search({queries:[" + queries.map((q) => JSON.stringify(q)).join(",") + "], source:" + JSON.stringify(handle) + "}) searches the whole output (" +
|
|
11171
|
+
return prefix + "ctx_search({queries:[" + queries.map((q) => JSON.stringify(q)).join(",") + "], source:" + JSON.stringify(handle) + "}) searches the whole output (" + bytes5 + " B).";
|
|
11172
11172
|
}
|
|
11173
11173
|
var HANDLE_PROMPT_WORDS = 3;
|
|
11174
11174
|
var MAX_CHUNK_BYTES = 4096;
|
|
@@ -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";
|
|
@@ -11419,8 +11420,8 @@ var HOOK_FAIL_TOOLS = Object.freeze({
|
|
|
11419
11420
|
grep: Object.freeze(["Grep", "grep_search"]),
|
|
11420
11421
|
fetch: Object.freeze(["WebFetch", "web_fetch", "fetch"])
|
|
11421
11422
|
});
|
|
11422
|
-
function HOOK_FAIL_LINE(
|
|
11423
|
-
return `${DENY_PREFIX}the hook failed (${
|
|
11423
|
+
function HOOK_FAIL_LINE(label2, prefix) {
|
|
11424
|
+
return `${DENY_PREFIX}the hook failed (${label2}). Fix: run ${prefix}ctx_doctor.`;
|
|
11424
11425
|
}
|
|
11425
11426
|
var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
11426
11427
|
read: "Read the file in parts with offset and limit, or process it with ctx_execute(language, code); only what you print comes back.",
|
|
@@ -11428,11 +11429,11 @@ var HOOK_FAIL_REDIRECT = Object.freeze({
|
|
|
11428
11429
|
grep: "Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",
|
|
11429
11430
|
fetch: "Index the URL with ctx_index and query it with ctx_search."
|
|
11430
11431
|
});
|
|
11431
|
-
function D5_LAST_HOOK_ERROR(ts, stage,
|
|
11432
|
-
return `; last hook error ${ts} at ${stage} (${
|
|
11432
|
+
function D5_LAST_HOOK_ERROR(ts, stage, label2) {
|
|
11433
|
+
return `; last hook error ${ts} at ${stage} (${label2}), stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
11433
11434
|
}
|
|
11434
|
-
function D5_PAST_HOOK_ERROR(ts, stage,
|
|
11435
|
-
return `; past hook error ${ts} at ${stage} (${
|
|
11435
|
+
function D5_PAST_HOOK_ERROR(ts, stage, label2) {
|
|
11436
|
+
return `; past hook error ${ts} at ${stage} (${label2}), before this run, stack in ${HOOK_ERROR_LOG_FILE}`;
|
|
11436
11437
|
}
|
|
11437
11438
|
var BOUNDED_COMMANDS = Object.freeze(["pwd", "whoami", "uname", "id", "realpath", "ln"]);
|
|
11438
11439
|
var BOUNDED_GIT_SUBCOMMANDS = Object.freeze(["status"]);
|
|
@@ -11501,6 +11502,59 @@ function STATS_SUMMARY(allTimePct, sessionPct) {
|
|
|
11501
11502
|
}
|
|
11502
11503
|
var STATS_COLUMNS = Object.freeze(["Scope", "Produced", "Returned", "Saved", "Reduction %"]);
|
|
11503
11504
|
var STATS_NO_DATA = "no data \u2014 no tool calls recorded yet";
|
|
11505
|
+
var STATS_WIDTH = 80;
|
|
11506
|
+
var STATS_BYTES_PER_TOKEN = 4;
|
|
11507
|
+
var STATS_MAX_TOOL_ROWS = 12;
|
|
11508
|
+
var STATS_LABEL_W = 21;
|
|
11509
|
+
var STATS_LABEL_MAX = 20;
|
|
11510
|
+
var STATS_CALLS_W = 7;
|
|
11511
|
+
var STATS_NUM_W = 11;
|
|
11512
|
+
var STATS_PCT_W = 8;
|
|
11513
|
+
var STATS_KIND_W = 9;
|
|
11514
|
+
var STATS_HEAD_BAR = 40;
|
|
11515
|
+
var STATS_ROW_BAR = 8;
|
|
11516
|
+
var STATS_KIND_BAR = 20;
|
|
11517
|
+
var STATS_KIB = 1024;
|
|
11518
|
+
var STATS_MILLION = 1e6;
|
|
11519
|
+
var STATS_MS_PER_MINUTE = 6e4;
|
|
11520
|
+
var STATS_MINUTES_PER_HOUR = 60;
|
|
11521
|
+
var STATS_HOURS_PER_DAY = 24;
|
|
11522
|
+
var STATS_CLOCK_DIGITS = 2;
|
|
11523
|
+
var STATS_REPORT_TITLE = "context-mode stats";
|
|
11524
|
+
var STATS_EMPTY_LINES = Object.freeze([
|
|
11525
|
+
"Ready. Your savings show up here after the first tool call.",
|
|
11526
|
+
"Large outputs from ctx_execute, ctx_batch and ctx_index stay in the",
|
|
11527
|
+
"sandbox, and only the short answer goes to the chat."
|
|
11528
|
+
]);
|
|
11529
|
+
var STATS_KIND_LABELS = Object.freeze([
|
|
11530
|
+
// D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
|
|
11531
|
+
["index", "Content indexed"],
|
|
11532
|
+
["edit", "File edits"],
|
|
11533
|
+
["toolerr", "Issues kept"],
|
|
11534
|
+
["decision", "Your decisions"],
|
|
11535
|
+
["cmd", "Other tool calls"],
|
|
11536
|
+
["prompt", "Your prompts"]
|
|
11537
|
+
]);
|
|
11538
|
+
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
11539
|
+
"ctx_resume brings back your last task, files changed and open issues",
|
|
11540
|
+
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
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";
|
|
11504
11558
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
11505
11559
|
var PURGE_NO_SCOPE_LINE = "ctx_purge: pick one scope \u2014 session, source, or project.";
|
|
11506
11560
|
var PURGE_MANY_SCOPES_LINE = "ctx_purge: pick only one scope \u2014 session, source, or project.";
|
|
@@ -11516,7 +11570,7 @@ var DECISION_OPTION_KEY = "option";
|
|
|
11516
11570
|
var DECISION_LABEL_JOIN = " | ";
|
|
11517
11571
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
11518
11572
|
var RELEASE_BRANCH = "release";
|
|
11519
|
-
var BUNDLE_SHA = true ? "
|
|
11573
|
+
var BUNDLE_SHA = true ? "feb8de116956b3d3eff56c7d5ed2d840483d0cd4" : void 0;
|
|
11520
11574
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
11521
11575
|
var DOCTOR_LABEL = Object.freeze({
|
|
11522
11576
|
D1: "version",
|
|
@@ -11546,9 +11600,49 @@ function DOCTOR_FAIL_LINE(host, check2, cause, command) {
|
|
|
11546
11600
|
return `FAIL ${host}: ${check2} \u2014 ${cause}. Fix: ${command}`;
|
|
11547
11601
|
}
|
|
11548
11602
|
var DOCTOR_FIX_UPGRADE = "run ctx_upgrade";
|
|
11549
|
-
var
|
|
11550
|
-
var D1_DEV_BUILD_DETAIL = "dev build";
|
|
11603
|
+
var D1_DEV_BUILD_DETAIL = "dev build: source checkout; release builds stamp the sha";
|
|
11551
11604
|
var D1_UPDATE_DETAIL = "update available";
|
|
11605
|
+
var D1_SHORT_SHA_LEN = 7;
|
|
11606
|
+
var D1_PACKAGE_FILE = "package.json";
|
|
11607
|
+
function D1_PREFIX(version4, sha) {
|
|
11608
|
+
return `${version4 ?? "bundle"} (${sha.slice(0, D1_SHORT_SHA_LEN)})`;
|
|
11609
|
+
}
|
|
11610
|
+
var D1_GIT_PASS = "latest on the release branch";
|
|
11611
|
+
function D1_NPM_PASS(tag2) {
|
|
11612
|
+
return `latest ${tag2} on npm`;
|
|
11613
|
+
}
|
|
11614
|
+
function D1_NPM_UPDATE(tag2, latest) {
|
|
11615
|
+
return `${D1_UPDATE_DETAIL}, ${tag2} on npm is ${latest}`;
|
|
11616
|
+
}
|
|
11617
|
+
var D1_LATEST_UNKNOWN = "latest unknown";
|
|
11618
|
+
var D1_GIT_MISSING = "git not found on PATH";
|
|
11619
|
+
function D1_GIT_EXIT(code, stderrLine) {
|
|
11620
|
+
return stderrLine === "" ? `git exit ${code}` : `git exit ${code}: ${stderrLine}`;
|
|
11621
|
+
}
|
|
11622
|
+
function D1_GIT_TIMEOUT(ms) {
|
|
11623
|
+
return `git timed out after ${ms} ms`;
|
|
11624
|
+
}
|
|
11625
|
+
var D1_GIT_CANCEL = "git stopped by cancel";
|
|
11626
|
+
var D1_GIT_NO_START = "git did not start";
|
|
11627
|
+
var D1_GIT_NO_SHA = "git answered no sha";
|
|
11628
|
+
function D1_NPM_TIMEOUT(ms) {
|
|
11629
|
+
return `npm registry timed out after ${ms} ms`;
|
|
11630
|
+
}
|
|
11631
|
+
function D1_NPM_HTTP(status) {
|
|
11632
|
+
return `npm registry answered HTTP ${status}`;
|
|
11633
|
+
}
|
|
11634
|
+
function D1_NPM_ERROR(cause) {
|
|
11635
|
+
return `npm registry: ${cause}`;
|
|
11636
|
+
}
|
|
11637
|
+
function D1_NPM_NO_TAG(tag2) {
|
|
11638
|
+
return `npm registry answered no ${tag2} version`;
|
|
11639
|
+
}
|
|
11640
|
+
var D1_CAUSE_JOIN = "; ";
|
|
11641
|
+
var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
|
|
11642
|
+
var D1_NPM_CHECK_FIX = "npm view context-mode dist-tags";
|
|
11643
|
+
var D1_REGISTRY_URL = "https://registry.npmjs.org/-/package/context-mode/dist-tags";
|
|
11644
|
+
var D1_PRERELEASE_SEP = "-";
|
|
11645
|
+
var D1_DEFAULT_TAG = "latest";
|
|
11552
11646
|
var GIT_LS_REMOTE = "ls-remote";
|
|
11553
11647
|
var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
|
|
11554
11648
|
function D2_NODE_DETAIL(version4) {
|
|
@@ -11837,7 +11931,7 @@ var V1_REASON = Object.freeze({
|
|
|
11837
11931
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
11838
11932
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
11839
11933
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
11840
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only,
|
|
11934
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
11841
11935
|
});
|
|
11842
11936
|
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
11843
11937
|
var PLUGIN_NAME = SERVER_KEY;
|
|
@@ -11878,6 +11972,85 @@ var REPORT_ENV_PREFIX = "env.";
|
|
|
11878
11972
|
var REPORT_ENV_ENUMS = Object.freeze({
|
|
11879
11973
|
NODE_ENV: Object.freeze(["development", "production", "test"])
|
|
11880
11974
|
});
|
|
11975
|
+
var DOCTOR_ENV_PREFIX = "Environment: ";
|
|
11976
|
+
var DOCTOR_DOCS_URL = "https://contextmode.ai/docs/engine/doctor";
|
|
11977
|
+
var DOCTOR_DOCS_ANCHOR = "checks";
|
|
11978
|
+
function DOCTOR_DOCS_LINK(check2) {
|
|
11979
|
+
return `${DOCTOR_DOCS_URL}?utm_source=ctx_doctor&utm_medium=doctor&utm_content=${check2}#${DOCTOR_DOCS_ANCHOR}`;
|
|
11980
|
+
}
|
|
11981
|
+
var DOCTOR_DOCS_LABEL = "Docs: ";
|
|
11982
|
+
function D3_NO_SETUP_FIX(agent) {
|
|
11983
|
+
return `context-mode setup --agents ${agent}`;
|
|
11984
|
+
}
|
|
11985
|
+
function D5_FIXTURE_FILE_ABSENT(file2) {
|
|
11986
|
+
return `hook fixture ${file2} is absent: the round trip needs it`;
|
|
11987
|
+
}
|
|
11988
|
+
function D5_FIXTURE_PARSE(file2, cause) {
|
|
11989
|
+
return `the hook fixture file ${file2} failed to parse: ${cause}`;
|
|
11990
|
+
}
|
|
11991
|
+
function D5_FIXTURE_AGENT_ABSENT(file2, keys) {
|
|
11992
|
+
return `the hook fixture file ${file2} records payloads for ${keys.join(", ") || "zero agents"} only`;
|
|
11993
|
+
}
|
|
11994
|
+
var DOCTOR_REPORTS_DIR = "reports";
|
|
11995
|
+
var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
|
|
11996
|
+
var DOCTOR_REPORT_LINE = "Report file: ";
|
|
11997
|
+
var DOCTOR_GH_LINE = "File it: ";
|
|
11998
|
+
var DOCTOR_URL_LINE = "Or open: ";
|
|
11999
|
+
var DOCTOR_GH_NEXT = " --";
|
|
12000
|
+
var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
12001
|
+
DOCTOR_ENV_PREFIX,
|
|
12002
|
+
DOCTOR_DOCS_LABEL,
|
|
12003
|
+
DOCTOR_REPORT_LINE,
|
|
12004
|
+
DOCTOR_GH_LINE,
|
|
12005
|
+
DOCTOR_GH_NEXT.trim(),
|
|
12006
|
+
DOCTOR_URL_LINE
|
|
12007
|
+
]);
|
|
12008
|
+
var ISSUE_REPO_SLUG = "mksglu/context-mode";
|
|
12009
|
+
var ISSUE_FORM_FILE = "agent-report.yml";
|
|
12010
|
+
var ISSUE_URL_MAX = 8e3;
|
|
12011
|
+
var ISSUE_FORM_HEADINGS = Object.freeze([
|
|
12012
|
+
"Summary",
|
|
12013
|
+
"ctx-report",
|
|
12014
|
+
"What happened",
|
|
12015
|
+
"Hook errors",
|
|
12016
|
+
"Journal rows",
|
|
12017
|
+
"Agent config",
|
|
12018
|
+
"Expected",
|
|
12019
|
+
"Steps",
|
|
12020
|
+
"Environment"
|
|
12021
|
+
]);
|
|
12022
|
+
var DOCTOR_HOOK_LOG_LINES = 50;
|
|
12023
|
+
var DOCTOR_JOURNAL_ROWS = 30;
|
|
12024
|
+
var DOCTOR_CONFIG_LINES = 40;
|
|
12025
|
+
var DOCTOR_ENV_NAMES = Object.freeze([
|
|
12026
|
+
"CODEX_HOME",
|
|
12027
|
+
"CLAUDE_CONFIG_DIR",
|
|
12028
|
+
"CLAUDE_PLUGIN_ROOT",
|
|
12029
|
+
"COPILOT_HOME",
|
|
12030
|
+
"KIRO_HOME",
|
|
12031
|
+
"OPENCODE_CONFIG_DIR",
|
|
12032
|
+
"PI_CODING_AGENT_DIR",
|
|
12033
|
+
"XDG_CONFIG_HOME",
|
|
12034
|
+
"SHELL"
|
|
12035
|
+
]);
|
|
12036
|
+
var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
|
|
12037
|
+
var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
|
|
12038
|
+
var DOCTOR_MASK = "<masked>";
|
|
12039
|
+
var NATIVE_INSTALL = Object.freeze({
|
|
12040
|
+
"claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
|
|
12041
|
+
codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
|
|
12042
|
+
gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
|
|
12043
|
+
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
|
|
12044
|
+
opencode: ["opencode plugin add context-mode@next"],
|
|
12045
|
+
pi: ["pi install npm:context-mode@next"],
|
|
12046
|
+
"copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
|
|
12047
|
+
vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
|
|
12048
|
+
kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
|
|
12049
|
+
zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
|
|
12050
|
+
});
|
|
12051
|
+
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
12052
|
+
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
12053
|
+
var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
11881
12054
|
|
|
11882
12055
|
// src/adapters/pi.ts
|
|
11883
12056
|
var TOOL_NAME_PREFIX = "";
|
|
@@ -12339,8 +12512,8 @@ function decode6(raw) {
|
|
|
12339
12512
|
if (event === "SessionStart" && typeof raw.source === "string" && COPILOT_SOURCES[raw.source] !== void 0) ev.source = COPILOT_SOURCES[raw.source];
|
|
12340
12513
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
12341
12514
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
12342
|
-
const
|
|
12343
|
-
const tool = { name:
|
|
12515
|
+
const toolName2 = String(raw[k.tool] ?? "");
|
|
12516
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
12344
12517
|
ev.tool = tool;
|
|
12345
12518
|
}
|
|
12346
12519
|
if (event === "PostToolUse") ev.result = readResult4(raw[k.result], native.casing, native.failure);
|
|
@@ -12454,9 +12627,9 @@ function decodeCamel(p, name) {
|
|
|
12454
12627
|
if (event === "SessionStart" && typeof p.source === "string" && SESSION_SOURCES[p.source] !== void 0) ev.source = SESSION_SOURCES[p.source];
|
|
12455
12628
|
if (event === "UserPromptSubmit" && typeof p.prompt === "string") ev.prompt = p.prompt;
|
|
12456
12629
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
12457
|
-
const
|
|
12458
|
-
const canonical = canonicalName4(
|
|
12459
|
-
ev.tool = { name:
|
|
12630
|
+
const toolName2 = String(p.toolName ?? "");
|
|
12631
|
+
const canonical = canonicalName4(toolName2);
|
|
12632
|
+
ev.tool = { name: toolName2, canonicalName: canonical, input: policyInput(toolName2, canonical, readArgs2(p.toolArgs)) };
|
|
12460
12633
|
}
|
|
12461
12634
|
if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
|
|
12462
12635
|
return ev;
|
|
@@ -13249,10 +13422,10 @@ function lexSpan(st, from, inParen, depth, out, bodies) {
|
|
|
13249
13422
|
}
|
|
13250
13423
|
function scan(cmd) {
|
|
13251
13424
|
const st = { s: cmd, n: cmd.length, end: "complete" };
|
|
13252
|
-
const
|
|
13425
|
+
const tokens2 = [];
|
|
13253
13426
|
const heredocBodies = [];
|
|
13254
|
-
lexSpan(st, 0, false, 0,
|
|
13255
|
-
return { tokens, heredocBodies, end: st.end };
|
|
13427
|
+
lexSpan(st, 0, false, 0, tokens2, heredocBodies);
|
|
13428
|
+
return { tokens: tokens2, heredocBodies, end: st.end };
|
|
13256
13429
|
}
|
|
13257
13430
|
function dequote(word) {
|
|
13258
13431
|
let out = "";
|
|
@@ -13484,11 +13657,11 @@ function jqPath(s) {
|
|
|
13484
13657
|
function jqWhitelisted(filter2) {
|
|
13485
13658
|
const s = filter2.trim();
|
|
13486
13659
|
if (s === JQ_WHITELIST.identity || s === JQ_WHITELIST.length) return true;
|
|
13487
|
-
const
|
|
13488
|
-
if (
|
|
13489
|
-
const left = s.slice(0,
|
|
13660
|
+
const bar2 = s.indexOf(JQ_WHITELIST.pipeLength.charAt(0));
|
|
13661
|
+
if (bar2 < 0) return jqPath(s);
|
|
13662
|
+
const left = s.slice(0, bar2).trim();
|
|
13490
13663
|
const right = JQ_WHITELIST.pipeLength.slice(1).trim();
|
|
13491
|
-
return (left === JQ_WHITELIST.identity || jqPath(left)) && s.slice(
|
|
13664
|
+
return (left === JQ_WHITELIST.identity || jqPath(left)) && s.slice(bar2 + 1).trim() === right;
|
|
13492
13665
|
}
|
|
13493
13666
|
function isBoundedSink(c) {
|
|
13494
13667
|
const name = c.argv0.toLowerCase();
|
|
@@ -14695,8 +14868,8 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
14695
14868
|
ctx_index: 'Example: `ctx_index({path:"docs/api.md"})`. Required: one of path, content, url.\nStores content so it can be searched later: a local file or folder (nested .gitignore files are respected), raw text, or a URL, which is fetched and converted to Markdown. Use it for documentation or large files you will query more than once, then use ctx_search instead of reading the content again. Returns the source label and how many chunks were stored.',
|
|
14696
14869
|
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.',
|
|
14697
14870
|
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.",
|
|
14698
|
-
ctx_stats: "Example: `ctx_stats({})`. Required: none.\nReports
|
|
14699
|
-
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
|
|
14871
|
+
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.",
|
|
14872
|
+
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",
|
|
14700
14873
|
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.",
|
|
14701
14874
|
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.'
|
|
14702
14875
|
});
|
|
@@ -15209,8 +15382,8 @@ function firstLine(file2) {
|
|
|
15209
15382
|
return line === "" ? null : line;
|
|
15210
15383
|
}
|
|
15211
15384
|
function git(dir, args) {
|
|
15212
|
-
const { spawnSync:
|
|
15213
|
-
const r =
|
|
15385
|
+
const { spawnSync: spawnSync4 } = process.getBuiltinModule("node:child_process");
|
|
15386
|
+
const r = spawnSync4("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
15214
15387
|
if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
15215
15388
|
return r.stdout.split("\n").filter((l) => l !== "");
|
|
15216
15389
|
}
|
|
@@ -15774,7 +15947,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
15774
15947
|
terms = given.filter((t) => t.text.length >= 5).map((t) => ({ ...t, text: t.text.slice(0, Math.max(4, t.text.length - 2)) }));
|
|
15775
15948
|
pos = terms.map(find2);
|
|
15776
15949
|
}
|
|
15777
|
-
const
|
|
15950
|
+
const count2 = (ti, a, b) => {
|
|
15778
15951
|
const ps = pos[ti];
|
|
15779
15952
|
let lo = 0, hi = ps.length;
|
|
15780
15953
|
while (lo < hi) {
|
|
@@ -15789,7 +15962,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
15789
15962
|
const N = blocks.length;
|
|
15790
15963
|
const blen = blocks.map((bk2) => rangeBytes(bk2.first, bk2.last));
|
|
15791
15964
|
const avg = blen.reduce((a, b) => a + b, 0) / N || 1;
|
|
15792
|
-
const tf = blocks.map((bk2) => terms.map((_, ti) =>
|
|
15965
|
+
const tf = blocks.map((bk2) => terms.map((_, ti) => count2(ti, ls[bk2.first], le[bk2.last])));
|
|
15793
15966
|
const idf = terms.map((_, ti) => {
|
|
15794
15967
|
let df = 0;
|
|
15795
15968
|
for (let k = 0; k < N; k++) if (tf[k][ti] > 0) df++;
|
|
@@ -15811,7 +15984,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
15811
15984
|
const lineScore = (i) => {
|
|
15812
15985
|
let s = 0;
|
|
15813
15986
|
terms.forEach((_, ti) => {
|
|
15814
|
-
if (
|
|
15987
|
+
if (count2(ti, ls[i], le[i]) > 0) s += weight(ti, bk.code);
|
|
15815
15988
|
});
|
|
15816
15989
|
return s;
|
|
15817
15990
|
};
|
|
@@ -15819,7 +15992,7 @@ function buildSnippet(row5, given, maxBytes, codeMaxBytes = SNIPPET_CODE_MAX_BYT
|
|
|
15819
15992
|
let at2 = -1;
|
|
15820
15993
|
let w = -1;
|
|
15821
15994
|
terms.forEach((_, ti) => {
|
|
15822
|
-
const c =
|
|
15995
|
+
const c = count2(ti, ls[i], le[i]);
|
|
15823
15996
|
if (c === 0 || weight(ti, bk.code) <= w) return;
|
|
15824
15997
|
const ps = pos[ti];
|
|
15825
15998
|
let lo = 0, hi = ps.length;
|
|
@@ -17788,8 +17961,8 @@ function trigramMatch(q) {
|
|
|
17788
17961
|
const words = blankTokens(q);
|
|
17789
17962
|
const kept = words.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
17790
17963
|
const parts = new Set((kept.length > 0 ? kept : words).filter((w) => [...w].length >= 3));
|
|
17791
|
-
const
|
|
17792
|
-
if (words.length > 1 && [...
|
|
17964
|
+
const whole2 = words.join(" ");
|
|
17965
|
+
if (words.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
17793
17966
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
17794
17967
|
}
|
|
17795
17968
|
function editDistance(a, b, max) {
|
|
@@ -18069,8 +18242,8 @@ function parseSourceHandle(s) {
|
|
|
18069
18242
|
function pathLabel(p) {
|
|
18070
18243
|
return p.includes("\\") ? p.split("\\").join("/") : p;
|
|
18071
18244
|
}
|
|
18072
|
-
function labelStored(db,
|
|
18073
|
-
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(
|
|
18245
|
+
function labelStored(db, label2) {
|
|
18246
|
+
return stmt(db.raw, "SELECT 1 AS x FROM sources WHERE label = ? LIMIT 1").get(label2) !== void 0;
|
|
18074
18247
|
}
|
|
18075
18248
|
function storedLabel(db, source) {
|
|
18076
18249
|
if (labelStored(db, source)) return source;
|
|
@@ -18100,9 +18273,9 @@ function insertUnits(db, sourceId, sessionId, units) {
|
|
|
18100
18273
|
let start = 0;
|
|
18101
18274
|
while (start < units.length) {
|
|
18102
18275
|
let end = start;
|
|
18103
|
-
let
|
|
18104
|
-
while (end < units.length && (end === start ||
|
|
18105
|
-
|
|
18276
|
+
let bytes5 = 0;
|
|
18277
|
+
while (end < units.length && (end === start || bytes5 + units[end].body.length <= INDEX_WRITE_CHUNK)) {
|
|
18278
|
+
bytes5 += units[end].body.length;
|
|
18106
18279
|
end++;
|
|
18107
18280
|
}
|
|
18108
18281
|
const from = start;
|
|
@@ -18136,15 +18309,15 @@ function indentOf(line) {
|
|
|
18136
18309
|
}
|
|
18137
18310
|
function buildUnits(text) {
|
|
18138
18311
|
const lines = text.split("\n");
|
|
18139
|
-
const
|
|
18312
|
+
const stack2 = [];
|
|
18140
18313
|
const out = [];
|
|
18141
18314
|
for (let i = 0; i < lines.length; i++) {
|
|
18142
18315
|
const line = lines[i].endsWith("\r") ? lines[i].slice(0, -1) : lines[i];
|
|
18143
18316
|
const indent = indentOf(line);
|
|
18144
18317
|
if (indent === line.length) continue;
|
|
18145
|
-
while (
|
|
18146
|
-
out.push({ ord: i, body: [...
|
|
18147
|
-
|
|
18318
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].indent >= indent) stack2.pop();
|
|
18319
|
+
out.push({ ord: i, body: [...stack2.map((s) => s.line), line].join("\n") });
|
|
18320
|
+
stack2.push({ indent, line });
|
|
18148
18321
|
}
|
|
18149
18322
|
return out;
|
|
18150
18323
|
}
|
|
@@ -18155,9 +18328,9 @@ function firstLine2(body) {
|
|
|
18155
18328
|
return (nl < 0 ? body : body.slice(0, nl)).replaceAll("\r", " ");
|
|
18156
18329
|
}
|
|
18157
18330
|
function make(section, row5, text, repeatCount, query) {
|
|
18158
|
-
const
|
|
18159
|
-
if (
|
|
18160
|
-
return { section, seq: row5.seq, turn: row5.turn, text, bytes:
|
|
18331
|
+
const bytes5 = Buffer.byteLength(text, "utf8");
|
|
18332
|
+
if (bytes5 < 1) throw new Error("compaction: empty candidate line (DECISIONS-r9 M9).");
|
|
18333
|
+
return { section, seq: row5.seq, turn: row5.turn, text, bytes: bytes5, repeatCount, pinned: section === "last_request", query };
|
|
18161
18334
|
}
|
|
18162
18335
|
function capSection(list4) {
|
|
18163
18336
|
return list4.length > MAX_CANDIDATES ? list4.slice(list4.length - MAX_CANDIDATES) : list4;
|
|
@@ -18446,11 +18619,11 @@ function chunkText(text, kind, maxBytes = MAX_CHUNK_BYTES) {
|
|
|
18446
18619
|
}
|
|
18447
18620
|
function mdChunks(src, cap, lineCut) {
|
|
18448
18621
|
const out = [];
|
|
18449
|
-
const
|
|
18622
|
+
const stack2 = [];
|
|
18450
18623
|
let title = "";
|
|
18451
18624
|
let run = [];
|
|
18452
|
-
const push2 = (text,
|
|
18453
|
-
out.push({ ord: out.length, text, bytes:
|
|
18625
|
+
const push2 = (text, bytes5) => {
|
|
18626
|
+
out.push({ ord: out.length, text, bytes: bytes5, title });
|
|
18454
18627
|
};
|
|
18455
18628
|
const flush = () => {
|
|
18456
18629
|
if (run.length === 0) return;
|
|
@@ -18460,9 +18633,9 @@ function mdChunks(src, cap, lineCut) {
|
|
|
18460
18633
|
for (const b of lineBlocks(src, true)) {
|
|
18461
18634
|
if (b.heading !== void 0) {
|
|
18462
18635
|
flush();
|
|
18463
|
-
while (
|
|
18464
|
-
|
|
18465
|
-
title =
|
|
18636
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].level >= b.heading.level) stack2.pop();
|
|
18637
|
+
stack2.push(b.heading);
|
|
18638
|
+
title = stack2.map((h) => h.text).join(" > ");
|
|
18466
18639
|
}
|
|
18467
18640
|
if (b.fence !== void 0 && utf8Bytes(src.slice(b.start, b.end)) > cap) {
|
|
18468
18641
|
const pieces = fencePieces(src, b, b.fence, cap);
|
|
@@ -18500,19 +18673,19 @@ function lineBlocks(src, md) {
|
|
|
18500
18673
|
let fenceInfo;
|
|
18501
18674
|
const close = () => {
|
|
18502
18675
|
if (start >= 0) {
|
|
18503
|
-
const
|
|
18504
|
-
if (heading !== void 0)
|
|
18505
|
-
if (fenceInfo !== void 0)
|
|
18506
|
-
out.push(
|
|
18676
|
+
const span2 = { start, end };
|
|
18677
|
+
if (heading !== void 0) span2.heading = heading;
|
|
18678
|
+
if (fenceInfo !== void 0) span2.fence = fenceInfo;
|
|
18679
|
+
out.push(span2);
|
|
18507
18680
|
}
|
|
18508
18681
|
start = -1;
|
|
18509
18682
|
heading = void 0;
|
|
18510
18683
|
fenceInfo = void 0;
|
|
18511
18684
|
};
|
|
18512
|
-
const add = (from, to,
|
|
18685
|
+
const add = (from, to, table3) => {
|
|
18513
18686
|
if (start < 0) start = from;
|
|
18514
18687
|
end = to;
|
|
18515
|
-
inTable =
|
|
18688
|
+
inTable = table3;
|
|
18516
18689
|
};
|
|
18517
18690
|
let pos = 0;
|
|
18518
18691
|
while (pos <= src.length) {
|
|
@@ -18533,9 +18706,9 @@ function lineBlocks(src, md) {
|
|
|
18533
18706
|
} else {
|
|
18534
18707
|
const opener = md ? fenceOf(line) : "";
|
|
18535
18708
|
const head = md && opener === "" ? headingOf(line) : void 0;
|
|
18536
|
-
const
|
|
18537
|
-
if (md && start >= 0 && (
|
|
18538
|
-
add(pos, eol,
|
|
18709
|
+
const table3 = md && opener === "" && head === void 0 && line.includes("|");
|
|
18710
|
+
if (md && start >= 0 && (table3 !== inTable || opener !== "" || head !== void 0)) close();
|
|
18711
|
+
add(pos, eol, table3);
|
|
18539
18712
|
fence = opener;
|
|
18540
18713
|
if (opener !== "") fenceInfo = { fence: opener, openEnd: eol, closeStart: -1 };
|
|
18541
18714
|
if (head !== void 0) {
|
|
@@ -18695,17 +18868,17 @@ function cutPoint(src, start, end, scratch) {
|
|
|
18695
18868
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
18696
18869
|
return { end: start + r.read, written: r.written };
|
|
18697
18870
|
}
|
|
18698
|
-
function merge2(src, blocks,
|
|
18871
|
+
function merge2(src, blocks, join27, cap, lineCut) {
|
|
18699
18872
|
const out = [];
|
|
18700
18873
|
const scratch = new Uint8Array(cap);
|
|
18701
18874
|
let wide;
|
|
18702
18875
|
let cur;
|
|
18703
18876
|
let curBytes = 0;
|
|
18704
|
-
const emit = (start, end,
|
|
18705
|
-
out.push({ ord: out.length, text: src.slice(start, end), bytes:
|
|
18877
|
+
const emit = (start, end, bytes5) => {
|
|
18878
|
+
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
18706
18879
|
};
|
|
18707
18880
|
for (const b of blocks) {
|
|
18708
|
-
if (cur !== void 0 && !
|
|
18881
|
+
if (cur !== void 0 && !join27) {
|
|
18709
18882
|
emit(cur.start, cur.end, curBytes);
|
|
18710
18883
|
cur = void 0;
|
|
18711
18884
|
}
|
|
@@ -18720,15 +18893,15 @@ function merge2(src, blocks, join25, cap, lineCut) {
|
|
|
18720
18893
|
cur = void 0;
|
|
18721
18894
|
}
|
|
18722
18895
|
let start = b.start;
|
|
18723
|
-
let
|
|
18724
|
-
while (
|
|
18896
|
+
let bytes5 = utf8Bytes(src.slice(b.start, b.end));
|
|
18897
|
+
while (bytes5 > cap) {
|
|
18725
18898
|
const cut = cutPoint(src, start, b.end, scratch);
|
|
18726
18899
|
const nl = lineCut ? src.lastIndexOf("\n", cut.end - 1) : -1;
|
|
18727
18900
|
if (nl > start) {
|
|
18728
18901
|
const w = utf8Bytes(src.slice(start, nl + 1));
|
|
18729
18902
|
emit(start, nl + 1, w);
|
|
18730
18903
|
start = nl + 1;
|
|
18731
|
-
|
|
18904
|
+
bytes5 -= w;
|
|
18732
18905
|
continue;
|
|
18733
18906
|
}
|
|
18734
18907
|
if (lineCut) {
|
|
@@ -18738,23 +18911,23 @@ function merge2(src, blocks, join25, cap, lineCut) {
|
|
|
18738
18911
|
if (w <= MAX_CHUNK_BYTES) {
|
|
18739
18912
|
emit(start, lineEnd, w);
|
|
18740
18913
|
start = lineEnd;
|
|
18741
|
-
|
|
18914
|
+
bytes5 -= w;
|
|
18742
18915
|
continue;
|
|
18743
18916
|
}
|
|
18744
18917
|
wide ??= new Uint8Array(MAX_CHUNK_BYTES);
|
|
18745
18918
|
const big = cutPoint(src, start, lineEnd, wide);
|
|
18746
18919
|
emit(start, big.end, big.written);
|
|
18747
18920
|
start = big.end;
|
|
18748
|
-
|
|
18921
|
+
bytes5 -= big.written;
|
|
18749
18922
|
continue;
|
|
18750
18923
|
}
|
|
18751
18924
|
emit(start, cut.end, cut.written);
|
|
18752
18925
|
start = cut.end;
|
|
18753
|
-
|
|
18926
|
+
bytes5 -= cut.written;
|
|
18754
18927
|
}
|
|
18755
18928
|
if (start >= b.end) continue;
|
|
18756
18929
|
cur = { start, end: b.end };
|
|
18757
|
-
curBytes =
|
|
18930
|
+
curBytes = bytes5;
|
|
18758
18931
|
}
|
|
18759
18932
|
if (cur !== void 0) emit(cur.start, cur.end, curBytes);
|
|
18760
18933
|
return out;
|
|
@@ -18775,7 +18948,7 @@ function selectChunks(db, sourceId, intent, budget) {
|
|
|
18775
18948
|
function selectChunksInMemory(chunks, intent, budget, source, rankQuery) {
|
|
18776
18949
|
return select(chunks, intent, budget, source, rankQuery);
|
|
18777
18950
|
}
|
|
18778
|
-
function select(chunks, intent, budget,
|
|
18951
|
+
function select(chunks, intent, budget, label2, rankQuery) {
|
|
18779
18952
|
if (chunks.length === 0) return { text: "", more: null };
|
|
18780
18953
|
const texts = chunks.map((c) => c.text);
|
|
18781
18954
|
const scores = rankQuery === void 0 ? rankTexts(texts, intent) : rankTexts(texts, rankQuery, "any");
|
|
@@ -18794,10 +18967,10 @@ function select(chunks, intent, budget, label, rankQuery) {
|
|
|
18794
18967
|
}
|
|
18795
18968
|
picked.sort((a, b) => a.ord - b.ord);
|
|
18796
18969
|
const text = picked.map((c) => c.text).join(SEP);
|
|
18797
|
-
return { text, more: skipped ? moreLine2(intent,
|
|
18970
|
+
return { text, more: skipped ? moreLine2(intent, label2) : null };
|
|
18798
18971
|
}
|
|
18799
|
-
function moreLine2(intent,
|
|
18800
|
-
const source =
|
|
18972
|
+
function moreLine2(intent, label2) {
|
|
18973
|
+
const source = label2 === void 0 ? "" : ", source:" + JSON.stringify(label2);
|
|
18801
18974
|
const query = Buffer.byteLength(intent, "utf8") > ECHO_MAX_BYTES ? "..." : JSON.stringify(intent);
|
|
18802
18975
|
return "ctx_search({queries:[" + query + "]" + source + "})";
|
|
18803
18976
|
}
|
|
@@ -18845,10 +19018,10 @@ function firstNonSpace(s) {
|
|
|
18845
19018
|
function isPlainObject2(v) {
|
|
18846
19019
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
18847
19020
|
}
|
|
18848
|
-
function rareOfSkewed(n, counts,
|
|
18849
|
-
if (
|
|
18850
|
-
const sorted = [...
|
|
18851
|
-
if (
|
|
19021
|
+
function rareOfSkewed(n, counts, totals2) {
|
|
19022
|
+
if (totals2.size < 2 || totals2.size > SHAPE_CATEGORICAL_MAX) return [];
|
|
19023
|
+
const sorted = [...totals2.entries()].sort((a, b) => b[1] - a[1]);
|
|
19024
|
+
if (totals2.size <= SHAPE_RARE_MAX + 1) {
|
|
18852
19025
|
if (sorted[0][1] < SHAPE_DOMINANT * n || n - sorted[0][1] > SHAPE_RARE_MAX) return [];
|
|
18853
19026
|
return sorted.slice(1).flatMap(([v]) => counts.get(v) ?? []);
|
|
18854
19027
|
}
|
|
@@ -18883,7 +19056,7 @@ function jsonShape(text, query) {
|
|
|
18883
19056
|
const outliers = /* @__PURE__ */ new Map();
|
|
18884
19057
|
for (const k of keys) {
|
|
18885
19058
|
const counts = /* @__PURE__ */ new Map();
|
|
18886
|
-
const
|
|
19059
|
+
const totals2 = /* @__PURE__ */ new Map();
|
|
18887
19060
|
let scalar = true;
|
|
18888
19061
|
for (let i = 0; i < objs.length && scalar; i++) {
|
|
18889
19062
|
const v = k in objs[i] ? objs[i][k] : void 0;
|
|
@@ -18892,14 +19065,14 @@ function jsonShape(text, query) {
|
|
|
18892
19065
|
break;
|
|
18893
19066
|
}
|
|
18894
19067
|
const s = v === void 0 ? ABSENT : JSON.stringify(v);
|
|
18895
|
-
|
|
19068
|
+
totals2.set(s, (totals2.get(s) ?? 0) + 1);
|
|
18896
19069
|
const at2 = counts.get(s) ?? [];
|
|
18897
19070
|
if (at2.length <= SHAPE_RARE_MAX) at2.push(i);
|
|
18898
19071
|
counts.set(s, at2);
|
|
18899
|
-
if (
|
|
19072
|
+
if (totals2.size > SHAPE_CATEGORICAL_MAX) break;
|
|
18900
19073
|
}
|
|
18901
19074
|
if (!scalar) continue;
|
|
18902
|
-
for (const i of rareOfSkewed(objs.length, counts,
|
|
19075
|
+
for (const i of rareOfSkewed(objs.length, counts, totals2)) outliers.set(i, [...outliers.get(i) ?? [], k]);
|
|
18903
19076
|
}
|
|
18904
19077
|
if (outliers.size === 0 || outliers.size > SHAPE_RARE_UNITS_MAX) return null;
|
|
18905
19078
|
const keyScore = rankTexts(keys, query, "any");
|
|
@@ -18917,8 +19090,8 @@ function renderRow(i, row5, skewed, named, budget) {
|
|
|
18917
19090
|
return body === null ? null : prefix + body;
|
|
18918
19091
|
}
|
|
18919
19092
|
function fitRow(row5, skewed, named, budget) {
|
|
18920
|
-
const
|
|
18921
|
-
if (bytes(
|
|
19093
|
+
const whole2 = JSON.stringify(row5);
|
|
19094
|
+
if (bytes(whole2) <= budget) return whole2;
|
|
18922
19095
|
const own4 = Object.keys(row5);
|
|
18923
19096
|
const tier = (k) => skewed.includes(k) ? 0 : named.has(k) ? 1 : typeof row5[k] !== "object" || row5[k] === null ? 2 : 3;
|
|
18924
19097
|
const order = [...own4].sort((a, b) => tier(a) - tier(b) || own4.indexOf(a) - own4.indexOf(b));
|
|
@@ -19027,14 +19200,14 @@ function lineShape(text) {
|
|
|
19027
19200
|
}
|
|
19028
19201
|
|
|
19029
19202
|
// src/core/index/text.ts
|
|
19030
|
-
function storeText(db, project, sessionId, sourceKind,
|
|
19203
|
+
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
19031
19204
|
const sourceId = ftsInsert(db, {
|
|
19032
19205
|
projectKey: project.projectKey,
|
|
19033
19206
|
sessionId,
|
|
19034
19207
|
worktree: project.worktree,
|
|
19035
19208
|
agent: project.agent,
|
|
19036
19209
|
kind: sourceKind,
|
|
19037
|
-
label,
|
|
19210
|
+
label: label2,
|
|
19038
19211
|
bytes: Buffer.byteLength(text, "utf8"),
|
|
19039
19212
|
chunkCount: chunks.length,
|
|
19040
19213
|
createdAt: Date.now()
|
|
@@ -19097,9 +19270,9 @@ function answerDecisions(responseText) {
|
|
|
19097
19270
|
if (!isObject3(parsed)) return [];
|
|
19098
19271
|
const out = [];
|
|
19099
19272
|
for (const [question, value] of answerPairs(parsed[DECISION_ANSWERS_KEY])) {
|
|
19100
|
-
const
|
|
19101
|
-
if (question === "" ||
|
|
19102
|
-
out.push({ key: question, body: "Q: " + question + " \u2192 A: " +
|
|
19273
|
+
const label2 = labelText(value);
|
|
19274
|
+
if (question === "" || label2 === "") continue;
|
|
19275
|
+
out.push({ key: question, body: "Q: " + question + " \u2192 A: " + label2 });
|
|
19103
19276
|
}
|
|
19104
19277
|
return out;
|
|
19105
19278
|
}
|
|
@@ -19119,9 +19292,9 @@ function fold(s) {
|
|
|
19119
19292
|
function optionEchoDecision(prompt, labels, refSeq) {
|
|
19120
19293
|
const p = fold(prompt);
|
|
19121
19294
|
if (p === "") return null;
|
|
19122
|
-
const
|
|
19123
|
-
if (
|
|
19124
|
-
return { key: DECISION_OPTION_KEY, body: "A: " +
|
|
19295
|
+
const label2 = labels.find((l) => fold(l) === p);
|
|
19296
|
+
if (label2 === void 0) return null;
|
|
19297
|
+
return { key: DECISION_OPTION_KEY, body: "A: " + label2 + "\nref: #" + refSeq };
|
|
19125
19298
|
}
|
|
19126
19299
|
|
|
19127
19300
|
// src/core/hooks/throttle.ts
|
|
@@ -19135,9 +19308,9 @@ function takeOnce(db, key) {
|
|
|
19135
19308
|
}
|
|
19136
19309
|
function takeEvery(db, key, everyN) {
|
|
19137
19310
|
const stored = metaGet(db, key);
|
|
19138
|
-
const
|
|
19139
|
-
metaSet(db, key, String(
|
|
19140
|
-
return (
|
|
19311
|
+
const count2 = (stored === null ? 0 : Number.parseInt(stored, 10)) + 1;
|
|
19312
|
+
metaSet(db, key, String(count2));
|
|
19313
|
+
return (count2 - 1) % everyN === 0;
|
|
19141
19314
|
}
|
|
19142
19315
|
function shouldHint(db, sessionId, onceKey, everyN) {
|
|
19143
19316
|
if (sessionId === "") return false;
|
|
@@ -19630,33 +19803,33 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
19630
19803
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
19631
19804
|
if (result.keep === true) return ALLOW2;
|
|
19632
19805
|
if (!hasReplace(row5)) return ALLOW2;
|
|
19633
|
-
let
|
|
19806
|
+
let label2;
|
|
19634
19807
|
if (isSubagentCall(ev)) {
|
|
19635
19808
|
const subCase = pickSubagentCase(ev, toolSetForAgentType(ev, { projectDir: project.worktree, env }));
|
|
19636
19809
|
if (subCase === "A") return ALLOW2;
|
|
19637
|
-
|
|
19810
|
+
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + String(ev.turn ?? 0);
|
|
19638
19811
|
} else {
|
|
19639
|
-
|
|
19812
|
+
label2 = mainLabel(tool, ev);
|
|
19640
19813
|
}
|
|
19641
19814
|
const intent = [tool.input.description, tool.input.command, tool.input.file_path, tool.input.pattern, tool.input.url].map(str2).find((v) => v.trim() !== "") ?? "";
|
|
19642
19815
|
const chunks = chunkText(text, "text", REPLACE_CHUNK_BYTES);
|
|
19643
19816
|
const db = await openDb(project);
|
|
19644
19817
|
let sourceId;
|
|
19645
19818
|
if (result.bytes <= SYNC_INDEX_MAX_BYTES) {
|
|
19646
|
-
sourceId = indexText(db, project, ev.sessionId,
|
|
19819
|
+
sourceId = indexText(db, project, ev.sessionId, label2, text, "text", chunks).sourceId;
|
|
19647
19820
|
insertUnits(db, sourceId, ev.sessionId, buildUnits(text));
|
|
19648
19821
|
} else {
|
|
19649
|
-
sourceId = reserveSource(db, sourceRowOf(project, ev.sessionId,
|
|
19650
|
-
indexDetached(project, ev.sessionId, sourceId,
|
|
19822
|
+
sourceId = reserveSource(db, sourceRowOf(project, ev.sessionId, label2), chunks);
|
|
19823
|
+
indexDetached(project, ev.sessionId, sourceId, label2, text, chunks);
|
|
19651
19824
|
}
|
|
19652
19825
|
const handle = sourceHandle(sourceId);
|
|
19653
19826
|
const prompt = await lastPrompt(project, ev.sessionId);
|
|
19654
19827
|
const rankQuery = prompt.trim() === "" ? void 0 : intent + " " + prompt;
|
|
19655
19828
|
const handleLine = REPLACE_HANDLE_LINE(intent, handle, result.bytes, row5.toolNamePrefix, askedWords(intent, prompt, text));
|
|
19656
|
-
const budget = replaceBudget(handleLine, moreLine2(intent,
|
|
19829
|
+
const budget = replaceBudget(handleLine, moreLine2(intent, label2));
|
|
19657
19830
|
const digest = shapeDigest(text, rankQuery ?? intent, SHAPE_RETURN_BYTES);
|
|
19658
19831
|
if (digest !== null) return { kind: "replace", output: replaceOutput(digest, handleLine) };
|
|
19659
|
-
const selected = selectChunksInMemory(chunks, intent, budget,
|
|
19832
|
+
const selected = selectChunksInMemory(chunks, intent, budget, label2, rankQuery);
|
|
19660
19833
|
return { kind: "replace", output: selected.more !== null ? replaceOutput(selected.text, handleLine) : selected.text };
|
|
19661
19834
|
}
|
|
19662
19835
|
function replaceOutput(body, handleLine) {
|
|
@@ -19687,15 +19860,15 @@ function mainLabel(tool, ev) {
|
|
|
19687
19860
|
const head = (tool.canonicalName + ":" + (nl < 0 ? cmd : cmd.slice(0, nl))).slice(0, SOURCE_LABEL_MAX_CHARS);
|
|
19688
19861
|
return head + "#" + (tool.callId ?? String(ev.turn ?? 0));
|
|
19689
19862
|
}
|
|
19690
|
-
function indexDetached(project, sessionId, sourceId,
|
|
19863
|
+
function indexDetached(project, sessionId, sourceId, label2, text, chunks) {
|
|
19691
19864
|
void openDb(project).then((db) => {
|
|
19692
|
-
finishReserved(db, sourceId, sourceRowOf(project, sessionId,
|
|
19865
|
+
finishReserved(db, sourceId, sourceRowOf(project, sessionId, label2), chunks, buildUnits(text));
|
|
19693
19866
|
}).catch((err) => {
|
|
19694
19867
|
process.stderr.write("hooks: index write failed: " + message(err) + "\n");
|
|
19695
19868
|
});
|
|
19696
19869
|
}
|
|
19697
|
-
function sourceRowOf(project, sessionId,
|
|
19698
|
-
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label, createdAt: Date.now() };
|
|
19870
|
+
function sourceRowOf(project, sessionId, label2) {
|
|
19871
|
+
return { sessionId, worktree: project.worktree, agent: project.agent, kind: "content", label: label2, createdAt: Date.now() };
|
|
19699
19872
|
}
|
|
19700
19873
|
async function preCompact(ev, row5, project) {
|
|
19701
19874
|
const db = await openDb(project);
|
|
@@ -19784,9 +19957,9 @@ import { accessSync, constants as fsConstants, statSync as statSync3 } from "nod
|
|
|
19784
19957
|
import path from "node:path";
|
|
19785
19958
|
|
|
19786
19959
|
// src/core/sandbox/path-entries.ts
|
|
19787
|
-
function pathEntries(value, platform = process.platform,
|
|
19960
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
19788
19961
|
const win = platform === "win32";
|
|
19789
|
-
return value.split(
|
|
19962
|
+
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
19790
19963
|
}
|
|
19791
19964
|
|
|
19792
19965
|
// src/core/sandbox/runtimes.ts
|
|
@@ -20156,7 +20329,7 @@ function relevance(db, given, scope, ctx) {
|
|
|
20156
20329
|
mine.add(hit.sourceId);
|
|
20157
20330
|
}
|
|
20158
20331
|
if (again.size > 0) {
|
|
20159
|
-
const line = "Same as above: " + [...again].map(([
|
|
20332
|
+
const line = "Same as above: " + [...again].map(([label2, ords]) => label2 + " (chunk " + ords.join(",") + ")").join("; ");
|
|
20160
20333
|
lines.push(line);
|
|
20161
20334
|
used += bytes2(line) + 1;
|
|
20162
20335
|
}
|
|
@@ -20303,7 +20476,7 @@ function shown(chunks, heads) {
|
|
|
20303
20476
|
return c.text;
|
|
20304
20477
|
});
|
|
20305
20478
|
}
|
|
20306
|
-
function indexCombined(db, ctx,
|
|
20479
|
+
function indexCombined(db, ctx, label2, ran, deadline, budgetBytes) {
|
|
20307
20480
|
const chunks = chunkText(ran.map((r) => r.block).join(BLOCK_SEP), "text");
|
|
20308
20481
|
const display = shown(chunks, ran.map((r) => r.head));
|
|
20309
20482
|
const bodies = /* @__PURE__ */ new Map();
|
|
@@ -20323,7 +20496,7 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20323
20496
|
worktree: ctx.project.worktree,
|
|
20324
20497
|
agent: ctx.project.agent,
|
|
20325
20498
|
kind: "content",
|
|
20326
|
-
label,
|
|
20499
|
+
label: label2,
|
|
20327
20500
|
bytes: groupBytes,
|
|
20328
20501
|
chunkCount: group.length,
|
|
20329
20502
|
createdAt: Date.now()
|
|
@@ -20353,12 +20526,12 @@ function indexCombined(db, ctx, label, ran, deadline, budgetBytes) {
|
|
|
20353
20526
|
function bytes3(s) {
|
|
20354
20527
|
return Buffer.byteLength(s, "utf8");
|
|
20355
20528
|
}
|
|
20356
|
-
function answer(db, ctx,
|
|
20529
|
+
function answer(db, ctx, label2, queries, share, own4) {
|
|
20357
20530
|
const seen = /* @__PURE__ */ new Set();
|
|
20358
20531
|
const lines = [];
|
|
20359
20532
|
for (const [qi, q] of queries.entries()) {
|
|
20360
20533
|
if (ctx.signal.aborted) break;
|
|
20361
|
-
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0,
|
|
20534
|
+
let hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0, label2);
|
|
20362
20535
|
if (hits.length === 0) hits = ftsQuery(db, q, "session", ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, 0);
|
|
20363
20536
|
const head = "## " + (bytes3(q) > ECHO_MAX_BYTES ? "query " + (qi + 1) : q);
|
|
20364
20537
|
let used = bytes3(head) + 1;
|
|
@@ -20397,17 +20570,17 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20397
20570
|
const ran = pool.results;
|
|
20398
20571
|
const last2 = ran[ran.length - 1];
|
|
20399
20572
|
const sandboxBytes = ran.reduce((n, r) => n + r.bytes, 0);
|
|
20400
|
-
const
|
|
20573
|
+
const label2 = LABEL_PREFIX + ctx.turn;
|
|
20401
20574
|
try {
|
|
20402
20575
|
const db = await openDb(ctx.project);
|
|
20403
20576
|
let sections;
|
|
20404
20577
|
let idx;
|
|
20405
20578
|
const exitLine = last2.exitCode === null || last2.exitCode === 0 ? null : "exit " + last2.exitCode;
|
|
20406
|
-
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(
|
|
20579
|
+
const footer = "more: ctx_search({queries:[...], source:" + JSON.stringify(label2) + "})";
|
|
20407
20580
|
let notice;
|
|
20408
20581
|
let showMore;
|
|
20409
20582
|
try {
|
|
20410
|
-
idx = indexCombined(db, ctx,
|
|
20583
|
+
idx = indexCombined(db, ctx, label2, ran, deadline, budgetBytes);
|
|
20411
20584
|
const stop = last2.error;
|
|
20412
20585
|
const cut = idx.indexed < idx.total ? "Indexed " + idx.indexed + " of " + idx.total + " B." : null;
|
|
20413
20586
|
const timeout = formatError2("TIMEOUT", { ms: boundMs });
|
|
@@ -20415,7 +20588,7 @@ async function runBatch(input, ctx, boundMs, budgetBytes) {
|
|
|
20415
20588
|
notice = cut === null ? stop : cause === null ? cut : cause + " " + cut;
|
|
20416
20589
|
const fixed = (exitLine === null ? 0 : bytes3(exitLine) + 1) + (notice === null ? 0 : bytes3(notice) + 1) + bytes3(footer);
|
|
20417
20590
|
const share = Math.floor((OUTPUT_CAP - fixed) / queries.length);
|
|
20418
|
-
const answered = answer(db, ctx,
|
|
20591
|
+
const answered = answer(db, ctx, label2, queries, share, idx.bodies);
|
|
20419
20592
|
sections = answered.lines;
|
|
20420
20593
|
const unseen = [...idx.bodies].filter(([k, text]) => text !== "" && !answered.seen.has(k)).map(([k]) => idx.raw.get(k));
|
|
20421
20594
|
const unseenBytes = unseen.reduce((n, t) => n + bytes3(t) + 1, 0);
|
|
@@ -20451,8 +20624,8 @@ var ctxBatch = Object.freeze({
|
|
|
20451
20624
|
});
|
|
20452
20625
|
|
|
20453
20626
|
// src/core/tools/doctor.ts
|
|
20454
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
20455
|
-
import { basename as basename4, dirname as dirname7, join as
|
|
20627
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync13, existsSync as existsSync13 } from "node:fs";
|
|
20628
|
+
import { basename as basename4, dirname as dirname7, join as join15 } from "node:path";
|
|
20456
20629
|
|
|
20457
20630
|
// src/core/ops/doctor-config.ts
|
|
20458
20631
|
import { existsSync as existsSync6, readdirSync as readdirSync3 } from "node:fs";
|
|
@@ -21622,7 +21795,7 @@ var Tokenizer = class {
|
|
|
21622
21795
|
hasUnderscore
|
|
21623
21796
|
};
|
|
21624
21797
|
}
|
|
21625
|
-
parseUnicode(
|
|
21798
|
+
parseUnicode(count2) {
|
|
21626
21799
|
const startLoc = this.codePointIterator.start;
|
|
21627
21800
|
const start = this.codePointIterator.end;
|
|
21628
21801
|
let charCount = 0;
|
|
@@ -21633,7 +21806,7 @@ var Tokenizer = class {
|
|
|
21633
21806
|
return this.reportParseError("invalid-char-in-escape-sequence");
|
|
21634
21807
|
}
|
|
21635
21808
|
charCount++;
|
|
21636
|
-
if (charCount >=
|
|
21809
|
+
if (charCount >= count2) break;
|
|
21637
21810
|
}
|
|
21638
21811
|
const end = this.codePointIterator.end;
|
|
21639
21812
|
const code = this.text.slice(start, end);
|
|
@@ -22399,17 +22572,17 @@ function generateConvertTOMLValue(convertValue) {
|
|
|
22399
22572
|
return baseTable;
|
|
22400
22573
|
},
|
|
22401
22574
|
TOMLTable(node3, baseTable = {}) {
|
|
22402
|
-
const
|
|
22403
|
-
for (const body of node3.body) resolveValue(body,
|
|
22575
|
+
const table3 = getTable(baseTable, resolveValue(node3.key), node3.kind === "array");
|
|
22576
|
+
for (const body of node3.body) resolveValue(body, table3);
|
|
22404
22577
|
return baseTable;
|
|
22405
22578
|
},
|
|
22406
22579
|
TOMLArray(node3) {
|
|
22407
22580
|
return node3.elements.map((e) => resolveValue(e));
|
|
22408
22581
|
},
|
|
22409
22582
|
TOMLInlineTable(node3) {
|
|
22410
|
-
const
|
|
22411
|
-
for (const body of node3.body) resolveValue(body,
|
|
22412
|
-
return
|
|
22583
|
+
const table3 = {};
|
|
22584
|
+
for (const body of node3.body) resolveValue(body, table3);
|
|
22585
|
+
return table3;
|
|
22413
22586
|
},
|
|
22414
22587
|
TOMLKey(node3) {
|
|
22415
22588
|
return node3.keys.map((key) => resolveValue(key));
|
|
@@ -22904,8 +23077,8 @@ function setTomlText(text, path7, value) {
|
|
|
22904
23077
|
if (sameValue(cur, value)) return text;
|
|
22905
23078
|
const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
|
|
22906
23079
|
if (inline !== void 0) {
|
|
22907
|
-
const
|
|
22908
|
-
return replaceToml(text, doc, inline.full,
|
|
23080
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
|
|
23081
|
+
return replaceToml(text, doc, inline.full, whole2);
|
|
22909
23082
|
}
|
|
22910
23083
|
if (isPlainObject3(cur) && isPlainObject3(value)) {
|
|
22911
23084
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
@@ -23149,10 +23322,10 @@ function scanCodex(agentHome, out) {
|
|
|
23149
23322
|
}
|
|
23150
23323
|
const tomlFile = join9(agentHome, CONFIG_TOML_FILE);
|
|
23151
23324
|
const config4 = readTomlValue(tomlFile);
|
|
23152
|
-
for (const
|
|
23153
|
-
if (
|
|
23154
|
-
if (
|
|
23155
|
-
out.push(finding(tomlFile,
|
|
23325
|
+
for (const span2 of readTomlTables(tomlFile)) {
|
|
23326
|
+
if (span2.path[0] !== V1_TOML_SECTION_ROOT || span2.path[1] !== SERVER_KEY) continue;
|
|
23327
|
+
if (span2.path.length === 2 && isV2McpTable(hostConfigValueAt(config4, span2.path))) continue;
|
|
23328
|
+
out.push(finding(tomlFile, span2.header.trim(), V1_REASON.codexToml));
|
|
23156
23329
|
}
|
|
23157
23330
|
dataDir(join9(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
23158
23331
|
}
|
|
@@ -23584,14 +23757,18 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
23584
23757
|
return true;
|
|
23585
23758
|
}
|
|
23586
23759
|
}
|
|
23760
|
+
function hookFile(row5, spec, home, env, worktree) {
|
|
23761
|
+
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
23762
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23763
|
+
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);
|
|
23764
|
+
return file2;
|
|
23765
|
+
}
|
|
23587
23766
|
function hookParts(row5, home, env, worktree) {
|
|
23588
23767
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
23589
23768
|
if (spec === null) return [];
|
|
23590
23769
|
let block;
|
|
23591
23770
|
try {
|
|
23592
|
-
const
|
|
23593
|
-
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23594
|
-
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);
|
|
23771
|
+
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
23595
23772
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
23596
23773
|
if (row5.id === "codex") {
|
|
23597
23774
|
const config4 = readParsed(row5.id, join11(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -23632,12 +23809,15 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
23632
23809
|
const read3 = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
23633
23810
|
if (parts.length === 0) return read3 === null ? pass("D3") : { ...pass("D3"), detail: read3 };
|
|
23634
23811
|
const detail = D3_DETAIL(parts);
|
|
23635
|
-
|
|
23812
|
+
const fix = parts.includes(PART_MCP) && parts.includes(PART_HOOKS) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
23813
|
+
return fail2("D3", read3 === null ? detail : detail + D4_REASON_JOIN + read3, fix);
|
|
23636
23814
|
}
|
|
23637
23815
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
23638
23816
|
const findings = detectV1(agent, home, scope);
|
|
23639
23817
|
if (findings.length === 0) return pass("D4");
|
|
23640
|
-
|
|
23818
|
+
const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
|
|
23819
|
+
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass("D4"), detail };
|
|
23820
|
+
return fail2("D4", detail, DOCTOR_FIX_UPGRADE);
|
|
23641
23821
|
}
|
|
23642
23822
|
function parsedOrNull(agent, file2, jsonc) {
|
|
23643
23823
|
try {
|
|
@@ -23656,6 +23836,31 @@ function checkDoubleFire(agent, worktree) {
|
|
|
23656
23836
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
23657
23837
|
return hooksOn && useClaudeHooks ? fail2("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
23658
23838
|
}
|
|
23839
|
+
function configPaths(row5, env, worktree) {
|
|
23840
|
+
const home = homeDirOf(env);
|
|
23841
|
+
if (home === null) return [];
|
|
23842
|
+
const out = [];
|
|
23843
|
+
const mcp = mcpFile(row5, home, env);
|
|
23844
|
+
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
23845
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
23846
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join11(native, CODEX_PLUGIN_MCP_FILE) });
|
|
23847
|
+
const spec = HOOK_HOST_FILE[row5.id];
|
|
23848
|
+
if (spec !== null) {
|
|
23849
|
+
try {
|
|
23850
|
+
out.push({ label: "hook entries", path: hookFile(row5, spec, home, env, worktree) });
|
|
23851
|
+
} catch (err) {
|
|
23852
|
+
out.push({ label: "hook entries", path: err instanceof Error ? err.message : String(err) });
|
|
23853
|
+
}
|
|
23854
|
+
}
|
|
23855
|
+
if (spec !== null && spec.root === "plugin" || row5.installMode === "marketplace" || row5.installMode === "plugin") {
|
|
23856
|
+
try {
|
|
23857
|
+
out.push({ label: "plugin root", path: resolvePluginRoot(row5, env, worktree) });
|
|
23858
|
+
} catch (err) {
|
|
23859
|
+
out.push({ label: "plugin root", path: err instanceof Error ? err.message : String(err) });
|
|
23860
|
+
}
|
|
23861
|
+
}
|
|
23862
|
+
return out.filter((e, i) => out.findIndex((o) => o.path === e.path) === i);
|
|
23863
|
+
}
|
|
23659
23864
|
|
|
23660
23865
|
// src/core/ops/doctor-db.ts
|
|
23661
23866
|
import { existsSync as existsSync7 } from "node:fs";
|
|
@@ -23741,29 +23946,92 @@ async function checkIndex(project) {
|
|
|
23741
23946
|
}
|
|
23742
23947
|
|
|
23743
23948
|
// src/core/ops/doctor-env.ts
|
|
23744
|
-
import { existsSync as existsSync8, realpathSync as realpathSync5 } from "node:fs";
|
|
23745
|
-
import { isAbsolute as isAbsolute3, relative as relative2 } from "node:path";
|
|
23949
|
+
import { existsSync as existsSync8, readFileSync as readFileSync9, realpathSync as realpathSync5 } from "node:fs";
|
|
23950
|
+
import { isAbsolute as isAbsolute3, join as join12, relative as relative2 } from "node:path";
|
|
23746
23951
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
23747
23952
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
23748
23953
|
}
|
|
23749
|
-
function unknown3(id, detail) {
|
|
23750
|
-
return { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail };
|
|
23954
|
+
function unknown3(id, detail, fixCommand) {
|
|
23955
|
+
return fixCommand === void 0 ? { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail } : { id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail, fixCommand };
|
|
23751
23956
|
}
|
|
23752
23957
|
function fail4(id, detail, fixCommand) {
|
|
23753
23958
|
return { id, label: DOCTOR_LABEL[id], status: "FAIL", detail, fixCommand };
|
|
23754
23959
|
}
|
|
23960
|
+
function bundleVersion(bundleDir2) {
|
|
23961
|
+
try {
|
|
23962
|
+
const v = JSON.parse(readFileSync9(join12(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
23963
|
+
return typeof v === "string" && v !== "" ? v : void 0;
|
|
23964
|
+
} catch {
|
|
23965
|
+
return void 0;
|
|
23966
|
+
}
|
|
23967
|
+
}
|
|
23968
|
+
function channelOf(version4) {
|
|
23969
|
+
const at2 = version4.indexOf(D1_PRERELEASE_SEP);
|
|
23970
|
+
if (at2 < 0) return D1_DEFAULT_TAG;
|
|
23971
|
+
const pre = version4.slice(at2 + 1);
|
|
23972
|
+
const dot = pre.indexOf(".");
|
|
23973
|
+
const tag2 = dot < 0 ? pre : pre.slice(0, dot);
|
|
23974
|
+
return tag2 === "" ? D1_DEFAULT_TAG : tag2;
|
|
23975
|
+
}
|
|
23976
|
+
function firstLine3(b) {
|
|
23977
|
+
const text = b.toString("utf8").trim();
|
|
23978
|
+
const nl = text.indexOf("\n");
|
|
23979
|
+
return (nl < 0 ? text : text.slice(0, nl)).trim();
|
|
23980
|
+
}
|
|
23981
|
+
function gitCause(r, timeoutMs) {
|
|
23982
|
+
if (r.killed === "timeout") return D1_GIT_TIMEOUT(timeoutMs);
|
|
23983
|
+
if (r.killed === "cancel") return D1_GIT_CANCEL;
|
|
23984
|
+
if (r.exitCode === null) return D1_GIT_NO_START;
|
|
23985
|
+
return D1_GIT_EXIT(r.exitCode, firstLine3(r.stderr));
|
|
23986
|
+
}
|
|
23987
|
+
function fetchCause(err, timeoutMs) {
|
|
23988
|
+
const name = err instanceof Error ? err.name : "";
|
|
23989
|
+
if (name === "TimeoutError") return D1_NPM_TIMEOUT(timeoutMs);
|
|
23990
|
+
const cause = err instanceof Error && err.cause instanceof Error ? err.cause : err;
|
|
23991
|
+
const code = typeof cause === "object" && cause !== null && "code" in cause && typeof cause.code === "string" ? cause.code : "";
|
|
23992
|
+
const msg = cause instanceof Error ? cause.message : String(cause);
|
|
23993
|
+
return D1_NPM_ERROR(code !== "" && !msg.includes(code) ? `${code} ${msg}` : msg);
|
|
23994
|
+
}
|
|
23995
|
+
async function npmLatest(url4, tag2, signal, timeoutMs) {
|
|
23996
|
+
try {
|
|
23997
|
+
const res = await fetch(url4, { signal: AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]) });
|
|
23998
|
+
if (!res.ok) return { ok: false, cause: D1_NPM_HTTP(res.status) };
|
|
23999
|
+
const body = await res.json();
|
|
24000
|
+
const v = typeof body === "object" && body !== null ? body[tag2] : void 0;
|
|
24001
|
+
return typeof v === "string" && v !== "" ? { ok: true, version: v } : { ok: false, cause: D1_NPM_NO_TAG(tag2) };
|
|
24002
|
+
} catch (err) {
|
|
24003
|
+
return { ok: false, cause: fetchCause(err, timeoutMs) };
|
|
24004
|
+
}
|
|
24005
|
+
}
|
|
23755
24006
|
async function checkVersion(i) {
|
|
23756
24007
|
if (i.bundleSha === void 0) return unknown3("D1", D1_DEV_BUILD_DETAIL);
|
|
23757
|
-
const
|
|
23758
|
-
|
|
23759
|
-
|
|
23760
|
-
|
|
23761
|
-
|
|
23762
|
-
|
|
23763
|
-
|
|
23764
|
-
|
|
23765
|
-
|
|
23766
|
-
|
|
24008
|
+
const head = D1_PREFIX(i.version, i.bundleSha) + ": ";
|
|
24009
|
+
const git3 = findRuntime(GIT_BIN, i.env);
|
|
24010
|
+
let cause = D1_GIT_MISSING;
|
|
24011
|
+
if (git3 !== null) {
|
|
24012
|
+
const r = await runProcess([git3, GIT_LS_REMOTE, RELEASE_REPO_URL, RELEASE_BRANCH], {
|
|
24013
|
+
cwd: i.cwd,
|
|
24014
|
+
env: { ...i.env, ...GIT_NO_PROMPT_ENV },
|
|
24015
|
+
signal: i.signal,
|
|
24016
|
+
timeoutMs: i.timeoutMs
|
|
24017
|
+
});
|
|
24018
|
+
if (r.exitCode === 0 && r.killed === null) {
|
|
24019
|
+
const latest = r.stdout.toString("utf8").split(LS_REMOTE_FIELD_SEP)[0];
|
|
24020
|
+
if (latest.length === GIT_SHA_HEX_LEN) {
|
|
24021
|
+
return latest === i.bundleSha ? pass3("D1", head + D1_GIT_PASS) : fail4("D1", head + D1_UPDATE_DETAIL, DOCTOR_FIX_UPGRADE);
|
|
24022
|
+
}
|
|
24023
|
+
cause = D1_GIT_NO_SHA;
|
|
24024
|
+
} else {
|
|
24025
|
+
cause = gitCause(r, i.timeoutMs);
|
|
24026
|
+
}
|
|
24027
|
+
}
|
|
24028
|
+
const handFix = git3 === null ? D1_NPM_CHECK_FIX : D1_GIT_CHECK_FIX;
|
|
24029
|
+
if (i.version === void 0) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + cause, handFix);
|
|
24030
|
+
const tag2 = channelOf(i.version);
|
|
24031
|
+
const npm = await npmLatest(i.registryUrl, tag2, i.signal, i.timeoutMs);
|
|
24032
|
+
if (!npm.ok) return unknown3("D1", head + D1_LATEST_UNKNOWN + ", " + cause + D1_CAUSE_JOIN + npm.cause, handFix);
|
|
24033
|
+
if (npm.version === i.version) return pass3("D1", head + D1_NPM_PASS(tag2) + D1_CAUSE_JOIN + cause);
|
|
24034
|
+
return fail4("D1", head + D1_NPM_UPDATE(tag2, npm.version) + D1_CAUSE_JOIN + cause, DOCTOR_FIX_UPGRADE);
|
|
23767
24035
|
}
|
|
23768
24036
|
function numbers(v) {
|
|
23769
24037
|
const bare2 = v.startsWith(NODE_VERSION_PREFIX) ? v.slice(NODE_VERSION_PREFIX.length) : v;
|
|
@@ -23820,7 +24088,7 @@ function checkShell(env) {
|
|
|
23820
24088
|
}
|
|
23821
24089
|
|
|
23822
24090
|
// src/core/ops/doctor-hook.ts
|
|
23823
|
-
import { existsSync as existsSync10, readFileSync as
|
|
24091
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10, realpathSync as realpathSync7 } from "node:fs";
|
|
23824
24092
|
import path6 from "node:path";
|
|
23825
24093
|
|
|
23826
24094
|
// src/setup/codex-trust.ts
|
|
@@ -24042,16 +24310,19 @@ function isObject5(v) {
|
|
|
24042
24310
|
}
|
|
24043
24311
|
function loadFixture(bundleDir2, agent) {
|
|
24044
24312
|
const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
24045
|
-
if (!existsSync10(file2)) return
|
|
24313
|
+
if (!existsSync10(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
24046
24314
|
let all;
|
|
24047
24315
|
try {
|
|
24048
|
-
all = JSON.parse(hostText(
|
|
24049
|
-
} catch {
|
|
24050
|
-
return
|
|
24316
|
+
all = JSON.parse(hostText(readFileSync10(file2, "utf8")));
|
|
24317
|
+
} catch (err) {
|
|
24318
|
+
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
24051
24319
|
}
|
|
24052
|
-
if (!isObject5(all)
|
|
24320
|
+
if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
|
|
24321
|
+
if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
|
|
24053
24322
|
const e = all[agent];
|
|
24054
|
-
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload"))
|
|
24323
|
+
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
|
|
24324
|
+
return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
|
|
24325
|
+
}
|
|
24055
24326
|
return { event: e.event, payload: e.payload };
|
|
24056
24327
|
}
|
|
24057
24328
|
function payloadFor(payload, worktree) {
|
|
@@ -24105,7 +24376,7 @@ async function checkHookRoundTrip(i) {
|
|
|
24105
24376
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
24106
24377
|
}
|
|
24107
24378
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
24108
|
-
if (
|
|
24379
|
+
if ("cause" in fixture) return row("UNKNOWN", fixture.cause);
|
|
24109
24380
|
const now = i.now ?? (() => performance.now());
|
|
24110
24381
|
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
24111
24382
|
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
@@ -24141,13 +24412,13 @@ async function checkHookRoundTrip(i) {
|
|
|
24141
24412
|
import { existsSync as existsSync11, rmSync as rmSync3 } from "node:fs";
|
|
24142
24413
|
|
|
24143
24414
|
// src/core/store/owners.ts
|
|
24144
|
-
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as
|
|
24145
|
-
import { basename as basename3, join as
|
|
24415
|
+
import { mkdirSync as mkdirSync4, readdirSync as readdirSync4, readFileSync as readFileSync11, rmSync as rmSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
24416
|
+
import { basename as basename3, join as join13 } from "node:path";
|
|
24146
24417
|
function ownersDir(configDir, projectKey) {
|
|
24147
|
-
return
|
|
24418
|
+
return join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24148
24419
|
}
|
|
24149
24420
|
function ownerFile(configDir, projectKey, serverId) {
|
|
24150
|
-
return
|
|
24421
|
+
return join13(ownersDir(configDir, projectKey), serverId + OWNER_PID_EXT);
|
|
24151
24422
|
}
|
|
24152
24423
|
function errCode2(err) {
|
|
24153
24424
|
return err.code;
|
|
@@ -24182,10 +24453,10 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
24182
24453
|
const live = [];
|
|
24183
24454
|
for (const name of names) {
|
|
24184
24455
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24185
|
-
const file2 =
|
|
24456
|
+
const file2 = join13(dir, name);
|
|
24186
24457
|
let text;
|
|
24187
24458
|
try {
|
|
24188
|
-
text =
|
|
24459
|
+
text = readFileSync11(file2, "utf8");
|
|
24189
24460
|
} catch (err) {
|
|
24190
24461
|
if (errCode2(err) === "ENOENT") continue;
|
|
24191
24462
|
throw err;
|
|
@@ -24267,8 +24538,13 @@ function envLine(key, value) {
|
|
|
24267
24538
|
const typedValue = allowed !== void 0 && allowed.includes(value) ? value : REPORT_INVALID;
|
|
24268
24539
|
return REPORT_ENV_PREFIX + typedKey + ": " + typedValue;
|
|
24269
24540
|
}
|
|
24541
|
+
function fixCell(agent, row5) {
|
|
24542
|
+
if (row5.status === "PASS") return "";
|
|
24543
|
+
if (row5.status === "FAIL") return DOCTOR_FAIL_LINE(agent, row5.id, row5.detail, row5.fixCommand ?? "");
|
|
24544
|
+
return row5.fixCommand === void 0 ? "" : "Fix: " + row5.fixCommand;
|
|
24545
|
+
}
|
|
24270
24546
|
function rowLine(agent, row5) {
|
|
24271
|
-
const fix =
|
|
24547
|
+
const fix = fixCell(agent, row5);
|
|
24272
24548
|
return "| " + [row5.id + " " + row5.label, row5.status, row5.detail, fix].join(" | ") + " |";
|
|
24273
24549
|
}
|
|
24274
24550
|
function buildReport(input) {
|
|
@@ -24298,6 +24574,196 @@ function buildReportHead(input) {
|
|
|
24298
24574
|
return lines.concat(tail).join("\n");
|
|
24299
24575
|
}
|
|
24300
24576
|
|
|
24577
|
+
// src/core/ops/doctor-issue.ts
|
|
24578
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
24579
|
+
import { closeSync, existsSync as existsSync12, fstatSync, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync12, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
24580
|
+
import { delimiter, join as join14 } from "node:path";
|
|
24581
|
+
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
24582
|
+
function tildeOf(env) {
|
|
24583
|
+
const home = homeDirOf(env);
|
|
24584
|
+
if (home === null || home === "") return (t) => t;
|
|
24585
|
+
const homes = [home];
|
|
24586
|
+
try {
|
|
24587
|
+
const real2 = realpathSync8.native(home);
|
|
24588
|
+
if (real2 !== home) homes.push(real2);
|
|
24589
|
+
} catch {
|
|
24590
|
+
}
|
|
24591
|
+
homes.sort((a, b) => b.length - a.length);
|
|
24592
|
+
const slash = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
|
|
24593
|
+
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash(piece)).join("~"), t);
|
|
24594
|
+
}
|
|
24595
|
+
function maskLine(line) {
|
|
24596
|
+
const lower = line.toLowerCase();
|
|
24597
|
+
const named = DOCTOR_SECRET_WORDS.some((w) => lower.includes(w));
|
|
24598
|
+
const token = TOKEN_PREFIXES.some((p) => line.includes(p));
|
|
24599
|
+
if (!named && !token) return line;
|
|
24600
|
+
const at2 = Math.max(line.indexOf(":"), line.indexOf("="));
|
|
24601
|
+
return at2 === -1 ? DOCTOR_MASK : line.slice(0, at2 + 1) + " " + DOCTOR_MASK;
|
|
24602
|
+
}
|
|
24603
|
+
function environmentLine(ctx, adapter, env, version4) {
|
|
24604
|
+
const sha = BUNDLE_SHA === void 0 ? "dev build" : BUNDLE_SHA.slice(0, 7);
|
|
24605
|
+
const client = ctx.clientInfo;
|
|
24606
|
+
const agent = client === void 0 ? adapter.id : client.name === adapter.id ? `${adapter.id} ${client.version}` : `${adapter.id} ${client.version} (client ${client.name})`;
|
|
24607
|
+
const shell = env.SHELL ?? env.ComSpec ?? "sh";
|
|
24608
|
+
return `${DOCTOR_ENV_PREFIX}context-mode ${version4 ?? "source checkout"} (${sha}), agent ${agent}
|
|
24609
|
+
${DOCTOR_ENV_PREFIX}${process.platform}-${process.arch}, Node ${process.version}, shell ${shell}`;
|
|
24610
|
+
}
|
|
24611
|
+
function gitVersion(env) {
|
|
24612
|
+
const r = spawnSync3("git", ["--version"], { env, encoding: "utf8", timeout: DOCTOR_GIT_VERSION_TIMEOUT_MS, windowsHide: true });
|
|
24613
|
+
if (r.status === 0) return `${r.stdout}`.trim();
|
|
24614
|
+
return `git --version: ${r.error ? r.error.message : `exit ${r.status}`}`;
|
|
24615
|
+
}
|
|
24616
|
+
function onPath(env, tool) {
|
|
24617
|
+
const names = process.platform === "win32" ? [tool + EXE_SUFFIX, tool + ".cmd", tool] : [tool];
|
|
24618
|
+
const out = [];
|
|
24619
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
24620
|
+
if (dir === "") continue;
|
|
24621
|
+
for (const n of names) if (existsSync12(join14(dir, n))) {
|
|
24622
|
+
out.push(join14(dir, n));
|
|
24623
|
+
break;
|
|
24624
|
+
}
|
|
24625
|
+
}
|
|
24626
|
+
return out;
|
|
24627
|
+
}
|
|
24628
|
+
function hookLogTail(env) {
|
|
24629
|
+
const file2 = hookLogPath(env);
|
|
24630
|
+
if (file2 === "" || !existsSync12(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
24631
|
+
try {
|
|
24632
|
+
const fd = openSync(file2, "r");
|
|
24633
|
+
try {
|
|
24634
|
+
const size = fstatSync(fd).size;
|
|
24635
|
+
const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
|
|
24636
|
+
const buf = Buffer.alloc(size - start);
|
|
24637
|
+
readSync(fd, buf, 0, buf.length, start);
|
|
24638
|
+
const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
|
|
24639
|
+
if (start > 0) lines.shift();
|
|
24640
|
+
return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
|
|
24641
|
+
} finally {
|
|
24642
|
+
closeSync(fd);
|
|
24643
|
+
}
|
|
24644
|
+
} catch (err) {
|
|
24645
|
+
return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
|
|
24646
|
+
}
|
|
24647
|
+
}
|
|
24648
|
+
async function journalRows(ctx) {
|
|
24649
|
+
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
24650
|
+
if (!existsSync12(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
24651
|
+
try {
|
|
24652
|
+
const db = await openDb(ctx.project, { readOnly: true });
|
|
24653
|
+
try {
|
|
24654
|
+
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();
|
|
24655
|
+
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
24656
|
+
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)} |`));
|
|
24657
|
+
} finally {
|
|
24658
|
+
closeDb(db);
|
|
24659
|
+
}
|
|
24660
|
+
} catch (err) {
|
|
24661
|
+
return [`journal read: ${err instanceof Error ? err.message : String(err)}`];
|
|
24662
|
+
}
|
|
24663
|
+
}
|
|
24664
|
+
function agentConfig(adapter, env, worktree) {
|
|
24665
|
+
const home = homeDirOf(env);
|
|
24666
|
+
const files = configPaths(adapter, env, worktree);
|
|
24667
|
+
if (home !== null) {
|
|
24668
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join14(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
24669
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join14(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
24670
|
+
}
|
|
24671
|
+
const out = [];
|
|
24672
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24673
|
+
for (const f of files) {
|
|
24674
|
+
if (seen.has(f.path)) continue;
|
|
24675
|
+
seen.add(f.path);
|
|
24676
|
+
if (!existsSync12(f.path)) {
|
|
24677
|
+
out.push(`${f.label}: ${f.path} (absent)`);
|
|
24678
|
+
continue;
|
|
24679
|
+
}
|
|
24680
|
+
let text = "";
|
|
24681
|
+
try {
|
|
24682
|
+
text = readFileSync12(f.path, "utf8");
|
|
24683
|
+
} catch (err) {
|
|
24684
|
+
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
24685
|
+
continue;
|
|
24686
|
+
}
|
|
24687
|
+
const hit = text.split("\n").filter((l) => l.includes("context-mode") || l.includes("hook.mjs") || adapter.id === "codex" && l.includes("trust"));
|
|
24688
|
+
out.push(`${f.label}: ${f.path} (${hit.length} matching lines)`);
|
|
24689
|
+
for (const l of hit.slice(0, DOCTOR_CONFIG_LINES)) out.push(" " + maskLine(l.trimEnd()));
|
|
24690
|
+
}
|
|
24691
|
+
return out;
|
|
24692
|
+
}
|
|
24693
|
+
function failing(rows) {
|
|
24694
|
+
return rows.filter((r) => r.status === "FAIL");
|
|
24695
|
+
}
|
|
24696
|
+
function issueTitle(agent, rows) {
|
|
24697
|
+
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
24698
|
+
}
|
|
24699
|
+
function summaryOf(agent, rows) {
|
|
24700
|
+
const f = failing(rows)[0];
|
|
24701
|
+
return f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`;
|
|
24702
|
+
}
|
|
24703
|
+
async function buildIssueBody(i) {
|
|
24704
|
+
const tilde = tildeOf(i.env);
|
|
24705
|
+
const agent = i.adapter.id;
|
|
24706
|
+
const install = NATIVE_INSTALL[agent] ?? [];
|
|
24707
|
+
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
24708
|
+
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
24709
|
+
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
24710
|
+
const sections = {
|
|
24711
|
+
"Summary": [summaryOf(agent, i.rows)],
|
|
24712
|
+
"ctx-report": [i.table],
|
|
24713
|
+
"What happened": [
|
|
24714
|
+
"Rows that need a look:",
|
|
24715
|
+
...failRows.map((r) => `- ${r.id} ${r.label} ${r.status}: ${r.detail}${r.fixCommand ? ` (Fix: ${r.fixCommand})` : ""}`),
|
|
24716
|
+
"Error code and text: <the agent fills this in: the exact error the user saw>"
|
|
24717
|
+
],
|
|
24718
|
+
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
24719
|
+
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
24720
|
+
"Agent config": agentConfig(i.adapter, i.env, i.ctx.project.worktree),
|
|
24721
|
+
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
24722
|
+
"Steps": [
|
|
24723
|
+
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
24724
|
+
"Prompt or command: <the agent fills this in: the exact prompt or command>",
|
|
24725
|
+
"Actual: <the agent fills this in: what context-mode did, with the byte count>",
|
|
24726
|
+
"Repro script (fresh HOME, native install for " + agent + "):",
|
|
24727
|
+
"```sh",
|
|
24728
|
+
'export HOME="$(mktemp -d)"',
|
|
24729
|
+
'cd "$HOME"',
|
|
24730
|
+
...install,
|
|
24731
|
+
"<the command or prompt above>",
|
|
24732
|
+
"```"
|
|
24733
|
+
],
|
|
24734
|
+
"Environment": [
|
|
24735
|
+
i.envLine,
|
|
24736
|
+
`context-mode bundle: ${i.bundleDir}`,
|
|
24737
|
+
`Install route: ${install.join(" && ")}`,
|
|
24738
|
+
`git: ${gitVersion(i.env)}`,
|
|
24739
|
+
...pathTools,
|
|
24740
|
+
...envNames,
|
|
24741
|
+
`Project: ${i.ctx.project.worktree} (key ${i.ctx.project.projectKey})`,
|
|
24742
|
+
"Filed by: <your agent name, version, model id>"
|
|
24743
|
+
]
|
|
24744
|
+
};
|
|
24745
|
+
const out = [];
|
|
24746
|
+
for (const h of ISSUE_FORM_HEADINGS) out.push(`### ${h}`, "", ...sections[h] ?? [], "");
|
|
24747
|
+
return tilde(out.join("\n"));
|
|
24748
|
+
}
|
|
24749
|
+
async function writeIssueReport(i) {
|
|
24750
|
+
const tilde = tildeOf(i.env);
|
|
24751
|
+
const body = await buildIssueBody(i);
|
|
24752
|
+
const dir = join14(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
24753
|
+
mkdirSync5(dir, { recursive: true });
|
|
24754
|
+
const file2 = join14(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
24755
|
+
writeFileSync3(file2, body);
|
|
24756
|
+
const shown2 = tilde(file2);
|
|
24757
|
+
const title = issueTitle(i.adapter.id, i.rows);
|
|
24758
|
+
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
24759
|
+
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))];
|
|
24760
|
+
}
|
|
24761
|
+
function formUrl(title, summary) {
|
|
24762
|
+
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
24763
|
+
const full = `${base}&summary=${encodeURIComponent(summary)}`;
|
|
24764
|
+
return full.length < ISSUE_URL_MAX ? full : base;
|
|
24765
|
+
}
|
|
24766
|
+
|
|
24301
24767
|
// src/core/tools/doctor.ts
|
|
24302
24768
|
var ctxDoctorSchema = external_exports.object({}).strict();
|
|
24303
24769
|
function lineOf2(err) {
|
|
@@ -24312,7 +24778,7 @@ async function guard(id, run) {
|
|
|
24312
24778
|
}
|
|
24313
24779
|
}
|
|
24314
24780
|
async function codexDb(ctx, adapter) {
|
|
24315
|
-
if (adapter.id !== "codex" || !
|
|
24781
|
+
if (adapter.id !== "codex" || !existsSync13(ctx.project.dbPath)) return null;
|
|
24316
24782
|
try {
|
|
24317
24783
|
return await openDb(ctx.project, { readOnly: true });
|
|
24318
24784
|
} catch {
|
|
@@ -24342,11 +24808,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
24342
24808
|
}
|
|
24343
24809
|
}
|
|
24344
24810
|
function ownServerId(configDir, projectKey) {
|
|
24345
|
-
const dir =
|
|
24346
|
-
if (!
|
|
24811
|
+
const dir = join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
24812
|
+
if (!existsSync13(dir)) return "";
|
|
24347
24813
|
for (const name of readdirSync5(dir)) {
|
|
24348
24814
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
24349
|
-
if (
|
|
24815
|
+
if (readFileSync13(join15(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
24350
24816
|
}
|
|
24351
24817
|
return "";
|
|
24352
24818
|
}
|
|
@@ -24356,7 +24822,7 @@ async function runDoctorChecks(ctx, adapter, host0) {
|
|
|
24356
24822
|
const project = ctx.project;
|
|
24357
24823
|
let integrityFailed = false;
|
|
24358
24824
|
const checks = {
|
|
24359
|
-
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
24825
|
+
D1: () => checkVersion({ bundleSha: BUNDLE_SHA, version: bundleVersion(host.bundleDir), registryUrl: D1_REGISTRY_URL, timeoutMs: DOCTOR_GIT_TIMEOUT_MS, env: buildChildEnv(env), cwd: project.worktree, signal: ctx.signal }),
|
|
24360
24826
|
D2: () => checkNode({ nodeVersion: process.version, bunVersion: process.versions.bun }),
|
|
24361
24827
|
D3: () => checkHostConfig(adapter, env, project.worktree),
|
|
24362
24828
|
D4: () => checkV1Leftovers(adapter.id, requireHomeDir(env), { project: project.worktree, piAgentDir: piAgentDirOf(env, requireHomeDir(env)), claudeDir: claudeDirOf(env, requireHomeDir(env)), codexDir: codexDirOf(env, requireHomeDir(env)), copilotDir: copilotDirOf(env, requireHomeDir(env)), kiroDir: kiroDirOf(env, requireHomeDir(env)), opencodeDir: opencodeDirOf(env, requireHomeDir(env)) }),
|
|
@@ -24391,23 +24857,38 @@ function reportEnv(env) {
|
|
|
24391
24857
|
}
|
|
24392
24858
|
return out;
|
|
24393
24859
|
}
|
|
24394
|
-
async function
|
|
24860
|
+
async function doctorReply(ctx, host) {
|
|
24395
24861
|
const adapter = getAdapter(ctx.project.agent);
|
|
24396
|
-
const host = { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 };
|
|
24397
24862
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
24398
|
-
const
|
|
24399
|
-
const
|
|
24400
|
-
const
|
|
24401
|
-
const
|
|
24402
|
-
|
|
24863
|
+
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
24864
|
+
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
24865
|
+
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
24866
|
+
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
24867
|
+
const table3 = buildReport(input);
|
|
24868
|
+
let notes = [];
|
|
24869
|
+
if (failed2) {
|
|
24870
|
+
try {
|
|
24871
|
+
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
24872
|
+
} catch (err) {
|
|
24873
|
+
notes = [`Report file: ${lineOf2(err)}`];
|
|
24874
|
+
}
|
|
24875
|
+
}
|
|
24876
|
+
const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
|
|
24877
|
+
const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
|
|
24878
|
+
const whole2 = [envLine2, table3, ...docs, ...notes].join("\n");
|
|
24879
|
+
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
24880
|
+
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
24403
24881
|
const db = await openDb(ctx.project);
|
|
24404
24882
|
try {
|
|
24405
|
-
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL,
|
|
24883
|
+
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
24406
24884
|
} finally {
|
|
24407
24885
|
closeDb(db);
|
|
24408
24886
|
}
|
|
24409
|
-
const text = buildReportHead(input);
|
|
24410
|
-
return { text, isError: false, sandboxBytes:
|
|
24887
|
+
const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
|
|
24888
|
+
return { text, isError: false, sandboxBytes: bytes5 };
|
|
24889
|
+
}
|
|
24890
|
+
async function handler2(_input, ctx) {
|
|
24891
|
+
return doctorReply(ctx, { env: process.env, bundleDir: dirname7(process.argv[1]), piCwd: void 0 });
|
|
24411
24892
|
}
|
|
24412
24893
|
var ctxDoctor = Object.freeze({
|
|
24413
24894
|
name: "ctx_doctor",
|
|
@@ -24419,9 +24900,9 @@ var ctxDoctor = Object.freeze({
|
|
|
24419
24900
|
});
|
|
24420
24901
|
|
|
24421
24902
|
// src/core/tools/execute.ts
|
|
24422
|
-
import { existsSync as
|
|
24903
|
+
import { existsSync as existsSync14, mkdtempSync, rmSync as rmSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
24423
24904
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
24424
|
-
import { dirname as dirname8, join as
|
|
24905
|
+
import { dirname as dirname8, join as join16, parse as parse3, resolve as resolve6 } from "node:path";
|
|
24425
24906
|
|
|
24426
24907
|
// src/core/sandbox/win-build.ts
|
|
24427
24908
|
var SEPARATORS2 = ";&|(\n";
|
|
@@ -24505,7 +24986,7 @@ function schemaLine(issue4) {
|
|
|
24505
24986
|
}
|
|
24506
24987
|
function fileError(given, abs, root) {
|
|
24507
24988
|
let dir = abs;
|
|
24508
|
-
while (!
|
|
24989
|
+
while (!existsSync14(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
24509
24990
|
if (isInside(root, dir)) return null;
|
|
24510
24991
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
24511
24992
|
}
|
|
@@ -24531,8 +25012,8 @@ function sourceLabel(code) {
|
|
|
24531
25012
|
const first = nl < 0 ? code : code.slice(0, nl);
|
|
24532
25013
|
return Array.from(TOOL2 + ":" + first).slice(0, SOURCE_LABEL_MAX_CHARS).join("");
|
|
24533
25014
|
}
|
|
24534
|
-
function moreReserve(intent,
|
|
24535
|
-
return Buffer.byteLength(moreLine2(intent,
|
|
25015
|
+
function moreReserve(intent, label2) {
|
|
25016
|
+
return Buffer.byteLength(moreLine2(intent, label2), "utf8");
|
|
24536
25017
|
}
|
|
24537
25018
|
function spawnFailed(argv0, cwd) {
|
|
24538
25019
|
return new CtxError("SPAWN_FAILED", { detail: argv0 + " gave no exit code in " + cwd }).toLine();
|
|
@@ -24549,12 +25030,12 @@ async function finish(input, ctx, r, exitCode, journal) {
|
|
|
24549
25030
|
if (intent === "" && fits) {
|
|
24550
25031
|
return { text: direct, isError, sandboxBytes: fullBytes, journal };
|
|
24551
25032
|
}
|
|
24552
|
-
const
|
|
24553
|
-
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent,
|
|
25033
|
+
const label2 = sourceLabel(input.code);
|
|
25034
|
+
const budget = (fits ? OUTPUT_CAP : EXEC_PREVIEW_BYTES) - Buffer.byteLength(head, "utf8") - 2 - moreReserve(intent, label2);
|
|
24554
25035
|
const db = await openDb(ctx.project);
|
|
24555
25036
|
let picked;
|
|
24556
25037
|
try {
|
|
24557
|
-
const { sourceId } = indexText(db, ctx.project, ctx.sessionId,
|
|
25038
|
+
const { sourceId } = indexText(db, ctx.project, ctx.sessionId, label2, combined, "text");
|
|
24558
25039
|
picked = selectChunks(db, sourceId, intent, budget);
|
|
24559
25040
|
} finally {
|
|
24560
25041
|
closeDb(db);
|
|
@@ -24586,9 +25067,9 @@ async function handler3(raw, ctx) {
|
|
|
24586
25067
|
if (takesDashC(input.language, runtime)) {
|
|
24587
25068
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
24588
25069
|
} else {
|
|
24589
|
-
tmpDir = mkdtempSync(
|
|
24590
|
-
const file2 =
|
|
24591
|
-
|
|
25070
|
+
tmpDir = mkdtempSync(join16(tmpdir2(), TMP_PREFIX));
|
|
25071
|
+
const file2 = join16(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
25072
|
+
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
24592
25073
|
argv = scriptArgv(input.language, runtime, file2);
|
|
24593
25074
|
}
|
|
24594
25075
|
if (input.background === true) {
|
|
@@ -24622,21 +25103,21 @@ var ctxExecute = {
|
|
|
24622
25103
|
};
|
|
24623
25104
|
|
|
24624
25105
|
// src/core/tools/index.ts
|
|
24625
|
-
import { existsSync as
|
|
24626
|
-
import { dirname as dirname9, extname, join as
|
|
25106
|
+
import { existsSync as existsSync15, readFileSync as readFileSync15, statSync as statSync7 } from "node:fs";
|
|
25107
|
+
import { dirname as dirname9, extname, join as join18, relative as relative3, resolve as resolve7 } from "node:path";
|
|
24627
25108
|
|
|
24628
25109
|
// src/core/index/walk.ts
|
|
24629
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
24630
|
-
import { join as
|
|
25110
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync14, realpathSync as realpathSync9, statSync as statSync6 } from "node:fs";
|
|
25111
|
+
import { join as join17 } from "node:path";
|
|
24631
25112
|
var GITIGNORE = ".gitignore";
|
|
24632
25113
|
var GIT_DIR = ".git";
|
|
24633
25114
|
function walkDir(root, containmentRoot) {
|
|
24634
|
-
const real2 =
|
|
25115
|
+
const real2 = realpathSync9(root);
|
|
24635
25116
|
if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
24636
25117
|
const found = [];
|
|
24637
25118
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
24638
25119
|
found.sort(compareFound);
|
|
24639
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
25120
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join17(...f.dir, f.name) }));
|
|
24640
25121
|
}
|
|
24641
25122
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
24642
25123
|
let entries;
|
|
@@ -24645,17 +25126,17 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24645
25126
|
} catch {
|
|
24646
25127
|
return;
|
|
24647
25128
|
}
|
|
24648
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
25129
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join17(abs, GITIGNORE), rel)) : parent;
|
|
24649
25130
|
for (const e of entries) {
|
|
24650
25131
|
if (e.name === GIT_DIR) continue;
|
|
24651
|
-
const path7 =
|
|
25132
|
+
const path7 = join17(abs, e.name);
|
|
24652
25133
|
let isDir = e.isDirectory();
|
|
24653
25134
|
let isFile = e.isFile();
|
|
24654
25135
|
let target = path7;
|
|
24655
25136
|
if (e.isSymbolicLink()) {
|
|
24656
25137
|
let resolved;
|
|
24657
25138
|
try {
|
|
24658
|
-
resolved =
|
|
25139
|
+
resolved = realpathSync9(path7);
|
|
24659
25140
|
} catch {
|
|
24660
25141
|
continue;
|
|
24661
25142
|
}
|
|
@@ -24670,7 +25151,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
24670
25151
|
if (isFile) {
|
|
24671
25152
|
found.push({ dir: rel, name: e.name, absPath: path7 });
|
|
24672
25153
|
} else if (isDir) {
|
|
24673
|
-
const key = e.isSymbolicLink() ? target :
|
|
25154
|
+
const key = e.isSymbolicLink() ? target : realpathSync9(path7);
|
|
24674
25155
|
if (seen.has(key)) continue;
|
|
24675
25156
|
seen.add(key);
|
|
24676
25157
|
visit(path7, segs, rules, contain, seen, found);
|
|
@@ -24688,7 +25169,7 @@ function compareFound(a, b) {
|
|
|
24688
25169
|
function readRules(file2, base) {
|
|
24689
25170
|
let body;
|
|
24690
25171
|
try {
|
|
24691
|
-
body =
|
|
25172
|
+
body = readFileSync14(file2, "utf8");
|
|
24692
25173
|
} catch {
|
|
24693
25174
|
return [];
|
|
24694
25175
|
}
|
|
@@ -24998,14 +25479,14 @@ function replaceCodePointXML(codePoint) {
|
|
|
24998
25479
|
|
|
24999
25480
|
// node_modules/entities/dist/internal/decode-shared.js
|
|
25000
25481
|
var BASE91_INVERSE = /* @__PURE__ */ (() => {
|
|
25001
|
-
const
|
|
25482
|
+
const table3 = new Uint8Array(127);
|
|
25002
25483
|
let code = 0;
|
|
25003
25484
|
for (let char = 33; char <= 126; char++) {
|
|
25004
25485
|
if (char !== 34 && char !== 36 && char !== 92) {
|
|
25005
|
-
|
|
25486
|
+
table3[char] = code++;
|
|
25006
25487
|
}
|
|
25007
25488
|
}
|
|
25008
|
-
return
|
|
25489
|
+
return table3;
|
|
25009
25490
|
})();
|
|
25010
25491
|
function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCount, dictSize) {
|
|
25011
25492
|
const base = 91;
|
|
@@ -25023,10 +25504,10 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
25023
25504
|
single.fill(-1, dictSize + dict2AtomCount, slotCount);
|
|
25024
25505
|
const start = new Int32Array(slotCount);
|
|
25025
25506
|
const length = new Int32Array(slotCount);
|
|
25026
|
-
function decodeDelta(
|
|
25507
|
+
function decodeDelta(count2, off) {
|
|
25027
25508
|
let previous = 0;
|
|
25028
25509
|
let slot = off;
|
|
25029
|
-
const end = off +
|
|
25510
|
+
const end = off + count2;
|
|
25030
25511
|
while (slot < end) {
|
|
25031
25512
|
const code = BASE91_INVERSE[input.charCodeAt(pos++)];
|
|
25032
25513
|
if (code < 89) {
|
|
@@ -25049,8 +25530,8 @@ function decodeTrieDict(input, resultLength, atomCount, dict1AtomCount, ngramCou
|
|
|
25049
25530
|
const references = new Int32Array(ngramCount * 2);
|
|
25050
25531
|
let poolSize = 0;
|
|
25051
25532
|
let ngramIndex = 0;
|
|
25052
|
-
function readNgramReferences(
|
|
25053
|
-
for (let index = 0; index <
|
|
25533
|
+
function readNgramReferences(count2, startSlot) {
|
|
25534
|
+
for (let index = 0; index < count2; index++) {
|
|
25054
25535
|
const slot = startSlot + index;
|
|
25055
25536
|
const a = readSlotCode();
|
|
25056
25537
|
const b = readSlotCode();
|
|
@@ -28758,8 +29239,8 @@ var EXT_KIND = Object.freeze({ ".md": "md", ".html": "html", ".htm": "html" });
|
|
|
28758
29239
|
var TYPE_KIND = Object.freeze({ "text/html": "html", "text/markdown": "md" });
|
|
28759
29240
|
var DEFAULT_CONTENT_LABEL = "content";
|
|
28760
29241
|
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
28761
|
-
function userLabel(
|
|
28762
|
-
return
|
|
29242
|
+
function userLabel(label2) {
|
|
29243
|
+
return label2 === DECISION_SOURCE ? DECISION_USER_LABEL : label2;
|
|
28763
29244
|
}
|
|
28764
29245
|
function kindOfPath(p) {
|
|
28765
29246
|
return EXT_KIND[extname(p).toLowerCase()] ?? "text";
|
|
@@ -28771,14 +29252,14 @@ function kindOfType(contentType) {
|
|
|
28771
29252
|
}
|
|
28772
29253
|
function readUtf8(absPath) {
|
|
28773
29254
|
try {
|
|
28774
|
-
return utf8.decode(
|
|
29255
|
+
return utf8.decode(readFileSync15(absPath));
|
|
28775
29256
|
} catch {
|
|
28776
29257
|
return void 0;
|
|
28777
29258
|
}
|
|
28778
29259
|
}
|
|
28779
29260
|
function missingOrOutside(given, abs, root) {
|
|
28780
29261
|
let dir = abs;
|
|
28781
|
-
while (!
|
|
29262
|
+
while (!existsSync15(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
28782
29263
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
28783
29264
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
28784
29265
|
}
|
|
@@ -28789,7 +29270,7 @@ function pathItems(input, project) {
|
|
|
28789
29270
|
if (statSync7(abs).isDirectory()) {
|
|
28790
29271
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
28791
29272
|
sourceKind: "path",
|
|
28792
|
-
label: pathLabel(
|
|
29273
|
+
label: pathLabel(join18(base, f.relPath)),
|
|
28793
29274
|
kind: kindOfPath(f.relPath),
|
|
28794
29275
|
read: () => readUtf8(f.absPath)
|
|
28795
29276
|
}));
|
|
@@ -28799,9 +29280,9 @@ function pathItems(input, project) {
|
|
|
28799
29280
|
async function itemsOf(input, ctx) {
|
|
28800
29281
|
if (input.content !== void 0) {
|
|
28801
29282
|
const text2 = input.content;
|
|
28802
|
-
const
|
|
29283
|
+
const label3 = input.source ?? DEFAULT_CONTENT_LABEL;
|
|
28803
29284
|
const kind = hasMdStructure(text2) ? "md" : "text";
|
|
28804
|
-
return { items: [{ sourceKind: "content", label:
|
|
29285
|
+
return { items: [{ sourceKind: "content", label: label3, kind, read: () => text2 }], from: label3 };
|
|
28805
29286
|
}
|
|
28806
29287
|
if (input.path !== void 0) {
|
|
28807
29288
|
const items = pathItems({ ...input, path: input.path }, ctx.project);
|
|
@@ -28809,8 +29290,8 @@ async function itemsOf(input, ctx) {
|
|
|
28809
29290
|
}
|
|
28810
29291
|
const res = await safeFetch(input.url ?? "", AbortSignal.any([ctx.signal, AbortSignal.timeout(EXEC_TIMEOUT_MS)]));
|
|
28811
29292
|
const text = res.body.toString("utf8");
|
|
28812
|
-
const
|
|
28813
|
-
return { items: [{ sourceKind: "url", label, kind: kindOfType(res.contentType), read: () => text, base:
|
|
29293
|
+
const label2 = res.finalUrl;
|
|
29294
|
+
return { items: [{ sourceKind: "url", label: label2, kind: kindOfType(res.contentType), read: () => text, base: label2 }], from: label2 };
|
|
28814
29295
|
}
|
|
28815
29296
|
async function handler4(input, ctx) {
|
|
28816
29297
|
const given = INPUT_FIELDS.filter((f) => input[f] !== void 0);
|
|
@@ -28822,14 +29303,14 @@ async function handler4(input, ctx) {
|
|
|
28822
29303
|
const db = await openDb(ctx.project);
|
|
28823
29304
|
let sources = 0;
|
|
28824
29305
|
let chunks = 0;
|
|
28825
|
-
let
|
|
29306
|
+
let bytes5 = 0;
|
|
28826
29307
|
let lastId = 0;
|
|
28827
29308
|
const notes = [];
|
|
28828
29309
|
try {
|
|
28829
29310
|
for (const it of items) {
|
|
28830
29311
|
const text = it.read();
|
|
28831
29312
|
if (text === void 0) continue;
|
|
28832
|
-
|
|
29313
|
+
bytes5 += Buffer.byteLength(text, "utf8");
|
|
28833
29314
|
if (it.kind === "html") {
|
|
28834
29315
|
let readable;
|
|
28835
29316
|
try {
|
|
@@ -28866,7 +29347,7 @@ async function handler4(input, ctx) {
|
|
|
28866
29347
|
return {
|
|
28867
29348
|
text: capBytes(line, OUTPUT_CAP).text,
|
|
28868
29349
|
isError: false,
|
|
28869
|
-
sandboxBytes:
|
|
29350
|
+
sandboxBytes: bytes5,
|
|
28870
29351
|
journal: { kind: "index", key: from, path: from, exit_code: null }
|
|
28871
29352
|
};
|
|
28872
29353
|
} catch (err) {
|
|
@@ -28906,8 +29387,8 @@ function purgeScope(db, scope, input) {
|
|
|
28906
29387
|
const raw = db.raw;
|
|
28907
29388
|
if (scope === "session") return changes(raw, "DELETE FROM events WHERE session_id = ?", input.session);
|
|
28908
29389
|
if (scope === "source") {
|
|
28909
|
-
const
|
|
28910
|
-
return deleteChunkRows(raw, { label }) + changes(raw, "DELETE FROM sources WHERE label = ?",
|
|
29390
|
+
const label2 = storedLabel(db, input.source);
|
|
29391
|
+
return deleteChunkRows(raw, { label: label2 }) + changes(raw, "DELETE FROM sources WHERE label = ?", label2);
|
|
28911
29392
|
}
|
|
28912
29393
|
const chunks = deleteChunkRows(raw, "all");
|
|
28913
29394
|
return changes(raw, "DELETE FROM events") + chunks + changes(raw, "DELETE FROM sources");
|
|
@@ -28989,14 +29470,83 @@ var ctxResume = Object.freeze({
|
|
|
28989
29470
|
var ctxStatsSchema = external_exports.object({}, {
|
|
28990
29471
|
error: (issue4) => issue4.code === "unrecognized_keys" ? STATS_UNKNOWN_FIELD_LINE : void 0
|
|
28991
29472
|
}).strict();
|
|
28992
|
-
var
|
|
29473
|
+
var CALLS = "tool IS NOT NULL AND kind <> 'cost' AND tool <> 'ctx_stats'";
|
|
29474
|
+
var GROUPS = `SELECT session_id, agent, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} GROUP BY session_id, agent ORDER BY agent, session_id`;
|
|
29475
|
+
var TOOLS = `SELECT tool, COUNT(*) AS calls, COALESCE(SUM(sandbox_bytes), 0) AS produced, COALESCE(SUM(returned_bytes), 0) AS returned FROM events WHERE ${CALLS} GROUP BY tool`;
|
|
29476
|
+
var KINDS = "SELECT kind, COALESCE(SUM(session_id = ?), 0) AS s, COUNT(*) AS p FROM events WHERE kind <> 'cost' AND (tool IS NULL OR tool <> 'ctx_stats') GROUP BY kind";
|
|
29477
|
+
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}`;
|
|
29478
|
+
var SPAN = "SELECT COALESCE(MAX(created_at) - MIN(created_at), 0) AS span FROM events WHERE session_id = ? AND kind <> 'cost'";
|
|
29479
|
+
var SOURCES = "SELECT COUNT(*) AS n, COALESCE(SUM(chunk_count), 0) AS chunks, COALESCE(SUM(bytes_total), 0) AS bytes FROM sources";
|
|
29480
|
+
var HOST = "tool NOT LIKE 'ctx\\_%' ESCAPE '\\'";
|
|
29481
|
+
var REPLACED = `SELECT COUNT(*) AS n FROM events WHERE ${CALLS} AND ${HOST} AND returned_bytes < sandbox_bytes`;
|
|
29482
|
+
var RUNS = "FROM sources WHERE substr(label, 1, ?) = ?";
|
|
29483
|
+
var REDIRECTED = `SELECT COUNT(*) AS n, COALESCE(MAX(created_ts), 0) AS last ${RUNS}`;
|
|
29484
|
+
var LAST = `SELECT COALESCE(MAX(created_at), 0) AS last FROM events WHERE ${CALLS}`;
|
|
29485
|
+
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`;
|
|
29486
|
+
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`;
|
|
29487
|
+
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}`;
|
|
29488
|
+
function wayOf(tool) {
|
|
29489
|
+
if (STATS_INDEX_TOOLS.includes(tool)) return "index";
|
|
29490
|
+
return tool.startsWith("ctx_") ? "sandbox" : "replace";
|
|
29491
|
+
}
|
|
29492
|
+
function readWeek(raw, lastMs) {
|
|
29493
|
+
const last2 = Math.floor(lastMs / MS_PER_DAY);
|
|
29494
|
+
const first = last2 - STATS_DAYS + 1;
|
|
29495
|
+
const days = Array.from({ length: STATS_DAYS }, (_, i) => ({
|
|
29496
|
+
day: first + i,
|
|
29497
|
+
calls: 0,
|
|
29498
|
+
ways: { sandbox: 0, index: 0, redirect: 0, replace: 0 }
|
|
29499
|
+
}));
|
|
29500
|
+
const net = /* @__PURE__ */ new Map();
|
|
29501
|
+
for (const r of raw.prepare(WEEK).all(first * MS_PER_DAY)) {
|
|
29502
|
+
const d = days[Number(r.day) - first];
|
|
29503
|
+
if (d === void 0) continue;
|
|
29504
|
+
d.calls += Number(r.calls);
|
|
29505
|
+
const key = `${d.day}:${wayOf(String(r.tool))}`;
|
|
29506
|
+
net.set(key, (net.get(key) ?? 0) + Number(r.produced) - Number(r.returned));
|
|
29507
|
+
}
|
|
29508
|
+
for (const d of days) for (const [way] of STATS_WAYS) d.ways[way] = Math.max(0, net.get(`${d.day}:${way}`) ?? 0);
|
|
29509
|
+
for (const r of raw.prepare(WEEK_RUNS).all(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX, first * MS_PER_DAY)) {
|
|
29510
|
+
const d = days[Number(r.day) - first];
|
|
29511
|
+
if (d === void 0) continue;
|
|
29512
|
+
d.calls += Number(r.calls);
|
|
29513
|
+
d.ways.redirect += Number(r.saved);
|
|
29514
|
+
}
|
|
29515
|
+
return days;
|
|
29516
|
+
}
|
|
28993
29517
|
var EMPTY5 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
28994
|
-
function
|
|
28995
|
-
|
|
28996
|
-
|
|
28997
|
-
|
|
28998
|
-
|
|
28999
|
-
|
|
29518
|
+
function totals(r) {
|
|
29519
|
+
const produced = Number(r.produced);
|
|
29520
|
+
const returned = Number(r.returned);
|
|
29521
|
+
return { calls: Number(r.calls), produced, returned, saved: Math.max(0, produced - returned) };
|
|
29522
|
+
}
|
|
29523
|
+
function readFacts(raw, sessionId) {
|
|
29524
|
+
const groups = raw.prepare(GROUPS).all().map((r) => ({ session: String(r.session_id), agent: String(r.agent), ...totals(r) }));
|
|
29525
|
+
const tools = raw.prepare(TOOLS).all().map((r) => ({ name: String(r.tool), ...totals(r) }));
|
|
29526
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
29527
|
+
for (const r of raw.prepare(KINDS).all(sessionId)) kinds.set(String(r.kind), { session: Number(r.s), project: Number(r.p) });
|
|
29528
|
+
const meta3 = raw.prepare(META).get();
|
|
29529
|
+
const span2 = Number(raw.prepare(SPAN).get(sessionId).span);
|
|
29530
|
+
const src = raw.prepare(SOURCES).get();
|
|
29531
|
+
const runs = raw.prepare(REDIRECTED).get(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX);
|
|
29532
|
+
const last2 = Math.max(Number(raw.prepare(LAST).get().last), Number(runs.last));
|
|
29533
|
+
const pages = raw.prepare("PRAGMA page_count").get();
|
|
29534
|
+
const size = raw.prepare("PRAGMA page_size").get();
|
|
29535
|
+
return {
|
|
29536
|
+
groups,
|
|
29537
|
+
tools,
|
|
29538
|
+
kinds,
|
|
29539
|
+
span: span2,
|
|
29540
|
+
sessions: Number(meta3.sessions),
|
|
29541
|
+
agents: Number(meta3.agents),
|
|
29542
|
+
days: Number(meta3.days),
|
|
29543
|
+
sources: { count: Number(src.n), chunks: Number(src.chunks), bytes: Number(src.bytes) },
|
|
29544
|
+
dbBytes: Number(pages.page_count) * Number(size.page_size),
|
|
29545
|
+
top: raw.prepare(TOP).all().map((r) => ({ name: String(r.tool), ...totals(r) })),
|
|
29546
|
+
replaced: Number(raw.prepare(REPLACED).get().n),
|
|
29547
|
+
redirected: Number(runs.n),
|
|
29548
|
+
week: readWeek(raw, last2)
|
|
29549
|
+
};
|
|
29000
29550
|
}
|
|
29001
29551
|
function sum(groups) {
|
|
29002
29552
|
return groups.reduce((t, g) => ({
|
|
@@ -29010,23 +29560,225 @@ function reductionPct(t) {
|
|
|
29010
29560
|
if (t.calls === 0) return 0;
|
|
29011
29561
|
return Number((t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1));
|
|
29012
29562
|
}
|
|
29013
|
-
function tableRow(
|
|
29563
|
+
function tableRow(label2, t) {
|
|
29014
29564
|
const last2 = t.calls === 0 ? STATS_NO_DATA : String(reductionPct(t));
|
|
29015
|
-
return "| " + [
|
|
29565
|
+
return "| " + [label2, t.produced + " B", t.returned + " B", t.saved + " B", last2].join(" | ") + " |";
|
|
29566
|
+
}
|
|
29567
|
+
var UNITS = ["KB", "MB", "GB", "TB"];
|
|
29568
|
+
var LABEL_W = STATS_LABEL_W;
|
|
29569
|
+
var NUM_W = STATS_NUM_W;
|
|
29570
|
+
var PCT_W = STATS_PCT_W;
|
|
29571
|
+
var INT = new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 });
|
|
29572
|
+
function int2(n) {
|
|
29573
|
+
return INT.format(Math.round(n));
|
|
29574
|
+
}
|
|
29575
|
+
function count(n) {
|
|
29576
|
+
return n < STATS_MILLION ? int2(n) : (n / STATS_MILLION).toFixed(1) + "M";
|
|
29577
|
+
}
|
|
29578
|
+
function bytes4(n) {
|
|
29579
|
+
if (n < 0) return "-" + bytes4(-n);
|
|
29580
|
+
if (n < STATS_KIB) return int2(n) + " B";
|
|
29581
|
+
let v = n / STATS_KIB;
|
|
29582
|
+
let u = 0;
|
|
29583
|
+
while (v >= STATS_KIB && u < UNITS.length - 1) {
|
|
29584
|
+
v /= STATS_KIB;
|
|
29585
|
+
u++;
|
|
29586
|
+
}
|
|
29587
|
+
return v.toFixed(1) + " " + UNITS[u];
|
|
29588
|
+
}
|
|
29589
|
+
function pct(t) {
|
|
29590
|
+
return (t.saved * PERCENT_SCALE / Math.max(1, t.produced)).toFixed(1) + "%";
|
|
29591
|
+
}
|
|
29592
|
+
function bar(value, max, width, fill = "\u2588", rest = "") {
|
|
29593
|
+
const n = value <= 0 || max <= 0 ? 0 : Math.min(width, Math.max(1, Math.round(value / max * width)));
|
|
29594
|
+
return fill.repeat(n) + rest.repeat(width - n);
|
|
29595
|
+
}
|
|
29596
|
+
function label(s) {
|
|
29597
|
+
const chars = [...s];
|
|
29598
|
+
return (chars.length > STATS_LABEL_MAX ? chars.slice(0, STATS_LABEL_MAX - 1).join("") + "\u2026" : s).padEnd(LABEL_W);
|
|
29599
|
+
}
|
|
29600
|
+
function span(ms) {
|
|
29601
|
+
const min = Math.floor(ms / STATS_MS_PER_MINUTE);
|
|
29602
|
+
if (min < 1) return "<1m";
|
|
29603
|
+
if (min < STATS_MINUTES_PER_HOUR) return min + "m";
|
|
29604
|
+
const h = Math.floor(min / STATS_MINUTES_PER_HOUR);
|
|
29605
|
+
return h < STATS_HOURS_PER_DAY ? `${h}h ${String(min % STATS_MINUTES_PER_HOUR).padStart(STATS_CLOCK_DIGITS, "0")}m` : `${Math.floor(h / STATS_HOURS_PER_DAY)}d ${h % STATS_HOURS_PER_DAY}h`;
|
|
29606
|
+
}
|
|
29607
|
+
function plural(n, word) {
|
|
29608
|
+
return `${int2(n)} ${word}${n === 1 ? "" : "s"}`;
|
|
29609
|
+
}
|
|
29610
|
+
function table2(title, rows) {
|
|
29611
|
+
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
29612
|
+
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);
|
|
29613
|
+
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())];
|
|
29614
|
+
}
|
|
29615
|
+
function bySaved(a, b) {
|
|
29616
|
+
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
29617
|
+
}
|
|
29618
|
+
function toolName(tool) {
|
|
29619
|
+
return tool.startsWith("ctx_") ? tool : "hook " + tool;
|
|
29620
|
+
}
|
|
29621
|
+
function joinIndex(tools) {
|
|
29622
|
+
const idx = tools.filter((t2) => STATS_INDEX_TOOLS.includes(t2.name));
|
|
29623
|
+
if (idx.length <= 1) return tools;
|
|
29624
|
+
const t = sum(idx);
|
|
29625
|
+
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: t.produced - t.returned };
|
|
29626
|
+
return [...tools.filter((x) => !idx.includes(x)), one];
|
|
29627
|
+
}
|
|
29628
|
+
function toolRows(tools) {
|
|
29629
|
+
const named = joinIndex(tools.map((t) => ({ ...t, saved: t.produced - t.returned }))).map((t) => ({ ...t, name: toolName(t.name) })).sort(bySaved);
|
|
29630
|
+
const zero = named.filter((t) => t.saved <= 0);
|
|
29631
|
+
const fold2 = zero.length > 1 ? zero : [];
|
|
29632
|
+
const keep = named.filter((t) => !fold2.includes(t));
|
|
29633
|
+
const room = fold2.length > 0 ? STATS_MAX_TOOL_ROWS - 1 : STATS_MAX_TOOL_ROWS;
|
|
29634
|
+
const over = keep.length > room;
|
|
29635
|
+
const shown2 = over ? keep.slice(0, STATS_MAX_TOOL_ROWS - 1) : keep;
|
|
29636
|
+
const rest = over ? [...keep.slice(STATS_MAX_TOOL_ROWS - 1), ...fold2] : fold2;
|
|
29637
|
+
return rest.length === 0 ? shown2 : [...shown2, { name: `other (${plural(rest.length, "tool")})`, ...sum(rest) }];
|
|
29638
|
+
}
|
|
29639
|
+
var TOKEN_UNITS = ["K", "M", "B", "T"];
|
|
29640
|
+
function whole(v) {
|
|
29641
|
+
return v >= STATS_WHOLE_FROM ? int2(v) : v.toFixed(1);
|
|
29642
|
+
}
|
|
29643
|
+
function tokens(n) {
|
|
29644
|
+
if (n < STATS_THOUSAND) return int2(n);
|
|
29645
|
+
let v = n / STATS_THOUSAND;
|
|
29646
|
+
let u = 0;
|
|
29647
|
+
while (v >= STATS_THOUSAND && u < TOKEN_UNITS.length - 1) {
|
|
29648
|
+
v /= STATS_THOUSAND;
|
|
29649
|
+
u++;
|
|
29650
|
+
}
|
|
29651
|
+
return whole(v) + TOKEN_UNITS[u];
|
|
29652
|
+
}
|
|
29653
|
+
function windowLine(saved) {
|
|
29654
|
+
const t = saved / STATS_BYTES_PER_TOKEN;
|
|
29655
|
+
const share = t / STATS_WINDOW_TOKENS;
|
|
29656
|
+
const win = `a ${tokens(STATS_WINDOW_TOKENS)} window`;
|
|
29657
|
+
const head = ` about ${tokens(t)} tokens kept out`;
|
|
29658
|
+
if (share >= 1) return `${head}, ${whole(share)} times ${win}`;
|
|
29659
|
+
const p = share * PERCENT_SCALE;
|
|
29660
|
+
return p * STATS_WHOLE_FROM < 1 ? head : `${head}, ${whole(p)}% of ${win}`;
|
|
29661
|
+
}
|
|
29662
|
+
function ymd(day) {
|
|
29663
|
+
return new Date(day * MS_PER_DAY).toISOString().slice(0, "yyyy-mm-dd".length);
|
|
29664
|
+
}
|
|
29665
|
+
function mmdd(day) {
|
|
29666
|
+
return ymd(day).slice("yyyy-".length);
|
|
29667
|
+
}
|
|
29668
|
+
function stack(parts, max, width) {
|
|
29669
|
+
let total = 0;
|
|
29670
|
+
let at2 = 0;
|
|
29671
|
+
let out = "";
|
|
29672
|
+
parts.forEach((v, i) => {
|
|
29673
|
+
total += v;
|
|
29674
|
+
const end = max <= 0 ? 0 : Math.round(total / max * width);
|
|
29675
|
+
if (end > at2) {
|
|
29676
|
+
out += STATS_WAYS[i][1].repeat(end - at2);
|
|
29677
|
+
at2 = end;
|
|
29678
|
+
}
|
|
29679
|
+
});
|
|
29680
|
+
if (out === "" && total > 0) out = STATS_WAYS[parts.indexOf(Math.max(...parts))][1];
|
|
29681
|
+
return out;
|
|
29682
|
+
}
|
|
29683
|
+
function cards(cells) {
|
|
29684
|
+
return (" " + cells.map((c) => c.padEnd(STATS_CARD_W)).join("")).trimEnd();
|
|
29685
|
+
}
|
|
29686
|
+
function lastDays(week, allCalls) {
|
|
29687
|
+
const saved = week.map((d) => STATS_WAYS.reduce((t, [w]) => t + d.ways[w], 0));
|
|
29688
|
+
const all = saved.reduce((a, b) => a + b, 0);
|
|
29689
|
+
const calls = week.reduce((a, d) => a + d.calls, 0);
|
|
29690
|
+
const max = Math.max(0, ...saved);
|
|
29691
|
+
const head = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
|
|
29692
|
+
const card = calls < allCalls ? [
|
|
29693
|
+
cards(["Kept out", "Tokens kept out", "Calls", "Kept out per call"]),
|
|
29694
|
+
cards([bytes4(all), "about " + tokens(all / STATS_BYTES_PER_TOKEN), count(calls), bytes4(calls > 0 ? all / calls : 0)]),
|
|
29695
|
+
""
|
|
29696
|
+
] : [];
|
|
29697
|
+
return [
|
|
29698
|
+
head,
|
|
29699
|
+
...card,
|
|
29700
|
+
...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)] : []),
|
|
29701
|
+
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
29702
|
+
""
|
|
29703
|
+
];
|
|
29704
|
+
}
|
|
29705
|
+
function hookLine(redirected, replaced) {
|
|
29706
|
+
const all = redirected + replaced;
|
|
29707
|
+
if (all === 0) return [];
|
|
29708
|
+
const parts = [...redirected > 0 ? [`${int2(redirected)} sent to the sandbox`] : [], ...replaced > 0 ? [`${int2(replaced)} cut down`] : []];
|
|
29709
|
+
const what = plural(all, "large output");
|
|
29710
|
+
return [parts.length === 1 ? ` Project hooks: ${what} ${parts[0].replace(/^[\d,]+ /, "")}` : ` Project hooks: ${what} kept out \xB7 ${parts.join(", ")}`];
|
|
29711
|
+
}
|
|
29712
|
+
function fit(line) {
|
|
29713
|
+
const chars = [...line];
|
|
29714
|
+
return chars.length <= STATS_WIDTH ? line : chars.slice(0, STATS_WIDTH - 1).join("") + "\u2026";
|
|
29715
|
+
}
|
|
29716
|
+
function report(f, sessionId, agent) {
|
|
29717
|
+
const head = [STATS_REPORT_TITLE, "\u2500".repeat(STATS_WIDTH), ""];
|
|
29718
|
+
const project = sum(f.groups);
|
|
29719
|
+
if (project.calls === 0) return [...head, ...STATS_EMPTY_LINES].join("\n");
|
|
29720
|
+
const session = sum(f.groups.filter((g) => g.session === sessionId));
|
|
29721
|
+
const [scopeName, focus] = session.calls > 0 ? ["This session", session] : ["This project", project];
|
|
29722
|
+
const top = Math.max(focus.produced, focus.returned);
|
|
29723
|
+
const extra = session.calls > 0 ? ` \xB7 ${span(f.span)} active` : "";
|
|
29724
|
+
const lines = [
|
|
29725
|
+
...head,
|
|
29726
|
+
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
29727
|
+
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
29728
|
+
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced).padStart(NUM_W),
|
|
29729
|
+
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned).padStart(NUM_W),
|
|
29730
|
+
...focus.saved > 0 ? [windowLine(focus.saved), STATS_TOKEN_NOTE] : [],
|
|
29731
|
+
...hookLine(f.redirected, f.replaced),
|
|
29732
|
+
"",
|
|
29733
|
+
...lastDays(f.week, project.calls + f.redirected),
|
|
29734
|
+
// D-STATS-FIX-1 (5): one DB per project holds every session of it, so project and all-time are one row.
|
|
29735
|
+
"By scope",
|
|
29736
|
+
...table2("Scope", [{ name: "session", ...session }, { name: "project (all-time)", ...project }]),
|
|
29737
|
+
"",
|
|
29738
|
+
"By tool (this project)",
|
|
29739
|
+
...table2("Tool", toolRows(f.tools)),
|
|
29740
|
+
"",
|
|
29741
|
+
...f.top.length > 0 ? [
|
|
29742
|
+
"Largest single outputs (made \u2192 sent to the chat)",
|
|
29743
|
+
...f.top.map((t) => " " + label(toolName(t.name)) + bytes4(t.produced).padStart(NUM_W) + " \u2192 " + bytes4(t.returned).padStart(NUM_W)),
|
|
29744
|
+
""
|
|
29745
|
+
] : []
|
|
29746
|
+
];
|
|
29747
|
+
const agents = /* @__PURE__ */ new Map();
|
|
29748
|
+
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY5, g]));
|
|
29749
|
+
if (!agents.has(agent)) agents.set(agent, EMPTY5);
|
|
29750
|
+
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
29751
|
+
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
29752
|
+
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session".padStart(STATS_KIND_W) + "Project".padStart(STATS_KIND_W));
|
|
29753
|
+
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
29754
|
+
const k = f.kinds.get(kind) ?? { session: 0, project: 0 };
|
|
29755
|
+
lines.push((" " + label(name) + int2(k.session).padStart(STATS_KIND_W) + int2(k.project).padStart(STATS_KIND_W) + " " + bar(k.project, maxKind, STATS_KIND_BAR)).trimEnd());
|
|
29756
|
+
}
|
|
29757
|
+
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
29758
|
+
lines.push(
|
|
29759
|
+
" " + "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")}`,
|
|
29760
|
+
" " + "Database file".padEnd(LABEL_W) + bytes4(f.dbBytes),
|
|
29761
|
+
" " + "Sessions".padEnd(LABEL_W) + `${int2(f.sessions)} \xB7 agents ${int2(f.agents)} \xB7 active days ${int2(f.days)}`,
|
|
29762
|
+
"",
|
|
29763
|
+
STATS_FOOTER_URL,
|
|
29764
|
+
"github.com/" + ISSUE_REPO_SLUG
|
|
29765
|
+
);
|
|
29766
|
+
return lines.map(fit).join("\n");
|
|
29016
29767
|
}
|
|
29017
29768
|
async function handler7(_input, ctx) {
|
|
29018
29769
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
29019
|
-
let
|
|
29770
|
+
let facts;
|
|
29020
29771
|
try {
|
|
29021
|
-
|
|
29772
|
+
facts = readFacts(db.raw, ctx.sessionId);
|
|
29022
29773
|
} finally {
|
|
29023
29774
|
closeDb(db);
|
|
29024
29775
|
}
|
|
29776
|
+
const groups = facts.groups;
|
|
29025
29777
|
const session = sum(groups.filter((g) => g.session === ctx.sessionId));
|
|
29026
29778
|
const project = sum(groups);
|
|
29027
29779
|
const allTime = project;
|
|
29028
29780
|
const agentIds = [.../* @__PURE__ */ new Set([...groups.map((g) => g.agent), ctx.project.agent])].sort();
|
|
29029
|
-
const
|
|
29781
|
+
const mdTable = [
|
|
29030
29782
|
"| " + STATS_COLUMNS.join(" | ") + " |",
|
|
29031
29783
|
"|" + STATS_COLUMNS.map(() => "---").join("|") + "|",
|
|
29032
29784
|
tableRow("session", session),
|
|
@@ -29035,7 +29787,8 @@ async function handler7(_input, ctx) {
|
|
|
29035
29787
|
...agentIds.map((a) => tableRow("agent " + a, sum(groups.filter((g) => g.agent === a))))
|
|
29036
29788
|
].join("\n");
|
|
29037
29789
|
const summary = STATS_SUMMARY(reductionPct(allTime), reductionPct(session));
|
|
29038
|
-
|
|
29790
|
+
const text = summary + "\n\n```text\n" + report(facts, ctx.sessionId, ctx.project.agent) + "\n```\n\n" + mdTable;
|
|
29791
|
+
return { text: capBytes(text, OUTPUT_CAP).text, isError: false, sandboxBytes: 0 };
|
|
29039
29792
|
}
|
|
29040
29793
|
var ctxStats = Object.freeze({
|
|
29041
29794
|
name: "ctx_stats",
|
|
@@ -29046,28 +29799,28 @@ var ctxStats = Object.freeze({
|
|
|
29046
29799
|
});
|
|
29047
29800
|
|
|
29048
29801
|
// src/core/tools/upgrade.ts
|
|
29049
|
-
import { existsSync as
|
|
29050
|
-
import { basename as basename6, dirname as dirname11, join as
|
|
29802
|
+
import { existsSync as existsSync21, realpathSync as realpathSync10, rmSync as rmSync9 } from "node:fs";
|
|
29803
|
+
import { basename as basename6, dirname as dirname11, join as join24 } from "node:path";
|
|
29051
29804
|
|
|
29052
29805
|
// src/core/ops/host-write.ts
|
|
29053
|
-
import { copyFileSync, existsSync as
|
|
29054
|
-
import { dirname as dirname10, join as
|
|
29806
|
+
import { copyFileSync, existsSync as existsSync16, mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
29807
|
+
import { dirname as dirname10, join as join19 } from "node:path";
|
|
29055
29808
|
function defaultWrite(file2, text) {
|
|
29056
|
-
|
|
29809
|
+
writeFileSync5(file2, text, "utf8");
|
|
29057
29810
|
}
|
|
29058
29811
|
function hostConfigPath(agent, home, env) {
|
|
29059
29812
|
const own4 = OWN_MCP_ENTRY[agent];
|
|
29060
29813
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
29061
29814
|
switch (agent) {
|
|
29062
29815
|
case "opencode":
|
|
29063
|
-
return
|
|
29816
|
+
return join19(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
29064
29817
|
// D-WIN-OPENCODE-DIR-1
|
|
29065
29818
|
case "pi":
|
|
29066
|
-
return
|
|
29819
|
+
return join19(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
29067
29820
|
case "copilot-cli":
|
|
29068
29821
|
return null;
|
|
29069
29822
|
default:
|
|
29070
|
-
return
|
|
29823
|
+
return join19(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
29071
29824
|
}
|
|
29072
29825
|
}
|
|
29073
29826
|
function cell3(value) {
|
|
@@ -29079,8 +29832,8 @@ function toRow(file2, edit) {
|
|
|
29079
29832
|
function writeWithRollback(file2, text, write2, atomic) {
|
|
29080
29833
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
29081
29834
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
29082
|
-
const had =
|
|
29083
|
-
|
|
29835
|
+
const had = existsSync16(file2);
|
|
29836
|
+
mkdirSync6(dirname10(file2), { recursive: true });
|
|
29084
29837
|
if (had) copyFileSync(file2, trash);
|
|
29085
29838
|
try {
|
|
29086
29839
|
write2(tmp, text);
|
|
@@ -29109,7 +29862,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
29109
29862
|
if (requested === null) return [];
|
|
29110
29863
|
const current = readHostConfig(row5.id, requested);
|
|
29111
29864
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
29112
|
-
const exists =
|
|
29865
|
+
const exists = existsSync16(current.path);
|
|
29113
29866
|
if (exists && result.text === current.text) return [];
|
|
29114
29867
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
29115
29868
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -29117,8 +29870,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
29117
29870
|
}
|
|
29118
29871
|
|
|
29119
29872
|
// src/core/ops/plugin-swap.ts
|
|
29120
|
-
import { existsSync as
|
|
29121
|
-
import { basename as basename5, join as
|
|
29873
|
+
import { existsSync as existsSync17, lstatSync, readdirSync as readdirSync7, readlinkSync, rmSync as rmSync5, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
29874
|
+
import { basename as basename5, join as join20, win32 as win322 } from "node:path";
|
|
29122
29875
|
function linkTarget(path7, win) {
|
|
29123
29876
|
if (!isLink(path7)) return null;
|
|
29124
29877
|
const target = readlinkSync(path7);
|
|
@@ -29137,11 +29890,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
29137
29890
|
else renameWithRetry(old, link, opts);
|
|
29138
29891
|
}
|
|
29139
29892
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
29140
|
-
const next =
|
|
29141
|
-
if (!
|
|
29893
|
+
const next = join20(agentDir, sha);
|
|
29894
|
+
if (!existsSync17(next) || !lstatSync(next).isDirectory()) {
|
|
29142
29895
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
29143
29896
|
}
|
|
29144
|
-
const link =
|
|
29897
|
+
const link = join20(agentDir, PLUGIN_CURRENT_LINK);
|
|
29145
29898
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
29146
29899
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
29147
29900
|
settleLinks(link, tmp, old, opts);
|
|
@@ -29156,15 +29909,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
29156
29909
|
if (before !== null) unlinkSync2(old);
|
|
29157
29910
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
29158
29911
|
if (before !== null) keep.add(before);
|
|
29159
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
29912
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join20(agentDir, name));
|
|
29160
29913
|
for (const dir of removed) rmSync5(dir, { recursive: true, force: true });
|
|
29161
|
-
const previous = before !== null &&
|
|
29914
|
+
const previous = before !== null && existsSync17(join20(agentDir, before)) ? join20(agentDir, before) : null;
|
|
29162
29915
|
return { current: next, previous, removed };
|
|
29163
29916
|
}
|
|
29164
29917
|
|
|
29165
29918
|
// src/core/ops/release-fetch.ts
|
|
29166
|
-
import { existsSync as
|
|
29167
|
-
import { join as
|
|
29919
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync7, rmSync as rmSync6 } from "node:fs";
|
|
29920
|
+
import { join as join21 } from "node:path";
|
|
29168
29921
|
function failed(r) {
|
|
29169
29922
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
29170
29923
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -29176,9 +29929,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
29176
29929
|
return r.stdout.toString().trim();
|
|
29177
29930
|
}
|
|
29178
29931
|
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
29179
|
-
const agentDir =
|
|
29180
|
-
|
|
29181
|
-
const fetchDir =
|
|
29932
|
+
const agentDir = join21(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
29933
|
+
mkdirSync7(agentDir, { recursive: true });
|
|
29934
|
+
const fetchDir = join21(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
29182
29935
|
rmSync6(fetchDir, { recursive: true, force: true });
|
|
29183
29936
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
29184
29937
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -29186,8 +29939,8 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
29186
29939
|
try {
|
|
29187
29940
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
29188
29941
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
29189
|
-
const dir =
|
|
29190
|
-
if (
|
|
29942
|
+
const dir = join21(agentDir, sha);
|
|
29943
|
+
if (existsSync18(dir)) rmSync6(fetchDir, { recursive: true, force: true });
|
|
29191
29944
|
else renameWithRetry(fetchDir, dir, opts);
|
|
29192
29945
|
return { sha, dir };
|
|
29193
29946
|
} catch (e) {
|
|
@@ -29197,15 +29950,15 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
29197
29950
|
}
|
|
29198
29951
|
|
|
29199
29952
|
// src/core/ops/uninstall.ts
|
|
29200
|
-
import { existsSync as
|
|
29201
|
-
import { join as
|
|
29953
|
+
import { existsSync as existsSync19, readdirSync as readdirSync8, rmSync as rmSync7, writeFileSync as writeFileSync6 } from "node:fs";
|
|
29954
|
+
import { join as join22 } from "node:path";
|
|
29202
29955
|
function row2(area, before, after) {
|
|
29203
29956
|
return { area, before, after };
|
|
29204
29957
|
}
|
|
29205
29958
|
function stopServers(configDir, projectKey) {
|
|
29206
29959
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
29207
|
-
const dir =
|
|
29208
|
-
for (const serverId of stopped)
|
|
29960
|
+
const dir = join22(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
29961
|
+
for (const serverId of stopped) writeFileSync6(join22(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
29209
29962
|
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 };
|
|
29210
29963
|
}
|
|
29211
29964
|
function rootOrNull(adapter, env) {
|
|
@@ -29223,15 +29976,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
29223
29976
|
const root = rootOrNull(adapter, env);
|
|
29224
29977
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29225
29978
|
if (adapter.installMode === "marketplace") {
|
|
29226
|
-
const cache =
|
|
29979
|
+
const cache = join22(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
29227
29980
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
29228
29981
|
}
|
|
29229
29982
|
rmSync7(root, { recursive: true, force: true });
|
|
29230
29983
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
29231
29984
|
}
|
|
29232
29985
|
case "plugin": {
|
|
29233
|
-
const agentDir =
|
|
29234
|
-
if (!
|
|
29986
|
+
const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
29987
|
+
if (!existsSync19(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
29235
29988
|
rmSync7(agentDir, { recursive: true, force: true });
|
|
29236
29989
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
29237
29990
|
}
|
|
@@ -29276,7 +30029,7 @@ function ownEntries(agent, env) {
|
|
|
29276
30029
|
}
|
|
29277
30030
|
if (agent === "opencode") {
|
|
29278
30031
|
return [{
|
|
29279
|
-
file:
|
|
30032
|
+
file: join22(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
29280
30033
|
// D-WIN-OPENCODE-DIR-1
|
|
29281
30034
|
key: OPENCODE_PLUGIN_KEY,
|
|
29282
30035
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -29287,7 +30040,7 @@ function ownEntries(agent, env) {
|
|
|
29287
30040
|
if (agent === "pi") {
|
|
29288
30041
|
const agentDir = piAgentDirOf(env, home);
|
|
29289
30042
|
return [{
|
|
29290
|
-
file:
|
|
30043
|
+
file: join22(agentDir, SETTINGS_FILE),
|
|
29291
30044
|
key: PI_PACKAGES_KEY,
|
|
29292
30045
|
shown: PI_PACKAGES_KEY,
|
|
29293
30046
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -29309,12 +30062,12 @@ function removeOwnEntries(agent, env) {
|
|
|
29309
30062
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
29310
30063
|
}
|
|
29311
30064
|
function removeProjectData(configDir, projectKey) {
|
|
29312
|
-
const projects =
|
|
29313
|
-
const dir =
|
|
29314
|
-
if (!
|
|
30065
|
+
const projects = join22(configDir, PROJECTS_DIR_NAME);
|
|
30066
|
+
const dir = join22(projects, projectKey);
|
|
30067
|
+
if (!existsSync19(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
29315
30068
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
29316
30069
|
for (const name of readdirSync8(dir)) {
|
|
29317
|
-
if (name !== OWNERS_DIR_NAME) rmSync7(
|
|
30070
|
+
if (name !== OWNERS_DIR_NAME) rmSync7(join22(dir, name), { recursive: true, force: true });
|
|
29318
30071
|
}
|
|
29319
30072
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
29320
30073
|
}
|
|
@@ -29322,12 +30075,12 @@ function runUninstall(input) {
|
|
|
29322
30075
|
const configDir = resolveConfigDir(input.env);
|
|
29323
30076
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
29324
30077
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
29325
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
30078
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join22(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
29326
30079
|
return { rows, stopped: stop.stopped };
|
|
29327
30080
|
}
|
|
29328
30081
|
|
|
29329
30082
|
// src/core/ops/v1-remove.ts
|
|
29330
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
30083
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync20, readFileSync as readFileSync16, rmSync as rmSync8 } from "node:fs";
|
|
29331
30084
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
29332
30085
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
29333
30086
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -29346,13 +30099,13 @@ function keepOriginal(file2, kept, undo) {
|
|
|
29346
30099
|
undo.push({ trash, target: file2 });
|
|
29347
30100
|
}
|
|
29348
30101
|
function cutTomlTable(text, header) {
|
|
29349
|
-
let
|
|
30102
|
+
let span2;
|
|
29350
30103
|
try {
|
|
29351
|
-
|
|
30104
|
+
span2 = tomlTableSpans(text).find((t) => t.header.trim() === header);
|
|
29352
30105
|
} catch {
|
|
29353
30106
|
return null;
|
|
29354
30107
|
}
|
|
29355
|
-
return
|
|
30108
|
+
return span2 === void 0 ? null : text.slice(0, span2.start) + text.slice(span2.end);
|
|
29356
30109
|
}
|
|
29357
30110
|
function writeAtomic(file2, text) {
|
|
29358
30111
|
atomicWriteFile(file2, text);
|
|
@@ -29371,8 +30124,8 @@ function locate(doc, path7) {
|
|
|
29371
30124
|
return null;
|
|
29372
30125
|
}
|
|
29373
30126
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
29374
|
-
const layout = hostLayout(
|
|
29375
|
-
const text = hostText(
|
|
30127
|
+
const layout = hostLayout(readFileSync16(file2, "utf8"));
|
|
30128
|
+
const text = hostText(readFileSync16(file2, "utf8"));
|
|
29376
30129
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
29377
30130
|
const hit = /* @__PURE__ */ new Set();
|
|
29378
30131
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -29408,19 +30161,19 @@ function removeV1(agent, findings) {
|
|
|
29408
30161
|
for (const f of findings) {
|
|
29409
30162
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
29410
30163
|
else if (f.path === "") {
|
|
29411
|
-
if (
|
|
30164
|
+
if (existsSync20(f.file)) {
|
|
29412
30165
|
moveAside(f.file, undo);
|
|
29413
30166
|
done.set(f, UPGRADE_REMOVED);
|
|
29414
30167
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
29415
30168
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
29416
30169
|
}
|
|
29417
30170
|
for (const [file2, list4] of entries) {
|
|
29418
|
-
if (!
|
|
30171
|
+
if (!existsSync20(file2)) {
|
|
29419
30172
|
for (const f of list4) done.set(f, UPGRADE_NOT_FOUND);
|
|
29420
30173
|
continue;
|
|
29421
30174
|
}
|
|
29422
30175
|
if (file2.endsWith(TOML_EXT)) {
|
|
29423
|
-
const rawToml =
|
|
30176
|
+
const rawToml = readFileSync16(file2, "utf8");
|
|
29424
30177
|
const tomlLayout = hostLayout(rawToml);
|
|
29425
30178
|
let text = hostText(rawToml);
|
|
29426
30179
|
for (const f of list4) {
|
|
@@ -29448,7 +30201,7 @@ function removeV1(agent, findings) {
|
|
|
29448
30201
|
},
|
|
29449
30202
|
rollback() {
|
|
29450
30203
|
for (const u of undo.splice(0).reverse()) {
|
|
29451
|
-
if (!
|
|
30204
|
+
if (!existsSync20(u.trash)) continue;
|
|
29452
30205
|
rmSync8(u.target, { recursive: true, force: true });
|
|
29453
30206
|
renameWithRetry(u.trash, u.target);
|
|
29454
30207
|
}
|
|
@@ -29458,8 +30211,8 @@ function removeV1(agent, findings) {
|
|
|
29458
30211
|
|
|
29459
30212
|
// src/core/ops/verify-sums.ts
|
|
29460
30213
|
import { createHash as createHash2 } from "node:crypto";
|
|
29461
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as
|
|
29462
|
-
import { join as
|
|
30214
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync9, readFileSync as readFileSync17 } from "node:fs";
|
|
30215
|
+
import { join as join23 } from "node:path";
|
|
29463
30216
|
function mismatch() {
|
|
29464
30217
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
29465
30218
|
}
|
|
@@ -29480,24 +30233,24 @@ function walk3(dir, prefix, out) {
|
|
|
29480
30233
|
for (const entry of readdirSync9(dir, { withFileTypes: true })) {
|
|
29481
30234
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
29482
30235
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
29483
|
-
const abs =
|
|
30236
|
+
const abs = join23(dir, entry.name);
|
|
29484
30237
|
if (entry.isDirectory()) walk3(abs, rel, out);
|
|
29485
30238
|
else if (entry.isFile()) out.set(rel, abs);
|
|
29486
30239
|
else throw mismatch();
|
|
29487
30240
|
}
|
|
29488
30241
|
}
|
|
29489
30242
|
function verifySums(dir) {
|
|
29490
|
-
const sumsPath =
|
|
30243
|
+
const sumsPath = join23(dir, RELEASE_SUMS_FILE);
|
|
29491
30244
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
29492
30245
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
29493
|
-
const sums = parseSums(
|
|
30246
|
+
const sums = parseSums(readFileSync17(sumsPath, "utf8"));
|
|
29494
30247
|
const files = /* @__PURE__ */ new Map();
|
|
29495
30248
|
walk3(dir, "", files);
|
|
29496
30249
|
if (files.size !== sums.size) throw mismatch();
|
|
29497
30250
|
for (const [rel, abs] of files) {
|
|
29498
30251
|
const want = sums.get(rel);
|
|
29499
30252
|
if (want === void 0) throw mismatch();
|
|
29500
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
30253
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync17(abs)).digest(HASH_ENCODING);
|
|
29501
30254
|
if (got !== want) throw mismatch();
|
|
29502
30255
|
}
|
|
29503
30256
|
}
|
|
@@ -29525,8 +30278,8 @@ function pluginRootRow(adapter, env) {
|
|
|
29525
30278
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
29526
30279
|
}
|
|
29527
30280
|
function isCurrent(agentDir, dir) {
|
|
29528
|
-
const link =
|
|
29529
|
-
return
|
|
30281
|
+
const link = join24(agentDir, PLUGIN_CURRENT_LINK);
|
|
30282
|
+
return existsSync21(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
29530
30283
|
}
|
|
29531
30284
|
async function checkout(adapter, deps) {
|
|
29532
30285
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -29622,7 +30375,7 @@ function define(name) {
|
|
|
29622
30375
|
handler: built.handler
|
|
29623
30376
|
};
|
|
29624
30377
|
}
|
|
29625
|
-
var
|
|
30378
|
+
var TOOLS2 = Object.freeze(TOOL_ORDER.map(define));
|
|
29626
30379
|
function callExample(tool) {
|
|
29627
30380
|
const a = tool.description.indexOf("`");
|
|
29628
30381
|
const b = tool.description.indexOf("`", a + 1);
|
|
@@ -29646,8 +30399,8 @@ function checkCall(tool, input) {
|
|
|
29646
30399
|
|
|
29647
30400
|
// src/entries/server.ts
|
|
29648
30401
|
import { randomUUID } from "node:crypto";
|
|
29649
|
-
import { existsSync as
|
|
29650
|
-
import { dirname as dirname12, join as
|
|
30402
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync11 } from "node:fs";
|
|
30403
|
+
import { dirname as dirname12, join as join26 } from "node:path";
|
|
29651
30404
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
29652
30405
|
|
|
29653
30406
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -30354,14 +31107,14 @@ function codePointLength(str4) {
|
|
|
30354
31107
|
const units = str4.length;
|
|
30355
31108
|
if (!highSurrogate.test(str4))
|
|
30356
31109
|
return units;
|
|
30357
|
-
let
|
|
31110
|
+
let count2 = units;
|
|
30358
31111
|
for (let i = 0; i < units - 1; i++) {
|
|
30359
31112
|
if ((str4.charCodeAt(i) & 64512) === 55296 && (str4.charCodeAt(i + 1) & 64512) === 56320) {
|
|
30360
|
-
|
|
31113
|
+
count2--;
|
|
30361
31114
|
i++;
|
|
30362
31115
|
}
|
|
30363
31116
|
}
|
|
30364
|
-
return
|
|
31117
|
+
return count2;
|
|
30365
31118
|
}
|
|
30366
31119
|
function getLengthableOrigin2(input) {
|
|
30367
31120
|
if (Array.isArray(input))
|
|
@@ -30410,16 +31163,16 @@ function cleanEnum2(obj) {
|
|
|
30410
31163
|
}
|
|
30411
31164
|
function base64ToUint8Array(base645) {
|
|
30412
31165
|
const binaryString = atob(base645);
|
|
30413
|
-
const
|
|
31166
|
+
const bytes5 = new Uint8Array(binaryString.length);
|
|
30414
31167
|
for (let i = 0; i < binaryString.length; i++) {
|
|
30415
|
-
|
|
31168
|
+
bytes5[i] = binaryString.charCodeAt(i);
|
|
30416
31169
|
}
|
|
30417
|
-
return
|
|
31170
|
+
return bytes5;
|
|
30418
31171
|
}
|
|
30419
|
-
function uint8ArrayToBase64(
|
|
31172
|
+
function uint8ArrayToBase64(bytes5) {
|
|
30420
31173
|
let binaryString = "";
|
|
30421
|
-
for (let i = 0; i <
|
|
30422
|
-
binaryString += String.fromCharCode(
|
|
31174
|
+
for (let i = 0; i < bytes5.length; i++) {
|
|
31175
|
+
binaryString += String.fromCharCode(bytes5[i]);
|
|
30423
31176
|
}
|
|
30424
31177
|
return btoa(binaryString);
|
|
30425
31178
|
}
|
|
@@ -30428,30 +31181,30 @@ function base64urlToUint8Array(base64url5) {
|
|
|
30428
31181
|
const padding = "=".repeat((4 - base645.length % 4) % 4);
|
|
30429
31182
|
return base64ToUint8Array(base645 + padding);
|
|
30430
31183
|
}
|
|
30431
|
-
function uint8ArrayToBase64url(
|
|
30432
|
-
return uint8ArrayToBase64(
|
|
31184
|
+
function uint8ArrayToBase64url(bytes5) {
|
|
31185
|
+
return uint8ArrayToBase64(bytes5).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
30433
31186
|
}
|
|
30434
31187
|
function hexToUint8Array(hex) {
|
|
30435
31188
|
const cleanHex = hex.replace(/^0x/, "");
|
|
30436
31189
|
if (cleanHex.length % 2 !== 0) {
|
|
30437
31190
|
throw new Error("Invalid hex string length");
|
|
30438
31191
|
}
|
|
30439
|
-
const
|
|
31192
|
+
const bytes5 = new Uint8Array(cleanHex.length / 2);
|
|
30440
31193
|
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
30441
|
-
|
|
31194
|
+
bytes5[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
30442
31195
|
}
|
|
30443
|
-
return
|
|
31196
|
+
return bytes5;
|
|
30444
31197
|
}
|
|
30445
|
-
function uint8ArrayToHex(
|
|
30446
|
-
return Array.from(
|
|
31198
|
+
function uint8ArrayToHex(bytes5) {
|
|
31199
|
+
return Array.from(bytes5).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
30447
31200
|
}
|
|
30448
31201
|
var Class2 = class {
|
|
30449
31202
|
constructor(..._args) {
|
|
30450
31203
|
}
|
|
30451
31204
|
};
|
|
30452
|
-
function members(proto,
|
|
30453
|
-
for (const key in
|
|
30454
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
31205
|
+
function members(proto, table3) {
|
|
31206
|
+
for (const key in table3) {
|
|
31207
|
+
const desc = Object.getOwnPropertyDescriptor(table3, key);
|
|
30455
31208
|
if (desc.get)
|
|
30456
31209
|
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
30457
31210
|
else
|
|
@@ -30466,10 +31219,10 @@ function hide(inst, key, value) {
|
|
|
30466
31219
|
return own2(inst, key, value, false);
|
|
30467
31220
|
}
|
|
30468
31221
|
// @__NO_SIDE_EFFECTS__
|
|
30469
|
-
function derived(computes,
|
|
31222
|
+
function derived(computes, table3) {
|
|
30470
31223
|
for (const key in computes) {
|
|
30471
31224
|
const compute = computes[key];
|
|
30472
|
-
Object.defineProperty(
|
|
31225
|
+
Object.defineProperty(table3, key, {
|
|
30473
31226
|
configurable: true,
|
|
30474
31227
|
enumerable: true,
|
|
30475
31228
|
get() {
|
|
@@ -30480,7 +31233,7 @@ function derived(computes, table2) {
|
|
|
30480
31233
|
}
|
|
30481
31234
|
});
|
|
30482
31235
|
}
|
|
30483
|
-
return
|
|
31236
|
+
return table3;
|
|
30484
31237
|
}
|
|
30485
31238
|
function defineBound(proto, key, fn) {
|
|
30486
31239
|
Object.defineProperty(proto, key, {
|
|
@@ -33126,17 +33879,17 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
33126
33879
|
var NONE3 = 0;
|
|
33127
33880
|
var ASSUMED = 1;
|
|
33128
33881
|
var PROVEN = 2;
|
|
33129
|
-
function isRecursive(inst,
|
|
33882
|
+
function isRecursive(inst, stack2, resolve8) {
|
|
33130
33883
|
const cached4 = recursive.get(inst);
|
|
33131
33884
|
if (cached4 !== void 0)
|
|
33132
33885
|
return cached4 ? PROVEN : NONE3;
|
|
33133
|
-
if (
|
|
33886
|
+
if (stack2.has(inst))
|
|
33134
33887
|
return PROVEN;
|
|
33135
|
-
|
|
33888
|
+
stack2.add(inst);
|
|
33136
33889
|
let result = NONE3;
|
|
33137
33890
|
const check2 = (child) => {
|
|
33138
33891
|
if (result !== PROVEN && child?._zod) {
|
|
33139
|
-
const answer2 = isRecursive(child,
|
|
33892
|
+
const answer2 = isRecursive(child, stack2, resolve8);
|
|
33140
33893
|
if (answer2 > result)
|
|
33141
33894
|
result = answer2;
|
|
33142
33895
|
}
|
|
@@ -33147,7 +33900,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
33147
33900
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
33148
33901
|
if (spread && !desc.enumerable)
|
|
33149
33902
|
continue;
|
|
33150
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value,
|
|
33903
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve8) : NONE3;
|
|
33151
33904
|
if (child > answer2)
|
|
33152
33905
|
answer2 = child;
|
|
33153
33906
|
}
|
|
@@ -33212,7 +33965,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
33212
33965
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
33213
33966
|
case "lazy": {
|
|
33214
33967
|
const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
|
|
33215
|
-
merge5(inner ? isRecursive(inner,
|
|
33968
|
+
merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
|
|
33216
33969
|
break;
|
|
33217
33970
|
}
|
|
33218
33971
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -33255,7 +34008,7 @@ function isRecursive(inst, stack, resolve8) {
|
|
|
33255
34008
|
}
|
|
33256
34009
|
}
|
|
33257
34010
|
}
|
|
33258
|
-
|
|
34011
|
+
stack2.delete(inst);
|
|
33259
34012
|
return settle(inst, result);
|
|
33260
34013
|
}
|
|
33261
34014
|
function settle(inst, answer2) {
|
|
@@ -35718,10 +36471,10 @@ var ZodNumber2 = /* @__PURE__ */ $constructor2(
|
|
|
35718
36471
|
return this.check(_lte2(value, params));
|
|
35719
36472
|
},
|
|
35720
36473
|
int(params) {
|
|
35721
|
-
return this.check(
|
|
36474
|
+
return this.check(int3(params));
|
|
35722
36475
|
},
|
|
35723
36476
|
safe(params) {
|
|
35724
|
-
return this.check(
|
|
36477
|
+
return this.check(int3(params));
|
|
35725
36478
|
},
|
|
35726
36479
|
positive(params) {
|
|
35727
36480
|
return this.check(_gt2(0, params));
|
|
@@ -35753,7 +36506,7 @@ var ZodNumberFormat2 = /* @__PURE__ */ $constructor2("ZodNumberFormat", (inst, d
|
|
|
35753
36506
|
$ZodNumberFormat2.init(inst, def);
|
|
35754
36507
|
ZodNumber2.init(inst, def);
|
|
35755
36508
|
});
|
|
35756
|
-
function
|
|
36509
|
+
function int3(params) {
|
|
35757
36510
|
return _int2(ZodNumberFormat2, params);
|
|
35758
36511
|
}
|
|
35759
36512
|
var ZodBoolean2 = /* @__PURE__ */ $constructor2("ZodBoolean", (inst, def) => {
|
|
@@ -37935,14 +38688,14 @@ function codePointLength2(str4) {
|
|
|
37935
38688
|
const units = str4.length;
|
|
37936
38689
|
if (!highSurrogate2.test(str4))
|
|
37937
38690
|
return units;
|
|
37938
|
-
let
|
|
38691
|
+
let count2 = units;
|
|
37939
38692
|
for (let i = 0; i < units - 1; i++) {
|
|
37940
38693
|
if ((str4.charCodeAt(i) & 64512) === 55296 && (str4.charCodeAt(i + 1) & 64512) === 56320) {
|
|
37941
|
-
|
|
38694
|
+
count2--;
|
|
37942
38695
|
i++;
|
|
37943
38696
|
}
|
|
37944
38697
|
}
|
|
37945
|
-
return
|
|
38698
|
+
return count2;
|
|
37946
38699
|
}
|
|
37947
38700
|
function getLengthableOrigin3(input) {
|
|
37948
38701
|
if (Array.isArray(input))
|
|
@@ -37991,16 +38744,16 @@ function cleanEnum3(obj) {
|
|
|
37991
38744
|
}
|
|
37992
38745
|
function base64ToUint8Array2(base645) {
|
|
37993
38746
|
const binaryString = atob(base645);
|
|
37994
|
-
const
|
|
38747
|
+
const bytes5 = new Uint8Array(binaryString.length);
|
|
37995
38748
|
for (let i = 0; i < binaryString.length; i++) {
|
|
37996
|
-
|
|
38749
|
+
bytes5[i] = binaryString.charCodeAt(i);
|
|
37997
38750
|
}
|
|
37998
|
-
return
|
|
38751
|
+
return bytes5;
|
|
37999
38752
|
}
|
|
38000
|
-
function uint8ArrayToBase642(
|
|
38753
|
+
function uint8ArrayToBase642(bytes5) {
|
|
38001
38754
|
let binaryString = "";
|
|
38002
|
-
for (let i = 0; i <
|
|
38003
|
-
binaryString += String.fromCharCode(
|
|
38755
|
+
for (let i = 0; i < bytes5.length; i++) {
|
|
38756
|
+
binaryString += String.fromCharCode(bytes5[i]);
|
|
38004
38757
|
}
|
|
38005
38758
|
return btoa(binaryString);
|
|
38006
38759
|
}
|
|
@@ -38009,30 +38762,30 @@ function base64urlToUint8Array2(base64url5) {
|
|
|
38009
38762
|
const padding = "=".repeat((4 - base645.length % 4) % 4);
|
|
38010
38763
|
return base64ToUint8Array2(base645 + padding);
|
|
38011
38764
|
}
|
|
38012
|
-
function uint8ArrayToBase64url2(
|
|
38013
|
-
return uint8ArrayToBase642(
|
|
38765
|
+
function uint8ArrayToBase64url2(bytes5) {
|
|
38766
|
+
return uint8ArrayToBase642(bytes5).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
38014
38767
|
}
|
|
38015
38768
|
function hexToUint8Array2(hex) {
|
|
38016
38769
|
const cleanHex = hex.replace(/^0x/, "");
|
|
38017
38770
|
if (cleanHex.length % 2 !== 0) {
|
|
38018
38771
|
throw new Error("Invalid hex string length");
|
|
38019
38772
|
}
|
|
38020
|
-
const
|
|
38773
|
+
const bytes5 = new Uint8Array(cleanHex.length / 2);
|
|
38021
38774
|
for (let i = 0; i < cleanHex.length; i += 2) {
|
|
38022
|
-
|
|
38775
|
+
bytes5[i / 2] = Number.parseInt(cleanHex.slice(i, i + 2), 16);
|
|
38023
38776
|
}
|
|
38024
|
-
return
|
|
38777
|
+
return bytes5;
|
|
38025
38778
|
}
|
|
38026
|
-
function uint8ArrayToHex2(
|
|
38027
|
-
return Array.from(
|
|
38779
|
+
function uint8ArrayToHex2(bytes5) {
|
|
38780
|
+
return Array.from(bytes5).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
38028
38781
|
}
|
|
38029
38782
|
var Class3 = class {
|
|
38030
38783
|
constructor(..._args) {
|
|
38031
38784
|
}
|
|
38032
38785
|
};
|
|
38033
|
-
function members2(proto,
|
|
38034
|
-
for (const key in
|
|
38035
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
38786
|
+
function members2(proto, table3) {
|
|
38787
|
+
for (const key in table3) {
|
|
38788
|
+
const desc = Object.getOwnPropertyDescriptor(table3, key);
|
|
38036
38789
|
if (desc.get)
|
|
38037
38790
|
Object.defineProperty(proto, key, { ...desc, enumerable: false });
|
|
38038
38791
|
else
|
|
@@ -38047,10 +38800,10 @@ function hide2(inst, key, value) {
|
|
|
38047
38800
|
return own3(inst, key, value, false);
|
|
38048
38801
|
}
|
|
38049
38802
|
// @__NO_SIDE_EFFECTS__
|
|
38050
|
-
function derived2(computes,
|
|
38803
|
+
function derived2(computes, table3) {
|
|
38051
38804
|
for (const key in computes) {
|
|
38052
38805
|
const compute = computes[key];
|
|
38053
|
-
Object.defineProperty(
|
|
38806
|
+
Object.defineProperty(table3, key, {
|
|
38054
38807
|
configurable: true,
|
|
38055
38808
|
enumerable: true,
|
|
38056
38809
|
get() {
|
|
@@ -38061,7 +38814,7 @@ function derived2(computes, table2) {
|
|
|
38061
38814
|
}
|
|
38062
38815
|
});
|
|
38063
38816
|
}
|
|
38064
|
-
return
|
|
38817
|
+
return table3;
|
|
38065
38818
|
}
|
|
38066
38819
|
function defineBound2(proto, key, fn) {
|
|
38067
38820
|
Object.defineProperty(proto, key, {
|
|
@@ -40655,17 +41408,17 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
40655
41408
|
var NONE4 = 0;
|
|
40656
41409
|
var ASSUMED2 = 1;
|
|
40657
41410
|
var PROVEN2 = 2;
|
|
40658
|
-
function isRecursive2(inst,
|
|
41411
|
+
function isRecursive2(inst, stack2, resolve8) {
|
|
40659
41412
|
const cached4 = recursive2.get(inst);
|
|
40660
41413
|
if (cached4 !== void 0)
|
|
40661
41414
|
return cached4 ? PROVEN2 : NONE4;
|
|
40662
|
-
if (
|
|
41415
|
+
if (stack2.has(inst))
|
|
40663
41416
|
return PROVEN2;
|
|
40664
|
-
|
|
41417
|
+
stack2.add(inst);
|
|
40665
41418
|
let result = NONE4;
|
|
40666
41419
|
const check2 = (child) => {
|
|
40667
41420
|
if (result !== PROVEN2 && child?._zod) {
|
|
40668
|
-
const answer2 = isRecursive2(child,
|
|
41421
|
+
const answer2 = isRecursive2(child, stack2, resolve8);
|
|
40669
41422
|
if (answer2 > result)
|
|
40670
41423
|
result = answer2;
|
|
40671
41424
|
}
|
|
@@ -40676,7 +41429,7 @@ function isRecursive2(inst, stack, resolve8) {
|
|
|
40676
41429
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
40677
41430
|
if (spread && !desc.enumerable)
|
|
40678
41431
|
continue;
|
|
40679
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value,
|
|
41432
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve8) : NONE4;
|
|
40680
41433
|
if (child > answer2)
|
|
40681
41434
|
answer2 = child;
|
|
40682
41435
|
}
|
|
@@ -40741,7 +41494,7 @@ function isRecursive2(inst, stack, resolve8) {
|
|
|
40741
41494
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
40742
41495
|
case "lazy": {
|
|
40743
41496
|
const inner = def._cachedInner ?? (resolve8 ? inst._zod.innerType : void 0);
|
|
40744
|
-
merge5(inner ? isRecursive2(inner,
|
|
41497
|
+
merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
|
|
40745
41498
|
break;
|
|
40746
41499
|
}
|
|
40747
41500
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -40784,7 +41537,7 @@ function isRecursive2(inst, stack, resolve8) {
|
|
|
40784
41537
|
}
|
|
40785
41538
|
}
|
|
40786
41539
|
}
|
|
40787
|
-
|
|
41540
|
+
stack2.delete(inst);
|
|
40788
41541
|
return settle2(inst, result);
|
|
40789
41542
|
}
|
|
40790
41543
|
function settle2(inst, answer2) {
|
|
@@ -43408,10 +44161,10 @@ var ZodNumber3 = /* @__PURE__ */ $constructor3(
|
|
|
43408
44161
|
return this.check(_lte3(value, params));
|
|
43409
44162
|
},
|
|
43410
44163
|
int(params) {
|
|
43411
|
-
return this.check(
|
|
44164
|
+
return this.check(int4(params));
|
|
43412
44165
|
},
|
|
43413
44166
|
safe(params) {
|
|
43414
|
-
return this.check(
|
|
44167
|
+
return this.check(int4(params));
|
|
43415
44168
|
},
|
|
43416
44169
|
positive(params) {
|
|
43417
44170
|
return this.check(_gt3(0, params));
|
|
@@ -43443,7 +44196,7 @@ var ZodNumberFormat3 = /* @__PURE__ */ $constructor3("ZodNumberFormat", (inst, d
|
|
|
43443
44196
|
$ZodNumberFormat3.init(inst, def);
|
|
43444
44197
|
ZodNumber3.init(inst, def);
|
|
43445
44198
|
});
|
|
43446
|
-
function
|
|
44199
|
+
function int4(params) {
|
|
43447
44200
|
return _int3(ZodNumberFormat3, params);
|
|
43448
44201
|
}
|
|
43449
44202
|
var ZodBoolean3 = /* @__PURE__ */ $constructor3("ZodBoolean", (inst, def) => {
|
|
@@ -48997,9 +49750,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
48997
49750
|
}
|
|
48998
49751
|
};
|
|
48999
49752
|
var Label = class extends Node2 {
|
|
49000
|
-
constructor(
|
|
49753
|
+
constructor(label2) {
|
|
49001
49754
|
super();
|
|
49002
|
-
this.label =
|
|
49755
|
+
this.label = label2;
|
|
49003
49756
|
this.names = {};
|
|
49004
49757
|
}
|
|
49005
49758
|
render({ _n }) {
|
|
@@ -49007,9 +49760,9 @@ var require_codegen = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
49007
49760
|
}
|
|
49008
49761
|
};
|
|
49009
49762
|
var Break = class extends Node2 {
|
|
49010
|
-
constructor(
|
|
49763
|
+
constructor(label2) {
|
|
49011
49764
|
super();
|
|
49012
|
-
this.label =
|
|
49765
|
+
this.label = label2;
|
|
49013
49766
|
this.names = {};
|
|
49014
49767
|
}
|
|
49015
49768
|
render({ _n }) {
|
|
@@ -49374,11 +50127,11 @@ var require_codegen = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
49374
50127
|
endFor() {
|
|
49375
50128
|
return this._endBlockNode(For);
|
|
49376
50129
|
}
|
|
49377
|
-
label(
|
|
49378
|
-
return this._leafNode(new Label(
|
|
50130
|
+
label(label2) {
|
|
50131
|
+
return this._leafNode(new Label(label2));
|
|
49379
50132
|
}
|
|
49380
|
-
break(
|
|
49381
|
-
return this._leafNode(new Break(
|
|
50133
|
+
break(label2) {
|
|
50134
|
+
return this._leafNode(new Break(label2));
|
|
49382
50135
|
}
|
|
49383
50136
|
return(value) {
|
|
49384
50137
|
const node3 = new Return();
|
|
@@ -50516,15 +51269,15 @@ var require_resolve = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
50516
51269
|
return false;
|
|
50517
51270
|
}
|
|
50518
51271
|
function countKeys(schema) {
|
|
50519
|
-
let
|
|
51272
|
+
let count2 = 0;
|
|
50520
51273
|
for (const key in schema) {
|
|
50521
51274
|
if (key === "$ref") return Infinity;
|
|
50522
|
-
|
|
51275
|
+
count2++;
|
|
50523
51276
|
if (SIMPLE_INLINED.has(key)) continue;
|
|
50524
|
-
if (typeof schema[key] == "object") (0, util_1.eachItem)(schema[key], (sch) =>
|
|
50525
|
-
if (
|
|
51277
|
+
if (typeof schema[key] == "object") (0, util_1.eachItem)(schema[key], (sch) => count2 += countKeys(sch));
|
|
51278
|
+
if (count2 === Infinity) return Infinity;
|
|
50526
51279
|
}
|
|
50527
|
-
return
|
|
51280
|
+
return count2;
|
|
50528
51281
|
}
|
|
50529
51282
|
function getFullPath(resolver, id = "", normalize2) {
|
|
50530
51283
|
if (normalize2 !== false) id = normalizeId(id);
|
|
@@ -53124,8 +53877,8 @@ var require_contains = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
53124
53877
|
cxt.result(valid, () => cxt.reset());
|
|
53125
53878
|
function validateItemsWithCount() {
|
|
53126
53879
|
const schValid = gen.name("_valid");
|
|
53127
|
-
const
|
|
53128
|
-
validateItems(schValid, () => gen.if(schValid, () => checkLimits(
|
|
53880
|
+
const count2 = gen.let("count", 0);
|
|
53881
|
+
validateItems(schValid, () => gen.if(schValid, () => checkLimits(count2)));
|
|
53129
53882
|
}
|
|
53130
53883
|
function validateItems(_valid, block) {
|
|
53131
53884
|
gen.forRange("i", 0, len, (i) => {
|
|
@@ -53138,13 +53891,13 @@ var require_contains = /* @__PURE__ */ __commonJSMin((exports) => {
|
|
|
53138
53891
|
block();
|
|
53139
53892
|
});
|
|
53140
53893
|
}
|
|
53141
|
-
function checkLimits(
|
|
53142
|
-
gen.code((0, codegen_1._)`${
|
|
53143
|
-
if (max === void 0) gen.if((0, codegen_1._)`${
|
|
53894
|
+
function checkLimits(count2) {
|
|
53895
|
+
gen.code((0, codegen_1._)`${count2}++`);
|
|
53896
|
+
if (max === void 0) gen.if((0, codegen_1._)`${count2} >= ${min}`, () => gen.assign(valid, true).break());
|
|
53144
53897
|
else {
|
|
53145
|
-
gen.if((0, codegen_1._)`${
|
|
53898
|
+
gen.if((0, codegen_1._)`${count2} > ${max}`, () => gen.assign(valid, false).break());
|
|
53146
53899
|
if (min === 1) gen.assign(valid, true);
|
|
53147
|
-
else gen.if((0, codegen_1._)`${
|
|
53900
|
+
else gen.if((0, codegen_1._)`${count2} >= ${min}`, () => gen.assign(valid, true));
|
|
53148
53901
|
}
|
|
53149
53902
|
}
|
|
53150
53903
|
}
|
|
@@ -55811,11 +56564,11 @@ function coerceEmbeddedInputRequest(method, key, entry) {
|
|
|
55811
56564
|
function syntheticElicitationId() {
|
|
55812
56565
|
const webCrypto = globalThis.crypto;
|
|
55813
56566
|
if (webCrypto?.randomUUID !== void 0) return webCrypto.randomUUID();
|
|
55814
|
-
const
|
|
55815
|
-
webCrypto.getRandomValues(
|
|
55816
|
-
|
|
55817
|
-
|
|
55818
|
-
const hex = [...
|
|
56567
|
+
const bytes5 = new Uint8Array(16);
|
|
56568
|
+
webCrypto.getRandomValues(bytes5);
|
|
56569
|
+
bytes5[6] = bytes5[6] & 15 | 64;
|
|
56570
|
+
bytes5[8] = bytes5[8] & 63 | 128;
|
|
56571
|
+
const hex = [...bytes5].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
55819
56572
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
55820
56573
|
}
|
|
55821
56574
|
function legacyShimFailure(method, message3) {
|
|
@@ -56547,23 +57300,23 @@ function discoverAdvertisedCapabilities(capabilities) {
|
|
|
56547
57300
|
return { ...capabilities };
|
|
56548
57301
|
}
|
|
56549
57302
|
function toolInputElementCount(value, max) {
|
|
56550
|
-
let
|
|
56551
|
-
const
|
|
56552
|
-
while (
|
|
56553
|
-
const node3 =
|
|
57303
|
+
let count2 = 0;
|
|
57304
|
+
const stack2 = [value];
|
|
57305
|
+
while (stack2.length > 0) {
|
|
57306
|
+
const node3 = stack2.pop();
|
|
56554
57307
|
if (node3 === null || typeof node3 !== "object") continue;
|
|
56555
57308
|
if (Array.isArray(node3)) for (const child of node3) {
|
|
56556
|
-
if (++
|
|
56557
|
-
if (child !== null && typeof child === "object")
|
|
57309
|
+
if (++count2 > max) return count2;
|
|
57310
|
+
if (child !== null && typeof child === "object") stack2.push(child);
|
|
56558
57311
|
}
|
|
56559
57312
|
else for (const key in node3) {
|
|
56560
57313
|
if (!Object.prototype.hasOwnProperty.call(node3, key)) continue;
|
|
56561
|
-
if (++
|
|
57314
|
+
if (++count2 > max) return count2;
|
|
56562
57315
|
const child = node3[key];
|
|
56563
|
-
if (child !== null && typeof child === "object")
|
|
57316
|
+
if (child !== null && typeof child === "object") stack2.push(child);
|
|
56564
57317
|
}
|
|
56565
57318
|
}
|
|
56566
|
-
return
|
|
57319
|
+
return count2;
|
|
56567
57320
|
}
|
|
56568
57321
|
function resolveMaxToolInputElements(value) {
|
|
56569
57322
|
if (value === void 0 || value === Infinity) return void 0;
|
|
@@ -56636,9 +57389,9 @@ var McpServer = class {
|
|
|
56636
57389
|
resolveScopeChallenge = (context) => {
|
|
56637
57390
|
switch (context.request.method) {
|
|
56638
57391
|
case "tools/call": {
|
|
56639
|
-
const
|
|
56640
|
-
if (typeof
|
|
56641
|
-
const tool = this._registeredTools[
|
|
57392
|
+
const toolName2 = context.request.params?.name;
|
|
57393
|
+
if (typeof toolName2 !== "string") return;
|
|
57394
|
+
const tool = this._registeredTools[toolName2];
|
|
56642
57395
|
if (tool === void 0 || !tool.enabled) return;
|
|
56643
57396
|
return tool.scopeChallenge?.(context);
|
|
56644
57397
|
}
|
|
@@ -56722,23 +57475,23 @@ var McpServer = class {
|
|
|
56722
57475
|
/**
|
|
56723
57476
|
* Validates tool input arguments against the tool's input schema.
|
|
56724
57477
|
*/
|
|
56725
|
-
async validateToolInput(tool, args,
|
|
56726
|
-
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${
|
|
57478
|
+
async validateToolInput(tool, args, toolName2) {
|
|
57479
|
+
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`);
|
|
56727
57480
|
if (!tool.inputSchema) return;
|
|
56728
57481
|
const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});
|
|
56729
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${
|
|
57482
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName2}: ${parseResult.error}`);
|
|
56730
57483
|
return parseResult.data;
|
|
56731
57484
|
}
|
|
56732
57485
|
/**
|
|
56733
57486
|
* Validates tool output against the tool's output schema.
|
|
56734
57487
|
*/
|
|
56735
|
-
async validateToolOutput(tool, result,
|
|
57488
|
+
async validateToolOutput(tool, result, toolName2) {
|
|
56736
57489
|
if (!tool.outputSchema) return;
|
|
56737
57490
|
if (isInputRequiredResult(result)) return;
|
|
56738
57491
|
if (result.isError) return;
|
|
56739
|
-
if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${
|
|
57492
|
+
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`);
|
|
56740
57493
|
const parseResult = await validateStandardSchema(tool.outputSchema, result.structuredContent);
|
|
56741
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${
|
|
57494
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName2}: ${parseResult.error}`);
|
|
56742
57495
|
}
|
|
56743
57496
|
/**
|
|
56744
57497
|
* Executes a tool handler.
|
|
@@ -57712,8 +58465,8 @@ function installExitGuard(opts) {
|
|
|
57712
58465
|
}
|
|
57713
58466
|
|
|
57714
58467
|
// src/core/store/cleanup.ts
|
|
57715
|
-
import { existsSync as
|
|
57716
|
-
import { join as
|
|
58468
|
+
import { existsSync as existsSync22, readdirSync as readdirSync10, rmSync as rmSync10 } from "node:fs";
|
|
58469
|
+
import { join as join25 } from "node:path";
|
|
57717
58470
|
function deleteSource(raw, id) {
|
|
57718
58471
|
raw.prepare("DELETE FROM sources WHERE id = ?").run(id);
|
|
57719
58472
|
deleteChunkRows(raw, { sourceId: id });
|
|
@@ -57748,7 +58501,7 @@ function userVersion(raw) {
|
|
|
57748
58501
|
return raw.prepare("PRAGMA user_version").get().user_version;
|
|
57749
58502
|
}
|
|
57750
58503
|
function openForSweep(dbPath, projectKey) {
|
|
57751
|
-
if (!
|
|
58504
|
+
if (!existsSync22(dbPath) && (existsSync22(dbPath + DB_WAL_SUFFIX) || existsSync22(dbPath + DB_SHM_SUFFIX))) {
|
|
57752
58505
|
throw new CtxError("DB_GONE");
|
|
57753
58506
|
}
|
|
57754
58507
|
const sqlite = process.getBuiltinModule("node:sqlite");
|
|
@@ -57769,8 +58522,8 @@ function lastAccess(raw) {
|
|
|
57769
58522
|
return row5.t;
|
|
57770
58523
|
}
|
|
57771
58524
|
function sweepOne(configDir, projectKey, cutoff) {
|
|
57772
|
-
const dir =
|
|
57773
|
-
const db = openForSweep(
|
|
58525
|
+
const dir = join25(configDir, PROJECTS_DIR_NAME, projectKey);
|
|
58526
|
+
const db = openForSweep(join25(dir, DB_FILE_NAME), projectKey);
|
|
57774
58527
|
let dead;
|
|
57775
58528
|
try {
|
|
57776
58529
|
dead = withWrite(db, (h) => listLiveOwners(configDir, projectKey).length === 0 && lastAccess(h.raw) < cutoff);
|
|
@@ -57783,7 +58536,7 @@ function sweepOne(configDir, projectKey, cutoff) {
|
|
|
57783
58536
|
function sweepDeadProjects(configDir) {
|
|
57784
58537
|
let entries;
|
|
57785
58538
|
try {
|
|
57786
|
-
entries = readdirSync10(
|
|
58539
|
+
entries = readdirSync10(join25(configDir, PROJECTS_DIR_NAME), { withFileTypes: true });
|
|
57787
58540
|
} catch (err) {
|
|
57788
58541
|
if (err.code === "ENOENT") return [];
|
|
57789
58542
|
throw err;
|
|
@@ -57802,12 +58555,12 @@ function sweepDeadProjects(configDir) {
|
|
|
57802
58555
|
}
|
|
57803
58556
|
|
|
57804
58557
|
// src/entries/is-entry.ts
|
|
57805
|
-
import { realpathSync as
|
|
58558
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
57806
58559
|
function isEntry(main, argv1, self) {
|
|
57807
58560
|
if (main !== void 0) return main;
|
|
57808
58561
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
57809
58562
|
try {
|
|
57810
|
-
return
|
|
58563
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
57811
58564
|
} catch {
|
|
57812
58565
|
return false;
|
|
57813
58566
|
}
|
|
@@ -57883,7 +58636,7 @@ function workspaceFromMeta(meta3) {
|
|
|
57883
58636
|
}
|
|
57884
58637
|
function realOrSame(p) {
|
|
57885
58638
|
try {
|
|
57886
|
-
return
|
|
58639
|
+
return realpathSync12.native(p);
|
|
57887
58640
|
} catch {
|
|
57888
58641
|
return p;
|
|
57889
58642
|
}
|
|
@@ -57902,7 +58655,7 @@ function errorReply(err) {
|
|
|
57902
58655
|
async function startServer(argv, env) {
|
|
57903
58656
|
const serverId = randomUUID();
|
|
57904
58657
|
const degraded = await isDegraded();
|
|
57905
|
-
const tools = degraded ?
|
|
58658
|
+
const tools = degraded ? TOOLS2.filter((t) => t.name === "ctx_doctor") : TOOLS2;
|
|
57906
58659
|
const pending = /* @__PURE__ */ new Map();
|
|
57907
58660
|
const held = [];
|
|
57908
58661
|
let cleaned = false;
|
|
@@ -57931,15 +58684,15 @@ async function startServer(argv, env) {
|
|
|
57931
58684
|
opening.catch(() => pending.delete(project.dbPath));
|
|
57932
58685
|
}
|
|
57933
58686
|
const db = await opening;
|
|
57934
|
-
if (!
|
|
58687
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
57935
58688
|
return db;
|
|
57936
58689
|
}
|
|
57937
58690
|
function stopMarker(configDir, projectKey) {
|
|
57938
|
-
return
|
|
58691
|
+
return join26(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
57939
58692
|
}
|
|
57940
58693
|
function stopRequested() {
|
|
57941
58694
|
const configDir = resolveConfigDir(process.env);
|
|
57942
|
-
return held.some((db) =>
|
|
58695
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
57943
58696
|
}
|
|
57944
58697
|
async function journal(project, ctx, name, reply4) {
|
|
57945
58698
|
const db = await ownDb(project);
|
|
@@ -58124,7 +58877,7 @@ function piExtension(pi) {
|
|
|
58124
58877
|
function registerTools() {
|
|
58125
58878
|
if (toolsRegistered) return;
|
|
58126
58879
|
try {
|
|
58127
|
-
for (const tool of
|
|
58880
|
+
for (const tool of TOOLS2) pi.registerTool(piTool(tool));
|
|
58128
58881
|
toolsRegistered = true;
|
|
58129
58882
|
} catch {
|
|
58130
58883
|
}
|