context-mode 2.1.0 → 2.1.2
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 +6 -2
- package/.claude-plugin/plugin.json +5 -2
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +73 -73
- package/SHA256SUMS +18 -21
- package/cli.mjs +190 -145
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +86 -83
- package/opencode/plugin.js +336 -221
- package/package.json +1 -2
- package/pi/index.js +390 -273
- package/qwen-extension.json +1 -1
- package/run.mjs +34 -7
- package/search.mjs +34 -7
- package/server.mjs +366 -255
- package/skills/ctx-doctor/SKILL.md +1 -1
- package/skills/ctx-stats/SKILL.md +1 -1
- package/skills/ctx-upgrade/SKILL.md +1 -1
- package/claude-code/skills/ctx-doctor/SKILL.md +0 -6
- package/claude-code/skills/ctx-stats/SKILL.md +0 -6
- package/claude-code/skills/ctx-upgrade/SKILL.md +0 -6
package/server.mjs
CHANGED
|
@@ -7,7 +7,7 @@ var __export = (target, all) => {
|
|
|
7
7
|
|
|
8
8
|
// src/entries/server.ts
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { existsSync as
|
|
10
|
+
import { existsSync as existsSync25, realpathSync as realpathSync13, rmSync as rmSync12 } from "node:fs";
|
|
11
11
|
import { dirname as dirname13, join as join25 } from "node:path";
|
|
12
12
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
13
13
|
|
|
@@ -305,10 +305,10 @@ function mergeDefs(...defs) {
|
|
|
305
305
|
function cloneDef(schema) {
|
|
306
306
|
return mergeDefs(schema._zod.def);
|
|
307
307
|
}
|
|
308
|
-
function getElementAtPath(obj,
|
|
309
|
-
if (!
|
|
308
|
+
function getElementAtPath(obj, path8) {
|
|
309
|
+
if (!path8)
|
|
310
310
|
return obj;
|
|
311
|
-
return
|
|
311
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
312
312
|
}
|
|
313
313
|
function promiseAllObject(promisesObj) {
|
|
314
314
|
const keys = Object.keys(promisesObj);
|
|
@@ -648,11 +648,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
648
648
|
}
|
|
649
649
|
return false;
|
|
650
650
|
}
|
|
651
|
-
function prefixIssues(
|
|
651
|
+
function prefixIssues(path8, issues) {
|
|
652
652
|
return issues.map((iss) => {
|
|
653
653
|
var _a5;
|
|
654
654
|
(_a5 = iss).path ?? (_a5.path = []);
|
|
655
|
-
iss.path.unshift(
|
|
655
|
+
iss.path.unshift(path8);
|
|
656
656
|
return iss;
|
|
657
657
|
});
|
|
658
658
|
}
|
|
@@ -1113,16 +1113,16 @@ function flattenError(error42, mapper = (issue4) => issue4.message) {
|
|
|
1113
1113
|
}
|
|
1114
1114
|
function formatError(error42, mapper = (issue4) => issue4.message) {
|
|
1115
1115
|
const fieldErrors = { _errors: [] };
|
|
1116
|
-
const processError = (error43,
|
|
1116
|
+
const processError = (error43, path8 = []) => {
|
|
1117
1117
|
for (const issue4 of error43.issues) {
|
|
1118
1118
|
if (issue4.code === "invalid_union" && issue4.errors.length) {
|
|
1119
|
-
issue4.errors.map((issues) => processError({ issues }, [...
|
|
1119
|
+
issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
|
|
1120
1120
|
} else if (issue4.code === "invalid_key") {
|
|
1121
|
-
processError({ issues: issue4.issues }, [...
|
|
1121
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
1122
1122
|
} else if (issue4.code === "invalid_element") {
|
|
1123
|
-
processError({ issues: issue4.issues }, [...
|
|
1123
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
1124
1124
|
} else {
|
|
1125
|
-
const fullpath = [...
|
|
1125
|
+
const fullpath = [...path8, ...issue4.path];
|
|
1126
1126
|
if (fullpath.length === 0) {
|
|
1127
1127
|
fieldErrors._errors.push(mapper(issue4));
|
|
1128
1128
|
} else {
|
|
@@ -7886,10 +7886,10 @@ function mergeDefs2(...defs) {
|
|
|
7886
7886
|
function cloneDef2(schema) {
|
|
7887
7887
|
return mergeDefs2(schema._zod.def);
|
|
7888
7888
|
}
|
|
7889
|
-
function getElementAtPath2(obj,
|
|
7890
|
-
if (!
|
|
7889
|
+
function getElementAtPath2(obj, path8) {
|
|
7890
|
+
if (!path8)
|
|
7891
7891
|
return obj;
|
|
7892
|
-
return
|
|
7892
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
7893
7893
|
}
|
|
7894
7894
|
function promiseAllObject2(promisesObj) {
|
|
7895
7895
|
const keys = Object.keys(promisesObj);
|
|
@@ -8229,11 +8229,11 @@ function explicitlyAborted2(x, startIndex = 0) {
|
|
|
8229
8229
|
}
|
|
8230
8230
|
return false;
|
|
8231
8231
|
}
|
|
8232
|
-
function prefixIssues2(
|
|
8232
|
+
function prefixIssues2(path8, issues) {
|
|
8233
8233
|
return issues.map((iss) => {
|
|
8234
8234
|
var _a5;
|
|
8235
8235
|
(_a5 = iss).path ?? (_a5.path = []);
|
|
8236
|
-
iss.path.unshift(
|
|
8236
|
+
iss.path.unshift(path8);
|
|
8237
8237
|
return iss;
|
|
8238
8238
|
});
|
|
8239
8239
|
}
|
|
@@ -8691,16 +8691,16 @@ function flattenError2(error42, mapper = (issue4) => issue4.message) {
|
|
|
8691
8691
|
}
|
|
8692
8692
|
function formatError2(error42, mapper = (issue4) => issue4.message) {
|
|
8693
8693
|
const fieldErrors = { _errors: [] };
|
|
8694
|
-
const processError = (error43,
|
|
8694
|
+
const processError = (error43, path8 = []) => {
|
|
8695
8695
|
for (const issue4 of error43.issues) {
|
|
8696
8696
|
if (issue4.code === "invalid_union" && issue4.errors.length) {
|
|
8697
|
-
issue4.errors.map((issues) => processError({ issues }, [...
|
|
8697
|
+
issue4.errors.map((issues) => processError({ issues }, [...path8, ...issue4.path]));
|
|
8698
8698
|
} else if (issue4.code === "invalid_key") {
|
|
8699
|
-
processError({ issues: issue4.issues }, [...
|
|
8699
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
8700
8700
|
} else if (issue4.code === "invalid_element") {
|
|
8701
|
-
processError({ issues: issue4.issues }, [...
|
|
8701
|
+
processError({ issues: issue4.issues }, [...path8, ...issue4.path]);
|
|
8702
8702
|
} else {
|
|
8703
|
-
const fullpath = [...
|
|
8703
|
+
const fullpath = [...path8, ...issue4.path];
|
|
8704
8704
|
if (fullpath.length === 0) {
|
|
8705
8705
|
fieldErrors._errors.push(mapper(issue4));
|
|
8706
8706
|
} else {
|
|
@@ -16916,9 +16916,9 @@ var rev2026Codec = {
|
|
|
16916
16916
|
});
|
|
16917
16917
|
const parsed = buildSchemas2026().RequestMetaEnvelopeSchema.safeParse(meta3);
|
|
16918
16918
|
if (!parsed.success) for (const issue4 of parsed.error.issues) {
|
|
16919
|
-
const
|
|
16920
|
-
const key =
|
|
16921
|
-
if (
|
|
16919
|
+
const path8 = issue4.path.map(String);
|
|
16920
|
+
const key = path8.length > 0 ? path8.join(".") : "_meta";
|
|
16921
|
+
if (path8.length === 1 && issues.some((existing) => existing.key === key && existing.problem === "missing")) continue;
|
|
16922
16922
|
issues.push({
|
|
16923
16923
|
key,
|
|
16924
16924
|
problem: issue4.message
|
|
@@ -17245,29 +17245,29 @@ var PERMITTED_X_MCP_HEADER_TYPES = /* @__PURE__ */ new Set([
|
|
|
17245
17245
|
function scanXMcpHeaderDeclarations(inputSchema) {
|
|
17246
17246
|
const declarations = [];
|
|
17247
17247
|
const seenLower = /* @__PURE__ */ new Map();
|
|
17248
|
-
const visit2 = (node3,
|
|
17248
|
+
const visit2 = (node3, path8, reachable) => {
|
|
17249
17249
|
if (node3 === null || typeof node3 !== "object") return void 0;
|
|
17250
17250
|
const schema = node3;
|
|
17251
17251
|
if (X_MCP_HEADER_KEY in schema) {
|
|
17252
|
-
if (!reachable ||
|
|
17252
|
+
if (!reachable || path8.length === 0) return `${pathName(path8)}: x-mcp-header is only permitted on properties statically reachable via a chain of 'properties' keys (not under items, additionalProperties, oneOf/anyOf/allOf/not, if/then/else, or $ref)`;
|
|
17253
17253
|
const raw = schema[X_MCP_HEADER_KEY];
|
|
17254
|
-
if (typeof raw !== "string" || raw.length === 0) return `${pathName(
|
|
17255
|
-
if (!RFC9110_TOKEN.test(raw)) return `${pathName(
|
|
17254
|
+
if (typeof raw !== "string" || raw.length === 0) return `${pathName(path8)}: x-mcp-header MUST be a non-empty string`;
|
|
17255
|
+
if (!RFC9110_TOKEN.test(raw)) return `${pathName(path8)}: x-mcp-header '${raw}' is not a valid RFC 9110 token (no spaces, control characters or HTTP delimiters)`;
|
|
17256
17256
|
const type = typeof schema.type === "string" ? schema.type : void 0;
|
|
17257
|
-
if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(
|
|
17257
|
+
if (type === void 0 || !PERMITTED_X_MCP_HEADER_TYPES.has(type)) return `${pathName(path8)}: x-mcp-header is only permitted on primitive-typed properties (string, integer, boolean); got ${type ?? "<none>"}`;
|
|
17258
17258
|
const lower = raw.toLowerCase();
|
|
17259
17259
|
const prior = seenLower.get(lower);
|
|
17260
17260
|
if (prior !== void 0) return `x-mcp-header '${raw}' is not case-insensitively unique (also declared as '${prior}')`;
|
|
17261
17261
|
seenLower.set(lower, raw);
|
|
17262
17262
|
declarations.push({
|
|
17263
|
-
path:
|
|
17263
|
+
path: path8,
|
|
17264
17264
|
headerName: raw,
|
|
17265
17265
|
type
|
|
17266
17266
|
});
|
|
17267
17267
|
}
|
|
17268
17268
|
const properties = schema.properties;
|
|
17269
17269
|
if (properties !== null && typeof properties === "object") for (const [key, child] of Object.entries(properties)) {
|
|
17270
|
-
const fault$1 = visit2(child, [...
|
|
17270
|
+
const fault$1 = visit2(child, [...path8, key], reachable);
|
|
17271
17271
|
if (fault$1 !== void 0) return fault$1;
|
|
17272
17272
|
}
|
|
17273
17273
|
for (const k of NON_REACHABLE_SUBSCHEMA_KEYWORDS) {
|
|
@@ -17275,7 +17275,7 @@ function scanXMcpHeaderDeclarations(inputSchema) {
|
|
|
17275
17275
|
if (sub === void 0) continue;
|
|
17276
17276
|
const branches = Array.isArray(sub) ? sub : sub !== null && typeof sub === "object" && OBJECT_VALUED_SUBSCHEMA_KEYWORDS.has(k) ? Object.values(sub) : [sub];
|
|
17277
17277
|
for (const branch of branches) {
|
|
17278
|
-
const fault$1 = visit2(branch, [...
|
|
17278
|
+
const fault$1 = visit2(branch, [...path8, `<${k}>`], false);
|
|
17279
17279
|
if (fault$1 !== void 0) return fault$1;
|
|
17280
17280
|
}
|
|
17281
17281
|
}
|
|
@@ -17315,8 +17315,8 @@ var OBJECT_VALUED_SUBSCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
|
17315
17315
|
"$defs",
|
|
17316
17316
|
"definitions"
|
|
17317
17317
|
]);
|
|
17318
|
-
function pathName(
|
|
17319
|
-
return
|
|
17318
|
+
function pathName(path8) {
|
|
17319
|
+
return path8.length === 0 ? "<root>" : path8.join(".");
|
|
17320
17320
|
}
|
|
17321
17321
|
var HEADER_MISMATCH_ERROR_CODE = -32020;
|
|
17322
17322
|
var INBOUND_VALIDATION_LADDER = [
|
|
@@ -17605,7 +17605,7 @@ var PROPERTY_KEYS_BY_TYPE = {
|
|
|
17605
17605
|
array: shapeKeys([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema])
|
|
17606
17606
|
};
|
|
17607
17607
|
var SUPPORTED_STRING_FORMATS = new Set(StringSchemaSchema.shape.format.unwrap().options);
|
|
17608
|
-
function walkProperty(node3,
|
|
17608
|
+
function walkProperty(node3, path8, vendor, unsupported) {
|
|
17609
17609
|
if (!isJsonObject(node3)) return node3;
|
|
17610
17610
|
const allowedKeys = typeof node3.type === "string" && Object.hasOwn(PROPERTY_KEYS_BY_TYPE, node3.type) ? PROPERTY_KEYS_BY_TYPE[node3.type] : void 0;
|
|
17611
17611
|
if (allowedKeys === void 0) return node3;
|
|
@@ -17613,8 +17613,8 @@ function walkProperty(node3, path7, vendor, unsupported) {
|
|
|
17613
17613
|
for (const [key, value] of Object.entries(node3)) if (allowedKeys.has(key) || isAnnotationOnlyJsonSchemaKeyword(key)) pruned[key] = value;
|
|
17614
17614
|
else if (key === "pattern" && node3.type === "string" && typeof node3.format === "string") {
|
|
17615
17615
|
if (!SUPPORTED_STRING_FORMATS.has(node3.format)) pruned[key] = value;
|
|
17616
|
-
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${
|
|
17617
|
-
} else unsupported.push(`${
|
|
17616
|
+
else if (typeof value !== "string" || !isLibraryFormatPattern(node3.format, value, vendor)) unsupported.push(`${path8}.${key}`);
|
|
17617
|
+
} else unsupported.push(`${path8}.${key}`);
|
|
17618
17618
|
return pruned;
|
|
17619
17619
|
}
|
|
17620
17620
|
function walkRequestedSchema(converted, vendor) {
|
|
@@ -17631,11 +17631,11 @@ function describeUnsupportedProperties(pruned, fallback) {
|
|
|
17631
17631
|
const offenders = Object.entries(pruned.properties).filter(([, node3]) => !parseSchema(PrimitiveSchemaDefinitionSchema, node3).success).map(([name]) => `properties.${name}`);
|
|
17632
17632
|
return offenders.length > 0 ? offenders.join(", ") : fallback;
|
|
17633
17633
|
}
|
|
17634
|
-
function findDroppedConstraintPaths(original, parsed,
|
|
17635
|
-
if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${
|
|
17634
|
+
function findDroppedConstraintPaths(original, parsed, path8 = "") {
|
|
17635
|
+
if (Array.isArray(original) && Array.isArray(parsed)) return original.flatMap((item, index) => findDroppedConstraintPaths(item, parsed[index], `${path8}[${index}]`));
|
|
17636
17636
|
if (!isJsonObject(original) || !isJsonObject(parsed)) return [];
|
|
17637
17637
|
return Object.entries(original).flatMap(([key, value]) => {
|
|
17638
|
-
const childPath =
|
|
17638
|
+
const childPath = path8 ? `${path8}.${key}` : key;
|
|
17639
17639
|
if (!Object.prototype.hasOwnProperty.call(parsed, key)) return isAnnotationOnlyJsonSchemaKeyword(key) ? [] : [childPath];
|
|
17640
17640
|
return findDroppedConstraintPaths(value, parsed[key], childPath);
|
|
17641
17641
|
});
|
|
@@ -21723,8 +21723,8 @@ var require_utils = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
21723
21723
|
for (let i = 0; i < str.length; i++) if (str[i] === token) ind++;
|
|
21724
21724
|
return ind;
|
|
21725
21725
|
}
|
|
21726
|
-
function removeDotSegments(
|
|
21727
|
-
let input =
|
|
21726
|
+
function removeDotSegments(path8) {
|
|
21727
|
+
let input = path8;
|
|
21728
21728
|
const output = [];
|
|
21729
21729
|
let nextSlash = -1;
|
|
21730
21730
|
let len = 0;
|
|
@@ -21877,8 +21877,8 @@ var require_schemes = /* @__PURE__ */ __commonJSMin((exports, module) => {
|
|
|
21877
21877
|
wsComponent.secure = void 0;
|
|
21878
21878
|
}
|
|
21879
21879
|
if (wsComponent.resourceName) {
|
|
21880
|
-
const [
|
|
21881
|
-
wsComponent.path =
|
|
21880
|
+
const [path8, query] = wsComponent.resourceName.split("?");
|
|
21881
|
+
wsComponent.path = path8 && path8 !== "/" ? path8 : void 0;
|
|
21882
21882
|
wsComponent.query = query;
|
|
21883
21883
|
wsComponent.resourceName = void 0;
|
|
21884
21884
|
}
|
|
@@ -28407,7 +28407,7 @@ var DECISION_SOURCE = "decision";
|
|
|
28407
28407
|
var DECISION_USER_LABEL = "decision (user)";
|
|
28408
28408
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
28409
28409
|
var RELEASE_BRANCH = "release";
|
|
28410
|
-
var BUNDLE_SHA = true ? "
|
|
28410
|
+
var BUNDLE_SHA = true ? "1ce32b37e98bfffd69edcd071b13e1e2d43a0ae9" : void 0;
|
|
28411
28411
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
28412
28412
|
var DOCTOR_LABEL = Object.freeze({
|
|
28413
28413
|
D1: "version",
|
|
@@ -28729,6 +28729,11 @@ var V1_CACHE_HEAL_NAME = "context-mode-cache-heal";
|
|
|
28729
28729
|
var V1_CACHE_HEAL_EXTS = Object.freeze([".mjs", ".sh"]);
|
|
28730
28730
|
var V1_STATUSLINE_COMMAND = "context-mode statusline";
|
|
28731
28731
|
var V1_PI_PACKAGE = "npm:context-mode";
|
|
28732
|
+
var PI_NPM_DIR = "npm";
|
|
28733
|
+
var PI_NODE_MODULES_DIR = "node_modules";
|
|
28734
|
+
var PI_PACKAGE_JSON_FILE = "package.json";
|
|
28735
|
+
var PI_LIST_COMMAND = "pi list";
|
|
28736
|
+
var PI_CURRENT_MAJOR = 2;
|
|
28732
28737
|
var V1_OPENCODE_PLUGIN_SPEC = "context-mode";
|
|
28733
28738
|
var V1_TMP_PREFIX = "context-mode-";
|
|
28734
28739
|
var V1_TOML_SECTION_ROOT = "mcp_servers";
|
|
@@ -29169,9 +29174,9 @@ function readUserVersion(raw) {
|
|
|
29169
29174
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
29170
29175
|
return row5.user_version;
|
|
29171
29176
|
}
|
|
29172
|
-
function createAtomically(sqlite,
|
|
29177
|
+
function createAtomically(sqlite, path8) {
|
|
29173
29178
|
const { randomUUID: randomUUID2 } = process.getBuiltinModule("node:crypto");
|
|
29174
|
-
const tmp =
|
|
29179
|
+
const tmp = path8 + "." + randomUUID2() + DB_TMP_SUFFIX;
|
|
29175
29180
|
try {
|
|
29176
29181
|
const raw = new sqlite.DatabaseSync(tmp, { timeout: DB_TIMEOUT_MS });
|
|
29177
29182
|
try {
|
|
@@ -29180,7 +29185,7 @@ function createAtomically(sqlite, path7) {
|
|
|
29180
29185
|
raw.close();
|
|
29181
29186
|
}
|
|
29182
29187
|
try {
|
|
29183
|
-
linkSync(tmp,
|
|
29188
|
+
linkSync(tmp, path8);
|
|
29184
29189
|
} catch (err) {
|
|
29185
29190
|
if (err.code !== "EEXIST") throw err;
|
|
29186
29191
|
}
|
|
@@ -29188,11 +29193,11 @@ function createAtomically(sqlite, path7) {
|
|
|
29188
29193
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
29189
29194
|
}
|
|
29190
29195
|
}
|
|
29191
|
-
function openWritable(sqlite,
|
|
29196
|
+
function openWritable(sqlite, path8) {
|
|
29192
29197
|
let raw = null;
|
|
29193
29198
|
try {
|
|
29194
|
-
if (!existsSync(
|
|
29195
|
-
raw = new sqlite.DatabaseSync(
|
|
29199
|
+
if (!existsSync(path8)) createAtomically(sqlite, path8);
|
|
29200
|
+
raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS });
|
|
29196
29201
|
applyMigrations(raw, readUserVersion(raw));
|
|
29197
29202
|
return raw;
|
|
29198
29203
|
} catch (err) {
|
|
@@ -29200,8 +29205,8 @@ function openWritable(sqlite, path7) {
|
|
|
29200
29205
|
throw err;
|
|
29201
29206
|
}
|
|
29202
29207
|
}
|
|
29203
|
-
function openReadOnly(sqlite,
|
|
29204
|
-
const raw = new sqlite.DatabaseSync(
|
|
29208
|
+
function openReadOnly(sqlite, path8) {
|
|
29209
|
+
const raw = new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
29205
29210
|
try {
|
|
29206
29211
|
const found = readUserVersion(raw);
|
|
29207
29212
|
if (found !== SCHEMA_VERSION) throw new CtxError("SCHEMA_STALE", { found, want: SCHEMA_VERSION });
|
|
@@ -29215,20 +29220,20 @@ async function openDb(project, opts) {
|
|
|
29215
29220
|
if (isBelow(process.version, NODE_MIN)) throw new CtxError("NODE_TOO_OLD", { v: process.version });
|
|
29216
29221
|
const sqlite = await loadSqlite();
|
|
29217
29222
|
mkdirSync(project.projectDir, { recursive: true });
|
|
29218
|
-
const
|
|
29219
|
-
const sibling = existsSync(
|
|
29220
|
-
if (sibling && !existsSync(
|
|
29223
|
+
const path8 = project.dbPath;
|
|
29224
|
+
const sibling = existsSync(path8 + DB_WAL_SUFFIX) || existsSync(path8 + DB_SHM_SUFFIX);
|
|
29225
|
+
if (sibling && !existsSync(path8)) {
|
|
29221
29226
|
throw new CtxError("DB_GONE");
|
|
29222
29227
|
}
|
|
29223
29228
|
try {
|
|
29224
29229
|
let raw;
|
|
29225
29230
|
if (opts?.readOnly === true) {
|
|
29226
|
-
if (!existsSync(
|
|
29227
|
-
raw = openReadOnly(sqlite,
|
|
29231
|
+
if (!existsSync(path8)) openWritable(sqlite, path8).close();
|
|
29232
|
+
raw = openReadOnly(sqlite, path8);
|
|
29228
29233
|
} else {
|
|
29229
|
-
raw = openWritable(sqlite,
|
|
29234
|
+
raw = openWritable(sqlite, path8);
|
|
29230
29235
|
}
|
|
29231
|
-
return { raw, projectKey: project.projectKey, path:
|
|
29236
|
+
return { raw, projectKey: project.projectKey, path: path8, ...opts?.readOnly === true ? { readOnly: true } : {} };
|
|
29232
29237
|
} catch (err) {
|
|
29233
29238
|
if (isCorrupt(err)) throw new CtxError("DB_CORRUPT");
|
|
29234
29239
|
throw err;
|
|
@@ -29401,21 +29406,21 @@ function kiroDirOf(env, home, platform = process.platform) {
|
|
|
29401
29406
|
if (dir === void 0 || dir === "" || !p.isAbsolute(dir)) return fallback;
|
|
29402
29407
|
if (platform === "win32" && p.parse(dir).root.length < 2) return fallback;
|
|
29403
29408
|
const abs = p.resolve(dir);
|
|
29404
|
-
const
|
|
29405
|
-
const target =
|
|
29409
|
+
const real3 = platform === process.platform ? realOrSelf : (x) => x;
|
|
29410
|
+
const target = real3(abs);
|
|
29406
29411
|
if (p.parse(target).root === target) return fallback;
|
|
29407
|
-
const up = p.relative(target,
|
|
29412
|
+
const up = p.relative(target, real3(p.resolve(home)));
|
|
29408
29413
|
if (!p.isAbsolute(up) && up.split(p.sep)[0] !== "..") return fallback;
|
|
29409
29414
|
return abs;
|
|
29410
29415
|
}
|
|
29411
|
-
function realOrSelf(
|
|
29416
|
+
function realOrSelf(path8) {
|
|
29412
29417
|
const tail = [];
|
|
29413
|
-
for (let at =
|
|
29418
|
+
for (let at = path8; ; ) {
|
|
29414
29419
|
try {
|
|
29415
29420
|
return join(realpathSync.native(at), ...tail.reverse());
|
|
29416
29421
|
} catch {
|
|
29417
29422
|
const up = dirname(at);
|
|
29418
|
-
if (up === at) return
|
|
29423
|
+
if (up === at) return path8;
|
|
29419
29424
|
tail.push(basename(at));
|
|
29420
29425
|
at = up;
|
|
29421
29426
|
}
|
|
@@ -33080,10 +33085,10 @@ function assignProp3(target, prop, value) {
|
|
|
33080
33085
|
configurable: true
|
|
33081
33086
|
});
|
|
33082
33087
|
}
|
|
33083
|
-
function getElementAtPath3(obj,
|
|
33084
|
-
if (!
|
|
33088
|
+
function getElementAtPath3(obj, path8) {
|
|
33089
|
+
if (!path8)
|
|
33085
33090
|
return obj;
|
|
33086
|
-
return
|
|
33091
|
+
return path8.reduce((acc, key) => acc?.[key], obj);
|
|
33087
33092
|
}
|
|
33088
33093
|
function promiseAllObject3(promisesObj) {
|
|
33089
33094
|
const keys = Object.keys(promisesObj);
|
|
@@ -33403,11 +33408,11 @@ function aborted3(x, startIndex = 0) {
|
|
|
33403
33408
|
}
|
|
33404
33409
|
return false;
|
|
33405
33410
|
}
|
|
33406
|
-
function prefixIssues3(
|
|
33411
|
+
function prefixIssues3(path8, issues) {
|
|
33407
33412
|
return issues.map((iss) => {
|
|
33408
33413
|
var _a5;
|
|
33409
33414
|
(_a5 = iss).path ?? (_a5.path = []);
|
|
33410
|
-
iss.path.unshift(
|
|
33415
|
+
iss.path.unshift(path8);
|
|
33411
33416
|
return iss;
|
|
33412
33417
|
});
|
|
33413
33418
|
}
|
|
@@ -33544,7 +33549,7 @@ function treeifyError2(error42, _mapper) {
|
|
|
33544
33549
|
return issue4.message;
|
|
33545
33550
|
};
|
|
33546
33551
|
const result = { errors: [] };
|
|
33547
|
-
const processError = (error43,
|
|
33552
|
+
const processError = (error43, path8 = []) => {
|
|
33548
33553
|
var _a5, _b;
|
|
33549
33554
|
for (const issue4 of error43.issues) {
|
|
33550
33555
|
if (issue4.code === "invalid_union" && issue4.errors.length) {
|
|
@@ -33554,7 +33559,7 @@ function treeifyError2(error42, _mapper) {
|
|
|
33554
33559
|
} else if (issue4.code === "invalid_element") {
|
|
33555
33560
|
processError({ issues: issue4.issues }, issue4.path);
|
|
33556
33561
|
} else {
|
|
33557
|
-
const fullpath = [...
|
|
33562
|
+
const fullpath = [...path8, ...issue4.path];
|
|
33558
33563
|
if (fullpath.length === 0) {
|
|
33559
33564
|
result.errors.push(mapper(issue4));
|
|
33560
33565
|
continue;
|
|
@@ -33584,9 +33589,9 @@ function treeifyError2(error42, _mapper) {
|
|
|
33584
33589
|
processError(error42);
|
|
33585
33590
|
return result;
|
|
33586
33591
|
}
|
|
33587
|
-
function toDotPath(
|
|
33592
|
+
function toDotPath(path8) {
|
|
33588
33593
|
const segs = [];
|
|
33589
|
-
for (const seg of
|
|
33594
|
+
for (const seg of path8) {
|
|
33590
33595
|
if (typeof seg === "number")
|
|
33591
33596
|
segs.push(`[${seg}]`);
|
|
33592
33597
|
else if (typeof seg === "symbol")
|
|
@@ -44161,19 +44166,19 @@ function steeringFiles(worktree) {
|
|
|
44161
44166
|
function readAutoMemory(project) {
|
|
44162
44167
|
const rows = [];
|
|
44163
44168
|
for (const segs of [...MEMORY_FILES, ...steeringFiles(project.worktree)]) {
|
|
44164
|
-
const
|
|
44165
|
-
if (!isInside(project.worktree,
|
|
44169
|
+
const path8 = join5(project.worktree, ...segs);
|
|
44170
|
+
if (!isInside(project.worktree, path8)) continue;
|
|
44166
44171
|
try {
|
|
44167
|
-
const st = statSync3(
|
|
44172
|
+
const st = statSync3(path8);
|
|
44168
44173
|
if (!st.isFile()) continue;
|
|
44169
44174
|
rows.push({
|
|
44170
44175
|
origin: "memory",
|
|
44171
44176
|
ts: Math.trunc(st.mtimeMs),
|
|
44172
44177
|
seq: null,
|
|
44173
44178
|
sourceId: null,
|
|
44174
|
-
path:
|
|
44179
|
+
path: path8,
|
|
44175
44180
|
label: segs.join("/"),
|
|
44176
|
-
text: readFileSync3(
|
|
44181
|
+
text: readFileSync3(path8, "utf8")
|
|
44177
44182
|
});
|
|
44178
44183
|
} catch {
|
|
44179
44184
|
}
|
|
@@ -44797,7 +44802,7 @@ var ctxBatch = Object.freeze({
|
|
|
44797
44802
|
});
|
|
44798
44803
|
|
|
44799
44804
|
// src/core/tools/doctor.ts
|
|
44800
|
-
import { readdirSync as readdirSync7, readFileSync as
|
|
44805
|
+
import { readdirSync as readdirSync7, readFileSync as readFileSync11, existsSync as existsSync16 } from "node:fs";
|
|
44801
44806
|
import { basename as basename5, join as join15 } from "node:path";
|
|
44802
44807
|
|
|
44803
44808
|
// src/adapters/claude-code.ts
|
|
@@ -44838,7 +44843,7 @@ function outputOf(resp) {
|
|
|
44838
44843
|
function textSlot(r) {
|
|
44839
44844
|
const file2 = r.file;
|
|
44840
44845
|
if (r.type === "text" && typeof file2 === "object" && file2 !== null && typeof file2.content === "string") {
|
|
44841
|
-
return { text: file2.content, put: (o, output) => ({ ...o, file:
|
|
44846
|
+
return { text: file2.content, put: (o, output) => ({ ...o, file: readFile(o.file, output) }) };
|
|
44842
44847
|
}
|
|
44843
44848
|
if (isGrepContent(r)) return { text: r.content, put: (o, output) => ({ ...o, content: output }) };
|
|
44844
44849
|
if (Array.isArray(r.filenames) && r.filenames.every((f) => typeof f === "string")) {
|
|
@@ -44847,13 +44852,35 @@ function textSlot(r) {
|
|
|
44847
44852
|
if (typeof r.result === "string") return { text: r.result, put: (o, output) => ({ ...o, result: output }) };
|
|
44848
44853
|
return null;
|
|
44849
44854
|
}
|
|
44855
|
+
function readFile(file2, output) {
|
|
44856
|
+
const start = typeof file2.startLine === "number" ? file2.startLine : 1;
|
|
44857
|
+
const lines = String(file2.content).split("\n");
|
|
44858
|
+
const read = typeof file2.numLines === "number" ? file2.numLines : lines.length;
|
|
44859
|
+
const out = output.split("\n");
|
|
44860
|
+
const run = firstRun(lines, out);
|
|
44861
|
+
if (run === null) return { ...file2, content: output, startLine: start + read, numLines: out.length };
|
|
44862
|
+
const kept = out.slice(0, run.length);
|
|
44863
|
+
if (run.length < out.length) kept.push(out[out.length - 1]);
|
|
44864
|
+
return { ...file2, content: kept.join("\n"), startLine: start + run.at, numLines: kept.length };
|
|
44865
|
+
}
|
|
44866
|
+
function firstRun(lines, out) {
|
|
44867
|
+
let best = null;
|
|
44868
|
+
for (let i = 0; i < lines.length; i++) {
|
|
44869
|
+
if (lines[i] !== out[0]) continue;
|
|
44870
|
+
let n = 1;
|
|
44871
|
+
while (n < out.length && i + n < lines.length && lines[i + n] === out[n]) n++;
|
|
44872
|
+
if (best === null || n > best.length) best = { at: i, length: n };
|
|
44873
|
+
if (n === out.length) break;
|
|
44874
|
+
}
|
|
44875
|
+
return best;
|
|
44876
|
+
}
|
|
44850
44877
|
function isShellShape(resp) {
|
|
44851
44878
|
const r = resp;
|
|
44852
44879
|
return typeof r.stdout === "string" || typeof r.stderr === "string";
|
|
44853
44880
|
}
|
|
44854
44881
|
function isGrepContent(resp) {
|
|
44855
44882
|
const r = resp;
|
|
44856
|
-
return r.mode === "content" && typeof r.content === "string";
|
|
44883
|
+
return (r.mode === "content" || r.mode === "count") && typeof r.content === "string";
|
|
44857
44884
|
}
|
|
44858
44885
|
function blocksOf(resp) {
|
|
44859
44886
|
const parts = [];
|
|
@@ -44869,6 +44896,7 @@ function readResult(resp) {
|
|
|
44869
44896
|
const text = outputOf(resp);
|
|
44870
44897
|
const isError = typeof resp === "object" && resp !== null && resp.is_error === true;
|
|
44871
44898
|
const info = { isError, bytes: Buffer.byteLength(text), text };
|
|
44899
|
+
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && isShellShape(resp)) info.shape = resp;
|
|
44872
44900
|
if (typeof resp === "object" && resp !== null && !Array.isArray(resp) && !isShellShape(resp)) {
|
|
44873
44901
|
if (textSlot(resp) !== null) info.shape = resp;
|
|
44874
44902
|
else info.keep = true;
|
|
@@ -44908,8 +44936,11 @@ function decodeClaudeShape(raw, agent, ownPrefix, sources) {
|
|
|
44908
44936
|
return ev;
|
|
44909
44937
|
}
|
|
44910
44938
|
function replaceShape(ev, output) {
|
|
44911
|
-
if (ev.tool?.canonicalName === "Bash") return { stdout: output, stderr: "", interrupted: false };
|
|
44912
44939
|
const shape = ev.result?.shape;
|
|
44940
|
+
if (ev.tool?.canonicalName === "Bash") {
|
|
44941
|
+
const { persistedOutputPath: _p, persistedOutputSize: _s, ...host } = shape ?? {};
|
|
44942
|
+
return { interrupted: false, ...host, stdout: output, stderr: "" };
|
|
44943
|
+
}
|
|
44913
44944
|
const slot = shape === void 0 ? null : textSlot(shape);
|
|
44914
44945
|
if (shape !== void 0 && slot !== null) return slot.put(shape, output);
|
|
44915
44946
|
if (ev.result?.blocks === true) return [{ type: "text", text: output }];
|
|
@@ -45404,7 +45435,7 @@ var PI_EVENTS = {
|
|
|
45404
45435
|
tool_call: { event: "PreToolUse" },
|
|
45405
45436
|
tool_result: { event: "PostToolUse" }
|
|
45406
45437
|
};
|
|
45407
|
-
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read" };
|
|
45438
|
+
var NATIVE_TO_CANONICAL6 = { bash: "Bash", read: "Read", edit: "Edit", write: "Write" };
|
|
45408
45439
|
function record4(v) {
|
|
45409
45440
|
return typeof v === "object" && v !== null && !Array.isArray(v) ? v : {};
|
|
45410
45441
|
}
|
|
@@ -45529,8 +45560,8 @@ var ADAPTERS = Object.freeze([
|
|
|
45529
45560
|
hookTimeoutMs: HOOK_TIMEOUT_MS,
|
|
45530
45561
|
denyChannel: "deny-reason",
|
|
45531
45562
|
hookChannel: { kind: "package", path: "hooks/claude-code.json" },
|
|
45532
|
-
skillChannel: { kind: "package", path: "
|
|
45533
|
-
// ADR-0020, D-
|
|
45563
|
+
skillChannel: { kind: "package", path: "skills" },
|
|
45564
|
+
// ADR-0020, D-R33-CC-SKILLS-1: Claude Code always loads <plugin>/skills, shared with gemini and qwen
|
|
45534
45565
|
decode: decode3,
|
|
45535
45566
|
encode: encode3
|
|
45536
45567
|
},
|
|
@@ -45674,8 +45705,9 @@ var ADAPTERS = Object.freeze([
|
|
|
45674
45705
|
installMode: "in-process",
|
|
45675
45706
|
projectSource: "pi:ctx.cwd",
|
|
45676
45707
|
toolNamePrefix: TOOL_NAME_PREFIX9,
|
|
45677
|
-
nativeTools: { shell: ["bash"], read: ["read"] },
|
|
45708
|
+
nativeTools: { shell: ["bash", "powershell"], read: ["read"] },
|
|
45678
45709
|
execReadOnlyHint: false,
|
|
45710
|
+
// D-R38-PI-PWSH-1: Pi on Windows names its shell tool "powershell"
|
|
45679
45711
|
eventMap: { SessionStart: "session_start", UserPromptSubmit: "input", PreToolUse: "tool_call", PostToolUse: "tool_result" },
|
|
45680
45712
|
compactDelivery: "pi-flag",
|
|
45681
45713
|
compactSummary: "none",
|
|
@@ -45742,7 +45774,7 @@ function ownBundleDir() {
|
|
|
45742
45774
|
}
|
|
45743
45775
|
|
|
45744
45776
|
// src/core/ops/doctor-config.ts
|
|
45745
|
-
import { existsSync as
|
|
45777
|
+
import { existsSync as existsSync9, readdirSync as readdirSync6 } from "node:fs";
|
|
45746
45778
|
import { join as join10 } from "node:path";
|
|
45747
45779
|
|
|
45748
45780
|
// src/core/ops/detect-v1.ts
|
|
@@ -47884,15 +47916,15 @@ function withLayout(text, layout) {
|
|
|
47884
47916
|
}
|
|
47885
47917
|
|
|
47886
47918
|
// src/core/ops/host-config.ts
|
|
47887
|
-
function formatOf(
|
|
47888
|
-
if (
|
|
47889
|
-
if (
|
|
47919
|
+
function formatOf(path8) {
|
|
47920
|
+
if (path8.endsWith(JSONC_EXT)) return "jsonc";
|
|
47921
|
+
if (path8.endsWith(TOML_EXT)) return "toml";
|
|
47890
47922
|
return "json";
|
|
47891
47923
|
}
|
|
47892
|
-
function readHostConfig(agent,
|
|
47893
|
-
let file2 =
|
|
47924
|
+
function readHostConfig(agent, path8) {
|
|
47925
|
+
let file2 = path8;
|
|
47894
47926
|
if (agent === "opencode") {
|
|
47895
|
-
const jsonc = join7(dirname5(
|
|
47927
|
+
const jsonc = join7(dirname5(path8), OPENCODE_CONFIG_FILES[0]);
|
|
47896
47928
|
if (existsSync5(jsonc)) file2 = jsonc;
|
|
47897
47929
|
}
|
|
47898
47930
|
const raw = existsSync5(file2) ? readFileSync4(file2, "utf8") : "";
|
|
@@ -48056,14 +48088,14 @@ function scanToml(text) {
|
|
|
48056
48088
|
continue;
|
|
48057
48089
|
}
|
|
48058
48090
|
if (!node3.resolvedKey.every((seg) => typeof seg === "string")) continue;
|
|
48059
|
-
const
|
|
48060
|
-
for (const kv of node3.body) addKey(
|
|
48091
|
+
const path8 = node3.resolvedKey;
|
|
48092
|
+
for (const kv of node3.body) addKey(path8, kv);
|
|
48061
48093
|
if (node3.kind !== "standard") continue;
|
|
48062
48094
|
const start = lineStartOf(text, node3.range[0]);
|
|
48063
48095
|
const headEnd = lineEndOf(text, node3.key.range[1]);
|
|
48064
48096
|
const last2 = node3.body[node3.body.length - 1];
|
|
48065
48097
|
tables.push({
|
|
48066
|
-
path:
|
|
48098
|
+
path: path8,
|
|
48067
48099
|
header: text.slice(start, text[headEnd - 1] === "\n" ? headEnd - 1 : headEnd),
|
|
48068
48100
|
start,
|
|
48069
48101
|
end: last2 === void 0 ? headEnd : lineEndOf(text, last2.range[1])
|
|
@@ -48074,16 +48106,16 @@ function scanToml(text) {
|
|
|
48074
48106
|
function tomlTableSpans(text) {
|
|
48075
48107
|
return scanToml(text).tables;
|
|
48076
48108
|
}
|
|
48077
|
-
function parseHostConfig(agent,
|
|
48109
|
+
function parseHostConfig(agent, path8, text, format) {
|
|
48078
48110
|
try {
|
|
48079
48111
|
return format === "toml" ? scanToml(text).value : scanJson(text, format).value;
|
|
48080
48112
|
} catch {
|
|
48081
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
48113
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
|
|
48082
48114
|
}
|
|
48083
48115
|
}
|
|
48084
|
-
function hostConfigValueAt(value,
|
|
48116
|
+
function hostConfigValueAt(value, path8) {
|
|
48085
48117
|
let cur = value;
|
|
48086
|
-
for (const seg of
|
|
48118
|
+
for (const seg of path8) {
|
|
48087
48119
|
if (!isPlainObject6(cur)) return void 0;
|
|
48088
48120
|
cur = cur[seg];
|
|
48089
48121
|
}
|
|
@@ -48116,32 +48148,32 @@ function indentUnit(root, clean) {
|
|
|
48116
48148
|
function render(value, unit, base) {
|
|
48117
48149
|
return JSON.stringify(value, null, unit).split("\n").join("\n" + base);
|
|
48118
48150
|
}
|
|
48119
|
-
function nest(
|
|
48151
|
+
function nest(path8, value) {
|
|
48120
48152
|
let out = value;
|
|
48121
|
-
for (let k =
|
|
48153
|
+
for (let k = path8.length - 1; k >= 0; k -= 1) out = { [path8[k]]: out };
|
|
48122
48154
|
return out;
|
|
48123
48155
|
}
|
|
48124
|
-
function setJsonText(text, format,
|
|
48156
|
+
function setJsonText(text, format, path8, value) {
|
|
48125
48157
|
const doc = scanJson(text, format);
|
|
48126
48158
|
const unit = indentUnit(doc.root, doc.clean);
|
|
48127
|
-
if (doc.root === null) return render(nest(
|
|
48159
|
+
if (doc.root === null) return render(nest(path8, value), unit, "") + "\n";
|
|
48128
48160
|
let node3 = doc.root;
|
|
48129
48161
|
let depth = 0;
|
|
48130
|
-
while (depth <
|
|
48131
|
-
const hit = node3.members.find((m) => m.key ===
|
|
48162
|
+
while (depth < path8.length && node3.kind === "object") {
|
|
48163
|
+
const hit = node3.members.find((m) => m.key === path8[depth]);
|
|
48132
48164
|
if (hit === void 0) break;
|
|
48133
48165
|
node3 = hit.node;
|
|
48134
48166
|
depth += 1;
|
|
48135
48167
|
}
|
|
48136
|
-
if (depth ===
|
|
48168
|
+
if (depth === path8.length) {
|
|
48137
48169
|
return text.slice(0, node3.start) + render(value, unit, lineIndent(doc.clean, node3.start)) + text.slice(node3.end);
|
|
48138
48170
|
}
|
|
48139
|
-
if (node3.kind !== "object") throw new SyntaxError("not an object at " +
|
|
48140
|
-
const rest = nest(
|
|
48171
|
+
if (node3.kind !== "object") throw new SyntaxError("not an object at " + path8.slice(0, depth).join("."));
|
|
48172
|
+
const rest = nest(path8.slice(depth + 1), value);
|
|
48141
48173
|
const last2 = node3.members[node3.members.length - 1];
|
|
48142
48174
|
if (last2 === void 0) {
|
|
48143
48175
|
const base2 = lineIndent(doc.clean, node3.start);
|
|
48144
|
-
const member2 = "\n" + base2 + unit + JSON.stringify(
|
|
48176
|
+
const member2 = "\n" + base2 + unit + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base2 + unit) + "\n" + base2;
|
|
48145
48177
|
return text.slice(0, node3.start + 1) + member2 + text.slice(node3.end - 1);
|
|
48146
48178
|
}
|
|
48147
48179
|
const base = lineIndent(doc.clean, last2.keyStart);
|
|
@@ -48149,7 +48181,7 @@ function setJsonText(text, format, path7, value) {
|
|
|
48149
48181
|
while (" \r\n".includes(doc.clean[at])) at += 1;
|
|
48150
48182
|
const trailing = doc.clean[at] === ",";
|
|
48151
48183
|
const insertAt = trailing ? at + 1 : last2.node.end;
|
|
48152
|
-
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(
|
|
48184
|
+
const member = (trailing ? "" : ",") + "\n" + base + JSON.stringify(path8[depth]) + ": " + render(rest, unit, base);
|
|
48153
48185
|
return text.slice(0, insertAt) + member + text.slice(insertAt);
|
|
48154
48186
|
}
|
|
48155
48187
|
function tomlScalar(v) {
|
|
@@ -48167,17 +48199,17 @@ function tomlHeaderKey(seg) {
|
|
|
48167
48199
|
}
|
|
48168
48200
|
return seg;
|
|
48169
48201
|
}
|
|
48170
|
-
function tomlBlock(
|
|
48171
|
-
let out = "[" +
|
|
48202
|
+
function tomlBlock(path8, value) {
|
|
48203
|
+
let out = "[" + path8.map(tomlHeaderKey).join(".") + "]\n";
|
|
48172
48204
|
const subs = [];
|
|
48173
48205
|
for (const [k, v] of Object.entries(value)) {
|
|
48174
|
-
if (isPlainObject6(v)) subs.push(tomlBlock([...
|
|
48206
|
+
if (isPlainObject6(v)) subs.push(tomlBlock([...path8, k], v));
|
|
48175
48207
|
else out += tomlHeaderKey(k) + " = " + tomlScalar(v) + "\n";
|
|
48176
48208
|
}
|
|
48177
48209
|
return [out, ...subs].join("\n");
|
|
48178
48210
|
}
|
|
48179
|
-
function under(
|
|
48180
|
-
return
|
|
48211
|
+
function under(path8, prefix) {
|
|
48212
|
+
return path8.length >= prefix.length && prefix.every((seg, k) => path8[k] === seg);
|
|
48181
48213
|
}
|
|
48182
48214
|
function keyLineRange(text, k) {
|
|
48183
48215
|
const ls = lineStartOf(text, k.start);
|
|
@@ -48194,10 +48226,10 @@ function withValueAt(root, rel, value) {
|
|
|
48194
48226
|
else base[rel[0]] = next;
|
|
48195
48227
|
return base;
|
|
48196
48228
|
}
|
|
48197
|
-
function replaceToml(text, doc,
|
|
48198
|
-
const block = value === void 0 ? "" : tomlBlock(
|
|
48199
|
-
const owned = doc.tables.filter((t) => under(t.path,
|
|
48200
|
-
const cuts = doc.keys.filter((k) => under(k.full,
|
|
48229
|
+
function replaceToml(text, doc, path8, value) {
|
|
48230
|
+
const block = value === void 0 ? "" : tomlBlock(path8, value);
|
|
48231
|
+
const owned = doc.tables.filter((t) => under(t.path, path8));
|
|
48232
|
+
const cuts = doc.keys.filter((k) => under(k.full, path8) && !under(k.base, path8)).map((k) => [...keyLineRange(text, k), ""]);
|
|
48201
48233
|
owned.forEach((t, n) => cuts.push([t.start, t.end, n === 0 ? block : ""]));
|
|
48202
48234
|
cuts.sort((a, b) => b[0] - a[0]);
|
|
48203
48235
|
let out = text;
|
|
@@ -48207,27 +48239,27 @@ function replaceToml(text, doc, path7, value) {
|
|
|
48207
48239
|
return out + sep3 + block;
|
|
48208
48240
|
}
|
|
48209
48241
|
var tableLike = (v) => v === void 0 || isPlainObject6(v);
|
|
48210
|
-
function setTomlText(text,
|
|
48242
|
+
function setTomlText(text, path8, value) {
|
|
48211
48243
|
if (value !== void 0 && !isPlainObject6(value)) throw new SyntaxError("TOML edits replace a whole table");
|
|
48212
48244
|
const doc = scanToml(text);
|
|
48213
|
-
const cur = hostConfigValueAt(doc.value,
|
|
48245
|
+
const cur = hostConfigValueAt(doc.value, path8);
|
|
48214
48246
|
if (sameValue(cur, value)) return text;
|
|
48215
|
-
const inline = doc.keys.find((k) => k.inline && k.full.length <
|
|
48247
|
+
const inline = doc.keys.find((k) => k.inline && k.full.length < path8.length && under(path8, k.full));
|
|
48216
48248
|
if (inline !== void 0) {
|
|
48217
|
-
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full),
|
|
48249
|
+
const whole2 = withValueAt(hostConfigValueAt(doc.value, inline.full), path8.slice(inline.full.length), value);
|
|
48218
48250
|
return replaceToml(text, doc, inline.full, whole2);
|
|
48219
48251
|
}
|
|
48220
48252
|
if (isPlainObject6(cur) && isPlainObject6(value)) {
|
|
48221
48253
|
const names = [.../* @__PURE__ */ new Set([...Object.keys(cur), ...Object.keys(value)])].filter((k) => !sameValue(cur[k], value[k]));
|
|
48222
48254
|
if (names.every((k) => tableLike(cur[k]) && tableLike(value[k]))) {
|
|
48223
48255
|
let out = text;
|
|
48224
|
-
for (const k of names) out = setTomlText(out, [...
|
|
48256
|
+
for (const k of names) out = setTomlText(out, [...path8, k], value[k]);
|
|
48225
48257
|
return out;
|
|
48226
48258
|
}
|
|
48227
48259
|
}
|
|
48228
|
-
return replaceToml(text, doc,
|
|
48260
|
+
return replaceToml(text, doc, path8, value);
|
|
48229
48261
|
}
|
|
48230
|
-
function setText(agent,
|
|
48262
|
+
function setText(agent, path8, text, format, key, value) {
|
|
48231
48263
|
try {
|
|
48232
48264
|
if (format !== "toml") return setJsonText(text, format, key, value);
|
|
48233
48265
|
const out = setTomlText(text, key, value);
|
|
@@ -48236,7 +48268,7 @@ function setText(agent, path7, text, format, key, value) {
|
|
|
48236
48268
|
if (!sameValue(landed, value) && !(emptyTable && landed === void 0)) throw new SyntaxError("edit did not land");
|
|
48237
48269
|
return out;
|
|
48238
48270
|
} catch {
|
|
48239
|
-
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path:
|
|
48271
|
+
throw new CtxError("CONFIG_PARSE_FAILED", { agent, path: path8, format });
|
|
48240
48272
|
}
|
|
48241
48273
|
}
|
|
48242
48274
|
function serverScript() {
|
|
@@ -48283,14 +48315,14 @@ function ownTargets(agent, accept) {
|
|
|
48283
48315
|
if (agent === "pi") return [listTarget(PI_PACKAGES_KEY, PI_GIT_PACKAGE, V1_PI_PACKAGE)];
|
|
48284
48316
|
return [];
|
|
48285
48317
|
}
|
|
48286
|
-
function applyEdits(agent,
|
|
48287
|
-
const parsed = parseHostConfig(agent,
|
|
48318
|
+
function applyEdits(agent, path8, text, format, wanted) {
|
|
48319
|
+
const parsed = parseHostConfig(agent, path8, text, format);
|
|
48288
48320
|
let out = text;
|
|
48289
48321
|
const edits = [];
|
|
48290
48322
|
for (const [key, after] of wanted) {
|
|
48291
48323
|
const before = hostConfigValueAt(parsed, key);
|
|
48292
48324
|
if (sameValue(before, after)) continue;
|
|
48293
|
-
out = setText(agent,
|
|
48325
|
+
out = setText(agent, path8, out, format, key, after);
|
|
48294
48326
|
edits.push({ path: key.join("."), before, after });
|
|
48295
48327
|
}
|
|
48296
48328
|
return { text: out, format, edits };
|
|
@@ -48311,7 +48343,7 @@ function writeHostConfigEdit(_requested, current, patch) {
|
|
|
48311
48343
|
// src/core/ops/detect-v1.ts
|
|
48312
48344
|
var isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
48313
48345
|
var keyPath = (...parts) => parts.join(".");
|
|
48314
|
-
var finding = (file2,
|
|
48346
|
+
var finding = (file2, path8, reason) => ({ file: file2, path: path8, reason });
|
|
48315
48347
|
function stripJsonc(text) {
|
|
48316
48348
|
let out = "";
|
|
48317
48349
|
let inStr = false;
|
|
@@ -48516,12 +48548,17 @@ function scanKiro(agentHome, project, out) {
|
|
|
48516
48548
|
}
|
|
48517
48549
|
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48518
48550
|
}
|
|
48551
|
+
function piNpmIsCurrent(piAgentDir) {
|
|
48552
|
+
const doc = readJson(join8(piAgentDir, PI_NPM_DIR, PI_NODE_MODULES_DIR, SERVER_KEY, PI_PACKAGE_JSON_FILE));
|
|
48553
|
+
const version4 = isObj(doc) && typeof doc.version === "string" ? doc.version : "";
|
|
48554
|
+
return Number.parseInt(version4, 10) >= PI_CURRENT_MAJOR;
|
|
48555
|
+
}
|
|
48519
48556
|
function scanPi(piAgentDir, agentHome, out) {
|
|
48520
48557
|
const file2 = join8(piAgentDir, SETTINGS_FILE);
|
|
48521
48558
|
const doc = readJson(file2);
|
|
48522
48559
|
listOf(isObj(doc) ? doc[PI_PACKAGES_KEY] : void 0).forEach((pkg, i) => {
|
|
48523
48560
|
const spec = isObj(pkg) ? pkg[PI_PACKAGE_SOURCE_KEY] : pkg;
|
|
48524
|
-
if (spec === V1_PI_PACKAGE) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
48561
|
+
if (spec === V1_PI_PACKAGE && !piNpmIsCurrent(piAgentDir)) out.push(finding(file2, keyPath(PI_PACKAGES_KEY, i), V1_REASON.piNpm));
|
|
48525
48562
|
});
|
|
48526
48563
|
dataDir(join8(agentHome, V1_DATA_DIR_NAME), V1_REASON.dataDir, out);
|
|
48527
48564
|
}
|
|
@@ -48618,8 +48655,8 @@ function detectV1(agent, home, scope = {}) {
|
|
|
48618
48655
|
import { existsSync as existsSync7, readdirSync as readdirSync5, readFileSync as readFileSync6, realpathSync as realpathSync4 } from "node:fs";
|
|
48619
48656
|
import { dirname as dirname6, isAbsolute, join as join9, sep as sep2 } from "node:path";
|
|
48620
48657
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
48621
|
-
function missing(agent,
|
|
48622
|
-
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path:
|
|
48658
|
+
function missing(agent, path8) {
|
|
48659
|
+
return new CtxError("PLUGIN_ROOT_MISSING", { agent, path: path8 });
|
|
48623
48660
|
}
|
|
48624
48661
|
var parseOrNull = (text) => {
|
|
48625
48662
|
try {
|
|
@@ -48648,9 +48685,9 @@ function recordedInstalls(text) {
|
|
|
48648
48685
|
}
|
|
48649
48686
|
return out;
|
|
48650
48687
|
}
|
|
48651
|
-
var realOrNull = (
|
|
48688
|
+
var realOrNull = (path8) => {
|
|
48652
48689
|
try {
|
|
48653
|
-
return realpathSync4.native(
|
|
48690
|
+
return realpathSync4.native(path8);
|
|
48654
48691
|
} catch {
|
|
48655
48692
|
return null;
|
|
48656
48693
|
}
|
|
@@ -48748,14 +48785,83 @@ function candidate(adapter, env, worktree) {
|
|
|
48748
48785
|
}
|
|
48749
48786
|
}
|
|
48750
48787
|
function resolvePluginRoot(adapter, env, worktree) {
|
|
48751
|
-
const
|
|
48788
|
+
const path8 = candidate(adapter, env, worktree);
|
|
48752
48789
|
try {
|
|
48753
|
-
return realpathSync4.native(
|
|
48790
|
+
return realpathSync4.native(path8);
|
|
48754
48791
|
} catch {
|
|
48755
|
-
throw missing(adapter.id,
|
|
48792
|
+
throw missing(adapter.id, path8);
|
|
48756
48793
|
}
|
|
48757
48794
|
}
|
|
48758
48795
|
|
|
48796
|
+
// src/setup/pi-gate.ts
|
|
48797
|
+
import { existsSync as existsSync8, readFileSync as readFileSync7, realpathSync as realpathSync5 } from "node:fs";
|
|
48798
|
+
import path4 from "node:path";
|
|
48799
|
+
var EXTENSIONS_KEY = "extensions";
|
|
48800
|
+
var PROJECT_DIR = ".pi";
|
|
48801
|
+
var TRUST_FILE = "trust.json";
|
|
48802
|
+
var ALWAYS = "always";
|
|
48803
|
+
var SOURCE_PREFIXES = ["npm:", "git:"];
|
|
48804
|
+
function load(file2) {
|
|
48805
|
+
if (!existsSync8(file2)) return void 0;
|
|
48806
|
+
try {
|
|
48807
|
+
return { file: file2, doc: parseHostConfig("pi", file2, hostText(readFileSync7(file2, "utf8")), "json") };
|
|
48808
|
+
} catch {
|
|
48809
|
+
return void 0;
|
|
48810
|
+
}
|
|
48811
|
+
}
|
|
48812
|
+
var real2 = (p) => {
|
|
48813
|
+
try {
|
|
48814
|
+
return realpathSync5(p);
|
|
48815
|
+
} catch {
|
|
48816
|
+
return path4.resolve(p);
|
|
48817
|
+
}
|
|
48818
|
+
};
|
|
48819
|
+
function sourceName(source) {
|
|
48820
|
+
let s = source;
|
|
48821
|
+
for (const p of SOURCE_PREFIXES) if (s.startsWith(p)) s = s.slice(p.length);
|
|
48822
|
+
const last2 = s.split("/").pop() ?? "";
|
|
48823
|
+
const at = last2.indexOf("@", 1);
|
|
48824
|
+
const name = at > 0 ? last2.slice(0, at) : last2;
|
|
48825
|
+
return name.endsWith(".git") ? name.slice(0, -4) : name;
|
|
48826
|
+
}
|
|
48827
|
+
function isOwn(source, pkgDir) {
|
|
48828
|
+
if (typeof source !== "string") return false;
|
|
48829
|
+
return real2(source) === real2(pkgDir) || sourceName(source) === SERVER_KEY;
|
|
48830
|
+
}
|
|
48831
|
+
function ownEntries(src, pkgDir) {
|
|
48832
|
+
const list3 = hostConfigValueAt(src.doc, [PI_PACKAGES_KEY]);
|
|
48833
|
+
if (!Array.isArray(list3)) return [];
|
|
48834
|
+
const out = [];
|
|
48835
|
+
for (const e of list3) {
|
|
48836
|
+
const obj = typeof e === "object" && e !== null && !Array.isArray(e) ? e : void 0;
|
|
48837
|
+
if (!isOwn(obj ? obj[PI_PACKAGE_SOURCE_KEY] : e, pkgDir)) continue;
|
|
48838
|
+
const ext = obj?.[EXTENSIONS_KEY];
|
|
48839
|
+
out.push({ source: src, patterns: Array.isArray(ext) ? ext.filter((x) => typeof x === "string") : void 0 });
|
|
48840
|
+
}
|
|
48841
|
+
return out;
|
|
48842
|
+
}
|
|
48843
|
+
function projectTrusted(agentDir, userDoc, cwd) {
|
|
48844
|
+
const trust = load(path4.join(agentDir, TRUST_FILE));
|
|
48845
|
+
const entries = /* @__PURE__ */ new Map();
|
|
48846
|
+
if (trust && typeof trust.doc === "object" && trust.doc !== null) for (const [k, v] of Object.entries(trust.doc)) entries.set(real2(k), v);
|
|
48847
|
+
let dir = real2(cwd);
|
|
48848
|
+
for (; ; ) {
|
|
48849
|
+
const v = entries.get(dir);
|
|
48850
|
+
if (v === true || v === false) return v;
|
|
48851
|
+
const up = path4.dirname(dir);
|
|
48852
|
+
if (up === dir) break;
|
|
48853
|
+
dir = up;
|
|
48854
|
+
}
|
|
48855
|
+
return hostConfigValueAt(userDoc, ["defaultProjectTrust"]) === ALWAYS;
|
|
48856
|
+
}
|
|
48857
|
+
function piInstalledIn(env, home, pkgDir, cwd) {
|
|
48858
|
+
const agentDir = piAgentDirOf(env, home);
|
|
48859
|
+
const user = load(path4.join(agentDir, SETTINGS_FILE));
|
|
48860
|
+
const project = load(path4.join(cwd, PROJECT_DIR, SETTINGS_FILE));
|
|
48861
|
+
if (project && projectTrusted(agentDir, user?.doc, cwd) && ownEntries(project, pkgDir).length > 0) return project.file;
|
|
48862
|
+
return user && ownEntries(user, pkgDir).length > 0 ? user.file : void 0;
|
|
48863
|
+
}
|
|
48864
|
+
|
|
48759
48865
|
// src/core/ops/doctor-config.ts
|
|
48760
48866
|
var [PART_MCP, PART_HOOKS, PART_TIMEOUT] = D3_PARTS;
|
|
48761
48867
|
var isObject4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -48856,14 +48962,14 @@ function codexNativeDir(env, home) {
|
|
|
48856
48962
|
}
|
|
48857
48963
|
if (enabled !== true) return null;
|
|
48858
48964
|
const cache = join10(codexDir, "plugins", PLUGIN_CACHE_DIR_NAME);
|
|
48859
|
-
if (!
|
|
48965
|
+
if (!existsSync9(cache)) return null;
|
|
48860
48966
|
const found = [];
|
|
48861
48967
|
for (const market of readdirSync6(cache)) {
|
|
48862
48968
|
const plugin = join10(cache, market, SERVER_KEY);
|
|
48863
|
-
if (!
|
|
48969
|
+
if (!existsSync9(plugin)) continue;
|
|
48864
48970
|
for (const version4 of readdirSync6(plugin).sort()) {
|
|
48865
48971
|
const dir = join10(plugin, version4, CODEX_PLUGIN_SUBDIR);
|
|
48866
|
-
if (
|
|
48972
|
+
if (existsSync9(join10(dir, CODEX_PLUGIN_MCP_FILE))) found.push(dir);
|
|
48867
48973
|
}
|
|
48868
48974
|
}
|
|
48869
48975
|
return found.length === 0 ? null : found[found.length - 1];
|
|
@@ -48954,12 +49060,17 @@ function checkHostConfig(row5, env, worktree) {
|
|
|
48954
49060
|
const choice = marketplaceChoice(env, worktree);
|
|
48955
49061
|
if ("installs" in choice) return fail("D3", D3_ROOT_DETAIL(choice.installs.map((r) => r.installPath)), D3_ROOT_FIX(choice.installs));
|
|
48956
49062
|
}
|
|
49063
|
+
if (row5.id === "pi") return checkPiInstall(env, home, worktree);
|
|
48957
49064
|
const parts = [...mcpWrong(row5, home, env, worktree) ? [PART_MCP] : [], ...hookParts(row5, home, env, worktree)];
|
|
48958
|
-
|
|
48959
|
-
if (parts.length === 0) return read === null ? pass("D3") : { ...pass("D3"), detail: read };
|
|
49065
|
+
if (parts.length === 0) return pass("D3");
|
|
48960
49066
|
const detail = D3_DETAIL(parts);
|
|
48961
49067
|
const fix = parts.includes(PART_MCP) ? D3_NO_SETUP_FIX(row5.id) : DOCTOR_FIX_UPGRADE;
|
|
48962
|
-
return fail("D3",
|
|
49068
|
+
return fail("D3", detail, fix);
|
|
49069
|
+
}
|
|
49070
|
+
function checkPiInstall(env, home, worktree) {
|
|
49071
|
+
const found = piInstalledIn(env, home, ownBundleDir(), worktree);
|
|
49072
|
+
if (found !== void 0) return { ...pass("D3"), detail: found };
|
|
49073
|
+
return fail("D3", D3_DETAIL([PART_MCP]) + D4_REASON_JOIN + join10(piAgentDirOf(env, home), SETTINGS_FILE), NATIVE_INSTALL.pi[0]);
|
|
48963
49074
|
}
|
|
48964
49075
|
function checkV1Leftovers(agent, home, scope = {}) {
|
|
48965
49076
|
const findings = detectV1(agent, home, scope);
|
|
@@ -49012,7 +49123,7 @@ function configPaths(row5, env, worktree) {
|
|
|
49012
49123
|
}
|
|
49013
49124
|
|
|
49014
49125
|
// src/core/ops/doctor-db.ts
|
|
49015
|
-
import { existsSync as
|
|
49126
|
+
import { existsSync as existsSync10, statSync as statSync4 } from "node:fs";
|
|
49016
49127
|
var unknown4 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "UNKNOWN", detail });
|
|
49017
49128
|
var pass2 = (id, detail) => ({ id, label: DOCTOR_LABEL[id], status: "PASS", detail });
|
|
49018
49129
|
var fail2 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -49031,8 +49142,8 @@ async function loadSqlite2() {
|
|
|
49031
49142
|
return null;
|
|
49032
49143
|
}
|
|
49033
49144
|
}
|
|
49034
|
-
function openRead(sqlite,
|
|
49035
|
-
return new sqlite.DatabaseSync(
|
|
49145
|
+
function openRead(sqlite, path8) {
|
|
49146
|
+
return new sqlite.DatabaseSync(path8, { timeout: DB_TIMEOUT_MS, readOnly: true });
|
|
49036
49147
|
}
|
|
49037
49148
|
var cell = (row5) => Object.values(row5)[0];
|
|
49038
49149
|
function readSchema(raw) {
|
|
@@ -49053,16 +49164,16 @@ function failsOnCorrupt(step) {
|
|
|
49053
49164
|
function orphanFiles(dbPath) {
|
|
49054
49165
|
const files = [];
|
|
49055
49166
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
49056
|
-
const
|
|
49057
|
-
if (
|
|
49167
|
+
const path8 = dbPath + suffix;
|
|
49168
|
+
if (existsSync10(path8)) files.push({ path: path8, bytes: statSync4(path8).size });
|
|
49058
49169
|
}
|
|
49059
|
-
return files.length > 0 && !
|
|
49170
|
+
return files.length > 0 && !existsSync10(dbPath) ? files : [];
|
|
49060
49171
|
}
|
|
49061
49172
|
async function checkDb(project) {
|
|
49062
49173
|
const clean = { schemaStale: false, integrityFailed: false, orphan: [] };
|
|
49063
49174
|
const orphan = orphanFiles(project.dbPath);
|
|
49064
49175
|
if (orphan.length > 0) return { row: fail2(D8_ORPHAN_DETAIL(orphan), D8_ORPHAN_FIX), schemaStale: false, integrityFailed: false, orphan };
|
|
49065
|
-
if (!
|
|
49176
|
+
if (!existsSync10(project.dbPath)) return { row: pass2("D8", DOCTOR_PASS_DETAIL), ...clean };
|
|
49066
49177
|
const sqlite = await loadSqlite2();
|
|
49067
49178
|
if (sqlite === null) return { row: unknown4("D8", D2_SQLITE_DETAIL), ...clean };
|
|
49068
49179
|
let raw = null;
|
|
@@ -49088,7 +49199,7 @@ async function checkDb(project) {
|
|
|
49088
49199
|
}
|
|
49089
49200
|
}
|
|
49090
49201
|
async function checkIndex(project) {
|
|
49091
|
-
if (!
|
|
49202
|
+
if (!existsSync10(project.dbPath)) return pass2("D9", D9_INDEX_DETAIL(0, 0));
|
|
49092
49203
|
const sqlite = await loadSqlite2();
|
|
49093
49204
|
if (sqlite === null) return unknown4("D9", D2_SQLITE_DETAIL);
|
|
49094
49205
|
let raw = null;
|
|
@@ -49105,7 +49216,7 @@ async function checkIndex(project) {
|
|
|
49105
49216
|
}
|
|
49106
49217
|
|
|
49107
49218
|
// src/core/ops/doctor-env.ts
|
|
49108
|
-
import { existsSync as
|
|
49219
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync6 } from "node:fs";
|
|
49109
49220
|
import { isAbsolute as isAbsolute2, join as join11, relative } from "node:path";
|
|
49110
49221
|
function pass3(id, detail = DOCTOR_PASS_DETAIL) {
|
|
49111
49222
|
return { id, label: DOCTOR_LABEL[id], status: "PASS", detail };
|
|
@@ -49118,7 +49229,7 @@ function fail3(id, detail, fixCommand) {
|
|
|
49118
49229
|
}
|
|
49119
49230
|
function bundleVersion(bundleDir2) {
|
|
49120
49231
|
try {
|
|
49121
|
-
const v = JSON.parse(
|
|
49232
|
+
const v = JSON.parse(readFileSync8(join11(bundleDir2, D1_PACKAGE_FILE), "utf8")).version;
|
|
49122
49233
|
return typeof v === "string" && v !== "" ? v : void 0;
|
|
49123
49234
|
} catch {
|
|
49124
49235
|
return void 0;
|
|
@@ -49268,8 +49379,8 @@ function checkMcp(ctx) {
|
|
|
49268
49379
|
return named2 || versioned ? pass3("D6") : unknown5("D6", D6_UNKNOWN_DETAIL);
|
|
49269
49380
|
}
|
|
49270
49381
|
function piCwdInside(worktree, piCwd) {
|
|
49271
|
-
if (piCwd === void 0 || !
|
|
49272
|
-
const rel = relative(worktree,
|
|
49382
|
+
if (piCwd === void 0 || !existsSync11(piCwd)) return false;
|
|
49383
|
+
const rel = relative(worktree, realpathSync6.native(piCwd));
|
|
49273
49384
|
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
49274
49385
|
}
|
|
49275
49386
|
function checkProject(i) {
|
|
@@ -49289,20 +49400,20 @@ function checkShell(env) {
|
|
|
49289
49400
|
}
|
|
49290
49401
|
|
|
49291
49402
|
// src/core/ops/doctor-hook.ts
|
|
49292
|
-
import { existsSync as
|
|
49403
|
+
import { existsSync as existsSync13, mkdtempSync, readFileSync as readFileSync9, realpathSync as realpathSync8, rmSync as rmSync4 } from "node:fs";
|
|
49293
49404
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
49294
|
-
import
|
|
49405
|
+
import path7 from "node:path";
|
|
49295
49406
|
|
|
49296
49407
|
// src/setup/codex-trust.ts
|
|
49297
49408
|
import { createHash } from "node:crypto";
|
|
49298
|
-
import { existsSync as
|
|
49299
|
-
import
|
|
49409
|
+
import { existsSync as existsSync12, realpathSync as realpathSync7 } from "node:fs";
|
|
49410
|
+
import path6 from "node:path";
|
|
49300
49411
|
import { spawn as spawn2, spawnSync as spawnSync2 } from "node:child_process";
|
|
49301
49412
|
|
|
49302
49413
|
// src/setup/spawn-bin.ts
|
|
49303
49414
|
import { spawnSync } from "node:child_process";
|
|
49304
49415
|
import { accessSync as accessSync2, constants as fsc, statSync as statSync5 } from "node:fs";
|
|
49305
|
-
import
|
|
49416
|
+
import path5 from "node:path";
|
|
49306
49417
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
49307
49418
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
49308
49419
|
var DEFAULT_COMSPEC = "cmd.exe";
|
|
@@ -49313,10 +49424,10 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
49313
49424
|
const get = (k) => envGet(env, k);
|
|
49314
49425
|
const win = platform === "win32";
|
|
49315
49426
|
const exts = win ? (get("PATHEXT") || WIN_EXT).split(";").filter(Boolean) : [""];
|
|
49316
|
-
const names = win &&
|
|
49427
|
+
const names = win && path5.extname(bin) ? [bin] : exts.map((e) => bin + e.toLowerCase());
|
|
49317
49428
|
for (const dir of pathEntries(get("PATH") ?? "", platform)) {
|
|
49318
49429
|
for (const n of names) {
|
|
49319
|
-
const f =
|
|
49430
|
+
const f = path5.join(dir, n);
|
|
49320
49431
|
try {
|
|
49321
49432
|
accessSync2(f, fsc.X_OK);
|
|
49322
49433
|
if (statSync5(f).isFile()) return f;
|
|
@@ -49357,7 +49468,7 @@ function winCmdLine(file2, args, env = {}) {
|
|
|
49357
49468
|
return `"${[file2, ...args].map(q).join(" ")}"`;
|
|
49358
49469
|
}
|
|
49359
49470
|
function spawnForm(file2, args, env, platform = process.platform) {
|
|
49360
|
-
if (platform === "win32" && WIN_SHIM_EXTS.includes(
|
|
49471
|
+
if (platform === "win32" && WIN_SHIM_EXTS.includes(path5.extname(file2).toLowerCase())) {
|
|
49361
49472
|
return { command: envGet(env, "COMSPEC") || DEFAULT_COMSPEC, args: ["/d", "/v:off", "/s", "/c", winCmdLine(file2, args, env)], windowsVerbatimArguments: true };
|
|
49362
49473
|
}
|
|
49363
49474
|
return { command: file2, args, windowsVerbatimArguments: false };
|
|
@@ -49381,10 +49492,10 @@ function codexHomeFromReply(out) {
|
|
|
49381
49492
|
return void 0;
|
|
49382
49493
|
}
|
|
49383
49494
|
function sameDir(a, b, platform = process.platform) {
|
|
49384
|
-
if (platform !== "win32") return
|
|
49495
|
+
if (platform !== "win32") return path6.posix.normalize(a) === path6.posix.normalize(b);
|
|
49385
49496
|
const norm = (p) => {
|
|
49386
49497
|
const bare2 = p.startsWith(WIN_VERBATIM_PREFIX) ? p.slice(WIN_VERBATIM_PREFIX.length) : p;
|
|
49387
|
-
const n =
|
|
49498
|
+
const n = path6.win32.normalize(bare2).toLowerCase();
|
|
49388
49499
|
return n.length > 3 && n.endsWith("\\") ? n.slice(0, -1) : n;
|
|
49389
49500
|
};
|
|
49390
49501
|
return norm(a) === norm(b);
|
|
@@ -49517,11 +49628,11 @@ function isObject5(v) {
|
|
|
49517
49628
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
49518
49629
|
}
|
|
49519
49630
|
function loadFixture(bundleDir2, agent) {
|
|
49520
|
-
const file2 =
|
|
49521
|
-
if (!
|
|
49631
|
+
const file2 = path7.join(bundleDir2, HOOK_FIXTURE_DIR, HOOK_FIXTURE_FILE);
|
|
49632
|
+
if (!existsSync13(file2)) return { cause: D5_FIXTURE_FILE_ABSENT(file2) };
|
|
49522
49633
|
let all;
|
|
49523
49634
|
try {
|
|
49524
|
-
all = JSON.parse(hostText(
|
|
49635
|
+
all = JSON.parse(hostText(readFileSync9(file2, "utf8")));
|
|
49525
49636
|
} catch (err) {
|
|
49526
49637
|
return { cause: D5_FIXTURE_PARSE(file2, err instanceof Error ? err.message : String(err)) };
|
|
49527
49638
|
}
|
|
@@ -49583,7 +49694,7 @@ function isNativeShape(agent, stdout, exitCode, killed, event) {
|
|
|
49583
49694
|
var READ_PROBE_LINES = 4 * Math.ceil(REPLACE_TRIGGER_BYTES / 40);
|
|
49584
49695
|
function readProbePayload(cwd) {
|
|
49585
49696
|
const content = Array.from({ length: READ_PROBE_LINES }, (_, n) => "d5 read probe line " + n + " ".padEnd(20, "x")).join("\n");
|
|
49586
|
-
const filePath =
|
|
49697
|
+
const filePath = path7.join(cwd, "d5-read-probe.txt");
|
|
49587
49698
|
return {
|
|
49588
49699
|
session_id: "d5-read-probe",
|
|
49589
49700
|
transcript_path: "",
|
|
@@ -49610,9 +49721,9 @@ function isReadShape(stdout) {
|
|
|
49610
49721
|
return typeof f.filePath === "string" && typeof f.content === "string" && ["numLines", "startLine", "totalLines"].every((k) => typeof f[k] === "number");
|
|
49611
49722
|
}
|
|
49612
49723
|
async function readProbeOk(i, timeoutMs) {
|
|
49613
|
-
const home = mkdtempSync(
|
|
49724
|
+
const home = mkdtempSync(path7.join(tmpdir2(), "cm-d5-read-"));
|
|
49614
49725
|
try {
|
|
49615
|
-
const r = await runProcess([process.execPath,
|
|
49726
|
+
const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
49616
49727
|
cwd: i.bundleDir,
|
|
49617
49728
|
env: { ...i.env, HOME: home, USERPROFILE: home },
|
|
49618
49729
|
signal: i.signal,
|
|
@@ -49630,7 +49741,7 @@ function codexHookJournaled(db) {
|
|
|
49630
49741
|
}
|
|
49631
49742
|
function realDir(p) {
|
|
49632
49743
|
try {
|
|
49633
|
-
return
|
|
49744
|
+
return realpathSync8(p);
|
|
49634
49745
|
} catch {
|
|
49635
49746
|
return p;
|
|
49636
49747
|
}
|
|
@@ -49657,7 +49768,7 @@ async function checkHookRoundTrip(i) {
|
|
|
49657
49768
|
const trust = await codexPluginTrust(i);
|
|
49658
49769
|
if (trust !== null) return trust;
|
|
49659
49770
|
}
|
|
49660
|
-
if (i.agent === "codex" &&
|
|
49771
|
+
if (i.agent === "codex" && existsSync13(path7.join(i.codexConfigDir, HOOKS_JSON_FILE)) && !codexHookJournaled(i.db)) {
|
|
49661
49772
|
return row("UNKNOWN", D5_CODEX_UNTRUSTED_DETAIL);
|
|
49662
49773
|
}
|
|
49663
49774
|
const fixture = loadFixture(i.bundleDir, i.agent);
|
|
@@ -49677,7 +49788,7 @@ async function checkHookRoundTrip(i) {
|
|
|
49677
49788
|
let ms = 0;
|
|
49678
49789
|
for (let n = 1; n <= maxPairs; n++) {
|
|
49679
49790
|
const start = now();
|
|
49680
|
-
const r = await runProcess([process.execPath,
|
|
49791
|
+
const r = await runProcess([process.execPath, path7.join(i.bundleDir, HOOK_ENTRY_FILE), AGENT_ARG, i.agent], {
|
|
49681
49792
|
cwd: i.bundleDir,
|
|
49682
49793
|
env: i.env,
|
|
49683
49794
|
signal: i.signal,
|
|
@@ -49733,7 +49844,7 @@ function lastHookError(env) {
|
|
|
49733
49844
|
}
|
|
49734
49845
|
|
|
49735
49846
|
// src/core/ops/db-heal.ts
|
|
49736
|
-
import { existsSync as
|
|
49847
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync5, rmSync as rmSync5 } from "node:fs";
|
|
49737
49848
|
import { basename as basename4, dirname as dirname7, join as join13 } from "node:path";
|
|
49738
49849
|
function integrityOk2(rows) {
|
|
49739
49850
|
return rows.length === 1 && rows[0].integrity_check === INTEGRITY_OK;
|
|
@@ -49768,7 +49879,7 @@ function renameAside(dbPath) {
|
|
|
49768
49879
|
const ts = String(Date.now());
|
|
49769
49880
|
for (const suffix of DB_SIBLING_SUFFIXES) {
|
|
49770
49881
|
const file2 = dbPath + suffix;
|
|
49771
|
-
if (
|
|
49882
|
+
if (existsSync14(file2)) renameWithRetry(file2, file2 + HEAL_TS_SEP + ts + HEAL_BACKUP_SUFFIX);
|
|
49772
49883
|
}
|
|
49773
49884
|
return ts;
|
|
49774
49885
|
}
|
|
@@ -49875,7 +49986,7 @@ function buildReportHead(input) {
|
|
|
49875
49986
|
|
|
49876
49987
|
// src/core/ops/doctor-issue.ts
|
|
49877
49988
|
import { spawnSync as spawnSync3 } from "node:child_process";
|
|
49878
|
-
import { closeSync, existsSync as
|
|
49989
|
+
import { closeSync, existsSync as existsSync15, fstatSync, mkdirSync as mkdirSync6, openSync, readFileSync as readFileSync10, readSync, realpathSync as realpathSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
49879
49990
|
import { delimiter, join as join14 } from "node:path";
|
|
49880
49991
|
var TOKEN_PREFIXES = ["ghp_", "gho_", "github_pat_", "sk-", "xoxb-", "AKIA"];
|
|
49881
49992
|
function tildeOf(env) {
|
|
@@ -49883,8 +49994,8 @@ function tildeOf(env) {
|
|
|
49883
49994
|
if (home === null || home === "") return (t) => t;
|
|
49884
49995
|
const homes = [home];
|
|
49885
49996
|
try {
|
|
49886
|
-
const
|
|
49887
|
-
if (
|
|
49997
|
+
const real3 = realpathSync9.native(home);
|
|
49998
|
+
if (real3 !== home) homes.push(real3);
|
|
49888
49999
|
} catch {
|
|
49889
50000
|
}
|
|
49890
50001
|
homes.sort((a, b) => b.length - a.length);
|
|
@@ -49917,7 +50028,7 @@ function onPath(env, tool) {
|
|
|
49917
50028
|
const out = [];
|
|
49918
50029
|
for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter)) {
|
|
49919
50030
|
if (dir === "") continue;
|
|
49920
|
-
for (const n of names) if (
|
|
50031
|
+
for (const n of names) if (existsSync15(join14(dir, n))) {
|
|
49921
50032
|
out.push(join14(dir, n));
|
|
49922
50033
|
break;
|
|
49923
50034
|
}
|
|
@@ -49926,7 +50037,7 @@ function onPath(env, tool) {
|
|
|
49926
50037
|
}
|
|
49927
50038
|
function hookLogTail(env) {
|
|
49928
50039
|
const file2 = hookLogPath(env);
|
|
49929
|
-
if (file2 === "" || !
|
|
50040
|
+
if (file2 === "" || !existsSync15(file2)) return [`(${file2 || "hook-errors.log"} holds zero lines)`];
|
|
49930
50041
|
try {
|
|
49931
50042
|
const fd = openSync(file2, "r");
|
|
49932
50043
|
try {
|
|
@@ -49946,7 +50057,7 @@ function hookLogTail(env) {
|
|
|
49946
50057
|
}
|
|
49947
50058
|
async function journalRows(ctx) {
|
|
49948
50059
|
const head = ["| kind | tool | bytes | ok | exit_code | created_at |", "|---|---|---|---|---|---|"];
|
|
49949
|
-
if (!
|
|
50060
|
+
if (!existsSync15(ctx.project.dbPath)) return [`(context.db is absent at ${ctx.project.dbPath})`];
|
|
49950
50061
|
try {
|
|
49951
50062
|
const db = await openDb(ctx.project, { readOnly: true });
|
|
49952
50063
|
try {
|
|
@@ -49972,13 +50083,13 @@ function agentConfig(adapter, env, worktree) {
|
|
|
49972
50083
|
for (const f of files) {
|
|
49973
50084
|
if (seen.has(f.path)) continue;
|
|
49974
50085
|
seen.add(f.path);
|
|
49975
|
-
if (!
|
|
50086
|
+
if (!existsSync15(f.path)) {
|
|
49976
50087
|
out.push(`${f.label}: ${f.path} (absent)`);
|
|
49977
50088
|
continue;
|
|
49978
50089
|
}
|
|
49979
50090
|
let text = "";
|
|
49980
50091
|
try {
|
|
49981
|
-
text =
|
|
50092
|
+
text = readFileSync10(f.path, "utf8");
|
|
49982
50093
|
} catch (err) {
|
|
49983
50094
|
out.push(`${f.label}: ${f.path} (read: ${err instanceof Error ? err.message : String(err)})`);
|
|
49984
50095
|
continue;
|
|
@@ -50096,7 +50207,7 @@ async function guard(id, run) {
|
|
|
50096
50207
|
}
|
|
50097
50208
|
}
|
|
50098
50209
|
async function codexDb(ctx, adapter) {
|
|
50099
|
-
if (adapter.id !== "codex" || !
|
|
50210
|
+
if (adapter.id !== "codex" || !existsSync16(ctx.project.dbPath)) return null;
|
|
50100
50211
|
try {
|
|
50101
50212
|
return await openDb(ctx.project, { readOnly: true });
|
|
50102
50213
|
} catch {
|
|
@@ -50127,10 +50238,10 @@ async function hookRow(ctx, adapter, host) {
|
|
|
50127
50238
|
}
|
|
50128
50239
|
function ownServerId(configDir, projectKey) {
|
|
50129
50240
|
const dir = join15(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
50130
|
-
if (!
|
|
50241
|
+
if (!existsSync16(dir)) return "";
|
|
50131
50242
|
for (const name of readdirSync7(dir)) {
|
|
50132
50243
|
if (!name.endsWith(OWNER_PID_EXT)) continue;
|
|
50133
|
-
if (
|
|
50244
|
+
if (readFileSync11(join15(dir, name), "utf8").trim() === String(process.pid)) return basename5(name, OWNER_PID_EXT);
|
|
50134
50245
|
}
|
|
50135
50246
|
return "";
|
|
50136
50247
|
}
|
|
@@ -50186,7 +50297,7 @@ async function doctorReply(ctx, host) {
|
|
|
50186
50297
|
const adapter = getAdapter(ctx.project.agent);
|
|
50187
50298
|
const rows = await runDoctorChecks(ctx, adapter, host);
|
|
50188
50299
|
const failed2 = rows.some((r) => r.status === "FAIL");
|
|
50189
|
-
const command = `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
50300
|
+
const command = adapter.id === "pi" ? failed2 ? NATIVE_INSTALL.pi[0] : PI_LIST_COMMAND : `context-mode ${failed2 ? "setup" : "doctor"} --agents ${adapter.id}`;
|
|
50190
50301
|
const input = { agent: adapter.id, rows, env: reportEnv(host.env), command };
|
|
50191
50302
|
const envLine2 = environmentLine(ctx, adapter, host.env, bundleVersion(host.bundleDir));
|
|
50192
50303
|
const table3 = buildReport(input);
|
|
@@ -50213,7 +50324,7 @@ async function doctorReply(ctx, host) {
|
|
|
50213
50324
|
return { text, isError: false, sandboxBytes: bytes5 };
|
|
50214
50325
|
}
|
|
50215
50326
|
async function handler2(_input, ctx) {
|
|
50216
|
-
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd:
|
|
50327
|
+
return doctorReply(ctx, { env: process.env, bundleDir: ownBundleDir(), piCwd: ctx.piCwd });
|
|
50217
50328
|
}
|
|
50218
50329
|
var ctxDoctor = Object.freeze({
|
|
50219
50330
|
name: "ctx_doctor",
|
|
@@ -50225,7 +50336,7 @@ var ctxDoctor = Object.freeze({
|
|
|
50225
50336
|
});
|
|
50226
50337
|
|
|
50227
50338
|
// src/core/tools/execute.ts
|
|
50228
|
-
import { existsSync as
|
|
50339
|
+
import { existsSync as existsSync17, mkdtempSync as mkdtempSync2, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
50229
50340
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
50230
50341
|
import { dirname as dirname9, join as join16, parse as parse5, resolve as resolve4 } from "node:path";
|
|
50231
50342
|
|
|
@@ -50350,7 +50461,7 @@ function schemaLine(issue4) {
|
|
|
50350
50461
|
}
|
|
50351
50462
|
function fileError(given, abs, root) {
|
|
50352
50463
|
let dir = abs;
|
|
50353
|
-
while (!
|
|
50464
|
+
while (!existsSync17(dir) && dirname9(dir) !== dir) dir = dirname9(dir);
|
|
50354
50465
|
if (isInside(root, dir)) return null;
|
|
50355
50466
|
return new CtxError("OUTSIDE_ROOT", { p: given, root }).toLine();
|
|
50356
50467
|
}
|
|
@@ -50467,19 +50578,19 @@ var ctxExecute = {
|
|
|
50467
50578
|
};
|
|
50468
50579
|
|
|
50469
50580
|
// src/core/tools/index.ts
|
|
50470
|
-
import { existsSync as
|
|
50581
|
+
import { existsSync as existsSync18, readFileSync as readFileSync13, statSync as statSync7 } from "node:fs";
|
|
50471
50582
|
import { dirname as dirname10, extname, join as join18, relative as relative2, resolve as resolve5 } from "node:path";
|
|
50472
50583
|
|
|
50473
50584
|
// src/core/index/walk.ts
|
|
50474
|
-
import { readdirSync as readdirSync8, readFileSync as
|
|
50585
|
+
import { readdirSync as readdirSync8, readFileSync as readFileSync12, realpathSync as realpathSync10, statSync as statSync6 } from "node:fs";
|
|
50475
50586
|
import { join as join17 } from "node:path";
|
|
50476
50587
|
var GITIGNORE = ".gitignore";
|
|
50477
50588
|
var GIT_DIR = ".git";
|
|
50478
50589
|
function walkDir(root, containmentRoot) {
|
|
50479
|
-
const
|
|
50480
|
-
if (!isInside(containmentRoot,
|
|
50590
|
+
const real3 = realpathSync10(root);
|
|
50591
|
+
if (!isInside(containmentRoot, real3)) throw new CtxError("OUTSIDE_ROOT", { p: root, root: containmentRoot });
|
|
50481
50592
|
const found = [];
|
|
50482
|
-
visit(
|
|
50593
|
+
visit(real3, [], [], containmentRoot, /* @__PURE__ */ new Set([real3]), found);
|
|
50483
50594
|
found.sort(compareFound);
|
|
50484
50595
|
return found.map((f) => ({ absPath: f.absPath, relPath: join17(...f.dir, f.name) }));
|
|
50485
50596
|
}
|
|
@@ -50493,14 +50604,14 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
50493
50604
|
const rules = entries.some((e) => e.name === GITIGNORE && e.isFile()) ? parent.concat(readRules(join17(abs, GITIGNORE), rel)) : parent;
|
|
50494
50605
|
for (const e of entries) {
|
|
50495
50606
|
if (e.name === GIT_DIR) continue;
|
|
50496
|
-
const
|
|
50607
|
+
const path8 = join17(abs, e.name);
|
|
50497
50608
|
let isDir = e.isDirectory();
|
|
50498
50609
|
let isFile = e.isFile();
|
|
50499
|
-
let target =
|
|
50610
|
+
let target = path8;
|
|
50500
50611
|
if (e.isSymbolicLink()) {
|
|
50501
50612
|
let resolved;
|
|
50502
50613
|
try {
|
|
50503
|
-
resolved =
|
|
50614
|
+
resolved = realpathSync10(path8);
|
|
50504
50615
|
} catch {
|
|
50505
50616
|
continue;
|
|
50506
50617
|
}
|
|
@@ -50513,12 +50624,12 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
50513
50624
|
const segs = rel.concat(e.name);
|
|
50514
50625
|
if (ignored(rules, segs, isDir)) continue;
|
|
50515
50626
|
if (isFile) {
|
|
50516
|
-
found.push({ dir: rel, name: e.name, absPath:
|
|
50627
|
+
found.push({ dir: rel, name: e.name, absPath: path8 });
|
|
50517
50628
|
} else if (isDir) {
|
|
50518
|
-
const key = e.isSymbolicLink() ? target :
|
|
50629
|
+
const key = e.isSymbolicLink() ? target : realpathSync10(path8);
|
|
50519
50630
|
if (seen.has(key)) continue;
|
|
50520
50631
|
seen.add(key);
|
|
50521
|
-
visit(
|
|
50632
|
+
visit(path8, segs, rules, contain, seen, found);
|
|
50522
50633
|
}
|
|
50523
50634
|
}
|
|
50524
50635
|
}
|
|
@@ -50533,7 +50644,7 @@ function compareFound(a, b) {
|
|
|
50533
50644
|
function readRules(file2, base) {
|
|
50534
50645
|
let body;
|
|
50535
50646
|
try {
|
|
50536
|
-
body =
|
|
50647
|
+
body = readFileSync12(file2, "utf8");
|
|
50537
50648
|
} catch {
|
|
50538
50649
|
return [];
|
|
50539
50650
|
}
|
|
@@ -50709,12 +50820,12 @@ function tlsName(host) {
|
|
|
50709
50820
|
function request(u, conn, proxy, signal) {
|
|
50710
50821
|
const host = bare(u.hostname);
|
|
50711
50822
|
const port = u.port === "" ? defaultPort(u.protocol) : Number(u.port);
|
|
50712
|
-
const
|
|
50823
|
+
const path8 = u.pathname + u.search;
|
|
50713
50824
|
return new Promise((resolve6, reject) => {
|
|
50714
50825
|
const onErr = (err) => reject(fail5(causeCode(err)));
|
|
50715
50826
|
if (proxy === void 0) {
|
|
50716
50827
|
const mod = u.protocol === "https:" ? https : http;
|
|
50717
|
-
const req = mod.request({ host: conn.address, port, path:
|
|
50828
|
+
const req = mod.request({ host: conn.address, port, path: path8, signal, servername: tlsName(host), headers: { host: u.host } });
|
|
50718
50829
|
req.on("response", resolve6).on("error", onErr).end();
|
|
50719
50830
|
return;
|
|
50720
50831
|
}
|
|
@@ -50736,7 +50847,7 @@ function request(u, conn, proxy, signal) {
|
|
|
50736
50847
|
const req = https.request({
|
|
50737
50848
|
host,
|
|
50738
50849
|
port,
|
|
50739
|
-
path:
|
|
50850
|
+
path: path8,
|
|
50740
50851
|
signal,
|
|
50741
50852
|
headers: { host: u.host },
|
|
50742
50853
|
createConnection: () => tlsConnect({ socket, host, servername: tlsName(host) })
|
|
@@ -54616,14 +54727,14 @@ function kindOfType(contentType) {
|
|
|
54616
54727
|
}
|
|
54617
54728
|
function readUtf8(absPath) {
|
|
54618
54729
|
try {
|
|
54619
|
-
return utf8.decode(
|
|
54730
|
+
return utf8.decode(readFileSync13(absPath));
|
|
54620
54731
|
} catch {
|
|
54621
54732
|
return void 0;
|
|
54622
54733
|
}
|
|
54623
54734
|
}
|
|
54624
54735
|
function missingOrOutside(given, abs, root) {
|
|
54625
54736
|
let dir = abs;
|
|
54626
|
-
while (!
|
|
54737
|
+
while (!existsSync18(dir) && dirname10(dir) !== dir) dir = dirname10(dir);
|
|
54627
54738
|
if (dir !== abs && isInside(root, dir)) return new CtxError("INVALID_ARGS", { field: "path", action: "pass an existing file or folder" });
|
|
54628
54739
|
return new CtxError("OUTSIDE_ROOT", { p: given, root });
|
|
54629
54740
|
}
|
|
@@ -54834,8 +54945,8 @@ function buildCandidates(rows, sessionId) {
|
|
|
54834
54945
|
edits.set(r.path, { row: r, count: (edits.get(r.path)?.count ?? 0) + 1 });
|
|
54835
54946
|
}
|
|
54836
54947
|
const changedFiles = [];
|
|
54837
|
-
for (const [
|
|
54838
|
-
const c = make("changed_files", e.row, "edited " +
|
|
54948
|
+
for (const [path8, e] of edits) {
|
|
54949
|
+
const c = make("changed_files", e.row, "edited " + path8 + " x" + e.count, e.count, path8);
|
|
54839
54950
|
changedFiles.push({ ...c, editCount: e.count });
|
|
54840
54951
|
}
|
|
54841
54952
|
changedFiles.sort((a, b) => a.seq - b.seq);
|
|
@@ -55439,11 +55550,11 @@ var ctxStats = Object.freeze({
|
|
|
55439
55550
|
});
|
|
55440
55551
|
|
|
55441
55552
|
// src/core/tools/upgrade.ts
|
|
55442
|
-
import { existsSync as
|
|
55553
|
+
import { existsSync as existsSync24, realpathSync as realpathSync11, rmSync as rmSync11 } from "node:fs";
|
|
55443
55554
|
import { basename as basename7, dirname as dirname12, join as join24 } from "node:path";
|
|
55444
55555
|
|
|
55445
55556
|
// src/core/ops/host-write.ts
|
|
55446
|
-
import { copyFileSync, existsSync as
|
|
55557
|
+
import { copyFileSync, existsSync as existsSync19, mkdirSync as mkdirSync7, writeFileSync as writeFileSync5 } from "node:fs";
|
|
55447
55558
|
import { dirname as dirname11, join as join19 } from "node:path";
|
|
55448
55559
|
function defaultWrite(file2, text) {
|
|
55449
55560
|
writeFileSync5(file2, text, "utf8");
|
|
@@ -55472,7 +55583,7 @@ function toRow(file2, edit) {
|
|
|
55472
55583
|
function writeWithRollback(file2, text, write, atomic) {
|
|
55473
55584
|
const trash = file2 + UPGRADE_TRASH_SUFFIX;
|
|
55474
55585
|
const tmp = `${file2}${HOST_CONFIG_TMP_SUFFIX}.${process.pid}`;
|
|
55475
|
-
const had =
|
|
55586
|
+
const had = existsSync19(file2);
|
|
55476
55587
|
mkdirSync7(dirname11(file2), { recursive: true });
|
|
55477
55588
|
if (had) copyFileSync(file2, trash);
|
|
55478
55589
|
try {
|
|
@@ -55502,7 +55613,7 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
55502
55613
|
if (requested === null) return [];
|
|
55503
55614
|
const current = readHostConfig(row5.id, requested);
|
|
55504
55615
|
const result = mergeOwnEntries(row5.id, current.text, current.format, row5);
|
|
55505
|
-
const exists =
|
|
55616
|
+
const exists = existsSync19(current.path);
|
|
55506
55617
|
if (exists && result.text === current.text) return [];
|
|
55507
55618
|
const text = result.text === "" && current.format !== "toml" ? JSON.stringify({}) : result.text;
|
|
55508
55619
|
writeWithRollback(current.path, current.layout === void 0 ? text : withLayout(text, current.layout), opts.write ?? defaultWrite, opts.atomic ?? {});
|
|
@@ -55510,15 +55621,15 @@ function regenerateHostConfig(row5, home, opts = {}) {
|
|
|
55510
55621
|
}
|
|
55511
55622
|
|
|
55512
55623
|
// src/core/ops/plugin-swap.ts
|
|
55513
|
-
import { existsSync as
|
|
55624
|
+
import { existsSync as existsSync20, lstatSync, readdirSync as readdirSync9, readlinkSync, rmSync as rmSync7, symlinkSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
55514
55625
|
import { basename as basename6, join as join20, win32 as win322 } from "node:path";
|
|
55515
|
-
function linkTarget(
|
|
55516
|
-
if (!isLink(
|
|
55517
|
-
const target = readlinkSync(
|
|
55626
|
+
function linkTarget(path8, win) {
|
|
55627
|
+
if (!isLink(path8)) return null;
|
|
55628
|
+
const target = readlinkSync(path8);
|
|
55518
55629
|
return win ? win322.basename(target) : target;
|
|
55519
55630
|
}
|
|
55520
|
-
function isLink(
|
|
55521
|
-
return lstatSync(
|
|
55631
|
+
function isLink(path8) {
|
|
55632
|
+
return lstatSync(path8, { throwIfNoEntry: false })?.isSymbolicLink() === true;
|
|
55522
55633
|
}
|
|
55523
55634
|
function generations(agentDir) {
|
|
55524
55635
|
return readdirSync9(agentDir, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).filter((name) => !name.startsWith(UPGRADE_FETCH_DIR_PREFIX) && !name.endsWith(UPGRADE_TRASH_SUFFIX)).sort();
|
|
@@ -55531,7 +55642,7 @@ function settleLinks(link, tmp, old, opts) {
|
|
|
55531
55642
|
}
|
|
55532
55643
|
function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
55533
55644
|
const next = join20(agentDir, sha);
|
|
55534
|
-
if (!
|
|
55645
|
+
if (!existsSync20(next) || !lstatSync(next).isDirectory()) {
|
|
55535
55646
|
throw new CtxError("PLUGIN_ROOT_MISSING", { agent: basename6(agentDir), path: next });
|
|
55536
55647
|
}
|
|
55537
55648
|
const link = join20(agentDir, PLUGIN_CURRENT_LINK);
|
|
@@ -55551,12 +55662,12 @@ function swapPluginCurrent(agentDir, sha, opts = {}) {
|
|
|
55551
55662
|
if (before !== null) keep.add(before);
|
|
55552
55663
|
const removed = generations(agentDir).filter((name) => !keep.has(name)).map((name) => join20(agentDir, name));
|
|
55553
55664
|
for (const dir of removed) rmSync7(dir, { recursive: true, force: true });
|
|
55554
|
-
const previous = before !== null &&
|
|
55665
|
+
const previous = before !== null && existsSync20(join20(agentDir, before)) ? join20(agentDir, before) : null;
|
|
55555
55666
|
return { current: next, previous, removed };
|
|
55556
55667
|
}
|
|
55557
55668
|
|
|
55558
55669
|
// src/core/ops/release-fetch.ts
|
|
55559
|
-
import { existsSync as
|
|
55670
|
+
import { existsSync as existsSync21, mkdirSync as mkdirSync8, rmSync as rmSync8 } from "node:fs";
|
|
55560
55671
|
import { join as join21 } from "node:path";
|
|
55561
55672
|
function failed(r) {
|
|
55562
55673
|
if (r.exitCode === null && r.killed === null) return new CtxError("FETCH_FAILED", { code: GIT_NOT_STARTED });
|
|
@@ -55580,7 +55691,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
55580
55691
|
await git2(gitBin, [...GIT_CLONE_ARGS, RELEASE_BRANCH, url4, fetchDir], agentDir, childEnv, signal);
|
|
55581
55692
|
const sha = await git2(gitBin, GIT_HEAD_SHA_ARGS, fetchDir, childEnv, signal);
|
|
55582
55693
|
const dir = join21(agentDir, sha);
|
|
55583
|
-
if (
|
|
55694
|
+
if (existsSync21(dir)) rmSync8(fetchDir, { recursive: true, force: true });
|
|
55584
55695
|
else renameWithRetry(fetchDir, dir, opts);
|
|
55585
55696
|
return { sha, dir };
|
|
55586
55697
|
} catch (e) {
|
|
@@ -55590,7 +55701,7 @@ async function fetchRelease(agent, url4, env, signal, opts = {}) {
|
|
|
55590
55701
|
}
|
|
55591
55702
|
|
|
55592
55703
|
// src/core/ops/uninstall.ts
|
|
55593
|
-
import { existsSync as
|
|
55704
|
+
import { existsSync as existsSync22, readdirSync as readdirSync10, rmSync as rmSync9, writeFileSync as writeFileSync6 } from "node:fs";
|
|
55594
55705
|
import { join as join22 } from "node:path";
|
|
55595
55706
|
function row2(area, before, after) {
|
|
55596
55707
|
return { area, before, after };
|
|
@@ -55624,7 +55735,7 @@ function removeCache(adapter, env, configDir) {
|
|
|
55624
55735
|
}
|
|
55625
55736
|
case "plugin": {
|
|
55626
55737
|
const agentDir = join22(configDir, DATA_PLUGINS_DIR_NAME, adapter.id);
|
|
55627
|
-
if (!
|
|
55738
|
+
if (!existsSync22(agentDir)) return row2(UPGRADE_CACHE_AREA, "", UPGRADE_NOT_FOUND);
|
|
55628
55739
|
rmSync9(agentDir, { recursive: true, force: true });
|
|
55629
55740
|
return row2(UPGRADE_CACHE_AREA, agentDir, UPGRADE_REMOVED);
|
|
55630
55741
|
}
|
|
@@ -55643,7 +55754,7 @@ function isObj3(v) {
|
|
|
55643
55754
|
function piSource(entry) {
|
|
55644
55755
|
return isObj3(entry) ? entry[PI_PACKAGE_SOURCE_KEY] : entry;
|
|
55645
55756
|
}
|
|
55646
|
-
function
|
|
55757
|
+
function ownEntries2(agent, env) {
|
|
55647
55758
|
const home = requireHomeDir(env);
|
|
55648
55759
|
const mcp = OWN_MCP_ENTRY[agent];
|
|
55649
55760
|
if (mcp !== void 0) {
|
|
@@ -55651,10 +55762,10 @@ function ownEntries(agent, env) {
|
|
|
55651
55762
|
const inner = mcp.key.slice(1, -1);
|
|
55652
55763
|
const own4 = mcp.key[mcp.key.length - 1];
|
|
55653
55764
|
const holder = (v) => inner.reduce((cur, k) => isObj3(cur) ? cur[k] : void 0, v);
|
|
55654
|
-
const without = (v,
|
|
55765
|
+
const without = (v, path8) => {
|
|
55655
55766
|
const o = v;
|
|
55656
|
-
if (
|
|
55657
|
-
return { ...o, [
|
|
55767
|
+
if (path8.length === 0) return Object.fromEntries(Object.entries(o).filter(([k]) => k !== own4));
|
|
55768
|
+
return { ...o, [path8[0]]: without(o[path8[0]], path8.slice(1)) };
|
|
55658
55769
|
};
|
|
55659
55770
|
return [{
|
|
55660
55771
|
file: ownMcpFileOf(agent, mcp.file, env, home),
|
|
@@ -55691,7 +55802,7 @@ function ownEntries(agent, env) {
|
|
|
55691
55802
|
}
|
|
55692
55803
|
function removeOwnEntries(agent, env) {
|
|
55693
55804
|
const rows = [];
|
|
55694
|
-
for (const entry of
|
|
55805
|
+
for (const entry of ownEntries2(agent, env)) {
|
|
55695
55806
|
const current = readHostConfig(agent, entry.file);
|
|
55696
55807
|
if (current.text === "") continue;
|
|
55697
55808
|
const value = hostConfigValueAt(parseHostConfig(agent, current.path, current.text, current.format), [entry.key]);
|
|
@@ -55704,7 +55815,7 @@ function removeOwnEntries(agent, env) {
|
|
|
55704
55815
|
function removeProjectData(configDir, projectKey) {
|
|
55705
55816
|
const projects = join22(configDir, PROJECTS_DIR_NAME);
|
|
55706
55817
|
const dir = join22(projects, projectKey);
|
|
55707
|
-
if (!
|
|
55818
|
+
if (!existsSync22(dir)) return row2(UPGRADE_DATA_AREA, "", UPGRADE_NOT_FOUND);
|
|
55708
55819
|
if (dir === projects || !isInside(projects, dir)) throw new CtxError("OUTSIDE_ROOT", { p: dir, root: projects });
|
|
55709
55820
|
for (const name of readdirSync10(dir)) {
|
|
55710
55821
|
if (name !== OWNERS_DIR_NAME) rmSync9(join22(dir, name), { recursive: true, force: true });
|
|
@@ -55720,7 +55831,7 @@ function runUninstall(input) {
|
|
|
55720
55831
|
}
|
|
55721
55832
|
|
|
55722
55833
|
// src/core/ops/v1-remove.ts
|
|
55723
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
55834
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync23, readFileSync as readFileSync14, rmSync as rmSync10 } from "node:fs";
|
|
55724
55835
|
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
55725
55836
|
var areaOf = (f) => f.path === "" ? f.file : f.file + UPGRADE_AREA_KEY_SEP + f.path;
|
|
55726
55837
|
var row3 = (f, after) => ({ area: areaOf(f), before: f.reason, after });
|
|
@@ -55750,8 +55861,8 @@ function cutTomlTable(text, header) {
|
|
|
55750
55861
|
function writeAtomic(file2, text) {
|
|
55751
55862
|
atomicWriteFile(file2, text);
|
|
55752
55863
|
}
|
|
55753
|
-
function locate(doc,
|
|
55754
|
-
const segs =
|
|
55864
|
+
function locate(doc, path8) {
|
|
55865
|
+
const segs = path8.split(V1_KEY_PATH_SEP);
|
|
55755
55866
|
let cur = doc;
|
|
55756
55867
|
for (const seg of segs.slice(0, -1)) {
|
|
55757
55868
|
if (Array.isArray(cur)) cur = cur[Number(seg)];
|
|
@@ -55764,8 +55875,8 @@ function locate(doc, path7) {
|
|
|
55764
55875
|
return null;
|
|
55765
55876
|
}
|
|
55766
55877
|
function stripJsonEntries(agent, file2, findings, kept, undo) {
|
|
55767
|
-
const layout = hostLayout(
|
|
55768
|
-
const text = hostText(
|
|
55878
|
+
const layout = hostLayout(readFileSync14(file2, "utf8"));
|
|
55879
|
+
const text = hostText(readFileSync14(file2, "utf8"));
|
|
55769
55880
|
const doc = parseHostConfig(agent, file2, text, "jsonc");
|
|
55770
55881
|
const hit = /* @__PURE__ */ new Set();
|
|
55771
55882
|
const byContainer = /* @__PURE__ */ new Map();
|
|
@@ -55801,19 +55912,19 @@ function removeV1(agent, findings) {
|
|
|
55801
55912
|
for (const f of findings) {
|
|
55802
55913
|
if (UPGRADE_REPORT_ONLY_REASONS.includes(f.reason)) done.set(f, UPGRADE_REPORT_ONLY);
|
|
55803
55914
|
else if (f.path === "") {
|
|
55804
|
-
if (
|
|
55915
|
+
if (existsSync23(f.file)) {
|
|
55805
55916
|
moveAside(f.file, undo);
|
|
55806
55917
|
done.set(f, UPGRADE_REMOVED);
|
|
55807
55918
|
} else done.set(f, UPGRADE_NOT_FOUND);
|
|
55808
55919
|
} else entries.set(f.file, [...entries.get(f.file) ?? [], f]);
|
|
55809
55920
|
}
|
|
55810
55921
|
for (const [file2, list3] of entries) {
|
|
55811
|
-
if (!
|
|
55922
|
+
if (!existsSync23(file2)) {
|
|
55812
55923
|
for (const f of list3) done.set(f, UPGRADE_NOT_FOUND);
|
|
55813
55924
|
continue;
|
|
55814
55925
|
}
|
|
55815
55926
|
if (file2.endsWith(TOML_EXT)) {
|
|
55816
|
-
const rawToml =
|
|
55927
|
+
const rawToml = readFileSync14(file2, "utf8");
|
|
55817
55928
|
const tomlLayout = hostLayout(rawToml);
|
|
55818
55929
|
let text = hostText(rawToml);
|
|
55819
55930
|
for (const f of list3) {
|
|
@@ -55841,7 +55952,7 @@ function removeV1(agent, findings) {
|
|
|
55841
55952
|
},
|
|
55842
55953
|
rollback() {
|
|
55843
55954
|
for (const u of undo.splice(0).reverse()) {
|
|
55844
|
-
if (!
|
|
55955
|
+
if (!existsSync23(u.trash)) continue;
|
|
55845
55956
|
rmSync10(u.target, { recursive: true, force: true });
|
|
55846
55957
|
renameWithRetry(u.trash, u.target);
|
|
55847
55958
|
}
|
|
@@ -55851,7 +55962,7 @@ function removeV1(agent, findings) {
|
|
|
55851
55962
|
|
|
55852
55963
|
// src/core/ops/verify-sums.ts
|
|
55853
55964
|
import { createHash as createHash2 } from "node:crypto";
|
|
55854
|
-
import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as
|
|
55965
|
+
import { lstatSync as lstatSync2, readdirSync as readdirSync11, readFileSync as readFileSync15 } from "node:fs";
|
|
55855
55966
|
import { join as join23 } from "node:path";
|
|
55856
55967
|
function mismatch() {
|
|
55857
55968
|
return new CtxError("BUNDLE_HASH_MISMATCH");
|
|
@@ -55883,14 +55994,14 @@ function verifySums(dir) {
|
|
|
55883
55994
|
const sumsPath = join23(dir, RELEASE_SUMS_FILE);
|
|
55884
55995
|
const sumsStat = lstatSync2(sumsPath, { throwIfNoEntry: false });
|
|
55885
55996
|
if (sumsStat === void 0 || !sumsStat.isFile()) throw mismatch();
|
|
55886
|
-
const sums = parseSums(
|
|
55997
|
+
const sums = parseSums(readFileSync15(sumsPath, "utf8"));
|
|
55887
55998
|
const files = /* @__PURE__ */ new Map();
|
|
55888
55999
|
walk2(dir, "", files);
|
|
55889
56000
|
if (files.size !== sums.size) throw mismatch();
|
|
55890
56001
|
for (const [rel, abs] of files) {
|
|
55891
56002
|
const want = sums.get(rel);
|
|
55892
56003
|
if (want === void 0) throw mismatch();
|
|
55893
|
-
const got = createHash2(SUMS_HASH_ALGORITHM).update(
|
|
56004
|
+
const got = createHash2(SUMS_HASH_ALGORITHM).update(readFileSync15(abs)).digest(HASH_ENCODING);
|
|
55894
56005
|
if (got !== want) throw mismatch();
|
|
55895
56006
|
}
|
|
55896
56007
|
}
|
|
@@ -55919,7 +56030,7 @@ function pluginRootRow(adapter, env) {
|
|
|
55919
56030
|
}
|
|
55920
56031
|
function isCurrent(agentDir, dir) {
|
|
55921
56032
|
const link = join24(agentDir, PLUGIN_CURRENT_LINK);
|
|
55922
|
-
return
|
|
56033
|
+
return existsSync24(link) && realpathSync11.native(link) === realpathSync11.native(dir);
|
|
55923
56034
|
}
|
|
55924
56035
|
async function checkout(adapter, deps) {
|
|
55925
56036
|
const fetched = await fetchRelease(adapter.id, deps.releaseUrl, deps.env, deps.signal);
|
|
@@ -56038,12 +56149,12 @@ function checkCall(tool, input) {
|
|
|
56038
56149
|
}
|
|
56039
56150
|
|
|
56040
56151
|
// src/entries/is-entry.ts
|
|
56041
|
-
import { realpathSync as
|
|
56152
|
+
import { realpathSync as realpathSync12 } from "node:fs";
|
|
56042
56153
|
function isEntry(main, argv1, self) {
|
|
56043
56154
|
if (main !== void 0) return main;
|
|
56044
56155
|
if (argv1 === void 0 || argv1 === "") return false;
|
|
56045
56156
|
try {
|
|
56046
|
-
return
|
|
56157
|
+
return realpathSync12(argv1) === realpathSync12(self);
|
|
56047
56158
|
} catch {
|
|
56048
56159
|
return false;
|
|
56049
56160
|
}
|
|
@@ -56119,7 +56230,7 @@ function workspaceFromMeta(meta3) {
|
|
|
56119
56230
|
}
|
|
56120
56231
|
function realOrSame(p) {
|
|
56121
56232
|
try {
|
|
56122
|
-
return
|
|
56233
|
+
return realpathSync13.native(p);
|
|
56123
56234
|
} catch {
|
|
56124
56235
|
return p;
|
|
56125
56236
|
}
|
|
@@ -56167,7 +56278,7 @@ async function startServer(argv, env) {
|
|
|
56167
56278
|
opening.catch(() => pending.delete(project.dbPath));
|
|
56168
56279
|
}
|
|
56169
56280
|
const db = await opening;
|
|
56170
|
-
if (!
|
|
56281
|
+
if (!existsSync25(db.path)) throw new CtxError("DB_GONE");
|
|
56171
56282
|
return db;
|
|
56172
56283
|
}
|
|
56173
56284
|
function stopMarker(configDir, projectKey) {
|
|
@@ -56175,7 +56286,7 @@ async function startServer(argv, env) {
|
|
|
56175
56286
|
}
|
|
56176
56287
|
function stopRequested() {
|
|
56177
56288
|
const configDir = resolveConfigDir(process.env);
|
|
56178
|
-
return held.some((db) =>
|
|
56289
|
+
return held.some((db) => existsSync25(stopMarker(configDir, db.projectKey)));
|
|
56179
56290
|
}
|
|
56180
56291
|
async function journal(project, ctx, name, reply4) {
|
|
56181
56292
|
const db = await ownDb(project);
|