sphica 0.6.48 → 0.6.49
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 +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +2 -1
- package/dist/capture.js +14 -9
- package/dist/cli.js +39 -9
- package/dist/deliver.js +42 -16
- package/dist/git-worker.js +43 -16
- package/dist/mcp-record.js +14 -9
- package/dist/mcp.js +1710 -1539
- package/package.json +1 -1
- package/skills/export/SKILL.md +3 -1
- package/skills/fields/SKILL.md +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "sphica",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.49",
|
|
5
5
|
"description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "iroha924",
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ The database is a single SQLite file on your machine.
|
|
|
31
31
|
- **See what is live, and what needs a look.** Ask for the overview: `view: "live"` lists every active decision and constraint by the directory it applies to; `view: "look"` lists records whose file is gone or whose symbol is not found, conditions you said would bring a rejected option back, and lines in your instruction files whose record was replaced. Nothing is expired or changed on its own.
|
|
32
32
|
- **See what Sphica showed your agent.** Ask what Sphica has been showing: `view: "delivery"` (with `days`, 1 to 90, 7 by default) counts the deliveries the hooks logged by event and by main agent or subagent, lists the records shown most, and gives recent sessions with each record's key, so you can judge whether each helped. It says what the log leaves out, and marks a record "named later" only when a later reply wrote its key.
|
|
33
33
|
- **Track your own fields on records (trial).** Say in a session which extra field to keep on records (the affected tenant, a p95 figure); trace then saves a value only when the conversation writes it, with the quote. `/sphica:fields` shows each field and how many records carry a value.
|
|
34
|
-
- **Share decisions as a file.** `/sphica:export` writes the live decisions you pick, with the words quoted for them and the older decisions they replaced, to a Markdown file in your repository for people who do not run Sphica. You see the whole file before it is written, and it is never committed for you.
|
|
34
|
+
- **Share decisions as a file.** `/sphica:export` writes the live decisions you pick, with the words quoted for them and the older decisions they replaced, to a Markdown file in your repository for people who do not run Sphica. You see the whole file before it is written, and it is never committed for you. One file holds about 29 KB, what a single reply to the agent carries whole; more decisions go into several files.
|
|
35
35
|
- **Rule text from records.** `/sphica:rules` drafts lines for CLAUDE.md, AGENTS.md, or `.claude/rules` from the constraints and decisions you pick, each marked with its record key so the overview flags it once the record changes. It never edits the file.
|
|
36
36
|
- **Reviews check past decisions.** `/sphica:review` runs a reviewer per focus (correctness, security, written conventions, and past decisions by default; redundancy with `full`), and checks the diff against the records it touches.
|
|
37
37
|
|
|
@@ -200,6 +200,7 @@ Run `sphica doctor` first. It shows which part is out of date or not working. Co
|
|
|
200
200
|
- **The MCP servers report an older version.** Restart the session, or run `/reload-plugins` in Claude Code.
|
|
201
201
|
- **A search finds nothing.** Search matches words. Try other words, the other language, an identifier, or fewer words. Ask the agent to check `status`: sessions not traced yet are searchable only as captured text.
|
|
202
202
|
- **`doctor` says the full-text index is broken.** Run `sphica doctor --reindex`.
|
|
203
|
+
- **A review says Sphica's git worker would not start, or `doctor` shows it under `Git worker`.** Sphica reads your working tree with git in a folder of its own, `.sphica/git` under your home directory, and refuses to when that folder overlaps the temp directory or the working tree itself (an agent in a sandbox can write there), or is a link. `sphica doctor`, run inside the repository, says which. Until it is fixed, the check before a review cannot read your local change.
|
|
203
204
|
|
|
204
205
|
## Commands
|
|
205
206
|
|
package/dist/capture.js
CHANGED
|
@@ -11159,7 +11159,7 @@ var commitDiffNames = (root, a, b, limits) => list(text(root, ["diff", ...DIFF_O
|
|
|
11159
11159
|
var originUrl = (root, limits) => text(root, ["remote", "get-url", "origin"], limits).trim();
|
|
11160
11160
|
async function worktreeStatus(root, deadline) {
|
|
11161
11161
|
const out = await inIsolation(root, [{ kind: "status" }], { deadline, max: 16 * 1024 * 1024 });
|
|
11162
|
-
return out
|
|
11162
|
+
return Array.isArray(out) ? out[0] ?? null : null;
|
|
11163
11163
|
}
|
|
11164
11164
|
function workerFile() {
|
|
11165
11165
|
const js = path.join(import.meta.dirname, "git-worker.js");
|
|
@@ -11176,7 +11176,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
11176
11176
|
detached: process.platform !== "win32"
|
|
11177
11177
|
});
|
|
11178
11178
|
} catch {
|
|
11179
|
-
resolve(
|
|
11179
|
+
resolve({ unread: "failed" });
|
|
11180
11180
|
return;
|
|
11181
11181
|
}
|
|
11182
11182
|
const chunks = [];
|
|
@@ -11187,7 +11187,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
11187
11187
|
return;
|
|
11188
11188
|
done = true;
|
|
11189
11189
|
clearTimeout(timer);
|
|
11190
|
-
if (out
|
|
11190
|
+
if (!Array.isArray(out)) {
|
|
11191
11191
|
try {
|
|
11192
11192
|
if (process.platform !== "win32" && child.pid)
|
|
11193
11193
|
process.kill(-child.pid, "SIGKILL");
|
|
@@ -11202,25 +11202,30 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
11202
11202
|
}
|
|
11203
11203
|
resolve(out);
|
|
11204
11204
|
};
|
|
11205
|
-
const timer = setTimeout(() => finish(
|
|
11205
|
+
const timer = setTimeout(() => finish({ unread: "timeout" }), deadline);
|
|
11206
11206
|
const cap = 6 * max * Math.max(1, ops.length * 2) + 64 * 1024;
|
|
11207
11207
|
child.stdout?.on("data", (c) => {
|
|
11208
11208
|
size += c.length;
|
|
11209
11209
|
if (size > cap)
|
|
11210
|
-
finish(
|
|
11210
|
+
finish({ unread: "too_large" });
|
|
11211
11211
|
else
|
|
11212
11212
|
chunks.push(c);
|
|
11213
11213
|
});
|
|
11214
|
-
child.on("error", () => finish(
|
|
11214
|
+
child.on("error", () => finish({ unread: "failed" }));
|
|
11215
11215
|
child.on("close", () => {
|
|
11216
11216
|
try {
|
|
11217
11217
|
const result = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
11218
|
-
|
|
11218
|
+
if (result.ok)
|
|
11219
|
+
finish(result.out);
|
|
11220
|
+
else if ("refused" in result)
|
|
11221
|
+
finish({ unread: "refused", code: result.refused });
|
|
11222
|
+
else
|
|
11223
|
+
finish({ unread: result.failed });
|
|
11219
11224
|
} catch {
|
|
11220
|
-
finish(
|
|
11225
|
+
finish({ unread: "failed" });
|
|
11221
11226
|
}
|
|
11222
11227
|
});
|
|
11223
|
-
child.stdin?.on("error", () => finish(
|
|
11228
|
+
child.stdin?.on("error", () => finish({ unread: "failed" }));
|
|
11224
11229
|
child.stdin?.end(JSON.stringify({
|
|
11225
11230
|
root,
|
|
11226
11231
|
ops,
|
package/dist/cli.js
CHANGED
|
@@ -93,6 +93,7 @@ var require_src = __commonJS(function(exports, module) {
|
|
|
93
93
|
|
|
94
94
|
// server/src/cli.ts
|
|
95
95
|
import fs11 from "node:fs";
|
|
96
|
+
import os4 from "node:os";
|
|
96
97
|
import path11 from "node:path";
|
|
97
98
|
|
|
98
99
|
// server/node_modules/@clack/core/dist/index.mjs
|
|
@@ -4193,12 +4194,26 @@ function listFiles(root, kind, { pathspecs = [], ...limits } = {}) {
|
|
|
4193
4194
|
var originUrl = (root, limits) => text(root, ["remote", "get-url", "origin"], limits).trim();
|
|
4194
4195
|
async function worktreeStatus(root, deadline) {
|
|
4195
4196
|
const out = await inIsolation(root, [{ kind: "status" }], { deadline, max: 16 * 1024 * 1024 });
|
|
4196
|
-
return out
|
|
4197
|
+
return Array.isArray(out) ? out[0] ?? null : null;
|
|
4197
4198
|
}
|
|
4198
4199
|
function workerFile() {
|
|
4199
4200
|
const js = path2.join(import.meta.dirname, "git-worker.js");
|
|
4200
4201
|
return fs2.existsSync(js) ? js : path2.join(import.meta.dirname, "git-worker.ts");
|
|
4201
4202
|
}
|
|
4203
|
+
function refusalText(code) {
|
|
4204
|
+
const folder = "Sphica's git folder (.sphica/git under your home directory)";
|
|
4205
|
+
return {
|
|
4206
|
+
hooks_not_empty: `the hooks folder inside ${folder}, which Sphica keeps empty, holds files`,
|
|
4207
|
+
not_plain_dir: "one of Sphica's folders under your home directory (.sphica, .sphica/git, or .sphica/git/hooks) is a link or not a directory",
|
|
4208
|
+
outside_home: `${folder} leads out of your home directory`,
|
|
4209
|
+
overlaps_worktree: `${folder} overlaps this work tree, which an agent can write`,
|
|
4210
|
+
overlaps_tmp: `${folder} overlaps the temp directory, which an agent can write`
|
|
4211
|
+
}[code];
|
|
4212
|
+
}
|
|
4213
|
+
async function workerPlace(root, deadline = 5000) {
|
|
4214
|
+
const out = await inIsolation(root, [{ kind: "place" }], { deadline, max: 1024 });
|
|
4215
|
+
return Array.isArray(out) ? "ready" : out;
|
|
4216
|
+
}
|
|
4202
4217
|
function inIsolation(root, ops, { deadline, max }) {
|
|
4203
4218
|
return new Promise((resolve) => {
|
|
4204
4219
|
let child;
|
|
@@ -4210,7 +4225,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
4210
4225
|
detached: process.platform !== "win32"
|
|
4211
4226
|
});
|
|
4212
4227
|
} catch {
|
|
4213
|
-
resolve(
|
|
4228
|
+
resolve({ unread: "failed" });
|
|
4214
4229
|
return;
|
|
4215
4230
|
}
|
|
4216
4231
|
const chunks = [];
|
|
@@ -4221,7 +4236,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
4221
4236
|
return;
|
|
4222
4237
|
done = true;
|
|
4223
4238
|
clearTimeout(timer);
|
|
4224
|
-
if (out
|
|
4239
|
+
if (!Array.isArray(out)) {
|
|
4225
4240
|
try {
|
|
4226
4241
|
if (process.platform !== "win32" && child.pid)
|
|
4227
4242
|
process.kill(-child.pid, "SIGKILL");
|
|
@@ -4236,25 +4251,30 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
4236
4251
|
}
|
|
4237
4252
|
resolve(out);
|
|
4238
4253
|
};
|
|
4239
|
-
const timer = setTimeout(() => finish(
|
|
4254
|
+
const timer = setTimeout(() => finish({ unread: "timeout" }), deadline);
|
|
4240
4255
|
const cap = 6 * max * Math.max(1, ops.length * 2) + 64 * 1024;
|
|
4241
4256
|
child.stdout?.on("data", (c) => {
|
|
4242
4257
|
size += c.length;
|
|
4243
4258
|
if (size > cap)
|
|
4244
|
-
finish(
|
|
4259
|
+
finish({ unread: "too_large" });
|
|
4245
4260
|
else
|
|
4246
4261
|
chunks.push(c);
|
|
4247
4262
|
});
|
|
4248
|
-
child.on("error", () => finish(
|
|
4263
|
+
child.on("error", () => finish({ unread: "failed" }));
|
|
4249
4264
|
child.on("close", () => {
|
|
4250
4265
|
try {
|
|
4251
4266
|
const result = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
4252
|
-
|
|
4267
|
+
if (result.ok)
|
|
4268
|
+
finish(result.out);
|
|
4269
|
+
else if ("refused" in result)
|
|
4270
|
+
finish({ unread: "refused", code: result.refused });
|
|
4271
|
+
else
|
|
4272
|
+
finish({ unread: result.failed });
|
|
4253
4273
|
} catch {
|
|
4254
|
-
finish(
|
|
4274
|
+
finish({ unread: "failed" });
|
|
4255
4275
|
}
|
|
4256
4276
|
});
|
|
4257
|
-
child.stdin?.on("error", () => finish(
|
|
4277
|
+
child.stdin?.on("error", () => finish({ unread: "failed" }));
|
|
4258
4278
|
child.stdin?.end(JSON.stringify({
|
|
4259
4279
|
root,
|
|
4260
4280
|
ops,
|
|
@@ -19195,6 +19215,16 @@ async function doctor(cwd) {
|
|
|
19195
19215
|
runtime = false;
|
|
19196
19216
|
say2("fail", "Node", plain(reason(e)));
|
|
19197
19217
|
}
|
|
19218
|
+
const tree = fs11.lstatSync(path11.join(os4.homedir(), ".sphica"), { throwIfNoEntry: false }) ? repositoryRoot(cwd) : null;
|
|
19219
|
+
if (tree) {
|
|
19220
|
+
const place = await workerPlace(tree);
|
|
19221
|
+
if (place === "ready")
|
|
19222
|
+
say2("ok", "Git worker", "ready");
|
|
19223
|
+
else if (place.unread === "refused")
|
|
19224
|
+
say2("warn", "Git worker", `would not start: ${refusalText(place.code)}. Reviews cannot read this work tree until that changes`);
|
|
19225
|
+
else
|
|
19226
|
+
say2("warn", "Git worker", place.unread === "timeout" ? "did not answer in time" : "could not be started");
|
|
19227
|
+
}
|
|
19198
19228
|
const file = dbFile();
|
|
19199
19229
|
let usable2 = false;
|
|
19200
19230
|
if (!runtime)
|
package/dist/deliver.js
CHANGED
|
@@ -11474,16 +11474,32 @@ function listFiles(root, kind, { pathspecs = [], ...limits } = {}) {
|
|
|
11474
11474
|
var originUrl = (root, limits) => text(root, ["remote", "get-url", "origin"], limits).trim();
|
|
11475
11475
|
async function worktreeStatus(root, deadline) {
|
|
11476
11476
|
const out = await inIsolation(root, [{ kind: "status" }], { deadline, max: 16 * 1024 * 1024 });
|
|
11477
|
-
return out
|
|
11477
|
+
return Array.isArray(out) ? out[0] ?? null : null;
|
|
11478
11478
|
}
|
|
11479
11479
|
async function worktreeDiff(root, from, { max, deadline }) {
|
|
11480
11480
|
const out = await inIsolation(root, [{ kind: "diff", from: objectId(from) }], { deadline, max });
|
|
11481
|
-
|
|
11481
|
+
if (!Array.isArray(out))
|
|
11482
|
+
return out;
|
|
11483
|
+
return out.length === 2 ? { patch: out[0] ?? "", names: list(out[1] ?? "") } : { unread: "failed" };
|
|
11482
11484
|
}
|
|
11483
11485
|
function workerFile() {
|
|
11484
11486
|
const js = path2.join(import.meta.dirname, "git-worker.js");
|
|
11485
11487
|
return fs.existsSync(js) ? js : path2.join(import.meta.dirname, "git-worker.ts");
|
|
11486
11488
|
}
|
|
11489
|
+
function unreadOf(e) {
|
|
11490
|
+
const code = e?.code;
|
|
11491
|
+
return { unread: code === "ETIMEDOUT" ? "timeout" : code === "ENOBUFS" ? "too_large" : "failed" };
|
|
11492
|
+
}
|
|
11493
|
+
function refusalText(code) {
|
|
11494
|
+
const folder = "Sphica's git folder (.sphica/git under your home directory)";
|
|
11495
|
+
return {
|
|
11496
|
+
hooks_not_empty: `the hooks folder inside ${folder}, which Sphica keeps empty, holds files`,
|
|
11497
|
+
not_plain_dir: "one of Sphica's folders under your home directory (.sphica, .sphica/git, or .sphica/git/hooks) is a link or not a directory",
|
|
11498
|
+
outside_home: `${folder} leads out of your home directory`,
|
|
11499
|
+
overlaps_worktree: `${folder} overlaps this work tree, which an agent can write`,
|
|
11500
|
+
overlaps_tmp: `${folder} overlaps the temp directory, which an agent can write`
|
|
11501
|
+
}[code];
|
|
11502
|
+
}
|
|
11487
11503
|
function inIsolation(root, ops, { deadline, max }) {
|
|
11488
11504
|
return new Promise((resolve) => {
|
|
11489
11505
|
let child;
|
|
@@ -11495,7 +11511,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
11495
11511
|
detached: process.platform !== "win32"
|
|
11496
11512
|
});
|
|
11497
11513
|
} catch {
|
|
11498
|
-
resolve(
|
|
11514
|
+
resolve({ unread: "failed" });
|
|
11499
11515
|
return;
|
|
11500
11516
|
}
|
|
11501
11517
|
const chunks = [];
|
|
@@ -11506,7 +11522,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
11506
11522
|
return;
|
|
11507
11523
|
done = true;
|
|
11508
11524
|
clearTimeout(timer);
|
|
11509
|
-
if (out
|
|
11525
|
+
if (!Array.isArray(out)) {
|
|
11510
11526
|
try {
|
|
11511
11527
|
if (process.platform !== "win32" && child.pid)
|
|
11512
11528
|
process.kill(-child.pid, "SIGKILL");
|
|
@@ -11521,25 +11537,30 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
11521
11537
|
}
|
|
11522
11538
|
resolve(out);
|
|
11523
11539
|
};
|
|
11524
|
-
const timer = setTimeout(() => finish(
|
|
11540
|
+
const timer = setTimeout(() => finish({ unread: "timeout" }), deadline);
|
|
11525
11541
|
const cap = 6 * max * Math.max(1, ops.length * 2) + 64 * 1024;
|
|
11526
11542
|
child.stdout?.on("data", (c) => {
|
|
11527
11543
|
size += c.length;
|
|
11528
11544
|
if (size > cap)
|
|
11529
|
-
finish(
|
|
11545
|
+
finish({ unread: "too_large" });
|
|
11530
11546
|
else
|
|
11531
11547
|
chunks.push(c);
|
|
11532
11548
|
});
|
|
11533
|
-
child.on("error", () => finish(
|
|
11549
|
+
child.on("error", () => finish({ unread: "failed" }));
|
|
11534
11550
|
child.on("close", () => {
|
|
11535
11551
|
try {
|
|
11536
11552
|
const result = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
11537
|
-
|
|
11553
|
+
if (result.ok)
|
|
11554
|
+
finish(result.out);
|
|
11555
|
+
else if ("refused" in result)
|
|
11556
|
+
finish({ unread: "refused", code: result.refused });
|
|
11557
|
+
else
|
|
11558
|
+
finish({ unread: result.failed });
|
|
11538
11559
|
} catch {
|
|
11539
|
-
finish(
|
|
11560
|
+
finish({ unread: "failed" });
|
|
11540
11561
|
}
|
|
11541
11562
|
});
|
|
11542
|
-
child.stdin?.on("error", () => finish(
|
|
11563
|
+
child.stdin?.on("error", () => finish({ unread: "failed" }));
|
|
11543
11564
|
child.stdin?.end(JSON.stringify({
|
|
11544
11565
|
root,
|
|
11545
11566
|
ops,
|
|
@@ -13144,6 +13165,13 @@ function reviewCall(input) {
|
|
|
13144
13165
|
return null;
|
|
13145
13166
|
return { name, args: typeof args === "string" ? args.slice(0, 1000) : "" };
|
|
13146
13167
|
}
|
|
13168
|
+
function unreadText(why) {
|
|
13169
|
+
if (why.unread === "refused")
|
|
13170
|
+
return `Sphica's git worker would not start, because ${refusalText(why.code)} (run sphica doctor in this work tree)`;
|
|
13171
|
+
if (why.unread === "failed")
|
|
13172
|
+
return "the change could not be read (git failed or could not be started)";
|
|
13173
|
+
return "the change could not be read in time, or is too large to read (over 4 MB of diff or file names)";
|
|
13174
|
+
}
|
|
13147
13175
|
async function localChange(root, args) {
|
|
13148
13176
|
if (/^\s*#?\d+\s*$|(^|\s)#\d+\b|\/pull\/\d+/.test(args))
|
|
13149
13177
|
return { problem: "it names a pull request, and Sphica sees only the local change" };
|
|
@@ -13166,15 +13194,13 @@ async function localChange(root, args) {
|
|
|
13166
13194
|
return { problem: `HEAD shares no history with ${base}` };
|
|
13167
13195
|
}
|
|
13168
13196
|
const got = await worktreeDiff(root, from, { max: MAX_DIFF, deadline: left() });
|
|
13197
|
+
if ("unread" in got)
|
|
13198
|
+
return { problem: unreadText(got) };
|
|
13169
13199
|
let untracked;
|
|
13170
13200
|
try {
|
|
13171
|
-
if (!got)
|
|
13172
|
-
throw new Error("no diff");
|
|
13173
13201
|
untracked = listFiles(root, "untracked", { max: MAX_DIFF, timeout: left() });
|
|
13174
|
-
} catch {
|
|
13175
|
-
return {
|
|
13176
|
-
problem: "the change could not be read in time, or is too large to read (over 4 MB of diff or file names)"
|
|
13177
|
-
};
|
|
13202
|
+
} catch (e) {
|
|
13203
|
+
return { problem: unreadText(unreadOf(e)) };
|
|
13178
13204
|
}
|
|
13179
13205
|
const { patch: diff, names } = got;
|
|
13180
13206
|
const files = parseDiff(diff);
|
package/dist/git-worker.js
CHANGED
|
@@ -104,6 +104,13 @@ function configGet(root, key, limits) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// server/src/git-worker.ts
|
|
107
|
+
class Refused extends Error {
|
|
108
|
+
code;
|
|
109
|
+
constructor(code) {
|
|
110
|
+
super(code);
|
|
111
|
+
this.code = code;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
107
114
|
var INDEX_LIMIT = 256 * 1024 * 1024;
|
|
108
115
|
var FILE_LIMIT = 1024 * 1024;
|
|
109
116
|
var STALE_MS = 60 * 60 * 1000;
|
|
@@ -114,11 +121,13 @@ var inside = (root, p) => {
|
|
|
114
121
|
var overlap = (a, b) => inside(a, b) || inside(b, a);
|
|
115
122
|
function ownDir(parent, name) {
|
|
116
123
|
const dir = path2.join(parent, name);
|
|
117
|
-
|
|
124
|
+
let st = fs2.lstatSync(dir, { throwIfNoEntry: false });
|
|
125
|
+
if (!st) {
|
|
118
126
|
fs2.mkdirSync(dir, { mode: 448 });
|
|
119
|
-
|
|
127
|
+
st = fs2.lstatSync(dir);
|
|
128
|
+
}
|
|
120
129
|
if (!st.isDirectory() || st.isSymbolicLink())
|
|
121
|
-
throw new
|
|
130
|
+
throw new Refused("not_plain_dir");
|
|
122
131
|
return dir;
|
|
123
132
|
}
|
|
124
133
|
function isolatedHome(root) {
|
|
@@ -126,18 +135,26 @@ function isolatedHome(root) {
|
|
|
126
135
|
const git = ownDir(ownDir(home, ".sphica"), "git");
|
|
127
136
|
const hooks = ownDir(git, "hooks");
|
|
128
137
|
if (fs2.readdirSync(hooks).length)
|
|
129
|
-
throw new
|
|
138
|
+
throw new Refused("hooks_not_empty");
|
|
130
139
|
const iso = fs2.mkdtempSync(path2.join(git, "iso-"));
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
|
|
140
|
+
try {
|
|
141
|
+
const st = fs2.lstatSync(iso);
|
|
142
|
+
if (!st.isDirectory() || st.isSymbolicLink())
|
|
143
|
+
throw new Refused("not_plain_dir");
|
|
144
|
+
const real = fs2.realpathSync(iso);
|
|
145
|
+
if (!inside(home, real) || real !== iso)
|
|
146
|
+
throw new Refused("outside_home");
|
|
147
|
+
for (const [other, code] of [
|
|
148
|
+
[root, "overlaps_worktree"],
|
|
149
|
+
[os2.tmpdir(), "overlaps_tmp"]
|
|
150
|
+
]) {
|
|
151
|
+
const otherReal = fs2.realpathSync(other);
|
|
152
|
+
if (overlap(real, otherReal) || overlap(git, otherReal))
|
|
153
|
+
throw new Refused(code);
|
|
154
|
+
}
|
|
155
|
+
} catch (e) {
|
|
156
|
+
fs2.rmSync(iso, { recursive: true, force: true });
|
|
157
|
+
throw e;
|
|
141
158
|
}
|
|
142
159
|
return { git, iso, hooks };
|
|
143
160
|
}
|
|
@@ -317,8 +334,12 @@ function work(request) {
|
|
|
317
334
|
sweep(git);
|
|
318
335
|
const remaining = () => ({ timeout: Math.max(1, Math.floor(request.until - Date.now())) });
|
|
319
336
|
try {
|
|
337
|
+
if (request.ops.every((op) => op.kind === "place"))
|
|
338
|
+
return { ok: true, out: [] };
|
|
320
339
|
const { env, options } = prepare(request.root, iso, hooks, remaining);
|
|
321
340
|
const out = request.ops.flatMap((op) => {
|
|
341
|
+
if (op.kind === "place")
|
|
342
|
+
return [];
|
|
322
343
|
const run2 = (args) => execFileSync2("git", ["-C", request.root, ...options, ...args], {
|
|
323
344
|
cwd: startDir(),
|
|
324
345
|
env,
|
|
@@ -340,7 +361,13 @@ function work(request) {
|
|
|
340
361
|
fs2.rmSync(iso, { recursive: true, force: true });
|
|
341
362
|
}
|
|
342
363
|
} catch (e) {
|
|
343
|
-
|
|
364
|
+
if (e instanceof Refused)
|
|
365
|
+
return { ok: false, refused: e.code };
|
|
366
|
+
const code = e.code;
|
|
367
|
+
return {
|
|
368
|
+
ok: false,
|
|
369
|
+
failed: code === "ETIMEDOUT" ? "timeout" : code === "ENOBUFS" ? "too_large" : "failed"
|
|
370
|
+
};
|
|
344
371
|
}
|
|
345
372
|
}
|
|
346
373
|
if (process.argv[1] && path2.resolve(process.argv[1]) === path2.resolve(import.meta.filename ?? "")) {
|
|
@@ -351,7 +378,7 @@ if (process.argv[1] && path2.resolve(process.argv[1]) === path2.resolve(import.m
|
|
|
351
378
|
try {
|
|
352
379
|
request = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
353
380
|
} catch {
|
|
354
|
-
process.stdout.write(JSON.stringify({ ok: false,
|
|
381
|
+
process.stdout.write(JSON.stringify({ ok: false, failed: "failed" }));
|
|
355
382
|
return;
|
|
356
383
|
}
|
|
357
384
|
process.stdout.write(JSON.stringify(work(request)));
|
package/dist/mcp-record.js
CHANGED
|
@@ -45929,7 +45929,7 @@ function repoFiles(root) {
|
|
|
45929
45929
|
}
|
|
45930
45930
|
async function worktreeStatus(root, deadline) {
|
|
45931
45931
|
const out = await inIsolation(root, [{ kind: "status" }], { deadline, max: 16 * 1024 * 1024 });
|
|
45932
|
-
return out
|
|
45932
|
+
return Array.isArray(out) ? out[0] ?? null : null;
|
|
45933
45933
|
}
|
|
45934
45934
|
function workerFile() {
|
|
45935
45935
|
const js = path.join(import.meta.dirname, "git-worker.js");
|
|
@@ -45946,7 +45946,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
45946
45946
|
detached: process.platform !== "win32"
|
|
45947
45947
|
});
|
|
45948
45948
|
} catch {
|
|
45949
|
-
resolve(
|
|
45949
|
+
resolve({ unread: "failed" });
|
|
45950
45950
|
return;
|
|
45951
45951
|
}
|
|
45952
45952
|
const chunks = [];
|
|
@@ -45957,7 +45957,7 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
45957
45957
|
return;
|
|
45958
45958
|
done = true;
|
|
45959
45959
|
clearTimeout(timer);
|
|
45960
|
-
if (out
|
|
45960
|
+
if (!Array.isArray(out)) {
|
|
45961
45961
|
try {
|
|
45962
45962
|
if (process.platform !== "win32" && child.pid)
|
|
45963
45963
|
process.kill(-child.pid, "SIGKILL");
|
|
@@ -45972,25 +45972,30 @@ function inIsolation(root, ops, { deadline, max }) {
|
|
|
45972
45972
|
}
|
|
45973
45973
|
resolve(out);
|
|
45974
45974
|
};
|
|
45975
|
-
const timer = setTimeout(() => finish(
|
|
45975
|
+
const timer = setTimeout(() => finish({ unread: "timeout" }), deadline);
|
|
45976
45976
|
const cap = 6 * max * Math.max(1, ops.length * 2) + 64 * 1024;
|
|
45977
45977
|
child.stdout?.on("data", (c) => {
|
|
45978
45978
|
size += c.length;
|
|
45979
45979
|
if (size > cap)
|
|
45980
|
-
finish(
|
|
45980
|
+
finish({ unread: "too_large" });
|
|
45981
45981
|
else
|
|
45982
45982
|
chunks.push(c);
|
|
45983
45983
|
});
|
|
45984
|
-
child.on("error", () => finish(
|
|
45984
|
+
child.on("error", () => finish({ unread: "failed" }));
|
|
45985
45985
|
child.on("close", () => {
|
|
45986
45986
|
try {
|
|
45987
45987
|
const result = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
45988
|
-
|
|
45988
|
+
if (result.ok)
|
|
45989
|
+
finish(result.out);
|
|
45990
|
+
else if ("refused" in result)
|
|
45991
|
+
finish({ unread: "refused", code: result.refused });
|
|
45992
|
+
else
|
|
45993
|
+
finish({ unread: result.failed });
|
|
45989
45994
|
} catch {
|
|
45990
|
-
finish(
|
|
45995
|
+
finish({ unread: "failed" });
|
|
45991
45996
|
}
|
|
45992
45997
|
});
|
|
45993
|
-
child.stdin?.on("error", () => finish(
|
|
45998
|
+
child.stdin?.on("error", () => finish({ unread: "failed" }));
|
|
45994
45999
|
child.stdin?.end(JSON.stringify({
|
|
45995
46000
|
root,
|
|
45996
46001
|
ops,
|