sphica 0.6.40 → 0.6.41

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.40",
4
+ "version": "0.6.41",
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.40",
3
+ "version": "0.6.41",
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",
@@ -0,0 +1,59 @@
1
+ -- Revision 11 → 12 of generation 2: glean keeps the owner's words that retired or moved an anchor (unit_anchor_retirement). Anchors
2
+ -- retired before it have no reason row; nothing is inferred for them. Every statement is the same as in the schema at revision 12.
3
+
4
+ create table unit_anchor_retirement (
5
+ anchor_id integer primary key not null references unit_anchor (id) on delete cascade,
6
+ run_id integer not null references extraction_run (id),
7
+ source_id integer not null references source (id) on delete cascade,
8
+ span_start integer not null check (span_start >= 0),
9
+ span_end integer not null check (span_end > span_start),
10
+ added_at text not null check (strftime('%Y-%m-%dT%H:%M:%fZ', added_at) is added_at)
11
+ ) strict;
12
+ create index unit_anchor_retirement_run on unit_anchor_retirement (run_id);
13
+ create index unit_anchor_retirement_source on unit_anchor_retirement (source_id);
14
+ create trigger unit_anchor_retirement_check before insert on unit_anchor_retirement begin
15
+ select raise(abort, 'a retirement reason is written for a retired anchor')
16
+ where not exists (select 1 from unit_anchor where id = new.anchor_id and retired_at is not null);
17
+ select raise(abort, 'retirement reason and anchor belong to different projects')
18
+ where (select u.project_id from unit_anchor a join unit u on u.id = a.unit_id where a.id = new.anchor_id)
19
+ is not (select project_id from source where id = new.source_id)
20
+ or (select u.project_id from unit_anchor a join unit u on u.id = a.unit_id where a.id = new.anchor_id)
21
+ is not (select project_id from extraction_run where id = new.run_id);
22
+ select raise(abort, 'only the owner''s words retire an anchor')
23
+ where not exists (select 1 from source where id = new.source_id and author_kind = 'owner');
24
+ select raise(abort, 'retirement span is outside the source text')
25
+ where new.span_end > (select length(cast(text as blob)) from source where id = new.source_id);
26
+ select raise(abort, 'a span starts or ends inside a character')
27
+ where hex(substr((select cast(text as blob) from source where id = new.source_id), new.span_start + 1, 1)) between '80' and 'BF'
28
+ or hex(substr((select cast(text as blob) from source where id = new.source_id), new.span_end + 1, 1)) between '80' and 'BF';
29
+ end;
30
+ create trigger unit_anchor_retirement_frozen before update on unit_anchor_retirement begin
31
+ select raise(abort, 'a retirement reason is never changed');
32
+ end;
33
+ create trigger unit_anchor_retirement_no_delete before delete on unit_anchor_retirement
34
+ when exists (select 1 from unit_anchor where id = old.anchor_id) and exists (select 1 from source where id = old.source_id) begin
35
+ select raise(abort, 'a retirement reason goes only with its anchor or its source');
36
+ end;
37
+
38
+ drop trigger session_cited;
39
+ create trigger session_cited before delete on session
40
+ when exists (select 1 from project where id = old.project_id) and (
41
+ exists (select 1 from source s where s.session_id = old.id and (
42
+ exists (select 1 from unit_evidence e where e.source_id = s.id or e.retraction_source_id = s.id)
43
+ or exists (select 1 from unit_adoption a where a.source_id = s.id or a.retraction_source_id = s.id)
44
+ or exists (select 1 from field_def d where d.source_id = s.id)
45
+ or exists (select 1 from unit_field f where f.source_id = s.id)
46
+ or exists (select 1 from unit_state t where t.source_id = s.id)
47
+ or exists (select 1 from unit_anchor_retirement r where r.source_id = s.id)))
48
+ or exists (select 1 from edit_observation o join unit_anchor a on a.edit_observation_id = o.id where o.session_id = old.id)) begin
49
+ select raise(abort, 'records cite this session; forget its messages with /sphica:forget rather than deleting it');
50
+ end;
51
+
52
+ create trigger unit_rev_retirement_i after insert on unit_anchor_retirement begin
53
+ update unit set revision = revision + 1 where id = (select unit_id from unit_anchor where id = new.anchor_id);
54
+ end;
55
+ create trigger unit_rev_retirement_d after delete on unit_anchor_retirement begin
56
+ update unit set revision = revision + 1 where id = (select unit_id from unit_anchor where id = old.anchor_id);
57
+ end;
58
+
59
+ pragma user_version = 12;
package/db/schema.sql CHANGED
@@ -141,7 +141,8 @@ when exists (select 1 from project where id = old.project_id) and (
141
141
  or exists (select 1 from unit_adoption a where a.source_id = s.id or a.retraction_source_id = s.id)
142
142
  or exists (select 1 from field_def d where d.source_id = s.id)
143
143
  or exists (select 1 from unit_field f where f.source_id = s.id)
144
- or exists (select 1 from unit_state t where t.source_id = s.id)))
144
+ or exists (select 1 from unit_state t where t.source_id = s.id)
145
+ or exists (select 1 from unit_anchor_retirement r where r.source_id = s.id)))
145
146
  or exists (select 1 from edit_observation o join unit_anchor a on a.edit_observation_id = o.id where o.session_id = old.id)) begin
146
147
  select raise(abort, 'records cite this session; forget its messages with /sphica:forget rather than deleting it');
147
148
  end;
