sphica 0.6.40 → 0.6.42
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/THIRD_PARTY_NOTICES.md +2 -2
- package/db/migrations/0012.sql +59 -0
- package/db/schema.sql +44 -2
- package/dist/capture.js +6 -2
- package/dist/cli.js +6 -2
- package/dist/deliver.js +15 -4
- package/dist/mcp-record.js +92 -32
- package/dist/mcp.js +110 -30
- package/package.json +1 -1
- package/skills/glean/SKILL.md +2 -1
- package/skills/review/reviewers/precedent.md +5 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "sphica",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.42",
|
|
5
5
|
"description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "iroha924",
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -10,7 +10,7 @@ This file is generated by `node scripts/third-party-notices.mjs`. Do not edit it
|
|
|
10
10
|
| @clack/core | 1.5.1 | MIT |
|
|
11
11
|
| @clack/prompts | 1.8.1 | MIT |
|
|
12
12
|
| @hono/node-server | 2.1.1 | MIT |
|
|
13
|
-
| @modelcontextprotocol/sdk | 1.
|
|
13
|
+
| @modelcontextprotocol/sdk | 1.31.0 | MIT |
|
|
14
14
|
| @stricli/core | 1.3.0 | Apache-2.0 |
|
|
15
15
|
| accepts | 2.0.0 | MIT |
|
|
16
16
|
| ajv | 8.20.0 | MIT |
|
|
@@ -174,7 +174,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
174
174
|
SOFTWARE.
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
## @modelcontextprotocol/sdk 1.
|
|
177
|
+
## @modelcontextprotocol/sdk 1.31.0
|
|
178
178
|
|
|
179
179
|
SPDX: MIT
|
|
180
180
|
Source: https://github.com/modelcontextprotocol/typescript-sdk
|
|
@@ -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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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",
|
|
@@ -12799,6 +12803,11 @@ if (process.argv[1] && /capture\.(ts|js)$/.test(process.argv[1])) {
|
|
|
12799
12803
|
main().catch(() => {});
|
|
12800
12804
|
}
|
|
12801
12805
|
|
|
12806
|
+
// server/src/read.ts
|
|
12807
|
+
var READ_BUDGET = 32 * 1024;
|
|
12808
|
+
var CONTROL_SEQUENCE = /(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]?/;
|
|
12809
|
+
var HIDDEN = new RegExp(`${STRING_SEQUENCE.source}|${CONTROL_SEQUENCE.source}`, "g");
|
|
12810
|
+
|
|
12802
12811
|
// server/src/review.ts
|
|
12803
12812
|
var ESCAPES = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13, '"': 34, "\\": 92 };
|
|
12804
12813
|
function gitPath(token, prefix) {
|
|
@@ -12909,7 +12918,8 @@ async function selectForReview(db, projectId2, files) {
|
|
|
12909
12918
|
kind: a.kind,
|
|
12910
12919
|
stance: a.stance,
|
|
12911
12920
|
text: a.text,
|
|
12912
|
-
because: `anchored to ${a.path}${a.symbol ? ` ${a.symbol}` : ""}
|
|
12921
|
+
because: `anchored to ${a.path}${a.symbol ? ` ${a.symbol}` : ""}`,
|
|
12922
|
+
why: { path: a.path, symbol: a.symbol }
|
|
12913
12923
|
});
|
|
12914
12924
|
const added = files.flatMap((f) => f.added.map((l) => ({ path: f.path, text: l.normalize("NFKC").toLowerCase() })));
|
|
12915
12925
|
const locationFree = live.where("u.stance", "in", ["dont", "defer"]).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.retired_at", "is", null))));
|
|
@@ -12931,7 +12941,8 @@ async function selectForReview(db, projectId2, files) {
|
|
|
12931
12941
|
kind: u.kind,
|
|
12932
12942
|
stance: u.stance,
|
|
12933
12943
|
text: u.text,
|
|
12934
|
-
because: `an added line in ${hit.path} names the option ${o.text}
|
|
12944
|
+
because: `an added line in ${hit.path} names the option ${o.text}`,
|
|
12945
|
+
why: { path: hit.path, option: o.text }
|
|
12935
12946
|
});
|
|
12936
12947
|
break;
|
|
12937
12948
|
}
|
package/dist/mcp-record.js
CHANGED
|
@@ -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 =
|
|
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:
|
|
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
|
-
|
|
49504
|
-
|
|
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
|
-
|
|
49517
|
-
|
|
49518
|
-
|
|
49519
|
-
|
|
49520
|
-
|
|
49521
|
-
|
|
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 (
|
|
49524
|
-
errors3.push(`${what}: another operation in this batch already replaces ${name}`);
|
|
49525
|
-
if (
|
|
49526
|
-
|
|
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
|
-
|
|
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({
|
|
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 = [
|
|
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
|
|
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
|
|
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:
|
|
49759
|
-
retraction_span_start:
|
|
49760
|
-
retraction_span_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${
|
|
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:
|
|
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
|
-
...
|
|
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 =
|
|
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").
|
|
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
|
|
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_./-]/;
|
|
@@ -47701,21 +47728,31 @@ async function liveOverview(db, projectId, after) {
|
|
|
47701
47728
|
const n = Number(total?.n ?? 0);
|
|
47702
47729
|
if (!shown.length)
|
|
47703
47730
|
return after === null ? "No active decision or constraint is recorded for this project. status says whether sessions are still untraced." : `No active decision or constraint after id ${after}. ${n} in all.`;
|
|
47704
|
-
const
|
|
47705
|
-
|
|
47706
|
-
|
|
47707
|
-
|
|
47708
|
-
|
|
47709
|
-
|
|
47710
|
-
|
|
47711
|
-
|
|
47712
|
-
|
|
47713
|
-
|
|
47714
|
-
|
|
47715
|
-
|
|
47716
|
-
|
|
47717
|
-
|
|
47731
|
+
const page = (taken) => {
|
|
47732
|
+
const groups = [...new Set(taken.map((s) => s.group))].sort((a, b) => a === PROJECT_WIDE ? 1 : b === PROJECT_WIDE ? -1 : a.localeCompare(b));
|
|
47733
|
+
const last = taken.at(-1)?.id ?? 0;
|
|
47734
|
+
return [
|
|
47735
|
+
...groups.flatMap((g) => [
|
|
47736
|
+
`## ${head(inline(g), OVERVIEW_LIMITS.heading)}`,
|
|
47737
|
+
...taken.filter((s) => s.group === g).map((s) => s.line),
|
|
47738
|
+
""
|
|
47739
|
+
]),
|
|
47740
|
+
`${taken.length} shown of ${n} active decisions and constraints${after === null ? "" : ` (ids after ${after})`}.`,
|
|
47741
|
+
rows.length > taken.length ? `More follow: call overview again with after: ${last}. Pages are read at different times: a record that became active in between, with a lower id, is not on a later page.` : "That is the end of the list.",
|
|
47742
|
+
"Read a record by its key or u<id> before relying on it.",
|
|
47743
|
+
...taken.some((x) => whose.get(x.id) === "agent") ? [AI_DECIDED] : []
|
|
47744
|
+
].join(`
|
|
47718
47745
|
`);
|
|
47746
|
+
};
|
|
47747
|
+
const frame = bytes(framed(""));
|
|
47748
|
+
let best = page(shown.slice(0, 1));
|
|
47749
|
+
for (let k = 2;k <= shown.length; k++) {
|
|
47750
|
+
const candidate = page(shown.slice(0, k));
|
|
47751
|
+
if (frame + bytes(candidate) > READ_BUDGET)
|
|
47752
|
+
break;
|
|
47753
|
+
best = candidate;
|
|
47754
|
+
}
|
|
47755
|
+
return best;
|
|
47719
47756
|
}
|
|
47720
47757
|
var LOOK_LIMITS = { anchors: 2000, line: 2200, bytes: READ_BUDGET - 4 * 1024 };
|
|
47721
47758
|
var CONDITION_ROWS = Math.ceil(LOOK_LIMITS.bytes / 28);
|
|
@@ -47907,7 +47944,7 @@ ${shown.length ? shown.join(`
|
|
|
47907
47944
|
${notChecked.length ? notChecked.map((n) => `- ${n}`).join(`
|
|
47908
47945
|
`) : "nothing: every place above was checked"}`,
|
|
47909
47946
|
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
|
|
47947
|
+
"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
47948
|
].join(`
|
|
47912
47949
|
|
|
47913
47950
|
`);
|
|
@@ -48135,7 +48172,8 @@ async function selectForReview(db, projectId2, files) {
|
|
|
48135
48172
|
kind: a.kind,
|
|
48136
48173
|
stance: a.stance,
|
|
48137
48174
|
text: a.text,
|
|
48138
|
-
because: `anchored to ${a.path}${a.symbol ? ` ${a.symbol}` : ""}
|
|
48175
|
+
because: `anchored to ${a.path}${a.symbol ? ` ${a.symbol}` : ""}`,
|
|
48176
|
+
why: { path: a.path, symbol: a.symbol }
|
|
48139
48177
|
});
|
|
48140
48178
|
const added = files.flatMap((f) => f.added.map((l) => ({ path: f.path, text: l.normalize("NFKC").toLowerCase() })));
|
|
48141
48179
|
const locationFree = live.where("u.stance", "in", ["dont", "defer"]).where(({ not, exists, selectFrom }) => not(exists(selectFrom("unit_anchor as a").select("a.id").whereRef("a.unit_id", "=", "u.id").where("a.retired_at", "is", null))));
|
|
@@ -48157,7 +48195,8 @@ async function selectForReview(db, projectId2, files) {
|
|
|
48157
48195
|
kind: u.kind,
|
|
48158
48196
|
stance: u.stance,
|
|
48159
48197
|
text: u.text,
|
|
48160
|
-
because: `an added line in ${hit.path} names the option ${o.text}
|
|
48198
|
+
because: `an added line in ${hit.path} names the option ${o.text}`,
|
|
48199
|
+
why: { path: hit.path, option: o.text }
|
|
48161
48200
|
});
|
|
48162
48201
|
break;
|
|
48163
48202
|
}
|
|
@@ -48186,13 +48225,57 @@ async function reviewBatch(db, projectId2, files, after, diff) {
|
|
|
48186
48225
|
};
|
|
48187
48226
|
}
|
|
48188
48227
|
var AI_DEPARTURE = "A record marked decided by an AI was decided by an AI in an earlier session, not by the owner: a change that departs from it is a violation only when the change gives no reason for departing.";
|
|
48189
|
-
|
|
48228
|
+
var SHOWN = { text: 300, path: 160, symbol: 80, option: 160 };
|
|
48229
|
+
var LEAST = 24;
|
|
48230
|
+
var NONE2 = { text: 0, path: 0, symbol: 0, option: 0 };
|
|
48231
|
+
var part = (value, max) => {
|
|
48232
|
+
if (!max)
|
|
48233
|
+
return "";
|
|
48234
|
+
const v = inline(value);
|
|
48235
|
+
return bytes(v) <= max ? v : `${head(v, max - 3)}…`;
|
|
48236
|
+
};
|
|
48237
|
+
async function selectedText(db, hits, room) {
|
|
48190
48238
|
const whose = await authorityOf(db, hits.map((u) => u.id));
|
|
48191
|
-
const
|
|
48192
|
-
|
|
48193
|
-
|
|
48194
|
-
|
|
48195
|
-
|
|
48239
|
+
const marked = (u) => whose.get(u.id) === "agent" ? ", decided by an AI" : "";
|
|
48240
|
+
const tail = hits.some((u) => whose.get(u.id) === "agent") ? [AI_DEPARTURE] : [];
|
|
48241
|
+
const line = (u, c) => {
|
|
48242
|
+
const why = "option" in u.why ? `an added line in ${part(u.why.path, c.path)} names the option ${part(u.why.option, c.option)}` : `anchored to ${part(u.why.path, c.path)}${u.why.symbol ? ` ${part(u.why.symbol, c.symbol)}` : ""}`;
|
|
48243
|
+
return `- ${inline(u.key)} (u${u.id}, ${u.kind}${u.stance ? ` ${u.stance}` : ""}${marked(u)}): ${part(u.text, c.text)} [${why}]`;
|
|
48244
|
+
};
|
|
48245
|
+
const join = (lines2) => [...lines2, ...tail].join(`
|
|
48246
|
+
`);
|
|
48247
|
+
const each = Math.floor((room - bytes(join(hits.map((u) => line(u, NONE2))))) / Math.max(1, hits.length));
|
|
48248
|
+
if (each >= LEAST) {
|
|
48249
|
+
const text2 = join(hits.map((u) => {
|
|
48250
|
+
const t = Math.min(SHOWN.text, Math.floor(each / 2));
|
|
48251
|
+
const rest = each - t;
|
|
48252
|
+
const two = "option" in u.why || u.why.symbol;
|
|
48253
|
+
const path8 = Math.min(SHOWN.path, two ? Math.floor(rest / 2) : rest);
|
|
48254
|
+
return line(u, {
|
|
48255
|
+
text: t,
|
|
48256
|
+
path: path8,
|
|
48257
|
+
symbol: Math.min(SHOWN.symbol, rest - path8),
|
|
48258
|
+
option: Math.min(SHOWN.option, rest - path8)
|
|
48259
|
+
});
|
|
48260
|
+
}));
|
|
48261
|
+
if (bytes(text2) <= room)
|
|
48262
|
+
return { text: text2, byId: false };
|
|
48263
|
+
}
|
|
48264
|
+
return {
|
|
48265
|
+
text: join(hits.map((u) => `- u${u.id}${marked(u) ? ` (${marked(u).slice(2)})` : ""}`)),
|
|
48266
|
+
byId: true
|
|
48267
|
+
};
|
|
48268
|
+
}
|
|
48269
|
+
var BY_ID = "The keys are too long to show here: read each by u<id>, and pass the key read shows as the finding's unit.";
|
|
48270
|
+
async function selectReply(db, b, after) {
|
|
48271
|
+
const from = b.all.length - b.all.filter((u) => u.id > (after ?? 0)).length + 1;
|
|
48272
|
+
const lead = `Decision lane: checked. ${b.all.length} records apply. Batch ${b.k} of ${b.n} (records ${from}-${from + b.records.length - 1}), selection ${b.selection}; read each before judging it.`;
|
|
48273
|
+
const end = b.next === null ? "This is the last batch." : `Next batch: after checking this one, call review_select with after: ${b.next}.`;
|
|
48274
|
+
const room = READ_BUDGET - bytes(`${lead} ${BY_ID}
|
|
48275
|
+
${framed("")}
|
|
48276
|
+
${end}`);
|
|
48277
|
+
const s = await selectedText(db, b.records, room);
|
|
48278
|
+
return [s.byId ? `${lead} ${BY_ID}` : lead, framed(s.text), end].join(`
|
|
48196
48279
|
`);
|
|
48197
48280
|
}
|
|
48198
48281
|
|
|
@@ -48593,10 +48676,7 @@ server.registerTool("review_select", {
|
|
|
48593
48676
|
return text2(`Decision lane: not checked. after ${a.after} is not where a batch ended: pass the after a batch gave, or none for the first batch.`, true);
|
|
48594
48677
|
if (!b.records.length)
|
|
48595
48678
|
return text2(`Decision lane: checked. No record after id ${a.after}: ${b.all.length} records apply in all (selection ${b.selection}).`);
|
|
48596
|
-
|
|
48597
|
-
return text2(`Decision lane: checked. ${b.all.length} records apply. Batch ${b.k} of ${b.n} (records ${from}-${from + b.records.length - 1}), selection ${b.selection}; read each before judging it.
|
|
48598
|
-
${framed(await selectedText(db, b.records))}
|
|
48599
|
-
${b.next === null ? "This is the last batch." : `Next batch: after checking this one, call review_select with after: ${b.next}.`}`);
|
|
48679
|
+
return text2(await selectReply(db, b, a.after ?? null));
|
|
48600
48680
|
} catch (e) {
|
|
48601
48681
|
return notChecked(e);
|
|
48602
48682
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sphica",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.42",
|
|
4
4
|
"description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/skills/glean/SKILL.md
CHANGED
|
@@ -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 |
|
|
@@ -32,7 +32,7 @@ Pass the diff under review and the root of the repository under review (`cwd`) t
|
|
|
32
32
|
|---|---|---|
|
|
33
33
|
| The tool call fails, or it says "Decision lane: not checked" | MCP does not connect, the database is unreachable, or the project is not registered | **`blocked_unknown`** + the reason it gave |
|
|
34
34
|
| "Decision lane: checked" with no record | No active record applies | Continue to Step 3; 0 records may be treated as a **grounded negative** |
|
|
35
|
-
| "Decision lane: checked" with records | One batch of at most 50 records, `Batch k of n`, and a `selection`. Each record says why it applies (anchored to a changed path, or an added line names an option it rejected); an AI's decision is marked `decided by an AI` | Continue |
|
|
35
|
+
| "Decision lane: checked" with records | One batch of at most 50 records, `Batch k of n`, and a `selection`. Each record says why it applies (anchored to a changed path, or an added line names an option it rejected), cut short with `…` when long; an AI's decision is marked `decided by an AI`. A batch whose keys are too long to show lists `u<id>` alone and says so | Continue |
|
|
36
36
|
|
|
37
37
|
**When returning `blocked_unknown`, state concretely what was missing.** Silently returning 0 results makes the caller read it as "no findings".
|
|
38
38
|
**This step is deterministic and can claim coverage.** It selects only active records; candidates and superseded records never apply.
|
|
@@ -45,8 +45,10 @@ Changes to the working tree between batches (which code locations still exist) a
|
|
|
45
45
|
|
|
46
46
|
## Step 2 — Read every selected record
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
Read them by the `u<id>` each line gives: `read(["u12", "u40"], cwd)`. A batch whose keys are too long to show names its records by
|
|
49
|
+
`u<id>` alone, and read shows each one's whole key, which its finding's `unit` takes. read returns each record's text, its options, the
|
|
50
|
+
exact words cited as evidence and adoption with who said them, what it superseded or conflicts with, and each code location checked in
|
|
51
|
+
the working tree now. **Judge from this body, never from the key or the one line**, which is cut short (`…`) to keep the batch whole.
|
|
50
52
|
When a reply says some refs were not read or a record continues, call `read` again with exactly what it names until nothing is left.
|
|
51
53
|
|
|
52
54
|
## Step 3 — Search by the approach's meaning
|