@contractspec/example.versioned-knowledge-base 3.7.6 → 3.7.10

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 (42) hide show
  1. package/.turbo/turbo-build.log +45 -42
  2. package/AGENTS.md +50 -26
  3. package/CHANGELOG.md +21 -0
  4. package/README.md +80 -35
  5. package/dist/browser/entities/index.js +1 -1
  6. package/dist/browser/entities/models.js +1 -1
  7. package/dist/browser/events.js +1 -1
  8. package/dist/browser/index.js +52 -3
  9. package/dist/browser/knowledge-snapshot-publication.migration.js +50 -0
  10. package/dist/browser/operations/index.js +2 -2
  11. package/dist/browser/operations/kb.js +2 -2
  12. package/dist/contracts.test.d.ts +1 -0
  13. package/dist/entities/index.js +1 -1
  14. package/dist/entities/models.js +1 -1
  15. package/dist/events.js +1 -1
  16. package/dist/index.d.ts +3 -2
  17. package/dist/index.js +52 -3
  18. package/dist/knowledge-snapshot-publication.migration.d.ts +2 -0
  19. package/dist/knowledge-snapshot-publication.migration.js +51 -0
  20. package/dist/node/entities/index.js +1 -1
  21. package/dist/node/entities/models.js +1 -1
  22. package/dist/node/events.js +1 -1
  23. package/dist/node/index.js +52 -3
  24. package/dist/node/knowledge-snapshot-publication.migration.js +50 -0
  25. package/dist/node/operations/index.js +2 -2
  26. package/dist/node/operations/kb.js +2 -2
  27. package/dist/operations/index.js +2 -2
  28. package/dist/operations/kb.js +2 -2
  29. package/package.json +21 -7
  30. package/src/contracts.test.ts +17 -0
  31. package/src/docs/versioned-knowledge-base.docblock.ts +21 -21
  32. package/src/entities/models.ts +60 -60
  33. package/src/events.ts +77 -77
  34. package/src/example.ts +28 -28
  35. package/src/handlers/memory.handlers.test.ts +65 -65
  36. package/src/handlers/memory.handlers.ts +185 -185
  37. package/src/index.ts +3 -2
  38. package/src/knowledge-snapshot-publication.migration.ts +51 -0
  39. package/src/operations/kb.ts +161 -161
  40. package/src/versioned-knowledge-base.feature.ts +35 -35
  41. package/tsconfig.json +7 -17
  42. package/tsdown.config.js +7 -13
@@ -2,52 +2,55 @@ $ contractspec-bun-build prebuild
2
2
  $ bun run prebuild && bun run build:bundle && bun run build:types
3
3
  $ contractspec-bun-build prebuild
4
4
  $ contractspec-bun-build transpile
5
- [contractspec-bun-build] transpile target=bun root=src entries=12 noBundle=false
6
- Bundled 12 modules in 24ms
5
+ [contractspec-bun-build] transpile target=bun root=src entries=13 noBundle=false
6
+ Bundled 13 modules in 19ms
7
7
 
8
- docs/index.js 1.51 KB (entry point)
9
- ./index.js 20.31 KB (entry point)
10
- operations/index.js 9.56 KB (entry point)
11
- operations/kb.js 9.56 KB (entry point)
12
- ./versioned-knowledge-base.feature.js 1.41 KB (entry point)
13
- docs/versioned-knowledge-base.docblock.js 1.51 KB (entry point)
14
- entities/index.js 3.22 KB (entry point)
15
- entities/models.js 3.22 KB (entry point)
16
- ./events.js 3.17 KB (entry point)
17
- ./example.js 1.0 KB (entry point)
18
- handlers/index.js 3.56 KB (entry point)
19
- handlers/memory.handlers.js 3.56 KB (entry point)
8
+ docs/index.js 1.51 KB (entry point)
9
+ ./index.js 21.87 KB (entry point)
10
+ ./knowledge-snapshot-publication.migration.js 1.57 KB (entry point)
11
+ operations/index.js 9.56 KB (entry point)
12
+ operations/kb.js 9.56 KB (entry point)
13
+ ./versioned-knowledge-base.feature.js 1.41 KB (entry point)
14
+ docs/versioned-knowledge-base.docblock.js 1.51 KB (entry point)
15
+ entities/index.js 3.22 KB (entry point)
16
+ entities/models.js 3.22 KB (entry point)
17
+ ./events.js 3.17 KB (entry point)
18
+ ./example.js 1.0 KB (entry point)
19
+ handlers/index.js 3.56 KB (entry point)
20
+ handlers/memory.handlers.js 3.56 KB (entry point)
20
21
 
