@gnolith/taproot 0.1.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/COMPATIBILITY.md +42 -0
  3. package/LICENSE +21 -0
  4. package/README.md +128 -0
  5. package/SECURITY.md +19 -0
  6. package/SUPPORT.md +11 -0
  7. package/dist/canonical.d.ts +16 -0
  8. package/dist/canonical.d.ts.map +1 -0
  9. package/dist/canonical.js +519 -0
  10. package/dist/canonical.js.map +1 -0
  11. package/dist/errors.d.ts +35 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +42 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/index.d.ts +57 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +53 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/iri.d.ts +3 -0
  20. package/dist/iri.d.ts.map +1 -0
  21. package/dist/iri.js +8 -0
  22. package/dist/iri.js.map +1 -0
  23. package/dist/rdf.d.ts +6 -0
  24. package/dist/rdf.d.ts.map +1 -0
  25. package/dist/rdf.js +292 -0
  26. package/dist/rdf.js.map +1 -0
  27. package/dist/repository.d.ts +94 -0
  28. package/dist/repository.d.ts.map +1 -0
  29. package/dist/repository.js +1499 -0
  30. package/dist/repository.js.map +1 -0
  31. package/dist/schema.d.ts +19 -0
  32. package/dist/schema.d.ts.map +1 -0
  33. package/dist/schema.js +390 -0
  34. package/dist/schema.js.map +1 -0
  35. package/dist/types.d.ts +299 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +21 -0
  38. package/dist/types.js.map +1 -0
  39. package/docs/api.md +47 -0
  40. package/docs/architecture.md +30 -0
  41. package/docs/completion-audit.md +31 -0
  42. package/docs/operations.md +47 -0
  43. package/docs/product-scope.md +20 -0
  44. package/docs/release-policy.md +16 -0
  45. package/docs/testing.md +21 -0
  46. package/docs/threat-model.md +40 -0
  47. package/examples/codex-site/.openai/hosting.json +3 -0
  48. package/examples/codex-site/README.md +13 -0
  49. package/examples/codex-site/demo.ts +152 -0
  50. package/migrations/0001_taproot.sql +64 -0
  51. package/migrations/0002_audit_operations.sql +48 -0
  52. package/package.json +89 -0
