@kb-labs/mind-contracts 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # @kb-labs/mind-contracts
2
+
3
+ Public contracts for the KB Labs Mind plugin. Declares artifacts, commands, workflows, and API guarantees for consumers.
4
+
5
+ ## Vision & Purpose
6
+
7
+ **@kb-labs/mind-contracts** provides public contracts for KB Labs Mind. It describes the guarantees that other products (CLI, Studio, REST gateway, Workflow Engine) can rely on without depending on Mind runtime code.
8
+
9
+ ### Core Goals
10
+
11
+ - **Contract Definition**: Define public contracts for Mind
12
+ - **Schema Validation**: Zod schemas for validation
13
+ - **Type Safety**: TypeScript types derived from schemas
14
+ - **Versioning**: SemVer-based contract versioning
15
+
16
+ ## Package Status
17
+
18
+ - **Version**: 0.1.0
19
+ - **Stage**: Stable
20
+ - **Status**: Production Ready ✅
21
+
22
+ ## Architecture
23
+
24
+ ### High-Level Overview
25
+
26
+ ```
27
+ Mind Contracts
28
+
29
+ ├──► Contract Manifest
30
+ ├──► Zod Schemas
31
+ ├──► TypeScript Types
32
+ └──► Helper Parsers
33
+ ```
34
+
35
+ ### Key Components
36
+
37
+ 1. **Contract Manifest** (`contract.ts`): Plugin contracts manifest
38
+ 2. **Schemas** (`schema/`): Zod validation schemas
39
+ 3. **Types** (`types.ts`): TypeScript type definitions
40
+ 4. **Parsers** (`schema.ts`): Helper parsers
41
+
42
+ ## ✨ Features
43
+
44
+ - **Contract Manifest**: Typed declaration of Mind artifacts, commands, workflows, and REST routes
45
+ - **Zod Schemas**: Validation schemas for CLI flag definitions, query DTOs, REST responses, Studio widgets
46
+ - **TypeScript Types**: Type definitions for command inputs/outputs
47
+ - **Helper Parsers**: `parsePluginContracts` for runtime validation
48
+
49
+ ## 📦 API Reference
50
+
51
+ ### Main Exports
52
+
53
+ #### Contract Manifest
54
+
55
+ - `pluginContractsManifest`: Typed declaration of Mind artifacts, commands, workflows, and REST routes
56
+ - `contractsVersion`: SemVer version for contract coordination
57
+ - `contractsSchemaId`: Schema ID for contract validation
58
+
59
+ #### Schemas
60
+
61
+ - `parsePluginContracts`: Parse plugin contracts
62
+ - `pluginContractsSchema`: Plugin contracts schema
63
+
64
+ #### Types
65
+
66
+ - `PluginContracts`: Plugin contracts type
67
+ - `ArtifactDecl`: Artifact declaration type
68
+ - `CommandDecl`: Command declaration type
69
+
70
+ ## 🔧 Configuration
71
+
72
+ ### Configuration Options
73
+
74
+ No configuration needed - pure contract definitions.
75
+
76
+ ## 🔗 Dependencies
77
+
78
+ ### Runtime Dependencies
79
+
80
+ - `zod` (`^3.23.8`): Schema validation
81
+
82
+ ### Development Dependencies
83
+
84
+ - `@kb-labs/devkit` (`link:../../../kb-labs-devkit`): DevKit presets
85
+ - `@types/node` (`^24.7.0`): Node.js types
86
+ - `semver` (`^7.6.3`): SemVer parsing
87
+ - `tsup` (`^8.5.0`): TypeScript bundler
88
+ - `typescript` (`^5.6.3`): TypeScript compiler
89
+ - `vitest` (`^3.2.4`): Test runner
90
+
91
+ ## 🧪 Testing
92
+
93
+ ### Test Structure
94
+
95
+ ```
96
+ tests/
97
+ └── contracts.manifest.test.ts
98
+ ```
99
+
100
+ ### Test Coverage
101
+
102
+ - **Current Coverage**: ~70%
103
+ - **Target Coverage**: 90%
104
+
105
+ ## 📈 Performance
106
+
107
+ ### Performance Characteristics
108
+
109
+ - **Time Complexity**: O(1) for type operations, O(n) for schema validation
110
+ - **Space Complexity**: O(1)
111
+ - **Bottlenecks**: Schema validation for large payloads
112
+
113
+ ## 🔒 Security
114
+
115
+ ### Security Considerations
116
+
117
+ - **Schema Validation**: Input validation via Zod schemas
118
+ - **Type Safety**: TypeScript type safety
119
+
120
+ ### Known Vulnerabilities
121
+
122
+ - None
123
+
124
+ ## 🐛 Known Issues & Limitations
125
+
126
+ ### Known Issues
127
+
128
+ - None currently
129
+
130
+ ### Limitations
131
+
132
+ - **Schema Validation**: Basic validation only
133
+
134
+ ### Future Improvements
135
+
136
+ - **Enhanced Validation**: More validation rules
137
+
138
+ ## 🔄 Migration & Breaking Changes
139
+
140
+ ### Versioning Rules
141
+
142
+ - **MAJOR** — breaking changes (removed fields, renamed IDs, incompatible schema updates)
143
+ - **MINOR** — backwards-compatible additions (new flags, artifacts, optional fields)
144
+ - **PATCH** — metadata/documentation tweaks that do not alter payload structure
145
+
146
+ ### Breaking Changes in Future Versions
147
+
148
+ - None planned
149
+
150
+ ## 📚 Examples
151
+
152
+ ### Example 1: Use Contract Manifest
153
+
154
+ ```typescript
155
+ import { pluginContractsManifest } from '@kb-labs/mind-contracts';
156
+
157
+ const queryArtifactId = pluginContractsManifest.artifacts['mind.query.json'].id;
158
+ ```
159
+
160
+ ### Example 2: Parse Plugin Contracts
161
+
162
+ ```typescript
163
+ import { parsePluginContracts } from '@kb-labs/mind-contracts';
164
+
165
+ const contracts = parsePluginContracts(rawManifest);
166
+ ```
167
+
168
+ ## 🤝 Contributing
169
+
170
+ See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development guidelines.
171
+
172
+ ## 📄 License
173
+
174
+ MIT © KB Labs
@@ -0,0 +1,96 @@
1
+ type SchemaFormat = 'zod' | 'json-schema' | 'openapi';
2
+ interface SchemaReference {
3
+ ref: string;
4
+ format?: SchemaFormat;
5
+ description?: string;
6
+ }
7
+ interface RestRouteContract {
8
+ id: string;
9
+ method: string;
10
+ path: string;
11
+ description?: string;
12
+ request?: SchemaReference;
13
+ response?: SchemaReference;
14
+ produces?: string[];
15
+ consumes?: string[];
16
+ }
17
+ interface RestApiContract {
18
+ basePath: string;
19
+ routes: Record<string, RestRouteContract>;
20
+ }
21
+ interface ApiContract {
22
+ rest?: RestApiContract;
23
+ }
24
+
25
+ type ArtifactKind = 'file' | 'json' | 'markdown' | 'binary' | 'dir' | 'log';
26
+ interface ArtifactExample {
27
+ summary?: string;
28
+ payload?: unknown;
29
+ }
30
+ interface PluginArtifactContract {
31
+ id: string;
32
+ kind: ArtifactKind;
33
+ description?: string;
34
+ /**
35
+ * Relative path or glob pattern describing where the artifact is produced.
36
+ */
37
+ pathPattern?: string;
38
+ /**
39
+ * IANA media type describing the artifact (for example: application/json).
40
+ */
41
+ mediaType?: string;
42
+ /**
43
+ * Reference to a schema describing the artifact payload. Can be a URI or package export.
44
+ */
45
+ schemaRef?: string;
46
+ /**
47
+ * Optional example payload to support documentation and tooling.
48
+ */
49
+ example?: ArtifactExample;
50
+ }
51
+ type ArtifactContractsMap = Record<string, PluginArtifactContract>;
52
+
53
+ interface CommandContract {
54
+ id: string;
55
+ description?: string;
56
+ input?: SchemaReference;
57
+ output?: SchemaReference;
58
+ produces?: string[];
59
+ consumes?: string[];
60
+ examples?: string[];
61
+ }
62
+ type CommandContractsMap = Record<string, CommandContract>;
63
+
64
+ interface WorkflowStepContract {
65
+ id: string;
66
+ description?: string;
67
+ commandId?: string;
68
+ consumes?: string[];
69
+ produces?: string[];
70
+ }
71
+ interface WorkflowContract {
72
+ id: string;
73
+ description?: string;
74
+ consumes?: string[];
75
+ produces?: string[];
76
+ steps?: WorkflowStepContract[];
77
+ }
78
+ type WorkflowContractsMap = Record<string, WorkflowContract>;
79
+
80
+ declare const contractsVersion = "1.0.0";
81
+ declare const contractsSchemaId = "@kb-labs/mind-contracts/schema";
82
+ type ContractsSchemaId = typeof contractsSchemaId;
83
+
84
+ interface PluginContracts {
85
+ schema: ContractsSchemaId;
86
+ pluginId: string;
87
+ contractsVersion: string;
88
+ artifacts: ArtifactContractsMap;
89
+ commands?: CommandContractsMap;
90
+ workflows?: WorkflowContractsMap;
91
+ api?: ApiContract;
92
+ }
93
+
94
+ declare const pluginContractsManifest: PluginContracts;
95
+
96
+ export { type ApiContract as A, type CommandContract as C, type PluginContracts as P, type RestApiContract as R, type SchemaReference as S, type WorkflowContract as W, contractsSchemaId as a, type RestRouteContract as b, contractsVersion as c, type ArtifactKind as d, type ArtifactContractsMap as e, type PluginArtifactContract as f, type ArtifactExample as g, type CommandContractsMap as h, type WorkflowContractsMap as i, type WorkflowStepContract as j, pluginContractsManifest as p };
@@ -0,0 +1 @@
1
+ export { p as pluginContractsManifest } from './contract-D8Rjf1rz.js';
@@ -0,0 +1,57 @@
1
+ // src/version.ts
2
+ var contractsVersion = "1.0.0";
3
+ var contractsSchemaId = "@kb-labs/mind-contracts/schema";
4
+
5
+ // src/contract.ts
6
+ var pluginContractsManifest = {
7
+ schema: contractsSchemaId,
8
+ pluginId: "@kb-labs/mind",
9
+ contractsVersion,
10
+ artifacts: {},
11
+ commands: {
12
+ "mind:init": {
13
+ id: "mind:init",
14
+ description: "Initialise the Mind workspace structure.",
15
+ input: {
16
+ ref: "@kb-labs/mind-contracts/schema#MindInitCommandInputSchema",
17
+ format: "zod"
18
+ },
19
+ examples: ["kb mind init --force", "kb mind init --json"]
20
+ },
21
+ "mind:verify": {
22
+ id: "mind:verify",
23
+ description: "Validate Mind indexes and surface inconsistencies.",
24
+ input: {
25
+ ref: "@kb-labs/mind-contracts/schema#MindVerifyCommandInputSchema",
26
+ format: "zod"
27
+ },
28
+ output: {
29
+ ref: "@kb-labs/mind-contracts/schema#MindVerifyCommandOutputSchema",
30
+ format: "zod"
31
+ },
32
+ examples: ["kb mind verify", "kb mind verify --json"]
33
+ }
34
+ },
35
+ workflows: {},
36
+ api: {
37
+ rest: {
38
+ basePath: "/v1/plugins/mind",
39
+ routes: {
40
+ "mind.rest.verify": {
41
+ id: "mind.rest.verify",
42
+ method: "GET",
43
+ path: "/verify",
44
+ description: "Summarise index verification status for Studio dashboards.",
45
+ response: {
46
+ ref: "@kb-labs/mind-contracts/schema#MindVerifyResponseSchema",
47
+ format: "zod"
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ };
54
+ export {
55
+ pluginContractsManifest
56
+ };
57
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/version.ts","../src/contract.ts"],"sourcesContent":["export const contractsVersion = '1.0.0';\nexport const contractsSchemaId = '@kb-labs/mind-contracts/schema';\n\nexport type ContractsSchemaId = typeof contractsSchemaId;\n","import type { PluginContracts } from './types';\nimport { contractsSchemaId, contractsVersion } from './version';\n\nexport const pluginContractsManifest: PluginContracts = {\n schema: contractsSchemaId,\n pluginId: '@kb-labs/mind',\n contractsVersion,\n artifacts: {},\n commands: {\n 'mind:init': {\n id: 'mind:init',\n description: 'Initialise the Mind workspace structure.',\n input: {\n ref: '@kb-labs/mind-contracts/schema#MindInitCommandInputSchema',\n format: 'zod',\n },\n examples: ['kb mind init --force', 'kb mind init --json'],\n },\n 'mind:verify': {\n id: 'mind:verify',\n description: 'Validate Mind indexes and surface inconsistencies.',\n input: {\n ref: '@kb-labs/mind-contracts/schema#MindVerifyCommandInputSchema',\n format: 'zod',\n },\n output: {\n ref: '@kb-labs/mind-contracts/schema#MindVerifyCommandOutputSchema',\n format: 'zod',\n },\n examples: ['kb mind verify', 'kb mind verify --json'],\n },\n },\n workflows: {},\n api: {\n rest: {\n basePath: '/v1/plugins/mind',\n routes: {\n 'mind.rest.verify': {\n id: 'mind.rest.verify',\n method: 'GET',\n path: '/verify',\n description: 'Summarise index verification status for Studio dashboards.',\n response: {\n ref: '@kb-labs/mind-contracts/schema#MindVerifyResponseSchema',\n format: 'zod',\n },\n },\n },\n },\n },\n};\n"],"mappings":";AAAO,IAAM,mBAAmB;AACzB,IAAM,oBAAoB;;;ACE1B,IAAM,0BAA2C;AAAA,EACtD,QAAQ;AAAA,EACR,UAAU;AAAA,EACV;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,UAAU;AAAA,IACR,aAAa;AAAA,MACX,IAAI;AAAA,MACJ,aAAa;AAAA,MACb,OAAO;AAAA,QACL,KAAK;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,MACA,UAAU,CAAC,wBAAwB,qBAAqB;AAAA,IAC1D;AAAA,IACA,eAAe;AAAA,MACb,IAAI;AAAA,MACJ,aAAa;AAAA,MACb,OAAO;AAAA,QACL,KAAK;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,QACN,KAAK;AAAA,QACL,QAAQ;AAAA,MACV;AAAA,MACA,UAAU,CAAC,kBAAkB,uBAAuB;AAAA,IACtD;AAAA,EACF;AAAA,EACA,WAAW,CAAC;AAAA,EACZ,KAAK;AAAA,IACH,MAAM;AAAA,MACJ,UAAU;AAAA,MACV,QAAQ;AAAA,QACN,oBAAoB;AAAA,UAClB,IAAI;AAAA,UACJ,QAAQ;AAAA,UACR,MAAM;AAAA,UACN,aAAa;AAAA,UACb,UAAU;AAAA,YACR,KAAK;AAAA,YACL,QAAQ;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,95 @@
1
+ export { A as ApiContract, e as ArtifactContractsMap, g as ArtifactExample, d as ArtifactKind, C as CommandContract, h as CommandContractsMap, f as PluginArtifactContract, P as PluginContracts, R as RestApiContract, b as RestRouteContract, S as SchemaReference, W as WorkflowContract, i as WorkflowContractsMap, j as WorkflowStepContract, a as contractsSchemaId, c as contractsVersion, p as pluginContractsManifest } from './contract-D8Rjf1rz.js';
2
+ export { MindFeedCommandInputSchema, MindFeedCommandOutputSchema, MindInitCommandInputSchema, MindPackCommandInputSchema, MindPackCommandOutputSchema, MindQueryCommandInputSchema, MindQueryCommandOutputSchema, MindQueryRequestSchema, MindQueryResponseSchema, MindUpdateCommandInputSchema, MindUpdateCommandOutputSchema, MindVerifyCommandInputSchema, MindVerifyCommandOutputSchema, MindVerifyResponseSchema, PluginContractsSchema, apiContractSchema, artifactContractSchema, artifactExampleSchema, artifactsContractMapSchema, commandContractMapSchema, commandContractSchema, parsePluginContracts, pluginContractsSchema, restApiContractSchema, restRouteContractSchema, schemaReferenceSchema, workflowContractMapSchema, workflowContractSchema, workflowStepSchema } from './schema.js';
3
+ import 'zod';
4
+
5
+ /**
6
+ * Registry configuration for Mind sync
7
+ */
8
+ interface MindSyncRegistryConfig {
9
+ type: 'filesystem';
10
+ path: string;
11
+ }
12
+ /**
13
+ * Soft delete configuration for Mind sync
14
+ */
15
+ interface MindSyncSoftDeleteConfig {
16
+ enabled: boolean;
17
+ ttlDays: number;
18
+ }
19
+ /**
20
+ * Partial updates configuration for Mind sync
21
+ */
22
+ interface MindSyncPartialUpdatesConfig {
23
+ enabled: boolean;
24
+ }
25
+ /**
26
+ * Batch processing configuration for Mind sync
27
+ */
28
+ interface MindSyncBatchConfig {
29
+ maxSize: number;
30
+ }
31
+ /**
32
+ * Mind synchronization configuration
33
+ */
34
+ interface MindSyncConfig {
35
+ registry: MindSyncRegistryConfig;
36
+ softDelete: MindSyncSoftDeleteConfig;
37
+ partialUpdates: MindSyncPartialUpdatesConfig;
38
+ batch: MindSyncBatchConfig;
39
+ }
40
+ /**
41
+ * Mind source configuration
42
+ */
43
+ interface MindSourceConfig {
44
+ id: string;
45
+ paths: string[];
46
+ exclude?: string[];
47
+ }
48
+ /**
49
+ * Mind engine configuration
50
+ */
51
+ interface MindEngineConfig {
52
+ id: string;
53
+ type: string;
54
+ options?: Record<string, unknown>;
55
+ }
56
+ /**
57
+ * Mind scope configuration
58
+ */
59
+ interface MindScopeConfig {
60
+ id: string;
61
+ sourceIds?: string[];
62
+ defaultEngine?: string;
63
+ include?: string[];
64
+ exclude?: string[];
65
+ }
66
+ /**
67
+ * Mind defaults configuration
68
+ */
69
+ interface MindDefaultsConfig {
70
+ fallbackEngineId?: string;
71
+ }
72
+ /**
73
+ * Canonical Mind configuration input
74
+ */
75
+ interface MindConfigInput {
76
+ sources: MindSourceConfig[];
77
+ scopes: MindScopeConfig[];
78
+ engines: MindEngineConfig[];
79
+ defaults?: MindDefaultsConfig;
80
+ }
81
+ /**
82
+ * Mind configuration with sync section
83
+ */
84
+ interface MindConfig extends MindConfigInput {
85
+ /**
86
+ * Synchronization settings for Mind
87
+ */
88
+ sync?: MindSyncConfig;
89
+ }
90
+ /**
91
+ * Default sync configuration
92
+ */
93
+ declare const defaultMindSyncConfig: MindSyncConfig;
94
+
95
+ export { type MindConfig, type MindConfigInput, type MindDefaultsConfig, type MindEngineConfig, type MindScopeConfig, type MindSourceConfig, type MindSyncBatchConfig, type MindSyncConfig, type MindSyncPartialUpdatesConfig, type MindSyncRegistryConfig, type MindSyncSoftDeleteConfig, defaultMindSyncConfig };