21
- [contractspec-bun-build] transpile target=node root=src entries=12 noBundle=false
22
- Bundled 12 modules in 43ms
22
+ [contractspec-bun-build] transpile target=node root=src entries=13 noBundle=false
23
+ Bundled 13 modules in 18ms
23
24
 
24
- docs/index.js 1.50 KB (entry point)
25
- ./index.js 20.30 KB (entry point)
26
- operations/index.js 9.55 KB (entry point)
27
- operations/kb.js 9.55 KB (entry point)
28
- ./versioned-knowledge-base.feature.js 1.40 KB (entry point)
29
- docs/versioned-knowledge-base.docblock.js 1.50 KB (entry point)
30
- entities/index.js 3.22 KB (entry point)
31
- entities/models.js 3.22 KB (entry point)
32
- ./events.js 3.16 KB (entry point)
33
- ./example.js 1.0 KB (entry point)
34
- handlers/index.js 3.55 KB (entry point)
35
- handlers/memory.handlers.js 3.55 KB (entry point)
25
+ docs/index.js 1.50 KB (entry point)
26
+ ./index.js 21.85 KB (entry point)
27
+ ./knowledge-snapshot-publication.migration.js 1.56 KB (entry point)
28
+ operations/index.js 9.55 KB (entry point)
29
+ operations/kb.js 9.55 KB (entry point)
30
+ ./versioned-knowledge-base.feature.js 1.40 KB (entry point)
31
+ docs/versioned-knowledge-base.docblock.js 1.50 KB (entry point)
32
+ entities/index.js 3.22 KB (entry point)
33
+ entities/models.js 3.22 KB (entry point)
34
+ ./events.js 3.16 KB (entry point)
35
+ ./example.js 1.0 KB (entry point)
36
+ handlers/index.js 3.55 KB (entry point)
37
+ handlers/memory.handlers.js 3.55 KB (entry point)
36
38
 
37
- [contractspec-bun-build] transpile target=browser root=src entries=12 noBundle=false
38
- Bundled 12 modules in 26ms
39
+ [contractspec-bun-build] transpile target=browser root=src entries=13 noBundle=false
40
+ Bundled 13 modules in 33ms
39
41
 
40
- docs/index.js 1.50 KB (entry point)
41
- ./index.js 20.30 KB (entry point)
42
- operations/index.js 9.55 KB (entry point)
43
- operations/kb.js 9.55 KB (entry point)
44
- ./versioned-knowledge-base.feature.js 1.40 KB (entry point)
45
- docs/versioned-knowledge-base.docblock.js 1.50 KB (entry point)
46
- entities/index.js 3.22 KB (entry point)
47
- entities/models.js 3.22 KB (entry point)
48
- ./events.js 3.16 KB (entry point)
49
- ./example.js 1.0 KB (entry point)
50
- handlers/index.js 3.55 KB (entry point)
51
- handlers/memory.handlers.js 3.55 KB (entry point)
42
+ docs/index.js 1.50 KB (entry point)
43
+ ./index.js 21.85 KB (entry point)
44
+ ./knowledge-snapshot-publication.migration.js 1.56 KB (entry point)
45
+ operations/index.js 9.55 KB (entry point)
46
+ operations/kb.js 9.55 KB (entry point)
47
+ ./versioned-knowledge-base.feature.js 1.40 KB (entry point)
48
+ docs/versioned-knowledge-base.docblock.js 1.50 KB (entry point)
49
+ entities/index.js 3.22 KB (entry point)
50
+ entities/models.js 3.22 KB (entry point)
51
+ ./events.js 3.16 KB (entry point)
52
+ ./example.js 1.0 KB (entry point)
53
+ handlers/index.js 3.55 KB (entry point)
54
+ handlers/memory.handlers.js 3.55 KB (entry point)
52
55
 
53
56
  $ contractspec-bun-build types
package/AGENTS.md CHANGED
@@ -1,35 +1,59 @@
1
- # AI Agent Guide -- `@contractspec/example.versioned-knowledge-base`
1
+ # AI Agent Guide `@contractspec/example.versioned-knowledge-base`
2
2
 
