sphica 0.6.50 → 0.6.51

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.
@@ -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.50",
4
+ "version": "0.6.51",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.50",
3
+ "version": "0.6.51",
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
  "author": {
6
6
  "name": "iroha924",
@@ -48875,6 +48875,7 @@ var Unit = exports_external.object({
48875
48875
  aliases: exports_external.array(exports_external.string()).max(12).default([]),
48876
48876
  supersedes: exports_external.string().min(1).optional(),
48877
48877
  conflicts: exports_external.array(exports_external.string().min(1)).max(5).default([]),
48878
+ answers: exports_external.array(exports_external.string().min(1)).max(5).default([]),
48878
48879
  fields: exports_external.array(exports_external.object({
48879
48880
  name: exports_external.string().regex(FIELD_NAME2, "a defined field name"),
48880
48881
  value: text3(200),
@@ -48892,16 +48893,16 @@ var FieldDef = exports_external.object({
48892
48893
  }).strict();
48893
48894
  var Work = exports_external.object({
48894
48895
  key: exports_external.string().regex(KEY),
48895
- title: text3(200),
48896
- goal: text3(1000),
48897
- current: text3(2000),
48898
- next: exports_external.array(text3(500)).max(10).default([]),
48899
- status: exports_external.enum(WORK_STATUSES)
48896
+ title: text3(200).optional(),
48897
+ goal: text3(1000).optional(),
48898
+ current: text3(2000).optional(),
48899
+ next: exports_external.array(text3(500)).max(10).optional(),
48900
+ status: exports_external.enum(WORK_STATUSES).optional()
48900
48901
  }).strict();
48901
48902
  var Record = exports_external.object({
48902
48903
  field_defs: exports_external.array(FieldDef).max(10).default([]),
48903
48904
  units: exports_external.array(Unit).max(50),
48904
- work: Work.optional()
48905
+ work: exports_external.preprocess((w) => w === undefined || Array.isArray(w) ? w : [w], exports_external.array(Work).min(1).max(10).optional())
48905
48906
  }).strict();
48906
48907
  var cited = (body, quote) => quote.trim() ? locate(body, quote) : null;
48907
48908
  function anchorProblem(facts, a) {
@@ -48958,7 +48959,7 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
48958
48959
  errors: parsed.error.issues.map((i) => `${preview(i.path.join(".") || "record", 300)}: ${preview(i.message, 600)}`),
48959
48960
  problems,
48960
48961
  units: [],
48961
- work: null,
48962
+ work: [],
48962
48963
  fieldDefs: [],
48963
48964
  facts
48964
48965
  };
@@ -49050,7 +49051,7 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
49050
49051
  for (const n of new Set(names.filter((n2, i) => names.indexOf(n2) !== i)))
49051
49052
  errors3.push(`field_defs ${n}: defined twice in this record`);
49052
49053
  const linked = [
49053
- ...new Set(record4.units.flatMap((u) => [...u.supersedes ? [u.supersedes] : [], ...u.conflicts]))
49054
+ ...new Set(record4.units.flatMap((u) => [...u.supersedes ? [u.supersedes] : [], ...u.conflicts, ...u.answers]))
49054
49055
  ];
49055
49056
  const others = new Map((linked.length ? await db.selectFrom("unit as o").select(["o.id", "o.key", "o.kind", "o.lifecycle"]).where("o.project_id", "=", target.projectId).where("o.key", "in", linked).execute() : []).map((u) => [u.key, u]));
49056
49057
  const units = [];
@@ -49216,6 +49217,16 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
49216
49217
  errors3.push(`${key}: conflicts with ${k}, which is not a record of this project`);
49217
49218
  return other ? [other.id] : [];
49218
49219
  });
49220
+ if (u.answers.length && u.kind === "question")
49221
+ errors3.push(`${key}: a question does not answer another; one that replaces it supersedes it`);
49222
+ const answers = [...new Set(u.answers)].flatMap((k) => {
49223
+ const other = others.get(k);
49224
+ if (!other)
49225
+ errors3.push(`${key}: answers ${k}, which is not a record of this project`);
49226
+ else if (other.kind !== "question")
49227
+ errors3.push(`${key}: answers ${k}, a ${other.kind}; only a question is answered`);
49228
+ return other?.kind === "question" ? [other.id] : [];
49229
+ });
49219
49230
  for (const x of adoption.filter((x2) => x2.route === "agent")) {
49220
49231
  const why = await agentRefusal(db, u, x, sources.get(x.source), evidence, anchors);
49221
49232
  if (!why)
@@ -49223,6 +49234,7 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
49223
49234
  problems.push(`${key}: the AI's adoption in s${x.source} left out, so it stays a candidate: ${why}`);
49224
49235
  adoption.splice(adoption.indexOf(x), 1);
49225
49236
  }
49237
+ const grounds = (["decision", "constraint"].includes(u.kind) ? adoption.find((x) => x.route !== "agent") : evidence[0])?.source ?? null;
49226
49238
  const fields = [];
49227
49239
  for (const f of u.fields) {
49228
49240
  const at = `${key}: field ${f.name}`;
@@ -49271,12 +49283,24 @@ async function checkRecord(db, target, raw, facts = prepareRecord(target.root, r
49271
49283
  aliases: aliases.filter((a) => !bad.includes(a)),
49272
49284
  supersedes,
49273
49285
  conflicts,
49286
+ answers,
49287
+ grounds,
49274
49288
  fields
49275
49289
  });
49276
49290
  }
49277
- if (record4.work && target.origin !== "trace")
49291
+ if (target.origin !== "trace" && record4.units.some((u) => u.answers.length))
49292
+ errors3.push("answers: only trace closes a question");
49293
+ const work = record4.work ?? [];
49294
+ if (work.length && target.origin !== "trace")
49278
49295
  errors3.push("work: only trace records work");
49279
- return { errors: errors3, problems, units, work: record4.work ?? null, fieldDefs, facts };
49296
+ const named = work.map((w) => w.key);
49297
+ for (const k of new Set(named.filter((k2, i) => named.indexOf(k2) !== i)))
49298
+ errors3.push(`work ${k}: the key appears twice`);
49299
+ const known = new Set((work.length ? await db.selectFrom("work").select("key").where("project_id", "=", target.projectId).where("key", "in", named).execute() : []).map((w) => w.key));
49300
+ for (const w of work)
49301
+ if (!known.has(w.key) && [w.title, w.goal, w.current, w.status].includes(undefined))
49302
+ errors3.push(`work ${w.key}: a new key needs title, goal, current, and status`);
49303
+ return { errors: errors3, problems, units, work, fieldDefs, facts };
49280
49304
  }
49281
49305
  function fieldTypeError(type, values, v) {
49282
49306
  if (type === "integer" && !/^-?[0-9]+$/.test(v))
@@ -49370,6 +49394,115 @@ async function settleSaved(trx, runId, saved, more = {}) {
49370
49394
  saved.superseded.push(c.key);
49371
49395
  return settled2;
49372
49396
  }
49397
+ var OLDER_QUESTIONS = 10;
49398
+ async function closeAnswered(trx, runId, units, saved) {
49399
+ const answering = units.filter((p) => p.answers.length);
49400
+ if (!answering.length)
49401
+ return;
49402
+ const questions = new Map((await trx.selectFrom("unit").select(["id", "key", "lifecycle"]).where("id", "in", [...new Set(answering.flatMap((p) => p.answers))]).execute()).map((q) => [q.id, q]));
49403
+ const withdraw = new Map;
49404
+ const by = new Map;
49405
+ const root = new Map;
49406
+ const left = new Map;
49407
+ for (const p of answering) {
49408
+ const why = !saved.active.includes(p.key) ? `${p.key} did not become active` : p.grounds !== null ? null : `${p.key} is an AI's decision, and a question closes only on the owner's or a maintainer's adoption`;
49409
+ for (const id of p.answers) {
49410
+ const q = questions.get(id);
49411
+ if (!q || withdraw.has(id))
49412
+ continue;
49413
+ if (q.lifecycle !== "active" && q.lifecycle !== "candidate")
49414
+ left.set(id, `${q.key}: already ${q.lifecycle}, so ${p.key} closes nothing there`);
49415
+ else if (why !== null || p.grounds === null)
49416
+ left.set(id, left.get(id) ?? `${q.key}: left open: ${why}`);
49417
+ else {
49418
+ withdraw.set(id, { reason: `answered by ${p.key}`, source: p.grounds });
49419
+ by.set(id, p.key);
49420
+ root.set(id, id);
49421
+ }
49422
+ }
49423
+ }
49424
+ const moved = new Map;
49425
+ const through = new Map;
49426
+ let asked = new Map(withdraw);
49427
+ for (let round = 0;asked.size; round++) {
49428
+ if (round > OLDER_QUESTIONS) {
49429
+ const named = root.get([...asked.keys()][0]);
49430
+ throw new SaveRefused(`${by.get(named)}: answering ${questions.get(named)?.key} would close more than ${OLDER_QUESTIONS} older questions it replaced; leave it out of answers, and the owner can withdraw them`);
49431
+ }
49432
+ const settled2 = await reconcile(trx, [...asked.keys()], { runId }, { withdraw: asked });
49433
+ for (const c of settled2.changes)
49434
+ moved.set(c.id, { key: c.key, before: moved.get(c.id)?.before ?? c.before, after: c.after });
49435
+ const back = settled2.changes.filter((c) => c.before === "superseded" && c.after !== "superseded");
49436
+ const older = back.length ? await trx.selectFrom("unit_link").select(["from_unit", "to_unit"]).where("kind", "=", "supersedes").where("from_unit", "in", [...asked.keys()]).where("to_unit", "in", back.map((c) => c.id)).orderBy("to_unit").orderBy("from_unit").execute() : [];
49437
+ const next = new Map;
49438
+ for (const l of older) {
49439
+ const from = asked.get(l.from_unit);
49440
+ const answer = by.get(l.from_unit);
49441
+ next.set(l.to_unit, {
49442
+ reason: `answered by ${answer} (through ${settled2.keys.get(l.from_unit)})`,
49443
+ source: from.source
49444
+ });
49445
+ by.set(l.to_unit, answer);
49446
+ through.set(l.to_unit, settled2.keys.get(l.from_unit) ?? `u${l.from_unit}`);
49447
+ root.set(l.to_unit, root.get(l.from_unit));
49448
+ }
49449
+ asked = next;
49450
+ }
49451
+ for (const [id, answer] of by) {
49452
+ const m = moved.get(id);
49453
+ if (m?.after === "withdrawn")
49454
+ saved.closed.push(`${m.key}: withdrawn, answered by ${answer}${through.has(id) ? ` through ${through.get(id)}` : ""}`);
49455
+ }
49456
+ for (const [id, m] of moved)
49457
+ if (!(by.has(id) && m.after === "withdrawn") && m.after !== m.before)
49458
+ saved.closed.push(`${m.key}: now ${m.after} (was ${m.before})`);
49459
+ for (const [id, note] of left)
49460
+ if (moved.get(id)?.after !== "withdrawn")
49461
+ saved.notes.push(note);
49462
+ }
49463
+ async function saveWork(trx, target, runId, items, now, saved) {
49464
+ if (!items.length)
49465
+ return;
49466
+ const traced = target.sessionId ? await trx.selectFrom("session").select(["started_at", "branch"]).where("id", "=", target.sessionId).executeTakeFirst() : undefined;
49467
+ const stamp = { branch: traced?.branch ?? null, run_id: runId, updated_at: now };
49468
+ for (const w of items) {
49469
+ const held = await trx.selectFrom("work as w").leftJoin("extraction_run as r", "r.id", "w.run_id").leftJoin("session as s", "s.id", "r.session_id").select(["w.id", "w.title", "w.goal", "w.current", "w.next", "w.status", "s.started_at"]).where("w.project_id", "=", target.projectId).where("w.key", "=", w.key).executeTakeFirst();
49470
+ if (!held) {
49471
+ await trx.insertInto("work").values({
49472
+ project_id: target.projectId,
49473
+ key: w.key,
49474
+ title: w.title,
49475
+ goal: w.goal,
49476
+ current: w.current,
49477
+ next: JSON.stringify(w.next ?? []),
49478
+ status: w.status,
49479
+ ...stamp
49480
+ }).execute();
49481
+ saved.work.push(`work ${w.key}: created`);
49482
+ continue;
49483
+ }
49484
+ if ([w.title, w.goal, w.current, w.next, w.status].every((v) => v === undefined)) {
49485
+ saved.notes.push(`work ${w.key}: nothing to change: only its key was given`);
49486
+ continue;
49487
+ }
49488
+ const mine = traced?.started_at;
49489
+ if (held.started_at && mine && held.started_at > mine) {
49490
+ saved.notes.push(`work ${w.key}: left as it is: a newer session's state is already saved`);
49491
+ continue;
49492
+ }
49493
+ const stored = typeof held.next === "string" ? held.next : JSON.stringify(held.next);
49494
+ const row = {
49495
+ title: w.title ?? held.title,
49496
+ goal: w.goal ?? held.goal,
49497
+ current: w.current ?? held.current,
49498
+ next: w.next ? JSON.stringify(w.next) : stored,
49499
+ status: w.status ?? held.status
49500
+ };
49501
+ const same = row.title === held.title && row.goal === held.goal && row.current === held.current && row.next === stored && row.status === held.status;
49502
+ await trx.updateTable("work").set(same ? { run_id: runId } : { ...row, ...stamp }).where("id", "=", held.id).execute();
49503
+ saved.work.push(`work ${w.key}: ${same ? "confirmed, nothing changed" : "updated"}`);
49504
+ }
49505
+ }
49373
49506
  async function saveRecord(trx, target, runId, checked, looked, { settle: settle2 = true } = {}) {
49374
49507
  if (checked.errors.length)
49375
49508
  throw new Error(`The record is not valid:
@@ -49382,6 +49515,9 @@ ${checked.errors.map((e) => ` ${e}`).join(`
49382
49515
  quarantined: [],
49383
49516
  superseded: [],
49384
49517
  anchorProblems: [],
49518
+ closed: [],
49519
+ notes: [],
49520
+ work: [],
49385
49521
  written: []
49386
49522
  };
49387
49523
  const cited2 = new Set;
@@ -49534,26 +49670,11 @@ ${checked.errors.map((e) => ` ${e}`).join(`
49534
49670
  }
49535
49671
  });
49536
49672
  }
49537
- if (settle2)
49673
+ if (settle2) {
49538
49674
  await settleSaved(trx, runId, saved);
49539
- if (checked.work) {
49540
- const w = checked.work;
49541
- const traced = target.sessionId ? await trx.selectFrom("session").select(["started_at", "branch"]).where("id", "=", target.sessionId).executeTakeFirst() : undefined;
49542
- const row = {
49543
- title: w.title,
49544
- goal: w.goal,
49545
- current: w.current,
49546
- next: JSON.stringify(w.next),
49547
- status: w.status,
49548
- branch: traced?.branch ?? null,
49549
- run_id: runId,
49550
- updated_at: now
49551
- };
49552
- const held = await trx.selectFrom("work as w").leftJoin("extraction_run as r", "r.id", "w.run_id").leftJoin("session as s", "s.id", "r.session_id").select("s.started_at").where("w.project_id", "=", target.projectId).where("w.key", "=", w.key).executeTakeFirst();
49553
- const mine = traced?.started_at;
49554
- if (!(held?.started_at && mine && held.started_at > mine))
49555
- await trx.insertInto("work").values({ project_id: target.projectId, key: w.key, ...row }).onConflict((oc) => oc.columns(["project_id", "key"]).doUpdateSet(row)).execute();
49675
+ await closeAnswered(trx, runId, checked.units, saved);
49556
49676
  }
49677
+ await saveWork(trx, target, runId, checked.work, now, saved);
49557
49678
  for (const s of new Set(looked))
49558
49679
  await trx.insertInto("source_processing").values({ source_id: s, run_id: runId, outcome: cited2.has(s) ? "units" : "no_unit" }).onConflict((oc) => oc.doNothing()).execute();
49559
49680
  return saved;
@@ -49741,7 +49862,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
49741
49862
  errors: [],
49742
49863
  problems: [],
49743
49864
  units: [],
49744
- work: null,
49865
+ work: [],
49745
49866
  fieldDefs: [],
49746
49867
  facts
49747
49868
  },
@@ -50404,6 +50525,13 @@ async function sessionSources(db, sessionId2) {
50404
50525
  async function sessionEdits(db, sessionId2) {
50405
50526
  return db.selectFrom("edit_observation").where("session_id", "=", sessionId2).select(["path", "via", "turn_id"]).orderBy("id").execute();
50406
50527
  }
50528
+ async function workItems(db, projectId2, closed = 10) {
50529
+ const items = db.selectFrom("work").where("project_id", "=", projectId2).select(["key", "title", "goal", "current", "next", "status", "updated_at"]).orderBy("updated_at", "desc").orderBy("id", "desc");
50530
+ return {
50531
+ open: await items.where("status", "in", ["active", "blocked", "paused"]).execute(),
50532
+ closed: await items.where("status", "in", ["done", "abandoned"]).limit(closed).execute()
50533
+ };
50534
+ }
50407
50535
  async function liveUnits(db, projectId2, limit = 40) {
50408
50536
  return db.selectFrom("unit").where("project_id", "=", projectId2).where("lifecycle", "in", ["active", "candidate"]).where("extraction", "=", "supported").select(["id", "key", "kind", "stance", "lifecycle", "text"]).orderBy("id", "desc").limit(limit).execute();
50409
50537
  }
@@ -50742,6 +50870,8 @@ ${body}` : body;
50742
50870
  const live = await liveUnits(db, projectId2);
50743
50871
  const whose = await authorityOf(db, live.map((u) => u.id));
50744
50872
  const fields = scope.target.origin === "trace" ? await db.selectFrom("field_def").select(["name", "type", "label", "description", "enum_values", "kinds"]).where("project_id", "=", projectId2).orderBy("id").execute() : [];
50873
+ const work = scope.target.origin === "trace" ? await workItems(db, projectId2) : { open: [], closed: [] };
50874
+ const item2 = (w) => `- ${w.key} (${w.status}, updated ${w.updated_at.slice(0, 10)}) ${inline(w.title)}`;
50745
50875
  const keys = live.map((u) => keyShown(u.key, u.id));
50746
50876
  let tailId = "";
50747
50877
  do
@@ -50759,10 +50889,23 @@ ${body}` : body;
50759
50889
  return `- ${f.name} (${f.type}${values}; ${kinds.length ? kinds.join(", ") : "every kind"}) ${inline(f.label)}: ${inline(f.description)}`;
50760
50890
  })
50761
50891
  ] : [],
50762
- "Live records of this project (supersedes and conflicts take these keys):",
50892
+ ...work.open.length ? [
50893
+ "Work in progress (to update one, give its key and only the fields that change; the same work keeps its key):",
50894
+ ...work.open.flatMap((w) => [
50895
+ item2(w),
50896
+ ` goal: ${inline(w.goal)}`,
50897
+ ` current: ${inline(w.current)}`,
50898
+ ` next: ${w.next.map(inline).join(" | ") || "none"}`
50899
+ ])
50900
+ ] : [],
50901
+ ...work.closed.length ? [
50902
+ "Closed work, newest first (a key here is taken: work that goes on keeps it):",
50903
+ ...work.closed.map(item2)
50904
+ ] : [],
50905
+ `Live records of this project (${scope.target.origin === "trace" ? "supersedes, conflicts, and answers" : "supersedes and conflicts"} take these keys):`,
50763
50906
  ...live.length ? live.map((u, i) => `- ${keys[i]} (${u.kind}${u.stance ? ` ${u.stance}` : ""}, ${u.lifecycle}${["decision", "constraint"].includes(u.kind) ? `, ${AUTHORITY[whose.get(u.id) ?? "none"]}` : ""}) ${preview(u.text, 480)}`) : ["None."],
50764
50907
  ...keys.some((k, i) => k !== inline(live[i]?.key ?? "")) ? [
50765
- "A key marked [key cut] is not whole: read that u<id> and take the key from there before using it in supersedes or conflicts."
50908
+ "A key marked [key cut] is not whole: read that u<id> and take the key from there before using it."
50766
50909
  ] : []
50767
50910
  ].flatMap(pieces)
50768
50911
  };
@@ -50809,7 +50952,7 @@ function contextOnly(id, items, c) {
50809
50952
  return [
50810
50953
  ...c.units.filter((u) => [...u.evidence, ...u.options.flatMap((o) => o.evidence), ...u.adoption].every((x) => old.has(x.source))).map((u) => `${u.key}: quotes only messages earlier runs already looked at; an automatic run's record quotes at least one message it traces`),
50811
50954
  ...c.fieldDefs.filter((d) => old.has(d.source)).map((d) => `field_defs ${d.name}: an automatic run defines a field only from a message it traces`),
50812
- ...c.work && !c.units.length ? ["work: an automatic run updates work only beside a record of the messages it traces"] : []
50955
+ ...c.work.length && !c.units.length ? ["work: an automatic run updates work only beside a record of the messages it traces"] : []
50813
50956
  ];
50814
50957
  }
50815
50958
  async function prepare2(db, id, projectId2, root, record4, probe, call) {
@@ -50860,7 +51003,7 @@ async function validate2(trx, id, projectId2, root, record4, prepared, call) {
50860
51003
  ...checked.fieldDefs
50861
51004
  ].map((q) => q.source));
50862
51005
  const saved = await saveRecord(w, scope.target, run2.id, checked, scope.looked.filter((s) => shown.has(s) || cited2.has(s)));
50863
- return { saved, changed: [] };
51006
+ return { saved, changed: [...saved.closed, ...saved.work] };
50864
51007
  }
50865
51008
  };
50866
51009
  }
@@ -50889,6 +51032,7 @@ async function checkText(db, id, projectId2, root, record4, call, probe) {
50889
51032
  ...done.saved.superseded.map((k) => `✓ would be superseded: ${k}`),
50890
51033
  ...done.saved.candidates.map((c) => `△ would stay a candidate: ${c.key}: ${c.why}`),
50891
51034
  ...done.saved.quarantined.map((q) => `△ would be quarantined: ${q}`),
51035
+ ...done.saved.notes.map((n) => `△ ${n}`),
50892
51036
  ...[...new Set(done.saved.anchorProblems)].filter((a) => !v.problems.some((p) => p === a || p.endsWith(` ${a}`))).map((a) => `△ ${a}`),
50893
51037
  ...done.changed.map((c) => `✓ would: ${c}`)
50894
51038
  ] : v.quarantine.map((q) => `△ ${q}`)
@@ -50941,6 +51085,7 @@ async function saveText(db, id, projectId2, root, record4, probe, call) {
50941
51085
  const warnings = [
50942
51086
  ...new Set([
50943
51087
  ...saved.anchorProblems.map((a) => `△ ${a}`),
51088
+ ...saved.notes.map((n) => `△ ${n}`),
50944
51089
  ...v.ops === null ? v.problems.map((n) => `△ ${n}`) : []
50945
51090
  ])
50946
51091
  ];
package/dist/mcp.js CHANGED
@@ -46674,6 +46674,7 @@ var Unit = exports_external.object({
46674
46674
  aliases: exports_external.array(exports_external.string()).max(12).default([]),
46675
46675
  supersedes: exports_external.string().min(1).optional(),
46676
46676
  conflicts: exports_external.array(exports_external.string().min(1)).max(5).default([]),
46677
+ answers: exports_external.array(exports_external.string().min(1)).max(5).default([]),
46677
46678
  fields: exports_external.array(exports_external.object({
46678
46679
  name: exports_external.string().regex(FIELD_NAME, "a defined field name"),
46679
46680
  value: text2(200),
@@ -46691,16 +46692,16 @@ var FieldDef = exports_external.object({
46691
46692
  }).strict();
46692
46693
  var Work = exports_external.object({
46693
46694
  key: exports_external.string().regex(KEY),
46694
- title: text2(200),
46695
- goal: text2(1000),
46696
- current: text2(2000),
46697
- next: exports_external.array(text2(500)).max(10).default([]),
46698
- status: exports_external.enum(WORK_STATUSES)
46695
+ title: text2(200).optional(),
46696
+ goal: text2(1000).optional(),
46697
+ current: text2(2000).optional(),
46698
+ next: exports_external.array(text2(500)).max(10).optional(),
46699
+ status: exports_external.enum(WORK_STATUSES).optional()
46699
46700
  }).strict();
46700
46701
  var Record = exports_external.object({
46701
46702
  field_defs: exports_external.array(FieldDef).max(10).default([]),
46702
46703
  units: exports_external.array(Unit).max(50),
46703
- work: Work.optional()
46704
+ work: exports_external.preprocess((w) => w === undefined || Array.isArray(w) ? w : [w], exports_external.array(Work).min(1).max(10).optional())
46704
46705
  }).strict();
46705
46706
  function repoPath(p) {
46706
46707
  const s = p.trim().replace(/^\.\//, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.50",
3
+ "version": "0.6.51",
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",
@@ -90,7 +90,7 @@ Japanese corner brackets, backticks, apostrophes): quote more of the owner's own
90
90
  Check reads where the words sit, not what they mean: whether they settle this record is yours to judge.
91
91
 
92
92
  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
93
- 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
93
+ record in `units` (trace's shape without the keys `"work"`, `"answers"`, `"field_defs"`, and `"fields"`, and without evidence of the role `decides`, all of which only a trace takes; 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
94
94
  quotation there); records are never rewritten.
95
95
 
96
96
  ## When a source turns up for an unsourced record
@@ -38,7 +38,7 @@ as `cwd` to every tool.
38
38
  when a page's last line says `call record_context with after: "..."`, call it again with that `after`, exactly as written, until a page names none
39
39
  (a source too long for a page says where `read` goes on)
40
40
  4. **Check**: `record_check` with the run and the record as `record`. The shape and fields are trace's ([../trace/SKILL.md](../trace/SKILL.md),
41
- "The record"), with `work` left out. Keys are saved as `harvest:<number>/<key>`. As in trace, check runs the save in a transaction that
41
+ "The record"), without the keys `"work"`, `"answers"`, `"field_defs"`, and `"fields"`, and without evidence of the role `decides`: only a trace takes those. Keys are saved as `harvest:<number>/<key>`. As in trace, check runs the save in a transaction that
42
42
  rolls back and says what would become of each record (`would be active`, ...), the verdict and the counts first; when a reply ends with
43
43
  `call record_more with cursor: "..."`, read the rest with `record_more`. Fix and check again until there are no errors.
44
44
  A file the pull request touched may have moved since: on a warning that a path is not in the working tree, give the commit that holds it,
@@ -36,9 +36,9 @@ Everything goes through Sphica's `record` MCP server (its tools are `trace_pendi
36
36
  them, but they can still be traced. Trace one session at a time
37
37
  2. **Begin**: `trace_begin` with that `session`. It returns a `run` id bound to that session and this project; the record never names them
38
38
  3. **Read**: `record_context` with the run. It prints each captured message as `## s<N> owner|assistant <turn> <time>` followed by its text,
39
- the edits observed, and the project's live records. `(traced before)` marks messages an earlier trace already looked at.
39
+ the edits observed, the work items there are, and the project's live records. `(traced before)` marks messages an earlier trace already looked at.
40
40
  It comes in pages: when a page's last line says `call record_context with after: "..."`, call it again with that `after`, exactly as written
41
- (`s<N>` while messages follow, then `t<id>.<line>` while the edits, fields, and live records go on), until a page names no `after`.
41
+ (`s<N>` while messages follow, then `t<id>.<line>` while the edits, fields, work items, and live records go on), until a page names no `after`.
42
42
  A message too long for a page ends with `(cut here; read s<N>@<byte> for the rest)`: read on with `read` when what it says matters.
43
43
  Saving marks as looked at only the messages you were shown and those you quote; the rest stay pending.
44
44
  Use `search` and `read` to look at older records this session may replace
@@ -91,10 +91,15 @@ When Sphica's session-start notice in Claude Code says earlier sessions wait to
91
91
  "aliases": ["database", "storage", "SQLite", "Postgres", "server", "persistence", "..."]
92
92
  }
93
93
  ],
94
- "work": { "key": "storage", "title": "Pick the storage", "goal": "One file per user", "current": "Decided", "next": [], "status": "done" }
94
+ "work": [
95
+ { "key": "storage", "current": "Decided", "next": [], "status": "done" },
96
+ { "key": "csv-export", "title": "Rework the export", "goal": "Notes never leave in a CSV", "current": "Not started", "next": ["List the columns"], "status": "active" }
97
+ ]
95
98
  }
96
99
  ```
97
100
 
101
+ In this example `storage` is a work item context already lists, so only what changed is given; `csv-export` is new and gives every field.
102
+
98
103
  <!-- english-exempt: the aliases example has to show Japanese words -->
99
104
  The `"..."` stands for the other language's words: in this example, `"データベース", "保存先", "DB サーバー", "永続化"`.
100
105
 
@@ -111,12 +116,17 @@ The `"..."` stands for the other language's words: in this example, `"データ
111
116
  | `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`) |
112
117
  | `supersedes` | The key of a live record this one replaces (context lists them). The old one is marked superseded, never deleted |
113
118
  | `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 |
114
- | `work` | The current work status, optional. The same `key` updates it |
119
+ | `answers` | Keys of open questions (context lists them) this record answers, up to 5. Each is closed, withdrawn with this record named as the reason, once this record is active; a decision or constraint also needs the owner's or a maintainer's adoption, so an AI's own decision closes none. Only for a record that settles the question, never a proposal or something merely related. A closed question does not come back: save a new question if it is still open. Not on a question: one question replaces another with `supersedes` |
120
+ | `work` | Work items, optional: one, or a list of up to 10. Context lists the ones there are. For work it lists, reuse its `key` and give only the fields that change (`title`, `goal`, `current`, `next`, `status`): a field left out keeps what is saved, and `next: []` clears the next steps. A new key gives `title`, `goal`, `current`, and `status`. Finished work is `done`; work given up, or opened twice under two keys, is `abandoned`. Change only what the conversation shows: a similar title is no reason to close an item or fold two together. Save says what became of each: created, updated, confirmed with nothing changed, or left as it is because a newer session's trace already wrote it |
115
121
  | `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 |
116
122
  | `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 |
117
123
 
118
124
  A field value that breaks these rules refuses the whole save, like a `reconsider_quote` not found: fix it or leave the field out.
119
125
 
126
+ 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
127
+ 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
128
+ begin again, read context, and save.
129
+
120
130
  What becomes active: a decision or constraint with evidence and adoption (the owner's words, or the AI's own decision under the rules below); an implementation with code or commit evidence
121
131
  (an `evidence` anchor on a path this session edited counts); a finding, dead end, or question with evidence. Everything else stays a candidate,
122
132
  and a record whose quote is not in the message is quarantined. Neither is injected into later sessions.