@lssm/example.kb-update-pipeline 0.0.0-canary-20251213172311

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.
@@ -0,0 +1,23 @@
1
+ $ bun build:bundle && bun build:types
2
+ $ tsdown
3
+ ℹ tsdown v0.17.0 powered by rolldown v1.0.0-beta.53
4
+ ℹ config file: /home/runner/work/contractspec/contractspec/packages/examples/kb-update-pipeline/tsdown.config.js
5
+ ℹ entry: src/events.ts, src/example.ts, src/feature.ts, src/index.ts, src/contracts/index.ts, src/contracts/pipeline.ts, src/docs/index.ts, src/docs/kb-update-pipeline.docblock.ts, src/entities/index.ts, src/entities/models.ts, src/handlers/index.ts, src/handlers/memory.handlers.ts
6
+ ℹ target: esnext
7
+ ℹ tsconfig: tsconfig.json
8
+ ℹ Build start
9
+ ℹ dist/contracts/pipeline.js 3.44 kB │ gzip: 1.18 kB
10
+ ℹ dist/handlers/memory.handlers.js 2.27 kB │ gzip: 0.87 kB
11
+ ℹ dist/events.js 2.02 kB │ gzip: 0.54 kB
12
+ ℹ dist/index.js 1.30 kB │ gzip: 0.45 kB
13
+ ℹ dist/docs/kb-update-pipeline.docblock.js 1.26 kB │ gzip: 0.64 kB
14
+ ℹ dist/entities/models.js 1.11 kB │ gzip: 0.44 kB
15
+ ℹ dist/feature.js 0.92 kB │ gzip: 0.45 kB
16
+ ℹ dist/example.js 0.58 kB │ gzip: 0.36 kB
17
+ ℹ dist/contracts/index.js 0.33 kB │ gzip: 0.16 kB
18
+ ℹ dist/entities/index.js 0.28 kB │ gzip: 0.16 kB
19
+ ℹ dist/handlers/index.js 0.17 kB │ gzip: 0.11 kB
20
+ ℹ dist/docs/index.js 0.04 kB │ gzip: 0.06 kB
21
+ ℹ 12 files, total: 13.72 kB
22
+ ✔ Build complete in 53ms
23
+ $ tsc --noEmit
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # @lssm/example.kb-update-pipeline
2
+
3
+ ## 0.0.0-canary-20251213172311
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [3086383]
8
+ - @lssm/lib.contracts@0.0.0-canary-20251213172311
9
+ - @lssm/lib.schema@0.0.0-canary-20251213172311
10
+ - @lssm/lib.identity-rbac@0.0.0-canary-20251213172311
11
+ - @lssm/module.notifications@0.0.0-canary-20251213172311
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # `@lssm/example.kb-update-pipeline`
2
+
3
+ Spec-first example for a **knowledge base update pipeline** where:
4
+
5
+ - automation **proposes** changes (watch/diff/summarize/propose patches)\n+- humans **verify** (HITL) with role-based rules\n+- snapshots are published only when rule versions are approved\n+- notifications + audit trails provide traceability\n+
6
+ ## Contracts
7
+
8
+ - `kbPipeline.runWatch()`\n+- `kbPipeline.createReviewTask(changeCandidateId)`\n+- `kbPipeline.submitDecision(reviewTaskId, decision)`\n+- `kbPipeline.publishIfReady(jurisdiction)`\n+
9
+ ## Tests
10
+
11
+ - high-risk change cannot be approved by curator role\n+- publish fails if any included rule versions are unapproved\n+- notifications fire on review requested\n+
12
+ ## Running tests
13
+
14
+ ```bash
15
+ bun test
16
+ ```
17
+
18
+
@@ -0,0 +1 @@
1
+ import{KbPipelineCreateReviewTaskContract as e,KbPipelinePublishIfReadyContract as t,KbPipelineRunWatchContract as n,KbPipelineSubmitDecisionContract as r}from"./pipeline.js";export{e as KbPipelineCreateReviewTaskContract,t as KbPipelinePublishIfReadyContract,n as KbPipelineRunWatchContract,r as KbPipelineSubmitDecisionContract};
@@ -0,0 +1 @@
1
+ import{ChangeCandidateModel as e,ReviewDecisionEnum as t,ReviewTaskModel as n}from"../entities/models.js";import{defineCommand as r}from"@lssm/lib.contracts";import{ScalarTypeEnum as i,defineSchemaModel as a}from"@lssm/lib.schema";const o=a({name:`KbPipelineRunWatchInput`,description:`Trigger a watch cycle for KB sources (demo).`,fields:{jurisdiction:{type:i.String_unsecure(),isOptional:!1}}}),s=a({name:`KbPipelineRunWatchOutput`,description:`Output containing detected changes.`,fields:{candidates:{type:e,isArray:!0,isOptional:!1}}}),c=a({name:`KbPipelineCreateReviewTaskInput`,description:`Create a review task for a change candidate.`,fields:{changeCandidateId:{type:i.String_unsecure(),isOptional:!1}}}),l=a({name:`KbPipelineSubmitDecisionInput`,description:`Submit a decision for a review task.`,fields:{reviewTaskId:{type:i.String_unsecure(),isOptional:!1},decision:{type:t,isOptional:!1},decidedBy:{type:i.String_unsecure(),isOptional:!1},decidedByRole:{type:i.String_unsecure(),isOptional:!1}}}),u=a({name:`KbPipelinePublishIfReadyInput`,description:`Publish snapshot if approvals are satisfied for a jurisdiction.`,fields:{jurisdiction:{type:i.String_unsecure(),isOptional:!1}}}),d=a({name:`KbPipelinePublishIfReadyOutput`,description:`Output for publish-if-ready operation.`,fields:{published:{type:i.Boolean(),isOptional:!1},reason:{type:i.String_unsecure(),isOptional:!0}}}),f=r({meta:{name:`kbPipeline.runWatch`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`pipeline`,`jobs`],description:`Detect source changes and create change candidates.`,goal:`Automate discovery of updates needing review.`,context:`Scheduled job or manual trigger in demos.`},io:{input:o,output:s},policy:{auth:`user`}}),p=r({meta:{name:`kbPipeline.createReviewTask`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`pipeline`,`hitl`],description:`Create a review task for a detected change.`,goal:`Route work to human verifiers.`,context:`Called after change detection or manual selection.`},io:{input:c,output:n},policy:{auth:`user`}}),m=r({meta:{name:`kbPipeline.submitDecision`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`pipeline`,`hitl`,`rbac`],description:`Submit approve/reject decision for a review task.`,goal:`Ensure humans verify before publishing.`,context:`Curator/expert reviews and decides.`},io:{input:l,output:n,errors:{FORBIDDEN_ROLE:{description:`Role not allowed to approve the given risk level`,http:403,gqlCode:`FORBIDDEN_ROLE`,when:`curator attempts to approve a high-risk change`},REVIEW_TASK_NOT_FOUND:{description:`Review task not found`,http:404,gqlCode:`REVIEW_TASK_NOT_FOUND`,when:`reviewTaskId is invalid`}}},policy:{auth:`user`}}),h=r({meta:{name:`kbPipeline.publishIfReady`,version:1,stability:`experimental`,owners:[`examples`],tags:[`knowledge`,`pipeline`,`publishing`],description:`Publish snapshot if ready (all approvals satisfied).`,goal:`Prevent publishing until all required approvals exist.`,context:`Called by job or UI to attempt publish.`},io:{input:u,output:d,errors:{NOT_READY:{description:`Publishing is blocked because approvals are incomplete`,http:409,gqlCode:`NOT_READY`,when:`there are open review tasks or unapproved rule versions`}}},policy:{auth:`user`}});export{p as KbPipelineCreateReviewTaskContract,h as KbPipelinePublishIfReadyContract,f as KbPipelineRunWatchContract,m as KbPipelineSubmitDecisionContract};
@@ -0,0 +1 @@
1
+ import"./kb-update-pipeline.docblock.js";
@@ -0,0 +1,19 @@
1
+ import{registerDocBlocks as e}from"@lssm/lib.contracts/docs";e([{id:`docs.examples.kb-update-pipeline.goal`,title:`KB Update Pipeline — Goal`,summary:`Automation proposes KB patches; humans verify; publishing is blocked until approvals are complete.`,kind:`goal`,visibility:`public`,route:`/docs/examples/kb-update-pipeline/goal`,tags:[`knowledge`,`pipeline`,`hitl`,`audit`],body:`## Why it matters
2
+ - Keeps humans as the verifiers (HITL) while automation does the busywork.
3
+ - Produces an auditable chain: source change -> diff -> proposal -> review -> publish.
4
+
5
+ ## Guardrails
6
+ - High-risk changes require expert approval.
7
+ - Publishing fails if any included rule versions are not approved.
8
+ - Review requests emit notifications/events.`},{id:`docs.examples.kb-update-pipeline.reference`,title:`KB Update Pipeline — Reference`,summary:`Entities, contracts, and events for the KB update pipeline example.`,kind:`reference`,visibility:`public`,route:`/docs/examples/kb-update-pipeline`,tags:[`knowledge`,`reference`],body:`## Contracts
9
+ - kbPipeline.runWatch
10
+ - kbPipeline.createReviewTask
11
+ - kbPipeline.submitDecision
12
+ - kbPipeline.publishIfReady
13
+
14
+ ## Events
15
+ - kb.change.detected
16
+ - kb.change.summarized
17
+ - kb.patch.proposed
18
+ - kb.review.requested
19
+ - kb.review.decided`}]);
@@ -0,0 +1 @@
1
+ import{ChangeCandidateModel as e,ChangeRiskLevelEnum as t,ReviewAssignedRoleEnum as n,ReviewDecisionEnum as r,ReviewTaskModel as i}from"./models.js";export{e as ChangeCandidateModel,t as ChangeRiskLevelEnum,n as ReviewAssignedRoleEnum,r as ReviewDecisionEnum,i as ReviewTaskModel};
@@ -0,0 +1 @@
1
+ import{ScalarTypeEnum as e,defineEnum as t,defineSchemaModel as n}from"@lssm/lib.schema";const r=t(`ChangeRiskLevel`,[`low`,`medium`,`high`]),i=t(`ReviewAssignedRole`,[`curator`,`expert`]),a=t(`ReviewDecision`,[`approve`,`reject`]),o=n({name:`ChangeCandidate`,description:`Candidate change detected in a source document.`,fields:{id:{type:e.String_unsecure(),isOptional:!1},sourceDocumentId:{type:e.String_unsecure(),isOptional:!1},detectedAt:{type:e.DateTime(),isOptional:!1},diffSummary:{type:e.String_unsecure(),isOptional:!1},riskLevel:{type:r,isOptional:!1}}}),s=n({name:`ReviewTask`,description:`Human verification task for a change candidate.`,fields:{id:{type:e.String_unsecure(),isOptional:!1},changeCandidateId:{type:e.String_unsecure(),isOptional:!1},status:{type:e.String_unsecure(),isOptional:!1},assignedRole:{type:i,isOptional:!1},decision:{type:a,isOptional:!0},decidedAt:{type:e.DateTime(),isOptional:!0},decidedBy:{type:e.String_unsecure(),isOptional:!0}}});export{o as ChangeCandidateModel,r as ChangeRiskLevelEnum,i as ReviewAssignedRoleEnum,a as ReviewDecisionEnum,s as ReviewTaskModel};
package/dist/events.js ADDED
@@ -0,0 +1 @@
1
+ import{defineEvent as e,defineSchemaModel as t}from"@lssm/lib.contracts";import{ScalarTypeEnum as n}from"@lssm/lib.schema";const r=e({name:`kb.change.detected`,version:1,description:`KB source change detected.`,payload:t({name:`KbChangeDetectedPayload`,description:`Emitted when a source change is detected.`,fields:{changeCandidateId:{type:n.String_unsecure(),isOptional:!1},sourceDocumentId:{type:n.String_unsecure(),isOptional:!1},riskLevel:{type:n.String_unsecure(),isOptional:!1}}})}),i=e({name:`kb.change.summarized`,version:1,description:`KB change summarized.`,payload:t({name:`KbChangeSummarizedPayload`,description:`Emitted when a change summary is produced.`,fields:{changeCandidateId:{type:n.String_unsecure(),isOptional:!1},summary:{type:n.String_unsecure(),isOptional:!1},riskLevel:{type:n.String_unsecure(),isOptional:!1}}})}),a=e({name:`kb.patch.proposed`,version:1,description:`KB rule patch proposed (draft versions created).`,payload:t({name:`KbPatchProposedPayload`,description:`Emitted when draft rule patches are proposed.`,fields:{changeCandidateId:{type:n.String_unsecure(),isOptional:!1},proposedRuleVersionIds:{type:n.String_unsecure(),isArray:!0,isOptional:!1}}})}),o=e({name:`kb.review.requested`,version:1,description:`KB review requested.`,payload:t({name:`KbReviewRequestedPayload`,description:`Emitted when a review is requested.`,fields:{reviewTaskId:{type:n.String_unsecure(),isOptional:!1},changeCandidateId:{type:n.String_unsecure(),isOptional:!1},assignedRole:{type:n.String_unsecure(),isOptional:!1}}})}),s=e({name:`kb.review.decided`,version:1,description:`KB review decided.`,payload:t({name:`KbReviewDecidedPayload`,description:`Emitted when a review task is decided.`,fields:{reviewTaskId:{type:n.String_unsecure(),isOptional:!1},decision:{type:n.String_unsecure(),isOptional:!1},decidedBy:{type:n.String_unsecure(),isOptional:!1}}})});export{r as KbChangeDetectedEvent,i as KbChangeSummarizedEvent,a as KbPatchProposedEvent,s as KbReviewDecidedEvent,o as KbReviewRequestedEvent};
@@ -0,0 +1 @@
1
+ var e={id:`kb-update-pipeline`,title:`KB Update Pipeline`,summary:`Automation proposes KB updates; humans verify; everything audited and notified.`,tags:[`knowledge`,`pipeline`,`hitl`,`audit`],kind:`knowledge`,visibility:`public`,docs:{rootDocId:`docs.examples.kb-update-pipeline`},entrypoints:{packageName:`@lssm/example.kb-update-pipeline`,feature:`./feature`,contracts:`./contracts`,handlers:`./handlers`,docs:`./docs`},surfaces:{templates:!0,sandbox:{enabled:!0,modes:[`markdown`,`specs`,`builder`]},studio:{enabled:!0,installable:!0},mcp:{enabled:!0}}};export{e as default};
@@ -0,0 +1 @@
1
+ const e={meta:{key:`kb-update-pipeline`,title:`KB Update Pipeline (HITL)`,description:`Automation proposes KB patches; humans verify; publishing is blocked until approvals are complete.`,domain:`knowledge`,owners:[`examples`],tags:[`knowledge`,`pipeline`,`hitl`,`audit`,`notifications`],stability:`experimental`},operations:[{name:`kbPipeline.runWatch`,version:1},{name:`kbPipeline.createReviewTask`,version:1},{name:`kbPipeline.submitDecision`,version:1},{name:`kbPipeline.publishIfReady`,version:1}],events:[{name:`kb.change.detected`,version:1},{name:`kb.change.summarized`,version:1},{name:`kb.patch.proposed`,version:1},{name:`kb.review.requested`,version:1},{name:`kb.review.decided`,version:1}],presentations:[],opToPresentation:[],presentationsTargets:[],capabilities:{requires:[{key:`identity`,version:1},{key:`notifications`,version:1},{key:`audit-trail`,version:1}]}};export{e as KbUpdatePipelineFeature};
@@ -0,0 +1 @@
1
+ import{createPipelineMemoryHandlers as e,createPipelineMemoryStore as t}from"./memory.handlers.js";export{e as createPipelineMemoryHandlers,t as createPipelineMemoryStore};
@@ -0,0 +1 @@
1
+ function e(){return{candidates:new Map,reviewTasks:new Map,proposedRuleVersionIdsByCandidate:new Map,approvedRuleVersionIds:new Set,notifications:[]}}function t(e,t){return`${e}_${t.replace(/[^a-zA-Z0-9_-]/g,`_`)}`}function n(e){async function n(t){return{candidates:[...e.candidates.values()].filter(e=>e.sourceDocumentId.startsWith(`${t.jurisdiction}_`)||!0)}}async function r(n){let r=e.candidates.get(n.changeCandidateId);if(!r)throw Error(`CHANGE_CANDIDATE_NOT_FOUND`);let i=r.riskLevel===`high`?`expert`:`curator`,a=t(`review`,n.changeCandidateId),o={id:a,changeCandidateId:n.changeCandidateId,status:`open`,assignedRole:i,decision:void 0,decidedAt:void 0,decidedBy:void 0};return e.reviewTasks.set(a,o),e.notifications.push({kind:`kb.review.requested`,reviewTaskId:a,changeCandidateId:n.changeCandidateId,assignedRole:i,createdAt:new Date}),o}async function i(t){if(!e.candidates.has(t.changeCandidateId))throw Error(`CHANGE_CANDIDATE_NOT_FOUND`);return e.proposedRuleVersionIdsByCandidate.set(t.changeCandidateId,[...t.proposedRuleVersionIds]),{proposedRuleVersionIds:[...t.proposedRuleVersionIds]}}async function a(t){return e.approvedRuleVersionIds.add(t.ruleVersionId),{ruleVersionId:t.ruleVersionId}}async function o(t){let n=e.reviewTasks.get(t.reviewTaskId);if(!n)throw Error(`REVIEW_TASK_NOT_FOUND`);let r=e.candidates.get(n.changeCandidateId);if(!r)throw Error(`CHANGE_CANDIDATE_NOT_FOUND`);if(r.riskLevel===`high`&&t.decision===`approve`&&t.decidedByRole!==`expert`)throw Error(`FORBIDDEN_ROLE`);let i={...n,status:`decided`,decision:t.decision,decidedAt:new Date,decidedBy:t.decidedBy};return e.reviewTasks.set(i.id,i),i}async function s(t){if([...e.reviewTasks.values()].filter(e=>e.status!==`decided`).length)throw Error(`NOT_READY`);if([...e.reviewTasks.values()].some(e=>e.decision===`reject`))return{published:!1,reason:`REJECTED`};for(let t of e.reviewTasks.values())if(t.decision===`approve`&&(e.proposedRuleVersionIdsByCandidate.get(t.changeCandidateId)??[]).filter(t=>!e.approvedRuleVersionIds.has(t)).length)throw Error(`NOT_READY`);return{published:!0}}return{runWatch:n,createReviewTask:r,proposeRulePatch:i,markRuleVersionApproved:a,submitDecision:o,publishIfReady:s}}export{n as createPipelineMemoryHandlers,e as createPipelineMemoryStore};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{KbChangeDetectedEvent as e,KbChangeSummarizedEvent as t,KbPatchProposedEvent as n,KbReviewDecidedEvent as r,KbReviewRequestedEvent as i}from"./events.js";import a from"./example.js";import{KbUpdatePipelineFeature as o}from"./feature.js";import{ChangeCandidateModel as s,ChangeRiskLevelEnum as c,ReviewAssignedRoleEnum as l,ReviewDecisionEnum as u,ReviewTaskModel as d}from"./entities/models.js";import"./entities/index.js";import{KbPipelineCreateReviewTaskContract as f,KbPipelinePublishIfReadyContract as p,KbPipelineRunWatchContract as m,KbPipelineSubmitDecisionContract as h}from"./contracts/pipeline.js";import"./contracts/index.js";import{createPipelineMemoryHandlers as g,createPipelineMemoryStore as _}from"./handlers/memory.handlers.js";import"./docs/index.js";export{s as ChangeCandidateModel,c as ChangeRiskLevelEnum,e as KbChangeDetectedEvent,t as KbChangeSummarizedEvent,n as KbPatchProposedEvent,f as KbPipelineCreateReviewTaskContract,p as KbPipelinePublishIfReadyContract,m as KbPipelineRunWatchContract,h as KbPipelineSubmitDecisionContract,r as KbReviewDecidedEvent,i as KbReviewRequestedEvent,o as KbUpdatePipelineFeature,l as ReviewAssignedRoleEnum,u as ReviewDecisionEnum,d as ReviewTaskModel,g as createPipelineMemoryHandlers,_ as createPipelineMemoryStore,a as example};
package/example.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './src/example';
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@lssm/example.kb-update-pipeline",
3
+ "version": "0.0.0-canary-20251213172311",
4
+ "description": "Example: KB update automation pipeline with HITL review and auditability.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": "./src/index.ts",
11
+ "./contracts": "./src/contracts/index.ts",
12
+ "./contracts/pipeline": "./src/contracts/pipeline.ts",
13
+ "./docs": "./src/docs/index.ts",
14
+ "./docs/kb-update-pipeline.docblock": "./src/docs/kb-update-pipeline.docblock.ts",
15
+ "./entities": "./src/entities/index.ts",
16
+ "./entities/models": "./src/entities/models.ts",
17
+ "./events": "./src/events.ts",
18
+ "./example": "./src/example.ts",
19
+ "./feature": "./src/feature.ts",
20
+ "./handlers": "./src/handlers/index.ts",
21
+ "./handlers/memory.handlers": "./src/handlers/memory.handlers.ts",
22
+ "./*": "./*"
23
+ },
24
+ "scripts": {
25
+ "build": "bun build:bundle && bun build:types",
26
+ "build:bundle": "tsdown",
27
+ "build:types": "tsc --noEmit",
28
+ "dev": "bun build:bundle --watch",
29
+ "clean": "rimraf dist .turbo",
30
+ "lint": "bun lint:fix",
31
+ "lint:fix": "eslint src --fix",
32
+ "lint:check": "eslint src",
33
+ "test": "bun test"
34
+ },
35
+ "dependencies": {
36
+ "@lssm/lib.contracts": "workspace:*",
37
+ "@lssm/lib.identity-rbac": "workspace:*",
38
+ "@lssm/lib.schema": "workspace:*",
39
+ "@lssm/module.notifications": "workspace:*",
40
+ "zod": "^4.1.13"
41
+ },
42
+ "devDependencies": {
43
+ "@lssm/tool.tsdown": "workspace:*",
44
+ "@lssm/tool.typescript": "workspace:*",
45
+ "tsdown": "^0.17.0",
46
+ "typescript": "^5.9.3"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "exports": {
51
+ ".": "./dist/index.js",
52
+ "./contracts": "./dist/contracts/index.js",
53
+ "./contracts/pipeline": "./dist/contracts/pipeline.js",
54
+ "./docs": "./dist/docs/index.js",
55
+ "./docs/kb-update-pipeline.docblock": "./dist/docs/kb-update-pipeline.docblock.js",
56
+ "./entities": "./dist/entities/index.js",
57
+ "./entities/models": "./dist/entities/models.js",
58
+ "./events": "./dist/events.js",
59
+ "./example": "./dist/example.js",
60
+ "./feature": "./dist/feature.js",
61
+ "./handlers": "./dist/handlers/index.js",
62
+ "./handlers/memory.handlers": "./dist/handlers/memory.handlers.js",
63
+ "./*": "./*"
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,3 @@
1
+ export * from './pipeline';
2
+
3
+
@@ -0,0 +1,146 @@
1
+ import { defineCommand } from '@lssm/lib.contracts';
2
+ import { ScalarTypeEnum, defineSchemaModel } from '@lssm/lib.schema';
3
+
4
+ import { ChangeCandidateModel, ReviewDecisionEnum, ReviewTaskModel } from '../entities/models';
5
+
6
+ const RunWatchInput = defineSchemaModel({
7
+ name: 'KbPipelineRunWatchInput',
8
+ description: 'Trigger a watch cycle for KB sources (demo).',
9
+ fields: {
10
+ jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
11
+ },
12
+ });
13
+
14
+ const RunWatchOutput = defineSchemaModel({
15
+ name: 'KbPipelineRunWatchOutput',
16
+ description: 'Output containing detected changes.',
17
+ fields: {
18
+ candidates: { type: ChangeCandidateModel, isArray: true, isOptional: false },
19
+ },
20
+ });
21
+
22
+ const CreateReviewTaskInput = defineSchemaModel({
23
+ name: 'KbPipelineCreateReviewTaskInput',
24
+ description: 'Create a review task for a change candidate.',
25
+ fields: {
26
+ changeCandidateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
27
+ },
28
+ });
29
+
30
+ const SubmitDecisionInput = defineSchemaModel({
31
+ name: 'KbPipelineSubmitDecisionInput',
32
+ description: 'Submit a decision for a review task.',
33
+ fields: {
34
+ reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
35
+ decision: { type: ReviewDecisionEnum, isOptional: false },
36
+ decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ decidedByRole: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
38
+ },
39
+ });
40
+
41
+ const PublishIfReadyInput = defineSchemaModel({
42
+ name: 'KbPipelinePublishIfReadyInput',
43
+ description: 'Publish snapshot if approvals are satisfied for a jurisdiction.',
44
+ fields: {
45
+ jurisdiction: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
46
+ },
47
+ });
48
+
49
+ const PublishIfReadyOutput = defineSchemaModel({
50
+ name: 'KbPipelinePublishIfReadyOutput',
51
+ description: 'Output for publish-if-ready operation.',
52
+ fields: {
53
+ published: { type: ScalarTypeEnum.Boolean(), isOptional: false },
54
+ reason: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
55
+ },
56
+ });
57
+
58
+ export const KbPipelineRunWatchContract = defineCommand({
59
+ meta: {
60
+ name: 'kbPipeline.runWatch',
61
+ version: 1,
62
+ stability: 'experimental',
63
+ owners: ['examples'],
64
+ tags: ['knowledge', 'pipeline', 'jobs'],
65
+ description: 'Detect source changes and create change candidates.',
66
+ goal: 'Automate discovery of updates needing review.',
67
+ context: 'Scheduled job or manual trigger in demos.',
68
+ },
69
+ io: { input: RunWatchInput, output: RunWatchOutput },
70
+ policy: { auth: 'user' },
71
+ });
72
+
73
+ export const KbPipelineCreateReviewTaskContract = defineCommand({
74
+ meta: {
75
+ name: 'kbPipeline.createReviewTask',
76
+ version: 1,
77
+ stability: 'experimental',
78
+ owners: ['examples'],
79
+ tags: ['knowledge', 'pipeline', 'hitl'],
80
+ description: 'Create a review task for a detected change.',
81
+ goal: 'Route work to human verifiers.',
82
+ context: 'Called after change detection or manual selection.',
83
+ },
84
+ io: { input: CreateReviewTaskInput, output: ReviewTaskModel },
85
+ policy: { auth: 'user' },
86
+ });
87
+
88
+ export const KbPipelineSubmitDecisionContract = defineCommand({
89
+ meta: {
90
+ name: 'kbPipeline.submitDecision',
91
+ version: 1,
92
+ stability: 'experimental',
93
+ owners: ['examples'],
94
+ tags: ['knowledge', 'pipeline', 'hitl', 'rbac'],
95
+ description: 'Submit approve/reject decision for a review task.',
96
+ goal: 'Ensure humans verify before publishing.',
97
+ context: 'Curator/expert reviews and decides.',
98
+ },
99
+ io: {
100
+ input: SubmitDecisionInput,
101
+ output: ReviewTaskModel,
102
+ errors: {
103
+ FORBIDDEN_ROLE: {
104
+ description: 'Role not allowed to approve the given risk level',
105
+ http: 403,
106
+ gqlCode: 'FORBIDDEN_ROLE',
107
+ when: 'curator attempts to approve a high-risk change',
108
+ },
109
+ REVIEW_TASK_NOT_FOUND: {
110
+ description: 'Review task not found',
111
+ http: 404,
112
+ gqlCode: 'REVIEW_TASK_NOT_FOUND',
113
+ when: 'reviewTaskId is invalid',
114
+ },
115
+ },
116
+ },
117
+ policy: { auth: 'user' },
118
+ });
119
+
120
+ export const KbPipelinePublishIfReadyContract = defineCommand({
121
+ meta: {
122
+ name: 'kbPipeline.publishIfReady',
123
+ version: 1,
124
+ stability: 'experimental',
125
+ owners: ['examples'],
126
+ tags: ['knowledge', 'pipeline', 'publishing'],
127
+ description: 'Publish snapshot if ready (all approvals satisfied).',
128
+ goal: 'Prevent publishing until all required approvals exist.',
129
+ context: 'Called by job or UI to attempt publish.',
130
+ },
131
+ io: {
132
+ input: PublishIfReadyInput,
133
+ output: PublishIfReadyOutput,
134
+ errors: {
135
+ NOT_READY: {
136
+ description: 'Publishing is blocked because approvals are incomplete',
137
+ http: 409,
138
+ gqlCode: 'NOT_READY',
139
+ when: 'there are open review tasks or unapproved rule versions',
140
+ },
141
+ },
142
+ },
143
+ policy: { auth: 'user' },
144
+ });
145
+
146
+
@@ -0,0 +1,3 @@
1
+ import './kb-update-pipeline.docblock';
2
+
3
+
@@ -0,0 +1,31 @@
1
+ import type { DocBlock } from '@lssm/lib.contracts/docs';
2
+ import { registerDocBlocks } from '@lssm/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: 'Entities, contracts, and events for the KB update pipeline example.',
21
+ kind: 'reference',
22
+ visibility: 'public',
23
+ route: '/docs/examples/kb-update-pipeline',
24
+ tags: ['knowledge', 'reference'],
25
+ 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`,
26
+ },
27
+ ];
28
+
29
+ registerDocBlocks(docBlocks);
30
+
31
+
@@ -0,0 +1,3 @@
1
+ export * from './models';
2
+
3
+
@@ -0,0 +1,45 @@
1
+ import { ScalarTypeEnum, defineEnum, defineSchemaModel } from '@lssm/lib.schema';
2
+
3
+ export const ChangeRiskLevelEnum = defineEnum('ChangeRiskLevel', [
4
+ 'low',
5
+ 'medium',
6
+ 'high',
7
+ ]);
8
+
9
+ export const ReviewAssignedRoleEnum = defineEnum('ReviewAssignedRole', [
10
+ 'curator',
11
+ 'expert',
12
+ ]);
13
+
14
+ export const ReviewDecisionEnum = defineEnum('ReviewDecision', [
15
+ 'approve',
16
+ 'reject',
17
+ ]);
18
+
19
+ export const ChangeCandidateModel = defineSchemaModel({
20
+ name: 'ChangeCandidate',
21
+ description: 'Candidate change detected in a source document.',
22
+ fields: {
23
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
24
+ sourceDocumentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
25
+ detectedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
26
+ diffSummary: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
27
+ riskLevel: { type: ChangeRiskLevelEnum, isOptional: false },
28
+ },
29
+ });
30
+
31
+ export const ReviewTaskModel = defineSchemaModel({
32
+ name: 'ReviewTask',
33
+ description: 'Human verification task for a change candidate.',
34
+ fields: {
35
+ id: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
36
+ changeCandidateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ status: { type: ScalarTypeEnum.String_unsecure(), isOptional: false }, // open|decided
38
+ assignedRole: { type: ReviewAssignedRoleEnum, isOptional: false },
39
+ decision: { type: ReviewDecisionEnum, isOptional: true },
40
+ decidedAt: { type: ScalarTypeEnum.DateTime(), isOptional: true },
41
+ decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
42
+ },
43
+ });
44
+
45
+
package/src/events.ts ADDED
@@ -0,0 +1,92 @@
1
+ import { defineEvent, defineSchemaModel } from '@lssm/lib.contracts';
2
+ import { ScalarTypeEnum } from '@lssm/lib.schema';
3
+
4
+ const KbChangeDetectedPayload = defineSchemaModel({
5
+ name: 'KbChangeDetectedPayload',
6
+ description: 'Emitted when a source change is detected.',
7
+ fields: {
8
+ changeCandidateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
9
+ sourceDocumentId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
10
+ riskLevel: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
11
+ },
12
+ });
13
+
14
+ export const KbChangeDetectedEvent = defineEvent({
15
+ name: 'kb.change.detected',
16
+ version: 1,
17
+ description: 'KB source change detected.',
18
+ payload: KbChangeDetectedPayload,
19
+ });
20
+
21
+ const KbChangeSummarizedPayload = defineSchemaModel({
22
+ name: 'KbChangeSummarizedPayload',
23
+ description: 'Emitted when a change summary is produced.',
24
+ fields: {
25
+ changeCandidateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
26
+ summary: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
27
+ riskLevel: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
28
+ },
29
+ });
30
+
31
+ export const KbChangeSummarizedEvent = defineEvent({
32
+ name: 'kb.change.summarized',
33
+ version: 1,
34
+ description: 'KB change summarized.',
35
+ payload: KbChangeSummarizedPayload,
36
+ });
37
+
38
+ const KbPatchProposedPayload = defineSchemaModel({
39
+ name: 'KbPatchProposedPayload',
40
+ description: 'Emitted when draft rule patches are proposed.',
41
+ fields: {
42
+ changeCandidateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
43
+ proposedRuleVersionIds: {
44
+ type: ScalarTypeEnum.String_unsecure(),
45
+ isArray: true,
46
+ isOptional: false,
47
+ },
48
+ },
49
+ });
50
+
51
+ export const KbPatchProposedEvent = defineEvent({
52
+ name: 'kb.patch.proposed',
53
+ version: 1,
54
+ description: 'KB rule patch proposed (draft versions created).',
55
+ payload: KbPatchProposedPayload,
56
+ });
57
+
58
+ const KbReviewRequestedPayload = defineSchemaModel({
59
+ name: 'KbReviewRequestedPayload',
60
+ description: 'Emitted when a review is requested.',
61
+ fields: {
62
+ reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
63
+ changeCandidateId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
64
+ assignedRole: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
65
+ },
66
+ });
67
+
68
+ export const KbReviewRequestedEvent = defineEvent({
69
+ name: 'kb.review.requested',
70
+ version: 1,
71
+ description: 'KB review requested.',
72
+ payload: KbReviewRequestedPayload,
73
+ });
74
+
75
+ const KbReviewDecidedPayload = defineSchemaModel({
76
+ name: 'KbReviewDecidedPayload',
77
+ description: 'Emitted when a review task is decided.',
78
+ fields: {
79
+ reviewTaskId: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
80
+ decision: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
81
+ decidedBy: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
82
+ },
83
+ });
84
+
85
+ export const KbReviewDecidedEvent = defineEvent({
86
+ name: 'kb.review.decided',
87
+ version: 1,
88
+ description: 'KB review decided.',
89
+ payload: KbReviewDecidedPayload,
90
+ });
91
+
92
+
package/src/example.ts ADDED
@@ -0,0 +1,29 @@
1
+ const example = {
2
+ id: 'kb-update-pipeline',
3
+ title: 'KB Update Pipeline',
4
+ summary:
5
+ 'Automation proposes KB updates; humans verify; everything audited and notified.',
6
+ tags: ['knowledge', 'pipeline', 'hitl', 'audit'],
7
+ kind: 'knowledge',
8
+ visibility: 'public',
9
+ docs: {
10
+ rootDocId: 'docs.examples.kb-update-pipeline',
11
+ },
12
+ entrypoints: {
13
+ packageName: '@lssm/example.kb-update-pipeline',
14
+ feature: './feature',
15
+ contracts: './contracts',
16
+ handlers: './handlers',
17
+ docs: './docs',
18
+ },
19
+ surfaces: {
20
+ templates: true,
21
+ sandbox: { enabled: true, modes: ['markdown', 'specs', 'builder'] },
22
+ studio: { enabled: true, installable: true },
23
+ mcp: { enabled: true },
24
+ },
25
+ } as const;
26
+
27
+ export default example;
28
+
29
+
package/src/feature.ts ADDED
@@ -0,0 +1,39 @@
1
+ import type { FeatureModuleSpec } from '@lssm/lib.contracts';
2
+
3
+ export const KbUpdatePipelineFeature: FeatureModuleSpec = {
4
+ meta: {
5
+ key: 'kb-update-pipeline',
6
+ title: 'KB Update Pipeline (HITL)',
7
+ description:
8
+ 'Automation proposes KB patches; humans verify; publishing is blocked until approvals are complete.',
9
+ domain: 'knowledge',
10
+ owners: ['examples'],
11
+ tags: ['knowledge', 'pipeline', 'hitl', 'audit', 'notifications'],
12
+ stability: 'experimental',
13
+ },
14
+ operations: [
15
+ { name: 'kbPipeline.runWatch', version: 1 },
16
+ { name: 'kbPipeline.createReviewTask', version: 1 },
17
+ { name: 'kbPipeline.submitDecision', version: 1 },
18
+ { name: 'kbPipeline.publishIfReady', version: 1 },
19
+ ],
20
+ events: [
21
+ { name: 'kb.change.detected', version: 1 },
22
+ { name: 'kb.change.summarized', version: 1 },
23
+ { name: 'kb.patch.proposed', version: 1 },
24
+ { name: 'kb.review.requested', version: 1 },
25
+ { name: 'kb.review.decided', version: 1 },
26
+ ],
27
+ presentations: [],
28
+ opToPresentation: [],
29
+ presentationsTargets: [],
30
+ capabilities: {
31
+ requires: [
32
+ { key: 'identity', version: 1 },
33
+ { key: 'notifications', version: 1 },
34
+ { key: 'audit-trail', version: 1 },
35
+ ],
36
+ },
37
+ };
38
+
39
+
@@ -0,0 +1,3 @@
1
+ export * from './memory.handlers';
2
+
3
+