3
3
  Scope: `packages/examples/versioned-knowledge-base/*`
4
4
 
5
- Curated, versioned knowledge base with immutable sources, rule versions, and published snapshots.
5
+ Example: curated, versioned knowledge base with immutable sources, rule versions, and published snapshots.
6
6
 
7
7
  ## Quick Context
8
8
 
9
- - **Layer**: example
10
- - **Related Packages**: `lib.contracts-spec`, `lib.schema`
11
-
12
- ## What This Demonstrates
13
-
14
- - Immutable source and versioned rule management
15
- - Snapshot publishing pattern
16
- - Entity models for KB domain
17
- - Memory-based handler implementation
18
- - Feature definition and event-driven architecture
19
-
20
- ## Public Exports
21
-
22
- - `.` -- root barrel
23
- - `./entities` -- models
24
- - `./operations` -- KB operations
25
- - `./handlers` -- memory handlers
26
- - `./events` -- KB lifecycle events
27
- - `./versioned-knowledge-base.feature` -- feature definition
28
- - `./docs`, `./example`
9
+ - Layer: `example`.
10
+ - Package visibility: published package.
11
+ - Primary consumers are example explorers, template authors, and documentation readers.
12
+ - Related packages: `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
13
+
14
+ ## Architecture
15
+
16
+ - `src/docs/` contains docblocks and documentation-facing exports.
17
+ - `src/entities/` contains domain entities and value objects.
18
+ - `src/events.ts` is package-level event definitions.
19
+ - `src/example.ts` is the runnable example entrypoint.
20
+ - `src/handlers/` contains handlers or demo adapters wired to contract surfaces.
21
+ - `src/index.ts` is the root public barrel and package entrypoint.
22
+ - `src/operations` is part of the package's public or composition surface.
23
+
24
+ ## Public Surface
25
+
26
+ - Export `.` resolves through `./src/index.ts`.
27
+ - Export `./docs` resolves through `./src/docs/index.ts`.
28
+ - Export `./docs/versioned-knowledge-base.docblock` resolves through `./src/docs/versioned-knowledge-base.docblock.ts`.
29
+ - Export `./entities` resolves through `./src/entities/index.ts`.
30
+ - Export `./entities/models` resolves through `./src/entities/models.ts`.
31
+ - Export `./events` resolves through `./src/events.ts`.
32
+ - Export `./example` resolves through `./src/example.ts`.
33
+ - Export `./handlers` resolves through `./src/handlers/index.ts`.
34
+ - Export `./handlers/memory.handlers` resolves through `./src/handlers/memory.handlers.ts`.
35
+ - Export `./operations` resolves through `./src/operations/index.ts`.
36
+ - The package publishes 12 total export subpaths; keep docs aligned with `package.json`.
37
+
38
+ ## Guardrails
39
+
40
+ - Keep the example package demonstrative, buildable, and aligned with the exported feature surface.
41
+ - Do not add hidden production assumptions that are not actually implemented in the example.
42
+ - Changes here can affect downstream packages such as `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
43
+ - Changes here can affect downstream packages such as `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
29
44
 
30
45
  ## Local Commands
31
46
 
32
- - Build: `bun run build`
33
- - Dev: `bun run dev`
34
- - Test: `bun test`
35
- - Typecheck: `bun run typecheck`
47
+ - `bun run dev` — contractspec-bun-build dev
48
+ - `bun run build`bun run prebuild && bun run build:bundle && bun run build:types
49
+ - `bun run test`bun test
50
+ - `bun run lint` — bun lint:fix
51
+ - `bun run lint:check` — biome check .
52
+ - `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
53
+ - `bun run typecheck` — tsc --noEmit
54
+ - `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
55
+ - `bun run publish:pkg:canary` — bun publish:pkg --tag canary
56
+ - `bun run clean` — rimraf dist .turbo
57
+ - `bun run build:bundle` — contractspec-bun-build transpile
58
+ - `bun run build:types` — contractspec-bun-build types
59
+ - `bun run prebuild` — contractspec-bun-build prebuild
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @contractspec/example.versioned-knowledge-base
2
2
 
3
+ ## 3.7.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 1a44cb6: feat: improve examples to increase coverage of Contracts type
8
+ - Updated dependencies [1a44cb6]
9
+ - @contractspec/lib.contracts-spec@4.1.2
10
+ - @contractspec/lib.schema@3.7.8
11
+
12
+ ## 3.7.9
13
+
14
+ ### Patch Changes
15
+
16
+ - fix: release
17
+ - Updated dependencies
18
+ - @contractspec/lib.contracts-spec@4.1.1
19
+ - @contractspec/lib.schema@3.7.7
20
+
3
21
  ## 3.7.6
4
22
 
5
23
  ### Patch Changes
@@ -704,14 +722,17 @@
704
722
  feat: Contract layers support (features, examples, app-configs)
705
723
 
706
724
  ### New CLI Commands
725
+
707
726
  - `contractspec list layers` - List all contract layers with filtering
708
727
 
709
728
  ### Enhanced Commands
729
+
710
730
  - `contractspec ci` - New `layers` check category validates features/examples/config
711
731
  - `contractspec doctor` - New `layers` health checks
712
732
  - `contractspec integrity` - Now shows layer statistics
713
733
 
714
734
  ### New APIs
735
+
715
736
  - `discoverLayers()` - Scan workspace for all layer files
716
737
  - `scanExampleSource()` - Parse ExampleSpec from source code
717
738
  - `isExampleFile()` - Check if file is an example spec
package/README.md CHANGED
@@ -1,35 +1,80 @@
1
- # `@contractspec/example.versioned-knowledge-base`
2
-
3
- Website: https://contractspec.io/
4
-
5
-
6
- Spec-first example demonstrating a **curated, versioned knowledge base**:
7
-
8
- - Raw **source documents** are immutable and referenced by hash.
9
- - Curated **rules** are versioned, reviewable, and must cite sources.
10
- - Published **KB snapshots** contain only **approved** rule versions.
11
- - Assistant answers reference a **snapshot id** for traceability.
12
-
13
- ## Contracts
14
-
15
- - `kb.ingestSource(docMeta, fileRef) -> SourceDocument`
16
- - `kb.upsertRuleVersion(ruleId, content, sourceRefs) -> RuleVersion (draft)`
17
- - `kb.approveRuleVersion(ruleVersionId, approver) -> RuleVersion (approved)`
18
- - `kb.publishSnapshot(jurisdiction, asOfDate) -> KBSnapshot`
19
- - `kb.search(snapshotId, query) -> results (ruleVersionIds + citations)`
20
-
21
- ## Running tests
22
-
23
- ```bash
24
- bun test
25
- ```
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
1
+ # @contractspec/example.versioned-knowledge-base
2
+
3
+ Website: https://contractspec.io
4
+
5
+ **Example: curated, versioned knowledge base with immutable sources, rule versions, and published snapshots.**
6
+
7
+ ## What This Demonstrates
8
+
9
+ - Immutable source and versioned rule management.
10
+ - Snapshot publishing pattern.
11
+ - Canonical `migration` export via `KnowledgeSnapshotPublicationMigration`.
12
+ - Entity models for KB domain.
13
+ - Memory-based handler implementation.
14
+ - Feature definition and event-driven architecture.
15
+ - `src/docs/` contains docblocks and documentation-facing exports.
16
+
17
+ ## Running Locally
18
+
19
+ From `packages/examples/versioned-knowledge-base`:
20
+ - `bun run dev`
21
+ - `bun run build`
22
+ - `bun run test`
23
+ - `bun run typecheck`
24
+
25
+ ## Usage
26
+
27
+ Use `@contractspec/example.versioned-knowledge-base` as a reference implementation, or import its exported surfaces into a workspace that composes ContractSpec examples and bundles.
28
+
29
+ ## Architecture
30
+
31
+ - `src/docs/` contains docblocks and documentation-facing exports.
32
+ - `src/entities/` contains domain entities and value objects.
33
+ - `src/events.ts` is package-level event definitions.
34
+ - `src/example.ts` is the runnable example entrypoint.
35
+ - `src/handlers/` contains handlers or demo adapters wired to contract surfaces.
36
+ - `src/index.ts` is the root public barrel and package entrypoint.
37
+ - `src/knowledge-snapshot-publication.migration.ts` defines the exported migration spec.
38
+ - `src/operations` is part of the package's public or composition surface.
39
+
40
+ ## Public Entry Points
41
+
42
+ - Export `.` resolves through `./src/index.ts`.
43
+ - Export `./docs` resolves through `./src/docs/index.ts`.
44
+ - Export `./docs/versioned-knowledge-base.docblock` resolves through `./src/docs/versioned-knowledge-base.docblock.ts`.
45
+ - Export `./entities` resolves through `./src/entities/index.ts`.
46
+ - Export `./entities/models` resolves through `./src/entities/models.ts`.
47
+ - Export `./events` resolves through `./src/events.ts`.
48
+ - Export `./example` resolves through `./src/example.ts`.
49
+ - Export `./handlers` resolves through `./src/handlers/index.ts`.
50
+ - Export `./handlers/memory.handlers` resolves through `./src/handlers/memory.handlers.ts`.
51
+ - Export `./knowledge-snapshot-publication.migration` resolves through `./src/knowledge-snapshot-publication.migration.ts`.
52
+ - Export `./operations` resolves through `./src/operations/index.ts`.
53
+ - Export `./operations/kb` resolves through `./src/operations/kb.ts`.
54
+ - Export `./versioned-knowledge-base.feature` resolves through `./src/versioned-knowledge-base.feature.ts`.
55
+ - The package publishes 12 total export subpaths; keep docs aligned with `package.json`.
56
+
57
+ ## Local Commands
58
+
59
+ - `bun run dev` — contractspec-bun-build dev
60
+ - `bun run build` — bun run prebuild && bun run build:bundle && bun run build:types
61
+ - `bun run test` — bun test
62
+ - `bun run lint` — bun lint:fix
63
+ - `bun run lint:check` — biome check .
64
+ - `bun run lint:fix` — biome check --write --unsafe --only=nursery/useSortedClasses . && biome check --write .
65
+ - `bun run typecheck` — tsc --noEmit
66
+ - `bun run publish:pkg` — bun publish --tolerate-republish --ignore-scripts --verbose
67
+ - `bun run publish:pkg:canary` — bun publish:pkg --tag canary
68
+ - `bun run clean` — rimraf dist .turbo
69
+ - `bun run build:bundle` — contractspec-bun-build transpile
70
+ - `bun run build:types` — contractspec-bun-build types
71
+ - `bun run prebuild` — contractspec-bun-build prebuild
72
+
73
+ ## Recent Updates
74
+
75
+ - Replace eslint+prettier by biomejs to optimize speed.
76
+ - Missing contract layers.
77
+
78
+ ## Notes
79
+
80
+ - Works alongside `@contractspec/lib.contracts-spec`, `@contractspec/lib.schema`, `@contractspec/tool.bun`, `@contractspec/tool.typescript`.
@@ -1,5 +1,5 @@
1
1
  // src/entities/models.ts
2
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
2
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
3
  var SourceDocumentModel = defineSchemaModel({
4
4
  name: "SourceDocument",
5
5
  description: "Immutable raw source document metadata referencing a stored file.",
@@ -1,5 +1,5 @@
1
1
  // src/entities/models.ts
2
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
2
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
3
  var SourceDocumentModel = defineSchemaModel({
4
4
  name: "SourceDocument",
5
5
  description: "Immutable raw source document metadata referencing a stored file.",
@@ -1,6 +1,6 @@
1
1
  // src/events.ts
2
2
  import { defineEvent } from "@contractspec/lib.contracts-spec";
3
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
3
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
4
4
  var KbSourceIngestedPayload = defineSchemaModel({
5
5
  name: "KbSourceIngestedPayload",
6
6
  description: "Emitted when a source document is ingested.",
@@ -43,7 +43,7 @@ var docBlocks = [
43
43
  ];
44
44
  registerDocBlocks(docBlocks);
45
45
  // src/entities/models.ts
46
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
46
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
47
47
  var SourceDocumentModel = defineSchemaModel({
48
48
  name: "SourceDocument",
49
49
  description: "Immutable raw source document metadata referencing a stored file.",
@@ -111,7 +111,7 @@ var KBSnapshotModel = defineSchemaModel({
111
111
  });
112
112
  // src/events.ts
113
113
  import { defineEvent } from "@contractspec/lib.contracts-spec";
114
- import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
114
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
115
115
  var KbSourceIngestedPayload = defineSchemaModel2({
116
116
  name: "KbSourceIngestedPayload",
117
117
  description: "Emitted when a source document is ingested.",
@@ -349,9 +349,57 @@ function createMemoryKbHandlers(store) {
349
349
  search
350
350
  };
351
351
  }
352
+ // src/knowledge-snapshot-publication.migration.ts
353
+ import {
354
+ OwnersEnum,
355
+ StabilityEnum,
356
+ TagsEnum
357
+ } from "@contractspec/lib.contracts-spec/ownership";
358
+ var KnowledgeSnapshotPublicationMigration = {
359
+ meta: {
360
+ key: "versioned-knowledge-base.migration.snapshot-publication",
361
+ version: "1.0.0",
362
+ title: "Knowledge Snapshot Publication Migration",
363
+ description: "Adds publication audit fields and validation checks for published knowledge snapshots.",
364
+ domain: "knowledge",
365
+ owners: [OwnersEnum.PlatformContent],
366
+ tags: ["knowledge", "migration", "snapshots", TagsEnum.Hygiene],
367
+ stability: StabilityEnum.Experimental
368
+ },
369
+ dependencies: ["versioned-knowledge-base.migration.bootstrap"],
370
+ plan: {
371
+ up: [
372
+ {
373
+ kind: "schema",
374
+ description: "Create the published snapshot audit table.",
375
+ sql: `
376
+ CREATE TABLE kb_snapshot_publications (
377
+ snapshot_id TEXT PRIMARY KEY,
378
+ published_by TEXT NOT NULL,
379
+ published_at TIMESTAMPTZ NOT NULL,
380
+ source_count INTEGER NOT NULL,
381
+ rule_version_count INTEGER NOT NULL
382
+ );`
383
+ },
384
+ {
385
+ kind: "validation",
386
+ description: "Ensure snapshots have at least one approved rule version.",
387
+ assertion: "SELECT COUNT(*) = 0 FROM kb_snapshots WHERE array_length(included_rule_version_ids, 1) = 0"
388
+ }
389
+ ],
390
+ down: [
391
+ {
392
+ kind: "schema",
393
+ description: "Remove the snapshot publication audit table.",
394
+ sql: "DROP TABLE IF EXISTS kb_snapshot_publications;"
395
+ }
396
+ ]
397
+ }
398
+ };
399
+
352
400
  // src/operations/kb.ts
353
401
  import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
354
- import { ScalarTypeEnum as ScalarTypeEnum3, defineSchemaModel as defineSchemaModel3 } from "@contractspec/lib.schema";
402
+ import { defineSchemaModel as defineSchemaModel3, ScalarTypeEnum as ScalarTypeEnum3 } from "@contractspec/lib.schema";
355
403
  var IngestSourceInput = defineSchemaModel3({
356
404
  name: "KbIngestSourceInput",
357
405
  description: "Ingest immutable source metadata referencing a stored file.",
@@ -578,6 +626,7 @@ export {
578
626
  SourceDocumentModel,
579
627
  RuleVersionModel,
580
628
  RuleModel,
629
+ KnowledgeSnapshotPublicationMigration,
581
630
  KbUpsertRuleVersionContract,
582
631
  KbSourceIngestedEvent,
583
632
  KbSnapshotPublishedEvent,
@@ -0,0 +1,50 @@
1
+ // src/knowledge-snapshot-publication.migration.ts
2
+ import {
3
+ OwnersEnum,
4
+ StabilityEnum,
5
+ TagsEnum
6
+ } from "@contractspec/lib.contracts-spec/ownership";
7
+ var KnowledgeSnapshotPublicationMigration = {
8
+ meta: {
9
+ key: "versioned-knowledge-base.migration.snapshot-publication",
10
+ version: "1.0.0",
11
+ title: "Knowledge Snapshot Publication Migration",
12
+ description: "Adds publication audit fields and validation checks for published knowledge snapshots.",
13
+ domain: "knowledge",
14
+ owners: [OwnersEnum.PlatformContent],
15
+ tags: ["knowledge", "migration", "snapshots", TagsEnum.Hygiene],
16
+ stability: StabilityEnum.Experimental
17
+ },
18
+ dependencies: ["versioned-knowledge-base.migration.bootstrap"],
19
+ plan: {
20
+ up: [
21
+ {
22
+ kind: "schema",
23
+ description: "Create the published snapshot audit table.",
24
+ sql: `
25
+ CREATE TABLE kb_snapshot_publications (
26
+ snapshot_id TEXT PRIMARY KEY,
27
+ published_by TEXT NOT NULL,
28
+ published_at TIMESTAMPTZ NOT NULL,
29
+ source_count INTEGER NOT NULL,
30
+ rule_version_count INTEGER NOT NULL
31
+ );`
32
+ },
33
+ {
34
+ kind: "validation",
35
+ description: "Ensure snapshots have at least one approved rule version.",
36
+ assertion: "SELECT COUNT(*) = 0 FROM kb_snapshots WHERE array_length(included_rule_version_ids, 1) = 0"
37
+ }
38
+ ],
39
+ down: [
40
+ {
41
+ kind: "schema",
42
+ description: "Remove the snapshot publication audit table.",
43
+ sql: "DROP TABLE IF EXISTS kb_snapshot_publications;"
44
+ }
45
+ ]
46
+ }
47
+ };
48
+ export {
49
+ KnowledgeSnapshotPublicationMigration
50
+ };
@@ -1,5 +1,5 @@
1
1
  // src/entities/models.ts
2
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
2
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
3
  var SourceDocumentModel = defineSchemaModel({
4
4
  name: "SourceDocument",
5
5
  description: "Immutable raw source document metadata referencing a stored file.",
@@ -68,7 +68,7 @@ var KBSnapshotModel = defineSchemaModel({
68
68
 
69
69
  // src/operations/kb.ts
70
70
  import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
71
- import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
71
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
72
72
  var IngestSourceInput = defineSchemaModel2({
73
73
  name: "KbIngestSourceInput",
74
74
  description: "Ingest immutable source metadata referencing a stored file.",
@@ -1,5 +1,5 @@
1
1
  // src/entities/models.ts
2
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
2
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
3
3
  var SourceDocumentModel = defineSchemaModel({
4
4
  name: "SourceDocument",
5
5
  description: "Immutable raw source document metadata referencing a stored file.",
@@ -68,7 +68,7 @@ var KBSnapshotModel = defineSchemaModel({
68
68
 
69
69
  // src/operations/kb.ts
70
70
  import { defineCommand, defineQuery } from "@contractspec/lib.contracts-spec";
71
- import { ScalarTypeEnum as ScalarTypeEnum2, defineSchemaModel as defineSchemaModel2 } from "@contractspec/lib.schema";
71
+ import { defineSchemaModel as defineSchemaModel2, ScalarTypeEnum as ScalarTypeEnum2 } from "@contractspec/lib.schema";
72
72
  var IngestSourceInput = defineSchemaModel2({
73
73
  name: "KbIngestSourceInput",
74
74
  description: "Ingest immutable source metadata referencing a stored file.",
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,6 @@
1
1
  // @bun
2
2
  // src/entities/models.ts
3
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
3
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
4
4
  var SourceDocumentModel = defineSchemaModel({
5
5
  name: "SourceDocument",
6
6
  description: "Immutable raw source document metadata referencing a stored file.",
@@ -1,6 +1,6 @@
1
1
  // @bun
2
2
  // src/entities/models.ts
3
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
3
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
4
4
  var SourceDocumentModel = defineSchemaModel({
5
5
  name: "SourceDocument",
6
6
  description: "Immutable raw source document metadata referencing a stored file.",
package/dist/events.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  // src/events.ts
3
3
  import { defineEvent } from "@contractspec/lib.contracts-spec";
4
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
4
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
5
5
  var KbSourceIngestedPayload = defineSchemaModel({
6
6
  name: "KbSourceIngestedPayload",
7
7
  description: "Emitted when a source document is ingested.",
package/dist/index.d.ts CHANGED
@@ -4,9 +4,10 @@
4
4
  * Curated KB with immutable sources, reviewable rule versions, and published snapshots.
5
5
  */
6
6
  export * from './entities';
7
- export * from './operations';
8
7
  export * from './events';
8
+ export { default as example } from './example';
9
9
  export * from './handlers';
10
+ export * from './knowledge-snapshot-publication.migration';
11
+ export * from './operations';
10
12
  export * from './versioned-knowledge-base.feature';
11
- export { default as example } from './example';
12
13
  import './docs';