context-mode 2.0.0-next.30 → 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 +22 -22
- package/SHA256SUMS +15 -15
- package/cli.mjs +325 -155
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +75 -75
- package/opencode/plugin.js +636 -149
- package/package.json +1 -1
- package/pi/index.js +678 -191
- package/qwen-extension.json +1 -1
- package/run.mjs +66 -5
- package/search.mjs +66 -5
- package/server.mjs +665 -178
package/server.mjs
CHANGED
|
@@ -7,8 +7,8 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
11
|
-
import { dirname as dirname11, join as
|
|
10
|
+
import { existsSync as existsSync23, realpathSync as realpathSync12, rmSync as rmSync11 } from "node:fs";
|
|
11
|
+
import { dirname as dirname11, join as join23 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13
13
|
|
|
14
14
|
// node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
|
|
@@ -3487,17 +3487,17 @@ var recursive = /* @__PURE__ */ new WeakMap();
|
|
|
3487
3487
|
var NONE = 0;
|
|
3488
3488
|
var ASSUMED = 1;
|
|
3489
3489
|
var PROVEN = 2;
|
|
3490
|
-
function isRecursive(inst,
|
|
3490
|
+
function isRecursive(inst, stack2, resolve6) {
|
|
3491
3491
|
const cached4 = recursive.get(inst);
|
|
3492
3492
|
if (cached4 !== void 0)
|
|
3493
3493
|
return cached4 ? PROVEN : NONE;
|
|
3494
|
-
if (
|
|
3494
|
+
if (stack2.has(inst))
|
|
3495
3495
|
return PROVEN;
|
|
3496
|
-
|
|
3496
|
+
stack2.add(inst);
|
|
3497
3497
|
let result = NONE;
|
|
3498
3498
|
const check2 = (child) => {
|
|
3499
3499
|
if (result !== PROVEN && child?._zod) {
|
|
3500
|
-
const answer2 = isRecursive(child,
|
|
3500
|
+
const answer2 = isRecursive(child, stack2, resolve6);
|
|
3501
3501
|
if (answer2 > result)
|
|
3502
3502
|
result = answer2;
|
|
3503
3503
|
}
|
|
@@ -3508,7 +3508,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
3508
3508
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
3509
3509
|
if (spread && !desc.enumerable)
|
|
3510
3510
|
continue;
|
|
3511
|
-
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value,
|
|
3511
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack2, resolve6) : NONE;
|
|
3512
3512
|
if (child > answer2)
|
|
3513
3513
|
answer2 = child;
|
|
3514
3514
|
}
|
|
@@ -3573,7 +3573,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
3573
3573
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
3574
3574
|
case "lazy": {
|
|
3575
3575
|
const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
|
|
3576
|
-
merge5(inner ? isRecursive(inner,
|
|
3576
|
+
merge5(inner ? isRecursive(inner, stack2, false) : ASSUMED);
|
|
3577
3577
|
break;
|
|
3578
3578
|
}
|
|
3579
3579
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -3616,7 +3616,7 @@ function isRecursive(inst, stack, resolve6) {
|
|
|
3616
3616
|
}
|
|
3617
3617
|
}
|
|
3618
3618
|
}
|
|
3619
|
-
|
|
3619
|
+
stack2.delete(inst);
|
|
3620
3620
|
return settle(inst, result);
|
|
3621
3621
|
}
|
|
3622
3622
|
function settle(inst, answer2) {
|
|
@@ -11016,17 +11016,17 @@ var recursive2 = /* @__PURE__ */ new WeakMap();
|
|
|
11016
11016
|
var NONE2 = 0;
|
|
11017
11017
|
var ASSUMED2 = 1;
|
|
11018
11018
|
var PROVEN2 = 2;
|
|
11019
|
-
function isRecursive2(inst,
|
|
11019
|
+
function isRecursive2(inst, stack2, resolve6) {
|
|
11020
11020
|
const cached4 = recursive2.get(inst);
|
|
11021
11021
|
if (cached4 !== void 0)
|
|
11022
11022
|
return cached4 ? PROVEN2 : NONE2;
|
|
11023
|
-
if (
|
|
11023
|
+
if (stack2.has(inst))
|
|
11024
11024
|
return PROVEN2;
|
|
11025
|
-
|
|
11025
|
+
stack2.add(inst);
|
|
11026
11026
|
let result = NONE2;
|
|
11027
11027
|
const check2 = (child) => {
|
|
11028
11028
|
if (result !== PROVEN2 && child?._zod) {
|
|
11029
|
-
const answer2 = isRecursive2(child,
|
|
11029
|
+
const answer2 = isRecursive2(child, stack2, resolve6);
|
|
11030
11030
|
if (answer2 > result)
|
|
11031
11031
|
result = answer2;
|
|
11032
11032
|
}
|
|
@@ -11037,7 +11037,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
11037
11037
|
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
11038
11038
|
if (spread && !desc.enumerable)
|
|
11039
11039
|
continue;
|
|
11040
|
-
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value,
|
|
11040
|
+
const child = desc.get ? ASSUMED2 : desc.value?._zod ? isRecursive2(desc.value, stack2, resolve6) : NONE2;
|
|
11041
11041
|
if (child > answer2)
|
|
11042
11042
|
answer2 = child;
|
|
11043
11043
|
}
|
|
@@ -11102,7 +11102,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
11102
11102
|
// `$ZodLazy` caches its inner on the def, so a resolved edge is followed exactly
|
|
11103
11103
|
case "lazy": {
|
|
11104
11104
|
const inner = def._cachedInner ?? (resolve6 ? inst._zod.innerType : void 0);
|
|
11105
|
-
merge5(inner ? isRecursive2(inner,
|
|
11105
|
+
merge5(inner ? isRecursive2(inner, stack2, false) : ASSUMED2);
|
|
11106
11106
|
break;
|
|
11107
11107
|
}
|
|
11108
11108
|
// a leaf by choice: `parts` are regex fragments, not data positions
|
|
@@ -11145,7 +11145,7 @@ function isRecursive2(inst, stack, resolve6) {
|
|
|
11145
11145
|
}
|
|
11146
11146
|
}
|
|
11147
11147
|
}
|
|
11148
|
-
|
|
11148
|
+
stack2.delete(inst);
|
|
11149
11149
|
return settle2(inst, result);
|
|
11150
11150
|
}
|
|
11151
11151
|
function settle2(inst, answer2) {
|
|
@@ -26909,19 +26909,19 @@ function discoverAdvertisedCapabilities(capabilities) {
|
|
|
26909
26909
|
}
|
|
26910
26910
|
function toolInputElementCount(value, max) {
|
|
26911
26911
|
let count2 = 0;
|
|
26912
|
-
const
|
|
26913
|
-
while (
|
|
26914
|
-
const node3 =
|
|
26912
|
+
const stack2 = [value];
|
|
26913
|
+
while (stack2.length > 0) {
|
|
26914
|
+
const node3 = stack2.pop();
|
|
26915
26915
|
if (node3 === null || typeof node3 !== "object") continue;
|
|
26916
26916
|
if (Array.isArray(node3)) for (const child of node3) {
|
|
26917
26917
|
if (++count2 > max) return count2;
|
|
26918
|
-
if (child !== null && typeof child === "object")
|
|
26918
|
+
if (child !== null && typeof child === "object") stack2.push(child);
|
|
26919
26919
|
}
|
|
26920
26920
|
else for (const key in node3) {
|
|
26921
26921
|
if (!Object.prototype.hasOwnProperty.call(node3, key)) continue;
|
|
26922
26922
|
if (++count2 > max) return count2;
|
|
26923
26923
|
const child = node3[key];
|
|
26924
|
-
if (child !== null && typeof child === "object")
|
|
26924
|
+
if (child !== null && typeof child === "object") stack2.push(child);
|
|
26925
26925
|
}
|
|
26926
26926
|
}
|
|
26927
26927
|
return count2;
|
|
@@ -26997,9 +26997,9 @@ var McpServer = class {
|
|
|
26997
26997
|
resolveScopeChallenge = (context) => {
|
|
26998
26998
|
switch (context.request.method) {
|
|
26999
26999
|
case "tools/call": {
|
|
27000
|
-
const
|
|
27001
|
-
if (typeof
|
|
27002
|
-
const tool = this._registeredTools[
|
|
27000
|
+
const toolName2 = context.request.params?.name;
|
|
27001
|
+
if (typeof toolName2 !== "string") return;
|
|
27002
|
+
const tool = this._registeredTools[toolName2];
|
|
27003
27003
|
if (tool === void 0 || !tool.enabled) return;
|
|
27004
27004
|
return tool.scopeChallenge?.(context);
|
|
27005
27005
|
}
|
|
@@ -27083,23 +27083,23 @@ var McpServer = class {
|
|
|
27083
27083
|
/**
|
|
27084
27084
|
* Validates tool input arguments against the tool's input schema.
|
|
27085
27085
|
*/
|
|
27086
|
-
async validateToolInput(tool, args,
|
|
27087
|
-
if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${
|
|
27086
|
+
async validateToolInput(tool, args, toolName2) {
|
|
27087
|
+
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`);
|
|
27088
27088
|
if (!tool.inputSchema) return;
|
|
27089
27089
|
const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});
|
|
27090
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${
|
|
27090
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName2}: ${parseResult.error}`);
|
|
27091
27091
|
return parseResult.data;
|
|
27092
27092
|
}
|
|
27093
27093
|
/**
|
|
27094
27094
|
* Validates tool output against the tool's output schema.
|
|
27095
27095
|
*/
|
|
27096
|
-
async validateToolOutput(tool, result,
|
|
27096
|
+
async validateToolOutput(tool, result, toolName2) {
|
|
27097
27097
|
if (!tool.outputSchema) return;
|
|
27098
27098
|
if (isInputRequiredResult(result)) return;
|
|
27099
27099
|
if (result.isError) return;
|
|
27100
|
-
if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${
|
|
27100
|
+
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`);
|
|
27101
27101
|
const parseResult = await validateStandardSchema(tool.outputSchema, result.structuredContent);
|
|
27102
|
-
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${
|
|
27102
|
+
if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName2}: ${parseResult.error}`);
|
|
27103
27103
|
}
|
|
27104
27104
|
/**
|
|
27105
27105
|
* Executes a tool handler.
|
|
@@ -28246,6 +28246,7 @@ var SOURCE_LABEL_MAX_CHARS = 80;
|
|
|
28246
28246
|
var CANCELLED_LINE = "Cancelled.";
|
|
28247
28247
|
var BACKGROUND_REPLY_PREFIX = "started in background, pid ";
|
|
28248
28248
|
var PLAIN_OUTPUT_ENV = Object.freeze({ NO_COLOR: "1", FORCE_COLOR: "0" });
|
|
28249
|
+
var RUN_LABEL_PREFIX = "run.mjs:";
|
|
28249
28250
|
var RUN_SESSION_PREFIX = "mcp:";
|
|
28250
28251
|
var HOST_SESSION_ENV = Object.freeze({ "claude-code": "CLAUDE_CODE_SESSION_ID" });
|
|
28251
28252
|
var NODE_MIN = "24.15.0";
|
|
@@ -28365,17 +28366,34 @@ var STATS_EMPTY_LINES = Object.freeze([
|
|
|
28365
28366
|
"sandbox, and only the short answer goes to the chat."
|
|
28366
28367
|
]);
|
|
28367
28368
|
var STATS_KIND_LABELS = Object.freeze([
|
|
28368
|
-
|
|
28369
|
+
// D-STATS-FIX-1 (8): the first five rows are call kinds, so they add up to the calls of the scope line.
|
|
28369
28370
|
["index", "Content indexed"],
|
|
28370
28371
|
["edit", "File edits"],
|
|
28371
|
-
["toolerr", "
|
|
28372
|
+
["toolerr", "Issues kept"],
|
|
28372
28373
|
["decision", "Your decisions"],
|
|
28374
|
+
["cmd", "Other tool calls"],
|
|
28373
28375
|
["prompt", "Your prompts"]
|
|
28374
28376
|
]);
|
|
28375
28377
|
var STATS_JOURNAL_HINTS = Object.freeze([
|
|
28376
|
-
"ctx_resume brings back your last task, files changed and open
|
|
28378
|
+
"ctx_resume brings back your last task, files changed and open issues",
|
|
28377
28379
|
"after a compact or a restart; ctx_search finds indexed content by words."
|
|
28378
28380
|
]);
|
|
28381
|
+
var STATS_WINDOW_TOKENS = 2e5;
|
|
28382
|
+
var STATS_THOUSAND = 1e3;
|
|
28383
|
+
var STATS_WHOLE_FROM = 10;
|
|
28384
|
+
var STATS_DAYS = 7;
|
|
28385
|
+
var STATS_TOP_OUTPUTS = 3;
|
|
28386
|
+
var STATS_CARD_W = 19;
|
|
28387
|
+
var STATS_DAY_BAR = 48;
|
|
28388
|
+
var STATS_TOKEN_NOTE = " (at 4 bytes per token; a Claude context window is 200K tokens)";
|
|
28389
|
+
var STATS_WAYS = Object.freeze([
|
|
28390
|
+
["sandbox", "\u2588", "sandbox run"],
|
|
28391
|
+
["index", "\u2593", "index + search"],
|
|
28392
|
+
["redirect", "\u2592", "hook sent to sandbox"],
|
|
28393
|
+
["replace", "\u2591", "hook cut down"]
|
|
28394
|
+
]);
|
|
28395
|
+
var STATS_INDEX_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
|
|
28396
|
+
var STATS_FOOTER_URL = "https://contextmode.ai/?utm_source=ctx_stats&utm_medium=stats&utm_content=footer";
|
|
28379
28397
|
var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
|
|
28380
28398
|
var PURGE_NO_SCOPE_LINE = "ctx_purge: pick one scope \u2014 session, source, or project.";
|
|
28381
28399
|
var PURGE_MANY_SCOPES_LINE = "ctx_purge: pick only one scope \u2014 session, source, or project.";
|
|
@@ -28387,7 +28405,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28387
28405
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28388
28406
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28389
28407
|
var RELEASE_BRANCH = "release";
|
|
28390
|
-
var BUNDLE_SHA = true ? "
|
|
28408
|
+
var BUNDLE_SHA = true ? "feb8de116956b3d3eff56c7d5ed2d840483d0cd4" : void 0;
|
|
28391
28409
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28392
28410
|
var DOCTOR_LABEL = Object.freeze({
|
|
28393
28411
|
D1: "version",
|
|
@@ -28417,7 +28435,7 @@ function DOCTOR_FAIL_LINE(host, check2, cause, command) {
|
|
|
28417
28435
|
return `FAIL ${host}: ${check2} \u2014 ${cause}. Fix: ${command}`;
|
|
28418
28436
|
}
|
|
28419
28437
|
var DOCTOR_FIX_UPGRADE = "run ctx_upgrade";
|
|
28420
|
-
var D1_DEV_BUILD_DETAIL = "dev build";
|
|
28438
|
+
var D1_DEV_BUILD_DETAIL = "dev build: source checkout; release builds stamp the sha";
|
|
28421
28439
|
var D1_UPDATE_DETAIL = "update available";
|
|
28422
28440
|
var D1_SHORT_SHA_LEN = 7;
|
|
28423
28441
|
var D1_PACKAGE_FILE = "package.json";
|
|
@@ -28748,7 +28766,7 @@ var V1_REASON = Object.freeze({
|
|
|
28748
28766
|
dataDir: "old context-mode data dir <agent home>/context-mode/",
|
|
28749
28767
|
dataDirShared: "old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",
|
|
28750
28768
|
dataRoot: "old context-mode content under ~/.context-mode/",
|
|
28751
|
-
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only,
|
|
28769
|
+
tmpFile: "old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"
|
|
28752
28770
|
});
|
|
28753
28771
|
var UPGRADE_REPORT_ONLY_REASONS = Object.freeze([V1_REASON.statusLine, V1_REASON.vscodeMcp, V1_REASON.dataDirShared, V1_REASON.tmpFile, V1_REASON.kiroSteering]);
|
|
28754
28772
|
var PLUGIN_NAME = SERVER_KEY;
|
|
@@ -28789,6 +28807,85 @@ var REPORT_ENV_PREFIX = "env.";
|
|
|
28789
28807
|
var REPORT_ENV_ENUMS = Object.freeze({
|
|
28790
28808
|
NODE_ENV: Object.freeze(["development", "production", "test"])
|
|
28791
28809
|
});
|
|
28810
|
+
var DOCTOR_ENV_PREFIX = "Environment: ";
|
|
28811
|
+
var DOCTOR_DOCS_URL = "https://contextmode.ai/docs/engine/doctor";
|
|
28812
|
+
var DOCTOR_DOCS_ANCHOR = "checks";
|
|
28813
|
+
function DOCTOR_DOCS_LINK(check2) {
|
|
28814
|
+
return `${DOCTOR_DOCS_URL}?utm_source=ctx_doctor&utm_medium=doctor&utm_content=${check2}#${DOCTOR_DOCS_ANCHOR}`;
|
|
28815
|
+
}
|
|
28816
|
+
var DOCTOR_DOCS_LABEL = "Docs: ";
|
|
28817
|
+
function D3_NO_SETUP_FIX(agent) {
|
|
28818
|
+
return `context-mode setup --agents ${agent}`;
|
|
28819
|
+
}
|
|
28820
|
+
function D5_FIXTURE_FILE_ABSENT(file2) {
|
|
28821
|
+
return `hook fixture ${file2} is absent: the round trip needs it`;
|
|
28822
|
+
}
|
|
28823
|
+
function D5_FIXTURE_PARSE(file2, cause) {
|
|
28824
|
+
return `the hook fixture file ${file2} failed to parse: ${cause}`;
|
|
28825
|
+
}
|
|
28826
|
+
function D5_FIXTURE_AGENT_ABSENT(file2, keys) {
|
|
28827
|
+
return `the hook fixture file ${file2} records payloads for ${keys.join(", ") || "zero agents"} only`;
|
|
28828
|
+
}
|
|
28829
|
+
var DOCTOR_REPORTS_DIR = "reports";
|
|
28830
|
+
var DOCTOR_REPORT_FILE_PREFIX = "doctor-";
|
|
28831
|
+
var DOCTOR_REPORT_LINE = "Report file: ";
|
|
28832
|
+
var DOCTOR_GH_LINE = "File it: ";
|
|
28833
|
+
var DOCTOR_URL_LINE = "Or open: ";
|
|
28834
|
+
var DOCTOR_GH_NEXT = " --";
|
|
28835
|
+
var DOCTOR_NOTE_PREFIXES = Object.freeze([
|
|
28836
|
+
DOCTOR_ENV_PREFIX,
|
|
28837
|
+
DOCTOR_DOCS_LABEL,
|
|
28838
|
+
DOCTOR_REPORT_LINE,
|
|
28839
|
+
DOCTOR_GH_LINE,
|
|
28840
|
+
DOCTOR_GH_NEXT.trim(),
|
|
28841
|
+
DOCTOR_URL_LINE
|
|
28842
|
+
]);
|
|
28843
|
+
var ISSUE_REPO_SLUG = "mksglu/context-mode";
|
|
28844
|
+
var ISSUE_FORM_FILE = "agent-report.yml";
|
|
28845
|
+
var ISSUE_URL_MAX = 8e3;
|
|
28846
|
+
var ISSUE_FORM_HEADINGS = Object.freeze([
|
|
28847
|
+
"Summary",
|
|
28848
|
+
"ctx-report",
|
|
28849
|
+
"What happened",
|
|
28850
|
+
"Hook errors",
|
|
28851
|
+
"Journal rows",
|
|
28852
|
+
"Agent config",
|
|
28853
|
+
"Expected",
|
|
28854
|
+
"Steps",
|
|
28855
|
+
"Environment"
|
|
28856
|
+
]);
|
|
28857
|
+
var DOCTOR_HOOK_LOG_LINES = 50;
|
|
28858
|
+
var DOCTOR_JOURNAL_ROWS = 30;
|
|
28859
|
+
var DOCTOR_CONFIG_LINES = 40;
|
|
28860
|
+
var DOCTOR_ENV_NAMES = Object.freeze([
|
|
28861
|
+
"CODEX_HOME",
|
|
28862
|
+
"CLAUDE_CONFIG_DIR",
|
|
28863
|
+
"CLAUDE_PLUGIN_ROOT",
|
|
28864
|
+
"COPILOT_HOME",
|
|
28865
|
+
"KIRO_HOME",
|
|
28866
|
+
"OPENCODE_CONFIG_DIR",
|
|
28867
|
+
"PI_CODING_AGENT_DIR",
|
|
28868
|
+
"XDG_CONFIG_HOME",
|
|
28869
|
+
"SHELL"
|
|
28870
|
+
]);
|
|
28871
|
+
var DOCTOR_PATH_TOOLS = Object.freeze(["node", "git", "sh"]);
|
|
28872
|
+
var DOCTOR_SECRET_WORDS = Object.freeze(["token", "secret", "password", "apikey", "api_key", "authorization", "bearer"]);
|
|
28873
|
+
var DOCTOR_MASK = "<masked>";
|
|
28874
|
+
var NATIVE_INSTALL = Object.freeze({
|
|
28875
|
+
"claude-code": ["claude plugin marketplace add mksglu/context-mode#release", "claude plugin install context-mode@context-mode"],
|
|
28876
|
+
codex: ["codex plugin marketplace add mksglu/context-mode@release", "codex plugin add context-mode@context-mode"],
|
|
28877
|
+
gemini: ["gemini extensions install https://github.com/mksglu/context-mode --ref release"],
|
|
28878
|
+
qwen: ["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],
|
|
28879
|
+
opencode: ["opencode plugin add context-mode@next"],
|
|
28880
|
+
pi: ["pi install npm:context-mode@next"],
|
|
28881
|
+
"copilot-cli": ["npm i -g context-mode@next", "context-mode setup --agents copilot-cli"],
|
|
28882
|
+
vscode: ["npm i -g context-mode@next", "context-mode setup --agents vscode"],
|
|
28883
|
+
kiro: ["npm i -g context-mode@next", "context-mode setup --agents kiro"],
|
|
28884
|
+
zcode: ["npm i -g context-mode@next", "context-mode setup --agents zcode"]
|
|
28885
|
+
});
|
|
28886
|
+
var ISSUE_FORM_URL = `https://github.com/${ISSUE_REPO_SLUG}/issues/new?template=${ISSUE_FORM_FILE}`;
|
|
28887
|
+
var DOCTOR_GIT_VERSION_TIMEOUT_MS = 5e3;
|
|
28888
|
+
var DOCTOR_LOG_TAIL_BYTES = 262144;
|
|
28792
28889
|
|
|
28793
28890
|
// src/core/contracts/errors.ts
|
|
28794
28891
|
var ERROR_TEXT = Object.freeze({
|
|
@@ -29538,8 +29635,8 @@ function firstLine(file2) {
|
|
|
29538
29635
|
return line === "" ? null : line;
|
|
29539
29636
|
}
|
|
29540
29637
|
function git(dir, args) {
|
|
29541
|
-
const { spawnSync:
|
|
29542
|
-
const r =
|
|
29638
|
+
const { spawnSync: spawnSync4 } = process.getBuiltinModule("node:child_process");
|
|
29639
|
+
const r = spawnSync4("git", args, { cwd: dir, shell: false, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
29543
29640
|
if (r.error !== void 0 || r.status !== 0) throw new CtxError("NO_GIT_DIR", { path: dir });
|
|
29544
29641
|
return r.stdout.split("\n").filter((l) => l !== "");
|
|
29545
29642
|
}
|
|
@@ -31727,8 +31824,8 @@ function trigramMatch(q) {
|
|
|
31727
31824
|
const words = blankTokens(q);
|
|
31728
31825
|
const kept = words.filter((w) => !STOPWORDS.has(w.toLowerCase()));
|
|
31729
31826
|
const parts = new Set((kept.length > 0 ? kept : words).filter((w) => [...w].length >= 3));
|
|
31730
|
-
const
|
|
31731
|
-
if (words.length > 1 && [...
|
|
31827
|
+
const whole2 = words.join(" ");
|
|
31828
|
+
if (words.length > 1 && [...whole2].length >= 3) parts.add(whole2);
|
|
31732
31829
|
return [...parts].map((w) => `"${w.replaceAll('"', '""')}"`).join(" OR ");
|
|
31733
31830
|
}
|
|
31734
31831
|
function editDistance(a, b, max) {
|
|
@@ -43340,7 +43437,7 @@ var TOOL_DESCRIPTIONS = Object.freeze({
|
|
|
43340
43437
|
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.',
|
|
43341
43438
|
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.",
|
|
43342
43439
|
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.",
|
|
43343
|
-
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
|
|
43440
|
+
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",
|
|
43344
43441
|
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.",
|
|
43345
43442
|
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.'
|
|
43346
43443
|
});
|
|
@@ -43374,7 +43471,7 @@ function chunkText(text, kind, maxBytes = MAX_CHUNK_BYTES) {
|
|
|
43374
43471
|
}
|
|
43375
43472
|
function mdChunks(src, cap, lineCut) {
|
|
43376
43473
|
const out = [];
|
|
43377
|
-
const
|
|
43474
|
+
const stack2 = [];
|
|
43378
43475
|
let title = "";
|
|
43379
43476
|
let run = [];
|
|
43380
43477
|
const push = (text, bytes5) => {
|
|
@@ -43388,9 +43485,9 @@ function mdChunks(src, cap, lineCut) {
|
|
|
43388
43485
|
for (const b of lineBlocks(src, true)) {
|
|
43389
43486
|
if (b.heading !== void 0) {
|
|
43390
43487
|
flush();
|
|
43391
|
-
while (
|
|
43392
|
-
|
|
43393
|
-
title =
|
|
43488
|
+
while (stack2.length > 0 && stack2[stack2.length - 1].level >= b.heading.level) stack2.pop();
|
|
43489
|
+
stack2.push(b.heading);
|
|
43490
|
+
title = stack2.map((h) => h.text).join(" > ");
|
|
43394
43491
|
}
|
|
43395
43492
|
if (b.fence !== void 0 && utf8Bytes(src.slice(b.start, b.end)) > cap) {
|
|
43396
43493
|
const pieces = fencePieces(src, b, b.fence, cap);
|
|
@@ -43623,7 +43720,7 @@ function cutPoint(src, start, end, scratch) {
|
|
|
43623
43720
|
const r = encoder.encodeInto(src.slice(start, limit), scratch);
|
|
43624
43721
|
return { end: start + r.read, written: r.written };
|
|
43625
43722
|
}
|
|
43626
|
-
function merge4(src, blocks,
|
|
43723
|
+
function merge4(src, blocks, join24, cap, lineCut) {
|
|
43627
43724
|
const out = [];
|
|
43628
43725
|
const scratch = new Uint8Array(cap);
|
|
43629
43726
|
let wide;
|
|
@@ -43633,7 +43730,7 @@ function merge4(src, blocks, join23, cap, lineCut) {
|
|
|
43633
43730
|
out.push({ ord: out.length, text: src.slice(start, end), bytes: bytes5 });
|
|
43634
43731
|
};
|
|
43635
43732
|
for (const b of blocks) {
|
|
43636
|
-
if (cur !== void 0 && !
|
|
43733
|
+
if (cur !== void 0 && !join24) {
|
|
43637
43734
|
emit(cur.start, cur.end, curBytes);
|
|
43638
43735
|
cur = void 0;
|
|
43639
43736
|
}
|
|
@@ -43731,9 +43828,9 @@ import { accessSync, constants as fsConstants, statSync as statSync2 } from "nod
|
|
|
43731
43828
|
import path from "node:path";
|
|
43732
43829
|
|
|
43733
43830
|
// src/core/sandbox/path-entries.ts
|
|
43734
|
-
function pathEntries(value, platform = process.platform,
|
|
43831
|
+
function pathEntries(value, platform = process.platform, delimiter2 = platform === "win32" ? ";" : ":") {
|
|
43735
43832
|
const win = platform === "win32";
|
|
43736
|
-
return value.split(
|
|
43833
|
+
return value.split(delimiter2).map((e) => win && e.length >= 2 && e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e).filter(Boolean);
|
|
43737
43834
|
}
|
|
43738
43835
|
|
|
43739
43836
|
// src/core/sandbox/runtimes.ts
|
|
@@ -43965,8 +44062,8 @@ function jsonRows(text) {
|
|
|
43965
44062
|
return { objs, keys };
|
|
43966
44063
|
}
|
|
43967
44064
|
function fitRow(row5, skewed, named, budget) {
|
|
43968
|
-
const
|
|
43969
|
-
if (bytes(
|
|
44065
|
+
const whole2 = JSON.stringify(row5);
|
|
44066
|
+
if (bytes(whole2) <= budget) return whole2;
|
|
43970
44067
|
const own4 = Object.keys(row5);
|
|
43971
44068
|
const tier = (k) => skewed.includes(k) ? 0 : named.has(k) ? 1 : typeof row5[k] !== "object" || row5[k] === null ? 2 : 3;
|
|
43972
44069
|
const order = [...own4].sort((a, b) => tier(a) - tier(b) || own4.indexOf(a) - own4.indexOf(b));
|
|
@@ -44452,8 +44549,8 @@ var ctxBatch = Object.freeze({
|
|
|
44452
44549
|
});
|
|
44453
44550
|
|
|
44454
44551
|
// src/core/tools/doctor.ts
|
|
44455
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
44456
|
-
import { basename as basename4, dirname as dirname6, join as
|
|
44552
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync10, existsSync as existsSync14 } from "node:fs";
|
|
44553
|
+
import { basename as basename4, dirname as dirname6, join as join13 } from "node:path";
|
|
44457
44554
|
|
|
44458
44555
|
// src/adapters/claude-code.ts
|
|
44459
44556
|
var TOOL_NAME_PREFIX = "mcp__plugin_context-mode_context-mode__";
|
|
@@ -44781,8 +44878,8 @@ function decode7(raw) {
|
|
|
44781
44878
|
if (event === "SessionStart" && typeof raw.source === "string" && COPILOT_SOURCES[raw.source] !== void 0) ev.source = COPILOT_SOURCES[raw.source];
|
|
44782
44879
|
if (event === "UserPromptSubmit" && typeof raw.prompt === "string") ev.prompt = raw.prompt;
|
|
44783
44880
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
44784
|
-
const
|
|
44785
|
-
const tool = { name:
|
|
44881
|
+
const toolName2 = String(raw[k.tool] ?? "");
|
|
44882
|
+
const tool = { name: toolName2, canonicalName: canonicalName3(toolName2), input: readArgs(raw[k.args]) };
|
|
44786
44883
|
ev.tool = tool;
|
|
44787
44884
|
}
|
|
44788
44885
|
if (event === "PostToolUse") ev.result = readResult3(raw[k.result], native.casing, native.failure);
|
|
@@ -44896,9 +44993,9 @@ function decodeCamel(p, name) {
|
|
|
44896
44993
|
if (event === "SessionStart" && typeof p.source === "string" && SESSION_SOURCES[p.source] !== void 0) ev.source = SESSION_SOURCES[p.source];
|
|
44897
44994
|
if (event === "UserPromptSubmit" && typeof p.prompt === "string") ev.prompt = p.prompt;
|
|
44898
44995
|
if (event === "PreToolUse" || event === "PostToolUse") {
|
|
44899
|
-
const
|
|
44900
|
-
const canonical = canonicalName4(
|
|
44901
|
-
ev.tool = { name:
|
|
44996
|
+
const toolName2 = String(p.toolName ?? "");
|
|
44997
|
+
const canonical = canonicalName4(toolName2);
|
|
44998
|
+
ev.tool = { name: toolName2, canonicalName: canonical, input: policyInput(toolName2, canonical, readArgs2(p.toolArgs)) };
|
|
44902
44999
|
}
|
|
44903
45000
|
if (event === "PostToolUse") ev.result = readCamelResult(p.toolResult);
|
|
44904
45001
|
return ev;
|
|
@@ -47814,8 +47911,8 @@ function setTomlText(text, path7, value) {
|
|
|
47814
47911
|
if (sameValue(cur, value)) return text;
|
|
47815
47912
|
const inline = doc.keys.find((k) => k.inline && k.full.length < path7.length && under(path7, k.full));
|
|
47816
47913
|
if (inline !== void 0) {
|
|
47817
|
-
const
|
|
47818
|
-
return replaceToml(text, doc, inline.full,
|
|
47914
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path7.slice(inline.full.length), value);
|
|
47915
|
+
return replaceToml(text, doc, inline.full, whole2);
|
|
47819
47916
|
}
|
|
47820
47917
|
if (isPlainObject6(cur) && isPlainObject6(value)) {
|
|
47821
47918
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
@@ -48494,14 +48591,18 @@ function mcpWrong(row5, home, env, worktree) {
|
|
|
48494
48591
|
return true;
|
|
48495
48592
|
}
|
|
48496
48593
|
}
|
|
48594
|
+
function hookFile(row5, spec, home, env, worktree) {
|
|
48595
|
+
const root = spec.root === "plugin" ? resolvePluginRoot(row5, env, worktree) : spec.root === "home" ? home : worktree;
|
|
48596
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48597
|
+
const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
|
|
48598
|
+
return file2;
|
|
48599
|
+
}
|
|
48497
48600
|
function hookParts(row5, home, env, worktree) {
|
|
48498
48601
|
const spec = HOOK_HOST_FILE[row5.id];
|
|
48499
48602
|
if (spec === null) return [];
|
|
48500
48603
|
let block;
|
|
48501
48604
|
try {
|
|
48502
|
-
const
|
|
48503
|
-
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48504
|
-
const file2 = native !== null ? join9(native, CODEX_PLUGIN_HOOKS_FILE) : row5.id === "codex" ? join9(codexDirOf(env, home), HOOKS_JSON_FILE) : row5.id === "copilot-cli" ? join9(copilotDirOf(env, home), ...spec.file.slice(1)) : row5.id === "kiro" ? join9(kiroDirOf(env, home), ...spec.file.slice(1)) : join9(root, ...spec.file);
|
|
48605
|
+
const file2 = hookFile(row5, spec, home, env, worktree);
|
|
48505
48606
|
block = hostConfigValueAt(readParsed(row5.id, file2).value, spec.key);
|
|
48506
48607
|
if (row5.id === "codex") {
|
|
48507
48608
|
const config4 = readParsed(row5.id, join9(codexDirOf(env, home), CONFIG_TOML_FILE)).value;
|
|
@@ -48542,12 +48643,15 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
48542
48643
|
const read = row5.id === "pi" ? mcpFile(row5, home, env) : null;
|
|
48543
48644
|
if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
|
|
48544
48645
|
const detail = D3_DETAIL(parts);
|
|
48545
|
-
|
|
48646
|
+
const fix = parts.includes(PART_MCP) && parts.includes(PART_HOOKS) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
48647
|
+
return fail("D3", read === null ? detail : detail + D4_REASON_JOIN + read, fix);
|
|
48546
48648
|
}
|
|
48547
48649
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
48548
48650
|
const findings = detectV1(agent, home, scope);
|
|
48549
48651
|
if (findings.length === 0) return pass("D4");
|
|
48550
|
-
|
|
48652
|
+
const detail = findings.map((f) => f.reason).join(D4_REASON_JOIN);
|
|
48653
|
+
if (findings.every((f) => f.reason === V1_REASON.tmpFile)) return { ...pass("D4"), detail };
|
|
48654
|
+
return fail("D4", detail, DOCTOR_FIX_UPGRADE);
|
|
48551
48655
|
}
|
|
48552
48656
|
function parsedOrNull(agent, file2, jsonc) {
|
|
48553
48657
|
try {
|
|
@@ -48566,6 +48670,31 @@ function checkDoubleFire(agent, worktree) {
|
|
|
48566
48670
|
const useClaudeHooks = isObject4(vscode) && vscode[VSCODE_CLAUDE_HOOKS_SETTING] === true;
|
|
48567
48671
|
return hooksOn && useClaudeHooks ? fail("D5b", D5B_DETAIL, D5B_FIX) : pass("D5b");
|
|
48568
48672
|
}
|
|
48673
|
+
function configPaths(row5, env, worktree) {
|
|
48674
|
+
const home = homeDirOf(env);
|
|
48675
|
+
if (home === null) return [];
|
|
48676
|
+
const out = [];
|
|
48677
|
+
const mcp = mcpFile(row5, home, env);
|
|
48678
|
+
if (mcp !== null) out.push({ label: "MCP entry", path: mcp });
|
|
48679
|
+
const native = row5.id === "codex" ? codexNativeDir(env, home) : null;
|
|
48680
|
+
if (native !== null) out.push({ label: "Codex plugin MCP", path: join9(native, CODEX_PLUGIN_MCP_FILE) });
|
|
48681
|
+
const spec = HOOK_HOST_FILE[row5.id];
|
|
48682
|
+
if (spec !== null) {
|
|
48683
|
+
try {
|
|
48684
|
+
out.push({ label: "hook entries", path: hookFile(row5, spec, home, env, worktree) });
|
|
48685
|
+
} catch (err) {
|
|
48686
|
+
out.push({ label: "hook entries", path: err instanceof Error ? err.message : String(err) });
|
|
48687
|
+
}
|
|
48688
|
+
}
|
|
48689
|
+
if (spec !== null && spec.root === "plugin" || row5.installMode === "marketplace" || row5.installMode === "plugin") {
|
|
48690
|
+
try {
|
|
48691
|
+
out.push({ label: "plugin root", path: resolvePluginRoot(row5, env, worktree) });
|
|
48692
|
+
} catch (err) {
|
|
48693
|
+
out.push({ label: "plugin root", path: err instanceof Error ? err.message : String(err) });
|
|
48694
|
+
}
|
|
48695
|
+
}
|
|
48696
|
+
return out.filter((e, i) => out.findIndex((o) => o.path === e.path) === i);
|
|
48697
|
+
}
|
|
48569
48698
|
|
|
48570
48699
|
// src/core/ops/doctor-db.ts
|
|
48571
48700
|
import { existsSync as existsSync8 } from "node:fs";
|
|
@@ -49015,16 +49144,19 @@ function isObject5(v) {
|
|
|
49015
49144
|
}
|
|
49016
49145
|
function loadFixture(bundleDir2, agent) {
|
|
49017
49146
|
const file2 = path6.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
49018
|
-
if (!existsSync11(file2)) return
|
|
49147
|
+
if (!existsSync11(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
49019
49148
|
let all;
|
|
49020
49149
|
try {
|
|
49021
49150
|
all = JSON.parse(hostText(readFileSync8(file2, "utf8")));
|
|
49022
|
-
} catch {
|
|
49023
|
-
return
|
|
49151
|
+
} catch (err) {
|
|
49152
|
+
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
49024
49153
|
}
|
|
49025
|
-
if (!isObject5(all)
|
|
49154
|
+
if (!isObject5(all)) return { cause: D5_FIXTURE_PARSE(file2, "top level is not an object") };
|
|
49155
|
+
if (!Object.hasOwn(all, agent)) return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": " + D5_FIXTURE_AGENT_ABSENT(file2, Object.keys(all)) };
|
|
49026
49156
|
const e = all[agent];
|
|
49027
|
-
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload"))
|
|
49157
|
+
if (!isObject5(e) || typeof e.event !== "string" || !Object.hasOwn(e, "payload")) {
|
|
49158
|
+
return { cause: D5_NO_FIXTURE_DETAIL(agent) + ": the entry lacks an event name or a payload" };
|
|
49159
|
+
}
|
|
49028
49160
|
return { event: e.event, payload: e.payload };
|
|
49029
49161
|
}
|
|
49030
49162
|
function payloadFor(payload, worktree) {
|
|
@@ -49078,7 +49210,7 @@ async function checkHookRoundTrip(i) {
|
|
|
49078
49210
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
49079
49211
|
}
|
|
49080
49212
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
49081
|
-
if (
|
|
49213
|
+
if ("cause" in fixture) return row("UNKNOWN", fixture.cause);
|
|
49082
49214
|
const now = i.now ?? (() => performance.now());
|
|
49083
49215
|
const fixed = i.samples === void 0 ? null : Math.max(1, i.samples);
|
|
49084
49216
|
const maxPairs = fixed ?? D5_MAX_PAIRS;
|
|
@@ -49218,8 +49350,13 @@ function envLine(key, value) {
|
|
|
49218
49350
|
const typedValue = allowed !== void 0 && allowed.includes(value) ? value : REPORT_INVALID;
|
|
49219
49351
|
return REPORT_ENV_PREFIX + typedKey + ": " + typedValue;
|
|
49220
49352
|
}
|
|
49353
|
+
function fixCell(agent, row5) {
|
|
49354
|
+
if (row5.status === "PASS") return "";
|
|
49355
|
+
if (row5.status === "FAIL") return DOCTOR_FAIL_LINE(agent, row5.id, row5.detail, row5.fixCommand ?? "");
|
|
49356
|
+
return row5.fixCommand === void 0 ? "" : "Fix: " + row5.fixCommand;
|
|
49357
|
+
}
|
|
49221
49358
|
function rowLine(agent, row5) {
|
|
49222
|
-
const fix =
|
|
49359
|
+
const fix = fixCell(agent, row5);
|
|
49223
49360
|
return "| " + [row5.id + " " + row5.label, row5.status, row5.detail, fix].join(" | ") + " |";
|
|
49224
49361
|
}
|
|
49225
49362
|
function buildReport(input) {
|
|
@@ -49249,6 +49386,196 @@ function buildReportHead(input) {
|
|
|
49249
49386
|
return lines.concat(tail).join("\n");
|
|
49250
49387
|
}
|
|
49251
49388
|
|
|
49389
|
+
// src/core/ops/doctor-issue.ts
|
|
49390
|
+
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
49391
|
+
import { closeSync, existsSync as existsSync13, fstatSync, mkdirSync as mkdirSync5, openSync, readFileSync as readFileSync9, readSync, realpathSync as realpathSync8, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49392
|
+
import { delimiter, join as join12 } from "node:path";
|
|
49393
|
+
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
49394
|
+
function tildeOf(env) {
|
|
49395
|
+
const home = homeDirOf(env);
|
|
49396
|
+
if (home === null || home === "") return (t) => t;
|
|
49397
|
+
const homes = [home];
|
|
49398
|
+
try {
|
|
49399
|
+
const real2 = realpathSync8.native(home);
|
|
49400
|
+
if (real2 !== home) homes.push(real2);
|
|
49401
|
+
} catch {
|
|
49402
|
+
}
|
|
49403
|
+
homes.sort((a, b) => b.length - a.length);
|
|
49404
|
+
const slash = (rest) => rest.replace(/^[^\s"'`|)>,;]*/, (run) => run.replace(/\\/g, "/"));
|
|
49405
|
+
return (t) => homes.reduce((acc, h) => acc.split(h).map((piece, n) => n === 0 ? piece : slash(piece)).join("~"), t);
|
|
49406
|
+
}
|
|
49407
|
+
function maskLine(line) {
|
|
49408
|
+
const lower = line.toLowerCase();
|
|
49409
|
+
const named = DOCTOR_SECRET_WORDS.some((w) => lower.includes(w));
|
|
49410
|
+
const token = TOKEN_PREFIXES.some((p) => line.includes(p));
|
|
49411
|
+
if (!named && !token) return line;
|
|
49412
|
+
const at = Math.max(line.indexOf(":"), line.indexOf("="));
|
|
49413
|
+
return at === -1 ? DOCTOR_MASK : line.slice(0, at + 1) + " " + DOCTOR_MASK;
|
|
49414
|
+
}
|
|
49415
|
+
function environmentLine(ctx, adapter, env, version4) {
|
|
49416
|
+
const sha = BUNDLE_SHA === void 0 ? "dev build" : BUNDLE_SHA.slice(0, 7);
|
|
49417
|
+
const client = ctx.clientInfo;
|
|
49418
|
+
const agent = client === void 0 ? adapter.id : client.name === adapter.id ? `${adapter.id} ${client.version}` : `${adapter.id} ${client.version} (client ${client.name})`;
|
|
49419
|
+
const shell = env.SHELL ?? env.ComSpec ?? "sh";
|
|
49420
|
+
return `${DOCTOR_ENV_PREFIX}context-mode ${version4 ?? "source checkout"} (${sha}), agent ${agent}
|
|
49421
|
+
${DOCTOR_ENV_PREFIX}${process.platform}-${process.arch}, Node ${process.version}, shell ${shell}`;
|
|
49422
|
+
}
|
|
49423
|
+
function gitVersion(env) {
|
|
49424
|
+
const r = spawnSync3("git", ["--version"], { env, encoding: "utf8", timeout: DOCTOR_GIT_VERSION_TIMEOUT_MS, windowsHide: true });
|
|
49425
|
+
if (r.status === 0) return `${r.stdout}`.trim();
|
|
49426
|
+
return `git --version: ${r.error ? r.error.message : `exit ${r.status}`}`;
|
|
49427
|
+
}
|
|
49428
|
+
function onPath(env, tool) {
|
|
49429
|
+
const names = process.platform === "win32" ? [tool + EXE_SUFFIX, tool + ".cmd", tool] : [tool];
|
|
49430
|
+
const out = [];
|
|
49431
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
49432
|
+
if (dir === "") continue;
|
|
49433
|
+
for (const n of names) if (existsSync13(join12(dir, n))) {
|
|
49434
|
+
out.push(join12(dir, n));
|
|
49435
|
+
break;
|
|
49436
|
+
}
|
|
49437
|
+
}
|
|
49438
|
+
return out;
|
|
49439
|
+
}
|
|
49440
|
+
function hookLogTail(env) {
|
|
49441
|
+
const file2 = hookLogPath(env);
|
|
49442
|
+
if (file2 === "" || !existsSync13(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
49443
|
+
try {
|
|
49444
|
+
const fd = openSync(file2, "r");
|
|
49445
|
+
try {
|
|
49446
|
+
const size = fstatSync(fd).size;
|
|
49447
|
+
const start = Math.max(0, size - DOCTOR_LOG_TAIL_BYTES);
|
|
49448
|
+
const buf = Buffer.alloc(size - start);
|
|
49449
|
+
readSync(fd, buf, 0, buf.length, start);
|
|
49450
|
+
const lines = buf.toString("utf8").split("\n").filter((l) => l.trim() !== "");
|
|
49451
|
+
if (start > 0) lines.shift();
|
|
49452
|
+
return lines.slice(-DOCTOR_HOOK_LOG_LINES).map(maskLine);
|
|
49453
|
+
} finally {
|
|
49454
|
+
closeSync(fd);
|
|
49455
|
+
}
|
|
49456
|
+
} catch (err) {
|
|
49457
|
+
return [`hook-errors.log read: ${err instanceof Error ? err.message : String(err)}`];
|
|
49458
|
+
}
|
|
49459
|
+
}
|
|
49460
|
+
async function journalRows(ctx) {
|
|
49461
|
+
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
49462
|
+
if (!existsSync13(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
49463
|
+
try {
|
|
49464
|
+
const db = await openDb(ctx.project, { readOnly: true });
|
|
49465
|
+
try {
|
|
49466
|
+
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();
|
|
49467
|
+
const cell5 = (v) => v === null || v === void 0 ? "" : String(v);
|
|
49468
|
+
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)} |`));
|
|
49469
|
+
} finally {
|
|
49470
|
+
closeDb(db);
|
|
49471
|
+
}
|
|
49472
|
+
} catch (err) {
|
|
49473
|
+
return [`journal read: ${err instanceof Error ? err.message : String(err)}`];
|
|
49474
|
+
}
|
|
49475
|
+
}
|
|
49476
|
+
function agentConfig(adapter, env, worktree) {
|
|
49477
|
+
const home = homeDirOf(env);
|
|
49478
|
+
const files = configPaths(adapter, env, worktree);
|
|
49479
|
+
if (home !== null) {
|
|
49480
|
+
if (adapter.id === "claude-code") files.push({ label: "agent settings (enabledPlugins)", path: join12(claudeDirOf(env, home), SETTINGS_FILE) });
|
|
49481
|
+
if (adapter.id === "codex") files.push({ label: "agent config (plugins, trust)", path: join12(codexDirOf(env, home), CONFIG_TOML_FILE) });
|
|
49482
|
+
}
|
|
49483
|
+
const out = [];
|
|
49484
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49485
|
+
for (const f of files) {
|
|
49486
|
+
if (seen.has(f.path)) continue;
|
|
49487
|
+
seen.add(f.path);
|
|
49488
|
+
if (!existsSync13(f.path)) {
|
|
49489
|
+
out.push(`${f.label}: ${f.path} (absent)`);
|
|
49490
|
+
continue;
|
|
49491
|
+
}
|
|
49492
|
+
let text = "";
|
|
49493
|
+
try {
|
|
49494
|
+
text = readFileSync9(f.path, "utf8");
|
|
49495
|
+
} catch (err) {
|
|
49496
|
+
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
49497
|
+
continue;
|
|
49498
|
+
}
|
|
49499
|
+
const hit = text.split("\n").filter((l) => l.includes("context-mode") || l.includes("hook.mjs") || adapter.id === "codex" && l.includes("trust"));
|
|
49500
|
+
out.push(`${f.label}: ${f.path} (${hit.length} matching lines)`);
|
|
49501
|
+
for (const l of hit.slice(0, DOCTOR_CONFIG_LINES)) out.push(" " + maskLine(l.trimEnd()));
|
|
49502
|
+
}
|
|
49503
|
+
return out;
|
|
49504
|
+
}
|
|
49505
|
+
function failing(rows) {
|
|
49506
|
+
return rows.filter((r) => r.status === "FAIL");
|
|
49507
|
+
}
|
|
49508
|
+
function issueTitle(agent, rows) {
|
|
49509
|
+
return `ctx_doctor ${agent}: ${failing(rows).map((r) => `${r.id} ${r.label}`).join(", ")} FAIL`;
|
|
49510
|
+
}
|
|
49511
|
+
function summaryOf(agent, rows) {
|
|
49512
|
+
const f = failing(rows)[0];
|
|
49513
|
+
return f === void 0 ? `ctx_doctor ${agent}` : `${f.id} ${f.label} FAIL on ${agent}: ${f.detail}`;
|
|
49514
|
+
}
|
|
49515
|
+
async function buildIssueBody(i) {
|
|
49516
|
+
const tilde = tildeOf(i.env);
|
|
49517
|
+
const agent = i.adapter.id;
|
|
49518
|
+
const install = NATIVE_INSTALL[agent] ?? [];
|
|
49519
|
+
const failRows = i.rows.filter((r) => r.status !== "PASS");
|
|
49520
|
+
const envNames = DOCTOR_ENV_NAMES.map((n) => i.env[n] === void 0 ? `${n} (unset)` : `${n}=${i.env[n]}`);
|
|
49521
|
+
const pathTools = DOCTOR_PATH_TOOLS.map((t) => `PATH holds ${t}: ${onPath(i.env, t).join(", ") || "(absent)"}`);
|
|
49522
|
+
const sections = {
|
|
49523
|
+
"Summary": [summaryOf(agent, i.rows)],
|
|
49524
|
+
"ctx-report": [i.table],
|
|
49525
|
+
"What happened": [
|
|
49526
|
+
"Rows that need a look:",
|
|
49527
|
+
...failRows.map((r) => `- ${r.id} ${r.label} ${r.status}: ${r.detail}${r.fixCommand ? ` (Fix: ${r.fixCommand})` : ""}`),
|
|
49528
|
+
"Error code and text: <the agent fills this in: the exact error the user saw>"
|
|
49529
|
+
],
|
|
49530
|
+
"Hook errors": ["hook-errors.log, last " + DOCTOR_HOOK_LOG_LINES + " lines (UTC):", "```", ...hookLogTail(i.env), "```"],
|
|
49531
|
+
"Journal rows": ["events, newest first, last " + DOCTOR_JOURNAL_ROWS + " (bodies stay local):", ...await journalRows(i.ctx)],
|
|
49532
|
+
"Agent config": agentConfig(i.adapter, i.env, i.ctx.project.worktree),
|
|
49533
|
+
"Expected": ["Expected: <the agent fills this in: what should happen, with the byte count>"],
|
|
49534
|
+
"Steps": [
|
|
49535
|
+
"Reproduced: <yes (2 of 2) or 1 of 2>",
|
|
49536
|
+
"Prompt or command: <the agent fills this in: the exact prompt or command>",
|
|
49537
|
+
"Actual: <the agent fills this in: what context-mode did, with the byte count>",
|
|
49538
|
+
"Repro script (fresh HOME, native install for " + agent + "):",
|
|
49539
|
+
"```sh",
|
|
49540
|
+
'export HOME="$(mktemp -d)"',
|
|
49541
|
+
'cd "$HOME"',
|
|
49542
|
+
...install,
|
|
49543
|
+
"<the command or prompt above>",
|
|
49544
|
+
"```"
|
|
49545
|
+
],
|
|
49546
|
+
"Environment": [
|
|
49547
|
+
i.envLine,
|
|
49548
|
+
`context-mode bundle: ${i.bundleDir}`,
|
|
49549
|
+
`Install route: ${install.join(" && ")}`,
|
|
49550
|
+
`git: ${gitVersion(i.env)}`,
|
|
49551
|
+
...pathTools,
|
|
49552
|
+
...envNames,
|
|
49553
|
+
`Project: ${i.ctx.project.worktree} (key ${i.ctx.project.projectKey})`,
|
|
49554
|
+
"Filed by: <your agent name, version, model id>"
|
|
49555
|
+
]
|
|
49556
|
+
};
|
|
49557
|
+
const out = [];
|
|
49558
|
+
for (const h of ISSUE_FORM_HEADINGS) out.push(`### ${h}`, "", ...sections[h] ?? [], "");
|
|
49559
|
+
return tilde(out.join("\n"));
|
|
49560
|
+
}
|
|
49561
|
+
async function writeIssueReport(i) {
|
|
49562
|
+
const tilde = tildeOf(i.env);
|
|
49563
|
+
const body = await buildIssueBody(i);
|
|
49564
|
+
const dir = join12(resolveConfigDir(i.env), DOCTOR_REPORTS_DIR);
|
|
49565
|
+
mkdirSync5(dir, { recursive: true });
|
|
49566
|
+
const file2 = join12(dir, `${DOCTOR_REPORT_FILE_PREFIX}${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-")}.md`);
|
|
49567
|
+
writeFileSync3(file2, body);
|
|
49568
|
+
const shown2 = tilde(file2);
|
|
49569
|
+
const title = issueTitle(i.adapter.id, i.rows);
|
|
49570
|
+
const gh = [`gh issue create --repo ${ISSUE_REPO_SLUG} --label bug \\`, `${DOCTOR_GH_NEXT}title ${JSON.stringify(title)} \\`, `${DOCTOR_GH_NEXT}body-file ${shown2}`];
|
|
49571
|
+
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))];
|
|
49572
|
+
}
|
|
49573
|
+
function formUrl(title, summary) {
|
|
49574
|
+
const base = `${ISSUE_FORM_URL}&title=${encodeURIComponent(title)}`;
|
|
49575
|
+
const full = `${base}&summary=${encodeURIComponent(summary)}`;
|
|
49576
|
+
return full.length < ISSUE_URL_MAX ? full : base;
|
|
49577
|
+
}
|
|
49578
|
+
|
|
49252
49579
|
// src/core/index/text.ts
|
|
49253
49580
|
function storeText(db, project, sessionId, sourceKind, label2, text, kind, chunks = chunkText(text, kind)) {
|
|
49254
49581
|
const sourceId = ftsInsert(db, {
|
|
@@ -49282,7 +49609,7 @@ async function guard(id, run) {
|
|
|
49282
49609
|
}
|
|
49283
49610
|
}
|
|
49284
49611
|
async function codexDb(ctx, adapter) {
|
|
49285
|
-
if (adapter.id !== "codex" || !
|
|
49612
|
+
if (adapter.id !== "codex" || !existsSync14(ctx.project.dbPath)) return null;
|
|
49286
49613
|
try {
|
|
49287
49614
|
return await openDb(ctx.project, { readOnly: true });
|
|
49288
49615
|
} catch {
|
|
@@ -49312,11 +49639,11 @@ async function hookRow(ctx, adapter, host) {
|
|
|
49312
49639
|
}
|
|
49313
49640
|
}
|
|
49314
49641
|
function ownServerId(configDir, projectKey) {
|
|
49315
|
-
const dir =
|
|
49316
|
-
if (!
|
|
49642
|
+
const dir = join13(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
49643
|
+
if (!existsSync14(dir)) return "";
|
|
49317
49644
|
for (const name of readdirSync6(dir)) {
|
|
49318
49645
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
49319
|
-
if (
|
|
49646
|
+
if (readFileSync10(join13(dir, name), "utf8").trim() === String(process.pid)) return basename4(name, OWNER_PID_EXT);
|
|
49320
49647
|
}
|
|
49321
49648
|
return "";
|
|
49322
49649
|
}
|
|
@@ -49361,24 +49688,39 @@ function reportEnv(env) {
|
|
|
49361
49688
|
}
|
|
49362
49689
|
return out;
|
|
49363
49690
|
}
|
|
49364
|
-
async function
|
|
49691
|
+
async function doctorReply(ctx, host) {
|
|
49365
49692
|
const adapter = getAdapter(ctx.project.agent);
|
|
49366
|
-
const host = { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 };
|
|
49367
49693
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
49368
|
-
const
|
|
49369
|
-
const
|
|
49370
|
-
const
|
|
49371
|
-
const
|
|
49372
|
-
|
|
49694
|
+
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
49695
|
+
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
49696
|
+
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
49697
|
+
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
49698
|
+
const table3 = buildReport(input);
|
|
49699
|
+
let notes = [];
|
|
49700
|
+
if (failed2) {
|
|
49701
|
+
try {
|
|
49702
|
+
notes = await writeIssueReport({ ctx, adapter, env: host.env, bundleDir: host.bundleDir, rows, envLine: envLine2, table: table3 });
|
|
49703
|
+
} catch (err) {
|
|
49704
|
+
notes = [`Report file: ${lineOf(err)}`];
|
|
49705
|
+
}
|
|
49706
|
+
}
|
|
49707
|
+
const look = rows.find((r) => r.status === "FAIL") ?? rows.find((r) => r.status !== "PASS");
|
|
49708
|
+
const docs = look === void 0 ? [] : [DOCTOR_DOCS_LABEL + DOCTOR_DOCS_LINK(look.id)];
|
|
49709
|
+
const whole2 = [envLine2, table3, ...docs, ...notes].join("\n");
|
|
49710
|
+
const bytes5 = Buffer.byteLength(whole2, "utf8");
|
|
49711
|
+
if (bytes5 <= REPORT_CAP) return { text: whole2, isError: false, sandboxBytes: bytes5 };
|
|
49373
49712
|
const db = await openDb(ctx.project);
|
|
49374
49713
|
try {
|
|
49375
|
-
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL,
|
|
49714
|
+
indexText(db, ctx.project, ctx.sessionId, REPORT_SOURCE_LABEL, whole2, "text");
|
|
49376
49715
|
} finally {
|
|
49377
49716
|
closeDb(db);
|
|
49378
49717
|
}
|
|
49379
|
-
const text = buildReportHead(input);
|
|
49718
|
+
const text = [envLine2, buildReportHead(input), ...docs, ...notes].join("\n");
|
|
49380
49719
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
49381
49720
|
}
|
|
49721
|
+
async function handler2(_input, ctx) {
|
|
49722
|
+
return doctorReply(ctx, { env: process.env, bundleDir: dirname6(process.argv[1]), piCwd: void 0 });
|
|
49723
|
+
}
|
|
49382
49724
|
var ctxDoctor = Object.freeze({
|
|
49383
49725
|
name: "ctx_doctor",
|
|
49384
49726
|
schema: ctxDoctorSchema,
|
|
@@ -49389,9 +49731,9 @@ var ctxDoctor = Object.freeze({
|
|
|
49389
49731
|
});
|
|
49390
49732
|
|
|
49391
49733
|
// src/core/tools/execute.ts
|
|
49392
|
-
import { existsSync as
|
|
49734
|
+
import { existsSync as existsSync15, mkdtempSync, rmSync as rmSync5, writeFileSync as writeFileSync4 } from "node:fs";
|
|
49393
49735
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49394
|
-
import { dirname as dirname7, join as
|
|
49736
|
+
import { dirname as dirname7, join as join14, parse as parse5, resolve as resolve4 } from "node:path";
|
|
49395
49737
|
|
|
49396
49738
|
// src/core/index/select.ts
|
|
49397
49739
|
var READ_CHUNKS = "SELECT ord, body FROM chunks WHERE source_id = ?";
|
|
@@ -49514,7 +49856,7 @@ function schemaLine(issue4) {
|
|
|
49514
49856
|
}
|
|
49515
49857
|
function fileError(given, abs, root) {
|
|
49516
49858
|
let dir = abs;
|
|
49517
|
-
while (!
|
|
49859
|
+
while (!existsSync15(dir) && dirname7(dir) !== dir) dir = dirname7(dir);
|
|
49518
49860
|
if (isInside(root, dir)) return null;
|
|
49519
49861
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
49520
49862
|
}
|
|
@@ -49595,9 +49937,9 @@ async function handler3(raw, ctx) {
|
|
|
49595
49937
|
if (takesDashC(input.language, runtime)) {
|
|
49596
49938
|
argv = [runtime, "-c", input.language === "shell" ? rewriteWindowsBuildTools(input.code, process.platform) : input.code];
|
|
49597
49939
|
} else {
|
|
49598
|
-
tmpDir = mkdtempSync(
|
|
49599
|
-
const file2 =
|
|
49600
|
-
|
|
49940
|
+
tmpDir = mkdtempSync(join14(tmpdir2(), TMP_PREFIX));
|
|
49941
|
+
const file2 = join14(tmpDir, SCRIPT_NAME + (SCRIPT_EXT[input.language] ?? ""));
|
|
49942
|
+
writeFileSync4(file2, scriptText(input.language, input.code), "utf8");
|
|
49601
49943
|
argv = scriptArgv(input.language, runtime, file2);
|
|
49602
49944
|
}
|
|
49603
49945
|
if (input.background === true) {
|
|
@@ -49631,21 +49973,21 @@ var ctxExecute = {
|
|
|
49631
49973
|
};
|
|
49632
49974
|
|
|
49633
49975
|
// src/core/tools/index.ts
|
|
49634
|
-
import { existsSync as
|
|
49635
|
-
import { dirname as dirname8, extname, join as
|
|
49976
|
+
import { existsSync as existsSync16, readFileSync as readFileSync12, statSync as statSync6 } from "node:fs";
|
|
49977
|
+
import { dirname as dirname8, extname, join as join16, relative as relative2, resolve as resolve5 } from "node:path";
|
|
49636
49978
|
|
|
49637
49979
|
// src/core/index/walk.ts
|
|
49638
|
-
import { readdirSync as readdirSync7, readFileSync as
|
|
49639
|
-
import { join as
|
|
49980
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync11, realpathSync as realpathSync9, statSync as statSync5 } from "node:fs";
|
|
49981
|
+
import { join as join15 } from "node:path";
|
|
49640
49982
|
var GITIGNORE = ".gitignore";
|
|
49641
49983
|
var GIT_DIR = ".git";
|
|
49642
49984
|
function walkDir(root, containmentRoot) {
|
|
49643
|
-
const real2 =
|
|
49985
|
+
const real2 = realpathSync9(root);
|
|
49644
49986
|
if (!isInside(containmentRoot, real2)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
49645
49987
|
const found = [];
|
|
49646
49988
|
visit(real2, [], [], containmentRoot, /* @__PURE__ */ new Set([real2]), found);
|
|
49647
49989
|
found.sort(compareFound);
|
|
49648
|
-
return found.map((f) => ({ absPath: f.absPath, relPath:
|
|
49990
|
+
return found.map((f) => ({ absPath: f.absPath, relPath: join15(...f.dir, f.name) }));
|
|
49649
49991
|
}
|
|
49650
49992
|
function visit(abs, rel, parent, contain, seen, found) {
|
|
49651
49993
|
let entries;
|
|
@@ -49654,17 +49996,17 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
49654
49996
|
} catch {
|
|
49655
49997
|
return;
|
|
49656
49998
|
}
|
|
49657
|
-
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(
|
|
49999
|
+
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join15(abs, GITIGNORE), rel)) : parent;
|
|
49658
50000
|
for (const e of entries) {
|
|
49659
50001
|
if (e.name === GIT_DIR) continue;
|
|
49660
|
-
const path7 =
|
|
50002
|
+
const path7 = join15(abs, e.name);
|
|
49661
50003
|
let isDir = e.isDirectory();
|
|
49662
50004
|
let isFile = e.isFile();
|
|
49663
50005
|
let target = path7;
|
|
49664
50006
|
if (e.isSymbolicLink()) {
|
|
49665
50007
|
let resolved;
|
|
49666
50008
|
try {
|
|
49667
|
-
resolved =
|
|
50009
|
+
resolved = realpathSync9(path7);
|
|
49668
50010
|
} catch {
|
|
49669
50011
|
continue;
|
|
49670
50012
|
}
|
|
@@ -49679,7 +50021,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
49679
50021
|
if (isFile) {
|
|
49680
50022
|
found.push({ dir: rel, name: e.name, absPath: path7 });
|
|
49681
50023
|
} else if (isDir) {
|
|
49682
|
-
const key = e.isSymbolicLink() ? target :
|
|
50024
|
+
const key = e.isSymbolicLink() ? target : realpathSync9(path7);
|
|
49683
50025
|
if (seen.has(key)) continue;
|
|
49684
50026
|
seen.add(key);
|
|
49685
50027
|
visit(path7, segs, rules, contain, seen, found);
|
|
@@ -49697,7 +50039,7 @@ function compareFound(a, b) {
|
|
|
49697
50039
|
function readRules(file2, base) {
|
|
49698
50040
|
let body;
|
|
49699
50041
|
try {
|
|
49700
|
-
body =
|
|
50042
|
+
body = readFileSync11(file2, "utf8");
|
|
49701
50043
|
} catch {
|
|
49702
50044
|
return [];
|
|
49703
50045
|
}
|
|
@@ -53780,14 +54122,14 @@ function kindOfType(contentType) {
|
|
|
53780
54122
|
}
|
|
53781
54123
|
function readUtf8(absPath) {
|
|
53782
54124
|
try {
|
|
53783
|
-
return utf8.decode(
|
|
54125
|
+
return utf8.decode(readFileSync12(absPath));
|
|
53784
54126
|
} catch {
|
|
53785
54127
|
return void 0;
|
|
53786
54128
|
}
|
|
53787
54129
|
}
|
|
53788
54130
|
function missingOrOutside(given, abs, root) {
|
|
53789
54131
|
let dir = abs;
|
|
53790
|
-
while (!
|
|
54132
|
+
while (!existsSync16(dir) && dirname8(dir) !== dir) dir = dirname8(dir);
|
|
53791
54133
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
53792
54134
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
53793
54135
|
}
|
|
@@ -53798,7 +54140,7 @@ function pathItems(input, project) {
|
|
|
53798
54140
|
if (statSync6(abs).isDirectory()) {
|
|
53799
54141
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
53800
54142
|
sourceKind: "path",
|
|
53801
|
-
label: pathLabel(
|
|
54143
|
+
label: pathLabel(join16(base, f.relPath)),
|
|
53802
54144
|
kind: kindOfPath(f.relPath),
|
|
53803
54145
|
read: () => readUtf8(f.absPath)
|
|
53804
54146
|
}));
|
|
@@ -54270,6 +54612,43 @@ var KINDS = "SELECT kind, COALESCE(SUM(session_id = ?), 0) AS s, COUNT(*) AS p F
|
|
|
54270
54612
|
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}`;
|
|
54271
54613
|
var SPAN = "SELECT COALESCE(MAX(created_at) - MIN(created_at), 0) AS span FROM events WHERE session_id = ? AND kind <> 'cost'";
|
|
54272
54614
|
var SOURCES = "SELECT COUNT(*) AS n, COALESCE(SUM(chunk_count), 0) AS chunks, COALESCE(SUM(bytes_total), 0) AS bytes FROM sources";
|
|
54615
|
+
var HOST = "tool NOT LIKE 'ctx\\_%' ESCAPE '\\'";
|
|
54616
|
+
var REPLACED = `SELECT COUNT(*) AS n FROM events WHERE ${CALLS} AND ${HOST} AND returned_bytes < sandbox_bytes`;
|
|
54617
|
+
var RUNS = "FROM sources WHERE substr(label, 1, ?) = ?";
|
|
54618
|
+
var REDIRECTED = `SELECT COUNT(*) AS n, COALESCE(MAX(created_ts), 0) AS last ${RUNS}`;
|
|
54619
|
+
var LAST = `SELECT COALESCE(MAX(created_at), 0) AS last FROM events WHERE ${CALLS}`;
|
|
54620
|
+
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`;
|
|
54621
|
+
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`;
|
|
54622
|
+
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}`;
|
|
54623
|
+
function wayOf(tool) {
|
|
54624
|
+
if (STATS_INDEX_TOOLS.includes(tool)) return "index";
|
|
54625
|
+
return tool.startsWith("ctx_") ? "sandbox" : "replace";
|
|
54626
|
+
}
|
|
54627
|
+
function readWeek(raw, lastMs) {
|
|
54628
|
+
const last2 = Math.floor(lastMs / MS_PER_DAY);
|
|
54629
|
+
const first = last2 - STATS_DAYS + 1;
|
|
54630
|
+
const days = Array.from({ length: STATS_DAYS }, (_, i) => ({
|
|
54631
|
+
day: first + i,
|
|
54632
|
+
calls: 0,
|
|
54633
|
+
ways: { sandbox: 0, index: 0, redirect: 0, replace: 0 }
|
|
54634
|
+
}));
|
|
54635
|
+
const net = /* @__PURE__ */ new Map();
|
|
54636
|
+
for (const r of raw.prepare(WEEK).all(first * MS_PER_DAY)) {
|
|
54637
|
+
const d = days[Number(r.day) - first];
|
|
54638
|
+
if (d === void 0) continue;
|
|
54639
|
+
d.calls += Number(r.calls);
|
|
54640
|
+
const key = `${d.day}:${wayOf(String(r.tool))}`;
|
|
54641
|
+
net.set(key, (net.get(key) ?? 0) + Number(r.produced) - Number(r.returned));
|
|
54642
|
+
}
|
|
54643
|
+
for (const d of days) for (const [way] of STATS_WAYS) d.ways[way] = Math.max(0, net.get(`${d.day}:${way}`) ?? 0);
|
|
54644
|
+
for (const r of raw.prepare(WEEK_RUNS).all(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX, first * MS_PER_DAY)) {
|
|
54645
|
+
const d = days[Number(r.day) - first];
|
|
54646
|
+
if (d === void 0) continue;
|
|
54647
|
+
d.calls += Number(r.calls);
|
|
54648
|
+
d.ways.redirect += Number(r.saved);
|
|
54649
|
+
}
|
|
54650
|
+
return days;
|
|
54651
|
+
}
|
|
54273
54652
|
var EMPTY3 = Object.freeze({ calls: 0, produced: 0, returned: 0, saved: 0 });
|
|
54274
54653
|
function totals(r) {
|
|
54275
54654
|
const produced = Number(r.produced);
|
|
@@ -54284,6 +54663,8 @@ function readFacts(raw, sessionId) {
|
|
|
54284
54663
|
const meta3 = raw.prepare(META).get();
|
|
54285
54664
|
const span2 = Number(raw.prepare(SPAN).get(sessionId).span);
|
|
54286
54665
|
const src = raw.prepare(SOURCES).get();
|
|
54666
|
+
const runs = raw.prepare(REDIRECTED).get(RUN_LABEL_PREFIX.length, RUN_LABEL_PREFIX);
|
|
54667
|
+
const last2 = Math.max(Number(raw.prepare(LAST).get().last), Number(runs.last));
|
|
54287
54668
|
const pages = raw.prepare("PRAGMA page_count").get();
|
|
54288
54669
|
const size = raw.prepare("PRAGMA page_size").get();
|
|
54289
54670
|
return {
|
|
@@ -54295,7 +54676,11 @@ function readFacts(raw, sessionId) {
|
|
|
54295
54676
|
agents: Number(meta3.agents),
|
|
54296
54677
|
days: Number(meta3.days),
|
|
54297
54678
|
sources: { count: Number(src.n), chunks: Number(src.chunks), bytes: Number(src.bytes) },
|
|
54298
|
-
dbBytes: Number(pages.page_count) * Number(size.page_size)
|
|
54679
|
+
dbBytes: Number(pages.page_count) * Number(size.page_size),
|
|
54680
|
+
top: raw.prepare(TOP).all().map((r) => ({ name: String(r.tool), ...totals(r) })),
|
|
54681
|
+
replaced: Number(raw.prepare(REPLACED).get().n),
|
|
54682
|
+
redirected: Number(runs.n),
|
|
54683
|
+
week: readWeek(raw, last2)
|
|
54299
54684
|
};
|
|
54300
54685
|
}
|
|
54301
54686
|
function sum(groups) {
|
|
@@ -54326,6 +54711,7 @@ function count(n) {
|
|
|
54326
54711
|
return n < STATS_MILLION ? int4(n) : (n / STATS_MILLION).toFixed(1) + "M";
|
|
54327
54712
|
}
|
|
54328
54713
|
function bytes4(n) {
|
|
54714
|
+
if (n < 0) return "-" + bytes4(-n);
|
|
54329
54715
|
if (n < STATS_KIB) return int4(n) + " B";
|
|
54330
54716
|
let v = n / STATS_KIB;
|
|
54331
54717
|
let u = 0;
|
|
@@ -54358,17 +54744,105 @@ function plural(n, word) {
|
|
|
54358
54744
|
}
|
|
54359
54745
|
function table2(title, rows) {
|
|
54360
54746
|
const max = Math.max(0, ...rows.map((r) => r.saved));
|
|
54361
|
-
const head = " " + title.padEnd(LABEL_W) + "Calls".padStart(STATS_CALLS_W) + "
|
|
54747
|
+
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);
|
|
54362
54748
|
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())];
|
|
54363
54749
|
}
|
|
54364
54750
|
function bySaved(a, b) {
|
|
54365
54751
|
return b.saved - a.saved || b.produced - a.produced || a.returned - b.returned || (a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
54366
54752
|
}
|
|
54753
|
+
function toolName(tool) {
|
|
54754
|
+
return tool.startsWith("ctx_") ? tool : "hook " + tool;
|
|
54755
|
+
}
|
|
54756
|
+
function joinIndex(tools) {
|
|
54757
|
+
const idx = tools.filter((t2) => STATS_INDEX_TOOLS.includes(t2.name));
|
|
54758
|
+
if (idx.length <= 1) return tools;
|
|
54759
|
+
const t = sum(idx);
|
|
54760
|
+
const one = { name: STATS_INDEX_TOOLS.join(" + ").replace(" + ctx_", " + "), ...t, saved: t.produced - t.returned };
|
|
54761
|
+
return [...tools.filter((x) => !idx.includes(x)), one];
|
|
54762
|
+
}
|
|
54367
54763
|
function toolRows(tools) {
|
|
54368
|
-
const named = tools.map((t) => ({ ...t,
|
|
54369
|
-
|
|
54370
|
-
const
|
|
54371
|
-
|
|
54764
|
+
const named = joinIndex(tools.map((t) => ({ ...t, saved: t.produced - t.returned }))).map((t) => ({ ...t, name: toolName(t.name) })).sort(bySaved);
|
|
54765
|
+
const zero = named.filter((t) => t.saved <= 0);
|
|
54766
|
+
const fold = zero.length > 1 ? zero : [];
|
|
54767
|
+
const keep = named.filter((t) => !fold.includes(t));
|
|
54768
|
+
const room = fold.length > 0 ? STATS_MAX_TOOL_ROWS - 1 : STATS_MAX_TOOL_ROWS;
|
|
54769
|
+
const over = keep.length > room;
|
|
54770
|
+
const shown2 = over ? keep.slice(0, STATS_MAX_TOOL_ROWS - 1) : keep;
|
|
54771
|
+
const rest = over ? [...keep.slice(STATS_MAX_TOOL_ROWS - 1), ...fold] : fold;
|
|
54772
|
+
return rest.length === 0 ? shown2 : [...shown2, { name: `other (${plural(rest.length, "tool")})`, ...sum(rest) }];
|
|
54773
|
+
}
|
|
54774
|
+
var TOKEN_UNITS = ["K", "M", "B", "T"];
|
|
54775
|
+
function whole(v) {
|
|
54776
|
+
return v >= STATS_WHOLE_FROM ? int4(v) : v.toFixed(1);
|
|
54777
|
+
}
|
|
54778
|
+
function tokens(n) {
|
|
54779
|
+
if (n < STATS_THOUSAND) return int4(n);
|
|
54780
|
+
let v = n / STATS_THOUSAND;
|
|
54781
|
+
let u = 0;
|
|
54782
|
+
while (v >= STATS_THOUSAND && u < TOKEN_UNITS.length - 1) {
|
|
54783
|
+
v /= STATS_THOUSAND;
|
|
54784
|
+
u++;
|
|
54785
|
+
}
|
|
54786
|
+
return whole(v) + TOKEN_UNITS[u];
|
|
54787
|
+
}
|
|
54788
|
+
function windowLine(saved) {
|
|
54789
|
+
const t = saved / STATS_BYTES_PER_TOKEN;
|
|
54790
|
+
const share = t / STATS_WINDOW_TOKENS;
|
|
54791
|
+
const win = `a ${tokens(STATS_WINDOW_TOKENS)} window`;
|
|
54792
|
+
const head = ` about ${tokens(t)} tokens kept out`;
|
|
54793
|
+
if (share >= 1) return `${head}, ${whole(share)} times ${win}`;
|
|
54794
|
+
const p = share * PERCENT_SCALE;
|
|
54795
|
+
return p * STATS_WHOLE_FROM < 1 ? head : `${head}, ${whole(p)}% of ${win}`;
|
|
54796
|
+
}
|
|
54797
|
+
function ymd(day) {
|
|
54798
|
+
return new Date(day * MS_PER_DAY).toISOString().slice(0, "yyyy-mm-dd".length);
|
|
54799
|
+
}
|
|
54800
|
+
function mmdd(day) {
|
|
54801
|
+
return ymd(day).slice("yyyy-".length);
|
|
54802
|
+
}
|
|
54803
|
+
function stack(parts, max, width) {
|
|
54804
|
+
let total = 0;
|
|
54805
|
+
let at = 0;
|
|
54806
|
+
let out = "";
|
|
54807
|
+
parts.forEach((v, i) => {
|
|
54808
|
+
total += v;
|
|
54809
|
+
const end = max <= 0 ? 0 : Math.round(total / max * width);
|
|
54810
|
+
if (end > at) {
|
|
54811
|
+
out += STATS_WAYS[i][1].repeat(end - at);
|
|
54812
|
+
at = end;
|
|
54813
|
+
}
|
|
54814
|
+
});
|
|
54815
|
+
if (out === "" && total > 0) out = STATS_WAYS[parts.indexOf(Math.max(...parts))][1];
|
|
54816
|
+
return out;
|
|
54817
|
+
}
|
|
54818
|
+
function cards(cells) {
|
|
54819
|
+
return (" " + cells.map((c) => c.padEnd(STATS_CARD_W)).join("")).trimEnd();
|
|
54820
|
+
}
|
|
54821
|
+
function lastDays(week, allCalls) {
|
|
54822
|
+
const saved = week.map((d) => STATS_WAYS.reduce((t, [w]) => t + d.ways[w], 0));
|
|
54823
|
+
const all = saved.reduce((a, b) => a + b, 0);
|
|
54824
|
+
const calls = week.reduce((a, d) => a + d.calls, 0);
|
|
54825
|
+
const max = Math.max(0, ...saved);
|
|
54826
|
+
const head = `Last ${STATS_DAYS} days of use \xB7 ${ymd(week[0].day)} to ${ymd(week[week.length - 1].day)}`;
|
|
54827
|
+
const card = calls < allCalls ? [
|
|
54828
|
+
cards(["Kept out", "Tokens kept out", "Calls", "Kept out per call"]),
|
|
54829
|
+
cards([bytes4(all), "about " + tokens(all / STATS_BYTES_PER_TOKEN), count(calls), bytes4(calls > 0 ? all / calls : 0)]),
|
|
54830
|
+
""
|
|
54831
|
+
] : [];
|
|
54832
|
+
return [
|
|
54833
|
+
head,
|
|
54834
|
+
...card,
|
|
54835
|
+
...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)] : []),
|
|
54836
|
+
" " + STATS_WAYS.map(([, ch, name]) => `${ch} ${name}`).join(" "),
|
|
54837
|
+
""
|
|
54838
|
+
];
|
|
54839
|
+
}
|
|
54840
|
+
function hookLine(redirected, replaced) {
|
|
54841
|
+
const all = redirected + replaced;
|
|
54842
|
+
if (all === 0) return [];
|
|
54843
|
+
const parts = [...redirected > 0 ? [`${int4(redirected)} sent to the sandbox`] : [], ...replaced > 0 ? [`${int4(replaced)} cut down`] : []];
|
|
54844
|
+
const what = plural(all, "large output");
|
|
54845
|
+
return [parts.length === 1 ? ` Project hooks: ${what} ${parts[0].replace(/^[\d,]+ /, "")}` : ` Project hooks: ${what} kept out \xB7 ${parts.join(", ")}`];
|
|
54372
54846
|
}
|
|
54373
54847
|
function fit(line) {
|
|
54374
54848
|
const chars = [...line];
|
|
@@ -54385,20 +54859,30 @@ function report(f, sessionId, agent) {
|
|
|
54385
54859
|
const lines = [
|
|
54386
54860
|
...head,
|
|
54387
54861
|
`${scopeName} \xB7 ${plural(focus.calls, "call")}${extra}`,
|
|
54862
|
+
` ${bytes4(focus.produced)} became ${bytes4(focus.returned)}: ${bytes4(focus.saved)} kept out (${pct(focus)})`,
|
|
54388
54863
|
" " + "Without context-mode".padEnd(LABEL_W) + "|" + bar(focus.produced, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.produced).padStart(NUM_W),
|
|
54389
54864
|
" " + "With context-mode".padEnd(LABEL_W) + "|" + bar(focus.returned, top, STATS_HEAD_BAR, "\u2588", "\u2591") + "|" + bytes4(focus.returned).padStart(NUM_W),
|
|
54390
|
-
|
|
54865
|
+
...focus.saved > 0 ? [windowLine(focus.saved), STATS_TOKEN_NOTE] : [],
|
|
54866
|
+
...hookLine(f.redirected, f.replaced),
|
|
54391
54867
|
"",
|
|
54392
|
-
...
|
|
54868
|
+
...lastDays(f.week, project.calls + f.redirected),
|
|
54869
|
+
// D-STATS-FIX-1 (5): one DB per project holds every session of it, so project and all-time are one row.
|
|
54870
|
+
"By scope",
|
|
54871
|
+
...table2("Scope", [{ name: "session", ...session }, { name: "project (all-time)", ...project }]),
|
|
54393
54872
|
"",
|
|
54394
|
-
"
|
|
54873
|
+
"By tool (this project)",
|
|
54395
54874
|
...table2("Tool", toolRows(f.tools)),
|
|
54396
|
-
""
|
|
54875
|
+
"",
|
|
54876
|
+
...f.top.length > 0 ? [
|
|
54877
|
+
"Largest single outputs (made \u2192 sent to the chat)",
|
|
54878
|
+
...f.top.map((t) => " " + label(toolName(t.name)) + bytes4(t.produced).padStart(NUM_W) + " \u2192 " + bytes4(t.returned).padStart(NUM_W)),
|
|
54879
|
+
""
|
|
54880
|
+
] : []
|
|
54397
54881
|
];
|
|
54398
54882
|
const agents = /* @__PURE__ */ new Map();
|
|
54399
54883
|
for (const g of f.groups) agents.set(g.agent, sum([agents.get(g.agent) ?? EMPTY3, g]));
|
|
54400
54884
|
if (!agents.has(agent)) agents.set(agent, EMPTY3);
|
|
54401
|
-
lines.push(...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
54885
|
+
lines.push("By agent (this project)", ...table2("Agent", [...agents].map(([name, t]) => ({ name, ...t })).sort(bySaved)), "");
|
|
54402
54886
|
const maxKind = Math.max(0, ...[...f.kinds.values()].map((k) => k.project));
|
|
54403
54887
|
lines.push("Kept in the session journal", " " + "Journal".padEnd(LABEL_W) + "Session".padStart(STATS_KIND_W) + "Project".padStart(STATS_KIND_W));
|
|
54404
54888
|
for (const [kind, name] of STATS_KIND_LABELS) {
|
|
@@ -54407,9 +54891,12 @@ function report(f, sessionId, agent) {
|
|
|
54407
54891
|
}
|
|
54408
54892
|
lines.push("", ...STATS_JOURNAL_HINTS.map((h) => " " + h), "");
|
|
54409
54893
|
lines.push(
|
|
54410
|
-
" " + "
|
|
54894
|
+
" " + "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")}`,
|
|
54411
54895
|
" " + "Database file".padEnd(LABEL_W) + bytes4(f.dbBytes),
|
|
54412
|
-
" " + "Sessions".padEnd(LABEL_W) + `${int4(f.sessions)} \xB7 agents ${int4(f.agents)} \xB7 active days ${int4(f.days)}
|
|
54896
|
+
" " + "Sessions".padEnd(LABEL_W) + `${int4(f.sessions)} \xB7 agents ${int4(f.agents)} \xB7 active days ${int4(f.days)}`,
|
|
54897
|
+
"",
|
|
54898
|
+
STATS_FOOTER_URL,
|
|
54899
|
+
"github.com/" + ISSUE_REPO_SLUG
|
|
54413
54900
|
);
|
|
54414
54901
|
return lines.map(fit).join("\n");
|
|
54415
54902
|
}
|
|
@@ -54447,28 +54934,28 @@ var ctxStats = Object.freeze({
|
|
|
54447
54934
|
});
|
|
54448
54935
|
|
|
54449
54936
|
// src/core/tools/upgrade.ts
|
|
54450
|
-
import { existsSync as
|
|
54451
|
-
import { basename as basename6, dirname as dirname10, join as
|
|
54937
|
+
import { existsSync as existsSync22, realpathSync as realpathSync10, rmSync as rmSync10 } from "node:fs";
|
|
54938
|
+
import { basename as basename6, dirname as dirname10, join as join22 } from "node:path";
|
|
54452
54939
|
|
|
54453
54940
|
// src/core/ops/host-write.ts
|
|
54454
|
-
import { copyFileSync, existsSync as
|
|
54455
|
-
import { dirname as dirname9, join as
|
|
54941
|
+
import { copyFileSync, existsSync as existsSync17, mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
54942
|
+
import { dirname as dirname9, join as join17 } from "node:path";
|
|
54456
54943
|
function defaultWrite(file2, text) {
|
|
54457
|
-
|
|
54944
|
+
writeFileSync5(file2, text, "utf8");
|
|
54458
54945
|
}
|
|
54459
54946
|
function hostConfigPath(agent, home, env) {
|
|
54460
54947
|
const own4 = OWN_MCP_ENTRY[agent];
|
|
54461
54948
|
if (own4 !== void 0) return ownMcpFileOf(agent, own4.file, env, home);
|
|
54462
54949
|
switch (agent) {
|
|
54463
54950
|
case "opencode":
|
|
54464
|
-
return
|
|
54951
|
+
return join17(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE);
|
|
54465
54952
|
// D-WIN-OPENCODE-DIR-1
|
|
54466
54953
|
case "pi":
|
|
54467
|
-
return
|
|
54954
|
+
return join17(piAgentDirOf(env, home), SETTINGS_FILE);
|
|
54468
54955
|
case "copilot-cli":
|
|
54469
54956
|
return null;
|
|
54470
54957
|
default:
|
|
54471
|
-
return
|
|
54958
|
+
return join17(home, ...AGENT_HOME_DIR[agent], SETTINGS_FILE);
|
|
54472
54959
|
}
|
|
54473
54960
|
}
|
|
54474
54961
|
function cell3(value) {
|
|
@@ -54480,8 +54967,8 @@ function toRow(file2, edit) {
|
|
|
54480
54967
|
function writeWithRollback(file2, text, write, atomic) {
|
|
54481
54968
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
54482
54969
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
54483
|
-
const had =
|
|
54484
|
-
|
|
54970
|
+
const had = existsSync17(file2);
|
|
54971
|
+
mkdirSync6(dirname9(file2), { recursive: true });
|
|
54485
54972
|
if (had) copyFileSync(file2, trash);
|
|
54486
54973
|
try {
|
|
54487
54974
|
write(tmp, text);
|
|
@@ -54510,7 +54997,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
54510
54997
|
if (requested === null) return [];
|
|
54511
54998
|
const current = readHostConfig(row5.id, requested);
|
|
54512
54999
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
54513
|
-
const exists =
|
|
55000
|
+
const exists = existsSync17(current.path);
|
|
54514
55001
|
if (exists && result.text === current.text) return [];
|
|
54515
55002
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
54516
55003
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -54518,8 +55005,8 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
54518
55005
|
}
|
|
54519
55006
|
|
|
54520
55007
|
// src/core/ops/plugin-swap.ts
|
|
54521
|
-
import { existsSync as
|
|
54522
|
-
import { basename as basename5, join as
|
|
55008
|
+
import { existsSync as existsSync18, lstatSync, readdirSync as readdirSync8, readlinkSync, rmSync as rmSync6, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
55009
|
+
import { basename as basename5, join as join18, win32 as win322 } from "node:path";
|
|
54523
55010
|
function linkTarget(path7, win) {
|
|
54524
55011
|
if (!isLink(path7)) return null;
|
|
54525
55012
|
const target = readlinkSync(path7);
|
|
@@ -54538,11 +55025,11 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
54538
55025
|
else renameWithRetry(old, link, opts);
|
|
54539
55026
|
}
|
|
54540
55027
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
54541
|
-
const next =
|
|
54542
|
-
if (!
|
|
55028
|
+
const next = join18(agentDir, sha);
|
|
55029
|
+
if (!existsSync18(next) || !lstatSync(next).isDirectory()) {
|
|
54543
55030
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename5(agentDir), path: next });
|
|
54544
55031
|
}
|
|
54545
|
-
const link =
|
|
55032
|
+
const link = join18(agentDir, PLUGIN_CURRENT_LINK);
|
|
54546
55033
|
const tmp = link + PLUGIN_LINK_TMP_SUFFIX;
|
|
54547
55034
|
const old = link + PLUGIN_LINK_OLD_SUFFIX;
|
|
54548
55035
|
settleLinks(link, tmp, old, opts);
|
|
@@ -54557,15 +55044,15 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
54557
55044
|
if (before !== null) unlinkSync2(old);
|
|
54558
55045
|
const keep = /* @__PURE__ */ new Set([sha]);
|
|
54559
55046
|
if (before !== null) keep.add(before);
|
|
54560
|
-
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) =>
|
|
55047
|
+
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join18(agentDir, name));
|
|
54561
55048
|
for (const dir of removed) rmSync6(dir, { recursive: true, force: true });
|
|
54562
|
-
const previous = before !== null &&
|
|
55049
|
+
const previous = before !== null && existsSync18(join18(agentDir, before)) ? join18(agentDir, before) : null;
|
|
54563
55050
|
return { current: next, previous, removed };
|
|
54564
55051
|
}
|
|
54565
55052
|
|
|
54566
55053
|
// src/core/ops/release-fetch.ts
|
|
54567
|
-
import { existsSync as
|
|
54568
|
-
import { join as
|
|
55054
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync7, rmSync as rmSync7 } from "node:fs";
|
|
55055
|
+
import { join as join19 } from "node:path";
|
|
54569
55056
|
function failed(r) {
|
|
54570
55057
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
54571
55058
|
const status = r.killed ?? String(r.exitCode);
|
|
@@ -54577,9 +55064,9 @@ async function git2(bin, args, cwd, env, signal) {
|
|
|
54577
55064
|
return r.stdout.toString().trim();
|
|
54578
55065
|
}
|
|
54579
55066
|
async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
54580
|
-
const agentDir =
|
|
54581
|
-
|
|
54582
|
-
const fetchDir =
|
|
55067
|
+
const agentDir = join19(resolveConfigDir(env), DATA_PLUGINS_DIR_NAME, agent);
|
|
55068
|
+
mkdirSync7(agentDir, { recursive: true });
|
|
55069
|
+
const fetchDir = join19(agentDir, UPGRADE_FETCH_DIR_PREFIX + process.pid);
|
|
54583
55070
|
rmSync7(fetchDir, { recursive: true, force: true });
|
|
54584
55071
|
const gitBin = findRuntime(GIT_BIN, env);
|
|
54585
55072
|
if (gitBin === null) throw new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -54587,8 +55074,8 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
54587
55074
|
try {
|
|
54588
55075
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
54589
55076
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
54590
|
-
const dir =
|
|
54591
|
-
if (
|
|
55077
|
+
const dir = join19(agentDir, sha);
|
|
55078
|
+
if (existsSync19(dir)) rmSync7(fetchDir, { recursive: true, force: true });
|
|
54592
55079
|
else renameWithRetry(fetchDir, dir, opts);
|
|
54593
55080
|
return { sha, dir };
|
|
54594
55081
|
} catch (e) {
|
|
@@ -54598,15 +55085,15 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
54598
55085
|
}
|
|
54599
55086
|
|
|
54600
55087
|
// src/core/ops/uninstall.ts
|
|
54601
|
-
import { existsSync as
|
|
54602
|
-
import { join as
|
|
55088
|
+
import { existsSync as existsSync20, readdirSync as readdirSync9, rmSync as rmSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
55089
|
+
import { join as join20 } from "node:path";
|
|
54603
55090
|
function row2(area, before, after) {
|
|
54604
55091
|
return { area, before, after };
|
|
54605
55092
|
}
|
|
54606
55093
|
function stopServers(configDir, projectKey) {
|
|
54607
55094
|
const stopped = listLiveOwners(configDir, projectKey);
|
|
54608
|
-
const dir =
|
|
54609
|
-
for (const serverId of stopped)
|
|
55095
|
+
const dir = join20(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
55096
|
+
for (const serverId of stopped) writeFileSync6(join20(dir, serverId + OWNER_STOP_EXT), "", "utf8");
|
|
54610
55097
|
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 };
|
|
54611
55098
|
}
|
|
54612
55099
|
function rootOrNull(adapter, env) {
|
|
@@ -54624,15 +55111,15 @@ function removeCache(adapter, env, configDir) {
|
|
|
54624
55111
|
const root = rootOrNull(adapter, env);
|
|
54625
55112
|
if (root === null) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
54626
55113
|
if (adapter.installMode === "marketplace") {
|
|
54627
|
-
const cache =
|
|
55114
|
+
const cache = join20(claudeDirOf(env, requireHomeDir(env)), HOST_PLUGINS_DIR_NAME, PLUGIN_CACHE_DIR_NAME);
|
|
54628
55115
|
if (!isInside(cache, root) || isInside(root, cache)) return row2(UPGRADE_CACHE_AREA, root, UPGRADE_CACHE_BY_HAND);
|
|
54629
55116
|
}
|
|
54630
55117
|
rmSync8(root, { recursive: true, force: true });
|
|
54631
55118
|
return row2(UPGRADE_CACHE_AREA, root, UPGRADE_REMOVED);
|
|
54632
55119
|
}
|
|
54633
55120
|
case "plugin": {
|
|
54634
|
-
const agentDir =
|
|
54635
|
-
if (!
|
|
55121
|
+
const agentDir = join20(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
55122
|
+
if (!existsSync20(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
54636
55123
|
rmSync8(agentDir, { recursive: true, force: true });
|
|
54637
55124
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
54638
55125
|
}
|
|
@@ -54677,7 +55164,7 @@ function ownEntries(agent, env) {
|
|
|
54677
55164
|
}
|
|
54678
55165
|
if (agent === "opencode") {
|
|
54679
55166
|
return [{
|
|
54680
|
-
file:
|
|
55167
|
+
file: join20(opencodeDirOf(env, home), OPENCODE_BASE_CONFIG_FILE),
|
|
54681
55168
|
// D-WIN-OPENCODE-DIR-1
|
|
54682
55169
|
key: OPENCODE_PLUGIN_KEY,
|
|
54683
55170
|
shown: OPENCODE_PLUGIN_KEY,
|
|
@@ -54688,7 +55175,7 @@ function ownEntries(agent, env) {
|
|
|
54688
55175
|
if (agent === "pi") {
|
|
54689
55176
|
const agentDir = piAgentDirOf(env, home);
|
|
54690
55177
|
return [{
|
|
54691
|
-
file:
|
|
55178
|
+
file: join20(agentDir, SETTINGS_FILE),
|
|
54692
55179
|
key: PI_PACKAGES_KEY,
|
|
54693
55180
|
shown: PI_PACKAGES_KEY,
|
|
54694
55181
|
has: (v) => Array.isArray(v) && v.some((x) => piSource(x) === PI_GIT_PACKAGE),
|
|
@@ -54710,12 +55197,12 @@ function removeOwnEntries(agent, env) {
|
|
|
54710
55197
|
return rows.length === 0 ? [row2(UPGRADE_CONFIG_AREA, "", UPGRADE_NOT_FOUND)] : rows;
|
|
54711
55198
|
}
|
|
54712
55199
|
function removeProjectData(configDir, projectKey) {
|
|
54713
|
-
const projects =
|
|
54714
|
-
const dir =
|
|
54715
|
-
if (!
|
|
55200
|
+
const projects = join20(configDir, PROJECTS_DIR_NAME);
|
|
55201
|
+
const dir = join20(projects, projectKey);
|
|
55202
|
+
if (!existsSync20(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
54716
55203
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
54717
55204
|
for (const name of readdirSync9(dir)) {
|
|
54718
|
-
if (name !== OWNERS_DIR_NAME) rmSync8(
|
|
55205
|
+
if (name !== OWNERS_DIR_NAME) rmSync8(join20(dir, name), { recursive: true, force: true });
|
|
54719
55206
|
}
|
|
54720
55207
|
return row2(UPGRADE_DATA_AREA, dir, UPGRADE_DATA_DELETED);
|
|
54721
55208
|
}
|
|
@@ -54723,12 +55210,12 @@ function runUninstall(input) {
|
|
|
54723
55210
|
const configDir = resolveConfigDir(input.env);
|
|
54724
55211
|
const stop = stopServers(configDir, input.project.projectKey);
|
|
54725
55212
|
const rows = [stop.row, removeCache(input.adapter, input.env, configDir), ...removeOwnEntries(input.adapter.id, input.env)];
|
|
54726
|
-
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA,
|
|
55213
|
+
rows.push(input.confirmDelete ? removeProjectData(configDir, input.project.projectKey) : row2(UPGRADE_DATA_AREA, join20(configDir, PROJECTS_DIR_NAME, input.project.projectKey), UPGRADE_DATA_KEPT));
|
|
54727
55214
|
return { rows, stopped: stop.stopped };
|
|
54728
55215
|
}
|
|
54729
55216
|
|
|
54730
55217
|
// src/core/ops/v1-remove.ts
|
|
54731
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
55218
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync21, readFileSync as readFileSync13, rmSync as rmSync9 } from "node:fs";
|
|
54732
55219
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
54733
55220
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
54734
55221
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -54772,8 +55259,8 @@ function locate(doc, path7) {
|
|
|
54772
55259
|
return null;
|
|
54773
55260
|
}
|
|
54774
55261
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
54775
|
-
const layout = hostLayout(
|
|
54776
|
-
const text = hostText(
|
|
55262
|
+
const layout = hostLayout(readFileSync13(file2, "utf8"));
|
|
55263
|
+
const text = hostText(readFileSync13(file2, "utf8"));
|
|
54777
55264
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
54778
55265
|
const hit = /* @__PURE__ */ new Set();
|
|
54779
55266
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -54809,19 +55296,19 @@ function removeV1(agent, findings) {
|
|
|
54809
55296
|
for (const f of findings) {
|
|
54810
55297
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
54811
55298
|
else if (f.path === "") {
|
|
54812
|
-
if (
|
|
55299
|
+
if (existsSync21(f.file)) {
|
|
54813
55300
|
moveAside(f.file, undo);
|
|
54814
55301
|
done.set(f, UPGRADE_REMOVED);
|
|
54815
55302
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
54816
55303
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
54817
55304
|
}
|
|
54818
55305
|
for (const [file2, list3] of entries) {
|
|
54819
|
-
if (!
|
|
55306
|
+
if (!existsSync21(file2)) {
|
|
54820
55307
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
54821
55308
|
continue;
|
|
54822
55309
|
}
|
|
54823
55310
|
if (file2.endsWith(TOML_EXT)) {
|
|
54824
|
-
const rawToml =
|
|
55311
|
+
const rawToml = readFileSync13(file2, "utf8");
|
|
54825
55312
|
const tomlLayout = hostLayout(rawToml);
|
|
54826
55313
|
let text = hostText(rawToml);
|
|
54827
55314
|
for (const f of list3) {
|
|
@@ -54849,7 +55336,7 @@ function removeV1(agent, findings) {
|
|
|
54849
55336
|
},
|
|
54850
55337
|
rollback() {
|
|
54851
55338
|
for (const u of undo.splice(0).reverse()) {
|
|
54852
|
-
if (!
|
|
55339
|
+
if (!existsSync21(u.trash)) continue;
|
|
54853
55340
|
rmSync9(u.target, { recursive: true, force: true });
|
|
54854
55341
|
renameWithRetry(u.trash, u.target);
|
|
54855
55342
|
}
|
|
@@ -54859,8 +55346,8 @@ function removeV1(agent, findings) {
|
|
|
54859
55346
|
|
|
54860
55347
|
// src/core/ops/verify-sums.ts
|
|
54861
55348
|
import { createHash as createHash2 } from "node:crypto";
|
|
54862
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as
|
|
54863
|
-
import { join as
|
|
55349
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync10, readFileSync as readFileSync14 } from "node:fs";
|
|
55350
|
+
import { join as join21 } from "node:path";
|
|
54864
55351
|
function mismatch() {
|
|
54865
55352
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
54866
55353
|
}
|
|
@@ -54881,24 +55368,24 @@ function walk2(dir, prefix, out) {
|
|
|
54881
55368
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
54882
55369
|
const rel = prefix === "" ? entry.name : prefix + "/" + entry.name;
|
|
54883
55370
|
if (prefix === "" && (entry.name === GIT_DIR_NAME || entry.name === RELEASE_SUMS_FILE)) continue;
|
|
54884
|
-
const abs =
|
|
55371
|
+
const abs = join21(dir, entry.name);
|
|
54885
55372
|
if (entry.isDirectory()) walk2(abs, rel, out);
|
|
54886
55373
|
else if (entry.isFile()) out.set(rel, abs);
|
|
54887
55374
|
else throw mismatch();
|
|
54888
55375
|
}
|
|
54889
55376
|
}
|
|
54890
55377
|
function verifySums(dir) {
|
|
54891
|
-
const sumsPath =
|
|
55378
|
+
const sumsPath = join21(dir, RELEASE_SUMS_FILE);
|
|
54892
55379
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
54893
55380
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
54894
|
-
const sums = parseSums(
|
|
55381
|
+
const sums = parseSums(readFileSync14(sumsPath, "utf8"));
|
|
54895
55382
|
const files = /* @__PURE__ */ new Map();
|
|
54896
55383
|
walk2(dir, "", files);
|
|
54897
55384
|
if (files.size !== sums.size) throw mismatch();
|
|
54898
55385
|
for (const [rel, abs] of files) {
|
|
54899
55386
|
const want = sums.get(rel);
|
|
54900
55387
|
if (want === void 0) throw mismatch();
|
|
54901
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
55388
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync14(abs)).digest(HASH_ENCODING);
|
|
54902
55389
|
if (got !== want) throw mismatch();
|
|
54903
55390
|
}
|
|
54904
55391
|
}
|
|
@@ -54926,8 +55413,8 @@ function pluginRootRow(adapter, env) {
|
|
|
54926
55413
|
return root === own4 ? [] : [row4(UPGRADE_PLUGIN_ROOT_AREA, root, own4)];
|
|
54927
55414
|
}
|
|
54928
55415
|
function isCurrent(agentDir, dir) {
|
|
54929
|
-
const link =
|
|
54930
|
-
return
|
|
55416
|
+
const link = join22(agentDir, PLUGIN_CURRENT_LINK);
|
|
55417
|
+
return existsSync22(link) && realpathSync10.native(link) === realpathSync10.native(dir);
|
|
54931
55418
|
}
|
|
54932
55419
|
async function checkout(adapter, deps) {
|
|
54933
55420
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -55046,12 +55533,12 @@ function checkCall(tool, input) {
|
|
|
55046
55533
|
}
|
|
55047
55534
|
|
|
55048
55535
|
// src/entries/is-entry.ts
|
|
55049
|
-
import { realpathSync as
|
|
55536
|
+
import { realpathSync as realpathSync11 } from "node:fs";
|
|
55050
55537
|
function isEntry(main, argv1, self) {
|
|
55051
55538
|
if (main !== void 0) return main;
|
|
55052
55539
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
55053
55540
|
try {
|
|
55054
|
-
return
|
|
55541
|
+
return realpathSync11(argv1) === realpathSync11(self);
|
|
55055
55542
|
} catch {
|
|
55056
55543
|
return false;
|
|
55057
55544
|
}
|
|
@@ -55127,7 +55614,7 @@ function workspaceFromMeta(meta3) {
|
|
|
55127
55614
|
}
|
|
55128
55615
|
function realOrSame(p) {
|
|
55129
55616
|
try {
|
|
55130
|
-
return
|
|
55617
|
+
return realpathSync12.native(p);
|
|
55131
55618
|
} catch {
|
|
55132
55619
|
return p;
|
|
55133
55620
|
}
|
|
@@ -55175,15 +55662,15 @@ async function startServer(argv, env) {
|
|
|
55175
55662
|
opening.catch(() => pending.delete(project.dbPath));
|
|
55176
55663
|
}
|
|
55177
55664
|
const db = await opening;
|
|
55178
|
-
if (!
|
|
55665
|
+
if (!existsSync23(db.path)) throw new CtxError("DB_GONE");
|
|
55179
55666
|
return db;
|
|
55180
55667
|
}
|
|
55181
55668
|
function stopMarker(configDir, projectKey) {
|
|
55182
|
-
return
|
|
55669
|
+
return join23(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME, serverId + OWNER_STOP_EXT);
|
|
55183
55670
|
}
|
|
55184
55671
|
function stopRequested() {
|
|
55185
55672
|
const configDir = resolveConfigDir(process.env);
|
|
55186
|
-
return held.some((db) =>
|
|
55673
|
+
return held.some((db) => existsSync23(stopMarker(configDir, db.projectKey)));
|
|
55187
55674
|
}
|
|
55188
55675
|
async function journal(project, ctx, name, reply4) {
|
|
55189
55676
|
const db = await ownDb(project);
|