@@ -0,0 +1,299 @@
1
+ import type * as RDF from '@rdfjs/types';
2
+ export declare const ENTITY_DATATYPES: readonly ["wikibase-item", "wikibase-property", "wikibase-lexeme", "wikibase-form", "wikibase-sense", "entity-schema", "string", "external-id", "url", "commonsMedia", "monolingualtext", "time", "quantity", "globe-coordinate", "math", "musical-notation", "geo-shape", "tabular-data"];
3
+ export type EntityDatatype = (typeof ENTITY_DATATYPES)[number];
4
+ export type EntityId = `Q${number}` | `P${number}`;
5
+ export type ReferencedEntityId = EntityId | `L${number}` | `L${number}-F${number}` | `L${number}-S${number}` | `E${number}`;
6
+ export type PropertyId = `P${number}`;
7
+ export type EntityType = 'item' | 'property';
8
+ export type Rank = 'preferred' | 'normal' | 'deprecated';
9
+ export type SnakType = 'value' | 'somevalue' | 'novalue';
10
+ export interface LanguageValue {
11
+ language: string;
12
+ value: string;
13
+ }
14
+ export type LanguageMap = Record<string, LanguageValue>;
15
+ export type AliasMap = Record<string, LanguageValue[]>;
16
+ export interface EntityIdValue {
17
+ 'entity-type': 'item' | 'property' | 'lexeme' | 'form' | 'sense' | 'entity-schema';
18
+ 'numeric-id'?: number;
19
+ id: ReferencedEntityId;
20
+ }
21
+ export interface MonolingualTextValue {
22
+ language: string;
23
+ text: string;
24
+ }
25
+ export interface TimeValue {
26
+ time: string;
27
+ timezone: number;
28
+ before: number;
29
+ after: number;
30
+ precision: number;
31
+ calendarmodel: string;
32
+ }
33
+ export interface QuantityValue {
34
+ amount: string;
35
+ unit: string;
36
+ lowerBound?: string;
37
+ upperBound?: string;
38
+ }
39
+ export interface GlobeCoordinateValue {
40
+ latitude: number;
41
+ longitude: number;
42
+ altitude: number | null;
43
+ precision: number | null;
44
+ globe: string;
45
+ }
46
+ export type DataValueValue = string | EntityIdValue | MonolingualTextValue | TimeValue | QuantityValue | GlobeCoordinateValue;
47
+ export interface DataValue {
48
+ value: DataValueValue;
49
+ type: string;
50
+ }
51
+ export interface Snak {
52
+ snaktype: SnakType;
53
+ property: PropertyId;
54
+ hash?: string;
55
+ datatype: EntityDatatype;
56
+ datavalue?: DataValue;
57
+ }
58
+ export interface Reference {
59
+ hash: string;
60
+ snaks: Record<PropertyId, Snak[]>;
61
+ 'snaks-order': PropertyId[];
62
+ }
63
+ export interface Statement {
64
+ id: string;
65
+ type: 'statement';
66
+ rank: Rank;
67
+ mainsnak: Snak;
68
+ qualifiers: Record<PropertyId, Snak[]>;
69
+ 'qualifiers-order': PropertyId[];
70
+ references: Reference[];
71
+ }
72
+ export interface Sitelink {
73
+ site: string;
74
+ title: string;
75
+ badges: Array<`Q${number}`>;
76
+ url?: string;
77
+ }
78
+ interface EntityBase {
79
+ id: EntityId;
80
+ labels: LanguageMap;
81
+ descriptions: LanguageMap;
82
+ aliases: AliasMap;
83
+ claims: Record<PropertyId, Statement[]>;
84
+ lastrevid: number;
85
+ modified: string;
86
+ }
87
+ export interface Item extends EntityBase {
88
+ id: `Q${number}`;
89
+ type: 'item';
90
+ sitelinks: Record<string, Sitelink>;
91
+ }
92
+ export interface Property extends EntityBase {
93
+ id: `P${number}`;
94
+ type: 'property';
95
+ datatype: EntityDatatype;
96
+ }
97
+ export type WikibaseEntity = Item | Property;
98
+ export interface MappingOptions {
99
+ baseIri: string;
100
+ mappingVersion?: string;
101
+ factory?: RDF.DataFactory;
102
+ }
103
+ export type ActorKind = 'human' | 'agent' | 'import' | 'system';
104
+ export interface Attribution {
105
+ id: string;
106
+ kind: ActorKind;
107
+ name?: string;
108
+ organization?: string;
109
+ tool?: string;
110
+ url?: string;
111
+ }
112
+ export interface EditMetadata {
113
+ /** @deprecated Use attribution. Kept for source compatibility. */
114
+ actor?: string;
115
+ attribution?: Attribution;
116
+ editSummary?: string;
117
+ tags?: string[];
118
+ requestId?: string;
119
+ }
120
+ export interface ExpectedRevision extends EditMetadata {
121
+ expectedRevision: number;
122
+ }
123
+ export interface WriteResult {
124
+ entityId: EntityId;
125
+ previousRevision: number | null;
126
+ newRevision: number;
127
+ entity: WikibaseEntity;
128
+ quadPatch: {
129
+ deleted: number;
130
+ inserted: number;
131
+ };
132
+ eventId: string;
133
+ contentHash: string;
134
+ }
135
+ export interface StoredEntity {
136
+ entity: WikibaseEntity;
137
+ deletedAt: string | null;
138
+ redirectTo: EntityId | null;
139
+ }
140
+ export interface ResolvedEntity extends StoredEntity {
141
+ requestedId: EntityId;
142
+ resolvedId: EntityId;
143
+ redirects: EntityId[];
144
+ }
145
+ export interface RevisionEntry {
146
+ entityId: EntityId;
147
+ revision: number;
148
+ entity: WikibaseEntity;
149
+ actor: string | null;
150
+ attribution: Attribution | null;
151
+ editSummary: string | null;
152
+ tags: string[];
153
+ eventId: string;
154
+ contentHash: string;
155
+ parentHash: string | null;
156
+ deletedAt: string | null;
157
+ redirectTo: EntityId | null;
158
+ createdAt: string;
159
+ }
160
+ export type AuditEventType = 'create' | 'update' | 'revert' | 'delete' | 'restore' | 'redirect' | 'import' | 'repair';
161
+ export interface AuditEvent {
162
+ sequence: number;
163
+ eventId: string;
164
+ entityId: EntityId;
165
+ revision: number;
166
+ type: AuditEventType;
167
+ attribution: Attribution | null;
168
+ editSummary: string | null;
169
+ tags: string[];
170
+ requestId: string | null;
171
+ contentHash: string;
172
+ parentHash: string | null;
173
+ lifecycle: {
174
+ deletedAt: string | null;
175
+ redirectTo: EntityId | null;
176
+ };
177
+ createdAt: string;
178
+ }
179
+ export interface Page<T> {
180
+ items: T[];
181
+ cursor: string | null;
182
+ }
183
+ export interface EntityListEntry extends StoredEntity {
184
+ entityId: EntityId;
185
+ }
186
+ export interface IntegrityIssue {
187
+ code: 'current-revision-mismatch' | 'revision-json-mismatch' | 'content-hash-mismatch' | 'audit-event-missing' | 'term-projection-mismatch' | 'rdf-projection-mismatch';
188
+ message: string;
189
+ }
190
+ export interface EntityIntegrityReport {
191
+ entityId: EntityId;
192
+ revision: number;
193
+ valid: boolean;
194
+ issues: IntegrityIssue[];
195
+ }
196
+ export interface BulkImportResult {
197
+ succeeded: WriteResult[];
198
+ failed: Array<{
199
+ index: number;
200
+ entityId?: EntityId;
201
+ error: Error;
202
+ }>;
203
+ }
204
+ export interface TaprootObservation {
205
+ operation: string;
206
+ outcome: 'success' | 'error';
207
+ durationMs: number;
208
+ entityId?: EntityId;
209
+ revision?: number;
210
+ error?: unknown;
211
+ }
212
+ export type EntityCommand = {
213
+ type: 'set-label';
214
+ language: string;
215
+ value: string;
216
+ } | {
217
+ type: 'remove-label';
218
+ language: string;
219
+ } | {
220
+ type: 'set-description';
221
+ language: string;
222
+ value: string;
223
+ } | {
224
+ type: 'remove-description';
225
+ language: string;
226
+ } | {
227
+ type: 'add-alias';
228
+ language: string;
229
+ value: string;
230
+ } | {
231
+ type: 'remove-alias';
232
+ language: string;
233
+ ordinal: number;
234
+ } | {
235
+ type: 'set-sitelink';
236
+ site: string;
237
+ value: Sitelink;
238
+ } | {
239
+ type: 'remove-sitelink';
240
+ site: string;
241
+ } | {
242
+ type: 'add-statement';
243
+ statement: Statement;
244
+ } | {
245
+ type: 'replace-statement';
246
+ statementId: string;
247
+ statement: Statement;
248
+ } | {
249
+ type: 'remove-statement';
250
+ statementId: string;
251
+ } | {
252
+ type: 'set-statement-rank';
253
+ statementId: string;
254
+ rank: Rank;
255
+ } | {
256
+ type: 'add-qualifier';
257
+ statementId: string;
258
+ snak: Snak;
259
+ } | {
260
+ type: 'remove-qualifier';
261
+ statementId: string;
262
+ property: PropertyId;
263
+ ordinal: number;
264
+ } | {
265
+ type: 'add-reference';
266
+ statementId: string;
267
+ reference: Reference;
268
+ } | {
269
+ type: 'replace-reference';
270
+ statementId: string;
271
+ hash: string;
272
+ reference: Reference;
273
+ } | {
274
+ type: 'remove-reference';
275
+ statementId: string;
276
+ hash: string;
277
+ };
278
+ export type TaprootValidator = (entity: WikibaseEntity, context: {
279
+ previous: WikibaseEntity | null;
280
+ metadata: EditMetadata;
281
+ }) => void | Promise<void>;
282
+ export interface SearchResult {
283
+ entityId: EntityId;
284
+ entityType: EntityType;
285
+ language: string;
286
+ termType: 'label' | 'description' | 'alias';
287
+ value: string;
288
+ }
289
+ export interface TaprootOptions extends MappingOptions {
290
+ maxEntityBytes?: number;
291
+ maxBulkEntities?: number;
292
+ clock?: () => Date;
293
+ createId?: () => string;
294
+ validators?: TaprootValidator[];
295
+ observe?: (observation: TaprootObservation) => void | Promise<void>;
296
+ requireAttribution?: boolean;
297
+ }
298
+ export {};
299
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAC;AAEzC,eAAO,MAAM,gBAAgB,4RAmBnB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC/D,MAAM,MAAM,QAAQ,GAAG,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,CAAC;AACnD,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,IAAI,MAAM,EAAE,GACZ,IAAI,MAAM,KAAK,MAAM,EAAE,GACvB,IAAI,MAAM,KAAK,MAAM,EAAE,GACvB,IAAI,MAAM,EAAE,CAAC;AACjB,MAAM,MAAM,UAAU,GAAG,IAAI,MAAM,EAAE,CAAC;AACtC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,CAAC;AAC7C,MAAM,MAAM,IAAI,GAAG,WAAW,GAAG,QAAQ,GAAG,YAAY,CAAC;AACzD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,SAAS,CAAC;AAEzD,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,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AChC,OAAO,CAAC,EAAE,CAAC,WAAW,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
package/dist/types.js ADDED
@@ -0,0 +1,21 @@
1
+ export const ENTITY_DATATYPES = [
2
+ 'wikibase-item',
3
+ 'wikibase-property',
4
+ 'wikibase-lexeme',
5
+ 'wikibase-form',
6
+ 'wikibase-sense',
7
+ 'entity-schema',
8
+ 'string',
9
+ 'external-id',
10
+ 'url',
11
+ 'commonsMedia',
12
+ 'monolingualtext',
13
+ 'time',
14
+ 'quantity',
15
+ 'globe-coordinate',
16
+ 'math',
17
+ 'musical-notation',
18
+ 'geo-shape',
19
+ 'tabular-data',
20
+ ];
21
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,eAAe;IACf,mBAAmB;IACnB,iBAAiB;IACjB,eAAe;IACf,gBAAgB;IAChB,eAAe;IACf,QAAQ;IACR,aAAa;IACb,KAAK;IACL,cAAc;IACd,iBAAiB;IACjB,MAAM;IACN,UAAU;IACV,kBAAkB;IAClB,MAAM;IACN,kBAAkB;IAClB,WAAW;IACX,cAAc;CACN,CAAC"}
package/docs/api.md ADDED
@@ -0,0 +1,47 @@
1
+ # API guide
2
+
3
+ `TaprootRepository` is the primary API; equivalent top-level functions are
4
+ exported for request-scoped use.
5
+
6
+ ## Reads
7
+
8
+ - `getEntity`, `resolveEntity`, `getEntityRevision`
9
+ - `listEntities`, `listEntityRevisionsPage`, `searchEntitiesPage`
10
+ - `getAuditEvent`, `listAuditEvents`, `verifyAuditChain`
11
+ - `inspectEntityIntegrity`, `inspectTaprootIntegrity`
12
+
13
+ Page APIs return `{ items, cursor }`. Pass the opaque cursor back unchanged.
14
+ Entity and revision cursors are keyset cursors. Search cursors are bounded
15
+ offset cursors and should be consumed promptly when the search index is being
16
+ edited concurrently.
17
+
18
+ ## Writes
19
+
20
+ - `createItem`, `createProperty`, `importEntity`, `replaceEntity`, `revertEntity`
21
+ - `applyCommands` for multiple domain changes in one revision
22
+ - individual label, description, alias, sitelink, statement, qualifier,
23
+ reference, and rank methods
24
+ - `softDeleteEntity`, `restoreEntity`, `redirectEntity`
25
+ - `repairEntityProjection`
26
+
27
+ All updates require `expectedRevision`. Redirects must target a live entity of
28
+ the same type and cannot create a cycle. `resolveEntity` follows a bounded
29
+ chain and reports every hop.
30
+
31
+ `createStatement` and `createReference` build correctly shaped values. Import
32
+ accepts trusted explicit Q/P IDs and advances counters. `importEntities`
33
+ supports create-only or upsert mode and reports per-entity failures.
34
+
35
+ ## Edit context
36
+
37
+ An edit can contain structured `attribution`, `editSummary`, sorted/deduplicated
38
+ `tags`, and a `requestId`. Attribution kinds are `human`, `agent`, `import`, or
39
+ `system`. The legacy `actor` string remains accepted and is normalized to a
40
+ human attribution record.
41
+
42
+ Set `requireAttribution`, `validators`, `clock`, `createId`, `observe`, entity
43
+ size, and bulk limits in `TaprootOptions`. Validators run before the D1 batch.
44
+ Observers cannot fail or roll back committed writes.
45
+
46
+ All domain failures extend `TaprootError` and expose a stable uppercase
47
+ snake-case `code` in addition to their exported class for `instanceof` checks.
@@ -0,0 +1,30 @@
1
+ # Architecture
2
+
3
+ Taproot is the knowledge-domain layer between a Codex Site and Diamond. The
4
+ canonical source of truth is one Wikibase-shaped JSON document per Item or
5
+ Property. Revisions are append-only snapshots. Search terms and RDF are
6
+ rebuildable projections and never become a competing statement model.
7
+
8
+ Every write performs the same transaction:
9
+
10
+ 1. Load the current entity and enforce its expected revision.
11
+ 2. Apply commands, validate the whole document, referenced Property
12
+ datatypes, host validators, size limits, attribution, and lifecycle rules.
13
+ 3. Serialize canonical JSON and compute its SHA-256 content/parent hashes.
14
+ 4. Build the complete RDF closure and search-term projection.
15
+ 5. Commit the current row, immutable revision, audit event, terms, RDF patch,
16
+ and RDF ownership rows in one D1 batch.
17
+
18
+ RDF ownership is required because Wikibase full-value and reference nodes can
19
+ be shared. It allows an entity edit to remove an old quad only when no other
20
+ entity owns it. The table contains encoded quad keys only and is fully
21
+ rebuildable from canonical JSON.
22
+
23
+ The schema has no statement, qualifier, or reference tables. Those structures
24
+ live solely inside canonical entity JSON. Diamond's `rdf_quads` is the query
25
+ projection; `taproot_terms` is the search projection.
26
+
27
+ Taproot owns Items, Properties, their values and lifecycle, revisions,
28
+ attribution/audit history, deterministic projections, migration, integrity,
29
+ and repair. It deliberately does not own authentication, authorization, MCP,
30
+ agents, UI, wiki article bodies, media storage, or arbitrary SPARQL Update.
@@ -0,0 +1,31 @@
1
+ # Completion audit
2
+
3
+ This audit covers the complete Taproot package boundary defined in
4
+ `product-scope.md`, not merely CRUD.
5
+
6
+ | Capability | Evidence |
7
+ | -------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
8
+ | Canonical model | Item/Property types, strict validator, canonical serializer, statement/reference builders, JSON fixture |
9
+ | Complete edits | Typed individual commands, `applyCommands`, optimistic revisions, all term/sitelink/statement/qualifier/reference/rank paths |
10
+ | Lifecycle | Soft delete, restore, same-type acyclic redirects, bounded resolution, lifecycle snapshots in every revision/event |
11
+ | Attribution/audit | Structured actors, legacy normalization, summaries, tags, request IDs, immutable events/revisions, SHA-256 parent chains |
12
+ | D1 atomicity | One batch for current JSON, revision, audit, terms, RDF, and ownership; rollback and competing-edit Workerd tests |
13
+ | RDF/SPARQL | Wikibase paths, truthy/best rank, all snak types, full values, standard statement/provenance types, mapping v2 fixtures |
14
+ | Shared RDF safety | Per-entity quad ownership and behavioral regression covering a shared full-value node during another entity's edit |
15
+ | Search/read scale | Entity/revision/audit keyset cursors, bounded search cursor, configured page limits |
16
+ | Bulk/agent workflows | Multi-command single revision, bounded create/upsert import with indexed errors, NDJSON export, request correlation |
17
+ | Migration | Versioned SQL, programmatic v1 hash/audit backfill, resumable v1-to-v2 RDF reprojection and ownership creation |
18
+ | Integrity/repair | Schema inspection, audit-chain verification, JSON/revision/term/RDF comparison, cursor scan, audited reprojection repair |
19
+ | Extension points | Required attribution, async host validators, isolated observations, injected clock and IDs |
20
+ | Operations/release | Architecture/API/operations/scope/security/testing docs, Node 22/24 CI, packed consumer, license and release gates |
21
+
22
+ ## Reproduction
23
+
24
+ ```sh
25
+ npm ci
26
+ npm run check
27
+ ```
28
+
29
+ Diamond `0.3.2` or later supplies the registry-published composable patch API.
30
+ The packed-consumer gate installs Taproot and Diamond without repository
31
+ siblings or local paths and exercises a fresh Workerd D1 database.
@@ -0,0 +1,47 @@
1
+ # Operations
2
+
3
+ ## Initialize and migrate
4
+
5
+ Run `initializeTaproot(db)` during deployment or startup. It is idempotent and
6
+ initializes Diamond too. SQL migration users must still run the initializer
7
+ after applying `0002`: legacy revision hashes require Web Crypto and cannot be
8
+ correctly produced by SQLite alone.
9
+
10
+ The v1-to-v2 migration backfills SHA-256 content/parent chains and audit
11
+ events, migrates RDF mapping v1 to v2, creates ownership records, and uses a
12
+ durable migration marker so an interrupted reprojection resumes safely.
13
+ `inspectTaprootSchema` checks tables, required columns, indexes, triggers, and
14
+ format versions. Treat a failed inspection as a deployment failure.
15
+
16
+ ## Integrity and repair
17
+
18
+ `verifyAuditChain(id)` verifies revision continuity, every content hash and
19
+ parent link, the chain head, and corresponding audit events.
20
+ `inspectEntityIntegrity(id)` also compares current JSON, revision JSON, terms,
21
+ RDF, and ownership. `inspectTaprootIntegrity` scans by cursor.
22
+
23
+ `repairEntityProjection` atomically rebuilds terms, RDF, and ownership without
24
+ changing canonical content or inventing a new content revision. It appends a
25
+ `repair` audit event. It does not rewrite damaged immutable history; restore
26
+ such data from backup and investigate if hash verification fails.
27
+
28
+ ## Backup and restore
29
+
30
+ Back up the whole D1 database to preserve atomic boundaries. Canonical entities
31
+ can also be exported as newline-delimited JSON with `exportEntities`, but that
32
+ is a knowledge export, not a backup of attribution, revisions, deletions,
33
+ redirects, or audit history.
34
+
35
+ After database restore, run schema inspection and paginated integrity checks.
36
+ After JSON-only import, projections are generated during each import.
37
+
38
+ ## Limits and failure behavior
39
+
40
+ Writes are atomic per entity. Bulk import is deliberately not a cross-entity
41
+ transaction; retry failed entries using their result indexes. Default limits:
42
+ 1.8 MB canonical JSON, 100 bulk entities, 100 commands per revision, and 500
43
+ rows per page. Diamond separately enforces its atomic RDF payload bound.
44
+
45
+ Revision and audit rows have database triggers rejecting UPDATE and DELETE.
46
+ Projection repair is safe under shared RDF values because orphan removal checks
47
+ quad ownership inside the same D1 transaction.
@@ -0,0 +1,20 @@
1
+ # Product scope
2
+
3
+ Taproot exists so a Codex Site can own a Wikibase-style knowledge graph in D1
4
+ and query it through Diamond without operating MediaWiki or another external
5
+ knowledge service.
6
+
7
+ Version 0.1 is complete for the package's declared entity domain: Wikibase
8
+ core Items and Properties, canonical JSON interchange, statements and all
9
+ their components, supported datatypes, revision/lifecycle history,
10
+ attribution and audit, search, RDF/SPARQL projection, bulk workflows,
11
+ migration, integrity, repair, policy hooks, and operational documentation.
12
+
13
+ The following are separate products or future compatibility domains rather
14
+ than missing Taproot implementation: MCP transport, agent orchestration,
15
+ authentication/authorization, UI, wiki pages, media bytes, MediaWiki APIs,
16
+ Lexeme/Form/Sense, MediaInfo, and EntitySchema entity storage.
17
+
18
+ Adding an extension entity type changes IDs, JSON, commands, RDF, migration,
19
+ and compatibility fixtures. It must be designed and versioned as an explicit
20
+ new domain rather than accepted as unvalidated JSON.
@@ -0,0 +1,16 @@
1
+ # Release and support policy
2
+
3
+ Taproot uses Semantic Versioning. Before 1.0, minor versions may deliberately
4
+ change APIs or RDF mappings, but every such change must be documented and
5
+ migratable. Patch releases preserve the documented public API and stored model.
6
+
7
+ Releases are created only from annotated semantic-version tags whose commits
8
+ belong to `main`. The protected `release` environment accepts only `v*.*.*`
9
+ tags. GitHub Actions verifies the version and tag, runs the full quality gate,
10
+ inspects the packed artifact, publishes to npm through OIDC trusted publishing,
11
+ and attaches the tarball, SBOM, checksums, and build attestation to a GitHub
12
+ Release.
13
+
14
+ The current minor line receives fixes. Security support follows `SECURITY.md`.
15
+ Deprecations are announced in the changelog before removal whenever a safe
16
+ migration path exists.
@@ -0,0 +1,21 @@
1
+ # Testing strategy
2
+
3
+ Taproot's unit tests cover canonical Wikibase JSON validation, deterministic
4
+ serialization, and RDF mapping fixtures. Integration tests run against
5
+ Miniflare's Workerd D1 implementation and initialize Diamond and Taproot in the
6
+ same database.
7
+
8
+ The Workerd suite exercises successful edits, malformed and oversized input,
9
+ optimistic conflicts, concurrent writers, migration, immutable history,
10
+ projection repair, shared RDF values, and injected RDF failures. The injected
11
+ failure proves that canonical JSON, revisions, audit events, search terms,
12
+ ownership, and Diamond quads roll back as one D1 batch.
13
+
14
+ `test/example.test.ts` runs the documented Codex Site example and queries its
15
+ Taproot-generated graph through Diamond SPARQL. `consumer:check` packs the
16
+ package, installs the tarball into a fresh temporary project with registry
17
+ Diamond and Miniflare dependencies, initializes a new D1 database, writes an
18
+ entity, and verifies the RDF through SPARQL using only public package exports.
19
+
20
+ `npm run check` is the complete local release-quality gate. Coverage thresholds
21
+ are enforced in `vitest.config.ts`; lowering them requires an explained review.
@@ -0,0 +1,40 @@
1
+ # Threat model
2
+
3
+ ## Protected assets
4
+
5
+ Taproot protects canonical entity state, immutable revision and audit history,
6
+ optimistic-write ordering, search projections, RDF query projections, and the
7
+ association between an edit and its claimed attribution metadata.
8
+
9
+ ## Trust boundaries
10
+
11
+ The host application is trusted to authenticate and authorize callers, select
12
+ the D1 binding, supply an absolute site-owned base IRI, and protect mutation
13
+ routes. Attribution is a stored claim, not proof of identity. Diamond executes
14
+ the RDF patch prepared by Taproot and exposes read-only SPARQL querying; hosts
15
+ must not give untrusted callers an independent write path to Taproot or Diamond
16
+ tables.
17
+
18
+ ## Threats and controls
19
+
20
+ - Lost updates are blocked by expected-revision guards inside the same D1 batch
21
+ as all canonical and projected writes.
22
+ - Partial writes are blocked by D1 batch atomicity; injected Workerd failures
23
+ verify rollback across Taproot and Diamond.
24
+ - History tampering is deterred and detected by immutable-table triggers,
25
+ SHA-256 content/parent chains, schema inspection, and integrity APIs.
26
+ - Resource exhaustion is bounded by entity, command, page, bulk, redirect, and
27
+ RDF patch limits. Hosts still need request-size, authentication, and rate
28
+ limits at the network boundary.
29
+ - RDF projection confusion is constrained by strict entity validation,
30
+ deterministic mapping, site-owned namespaces, and per-entity quad ownership.
31
+ - Dependency and release compromise is reduced through locked installs, pinned
32
+ GitHub Actions, dependency review, CodeQL, secret scanning, license checks,
33
+ OIDC npm publishing, provenance, SBOMs, checksums, and attestations.
34
+
35
+ ## Out of scope
36
+
37
+ Taproot does not provide authentication, authorization, agent/MCP isolation,
38
+ network rate limiting, D1 backup custody, UI sanitization, or arbitrary SPARQL
39
+ Update. A compromised host with direct D1 access can bypass library controls;
40
+ restore from a trusted backup and verify audit chains after such an incident.
@@ -0,0 +1,3 @@
1
+ {
2
+ "framework": "nextjs"
3
+ }
@@ -0,0 +1,13 @@
1
+ # Codex Site example
2
+
3
+ Bind a Cloudflare D1 database as `DB`, apply Diamond's and Taproot's numbered
4
+ migrations, call `initializeTaproot`, and run `runTaprootDemo(env.DB)` from a
5
+ trusted setup route or test fixture.
6
+
7
+ `demo.ts` creates Properties and an Item, adds a qualified and referenced
8
+ statement, changes its rank, adds a `somevalue`, queries the truthy projection
9
+ through Diamond SPARQL, exports canonical JSON, proves that a stale edit is
10
+ rejected, and returns the attribution/audit and integrity records. A production
11
+ site should authenticate every mutation route and can enable
12
+ `requireAttribution`; Taproot deliberately does not own authentication or agent
13
+ transport.