skillar 0.2.1 → 0.3.1
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/NOTICE +280 -0
- package/README.md +37 -5
- package/dist/analysis/finding.js +8 -190
- package/dist/analysis/kernel.js +896 -0
- package/dist/analysis/tree.js +7 -154
- package/dist/analysis/usage.js +9 -394
- package/dist/api/flows.js +42 -212
- package/dist/api/report-kernel.js +1063 -0
- package/dist/api/routes.js +12 -2
- package/dist/catalog/fields.js +138 -146
- package/dist/catalog/watcher.js +7 -2
- package/dist/cli/init.js +45 -0
- package/dist/cli/main.js +76 -3
- package/dist/cli/private-skills.js +122 -0
- package/dist/cli/serve.js +15 -1
- package/dist/cli/sync.js +124 -0
- package/dist/dashboard/NOTICE +280 -0
- package/dist/dashboard/assets/app.js +737 -275
- package/dist/dashboard/assets/astryx-reset.css +407 -0
- package/dist/dashboard/assets/astryx.css +1077 -0
- package/dist/dashboard/assets/charts.css +54 -0
- package/dist/dashboard/assets/chunk-TPGDA2J4.js +1 -0
- package/dist/dashboard/assets/chunk-YLWHVDMP.js +36 -0
- package/dist/dashboard/assets/controls.css +207 -0
- package/dist/dashboard/assets/overlays.css +132 -0
- package/dist/dashboard/assets/p1.css +135 -0
- package/dist/dashboard/assets/shell.css +71 -0
- package/dist/dashboard/assets/skillar-theme.css +692 -0
- package/dist/dashboard/assets/styles.css +224 -121
- package/dist/dashboard/assets/tokens.css +278 -0
- package/dist/dashboard/assets/widgets.css +83 -0
- package/dist/dashboard/index.html +11 -2
- package/dist/dashboard/viewers/viewers.css +61 -0
- package/dist/ingest/attribution.js +5 -1
- package/dist/ingest/pipeline.js +2 -0
- package/dist/ingest/request-recorder.js +39 -0
- package/dist/mcp/dispatch.js +2 -2
- package/dist/mcp/http.js +43 -3
- package/dist/mcp/skills-extension.js +42 -15
- package/dist/mcp/stdio-proxy.js +24 -3
- package/dist/mcp/tools.js +38 -24
- package/dist/packs/claude-code.js +22 -11
- package/dist/packs/cursor.js +9 -4
- package/dist/packs/gemini.js +9 -4
- package/dist/packs/json-config.js +41 -0
- package/dist/packs/omo.js +15 -6
- package/dist/request-status.js +81 -0
- package/dist/search/fts.js +93 -58
- package/dist/search/fusion.js +49 -47
- package/dist/search/guidance.js +18 -6
- package/dist/search/index.js +291 -70
- package/dist/search/lexical.js +71 -63
- package/dist/server.js +12 -0
- package/dist/skills/apply.js +130 -0
- package/dist/skills/capture.js +54 -0
- package/dist/skills/cloud-plan.js +57 -0
- package/dist/skills/cloud.js +81 -0
- package/dist/skills/fs.js +133 -0
- package/dist/skills/package.js +734 -0
- package/dist/skills/plan.js +83 -0
- package/dist/skills/receipt.js +44 -0
- package/dist/skills/rollback.js +119 -0
- package/dist/skills/transfer.js +51 -0
- package/dist/store/db.js +7 -1
- package/dist/store/execution.js +2 -34
- package/dist/store/export.js +25 -4
- package/dist/store/migrations/007_sync.sql +49 -0
- package/dist/store/migrations/008_connector_commands.sql +12 -0
- package/dist/store/queries.js +33 -7
- package/dist/store/writes.js +38 -5
- package/dist/sync/cloud-blobs.js +175 -0
- package/dist/sync/cloud-commands.js +101 -0
- package/dist/sync/cloud-connection.js +105 -0
- package/dist/sync/cloud-delivery.js +114 -0
- package/dist/sync/cloud-documents.js +103 -0
- package/dist/sync/cloud-export.js +67 -0
- package/dist/sync/cloud-http.js +150 -0
- package/dist/sync/cloud-jobs.js +94 -0
- package/dist/sync/cloud-pending.js +143 -0
- package/dist/sync/cloud-prepare.js +101 -0
- package/dist/sync/cloud-restore.js +136 -0
- package/dist/sync/cloud-rollback.js +24 -0
- package/dist/sync/cloud-runner.js +86 -0
- package/dist/sync/cloud-runtime.js +293 -0
- package/dist/sync/cloud-schema.js +32 -0
- package/dist/sync/cloud-stage.js +112 -0
- package/dist/sync/cloud-wire.js +693 -0
- package/dist/sync/cloud-worker.js +57 -0
- package/dist/sync/cloud.js +157 -0
- package/dist/sync/command-apply.js +140 -0
- package/dist/sync/command-control.js +25 -0
- package/dist/sync/command-wire.js +437 -0
- package/dist/sync/consent.js +130 -0
- package/dist/sync/journal.js +43 -0
- package/dist/sync/outbox.js +134 -0
- package/dist/sync/restore-rows.js +125 -0
- package/dist/sync/restore.js +174 -0
- package/dist/sync/snapshot.js +78 -0
- package/dist/sync/spool-request.js +103 -0
- package/dist/sync/tables.js +27 -0
- package/dist/sync/triggers.js +34 -0
- package/dist/workflow/compare.js +3 -43
- package/docs/cloud-sync.md +94 -0
- package/docs/private-skills.md +75 -0
- package/docs/sync-p4.md +102 -0
- package/docs/sync-restore.md +167 -0
- package/package.json +18 -5
- package/src/store/migrations/007_sync.sql +49 -0
- package/src/store/migrations/008_connector_commands.sql +12 -0
- package/dist/dashboard/assets/chunk-5DFWNJC2.js +0 -1
- package/dist/dashboard/assets/chunk-S6B2HJQA.js +0 -17
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { targetTables } from "./tables.js";
|
|
3
|
+
/**
|
|
4
|
+
* Installed inside migration 007's transaction. Read actual stored values rather
|
|
5
|
+
* than NEW: an older AFTER trigger may already have changed the row. Each later
|
|
6
|
+
* derived write appends another image; readJournal chooses the last at the cut.
|
|
7
|
+
* Recursive triggers are enabled on every open, including REPLACE's delete path.
|
|
8
|
+
*/
|
|
9
|
+
export function installJournalTriggers(db) {
|
|
10
|
+
for (const table of targetTables) {
|
|
11
|
+
const columns = db.prepare(`PRAGMA table_info("${table}")`).all().map(row => z.object({ name: z.string(), pk: z.number() }).parse(row));
|
|
12
|
+
const keys = columns.filter(c => c.pk > 0).sort((a, b) => a.pk - b.pk);
|
|
13
|
+
const key = (prefix) => `json_array(${keys.map(c => `${prefix}."${c.name}"`).join(",")})`;
|
|
14
|
+
const match = keys.map(c => `"${c.name}" IS NEW."${c.name}"`).join(" AND ");
|
|
15
|
+
const changedKey = keys.map(c => `OLD."${c.name}" IS NOT NEW."${c.name}"`).join(" OR ");
|
|
16
|
+
const values = `json_object(${columns.map(c => `'${c.name}',"${c.name}"`).join(",")})`;
|
|
17
|
+
const before = `json_object(${columns.map(c => `'${c.name}',OLD."${c.name}"`).join(",")})`;
|
|
18
|
+
const order = table === "load_candidates" ? "NULL" : "rowid";
|
|
19
|
+
const oldOrder = table === "load_candidates" ? "NULL" : "OLD.rowid";
|
|
20
|
+
const upsert = `INSERT INTO sync_journal(table_name,entity_key,operation,source_order,row_json)
|
|
21
|
+
SELECT '${table}',${key(table)},'upsert',${order},${values} FROM "${table}" WHERE ${match};`;
|
|
22
|
+
const tombstone = `INSERT INTO sync_journal(table_name,entity_key,operation,source_order,row_json,before_json)
|
|
23
|
+
VALUES ('${table}',${key("OLD")},'delete',${oldOrder},NULL,${before});`;
|
|
24
|
+
db.exec(`
|
|
25
|
+
CREATE TRIGGER sync_${table}_insert AFTER INSERT ON "${table}" BEGIN ${upsert} END;
|
|
26
|
+
CREATE TRIGGER sync_${table}_update AFTER UPDATE ON "${table}" BEGIN
|
|
27
|
+
INSERT INTO sync_journal(table_name,entity_key,operation,source_order,row_json,before_json)
|
|
28
|
+
SELECT '${table}',${key("OLD")},'delete',${oldOrder},NULL,${before} WHERE ${changedKey};
|
|
29
|
+
${upsert}
|
|
30
|
+
END;
|
|
31
|
+
CREATE TRIGGER sync_${table}_delete AFTER DELETE ON "${table}" BEGIN ${tombstone} END;
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/workflow/compare.js
CHANGED
|
@@ -1,46 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
* - `not_run` no pane was mapped to the step
|
|
5
|
-
* - `no_skill_used` the step's panes used no skill at all although the step intends some
|
|
6
|
-
* - `different` skills were used but none of them was intended (or the step intends none)
|
|
7
|
-
* - `partial` a `together` step used some but not all of its intended skills
|
|
8
|
-
* - `matched` the intent is satisfied: all intended skills for `together`, any one of them otherwise
|
|
9
|
-
*
|
|
10
|
-
* `extraSkills` (used but not intended) are reported, not penalised - deviations are feedback data, never enforcement.
|
|
11
|
-
* `unexpectedTools` stays empty while a step declares no `expectTools`, because nothing was expected to deviate from.
|
|
12
|
-
*/
|
|
13
|
-
export function compare(input) {
|
|
14
|
-
const panesByStep = new Map();
|
|
15
|
-
const mapped = new Set();
|
|
16
|
-
for (const { stepId, paneId } of input.steps) {
|
|
17
|
-
panesByStep.set(stepId, [...(panesByStep.get(stepId) ?? []), paneId]);
|
|
18
|
-
mapped.add(paneId);
|
|
19
|
-
}
|
|
20
|
-
const skillsOf = (panes) => panes.flatMap((p) => input.paneSkillUse[p] ?? []);
|
|
21
|
-
const steps = input.spec.steps.map((step) => {
|
|
22
|
-
const panes = sorted(panesByStep.get(step.id) ?? []);
|
|
23
|
-
const intended = sorted(step.skills);
|
|
24
|
-
const used = sorted(skillsOf(panes));
|
|
25
|
-
const intendedSet = new Set(intended);
|
|
26
|
-
const usedSet = new Set(used);
|
|
27
|
-
const hit = intended.filter((s) => usedSet.has(s));
|
|
28
|
-
const missingSkills = intended.filter((s) => !usedSet.has(s));
|
|
29
|
-
const extraSkills = used.filter((s) => !intendedSet.has(s));
|
|
30
|
-
const expected = new Set(step.expectTools);
|
|
31
|
-
const unexpectedTools = expected.size === 0 ? [] : sorted(panes.flatMap((p) => input.paneTools[p] ?? [])).filter((t) => !expected.has(t));
|
|
32
|
-
const status = panes.length === 0 ? "not_run"
|
|
33
|
-
: used.length === 0 ? (intended.length === 0 ? "matched" : "no_skill_used")
|
|
34
|
-
: hit.length === 0 ? "different"
|
|
35
|
-
: step.together && missingSkills.length > 0 ? "partial"
|
|
36
|
-
: "matched";
|
|
37
|
-
return { stepId: step.id, panes, intendedSkills: intended, usedSkills: used, status, extraSkills, missingSkills, unexpectedTools };
|
|
38
|
-
});
|
|
39
|
-
const unplanned = sorted(input.panes ?? Object.keys(input.paneSkillUse))
|
|
40
|
-
.filter((paneId) => !mapped.has(paneId))
|
|
41
|
-
.map((paneId) => ({ paneId, usedSkills: sorted(input.paneSkillUse[paneId] ?? []) }));
|
|
42
|
-
return { steps, unplanned };
|
|
43
|
-
}
|
|
1
|
+
import * as kernel from "../analysis/kernel.js";
|
|
2
|
+
/** Step statuses and deviation fields are defined by the shared MIT kernel's compare(). */
|
|
3
|
+
export const compare = kernel.compare;
|
|
44
4
|
/**
|
|
45
5
|
* Store-backed input for compare(). Used skills come from the skillar `load` and `native_skill` events of the
|
|
46
6
|
* sessions linked to each pane; skill spans (todo 6) replace this source without changing the comparison.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Cloud sync and recovery
|
|
2
|
+
|
|
3
|
+
Cloud sync is optional. Local capture, the local dashboard, and Google sign-in do
|
|
4
|
+
not enable uploads. A device connection and an explicit account consent are
|
|
5
|
+
separate steps. The daemon runs transport in a worker thread only while an
|
|
6
|
+
account-issued device credential exists.
|
|
7
|
+
|
|
8
|
+
## Connect and choose coverage
|
|
9
|
+
|
|
10
|
+
1. Obtain a one-time device grant from the signed-in account's device API.
|
|
11
|
+
2. Save it in a private local file and run
|
|
12
|
+
`skillar sync connect --grant-file <path>`. This exchanges the grant and saves
|
|
13
|
+
the device credential with mode `0600`; it does not grant raw upload.
|
|
14
|
+
3. For historical upload, run `skillar sync prepare`. This makes a private,
|
|
15
|
+
consistent **local** SQLite backup and prints its snapshot ID, source domain,
|
|
16
|
+
journal cut, and expiry. No historical data is sent by preparation.
|
|
17
|
+
4. Grant `managed-content` for the selected device, content kinds, and time range
|
|
18
|
+
in the account consent API. Whole-device transport uses the explicit project
|
|
19
|
+
scope `device:<deviceId>` and an empty root restriction list. A project-only or
|
|
20
|
+
root-only grant is not treated as permission to upload the whole device.
|
|
21
|
+
Historical consent must identify the prepared snapshot and its exact cut.
|
|
22
|
+
The account stamps the consent time; local `captureLevel` is not consent.
|
|
23
|
+
5. `skillar sync run` performs one bounded unit. The running daemon continues
|
|
24
|
+
work automatically. `skillar sync backfill` schedules the prepared historical
|
|
25
|
+
snapshot without resetting an existing live cursor. The daemon also notices a
|
|
26
|
+
newly granted prepared snapshot automatically. After five live batches,
|
|
27
|
+
a backfill page gets a turn, so live traffic cannot starve historical work.
|
|
28
|
+
|
|
29
|
+
Without historical permission, the initial cloud baseline is empty at the
|
|
30
|
+
current local cut. Only subsequent changes inside the consented time range can
|
|
31
|
+
be sent. Out-of-range records are counted as excluded; this is reduced coverage,
|
|
32
|
+
not full-history parity. Selected content kinds keep only their permitted
|
|
33
|
+
columns. Full-fidelity recovery requires all seven raw-content kinds and a
|
|
34
|
+
complete historical snapshot. Metadata mode is explicitly reported as
|
|
35
|
+
`metadata-only`; this raw transport does not mislabel it as full-content sync.
|
|
36
|
+
|
|
37
|
+
The first binding to a new device connection forks the source and future
|
|
38
|
+
recording domains. It preserves existing row vectors and the recording clock's
|
|
39
|
+
monotone high-water mark. Restored databases get fresh local domains and do not
|
|
40
|
+
inherit a device credential, transport queue, or acknowledgement.
|
|
41
|
+
|
|
42
|
+
## Durable progress and failures
|
|
43
|
+
|
|
44
|
+
`skillar sync status` prints connection identity and progress, never the token.
|
|
45
|
+
The source database contains only its transaction journal. A separate private
|
|
46
|
+
`cloud/spool.sqlite` contains exact request bytes, referenced blobs, sequences,
|
|
47
|
+
and ACK cursors in one SQLite transaction. Restarting a process retries the same
|
|
48
|
+
bytes. A chunk or page ACK is not a snapshot ACK, and only a verified durable
|
|
49
|
+
receipt advances a cursor. The spool has a fenced single-writer lease.
|
|
50
|
+
|
|
51
|
+
429 and 5xx responses persist Retry-After plus bounded jitter as a future
|
|
52
|
+
scheduling time. There is no sleeping HTTP retry. Authentication, consent,
|
|
53
|
+
permanent schema errors, local pressure, and unsafe redirects are visible
|
|
54
|
+
states; pending bytes are not skipped. `skillar sync run --resume` explicitly
|
|
55
|
+
retries a quarantined job or clears a pause. A changed consent version cannot
|
|
56
|
+
silently authorize an older pending request.
|
|
57
|
+
|
|
58
|
+
Current bounded contracts allow 10,000 rows and 16 MiB per snapshot, 128 snapshot
|
|
59
|
+
pages, 128 chunks, 100 rows per page, and a 64 MiB local spool. A single large row
|
|
60
|
+
can span multiple 128 KiB content chunks. Exceeding a bound fails explicitly
|
|
61
|
+
without truncation or an advanced ACK. Prepared local backups expire after
|
|
62
|
+
24 hours; already-spooled jobs remain resumable. The SQLite backup API restarts
|
|
63
|
+
its copy on concurrent writers; its completed copy supplies both rows and cut.
|
|
64
|
+
|
|
65
|
+
## Pause, rollback, disconnect, and reverse restore
|
|
66
|
+
|
|
67
|
+
`skillar sync pause` prevents further delivery without changing local capture.
|
|
68
|
+
`skillar sync rollback` pauses locally and marks the latest prepared migration
|
|
69
|
+
for rollback. Unaccepted staging is abandoned. An accepted snapshot and its live
|
|
70
|
+
cursor remain intact and exportable. Neither command deletes accepted history.
|
|
71
|
+
`skillar sync disconnect` removes the local device credential; source history,
|
|
72
|
+
prepared backups, and durable pending bytes remain local.
|
|
73
|
+
|
|
74
|
+
To recover into a **new** database:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
skillar sync restore --destination ./recovered.sqlite \
|
|
78
|
+
--source-domain <source-domain> --snapshot-id <snapshot-id>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The authenticated read API exports the original snapshot and a fixed contiguous
|
|
82
|
+
CDC range, including raw values, tombstones, source row order, and recording
|
|
83
|
+
vectors. The client verifies each payload, whole-snapshot counts/hash, sequence
|
|
84
|
+
continuity, SQLite integrity, foreign keys, and the restored dataset. It rebuilds
|
|
85
|
+
FTS from restored skills and publishes the new file only after verification.
|
|
86
|
+
Existing destination files are never replaced. Read-only recovery remains
|
|
87
|
+
available with ingestion disabled, but still requires current account/device
|
|
88
|
+
authorization and consent.
|
|
89
|
+
|
|
90
|
+
A historical snapshot older than an empty future-only cloud baseline may have a
|
|
91
|
+
gap before the first uploaded CDC batch. Recovery rejects that gap instead of
|
|
92
|
+
claiming completeness; prepare a new snapshot after the live baseline to create
|
|
93
|
+
a recoverable backfill. Partial content projections and snapshots without the
|
|
94
|
+
recording clock cannot be used for full-fidelity recovery.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Private skill transfer
|
|
2
|
+
|
|
3
|
+
The web library stores immutable versions of `SKILL.md` and supporting files in your account. Web publication reads only files you choose, and requires the upload checkbox. CLI publication reads only the directory you explicitly select and requires a separate publication command. Activity consent and private skill permission are independent.
|
|
4
|
+
|
|
5
|
+
## Connect a private-capable device
|
|
6
|
+
|
|
7
|
+
Sign in on the web dashboard. In **Devices and consent**, select **Also allow this device to read and publish my private skills**, then connect a device and download its one-time grant file. The checkbox starts unchecked for each new device.
|
|
8
|
+
|
|
9
|
+
Use the connection command shown beside that download:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
skillar sync connect --grant-file ./skillar-grant.txt --origin https://skillar.sh
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Replace the file path with your actual download. Existing activity-only credentials do not gain private access automatically. Connecting uploads no skill files and requires no running daemon.
|
|
16
|
+
|
|
17
|
+
## Review and publish
|
|
18
|
+
|
|
19
|
+
Choose a self-contained skill directory. Its regular files are package members; unsupported paths, symlinks, archives and resource quotas are rejected. `SKILL.md` must be valid UTF-8 with `name` and `description` front matter.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
skillar skills push-preview --source-dir ./my-skill --plan ./publication-plan.json
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Preview sends only identity and metadata requests. It prints the skill ID, selected resource paths, byte counts and digests, and saves a mode-0600 plan containing the private package. Save the plan outside its source directory. It is not a publication acknowledgement.
|
|
26
|
+
|
|
27
|
+
After reviewing that selection:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
skillar skills push --plan ./publication-plan.json --allow-private-upload
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Publication rechecks the source directory and connection against the plan, then submits the reviewed package with its expected remote head. Changed source files or another connection require a fresh preview. To update an existing skill rather than create a new one, pass its printed ID as `--skill-id` to `push-preview`.
|
|
34
|
+
|
|
35
|
+
A concurrent head change returns a conflict instead of overwriting it. Offline and unverified responses are errors, not successful acknowledgements. If a network failure leaves the result uncertain, inspect the web library before preparing another publication.
|
|
36
|
+
|
|
37
|
+
Packages allow at most 128 resources, 512 KiB per resource and 2 MiB total. The encoded request is limited to 3 MiB, and the server limits `SKILL.md` to 64 KiB. No selected document or script is executed.
|
|
38
|
+
|
|
39
|
+
## Download an immutable export
|
|
40
|
+
|
|
41
|
+
Set `SKILL_ID` to the ID printed by your publication or shown in the web library:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
skillar skills pull --skill-id "$SKILL_ID" --output ./private-export.json
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The current head is resolved once and downloaded by its immutable digest. Add `--version` with a version digest to select an older version. All file hashes and manifest membership are verified before creating the export. An existing output file is not replaced.
|
|
48
|
+
|
|
49
|
+
You can instead use **Export JSON** on a version in the web library. Both exports use the same package format.
|
|
50
|
+
|
|
51
|
+
## Preview and apply local files
|
|
52
|
+
|
|
53
|
+
These commands work offline and do not acknowledge cloud delivery. Select an existing destination directory explicitly; there is no discovered default. Local apply paths must have no symlink components, including ancestors. On macOS, use `/private/tmp` rather than `/tmp` when supplying an absolute temporary path.
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
mkdir ./installed-skill
|
|
57
|
+
skillar skills preview --package ./private-export.json \
|
|
58
|
+
--destination-root ./installed-skill --plan ./apply-plan.json
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Preview creates only the plan, outside the destination. It prints each planned create or overwrite and captures current target identities and bytes. Existing target files require a new preview with `--allow-overwrite`, even when their bytes already match.
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
skillar skills apply --plan ./apply-plan.json
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Apply rechecks the plan, writes a private recovery receipt before changing targets, and reports its receipt path. It never executes a document or supporting script. Recovery directories are retained under the destination.
|
|
68
|
+
|
|
69
|
+
To undo that apply, set `RECEIPT` to the exact path reported by it:
|
|
70
|
+
|
|
71
|
+
```sh
|
|
72
|
+
skillar skills rollback --receipt "$RECEIPT"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Rollback restores only files that still match the installed identity and content. User edits are conflicts and are left in place; safe files can still be recovered, and incomplete recovery returns nonzero. Local operations use optimistic filesystem checks, not a transaction against other local writers. Keep the recovery directory until you are satisfied.
|
package/docs/sync-p4.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# P4: local CDC, snapshot and durable outbox
|
|
2
|
+
|
|
3
|
+
P4 is an offline library foundation. It adds no sender, daemon timer, CLI command,
|
|
4
|
+
cloud connection or automatic consent. P5/P6 own those integrations.
|
|
5
|
+
|
|
6
|
+
## Source history
|
|
7
|
+
|
|
8
|
+
Migration 007 installs `sync_journal` and three SQL triggers for every target:
|
|
9
|
+
skills, sessions, events, loads, eval_cases, otel_spans, herdr_workspaces,
|
|
10
|
+
herdr_tabs, herdr_panes, pane_sessions, workflow_specs, flows, flow_steps,
|
|
11
|
+
load_candidates and recording_clock. `meta` is local configuration/counters;
|
|
12
|
+
FTS tables and the candidate view are rebuildable indexes, not separate facts.
|
|
13
|
+
The migration registry installs the generated triggers within the same migration
|
|
14
|
+
transaction. Always use `openDb`, which enables recursive triggers (including
|
|
15
|
+
REPLACE deletes) on each connection.
|
|
16
|
+
|
|
17
|
+
Each trigger appends a full stored after-image or a tombstone with a local-only
|
|
18
|
+
before-image in the source transaction. Primary-key moves tombstone the old key.
|
|
19
|
+
Foreign-key cascades and existing recording/candidate triggers are captured.
|
|
20
|
+
Reading the live row **inside the trigger**, rather than copying `NEW`, avoids
|
|
21
|
+
stale outer images when another AFTER trigger already updated it.
|
|
22
|
+
|
|
23
|
+
`journalHead` returns a committed cut and immutable database-lineage identity.
|
|
24
|
+
`readJournal({after, through, limit})` selects each entity's last image inside
|
|
25
|
+
that fixed cut, ordered by its final revision. A continuation uses the last
|
|
26
|
+
returned revision as `after`, keeping `through` unchanged. Never manufacture a
|
|
27
|
+
cut from an intermediate journal row or call these APIs during a source
|
|
28
|
+
transaction. Journal images are retained; later edits/deletes cannot change
|
|
29
|
+
earlier cuts. Revisions, journal sequences and recording-clock positions remain
|
|
30
|
+
distinct. No journal compaction is implemented; disk usage needs operational
|
|
31
|
+
monitoring until a verified snapshot/receipt retention policy exists.
|
|
32
|
+
|
|
33
|
+
## Logical snapshot
|
|
34
|
+
|
|
35
|
+
Use `logicalSnapshot` on a **dedicated reader connection**. Its first SELECT
|
|
36
|
+
inside `BEGIN` pins both cut C and source rows. The generator yields bounded
|
|
37
|
+
chunks with snapshot ID, index, source domain, cut, record count (array length),
|
|
38
|
+
UTF-8 byte count and SHA-256 of the exact JSON record array. All snapshot rows
|
|
39
|
+
have revision C; CDC after C has strictly greater revisions.
|
|
40
|
+
|
|
41
|
+
Source rowid is explicit `sourceOrder`; the WITHOUT ROWID candidate table uses
|
|
42
|
+
composite-key order and null sourceOrder. All SQL values, JSON strings,
|
|
43
|
+
spec digests, recording domains/vectors, old zero marks and null boundaries are
|
|
44
|
+
preserved, without reconstructing unknown history. A final-value/hash comparison
|
|
45
|
+
can apply tombstones and upserts from CDC to the snapshot.
|
|
46
|
+
|
|
47
|
+
Exhaust or explicitly `return()` the iterator to release its read transaction.
|
|
48
|
+
Default read lifetime is 30 seconds, checked at each record; pausing a consumer
|
|
49
|
+
cannot be forcibly interrupted by this synchronous API. WAL readers pin files,
|
|
50
|
+
so integrations must also bound consumer pauses and monitor WAL growth. Default
|
|
51
|
+
chunks are at most 100 records and 256 KiB of record-array JSON. Oversized records
|
|
52
|
+
raise `record_too_large` (P5 supplies content chunk manifests), never truncate.
|
|
53
|
+
|
|
54
|
+
## Consent and outbox
|
|
55
|
+
|
|
56
|
+
`spoolBatch` defaults to local-only and returns null before serializing records,
|
|
57
|
+
resolving membership, creating streams or storing **any cloud payload bytes**.
|
|
58
|
+
The raw journal remains local capture, not a pre-consent cloud spool.
|
|
59
|
+
|
|
60
|
+
Callers supply a fixed journal interval and a bounded page, current explicit
|
|
61
|
+
consent, upload scope, and a synchronous `scopeFor` resolver proving each record's
|
|
62
|
+
source project/root membership. Resolve from retained source facts, including
|
|
63
|
+
`beforeValues` on deletes, never from the upload's asserted label. Historical
|
|
64
|
+
timestamps are checked against the grant's live/backfill range. A tombstone
|
|
65
|
+
without its authorization before-image is rejected. Resolvers must fail closed
|
|
66
|
+
for unknown membership; P4 cannot infer project identity from arbitrary schema
|
|
67
|
+
keys. Timeless facts need the same externally proven membership.
|
|
68
|
+
|
|
69
|
+
The consent shape and authorization match shared P1. The standalone local
|
|
70
|
+
package's NodeNext rootDir/published files do not include the unpublished shared
|
|
71
|
+
package, so the small consent boundary is local with cross-contract tests.
|
|
72
|
+
The all-table outbox envelope is explicitly **not** `ActivityBatch` or an HTTP
|
|
73
|
+
wire contract: shared P1 metadata DTOs currently cover only session/event/span.
|
|
74
|
+
P5 must adapt/extend wire contracts before uploading these records.
|
|
75
|
+
|
|
76
|
+
Metadata mode is a closed numeric/null column allowlist. Raw keys can be paths,
|
|
77
|
+
URIs or user text, so metadata hashes `table + NUL + source key` with SHA-256;
|
|
78
|
+
upsert/delete identities remain stable. Before-images never enter the spool.
|
|
79
|
+
Metadata does not offer full relationship/content parity. Full rows and original
|
|
80
|
+
keys require managed-content acknowledgement and **all seven content kinds**,
|
|
81
|
+
because unrestricted nested JSON may contain any kind. Partial raw selection
|
|
82
|
+
fails explicitly; P5/P6 need selected-kind, typed transformations for consent UX.
|
|
83
|
+
This conservative policy is not redaction or E2EE.
|
|
84
|
+
|
|
85
|
+
Outbox JSON is transformed before its immutable insert. Bounds include the whole
|
|
86
|
+
envelope, not just its records: default/hard ceilings are 100 records/256 KiB,
|
|
87
|
+
and explicit quota defaults are 1024 pending batches/64 MiB. Over-limit pages,
|
|
88
|
+
single records or envelope overhead fail explicitly; callers split pages or use
|
|
89
|
+
P5 chunk manifests. There is no silent truncation or automatic data dropping.
|
|
90
|
+
Quota failure rolls back sequence allocation. Batches bind device and source
|
|
91
|
+
lineage, retain exact bytes/hash/batch ID across restart and link contiguous
|
|
92
|
+
journal intervals.
|
|
93
|
+
|
|
94
|
+
`pendingBatch` exposes only sequence `ack + 1`. `acknowledgeBatch` accepts the
|
|
95
|
+
matching hash for exactly that next batch and atomically advances the durable
|
|
96
|
+
ack/cut and removes its spool. Repeating the most recent ACK is idempotent.
|
|
97
|
+
Future, stale or mismatched receipts cannot skip a batch. The caller must verify
|
|
98
|
+
remote durable receipts and recheck current consent/revocation before sending;
|
|
99
|
+
there is deliberately no network sender or remote-acceptance claim here.
|
|
100
|
+
|
|
101
|
+
Version 7 history exports/imports keep existing portable history semantics and
|
|
102
|
+
do not import another database's journal, outbox, receipts or source identity.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Local logical restore
|
|
2
|
+
|
|
3
|
+
`dist/sync/restore.js` restores complete logical snapshots into a **fresh, migrated
|
|
4
|
+
v7 database**. It does not merge history, replace an existing file, configure roots,
|
|
5
|
+
run recorded commands, or restore credentials. All runtime imports are inside the
|
|
6
|
+
local package; no sibling shared source is required.
|
|
7
|
+
|
|
8
|
+
## API
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { openDb } from "./dist/store/db.js";
|
|
12
|
+
import {
|
|
13
|
+
restoreSnapshot, applyCatchup, verify,
|
|
14
|
+
type RestoreDescriptor, type Catchup,
|
|
15
|
+
} from "./dist/sync/restore.js";
|
|
16
|
+
import type { SnapshotChunk } from "./dist/sync/snapshot.js";
|
|
17
|
+
import type { Db } from "./dist/store/db.js";
|
|
18
|
+
|
|
19
|
+
// Exact public argument signatures:
|
|
20
|
+
// restoreSnapshot(db: Db, input: RestoreDescriptor, pages: Iterable<SnapshotChunk>)
|
|
21
|
+
// applyCatchup(db: Db, input: Catchup)
|
|
22
|
+
// verify(db: Db, input: RestoreDescriptor)
|
|
23
|
+
//
|
|
24
|
+
// All return synchronously:
|
|
25
|
+
// { sourceDomain: string, cut: number,
|
|
26
|
+
// counts: Record<string, number>, hash: string }
|
|
27
|
+
//
|
|
28
|
+
// RestoreDescriptor:
|
|
29
|
+
// { readonly sourceDomain: string; readonly cut: number;
|
|
30
|
+
// readonly counts?: Record<TargetTable, number>; readonly hash?: string }
|
|
31
|
+
//
|
|
32
|
+
// Catchup:
|
|
33
|
+
// { readonly sourceDomain: string; readonly after: number; readonly cut: number;
|
|
34
|
+
// readonly records: Iterable<Mutation>;
|
|
35
|
+
// readonly counts?: Record<TargetTable, number>; readonly hash?: string }
|
|
36
|
+
|
|
37
|
+
const db = openDb("/new/location/restore.db");
|
|
38
|
+
try {
|
|
39
|
+
restoreSnapshot(db, snapshotDescriptor, downloadedSnapshotPages);
|
|
40
|
+
applyCatchup(db, {
|
|
41
|
+
...finalDescriptor,
|
|
42
|
+
after: snapshotDescriptor.cut,
|
|
43
|
+
records: completeCommittedCatchup,
|
|
44
|
+
});
|
|
45
|
+
verify(db, finalDescriptor);
|
|
46
|
+
} finally {
|
|
47
|
+
db.close();
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The example's descriptors and downloaded records are caller-provided verified
|
|
52
|
+
transport inputs; this module does not perform network requests or decoding.
|
|
53
|
+
`TargetTable` and `Mutation` are exported by `dist/sync/tables.js`.
|
|
54
|
+
|
|
55
|
+
Use a dedicated offline connection. The destination must have no source facts,
|
|
56
|
+
meta configuration, transport streams/outbox/journal, previously consumed journal
|
|
57
|
+
sequence, previous restore, or advanced recording clock. Its existing fresh
|
|
58
|
+
`sync_identity` and singleton `recording_clock` are expected. An active caller
|
|
59
|
+
transaction is refused without rolling it back.
|
|
60
|
+
|
|
61
|
+
## Transfer and verification contracts
|
|
62
|
+
|
|
63
|
+
Snapshot pages use the existing `logicalSnapshot()` shape. Page indices must be
|
|
64
|
+
contiguous from zero, with one snapshot ID/domain/cut. Each page's byte length and
|
|
65
|
+
SHA-256 cover `JSON.stringify(page.records)`. Every row must be an upsert at the
|
|
66
|
+
snapshot cut. Duplicate entity keys, partial/extra SQL columns, mismatched keys,
|
|
67
|
+
invalid rowids, missing source clock and broken foreign keys fail the restore.
|
|
68
|
+
Revision **0**, cut **0**, rowid **0**, vector marks **0**, and nullable historical
|
|
69
|
+
boundaries are legitimate and remain distinct.
|
|
70
|
+
|
|
71
|
+
Supply `counts` and `hash` whenever completeness must be verified. Counts contain
|
|
72
|
+
all 15 table names, including zero counts. The descriptor hash is SHA-256 of
|
|
73
|
+
`JSON.stringify(allRecords)`, with records concatenated in `logicalSnapshot()`
|
|
74
|
+
order: target table order, then source rowid (or primary key for
|
|
75
|
+
`load_candidates`). Each record has the snapshot's revision and the existing
|
|
76
|
+
Mutation fields, including `beforeValues: null`. This is an aggregate record
|
|
77
|
+
hash, **not** a hash of concatenated page hashes, and does not depend on page
|
|
78
|
+
sizes. `verify()` recomputes this canonical hash from stored rows and source-clock
|
|
79
|
+
provenance. It also runs SQLite integrity and foreign-key checks.
|
|
80
|
+
|
|
81
|
+
Counts/hash are optional for trusted local callers; without them, page integrity,
|
|
82
|
+
exact storage equality, SQL constraints and foreign keys are checked, but a
|
|
83
|
+
transport that omitted whole pages or entities cannot be detected. Do not claim
|
|
84
|
+
remote transfer completeness without the expected descriptor.
|
|
85
|
+
|
|
86
|
+
Catchup consumes **one entire committed source range**, not an arbitrary page:
|
|
87
|
+
|
|
88
|
+
1. Pin a source `journalHead()` cut `C`.
|
|
89
|
+
2. Gather all `readJournal({ after, through: C, limit })` pages, advancing the
|
|
90
|
+
paging cursor to the last returned revision until exhausted.
|
|
91
|
+
3. Call `applyCatchup({ sourceDomain, after: previousVerifiedCut, cut: C, records,
|
|
92
|
+
counts, hash })` once, with the final source descriptor at `C`.
|
|
93
|
+
|
|
94
|
+
Records must be globally ascending by revision, strictly above `after` and at or
|
|
95
|
+
below `cut`; each entity occurs only once, as in a coalesced journal range.
|
|
96
|
+
Sequence gaps are legal because coalescing removes intermediate images.
|
|
97
|
+
The domain and previous verified cut must match persisted restore state.
|
|
98
|
+
An empty same-cut range is valid. Replaying an older range is refused rather
|
|
99
|
+
than silently overwriting a newer restore. Final rows are rewritten as a set
|
|
100
|
+
inside one transaction so rowid reuse, key moves, uniqueness changes and
|
|
101
|
+
foreign-key dependencies cannot make arrival order change the result.
|
|
102
|
+
|
|
103
|
+
Catchup is restricted to the offline restore phase. Once normal local collection
|
|
104
|
+
has advanced the local clock or journal (or created a stream/configuration),
|
|
105
|
+
further source catchup is refused. It is not a bidirectional merge API.
|
|
106
|
+
|
|
107
|
+
## Identity, exact values and provenance
|
|
108
|
+
|
|
109
|
+
All 001–006 source columns, source keys, rowids, original recording vectors,
|
|
110
|
+
candidate membership, workflow bodies/digests and unknown flow boundaries are
|
|
111
|
+
restored exactly. SQLite type-affinity changes are detected by comparing stored
|
|
112
|
+
scalars with the input images. No arrival vectors are added, and no historical
|
|
113
|
+
cuts are inferred from timestamps.
|
|
114
|
+
|
|
115
|
+
Source `recording_clock` is the sole exception to placement: its exact complete
|
|
116
|
+
Mutation is persisted as `sync_restore_state.clock_json`, together with source
|
|
117
|
+
domain and verified cut, rather than replacing the local clock. `verify()` uses
|
|
118
|
+
that source clock image when reproducing the original logical export hash. The
|
|
119
|
+
destination keeps its independently generated recording domain and position;
|
|
120
|
+
the source sync identity, journal, streams, ACKs, outbox, configuration and
|
|
121
|
+
credentials are never imported. A regular `logicalSnapshot(destination)` exports
|
|
122
|
+
the destination's own lineage/clock, so its hash is intentionally different from
|
|
123
|
+
the source-provenance hash.
|
|
124
|
+
|
|
125
|
+
Recording, candidate and CDC trigger definitions are captured from
|
|
126
|
+
`sqlite_schema`, dropped **inside** the write transaction, and recreated from
|
|
127
|
+
their exact SQL in their existing creation order. This prevents generated arrival
|
|
128
|
+
marks or candidate reconstruction from replacing original facts. Rollback
|
|
129
|
+
restores the trigger definitions automatically. FTS is rebuilt from restored
|
|
130
|
+
active skills; source FTS internals are not copied.
|
|
131
|
+
|
|
132
|
+
After reopen, ordinary collection uses the destination recording domain and
|
|
133
|
+
journals normal local changes. Existing source vectors stay unchanged. Normal
|
|
134
|
+
store startup behavior still applies; use a snapshot from a canonical migrated
|
|
135
|
+
source, not a manually fabricated store with split-session duplicates that
|
|
136
|
+
`openDb()` would normalize on reopen.
|
|
137
|
+
|
|
138
|
+
## Failure and resource limits
|
|
139
|
+
|
|
140
|
+
Snapshot restore and each catchup range use separate `BEGIN IMMEDIATE`
|
|
141
|
+
transactions. Parsing errors, iterator failures, bad hashes/counts, SQL failures
|
|
142
|
+
and verification failures roll back rows, restore state, FTS and trigger DDL.
|
|
143
|
+
Other SQLite readers see only committed states. A failed catchup leaves the
|
|
144
|
+
previous verified snapshot/cut intact and can be retried. Source databases/files
|
|
145
|
+
are never opened or modified by these APIs. Existing destination data/files are
|
|
146
|
+
never deleted or replaced.
|
|
147
|
+
|
|
148
|
+
The caller creates and owns the new database file. Failed restore may leave that
|
|
149
|
+
fresh migrated empty file; there is no file replacement/publication API here.
|
|
150
|
+
Do not expose the new destination to normal collection until the final catchup
|
|
151
|
+
and verification succeed. To publish under another application path, the owner
|
|
152
|
+
must coordinate database closure and SQLite sidecars; renaming a live WAL file
|
|
153
|
+
alone is not publication.
|
|
154
|
+
|
|
155
|
+
This implementation materializes the complete restored record set in memory
|
|
156
|
+
and rewrites it during each catchup range. It favors exact offline recovery over
|
|
157
|
+
incremental write performance; it is not a bounded-memory restore engine.
|
|
158
|
+
Existing snapshot limits still apply upstream (100 records/256 KiB per page,
|
|
159
|
+
individual oversized records require the owner's chunk transport). The restore
|
|
160
|
+
layer accepts already reconstructed larger records without truncation. It does
|
|
161
|
+
not implement transport authentication, deletion ledgers, chunk reconstruction,
|
|
162
|
+
CLI commands, path remapping, or cloud generation fencing.
|
|
163
|
+
|
|
164
|
+
`RestoreError.code` distinguishes `destination_busy`, `destination_used`,
|
|
165
|
+
`invalid_snapshot`, `invalid_record`, `verification_failed`, `invalid_catchup`,
|
|
166
|
+
and `restore_missing`. Zod parse errors, SQLite errors and iterator errors retain
|
|
167
|
+
their original types and details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skillar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Local skill router for coding agents: search your skills, trace how agents use them, and see the flow.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"src/store/schema.sql",
|
|
18
18
|
"src/store/migrations",
|
|
19
19
|
"src/store/task-types.json",
|
|
20
|
-
"README.md"
|
|
20
|
+
"README.md",
|
|
21
|
+
"NOTICE"
|
|
21
22
|
],
|
|
22
23
|
"type": "module",
|
|
23
24
|
"bin": {
|
|
@@ -28,9 +29,11 @@
|
|
|
28
29
|
"node": ">=24.15"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|
|
31
|
-
"
|
|
32
|
+
"prebuild": "node dashboard/design/skillar-theme/build.mjs",
|
|
33
|
+
"dev:dashboard": "node dev-dashboard.mjs",
|
|
34
|
+
"build": "tsc -p tsconfig.json && node build-cloud.mjs && node build-dashboard.mjs",
|
|
32
35
|
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p dashboard/tsconfig.json",
|
|
33
|
-
"test": "node --test \"test/**/*.test.mjs\"",
|
|
36
|
+
"test": "node --test \"test/**/*.test.mjs\" && node --test test/sync-performance.mjs",
|
|
34
37
|
"start": "node dist/cli/main.js serve"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
@@ -39,12 +42,22 @@
|
|
|
39
42
|
"zod": "^4.1.11"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
45
|
+
"@astryxdesign/core": "^0.7.16",
|
|
46
|
+
"@astryxdesign/theme-neutral": "^0.7.16",
|
|
47
|
+
"@stylexjs/stylex": "^0.19.2",
|
|
42
48
|
"@types/d3-sankey": "^0.12.4",
|
|
43
49
|
"@types/express": "^5.0.5",
|
|
44
50
|
"@types/node": "^24.3.0",
|
|
51
|
+
"@types/prismjs": "1.26.5",
|
|
52
|
+
"@types/react": "^19.3.0",
|
|
53
|
+
"@types/react-dom": "^19.3.0",
|
|
45
54
|
"d3-sankey": "0.12.3",
|
|
46
55
|
"esbuild": "^0.28.2",
|
|
47
|
-
"
|
|
56
|
+
"jsdom": "^31.0.1",
|
|
57
|
+
"lucide-react": "^1.76.0",
|
|
58
|
+
"prismjs": "1.30.0",
|
|
59
|
+
"react": "^19.3.1",
|
|
60
|
+
"react-dom": "^19.3.1",
|
|
48
61
|
"typescript": "^5.9.2"
|
|
49
62
|
}
|
|
50
63
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
-- Local raw history is not a cloud payload. Consent is applied before outbox insertion.
|
|
2
|
+
CREATE TABLE sync_identity (
|
|
3
|
+
singleton INTEGER PRIMARY KEY CHECK (singleton = 1),
|
|
4
|
+
source_domain TEXT NOT NULL UNIQUE
|
|
5
|
+
);
|
|
6
|
+
INSERT INTO sync_identity SELECT 1, domain FROM recording_clock WHERE singleton = 1;
|
|
7
|
+
|
|
8
|
+
CREATE TABLE sync_journal (
|
|
9
|
+
seq INTEGER PRIMARY KEY AUTOINCREMENT CHECK (seq <= 9007199254740991),
|
|
10
|
+
table_name TEXT NOT NULL,
|
|
11
|
+
entity_key TEXT NOT NULL,
|
|
12
|
+
operation TEXT NOT NULL CHECK (operation IN ('upsert', 'delete')),
|
|
13
|
+
source_order INTEGER,
|
|
14
|
+
row_json TEXT,
|
|
15
|
+
before_json TEXT,
|
|
16
|
+
CHECK ((operation = 'delete') = (row_json IS NULL))
|
|
17
|
+
);
|
|
18
|
+
CREATE INDEX sync_journal_entity ON sync_journal(table_name, entity_key, seq);
|
|
19
|
+
-- RAISE(ABORT) must defeat an outer INSERT OR IGNORE on counter exhaustion.
|
|
20
|
+
CREATE TRIGGER sync_journal_range BEFORE INSERT ON sync_journal
|
|
21
|
+
WHEN COALESCE((SELECT seq FROM sqlite_sequence WHERE name='sync_journal'),0) >= 9007199254740991
|
|
22
|
+
BEGIN
|
|
23
|
+
SELECT RAISE(ABORT, 'sync journal exhausted');
|
|
24
|
+
END;
|
|
25
|
+
|
|
26
|
+
CREATE TABLE sync_streams (
|
|
27
|
+
stream_id TEXT PRIMARY KEY,
|
|
28
|
+
source_domain TEXT NOT NULL,
|
|
29
|
+
device_id TEXT NOT NULL,
|
|
30
|
+
next_sequence INTEGER NOT NULL DEFAULT 1 CHECK (next_sequence BETWEEN 1 AND 9007199254740991),
|
|
31
|
+
ack_sequence INTEGER NOT NULL DEFAULT 0,
|
|
32
|
+
ack_hash TEXT,
|
|
33
|
+
ack_cut INTEGER NOT NULL DEFAULT 0,
|
|
34
|
+
CHECK (ack_sequence < next_sequence)
|
|
35
|
+
);
|
|
36
|
+
CREATE TABLE sync_outbox (
|
|
37
|
+
stream_id TEXT NOT NULL REFERENCES sync_streams(stream_id),
|
|
38
|
+
sequence INTEGER NOT NULL,
|
|
39
|
+
batch_id TEXT NOT NULL UNIQUE,
|
|
40
|
+
payload TEXT NOT NULL,
|
|
41
|
+
payload_hash TEXT NOT NULL,
|
|
42
|
+
payload_bytes INTEGER NOT NULL CHECK (payload_bytes BETWEEN 1 AND 262144),
|
|
43
|
+
journal_from INTEGER NOT NULL,
|
|
44
|
+
journal_through INTEGER NOT NULL CHECK (journal_through >= journal_from),
|
|
45
|
+
PRIMARY KEY (stream_id, sequence)
|
|
46
|
+
);
|
|
47
|
+
CREATE TRIGGER sync_outbox_immutable BEFORE UPDATE ON sync_outbox BEGIN
|
|
48
|
+
SELECT RAISE(ABORT, 'sync outbox is immutable');
|
|
49
|
+
END;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- These receipts are local authority, not replicated source content.
|
|
2
|
+
-- Keep them across disconnect/reconnect and source data retention.
|
|
3
|
+
CREATE TABLE connector_command_receipts (
|
|
4
|
+
account_id TEXT NOT NULL,
|
|
5
|
+
generation INTEGER NOT NULL,
|
|
6
|
+
device_id TEXT NOT NULL,
|
|
7
|
+
source_domain TEXT NOT NULL,
|
|
8
|
+
command_id TEXT NOT NULL,
|
|
9
|
+
payload_hash TEXT NOT NULL,
|
|
10
|
+
result_json TEXT NOT NULL,
|
|
11
|
+
PRIMARY KEY (account_id, generation, device_id, source_domain, command_id)
|
|
12
|
+
);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e={attributionRate:{"claude-code":1,codex:.95,gemini:null,cursor:null,omo:null,gajae:1,openclaw:null,unknown:null},lastEventByRuntime:{codex:1791803932125,gajae:1791780277431,"claude-code":1791187883789,gemini:179179e7},unattributed:{searches:3,loads:1}},u={attributionRate:{"claude-code":null,codex:null,gemini:null,cursor:null,omo:null,gajae:null,openclaw:null,unknown:null},unattributed:{searches:0,loads:0}},a={stats:e,statsEmpty:u};export{a as default,e as stats,u as statsEmpty};
|