sphica 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +15 -30
- package/THIRD_PARTY_NOTICES.md +0 -53
- package/db/migrations/0006_harvest_provenance.sql +45 -0
- package/db/migrations/0007_drop_bulk_import.sql +238 -0
- package/db/schema.sql +35 -111
- package/dist/capture.js +4 -13
- package/dist/cli.js +1230 -3648
- package/dist/mcp.js +50 -163
- package/package.json +1 -1
- package/skills/harvest/SKILL.md +114 -0
- package/skills/harvest/agents/openai.yaml +2 -0
- package/skills/review/SKILL.md +1 -1
- package/skills/trace/SKILL.md +28 -18
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://anthropic.com/claude-code/plugin.schema.json",
|
|
3
3
|
"name": "sphica",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"description": "Records conversations automatically and recalls past decisions, rejected options, constraints, and what was said.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "iroha924",
|
package/README.md
CHANGED
|
@@ -16,12 +16,12 @@ The database is a single SQLite file on your machine.
|
|
|
16
16
|
|
|
17
17
|
## Features
|
|
18
18
|
|
|
19
|
-
- **Look things up while you work.** The MCP tools `recall` and `read` let Claude Code and Codex search past decisions, rejected options, constraints, dead ends, and what you
|
|
19
|
+
- **Look things up while you work.** The MCP tools `recall` and `read` let Claude Code and Codex search past decisions, rejected options, constraints, dead ends, and what you said in earlier sessions.
|
|
20
20
|
- **Warnings before an edit (Claude Code).** Before the agent edits a file, a hook shows it the constraints recorded for that exact file and any technical debt that was deliberately left there.
|
|
21
21
|
- **Automatic session recording.** Sphica keeps your prompts, the agent's final reply for each turn, and the paths of files changed by the agent's edit tools.
|
|
22
|
-
- **Decision records on request.** `/sphica:trace` saves the decisions, rejected options, constraints, and dead ends of a session, plus where the work stands.
|
|
22
|
+
- **Decision records on request.** `/sphica:trace` saves the decisions, rejected options, constraints, and dead ends of a session, with the pull requests and issues mentioned in it, plus where the work stands.
|
|
23
23
|
- **Multi-perspective review.** `/sphica:review` runs a separate reviewer for each focus: correctness, security, and written conventions by default, plus redundancy and past decisions with `full`. When Codex is installed, it offers to repeat the review with Codex.
|
|
24
|
-
- **
|
|
24
|
+
- **Decisions from a pull request.** `/sphica:harvest <number>` reads one GitHub pull request, including its review comments and follow-up commits, and saves what it decided in the same form. The agent picks the decisions, so it works with any pull request template.
|
|
25
25
|
|
|
26
26
|
The agent is told to treat records as history, not instructions, and to trust the code when a record and the current code disagree.
|
|
27
27
|
|
|
@@ -30,7 +30,7 @@ The agent is told to treat records as history, not instructions, and to trust th
|
|
|
30
30
|
- Node.js 24.15 or later
|
|
31
31
|
- Claude Code or Codex, or both
|
|
32
32
|
- `git`, to identify the repositories you register
|
|
33
|
-
- For
|
|
33
|
+
- For `/sphica:harvest` only: the GitHub CLI (`gh`), signed in with `gh auth login`
|
|
34
34
|
|
|
35
35
|
## Install
|
|
36
36
|
|
|
@@ -60,13 +60,14 @@ codex plugin add sphica@sphica
|
|
|
60
60
|
|
|
61
61
|
In Codex, open `/hooks` and mark Sphica's hooks as trusted. Nothing is recorded until you do. If a plugin update changes the hooks, trust them again.
|
|
62
62
|
|
|
63
|
-
**3.
|
|
63
|
+
**3. Set up in your repository**
|
|
64
64
|
|
|
65
65
|
```bash
|
|
66
|
+
cd ~/Projects/your-repo
|
|
66
67
|
sphica init
|
|
67
68
|
```
|
|
68
69
|
|
|
69
|
-
This creates `~/.sphica/sphica.db
|
|
70
|
+
This creates `~/.sphica/sphica.db` and registers the repository. Running it again leaves both untouched. If the repository has no `origin` remote, give it a name: `sphica init --name <name>`.
|
|
70
71
|
|
|
71
72
|
**4. Check the setup**
|
|
72
73
|
|
|
@@ -78,14 +79,7 @@ sphica doctor
|
|
|
78
79
|
|
|
79
80
|
## Quick start
|
|
80
81
|
|
|
81
|
-
Sphica writes sessions to the database only for repositories you register. A registered repository is called a project.
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
cd ~/Projects/your-repo
|
|
85
|
-
sphica project add
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
If the repository has no `origin` remote, give it a name: `sphica project add --name <name>`.
|
|
82
|
+
Sphica writes sessions to the database only for repositories you register. A registered repository is called a project; run `sphica init` in each repository you want recorded.
|
|
89
83
|
|
|
90
84
|
Then work as usual in Claude Code or Codex. To bring back earlier decisions, ask the agent:
|
|
91
85
|
|
|
@@ -96,15 +90,7 @@ Then work as usual in Claude Code or Codex. To bring back earlier decisions, ask
|
|
|
96
90
|
|
|
97
91
|
The agent searches with `recall` and opens full records with `read`. At the end of a session with decisions worth keeping, run `/sphica:trace`.
|
|
98
92
|
|
|
99
|
-
To
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
sphica harvest # every project Sphica can find on this machine
|
|
103
|
-
sphica harvest --cwd . # only the current repository
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Without `--cwd`, Sphica looks for projects directly under `~/Projects` and for projects registered with `--name`. Use `--cwd` for a repository somewhere else.
|
|
107
|
-
Docs are read from the default branch of `origin`, or from the local `HEAD` when there is no `origin`.
|
|
93
|
+
To keep what a pull request decided, run `/sphica:harvest 123` in Claude Code (`$sphica:harvest 123` in Codex). Without a number, it lists recent pull requests and asks which one.
|
|
108
94
|
|
|
109
95
|
## What gets recorded and where it goes
|
|
110
96
|
|
|
@@ -119,8 +105,8 @@ Docs are read from the default branch of `origin`, or from the local `HEAD` when
|
|
|
119
105
|
- `mysql -p`
|
|
120
106
|
|
|
121
107
|
**Anything else is stored as typed, so do not paste secrets into a session.**
|
|
122
|
-
- **Network.** Sphica has no account, no hosted service, and no telemetry, and makes no network connections itself. Two
|
|
123
|
-
- **Text written by others.** Pull request
|
|
108
|
+
- **Network.** Sphica has no account, no hosted service, and no telemetry, and makes no network connections itself. Two things call other tools that may: `/sphica:harvest` runs `gh api` with your credentials to read the pull request, and `sphica doctor` runs `npm` and `claude` to check installed versions.
|
|
109
|
+
- **Text written by others.** Pull request text read by `/sphica:harvest` may come from anyone. It is passed to the agent as data, and the MCP server cannot write to the database. The command that saves a harvest writes only records of that pull request in the current repository.
|
|
124
110
|
|
|
125
111
|
To delete a project's data, run `sphica project forget <name>`, where `<name>` is shown by `sphica project list`. Without `--yes`, it only shows how many records would be deleted. It deletes records in the database only. Records still waiting in `~/.sphica/spool` stay there and can be imported again if you register the repository again.
|
|
126
112
|
|
|
@@ -183,12 +169,11 @@ Run `sphica doctor` first. It shows which part is out of date or not working. Co
|
|
|
183
169
|
|
|
184
170
|
| Command | What it does |
|
|
185
171
|
|---|---|
|
|
186
|
-
| `sphica init` | Create the database |
|
|
187
|
-
| `sphica doctor` | Check versions, the database, and
|
|
188
|
-
| `sphica
|
|
189
|
-
| `sphica harvest` | Import GitHub pull requests, issues, and Markdown docs |
|
|
172
|
+
| `sphica init` | Create the database and register the current repository |
|
|
173
|
+
| `sphica doctor` | Check versions, the database, recording, and each project's last harvest |
|
|
174
|
+
| `sphica advice` | See how often the edit hook showed constraints |
|
|
190
175
|
|
|
191
|
-
Run `sphica --help` for
|
|
176
|
+
Run `sphica --help` for these, `sphica -H` for every command (managing projects, and the ones agents and maintenance use), and `sphica <command> --help` for each command's options.
|
|
192
177
|
|
|
193
178
|
## Security
|
|
194
179
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -68,7 +68,6 @@ This file is generated by `node scripts/third-party-notices.mjs`. Do not edit it
|
|
|
68
68
|
| json-schema-traverse | 1.0.0 | MIT |
|
|
69
69
|
| json-schema-typed | 8.0.2 | BSD-2-Clause |
|
|
70
70
|
| kysely | 0.29.6 | MIT |
|
|
71
|
-
| marked | 18.0.14 | MIT |
|
|
72
71
|
| math-intrinsics | 1.1.0 | MIT |
|
|
73
72
|
| media-typer | 1.1.1 | MIT |
|
|
74
73
|
| merge-descriptors | 2.0.0 | MIT |
|
|
@@ -2092,58 +2091,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
2092
2091
|
SOFTWARE.
|
|
2093
2092
|
```
|
|
2094
2093
|
|
|
2095
|
-
## marked 18.0.14
|
|
2096
|
-
|
|
2097
|
-
SPDX: MIT
|
|
2098
|
-
Source: https://github.com/markedjs/marked
|
|
2099
|
-
|
|
2100
|
-
```
|
|
2101
|
-
# License information
|
|
2102
|
-
|
|
2103
|
-
## Contribution License Agreement
|
|
2104
|
-
|
|
2105
|
-
If you contribute code to this project, you are implicitly allowing your code
|
|
2106
|
-
to be distributed under the MIT license. You are also implicitly verifying that
|
|
2107
|
-
all code is your original work. `</legalese>`
|
|
2108
|
-
|
|
2109
|
-
## Marked
|
|
2110
|
-
|
|
2111
|
-
Copyright (c) 2018+, MarkedJS (https://github.com/markedjs/)
|
|
2112
|
-
Copyright (c) 2011-2018, Christopher Jeffrey (https://github.com/chjj/)
|
|
2113
|
-
|
|
2114
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
2115
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
2116
|
-
in the Software without restriction, including without limitation the rights
|
|
2117
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
2118
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
2119
|
-
furnished to do so, subject to the following conditions:
|
|
2120
|
-
|
|
2121
|
-
The above copyright notice and this permission notice shall be included in
|
|
2122
|
-
all copies or substantial portions of the Software.
|
|
2123
|
-
|
|
2124
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
2125
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
2126
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
2127
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
2128
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
2129
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
2130
|
-
THE SOFTWARE.
|
|
2131
|
-
|
|
2132
|
-
## Markdown
|
|
2133
|
-
|
|
2134
|
-
Copyright © 2004, John Gruber
|
|
2135
|
-
http://daringfireball.net/
|
|
2136
|
-
All rights reserved.
|
|
2137
|
-
|
|
2138
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
2139
|
-
|
|
2140
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
2141
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
2142
|
-
* Neither the name “Markdown” nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
2143
|
-
|
|
2144
|
-
This software is provided by the copyright holders and contributors “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
|
|
2145
|
-
```
|
|
2146
|
-
|
|
2147
2094
|
## math-intrinsics 1.1.0
|
|
2148
2095
|
|
|
2149
2096
|
SPDX: MIT
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- Prepares removing the bulk import (GitHub sync, docs sync, PR-body extraction) and the people directory.
|
|
2
|
+
-- Decisions extracted from the owner's merged PR bodies are kept: they get a pull_request row as their provenance (0007 attaches them),
|
|
3
|
+
-- because trace verifications and supersessions may point at them. Document sections and GitHub conversations are deleted here, with
|
|
4
|
+
-- foreign keys on, so their messages, files, and terms go by cascade. 0007 rebuilds the tables without the removed columns.
|
|
5
|
+
|
|
6
|
+
-- Stop before deleting anything if a record outside the removed import points at a document section (trace can only point at decisions,
|
|
7
|
+
-- so this should be empty). A row that fails the CHECK aborts the migration.
|
|
8
|
+
create temp table guard (what text not null, n integer not null check (n = 0));
|
|
9
|
+
insert into guard
|
|
10
|
+
select 'records pointing at document sections', count(*)
|
|
11
|
+
from knowledge k join knowledge d on d.id in (k.decision_id, k.superseded_by_id)
|
|
12
|
+
where d.kind = 'document' and k.kind <> 'document';
|
|
13
|
+
insert into guard
|
|
14
|
+
select 'pull requests with a number that is not a positive integer', count(*)
|
|
15
|
+
from source_item s
|
|
16
|
+
where s.kind = 'pull_request'
|
|
17
|
+
and exists (select 1 from knowledge k where k.source_item_id = s.id)
|
|
18
|
+
and (cast(s.external_id as integer) <= 0 or cast(cast(s.external_id as integer) as text) <> s.external_id);
|
|
19
|
+
drop table guard;
|
|
20
|
+
|
|
21
|
+
create table pull_request (
|
|
22
|
+
id integer primary key autoincrement not null,
|
|
23
|
+
project_id integer not null references project (id) on delete cascade,
|
|
24
|
+
number integer not null check (number > 0),
|
|
25
|
+
github_id integer check (github_id > 0),
|
|
26
|
+
title text not null check (title <> ''),
|
|
27
|
+
url text,
|
|
28
|
+
state text not null check (state in ('open', 'merged', 'closed')),
|
|
29
|
+
harvested_at text check (strftime('%Y-%m-%dT%H:%M:%fZ', harvested_at) is harvested_at),
|
|
30
|
+
unique (project_id, number)
|
|
31
|
+
) strict;
|
|
32
|
+
|
|
33
|
+
insert into pull_request (project_id, number, title, url, state)
|
|
34
|
+
select c.project_id, cast(s.external_id as integer), s.title, s.url, s.state
|
|
35
|
+
from source_item s join connector c on c.id = s.connector_id
|
|
36
|
+
where s.kind = 'pull_request'
|
|
37
|
+
and exists (select 1 from knowledge k where k.source_item_id = s.id and k.kind <> 'document');
|
|
38
|
+
|
|
39
|
+
-- The moved decisions no longer belong to the GitHub conversation, which is deleted below (their provenance is the pull request)
|
|
40
|
+
update knowledge set conversation_id = null where source_item_id is not null and kind <> 'document';
|
|
41
|
+
-- Their search words came from the PR body, not from the harvest Skill
|
|
42
|
+
update knowledge_terms set source = 'import' where source = 'pr';
|
|
43
|
+
|
|
44
|
+
delete from knowledge where kind = 'document';
|
|
45
|
+
delete from conversation where origin = 'github';
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
-- sphica: foreign_keys=off
|
|
2
|
+
-- Rebuilds the tables that held the removed bulk import's columns and values, and drops the removed tables.
|
|
3
|
+
-- knowledge keeps its ids (the knowledge_fts rowid, and decision_id / superseded_by_id), and message keeps seq (the message_fts rowid).
|
|
4
|
+
-- The decisions 0006 kept move to their pull_request, with keys `pr:<number>#...` (the project already fixes the repository).
|
|
5
|
+
-- The runner turns foreign keys off for this file and checks `pragma foreign_key_check` before committing.
|
|
6
|
+
create temp table knowledge_seq as select seq from sqlite_sequence where name = 'knowledge';
|
|
7
|
+
|
|
8
|
+
-- Triggers that read the view go first: a rename re-reads every trigger, and one pointing at a dropped view stops it
|
|
9
|
+
drop trigger knowledge_fts_ai;
|
|
10
|
+
drop trigger knowledge_fts_ad;
|
|
11
|
+
drop trigger knowledge_fts_au;
|
|
12
|
+
drop trigger knowledge_terms_ai;
|
|
13
|
+
drop trigger knowledge_terms_au;
|
|
14
|
+
drop trigger knowledge_terms_ad;
|
|
15
|
+
drop view knowledge_search_text;
|
|
16
|
+
drop view capture_conversation;
|
|
17
|
+
drop view capture_message;
|
|
18
|
+
drop view capture_message_file;
|
|
19
|
+
|
|
20
|
+
create table "conversation_new" (
|
|
21
|
+
id text primary key not null,
|
|
22
|
+
project_id integer not null references project (id) on delete cascade,
|
|
23
|
+
origin text not null check (origin in ('claude-code', 'codex')),
|
|
24
|
+
external_id text not null,
|
|
25
|
+
branch text,
|
|
26
|
+
started_at text not null check (strftime('%Y-%m-%dT%H:%M:%fZ', started_at) is started_at),
|
|
27
|
+
unique (project_id, origin, external_id)
|
|
28
|
+
) strict;
|
|
29
|
+
insert into conversation_new (id, project_id, origin, external_id, branch, started_at)
|
|
30
|
+
select id, project_id, origin, external_id, branch, started_at from conversation;
|
|
31
|
+
drop table conversation;
|
|
32
|
+
alter table conversation_new rename to conversation;
|
|
33
|
+
|
|
34
|
+
create table "message_new" (
|
|
35
|
+
-- seq is the FTS5 rowid. It is an explicit integer primary key rather than the implicit rowid, so VACUUM does not renumber it
|
|
36
|
+
seq integer primary key not null,
|
|
37
|
+
id text not null unique,
|
|
38
|
+
conversation_id text not null references conversation (id) on delete cascade,
|
|
39
|
+
external_id text not null,
|
|
40
|
+
turn_id text,
|
|
41
|
+
speaker_kind text not null check (speaker_kind in ('self', 'assistant')),
|
|
42
|
+
body text not null check (body <> ''),
|
|
43
|
+
truncated integer not null default 0 check (truncated in (0, 1)),
|
|
44
|
+
original_bytes integer not null check (original_bytes > 0),
|
|
45
|
+
sent_at text not null check (strftime('%Y-%m-%dT%H:%M:%fZ', sent_at) is sent_at),
|
|
46
|
+
content_hash blob not null check (length(content_hash) = 32),
|
|
47
|
+
-- Whether it goes into the full-text index. 0 for AI replies (decided by indexesMessage in knowledge.ts)
|
|
48
|
+
indexed integer not null check (indexed in (0, 1)),
|
|
49
|
+
unique (conversation_id, external_id),
|
|
50
|
+
check (truncated = 1 or original_bytes = length(cast(body as blob))),
|
|
51
|
+
check (truncated = 0 or original_bytes > length(cast(body as blob)))
|
|
52
|
+
) strict;
|
|
53
|
+
insert into message_new (seq, id, conversation_id, external_id, turn_id, speaker_kind, body, truncated, original_bytes, sent_at,
|
|
54
|
+
content_hash, indexed)
|
|
55
|
+
select seq, id, conversation_id, external_id, turn_id, speaker_kind, body, truncated, original_bytes, sent_at, content_hash, indexed
|
|
56
|
+
from message;
|
|
57
|
+
drop table message;
|
|
58
|
+
alter table message_new rename to message;
|
|
59
|
+
|
|
60
|
+
create table "message_file_new" (
|
|
61
|
+
message_id text not null references message (id) on delete cascade,
|
|
62
|
+
path text not null check (path <> '' and path not glob '/*' and path not glob '*[/]..[/]*' and path not glob '..[/]*'
|
|
63
|
+
and path not glob '*[/]..' and path <> '..'),
|
|
64
|
+
action text not null check (action in ('edit', 'read')),
|
|
65
|
+
line_start integer check (line_start > 0),
|
|
66
|
+
line_end integer check (line_end >= line_start),
|
|
67
|
+
primary key (message_id, path, action)
|
|
68
|
+
) strict;
|
|
69
|
+
insert into message_file_new (message_id, path, action, line_start, line_end)
|
|
70
|
+
select message_id, path, action, line_start, line_end from message_file;
|
|
71
|
+
drop table message_file;
|
|
72
|
+
alter table message_file_new rename to message_file;
|
|
73
|
+
|
|
74
|
+
create table "knowledge_new" (
|
|
75
|
+
id integer primary key autoincrement not null,
|
|
76
|
+
project_id integer not null references project (id) on delete cascade,
|
|
77
|
+
conversation_id text references conversation (id) on delete cascade,
|
|
78
|
+
pull_request_id integer references pull_request (id) on delete cascade,
|
|
79
|
+
work_item_id integer references work_item (id) on delete set null,
|
|
80
|
+
source_key text not null,
|
|
81
|
+
kind text not null check (kind in ('decision', 'option', 'constraint', 'non_goal', 'dead_end', 'finding', 'debt',
|
|
82
|
+
'verification', 'question')),
|
|
83
|
+
status text,
|
|
84
|
+
stance text not null generated always as (
|
|
85
|
+
case
|
|
86
|
+
when kind in ('constraint', 'non_goal', 'debt') then (case status when 'active' then 'dont' else 'neutral' end)
|
|
87
|
+
when kind = 'dead_end' then 'dont'
|
|
88
|
+
when kind = 'option' then (case status when 'chosen' then 'do' else 'dont' end)
|
|
89
|
+
when kind = 'decision' then (case status when 'accepted' then 'do' when 'proposed' then 'neutral' else 'dont' end)
|
|
90
|
+
when kind = 'verification' then (case status when 'failed' then 'dont' else 'neutral' end)
|
|
91
|
+
else 'neutral'
|
|
92
|
+
end
|
|
93
|
+
) stored,
|
|
94
|
+
confidence text check (confidence in ('fact', 'inference', 'opinion')),
|
|
95
|
+
decision_id integer references knowledge (id) on delete cascade,
|
|
96
|
+
superseded_by_id integer references knowledge (id) on delete set null,
|
|
97
|
+
heading text,
|
|
98
|
+
body text not null check (body <> ''),
|
|
99
|
+
reason text,
|
|
100
|
+
confirmation text,
|
|
101
|
+
command text,
|
|
102
|
+
downsides text not null default '[]' check (json_valid(downsides) and json_type(downsides) = 'array'),
|
|
103
|
+
refs text not null default '[]' check (json_valid(refs) and json_type(refs) = 'array'),
|
|
104
|
+
occurred_at text not null check (strftime('%Y-%m-%dT%H:%M:%fZ', occurred_at) is occurred_at),
|
|
105
|
+
content_hash blob not null check (length(content_hash) = 32),
|
|
106
|
+
unique (project_id, source_key),
|
|
107
|
+
-- Exactly one provenance: the session trace read, or the pull request harvest read
|
|
108
|
+
check ((conversation_id is null) <> (pull_request_id is null)),
|
|
109
|
+
check (
|
|
110
|
+
case kind
|
|
111
|
+
when 'decision' then status is not null and status in ('proposed', 'accepted', 'rejected', 'superseded')
|
|
112
|
+
when 'option' then status is not null and status in ('chosen', 'rejected', 'was_chosen')
|
|
113
|
+
when 'verification' then status is not null and status in ('passed', 'failed', 'not_run')
|
|
114
|
+
when 'question' then status is not null and status in ('open', 'blocking', 'resolved')
|
|
115
|
+
when 'constraint' then status is not null and status in ('active', 'retired')
|
|
116
|
+
when 'non_goal' then status is not null and status in ('active', 'retired')
|
|
117
|
+
when 'debt' then status is not null and status in ('active', 'retired')
|
|
118
|
+
else status is null
|
|
119
|
+
end
|
|
120
|
+
),
|
|
121
|
+
check (case kind when 'option' then decision_id is not null when 'verification' then 1 else decision_id is null end),
|
|
122
|
+
check ((kind = 'decision' and status = 'superseded') = (superseded_by_id is not null)),
|
|
123
|
+
check (superseded_by_id is null or superseded_by_id <> id),
|
|
124
|
+
check (confirmation is null or kind = 'decision'),
|
|
125
|
+
check (command is null or kind = 'verification'),
|
|
126
|
+
check (json_array_length(downsides) = 0 or kind = 'decision')
|
|
127
|
+
) strict;
|
|
128
|
+
insert into knowledge_new (id, project_id, conversation_id, pull_request_id, work_item_id, source_key, kind, status, confidence,
|
|
129
|
+
decision_id, superseded_by_id, heading, body, reason, confirmation, command, downsides, refs,
|
|
130
|
+
occurred_at, content_hash)
|
|
131
|
+
select k.id, k.project_id, k.conversation_id, pr.id, k.work_item_id,
|
|
132
|
+
case when pr.id is null then k.source_key else 'pr:' || substr(k.source_key, instr(k.source_key, '/pull/') + 6) end,
|
|
133
|
+
k.kind, k.status, k.confidence, k.decision_id, k.superseded_by_id, k.heading, k.body, k.reason, k.confirmation, k.command,
|
|
134
|
+
k.downsides, k.refs, k.occurred_at, k.content_hash
|
|
135
|
+
from knowledge k
|
|
136
|
+
left join source_item s on s.id = k.source_item_id
|
|
137
|
+
left join connector c on c.id = s.connector_id
|
|
138
|
+
left join pull_request pr on pr.project_id = c.project_id and pr.number = cast(s.external_id as integer);
|
|
139
|
+
drop table knowledge;
|
|
140
|
+
alter table knowledge_new rename to knowledge;
|
|
141
|
+
delete from sqlite_sequence where name = 'knowledge';
|
|
142
|
+
insert into sqlite_sequence (name, seq) select 'knowledge', seq from knowledge_seq where seq is not null;
|
|
143
|
+
|
|
144
|
+
create table "knowledge_terms_new" (
|
|
145
|
+
knowledge_id integer primary key not null references knowledge (id) on delete cascade,
|
|
146
|
+
terms text not null check (terms <> '' and length(terms) <= 400),
|
|
147
|
+
content_hash blob not null check (length(content_hash) = 32),
|
|
148
|
+
source text not null check (source in ('trace', 'harvest', 'import')),
|
|
149
|
+
written_at text not null check (strftime('%Y-%m-%dT%H:%M:%fZ', written_at) is written_at)
|
|
150
|
+
) strict;
|
|
151
|
+
insert into knowledge_terms_new (knowledge_id, terms, content_hash, source, written_at)
|
|
152
|
+
select knowledge_id, terms, content_hash, source, written_at from knowledge_terms;
|
|
153
|
+
drop table knowledge_terms;
|
|
154
|
+
alter table knowledge_terms_new rename to knowledge_terms;
|
|
155
|
+
|
|
156
|
+
drop table source_item;
|
|
157
|
+
drop table docs_exclude;
|
|
158
|
+
drop table connector;
|
|
159
|
+
drop table person_identity;
|
|
160
|
+
drop table person;
|
|
161
|
+
|
|
162
|
+
create index conversation_recent on conversation (project_id, started_at desc);
|
|
163
|
+
create index message_order on message (conversation_id, sent_at);
|
|
164
|
+
create index message_self on message (sent_at desc) where speaker_kind = 'self';
|
|
165
|
+
create index message_file_path on message_file (path);
|
|
166
|
+
create index knowledge_listing on knowledge (project_id, kind, status, occurred_at desc);
|
|
167
|
+
create index knowledge_work on knowledge (work_item_id) where work_item_id is not null;
|
|
168
|
+
|
|
169
|
+
create view knowledge_search_text as
|
|
170
|
+
select k.id,
|
|
171
|
+
sphica_terms(coalesce(k.heading, '')) as h,
|
|
172
|
+
sphica_terms(k.body || char(10) || coalesce(k.reason, '')) as b,
|
|
173
|
+
sphica_terms(coalesce(t.terms, '') || char(10) || k.refs) as e
|
|
174
|
+
from knowledge k
|
|
175
|
+
left join knowledge_terms t on t.knowledge_id = k.id and t.content_hash = k.content_hash;
|
|
176
|
+
|
|
177
|
+
create view capture_conversation as
|
|
178
|
+
select id, project_id, origin, external_id, branch, started_at from conversation;
|
|
179
|
+
|
|
180
|
+
create view capture_message as
|
|
181
|
+
select id, conversation_id, external_id, turn_id, speaker_kind, body, truncated, original_bytes, sent_at, content_hash, indexed
|
|
182
|
+
from message;
|
|
183
|
+
|
|
184
|
+
create view capture_message_file as select message_id, path, action from message_file;
|
|
185
|
+
|
|
186
|
+
create trigger message_fts_ai after insert on message when new.indexed = 1 begin
|
|
187
|
+
insert into message_fts (rowid, lexemes) values (new.seq, sphica_terms(new.body));
|
|
188
|
+
end;
|
|
189
|
+
create trigger message_fts_ad after delete on message when old.indexed = 1 begin
|
|
190
|
+
delete from message_fts where rowid = old.seq;
|
|
191
|
+
end;
|
|
192
|
+
create trigger message_fts_au after update of body, indexed on message begin
|
|
193
|
+
delete from message_fts where rowid = old.seq and old.indexed = 1;
|
|
194
|
+
insert into message_fts (rowid, lexemes) select new.seq, sphica_terms(new.body) where new.indexed = 1;
|
|
195
|
+
end;
|
|
196
|
+
create trigger knowledge_fts_ai after insert on knowledge begin
|
|
197
|
+
insert into knowledge_fts (rowid, h, b, e) select id, h, b, e from knowledge_search_text where id = new.id;
|
|
198
|
+
end;
|
|
199
|
+
create trigger knowledge_fts_ad after delete on knowledge begin
|
|
200
|
+
delete from knowledge_fts where rowid = old.id;
|
|
201
|
+
end;
|
|
202
|
+
create trigger knowledge_fts_au after update of heading, body, reason, content_hash on knowledge begin
|
|
203
|
+
delete from knowledge_fts where rowid = old.id;
|
|
204
|
+
insert into knowledge_fts (rowid, h, b, e) select id, h, b, e from knowledge_search_text where id = new.id;
|
|
205
|
+
end;
|
|
206
|
+
create trigger knowledge_terms_ai after insert on knowledge_terms begin
|
|
207
|
+
delete from knowledge_fts where rowid = new.knowledge_id;
|
|
208
|
+
insert into knowledge_fts (rowid, h, b, e) select id, h, b, e from knowledge_search_text where id = new.knowledge_id;
|
|
209
|
+
end;
|
|
210
|
+
create trigger knowledge_terms_au after update of terms, content_hash on knowledge_terms begin
|
|
211
|
+
delete from knowledge_fts where rowid = new.knowledge_id;
|
|
212
|
+
insert into knowledge_fts (rowid, h, b, e) select id, h, b, e from knowledge_search_text where id = new.knowledge_id;
|
|
213
|
+
end;
|
|
214
|
+
create trigger knowledge_terms_ad after delete on knowledge_terms begin
|
|
215
|
+
delete from knowledge_fts where rowid = old.knowledge_id;
|
|
216
|
+
insert into knowledge_fts (rowid, h, b, e) select id, h, b, e from knowledge_search_text where id = old.knowledge_id;
|
|
217
|
+
end;
|
|
218
|
+
create trigger capture_conversation_insert instead of insert on capture_conversation begin
|
|
219
|
+
insert into conversation (id, project_id, origin, external_id, branch, started_at)
|
|
220
|
+
values (new.id, new.project_id, new.origin, new.external_id, new.branch, new.started_at)
|
|
221
|
+
on conflict do nothing;
|
|
222
|
+
end;
|
|
223
|
+
create trigger capture_message_insert instead of insert on capture_message begin
|
|
224
|
+
insert into message (id, conversation_id, external_id, turn_id, speaker_kind, body, truncated, original_bytes,
|
|
225
|
+
sent_at, content_hash, indexed)
|
|
226
|
+
values (new.id, new.conversation_id, new.external_id, new.turn_id, new.speaker_kind, new.body, new.truncated,
|
|
227
|
+
new.original_bytes, new.sent_at, new.content_hash, new.indexed)
|
|
228
|
+
on conflict do nothing;
|
|
229
|
+
end;
|
|
230
|
+
create trigger capture_message_file_insert instead of insert on capture_message_file begin
|
|
231
|
+
insert into message_file (message_id, path, action)
|
|
232
|
+
select new.message_id, new.path, new.action where exists (select 1 from message where id = new.message_id)
|
|
233
|
+
on conflict do nothing;
|
|
234
|
+
end;
|
|
235
|
+
|
|
236
|
+
-- The index text changed (refs are now searchable), so it is filled again from the view
|
|
237
|
+
insert into knowledge_fts (knowledge_fts) values ('delete-all');
|
|
238
|
+
insert into knowledge_fts (rowid, h, b, e) select id, h, b, e from knowledge_search_text;
|