sphica 0.6.57 → 0.6.59
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 +5 -2
- package/db/migrations/0014.sql +58 -0
- package/db/schema.sql +37 -3
- package/dist/capture.js +75 -11
- package/dist/cli.js +76 -12
- package/dist/deliver.js +227 -27
- package/dist/mcp-record.js +121 -18
- package/dist/mcp.js +28 -11
- package/package.json +1 -1
- package/skills/harvest/SKILL.md +1 -1
- package/skills/trace/SKILL.md +3 -2
package/dist/mcp.js
CHANGED
|
@@ -46269,7 +46269,7 @@ var HOST_MARKS = new Set([".orphaned_at", ".in_use"]);
|
|
|
46269
46269
|
|
|
46270
46270
|
// server/src/sqlite.ts
|
|
46271
46271
|
var SCHEMA_GENERATION = 2;
|
|
46272
|
-
var SCHEMA_REVISION =
|
|
46272
|
+
var SCHEMA_REVISION = 14;
|
|
46273
46273
|
var sphicaHome = () => process.env.SPHICA_HOME || path3.join(os2.homedir(), ".sphica");
|
|
46274
46274
|
var dbFile = () => process.env.SPHICA_DB || path3.join(sphicaHome(), "sphica.db");
|
|
46275
46275
|
function requireRuntime() {
|
|
@@ -46290,6 +46290,9 @@ function prepare(raw, check2, busyMs = 5000) {
|
|
|
46290
46290
|
checkGeneration(raw);
|
|
46291
46291
|
if (check2 === "generation")
|
|
46292
46292
|
return;
|
|
46293
|
+
requireRevision(raw);
|
|
46294
|
+
}
|
|
46295
|
+
function requireRevision(raw) {
|
|
46293
46296
|
const got = raw.prepare("pragma user_version").get()?.user_version;
|
|
46294
46297
|
if (got === SCHEMA_REVISION)
|
|
46295
46298
|
return;
|
|
@@ -46671,6 +46674,7 @@ var Unit = exports_external.object({
|
|
|
46671
46674
|
commit: exports_external.string().regex(/^[0-9a-f]{40}$/, "a full 40-character commit sha").optional(),
|
|
46672
46675
|
lines: exports_external.tuple([exports_external.number().int().positive(), exports_external.number().int().positive()]).optional()
|
|
46673
46676
|
}).strict()).max(20).default([]),
|
|
46677
|
+
commands: exports_external.array(exports_external.string()).max(5).default([]),
|
|
46674
46678
|
aliases: exports_external.array(exports_external.string()).max(12).default([]),
|
|
46675
46679
|
supersedes: exports_external.string().min(1).optional(),
|
|
46676
46680
|
conflicts: exports_external.array(exports_external.string().min(1)).max(5).default([]),
|
|
@@ -46940,12 +46944,13 @@ async function pastSuccessor(db, id, asOf) {
|
|
|
46940
46944
|
}
|
|
46941
46945
|
async function judgeUnits(db, rows, wanted, hits, asOf) {
|
|
46942
46946
|
const ids = rows.map((r) => r.id);
|
|
46943
|
-
const [options, anchors, aliases, fields] = ids.length ? await Promise.all([
|
|
46947
|
+
const [options, anchors, aliases, fields, commands] = ids.length ? await Promise.all([
|
|
46944
46948
|
db.selectFrom("unit_option").select(["unit_id", "text", "outcome", "why", "reconsider_when"]).where("unit_id", "in", ids).orderBy("position").execute(),
|
|
46945
46949
|
db.selectFrom("unit_anchor").select(["unit_id", "path", "symbol", "role"]).where("unit_id", "in", ids).$if(asOf === undefined, (a) => a.where("retired_at", "is", null)).$if(asOf !== undefined, (a) => a.where("added_at", "<=", asOf ?? "").where((eb) => eb.or([eb("retired_at", "is", null), eb("retired_at", ">", asOf ?? "")]))).orderBy("id").execute(),
|
|
46946
46950
|
db.selectFrom("unit_alias").select(["unit_id", "terms", "content_hash"]).where("unit_id", "in", ids).$if(asOf !== undefined, (a) => a.where("added_at", "<=", asOf ?? "")).orderBy("id", "desc").execute(),
|
|
46947
|
-
db.selectFrom("unit_field as f").innerJoin("field_def as d", "d.id", "f.field_def_id").select(["f.unit_id", "d.name", "f.value"]).where("f.unit_id", "in", ids).execute()
|
|
46948
|
-
|
|
46951
|
+
db.selectFrom("unit_field as f").innerJoin("field_def as d", "d.id", "f.field_def_id").select(["f.unit_id", "d.name", "f.value"]).where("f.unit_id", "in", ids).execute(),
|
|
46952
|
+
db.selectFrom("unit_command").select(["unit_id", "command"]).where("unit_id", "in", ids).execute()
|
|
46953
|
+
]) : [[], [], [], [], []];
|
|
46949
46954
|
let weaker = 0;
|
|
46950
46955
|
for (const r of rows) {
|
|
46951
46956
|
const opts = options.filter((o) => o.unit_id === r.id);
|
|
@@ -46958,6 +46963,7 @@ async function judgeUnits(db, rows, wanted, hits, asOf) {
|
|
|
46958
46963
|
r.revisit_when,
|
|
46959
46964
|
...opts.flatMap((o) => [o.text, o.why, o.reconsider_when]),
|
|
46960
46965
|
...anch.flatMap((a) => [a.path, a.symbol]),
|
|
46966
|
+
...commands.filter((c) => c.unit_id === r.id).map((c) => c.command),
|
|
46961
46967
|
...fields.filter((f) => f.unit_id === r.id).flatMap((f) => [f.name, f.value])
|
|
46962
46968
|
].filter(Boolean).join(`
|
|
46963
46969
|
`)));
|
|
@@ -47307,6 +47313,7 @@ var DAY_MS = 24 * 60 * 60 * 1000;
|
|
|
47307
47313
|
var MORE_LINE = 120;
|
|
47308
47314
|
var WHO = ["main", "subagent", "subagent, id unknown"];
|
|
47309
47315
|
var who = (named, event, reason2) => named ? "subagent" : event === "session_start" && reason2 === "subagent" ? "subagent, id unknown" : "main";
|
|
47316
|
+
var eventName = (event, reason2) => reason2 === "command" ? `${event} (command, stopped)` : reason2 === "command_context" ? `${event} (command, not stopped)` : event;
|
|
47310
47317
|
var DELIVERY_LIMITS_TEXT = [
|
|
47311
47318
|
"Counted are the logged delivery rows only: since 0.6.16 a read or edit that showed nothing is not logged (older rows show it as nothing), and a delivery answered while the write lock was busy, or whose log write failed, is not either.",
|
|
47312
47319
|
"A session's rows are dropped once its last delivery is older than 90 days, so a long period is not a rolling window.",
|
|
@@ -47360,7 +47367,7 @@ async function deliveryOverview(db, projectId, days, now = new Date) {
|
|
|
47360
47367
|
keyed().select((eb) => ["s.id", "s.host", "s.external_id", "s.branch", eb.fn.max("d.at").as("last")]).groupBy("s.id").orderBy("last", "desc").orderBy("s.id").limit(DELIVERY_LIMITS.sessions).execute(),
|
|
47361
47368
|
keyed().select((eb) => eb.fn.count("d.session_id").distinct().as("n")).executeTakeFirst()
|
|
47362
47369
|
]);
|
|
47363
|
-
const via = top.length ? await delivered().where("du.unit_id", "in", top.map((t) => t.id)).select(["du.unit_id", "d.event"]).distinct().
|
|
47370
|
+
const via = top.length ? await delivered().where("du.unit_id", "in", top.map((t) => t.id)).select(["du.unit_id", "d.event", "d.reason"]).distinct().execute() : [];
|
|
47364
47371
|
const shown2 = await Promise.all(recent.map(async (r) => {
|
|
47365
47372
|
const rows = keyed().where("d.session_id", "=", r.id);
|
|
47366
47373
|
const [list2, n] = await Promise.all([
|
|
@@ -47410,8 +47417,12 @@ async function deliveryOverview(db, projectId, days, now = new Date) {
|
|
|
47410
47417
|
return true;
|
|
47411
47418
|
};
|
|
47412
47419
|
const events = new Map;
|
|
47413
|
-
for (const v of via)
|
|
47414
|
-
|
|
47420
|
+
for (const v of via) {
|
|
47421
|
+
const name = eventName(v.event, v.reason);
|
|
47422
|
+
const seen = events.get(v.unit_id) ?? [];
|
|
47423
|
+
if (!seen.includes(name))
|
|
47424
|
+
events.set(v.unit_id, [...seen, name].sort());
|
|
47425
|
+
}
|
|
47415
47426
|
const topLines = [];
|
|
47416
47427
|
for (const t of top) {
|
|
47417
47428
|
const line = `- ${head(inline(t.key), DELIVERY_LIMITS.key)} (u${t.id}, ${t.kind}, ${t.lifecycle} now): ${t.sessions} session${Number(t.sessions) === 1 ? "" : "s"}, ${t.deliveries} deliver${Number(t.deliveries) === 1 ? "y" : "ies"}, via ${(events.get(t.id) ?? []).join(", ")}; named later in ${namedIn.get(t.id) ?? 0} of those sessions`;
|
|
@@ -47460,7 +47471,7 @@ async function deliveryOverview(db, projectId, days, now = new Date) {
|
|
|
47460
47471
|
function countTable(groups) {
|
|
47461
47472
|
const rows = new Map;
|
|
47462
47473
|
for (const g of groups) {
|
|
47463
|
-
const id = `${g.event}\x00${g.outcome}`;
|
|
47474
|
+
const id = `${eventName(g.event, g.reason)}\x00${g.outcome}`;
|
|
47464
47475
|
const row = rows.get(id) ?? { by: new Map, keyless: 0, left: 0 };
|
|
47465
47476
|
const w = who(Boolean(Number(g.named)), g.event, g.reason);
|
|
47466
47477
|
const n = Number(g.n);
|
|
@@ -47487,7 +47498,7 @@ function deliveryLine(d, units, namedLater) {
|
|
|
47487
47498
|
const agent = w === "subagent" && d.agent_id ? ` ${head(inline(d.agent_id), DELIVERY_LIMITS.agent)}` : "";
|
|
47488
47499
|
const named = units.slice(0, DELIVERY_LIMITS.keys).map((u) => `${head(inline(u.key), DELIVERY_LIMITS.key)} (u${u.id}${namedLater(u.key) ? ", named later" : ""})`).join(", ");
|
|
47489
47500
|
const more = units.length > DELIVERY_LIMITS.keys ? ` (+${units.length - DELIVERY_LIMITS.keys} more)` : "";
|
|
47490
|
-
return `- ${d.at} ${d.event}, ${w}${agent}${d.path ? ` ${head(inline(d.path), DELIVERY_LIMITS.path)}` : ""}: ${named}${more}`;
|
|
47501
|
+
return `- ${d.at} ${eventName(d.event, d.reason)}, ${w}${agent}${d.path ? ` ${head(inline(d.path), DELIVERY_LIMITS.path)}` : ""}: ${named}${more}`;
|
|
47491
47502
|
}
|
|
47492
47503
|
|
|
47493
47504
|
// server/src/export.ts
|
|
@@ -47511,7 +47522,7 @@ async function unitView(db, projectId, ref, root, asOf, renames) {
|
|
|
47511
47522
|
}
|
|
47512
47523
|
var RENAME_LOOKUPS = 5;
|
|
47513
47524
|
async function describe3(db, u, root, asOf, renames) {
|
|
47514
|
-
const [options, evidence, adoption, anchors, links, states, fields] = await Promise.all([
|
|
47525
|
+
const [options, evidence, adoption, anchors, links, states, fields, commands] = await Promise.all([
|
|
47515
47526
|
db.selectFrom("unit_option").select(["id", "text", "outcome", "why", "reconsider_when"]).where("unit_id", "=", u.id).orderBy("position").execute(),
|
|
47516
47527
|
db.selectFrom("unit_evidence as e").innerJoin("source as s", "s.id", "e.source_id").where("e.unit_id", "=", u.id).where("e.added_at", "<=", asOf ?? "9999").select([
|
|
47517
47528
|
"e.option_id",
|
|
@@ -47586,7 +47597,8 @@ async function describe3(db, u, root, asOf, renames) {
|
|
|
47586
47597
|
"s.author_association",
|
|
47587
47598
|
"s.created_at",
|
|
47588
47599
|
"s.text"
|
|
47589
|
-
]).orderBy("f.id").execute()
|
|
47600
|
+
]).orderBy("f.id").execute(),
|
|
47601
|
+
db.selectFrom("unit_command").select("command").where("unit_id", "=", u.id).where("added_at", "<=", asOf ?? "9999").orderBy("id").execute()
|
|
47590
47602
|
]);
|
|
47591
47603
|
let lifecycle = u.lifecycle;
|
|
47592
47604
|
let history = states;
|
|
@@ -47656,6 +47668,11 @@ async function describe3(db, u, root, asOf, renames) {
|
|
|
47656
47668
|
out.push(` - ${where} (${a.role}${a.commit_sha ? `, commit ${a.commit_sha.slice(0, 12)}` : ""}): ${c.state}${c.line ? ` at line ${c.line}` : ""}${c.state === "missing" ? ` — needs review: the code it points at is gone${moved}` : ""}`);
|
|
47657
47669
|
}
|
|
47658
47670
|
}
|
|
47671
|
+
if (commands.length) {
|
|
47672
|
+
out.push("Commands (the first call in a conversation that runs one, word for word on one line, is stopped with this dead end as the reason, unless the conversation has already seen it or been stopped 3 times):");
|
|
47673
|
+
for (const c of commands)
|
|
47674
|
+
out.push(` - ${inline(c.command)}`);
|
|
47675
|
+
}
|
|
47659
47676
|
const retired = anchors.filter((a) => a.retired_at);
|
|
47660
47677
|
if (retired.length) {
|
|
47661
47678
|
out.push("Retired anchors (they no longer count for delivery; a live anchor on the same path still does; kept with the words that retired them):");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sphica",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.59",
|
|
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/harvest/SKILL.md
CHANGED
|
@@ -66,7 +66,7 @@ and only by saying so: "we rejected yarn", "let's keep SQLite". check refuses th
|
|
|
66
66
|
- Options someone proposed and a maintainer declined, with the reason given: a `decision` whose rejected option carries its `why` and evidence
|
|
67
67
|
- What the pull request implemented: an `implementation` citing the commit message or the body, with an `evidence` anchor when a path and symbol are named (a `symbol` that is a key or a value Sphica masks is dropped, keeping the path)
|
|
68
68
|
- The problem the closed issue describes, when it states a rule ("exports must never include private notes"): a `constraint` citing the issue body
|
|
69
|
-
- Review findings that led to a change (`finding`), paths tried and abandoned (`dead_end`), questions left open (`question`)
|
|
69
|
+
- Review findings that led to a change (`finding`), paths tried and abandoned (`dead_end`), questions left open (`question`). Write a dead end as the trace Skill says: a lesson with its condition, the cause and the way around it only as the sources state them, and `commands` when it is about a command
|
|
70
70
|
|
|
71
71
|
Do not record the list of changes (git has it), approvals, or thanks. If the pull request decided nothing, save `"units": []` and say so.
|
|
72
72
|
Write text in the language the owner writes in the pull request's sources (English when they wrote none there), and give every record Japanese and English `aliases`.
|
package/skills/trace/SKILL.md
CHANGED
|
@@ -109,11 +109,12 @@ The `"..."` stands for the other language's words: in this example, `"データ
|
|
|
109
109
|
| `key` | A short meaningful word (lowercase letters, digits, `. _ -`). Saved as `trace:<session>/<key>`. A key is never reused: records are never rewritten |
|
|
110
110
|
| `kind` | `decision`, `constraint` (what must hold), `implementation` (what was built), `finding`, `dead_end` (a path tried that failed, and why), `question` |
|
|
111
111
|
| `stance` | Decisions and constraints only: `do`, `dont`, or `defer`. A deferral may add `revisit_when` |
|
|
112
|
-
| `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 |
|
|
112
|
+
| `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. A dead end's `text` is a lesson another task can use: what fails, under which condition (tool, version, environment), and the cause and the way around it only when the conversation says them. Leave the specifics to the quote, the anchors, and `commands` |
|
|
113
113
|
| `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` |
|
|
114
114
|
| `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) |
|
|
115
115
|
| `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 |
|
|
116
116
|
| `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) |
|
|
117
|
+
| `commands` | Dead ends only, up to 5: a command the dead end is about, as typed, cut to the shortest part that still names the failing use (the program and the flag or option, such as `pnpm test --watch`). The first call in a later conversation that runs it, word for word on one line, is stopped once and shown the dead end. Never a bare program name, a command in quotes, two commands joined with `;`, `\|`, or `&`, or one holding a secret |
|
|
117
118
|
| `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`) |
|
|
118
119
|
| `supersedes` | The key of a live record this one replaces (context lists them). The old one is marked superseded, never deleted |
|
|
119
120
|
| `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 |
|
|
@@ -124,7 +125,7 @@ The `"..."` stands for the other language's words: in this example, `"データ
|
|
|
124
125
|
|
|
125
126
|
A field value that breaks these rules refuses the whole save, like a `reconsider_quote` not found: fix it or leave the field out.
|
|
126
127
|
|
|
127
|
-
When check or save refuses `answers` as an unknown key, a `work` list as not an object, or a work item whose key is already there for leaving
|
|
128
|
+
When check or save refuses `answers` or `commands` as an unknown key, a `work` list as not an object, or a work item whose key is already there for leaving
|
|
128
129
|
out a field, the record server is older than this Skill. Do not drop them and save without: ask the owner to reload it (`/reload-plugins` in Claude Code; reopen Codex), then
|
|
129
130
|
begin again, read context, and save.
|
|
130
131
|
|