@contractspec/example.kb-update-pipeline 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.
- package/.turbo/turbo-build.log +3 -3
- package/AGENTS.md +50 -29
- package/CHANGELOG.md +21 -0
- package/README.md +59 -12
- package/dist/browser/entities/index.js +2 -2
- package/dist/browser/entities/models.js +2 -2
- package/dist/browser/events.js +1 -1
- package/dist/browser/index.js +70 -70
- package/dist/browser/operations/index.js +3 -3
- package/dist/browser/operations/pipeline.js +3 -3
- package/dist/browser/presentations.js +2 -2
- package/dist/entities/index.js +2 -2
- package/dist/entities/models.js +2 -2
- package/dist/events.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +70 -70
- package/dist/node/entities/index.js +2 -2
- package/dist/node/entities/models.js +2 -2
- package/dist/node/events.js +1 -1
- package/dist/node/index.js +70 -70
- package/dist/node/operations/index.js +3 -3
- package/dist/node/operations/pipeline.js +3 -3
- package/dist/node/presentations.js +2 -2
- package/dist/operations/index.js +3 -3
- package/dist/operations/pipeline.js +3 -3
- package/dist/presentations.js +2 -2
- package/package.json +7 -7
- package/src/docs/kb-update-pipeline.docblock.ts +22 -22
- package/src/entities/models.ts +36 -36
- package/src/events.ts +99 -99
- package/src/example.ts +28 -28
- package/src/handlers/memory.handlers.test.ts +64 -64
- package/src/handlers/memory.handlers.ts +158 -158
- package/src/index.ts +2 -2
- package/src/kb-update-pipeline.feature.ts +62 -62
- package/src/operations/pipeline.ts +125 -125
- package/src/presentations.ts +59 -59
- package/src/tests/operations.test-spec.ts +72 -72
- package/tsconfig.json +7 -17
- package/tsdown.config.js +7 -13
package/src/events.ts
CHANGED
|
@@ -1,130 +1,130 @@
|
|
|
1
1
|
import { defineEvent, StabilityEnum } from '@contractspec/lib.contracts-spec';
|
|
2
|
-
import {
|
|
2
|
+
import { defineSchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';
|
|
3
3
|
|
|
4
4
|
const KbChangeDetectedPayload = defineSchemaModel({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
name: 'KbChangeDetectedPayload',
|
|
6
|
+
description: 'Emitted when a source change is detected.',
|
|
7
|
+
fields: {
|
|
8
|
+
changeCandidateId: {
|
|
9
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
10
|
+
isOptional: false,
|
|
11
|
+
},
|
|
12
|
+
sourceDocumentId: {
|
|
13
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
14
|
+
isOptional: false,
|
|
15
|
+
},
|
|
16
|
+
riskLevel: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
17
|
+
},
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
export const KbChangeDetectedEvent = defineEvent({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
meta: {
|
|
22
|
+
key: 'kb.change.detected',
|
|
23
|
+
version: '1.0.0',
|
|
24
|
+
description: 'KB source change detected.',
|
|
25
|
+
stability: StabilityEnum.Experimental,
|
|
26
|
+
owners: [],
|
|
27
|
+
tags: [],
|
|
28
|
+
},
|
|
29
|
+
payload: KbChangeDetectedPayload,
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
const KbChangeSummarizedPayload = defineSchemaModel({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
name: 'KbChangeSummarizedPayload',
|
|
34
|
+
description: 'Emitted when a change summary is produced.',
|
|
35
|
+
fields: {
|
|
36
|
+
changeCandidateId: {
|
|
37
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
38
|
+
isOptional: false,
|
|
39
|
+
},
|
|
40
|
+
summary: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
41
|
+
riskLevel: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
42
|
+
},
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
export const KbChangeSummarizedEvent = defineEvent({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
meta: {
|
|
47
|
+
key: 'kb.change.summarized',
|
|
48
|
+
version: '1.0.0',
|
|
49
|
+
description: 'KB change summarized.',
|
|
50
|
+
stability: StabilityEnum.Experimental,
|
|
51
|
+
owners: [],
|
|
52
|
+
tags: [],
|
|
53
|
+
},
|
|
54
|
+
payload: KbChangeSummarizedPayload,
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
const KbPatchProposedPayload = defineSchemaModel({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
name: 'KbPatchProposedPayload',
|
|
59
|
+
description: 'Emitted when draft rule patches are proposed.',
|
|
60
|
+
fields: {
|
|
61
|
+
changeCandidateId: {
|
|
62
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
63
|
+
isOptional: false,
|
|
64
|
+
},
|
|
65
|
+
proposedRuleVersionIds: {
|
|
66
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
67
|
+
isArray: true,
|
|
68
|
+
isOptional: false,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
export const KbPatchProposedEvent = defineEvent({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
meta: {
|
|
75
|
+
key: 'kb.patch.proposed',
|
|
76
|
+
version: '1.0.0',
|
|
77
|
+
description: 'KB rule patch proposed (draft versions created).',
|
|
78
|
+
stability: StabilityEnum.Experimental,
|
|
79
|
+
owners: [],
|
|
80
|
+
tags: [],
|
|
81
|
+
},
|
|
82
|
+
payload: KbPatchProposedPayload,
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
const KbReviewRequestedPayload = defineSchemaModel({
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
name: 'KbReviewRequestedPayload',
|
|
87
|
+
description: 'Emitted when a review is requested.',
|
|
88
|
+
fields: {
|
|
89
|
+
reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
90
|
+
changeCandidateId: {
|
|
91
|
+
type: ScalarTypeEnum.String_unsecure(),
|
|
92
|
+
isOptional: false,
|
|
93
|
+
},
|
|
94
|
+
assignedRole: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
95
|
+
},
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
export const KbReviewRequestedEvent = defineEvent({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
99
|
+
meta: {
|
|
100
|
+
key: 'kb.review.requested',
|
|
101
|
+
version: '1.0.0',
|
|
102
|
+
description: 'KB review requested.',
|
|
103
|
+
stability: StabilityEnum.Experimental,
|
|
104
|
+
owners: [],
|
|
105
|
+
tags: [],
|
|
106
|
+
},
|
|
107
|
+
payload: KbReviewRequestedPayload,
|
|
108
108
|
});
|
|
109
109
|
|
|
110
110
|
const KbReviewDecidedPayload = defineSchemaModel({
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
name: 'KbReviewDecidedPayload',
|
|
112
|
+
description: 'Emitted when a review task is decided.',
|
|
113
|
+
fields: {
|
|
114
|
+
reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
115
|
+
decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
116
|
+
decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
|
|
117
|
+
},
|
|
118
118
|
});
|
|
119
119
|
|
|
120
120
|
export const KbReviewDecidedEvent = defineEvent({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
121
|
+
meta: {
|
|
122
|
+
key: 'kb.review.decided',
|
|
123
|
+
version: '1.0.0',
|
|
124
|
+
description: 'KB review decided.',
|
|
125
|
+
stability: StabilityEnum.Experimental,
|
|
126
|
+
owners: [],
|
|
127
|
+
tags: [],
|
|
128
|
+
},
|
|
129
|
+
payload: KbReviewDecidedPayload,
|
|
130
130
|
});
|
package/src/example.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { defineExample } from '@contractspec/lib.contracts-spec';
|
|
2
2
|
|
|
3
3
|
const example = defineExample({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
32
|
});
|
|
33
33
|
|
|
34
34
|
export default example;
|
|
@@ -1,81 +1,81 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
createPipelineMemoryHandlers,
|
|
5
|
+
createPipelineMemoryStore,
|
|
6
6
|
} from './memory.handlers';
|
|
7
7
|
|
|
8
8
|
describe('@contractspec/example.kb-update-pipeline memory handlers', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
it('high-risk change cannot be approved by curator role', async () => {
|
|
10
|
+
const store = createPipelineMemoryStore();
|
|
11
|
+
const pipeline = createPipelineMemoryHandlers(store);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
it('fires a notification when review is requested', async () => {
|
|
33
|
+
const store = createPipelineMemoryStore();
|
|
34
|
+
const pipeline = createPipelineMemoryHandlers(store);
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
it('publishing fails if any included rule versions are not approved', async () => {
|
|
51
|
+
const store = createPipelineMemoryStore();
|
|
52
|
+
const pipeline = createPipelineMemoryHandlers(store);
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
store.candidates.set('c3', {
|
|
55
|
+
id: 'c3',
|
|
56
|
+
sourceDocumentId: 'EU_src3',
|
|
57
|
+
detectedAt: new Date(),
|
|
58
|
+
diffSummary: 'Change',
|
|
59
|
+
riskLevel: 'low',
|
|
60
|
+
});
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
// only approve one of the proposed rule versions
|
|
75
|
+
await pipeline.markRuleVersionApproved({ ruleVersionId: 'rv1' });
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
await expect(
|
|
78
|
+
pipeline.publishIfReady({ jurisdiction: 'EU' })
|
|
79
|
+
).rejects.toThrow('NOT_READY');
|
|
80
|
+
});
|
|
81
81
|
});
|