sphica 0.6.46 → 0.6.48
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 +1 -0
- package/dist/cli.js +392 -1
- package/dist/deliver.js +3 -0
- package/dist/mcp-record.js +236 -128
- package/dist/mcp.js +5 -2
- package/package.json +1 -1
- package/skills/glean/SKILL.md +8 -1
- package/skills/harvest/SKILL.md +3 -1
- package/skills/trace/SKILL.md +3 -3
|
@@ -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.48",
|
|
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
|
@@ -207,6 +207,7 @@ Run `sphica doctor` first. It shows which part is out of date or not working. Co
|
|
|
207
207
|
|---|---|
|
|
208
208
|
| `sphica init` | Create the database, bind the GitHub account `gh` is signed in to, and register the current repository |
|
|
209
209
|
| `sphica doctor` | Check versions, the database, recording, and each registered project |
|
|
210
|
+
| `sphica doctor --audit-quotes` | List saved adoptions and reasons that rest on quoted words. It only reads: nothing is changed |
|
|
210
211
|
| `sphica uninstall` | Delete `~/.sphica` and show how to remove the plugin and the CLI |
|
|
211
212
|
|
|
212
213
|
Everything else runs inside Claude Code and Codex, through the `/sphica:*` commands and Sphica's MCP tools.
|
package/dist/cli.js
CHANGED
|
@@ -17540,6 +17540,10 @@ function closing(text2) {
|
|
|
17540
17540
|
return capture((output) => outro(bold(lines.join(`
|
|
17541
17541
|
${" ".repeat(GUIDE)}`)), { output }));
|
|
17542
17542
|
}
|
|
17543
|
+
function document(head2, meta, blocks, end) {
|
|
17544
|
+
return [title2(head2, meta), ...blocks.map(drawBlock), closing(end)].filter((x) => x !== "").join(`
|
|
17545
|
+
`);
|
|
17546
|
+
}
|
|
17543
17547
|
function failure(head2, reason2) {
|
|
17544
17548
|
return [title2(head2), stopped(reason2)].join(`
|
|
17545
17549
|
`);
|
|
@@ -17558,8 +17562,70 @@ function stopped(reason2) {
|
|
|
17558
17562
|
cancel("Stopped", { output });
|
|
17559
17563
|
}).replace(/\n+$/, "");
|
|
17560
17564
|
}
|
|
17565
|
+
var cell = (text2) => oneLine(text2).trim();
|
|
17561
17566
|
var cut = (text2, room) => dist_default2(text2) <= room ? text2 : `${wrapAnsi(text2, Math.max(1, room - 1), { hard: true }).split(`
|
|
17562
17567
|
`)[0]}…`;
|
|
17568
|
+
var padTo = (text2, to) => text2 + " ".repeat(Math.max(0, to - dist_default2(text2)));
|
|
17569
|
+
function drawBlock(b) {
|
|
17570
|
+
const fancy = colored2();
|
|
17571
|
+
const space = fancy ? 1 : 0;
|
|
17572
|
+
switch (b.kind) {
|
|
17573
|
+
case "lines":
|
|
17574
|
+
return content(b.lines, space);
|
|
17575
|
+
case "table": {
|
|
17576
|
+
const rows = [b.head, ...b.rows].map((r2) => r2.map(cell));
|
|
17577
|
+
if (!fancy)
|
|
17578
|
+
return content(rows.map((r2) => r2.join(" ")));
|
|
17579
|
+
const widths = b.head.map((_, i2) => Math.min(40, Math.max(...rows.map((r2) => dist_default2(r2[i2] ?? "")))));
|
|
17580
|
+
const room = columns() - GUIDE;
|
|
17581
|
+
const line = (r2, head2) => {
|
|
17582
|
+
const before = r2.slice(0, -1).map((c, i2) => padTo(cut(c, widths[i2] ?? 0), (widths[i2] ?? 0) + 3));
|
|
17583
|
+
const used = before.reduce((w, c) => w + dist_default2(c), 0);
|
|
17584
|
+
const text2 = before.join("") + cut(r2.at(-1) ?? "", Math.max(1, room - used));
|
|
17585
|
+
return head2 ? dim(text2) : text2;
|
|
17586
|
+
};
|
|
17587
|
+
return capture((output) => log.message(rows.flatMap((r2, i2) => wrapAnsi(line(r2, i2 === 0), room, { hard: true, trim: false }).split(`
|
|
17588
|
+
`)), { output, spacing: space }));
|
|
17589
|
+
}
|
|
17590
|
+
case "cards": {
|
|
17591
|
+
const items = b.items.map((c) => {
|
|
17592
|
+
const badge = c.badge ? fancy ? `${styleText3("inverse", ` ${cell(c.badge)} `)} ` : `[${cell(c.badge)}] ` : "";
|
|
17593
|
+
return [
|
|
17594
|
+
fancy ? `${badge}${bold(cell(c.title))}` : `${badge}${cell(c.title)}`,
|
|
17595
|
+
...c.body ? clean2(c.body).split(`
|
|
17596
|
+
`).map((l) => ` ${l}`) : [],
|
|
17597
|
+
...(c.meta ?? []).map((m) => ` ${fancy ? dim(cell(m)) : cell(m)}`)
|
|
17598
|
+
];
|
|
17599
|
+
});
|
|
17600
|
+
if (!fancy)
|
|
17601
|
+
return content(items.flat());
|
|
17602
|
+
return items.map((lines, i2) => content(lines, i2 === 0 ? space : 1)).join(`
|
|
17603
|
+
`);
|
|
17604
|
+
}
|
|
17605
|
+
case "fields": {
|
|
17606
|
+
const w = Math.max(...b.rows.map(([k]) => dist_default2(cell(k))));
|
|
17607
|
+
return content(b.rows.map(([k, v]) => fancy ? `${dim(padTo(cell(k), w + 3))}${bold(cell(v))}` : `${cell(k)} ${cell(v)}`), space);
|
|
17608
|
+
}
|
|
17609
|
+
case "meter": {
|
|
17610
|
+
if (!fancy)
|
|
17611
|
+
return content([`${cell(b.label)} ${cell(b.text)}`]);
|
|
17612
|
+
const bar = Math.max(8, Math.min(30, columns() - GUIDE - dist_default2(cell(b.label)) - dist_default2(cell(b.text)) - 4));
|
|
17613
|
+
const filled = Math.round(Math.max(0, Math.min(1, b.ratio)) * bar);
|
|
17614
|
+
return content([
|
|
17615
|
+
`${dim(cell(b.label))} ${"█".repeat(filled)}${dim("░".repeat(bar - filled))} ${bold(cell(b.text))}`
|
|
17616
|
+
], space);
|
|
17617
|
+
}
|
|
17618
|
+
case "note": {
|
|
17619
|
+
if (!fancy)
|
|
17620
|
+
return content([cell(b.text)]);
|
|
17621
|
+
const text2 = wrapAnsi(cell(b.text), columns() - GUIDE, { hard: true, trim: true });
|
|
17622
|
+
return capture((output) => {
|
|
17623
|
+
const say = { info: log.info, warning: log.warn, error: log.error, success: log.success }[b.tone];
|
|
17624
|
+
say(text2, { output });
|
|
17625
|
+
});
|
|
17626
|
+
}
|
|
17627
|
+
}
|
|
17628
|
+
}
|
|
17563
17629
|
function steps(heading, items, note) {
|
|
17564
17630
|
const room = columns() - 11;
|
|
17565
17631
|
if (!colored2() || items.some((x) => dist_default2(x.command) > room))
|
|
@@ -18084,6 +18150,304 @@ function inspect(file = dbFile()) {
|
|
|
18084
18150
|
});
|
|
18085
18151
|
}
|
|
18086
18152
|
|
|
18153
|
+
// server/src/own-words.ts
|
|
18154
|
+
var MAINTAINERS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
18155
|
+
var PAIRS = { '"': '"', "“": "”", "‘": "’", "「": "」", "『": "』" };
|
|
18156
|
+
var WORD2 = /[\p{Script=Latin}\p{N}]/u;
|
|
18157
|
+
var charAt = (line, at) => at < line.length ? String.fromCodePoint(line.codePointAt(at)) : "";
|
|
18158
|
+
function endsWord(line, end) {
|
|
18159
|
+
for (let i2 = end;i2 > 0; ) {
|
|
18160
|
+
const low = line.charCodeAt(i2 - 1);
|
|
18161
|
+
const from = low >= 56320 && low <= 57343 && i2 > 1 ? i2 - 2 : i2 - 1;
|
|
18162
|
+
const c = charAt(line, from);
|
|
18163
|
+
if (!/\p{M}/u.test(c))
|
|
18164
|
+
return WORD2.test(c);
|
|
18165
|
+
i2 = from;
|
|
18166
|
+
}
|
|
18167
|
+
return false;
|
|
18168
|
+
}
|
|
18169
|
+
var startsWord = (line, at) => WORD2.test(charAt(line, at + 1));
|
|
18170
|
+
function inlineRanges(line) {
|
|
18171
|
+
const found = [];
|
|
18172
|
+
const closing2 = new Map;
|
|
18173
|
+
const last = new Map;
|
|
18174
|
+
for (let end = line.length;end > 0; ) {
|
|
18175
|
+
if (line[end - 1] !== "`") {
|
|
18176
|
+
end--;
|
|
18177
|
+
continue;
|
|
18178
|
+
}
|
|
18179
|
+
let from = end - 1;
|
|
18180
|
+
while (from > 0 && line[from - 1] === "`")
|
|
18181
|
+
from--;
|
|
18182
|
+
const partner = last.get(end - from);
|
|
18183
|
+
if (partner !== undefined)
|
|
18184
|
+
closing2.set(from, partner);
|
|
18185
|
+
last.set(end - from, from);
|
|
18186
|
+
end = from;
|
|
18187
|
+
}
|
|
18188
|
+
const unpaired = new Set;
|
|
18189
|
+
for (let i2 = 0;i2 < line.length; ) {
|
|
18190
|
+
const c = line[i2];
|
|
18191
|
+
let close = -1;
|
|
18192
|
+
let width2 = 1;
|
|
18193
|
+
if (c === "`")
|
|
18194
|
+
while (line[i2 + width2] === "`")
|
|
18195
|
+
width2++;
|
|
18196
|
+
const mark2 = c === "`" ? c.repeat(width2) : c;
|
|
18197
|
+
if (unpaired.has(mark2)) {
|
|
18198
|
+
i2 += width2;
|
|
18199
|
+
continue;
|
|
18200
|
+
}
|
|
18201
|
+
if (c === "`")
|
|
18202
|
+
close = closing2.get(i2) ?? -1;
|
|
18203
|
+
else if (c === "'") {
|
|
18204
|
+
if (endsWord(line, i2)) {
|
|
18205
|
+
i2++;
|
|
18206
|
+
continue;
|
|
18207
|
+
}
|
|
18208
|
+
for (let j = i2 + 1;j < line.length; j++)
|
|
18209
|
+
if (line[j] === "'" && !startsWord(line, j)) {
|
|
18210
|
+
close = j;
|
|
18211
|
+
break;
|
|
18212
|
+
}
|
|
18213
|
+
} else if (PAIRS[c]) {
|
|
18214
|
+
close = line.indexOf(PAIRS[c], i2 + 1);
|
|
18215
|
+
while (c === "‘" && close >= 0 && startsWord(line, close))
|
|
18216
|
+
close = line.indexOf(PAIRS[c], close + 1);
|
|
18217
|
+
} else {
|
|
18218
|
+
i2++;
|
|
18219
|
+
continue;
|
|
18220
|
+
}
|
|
18221
|
+
if (close < 0) {
|
|
18222
|
+
unpaired.add(mark2);
|
|
18223
|
+
i2 += width2;
|
|
18224
|
+
continue;
|
|
18225
|
+
}
|
|
18226
|
+
found.push([i2, close + width2]);
|
|
18227
|
+
i2 = close + width2;
|
|
18228
|
+
}
|
|
18229
|
+
return found;
|
|
18230
|
+
}
|
|
18231
|
+
var OPENS = /["“'‘`「『]/;
|
|
18232
|
+
var CLOSES = /["”'’`」』]/;
|
|
18233
|
+
function notOwnWords(body, start, end) {
|
|
18234
|
+
const bytes2 = Buffer.from(body, "utf8");
|
|
18235
|
+
let fence = null;
|
|
18236
|
+
let own = "";
|
|
18237
|
+
let quoting = false;
|
|
18238
|
+
let before = "";
|
|
18239
|
+
let after = "";
|
|
18240
|
+
for (let at = 0;at <= bytes2.length; ) {
|
|
18241
|
+
const nl = bytes2.indexOf(10, at);
|
|
18242
|
+
const stop = nl < 0 ? bytes2.length : nl;
|
|
18243
|
+
const raw = bytes2.subarray(at, stop).toString("utf8").replace(/\r$/, "");
|
|
18244
|
+
const line = raw.trimStart();
|
|
18245
|
+
let block2 = fence !== null || line.startsWith(">");
|
|
18246
|
+
if (fence) {
|
|
18247
|
+
const closing2 = /^(`+|~+)\s*$/.exec(line)?.[1];
|
|
18248
|
+
if (closing2 && closing2[0] === fence.mark && closing2.length >= fence.length)
|
|
18249
|
+
fence = null;
|
|
18250
|
+
} else {
|
|
18251
|
+
const opening = /^(`{3,}|~{3,})(.*)$/.exec(line);
|
|
18252
|
+
if (opening && !(opening[1]?.startsWith("`") && opening[2]?.includes("`"))) {
|
|
18253
|
+
fence = { mark: opening[1][0], length: opening[1].length };
|
|
18254
|
+
block2 = true;
|
|
18255
|
+
}
|
|
18256
|
+
}
|
|
18257
|
+
if (at < end && stop > start) {
|
|
18258
|
+
if (block2)
|
|
18259
|
+
return "block";
|
|
18260
|
+
const from = Buffer.from(raw, "utf8").subarray(0, Math.max(start - at, 0)).toString("utf8").length;
|
|
18261
|
+
const to = Buffer.from(raw, "utf8").subarray(0, Math.min(end, stop) - at).toString("utf8").length;
|
|
18262
|
+
if (start >= at)
|
|
18263
|
+
before = raw.slice(0, from).trimEnd().slice(-1);
|
|
18264
|
+
if (end <= stop)
|
|
18265
|
+
after = raw.slice(to).trimStart().slice(0, 1);
|
|
18266
|
+
let cursor3 = from;
|
|
18267
|
+
for (const [a2, b] of inlineRanges(raw)) {
|
|
18268
|
+
if (b <= cursor3 || a2 >= to)
|
|
18269
|
+
continue;
|
|
18270
|
+
quoting = true;
|
|
18271
|
+
own += raw.slice(cursor3, Math.max(a2, cursor3));
|
|
18272
|
+
cursor3 = Math.max(cursor3, b);
|
|
18273
|
+
}
|
|
18274
|
+
own += `${raw.slice(cursor3, Math.max(to, cursor3))}
|
|
18275
|
+
`;
|
|
18276
|
+
}
|
|
18277
|
+
if (nl < 0)
|
|
18278
|
+
break;
|
|
18279
|
+
at = nl + 1;
|
|
18280
|
+
}
|
|
18281
|
+
if (OPENS.test(before) && CLOSES.test(after))
|
|
18282
|
+
return "inline";
|
|
18283
|
+
const span = bytes2.subarray(start, end).toString("utf8").trim();
|
|
18284
|
+
const opens = span.slice(0, 1);
|
|
18285
|
+
const closes = PAIRS[opens] ?? (opens === "'" || opens === "`" ? opens : "");
|
|
18286
|
+
if (closes && span.length > 1 && span.endsWith(closes) && !span.slice(1, -1).includes(closes))
|
|
18287
|
+
return "inline";
|
|
18288
|
+
return !quoting || /\p{L}/u.test(own) ? null : "inline";
|
|
18289
|
+
}
|
|
18290
|
+
|
|
18291
|
+
// server/src/audit-quotes.ts
|
|
18292
|
+
var KINDS = [
|
|
18293
|
+
"adoption",
|
|
18294
|
+
"retraction reason",
|
|
18295
|
+
"reconsider condition",
|
|
18296
|
+
"anchor reason",
|
|
18297
|
+
"field definition"
|
|
18298
|
+
];
|
|
18299
|
+
var REPAIR = {
|
|
18300
|
+
adoption: "if it is not your decision, retract it with glean's retract_adoption, giving your own words as the reason. The adoption stays in the history",
|
|
18301
|
+
"retraction reason": "a retraction cannot be undone, and the same words cannot be added again: add evidence or adoption from other words, or save a successor",
|
|
18302
|
+
"reconsider condition": "retract the condition's quote with glean's retract_evidence, or save a successor with the condition you stated. The retraction takes every piece of the record's evidence that cites the same words: when the record's own evidence does, save a successor instead",
|
|
18303
|
+
"anchor reason": "put the record back where it belongs with glean's anchor or replace_anchor. The retired anchor's row stays",
|
|
18304
|
+
"field definition": "a definition cannot be changed or withdrawn: define the field again under another name, or forget the message, which removes the message and everything that quotes it"
|
|
18305
|
+
};
|
|
18306
|
+
function uncheckedLines(unchecked) {
|
|
18307
|
+
const count = (n2, one, many) => `${n2} ${n2 === 1 ? one : many}`;
|
|
18308
|
+
return [
|
|
18309
|
+
unchecked.links ? `${count(unchecked.links, "link", "links")} from harvest or glean: the words a supersedes or conflicts link rested on are not kept. Read the record's evidence and adoption to judge it` : "",
|
|
18310
|
+
unchecked.withdrawals ? `${count(unchecked.withdrawals, "withdrawal", "withdrawals")}: the reason's message is kept, not its span. A withdrawal cannot be undone: if one was wrong, save the record again under a new key` : "",
|
|
18311
|
+
unchecked.resolutions ? `${count(unchecked.resolutions, "resolved conflict", "resolved conflicts")}: the reason's message is kept, not its span. A resolved conflict cannot be reopened: save a successor of one side that names the other in conflicts` : ""
|
|
18312
|
+
].filter(Boolean);
|
|
18313
|
+
}
|
|
18314
|
+
function auditSections(audit) {
|
|
18315
|
+
const sections = [];
|
|
18316
|
+
for (const kind of KINDS) {
|
|
18317
|
+
const found = audit.findings.filter((f) => f.kind === kind);
|
|
18318
|
+
if (!found.length)
|
|
18319
|
+
continue;
|
|
18320
|
+
sections.push([
|
|
18321
|
+
`${kind}: ${found.length}`,
|
|
18322
|
+
...found.map((f) => ` ${inline(f.project)} ${inline(f.what)} (${f.row}): s${f.source} bytes ${f.start}-${f.end} ${f.why === "block" ? "touch a block quote or fenced code" : "sit inside quotation marks"}; ${f.live ? "in effect" : "retracted, kept as history"}`),
|
|
18323
|
+
` What you can do: ${REPAIR[kind]}`
|
|
18324
|
+
]);
|
|
18325
|
+
}
|
|
18326
|
+
const unchecked = uncheckedLines(audit.unchecked);
|
|
18327
|
+
sections.push(unchecked.length ? ["Not checked, since their words are not kept:", ...unchecked.map((l) => ` ${l}`)] : [
|
|
18328
|
+
"Not checked, since their words are not kept: no such rows (links from harvest or glean, withdrawals, resolved conflicts)"
|
|
18329
|
+
]);
|
|
18330
|
+
return sections;
|
|
18331
|
+
}
|
|
18332
|
+
var auditClosing = (audit) => `${audit.findings.length} of ${audit.read} ${audit.read === 1 ? "row" : "rows"} rest on words the quotation rule refuses. Nothing was changed. The rule reads markup, not meaning: a row it passes may still be wrong, and one it lists may be right`;
|
|
18333
|
+
async function auditQuotes(db) {
|
|
18334
|
+
const findings = [];
|
|
18335
|
+
let read = 0;
|
|
18336
|
+
const judge2 = (kind, r2) => {
|
|
18337
|
+
read++;
|
|
18338
|
+
const why = notOwnWords(r2.text, r2.start, r2.end);
|
|
18339
|
+
if (why)
|
|
18340
|
+
findings.push({
|
|
18341
|
+
project: r2.project,
|
|
18342
|
+
what: r2.what,
|
|
18343
|
+
kind,
|
|
18344
|
+
row: r2.row,
|
|
18345
|
+
source: r2.source,
|
|
18346
|
+
start: r2.start,
|
|
18347
|
+
end: r2.end,
|
|
18348
|
+
why,
|
|
18349
|
+
live: r2.live
|
|
18350
|
+
});
|
|
18351
|
+
};
|
|
18352
|
+
for (const a2 of await db.selectFrom("unit_adoption as a").innerJoin("unit as u", "u.id", "a.unit_id").innerJoin("project as p", "p.id", "u.project_id").innerJoin("source as s", "s.id", "a.source_id").select([
|
|
18353
|
+
"a.id",
|
|
18354
|
+
"u.key",
|
|
18355
|
+
"p.name",
|
|
18356
|
+
"a.source_id",
|
|
18357
|
+
"a.span_start",
|
|
18358
|
+
"a.span_end",
|
|
18359
|
+
"s.text",
|
|
18360
|
+
"a.retracted_at"
|
|
18361
|
+
]).orderBy("a.id").execute())
|
|
18362
|
+
judge2("adoption", {
|
|
18363
|
+
project: a2.name,
|
|
18364
|
+
what: a2.key,
|
|
18365
|
+
row: `unit_adoption ${a2.id}`,
|
|
18366
|
+
source: a2.source_id,
|
|
18367
|
+
start: a2.span_start,
|
|
18368
|
+
end: a2.span_end,
|
|
18369
|
+
text: a2.text,
|
|
18370
|
+
live: a2.retracted_at === null
|
|
18371
|
+
});
|
|
18372
|
+
const reason2 = (table, r2) => judge2("retraction reason", {
|
|
18373
|
+
project: r2.name,
|
|
18374
|
+
what: r2.key,
|
|
18375
|
+
row: `${table} ${r2.id}`,
|
|
18376
|
+
source: r2.source,
|
|
18377
|
+
start: r2.retraction_span_start ?? 0,
|
|
18378
|
+
end: r2.retraction_span_end ?? 0,
|
|
18379
|
+
text: r2.text,
|
|
18380
|
+
live: true
|
|
18381
|
+
});
|
|
18382
|
+
for (const r2 of await db.selectFrom("unit_adoption as r").innerJoin("unit as u", "u.id", "r.unit_id").innerJoin("project as p", "p.id", "u.project_id").innerJoin("source as s", "s.id", "r.retraction_source_id").select([
|
|
18383
|
+
"r.id",
|
|
18384
|
+
"u.key",
|
|
18385
|
+
"p.name",
|
|
18386
|
+
"s.id as source",
|
|
18387
|
+
"r.retraction_span_start",
|
|
18388
|
+
"r.retraction_span_end",
|
|
18389
|
+
"s.text"
|
|
18390
|
+
]).where("r.retraction_span_end", "is not", null).orderBy("r.id").execute())
|
|
18391
|
+
reason2("unit_adoption", r2);
|
|
18392
|
+
for (const r2 of await db.selectFrom("unit_evidence as r").innerJoin("unit as u", "u.id", "r.unit_id").innerJoin("project as p", "p.id", "u.project_id").innerJoin("source as s", "s.id", "r.retraction_source_id").select([
|
|
18393
|
+
"r.id",
|
|
18394
|
+
"u.key",
|
|
18395
|
+
"p.name",
|
|
18396
|
+
"s.id as source",
|
|
18397
|
+
"r.retraction_span_start",
|
|
18398
|
+
"r.retraction_span_end",
|
|
18399
|
+
"s.text"
|
|
18400
|
+
]).where("r.retraction_span_end", "is not", null).orderBy("r.id").execute())
|
|
18401
|
+
reason2("unit_evidence", r2);
|
|
18402
|
+
for (const e of await db.selectFrom("unit_evidence as e").innerJoin("unit as u", "u.id", "e.unit_id").innerJoin("project as p", "p.id", "u.project_id").innerJoin("source as s", "s.id", "e.source_id").select([
|
|
18403
|
+
"e.id",
|
|
18404
|
+
"u.key",
|
|
18405
|
+
"p.name",
|
|
18406
|
+
"e.source_id",
|
|
18407
|
+
"e.span_start",
|
|
18408
|
+
"e.span_end",
|
|
18409
|
+
"s.text",
|
|
18410
|
+
"e.retracted_at"
|
|
18411
|
+
]).where("e.role", "=", "reconsiders").orderBy("e.id").execute())
|
|
18412
|
+
judge2("reconsider condition", {
|
|
18413
|
+
project: e.name,
|
|
18414
|
+
what: e.key,
|
|
18415
|
+
row: `unit_evidence ${e.id}`,
|
|
18416
|
+
source: e.source_id,
|
|
18417
|
+
start: e.span_start,
|
|
18418
|
+
end: e.span_end,
|
|
18419
|
+
text: e.text,
|
|
18420
|
+
live: e.retracted_at === null
|
|
18421
|
+
});
|
|
18422
|
+
for (const r2 of await db.selectFrom("unit_anchor_retirement as r").innerJoin("unit_anchor as an", "an.id", "r.anchor_id").innerJoin("unit as u", "u.id", "an.unit_id").innerJoin("project as p", "p.id", "u.project_id").innerJoin("source as s", "s.id", "r.source_id").select(["r.anchor_id", "u.key", "p.name", "r.source_id", "r.span_start", "r.span_end", "s.text"]).orderBy("r.anchor_id").execute())
|
|
18423
|
+
judge2("anchor reason", {
|
|
18424
|
+
project: r2.name,
|
|
18425
|
+
what: r2.key,
|
|
18426
|
+
row: `unit_anchor_retirement ${r2.anchor_id}`,
|
|
18427
|
+
source: r2.source_id,
|
|
18428
|
+
start: r2.span_start,
|
|
18429
|
+
end: r2.span_end,
|
|
18430
|
+
text: r2.text,
|
|
18431
|
+
live: true
|
|
18432
|
+
});
|
|
18433
|
+
for (const f of await db.selectFrom("field_def as f").innerJoin("project as p", "p.id", "f.project_id").innerJoin("source as s", "s.id", "f.source_id").select(["f.id", "f.name as field", "p.name", "f.source_id", "f.span_start", "f.span_end", "s.text"]).orderBy("f.id").execute())
|
|
18434
|
+
judge2("field definition", {
|
|
18435
|
+
project: f.name,
|
|
18436
|
+
what: f.field,
|
|
18437
|
+
row: `field_def ${f.id}`,
|
|
18438
|
+
source: f.source_id,
|
|
18439
|
+
start: f.span_start,
|
|
18440
|
+
end: f.span_end,
|
|
18441
|
+
text: f.text,
|
|
18442
|
+
live: true
|
|
18443
|
+
});
|
|
18444
|
+
const count = async (q) => Number((await q.executeTakeFirstOrThrow()).n);
|
|
18445
|
+
const links = await count(db.selectFrom("unit_link as l").innerJoin("extraction_run as r", "r.id", "l.run_id").select((eb) => eb.fn.countAll().as("n")).where("r.origin", "in", ["harvest", "glean"]));
|
|
18446
|
+
const withdrawals = await count(db.selectFrom("unit_state").select((eb) => eb.fn.countAll().as("n")).where("to_state", "=", "withdrawn").where("run_id", "is not", null));
|
|
18447
|
+
const resolutions = await count(db.selectFrom("unit_link").select((eb) => eb.fn.countAll().as("n")).where("kind", "=", "conflicts").where("resolved_at", "is not", null));
|
|
18448
|
+
return { findings, read, unchecked: { links, withdrawals, resolutions } };
|
|
18449
|
+
}
|
|
18450
|
+
|
|
18087
18451
|
// server/src/cli/common.ts
|
|
18088
18452
|
async function withDb(role, fn) {
|
|
18089
18453
|
const db = role === "reader" ? openReader() : openWriter(role);
|
|
@@ -19012,6 +19376,18 @@ async function uninstall(yes) {
|
|
|
19012
19376
|
], "Sphica does not run these for you"));
|
|
19013
19377
|
});
|
|
19014
19378
|
}
|
|
19379
|
+
async function auditReport() {
|
|
19380
|
+
const head2 = "sphica doctor --audit-quotes";
|
|
19381
|
+
let audit;
|
|
19382
|
+
try {
|
|
19383
|
+
audit = await withDb("reader", (db) => auditQuotes(db));
|
|
19384
|
+
} catch (e) {
|
|
19385
|
+
console.log(failure(head2, plain(reason(e))));
|
|
19386
|
+
process.exitCode = 1;
|
|
19387
|
+
return;
|
|
19388
|
+
}
|
|
19389
|
+
console.log(document(head2, undefined, auditSections(audit).map((lines) => ({ kind: "lines", lines })), `${mark(audit.findings.length ? "warn" : "ok")} ${auditClosing(audit)}`));
|
|
19390
|
+
}
|
|
19015
19391
|
async function boxed(head2, fn) {
|
|
19016
19392
|
console.log(title2(head2));
|
|
19017
19393
|
let outcome;
|
|
@@ -19063,10 +19439,25 @@ var root = buildRouteMap({
|
|
|
19063
19439
|
kind: "boolean",
|
|
19064
19440
|
brief: "Rebuild the full-text index when doctor reports it broken",
|
|
19065
19441
|
optional: true
|
|
19442
|
+
},
|
|
19443
|
+
"audit-quotes": {
|
|
19444
|
+
kind: "boolean",
|
|
19445
|
+
brief: "List saved adoptions and reasons that rest on quoted words, without changing anything",
|
|
19446
|
+
optional: true,
|
|
19447
|
+
withNegated: false
|
|
19066
19448
|
}
|
|
19067
19449
|
}
|
|
19068
19450
|
},
|
|
19069
|
-
func: (flags) =>
|
|
19451
|
+
func: (flags) => {
|
|
19452
|
+
if (flags.reindex && flags["audit-quotes"]) {
|
|
19453
|
+
console.log(failed("--audit-quotes only reads, so it cannot go with --reindex. Run them one at a time"));
|
|
19454
|
+
process.exitCode = 1;
|
|
19455
|
+
return;
|
|
19456
|
+
}
|
|
19457
|
+
if (flags["audit-quotes"])
|
|
19458
|
+
return auditReport();
|
|
19459
|
+
return flags.reindex ? boxed("sphica doctor --reindex", () => reindex()) : doctor(process.cwd());
|
|
19460
|
+
}
|
|
19070
19461
|
}),
|
|
19071
19462
|
uninstall: buildCommand({
|
|
19072
19463
|
docs: { brief: "Delete this machine's Sphica data (~/.sphica) and show how to remove the rest" },
|
package/dist/deliver.js
CHANGED
|
@@ -13486,14 +13486,17 @@ var noted = (text2, lead, notes) => {
|
|
|
13486
13486
|
${l}`).join("");
|
|
13487
13487
|
return { text: note ? `${text2 || lead}${note}` : text2, note };
|
|
13488
13488
|
};
|
|
13489
|
+
var sound = (unit) => sql`exists (select 1 from unit o where o.id = ${sql.ref(unit)} and o.extraction = 'supported' and o.unsourced = 0)`;
|
|
13489
13490
|
var deliverable = (db, projectId2, asOf) => db.selectFrom("unit as u").where("u.project_id", "=", projectId2).$call((q) => asOf === undefined ? q.where("u.lifecycle", "=", "active") : q.where(sql`(select s.to_state from unit_state s where s.unit_id = u.id and s.at <= ${asOf}
|
|
13490
13491
|
order by s.at desc, s.id desc limit 1) = 'active'`)).where("u.extraction", "=", "supported").where("u.unsourced", "=", 0).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_link as l").select("l.from_unit").where("l.kind", "=", "conflicts").$call((q) => asOf === undefined ? q.where("l.resolved_at", "is", null) : q.where("l.added_at", "<=", asOf).where((eb) => eb.or([eb("l.resolved_at", "is", null), eb("l.resolved_at", ">", asOf)]))).where((eb) => eb.or([
|
|
13491
13492
|
eb.and([
|
|
13492
13493
|
eb("l.from_unit", "=", eb.ref("u.id")),
|
|
13494
|
+
sound("l.to_unit"),
|
|
13493
13495
|
eb.or([eb.not(ownerAdopted("u.id", asOf)), ownerAdopted("l.to_unit", asOf)])
|
|
13494
13496
|
]),
|
|
13495
13497
|
eb.and([
|
|
13496
13498
|
eb("l.to_unit", "=", eb.ref("u.id")),
|
|
13499
|
+
sound("l.from_unit"),
|
|
13497
13500
|
eb.or([eb.not(ownerAdopted("u.id", asOf)), ownerAdopted("l.from_unit", asOf)])
|
|
13498
13501
|
])
|
|
13499
13502
|
])))));
|
package/dist/mcp-record.js
CHANGED
|
@@ -48223,6 +48223,163 @@ async function runSources(db, runId) {
|
|
|
48223
48223
|
]).select((eb) => eb.exists(eb.selectFrom("source_processing as p").whereRef("p.source_id", "=", "s.id").select(sql`1`.as("x"))).as("looked")).orderBy("s.created_at").orderBy("s.id").execute();
|
|
48224
48224
|
}
|
|
48225
48225
|
|
|
48226
|
+
// server/src/own-words.ts
|
|
48227
|
+
var MAINTAINERS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
48228
|
+
var refused = (words) => ("refused" in words);
|
|
48229
|
+
function locate(body, quote) {
|
|
48230
|
+
const at = Buffer.from(body, "utf8").indexOf(Buffer.from(quote, "utf8"));
|
|
48231
|
+
return at < 0 ? null : [at, at + Buffer.byteLength(quote, "utf8")];
|
|
48232
|
+
}
|
|
48233
|
+
function ownWords(s, quote, policy, agent = false) {
|
|
48234
|
+
if (policy === "maintainer" && s.kind === "pr_event")
|
|
48235
|
+
return { refused: "event" };
|
|
48236
|
+
const route = s.author_kind === "owner" ? "owner_statement" : policy !== "owner" && MAINTAINERS.has(s.author_association ?? "") ? "explicit" : policy === "maintainer" && agent && s.author_kind === "assistant" && s.kind === "session_message" ? "agent" : policy === "trusted" && s.kind === "session_message" ? "session" : null;
|
|
48237
|
+
if (!route)
|
|
48238
|
+
return { refused: "author" };
|
|
48239
|
+
const at = quote.trim() ? locate(s.text, quote) : null;
|
|
48240
|
+
if (!at)
|
|
48241
|
+
return { refused: "missing" };
|
|
48242
|
+
const quoted = notOwnWords(s.text, at[0], at[1]);
|
|
48243
|
+
if (quoted)
|
|
48244
|
+
return { refused: quoted };
|
|
48245
|
+
return { source: s.id, start: at[0], end: at[1], route };
|
|
48246
|
+
}
|
|
48247
|
+
var PAIRS = { '"': '"', "“": "”", "‘": "’", "「": "」", "『": "』" };
|
|
48248
|
+
var WORD2 = /[\p{Script=Latin}\p{N}]/u;
|
|
48249
|
+
var charAt = (line, at) => at < line.length ? String.fromCodePoint(line.codePointAt(at)) : "";
|
|
48250
|
+
function endsWord(line, end) {
|
|
48251
|
+
for (let i = end;i > 0; ) {
|
|
48252
|
+
const low = line.charCodeAt(i - 1);
|
|
48253
|
+
const from = low >= 56320 && low <= 57343 && i > 1 ? i - 2 : i - 1;
|
|
48254
|
+
const c = charAt(line, from);
|
|
48255
|
+
if (!/\p{M}/u.test(c))
|
|
48256
|
+
return WORD2.test(c);
|
|
48257
|
+
i = from;
|
|
48258
|
+
}
|
|
48259
|
+
return false;
|
|
48260
|
+
}
|
|
48261
|
+
var startsWord = (line, at) => WORD2.test(charAt(line, at + 1));
|
|
48262
|
+
function inlineRanges(line) {
|
|
48263
|
+
const found = [];
|
|
48264
|
+
const closing = new Map;
|
|
48265
|
+
const last = new Map;
|
|
48266
|
+
for (let end = line.length;end > 0; ) {
|
|
48267
|
+
if (line[end - 1] !== "`") {
|
|
48268
|
+
end--;
|
|
48269
|
+
continue;
|
|
48270
|
+
}
|
|
48271
|
+
let from = end - 1;
|
|
48272
|
+
while (from > 0 && line[from - 1] === "`")
|
|
48273
|
+
from--;
|
|
48274
|
+
const partner = last.get(end - from);
|
|
48275
|
+
if (partner !== undefined)
|
|
48276
|
+
closing.set(from, partner);
|
|
48277
|
+
last.set(end - from, from);
|
|
48278
|
+
end = from;
|
|
48279
|
+
}
|
|
48280
|
+
const unpaired = new Set;
|
|
48281
|
+
for (let i = 0;i < line.length; ) {
|
|
48282
|
+
const c = line[i];
|
|
48283
|
+
let close = -1;
|
|
48284
|
+
let width2 = 1;
|
|
48285
|
+
if (c === "`")
|
|
48286
|
+
while (line[i + width2] === "`")
|
|
48287
|
+
width2++;
|
|
48288
|
+
const mark2 = c === "`" ? c.repeat(width2) : c;
|
|
48289
|
+
if (unpaired.has(mark2)) {
|
|
48290
|
+
i += width2;
|
|
48291
|
+
continue;
|
|
48292
|
+
}
|
|
48293
|
+
if (c === "`")
|
|
48294
|
+
close = closing.get(i) ?? -1;
|
|
48295
|
+
else if (c === "'") {
|
|
48296
|
+
if (endsWord(line, i)) {
|
|
48297
|
+
i++;
|
|
48298
|
+
continue;
|
|
48299
|
+
}
|
|
48300
|
+
for (let j = i + 1;j < line.length; j++)
|
|
48301
|
+
if (line[j] === "'" && !startsWord(line, j)) {
|
|
48302
|
+
close = j;
|
|
48303
|
+
break;
|
|
48304
|
+
}
|
|
48305
|
+
} else if (PAIRS[c]) {
|
|
48306
|
+
close = line.indexOf(PAIRS[c], i + 1);
|
|
48307
|
+
while (c === "‘" && close >= 0 && startsWord(line, close))
|
|
48308
|
+
close = line.indexOf(PAIRS[c], close + 1);
|
|
48309
|
+
} else {
|
|
48310
|
+
i++;
|
|
48311
|
+
continue;
|
|
48312
|
+
}
|
|
48313
|
+
if (close < 0) {
|
|
48314
|
+
unpaired.add(mark2);
|
|
48315
|
+
i += width2;
|
|
48316
|
+
continue;
|
|
48317
|
+
}
|
|
48318
|
+
found.push([i, close + width2]);
|
|
48319
|
+
i = close + width2;
|
|
48320
|
+
}
|
|
48321
|
+
return found;
|
|
48322
|
+
}
|
|
48323
|
+
var OPENS = /["“'‘`「『]/;
|
|
48324
|
+
var CLOSES2 = /["”'’`」』]/;
|
|
48325
|
+
function notOwnWords(body, start, end) {
|
|
48326
|
+
const bytes2 = Buffer.from(body, "utf8");
|
|
48327
|
+
let fence = null;
|
|
48328
|
+
let own2 = "";
|
|
48329
|
+
let quoting = false;
|
|
48330
|
+
let before = "";
|
|
48331
|
+
let after = "";
|
|
48332
|
+
for (let at = 0;at <= bytes2.length; ) {
|
|
48333
|
+
const nl = bytes2.indexOf(10, at);
|
|
48334
|
+
const stop = nl < 0 ? bytes2.length : nl;
|
|
48335
|
+
const raw = bytes2.subarray(at, stop).toString("utf8").replace(/\r$/, "");
|
|
48336
|
+
const line = raw.trimStart();
|
|
48337
|
+
let block = fence !== null || line.startsWith(">");
|
|
48338
|
+
if (fence) {
|
|
48339
|
+
const closing = /^(`+|~+)\s*$/.exec(line)?.[1];
|
|
48340
|
+
if (closing && closing[0] === fence.mark && closing.length >= fence.length)
|
|
48341
|
+
fence = null;
|
|
48342
|
+
} else {
|
|
48343
|
+
const opening = /^(`{3,}|~{3,})(.*)$/.exec(line);
|
|
48344
|
+
if (opening && !(opening[1]?.startsWith("`") && opening[2]?.includes("`"))) {
|
|
48345
|
+
fence = { mark: opening[1][0], length: opening[1].length };
|
|
48346
|
+
block = true;
|
|
48347
|
+
}
|
|
48348
|
+
}
|
|
48349
|
+
if (at < end && stop > start) {
|
|
48350
|
+
if (block)
|
|
48351
|
+
return "block";
|
|
48352
|
+
const from = Buffer.from(raw, "utf8").subarray(0, Math.max(start - at, 0)).toString("utf8").length;
|
|
48353
|
+
const to = Buffer.from(raw, "utf8").subarray(0, Math.min(end, stop) - at).toString("utf8").length;
|
|
48354
|
+
if (start >= at)
|
|
48355
|
+
before = raw.slice(0, from).trimEnd().slice(-1);
|
|
48356
|
+
if (end <= stop)
|
|
48357
|
+
after = raw.slice(to).trimStart().slice(0, 1);
|
|
48358
|
+
let cursor = from;
|
|
48359
|
+
for (const [a, b] of inlineRanges(raw)) {
|
|
48360
|
+
if (b <= cursor || a >= to)
|
|
48361
|
+
continue;
|
|
48362
|
+
quoting = true;
|
|
48363
|
+
own2 += raw.slice(cursor, Math.max(a, cursor));
|
|
48364
|
+
cursor = Math.max(cursor, b);
|
|
48365
|
+
}
|
|
48366
|
+
own2 += `${raw.slice(cursor, Math.max(to, cursor))}
|
|
48367
|
+
`;
|
|
48368
|
+
}
|
|
48369
|
+
if (nl < 0)
|
|
48370
|
+
break;
|
|
48371
|
+
at = nl + 1;
|
|
48372
|
+
}
|
|
48373
|
+
if (OPENS.test(before) && CLOSES2.test(after))
|
|
48374
|
+
return "inline";
|
|
48375
|
+
const span = bytes2.subarray(start, end).toString("utf8").trim();
|
|
48376
|
+
const opens = span.slice(0, 1);
|
|
48377
|
+
const closes = PAIRS[opens] ?? (opens === "'" || opens === "`" ? opens : "");
|
|
48378
|
+
if (closes && span.length > 1 && span.endsWith(closes) && !span.slice(1, -1).includes(closes))
|
|
48379
|
+
return "inline";
|
|
48380
|
+
return !quoting || /\p{L}/u.test(own2) ? null : "inline";
|
|
48381
|
+
}
|
|
48382
|
+
|
|
48226
48383
|
// server/src/judge.ts
|
|
48227
48384
|
var replaceable = (successor, old) => successor === old || ["decision", "constraint"].includes(successor) && ["decision", "constraint"].includes(old);
|
|
48228
48385
|
var owned = (kind) => kind === "decision" || kind === "constraint";
|
|
@@ -48615,7 +48772,6 @@ var instructionFile = (relative) => {
|
|
|
48615
48772
|
var KEY = /^[a-z0-9][a-z0-9._/-]{0,63}$/;
|
|
48616
48773
|
var FIELD_NAME2 = /^[a-z][a-z0-9_]{0,39}$/;
|
|
48617
48774
|
var SOURCE_REF = /^s[1-9][0-9]{0,15}$/;
|
|
48618
|
-
var MAINTAINERS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
48619
48775
|
var text3 = (max) => exports_external.string().trim().min(1).max(max);
|
|
48620
48776
|
var Quote = exports_external.object({ source: exports_external.string().regex(SOURCE_REF, "cite a source ref such as s12"), quote: exports_external.string() }).strict();
|
|
48621
48777
|
var Evidence = Quote.extend({
|
|
@@ -48679,40 +48835,7 @@ var Record = exports_external.object({
|
|
|
48679
48835
|
units: exports_external.array(Unit).max(50),
|
|
48680
48836
|
work: Work.optional()
|
|
48681
48837
|
}).strict();
|
|
48682
|
-
|
|
48683
|
-
const bytes2 = Buffer.from(body, "utf8");
|
|
48684
|
-
let fenced = false;
|
|
48685
|
-
let touched = false;
|
|
48686
|
-
for (let at = 0;at <= bytes2.length; ) {
|
|
48687
|
-
const nl = bytes2.indexOf(10, at);
|
|
48688
|
-
const stop = nl < 0 ? bytes2.length : nl;
|
|
48689
|
-
const line = bytes2.subarray(at, stop).toString("utf8").trimStart();
|
|
48690
|
-
const fence = /^(```|~~~)/.test(line);
|
|
48691
|
-
if (stop >= start && at < end) {
|
|
48692
|
-
touched = true;
|
|
48693
|
-
if (!(fenced || fence || line.startsWith(">")))
|
|
48694
|
-
return false;
|
|
48695
|
-
}
|
|
48696
|
-
if (fence)
|
|
48697
|
-
fenced = !fenced;
|
|
48698
|
-
if (nl < 0)
|
|
48699
|
-
break;
|
|
48700
|
-
at = nl + 1;
|
|
48701
|
-
}
|
|
48702
|
-
return touched;
|
|
48703
|
-
}
|
|
48704
|
-
function inlineQuoted(body, start, end) {
|
|
48705
|
-
const bytes2 = Buffer.from(body, "utf8");
|
|
48706
|
-
const before = bytes2.subarray(0, start).toString("utf8").trimEnd().at(-1) ?? "";
|
|
48707
|
-
const after = bytes2.subarray(end).toString("utf8").trimStart()[0] ?? "";
|
|
48708
|
-
return /["“'‘`「『]/.test(before) && /["”'’`」』]/.test(after);
|
|
48709
|
-
}
|
|
48710
|
-
function locate(body, quote) {
|
|
48711
|
-
if (!quote.trim())
|
|
48712
|
-
return null;
|
|
48713
|
-
const at = Buffer.from(body, "utf8").indexOf(Buffer.from(quote, "utf8"));
|
|
48714
|
-
return at < 0 ? null : [at, at + Buffer.byteLength(quote, "utf8")];
|
|
48715
|
-
}
|
|
48838
|
+
var cited = (body, quote) => quote.trim() ? locate(body, quote) : null;
|
|
48716
48839
|
function anchorProblem(facts, a) {
|
|
48717
48840
|
if (!facts.root || a.held)
|
|
48718
48841
|
return null;
|
|
@@ -48846,18 +48969,14 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
|
|
|
48846
48969
|
const s = sources.get(Number(d.quote.source.slice(1)));
|
|
48847
48970
|
if (!s)
|
|
48848
48971
|
continue;
|
|
48849
|
-
|
|
48850
|
-
|
|
48851
|
-
|
|
48852
|
-
}
|
|
48853
|
-
const span = locate(s.text, d.quote.quote);
|
|
48854
|
-
if (!span) {
|
|
48855
|
-
errors3.push(`${at}: quote not found in ${d.quote.source}: "${head(d.quote.quote, 80)}"`);
|
|
48972
|
+
const said2 = ownWords(s, d.quote.quote, "owner");
|
|
48973
|
+
if (refused(said2)) {
|
|
48974
|
+
errors3.push(said2.refused === "author" ? `${at}: the quote must be the owner's; ${d.quote.source} is by ${s.author_login ?? s.author_kind}` : said2.refused === "missing" ? `${at}: quote not found in ${d.quote.source}: "${head(d.quote.quote, 80)}"` : `${at}: the quote in ${d.quote.source} is quoted or in a code block, so it is someone else's words; quote the owner's own`);
|
|
48856
48975
|
continue;
|
|
48857
48976
|
}
|
|
48858
48977
|
defined.set(d.name, { type: d.type, enum: d.enum ?? null, kinds: d.kinds });
|
|
48859
48978
|
const { quote: _, ...rest } = d;
|
|
48860
|
-
fieldDefs.push({ ...rest,
|
|
48979
|
+
fieldDefs.push({ ...rest, ...said2 });
|
|
48861
48980
|
}
|
|
48862
48981
|
const names = record4.field_defs.map((d) => d.name);
|
|
48863
48982
|
for (const n of new Set(names.filter((n2, i) => names.indexOf(n2) !== i)))
|
|
@@ -48880,7 +48999,7 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
|
|
|
48880
48999
|
errors3.push(`${key}: decides quotes the AI choosing in its own reply, never a question it asked, someone else's words, or an option, and only a trace records it`);
|
|
48881
49000
|
return [];
|
|
48882
49001
|
}
|
|
48883
|
-
const span =
|
|
49002
|
+
const span = cited(s.text, e.quote);
|
|
48884
49003
|
if (!span) {
|
|
48885
49004
|
quarantine.push(`quote not found in ${e.source}: "${head(e.quote, 80)}"`);
|
|
48886
49005
|
return [];
|
|
@@ -48900,16 +49019,12 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
|
|
|
48900
49019
|
if (!q || !s || o.reconsider_when === undefined)
|
|
48901
49020
|
return null;
|
|
48902
49021
|
cites.add(s.id);
|
|
48903
|
-
|
|
48904
|
-
|
|
48905
|
-
return
|
|
48906
|
-
}
|
|
48907
|
-
|
|
48908
|
-
|
|
48909
|
-
errors3.push(`${key}: option "${head(o.text, 60)}": reconsider_quote not found in ${q.source}: "${head(q.quote, 80)}"`);
|
|
48910
|
-
return null;
|
|
48911
|
-
}
|
|
48912
|
-
return { source: s.id, start: span[0], end: span[1] };
|
|
49022
|
+
const said2 = ownWords(s, q.quote, "owner");
|
|
49023
|
+
if (!refused(said2))
|
|
49024
|
+
return said2;
|
|
49025
|
+
const at = `${key}: option "${head(o.text, 60)}": reconsider_quote`;
|
|
49026
|
+
errors3.push(said2.refused === "author" ? `${at} must quote the owner; ${q.source} is by ${s.author_login ?? s.author_kind}` : said2.refused === "missing" ? `${at} not found in ${q.source}: "${head(q.quote, 80)}"` : `${at} in ${q.source} is quoted or in a code block, so it is someone else's words; quote the owner's own`);
|
|
49027
|
+
return null;
|
|
48913
49028
|
};
|
|
48914
49029
|
const options = u.options.map((o) => ({
|
|
48915
49030
|
input: o,
|
|
@@ -48924,10 +49039,10 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
|
|
|
48924
49039
|
if (target.origin !== "trace" && (u.supersedes || u.conflicts.length)) {
|
|
48925
49040
|
const trusted = [...u.evidence, ...u.adoption].some((q) => {
|
|
48926
49041
|
const s = sources.get(Number(q.source.slice(1)));
|
|
48927
|
-
return s && (s
|
|
49042
|
+
return s !== undefined && !refused(ownWords(s, q.quote, "trusted"));
|
|
48928
49043
|
});
|
|
48929
49044
|
if (!trusted)
|
|
48930
|
-
errors3.push(`${key}: supersedes and conflicts from ${target.origin} need the owner's or a maintainer's words, or the owner's session`);
|
|
49045
|
+
errors3.push(`${key}: supersedes and conflicts from ${target.origin} need the owner's or a maintainer's words, or the owner's session: words that are in the source, and not only a quotation there`);
|
|
48931
49046
|
}
|
|
48932
49047
|
const adoption = [];
|
|
48933
49048
|
for (const a of u.adoption) {
|
|
@@ -48940,25 +49055,19 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
|
|
|
48940
49055
|
problems.push(`${key}: adoption applies to decisions and constraints; ${a.source} left out`);
|
|
48941
49056
|
continue;
|
|
48942
49057
|
}
|
|
48943
|
-
|
|
48944
|
-
|
|
48945
|
-
|
|
48946
|
-
|
|
48947
|
-
|
|
48948
|
-
|
|
48949
|
-
|
|
48950
|
-
|
|
48951
|
-
|
|
48952
|
-
|
|
48953
|
-
if (!span) {
|
|
48954
|
-
quarantine.push(`adoption quote not found in ${a.source}: "${head(a.quote, 80)}"`);
|
|
48955
|
-
continue;
|
|
48956
|
-
}
|
|
48957
|
-
if (quotedSpan(s.text, span[0], span[1]) || inlineQuoted(s.text, span[0], span[1])) {
|
|
48958
|
-
problems.push(`${key}: the adoption in ${a.source} is quoted or in a code block, so it is someone else's words pasted in; left out, so it stays a candidate unless other words adopt it`);
|
|
49058
|
+
const words = ownWords(s, a.quote, "maintainer", target.agent);
|
|
49059
|
+
if (refused(words)) {
|
|
49060
|
+
if (words.refused === "event")
|
|
49061
|
+
problems.push(`${key}: the merge does not adopt a proposal (it only shows the code went in); cite the owner's or a maintainer's words`);
|
|
49062
|
+
else if (words.refused === "author")
|
|
49063
|
+
problems.push(`${key}: ${a.source} is by ${s.author_login ?? s.author_kind} (${s.author_association ?? "no association"}); only the owner or a maintainer can adopt${s.author_kind === "assistant" ? ", and an AI's own decision only in a trace an interactive session runs" : ""}`);
|
|
49064
|
+
else if (words.refused === "missing")
|
|
49065
|
+
quarantine.push(`adoption quote not found in ${a.source}: "${head(a.quote, 80)}"`);
|
|
49066
|
+
else
|
|
49067
|
+
problems.push(`${key}: the adoption in ${a.source} is quoted or in a code block, so it is someone else's words pasted in; left out, so it stays a candidate unless other words adopt it`);
|
|
48959
49068
|
continue;
|
|
48960
49069
|
}
|
|
48961
|
-
adoption.push(
|
|
49070
|
+
adoption.push(words);
|
|
48962
49071
|
}
|
|
48963
49072
|
const anchors = [];
|
|
48964
49073
|
const fallbacks = new Set;
|
|
@@ -49071,7 +49180,7 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
|
|
|
49071
49180
|
if (!s)
|
|
49072
49181
|
continue;
|
|
49073
49182
|
cites.add(s.id);
|
|
49074
|
-
const span =
|
|
49183
|
+
const span = cited(s.text, f.quote.quote);
|
|
49075
49184
|
if (!span) {
|
|
49076
49185
|
errors3.push(`${at}: quote not found in ${f.quote.source}: "${head(f.quote.quote, 80)}"`);
|
|
49077
49186
|
continue;
|
|
@@ -49114,13 +49223,13 @@ var isoDate = (v) => {
|
|
|
49114
49223
|
const d = new Date(`${v}T00:00:00Z`);
|
|
49115
49224
|
return !Number.isNaN(d.getTime()) && d.toISOString().slice(0, 10) === v;
|
|
49116
49225
|
};
|
|
49117
|
-
var
|
|
49226
|
+
var WORD3 = /[\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}\p{M}\p{N}_]/u;
|
|
49118
49227
|
var NUMBER = /(?<![\p{Script=Latin}\p{Script=Greek}\p{Script=Cyrillic}\p{M}\p{N}\p{Pd}_.+\uFF0B\u2212])[+-]?(?:[0-9]{1,3}(?:,[0-9]{3})+(?![0-9])|[0-9]+)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/gu;
|
|
49119
49228
|
function standsAlone(quote, value) {
|
|
49120
49229
|
for (let at = quote.indexOf(value);at >= 0; at = quote.indexOf(value, at + 1)) {
|
|
49121
49230
|
const before = [...quote.slice(Math.max(0, at - 2), at)].at(-1) ?? "";
|
|
49122
49231
|
const after = String.fromCodePoint(quote.codePointAt(at + value.length) ?? 32);
|
|
49123
|
-
if (!
|
|
49232
|
+
if (!WORD3.test(before) && !WORD3.test(after))
|
|
49124
49233
|
return true;
|
|
49125
49234
|
}
|
|
49126
49235
|
return false;
|
|
@@ -49207,9 +49316,9 @@ ${checked.errors.map((e) => ` ${e}`).join(`
|
|
|
49207
49316
|
anchorProblems: [],
|
|
49208
49317
|
written: []
|
|
49209
49318
|
};
|
|
49210
|
-
const
|
|
49319
|
+
const cited2 = new Set;
|
|
49211
49320
|
for (const d of checked.fieldDefs) {
|
|
49212
|
-
|
|
49321
|
+
cited2.add(d.source);
|
|
49213
49322
|
await trx.insertInto("field_def").values({
|
|
49214
49323
|
project_id: target.projectId,
|
|
49215
49324
|
name: d.name,
|
|
@@ -49228,7 +49337,7 @@ ${checked.errors.map((e) => ` ${e}`).join(`
|
|
|
49228
49337
|
const fieldIds = new Map((checked.units.some((p) => p.fields.length) ? await trx.selectFrom("field_def").select(["id", "name"]).where("project_id", "=", target.projectId).execute() : []).map((d) => [d.name, d.id]));
|
|
49229
49338
|
for (const p of checked.units) {
|
|
49230
49339
|
for (const c of p.cites)
|
|
49231
|
-
|
|
49340
|
+
cited2.add(c);
|
|
49232
49341
|
const u = p.input;
|
|
49233
49342
|
const hash2 = contentHash(u);
|
|
49234
49343
|
const { id } = await trx.insertInto("unit").values({
|
|
@@ -49250,7 +49359,7 @@ ${checked.errors.map((e) => ` ${e}`).join(`
|
|
|
49250
49359
|
}).returning("id").executeTakeFirstOrThrow();
|
|
49251
49360
|
const evidence = async (list2, option) => {
|
|
49252
49361
|
for (const e of list2) {
|
|
49253
|
-
|
|
49362
|
+
cited2.add(e.source);
|
|
49254
49363
|
await trx.insertInto("unit_evidence").values({
|
|
49255
49364
|
unit_id: id,
|
|
49256
49365
|
option_id: option,
|
|
@@ -49279,7 +49388,7 @@ ${checked.errors.map((e) => ` ${e}`).join(`
|
|
|
49279
49388
|
}
|
|
49280
49389
|
await evidence(p.evidence, null);
|
|
49281
49390
|
for (const a of p.adoption) {
|
|
49282
|
-
|
|
49391
|
+
cited2.add(a.source);
|
|
49283
49392
|
await trx.insertInto("unit_adoption").values({
|
|
49284
49393
|
unit_id: id,
|
|
49285
49394
|
route: a.route,
|
|
@@ -49378,7 +49487,7 @@ ${checked.errors.map((e) => ` ${e}`).join(`
|
|
|
49378
49487
|
await trx.insertInto("work").values({ project_id: target.projectId, key: w.key, ...row }).onConflict((oc) => oc.columns(["project_id", "key"]).doUpdateSet(row)).execute();
|
|
49379
49488
|
}
|
|
49380
49489
|
for (const s of new Set(looked))
|
|
49381
|
-
await trx.insertInto("source_processing").values({ source_id: s, run_id: runId, outcome:
|
|
49490
|
+
await trx.insertInto("source_processing").values({ source_id: s, run_id: runId, outcome: cited2.has(s) ? "units" : "no_unit" }).onConflict((oc) => oc.doNothing()).execute();
|
|
49382
49491
|
return saved;
|
|
49383
49492
|
}
|
|
49384
49493
|
async function finishRun(trx, runId) {
|
|
@@ -49390,7 +49499,6 @@ async function finishRun(trx, runId) {
|
|
|
49390
49499
|
|
|
49391
49500
|
// server/src/glean.ts
|
|
49392
49501
|
var MAX_FILE = 1024 * 1024;
|
|
49393
|
-
var MAINTAINERS2 = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
49394
49502
|
var SOURCE_REF2 = exports_external.string().regex(/^s[1-9][0-9]{0,15}$/, "cite a source ref such as s12");
|
|
49395
49503
|
var unit = exports_external.string().min(1).max(200);
|
|
49396
49504
|
var revision2 = exports_external.number().int().positive();
|
|
@@ -49519,10 +49627,6 @@ function readExcerpt(root, file3) {
|
|
|
49519
49627
|
throw new Error(`${p} lines ${a}-${b} cut through text Sphica masks; cite more lines around it`);
|
|
49520
49628
|
return { path: p, commit, blob, size, lines: [a, b], raw, text: text4 };
|
|
49521
49629
|
}
|
|
49522
|
-
var locate2 = (body, q) => {
|
|
49523
|
-
const at = Buffer.from(body, "utf8").indexOf(Buffer.from(q, "utf8"));
|
|
49524
|
-
return at < 0 ? null : [at, at + Buffer.byteLength(q, "utf8")];
|
|
49525
|
-
};
|
|
49526
49630
|
var excerptKey = (file3) => JSON.stringify([file3.path, file3.commit, file3.lines]);
|
|
49527
49631
|
function excerptOf(facts, file3) {
|
|
49528
49632
|
const key = excerptKey(file3);
|
|
@@ -49594,13 +49698,25 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49594
49698
|
errors3.push(`${what}: ${ref} is not a source of this project`);
|
|
49595
49699
|
return null;
|
|
49596
49700
|
}
|
|
49597
|
-
const at =
|
|
49701
|
+
const at = locate(s.text, q);
|
|
49598
49702
|
if (!at) {
|
|
49599
49703
|
errors3.push(`${what}: quote not found in ${ref}: "${head(q, 80)}"`);
|
|
49600
49704
|
return null;
|
|
49601
49705
|
}
|
|
49602
49706
|
return { s, at };
|
|
49603
49707
|
};
|
|
49708
|
+
const own2 = async (ref, q, policy, what, who) => {
|
|
49709
|
+
const s = await source(ref);
|
|
49710
|
+
if (!s) {
|
|
49711
|
+
errors3.push(`${what}: ${ref} is not a source of this project`);
|
|
49712
|
+
return null;
|
|
49713
|
+
}
|
|
49714
|
+
const words = policy === "owner" ? ownWords(s, q, "owner") : ownWords(s, q, "maintainer");
|
|
49715
|
+
if (!refused(words))
|
|
49716
|
+
return words;
|
|
49717
|
+
errors3.push(words.refused === "missing" ? `${what}: quote not found in ${ref}: "${head(q, 80)}"` : words.refused === "event" ? `${what}: the merge does not adopt a proposal` : words.refused === "author" ? `${what}: ${who}` : `${what}: the quote in ${ref} is quoted or in a code block, so it is someone else's words; quote the writer's own`);
|
|
49718
|
+
return null;
|
|
49719
|
+
};
|
|
49604
49720
|
const replaced = new Map;
|
|
49605
49721
|
const retired = new Set;
|
|
49606
49722
|
const anchored = new Set;
|
|
@@ -49622,6 +49738,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49622
49738
|
continue;
|
|
49623
49739
|
}
|
|
49624
49740
|
let excerpt = null;
|
|
49741
|
+
let said2 = null;
|
|
49625
49742
|
if (op.op === "add_evidence") {
|
|
49626
49743
|
if (!op.source === !op.file)
|
|
49627
49744
|
errors3.push(`${what}: cite either a source or a file`);
|
|
@@ -49633,7 +49750,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49633
49750
|
excerpt = read;
|
|
49634
49751
|
if ((await forgottenExcerpt(db, target.projectId, excerpt)).same)
|
|
49635
49752
|
errors3.push(`${what}: the owner forgot ${excerpt.path} lines ${op.file.lines.join("-")}; cite something else`);
|
|
49636
|
-
else if (!
|
|
49753
|
+
else if (!locate(excerpt.raw, op.quote))
|
|
49637
49754
|
errors3.push(`${what}: quote not found in ${excerpt.path} lines ${op.file.lines.join("-")}`);
|
|
49638
49755
|
else if (!quoteSpan(excerpt.raw, excerpt.text, op.quote))
|
|
49639
49756
|
errors3.push(`${what}: the quote also appears in text Sphica masks; quote a longer or different part`);
|
|
@@ -49649,11 +49766,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49649
49766
|
if (op.op === "adopt") {
|
|
49650
49767
|
if (!["decision", "constraint"].includes(u.kind))
|
|
49651
49768
|
errors3.push(`${what}: adoption applies to decisions and constraints`);
|
|
49652
|
-
|
|
49653
|
-
if (got && got.s.kind === "pr_event")
|
|
49654
|
-
errors3.push(`${what}: the merge does not adopt a proposal`);
|
|
49655
|
-
else if (got && got.s.author_kind !== "owner" && !MAINTAINERS2.has(got.s.author_association ?? ""))
|
|
49656
|
-
errors3.push(`${what}: only the owner or a maintainer can adopt`);
|
|
49769
|
+
said2 = await own2(op.source, op.quote, "maintainer", what, "only the owner or a maintainer can adopt");
|
|
49657
49770
|
}
|
|
49658
49771
|
if (op.op === "anchor" && !repoPath(op.path))
|
|
49659
49772
|
errors3.push(`${what}: the path is not inside the repository`);
|
|
@@ -49671,9 +49784,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49671
49784
|
if (op.op === "replace_anchor" || op.op === "retire_anchor") {
|
|
49672
49785
|
if (op.op === "replace_anchor" && !repoPath(op.to.path))
|
|
49673
49786
|
errors3.push(`${what}: the path is not inside the repository`);
|
|
49674
|
-
|
|
49675
|
-
if (said2 && said2.s.author_kind !== "owner")
|
|
49676
|
-
errors3.push(`${what}: only the owner's words can ${op.op === "retire_anchor" ? "retire" : "move"} an anchor`);
|
|
49787
|
+
said2 = await own2(op.source, op.quote, "owner", what, `only the owner's words can ${op.op === "retire_anchor" ? "retire" : "move"} an anchor`);
|
|
49677
49788
|
const from = repoPath(op.from.path);
|
|
49678
49789
|
if (!from)
|
|
49679
49790
|
errors3.push(`${what}: the from path is not inside the repository`);
|
|
@@ -49738,9 +49849,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49738
49849
|
});
|
|
49739
49850
|
}
|
|
49740
49851
|
if (op.op === "retract_evidence" || op.op === "retract_adoption" || op.op === "withdraw" || op.op === "resolve_conflict") {
|
|
49741
|
-
|
|
49742
|
-
if (got && got.s.author_kind !== "owner")
|
|
49743
|
-
errors3.push(`${what}: only the owner's words can retract, withdraw, or resolve`);
|
|
49852
|
+
said2 = await own2(op.reason_source, op.reason_quote, "owner", what, "only the owner's words can retract, withdraw, or resolve");
|
|
49744
49853
|
}
|
|
49745
49854
|
if (op.op === "withdraw") {
|
|
49746
49855
|
if (u.lifecycle === "superseded")
|
|
@@ -49785,6 +49894,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
|
|
|
49785
49894
|
unitId: u.id,
|
|
49786
49895
|
lifecycle: u.lifecycle,
|
|
49787
49896
|
excerpt,
|
|
49897
|
+
said: said2,
|
|
49788
49898
|
retracts,
|
|
49789
49899
|
replaces,
|
|
49790
49900
|
retires,
|
|
@@ -49856,10 +49966,10 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49856
49966
|
const units = await saveRecord(trx, target, runId, c.units, [], { settle: false });
|
|
49857
49967
|
const now = iso(Date.now());
|
|
49858
49968
|
const changed2 = [];
|
|
49859
|
-
const
|
|
49860
|
-
|
|
49861
|
-
|
|
49862
|
-
return
|
|
49969
|
+
const saidOf = (p) => {
|
|
49970
|
+
if (!p.said)
|
|
49971
|
+
throw new Error(`${p.input.op} ${p.input.unit}: saved without checked words`);
|
|
49972
|
+
return p.said;
|
|
49863
49973
|
};
|
|
49864
49974
|
const touched = new Map;
|
|
49865
49975
|
const withdraw = new Map;
|
|
@@ -49870,12 +49980,11 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49870
49980
|
...c.ops.filter((p) => p.input.op === "replace_anchor"),
|
|
49871
49981
|
...c.ops.filter((p) => !moves.includes(p.input.op))
|
|
49872
49982
|
];
|
|
49873
|
-
const reason2 = async (anchorId,
|
|
49874
|
-
const s = await spanOf(ref, q);
|
|
49983
|
+
const reason2 = async (anchorId, s) => {
|
|
49875
49984
|
await trx.insertInto("unit_anchor_retirement").values({
|
|
49876
49985
|
anchor_id: anchorId ?? -1,
|
|
49877
49986
|
run_id: runId,
|
|
49878
|
-
source_id: s.
|
|
49987
|
+
source_id: s.source,
|
|
49879
49988
|
span_start: s.start,
|
|
49880
49989
|
span_end: s.end,
|
|
49881
49990
|
added_at: now
|
|
@@ -49886,7 +49995,7 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49886
49995
|
touched.set(p.unitId, op.unit);
|
|
49887
49996
|
if (op.op === "add_evidence") {
|
|
49888
49997
|
const s = p.excerpt ? { id: await excerptSource(trx, target.projectId, p.excerpt), text: p.excerpt.text } : await trx.selectFrom("source").select(["id", "text"]).where("id", "=", Number(op.source?.slice(1))).executeTakeFirstOrThrow();
|
|
49889
|
-
const at = (p.excerpt ? quoteSpan(p.excerpt.raw, s.text, op.quote) :
|
|
49998
|
+
const at = (p.excerpt ? quoteSpan(p.excerpt.raw, s.text, op.quote) : locate(s.text, op.quote)) ?? [
|
|
49890
49999
|
0,
|
|
49891
50000
|
0
|
|
49892
50001
|
];
|
|
@@ -49902,12 +50011,11 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49902
50011
|
}).onConflict((oc) => oc.doNothing()).execute();
|
|
49903
50012
|
changed2.push(`${op.unit}: evidence added`);
|
|
49904
50013
|
} else if (op.op === "adopt") {
|
|
49905
|
-
const s =
|
|
49906
|
-
const author = await trx.selectFrom("source").select("author_kind").where("id", "=", s.id).executeTakeFirstOrThrow();
|
|
50014
|
+
const s = saidOf(p);
|
|
49907
50015
|
await trx.insertInto("unit_adoption").values({
|
|
49908
50016
|
unit_id: p.unitId,
|
|
49909
|
-
route:
|
|
49910
|
-
source_id: s.
|
|
50017
|
+
route: s.route,
|
|
50018
|
+
source_id: s.source,
|
|
49911
50019
|
span_start: s.start,
|
|
49912
50020
|
span_end: s.end,
|
|
49913
50021
|
run_id: runId,
|
|
@@ -49940,12 +50048,12 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49940
50048
|
}).returning("id").executeTakeFirstOrThrow();
|
|
49941
50049
|
if (op.op === "replace_anchor") {
|
|
49942
50050
|
await trx.updateTable("unit_anchor").set({ retired_at: now, replaced_by: added.id }).where("id", "=", p.replaces ?? -1).where("retired_at", "is", null).execute();
|
|
49943
|
-
await reason2(p.replaces,
|
|
50051
|
+
await reason2(p.replaces, saidOf(p));
|
|
49944
50052
|
}
|
|
49945
50053
|
changed2.push(`${op.unit}: anchor ${op.op === "anchor" ? "added" : "replaced"}`);
|
|
49946
50054
|
} else if (op.op === "retire_anchor") {
|
|
49947
50055
|
await trx.updateTable("unit_anchor").set({ retired_at: now }).where("id", "=", p.retires ?? -1).where("retired_at", "is", null).execute();
|
|
49948
|
-
await reason2(p.retires,
|
|
50056
|
+
await reason2(p.retires, saidOf(p));
|
|
49949
50057
|
changed2.push(`${op.unit}: anchor retired`);
|
|
49950
50058
|
} else if (op.op === "replace_aliases") {
|
|
49951
50059
|
const { content_hash } = await trx.selectFrom("unit").select("content_hash").where("id", "=", p.unitId).executeTakeFirstOrThrow();
|
|
@@ -49958,17 +50066,17 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49958
50066
|
}).execute();
|
|
49959
50067
|
changed2.push(`${op.unit}: aliases ${p.aliases?.length ? "replaced" : "cleared"}`);
|
|
49960
50068
|
} else {
|
|
49961
|
-
const reason3 =
|
|
50069
|
+
const reason3 = saidOf(p);
|
|
49962
50070
|
const retraction = {
|
|
49963
50071
|
retracted_at: now,
|
|
49964
50072
|
retraction_reason: op.reason_quote,
|
|
49965
|
-
retraction_source_id: reason3.
|
|
50073
|
+
retraction_source_id: reason3.source,
|
|
49966
50074
|
retraction_span_start: reason3.start,
|
|
49967
50075
|
retraction_span_end: reason3.end
|
|
49968
50076
|
};
|
|
49969
50077
|
if (op.op === "resolve_conflict") {
|
|
49970
50078
|
const other = await trx.selectFrom("unit").select("id").where("project_id", "=", target.projectId).where("key", "=", op.with).executeTakeFirstOrThrow();
|
|
49971
|
-
await trx.updateTable("unit_link").set({ resolved_at: now, resolution: `${head(op.reason_quote, 400)} (s${reason3.
|
|
50079
|
+
await trx.updateTable("unit_link").set({ resolved_at: now, resolution: `${head(op.reason_quote, 400)} (s${reason3.source})` }).where("kind", "=", "conflicts").where("resolved_at", "is", null).where((eb) => eb.or([
|
|
49972
50080
|
eb.and([eb("from_unit", "=", p.unitId), eb("to_unit", "=", other.id)]),
|
|
49973
50081
|
eb.and([eb("from_unit", "=", other.id), eb("to_unit", "=", p.unitId)])
|
|
49974
50082
|
])).execute();
|
|
@@ -49976,7 +50084,7 @@ ${c.errors.map((e) => ` ${e}`).join(`
|
|
|
49976
50084
|
continue;
|
|
49977
50085
|
}
|
|
49978
50086
|
if (op.op === "withdraw") {
|
|
49979
|
-
withdraw.set(p.unitId, { reason: `withdrawn: ${head(op.reason_quote, 200)}`, source: reason3.
|
|
50087
|
+
withdraw.set(p.unitId, { reason: `withdrawn: ${head(op.reason_quote, 200)}`, source: reason3.source });
|
|
49980
50088
|
continue;
|
|
49981
50089
|
}
|
|
49982
50090
|
const table = op.op === "retract_evidence" ? "unit_evidence" : "unit_adoption";
|
|
@@ -50490,7 +50598,7 @@ async function validate2(trx, id, projectId2, root, record4, prepared, call) {
|
|
|
50490
50598
|
ops: null,
|
|
50491
50599
|
write: async (w) => {
|
|
50492
50600
|
const shown = shownTo.get(id)?.sources ?? new Set;
|
|
50493
|
-
const
|
|
50601
|
+
const cited2 = new Set([
|
|
50494
50602
|
...checked.units.flatMap((u) => [
|
|
50495
50603
|
...u.evidence,
|
|
50496
50604
|
...u.adoption,
|
|
@@ -50499,14 +50607,14 @@ async function validate2(trx, id, projectId2, root, record4, prepared, call) {
|
|
|
50499
50607
|
]),
|
|
50500
50608
|
...checked.fieldDefs
|
|
50501
50609
|
].map((q) => q.source));
|
|
50502
|
-
const saved = await saveRecord(w, scope.target, run2.id, checked, scope.looked.filter((s) => shown.has(s) ||
|
|
50610
|
+
const saved = await saveRecord(w, scope.target, run2.id, checked, scope.looked.filter((s) => shown.has(s) || cited2.has(s)));
|
|
50503
50611
|
return { saved, changed: [] };
|
|
50504
50612
|
}
|
|
50505
50613
|
};
|
|
50506
50614
|
}
|
|
50507
50615
|
async function checkText(db, id, projectId2, root, record4, call, probe) {
|
|
50508
50616
|
const prepared = await prepare2(db, id, projectId2, root, record4, probe, call);
|
|
50509
|
-
const { v, done, refused } = await inRolledBack(db, async (trx) => {
|
|
50617
|
+
const { v, done, refused: refused2 } = await inRolledBack(db, async (trx) => {
|
|
50510
50618
|
const v2 = await validate2(trx, id, projectId2, root, record4, prepared, call);
|
|
50511
50619
|
if (v2.errors.length)
|
|
50512
50620
|
return { v: v2, done: null, refused: null };
|
|
@@ -50520,7 +50628,7 @@ async function checkText(db, id, projectId2, root, record4, call, probe) {
|
|
|
50520
50628
|
return { v: v2, done: null, refused: e.message };
|
|
50521
50629
|
}
|
|
50522
50630
|
});
|
|
50523
|
-
const errors3 = [...v.errors, ...
|
|
50631
|
+
const errors3 = [...v.errors, ...refused2 === null ? [] : [refused2]];
|
|
50524
50632
|
const lines = [
|
|
50525
50633
|
...errors3.map((e) => `✗ ${e}`),
|
|
50526
50634
|
...[...new Set(v.problems)].map((p) => `△ ${p}`),
|
|
@@ -50901,9 +51009,9 @@ server.registerTool("forget_apply", {
|
|
|
50901
51009
|
const seen = await previewForget(dbFile(), p.projectId, ids);
|
|
50902
51010
|
const n = seen.sources.length;
|
|
50903
51011
|
if (n > 0) {
|
|
50904
|
-
const
|
|
51012
|
+
const refused2 = (why) => new Error(`${why}, so nothing was forgotten`);
|
|
50905
51013
|
if (!server.server.getClientCapabilities()?.elicitation)
|
|
50906
|
-
throw
|
|
51014
|
+
throw refused2("This host cannot ask you directly (run /sphica:forget in Claude Code)");
|
|
50907
51015
|
let answer;
|
|
50908
51016
|
try {
|
|
50909
51017
|
answer = await server.server.elicitInput({
|
|
@@ -50923,14 +51031,14 @@ ${forgetText(seen, dbFile())}`,
|
|
|
50923
51031
|
}
|
|
50924
51032
|
}, { timeout: ANSWER_MS, signal: extra.signal });
|
|
50925
51033
|
} catch (e) {
|
|
50926
|
-
throw
|
|
51034
|
+
throw refused2(`The confirmation did not come back (${head(reason(e), 200)})`);
|
|
50927
51035
|
}
|
|
50928
51036
|
if (extra.signal.aborted)
|
|
50929
|
-
throw
|
|
51037
|
+
throw refused2("The call was cancelled");
|
|
50930
51038
|
if (answer.action !== "accept")
|
|
50931
|
-
throw
|
|
51039
|
+
throw refused2(`You ${answer.action === "decline" ? "declined" : "cancelled"}`);
|
|
50932
51040
|
if (String(answer.content?.confirm ?? "").trim() !== String(n))
|
|
50933
|
-
throw
|
|
51041
|
+
throw refused2(`The number typed does not match ${n}`);
|
|
50934
51042
|
}
|
|
50935
51043
|
const done = await applyForget(dbFile(), p.projectId, ids, seen, extra.signal);
|
|
50936
51044
|
return [
|
package/dist/mcp.js
CHANGED
|
@@ -46321,6 +46321,9 @@ var FIELD_TYPES = ["text", "enum", "integer", "date"];
|
|
|
46321
46321
|
var HOSTS = ["claude-code", "codex"];
|
|
46322
46322
|
var sessionId = (projectId, host, externalId) => uuidFrom(String(projectId), host, externalId);
|
|
46323
46323
|
|
|
46324
|
+
// server/src/own-words.ts
|
|
46325
|
+
var MAINTAINERS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
46326
|
+
|
|
46324
46327
|
// server/src/anchors.ts
|
|
46325
46328
|
import fs4 from "node:fs";
|
|
46326
46329
|
import path4 from "node:path";
|
|
@@ -46543,7 +46546,6 @@ var instructionFile = (relative) => {
|
|
|
46543
46546
|
var KEY = /^[a-z0-9][a-z0-9._/-]{0,63}$/;
|
|
46544
46547
|
var FIELD_NAME = /^[a-z][a-z0-9_]{0,39}$/;
|
|
46545
46548
|
var SOURCE_REF = /^s[1-9][0-9]{0,15}$/;
|
|
46546
|
-
var MAINTAINERS = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
|
|
46547
46549
|
var text2 = (max) => exports_external.string().trim().min(1).max(max);
|
|
46548
46550
|
var Quote = exports_external.object({ source: exports_external.string().regex(SOURCE_REF, "cite a source ref such as s12"), quote: exports_external.string() }).strict();
|
|
46549
46551
|
var Evidence = Quote.extend({
|
|
@@ -47049,6 +47051,7 @@ async function describe3(db, u, root, asOf, renames) {
|
|
|
47049
47051
|
"b.id as to_id",
|
|
47050
47052
|
"a.key as from_key",
|
|
47051
47053
|
"b.key as to_key",
|
|
47054
|
+
sql`a.extraction = 'supported' and a.unsourced = 0 and b.extraction = 'supported' and b.unsourced = 0`.as("sound"),
|
|
47052
47055
|
eb.selectFrom("unit_state as t").whereRef("t.unit_id", "=", "a.id").where("t.at", "<=", asOf ?? "9999").select("t.to_state").orderBy("t.id", "desc").limit(1).as("from_lifecycle")
|
|
47053
47056
|
]).execute(),
|
|
47054
47057
|
db.selectFrom("unit_state").select(["from_state", "to_state", "at", "reason"]).where("unit_id", "=", u.id).orderBy("id").execute(),
|
|
@@ -47152,7 +47155,7 @@ async function describe3(db, u, root, asOf, renames) {
|
|
|
47152
47155
|
for (const l of conflicting) {
|
|
47153
47156
|
const other = l.from_id === u.id ? l.to_id : l.from_id;
|
|
47154
47157
|
const held = mine !== "owner" || sides.get(other) === "owner";
|
|
47155
|
-
out.push(`Conflicts with ${l.from_id === u.id ? l.to_key : l.from_key}${l.resolved_at ? " (resolved)" : held ? " (unresolved: held back from automatic delivery until resolved, not withdrawn)" : " (unresolved: still delivered, since only the owner's words hold the owner's decision back)"}`);
|
|
47158
|
+
out.push(`Conflicts with ${l.from_id === u.id ? l.to_key : l.from_key}${l.resolved_at ? " (resolved)" : !l.sound ? " (unresolved, but it holds nothing back: one side is quarantined or unsourced, so it is never delivered)" : held ? " (unresolved: held back from automatic delivery until resolved, not withdrawn)" : " (unresolved: still delivered, since only the owner's words hold the owner's decision back)"}`);
|
|
47156
47159
|
}
|
|
47157
47160
|
const aliases = await db.selectFrom("unit_alias").select("terms").where("unit_id", "=", u.id).where("content_hash", "=", u.content_hash).where("added_at", "<=", asOf ?? "9999").orderBy("id", "desc").executeTakeFirst();
|
|
47158
47161
|
const terms2 = aliases ? JSON.parse(aliases.terms) : [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sphica",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.48",
|
|
4
4
|
"description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/skills/glean/SKILL.md
CHANGED
|
@@ -79,8 +79,15 @@ read tools `search` and `read`. Pass the repository root as `cwd` to every tool.
|
|
|
79
79
|
| `resolve_conflict` | Ends an unresolved conflict between `unit` and `with`, citing the owner's words (`reason_source`, `reason_quote`). Until then each is held back from being shown on its own, except the owner's decision, which only another record the owner adopted holds back |
|
|
80
80
|
| `withdraw` | Withdraws a record the owner says no longer holds, citing the owner's words. A superseded record is refused: withdraw the record that replaced it |
|
|
81
81
|
|
|
82
|
+
Words that give an op its authority have to be their writer's own: the `quote` of `adopt`, `replace_anchor`, and `retire_anchor`, and the
|
|
83
|
+
`reason_quote` of `retract_evidence`, `retract_adoption`, `resolve_conflict`, and `withdraw`. Check refuses a quote that touches a `>` line
|
|
84
|
+
or a fenced code block, or that sits wholly inside quotation marks on its line or right between two of them (straight or curly quotes,
|
|
85
|
+
Japanese corner brackets, backticks, apostrophes): quote more of the owner's own words around it instead. Evidence (`add_evidence`) and the `quote` that says which piece to retract may still be quoted text.
|
|
86
|
+
Check reads where the words sit, not what they mean: whether they settle this record is yours to judge.
|
|
87
|
+
|
|
82
88
|
Every op carries the `revision` read printed; a record changed since is refused, so read it again. To correct what a record says, write a new
|
|
83
|
-
record in `units` (trace's shape, keys saved as `glean:<key>`) with `supersedes` naming the old one (citing the owner's words, a maintainer's, or the owner's session, not other people's text
|
|
89
|
+
record in `units` (trace's shape, keys saved as `glean:<key>`) with `supersedes` naming the old one (citing the owner's words, a maintainer's, or the owner's session, not other people's text: words that are in the source, and not only a
|
|
90
|
+
quotation there); records are never rewritten.
|
|
84
91
|
|
|
85
92
|
## When a source turns up for an unsourced record
|
|
86
93
|
|
package/skills/harvest/SKILL.md
CHANGED
|
@@ -54,7 +54,9 @@ and only by saying so: "we rejected yarn", "let's keep SQLite". check refuses th
|
|
|
54
54
|
`sphica init` bound. It adopts like the owner's words anywhere, even where their association is CONTRIBUTOR
|
|
55
55
|
- The merge only shows the code went in. It is evidence for an `implementation` (with the commit message, `role: "implements"`), never adoption
|
|
56
56
|
- A resolved review thread is not agreement either
|
|
57
|
-
- `supersedes` and `conflicts` retire or dispute a saved record, so they need the owner's or a maintainer's words among the unit's evidence or adoption
|
|
57
|
+
- `supersedes` and `conflicts` retire or dispute a saved record, so they need the owner's or a maintainer's words among the unit's evidence or adoption.
|
|
58
|
+
Those words have to be in the source and be the writer's own: a maintainer quoting someone else (a `>` line, a code block, words wholly
|
|
59
|
+
inside quotation marks or right between two of them) does not count, and neither does a quote that is not there
|
|
58
60
|
|
|
59
61
|
## What to record
|
|
60
62
|
|
package/skills/trace/SKILL.md
CHANGED
|
@@ -100,14 +100,14 @@ The `"..."` stands for the other language's words: in this example, `"データ
|
|
|
100
100
|
| `stance` | Decisions and constraints only: `do`, `dont`, or `defer`. A deferral may add `revisit_when` |
|
|
101
101
|
| `text`, `why`, `scope_note` | In the conversation's language. `text` states the record in one sentence; `why` is the reason given, not one you infer |
|
|
102
102
|
| `evidence` | Required. `source` is a ref from context, `quote` is copied **exactly** from that message (a phrase is enough). `role`: `states`, `proposes`, `rejects`, `explains`, `implements`, `decides` (the AI's reply deciding it; see below). When the owner reports what someone else said, add `reported_speaker` |
|
|
103
|
-
| `options` | Options compared, with `outcome` `chosen` / `rejected` / `deferred` / `proposed` and the `why` given. Evidence is optional per option. A rejected option may add `reconsider_when` (when it would be worth looking at again) with `reconsider_quote` (`source`, `quote`): **only a condition the owner stated, quoting the owner's words**. Never infer one, and never take it from the AI's suggestion or from someone else's words the owner passes on. A `reconsider_quote` not found in the message refuses the save (unlike other quotes, which quarantine the record) |
|
|
104
|
-
| `adoption` | Decisions and constraints only: the words that settle it. The owner's message adopts it as the owner's decision. The AI's own reply adopts it as an AI's decision only under the rules below. The AI proposing something and the owner not objecting is not adoption; leave it out and the record stays a candidate. Words the owner quoted (`>` lines)
|
|
103
|
+
| `options` | Options compared, with `outcome` `chosen` / `rejected` / `deferred` / `proposed` and the `why` given. Evidence is optional per option. A rejected option may add `reconsider_when` (when it would be worth looking at again) with `reconsider_quote` (`source`, `quote`): **only a condition the owner stated, quoting the owner's words**. Never infer one, and never take it from the AI's suggestion or from someone else's words the owner passes on (a `>` line, a code block, or words wholly inside quotation marks refuse the save). A `reconsider_quote` not found in the message refuses the save (unlike other quotes, which quarantine the record) |
|
|
104
|
+
| `adoption` | Decisions and constraints only: the words that settle it. The owner's message adopts it as the owner's decision. The AI's own reply adopts it as an AI's decision only under the rules below. The AI proposing something and the owner not objecting is not adoption; leave it out and the record stays a candidate. Words the owner quoted (`>` lines), pasted in a code block, or put wholly inside quotation marks on a line (straight or curly quotes, Japanese corner brackets, backticks) are someone else's and never adopt, and neither do words that stand right between two such marks or apostrophes: quote more of the owner's own words around them. Check reads where the words sit, not what they mean |
|
|
105
105
|
| `anchors` | Only where the record has a code location: `path` relative to the repository root, `symbol` when there is one, `role` `applies_to` (where it applies) or `evidence` (code that shows it was done; add `commit` when known). When an adopted decision or constraint governs how one existing code location behaves (keeping it as it is included), give it `applies_to` there, even if this work did not change it: delivery shows it when that file is read or edited. Confirm the path in the repository; do not infer one from a broad topic, and leave it unanchored when several places are plausible. `no_code_surface` may say why there is none. A `symbol` must be a name in the code, never a key or a value Sphica masks: such a symbol is dropped and the anchor keeps only its path (save reports it) |
|
|
106
106
|
| `aliases` | 8 to 12 short search words in **both Japanese and English** a later reader might type: synonyms, the other language's words, abbreviations. Search only; never evidence. Not broad words that match everything (`code`, `fix`, `update`) |
|
|
107
107
|
| `supersedes` | The key of a live record this one replaces (context lists them). The old one is marked superseded, never deleted |
|
|
108
108
|
| `conflicts` | Keys of live records this one contradicts without replacing them. Until resolved, both are held back from automatic injection, except the owner's decision, which only another record the owner adopted holds back |
|
|
109
109
|
| `work` | The current work status, optional. The same `key` updates it |
|
|
110
|
-
| `field_defs` | Top level, beside `units`. Only when the owner said in this session to keep a field on records: `name` (a lowercase letter, then lowercase letters, digits, `_`; at most 40), `type` (`text`, `enum`, `integer`, `date`), `label`, `description`, `enum` (1 to 30 distinct allowed values, only for `enum`), `kinds` (the unit kinds it applies to; empty means every kind), and `quote` of **the owner's** words defining it. A field context already lists cannot be defined again |
|
|
110
|
+
| `field_defs` | Top level, beside `units`. Only when the owner said in this session to keep a field on records: `name` (a lowercase letter, then lowercase letters, digits, `_`; at most 40), `type` (`text`, `enum`, `integer`, `date`), `label`, `description`, `enum` (1 to 30 distinct allowed values, only for `enum`), `kinds` (the unit kinds it applies to; empty means every kind), and `quote` of **the owner's** words defining it (their own, not a quotation inside their message). A field context already lists cannot be defined again |
|
|
111
111
|
| `fields` | On a unit, only for fields context lists or this record's `field_defs` defines: `name`, `value`, and `quote` of the words that say it. The value must be written in the quote as it is: an `integer` whole (not the `95` of `p95`, not the `1` of `1.5` or `1,000`; `1,000` is `1000`), a `date` as `YYYY-MM-DD`, an `enum` value exactly, and a date or enum value on its own (not the `no` of `not`). When no message says the value, leave the field out; never infer one |
|
|
112
112
|
|
|
113
113
|
A field value that breaks these rules refuses the whole save, like a `reconsider_quote` not found: fix it or leave the field out.
|