@@ -699,6 +700,41 @@ end;
699
700
  create trigger unit_anchor_no_delete before delete on unit_anchor when exists (select 1 from unit where id = old.unit_id) begin
700
701
  select raise(abort, 'anchors are retired, never deleted');
701
702
  end;
703
+ -- The owner's words that retired an anchor (moved or retired by glean). Forgetting that source removes only this row: the anchor stays retired
704
+ create table unit_anchor_retirement (
705
+ anchor_id integer primary key not null references unit_anchor (id) on delete cascade,
706
+ run_id integer not null references extraction_run (id),
707
+ source_id integer not null references source (id) on delete cascade,
708
+ span_start integer not null check (span_start >= 0),
709
+ span_end integer not null check (span_end > span_start),
710
+ added_at text not null check (strftime('%Y-%m-%dT%H:%M:%fZ', added_at) is added_at)
711
+ ) strict;
712
+ create index unit_anchor_retirement_run on unit_anchor_retirement (run_id);
713
+ create index unit_anchor_retirement_source on unit_anchor_retirement (source_id);
714
+ create trigger unit_anchor_retirement_check before insert on unit_anchor_retirement begin
715
+ select raise(abort, 'a retirement reason is written for a retired anchor')
716
+ where not exists (select 1 from unit_anchor where id = new.anchor_id and retired_at is not null);
717
+ select raise(abort, 'retirement reason and anchor belong to different projects')
718
+ where (select u.project_id from unit_anchor a join unit u on u.id = a.unit_id where a.id = new.anchor_id)
719
+ is not (select project_id from source where id = new.source_id)
720
+ or (select u.project_id from unit_anchor a join unit u on u.id = a.unit_id where a.id = new.anchor_id)
721
+ is not (select project_id from extraction_run where id = new.run_id);
722
+ select raise(abort, 'only the owner''s words retire an anchor')
723
+ where not exists (select 1 from source where id = new.source_id and author_kind = 'owner');
724
+ select raise(abort, 'retirement span is outside the source text')
725
+ where new.span_end > (select length(cast(text as blob)) from source where id = new.source_id);
726
+ select raise(abort, 'a span starts or ends inside a character')
727
+ where hex(substr((select cast(text as blob) from source where id = new.source_id), new.span_start + 1, 1)) between '80' and 'BF'
728
+ or hex(substr((select cast(text as blob) from source where id = new.source_id), new.span_end + 1, 1)) between '80' and 'BF';
729
+ end;
730
+ create trigger unit_anchor_retirement_frozen before update on unit_anchor_retirement begin
731
+ select raise(abort, 'a retirement reason is never changed');
732
+ end;
733
+ -- Removed only with its anchor (the unit's deletion) or the source it quotes (forget)
734
+ create trigger unit_anchor_retirement_no_delete before delete on unit_anchor_retirement
735
+ when exists (select 1 from unit_anchor where id = old.anchor_id) and exists (select 1 from source where id = old.source_id) begin
736
+ select raise(abort, 'a retirement reason goes only with its anchor or its source');
737
+ end;
702
738
 
703
739
  -- What an active unit must have, in one place: missing says what it lacks, and is null when it lacks nothing. Activating reads it, and so
704
740
  -- does every change that can take support away (a retraction, retiring an anchor), so the two never disagree.
@@ -1015,6 +1051,12 @@ create trigger unit_rev_link_u after update on unit_link begin
1015
1051
  end;
1016
1052
  create trigger unit_rev_anchor_i after insert on unit_anchor begin update unit set revision = revision + 1 where id = new.unit_id; end;
1017
1053
  create trigger unit_rev_anchor_u after update on unit_anchor begin update unit set revision = revision + 1 where id = new.unit_id; end;
1054
+ create trigger unit_rev_retirement_i after insert on unit_anchor_retirement begin
1055
+ update unit set revision = revision + 1 where id = (select unit_id from unit_anchor where id = new.anchor_id);
1056
+ end;
1057
+ create trigger unit_rev_retirement_d after delete on unit_anchor_retirement begin
1058
+ update unit set revision = revision + 1 where id = (select unit_id from unit_anchor where id = old.anchor_id);
1059
+ end;
1018
1060
  create trigger unit_rev_alias_i after insert on unit_alias begin update unit set revision = revision + 1 where id = new.unit_id; end;
1019
1061
  create trigger unit_rev_field_i after insert on unit_field begin update unit set revision = revision + 1 where id = new.unit_id; end;
1020
1062
  create trigger unit_rev_field_d after delete on unit_field when exists (select 1 from unit where id = old.unit_id) begin
@@ -1225,4 +1267,4 @@ create trigger capture_delivery_prune_insert instead of insert on capture_delive
1225
1267
  order by d.at, d.id limit 200);
1226
1268
  end;
1227
1269
 
1228
- pragma user_version = 11;
1270
+ pragma user_version = 12;
package/dist/capture.js CHANGED
@@ -11396,7 +11396,7 @@ var HOST_MARKS = new Set([".orphaned_at", ".in_use"]);
11396
11396
 
11397
11397
  // server/src/sqlite.ts
11398
11398
  var SCHEMA_GENERATION = 2;
11399
- var SCHEMA_REVISION = 11;
11399
+ var SCHEMA_REVISION = 12;
11400
11400
  var sphicaHome = () => process.env.SPHICA_HOME || path2.join(os.homedir(), ".sphica");
11401
11401
  var dbFile = () => process.env.SPHICA_DB || path2.join(sphicaHome(), "sphica.db");
