@cavelang/cli 0.27.14 → 0.29.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/Authors.md +5 -0
- package/License.md +6 -0
- package/README.md +122 -24
- package/dist/internal/act/action.d.ts +69 -0
- package/dist/internal/act/action.d.ts.map +1 -0
- package/dist/internal/act/action.js +201 -0
- package/dist/internal/act/action.js.map +1 -0
- package/dist/internal/act/declare.d.ts +102 -0
- package/dist/internal/act/declare.d.ts.map +1 -0
- package/dist/internal/act/declare.js +270 -0
- package/dist/internal/act/declare.js.map +1 -0
- package/dist/internal/act/engine.d.ts +103 -0
- package/dist/internal/act/engine.d.ts.map +1 -0
- package/dist/internal/act/engine.js +298 -0
- package/dist/internal/act/engine.js.map +1 -0
- package/dist/internal/act/index.d.ts +27 -0
- package/dist/internal/act/index.d.ts.map +1 -0
- package/dist/internal/act/index.js +25 -0
- package/dist/internal/act/index.js.map +1 -0
- package/dist/internal/automate/automation.d.ts +78 -0
- package/dist/internal/automate/automation.d.ts.map +1 -0
- package/dist/internal/automate/automation.js +135 -0
- package/dist/internal/automate/automation.js.map +1 -0
- package/dist/internal/automate/declare.d.ts +84 -0
- package/dist/internal/automate/declare.d.ts.map +1 -0
- package/dist/internal/automate/declare.js +233 -0
- package/dist/internal/automate/declare.js.map +1 -0
- package/dist/internal/automate/engine.d.ts +125 -0
- package/dist/internal/automate/engine.d.ts.map +1 -0
- package/dist/internal/automate/engine.js +388 -0
- package/dist/internal/automate/engine.js.map +1 -0
- package/dist/internal/automate/index.d.ts +28 -0
- package/dist/internal/automate/index.d.ts.map +1 -0
- package/dist/internal/automate/index.js +26 -0
- package/dist/internal/automate/index.js.map +1 -0
- package/dist/internal/automate/main.d.ts +26 -0
- package/dist/internal/automate/main.d.ts.map +1 -0
- package/dist/internal/automate/main.js +298 -0
- package/dist/internal/automate/main.js.map +1 -0
- package/dist/internal/connect/index.d.ts +26 -0
- package/dist/internal/connect/index.d.ts.map +1 -0
- package/dist/internal/connect/index.js +24 -0
- package/dist/internal/connect/index.js.map +1 -0
- package/dist/internal/connect/main.d.ts +23 -0
- package/dist/internal/connect/main.d.ts.map +1 -0
- package/dist/internal/connect/main.js +330 -0
- package/dist/internal/connect/main.js.map +1 -0
- package/dist/internal/connect/run.d.ts +85 -0
- package/dist/internal/connect/run.d.ts.map +1 -0
- package/dist/internal/connect/run.js +242 -0
- package/dist/internal/connect/run.js.map +1 -0
- package/dist/internal/connect/source.d.ts +44 -0
- package/dist/internal/connect/source.d.ts.map +1 -0
- package/dist/internal/connect/source.js +215 -0
- package/dist/internal/connect/source.js.map +1 -0
- package/dist/internal/connect/template.d.ts +69 -0
- package/dist/internal/connect/template.d.ts.map +1 -0
- package/dist/internal/connect/template.js +221 -0
- package/dist/internal/connect/template.js.map +1 -0
- package/dist/internal/eval/index.d.ts +28 -0
- package/dist/internal/eval/index.d.ts.map +1 -0
- package/dist/internal/eval/index.js +27 -0
- package/dist/internal/eval/index.js.map +1 -0
- package/dist/internal/eval/judge.d.ts +30 -0
- package/dist/internal/eval/judge.d.ts.map +1 -0
- package/dist/internal/eval/judge.js +101 -0
- package/dist/internal/eval/judge.js.map +1 -0
- package/dist/internal/eval/loop.d.ts +64 -0
- package/dist/internal/eval/loop.d.ts.map +1 -0
- package/dist/internal/eval/loop.js +123 -0
- package/dist/internal/eval/loop.js.map +1 -0
- package/dist/internal/eval/main.d.ts +17 -0
- package/dist/internal/eval/main.d.ts.map +1 -0
- package/dist/internal/eval/main.js +236 -0
- package/dist/internal/eval/main.js.map +1 -0
- package/dist/internal/eval/queries.d.ts +74 -0
- package/dist/internal/eval/queries.d.ts.map +1 -0
- package/dist/internal/eval/queries.js +161 -0
- package/dist/internal/eval/queries.js.map +1 -0
- package/dist/internal/eval/run.d.ts +143 -0
- package/dist/internal/eval/run.d.ts.map +1 -0
- package/dist/internal/eval/run.js +376 -0
- package/dist/internal/eval/run.js.map +1 -0
- package/dist/internal/eval/score.d.ts +81 -0
- package/dist/internal/eval/score.d.ts.map +1 -0
- package/dist/internal/eval/score.js +126 -0
- package/dist/internal/eval/score.js.map +1 -0
- package/dist/internal/eval/suite.d.ts +66 -0
- package/dist/internal/eval/suite.d.ts.map +1 -0
- package/dist/internal/eval/suite.js +130 -0
- package/dist/internal/eval/suite.js.map +1 -0
- package/dist/internal/ingest/context.d.ts +20 -0
- package/dist/internal/ingest/context.d.ts.map +1 -0
- package/dist/internal/ingest/context.js +59 -0
- package/dist/internal/ingest/context.js.map +1 -0
- package/dist/internal/ingest/files.d.ts +46 -0
- package/dist/internal/ingest/files.d.ts.map +1 -0
- package/dist/internal/ingest/files.js +115 -0
- package/dist/internal/ingest/files.js.map +1 -0
- package/dist/internal/ingest/index.d.ts +31 -0
- package/dist/internal/ingest/index.d.ts.map +1 -0
- package/dist/internal/ingest/index.js +29 -0
- package/dist/internal/ingest/index.js.map +1 -0
- package/dist/internal/ingest/main.d.ts +12 -0
- package/dist/internal/ingest/main.d.ts.map +1 -0
- package/dist/internal/ingest/main.js +180 -0
- package/dist/internal/ingest/main.js.map +1 -0
- package/dist/internal/ingest/prompt.d.ts +32 -0
- package/dist/internal/ingest/prompt.d.ts.map +1 -0
- package/dist/internal/ingest/prompt.js +75 -0
- package/dist/internal/ingest/prompt.js.map +1 -0
- package/dist/internal/ingest/run.d.ts +142 -0
- package/dist/internal/ingest/run.d.ts.map +1 -0
- package/dist/internal/ingest/run.js +350 -0
- package/dist/internal/ingest/run.js.map +1 -0
- package/dist/internal/ingest/web.d.ts +48 -0
- package/dist/internal/ingest/web.d.ts.map +1 -0
- package/dist/internal/ingest/web.js +140 -0
- package/dist/internal/ingest/web.js.map +1 -0
- package/dist/internal/loop/demo.d.ts +22 -0
- package/dist/internal/loop/demo.d.ts.map +1 -0
- package/dist/internal/loop/demo.js +67 -0
- package/dist/internal/loop/demo.js.map +1 -0
- package/dist/internal/loop/index.d.ts +20 -0
- package/dist/internal/loop/index.d.ts.map +1 -0
- package/dist/internal/loop/index.js +17 -0
- package/dist/internal/loop/index.js.map +1 -0
- package/dist/internal/loop/llm.d.ts +99 -0
- package/dist/internal/loop/llm.d.ts.map +1 -0
- package/dist/internal/loop/llm.js +231 -0
- package/dist/internal/loop/llm.js.map +1 -0
- package/dist/internal/loop/reconstruct.d.ts +87 -0
- package/dist/internal/loop/reconstruct.d.ts.map +1 -0
- package/dist/internal/loop/reconstruct.js +157 -0
- package/dist/internal/loop/reconstruct.js.map +1 -0
- package/dist/internal/loop/sqlite.d.ts +13 -0
- package/dist/internal/loop/sqlite.d.ts.map +1 -0
- package/dist/internal/loop/sqlite.js +33 -0
- package/dist/internal/loop/sqlite.js.map +1 -0
- package/dist/internal/loop/store.d.ts +50 -0
- package/dist/internal/loop/store.d.ts.map +1 -0
- package/dist/internal/loop/store.js +100 -0
- package/dist/internal/loop/store.js.map +1 -0
- package/dist/internal/mcp/bin.d.ts +7 -0
- package/dist/internal/mcp/bin.d.ts.map +1 -0
- package/dist/internal/mcp/bin.js +8 -0
- package/dist/internal/mcp/bin.js.map +1 -0
- package/dist/internal/mcp/index.d.ts +25 -0
- package/dist/internal/mcp/index.d.ts.map +1 -0
- package/dist/internal/mcp/index.js +23 -0
- package/dist/internal/mcp/index.js.map +1 -0
- package/dist/internal/mcp/main.d.ts +23 -0
- package/dist/internal/mcp/main.d.ts.map +1 -0
- package/dist/internal/mcp/main.js +156 -0
- package/dist/internal/mcp/main.js.map +1 -0
- package/dist/internal/mcp/server.d.ts +92 -0
- package/dist/internal/mcp/server.d.ts.map +1 -0
- package/dist/internal/mcp/server.js +251 -0
- package/dist/internal/mcp/server.js.map +1 -0
- package/dist/internal/mcp/tools.d.ts +91 -0
- package/dist/internal/mcp/tools.d.ts.map +1 -0
- package/dist/internal/mcp/tools.js +584 -0
- package/dist/internal/mcp/tools.js.map +1 -0
- package/dist/internal/rules/declare.d.ts +58 -0
- package/dist/internal/rules/declare.d.ts.map +1 -0
- package/dist/internal/rules/declare.js +152 -0
- package/dist/internal/rules/declare.js.map +1 -0
- package/dist/internal/rules/engine.d.ts +125 -0
- package/dist/internal/rules/engine.d.ts.map +1 -0
- package/dist/internal/rules/engine.js +575 -0
- package/dist/internal/rules/engine.js.map +1 -0
- package/dist/internal/rules/index.d.ts +23 -0
- package/dist/internal/rules/index.d.ts.map +1 -0
- package/dist/internal/rules/index.js +21 -0
- package/dist/internal/rules/index.js.map +1 -0
- package/dist/internal/rules/rule.d.ts +88 -0
- package/dist/internal/rules/rule.d.ts.map +1 -0
- package/dist/internal/rules/rule.js +221 -0
- package/dist/internal/rules/rule.js.map +1 -0
- package/dist/internal/shape/check.d.ts +118 -0
- package/dist/internal/shape/check.d.ts.map +1 -0
- package/dist/internal/shape/check.js +331 -0
- package/dist/internal/shape/check.js.map +1 -0
- package/dist/internal/shape/client.d.ts +31 -0
- package/dist/internal/shape/client.d.ts.map +1 -0
- package/dist/internal/shape/client.js +170 -0
- package/dist/internal/shape/client.js.map +1 -0
- package/dist/internal/shape/gate.d.ts +33 -0
- package/dist/internal/shape/gate.d.ts.map +1 -0
- package/dist/internal/shape/gate.js +0 -0
- package/dist/internal/shape/gate.js.map +1 -0
- package/dist/internal/shape/index.d.ts +27 -0
- package/dist/internal/shape/index.d.ts.map +1 -0
- package/dist/internal/shape/index.js +23 -0
- package/dist/internal/shape/index.js.map +1 -0
- package/dist/internal/shape/suggest.d.ts +82 -0
- package/dist/internal/shape/suggest.d.ts.map +1 -0
- package/dist/internal/shape/suggest.js +374 -0
- package/dist/internal/shape/suggest.js.map +1 -0
- package/dist/internal/sync/index.d.ts +22 -0
- package/dist/internal/sync/index.d.ts.map +1 -0
- package/dist/internal/sync/index.js +21 -0
- package/dist/internal/sync/index.js.map +1 -0
- package/dist/internal/sync/sync.d.ts +95 -0
- package/dist/internal/sync/sync.d.ts.map +1 -0
- package/dist/internal/sync/sync.js +342 -0
- package/dist/internal/sync/sync.js.map +1 -0
- package/dist/internal/view/api.d.ts +196 -0
- package/dist/internal/view/api.d.ts.map +1 -0
- package/dist/internal/view/api.js +189 -0
- package/dist/internal/view/api.js.map +1 -0
- package/dist/internal/view/index.d.ts +33 -0
- package/dist/internal/view/index.d.ts.map +1 -0
- package/dist/internal/view/index.js +30 -0
- package/dist/internal/view/index.js.map +1 -0
- package/dist/internal/view/main.d.ts +11 -0
- package/dist/internal/view/main.d.ts.map +1 -0
- package/dist/internal/view/main.js +98 -0
- package/dist/internal/view/main.js.map +1 -0
- package/dist/internal/view/page.d.ts +14 -0
- package/dist/internal/view/page.d.ts.map +1 -0
- package/dist/internal/view/page.js +370 -0
- package/dist/internal/view/page.js.map +1 -0
- package/dist/internal/view/report.d.ts +52 -0
- package/dist/internal/view/report.d.ts.map +1 -0
- package/dist/internal/view/report.js +367 -0
- package/dist/internal/view/report.js.map +1 -0
- package/dist/internal/view/scope.d.ts +11 -0
- package/dist/internal/view/scope.d.ts.map +1 -0
- package/dist/internal/view/scope.js +41 -0
- package/dist/internal/view/scope.js.map +1 -0
- package/dist/internal/view/server.d.ts +35 -0
- package/dist/internal/view/server.d.ts.map +1 -0
- package/dist/internal/view/server.js +141 -0
- package/dist/internal/view/server.js.map +1 -0
- package/dist/src/act.d.ts +3 -0
- package/dist/src/act.d.ts.map +1 -0
- package/dist/src/act.js +3 -0
- package/dist/src/act.js.map +1 -0
- package/dist/src/automate.d.ts +3 -0
- package/dist/src/automate.d.ts.map +1 -0
- package/dist/src/automate.js +3 -0
- package/dist/src/automate.js.map +1 -0
- package/dist/src/cli.d.ts +24 -17
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +408 -107
- package/dist/src/cli.js.map +1 -1
- package/dist/src/commands.d.ts +104 -0
- package/dist/src/commands.d.ts.map +1 -0
- package/dist/src/commands.js +33 -0
- package/dist/src/commands.js.map +1 -0
- package/dist/src/connect.d.ts +3 -0
- package/dist/src/connect.d.ts.map +1 -0
- package/dist/src/connect.js +3 -0
- package/dist/src/connect.js.map +1 -0
- package/dist/src/dispatch.d.ts +14 -0
- package/dist/src/dispatch.d.ts.map +1 -0
- package/dist/src/dispatch.js +116 -0
- package/dist/src/dispatch.js.map +1 -0
- package/dist/src/doctor.d.ts +45 -0
- package/dist/src/doctor.d.ts.map +1 -0
- package/dist/src/doctor.js +284 -0
- package/dist/src/doctor.js.map +1 -0
- package/dist/src/eval.d.ts +3 -0
- package/dist/src/eval.d.ts.map +1 -0
- package/dist/src/eval.js +3 -0
- package/dist/src/eval.js.map +1 -0
- package/dist/src/index.d.ts +9 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/ingest.d.ts +3 -0
- package/dist/src/ingest.d.ts.map +1 -0
- package/dist/src/ingest.js +3 -0
- package/dist/src/ingest.js.map +1 -0
- package/dist/src/loop.d.ts +3 -0
- package/dist/src/loop.d.ts.map +1 -0
- package/dist/src/loop.js +3 -0
- package/dist/src/loop.js.map +1 -0
- package/dist/src/main.d.ts +1 -1
- package/dist/src/main.d.ts.map +1 -1
- package/dist/src/main.js +3 -75
- package/dist/src/main.js.map +1 -1
- package/dist/src/mcp.d.ts +3 -0
- package/dist/src/mcp.d.ts.map +1 -0
- package/dist/src/mcp.js +3 -0
- package/dist/src/mcp.js.map +1 -0
- package/dist/src/rules.d.ts +3 -0
- package/dist/src/rules.d.ts.map +1 -0
- package/dist/src/rules.js +3 -0
- package/dist/src/rules.js.map +1 -0
- package/dist/src/shape.d.ts +3 -0
- package/dist/src/shape.d.ts.map +1 -0
- package/dist/src/shape.js +3 -0
- package/dist/src/shape.js.map +1 -0
- package/dist/src/sync.d.ts +3 -0
- package/dist/src/sync.d.ts.map +1 -0
- package/dist/src/sync.js +3 -0
- package/dist/src/sync.js.map +1 -0
- package/dist/src/view.d.ts +3 -0
- package/dist/src/view.d.ts.map +1 -0
- package/dist/src/view.js +3 -0
- package/dist/src/view.js.map +1 -0
- package/package.json +81 -21
- package/src/act.ts +2 -0
- package/src/automate.ts +2 -0
- package/src/cli.ts +416 -102
- package/src/commands.ts +48 -0
- package/src/connect.ts +2 -0
- package/src/dispatch.ts +141 -0
- package/src/doctor.ts +370 -0
- package/src/eval.ts +2 -0
- package/src/index.ts +9 -2
- package/src/ingest.ts +2 -0
- package/src/loop.ts +2 -0
- package/src/main.ts +3 -66
- package/src/mcp.ts +2 -0
- package/src/rules.ts +2 -0
- package/src/shape.ts +2 -0
- package/src/sync.ts +2 -0
- package/src/view.ts +2 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store merge (spec §28).
|
|
3
|
+
*
|
|
4
|
+
* A row's UUIDv7 — one value serving as both `id` and `tx` — is its global
|
|
5
|
+
* identity (§28.1): merging copies rows absent by id verbatim (side tables
|
|
6
|
+
* included) and skips rows the target already has, which makes sync
|
|
7
|
+
* idempotent, transitive and bidirectional, and can never conflict —
|
|
8
|
+
* coexisting contradictions are legal data (§9.4), resolved at read time
|
|
9
|
+
* (§26). Merged transaction ids feed the generator's receive rule (§28.2),
|
|
10
|
+
* so everything appended after a merge sorts after everything merged,
|
|
11
|
+
* whatever the origin machine's clock read.
|
|
12
|
+
*
|
|
13
|
+
* Two source shapes, one semantic:
|
|
14
|
+
*
|
|
15
|
+
* - {@link syncDb} — another CAVE store file, merged through SQL (`ATTACH`);
|
|
16
|
+
* - {@link syncText} — §28.4 transaction-annotated canonical text
|
|
17
|
+
* (`cave export --tx`), replayed through the ordinary canonicalization
|
|
18
|
+
* pipeline under the recorded ids.
|
|
19
|
+
*
|
|
20
|
+
* An effective merge appends a §28.3 record claim in the target —
|
|
21
|
+
* `store/<from> SYNCED-INTO store/<into> @src:sync` — whose belief series
|
|
22
|
+
* is the sync log; a merge that changed nothing appends nothing.
|
|
23
|
+
*/
|
|
24
|
+
import { type Store } from '@cavelang/store';
|
|
25
|
+
export type SyncOptions = {
|
|
26
|
+
/** Origin label of the §28.3 merge record (default `origin`; `syncFile` defaults to the source's basename stem). */
|
|
27
|
+
readonly from?: string;
|
|
28
|
+
/** Target label of the §28.3 merge record (default `local`). */
|
|
29
|
+
readonly into?: string;
|
|
30
|
+
/** Append the §28.3 merge record on effective merges (default `true`). */
|
|
31
|
+
readonly record?: boolean;
|
|
32
|
+
/** Compute the full report inside a rolled-back transaction (default `false`). */
|
|
33
|
+
readonly dryRun?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export type SyncProblem = {
|
|
36
|
+
readonly line: number;
|
|
37
|
+
readonly message: string;
|
|
38
|
+
};
|
|
39
|
+
export type SyncReport = {
|
|
40
|
+
/** Claim rows merged (absent by id, now inserted). */
|
|
41
|
+
readonly merged: number;
|
|
42
|
+
/** Source claim rows skipped as already present. */
|
|
43
|
+
readonly skipped: number;
|
|
44
|
+
/** Edge rows inserted (edges already stored are skipped). */
|
|
45
|
+
readonly edges: number;
|
|
46
|
+
readonly dryRun: boolean;
|
|
47
|
+
/** The §28.3 merge record appended, when the merge was effective and records are on. */
|
|
48
|
+
readonly record?: string;
|
|
49
|
+
/** Text-source problems (spec §28.4 strictness); nothing merges when non-empty. */
|
|
50
|
+
readonly problems: readonly SyncProblem[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @returns text usable as one entity token in a §28.3 record subject:
|
|
54
|
+
* whitespace and comment/metadata sigils normalized to `-`, never empty.
|
|
55
|
+
*/
|
|
56
|
+
export declare const sanitizeLabel: (text: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* @returns merge-record label derived from a file path: basename with the
|
|
59
|
+
* extension dropped, sanitized to one entity token.
|
|
60
|
+
*/
|
|
61
|
+
export declare const labelOf: (path: string) => string;
|
|
62
|
+
/** @returns `true` when the file starts with the SQLite header — a store file rather than canonical text. */
|
|
63
|
+
export declare const isStoreFile: (path: string) => boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Merges another CAVE store file into `store` (spec §28.1): rows absent by
|
|
66
|
+
* id are copied verbatim — `id`, `tx`, `claim_key`, `raw_line`, contexts,
|
|
67
|
+
* tags, FTS — edges dedupe against stored edges, merged in-band
|
|
68
|
+
* declarations reload the registry, and the generator observes the merged
|
|
69
|
+
* transaction ids (§28.2). Idempotent: a re-run merges nothing and appends
|
|
70
|
+
* no record.
|
|
71
|
+
*/
|
|
72
|
+
export declare const syncDb: (store: Store, sourcePath: string, options?: SyncOptions) => SyncReport;
|
|
73
|
+
/**
|
|
74
|
+
* Merges §28.4 transaction-annotated canonical text (`cave export --tx`)
|
|
75
|
+
* into `store`: each claim line replays under the id its `;@` annotation
|
|
76
|
+
* carries — present ids skip, absent ids insert — through the ordinary
|
|
77
|
+
* canonicalization pipeline, never stamped (§9.5 interchange replay).
|
|
78
|
+
*
|
|
79
|
+
* Strict by the spec: every claim line must carry a well-formed UUIDv7
|
|
80
|
+
* annotation, every annotation must precede a claim line, and no id may
|
|
81
|
+
* repeat with different content — otherwise the whole text is rejected
|
|
82
|
+
* with line-level problems and nothing merges (plain text belongs to
|
|
83
|
+
* `cave import`). An *identical* repeat is a re-statement — the §28.4
|
|
84
|
+
* rendering of a row cited by several parents — and unions back into one
|
|
85
|
+
* row, contributing its edge.
|
|
86
|
+
*/
|
|
87
|
+
export declare const syncText: (store: Store, text: string, options?: SyncOptions) => SyncReport;
|
|
88
|
+
/**
|
|
89
|
+
* Merges a source file of either shape: a CAVE store (recognized by the
|
|
90
|
+
* SQLite header) through {@link syncDb}, anything else as §28.4 annotated
|
|
91
|
+
* text through {@link syncText}. The origin label defaults to the file's
|
|
92
|
+
* basename stem.
|
|
93
|
+
*/
|
|
94
|
+
export declare const syncFile: (store: Store, sourcePath: string, options?: SyncOptions) => SyncReport;
|
|
95
|
+
//# sourceMappingURL=sync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAEhE,MAAM,MAAM,WAAW,GAAG;IAC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AAgB,KAAG,UAsEhF,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,KAAK,EAAE,YAAY,MAAM,EAAE,UAAS,WAAgB,KAAG,UAKtF,CAAA"}
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Store merge (spec §28).
|
|
3
|
+
*
|
|
4
|
+
* A row's UUIDv7 — one value serving as both `id` and `tx` — is its global
|
|
5
|
+
* identity (§28.1): merging copies rows absent by id verbatim (side tables
|
|
6
|
+
* included) and skips rows the target already has, which makes sync
|
|
7
|
+
* idempotent, transitive and bidirectional, and can never conflict —
|
|
8
|
+
* coexisting contradictions are legal data (§9.4), resolved at read time
|
|
9
|
+
* (§26). Merged transaction ids feed the generator's receive rule (§28.2),
|
|
10
|
+
* so everything appended after a merge sorts after everything merged,
|
|
11
|
+
* whatever the origin machine's clock read.
|
|
12
|
+
*
|
|
13
|
+
* Two source shapes, one semantic:
|
|
14
|
+
*
|
|
15
|
+
* - {@link syncDb} — another CAVE store file, merged through SQL (`ATTACH`);
|
|
16
|
+
* - {@link syncText} — §28.4 transaction-annotated canonical text
|
|
17
|
+
* (`cave export --tx`), replayed through the ordinary canonicalization
|
|
18
|
+
* pipeline under the recorded ids.
|
|
19
|
+
*
|
|
20
|
+
* An effective merge appends a §28.3 record claim in the target —
|
|
21
|
+
* `store/<from> SYNCED-INTO store/<into> @src:sync` — whose belief series
|
|
22
|
+
* is the sync log; a merge that changed nothing appends nothing.
|
|
23
|
+
*/
|
|
24
|
+
import { closeSync, existsSync, openSync, readFileSync, readSync, realpathSync } from 'node:fs';
|
|
25
|
+
import { Uuidv7 } from '@cavelang/core';
|
|
26
|
+
import * as Canonical from '@cavelang/canonical';
|
|
27
|
+
import { Provenance, Schema } from '@cavelang/store';
|
|
28
|
+
/**
|
|
29
|
+
* @returns text usable as one entity token in a §28.3 record subject:
|
|
30
|
+
* whitespace and comment/metadata sigils normalized to `-`, never empty.
|
|
31
|
+
*/
|
|
32
|
+
export const sanitizeLabel = (text) => {
|
|
33
|
+
const label = text.replaceAll(/[\s;@#]+/g, '-');
|
|
34
|
+
return label === '' ? 'store' : label;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* @returns merge-record label derived from a file path: basename with the
|
|
38
|
+
* extension dropped, sanitized to one entity token.
|
|
39
|
+
*/
|
|
40
|
+
export const labelOf = (path) => {
|
|
41
|
+
const base = path.replaceAll('\\', '/').split('/').pop() ?? path;
|
|
42
|
+
return sanitizeLabel(base.replace(/\.[^.]+$/, ''));
|
|
43
|
+
};
|
|
44
|
+
/** SQLite database files begin with this NUL-terminated 16-byte header. */
|
|
45
|
+
const sqliteHeader = 'SQLite format 3\u0000';
|
|
46
|
+
/** @returns `true` when the file starts with the SQLite header — a store file rather than canonical text. */
|
|
47
|
+
export const isStoreFile = (path) => {
|
|
48
|
+
const fd = openSync(path, 'r');
|
|
49
|
+
try {
|
|
50
|
+
const head = Buffer.alloc(16);
|
|
51
|
+
return readSync(fd, head, 0, 16, 0) === 16 && head.toString('latin1') === sqliteHeader;
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
closeSync(fd);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
/** Runs `body` in a transaction that always rolls back — the dry-run mode. */
|
|
58
|
+
const rolledBack = (store, body) => {
|
|
59
|
+
const sentinel = Symbol('cave sync dry run');
|
|
60
|
+
let result;
|
|
61
|
+
try {
|
|
62
|
+
store.transaction(() => {
|
|
63
|
+
result = { value: body() };
|
|
64
|
+
throw sentinel;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error !== sentinel) {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result.value;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Appends the §28.3 merge record (declaring `SYNCED-INTO` in-band on first
|
|
76
|
+
* use) and returns the record line. Stamped `@src:sync` by the ordinary
|
|
77
|
+
* §9.5 path.
|
|
78
|
+
*/
|
|
79
|
+
const appendRecord = (store, from, into, merged, edges) => {
|
|
80
|
+
const declared = store.db.prepare("SELECT 1 FROM cave_claim WHERE subject = 'SYNCED-INTO' AND verb = 'IS' AND object = 'verb' AND negated = 0 LIMIT 1").get() !== undefined;
|
|
81
|
+
const line = `store/${sanitizeLabel(from)} SYNCED-INTO store/${sanitizeLabel(into)} ; +${merged} claim(s), +${edges} edge(s)`;
|
|
82
|
+
const text = declared ?
|
|
83
|
+
line :
|
|
84
|
+
`SYNCED-INTO IS verb ; an origin store's rows were merged into a target store\n${line}`;
|
|
85
|
+
store.ingest(text, { source: 'sync', strict: true });
|
|
86
|
+
return line;
|
|
87
|
+
};
|
|
88
|
+
/** Column list of `cave_claim`, for the verbatim §28.1 row copy. */
|
|
89
|
+
const claimColumns = [
|
|
90
|
+
'id', 'tx', 'subject', 'verb', 'negated', 'object', 'attribute',
|
|
91
|
+
'value_text', 'value_num', 'value_unit', 'value_approx',
|
|
92
|
+
'delta_text', 'delta_num', 'delta_unit', 'sigma_level',
|
|
93
|
+
'conf', 'importance', 'comment', 'raw_line', 'claim_key'
|
|
94
|
+
].join(', ');
|
|
95
|
+
/**
|
|
96
|
+
* Merges another CAVE store file into `store` (spec §28.1): rows absent by
|
|
97
|
+
* id are copied verbatim — `id`, `tx`, `claim_key`, `raw_line`, contexts,
|
|
98
|
+
* tags, FTS — edges dedupe against stored edges, merged in-band
|
|
99
|
+
* declarations reload the registry, and the generator observes the merged
|
|
100
|
+
* transaction ids (§28.2). Idempotent: a re-run merges nothing and appends
|
|
101
|
+
* no record.
|
|
102
|
+
*/
|
|
103
|
+
export const syncDb = (store, sourcePath, options = {}) => {
|
|
104
|
+
if (!existsSync(sourcePath)) {
|
|
105
|
+
// ATTACH would create an empty database at the missing path.
|
|
106
|
+
throw new Error(`${sourcePath}: no such file`);
|
|
107
|
+
}
|
|
108
|
+
const db = store.db;
|
|
109
|
+
const dryRun = options.dryRun === true;
|
|
110
|
+
const mainFile = db.prepare("SELECT file FROM pragma_database_list WHERE name = 'main'").get().file;
|
|
111
|
+
if (mainFile !== '' && realpathSync(sourcePath) === realpathSync(mainFile)) {
|
|
112
|
+
// Attaching the store to itself would deadlock on its own lock; a
|
|
113
|
+
// store trivially holds every row it holds.
|
|
114
|
+
return { merged: 0, skipped: 0, edges: 0, dryRun, problems: [] };
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
db.prepare('ATTACH DATABASE ? AS cave_sync_src').run(sourcePath);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw new Error(`${sourcePath}: not a CAVE store (not a SQLite database)`);
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
let isStore = false;
|
|
124
|
+
try {
|
|
125
|
+
isStore = db.prepare("SELECT 1 FROM cave_sync_src.sqlite_master WHERE type = 'table' AND name = 'cave_claim'").get() !== undefined;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
isStore = false;
|
|
129
|
+
}
|
|
130
|
+
if (!isStore) {
|
|
131
|
+
throw new Error(`${sourcePath}: not a CAVE store (no cave_claim table)`);
|
|
132
|
+
}
|
|
133
|
+
const sourceVersion = db.prepare('PRAGMA cave_sync_src.user_version').get().user_version;
|
|
134
|
+
if (sourceVersion > Schema.currentVersion) {
|
|
135
|
+
throw new Error(`${sourcePath}: schema version ${sourceVersion} is newer than this runtime supports ` +
|
|
136
|
+
`(${Schema.currentVersion}); upgrade CAVE`);
|
|
137
|
+
}
|
|
138
|
+
if (sourceVersion === Schema.currentVersion) {
|
|
139
|
+
try {
|
|
140
|
+
Schema.validate(db, sourceVersion, 'cave_sync_src');
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
throw new Error(`${sourcePath}: ${error instanceof Error ? error.message : String(error)}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const body = () => {
|
|
147
|
+
db.exec('DROP TABLE IF EXISTS temp.cave_sync_new');
|
|
148
|
+
db.exec(`CREATE TEMP TABLE cave_sync_new AS
|
|
149
|
+
SELECT id FROM cave_sync_src.cave_claim
|
|
150
|
+
WHERE id NOT IN (SELECT id FROM main.cave_claim)`);
|
|
151
|
+
try {
|
|
152
|
+
const count = (sql) => db.prepare(sql).get().n;
|
|
153
|
+
const total = count('SELECT COUNT(*) AS n FROM cave_sync_src.cave_claim');
|
|
154
|
+
const merged = count('SELECT COUNT(*) AS n FROM temp.cave_sync_new');
|
|
155
|
+
db.exec(`INSERT INTO main.cave_claim (${claimColumns})
|
|
156
|
+
SELECT ${claimColumns} FROM cave_sync_src.cave_claim
|
|
157
|
+
WHERE id IN (SELECT id FROM temp.cave_sync_new)`);
|
|
158
|
+
db.exec(`INSERT INTO main.cave_context (claim_id, context)
|
|
159
|
+
SELECT claim_id, context FROM cave_sync_src.cave_context
|
|
160
|
+
WHERE claim_id IN (SELECT id FROM temp.cave_sync_new)`);
|
|
161
|
+
const hasProvenance = db.prepare(`
|
|
162
|
+
SELECT 1 FROM cave_sync_src.sqlite_master
|
|
163
|
+
WHERE type = 'table' AND name = 'cave_provenance'
|
|
164
|
+
`).get() !== undefined;
|
|
165
|
+
if (hasProvenance) {
|
|
166
|
+
db.exec(`INSERT OR IGNORE INTO main.cave_provenance (claim_id, dimension, value)
|
|
167
|
+
SELECT claim_id, dimension, value FROM cave_sync_src.cave_provenance
|
|
168
|
+
WHERE claim_id IN (SELECT id FROM temp.cave_sync_new)`);
|
|
169
|
+
}
|
|
170
|
+
// Older stores have no dimension table. Derive every safely
|
|
171
|
+
// inferable dimension from their compact contexts after copying;
|
|
172
|
+
// INSERT OR IGNORE also fills gaps in partially upgraded stores.
|
|
173
|
+
const contextRows = db.prepare(`
|
|
174
|
+
SELECT n.id, ctx.context FROM temp.cave_sync_new n
|
|
175
|
+
LEFT JOIN main.cave_context ctx ON ctx.claim_id = n.id
|
|
176
|
+
ORDER BY n.id, ctx.rowid
|
|
177
|
+
`).all();
|
|
178
|
+
const contexts = new Map();
|
|
179
|
+
for (const row of contextRows) {
|
|
180
|
+
contexts.set(row.id, [...contexts.get(row.id) ?? [], ...row.context === null ? [] : [row.context]]);
|
|
181
|
+
}
|
|
182
|
+
const insertProvenance = db.prepare(`
|
|
183
|
+
INSERT OR IGNORE INTO main.cave_provenance (claim_id, dimension, value) VALUES (?, ?, ?)
|
|
184
|
+
`);
|
|
185
|
+
for (const [id, values] of contexts) {
|
|
186
|
+
for (const entry of Provenance.entries(values)) {
|
|
187
|
+
insertProvenance.run(id, entry.dimension, entry.value);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
db.exec(`INSERT INTO main.cave_tag (claim_id, key, value)
|
|
191
|
+
SELECT claim_id, key, value FROM cave_sync_src.cave_tag
|
|
192
|
+
WHERE claim_id IN (SELECT id FROM temp.cave_sync_new)`);
|
|
193
|
+
db.exec(`INSERT INTO main.cave_fts (claim_id, subject, verb, object, attribute, value_text, comment, raw_line)
|
|
194
|
+
SELECT id, subject, verb, object, attribute, value_text, comment, raw_line
|
|
195
|
+
FROM cave_sync_src.cave_claim
|
|
196
|
+
WHERE id IN (SELECT id FROM temp.cave_sync_new)`);
|
|
197
|
+
// Edges whose endpoints both exist after the row copy and that are
|
|
198
|
+
// not already stored — a re-sync adds none; an incremental sync may
|
|
199
|
+
// add edges into rows merged earlier.
|
|
200
|
+
const edges = Number(db.prepare(`INSERT INTO main.cave_edge (parent_id, role, child_id)
|
|
201
|
+
SELECT e.parent_id, e.role, e.child_id FROM cave_sync_src.cave_edge e
|
|
202
|
+
WHERE EXISTS (SELECT 1 FROM main.cave_claim p WHERE p.id = e.parent_id)
|
|
203
|
+
AND EXISTS (SELECT 1 FROM main.cave_claim c WHERE c.id = e.child_id)
|
|
204
|
+
AND NOT EXISTS (SELECT 1 FROM main.cave_edge m
|
|
205
|
+
WHERE m.parent_id = e.parent_id AND m.role = e.role AND m.child_id = e.child_id)`).run().changes);
|
|
206
|
+
if (!dryRun) {
|
|
207
|
+
// The receive rule (spec §28.2): later local appends outsort
|
|
208
|
+
// everything merged. Dry runs leave the generator untouched.
|
|
209
|
+
const maxTx = db.prepare('SELECT MAX(tx) AS tx FROM cave_sync_src.cave_claim').get();
|
|
210
|
+
if (maxTx.tx !== null) {
|
|
211
|
+
Uuidv7.observe(maxTx.tx);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Merged in-band declarations (REVERSE, extension verbs) take
|
|
215
|
+
// effect without reopening; rolled back with the transaction on
|
|
216
|
+
// dry runs and failures.
|
|
217
|
+
store.reloadRegistry();
|
|
218
|
+
const effective = merged + edges > 0;
|
|
219
|
+
const record = effective && options.record !== false ?
|
|
220
|
+
appendRecord(store, options.from ?? 'origin', options.into ?? 'local', merged, edges) :
|
|
221
|
+
undefined;
|
|
222
|
+
return {
|
|
223
|
+
merged,
|
|
224
|
+
skipped: total - merged,
|
|
225
|
+
edges,
|
|
226
|
+
dryRun,
|
|
227
|
+
...record === undefined ? {} : { record },
|
|
228
|
+
problems: []
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
db.exec('DROP TABLE IF EXISTS temp.cave_sync_new');
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
return dryRun ?
|
|
236
|
+
Uuidv7.withStatePreserved(() => rolledBack(store, body)) :
|
|
237
|
+
store.transaction(body);
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
db.exec('DETACH DATABASE cave_sync_src');
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* Merges §28.4 transaction-annotated canonical text (`cave export --tx`)
|
|
245
|
+
* into `store`: each claim line replays under the id its `;@` annotation
|
|
246
|
+
* carries — present ids skip, absent ids insert — through the ordinary
|
|
247
|
+
* canonicalization pipeline, never stamped (§9.5 interchange replay).
|
|
248
|
+
*
|
|
249
|
+
* Strict by the spec: every claim line must carry a well-formed UUIDv7
|
|
250
|
+
* annotation, every annotation must precede a claim line, and no id may
|
|
251
|
+
* repeat with different content — otherwise the whole text is rejected
|
|
252
|
+
* with line-level problems and nothing merges (plain text belongs to
|
|
253
|
+
* `cave import`). An *identical* repeat is a re-statement — the §28.4
|
|
254
|
+
* rendering of a row cited by several parents — and unions back into one
|
|
255
|
+
* row, contributing its edge.
|
|
256
|
+
*/
|
|
257
|
+
export const syncText = (store, text, options = {}) => {
|
|
258
|
+
const dryRun = options.dryRun === true;
|
|
259
|
+
const problems = [];
|
|
260
|
+
const txByLine = new Map();
|
|
261
|
+
text.split(/\r?\n/).forEach((raw, at) => {
|
|
262
|
+
const tx = Canonical.txOfLine(raw);
|
|
263
|
+
if (tx === undefined) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (Uuidv7.is(tx)) {
|
|
267
|
+
txByLine.set(at + 1, tx);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
problems.push({ line: at + 1, message: `malformed transaction annotation — expected \`;@ <uuidv7>\` (spec §28.4)` });
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
const result = Canonical.canonicalizeText(text, store.registry());
|
|
274
|
+
problems.push(...result.problems);
|
|
275
|
+
const consumed = new Set();
|
|
276
|
+
const seen = new Map();
|
|
277
|
+
const ids = result.claims.map(entry => {
|
|
278
|
+
const line = entry.line - 1;
|
|
279
|
+
const tx = txByLine.get(line);
|
|
280
|
+
if (tx === undefined) {
|
|
281
|
+
problems.push({
|
|
282
|
+
line: entry.line,
|
|
283
|
+
message: 'claim line without a transaction annotation — sync replays identity; use cave import for plain text (spec §28.4)'
|
|
284
|
+
});
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
consumed.add(line);
|
|
288
|
+
// A repeated id is a *re-statement* — how annotated text carries a row
|
|
289
|
+
// cited by several parents (§28.4) — and unions back into one row, the
|
|
290
|
+
// same §28.1 rule that makes re-syncs idempotent. Only a repeat that
|
|
291
|
+
// disagrees on content forks identity, and rejects.
|
|
292
|
+
const rendered = Canonical.emitClaim(entry.claim);
|
|
293
|
+
const first = seen.get(tx);
|
|
294
|
+
if (first !== undefined && first.rendered !== rendered) {
|
|
295
|
+
problems.push({ line: entry.line, message: `transaction annotation repeats line ${first.line}'s id with different content — a row has one identity (spec §28.1)` });
|
|
296
|
+
}
|
|
297
|
+
else if (first === undefined) {
|
|
298
|
+
seen.set(tx, { line: entry.line, rendered });
|
|
299
|
+
}
|
|
300
|
+
return tx;
|
|
301
|
+
});
|
|
302
|
+
for (const [line] of txByLine) {
|
|
303
|
+
if (!consumed.has(line)) {
|
|
304
|
+
problems.push({ line, message: 'transaction annotation does not precede a claim line (spec §28.4)' });
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (problems.length > 0) {
|
|
308
|
+
return { merged: 0, skipped: 0, edges: 0, dryRun, problems: problems.sort((a, b) => a.line - b.line) };
|
|
309
|
+
}
|
|
310
|
+
const body = () => {
|
|
311
|
+
const outcome = store.insertResult(result, { ids });
|
|
312
|
+
const merged = result.claims.length - outcome.skipped;
|
|
313
|
+
const effective = merged + outcome.edges > 0;
|
|
314
|
+
const record = effective && options.record !== false ?
|
|
315
|
+
appendRecord(store, options.from ?? 'origin', options.into ?? 'local', merged, outcome.edges) :
|
|
316
|
+
undefined;
|
|
317
|
+
return {
|
|
318
|
+
merged,
|
|
319
|
+
skipped: outcome.skipped,
|
|
320
|
+
edges: outcome.edges,
|
|
321
|
+
dryRun,
|
|
322
|
+
...record === undefined ? {} : { record },
|
|
323
|
+
problems: []
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
return dryRun ?
|
|
327
|
+
Uuidv7.withStatePreserved(() => rolledBack(store, body)) :
|
|
328
|
+
store.transaction(body);
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Merges a source file of either shape: a CAVE store (recognized by the
|
|
332
|
+
* SQLite header) through {@link syncDb}, anything else as §28.4 annotated
|
|
333
|
+
* text through {@link syncText}. The origin label defaults to the file's
|
|
334
|
+
* basename stem.
|
|
335
|
+
*/
|
|
336
|
+
export const syncFile = (store, sourcePath, options = {}) => {
|
|
337
|
+
const withLabel = { from: labelOf(sourcePath), ...options };
|
|
338
|
+
return isStoreFile(sourcePath) ?
|
|
339
|
+
syncDb(store, sourcePath, withLabel) :
|
|
340
|
+
syncText(store, readFileSync(sourcePath, 'utf8'), withLabel);
|
|
341
|
+
};
|
|
342
|
+
//# sourceMappingURL=sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAc,MAAM,iBAAiB,CAAA;AAgChE;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE;IACpD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,GAAG,CAAC,CAAA;IAC/C,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAA;AACvC,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE;IAC9C,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,CAAA;IAChE,OAAO,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAA;AACp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,CAAC,CAAC;QACtC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAA;AAChE,CAAC,CAAA"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View models (spec §30.2) — pure reads from a store into the JSON the
|
|
3
|
+
* page renders. Every function here is a read; nothing in this package
|
|
4
|
+
* ever writes. Semantics are the ones defined elsewhere: current belief
|
|
5
|
+
* is §9.1's latest-tx, the belief series is §9.1's history, lineage is
|
|
6
|
+
* the §13.2/§24.3 edge table, health is the §20.2 report — the view
|
|
7
|
+
* renders them, it never reinterprets them.
|
|
8
|
+
*
|
|
9
|
+
* Claims are returned *structured* (subject, verb, payload, contexts,
|
|
10
|
+
* tags as columns), not re-parsed from text: the page renders and links
|
|
11
|
+
* from row data, so no second grammar exists to drift out of sync, and
|
|
12
|
+
* `line` keeps the claim as authored for the places text is the point.
|
|
13
|
+
*/
|
|
14
|
+
import type { SourceReference } from '@cavelang/core';
|
|
15
|
+
import { check } from '@cavelang/cli/shape';
|
|
16
|
+
import { Sensitivity } from '@cavelang/store';
|
|
17
|
+
import type { Store } from '@cavelang/store';
|
|
18
|
+
/** One claim row, shaped for rendering (spec §30.2). */
|
|
19
|
+
export type ClaimView = {
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly tx: string;
|
|
22
|
+
/** ISO-8601 timestamp decoded from the tx UUIDv7. */
|
|
23
|
+
readonly at: string;
|
|
24
|
+
readonly subject: string;
|
|
25
|
+
readonly verb: string;
|
|
26
|
+
readonly negated: boolean;
|
|
27
|
+
readonly object?: string;
|
|
28
|
+
readonly attribute?: string;
|
|
29
|
+
/** Value as written (`~20B USD/yr`), attribute and metric payloads. */
|
|
30
|
+
readonly value?: string;
|
|
31
|
+
readonly delta?: string;
|
|
32
|
+
readonly conf: number;
|
|
33
|
+
readonly importance: boolean;
|
|
34
|
+
readonly comment?: string;
|
|
35
|
+
/** Context strings as stored (`src:cli`, `production`) — no `@` prefix. */
|
|
36
|
+
readonly contexts: readonly string[];
|
|
37
|
+
/** Parsed source identities and line links (spec §9.8). */
|
|
38
|
+
readonly sources: readonly SourceReference[];
|
|
39
|
+
readonly tags: readonly {
|
|
40
|
+
readonly key: string;
|
|
41
|
+
readonly value?: string;
|
|
42
|
+
}[];
|
|
43
|
+
/** The claim key — the fact whose belief series this row belongs to (§9.2). */
|
|
44
|
+
readonly key: string;
|
|
45
|
+
/** The line as authored. */
|
|
46
|
+
readonly line: string;
|
|
47
|
+
/** Rows this row cites (outgoing BECAUSE/VIA/WHEN… edges, §13.2). */
|
|
48
|
+
readonly cites: number;
|
|
49
|
+
/** Rows citing this row (incoming edges) — its dependents. */
|
|
50
|
+
readonly citedBy: number;
|
|
51
|
+
};
|
|
52
|
+
export type Options = {
|
|
53
|
+
/** Match entities through the §13.6 alias closure (default `false`). */
|
|
54
|
+
readonly aliases?: boolean;
|
|
55
|
+
/** Highest sensitivity level allowed to leave the store (default `internal`, spec §9.7). */
|
|
56
|
+
readonly maxSensitivity?: Sensitivity.Level;
|
|
57
|
+
};
|
|
58
|
+
export type Topic = {
|
|
59
|
+
readonly name: string;
|
|
60
|
+
/** Current positive `CONTAINS` members (spec §11.2). */
|
|
61
|
+
readonly members: number;
|
|
62
|
+
};
|
|
63
|
+
export declare const topics: (store: Store, options?: Pick<Options, "maxSensitivity">) => Topic[];
|
|
64
|
+
/** A §20.2 section capped for the page, with the uncapped count. */
|
|
65
|
+
export type Capped<T> = {
|
|
66
|
+
readonly total: number;
|
|
67
|
+
readonly items: readonly T[];
|
|
68
|
+
};
|
|
69
|
+
export type Overview = {
|
|
70
|
+
readonly version: string;
|
|
71
|
+
/** The §20.2 coverage stats verbatim. */
|
|
72
|
+
readonly coverage: ReturnType<typeof check>['coverage'];
|
|
73
|
+
readonly violations: Capped<{
|
|
74
|
+
readonly entity: string;
|
|
75
|
+
readonly via: string;
|
|
76
|
+
readonly kind: string;
|
|
77
|
+
readonly name: string;
|
|
78
|
+
readonly type: string;
|
|
79
|
+
readonly cardinality: 'some' | 'one';
|
|
80
|
+
readonly unit?: string;
|
|
81
|
+
readonly actualCount: number;
|
|
82
|
+
readonly actualUnits: readonly (string | null)[];
|
|
83
|
+
}>;
|
|
84
|
+
readonly stale: Capped<{
|
|
85
|
+
readonly ageDays: number;
|
|
86
|
+
readonly row: ClaimView;
|
|
87
|
+
}>;
|
|
88
|
+
readonly review: Capped<ClaimView>;
|
|
89
|
+
readonly disagreements: Capped<{
|
|
90
|
+
readonly kind: string;
|
|
91
|
+
readonly about: string;
|
|
92
|
+
readonly entities: readonly string[];
|
|
93
|
+
readonly rows: readonly ClaimView[];
|
|
94
|
+
}>;
|
|
95
|
+
readonly topics: readonly Topic[];
|
|
96
|
+
readonly recent: readonly ClaimView[];
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* The dashboard (spec §30.2): §20.2 coverage and frontier — violations,
|
|
100
|
+
* review candidates, stale beliefs, alias disagreements — plus topics
|
|
101
|
+
* and the latest appends. Long sections are capped (the report is the
|
|
102
|
+
* uncapped surface); `total` counts what the store has.
|
|
103
|
+
*/
|
|
104
|
+
export declare const overview: (store: Store, options?: {
|
|
105
|
+
staleDays?: number;
|
|
106
|
+
recent?: number;
|
|
107
|
+
limit?: number;
|
|
108
|
+
maxSensitivity?: Sensitivity.Level;
|
|
109
|
+
}) => Overview;
|
|
110
|
+
export type Entity = {
|
|
111
|
+
readonly name: string;
|
|
112
|
+
/** The §13.6 closure — the name itself first; length 1 means no aliases. */
|
|
113
|
+
readonly aliases: readonly string[];
|
|
114
|
+
/** Objects of current positive `IS` claims — what the entity is typed as (§20.1's binding surface). */
|
|
115
|
+
readonly types: readonly string[];
|
|
116
|
+
/** Current attribute / metric / existence claims (object-less payloads). */
|
|
117
|
+
readonly facts: readonly ClaimView[];
|
|
118
|
+
/** Current relations with the entity as subject, negated included. */
|
|
119
|
+
readonly out: readonly ClaimView[];
|
|
120
|
+
/** Current relations with the entity as object — each with the declared inverse name when one exists (§13.3). */
|
|
121
|
+
readonly in: readonly (ClaimView & {
|
|
122
|
+
readonly rel?: string;
|
|
123
|
+
})[];
|
|
124
|
+
/** Topics containing the entity (spec §11.2). */
|
|
125
|
+
readonly topics: readonly string[];
|
|
126
|
+
/** All rows about the entity, ever. */
|
|
127
|
+
readonly total: number;
|
|
128
|
+
/** The newest rows about it — superseded and retracted included. */
|
|
129
|
+
readonly activity: readonly ClaimView[];
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Entity 360 (spec §30.2): everything the store currently believes about
|
|
133
|
+
* one name — object-less facts, both relation directions, topics and the
|
|
134
|
+
* alias closure — plus the raw activity feed underneath. Negated current
|
|
135
|
+
* claims are shown (they are knowledge); retracted ones only appear in
|
|
136
|
+
* the activity feed and in each fact's own history.
|
|
137
|
+
*/
|
|
138
|
+
export declare const entity: (store: Store, name: string, options?: Options & {
|
|
139
|
+
activity?: number;
|
|
140
|
+
}) => Entity;
|
|
141
|
+
export type TopicPage = {
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly members: readonly string[];
|
|
144
|
+
};
|
|
145
|
+
/** One topic's members — the forward `CONTAINS` read (spec §11.2). */
|
|
146
|
+
export declare const topic: (store: Store, name: string, options?: Options) => TopicPage;
|
|
147
|
+
export type History = {
|
|
148
|
+
readonly key: string;
|
|
149
|
+
/** The belief series, oldest first (spec §9.1) — the last row is current. */
|
|
150
|
+
readonly rows: readonly ClaimView[];
|
|
151
|
+
};
|
|
152
|
+
/** The belief-history timeline of one claim key (spec §30.2). */
|
|
153
|
+
export declare const history: (store: Store, key: string, options?: Pick<Options, "maxSensitivity">) => History;
|
|
154
|
+
/** One node of a lineage tree (spec §30.2). */
|
|
155
|
+
export type LineageNode = {
|
|
156
|
+
/** Edge role that reached this row (§13.2) — absent on the root. */
|
|
157
|
+
readonly role?: string;
|
|
158
|
+
readonly row: ClaimView;
|
|
159
|
+
/**
|
|
160
|
+
* The row already appeared elsewhere in this tree (shared premises,
|
|
161
|
+
* §24.5 support cycles) — re-stated here, children rendered once,
|
|
162
|
+
* the §28.4 convention.
|
|
163
|
+
*/
|
|
164
|
+
readonly repeat?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* The row cites (or is cited by) further rows the walk's depth cap
|
|
167
|
+
* cut off — the explanation continues below this node but is not
|
|
168
|
+
* shown; follow the row's own lineage to keep walking. Never set
|
|
169
|
+
* on a genuine leaf.
|
|
170
|
+
*/
|
|
171
|
+
readonly truncated?: boolean;
|
|
172
|
+
readonly children: readonly LineageNode[];
|
|
173
|
+
};
|
|
174
|
+
export type Lineage = {
|
|
175
|
+
readonly row: ClaimView;
|
|
176
|
+
/** What this row cites, transitively — its BECAUSE/VIA/WHEN sources (§24.3). */
|
|
177
|
+
readonly cites: readonly LineageNode[];
|
|
178
|
+
/** What cites this row, transitively — its dependents. */
|
|
179
|
+
readonly citedBy: readonly LineageNode[];
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* The lineage of one row (spec §30.2): the §13.2 edge table walked both
|
|
183
|
+
* ways. Down answers "why is this believed" — premise rows and the rule
|
|
184
|
+
* behind a §24 derivation, conditions behind a qualified claim; up
|
|
185
|
+
* answers "what depends on this". Edges form a graph; the tree re-states
|
|
186
|
+
* a repeated row without children (`repeat`), so §24.5 cycles terminate.
|
|
187
|
+
* Depth is capped: a node whose further edges the cap cut off is marked
|
|
188
|
+
* `truncated`, so an incomplete explanation never renders as complete.
|
|
189
|
+
*/
|
|
190
|
+
export declare const lineage: (store: Store, id: string, options?: Pick<Options, "maxSensitivity">) => undefined | Lineage;
|
|
191
|
+
/** Full-text search (§13.5's FTS surface), newest first, capped in the query. */
|
|
192
|
+
export declare const search: (store: Store, text: string, options?: {
|
|
193
|
+
limit?: number;
|
|
194
|
+
maxSensitivity?: Sensitivity.Level;
|
|
195
|
+
}) => ClaimView[];
|
|
196
|
+
//# sourceMappingURL=api.d.ts.map
|