@contractspec/example.kb-update-pipeline 0.0.0-canary-20260113162409
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/.turbo/turbo-build$colon$bundle.log +55 -0
- package/.turbo/turbo-build.log +56 -0
- package/CHANGELOG.md +342 -0
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/kb-update-pipeline.docblock.d.ts +1 -0
- package/dist/docs/kb-update-pipeline.docblock.js +31 -0
- package/dist/docs/kb-update-pipeline.docblock.js.map +1 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/entities/index.js +3 -0
- package/dist/entities/models.d.ts +61 -0
- package/dist/entities/models.d.ts.map +1 -0
- package/dist/entities/models.js +74 -0
- package/dist/entities/models.js.map +1 -0
- package/dist/events.d.ts +74 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +150 -0
- package/dist/events.js.map +1 -0
- package/dist/example.d.ts +7 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +50 -0
- package/dist/example.js.map +1 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.js +3 -0
- package/dist/handlers/memory.handlers.d.ts +68 -0
- package/dist/handlers/memory.handlers.d.ts.map +1 -0
- package/dist/handlers/memory.handlers.js +93 -0
- package/dist/handlers/memory.handlers.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +12 -0
- package/dist/kb-update-pipeline.feature.d.ts +7 -0
- package/dist/kb-update-pipeline.feature.d.ts.map +1 -0
- package/dist/kb-update-pipeline.feature.js +142 -0
- package/dist/kb-update-pipeline.feature.js.map +1 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/index.js +3 -0
- package/dist/operations/pipeline.d.ts +137 -0
- package/dist/operations/pipeline.d.ts.map +1 -0
- package/dist/operations/pipeline.js +183 -0
- package/dist/operations/pipeline.js.map +1 -0
- package/dist/presentations.d.ts +9 -0
- package/dist/presentations.d.ts.map +1 -0
- package/dist/presentations.js +71 -0
- package/dist/presentations.js.map +1 -0
- package/dist/tests/operations.test-spec.d.ts +9 -0
- package/dist/tests/operations.test-spec.d.ts.map +1 -0
- package/dist/tests/operations.test-spec.js +94 -0
- package/dist/tests/operations.test-spec.js.map +1 -0
- package/example.ts +1 -0
- package/package.json +74 -0
- package/src/docs/index.ts +1 -0
- package/src/docs/kb-update-pipeline.docblock.ts +30 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/models.ts +53 -0
- package/src/events.ts +134 -0
- package/src/example.ts +34 -0
- package/src/handlers/index.ts +1 -0
- package/src/handlers/memory.handlers.test.ts +81 -0
- package/src/handlers/memory.handlers.ts +186 -0
- package/src/index.ts +15 -0
- package/src/kb-update-pipeline.feature.ts +59 -0
- package/src/operations/index.ts +1 -0
- package/src/operations/pipeline.ts +159 -0
- package/src/presentations.ts +68 -0
- package/src/tests/operations.test-spec.ts +82 -0
- package/tsconfig.json +19 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +17 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { defineTestSpec } from "@contractspec/lib.contracts";
|
|
2
|
+
|
|
3
|
+
//#region src/tests/operations.test-spec.ts
|
|
4
|
+
const RunWatchTest = defineTestSpec({
|
|
5
|
+
meta: {
|
|
6
|
+
key: "kbPipeline.runWatch.test",
|
|
7
|
+
version: "1.0.0",
|
|
8
|
+
stability: "experimental",
|
|
9
|
+
owners: ["@example.kb-update-pipeline"],
|
|
10
|
+
description: "Test for run watch operation",
|
|
11
|
+
tags: ["test"]
|
|
12
|
+
},
|
|
13
|
+
target: {
|
|
14
|
+
type: "operation",
|
|
15
|
+
operation: {
|
|
16
|
+
key: "kbPipeline.runWatch",
|
|
17
|
+
version: "1.0.0"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
scenarios: [{
|
|
21
|
+
key: "success",
|
|
22
|
+
when: { operation: { key: "kbPipeline.runWatch" } },
|
|
23
|
+
then: [{
|
|
24
|
+
type: "expectOutput",
|
|
25
|
+
match: {}
|
|
26
|
+
}]
|
|
27
|
+
}, {
|
|
28
|
+
key: "error",
|
|
29
|
+
when: { operation: { key: "kbPipeline.runWatch" } },
|
|
30
|
+
then: [{ type: "expectError" }]
|
|
31
|
+
}]
|
|
32
|
+
});
|
|
33
|
+
const CreateReviewTaskTest = defineTestSpec({
|
|
34
|
+
meta: {
|
|
35
|
+
key: "kbPipeline.createReviewTask.test",
|
|
36
|
+
version: "1.0.0",
|
|
37
|
+
stability: "experimental",
|
|
38
|
+
owners: ["@example.kb-update-pipeline"],
|
|
39
|
+
description: "Test for creating review task",
|
|
40
|
+
tags: ["test"]
|
|
41
|
+
},
|
|
42
|
+
target: {
|
|
43
|
+
type: "operation",
|
|
44
|
+
operation: {
|
|
45
|
+
key: "kbPipeline.createReviewTask",
|
|
46
|
+
version: "1.0.0"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
scenarios: [{
|
|
50
|
+
key: "success",
|
|
51
|
+
when: { operation: { key: "kbPipeline.createReviewTask" } },
|
|
52
|
+
then: [{
|
|
53
|
+
type: "expectOutput",
|
|
54
|
+
match: {}
|
|
55
|
+
}]
|
|
56
|
+
}, {
|
|
57
|
+
key: "error",
|
|
58
|
+
when: { operation: { key: "kbPipeline.createReviewTask" } },
|
|
59
|
+
then: [{ type: "expectError" }]
|
|
60
|
+
}]
|
|
61
|
+
});
|
|
62
|
+
const SubmitDecisionTest = defineTestSpec({
|
|
63
|
+
meta: {
|
|
64
|
+
key: "kbPipeline.submitDecision.test",
|
|
65
|
+
version: "1.0.0",
|
|
66
|
+
stability: "experimental",
|
|
67
|
+
owners: ["@example.kb-update-pipeline"],
|
|
68
|
+
description: "Test for submitting decision",
|
|
69
|
+
tags: ["test"]
|
|
70
|
+
},
|
|
71
|
+
target: {
|
|
72
|
+
type: "operation",
|
|
73
|
+
operation: {
|
|
74
|
+
key: "kbPipeline.submitDecision",
|
|
75
|
+
version: "1.0.0"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
scenarios: [{
|
|
79
|
+
key: "success",
|
|
80
|
+
when: { operation: { key: "kbPipeline.submitDecision" } },
|
|
81
|
+
then: [{
|
|
82
|
+
type: "expectOutput",
|
|
83
|
+
match: {}
|
|
84
|
+
}]
|
|
85
|
+
}, {
|
|
86
|
+
key: "error",
|
|
87
|
+
when: { operation: { key: "kbPipeline.submitDecision" } },
|
|
88
|
+
then: [{ type: "expectError" }]
|
|
89
|
+
}]
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
export { CreateReviewTaskTest, RunWatchTest, SubmitDecisionTest };
|
|
94
|
+
//# sourceMappingURL=operations.test-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.test-spec.js","names":[],"sources":["../../src/tests/operations.test-spec.ts"],"sourcesContent":["import { defineTestSpec } from '@contractspec/lib.contracts';\n\nexport const RunWatchTest = defineTestSpec({\n meta: {\n key: 'kbPipeline.runWatch.test',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@example.kb-update-pipeline'],\n description: 'Test for run watch operation',\n tags: ['test'],\n },\n target: {\n type: 'operation',\n operation: { key: 'kbPipeline.runWatch', version: '1.0.0' },\n },\n scenarios: [\n {\n key: 'success',\n when: { operation: { key: 'kbPipeline.runWatch' } },\n then: [{ type: 'expectOutput', match: {} }],\n },\n {\n key: 'error',\n when: { operation: { key: 'kbPipeline.runWatch' } },\n then: [{ type: 'expectError' }],\n },\n ],\n});\n\nexport const CreateReviewTaskTest = defineTestSpec({\n meta: {\n key: 'kbPipeline.createReviewTask.test',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@example.kb-update-pipeline'],\n description: 'Test for creating review task',\n tags: ['test'],\n },\n target: {\n type: 'operation',\n operation: { key: 'kbPipeline.createReviewTask', version: '1.0.0' },\n },\n scenarios: [\n {\n key: 'success',\n when: { operation: { key: 'kbPipeline.createReviewTask' } },\n then: [{ type: 'expectOutput', match: {} }],\n },\n {\n key: 'error',\n when: { operation: { key: 'kbPipeline.createReviewTask' } },\n then: [{ type: 'expectError' }],\n },\n ],\n});\n\nexport const SubmitDecisionTest = defineTestSpec({\n meta: {\n key: 'kbPipeline.submitDecision.test',\n version: '1.0.0',\n stability: 'experimental',\n owners: ['@example.kb-update-pipeline'],\n description: 'Test for submitting decision',\n tags: ['test'],\n },\n target: {\n type: 'operation',\n operation: { key: 'kbPipeline.submitDecision', version: '1.0.0' },\n },\n scenarios: [\n {\n key: 'success',\n when: { operation: { key: 'kbPipeline.submitDecision' } },\n then: [{ type: 'expectOutput', match: {} }],\n },\n {\n key: 'error',\n when: { operation: { key: 'kbPipeline.submitDecision' } },\n then: [{ type: 'expectError' }],\n },\n ],\n});\n"],"mappings":";;;AAEA,MAAa,eAAe,eAAe;CACzC,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,8BAA8B;EACvC,aAAa;EACb,MAAM,CAAC,OAAO;EACf;CACD,QAAQ;EACN,MAAM;EACN,WAAW;GAAE,KAAK;GAAuB,SAAS;GAAS;EAC5D;CACD,WAAW,CACT;EACE,KAAK;EACL,MAAM,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE;EACnD,MAAM,CAAC;GAAE,MAAM;GAAgB,OAAO,EAAE;GAAE,CAAC;EAC5C,EACD;EACE,KAAK;EACL,MAAM,EAAE,WAAW,EAAE,KAAK,uBAAuB,EAAE;EACnD,MAAM,CAAC,EAAE,MAAM,eAAe,CAAC;EAChC,CACF;CACF,CAAC;AAEF,MAAa,uBAAuB,eAAe;CACjD,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,8BAA8B;EACvC,aAAa;EACb,MAAM,CAAC,OAAO;EACf;CACD,QAAQ;EACN,MAAM;EACN,WAAW;GAAE,KAAK;GAA+B,SAAS;GAAS;EACpE;CACD,WAAW,CACT;EACE,KAAK;EACL,MAAM,EAAE,WAAW,EAAE,KAAK,+BAA+B,EAAE;EAC3D,MAAM,CAAC;GAAE,MAAM;GAAgB,OAAO,EAAE;GAAE,CAAC;EAC5C,EACD;EACE,KAAK;EACL,MAAM,EAAE,WAAW,EAAE,KAAK,+BAA+B,EAAE;EAC3D,MAAM,CAAC,EAAE,MAAM,eAAe,CAAC;EAChC,CACF;CACF,CAAC;AAEF,MAAa,qBAAqB,eAAe;CAC/C,MAAM;EACJ,KAAK;EACL,SAAS;EACT,WAAW;EACX,QAAQ,CAAC,8BAA8B;EACvC,aAAa;EACb,MAAM,CAAC,OAAO;EACf;CACD,QAAQ;EACN,MAAM;EACN,WAAW;GAAE,KAAK;GAA6B,SAAS;GAAS;EAClE;CACD,WAAW,CACT;EACE,KAAK;EACL,MAAM,EAAE,WAAW,EAAE,KAAK,6BAA6B,EAAE;EACzD,MAAM,CAAC;GAAE,MAAM;GAAgB,OAAO,EAAE;GAAE,CAAC;EAC5C,EACD;EACE,KAAK;EACL,MAAM,EAAE,WAAW,EAAE,KAAK,6BAA6B,EAAE;EACzD,MAAM,CAAC,EAAE,MAAM,eAAe,CAAC;EAChC,CACF;CACF,CAAC"}
|
package/example.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './src/example';
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contractspec/example.kb-update-pipeline",
|
|
3
|
+
"version": "0.0.0-canary-20260113162409",
|
|
4
|
+
"description": "Example: KB update automation pipeline with HITL review and auditability.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./docs": "./dist/docs/index.js",
|
|
10
|
+
"./docs/kb-update-pipeline.docblock": "./dist/docs/kb-update-pipeline.docblock.js",
|
|
11
|
+
"./entities": "./dist/entities/index.js",
|
|
12
|
+
"./entities/models": "./dist/entities/models.js",
|
|
13
|
+
"./events": "./dist/events.js",
|
|
14
|
+
"./example": "./dist/example.js",
|
|
15
|
+
"./handlers": "./dist/handlers/index.js",
|
|
16
|
+
"./handlers/memory.handlers": "./dist/handlers/memory.handlers.js",
|
|
17
|
+
"./kb-update-pipeline.feature": "./dist/kb-update-pipeline.feature.js",
|
|
18
|
+
"./operations": "./dist/operations/index.js",
|
|
19
|
+
"./operations/pipeline": "./dist/operations/pipeline.js",
|
|
20
|
+
"./presentations": "./dist/presentations.js",
|
|
21
|
+
"./tests/operations.test-spec": "./dist/tests/operations.test-spec.js",
|
|
22
|
+
"./*": "./*"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
26
|
+
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
27
|
+
"build": "bun build:types && bun build:bundle",
|
|
28
|
+
"build:bundle": "tsdown",
|
|
29
|
+
"build:types": "tsc --noEmit",
|
|
30
|
+
"dev": "bun build:bundle --watch",
|
|
31
|
+
"clean": "rimraf dist .turbo",
|
|
32
|
+
"lint": "bun lint:fix",
|
|
33
|
+
"lint:fix": "eslint src --fix",
|
|
34
|
+
"lint:check": "eslint src",
|
|
35
|
+
"test": "bun test"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@contractspec/lib.contracts": "0.0.0-canary-20260113162409",
|
|
39
|
+
"@contractspec/lib.schema": "0.0.0-canary-20260113162409"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@contractspec/tool.tsdown": "0.0.0-canary-20260113162409",
|
|
43
|
+
"@contractspec/tool.typescript": "0.0.0-canary-20260113162409",
|
|
44
|
+
"tsdown": "^0.19.0",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"exports": {
|
|
50
|
+
".": "./dist/index.js",
|
|
51
|
+
"./contracts": "./dist/contracts/index.js",
|
|
52
|
+
"./contracts/pipeline": "./dist/contracts/pipeline.js",
|
|
53
|
+
"./docs": "./dist/docs/index.js",
|
|
54
|
+
"./docs/kb-update-pipeline.docblock": "./dist/docs/kb-update-pipeline.docblock.js",
|
|
55
|
+
"./entities": "./dist/entities/index.js",
|
|
56
|
+
"./entities/models": "./dist/entities/models.js",
|
|
57
|
+
"./events": "./dist/events.js",
|
|
58
|
+
"./example": "./dist/example.js",
|
|
59
|
+
"./feature": "./dist/feature.js",
|
|
60
|
+
"./handlers": "./dist/handlers/index.js",
|
|
61
|
+
"./handlers/memory.handlers": "./dist/handlers/memory.handlers.js",
|
|
62
|
+
"./kb-update-pipeline.feature": "./dist/kb-update-pipeline.feature.js",
|
|
63
|
+
"./*": "./*"
|
|
64
|
+
},
|
|
65
|
+
"registry": "https://registry.npmjs.org/"
|
|
66
|
+
},
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"repository": {
|
|
69
|
+
"type": "git",
|
|
70
|
+
"url": "https://github.com/lssm-tech/contractspec.git",
|
|
71
|
+
"directory": "packages/examples/kb-update-pipeline"
|
|
72
|
+
},
|
|
73
|
+
"homepage": "https://contractspec.io"
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './kb-update-pipeline.docblock';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DocBlock } from '@contractspec/lib.contracts/docs';
|
|
2
|
+
import { registerDocBlocks } from '@contractspec/lib.contracts/docs';
|
|
3
|
+
|
|
4
|
+
const docBlocks: DocBlock[] = [
|
|
5
|
+
{
|
|
6
|
+
id: 'docs.examples.kb-update-pipeline.goal',
|
|
7
|
+
title: 'KB Update Pipeline — Goal',
|
|
8
|
+
summary:
|
|
9
|
+
'Automation proposes KB patches; humans verify; publishing is blocked until approvals are complete.',
|
|
10
|
+
kind: 'goal',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
route: '/docs/examples/kb-update-pipeline/goal',
|
|
13
|
+
tags: ['knowledge', 'pipeline', 'hitl', 'audit'],
|
|
14
|
+
body: `## Why it matters
|
|
15
|
+
- Keeps humans as the verifiers (HITL) while automation does the busywork.\n- Produces an auditable chain: source change -> diff -> proposal -> review -> publish.\n\n## Guardrails\n- High-risk changes require expert approval.\n- Publishing fails if any included rule versions are not approved.\n- Review requests emit notifications/events.`,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: 'docs.examples.kb-update-pipeline.reference',
|
|
19
|
+
title: 'KB Update Pipeline — Reference',
|
|
20
|
+
summary:
|
|
21
|
+
'Entities, contracts, and events for the KB update pipeline example.',
|
|
22
|
+
kind: 'reference',
|
|
23
|
+
visibility: 'public',
|
|
24
|
+
route: '/docs/examples/kb-update-pipeline',
|
|
25
|
+
tags: ['knowledge', 'reference'],
|
|
26
|
+
body: `## Contracts\n- kbPipeline.runWatch\n- kbPipeline.createReviewTask\n- kbPipeline.submitDecision\n- kbPipeline.publishIfReady\n\n## Events\n- kb.change.detected\n- kb.change.summarized\n- kb.patch.proposed\n- kb.review.requested\n- kb.review.decided`,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
registerDocBlocks(docBlocks);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './models';
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ScalarTypeEnum,
|
|
3
|
+
defineEnum,
|
|
4
|
+
defineSchemaModel,
|
|
5
|
+
} from '@contractspec/lib.schema';
|
|
6
|
+
|
|
7
|
+
export const ChangeRiskLevelEnum = defineEnum('ChangeRiskLevel', [
|
|
8
|
+
'low',
|
|
9
|
+
'medium',
|
|
10
|
+
'high',
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
export const ReviewAssignedRoleEnum = defineEnum('ReviewAssignedRole', [
|
|
14
|
+
'curator',
|
|
15
|
+
'expert',
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
export const ReviewDecisionEnum = defineEnum('ReviewDecision', [
|
|
19
|
+
'approve',
|
|
20
|
+
'reject',
|
|
21
|
+
]);
|
|
22
|
+
|
|
23
|
+
export const ChangeCandidateModel = defineSchemaModel({
|
|
24
|
+
name: 'ChangeCandidate',
|
|
25
|
+
description: 'Candidate change detected in a source document.',
|
|
26
|
+
fields: {
|
|
27
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
28
|
+
sourceDocumentId: {
|
|
29
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
30
|
+
isOptional: false,
|
|
31
|
+
},
|
|
32
|
+
detectedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
|
|
33
|
+
diffSummary: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
34
|
+
riskLevel: { type: ChangeRiskLevelEnum, isOptional: false },
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const ReviewTaskModel = defineSchemaModel({
|
|
39
|
+
name: 'ReviewTask',
|
|
40
|
+
description: 'Human verification task for a change candidate.',
|
|
41
|
+
fields: {
|
|
42
|
+
id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
43
|
+
changeCandidateId: {
|
|
44
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
45
|
+
isOptional: false,
|
|
46
|
+
},
|
|
47
|
+
status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // open|decided
|
|
48
|
+
assignedRole: { type: ReviewAssignedRoleEnum, isOptional: false },
|
|
49
|
+
decision: { type: ReviewDecisionEnum, isOptional: true },
|
|
50
|
+
decidedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
|
|
51
|
+
decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
|
|
52
|
+
},
|
|
53
|
+
});
|
package/src/events.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineEvent,
|
|
3
|
+
defineSchemaModel,
|
|
4
|
+
StabilityEnum,
|
|
5
|
+
} from '@contractspec/lib.contracts';
|
|
6
|
+
import { ScalarTypeEnum } from '@contractspec/lib.schema';
|
|
7
|
+
|
|
8
|
+
const KbChangeDetectedPayload = defineSchemaModel({
|
|
9
|
+
name: 'KbChangeDetectedPayload',
|
|
10
|
+
description: 'Emitted when a source change is detected.',
|
|
11
|
+
fields: {
|
|
12
|
+
changeCandidateId: {
|
|
13
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
14
|
+
isOptional: false,
|
|
15
|
+
},
|
|
16
|
+
sourceDocumentId: {
|
|
17
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
18
|
+
isOptional: false,
|
|
19
|
+
},
|
|
20
|
+
riskLevel: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const KbChangeDetectedEvent = defineEvent({
|
|
25
|
+
meta: {
|
|
26
|
+
key: 'kb.change.detected',
|
|
27
|
+
version: '1.0.0',
|
|
28
|
+
description: 'KB source change detected.',
|
|
29
|
+
stability: StabilityEnum.Experimental,
|
|
30
|
+
owners: [],
|
|
31
|
+
tags: [],
|
|
32
|
+
},
|
|
33
|
+
payload: KbChangeDetectedPayload,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const KbChangeSummarizedPayload = defineSchemaModel({
|
|
37
|
+
name: 'KbChangeSummarizedPayload',
|
|
38
|
+
description: 'Emitted when a change summary is produced.',
|
|
39
|
+
fields: {
|
|
40
|
+
changeCandidateId: {
|
|
41
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
42
|
+
isOptional: false,
|
|
43
|
+
},
|
|
44
|
+
summary: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
45
|
+
riskLevel: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const KbChangeSummarizedEvent = defineEvent({
|
|
50
|
+
meta: {
|
|
51
|
+
key: 'kb.change.summarized',
|
|
52
|
+
version: '1.0.0',
|
|
53
|
+
description: 'KB change summarized.',
|
|
54
|
+
stability: StabilityEnum.Experimental,
|
|
55
|
+
owners: [],
|
|
56
|
+
tags: [],
|
|
57
|
+
},
|
|
58
|
+
payload: KbChangeSummarizedPayload,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const KbPatchProposedPayload = defineSchemaModel({
|
|
62
|
+
name: 'KbPatchProposedPayload',
|
|
63
|
+
description: 'Emitted when draft rule patches are proposed.',
|
|
64
|
+
fields: {
|
|
65
|
+
changeCandidateId: {
|
|
66
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
67
|
+
isOptional: false,
|
|
68
|
+
},
|
|
69
|
+
proposedRuleVersionIds: {
|
|
70
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
71
|
+
isArray: true,
|
|
72
|
+
isOptional: false,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export const KbPatchProposedEvent = defineEvent({
|
|
78
|
+
meta: {
|
|
79
|
+
key: 'kb.patch.proposed',
|
|
80
|
+
version: '1.0.0',
|
|
81
|
+
description: 'KB rule patch proposed (draft versions created).',
|
|
82
|
+
stability: StabilityEnum.Experimental,
|
|
83
|
+
owners: [],
|
|
84
|
+
tags: [],
|
|
85
|
+
},
|
|
86
|
+
payload: KbPatchProposedPayload,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const KbReviewRequestedPayload = defineSchemaModel({
|
|
90
|
+
name: 'KbReviewRequestedPayload',
|
|
91
|
+
description: 'Emitted when a review is requested.',
|
|
92
|
+
fields: {
|
|
93
|
+
reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
94
|
+
changeCandidateId: {
|
|
95
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
96
|
+
isOptional: false,
|
|
97
|
+
},
|
|
98
|
+
assignedRole: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
export const KbReviewRequestedEvent = defineEvent({
|
|
103
|
+
meta: {
|
|
104
|
+
key: 'kb.review.requested',
|
|
105
|
+
version: '1.0.0',
|
|
106
|
+
description: 'KB review requested.',
|
|
107
|
+
stability: StabilityEnum.Experimental,
|
|
108
|
+
owners: [],
|
|
109
|
+
tags: [],
|
|
110
|
+
},
|
|
111
|
+
payload: KbReviewRequestedPayload,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const KbReviewDecidedPayload = defineSchemaModel({
|
|
115
|
+
name: 'KbReviewDecidedPayload',
|
|
116
|
+
description: 'Emitted when a review task is decided.',
|
|
117
|
+
fields: {
|
|
118
|
+
reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
119
|
+
decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
120
|
+
decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export const KbReviewDecidedEvent = defineEvent({
|
|
125
|
+
meta: {
|
|
126
|
+
key: 'kb.review.decided',
|
|
127
|
+
version: '1.0.0',
|
|
128
|
+
description: 'KB review decided.',
|
|
129
|
+
stability: StabilityEnum.Experimental,
|
|
130
|
+
owners: [],
|
|
131
|
+
tags: [],
|
|
132
|
+
},
|
|
133
|
+
payload: KbReviewDecidedPayload,
|
|
134
|
+
});
|
package/src/example.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { defineExample } from '@contractspec/lib.contracts';
|
|
2
|
+
|
|
3
|
+
const example = defineExample({
|
|
4
|
+
meta: {
|
|
5
|
+
key: 'kb-update-pipeline',
|
|
6
|
+
version: '1.0.0',
|
|
7
|
+
title: 'KB Update Pipeline',
|
|
8
|
+
description:
|
|
9
|
+
'Automation proposes KB updates; humans verify; everything audited and notified.',
|
|
10
|
+
kind: 'knowledge',
|
|
11
|
+
visibility: 'public',
|
|
12
|
+
stability: 'experimental',
|
|
13
|
+
owners: ['@platform.core'],
|
|
14
|
+
tags: ['knowledge', 'pipeline', 'hitl', 'audit'],
|
|
15
|
+
},
|
|
16
|
+
docs: {
|
|
17
|
+
rootDocId: 'docs.examples.kb-update-pipeline',
|
|
18
|
+
},
|
|
19
|
+
entrypoints: {
|
|
20
|
+
packageName: '@contractspec/example.kb-update-pipeline',
|
|
21
|
+
feature: './feature',
|
|
22
|
+
contracts: './contracts',
|
|
23
|
+
handlers: './handlers',
|
|
24
|
+
docs: './docs',
|
|
25
|
+
},
|
|
26
|
+
surfaces: {
|
|
27
|
+
templates: true,
|
|
28
|
+
sandbox: { enabled: true, modes: ['markdown', 'specs', 'builder'] },
|
|
29
|
+
studio: { enabled: true, installable: true },
|
|
30
|
+
mcp: { enabled: true },
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export default example;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './memory.handlers';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createPipelineMemoryHandlers,
|
|
5
|
+
createPipelineMemoryStore,
|
|
6
|
+
} from './memory.handlers';
|
|
7
|
+
|
|
8
|
+
describe('@contractspec/example.kb-update-pipeline memory handlers', () => {
|
|
9
|
+
it('high-risk change cannot be approved by curator role', async () => {
|
|
10
|
+
const store = createPipelineMemoryStore();
|
|
11
|
+
const pipeline = createPipelineMemoryHandlers(store);
|
|
12
|
+
|
|
13
|
+
store.candidates.set('c1', {
|
|
14
|
+
id: 'c1',
|
|
15
|
+
sourceDocumentId: 'EU_src1',
|
|
16
|
+
detectedAt: new Date(),
|
|
17
|
+
diffSummary: 'Change detected',
|
|
18
|
+
riskLevel: 'high',
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const review = await pipeline.createReviewTask({ changeCandidateId: 'c1' });
|
|
22
|
+
await expect(
|
|
23
|
+
pipeline.submitDecision({
|
|
24
|
+
reviewTaskId: review.id,
|
|
25
|
+
decision: 'approve',
|
|
26
|
+
decidedBy: 'u_curator',
|
|
27
|
+
decidedByRole: 'curator',
|
|
28
|
+
})
|
|
29
|
+
).rejects.toThrow('FORBIDDEN_ROLE');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('fires a notification when review is requested', async () => {
|
|
33
|
+
const store = createPipelineMemoryStore();
|
|
34
|
+
const pipeline = createPipelineMemoryHandlers(store);
|
|
35
|
+
|
|
36
|
+
store.candidates.set('c2', {
|
|
37
|
+
id: 'c2',
|
|
38
|
+
sourceDocumentId: 'EU_src2',
|
|
39
|
+
detectedAt: new Date(),
|
|
40
|
+
diffSummary: 'Minor change',
|
|
41
|
+
riskLevel: 'low',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const review = await pipeline.createReviewTask({ changeCandidateId: 'c2' });
|
|
45
|
+
expect(store.notifications.length).toBe(1);
|
|
46
|
+
expect(store.notifications[0]?.reviewTaskId).toBe(review.id);
|
|
47
|
+
expect(store.notifications[0]?.assignedRole).toBe('curator');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('publishing fails if any included rule versions are not approved', async () => {
|
|
51
|
+
const store = createPipelineMemoryStore();
|
|
52
|
+
const pipeline = createPipelineMemoryHandlers(store);
|
|
53
|
+
|
|
54
|
+
store.candidates.set('c3', {
|
|
55
|
+
id: 'c3',
|
|
56
|
+
sourceDocumentId: 'EU_src3',
|
|
57
|
+
detectedAt: new Date(),
|
|
58
|
+
diffSummary: 'Change',
|
|
59
|
+
riskLevel: 'low',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const review = await pipeline.createReviewTask({ changeCandidateId: 'c3' });
|
|
63
|
+
await pipeline.proposeRulePatch({
|
|
64
|
+
changeCandidateId: 'c3',
|
|
65
|
+
proposedRuleVersionIds: ['rv1', 'rv2'],
|
|
66
|
+
});
|
|
67
|
+
await pipeline.submitDecision({
|
|
68
|
+
reviewTaskId: review.id,
|
|
69
|
+
decision: 'approve',
|
|
70
|
+
decidedBy: 'u_curator',
|
|
71
|
+
decidedByRole: 'curator',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// only approve one of the proposed rule versions
|
|
75
|
+
await pipeline.markRuleVersionApproved({ ruleVersionId: 'rv1' });
|
|
76
|
+
|
|
77
|
+
await expect(
|
|
78
|
+
pipeline.publishIfReady({ jurisdiction: 'EU' })
|
|
79
|
+
).rejects.toThrow('NOT_READY');
|
|
80
|
+
});
|
|
81
|
+
});
|