11402
11402
  function requireRuntime() {
@@ -11606,6 +11606,7 @@ var INGEST_INSERTS = new Set([
11606
11606
  "unit_state",
11607
11607
  "unit_replacement",
11608
11608
  "unit_anchor",
11609
+ "unit_anchor_retirement",
11609
11610
  "unit_alias",
11610
11611
  "field_def",
11611
11612
  "unit_field",
@@ -11650,7 +11651,9 @@ var INGEST_TRIGGER_WRITES = {
11650
11651
  "anchor_u",
11651
11652
  "alias_i",
11652
11653
  "field_i",
11653
- "field_d"
11654
+ "field_d",
11655
+ "retirement_i",
11656
+ "retirement_d"
11654
11657
  ].map((t) => [`unit_rev_${t}`, ["update unit"]])),
11655
11658
  unit_fts_ai: ["insert unit_fts"],
11656
11659
  unit_fts_ad: ["delete unit_fts"],
@@ -11694,6 +11697,7 @@ var FORGET_WRITES = {
11694
11697
  "unit_adoption",
11695
11698
  "source_processing",
11696
11699
  "harvest_run_source",
11700
+ "unit_anchor_retirement",
11697
11701
  "source_fts",
11698
11702
  "field_def",
11699
11703
  "unit_field",
package/dist/cli.js CHANGED
@@ -4911,7 +4911,7 @@ ${indent}${caution(note)}` : ""}`);
4911
4911
 
4912
4912
  // server/src/sqlite.ts
4913
4913
  var SCHEMA_GENERATION = 2;
4914
- var SCHEMA_REVISION = 11;
4914
+ var SCHEMA_REVISION = 12;
4915
4915
  var sphicaHome = () => process.env.SPHICA_HOME || path3.join(os2.homedir(), ".sphica");
4916
4916
  var dbFile = () => process.env.SPHICA_DB || path3.join(sphicaHome(), "sphica.db");
4917
4917
  function requireRuntime() {
@@ -15965,6 +15965,7 @@ var INGEST_INSERTS = new Set([
15965
15965
  "unit_state",
15966
15966
  "unit_replacement",
15967
15967
  "unit_anchor",
15968
+ "unit_anchor_retirement",
15968
15969
  "unit_alias",
15969
15970
  "field_def",
15970
15971
  "unit_field",
@@ -16009,7 +16010,9 @@ var INGEST_TRIGGER_WRITES = {
16009
16010
  "anchor_u",
16010
16011
  "alias_i",
16011
16012
  "field_i",
16012
- "field_d"
16013
+ "field_d",
16014
+ "retirement_i",
16015
+ "retirement_d"
16013
16016
  ].map((t2) => [`unit_rev_${t2}`, ["update unit"]])),
16014
16017
  unit_fts_ai: ["insert unit_fts"],
16015
16018
  unit_fts_ad: ["delete unit_fts"],
@@ -16053,6 +16056,7 @@ var FORGET_WRITES = {
16053
16056
  "unit_adoption",
16054
16057
  "source_processing",
16055
16058
  "harvest_run_source",
16059
+ "unit_anchor_retirement",
16056
16060
  "source_fts",
16057
16061
  "field_def",
16058
16062
  "unit_field",
package/dist/deliver.js CHANGED
@@ -11427,7 +11427,7 @@ var HOST_MARKS = new Set([".orphaned_at", ".in_use"]);
11427
11427
 
11428
11428
  // server/src/sqlite.ts
11429
11429
  var SCHEMA_GENERATION = 2;
11430
- var SCHEMA_REVISION = 11;
11430
+ var SCHEMA_REVISION = 12;
11431
11431
  var sphicaHome = () => process.env.SPHICA_HOME || path3.join(os.homedir(), ".sphica");
11432
11432
  var dbFile = () => process.env.SPHICA_DB || path3.join(sphicaHome(), "sphica.db");
11433
11433
  function requireRuntime() {
@@ -11672,6 +11672,7 @@ var INGEST_INSERTS = new Set([
11672
11672
  "unit_state",
11673
11673
  "unit_replacement",
11674
11674
  "unit_anchor",
11675
+ "unit_anchor_retirement",
11675
11676
  "unit_alias",
11676
11677
  "field_def",
11677
11678
  "unit_field",
@@ -11716,7 +11717,9 @@ var INGEST_TRIGGER_WRITES = {
11716
11717
  "anchor_u",
11717
11718
  "alias_i",
11718
11719
  "field_i",
11719
- "field_d"
11720
+ "field_d",
11721
+ "retirement_i",
11722
+ "retirement_d"
11720
11723
  ].map((t) => [`unit_rev_${t}`, ["update unit"]])),
11721
11724
  unit_fts_ai: ["insert unit_fts"],
11722
11725
  unit_fts_ad: ["delete unit_fts"],
@@ -11760,6 +11763,7 @@ var FORGET_WRITES = {
11760
11763
  "unit_adoption",
11761
11764
  "source_processing",
11762
11765
  "harvest_run_source",
11766
+ "unit_anchor_retirement",
11763
11767
  "source_fts",
11764
11768
  "field_def",
11765
11769
  "unit_field",
@@ -46183,7 +46183,7 @@ var HOST_MARKS = new Set([".orphaned_at", ".in_use"]);
46183
46183
 
46184
46184
  // server/src/sqlite.ts
46185
46185
  var SCHEMA_GENERATION = 2;
46186
- var SCHEMA_REVISION = 11;
46186
+ var SCHEMA_REVISION = 12;
46187
46187
  var sphicaHome = () => process.env.SPHICA_HOME || path2.join(os.homedir(), ".sphica");
46188
46188
  var dbFile = () => process.env.SPHICA_DB || path2.join(sphicaHome(), "sphica.db");
46189
46189
  function requireRuntime() {
@@ -46407,6 +46407,7 @@ var INGEST_INSERTS = new Set([
46407
46407
  "unit_state",
46408
46408
  "unit_replacement",
46409
46409
  "unit_anchor",
46410
+ "unit_anchor_retirement",
46410
46411
  "unit_alias",
46411
46412
  "field_def",
46412
46413
  "unit_field",
@@ -46451,7 +46452,9 @@ var INGEST_TRIGGER_WRITES = {
46451
46452
  "anchor_u",
46452
46453
  "alias_i",
46453
46454
  "field_i",
46454
- "field_d"
46455
+ "field_d",
46456
+ "retirement_i",
46457
+ "retirement_d"
46455
46458
  ].map((t) => [`unit_rev_${t}`, ["update unit"]])),
46456
46459
  unit_fts_ai: ["insert unit_fts"],
46457
46460
  unit_fts_ad: ["delete unit_fts"],
@@ -46495,6 +46498,7 @@ var FORGET_WRITES = {
46495
46498
  "unit_adoption",
46496
46499
  "source_processing",
46497
46500
  "harvest_run_source",
46501
+ "unit_anchor_retirement",
46498
46502
  "source_fts",
46499
46503
  "field_def",
46500
46504
  "unit_field",
@@ -49239,6 +49243,11 @@ var File2 = exports_external.object({
49239
49243
  commit: exports_external.string().min(1).max(100).default("HEAD"),
49240
49244
  lines: exports_external.tuple([exports_external.number().int().positive(), exports_external.number().int().positive()])
49241
49245
  }).strict();
49246
+ var From = exports_external.object({
49247
+ path: exports_external.string().min(1),
49248
+ symbol: exports_external.string().min(1).optional(),
49249
+ role: exports_external.enum(["applies_to", "evidence"]).optional()
49250
+ }).strict();
49242
49251
  var Op = exports_external.discriminatedUnion("op", [
49243
49252
  exports_external.object({
49244
49253
  op: exports_external.literal("add_evidence"),
@@ -49264,7 +49273,7 @@ var Op = exports_external.discriminatedUnion("op", [
49264
49273
  op: exports_external.literal("replace_anchor"),
49265
49274
  unit,
49266
49275
  revision,
49267
- from: exports_external.object({ path: exports_external.string().min(1), symbol: exports_external.string().min(1).optional() }).strict(),
49276
+ from: From,
49268
49277
  to: exports_external.object({
49269
49278
  path: exports_external.string().min(1).max(500),
49270
49279
  symbol: exports_external.string().min(1).max(200).optional(),
@@ -49273,6 +49282,7 @@ var Op = exports_external.discriminatedUnion("op", [
49273
49282
  source: SOURCE_REF2,
49274
49283
  quote
49275
49284
  }).strict(),
49285
+ exports_external.object({ op: exports_external.literal("retire_anchor"), unit, revision, from: From, source: SOURCE_REF2, quote }).strict(),
49276
49286
  exports_external.object({
49277
49287
  op: exports_external.literal("retract_evidence"),
49278
49288
  unit,
@@ -49436,6 +49446,7 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
49436
49446
  return { s, at };
49437
49447
  };
49438
49448
  const replaced = new Map;
49449
+ const retired = new Set;
49439
49450
  const anchored = new Set;
49440
49451
  const places = [];
49441
49452
  const unsourcedSaid = new Set;
@@ -49500,34 +49511,43 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
49500
49511
  errors3.push(`${what}: commit ${op.commit.slice(0, 12)} does not hold ${rel2} in the repository`);
49501
49512
  }
49502
49513
  let replaces = null;
49503
- if (op.op === "replace_anchor") {
49504
- if (!repoPath(op.to.path))
49514
+ let retires = null;
49515
+ if (op.op === "replace_anchor" || op.op === "retire_anchor") {
49516
+ if (op.op === "replace_anchor" && !repoPath(op.to.path))
49505
49517
  errors3.push(`${what}: the path is not inside the repository`);
49506
49518
  const said2 = await span(op.source, op.quote, what);
49507
49519
  if (said2 && said2.s.author_kind !== "owner")
49508
- errors3.push(`${what}: only the owner's words can move an anchor`);
49520
+ errors3.push(`${what}: only the owner's words can ${op.op === "retire_anchor" ? "retire" : "move"} an anchor`);
49509
49521
  const from = repoPath(op.from.path);
49510
49522
  if (!from)
49511
49523
  errors3.push(`${what}: the from path is not inside the repository`);
49512
49524
  else {
49513
- let q = db.selectFrom("unit_anchor").select(["id", "path", "symbol", "role", "commit_sha"]).where("unit_id", "=", u.id).where("path", "=", from).where("retired_at", "is", null);
49525
+ let q = db.selectFrom("unit_anchor").select(["id", "path", "symbol", "role", "commit_sha", "line_start", "line_end"]).where("unit_id", "=", u.id).where("path", "=", from).where("retired_at", "is", null);
49514
49526
  if (op.from.symbol)
49515
49527
  q = q.where("symbol", "=", op.from.symbol);
49516
- const live = await q.execute();
49517
- const name = `${from}${op.from.symbol ? ` ${op.from.symbol}` : ""}`;
49518
- if (live.length === 1) {
49519
- replaces = live[0]?.id ?? null;
49520
- const held = live[0];
49521
- if (held && held.commit_sha === null && held.path === repoPath(op.to.path) && held.symbol === (op.to.symbol ?? null) && held.role === op.to.role)
49528
+ if (op.from.role)
49529
+ q = q.where("role", "=", op.from.role);
49530
+ const live = await q.orderBy("id").execute();
49531
+ const name = `${from}${op.from.symbol ? ` ${op.from.symbol}` : ""}${op.from.role ? ` (${op.from.role})` : ""}`;
49532
+ const held = live.length === 1 ? live[0] : undefined;
49533
+ if (held) {
49534
+ if (op.op === "replace_anchor" && held.commit_sha === null && held.path === repoPath(op.to.path) && held.symbol === (op.to.symbol ?? null) && held.role === op.to.role)
49522
49535
  errors3.push(`${what}: the anchor on ${name} is already that place`);
49523
- if (replaces !== null && replaced.has(replaces))
49524
- errors3.push(`${what}: another operation in this batch already replaces ${name}`);
49525
- if (replaces !== null)
49526
- replaced.set(replaces, i);
49536
+ if (replaced.has(held.id) || retired.has(held.id))
49537
+ errors3.push(`${what}: another operation in this batch already retires or replaces ${name}`);
49538
+ if (op.op === "replace_anchor") {
49539
+ replaces = held.id;
49540
+ replaced.set(held.id, i);
49541
+ } else {
49542
+ retires = held.id;
49543
+ retired.add(held.id);
49544
+ }
49527
49545
  } else if (!live.length)
49528
49546
  errors3.push(`${what}: no live anchor on ${name}`);
49529
- else
49530
- errors3.push(`${what}: ${live.length} live anchors on ${name}; give from.symbol`);
49547
+ else {
49548
+ const which = live.map((a) => `${a.role}${a.symbol ? ` ${inline(head(a.symbol, 80))}` : ""}${a.commit_sha ? ` at ${a.commit_sha.slice(0, 12)}` : ""}${!a.symbol && a.line_start ? ` lines ${a.line_start}-${a.line_end ?? a.line_start}` : ""}`);
49549
+ errors3.push(`${what}: ${live.length} live anchors on ${name} (${which.join("; ")}); give from.symbol or from.role`);
49550
+ }
49531
49551
  }
49532
49552
  }
49533
49553
  const dest = op.op === "anchor" ? op : op.op === "replace_anchor" ? op.to : null;
@@ -49604,10 +49624,22 @@ async function checkGlean(db, target, raw, facts = prepareGlean(target.root, raw
49604
49624
  if (bad.length)
49605
49625
  errors3.push(`${what}: aliases must be 1 to 40 characters; ${bad.map((a) => JSON.stringify(inline(head(a, 60)))).join(", ")}`);
49606
49626
  }
49607
- ops.push({ input: op, unitId: u.id, lifecycle: u.lifecycle, excerpt, retracts, replaces, aliases });
49627
+ ops.push({
49628
+ input: op,
49629
+ unitId: u.id,
49630
+ lifecycle: u.lifecycle,
49631
+ excerpt,
49632
+ retracts,
49633
+ replaces,
49634
+ retires,
49635
+ aliases
49636
+ });
49608
49637
  }
49609
49638
  for (const x of places) {
49610
- const gone = [...replaced].filter(([, by]) => x.replacing === null || by < x.replacing).map(([id]) => id);
49639
+ const gone = [
49640
+ ...retired,
49641
+ ...[...replaced].filter(([, by]) => x.replacing === null || by < x.replacing).map(([id]) => id)
49642
+ ];
49611
49643
  let q = db.selectFrom("unit_anchor").select("id").where("unit_id", "=", x.unit).where("path", "=", x.rel).where("role", "=", x.role).where("retired_at", "is", null).where("id", "not in", [...gone, -1]);
49612
49644
  q = x.symbol ? q.where("symbol", "=", x.symbol) : q.where("symbol", "is", null);
49613
49645
  q = x.commit ? q.where("commit_sha", "=", x.commit) : q.where("commit_sha", "is", null);
@@ -49676,10 +49708,23 @@ ${c.errors.map((e) => ` ${e}`).join(`
49676
49708
  const touched = new Map;
49677
49709
  const withdraw = new Map;
49678
49710
  const adopted = new Set;
49711
+ const moves = ["retire_anchor", "replace_anchor"];
49679
49712
  const ordered = [
49713
+ ...c.ops.filter((p) => p.input.op === "retire_anchor"),
49680
49714
  ...c.ops.filter((p) => p.input.op === "replace_anchor"),
49681
- ...c.ops.filter((p) => p.input.op !== "replace_anchor")
49715
+ ...c.ops.filter((p) => !moves.includes(p.input.op))
49682
49716
  ];
49717
+ const reason2 = async (anchorId, ref, q) => {
49718
+ const s = await spanOf(ref, q);
49719
+ await trx.insertInto("unit_anchor_retirement").values({
49720
+ anchor_id: anchorId ?? -1,
49721
+ run_id: runId,
49722
+ source_id: s.id,
49723
+ span_start: s.start,
49724
+ span_end: s.end,
49725
+ added_at: now
49726
+ }).execute();
49727
+ };
49683
49728
  for (const p of ordered) {
49684
49729
  const op = p.input;
49685
49730
  touched.set(p.unitId, op.unit);
@@ -49737,9 +49782,15 @@ ${c.errors.map((e) => ` ${e}`).join(`
49737
49782
  run_id: runId,
49738
49783
  added_at: now
49739
49784
  }).returning("id").executeTakeFirstOrThrow();
49740
- if (op.op === "replace_anchor")
49785
+ if (op.op === "replace_anchor") {
49741
49786
  await trx.updateTable("unit_anchor").set({ retired_at: now, replaced_by: added.id }).where("id", "=", p.replaces ?? -1).where("retired_at", "is", null).execute();
49787
+ await reason2(p.replaces, op.source, op.quote);
49788
+ }
49742
49789
  changed2.push(`${op.unit}: anchor ${op.op === "anchor" ? "added" : "replaced"}`);
49790
+ } else if (op.op === "retire_anchor") {
49791
+ await trx.updateTable("unit_anchor").set({ retired_at: now }).where("id", "=", p.retires ?? -1).where("retired_at", "is", null).execute();
49792
+ await reason2(p.retires, op.source, op.quote);
49793
+ changed2.push(`${op.unit}: anchor retired`);
49743
49794
  } else if (op.op === "replace_aliases") {
49744
49795
  const { content_hash } = await trx.selectFrom("unit").select("content_hash").where("id", "=", p.unitId).executeTakeFirstOrThrow();
49745
49796
  await trx.insertInto("unit_alias").values({
@@ -49751,17 +49802,17 @@ ${c.errors.map((e) => ` ${e}`).join(`
49751
49802
  }).execute();
49752
49803
  changed2.push(`${op.unit}: aliases ${p.aliases?.length ? "replaced" : "cleared"}`);
49753
49804
  } else {
49754
- const reason2 = await spanOf(op.reason_source, op.reason_quote);
49805
+ const reason3 = await spanOf(op.reason_source, op.reason_quote);
49755
49806
  const retraction = {
49756
49807
  retracted_at: now,
49757
49808
  retraction_reason: op.reason_quote,
49758
- retraction_source_id: reason2.id,
49759
- retraction_span_start: reason2.start,
49760
- retraction_span_end: reason2.end
49809
+ retraction_source_id: reason3.id,
49810
+ retraction_span_start: reason3.start,
49811
+ retraction_span_end: reason3.end
49761
49812
  };
49762
49813
  if (op.op === "resolve_conflict") {
49763
49814
  const other = await trx.selectFrom("unit").select("id").where("project_id", "=", target.projectId).where("key", "=", op.with).executeTakeFirstOrThrow();
49764
- await trx.updateTable("unit_link").set({ resolved_at: now, resolution: `${head(op.reason_quote, 400)} (s${reason2.id})` }).where("kind", "=", "conflicts").where("resolved_at", "is", null).where((eb) => eb.or([
49815
+ await trx.updateTable("unit_link").set({ resolved_at: now, resolution: `${head(op.reason_quote, 400)} (s${reason3.id})` }).where("kind", "=", "conflicts").where("resolved_at", "is", null).where((eb) => eb.or([
49765
49816
  eb.and([eb("from_unit", "=", p.unitId), eb("to_unit", "=", other.id)]),
49766
49817
  eb.and([eb("from_unit", "=", other.id), eb("to_unit", "=", p.unitId)])
49767
49818
  ])).execute();
@@ -49769,7 +49820,7 @@ ${c.errors.map((e) => ` ${e}`).join(`
49769
49820
  continue;
49770
49821
  }
49771
49822
  if (op.op === "withdraw") {
49772
- withdraw.set(p.unitId, { reason: `withdrawn: ${head(op.reason_quote, 200)}`, source: reason2.id });
49823
+ withdraw.set(p.unitId, { reason: `withdrawn: ${head(op.reason_quote, 200)}`, source: reason3.id });
49773
49824
  continue;
49774
49825
  }
49775
49826
  const table = op.op === "retract_evidence" ? "unit_evidence" : "unit_adoption";
@@ -50340,13 +50391,18 @@ ${v.errors.map((e) => ` ${e}`).join(`
50340
50391
  `)}`);
50341
50392
  const { saved, changed: changed2 } = await v.write(trx);
50342
50393
  await finishRun(trx, v.run.id);
50394
+ const warnings = [
50395
+ ...new Set([
50396
+ ...saved.anchorProblems.map((a) => `△ ${a}`),
50397
+ ...v.ops === null ? v.problems.map((n) => `△ ${n}`) : []
50398
+ ])
50399
+ ];
50343
50400
  return [
50344
50401
  ...saved.active.map((k) => `✓ ${k} active`),
50345
50402
  ...saved.superseded.map((k) => `✓ ${k} superseded`),
50346
50403
  ...saved.candidates.map((c) => `△ ${c.key} candidate: ${c.why}`),
50347
50404
  ...saved.quarantined.map((q) => `△ ${q} quarantined`),
50348
- ...saved.anchorProblems.map((a) => `△ ${a}`),
50349
- ...v.ops === null ? v.problems.map((n) => `△ ${n}`) : [],
50405
+ ...warnings,
50350
50406
  ...changed2.map((c) => `✓ ${c}`),
50351
50407
  "✓ saved"
50352
50408
  ].join(`
@@ -50399,7 +50455,8 @@ async function forgetIn(trx, projectId2, ids, at) {
50399
50455
  sources: rows.map((r) => ({ id: r.id, kind: r.kind, artifact: r.artifact, bytes: r.bytes })),
50400
50456
  already,
50401
50457
  units: [],
50402
- fields: { definitions: 0, values: 0 }
50458
+ fields: { definitions: 0, values: 0 },
50459
+ anchorReasons: 0
50403
50460
  };
50404
50461
  if (!rows.length)
50405
50462
  return outcome;
@@ -50418,6 +50475,7 @@ async function forgetIn(trx, projectId2, ids, at) {
50418
50475
  ...defIds.length ? [eb("field_def_id", "in", defIds)] : []
50419
50476
  ])).select((eb) => eb.fn.countAll().as("n")).executeTakeFirstOrThrow()).n)
50420
50477
  };
50478
+ outcome.anchorReasons = Number((await trx.selectFrom("unit_anchor_retirement as r").innerJoin("unit_anchor as a", "a.id", "r.anchor_id").innerJoin("unit as u", "u.id", "a.unit_id").where("u.project_id", "=", projectId2).where("r.source_id", "in", targets).select((eb) => eb.fn.countAll().as("n")).executeTakeFirstOrThrow()).n);
50421
50479
  const removed = new Map;
50422
50480
  for (const u of touched)
50423
50481
  removed.set(u.id, await count("unit_evidence", u.id) + await count("unit_adoption", u.id));
@@ -50508,6 +50566,8 @@ function forgetText(o, file3) {
50508
50566
  }
50509
50567
  if (o.fields.definitions || o.fields.values)
50510
50568
  lines.push(`- ${plural2(o.fields.definitions, "field definition")} and ${plural2(o.fields.values, "field value")} go with them`);
50569
+ if (o.anchorReasons)
50570
+ lines.push(`- ${plural2(o.anchorReasons, "reason")} for retiring or moving an anchor ${o.anchorReasons === 1 ? "goes" : "go"} with them; the anchors stay retired`);
50511
50571
  if (o.units.length || o.fields.values)
50512
50572
  lines.push("Records keep their own text: if one repeats the forgotten words, they stay in it.");
50513
50573
  let copies;
package/dist/mcp.js CHANGED
@@ -46004,7 +46004,7 @@ var HOST_MARKS = new Set([".orphaned_at", ".in_use"]);
46004
46004
 
46005
46005
  // server/src/sqlite.ts
46006
46006
  var SCHEMA_GENERATION = 2;
46007
- var SCHEMA_REVISION = 11;
46007
+ var SCHEMA_REVISION = 12;
46008
46008
  var sphicaHome = () => process.env.SPHICA_HOME || path2.join(os.homedir(), ".sphica");
46009
46009
  var dbFile = () => process.env.SPHICA_DB || path2.join(sphicaHome(), "sphica.db");
46010
46010
  function requireRuntime() {
@@ -46894,7 +46894,24 @@ async function describe3(db, u, root, asOf, renames) {
46894
46894
  "s.created_at",
46895
46895
  "s.text"
46896
46896
  ]).orderBy("a.id").execute(),
46897
- db.selectFrom("unit_anchor").select(["path", "symbol", "role", "commit_sha", "line_start", "retired_at"]).where("unit_id", "=", u.id).where("added_at", "<=", asOf ?? "9999").orderBy("id").execute(),
46897
+ db.selectFrom("unit_anchor as a").leftJoin("unit_anchor as to", "to.id", "a.replaced_by").leftJoin("unit_anchor_retirement as r", (j) => j.onRef("r.anchor_id", "=", "a.id").on("r.added_at", "<=", asOf ?? "9999")).leftJoin("source as s", "s.id", "r.source_id").select([
46898
+ "a.path",
46899
+ "a.symbol",
46900
+ "a.role",
46901
+ "a.commit_sha",
46902
+ "a.line_start",
46903
+ "a.retired_at",
46904
+ "to.path as to_path",
46905
+ "to.symbol as to_symbol",
46906
+ "r.span_start",
46907
+ "r.span_end",
46908
+ "s.id as source",
46909
+ "s.author_kind",
46910
+ "s.author_login",
46911
+ "s.author_association",
46912
+ "s.created_at",
46913
+ "s.text"
46914
+ ]).where("a.unit_id", "=", u.id).where("a.added_at", "<=", asOf ?? "9999").orderBy("a.id").execute(),
46898
46915
  db.selectFrom("unit_link as l").innerJoin("unit as a", "a.id", "l.from_unit").innerJoin("unit as b", "b.id", "l.to_unit").where((eb) => eb.or([eb("l.from_unit", "=", u.id), eb("l.to_unit", "=", u.id)])).where("l.added_at", "<=", asOf ?? "9999").select((eb) => [
46899
46916
  "l.kind",
46900
46917
  "l.resolved_at",
@@ -46987,6 +47004,16 @@ async function describe3(db, u, root, asOf, renames) {
46987
47004
  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${movedTo(root, a, renames, used)}` : ""}`);
46988
47005
  }
46989
47006
  }
47007
+ const retired = anchors.filter((a) => a.retired_at);
47008
+ if (retired.length) {
47009
+ 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):");
47010
+ for (const a of retired) {
47011
+ const where = inline(`${a.path}${a.symbol ? ` ${a.symbol}` : ""}`);
47012
+ const moved = a.to_path ? `, moved to ${inline(`${a.to_path}${a.to_symbol ? ` ${a.to_symbol}` : ""}`)}` : "";
47013
+ const why = a.source !== null && a.text !== null && a.author_kind !== null && a.span_start !== null && a.span_end !== null ? `s${a.source}, ${speaker({ author_kind: a.author_kind, author_login: a.author_login, author_association: a.author_association })}, ${a.created_at}: "${inline(cut(a.text, a.span_start, a.span_end))}"` : "reason not recorded";
47014
+ out.push(` - ${where} (${a.role}${a.commit_sha ? `, commit ${a.commit_sha.slice(0, 12)}` : ""}): retired ${a.retired_at}${moved}; ${why}`);
47015
+ }
47016
+ }
46990
47017
  out.push(...await replacements(db, u.id, links, asOf));
46991
47018
  const conflicting = links.filter((l) => l.kind === "conflicts");
46992
47019
  const sides = await authorityOf(db, conflicting.map((l) => l.from_id === u.id ? l.to_id : l.from_id), asOf);
@@ -47196,7 +47223,7 @@ var DELIVERY_LIMITS_TEXT = [
47196
47223
  "Rows without an agent id count as main, as the host reported them, except a subagent start logged without one: subagent, id unknown.",
47197
47224
  "named later: a captured reply of the same session, after the delivery, writes the key whole (questions asked with AskUserQuestion are not counted). An agent may use a record without naming it, naming it does not mean it helped, a reply may be missing, cut, or redacted in capture, and it may come from any agent of the session."
47198
47225
  ];
47199
- var CLOSING = "Read a record by its key or u<id> before relying on it. Change a record only through /sphica:trace, with the owner's words.";
47226
+ var CLOSING = "Read a record by its key or u<id> before relying on it. Change a record only with the owner's words, through /sphica:trace or /sphica:glean.";
47200
47227
  var BEFORE_KEY = /[A-Za-z0-9_./:-]/;
47201
47228
  var AFTER_KEY = /[A-Za-z0-9_/-]/;
47202
47229
  var KEY_AFTER_DOT = /[A-Za-z0-9_./-]/;
@@ -47907,7 +47934,7 @@ ${shown.length ? shown.join(`
47907
47934
  ${notChecked.length ? notChecked.map((n) => `- ${n}`).join(`
47908
47935
  `) : "nothing: every place above was checked"}`,
47909
47936
  stop ? `Partial: more follow. Call overview with view look and after: "${cursorText(stop)}". Pages are read at different times: a record or file that changed in between may be missed or shown twice.` : "Complete: every section was listed to its end. Not checked entries on any page still apply.",
47910
- "Read a record by its key before acting on it. Change a record only through /sphica:trace, with the owner's words."
47937
+ "Read a record by its key before acting on it. Change a record only with the owner's words, through /sphica:trace or /sphica:glean."
47911
47938
  ].join(`
47912
47939
 
47913
47940
  `);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.40",
3
+ "version": "0.6.41",
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",
@@ -72,7 +72,8 @@ read tools `search` and `read`. Pass the repository root as `cwd` to every tool.
72
72
  |---|---|
73
73
  | `add_evidence` | Cites a `source` ref or a committed `file` (path, commit, lines). `role` as in trace. When the owner reports what someone else said, add `reported_speaker`: it stays the owner's report, never that person's statement or an adoption. A file excerpt is stored with keys masked, so quote words around a key, never the key, and cite whole lines around it: a range that cuts through a private key, or leaves a key's name outside, is refused |
74
74
  | `adopt` | The owner's (or a maintainer's) words that settle a decision or constraint. "Kimura said it was agreed" is not adoption; the owner saying "let's make it final" is |
75
- | `anchor` / `replace_anchor` | Adds a code location, or replaces one whose code moved (`from` and `to`, citing the owner's words); the old one is kept as history. A replacement carries no commit, so an implementation whose proof was the replaced anchor goes back to candidate: add an `anchor` op with `commit` in the same batch to keep it active. A `symbol` that is a key or a value Sphica masks is refused: anchor a name, or the path alone. A warning that the path is not in the working tree (with near paths), is a directory, or does not hold the symbol means fix it and check again |
75
+ | `anchor` / `replace_anchor` | Adds a code location, or replaces one whose code moved (`from` and `to`, citing the owner's words); the old one is kept as history with those words. A replacement carries no commit, so an implementation whose proof was the replaced anchor goes back to candidate: add an `anchor` op with `commit` in the same batch to keep it active. A `symbol` that is a key or a value Sphica masks is refused: anchor a name, or the path alone. A warning that the path is not in the working tree (with near paths), is a directory, or does not hold the symbol means fix it and check again |
76
+ | `retire_anchor` | Retires a code location with nothing in its place (`from`, citing the owner's words). Reads and edits are matched by path, so the record stops being shown on that file only once it has no live `applies_to` anchor on the path; retire each one, whatever its symbol. `from` names one live anchor by `path`, and `symbol` or `role` when the path holds more than one; check lists them when it cannot tell. The anchor is kept as history with the owner's words, and read shows it under retired anchors. Retiring an implementation's only code proof puts it back to candidate. In one batch, retirements run first, then replacements, then new anchors |
76
77
  | `replace_aliases` | Replaces the record's search words (`aliases`, up to 12, each 1 to 40 characters) when search needs a word it lacks (the other language, a common term) or an alias is so broad it floods results. Search only, never evidence, so no quote; read prints the current ones, and `[]` clears them |
77
78
  | `retract_evidence` / `retract_adoption` | Marks a link mistaken, citing the owner's words (`reason_source`, `reason_quote`). When the record cites the same source more than once, add `quote` to say which one. It is kept as history, and the record is judged again |
78
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 |