sphica 0.6.42 → 0.6.44
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/plugin.json +7 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -1
- package/dist/capture.js +311 -164
- package/dist/cli.js +501 -343
- package/dist/deliver.js +1078 -541
- package/dist/git-worker.js +365 -0
- package/dist/mcp-record.js +489 -333
- package/dist/mcp.js +359 -232
- package/hooks/codex.json +11 -0
- package/hooks/hooks.json +28 -0
- package/package.json +1 -1
package/dist/mcp.js
CHANGED
|
@@ -45702,14 +45702,14 @@ function adapt(raw) {
|
|
|
45702
45702
|
}
|
|
45703
45703
|
|
|
45704
45704
|
// server/src/sqlite.ts
|
|
45705
|
-
import
|
|
45706
|
-
import
|
|
45707
|
-
import
|
|
45705
|
+
import fs3 from "node:fs";
|
|
45706
|
+
import os2 from "node:os";
|
|
45707
|
+
import path3 from "node:path";
|
|
45708
45708
|
import { constants as C, DatabaseSync } from "node:sqlite";
|
|
45709
45709
|
|
|
45710
45710
|
// server/src/plugin.ts
|
|
45711
|
-
import
|
|
45712
|
-
import
|
|
45711
|
+
import fs2 from "node:fs";
|
|
45712
|
+
import path2 from "node:path";
|
|
45713
45713
|
import { fileURLToPath } from "node:url";
|
|
45714
45714
|
|
|
45715
45715
|
// server/node_modules/smol-toml/dist/error.js
|
|
@@ -45979,12 +45979,184 @@ var NO_MATCHER = new Set(["UserPromptSubmit", "Stop", "Interrupt"]);
|
|
|
45979
45979
|
var CONTEXT = new Set(["PreToolUse", "PostToolUse", "SessionStart", "UserPromptSubmit", "SubagentStart"]);
|
|
45980
45980
|
var SHORT = new Set(["SessionEnd", "Interrupt"]);
|
|
45981
45981
|
|
|
45982
|
+
// server/src/git.ts
|
|
45983
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
45984
|
+
import fs from "node:fs";
|
|
45985
|
+
import os from "node:os";
|
|
45986
|
+
import path from "node:path";
|
|
45987
|
+
var gitHome = () => path.join(os.homedir(), ".sphica", "git");
|
|
45988
|
+
function gitEnv(extra = {}) {
|
|
45989
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !/^GIT_/i.test(k)));
|
|
45990
|
+
return {
|
|
45991
|
+
...env,
|
|
45992
|
+
GIT_ALLOW_PROTOCOL: "",
|
|
45993
|
+
GIT_NO_LAZY_FETCH: "1",
|
|
45994
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
45995
|
+
GIT_NO_REPLACE_OBJECTS: "1",
|
|
45996
|
+
...extra
|
|
45997
|
+
};
|
|
45998
|
+
}
|
|
45999
|
+
var gitOptions = (hooks = path.join(gitHome(), "hooks")) => [
|
|
46000
|
+
"-c",
|
|
46001
|
+
"core.fsmonitor=",
|
|
46002
|
+
"-c",
|
|
46003
|
+
`core.hooksPath=${hooks}`,
|
|
46004
|
+
"-c",
|
|
46005
|
+
"core.quotePath=false",
|
|
46006
|
+
"--no-pager",
|
|
46007
|
+
"--no-optional-locks"
|
|
46008
|
+
];
|
|
46009
|
+
function startDir() {
|
|
46010
|
+
const home = os.homedir();
|
|
46011
|
+
return fs.statSync(home, { throwIfNoEntry: false })?.isDirectory() ? home : path.dirname(process.execPath);
|
|
46012
|
+
}
|
|
46013
|
+
function run(root, args, { max = 1024 * 1024, timeout = 1e4 } = {}) {
|
|
46014
|
+
return execFileSync("git", ["-C", root, ...gitOptions(), ...args], {
|
|
46015
|
+
cwd: startDir(),
|
|
46016
|
+
env: gitEnv(),
|
|
46017
|
+
maxBuffer: max,
|
|
46018
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
46019
|
+
timeout,
|
|
46020
|
+
killSignal: "SIGKILL"
|
|
46021
|
+
});
|
|
46022
|
+
}
|
|
46023
|
+
var text = (root, args, limits) => run(root, args, limits).toString("utf8");
|
|
46024
|
+
var list = (out) => out.split("\x00").filter(Boolean);
|
|
46025
|
+
function revision(rev) {
|
|
46026
|
+
if (!rev || rev.startsWith("-") || /[\0\n]/.test(rev))
|
|
46027
|
+
throw new Error(`not a revision: ${JSON.stringify(rev)}`);
|
|
46028
|
+
return rev;
|
|
46029
|
+
}
|
|
46030
|
+
var topLevel = (dir, limits) => text(dir, ["rev-parse", "--show-toplevel"], limits).trim();
|
|
46031
|
+
var insideWorkTree = (dir) => text(dir, ["rev-parse", "--is-inside-work-tree"]).trim() === "true";
|
|
46032
|
+
var commitOf = (root, rev, limits) => text(root, ["rev-parse", "--verify", "-q", `${revision(rev)}^{commit}`], limits).trim();
|
|
46033
|
+
function listFiles(root, kind, { pathspecs = [], ...limits } = {}) {
|
|
46034
|
+
const which = {
|
|
46035
|
+
tracked: ["--cached"],
|
|
46036
|
+
untracked: ["--others", "--exclude-standard"],
|
|
46037
|
+
"tracked-and-untracked": ["--cached", "--others", "--exclude-standard"],
|
|
46038
|
+
deleted: ["--deleted"]
|
|
46039
|
+
}[kind];
|
|
46040
|
+
return list(text(root, ["ls-files", "-z", ...which, "--", ...pathspecs], limits));
|
|
46041
|
+
}
|
|
46042
|
+
var originUrl = (root, limits) => text(root, ["remote", "get-url", "origin"], limits).trim();
|
|
46043
|
+
async function renamesSince(root, commit, deadline = 1e4) {
|
|
46044
|
+
const limit = 1000;
|
|
46045
|
+
const until = Date.now() + deadline;
|
|
46046
|
+
let oid;
|
|
46047
|
+
try {
|
|
46048
|
+
oid = commitOf(root, commit, { timeout: deadline });
|
|
46049
|
+
} catch {
|
|
46050
|
+
return null;
|
|
46051
|
+
}
|
|
46052
|
+
const left = until - Date.now();
|
|
46053
|
+
if (left <= 0)
|
|
46054
|
+
return null;
|
|
46055
|
+
const out = await inIsolation(root, [{ kind: "renames", commit: oid }], {
|
|
46056
|
+
deadline: left,
|
|
46057
|
+
max: 32 * 1024 * 1024
|
|
46058
|
+
});
|
|
46059
|
+
const names = out?.[0];
|
|
46060
|
+
if (names === undefined)
|
|
46061
|
+
return null;
|
|
46062
|
+
const parts = names.split("\x00");
|
|
46063
|
+
const renames = new Map;
|
|
46064
|
+
const deleted = [];
|
|
46065
|
+
let added = 0;
|
|
46066
|
+
for (let i = 0;i < parts.length; ) {
|
|
46067
|
+
const status = parts[i] ?? "";
|
|
46068
|
+
if (/^[RC]\d*$/.test(status)) {
|
|
46069
|
+
if (status.startsWith("R"))
|
|
46070
|
+
renames.set(parts[i + 1] ?? "", parts[i + 2] ?? "");
|
|
46071
|
+
i += 3;
|
|
46072
|
+
} else {
|
|
46073
|
+
if (status === "D")
|
|
46074
|
+
deleted.push(parts[i + 1] ?? "");
|
|
46075
|
+
if (status === "A")
|
|
46076
|
+
added++;
|
|
46077
|
+
i += 2;
|
|
46078
|
+
}
|
|
46079
|
+
}
|
|
46080
|
+
if (deleted.length * added > limit * limit)
|
|
46081
|
+
for (const d of deleted)
|
|
46082
|
+
renames.set(d, null);
|
|
46083
|
+
return renames;
|
|
46084
|
+
}
|
|
46085
|
+
function workerFile() {
|
|
46086
|
+
const js = path.join(import.meta.dirname, "git-worker.js");
|
|
46087
|
+
return fs.existsSync(js) ? js : path.join(import.meta.dirname, "git-worker.ts");
|
|
46088
|
+
}
|
|
46089
|
+
function inIsolation(root, ops, { deadline, max }) {
|
|
46090
|
+
return new Promise((resolve) => {
|
|
46091
|
+
let child;
|
|
46092
|
+
try {
|
|
46093
|
+
child = spawn(process.execPath, [workerFile()], {
|
|
46094
|
+
cwd: startDir(),
|
|
46095
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
46096
|
+
windowsHide: true,
|
|
46097
|
+
detached: process.platform !== "win32"
|
|
46098
|
+
});
|
|
46099
|
+
} catch {
|
|
46100
|
+
resolve(null);
|
|
46101
|
+
return;
|
|
46102
|
+
}
|
|
46103
|
+
const chunks = [];
|
|
46104
|
+
let size = 0;
|
|
46105
|
+
let done = false;
|
|
46106
|
+
const finish = (out) => {
|
|
46107
|
+
if (done)
|
|
46108
|
+
return;
|
|
46109
|
+
done = true;
|
|
46110
|
+
clearTimeout(timer);
|
|
46111
|
+
if (out === null) {
|
|
46112
|
+
try {
|
|
46113
|
+
if (process.platform !== "win32" && child.pid)
|
|
46114
|
+
process.kill(-child.pid, "SIGKILL");
|
|
46115
|
+
else
|
|
46116
|
+
child.kill("SIGKILL");
|
|
46117
|
+
} catch {
|
|
46118
|
+
child.kill("SIGKILL");
|
|
46119
|
+
}
|
|
46120
|
+
child.stdin?.destroy();
|
|
46121
|
+
child.stdout?.destroy();
|
|
46122
|
+
child.unref();
|
|
46123
|
+
}
|
|
46124
|
+
resolve(out);
|
|
46125
|
+
};
|
|
46126
|
+
const timer = setTimeout(() => finish(null), deadline);
|
|
46127
|
+
const cap = 6 * max * Math.max(1, ops.length * 2) + 64 * 1024;
|
|
46128
|
+
child.stdout?.on("data", (c) => {
|
|
46129
|
+
size += c.length;
|
|
46130
|
+
if (size > cap)
|
|
46131
|
+
finish(null);
|
|
46132
|
+
else
|
|
46133
|
+
chunks.push(c);
|
|
46134
|
+
});
|
|
46135
|
+
child.on("error", () => finish(null));
|
|
46136
|
+
child.on("close", () => {
|
|
46137
|
+
try {
|
|
46138
|
+
const result = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
46139
|
+
finish(result.ok ? result.out : null);
|
|
46140
|
+
} catch {
|
|
46141
|
+
finish(null);
|
|
46142
|
+
}
|
|
46143
|
+
});
|
|
46144
|
+
child.stdin?.on("error", () => finish(null));
|
|
46145
|
+
child.stdin?.end(JSON.stringify({
|
|
46146
|
+
root,
|
|
46147
|
+
ops,
|
|
46148
|
+
max,
|
|
46149
|
+
until: Date.now() + Math.floor(deadline * 0.8)
|
|
46150
|
+
}));
|
|
46151
|
+
});
|
|
46152
|
+
}
|
|
46153
|
+
|
|
45982
46154
|
// server/src/plugin.ts
|
|
45983
|
-
var MANIFEST =
|
|
46155
|
+
var MANIFEST = path2.join(".claude-plugin", "plugin.json");
|
|
45984
46156
|
var PACKAGE = "package.json";
|
|
45985
46157
|
function versionAt(root) {
|
|
45986
46158
|
try {
|
|
45987
|
-
const m = JSON.parse(
|
|
46159
|
+
const m = JSON.parse(fs2.readFileSync(path2.join(root, MANIFEST), "utf8"));
|
|
45988
46160
|
return m.name === "sphica" && typeof m.version === "string" ? m.version : null;
|
|
45989
46161
|
} catch {
|
|
45990
46162
|
return null;
|
|
@@ -45992,28 +46164,28 @@ function versionAt(root) {
|
|
|
45992
46164
|
}
|
|
45993
46165
|
function packageVersionAt(root) {
|
|
45994
46166
|
try {
|
|
45995
|
-
const m = JSON.parse(
|
|
46167
|
+
const m = JSON.parse(fs2.readFileSync(path2.join(root, PACKAGE), "utf8"));
|
|
45996
46168
|
return m.name === "sphica" && typeof m.version === "string" ? m.version : null;
|
|
45997
46169
|
} catch {
|
|
45998
46170
|
return null;
|
|
45999
46171
|
}
|
|
46000
46172
|
}
|
|
46001
|
-
var here =
|
|
46002
|
-
var ROOT = [
|
|
46173
|
+
var here = path2.dirname(fileURLToPath(import.meta.url));
|
|
46174
|
+
var ROOT = [path2.join(here, ".."), path2.join(here, "..", "..", "plugin")].find((r) => versionAt(r) !== null) ?? path2.join(here, "..");
|
|
46003
46175
|
var HOST_MARKS = new Set([".orphaned_at", ".in_use"]);
|
|
46004
46176
|
|
|
46005
46177
|
// server/src/sqlite.ts
|
|
46006
46178
|
var SCHEMA_GENERATION = 2;
|
|
46007
46179
|
var SCHEMA_REVISION = 12;
|
|
46008
|
-
var sphicaHome = () => process.env.SPHICA_HOME ||
|
|
46009
|
-
var dbFile = () => process.env.SPHICA_DB ||
|
|
46180
|
+
var sphicaHome = () => process.env.SPHICA_HOME || path3.join(os2.homedir(), ".sphica");
|
|
46181
|
+
var dbFile = () => process.env.SPHICA_DB || path3.join(sphicaHome(), "sphica.db");
|
|
46010
46182
|
function requireRuntime() {
|
|
46011
46183
|
const proto = DatabaseSync.prototype;
|
|
46012
46184
|
if (typeof proto.setAuthorizer !== "function" || typeof proto.enableDefensive !== "function")
|
|
46013
46185
|
throw new Error(`Sphica needs Node 24.15 or later (this is ${process.version}). Upgrade Node.`);
|
|
46014
46186
|
}
|
|
46015
46187
|
function requireFile(file2) {
|
|
46016
|
-
if (!
|
|
46188
|
+
if (!fs3.existsSync(file2))
|
|
46017
46189
|
throw new Error(`No database at ${file2}. Create it with \`sphica init\`.`);
|
|
46018
46190
|
}
|
|
46019
46191
|
function prepare(raw, check2, busyMs = 5000) {
|
|
@@ -46114,9 +46286,9 @@ var iso = (d) => {
|
|
|
46114
46286
|
function byUnit(rows) {
|
|
46115
46287
|
const out = new Map;
|
|
46116
46288
|
for (const r of rows) {
|
|
46117
|
-
const
|
|
46118
|
-
if (
|
|
46119
|
-
|
|
46289
|
+
const list2 = out.get(r.unit_id);
|
|
46290
|
+
if (list2)
|
|
46291
|
+
list2.push(r);
|
|
46120
46292
|
else
|
|
46121
46293
|
out.set(r.unit_id, [r]);
|
|
46122
46294
|
}
|
|
@@ -46150,18 +46322,18 @@ var HOSTS = ["claude-code", "codex"];
|
|
|
46150
46322
|
var sessionId = (projectId, host, externalId) => uuidFrom(String(projectId), host, externalId);
|
|
46151
46323
|
|
|
46152
46324
|
// server/src/anchors.ts
|
|
46153
|
-
import
|
|
46154
|
-
import
|
|
46325
|
+
import fs4 from "node:fs";
|
|
46326
|
+
import path4 from "node:path";
|
|
46155
46327
|
var MAX_BYTES = 2 * 1024 * 1024;
|
|
46156
|
-
var leaves = (rel) => rel === ".." || rel.startsWith(`..${
|
|
46328
|
+
var leaves = (rel) => rel === ".." || rel.startsWith(`..${path4.sep}`) || path4.isAbsolute(rel);
|
|
46157
46329
|
var literal3 = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46158
46330
|
function readBytes(root, rel) {
|
|
46159
|
-
const abs =
|
|
46160
|
-
if (leaves(
|
|
46331
|
+
const abs = path4.join(root, rel);
|
|
46332
|
+
if (leaves(path4.relative(root, abs)))
|
|
46161
46333
|
return;
|
|
46162
46334
|
let st;
|
|
46163
46335
|
try {
|
|
46164
|
-
st =
|
|
46336
|
+
st = fs4.lstatSync(abs, { throwIfNoEntry: false });
|
|
46165
46337
|
} catch (e) {
|
|
46166
46338
|
return e.code === "ENOTDIR" ? null : undefined;
|
|
46167
46339
|
}
|
|
@@ -46170,10 +46342,10 @@ function readBytes(root, rel) {
|
|
|
46170
46342
|
if (!st.isFile() || st.size > MAX_BYTES)
|
|
46171
46343
|
return;
|
|
46172
46344
|
try {
|
|
46173
|
-
const inside =
|
|
46345
|
+
const inside = path4.relative(fs4.realpathSync(root), fs4.realpathSync(abs));
|
|
46174
46346
|
if (leaves(inside))
|
|
46175
46347
|
return;
|
|
46176
|
-
const buf =
|
|
46348
|
+
const buf = fs4.readFileSync(abs);
|
|
46177
46349
|
return buf.includes(0) ? undefined : buf;
|
|
46178
46350
|
} catch {
|
|
46179
46351
|
return;
|
|
@@ -46183,28 +46355,28 @@ function readText(root, rel) {
|
|
|
46183
46355
|
const buf = readBytes(root, rel);
|
|
46184
46356
|
return buf ? buf.toString("utf8") : buf;
|
|
46185
46357
|
}
|
|
46186
|
-
function findSymbol(
|
|
46358
|
+
function findSymbol(text2, symbol2) {
|
|
46187
46359
|
const re = new RegExp(`(?<![\\w$])${literal3(symbol2)}(?![\\w$])`);
|
|
46188
|
-
const lines =
|
|
46360
|
+
const lines = text2.split(/\r?\n/);
|
|
46189
46361
|
return { lines, i: lines.findIndex((l) => re.test(l)) };
|
|
46190
46362
|
}
|
|
46191
46363
|
function fileState(root, rel) {
|
|
46192
46364
|
if (!root)
|
|
46193
46365
|
return "unknown";
|
|
46194
|
-
if (leaves(
|
|
46366
|
+
if (leaves(path4.relative(root, path4.join(root, rel))))
|
|
46195
46367
|
return "unknown";
|
|
46196
46368
|
let realRoot;
|
|
46197
46369
|
try {
|
|
46198
|
-
realRoot =
|
|
46370
|
+
realRoot = fs4.realpathSync(root);
|
|
46199
46371
|
} catch {
|
|
46200
46372
|
return "unknown";
|
|
46201
46373
|
}
|
|
46202
46374
|
let at = root;
|
|
46203
46375
|
for (const part of rel.split("/")) {
|
|
46204
|
-
at =
|
|
46376
|
+
at = path4.join(at, part);
|
|
46205
46377
|
let st;
|
|
46206
46378
|
try {
|
|
46207
|
-
st =
|
|
46379
|
+
st = fs4.lstatSync(at, { throwIfNoEntry: false });
|
|
46208
46380
|
} catch (e) {
|
|
46209
46381
|
if (e.code === "ENOTDIR")
|
|
46210
46382
|
return "gone";
|
|
@@ -46214,7 +46386,7 @@ function fileState(root, rel) {
|
|
|
46214
46386
|
return "gone";
|
|
46215
46387
|
if (st.isSymbolicLink()) {
|
|
46216
46388
|
try {
|
|
46217
|
-
if (leaves(
|
|
46389
|
+
if (leaves(path4.relative(realRoot, fs4.realpathSync(at))))
|
|
46218
46390
|
return "unknown";
|
|
46219
46391
|
} catch {
|
|
46220
46392
|
return "unknown";
|
|
@@ -46226,14 +46398,14 @@ function fileState(root, rel) {
|
|
|
46226
46398
|
function checkAnchor(root, a) {
|
|
46227
46399
|
if (!root)
|
|
46228
46400
|
return { state: "unknown", line: null };
|
|
46229
|
-
const
|
|
46230
|
-
if (
|
|
46401
|
+
const text2 = readText(root, a.path);
|
|
46402
|
+
if (text2 === null)
|
|
46231
46403
|
return { state: "missing", line: null };
|
|
46232
|
-
if (
|
|
46404
|
+
if (text2 === undefined)
|
|
46233
46405
|
return { state: "unknown", line: null };
|
|
46234
46406
|
if (!a.symbol)
|
|
46235
46407
|
return { state: "located", line: a.line_start };
|
|
46236
|
-
const { i } = findSymbol(
|
|
46408
|
+
const { i } = findSymbol(text2, a.symbol);
|
|
46237
46409
|
if (i < 0)
|
|
46238
46410
|
return { state: "missing", line: null };
|
|
46239
46411
|
return {
|
|
@@ -46242,51 +46414,9 @@ function checkAnchor(root, a) {
|
|
|
46242
46414
|
};
|
|
46243
46415
|
}
|
|
46244
46416
|
|
|
46245
|
-
// server/src/git.ts
|
|
46246
|
-
import { execFileSync } from "node:child_process";
|
|
46247
|
-
function cleanGit(root, args, max = 1024 * 1024) {
|
|
46248
|
-
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => !k.startsWith("GIT_")));
|
|
46249
|
-
return execFileSync("git", ["-C", root, ...args], {
|
|
46250
|
-
env,
|
|
46251
|
-
maxBuffer: max,
|
|
46252
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
46253
|
-
timeout: 1e4
|
|
46254
|
-
});
|
|
46255
|
-
}
|
|
46256
|
-
function renamesSince(root, commit) {
|
|
46257
|
-
const limit = 1000;
|
|
46258
|
-
try {
|
|
46259
|
-
const out = cleanGit(root, ["diff", "-M", `-l${limit}`, "--name-status", "-z", commit, "--"], 32 * 1024 * 1024);
|
|
46260
|
-
const parts = out.toString("utf8").split("\x00");
|
|
46261
|
-
const renames = new Map;
|
|
46262
|
-
const deleted = [];
|
|
46263
|
-
let added = 0;
|
|
46264
|
-
for (let i = 0;i < parts.length; ) {
|
|
46265
|
-
const status = parts[i] ?? "";
|
|
46266
|
-
if (/^[RC]\d*$/.test(status)) {
|
|
46267
|
-
if (status.startsWith("R"))
|
|
46268
|
-
renames.set(parts[i + 1] ?? "", parts[i + 2] ?? "");
|
|
46269
|
-
i += 3;
|
|
46270
|
-
} else {
|
|
46271
|
-
if (status === "D")
|
|
46272
|
-
deleted.push(parts[i + 1] ?? "");
|
|
46273
|
-
if (status === "A")
|
|
46274
|
-
added++;
|
|
46275
|
-
i += 2;
|
|
46276
|
-
}
|
|
46277
|
-
}
|
|
46278
|
-
if (deleted.length * added > limit * limit)
|
|
46279
|
-
for (const d of deleted)
|
|
46280
|
-
renames.set(d, null);
|
|
46281
|
-
return renames;
|
|
46282
|
-
} catch {
|
|
46283
|
-
return null;
|
|
46284
|
-
}
|
|
46285
|
-
}
|
|
46286
|
-
|
|
46287
46417
|
// server/src/rule-files.ts
|
|
46288
|
-
import
|
|
46289
|
-
import
|
|
46418
|
+
import fs5 from "node:fs";
|
|
46419
|
+
import path5 from "node:path";
|
|
46290
46420
|
var RULE_LIMITS = { files: 200, bytes: 256 * 1024, depth: 8, entries: 5000 };
|
|
46291
46421
|
var RULE_NAMES = new Set(["CLAUDE.md", "AGENTS.md", "AGENTS.override.md"]);
|
|
46292
46422
|
var PATHSPECS = [...RULE_NAMES, ".claude/rules/**/*.md"].map((p) => `:(glob)**/${p}`);
|
|
@@ -46302,7 +46432,7 @@ var pathHash = (rel) => sha256(rel).toString("hex").slice(0, 16);
|
|
|
46302
46432
|
function ruleFiles(root, from) {
|
|
46303
46433
|
const listed = gitList(root) ?? walk(root);
|
|
46304
46434
|
const out = { files: [], skipped: 0, incomplete: listed.incomplete };
|
|
46305
|
-
const realRoot =
|
|
46435
|
+
const realRoot = fs5.realpathSync(root);
|
|
46306
46436
|
const paths = [...new Set(listed.paths)].sort();
|
|
46307
46437
|
const start = from ? Math.max(paths.findIndex((rel) => pathHash(rel) === from), 0) : 0;
|
|
46308
46438
|
for (const [i, rel] of paths.entries()) {
|
|
@@ -46312,29 +46442,29 @@ function ruleFiles(root, from) {
|
|
|
46312
46442
|
out.skipped++;
|
|
46313
46443
|
continue;
|
|
46314
46444
|
}
|
|
46315
|
-
const
|
|
46316
|
-
if (
|
|
46445
|
+
const text2 = readBounded(root, realRoot, rel);
|
|
46446
|
+
if (text2 === null)
|
|
46317
46447
|
continue;
|
|
46318
|
-
if (
|
|
46448
|
+
if (text2 === undefined)
|
|
46319
46449
|
out.skipped++;
|
|
46320
46450
|
else
|
|
46321
|
-
out.files.push({ path: rel, text });
|
|
46451
|
+
out.files.push({ path: rel, text: text2 });
|
|
46322
46452
|
}
|
|
46323
46453
|
return out;
|
|
46324
46454
|
}
|
|
46325
46455
|
function readBounded(root, realRoot, rel) {
|
|
46326
|
-
const abs =
|
|
46327
|
-
if (leaves(
|
|
46456
|
+
const abs = path5.join(root, rel);
|
|
46457
|
+
if (leaves(path5.relative(root, abs)))
|
|
46328
46458
|
return;
|
|
46329
46459
|
try {
|
|
46330
|
-
const st =
|
|
46460
|
+
const st = fs5.lstatSync(abs, { throwIfNoEntry: false });
|
|
46331
46461
|
if (!st)
|
|
46332
46462
|
return null;
|
|
46333
46463
|
if (!st.isFile() || st.size > RULE_LIMITS.bytes)
|
|
46334
46464
|
return;
|
|
46335
|
-
if (leaves(
|
|
46465
|
+
if (leaves(path5.relative(realRoot, fs5.realpathSync(abs))))
|
|
46336
46466
|
return;
|
|
46337
|
-
const buf =
|
|
46467
|
+
const buf = fs5.readFileSync(abs);
|
|
46338
46468
|
return buf.length > RULE_LIMITS.bytes || buf.includes(0) ? undefined : buf.toString("utf8");
|
|
46339
46469
|
} catch {
|
|
46340
46470
|
return;
|
|
@@ -46342,14 +46472,14 @@ function readBounded(root, realRoot, rel) {
|
|
|
46342
46472
|
}
|
|
46343
46473
|
function gitList(root) {
|
|
46344
46474
|
try {
|
|
46345
|
-
if (
|
|
46475
|
+
if (!insideWorkTree(root))
|
|
46346
46476
|
return null;
|
|
46347
46477
|
} catch {
|
|
46348
46478
|
return null;
|
|
46349
46479
|
}
|
|
46350
46480
|
try {
|
|
46351
|
-
const
|
|
46352
|
-
return { paths:
|
|
46481
|
+
const paths = listFiles(root, "tracked-and-untracked", { pathspecs: PATHSPECS, max: 16 * 1024 * 1024 });
|
|
46482
|
+
return { paths: paths.filter(isRuleFile), incomplete: null };
|
|
46353
46483
|
} catch {
|
|
46354
46484
|
return { paths: [], incomplete: "git could not list the files" };
|
|
46355
46485
|
}
|
|
@@ -46363,14 +46493,14 @@ function walk(root) {
|
|
|
46363
46493
|
const visit2 = (rel, depth) => {
|
|
46364
46494
|
if (stopped)
|
|
46365
46495
|
return;
|
|
46366
|
-
let
|
|
46496
|
+
let list2;
|
|
46367
46497
|
try {
|
|
46368
|
-
|
|
46498
|
+
list2 = fs5.readdirSync(path5.join(root, rel), { withFileTypes: true });
|
|
46369
46499
|
} catch {
|
|
46370
46500
|
unread++;
|
|
46371
46501
|
return;
|
|
46372
46502
|
}
|
|
46373
|
-
for (const d of
|
|
46503
|
+
for (const d of list2) {
|
|
46374
46504
|
if (++entries > RULE_LIMITS.entries) {
|
|
46375
46505
|
stopped = true;
|
|
46376
46506
|
return;
|
|
@@ -46414,34 +46544,34 @@ var KEY = /^[a-z0-9][a-z0-9._/-]{0,63}$/;
|
|
|
46414
46544
|
var FIELD_NAME = /^[a-z][a-z0-9_]{0,39}$/;
|
|
46415
46545
|
var SOURCE_REF = /^s[1-9][0-9]{0,15}$/;
|
|
46416
46546
|
var MAINTAINERS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
46417
|
-
var
|
|
46547
|
+
var text2 = (max) => exports_external.string().trim().min(1).max(max);
|
|
46418
46548
|
var Quote = exports_external.object({ source: exports_external.string().regex(SOURCE_REF, "cite a source ref such as s12"), quote: exports_external.string() }).strict();
|
|
46419
46549
|
var Evidence = Quote.extend({
|
|
46420
46550
|
role: exports_external.enum(EVIDENCE_ROLES).exclude(["reconsiders"]),
|
|
46421
|
-
reported_speaker:
|
|
46551
|
+
reported_speaker: text2(100).optional()
|
|
46422
46552
|
}).strict();
|
|
46423
46553
|
var Unit = exports_external.object({
|
|
46424
46554
|
key: exports_external.string().regex(KEY, "use lowercase letters, digits, and . _ - / (at most 64)"),
|
|
46425
46555
|
kind: exports_external.enum(UNIT_KINDS),
|
|
46426
46556
|
stance: exports_external.enum(STANCES).optional(),
|
|
46427
|
-
text:
|
|
46428
|
-
why:
|
|
46429
|
-
scope_note:
|
|
46430
|
-
revisit_when:
|
|
46431
|
-
no_code_surface:
|
|
46557
|
+
text: text2(2000),
|
|
46558
|
+
why: text2(2000).optional(),
|
|
46559
|
+
scope_note: text2(1000).optional(),
|
|
46560
|
+
revisit_when: text2(1000).optional(),
|
|
46561
|
+
no_code_surface: text2(500).optional(),
|
|
46432
46562
|
options: exports_external.array(exports_external.object({
|
|
46433
|
-
text:
|
|
46563
|
+
text: text2(500),
|
|
46434
46564
|
outcome: exports_external.enum(OPTION_OUTCOMES),
|
|
46435
|
-
why:
|
|
46436
|
-
reconsider_when:
|
|
46565
|
+
why: text2(2000).optional(),
|
|
46566
|
+
reconsider_when: text2(1000).optional(),
|
|
46437
46567
|
reconsider_quote: Quote.optional(),
|
|
46438
46568
|
evidence: exports_external.array(Evidence.partial({ role: true })).max(10).default([])
|
|
46439
46569
|
}).strict()).max(12).default([]),
|
|
46440
46570
|
evidence: exports_external.array(Evidence).max(20).default([]),
|
|
46441
46571
|
adoption: exports_external.array(Quote).max(5).default([]),
|
|
46442
46572
|
anchors: exports_external.array(exports_external.object({
|
|
46443
|
-
path:
|
|
46444
|
-
symbol:
|
|
46573
|
+
path: text2(500),
|
|
46574
|
+
symbol: text2(200).optional(),
|
|
46445
46575
|
role: exports_external.enum(["applies_to", "evidence"]),
|
|
46446
46576
|
commit: exports_external.string().regex(/^[0-9a-f]{40}$/, "a full 40-character commit sha").optional(),
|
|
46447
46577
|
lines: exports_external.tuple([exports_external.number().int().positive(), exports_external.number().int().positive()]).optional()
|
|
@@ -46451,25 +46581,25 @@ var Unit = exports_external.object({
|
|
|
46451
46581
|
conflicts: exports_external.array(exports_external.string().min(1)).max(5).default([]),
|
|
46452
46582
|
fields: exports_external.array(exports_external.object({
|
|
46453
46583
|
name: exports_external.string().regex(FIELD_NAME, "a defined field name"),
|
|
46454
|
-
value:
|
|
46584
|
+
value: text2(200),
|
|
46455
46585
|
quote: Quote
|
|
46456
46586
|
}).strict()).max(12).default([])
|
|
46457
46587
|
}).strict();
|
|
46458
46588
|
var FieldDef = exports_external.object({
|
|
46459
46589
|
name: exports_external.string().regex(FIELD_NAME, "a lowercase letter, then lowercase letters, digits, and _ (at most 40)"),
|
|
46460
46590
|
type: exports_external.enum(FIELD_TYPES),
|
|
46461
|
-
label:
|
|
46462
|
-
description:
|
|
46463
|
-
enum: exports_external.array(
|
|
46591
|
+
label: text2(100),
|
|
46592
|
+
description: text2(500),
|
|
46593
|
+
enum: exports_external.array(text2(100)).min(1).max(30).optional(),
|
|
46464
46594
|
kinds: exports_external.array(exports_external.enum(UNIT_KINDS)).max(UNIT_KINDS.length).default([]),
|
|
46465
46595
|
quote: Quote
|
|
46466
46596
|
}).strict();
|
|
46467
46597
|
var Work = exports_external.object({
|
|
46468
46598
|
key: exports_external.string().regex(KEY),
|
|
46469
|
-
title:
|
|
46470
|
-
goal:
|
|
46471
|
-
current:
|
|
46472
|
-
next: exports_external.array(
|
|
46599
|
+
title: text2(200),
|
|
46600
|
+
goal: text2(1000),
|
|
46601
|
+
current: text2(2000),
|
|
46602
|
+
next: exports_external.array(text2(500)).max(10).default([]),
|
|
46473
46603
|
status: exports_external.enum(WORK_STATUSES)
|
|
46474
46604
|
}).strict();
|
|
46475
46605
|
var Record = exports_external.object({
|
|
@@ -46498,8 +46628,8 @@ var strong = (matched, of) => matched * 2 > of;
|
|
|
46498
46628
|
var PATH_REFUSED = "path must be relative to the repository root, such as src/x.ts: absolute paths, .., backslashes, and empty parts are refused";
|
|
46499
46629
|
async function searchUnits(db, projectId, q) {
|
|
46500
46630
|
const wanted = queryTerms(q.question);
|
|
46501
|
-
const
|
|
46502
|
-
if (
|
|
46631
|
+
const path6 = q.path === undefined ? undefined : repoPath(q.path);
|
|
46632
|
+
if (path6 === null)
|
|
46503
46633
|
return { hits: [], weaker: 0, terms: wanted, stopped: false, read: 0, refused: PATH_REFUSED };
|
|
46504
46634
|
const match = ftsQuery(q.question);
|
|
46505
46635
|
if (!match)
|
|
@@ -46509,8 +46639,8 @@ async function searchUnits(db, projectId, q) {
|
|
|
46509
46639
|
query = query.where("u.kind", "in", q.kinds);
|
|
46510
46640
|
if (q.lifecycles?.length)
|
|
46511
46641
|
query = query.where("u.lifecycle", "in", q.lifecycles);
|
|
46512
|
-
if (
|
|
46513
|
-
query = query.where(({ exists, selectFrom }) => exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.path", "=",
|
|
46642
|
+
if (path6)
|
|
46643
|
+
query = query.where(({ exists, selectFrom }) => exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.path", "=", path6).where("a.retired_at", "is", null)));
|
|
46514
46644
|
const ranked = await query.select(["u.id", "f.rank"]).orderBy("f.rank").orderBy("u.id").limit(UNIT_SCAN_MAX + 1).execute();
|
|
46515
46645
|
const stopped = ranked.length > UNIT_SCAN_MAX;
|
|
46516
46646
|
let weaker = 0;
|
|
@@ -46849,7 +46979,7 @@ function framed(body) {
|
|
|
46849
46979
|
|
|
46850
46980
|
// server/src/read.ts
|
|
46851
46981
|
var UNSUPPORTED = "unsupported: its owner quote was retracted or forgotten, so it is not the owner's condition";
|
|
46852
|
-
var cut = (
|
|
46982
|
+
var cut = (text3, start, end) => Buffer.from(text3, "utf8").subarray(start, end).toString("utf8");
|
|
46853
46983
|
var speaker = (s) => s.author_kind === "owner" ? "the owner" : s.author_kind === "assistant" ? "the assistant" : `${s.author_login ?? "someone"} (${s.author_association ?? s.author_kind})`;
|
|
46854
46984
|
async function unitView(db, projectId, ref, root, asOf, renames) {
|
|
46855
46985
|
const byId = /^u([1-9][0-9]{0,15})$/.exec(ref);
|
|
@@ -47001,7 +47131,8 @@ async function describe3(db, u, root, asOf, renames) {
|
|
|
47001
47131
|
for (const a of live) {
|
|
47002
47132
|
const c = checkAnchor(root, a);
|
|
47003
47133
|
const where = inline(`${a.path}${a.symbol ? ` ${a.symbol}` : ""}`);
|
|
47004
|
-
|
|
47134
|
+
const moved = c.state === "missing" ? await movedTo(root, a, renames, used) : "";
|
|
47135
|
+
out.push(` - ${where} (${a.role}${a.commit_sha ? `, commit ${a.commit_sha.slice(0, 12)}` : ""}): ${c.state}${c.line ? ` at line ${c.line}` : ""}${c.state === "missing" ? ` — needs review: the code it points at is gone${moved}` : ""}`);
|
|
47005
47136
|
}
|
|
47006
47137
|
}
|
|
47007
47138
|
const retired = anchors.filter((a) => a.retired_at);
|
|
@@ -47071,7 +47202,7 @@ async function replacements(db, id, links, asOf) {
|
|
|
47071
47202
|
}
|
|
47072
47203
|
return out;
|
|
47073
47204
|
}
|
|
47074
|
-
function movedTo(root, a, renames, used) {
|
|
47205
|
+
async function movedTo(root, a, renames, used) {
|
|
47075
47206
|
if (!root || !a.commit_sha || fileState(root, a.path) !== "gone")
|
|
47076
47207
|
return "";
|
|
47077
47208
|
if (!used.has(a.commit_sha)) {
|
|
@@ -47080,7 +47211,7 @@ function movedTo(root, a, renames, used) {
|
|
|
47080
47211
|
used.add(a.commit_sha);
|
|
47081
47212
|
}
|
|
47082
47213
|
if (!renames.has(a.commit_sha))
|
|
47083
|
-
renames.set(a.commit_sha, renamesSince(root, a.commit_sha));
|
|
47214
|
+
renames.set(a.commit_sha, await renamesSince(root, a.commit_sha));
|
|
47084
47215
|
const seen = renames.get(a.commit_sha);
|
|
47085
47216
|
if (!seen)
|
|
47086
47217
|
return "; rename not checked";
|
|
@@ -47104,12 +47235,12 @@ function boundary(all, at) {
|
|
|
47104
47235
|
var CONTROL_SEQUENCE = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]?/;
|
|
47105
47236
|
var HIDDEN = new RegExp(`${STRING_SEQUENCE.source}|${CONTROL_SEQUENCE.source}`, "g");
|
|
47106
47237
|
function sequences(all) {
|
|
47107
|
-
const
|
|
47238
|
+
const text3 = all.toString("utf8");
|
|
47108
47239
|
const out = [];
|
|
47109
47240
|
let index = 0;
|
|
47110
47241
|
let at = 0;
|
|
47111
|
-
for (const m of
|
|
47112
|
-
at += bytes(
|
|
47242
|
+
for (const m of text3.matchAll(HIDDEN)) {
|
|
47243
|
+
at += bytes(text3.slice(index, m.index));
|
|
47113
47244
|
index = m.index + m[0].length;
|
|
47114
47245
|
if (plain(m[0]) === "")
|
|
47115
47246
|
out.push([at, at + bytes(m[0])]);
|
|
@@ -47184,12 +47315,12 @@ async function readRefs(db, projectId, refs, root) {
|
|
|
47184
47315
|
let end = inside ? inside[0] > from ? inside[0] : inside[1] : cut2;
|
|
47185
47316
|
if (bytes(plain(all.subarray(from, end).toString("utf8"))) > Math.max(room, 0))
|
|
47186
47317
|
end = cut2;
|
|
47187
|
-
const
|
|
47188
|
-
if (!
|
|
47318
|
+
const text3 = all.subarray(from, end).toString("utf8");
|
|
47319
|
+
if (!text3) {
|
|
47189
47320
|
next = refs.slice(i);
|
|
47190
47321
|
break;
|
|
47191
47322
|
}
|
|
47192
|
-
shown.push(`${plain(p.head)}${plain(
|
|
47323
|
+
shown.push(`${plain(p.head)}${plain(text3)}${note(all.length - end, end)}`);
|
|
47193
47324
|
used += sep + bytes(shown.at(-1) ?? "");
|
|
47194
47325
|
next = [p.resume(end), ...rest];
|
|
47195
47326
|
break;
|
|
@@ -47228,11 +47359,11 @@ var BEFORE_KEY = /[A-Za-z0-9_./:-]/;
|
|
|
47228
47359
|
var AFTER_KEY = /[A-Za-z0-9_/-]/;
|
|
47229
47360
|
var KEY_AFTER_DOT = /[A-Za-z0-9_./-]/;
|
|
47230
47361
|
var QUESTION2 = /:ask:.*:q:/s;
|
|
47231
|
-
function namesKey(
|
|
47232
|
-
for (let i =
|
|
47233
|
-
const before =
|
|
47234
|
-
const after =
|
|
47235
|
-
const next =
|
|
47362
|
+
function namesKey(text3, key) {
|
|
47363
|
+
for (let i = text3.indexOf(key);i !== -1 && key; i = text3.indexOf(key, i + 1)) {
|
|
47364
|
+
const before = text3[i - 1];
|
|
47365
|
+
const after = text3[i + key.length];
|
|
47366
|
+
const next = text3[i + key.length + 1];
|
|
47236
47367
|
const goesOn = after !== undefined && (AFTER_KEY.test(after) || after === "." && next !== undefined && KEY_AFTER_DOT.test(next));
|
|
47237
47368
|
if ((before === undefined || !BEFORE_KEY.test(before)) && !goesOn)
|
|
47238
47369
|
return true;
|
|
@@ -47271,11 +47402,11 @@ async function deliveryOverview(db, projectId, days, now = new Date) {
|
|
|
47271
47402
|
const via = top.length ? await delivered().where("du.unit_id", "in", top.map((t) => t.id)).select(["du.unit_id", "d.event"]).distinct().orderBy("d.event").execute() : [];
|
|
47272
47403
|
const shown = await Promise.all(recent.map(async (r) => {
|
|
47273
47404
|
const rows = keyed().where("d.session_id", "=", r.id);
|
|
47274
|
-
const [
|
|
47405
|
+
const [list2, n] = await Promise.all([
|
|
47275
47406
|
rows.select(["d.id", "d.at", "d.event", "d.agent_id", "d.reason", "d.path"]).orderBy("d.at").orderBy("d.id").limit(DELIVERY_LIMITS.deliveries).execute(),
|
|
47276
47407
|
rows.select((eb) => eb.fn.countAll().as("n")).executeTakeFirst()
|
|
47277
47408
|
]);
|
|
47278
|
-
return { session: r, list, total: Number(n?.n ?? 0) };
|
|
47409
|
+
return { session: r, list: list2, total: Number(n?.n ?? 0) };
|
|
47279
47410
|
}));
|
|
47280
47411
|
const ids = shown.flatMap((s) => s.list.map((d) => d.id));
|
|
47281
47412
|
const keys = ids.length ? await db.selectFrom("delivery_unit as du").innerJoin("unit as u", "u.id", "du.unit_id").where("du.delivery_id", "in", ids).select(["du.delivery_id", "u.id", "u.key"]).orderBy("du.delivery_id").orderBy("u.id").execute() : [];
|
|
@@ -47399,8 +47530,8 @@ function deliveryLine(d, units, namedLater) {
|
|
|
47399
47530
|
}
|
|
47400
47531
|
|
|
47401
47532
|
// server/src/export.ts
|
|
47402
|
-
import
|
|
47403
|
-
import
|
|
47533
|
+
import fs6 from "node:fs";
|
|
47534
|
+
import path6 from "node:path";
|
|
47404
47535
|
var EXPORT_LIMITS = { records: 50, depth: 20, bytes: 60 * 1024 };
|
|
47405
47536
|
async function chosen(db, projectId, ref) {
|
|
47406
47537
|
const byId = /^u([1-9][0-9]{0,15})$/.exec(ref);
|
|
@@ -47483,14 +47614,14 @@ async function lines(db, u) {
|
|
|
47483
47614
|
return out;
|
|
47484
47615
|
}
|
|
47485
47616
|
function fenced(body) {
|
|
47486
|
-
const
|
|
47617
|
+
const text3 = body.join(`
|
|
47487
47618
|
`);
|
|
47488
47619
|
let longest = 0;
|
|
47489
|
-
for (const m of
|
|
47620
|
+
for (const m of text3.matchAll(/`+/g))
|
|
47490
47621
|
longest = Math.max(longest, m[0].length);
|
|
47491
47622
|
const fence = "`".repeat(Math.max(3, longest + 1));
|
|
47492
47623
|
return `${fence}text
|
|
47493
|
-
${
|
|
47624
|
+
${text3}
|
|
47494
47625
|
${fence}`;
|
|
47495
47626
|
}
|
|
47496
47627
|
async function replaced(db, from) {
|
|
@@ -47562,8 +47693,8 @@ ${problems.join(`
|
|
|
47562
47693
|
}
|
|
47563
47694
|
const read = [...units, ...chains.flat().map((c) => c.unit)];
|
|
47564
47695
|
const now = await db.selectFrom("unit").select(["id", "revision"]).where("id", "in", read.map((u) => u.id)).execute();
|
|
47565
|
-
const
|
|
47566
|
-
if (read.some((u) =>
|
|
47696
|
+
const revision2 = new Map(now.map((u) => [u.id, u.revision]));
|
|
47697
|
+
if (read.some((u) => revision2.get(u.id) !== u.revision))
|
|
47567
47698
|
return { error: "Nothing was exported: records changed while the export read them. Export again." };
|
|
47568
47699
|
const document = `${parts.join(`
|
|
47569
47700
|
|
|
@@ -47576,22 +47707,22 @@ ${problems.join(`
|
|
|
47576
47707
|
function exportPath(root, given) {
|
|
47577
47708
|
if (inline(given) !== given || given.includes("\x00"))
|
|
47578
47709
|
return { error: "The path has characters that cannot be shown as typed; use plain characters." };
|
|
47579
|
-
if (
|
|
47710
|
+
if (path6.isAbsolute(given) || path6.win32.isAbsolute(given))
|
|
47580
47711
|
return { error: "Give a path relative to the repository root." };
|
|
47581
47712
|
if (given.split(/[\\/]/).some((p) => p !== "." && p !== ".." && /[. ]$/.test(p)))
|
|
47582
47713
|
return { error: "A name on the path ends with a dot or a space; drop it." };
|
|
47583
47714
|
if (!/\.md$/i.test(given))
|
|
47584
47715
|
return { error: "Give a Markdown file, ending in .md." };
|
|
47585
|
-
const target =
|
|
47716
|
+
const target = path6.resolve(root, given);
|
|
47586
47717
|
const inside = (base, p) => {
|
|
47587
|
-
const r =
|
|
47588
|
-
return r !== "" && r !== ".." && !r.startsWith(`..${
|
|
47718
|
+
const r = path6.relative(base, p);
|
|
47719
|
+
return r !== "" && r !== ".." && !r.startsWith(`..${path6.sep}`) && !path6.isAbsolute(r);
|
|
47589
47720
|
};
|
|
47590
47721
|
if (!inside(root, target))
|
|
47591
47722
|
return { error: "The path leaves the repository." };
|
|
47592
47723
|
const at = (p) => {
|
|
47593
47724
|
try {
|
|
47594
|
-
return
|
|
47725
|
+
return fs6.lstatSync(p);
|
|
47595
47726
|
} catch {
|
|
47596
47727
|
return null;
|
|
47597
47728
|
}
|
|
@@ -47605,17 +47736,17 @@ function exportPath(root, given) {
|
|
|
47605
47736
|
return {
|
|
47606
47737
|
error: "The file has more than one name (a hard link), so writing it could change a file elsewhere."
|
|
47607
47738
|
};
|
|
47608
|
-
let existing =
|
|
47609
|
-
const rest = [
|
|
47739
|
+
let existing = path6.dirname(target);
|
|
47740
|
+
const rest = [path6.basename(target)];
|
|
47610
47741
|
let found = at(existing);
|
|
47611
47742
|
while (!found) {
|
|
47612
|
-
rest.unshift(
|
|
47613
|
-
existing =
|
|
47743
|
+
rest.unshift(path6.basename(existing));
|
|
47744
|
+
existing = path6.dirname(existing);
|
|
47614
47745
|
found = at(existing);
|
|
47615
47746
|
}
|
|
47616
47747
|
let folder;
|
|
47617
47748
|
try {
|
|
47618
|
-
folder =
|
|
47749
|
+
folder = fs6.statSync(existing).isDirectory();
|
|
47619
47750
|
} catch {
|
|
47620
47751
|
folder = false;
|
|
47621
47752
|
}
|
|
@@ -47623,21 +47754,21 @@ function exportPath(root, given) {
|
|
|
47623
47754
|
return { error: "A part of the path is a file, not a folder." };
|
|
47624
47755
|
let real;
|
|
47625
47756
|
try {
|
|
47626
|
-
real = self ?
|
|
47757
|
+
real = self ? fs6.realpathSync.native(target) : path6.join(fs6.realpathSync.native(existing), ...rest);
|
|
47627
47758
|
} catch {
|
|
47628
47759
|
return { error: "A folder on the path cannot be resolved." };
|
|
47629
47760
|
}
|
|
47630
|
-
const rootReal =
|
|
47761
|
+
const rootReal = fs6.realpathSync.native(root);
|
|
47631
47762
|
if (!inside(rootReal, real))
|
|
47632
47763
|
return { error: "The path leads outside the repository." };
|
|
47633
47764
|
const inGit = (relative) => relative.toLowerCase().split(/[\\/]/).includes(".git");
|
|
47634
|
-
if (inGit(
|
|
47765
|
+
if (inGit(path6.relative(root, target)) || inGit(path6.relative(rootReal, real)))
|
|
47635
47766
|
return { error: "The path is inside Git's own folder." };
|
|
47636
|
-
if (instructionFile(
|
|
47767
|
+
if (instructionFile(path6.relative(root, target)) || instructionFile(path6.relative(rootReal, real)))
|
|
47637
47768
|
return {
|
|
47638
47769
|
error: "The path is a file agents load as instructions (CLAUDE.md, AGENTS.md, .github/copilot-instructions.md, or under .claude, .agents, .codex, .cursor)."
|
|
47639
47770
|
};
|
|
47640
|
-
return { relative:
|
|
47771
|
+
return { relative: path6.relative(root, target).split(path6.sep).join("/"), exists: Boolean(self) };
|
|
47641
47772
|
}
|
|
47642
47773
|
var exportReply = (where, document) => `Write to ${where.relative}, ${where.exists ? "replacing an existing file (show the owner its content first)" : "a new file"}. The rest of this reply, from the next line to the end, is the whole file, unchanged.
|
|
47643
47774
|
${document}`;
|
|
@@ -47688,7 +47819,7 @@ async function fieldsText(db, projectId) {
|
|
|
47688
47819
|
}
|
|
47689
47820
|
|
|
47690
47821
|
// server/src/overview.ts
|
|
47691
|
-
import
|
|
47822
|
+
import path7 from "node:path";
|
|
47692
47823
|
var OVERVIEW_LIMITS = { records: 50, key: 200, text: 300, paths: 520, heading: 120 };
|
|
47693
47824
|
var PROJECT_WIDE = "Project-wide (no code location)";
|
|
47694
47825
|
function pathList(paths) {
|
|
@@ -47717,7 +47848,7 @@ async function liveOverview(db, projectId, after) {
|
|
|
47717
47848
|
for (const r of rows.slice(0, OVERVIEW_LIMITS.records)) {
|
|
47718
47849
|
const paths = [...new Set(anchors.filter((a) => a.unit_id === r.id).map((a) => a.path))];
|
|
47719
47850
|
const first = paths[0];
|
|
47720
|
-
const dir = first === undefined ? null :
|
|
47851
|
+
const dir = first === undefined ? null : path7.posix.dirname(first);
|
|
47721
47852
|
const line = `- ${head(inline(r.key), OVERVIEW_LIMITS.key)} (u${r.id}, ${r.kind}${r.stance ? ` ${r.stance}` : ""}${whose.get(r.id) === "agent" ? ", decided by an AI" : ""}): ${head(inline(r.text), OVERVIEW_LIMITS.text)}${paths.length ? ` [${pathList(paths)}]` : ""}`;
|
|
47722
47853
|
shown.push({
|
|
47723
47854
|
id: r.id,
|
|
@@ -47880,8 +48011,8 @@ async function lookOverview(db, projectId, root, after) {
|
|
|
47880
48011
|
const todo = [];
|
|
47881
48012
|
for (const f of scan.files) {
|
|
47882
48013
|
const same = resume !== null && pathHash(f.path) === resume.file;
|
|
47883
|
-
for (const [i,
|
|
47884
|
-
for (const [n, m] of [...
|
|
48014
|
+
for (const [i, text3] of f.text.split(/\r?\n/).entries())
|
|
48015
|
+
for (const [n, m] of [...text3.matchAll(MARKER)].entries())
|
|
47885
48016
|
if (!same || i + 1 > resume.line || i + 1 === resume.line && n > resume.n)
|
|
47886
48017
|
todo.push({ file: f.path, line: i + 1, n, key: m[1] ?? "" });
|
|
47887
48018
|
}
|
|
@@ -47965,11 +48096,10 @@ async function successor(db, id) {
|
|
|
47965
48096
|
}
|
|
47966
48097
|
|
|
47967
48098
|
// server/src/project.ts
|
|
47968
|
-
import
|
|
47969
|
-
import
|
|
47970
|
-
import path7 from "node:path";
|
|
48099
|
+
import fs7 from "node:fs";
|
|
48100
|
+
import path8 from "node:path";
|
|
47971
48101
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
47972
|
-
var localFile = () =>
|
|
48102
|
+
var localFile = () => path8.join(sphicaHome(), "projects.json");
|
|
47973
48103
|
var LOCAL_KEY = /^[a-z0-9][a-z0-9._-]*$/;
|
|
47974
48104
|
function legacyRemote(url2) {
|
|
47975
48105
|
const raw = String(url2 ?? "").trim();
|
|
@@ -47997,21 +48127,18 @@ function normalizeKey(key) {
|
|
|
47997
48127
|
const host = fold(cut2 < 0 ? rest : rest.slice(0, cut2));
|
|
47998
48128
|
return host === "github.com" ? fold(key) : `git:${host}${cut2 < 0 ? "" : rest.slice(cut2)}`;
|
|
47999
48129
|
}
|
|
48000
|
-
var
|
|
48130
|
+
var ask = (fn) => {
|
|
48001
48131
|
try {
|
|
48002
|
-
return
|
|
48003
|
-
encoding: "utf8",
|
|
48004
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
48005
|
-
timeout: 5000
|
|
48006
|
-
}).trim();
|
|
48132
|
+
return fn() || null;
|
|
48007
48133
|
} catch {
|
|
48008
48134
|
return null;
|
|
48009
48135
|
}
|
|
48010
48136
|
};
|
|
48137
|
+
var top = (dir) => ask(() => topLevel(dir, { timeout: 5000 }));
|
|
48011
48138
|
function localMap() {
|
|
48012
48139
|
let raw;
|
|
48013
48140
|
try {
|
|
48014
|
-
raw =
|
|
48141
|
+
raw = fs7.readFileSync(localFile(), "utf8");
|
|
48015
48142
|
} catch (e) {
|
|
48016
48143
|
if (e.code === "ENOENT")
|
|
48017
48144
|
return {};
|
|
@@ -48023,26 +48150,26 @@ function localMap() {
|
|
|
48023
48150
|
} catch {
|
|
48024
48151
|
m = null;
|
|
48025
48152
|
}
|
|
48026
|
-
if (!m || typeof m !== "object" || Array.isArray(m) || Object.entries(m).some(([root, name]) => !
|
|
48153
|
+
if (!m || typeof m !== "object" || Array.isArray(m) || Object.entries(m).some(([root, name]) => !path8.isAbsolute(root) || typeof name !== "string" || !LOCAL_KEY.test(name)))
|
|
48027
48154
|
throw new Error(`${localFile()} is not a valid JSON project table. Fix or delete it, then name the project again.`);
|
|
48028
48155
|
return m;
|
|
48029
48156
|
}
|
|
48030
48157
|
function identify(dir) {
|
|
48031
|
-
const given =
|
|
48032
|
-
const
|
|
48033
|
-
const root =
|
|
48034
|
-
const legacy =
|
|
48158
|
+
const given = path8.resolve(dir);
|
|
48159
|
+
const found = top(given);
|
|
48160
|
+
const root = found || given;
|
|
48161
|
+
const legacy = found ? legacyRemote(ask(() => originUrl(root, { timeout: 5000 }))) : null;
|
|
48035
48162
|
if (legacy) {
|
|
48036
48163
|
const key = normalizeKey(`git:${legacy}`);
|
|
48037
48164
|
const remote = key.slice(4);
|
|
48038
48165
|
return { key, legacyKey: `git:${legacy}`, root, name: remote.split("/").slice(1).join("/") || remote };
|
|
48039
48166
|
}
|
|
48040
48167
|
const map3 = localMap();
|
|
48041
|
-
for (let d = root;; d =
|
|
48168
|
+
for (let d = root;; d = path8.dirname(d)) {
|
|
48042
48169
|
const local = map3[d];
|
|
48043
48170
|
if (local && LOCAL_KEY.test(local))
|
|
48044
48171
|
return { key: `local:${local}`, legacyKey: `local:${local}`, root: d, name: local };
|
|
48045
|
-
if (
|
|
48172
|
+
if (found || path8.dirname(d) === d)
|
|
48046
48173
|
return null;
|
|
48047
48174
|
}
|
|
48048
48175
|
}
|
|
@@ -48089,13 +48216,13 @@ function gitPath(token, prefix) {
|
|
|
48089
48216
|
}
|
|
48090
48217
|
return prefix && out.startsWith(prefix) ? out.slice(prefix.length) : out;
|
|
48091
48218
|
}
|
|
48092
|
-
function parseDiff(
|
|
48219
|
+
function parseDiff(text3) {
|
|
48093
48220
|
const files = [];
|
|
48094
|
-
const at = (
|
|
48095
|
-
const found = files.find((f2) => f2.path ===
|
|
48221
|
+
const at = (path9) => {
|
|
48222
|
+
const found = files.find((f2) => f2.path === path9);
|
|
48096
48223
|
if (found)
|
|
48097
48224
|
return found;
|
|
48098
|
-
const f = { path:
|
|
48225
|
+
const f = { path: path9, added: [], lines: [] };
|
|
48099
48226
|
files.push(f);
|
|
48100
48227
|
return f;
|
|
48101
48228
|
};
|
|
@@ -48109,7 +48236,7 @@ function parseDiff(text2) {
|
|
|
48109
48236
|
at(block);
|
|
48110
48237
|
block = null;
|
|
48111
48238
|
};
|
|
48112
|
-
const rows =
|
|
48239
|
+
const rows = text3.split(/\r?\n/);
|
|
48113
48240
|
for (const [i, raw] of rows.entries()) {
|
|
48114
48241
|
if (cur && (oldLeft > 0 || newLeft > 0)) {
|
|
48115
48242
|
if (raw.startsWith("+")) {
|
|
@@ -48246,20 +48373,20 @@ async function selectedText(db, hits, room) {
|
|
|
48246
48373
|
`);
|
|
48247
48374
|
const each = Math.floor((room - bytes(join(hits.map((u) => line(u, NONE2))))) / Math.max(1, hits.length));
|
|
48248
48375
|
if (each >= LEAST) {
|
|
48249
|
-
const
|
|
48376
|
+
const text3 = join(hits.map((u) => {
|
|
48250
48377
|
const t = Math.min(SHOWN.text, Math.floor(each / 2));
|
|
48251
48378
|
const rest = each - t;
|
|
48252
48379
|
const two = "option" in u.why || u.why.symbol;
|
|
48253
|
-
const
|
|
48380
|
+
const path9 = Math.min(SHOWN.path, two ? Math.floor(rest / 2) : rest);
|
|
48254
48381
|
return line(u, {
|
|
48255
48382
|
text: t,
|
|
48256
|
-
path:
|
|
48257
|
-
symbol: Math.min(SHOWN.symbol, rest -
|
|
48258
|
-
option: Math.min(SHOWN.option, rest -
|
|
48383
|
+
path: path9,
|
|
48384
|
+
symbol: Math.min(SHOWN.symbol, rest - path9),
|
|
48385
|
+
option: Math.min(SHOWN.option, rest - path9)
|
|
48259
48386
|
});
|
|
48260
48387
|
}));
|
|
48261
|
-
if (bytes(
|
|
48262
|
-
return { text:
|
|
48388
|
+
if (bytes(text3) <= room)
|
|
48389
|
+
return { text: text3, byId: false };
|
|
48263
48390
|
}
|
|
48264
48391
|
return {
|
|
48265
48392
|
text: join(hits.map((u) => `- u${u.id}${marked(u) ? ` (${marked(u).slice(2)})` : ""}`)),
|
|
@@ -48450,7 +48577,7 @@ ${framed(c.work.map((w) => `- ${head(inline(w.title), 200)} (${w.status}): ${hea
|
|
|
48450
48577
|
requireRuntime();
|
|
48451
48578
|
var db = openReader();
|
|
48452
48579
|
var VERSION = versionAt(ROOT);
|
|
48453
|
-
var
|
|
48580
|
+
var text3 = (t, isError = false) => ({
|
|
48454
48581
|
content: [{ type: "text", text: t }],
|
|
48455
48582
|
...isError ? { isError: true } : {}
|
|
48456
48583
|
});
|
|
@@ -48491,10 +48618,10 @@ server.registerTool("status", {
|
|
|
48491
48618
|
try {
|
|
48492
48619
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48493
48620
|
if (typeof p === "string")
|
|
48494
|
-
return
|
|
48495
|
-
return
|
|
48621
|
+
return text3(p);
|
|
48622
|
+
return text3(await status(db, p.id, head(inline(p.name), 200)));
|
|
48496
48623
|
} catch (e) {
|
|
48497
|
-
return
|
|
48624
|
+
return text3(`Sphica unavailable: ${head(reason(e), 300)}`, true);
|
|
48498
48625
|
}
|
|
48499
48626
|
});
|
|
48500
48627
|
server.registerTool("search", {
|
|
@@ -48516,11 +48643,11 @@ server.registerTool("search", {
|
|
|
48516
48643
|
try {
|
|
48517
48644
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48518
48645
|
if (typeof p === "string")
|
|
48519
|
-
return
|
|
48646
|
+
return text3(p);
|
|
48520
48647
|
const limit = a.limit ?? 8;
|
|
48521
48648
|
if (a.asked) {
|
|
48522
48649
|
if (a.sources || a.path !== undefined)
|
|
48523
|
-
return
|
|
48650
|
+
return text3("asked cannot be combined with sources or path.");
|
|
48524
48651
|
const external2 = [a.session, process.env.CLAUDE_CODE_SESSION_ID, process.env.CODEX_THREAD_ID].filter((x) => !!x);
|
|
48525
48652
|
const r2 = await askedBefore(db, p.id, {
|
|
48526
48653
|
question: a.query,
|
|
@@ -48531,16 +48658,16 @@ server.registerTool("search", {
|
|
|
48531
48658
|
});
|
|
48532
48659
|
const known = external2.length > 0;
|
|
48533
48660
|
if (!r2.messages.length)
|
|
48534
|
-
return
|
|
48535
|
-
return
|
|
48661
|
+
return text3(`No ${known ? "earlier " : ""}owner message ${r2.stopped ? `among the first ${r2.read} candidates by rank ` : ""}holds most of: ${r2.terms.join(", ") || "(no searchable words)"}. ${r2.weaker} weaker matches left out.${r2.stopped ? " Search with more specific words." : ""}${known ? "" : ` ${UNKNOWN_SESSION}`}`);
|
|
48662
|
+
return text3(framed(askedText(r2, known)));
|
|
48536
48663
|
}
|
|
48537
48664
|
if (a.sources) {
|
|
48538
48665
|
if (a.path !== undefined)
|
|
48539
|
-
return
|
|
48666
|
+
return text3("sources cannot be combined with path.", true);
|
|
48540
48667
|
const r2 = await searchSources(db, p.id, a.query, limit);
|
|
48541
48668
|
if (!r2.hits.length)
|
|
48542
|
-
return
|
|
48543
|
-
return
|
|
48669
|
+
return text3(`No source ${among(r2)}holds most of: ${r2.terms.join(", ") || "(no searchable words)"}. ${r2.weaker} weaker matches left out.${r2.stopped ? " Search with more specific words." : ""}`);
|
|
48670
|
+
return text3(framed(r2.hits.map((h) => `## s${h.id}: ${h.kind} ${h.artifact}, ${h.author}, ${h.created_at}
|
|
48544
48671
|
${head(h.text, 800)}
|
|
48545
48672
|
Matched: ${h.matched.join(", ")}`).join(`
|
|
48546
48673
|
|
|
@@ -48554,14 +48681,14 @@ Matched: ${h.matched.join(", ")}`).join(`
|
|
|
48554
48681
|
limit
|
|
48555
48682
|
});
|
|
48556
48683
|
if (r.refused)
|
|
48557
|
-
return
|
|
48684
|
+
return text3(`Nothing was searched: ${r.refused}`, true);
|
|
48558
48685
|
if (!r.hits.length)
|
|
48559
|
-
return
|
|
48560
|
-
return
|
|
48686
|
+
return text3(`No record ${among(r)}holds most of: ${r.terms.join(", ") || "(no searchable words)"}. ${r.weaker} weaker matches left out. ` + (r.stopped ? "Search with more specific words. " : "") + "Search again with other words or the other language, or search sources; status says whether sessions are still untraced.");
|
|
48687
|
+
return text3(framed(`${hitsText(r.hits)}${stoppedAfter(r)}
|
|
48561
48688
|
|
|
48562
48689
|
Read a record by its key before relying on it.`));
|
|
48563
48690
|
} catch (e) {
|
|
48564
|
-
return
|
|
48691
|
+
return text3(`Sphica unavailable: ${head(reason(e), 300)}`, true);
|
|
48565
48692
|
}
|
|
48566
48693
|
});
|
|
48567
48694
|
server.registerTool("read", {
|
|
@@ -48576,10 +48703,10 @@ server.registerTool("read", {
|
|
|
48576
48703
|
try {
|
|
48577
48704
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48578
48705
|
if (typeof p === "string")
|
|
48579
|
-
return
|
|
48580
|
-
return
|
|
48706
|
+
return text3(p);
|
|
48707
|
+
return text3(await readRefs(db, p.id, a.refs, p.root));
|
|
48581
48708
|
} catch (e) {
|
|
48582
|
-
return
|
|
48709
|
+
return text3(`Sphica unavailable: ${head(reason(e), 300)}`, true);
|
|
48583
48710
|
}
|
|
48584
48711
|
});
|
|
48585
48712
|
server.registerTool("export", {
|
|
@@ -48595,16 +48722,16 @@ server.registerTool("export", {
|
|
|
48595
48722
|
try {
|
|
48596
48723
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48597
48724
|
if (typeof p === "string")
|
|
48598
|
-
return
|
|
48725
|
+
return text3(`Nothing was exported: ${p}`, true);
|
|
48599
48726
|
const where = exportPath(p.root, a.path);
|
|
48600
48727
|
if ("error" in where)
|
|
48601
|
-
return
|
|
48728
|
+
return text3(`Nothing was exported: ${where.error}`, true);
|
|
48602
48729
|
const built = await exportDecisions(db, p.id, p.name, a.records);
|
|
48603
48730
|
if ("error" in built)
|
|
48604
|
-
return
|
|
48605
|
-
return
|
|
48731
|
+
return text3(built.error, true);
|
|
48732
|
+
return text3(exportReply(where, built.document));
|
|
48606
48733
|
} catch (e) {
|
|
48607
|
-
return
|
|
48734
|
+
return text3(`Sphica unavailable: ${head(reason(e), 300)}`, true);
|
|
48608
48735
|
}
|
|
48609
48736
|
});
|
|
48610
48737
|
server.registerTool("fields", {
|
|
@@ -48616,14 +48743,14 @@ server.registerTool("fields", {
|
|
|
48616
48743
|
try {
|
|
48617
48744
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48618
48745
|
if (typeof p === "string")
|
|
48619
|
-
return
|
|
48620
|
-
return
|
|
48746
|
+
return text3(p, true);
|
|
48747
|
+
return text3(await fieldsText(db, p.id));
|
|
48621
48748
|
} catch (e) {
|
|
48622
|
-
return
|
|
48749
|
+
return text3(`Sphica unavailable: ${head(reason(e), 300)}`, true);
|
|
48623
48750
|
}
|
|
48624
48751
|
});
|
|
48625
48752
|
var DIFF = exports_external.string().min(1).max(2000000).describe("The change under review as a unified diff (git diff output)");
|
|
48626
|
-
var notChecked = (e) =>
|
|
48753
|
+
var notChecked = (e) => text3(`Decision lane: not checked. Sphica unavailable: ${head(reason(e), 300)}. Report the decision check as not run, not as passed.`, true);
|
|
48627
48754
|
server.registerTool("overview", {
|
|
48628
48755
|
title: "Live decisions, records that need a look, and what Sphica showed",
|
|
48629
48756
|
description: "On request, not before every change. view live lists every active decision and constraint of the project, grouped by the directory it " + "applies to, a page at a time (pass after from the previous page). view look lists live records whose code file is gone or whose symbol " + "is not found, written conditions for reconsidering an option (for you to judge, never applied), and lines in CLAUDE.md, AGENTS.md, or " + ".claude/rules marked <!-- sphica: key --> whose record was replaced or withdrawn, a page at a time until one says Complete (pass the after it gives). " + "view delivery shows what Sphica's hooks showed the agent over the last days (default 7): logged rows by event, the records delivered most, " + "and example sessions; use it when the user asks what Sphica has been showing. " + "Read a record by its key before relying on it.",
|
|
@@ -48636,22 +48763,22 @@ server.registerTool("overview", {
|
|
|
48636
48763
|
annotations: READ_ONLY
|
|
48637
48764
|
}, async (a, extra) => {
|
|
48638
48765
|
if (a.view !== "delivery" && a.days !== undefined)
|
|
48639
|
-
return
|
|
48766
|
+
return text3("days: only with view delivery", true);
|
|
48640
48767
|
if (a.view === "delivery" && a.after !== undefined)
|
|
48641
|
-
return
|
|
48768
|
+
return text3("after: not with view delivery, which is one page", true);
|
|
48642
48769
|
if (a.view === "live" && typeof a.after === "string")
|
|
48643
|
-
return
|
|
48770
|
+
return text3("after: with view live, pass the id the previous page gave", true);
|
|
48644
48771
|
if (a.view === "look" && typeof a.after === "number")
|
|
48645
|
-
return
|
|
48772
|
+
return text3("after: with view look, pass the cursor the previous page gave, as it is", true);
|
|
48646
48773
|
if (typeof a.after === "string" && !lookCursor(a.after))
|
|
48647
|
-
return
|
|
48774
|
+
return text3("after: not a cursor a look page gave; call look without after to start again", true);
|
|
48648
48775
|
try {
|
|
48649
48776
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48650
48777
|
if (typeof p === "string")
|
|
48651
|
-
return
|
|
48652
|
-
return
|
|
48778
|
+
return text3(p);
|
|
48779
|
+
return text3(framed(a.view === "delivery" ? await deliveryOverview(db, p.id, a.days ?? DELIVERY_DAYS.default) : typeof a.after === "string" || a.view === "look" ? await lookOverview(db, p.id, p.root, typeof a.after === "string" ? a.after : undefined) : await liveOverview(db, p.id, a.after ?? null)));
|
|
48653
48780
|
} catch (e) {
|
|
48654
|
-
return
|
|
48781
|
+
return text3(`Sphica unavailable: ${head(reason(e), 300)}`, true);
|
|
48655
48782
|
}
|
|
48656
48783
|
});
|
|
48657
48784
|
server.registerTool("review_select", {
|
|
@@ -48671,12 +48798,12 @@ server.registerTool("review_select", {
|
|
|
48671
48798
|
const files = parseDiff(a.diff);
|
|
48672
48799
|
const b = await reviewBatch(db, p.id, files, a.after ?? null, a.diff);
|
|
48673
48800
|
if (!b.all.length)
|
|
48674
|
-
return
|
|
48801
|
+
return text3(`Decision lane: checked. No active record applies to the ${files.length} changed files.`);
|
|
48675
48802
|
if (!b.aligned)
|
|
48676
|
-
return
|
|
48803
|
+
return text3(`Decision lane: not checked. after ${a.after} is not where a batch ended: pass the after a batch gave, or none for the first batch.`, true);
|
|
48677
48804
|
if (!b.records.length)
|
|
48678
|
-
return
|
|
48679
|
-
return
|
|
48805
|
+
return text3(`Decision lane: checked. No record after id ${a.after}: ${b.all.length} records apply in all (selection ${b.selection}).`);
|
|
48806
|
+
return text3(await selectReply(db, b, a.after ?? null));
|
|
48680
48807
|
} catch (e) {
|
|
48681
48808
|
return notChecked(e);
|
|
48682
48809
|
}
|
|
@@ -48697,7 +48824,7 @@ server.registerTool("review_check", {
|
|
|
48697
48824
|
const p = await projectOf(a.cwd, extra._meta);
|
|
48698
48825
|
if (typeof p === "string")
|
|
48699
48826
|
return notChecked(new Error(p));
|
|
48700
|
-
return
|
|
48827
|
+
return text3(checkedText(await checkFindings(db, p.id, parseDiff(a.diff), a.findings, {
|
|
48701
48828
|
after: a.after ?? null,
|
|
48702
48829
|
selection: a.selection,
|
|
48703
48830
|
diff: a.diff
|