context-mode 2.2.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/.zcode-plugin/plugin.json +1 -1
- package/README.md +75 -75
- package/SHA256SUMS +16 -16
- package/cli.mjs +12 -9
- package/copilot/plugin.json +1 -1
- package/gemini-extension.json +1 -1
- package/hook.mjs +91 -91
- package/opencode/plugin.js +214 -61
- package/package.json +1 -1
- package/pi/index.js +228 -63
- package/qwen-extension.json +1 -1
- package/run.mjs +60 -16
- package/search.mjs +60 -16
- package/server.mjs +100 -39
package/opencode/plugin.js
CHANGED
|
@@ -203,6 +203,10 @@ var DB_TIMEOUT_MS = 5e3;
|
|
|
203
203
|
var DB_WAL_SUFFIX = "-wal";
|
|
204
204
|
var DB_SHM_SUFFIX = "-shm";
|
|
205
205
|
var DB_TMP_SUFFIX = ".tmp";
|
|
206
|
+
var DB_LINK_DENIED_CODES = ["EACCES", "EPERM", "ENOSYS", "ENOTSUP", "EOPNOTSUPP"];
|
|
207
|
+
var DB_PUBLISH_CLAIM_SUFFIX = ".publish";
|
|
208
|
+
var DB_CLAIM_BUSY_CODES = ["EEXIST", "EPERM"];
|
|
209
|
+
var DB_PUBLISH_POLL_MS = 5;
|
|
206
210
|
var SQLITE_PRIMARY_CODE_MASK = 255;
|
|
207
211
|
var SQLITE_CORRUPT_CODE = 11;
|
|
208
212
|
var SQLITE_NOTADB_CODE = 26;
|
|
@@ -481,7 +485,7 @@ var DECISION_ANSWERS_KEY = "answers";
|
|
|
481
485
|
var DECISION_OPTION_KEY = "option";
|
|
482
486
|
var DECISION_LABEL_JOIN = " | ";
|
|
483
487
|
var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
|
|
484
|
-
var BUNDLE_SHA = true ? "
|
|
488
|
+
var BUNDLE_SHA = true ? "1fce537096e8e2b7d1924c2b5ff2b83287f157ee" : void 0;
|
|
485
489
|
var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
|
|
486
490
|
var DOCTOR_LABEL = Object.freeze({
|
|
487
491
|
D1: "version",
|
|
@@ -3740,8 +3744,12 @@ var CC_READ_ONLY_DENY = Object.freeze(["Agent", "Artifact", "ArtifactComments",
|
|
|
3740
3744
|
var CLAUDE_CODE_BUILT_INS = Object.freeze({
|
|
3741
3745
|
"general-purpose": { tools: null, disallowed: [] },
|
|
3742
3746
|
fork: { tools: null, disallowed: [] },
|
|
3747
|
+
claude: { tools: null, disallowed: [] },
|
|
3743
3748
|
Explore: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3744
|
-
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] }
|
|
3749
|
+
Plan: { tools: null, disallowed: [...CC_READ_ONLY_DENY] },
|
|
3750
|
+
"claude-code-guide": { tools: ["Glob", "Grep", "Read", "WebFetch", "WebSearch"], disallowed: [] },
|
|
3751
|
+
"statusline-setup": { tools: ["Read", "Edit"], disallowed: [] },
|
|
3752
|
+
"web-fetch": { tools: ["WebFetch"], disallowed: [] }
|
|
3745
3753
|
});
|
|
3746
3754
|
var BUILT_IN_AGENT = "claude-code";
|
|
3747
3755
|
function isSubagentCall(ev) {
|
|
@@ -3942,13 +3950,15 @@ function unique(names) {
|
|
|
3942
3950
|
// src/core/policy/unwrap.ts
|
|
3943
3951
|
var NONE = "";
|
|
3944
3952
|
var WRAPPERS = Object.freeze({
|
|
3945
|
-
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE },
|
|
3946
|
-
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE },
|
|
3947
|
-
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE },
|
|
3948
|
-
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE },
|
|
3949
|
-
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE },
|
|
3950
|
-
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV" },
|
|
3951
|
-
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE }
|
|
3953
|
+
sudo: { valueShorts: "ugpChDrtUTR", valueLongs: ["--user", "--group", "--prompt", "--chdir", "--host"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3954
|
+
env: { valueShorts: "uCS", valueLongs: ["--unset", "--chdir", "--split-string"], assignments: true, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3955
|
+
time: { valueShorts: "fo", valueLongs: ["--format", "--output"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3956
|
+
nice: { valueShorts: "n", valueLongs: ["--adjustment"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3957
|
+
timeout: { valueShorts: "sk", valueLongs: ["--signal", "--kill-after"], assignments: false, duration: true, refuseShorts: NONE, subcommands: [] },
|
|
3958
|
+
command: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: "vV", subcommands: [] },
|
|
3959
|
+
xargs: { valueShorts: "aEdILnPs", valueLongs: ["--arg-file", "--delimiter", "--max-args", "--max-procs", "--max-chars"], assignments: false, duration: false, refuseShorts: NONE, subcommands: [] },
|
|
3960
|
+
// #1388: rtk (rtk-ai/rtk) runs the inner command as-is under `proxy` / `bypass`; its other subcommands are rtk's own.
|
|
3961
|
+
rtk: { valueShorts: NONE, valueLongs: [], assignments: false, duration: false, refuseShorts: NONE, subcommands: ["proxy", "bypass"] }
|
|
3952
3962
|
});
|
|
3953
3963
|
var SHELLS = ["bash", "sh", "zsh"];
|
|
3954
3964
|
var SCRIPT_FLAG = "c";
|
|
@@ -3971,6 +3981,10 @@ function isDuration(s) {
|
|
|
3971
3981
|
}
|
|
3972
3982
|
function peel(w, args) {
|
|
3973
3983
|
let k = 0;
|
|
3984
|
+
if (w.subcommands.length > 0) {
|
|
3985
|
+
if (args.length === 0 || !w.subcommands.includes(args[0])) return null;
|
|
3986
|
+
k = 1;
|
|
3987
|
+
}
|
|
3974
3988
|
while (k < args.length) {
|
|
3975
3989
|
const a = args[k];
|
|
3976
3990
|
if (a === LONG_OPT2) {
|
|
@@ -5106,7 +5120,7 @@ function openReadOnlyHandle(sqlite, path8, opts = {}) {
|
|
|
5106
5120
|
}
|
|
5107
5121
|
|
|
5108
5122
|
// src/core/store/db.ts
|
|
5109
|
-
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, rmSync } = process.getBuiltinModule("node:fs");
|
|
5123
|
+
var { existsSync: existsSync3, linkSync, mkdirSync: mkdirSync2, renameSync, rmSync, statSync: statSync3 } = process.getBuiltinModule("node:fs");
|
|
5110
5124
|
function versionParts(v) {
|
|
5111
5125
|
const bare2 = v.startsWith("v") ? v.slice(1) : v;
|
|
5112
5126
|
return bare2.split(".").map((p) => Number.parseInt(p, 10));
|
|
@@ -5138,6 +5152,34 @@ function readUserVersion(raw) {
|
|
|
5138
5152
|
const row5 = raw.prepare("PRAGMA user_version").get();
|
|
5139
5153
|
return row5.user_version;
|
|
5140
5154
|
}
|
|
5155
|
+
function errCode(err) {
|
|
5156
|
+
return err.code ?? "";
|
|
5157
|
+
}
|
|
5158
|
+
function publishWithoutLink(tmp, path8) {
|
|
5159
|
+
const claim = path8 + DB_PUBLISH_CLAIM_SUFFIX;
|
|
5160
|
+
const start = Date.now();
|
|
5161
|
+
for (; ; ) {
|
|
5162
|
+
if (existsSync3(path8)) return;
|
|
5163
|
+
try {
|
|
5164
|
+
mkdirSync2(claim);
|
|
5165
|
+
} catch (err) {
|
|
5166
|
+
if (!DB_CLAIM_BUSY_CODES.includes(errCode(err))) throw err;
|
|
5167
|
+
if (Date.now() - start < DB_TIMEOUT_MS) {
|
|
5168
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, DB_PUBLISH_POLL_MS);
|
|
5169
|
+
continue;
|
|
5170
|
+
}
|
|
5171
|
+
const held = statSync3(claim, { throwIfNoEntry: false });
|
|
5172
|
+
if (held !== void 0 && held.mtimeMs < start) rmSync(claim, { recursive: true, force: true });
|
|
5173
|
+
throw new Error(`context.db was not published within ${DB_TIMEOUT_MS} ms: ${claim} was held; open again`);
|
|
5174
|
+
}
|
|
5175
|
+
try {
|
|
5176
|
+
if (!existsSync3(path8)) renameSync(tmp, path8);
|
|
5177
|
+
} finally {
|
|
5178
|
+
rmSync(claim, { recursive: true, force: true });
|
|
5179
|
+
}
|
|
5180
|
+
return;
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5141
5183
|
function createAtomically(sqlite, path8) {
|
|
5142
5184
|
const { randomUUID } = process.getBuiltinModule("node:crypto");
|
|
5143
5185
|
const tmp = path8 + "." + randomUUID() + DB_TMP_SUFFIX;
|
|
@@ -5151,7 +5193,9 @@ function createAtomically(sqlite, path8) {
|
|
|
5151
5193
|
try {
|
|
5152
5194
|
linkSync(tmp, path8);
|
|
5153
5195
|
} catch (err) {
|
|
5154
|
-
|
|
5196
|
+
const code = errCode(err);
|
|
5197
|
+
if (DB_LINK_DENIED_CODES.includes(code)) publishWithoutLink(tmp, path8);
|
|
5198
|
+
else if (code !== "EEXIST") throw err;
|
|
5155
5199
|
}
|
|
5156
5200
|
} finally {
|
|
5157
5201
|
for (const suffix of ["", DB_WAL_SUFFIX, DB_SHM_SUFFIX]) rmSync(tmp + suffix, { force: true });
|
|
@@ -5342,9 +5386,15 @@ function readLastPrompt(db, sessionId) {
|
|
|
5342
5386
|
const row5 = db.raw.prepare("SELECT body FROM events WHERE session_id = ? AND kind = 'prompt' ORDER BY seq DESC LIMIT 1").get(sessionId);
|
|
5343
5387
|
return row5 === void 0 ? "" : row5.body;
|
|
5344
5388
|
}
|
|
5345
|
-
function readRecallRows(db, sessionId, worktree, limit) {
|
|
5389
|
+
function readRecallRows(db, sessionId, worktree, limit, maxSeq = Number.MAX_SAFE_INTEGER) {
|
|
5346
5390
|
if (sessionId === "") return [];
|
|
5347
|
-
return db.raw.prepare(
|
|
5391
|
+
return db.raw.prepare(
|
|
5392
|
+
"SELECT * FROM events WHERE kind <> 'cost' AND ((session_id = ? AND seq <= ?) OR (worktree = ? AND session_id <> ?)) ORDER BY seq DESC LIMIT ?"
|
|
5393
|
+
).all(sessionId, maxSeq, worktree, sessionId, limit);
|
|
5394
|
+
}
|
|
5395
|
+
function readMaxSeq(db) {
|
|
5396
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(seq), 0) AS n FROM events").get();
|
|
5397
|
+
return Number(row5.n);
|
|
5348
5398
|
}
|
|
5349
5399
|
function hasAgentRows(db, worktree, agent) {
|
|
5350
5400
|
return db.raw.prepare("SELECT 1 FROM events WHERE worktree = ? AND agent = ? LIMIT 1").get(worktree, agent) !== void 0;
|
|
@@ -5352,6 +5402,10 @@ function hasAgentRows(db, worktree, agent) {
|
|
|
5352
5402
|
function hasSessionRows(db, sessionId) {
|
|
5353
5403
|
return db.raw.prepare("SELECT 1 FROM events WHERE session_id = ? LIMIT 1").get(sessionId) !== void 0;
|
|
5354
5404
|
}
|
|
5405
|
+
function lastSessionSeq(db, sessionId) {
|
|
5406
|
+
const row5 = db.raw.prepare("SELECT MAX(seq) AS m FROM events WHERE session_id = ?").get(sessionId);
|
|
5407
|
+
return row5?.m ?? 0;
|
|
5408
|
+
}
|
|
5355
5409
|
|
|
5356
5410
|
// src/core/store/snippet.ts
|
|
5357
5411
|
var K1 = 1.2;
|
|
@@ -7929,12 +7983,16 @@ function recallQueryText(prompt) {
|
|
|
7929
7983
|
if (cur !== "" && kept.size < RECALL_QUERY_MAX_TERMS) add(cur);
|
|
7930
7984
|
return [...kept.size > 0 ? kept : all].join(" ");
|
|
7931
7985
|
}
|
|
7932
|
-
function
|
|
7986
|
+
function readMaxSourceId(db) {
|
|
7987
|
+
const row5 = db.raw.prepare("SELECT COALESCE(MAX(id), 0) AS n FROM sources").get();
|
|
7988
|
+
return Number(row5.n);
|
|
7989
|
+
}
|
|
7990
|
+
function queryUnits(db, sessionId, q, limit, maxSourceId = Number.MAX_SAFE_INTEGER) {
|
|
7933
7991
|
const match = searchTerms(q).join(" OR ");
|
|
7934
7992
|
if (match === "" || sessionId === "") return [];
|
|
7935
7993
|
const rows = db.raw.prepare(
|
|
7936
|
-
"SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? ORDER BY bm25(line_units) LIMIT ?"
|
|
7937
|
-
).all(match, sessionId, limit);
|
|
7994
|
+
"SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? AND s.id <= ? ORDER BY bm25(line_units) LIMIT ?"
|
|
7995
|
+
).all(match, sessionId, maxSourceId, limit);
|
|
7938
7996
|
return rows.map((r) => ({ sourceId: Number(r.source_id), ord: Number(r.ord), label: r.label, body: r.body, score: r.score }));
|
|
7939
7997
|
}
|
|
7940
7998
|
|
|
@@ -9218,8 +9276,9 @@ async function sessionStart(ev, row5, project) {
|
|
|
9218
9276
|
if (ev.source === "compact" && hasRecall(row5)) markCompacted(await openDb(project), ev.sessionId);
|
|
9219
9277
|
if (ev.source === "compact" && row5.compactDelivery === "sessionstart") {
|
|
9220
9278
|
const db2 = await openDb(project);
|
|
9221
|
-
|
|
9222
|
-
|
|
9279
|
+
const onceKey = COMPACT_STATE_KEY + ":" + lastSessionSeq(db2, ev.sessionId);
|
|
9280
|
+
if (!shouldHint(db2, ev.sessionId, onceKey)) return ALLOW2;
|
|
9281
|
+
return { kind: "hint", text: compactText(db2, ev, row5), onceKey };
|
|
9223
9282
|
}
|
|
9224
9283
|
const db = await openDb(project);
|
|
9225
9284
|
if (row5.compactDelivery === "opencode-cache" && metaTake(db, PENDING_COMPACT_META_PREFIX + ev.sessionId) !== null) {
|
|
@@ -9266,7 +9325,22 @@ async function firstTurnResume(ev, row5, project) {
|
|
|
9266
9325
|
return { kind: "hint", text: withPrefix(RESUME_HINT, row5), onceKey: RESUME_HINT_KEY };
|
|
9267
9326
|
}
|
|
9268
9327
|
function markCompacted(db, sessionId) {
|
|
9269
|
-
if (sessionId
|
|
9328
|
+
if (sessionId === "") return;
|
|
9329
|
+
metaSet(db, COMPACTED_META_PREFIX + sessionId, JSON.stringify({ seq: readMaxSeq(db), source: readMaxSourceId(db) }));
|
|
9330
|
+
}
|
|
9331
|
+
function compactBoundary(value) {
|
|
9332
|
+
const all = { seq: Number.MAX_SAFE_INTEGER, source: Number.MAX_SAFE_INTEGER };
|
|
9333
|
+
try {
|
|
9334
|
+
const v = JSON.parse(value);
|
|
9335
|
+
if (typeof v !== "object" || v === null) return all;
|
|
9336
|
+
const { seq, source } = v;
|
|
9337
|
+
return {
|
|
9338
|
+
seq: typeof seq === "number" ? seq : all.seq,
|
|
9339
|
+
source: typeof source === "number" ? source : all.source
|
|
9340
|
+
};
|
|
9341
|
+
} catch {
|
|
9342
|
+
return all;
|
|
9343
|
+
}
|
|
9270
9344
|
}
|
|
9271
9345
|
function seenSeqs(value) {
|
|
9272
9346
|
if (value === null) return [];
|
|
@@ -9289,13 +9363,16 @@ function seenUnitKeys(value) {
|
|
|
9289
9363
|
async function recall(ev, row5, project, prompt) {
|
|
9290
9364
|
if (!hasRecall(row5) || ev.sessionId === "") return ALLOW2;
|
|
9291
9365
|
const db = await openDb(project);
|
|
9292
|
-
|
|
9366
|
+
const compacted = metaGet(db, COMPACTED_META_PREFIX + ev.sessionId);
|
|
9367
|
+
if (compacted === null) return ALLOW2;
|
|
9368
|
+
const boundary = compactBoundary(compacted);
|
|
9293
9369
|
const seenKey = RECALL_SEEN_META_PREFIX + ev.sessionId;
|
|
9294
9370
|
const seen = seenSeqs(metaGet(db, seenKey));
|
|
9295
9371
|
const unitsKey = RECALL_UNITS_SEEN_META_PREFIX + ev.sessionId;
|
|
9296
9372
|
const seenUnits = seenUnitKeys(metaGet(db, unitsKey));
|
|
9297
|
-
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES);
|
|
9298
|
-
const
|
|
9373
|
+
const units = queryUnits(db, ev.sessionId, recallQueryText(prompt), RECALL_UNIT_CANDIDATES, boundary.source);
|
|
9374
|
+
const rows = readRecallRows(db, ev.sessionId, project.worktree, RECALL_MAX_ROWS, boundary.seq);
|
|
9375
|
+
const picked = pickRecall(rows, prompt, new Set(seen), units, new Set(seenUnits));
|
|
9299
9376
|
if (picked.text === "") return ALLOW2;
|
|
9300
9377
|
if (picked.seqs.length > 0) metaSet(db, seenKey, JSON.stringify([...seen, ...picked.seqs]));
|
|
9301
9378
|
if (picked.units !== void 0) metaSet(db, unitsKey, JSON.stringify([...seenUnits, ...picked.units]));
|
|
@@ -9482,6 +9559,7 @@ function ownRead(ev, tool, env) {
|
|
|
9482
9559
|
async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
9483
9560
|
if (result.bytes <= REPLACE_TRIGGER_BYTES) return ALLOW2;
|
|
9484
9561
|
if (boundedRead(tool)) return ALLOW2;
|
|
9562
|
+
if (ompRangedRead(ev, tool)) return ALLOW2;
|
|
9485
9563
|
if (ownRead(ev, tool, env)) return ALLOW2;
|
|
9486
9564
|
if (result.keep === true) return ALLOW2;
|
|
9487
9565
|
if (!hasReplace(row5)) return ALLOW2;
|
|
@@ -9496,6 +9574,7 @@ async function postReplace(ev, row5, project, env, tool, result, text) {
|
|
|
9496
9574
|
shell: has3(row5.nativeTools.shell),
|
|
9497
9575
|
read: RANGE_READ_TOOLS.includes(tool.canonicalName) && has3(row5.nativeTools.read ?? [])
|
|
9498
9576
|
};
|
|
9577
|
+
if (set3 !== null && !caller.ctx && !caller.shell && !caller.read) return ALLOW2;
|
|
9499
9578
|
label2 = SUBAGENT_SOURCE_PREFIX + tool.canonicalName + ":" + (tool.callId ?? String(ev.turn ?? 0));
|
|
9500
9579
|
} else {
|
|
9501
9580
|
label2 = mainLabel(tool, ev);
|
|
@@ -9529,6 +9608,53 @@ function searchTwin(handle, intent, project) {
|
|
|
9529
9608
|
function boundedRead(tool) {
|
|
9530
9609
|
return RANGE_READ_TOOLS.includes(tool.canonicalName) && READ_RANGE_KEYS.some((k) => tool.input[k] !== void 0 && tool.input[k] !== null);
|
|
9531
9610
|
}
|
|
9611
|
+
function ompRangedRead(ev, tool) {
|
|
9612
|
+
if (ev.agent !== "omp" || !RANGE_READ_TOOLS.includes(tool.canonicalName)) return false;
|
|
9613
|
+
const p = READ_PATH_KEYS.map((k) => tool.input[k]).find((v) => typeof v === "string" && v !== "");
|
|
9614
|
+
if (p === void 0 || !rangedPathSuffix(p)) return false;
|
|
9615
|
+
try {
|
|
9616
|
+
return lstatSync2(resolve8(ev.cwd, p), { throwIfNoEntry: false }) === void 0;
|
|
9617
|
+
} catch {
|
|
9618
|
+
return false;
|
|
9619
|
+
}
|
|
9620
|
+
}
|
|
9621
|
+
function rangedPathSuffix(path8) {
|
|
9622
|
+
let cut = path8.lastIndexOf(":");
|
|
9623
|
+
let sel = path8.slice(cut + 1);
|
|
9624
|
+
if (sel.toLowerCase() === "raw") {
|
|
9625
|
+
cut = path8.lastIndexOf(":", cut - 1);
|
|
9626
|
+
sel = path8.slice(cut + 1, path8.length - 4);
|
|
9627
|
+
}
|
|
9628
|
+
if (cut <= 0 || !rangeList(sel)) return false;
|
|
9629
|
+
let file2 = path8.slice(0, cut);
|
|
9630
|
+
if (file2.toLowerCase().endsWith(":raw")) file2 = file2.slice(0, -4);
|
|
9631
|
+
return file2.length > 1 || !asciiLetter(file2);
|
|
9632
|
+
}
|
|
9633
|
+
function rangeList(sel) {
|
|
9634
|
+
return sel !== "" && sel.split(",").every(rangeItem);
|
|
9635
|
+
}
|
|
9636
|
+
function rangeItem(item) {
|
|
9637
|
+
if (item.startsWith("-")) return digitsOnly(item.slice(1));
|
|
9638
|
+
let i = 0;
|
|
9639
|
+
while (i < item.length && digit(item[i])) i++;
|
|
9640
|
+
if (i === 0) return false;
|
|
9641
|
+
if (i === item.length) return true;
|
|
9642
|
+
const op = item[i];
|
|
9643
|
+
const rest = item.slice(i + 1);
|
|
9644
|
+
return op === "-" && (rest === "" || digitsOnly(rest)) || op === "+" && digitsOnly(rest);
|
|
9645
|
+
}
|
|
9646
|
+
function digitsOnly(s) {
|
|
9647
|
+
if (s === "") return false;
|
|
9648
|
+
for (const c of s) if (!digit(c)) return false;
|
|
9649
|
+
return true;
|
|
9650
|
+
}
|
|
9651
|
+
function digit(c) {
|
|
9652
|
+
return c >= "0" && c <= "9";
|
|
9653
|
+
}
|
|
9654
|
+
function asciiLetter(s) {
|
|
9655
|
+
const c = s.toLowerCase();
|
|
9656
|
+
return c.length === 1 && c >= "a" && c <= "z";
|
|
9657
|
+
}
|
|
9532
9658
|
function replaceOutput(body, handleLine) {
|
|
9533
9659
|
return body === "" ? handleLine : body + "\n" + handleLine;
|
|
9534
9660
|
}
|
|
@@ -20802,7 +20928,7 @@ function buildChildEnv(parent, extra) {
|
|
|
20802
20928
|
}
|
|
20803
20929
|
|
|
20804
20930
|
// src/core/sandbox/runtimes.ts
|
|
20805
|
-
import { accessSync, constants as fsConstants, statSync as
|
|
20931
|
+
import { accessSync, constants as fsConstants, statSync as statSync4 } from "node:fs";
|
|
20806
20932
|
import path from "node:path";
|
|
20807
20933
|
|
|
20808
20934
|
// src/core/sandbox/path-entries.ts
|
|
@@ -20847,7 +20973,7 @@ function fileNames(name, pathExt) {
|
|
|
20847
20973
|
function probe(full) {
|
|
20848
20974
|
let st;
|
|
20849
20975
|
try {
|
|
20850
|
-
st =
|
|
20976
|
+
st = statSync4(full, { throwIfNoEntry: false });
|
|
20851
20977
|
} catch {
|
|
20852
20978
|
return "unreadable";
|
|
20853
20979
|
}
|
|
@@ -21042,7 +21168,7 @@ function runProcess(argv, o) {
|
|
|
21042
21168
|
}
|
|
21043
21169
|
|
|
21044
21170
|
// src/core/index/auto-memory.ts
|
|
21045
|
-
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as
|
|
21171
|
+
import { readdirSync as readdirSync3, readFileSync as readFileSync6, statSync as statSync5 } from "node:fs";
|
|
21046
21172
|
import { join as join9 } from "node:path";
|
|
21047
21173
|
var MEMORY_FILES = Object.freeze([
|
|
21048
21174
|
Object.freeze(["CLAUDE.md"]),
|
|
@@ -21068,7 +21194,7 @@ function readAutoMemory(project) {
|
|
|
21068
21194
|
const path8 = join9(project.worktree, ...segs);
|
|
21069
21195
|
if (!isInside(project.worktree, path8)) continue;
|
|
21070
21196
|
try {
|
|
21071
|
-
const st =
|
|
21197
|
+
const st = statSync5(path8);
|
|
21072
21198
|
if (!st.isFile()) continue;
|
|
21073
21199
|
rows.push({
|
|
21074
21200
|
origin: "memory",
|
|
@@ -21138,15 +21264,42 @@ function sourceCount(db, scope, ctx, source) {
|
|
|
21138
21264
|
});
|
|
21139
21265
|
return Number(row5.n);
|
|
21140
21266
|
}
|
|
21141
|
-
function zeroHits(db, scope, ctx, source, mem, offset = 0) {
|
|
21142
|
-
const
|
|
21267
|
+
function zeroHits(db, scope, ctx, source, mem, nm, queries, offset = 0) {
|
|
21268
|
+
const inScope = sourceCount(db, scope, ctx, source);
|
|
21269
|
+
const n = inScope + mem.rows.length;
|
|
21143
21270
|
if (offset > 0) return reply("No more hits past offset " + offset + ' in scope "' + scope + '" across ' + n + " source(s).", false);
|
|
21144
|
-
|
|
21271
|
+
const head2 = 'No hits in scope "' + scope + '" across ' + n + " source(s).";
|
|
21272
|
+
const pick2 = nm.pick;
|
|
21273
|
+
if (pick2 === null || mem.named || inScope > 0) return reply(head2, false);
|
|
21274
|
+
if (pick2.id !== null) {
|
|
21275
|
+
const wider = scope === "session" && sourceCount(db, "worktree", ctx, source) > 0 ? "worktree" : "project";
|
|
21276
|
+
return reply(head2 + "\nSource " + JSON.stringify(nm.arg) + ' is stored in scope "' + wider + '": ' + callText(queries, wider, nm.arg, "") + " searches it.", false);
|
|
21277
|
+
}
|
|
21278
|
+
return reply(head2 + "\n" + unknownSource(db, scope, ctx, nm.arg), true);
|
|
21279
|
+
}
|
|
21280
|
+
var STORED_SOURCES = `
|
|
21281
|
+
SELECT MAX(id) AS id, label FROM sources
|
|
21282
|
+
WHERE (:scope <> 'session' OR session_id = :session_id)
|
|
21283
|
+
AND (:scope <> 'worktree' OR worktree = :worktree)
|
|
21284
|
+
GROUP BY label ORDER BY MAX(id) DESC LIMIT :limit`;
|
|
21285
|
+
var STORED_SOURCES_SHOWN = 5;
|
|
21286
|
+
function unknownSource(db, scope, ctx, given) {
|
|
21287
|
+
const line = "Source " + JSON.stringify(given) + ' is not a stored source in scope "' + scope + '".';
|
|
21288
|
+
const rows = db.raw.prepare(STORED_SOURCES).all({
|
|
21289
|
+
scope,
|
|
21290
|
+
session_id: ctx.sessionId,
|
|
21291
|
+
worktree: ctx.project.worktree,
|
|
21292
|
+
limit: STORED_SOURCES_SHOWN + 1
|
|
21293
|
+
});
|
|
21294
|
+
if (rows.length === 0) return line + '\nctx_index stores one: ctx_index({content:"...", source:' + JSON.stringify(given) + "}).";
|
|
21295
|
+
const names = rows.slice(0, STORED_SOURCES_SHOWN).map((r) => isLongLabel(r.label) ? sourceHandle(Number(r.id)) : JSON.stringify(r.label));
|
|
21296
|
+
const more = rows.length > STORED_SOURCES_SHOWN ? ", ..." : "";
|
|
21297
|
+
return line + "\nStored sources, newest first: " + names.join(", ") + more + ". " + callText([], scope, void 0, 'sort:"timeline"') + " lists them all.";
|
|
21145
21298
|
}
|
|
21146
21299
|
function named(given, pick2) {
|
|
21147
|
-
if (given === void 0 || pick2 === null) return { arg: given, note: null };
|
|
21300
|
+
if (given === void 0 || pick2 === null) return { arg: given, note: null, pick: null };
|
|
21148
21301
|
const arg = pick2.id !== null && isLongLabel(given) ? sourceHandle(pick2.id) : given;
|
|
21149
|
-
return { arg, note: collisionLine(given, pick2) };
|
|
21302
|
+
return { arg, note: collisionLine(given, pick2), pick: pick2 };
|
|
21150
21303
|
}
|
|
21151
21304
|
function sourceCard(db, id2, input, scope, arg) {
|
|
21152
21305
|
const row5 = sourceCardRow(db, id2);
|
|
@@ -21278,7 +21431,7 @@ function relevance(db, given, scope, ctx, nm, ms, indexed) {
|
|
|
21278
21431
|
});
|
|
21279
21432
|
const take = fetched.map((h) => replyHits(h, size));
|
|
21280
21433
|
const pages = fetched.map((h, i) => h.slice(0, take[i]));
|
|
21281
|
-
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, offset);
|
|
21434
|
+
if (pages.every((p) => p.length === 0)) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries, offset);
|
|
21282
21435
|
const moreLine3 = (q, pos) => "More: " + callText([q], scope, nm.arg, "offset:" + pos);
|
|
21283
21436
|
let reserve = 0;
|
|
21284
21437
|
for (const q of input.queries) reserve += bytes2(moreLine3(q, offset + size)) + 1;
|
|
@@ -21348,7 +21501,7 @@ function timelineLine(r) {
|
|
|
21348
21501
|
}
|
|
21349
21502
|
function timeline(db, input, scope, ctx, nm, ms) {
|
|
21350
21503
|
const page2 = ftsQueryTimeline(db, scope, ctx.project, ctx.sessionId, SEARCH_PAGE_SIZE, input.after ?? null, input.source, ms.rows);
|
|
21351
|
-
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms);
|
|
21504
|
+
if (page2.rows.length === 0) return zeroHits(db, scope, ctx, input.source, ms, nm, input.queries);
|
|
21352
21505
|
const moreLine3 = (ts) => "more: " + callText(input.queries, scope, nm.arg, 'sort:"timeline", after:' + ts);
|
|
21353
21506
|
const reserve = bytes2(moreLine3(page2.rows[page2.rows.length - 1].ts)) + 1;
|
|
21354
21507
|
const lines = nm.note === null ? [] : [nm.note];
|
|
@@ -23733,16 +23886,16 @@ function parseTOML(code, options) {
|
|
|
23733
23886
|
}
|
|
23734
23887
|
|
|
23735
23888
|
// src/core/ops/atomic-file.ts
|
|
23736
|
-
import { mkdirSync as mkdirSync3, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
23889
|
+
import { mkdirSync as mkdirSync3, renameSync as renameSync2, unlinkSync, writeFileSync } from "node:fs";
|
|
23737
23890
|
import path3 from "node:path";
|
|
23738
23891
|
function sleepSync(ms) {
|
|
23739
23892
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
23740
23893
|
}
|
|
23741
|
-
function
|
|
23894
|
+
function errCode2(e) {
|
|
23742
23895
|
return e.code;
|
|
23743
23896
|
}
|
|
23744
23897
|
function renameWithRetry(from, to, opts = {}) {
|
|
23745
|
-
const rename = opts.rename ??
|
|
23898
|
+
const rename = opts.rename ?? renameSync2;
|
|
23746
23899
|
const sleep = opts.sleep ?? sleepSync;
|
|
23747
23900
|
const win = (opts.platform ?? process.platform) === "win32";
|
|
23748
23901
|
for (let attempt = 0; ; attempt += 1) {
|
|
@@ -23750,7 +23903,7 @@ function renameWithRetry(from, to, opts = {}) {
|
|
|
23750
23903
|
rename(from, to);
|
|
23751
23904
|
return;
|
|
23752
23905
|
} catch (e) {
|
|
23753
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
23906
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23754
23907
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw e;
|
|
23755
23908
|
sleep(ATOMIC_RENAME_DELAY_MS);
|
|
23756
23909
|
}
|
|
@@ -23765,15 +23918,15 @@ function unlinkWithRetry(file2, opts = {}) {
|
|
|
23765
23918
|
unlink(file2);
|
|
23766
23919
|
return;
|
|
23767
23920
|
} catch (e) {
|
|
23768
|
-
if (
|
|
23769
|
-
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(
|
|
23921
|
+
if (errCode2(e) === "ENOENT") return;
|
|
23922
|
+
const busy = win && ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23770
23923
|
if (!busy || attempt >= ATOMIC_RENAME_RETRIES) throw replaceFailure(file2, e);
|
|
23771
23924
|
sleep(ATOMIC_RENAME_DELAY_MS);
|
|
23772
23925
|
}
|
|
23773
23926
|
}
|
|
23774
23927
|
}
|
|
23775
23928
|
function replaceFailure(file2, e) {
|
|
23776
|
-
const busy = ATOMIC_RENAME_BUSY_CODES.includes(
|
|
23929
|
+
const busy = ATOMIC_RENAME_BUSY_CODES.includes(errCode2(e) ?? "");
|
|
23777
23930
|
const cause = e.message;
|
|
23778
23931
|
return new Error(busy ? `Could not replace ${file2}: ${cause}. Fix: close the program using ${file2}, then re-run` : `Could not write ${file2}: ${cause}. Fix: check the path and its permissions, then re-run`, { cause: e });
|
|
23779
23932
|
}
|
|
@@ -25463,7 +25616,7 @@ function configPaths(row5, env, worktree) {
|
|
|
25463
25616
|
}
|
|
25464
25617
|
|
|
25465
25618
|
// src/core/ops/doctor-db.ts
|
|
25466
|
-
import { existsSync as existsSync12, statSync as
|
|
25619
|
+
import { existsSync as existsSync12, statSync as statSync6 } from "node:fs";
|
|
25467
25620
|
var unknown3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "UNKNOWN", detail });
|
|
25468
25621
|
var pass3 = (id2, detail) => ({ id: id2, label: DOCTOR_LABEL[id2], status: "PASS", detail });
|
|
25469
25622
|
var fail4 = (detail, fixCommand) => ({ id: "D8", label: DOCTOR_LABEL.D8, status: "FAIL", detail, fixCommand });
|
|
@@ -25505,7 +25658,7 @@ function orphanFiles(dbPath) {
|
|
|
25505
25658
|
const files = [];
|
|
25506
25659
|
for (const suffix of [DB_WAL_SUFFIX, DB_SHM_SUFFIX]) {
|
|
25507
25660
|
const path8 = dbPath + suffix;
|
|
25508
|
-
if (existsSync12(path8)) files.push({ path: path8, bytes:
|
|
25661
|
+
if (existsSync12(path8)) files.push({ path: path8, bytes: statSync6(path8).size });
|
|
25509
25662
|
}
|
|
25510
25663
|
return files.length > 0 && !existsSync12(dbPath) ? files : [];
|
|
25511
25664
|
}
|
|
@@ -27390,7 +27543,7 @@ import { spawn as spawn3, spawnSync as spawnSync2 } from "node:child_process";
|
|
|
27390
27543
|
|
|
27391
27544
|
// src/setup/spawn-bin.ts
|
|
27392
27545
|
import { spawnSync } from "node:child_process";
|
|
27393
|
-
import { accessSync as accessSync2, constants as fsc, statSync as
|
|
27546
|
+
import { accessSync as accessSync2, constants as fsc, statSync as statSync7 } from "node:fs";
|
|
27394
27547
|
import path5 from "node:path";
|
|
27395
27548
|
var WIN_EXT = ".COM;.EXE;.BAT;.CMD";
|
|
27396
27549
|
var WIN_SHIM_EXTS = Object.freeze([".cmd", ".bat"]);
|
|
@@ -27408,7 +27561,7 @@ function whichBin(bin, env, platform = process.platform) {
|
|
|
27408
27561
|
const f = path5.join(dir, n);
|
|
27409
27562
|
try {
|
|
27410
27563
|
accessSync2(f, fsc.X_OK);
|
|
27411
|
-
if (
|
|
27564
|
+
if (statSync7(f).isFile()) return f;
|
|
27412
27565
|
} catch {
|
|
27413
27566
|
}
|
|
27414
27567
|
}
|
|
@@ -27894,7 +28047,7 @@ import { basename as basename3, join as join17 } from "node:path";
|
|
|
27894
28047
|
function ownersDir(configDir, projectKey) {
|
|
27895
28048
|
return join17(configDir, PROJECTS_DIR_NAME, projectKey, OWNERS_DIR_NAME);
|
|
27896
28049
|
}
|
|
27897
|
-
function
|
|
28050
|
+
function errCode3(err) {
|
|
27898
28051
|
return err.code;
|
|
27899
28052
|
}
|
|
27900
28053
|
function isLive(pid) {
|
|
@@ -27903,8 +28056,8 @@ function isLive(pid) {
|
|
|
27903
28056
|
process.kill(pid, 0);
|
|
27904
28057
|
return true;
|
|
27905
28058
|
} catch (err) {
|
|
27906
|
-
if (
|
|
27907
|
-
if (
|
|
28059
|
+
if (errCode3(err) === "ESRCH") return false;
|
|
28060
|
+
if (errCode3(err) === "EPERM") return true;
|
|
27908
28061
|
throw err;
|
|
27909
28062
|
}
|
|
27910
28063
|
}
|
|
@@ -27914,7 +28067,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27914
28067
|
try {
|
|
27915
28068
|
names = readdirSync7(dir);
|
|
27916
28069
|
} catch (err) {
|
|
27917
|
-
if (
|
|
28070
|
+
if (errCode3(err) === "ENOENT") return [];
|
|
27918
28071
|
throw err;
|
|
27919
28072
|
}
|
|
27920
28073
|
const live = [];
|
|
@@ -27925,7 +28078,7 @@ function listLiveOwners(configDir, projectKey) {
|
|
|
27925
28078
|
try {
|
|
27926
28079
|
text = readFileSync15(file2, "utf8");
|
|
27927
28080
|
} catch (err) {
|
|
27928
|
-
if (
|
|
28081
|
+
if (errCode3(err) === "ENOENT") continue;
|
|
27929
28082
|
throw err;
|
|
27930
28083
|
}
|
|
27931
28084
|
const serverId = basename3(name, OWNER_PID_EXT);
|
|
@@ -28027,8 +28180,8 @@ function keyIsTyped(key) {
|
|
|
28027
28180
|
if (key.length === 0) return false;
|
|
28028
28181
|
for (const ch of key) {
|
|
28029
28182
|
const upper = ch >= "A" && ch <= "Z";
|
|
28030
|
-
const
|
|
28031
|
-
if (!upper && !
|
|
28183
|
+
const digit2 = ch >= "0" && ch <= "9";
|
|
28184
|
+
if (!upper && !digit2 && ch !== "_") return false;
|
|
28032
28185
|
}
|
|
28033
28186
|
return true;
|
|
28034
28187
|
}
|
|
@@ -28678,11 +28831,11 @@ var ctxExecute = {
|
|
|
28678
28831
|
};
|
|
28679
28832
|
|
|
28680
28833
|
// src/core/tools/index.ts
|
|
28681
|
-
import { existsSync as existsSync19, readFileSync as readFileSync20, statSync as
|
|
28834
|
+
import { existsSync as existsSync19, readFileSync as readFileSync20, statSync as statSync9 } from "node:fs";
|
|
28682
28835
|
import { dirname as dirname13, extname as extname3, join as join24, relative as relative5, resolve as resolve12 } from "node:path";
|
|
28683
28836
|
|
|
28684
28837
|
// src/core/index/walk.ts
|
|
28685
|
-
import { readdirSync as readdirSync9, readFileSync as readFileSync18, realpathSync as realpathSync10, statSync as
|
|
28838
|
+
import { readdirSync as readdirSync9, readFileSync as readFileSync18, realpathSync as realpathSync10, statSync as statSync8 } from "node:fs";
|
|
28686
28839
|
import { join as join22 } from "node:path";
|
|
28687
28840
|
var GITIGNORE = ".gitignore";
|
|
28688
28841
|
var GIT_DIR = ".git";
|
|
@@ -28716,7 +28869,7 @@ function visit(abs, rel, parent, contain, seen, found) {
|
|
|
28716
28869
|
continue;
|
|
28717
28870
|
}
|
|
28718
28871
|
if (!isInside(contain, resolved)) continue;
|
|
28719
|
-
const st =
|
|
28872
|
+
const st = statSync8(resolved);
|
|
28720
28873
|
isDir = st.isDirectory();
|
|
28721
28874
|
isFile = st.isFile();
|
|
28722
28875
|
target = resolved;
|
|
@@ -29419,8 +29572,8 @@ var EntityDecoder = class {
|
|
|
29419
29572
|
while (offset < inputLength) {
|
|
29420
29573
|
const char = input.charCodeAt(offset);
|
|
29421
29574
|
if (isNumber2(char) || isHexadecimalCharacter(char)) {
|
|
29422
|
-
const
|
|
29423
|
-
result = result * 16 +
|
|
29575
|
+
const digit2 = char <= CharCodes.NINE ? char - CharCodes.ZERO : (char | TO_LOWER_BIT) - CharCodes.LOWER_A + 10;
|
|
29576
|
+
result = result * 16 + digit2;
|
|
29424
29577
|
consumed += 1;
|
|
29425
29578
|
offset += 1;
|
|
29426
29579
|
} else {
|
|
@@ -29448,13 +29601,13 @@ var EntityDecoder = class {
|
|
|
29448
29601
|
let { result } = this;
|
|
29449
29602
|
let { consumed } = this;
|
|
29450
29603
|
while (offset < inputLength) {
|
|
29451
|
-
const
|
|
29452
|
-
if (
|
|
29604
|
+
const digit2 = input.charCodeAt(offset) - CharCodes.ZERO;
|
|
29605
|
+
if (digit2 >>> 0 > 9) {
|
|
29453
29606
|
this.result = result;
|
|
29454
29607
|
this.consumed = consumed;
|
|
29455
|
-
return this.emitNumericEntity(
|
|
29608
|
+
return this.emitNumericEntity(digit2 + CharCodes.ZERO, 2);
|
|
29456
29609
|
}
|
|
29457
|
-
result = result * 10 +
|
|
29610
|
+
result = result * 10 + digit2;
|
|
29458
29611
|
consumed += 1;
|
|
29459
29612
|
offset += 1;
|
|
29460
29613
|
}
|
|
@@ -32904,7 +33057,7 @@ function pathItems(input, project) {
|
|
|
32904
33057
|
const abs = resolve12(project.worktree, input.path);
|
|
32905
33058
|
if (!isInside(project.containmentRoot, abs)) throw missingOrOutside(input.path, abs, project.containmentRoot);
|
|
32906
33059
|
const base = relative5(project.worktree, abs);
|
|
32907
|
-
if (
|
|
33060
|
+
if (statSync9(abs).isDirectory()) {
|
|
32908
33061
|
return walkDir(abs, project.containmentRoot).map((f) => ({
|
|
32909
33062
|
sourceKind: "path",
|
|
32910
33063
|
label: pathLabel(join24(base, f.relPath)),
|
package/package.json
CHANGED