@kb-labs/mind-entry 2.93.0 → 2.96.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.
Files changed (98) hide show
  1. package/README.md +19 -208
  2. package/dist/cli/commands/ask.d.ts +31 -0
  3. package/dist/cli/commands/ask.js +88 -0
  4. package/dist/cli/commands/ask.js.map +1 -0
  5. package/dist/cli/commands/drop.d.ts +10 -0
  6. package/dist/cli/commands/drop.js +90 -0
  7. package/dist/cli/commands/drop.js.map +1 -0
  8. package/dist/cli/commands/explore.d.ts +26 -0
  9. package/dist/cli/commands/explore.js +96 -0
  10. package/dist/cli/commands/explore.js.map +1 -0
  11. package/dist/cli/commands/index.d.ts +11 -0
  12. package/dist/cli/commands/index.js +96 -0
  13. package/dist/cli/commands/index.js.map +1 -0
  14. package/dist/cli/commands/reindex.d.ts +11 -0
  15. package/dist/cli/commands/reindex.js +71 -0
  16. package/dist/cli/commands/reindex.js.map +1 -0
  17. package/dist/cli/commands/search.d.ts +25 -0
  18. package/dist/cli/commands/search.js +94 -0
  19. package/dist/cli/commands/search.js.map +1 -0
  20. package/dist/cli/commands/status.d.ts +17 -0
  21. package/dist/cli/commands/status.js +89 -0
  22. package/dist/cli/commands/status.js.map +1 -0
  23. package/dist/cli/commands/sync-add.d.ts +11 -0
  24. package/dist/cli/commands/sync-add.js +74 -0
  25. package/dist/cli/commands/sync-add.js.map +1 -0
  26. package/dist/cli/commands/sync-delete.d.ts +11 -0
  27. package/dist/cli/commands/sync-delete.js +90 -0
  28. package/dist/cli/commands/sync-delete.js.map +1 -0
  29. package/dist/cli/commands/sync-list.d.ts +13 -0
  30. package/dist/cli/commands/sync-list.js +80 -0
  31. package/dist/cli/commands/sync-list.js.map +1 -0
  32. package/dist/cli/commands/sync-status.d.ts +8 -0
  33. package/dist/cli/commands/sync-status.js +71 -0
  34. package/dist/cli/commands/sync-status.js.map +1 -0
  35. package/dist/cli/commands/sync-update.d.ts +11 -0
  36. package/dist/cli/commands/sync-update.js +74 -0
  37. package/dist/cli/commands/sync-update.js.map +1 -0
  38. package/dist/index.d.ts +2 -596
  39. package/dist/index.js +208 -1449
  40. package/dist/index.js.map +1 -1
  41. package/dist/manifest.d.ts +206 -0
  42. package/dist/manifest.js +261 -0
  43. package/dist/manifest.js.map +1 -0
  44. package/dist/rest/handlers/drop.d.ts +12 -0
  45. package/dist/rest/handlers/drop.js +59 -0
  46. package/dist/rest/handlers/drop.js.map +1 -0
  47. package/dist/rest/handlers/explore.d.ts +30 -0
  48. package/dist/rest/handlers/explore.js +59 -0
  49. package/dist/rest/handlers/explore.js.map +1 -0
  50. package/dist/rest/handlers/health.d.ts +11 -0
  51. package/dist/rest/handlers/health.js +58 -0
  52. package/dist/rest/handlers/health.js.map +1 -0
  53. package/dist/rest/handlers/index.d.ts +15 -0
  54. package/dist/rest/handlers/index.js +59 -0
  55. package/dist/rest/handlers/index.js.map +1 -0
  56. package/dist/rest/handlers/query.d.ts +36 -0
  57. package/dist/rest/handlers/query.js +59 -0
  58. package/dist/rest/handlers/query.js.map +1 -0
  59. package/dist/rest/handlers/reindex.d.ts +14 -0
  60. package/dist/rest/handlers/reindex.js +59 -0
  61. package/dist/rest/handlers/reindex.js.map +1 -0
  62. package/dist/rest/handlers/search.d.ts +31 -0
  63. package/dist/rest/handlers/search.js +59 -0
  64. package/dist/rest/handlers/search.js.map +1 -0
  65. package/dist/rest/handlers/status.d.ts +19 -0
  66. package/dist/rest/handlers/status.js +58 -0
  67. package/dist/rest/handlers/status.js.map +1 -0
  68. package/dist/rest/handlers/sync-add.d.ts +14 -0
  69. package/dist/rest/handlers/sync-add.js +59 -0
  70. package/dist/rest/handlers/sync-add.js.map +1 -0
  71. package/dist/rest/handlers/sync-delete.d.ts +14 -0
  72. package/dist/rest/handlers/sync-delete.js +59 -0
  73. package/dist/rest/handlers/sync-delete.js.map +1 -0
  74. package/dist/rest/handlers/sync-list.d.ts +15 -0
  75. package/dist/rest/handlers/sync-list.js +58 -0
  76. package/dist/rest/handlers/sync-list.js.map +1 -0
  77. package/dist/rest/handlers/sync-status.d.ts +14 -0
  78. package/dist/rest/handlers/sync-status.js +58 -0
  79. package/dist/rest/handlers/sync-status.js.map +1 -0
  80. package/dist/rest/handlers/sync-update.d.ts +14 -0
  81. package/dist/rest/handlers/sync-update.js +59 -0
  82. package/dist/rest/handlers/sync-update.js.map +1 -0
  83. package/package.json +15 -19
  84. package/dist/cli/commands/init.d.ts +0 -24
  85. package/dist/cli/commands/init.js +0 -115
  86. package/dist/cli/commands/init.js.map +0 -1
  87. package/dist/cli/commands/rag-index.d.ts +0 -20
  88. package/dist/cli/commands/rag-index.js +0 -364
  89. package/dist/cli/commands/rag-index.js.map +0 -1
  90. package/dist/cli/commands/rag-query.d.ts +0 -25
  91. package/dist/cli/commands/rag-query.js +0 -670
  92. package/dist/cli/commands/rag-query.js.map +0 -1
  93. package/dist/cli/commands/verify.d.ts +0 -15
  94. package/dist/cli/commands/verify.js +0 -92
  95. package/dist/cli/commands/verify.js.map +0 -1
  96. package/dist/manifest.v3.d.ts +0 -52
  97. package/dist/manifest.v3.js +0 -182
  98. package/dist/manifest.v3.js.map +0 -1
package/README.md CHANGED
@@ -1,218 +1,29 @@
1
- # @kb-labs/mind-cli
1
+ # @kb-labs/mind-entry
2
2
 
3
- CLI commands for KB Labs Mind.
3
+ Plugin entry point for KB Labs **Mind** (RAG) — the manifest that wires the
4
+ engine (`@kb-labs/mind-core`) to the platform: CLI commands, REST routes, and
5
+ permissions. Imports only `@kb-labs/sdk`.
4
6
 
5
- ## Vision & Purpose
6
-
7
- **@kb-labs/mind-cli** provides CLI commands for KB Labs Mind. It includes commands for indexing, querying, packing, and verifying Mind indexes, plus REST handlers and Studio widgets.
8
-
9
- ### Core Goals
10
-
11
- - **Indexing Commands**: Index codebase and update indexes
12
- - **Query Commands**: Query Mind indexes
13
- - **Pack Commands**: Build context packs
14
- - **Verify Commands**: Verify Mind indexes
15
- - **REST Handlers**: REST API handlers
16
- - **Studio Widgets**: Studio widget implementations
17
-
18
- ## Package Status
19
-
20
- - **Version**: 0.1.0
21
- - **Stage**: Stable
22
- - **Status**: Production Ready ✅
23
-
24
- ## Architecture
25
-
26
- ### High-Level Overview
27
-
28
- ```
29
- Mind CLI
30
-
31
- ├──► CLI Commands
32
- ├──► Application Layer
33
- ├──► Domain Layer
34
- ├──► Infrastructure Layer
35
- ├──► REST Handlers
36
- └──► Studio Widgets
37
- ```
38
-
39
- ### Key Components
40
-
41
- 1. **CLI Commands** (`cli/`): CLI command implementations
42
- 2. **Application Layer** (`application/`): Use cases and services
43
- 3. **Domain Layer** (`domain/`): Domain logic
44
- 4. **Infrastructure Layer** (`infra/`): Adapters and infrastructure
45
- 5. **REST Handlers** (`rest/`): REST API handlers
46
- 6. **Studio Widgets** (`studio/`): Studio widget implementations
47
-
48
- ## ✨ Features
49
-
50
- - **Indexing Commands**: Index codebase and update indexes
51
- - **Query Commands**: Query Mind indexes
52
- - **Pack Commands**: Build context packs
53
- - **Verify Commands**: Verify Mind indexes
54
- - **REST Handlers**: REST API handlers
55
- - **Studio Widgets**: Query and verify widgets for Studio
56
-
57
- ## 📦 API Reference
58
-
59
- ### Main Exports
60
-
61
- #### CLI Commands
62
-
63
- - `index`: Index codebase command
64
- - `query`: Query Mind index command
65
- - `pack`: Build context pack command
66
- - `verify`: Verify Mind index command
67
-
68
- #### Manifest
69
-
70
- - `manifest`: Plugin manifest V2
71
-
72
- ## 🔧 Configuration
73
-
74
- ### Configuration Options
75
-
76
- All configuration via CLI flags and kb-labs.config.json.
77
-
78
- ### CLI Flags
79
-
80
- - `--json`: Output JSON format
81
- - `--quiet`: Quiet mode
82
- - `--verbose`: Verbose output
83
-
84
- ## 🔗 Dependencies
85
-
86
- ### Runtime Dependencies
87
-
88
- - `@byjohann/toon` (`0.4.0`): Terminal UI library
89
- - `@kb-labs/analytics-sdk-node` (`link:../../../kb-labs-analytics/packages/analytics-sdk-node`): Analytics SDK
90
- - `@kb-labs/core` (`link:../../../kb-labs-core`): Core package
91
- - `@kb-labs/plugin-manifest` (`link:../../../kb-labs-plugin/packages/manifest`): Plugin manifest
92
- - `@kb-labs/plugin-adapter-studio` (`link:../../../kb-labs-plugin/packages/adapters/studio`): Studio adapter
93
- - `@kb-labs/mind-contracts` (`link:../contracts`): Mind contracts
94
- - `@kb-labs/mind-gateway` (`link:../mind-gateway`): Mind gateway
95
- - `@kb-labs/mind-core` (`link:../mind-core`): Mind core
96
- - `@kb-labs/mind-indexer` (`link:../mind-indexer`): Mind indexer
97
- - `@kb-labs/mind-pack` (`link:../mind-pack`): Mind pack
98
- - `@kb-labs/mind-query` (`link:../mind-query`): Mind query
99
- - `@kb-labs/mind-types` (`link:../mind-types`): Mind types
100
- - `@kb-labs/shared-cli-ui` (`link:../../../kb-labs-shared/packages/cli-ui`): Shared CLI UI
101
- - `@tanstack/react-query` (`^5.0.0`): React Query
102
- - `@aws-sdk/client-s3` (`^3.929.0`): AWS S3 client
103
- - `ajv` (`^8.17.1`): JSON schema validation
104
- - `ajv-formats` (`^3.0.1`): AJV formats
105
- - `glob` (`^11.0.0`): File globbing
106
- - `react` (`^18.0.0`): React
107
- - `uuidv7` (`^1.0.0`): UUID v7 generation
108
- - `yaml` (`^2.8.0`): YAML parsing
109
- - `zod` (`^3.23.8`): Schema validation
110
-
111
- ### Development Dependencies
112
-
113
- - `@kb-labs/devkit` (`link:../../../kb-labs-devkit`): DevKit presets
114
- - `@types/node` (`^24.7.0`): Node.js types
115
- - `@types/react` (`^18.3.18`): React types
116
- - `tsup` (`^8.5.0`): TypeScript bundler
117
- - `typescript` (`^5.6.3`): TypeScript compiler
118
- - `vitest` (`^3.2.4`): Test runner
119
-
120
- ## 🧪 Testing
121
-
122
- ### Test Structure
123
-
124
- ```
125
- src/__tests__/
126
- └── (13 test files)
127
- ```
128
-
129
- ### Test Coverage
130
-
131
- - **Current Coverage**: ~75%
132
- - **Target Coverage**: 90%
133
-
134
- ## 📈 Performance
135
-
136
- ### Performance Characteristics
137
-
138
- - **Time Complexity**: O(1) for command registration, O(n) for command execution
139
- - **Space Complexity**: O(1)
140
- - **Bottlenecks**: Indexing and query operations
141
-
142
- ## 🔒 Security
143
-
144
- ### Security Considerations
145
-
146
- - **Input Validation**: Command input validation
147
- - **Path Validation**: Path validation for file operations
148
-
149
- ### Known Vulnerabilities
150
-
151
- - None
152
-
153
- ## 🐛 Known Issues & Limitations
154
-
155
- ### Known Issues
156
-
157
- - None currently
158
-
159
- ### Limitations
160
-
161
- ## Breaking changes (no legacy compatibility)
162
-
163
- - `runRagQuery` response field `knowledge` renamed to `result`.
164
- - Runtime wrappers `createKnowledgeService/createKnowledgeEngineRegistry` removed from `mind-cli`.
165
- - Config resolution now supports only `.kb/kb.config.json` and `kb.config.json` with `profiles[].products.mind` (or root `mind`).
166
- - Legacy `knowledge.json` and top-level `knowledge` config are rejected.
167
-
168
- - **Command Types**: Fixed command types
169
- - **Output Formats**: Fixed output formats
170
-
171
- ### Future Improvements
172
-
173
- - **More Commands**: Additional commands
174
- - **Custom Output Formats**: Custom output format support
175
-
176
- ## 🔄 Migration & Breaking Changes
177
-
178
- ### Migration from Previous Versions
179
-
180
- No breaking changes in current version (0.1.0).
181
-
182
- ### Breaking Changes in Future Versions
183
-
184
- - None planned
185
-
186
- ## 📚 Examples
187
-
188
- ### Example 1: Index Codebase
189
-
190
- ```bash
191
- kb mind:index
192
- ```
193
-
194
- ### Example 2: Query Mind Index
7
+ ## CLI
195
8
 
196
9
  ```bash
197
- kb mind:query --query impact --params '{"symbol":"MyFunction"}'
10
+ kb mind index [--index <id>] [--scope <glob>] [--root <path>] [--full]
11
+ kb mind search --text "<query>" [--index <id>] [--snippet none|line|full] [--format json]
12
+ kb mind ask --text "<question>" [--index <id>] [--mode instant|auto|thinking] [--agent]
13
+ kb mind explore --task "<task>" [--index <id>] # task-orientation file map
14
+ kb mind sync add|update|delete <paths…> [--index <id>]
15
+ kb mind status [--index <id>]
198
16
  ```
199
17
 
200
- ### Example 3: Build Context Pack
201
-
202
- ```bash
203
- kb mind:pack --intent "Review this code change"
204
- ```
205
-
206
- ### Example 4: Verify Index
207
-
208
- ```bash
209
- kb mind:verify
210
- ```
18
+ Agent contract: `… --format json | grep "^{"` emits a single-line JSON response
19
+ (pointers + provenance/freshness, not payloads).
211
20
 
212
- ## 🤝 Contributing
21
+ ## REST
213
22
 
214
- See [CONTRIBUTING.md](../../CONTRIBUTING.md) for development guidelines.
23
+ Mounted under `MIND_BASE_PATH` (`/api/v1/plugins/mind`): `POST /index`,
24
+ `/search`, `/query`, `/explore`, `/reindex`, `/sync/*`; `GET /status`, `/health`.
215
25
 
216
- ## 📄 License
26
+ ## Tests
217
27
 
218
- MIT © KB Labs
28
+ - Unit/integration `pnpm --filter @kb-labs/mind-entry test`
29
+ - CLI handler (CLI↔REST parity) — `pnpm --filter @kb-labs/mind-entry test:cli`
@@ -0,0 +1,31 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+ import { CLIInput } from '@kb-labs/sdk';
3
+
4
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, CLIInput<any>, {
5
+ confidence: number;
6
+ answer: string;
7
+ abstained: boolean;
8
+ sources: {
9
+ file: string;
10
+ lines: [number, number];
11
+ kind: "code" | "file" | "doc" | "adr" | "repo" | "config" | "external";
12
+ matchedBy: "lexical" | "semantic" | "both";
13
+ stale: boolean;
14
+ snippet?: string | undefined;
15
+ }[];
16
+ meta: {
17
+ requestId: string;
18
+ mode: "instant" | "auto" | "thinking";
19
+ timingMs: number;
20
+ indexId: string;
21
+ } & {
22
+ [k: string]: unknown;
23
+ };
24
+ warnings?: {
25
+ code: string;
26
+ message: string;
27
+ details?: Record<string, unknown> | undefined;
28
+ }[] | undefined;
29
+ }>;
30
+
31
+ export { _default as default };
@@ -0,0 +1,88 @@
1
+ import { defineCommand, handleError, useVectorStore, useEmbeddings, useStorage, useCache, useLLM, useLogger, useConfig } from '@kb-labs/sdk';
2
+ import { QueryRequestSchema, resolveMindConfig } from '@kb-labs/mind-contracts';
3
+ import { createMind } from '@kb-labs/mind-core';
4
+
5
+ // src/cli/commands/ask.ts
6
+ function buildServices() {
7
+ const vectorStore = useVectorStore();
8
+ const embeddings = useEmbeddings();
9
+ const storage = useStorage();
10
+ const cache = useCache();
11
+ const llm = useLLM();
12
+ const logger = useLogger();
13
+ const missing = [];
14
+ if (!vectorStore) {
15
+ missing.push("vectorStore");
16
+ }
17
+ if (!embeddings) {
18
+ missing.push("embeddings");
19
+ }
20
+ if (!storage) {
21
+ missing.push("storage");
22
+ }
23
+ if (!cache) {
24
+ missing.push("cache");
25
+ }
26
+ if (!llm) {
27
+ missing.push("llm");
28
+ }
29
+ if (missing.length > 0) {
30
+ throw new Error(
31
+ `mind: required platform adapters not configured: ${missing.join(", ")}. Configure them in .kb/kb.config.json under "adapters".`
32
+ );
33
+ }
34
+ return { vectorStore, embeddings, storage, cache, llm, logger };
35
+ }
36
+ async function loadConfig() {
37
+ const raw = await useConfig();
38
+ return resolveMindConfig(raw ?? {});
39
+ }
40
+ async function buildMind(cwd) {
41
+ return createMind(buildServices(), await loadConfig(), { cwd: cwd ?? process.cwd() });
42
+ }
43
+
44
+ // src/cli/commands/ask.ts
45
+ var ask_default = defineCommand({
46
+ id: "mind:ask",
47
+ description: "Ask a question and get a grounded answer with citations",
48
+ handler: {
49
+ async execute(ctx, input) {
50
+ const { flags } = input;
51
+ const json = flags.agent || flags.format === "json" || flags.json;
52
+ try {
53
+ const req = QueryRequestSchema.parse({
54
+ text: flags.text,
55
+ indexId: flags.index,
56
+ mode: flags.mode,
57
+ snippet: flags.snippet
58
+ });
59
+ const mind = await buildMind(ctx.cwd);
60
+ const res = await mind.ask(req);
61
+ if (json) {
62
+ ctx.ui?.json?.(res);
63
+ return { exitCode: 0, result: res };
64
+ }
65
+ const head = res.abstained ? `\u26A0 low confidence (${res.confidence.toFixed(2)}) \u2014 answer may be unreliable` : `answer (confidence ${res.confidence.toFixed(2)})`;
66
+ ctx.ui?.success?.(head, {
67
+ sections: [
68
+ { header: "Answer", items: [res.answer] },
69
+ {
70
+ header: "Sources",
71
+ items: res.sources.map(
72
+ (s) => `${s.file}:${s.lines[0]}-${s.lines[1]} [${s.matchedBy}${s.stale ? ", stale" : ""}]`
73
+ )
74
+ }
75
+ ]
76
+ });
77
+ return { exitCode: 0, result: res };
78
+ } catch (err) {
79
+ handleError(ctx, err, json);
80
+ return { exitCode: 1 };
81
+ }
82
+ }
83
+ }
84
+ });
85
+
86
+ export { ask_default as default };
87
+ //# sourceMappingURL=ask.js.map
88
+ //# sourceMappingURL=ask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/platform.ts","../../../src/cli/commands/ask.ts"],"names":[],"mappings":";;;;;AAqBO,SAAS,aAAA,GAA8B;AAC5C,EAAA,MAAM,cAAc,cAAA,EAAe;AACnC,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,MAAM,UAAU,UAAA,EAAW;AAC3B,EAAA,MAAM,QAAQ,QAAA,EAAS;AACvB,EAAA,MAAM,MAAM,MAAA,EAAO;AACnB,EAAA,MAAM,SAAS,SAAA,EAAU;AAEzB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,OAAA,CAAQ,KAAK,aAAa,CAAA;AAAA,EAC5B;AACA,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAA,CAAQ,KAAK,YAAY,CAAA;AAAA,EAC3B;AACA,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAA,CAAQ,KAAK,SAAS,CAAA;AAAA,EACxB;AACA,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,OAAA,CAAQ,KAAK,OAAO,CAAA;AAAA,EACtB;AACA,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AAAA,EACpB;AACA,EAAA,IAAI,OAA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plugin touches platform hooks.\n *\n * Assembles `MindServices` from `@kb-labs/sdk` hooks and resolves the plugin\n * config. CLI commands and REST handlers both call `buildMind(...)` so they\n * drive the exact same engine.\n */\n\nimport {\n useVectorStore,\n useEmbeddings,\n useStorage,\n useCache,\n useLLM,\n useLogger,\n useConfig,\n} from '@kb-labs/sdk';\nimport { createMind, type Mind, type MindServices } from '@kb-labs/mind-core';\nimport { resolveMindConfig, type MindConfigInput } from '@kb-labs/mind-contracts';\n\n/** Build MindServices from platform hooks, failing fast on missing required adapters. */\nexport function buildServices(): MindServices {\n const vectorStore = useVectorStore();\n const embeddings = useEmbeddings();\n const storage = useStorage();\n const cache = useCache();\n const llm = useLLM();\n const logger = useLogger();\n\n const missing: string[] = [];\n if (!vectorStore) {\n missing.push('vectorStore');\n }\n if (!embeddings) {\n missing.push('embeddings');\n }\n if (!storage) {\n missing.push('storage');\n }\n if (!cache) {\n missing.push('cache');\n }\n if (!llm) {\n missing.push('llm');\n }\n if (missing.length > 0) {\n throw new Error(\n `mind: required platform adapters not configured: ${missing.join(', ')}. ` +\n `Configure them in .kb/kb.config.json under \"adapters\".`,\n );\n }\n\n return { vectorStore: vectorStore!, embeddings: embeddings!, storage: storage!, cache: cache!, llm: llm!, logger };\n}\n\n/** Resolve the plugin config from the `mind` config section. */\nexport async function loadConfig() {\n const raw = await useConfig<MindConfigInput>();\n return resolveMindConfig(raw ?? {});\n}\n\n/**\n * Convenience: build the Mind facade (services + config) in one call.\n * `cwd` is the workspace root source paths resolve against (from `ctx.cwd`).\n */\nexport async function buildMind(cwd?: string): Promise<Mind> {\n return createMind(buildServices(), await loadConfig(), { cwd: cwd ?? process.cwd() });\n}\n","import { defineCommand, handleError, type CLIInput, type PluginContextV3 } from '@kb-labs/sdk';\nimport { QueryRequestSchema, type AskFlags, type AgentResponse } from '@kb-labs/mind-contracts';\nimport { buildMind } from '../../platform';\n\ntype AskResult = { exitCode: number; result?: AgentResponse };\n\nexport default defineCommand<unknown, CLIInput<AskFlags>, AgentResponse>({\n id: 'mind:ask',\n description: 'Ask a question and get a grounded answer with citations',\n\n handler: {\n async execute(ctx: PluginContextV3, input: CLIInput<AskFlags>): Promise<AskResult> {\n const { flags } = input;\n // `--agent` == `--format json`: the machine-readable agent contract.\n const json = flags.agent || flags.format === 'json' || flags.json;\n try {\n const req = QueryRequestSchema.parse({\n text: flags.text,\n indexId: flags.index,\n mode: flags.mode,\n snippet: flags.snippet,\n });\n const mind = await buildMind(ctx.cwd);\n const res = await mind.ask(req);\n\n if (json) {\n ctx.ui?.json?.(res);\n return { exitCode: 0, result: res };\n }\n\n const head = res.abstained\n ? `⚠ low confidence (${res.confidence.toFixed(2)}) — answer may be unreliable`\n : `answer (confidence ${res.confidence.toFixed(2)})`;\n ctx.ui?.success?.(head, {\n sections: [\n { header: 'Answer', items: [res.answer] },\n {\n header: 'Sources',\n items: res.sources.map(\n (s) => `${s.file}:${s.lines[0]}-${s.lines[1]} [${s.matchedBy}${s.stale ? ', stale' : ''}]`,\n ),\n },\n ],\n });\n return { exitCode: 0, result: res };\n } catch (err) {\n handleError(ctx, err, json);\n return { exitCode: 1 };\n }\n },\n },\n});\n"]}
@@ -0,0 +1,10 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+ import { CLIInput } from '@kb-labs/sdk';
3
+
4
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, CLIInput<any>, {
5
+ indexId: string;
6
+ droppedChunks: number;
7
+ droppedFiles: number;
8
+ }>;
9
+
10
+ export { _default as default };
@@ -0,0 +1,90 @@
1
+ import { defineCommand, confirmDestructive, handleError, useVectorStore, useEmbeddings, useStorage, useCache, useLLM, useLogger, useConfig } from '@kb-labs/sdk';
2
+ import { DropRequestSchema, resolveMindConfig } from '@kb-labs/mind-contracts';
3
+ import { createMind } from '@kb-labs/mind-core';
4
+
5
+ // src/cli/commands/drop.ts
6
+ function buildServices() {
7
+ const vectorStore = useVectorStore();
8
+ const embeddings = useEmbeddings();
9
+ const storage = useStorage();
10
+ const cache = useCache();
11
+ const llm = useLLM();
12
+ const logger = useLogger();
13
+ const missing = [];
14
+ if (!vectorStore) {
15
+ missing.push("vectorStore");
16
+ }
17
+ if (!embeddings) {
18
+ missing.push("embeddings");
19
+ }
20
+ if (!storage) {
21
+ missing.push("storage");
22
+ }
23
+ if (!cache) {
24
+ missing.push("cache");
25
+ }
26
+ if (!llm) {
27
+ missing.push("llm");
28
+ }
29
+ if (missing.length > 0) {
30
+ throw new Error(
31
+ `mind: required platform adapters not configured: ${missing.join(", ")}. Configure them in .kb/kb.config.json under "adapters".`
32
+ );
33
+ }
34
+ return { vectorStore, embeddings, storage, cache, llm, logger };
35
+ }
36
+ async function loadConfig() {
37
+ const raw = await useConfig();
38
+ return resolveMindConfig(raw ?? {});
39
+ }
40
+ async function buildMind(cwd) {
41
+ return createMind(buildServices(), await loadConfig(), { cwd: cwd ?? process.cwd() });
42
+ }
43
+
44
+ // src/cli/commands/drop.ts
45
+ var drop_default = defineCommand({
46
+ id: "mind:drop",
47
+ description: "Drop an entire index \u2014 remove all its vectors and its manifest",
48
+ handler: {
49
+ async execute(ctx, input) {
50
+ const { flags } = input;
51
+ const json = flags.json;
52
+ try {
53
+ const blocked = confirmDestructive(ctx, {
54
+ confirmed: flags.yes,
55
+ isJson: json,
56
+ action: {
57
+ action: "mind drop",
58
+ resource: `index "${flags.index}"`,
59
+ effect: "deletes all vectors and the manifest",
60
+ severity: "high",
61
+ reversible: true,
62
+ recovery: "rebuild with `kb mind index --index <id> --full`",
63
+ blastRadius: { scope: "whole index" }
64
+ }
65
+ });
66
+ if (blocked) {
67
+ return blocked;
68
+ }
69
+ const req = DropRequestSchema.parse({ indexId: flags.index });
70
+ const mind = await buildMind(ctx.cwd);
71
+ const res = await mind.drop(req);
72
+ if (json) {
73
+ ctx.ui?.json?.(res);
74
+ return { exitCode: 0, result: res };
75
+ }
76
+ ctx.ui?.success?.(
77
+ `Dropped "${res.indexId}" \u2014 removed ${res.droppedChunks} vector(s), ${res.droppedFiles} doc(s)`
78
+ );
79
+ return { exitCode: 0, result: res };
80
+ } catch (err) {
81
+ handleError(ctx, err, json);
82
+ return { exitCode: 1 };
83
+ }
84
+ }
85
+ }
86
+ });
87
+
88
+ export { drop_default as default };
89
+ //# sourceMappingURL=drop.js.map
90
+ //# sourceMappingURL=drop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/platform.ts","../../../src/cli/commands/drop.ts"],"names":[],"mappings":";;;;;AAqBO,SAAS,aAAA,GAA8B;AAC5C,EAAA,MAAM,cAAc,cAAA,EAAe;AACnC,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,MAAM,UAAU,UAAA,EAAW;AAC3B,EAAA,MAAM,QAAQ,QAAA,EAAS;AACvB,EAAA,MAAM,MAAM,MAAA,EAAO;AACnB,EAAA,MAAM,SAAS,SAAA,EAAU;AAEzB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,OAAA,CAAQ,KAAK,aAAa,CAAA;AAAA,EAC5B;AACA,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAA,CAAQ,KAAK,YAAY,CAAA;AAAA,EAC3B;AACA,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAA,CAAQ,KAAK,SAAS,CAAA;AAAA,EACxB;AACA,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,OAAA,CAAQ,KAAK,OAAO,CAAA;AAAA,EACtB;AACA,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AAAA,EACpB;AACA,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,iDAAA,EAAoD,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,wDAAA;AAAA,KAExE;AAAA,EACF;AAE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kB,KAAA,CAAM,EAAE,OAAA,EAAS,KAAA,CAAM,OAAO,CAAA;AAC5D,QAAA,MAAM,IAAA,GAAO,MAAM,SAAA,CAAU,GAAA,CAAI,GAAG,CAAA;AACpC,QAAA,MAAM,GAAA,GAAM,MAAM,IAAA,CAAK,IAAA,CAAK,GAAG,CAAA;AAE/B,QAAA,IAAI,IAAA,EAAM;AACR,UAAA,GAAA,CAAI,EAAA,EAAI,OAAO,GAAG,CAAA;AAClB,UAAA,OAAO,EAAE,QAAA,EAAU,CAAA,EAAG,MAAA,EAAQ,GAAA,EAAI;AAAA,QACpC;AACA,QAAA,GAAA,CAAI,EAAA,EAAI,OAAA;AAAA,UACN,CAAA,SAAA,EAAY,IAAI,OAAO,CAAA,iBAAA,EAAe,IAAI,aAAa,CAAA,YAAA,EAAe,IAAI,YAAY,CAAA,OAAA;AAAA,SACxF;AACA,QAAA,OAAO,EAAE,QAAA,EAAU,CAAA,EAAG,MAAA,EAAQ,GAAA,EAAI;AAAA,MACpC,SAAS,GAAA,EAAK;AACZ,QAAA,WAAA,CAAY,GAAA,EAAK,KAAK,IAAI,CAAA;AAC1B,QAAA,OAAO,EAAE,UAAU,CAAA,EAAE;AAAA,MACvB;AAAA,IACF;AAAA;AAEJ,CAAC","file":"drop.js","sourcesContent":["/**\n * The single place the plugin touches platform hooks.\n *\n * Assembles `MindServices` from `@kb-labs/sdk` hooks and resolves the plugin\n * config. CLI commands and REST handlers both call `buildMind(...)` so they\n * drive the exact same engine.\n */\n\nimport {\n useVectorStore,\n useEmbeddings,\n useStorage,\n useCache,\n useLLM,\n useLogger,\n useConfig,\n} from '@kb-labs/sdk';\nimport { createMind, type Mind, type MindServices } from '@kb-labs/mind-core';\nimport { resolveMindConfig, type MindConfigInput } from '@kb-labs/mind-contracts';\n\n/** Build MindServices from platform hooks, failing fast on missing required adapters. */\nexport function buildServices(): MindServices {\n const vectorStore = useVectorStore();\n const embeddings = useEmbeddings();\n const storage = useStorage();\n const cache = useCache();\n const llm = useLLM();\n const logger = useLogger();\n\n const missing: string[] = [];\n if (!vectorStore) {\n missing.push('vectorStore');\n }\n if (!embeddings) {\n missing.push('embeddings');\n }\n if (!storage) {\n missing.push('storage');\n }\n if (!cache) {\n missing.push('cache');\n }\n if (!llm) {\n missing.push('llm');\n }\n if (missing.length > 0) {\n throw new Error(\n `mind: required platform adapters not configured: ${missing.join(', ')}. ` +\n `Configure them in .kb/kb.config.json under \"adapters\".`,\n );\n }\n\n return { vectorStore: vectorStore!, embeddings: embeddings!, storage: storage!, cache: cache!, llm: llm!, logger };\n}\n\n/** Resolve the plugin config from the `mind` config section. */\nexport async function loadConfig() {\n const raw = await useConfig<MindConfigInput>();\n return resolveMindConfig(raw ?? {});\n}\n\n/**\n * Convenience: build the Mind facade (services + config) in one call.\n * `cwd` is the workspace root source paths resolve against (from `ctx.cwd`).\n */\nexport async function buildMind(cwd?: string): Promise<Mind> {\n return createMind(buildServices(), await loadConfig(), { cwd: cwd ?? process.cwd() });\n}\n","import { defineCommand, handleError, confirmDestructive, type CLIInput, type PluginContextV3 } from '@kb-labs/sdk';\nimport { DropRequestSchema, type DropFlags, type DropResponse } from '@kb-labs/mind-contracts';\nimport { buildMind } from '../../platform';\n\ntype DropResult = { exitCode: number; result?: DropResponse };\n\nexport default defineCommand<unknown, CLIInput<DropFlags>, DropResponse>({\n id: 'mind:drop',\n description: 'Drop an entire index — remove all its vectors and its manifest',\n\n handler: {\n async execute(ctx: PluginContextV3, input: CLIInput<DropFlags>): Promise<DropResult> {\n const { flags } = input;\n const json = flags.json;\n try {\n // Destructive: blocks in EVERY mode until --yes (agents get a structured\n // confirmationRequired signal with severity/recovery, not a silent drop).\n const blocked = confirmDestructive(ctx, {\n confirmed: flags.yes,\n isJson: json,\n action: {\n action: 'mind drop',\n resource: `index \"${flags.index}\"`,\n effect: 'deletes all vectors and the manifest',\n severity: 'high',\n reversible: true,\n recovery: 'rebuild with `kb mind index --index <id> --full`',\n blastRadius: { scope: 'whole index' },\n },\n });\n if (blocked) {\n return blocked;\n }\n const req = DropRequestSchema.parse({ indexId: flags.index });\n const mind = await buildMind(ctx.cwd);\n const res = await mind.drop(req);\n\n if (json) {\n ctx.ui?.json?.(res);\n return { exitCode: 0, result: res };\n }\n ctx.ui?.success?.(\n `Dropped \"${res.indexId}\" — removed ${res.droppedChunks} vector(s), ${res.droppedFiles} doc(s)`,\n );\n return { exitCode: 0, result: res };\n } catch (err) {\n handleError(ctx, err, json);\n return { exitCode: 1 };\n }\n },\n },\n});\n"]}
@@ -0,0 +1,26 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+ import { CLIInput } from '@kb-labs/sdk';
3
+
4
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, CLIInput<any>, {
5
+ confidence: number;
6
+ task: string;
7
+ indexId: string;
8
+ meta: {
9
+ requestId: string;
10
+ timingMs: number;
11
+ filesTouched: number;
12
+ spread: number;
13
+ } & {
14
+ [k: string]: unknown;
15
+ };
16
+ summary: string;
17
+ files: {
18
+ file: string;
19
+ lines: [number, number];
20
+ matchedBy: "lexical" | "semantic" | "both";
21
+ stale: boolean;
22
+ why: string;
23
+ }[];
24
+ }>;
25
+
26
+ export { _default as default };
@@ -0,0 +1,96 @@
1
+ import { defineCommand, handleError, useVectorStore, useEmbeddings, useStorage, useCache, useLLM, useLogger, useConfig } from '@kb-labs/sdk';
2
+ import { ExploreRequestSchema, resolveMindConfig } from '@kb-labs/mind-contracts';
3
+ import { createMind } from '@kb-labs/mind-core';
4
+
5
+ // src/cli/commands/explore.ts
6
+ function buildServices() {
7
+ const vectorStore = useVectorStore();
8
+ const embeddings = useEmbeddings();
9
+ const storage = useStorage();
10
+ const cache = useCache();
11
+ const llm = useLLM();
12
+ const logger = useLogger();
13
+ const missing = [];
14
+ if (!vectorStore) {
15
+ missing.push("vectorStore");
16
+ }
17
+ if (!embeddings) {
18
+ missing.push("embeddings");
19
+ }
20
+ if (!storage) {
21
+ missing.push("storage");
22
+ }
23
+ if (!cache) {
24
+ missing.push("cache");
25
+ }
26
+ if (!llm) {
27
+ missing.push("llm");
28
+ }
29
+ if (missing.length > 0) {
30
+ throw new Error(
31
+ `mind: required platform adapters not configured: ${missing.join(", ")}. Configure them in .kb/kb.config.json under "adapters".`
32
+ );
33
+ }
34
+ return { vectorStore, embeddings, storage, cache, llm, logger };
35
+ }
36
+ async function loadConfig() {
37
+ const raw = await useConfig();
38
+ return resolveMindConfig(raw ?? {});
39
+ }
40
+ async function buildMind(cwd) {
41
+ return createMind(buildServices(), await loadConfig(), { cwd: cwd ?? process.cwd() });
42
+ }
43
+
44
+ // src/cli/commands/explore.ts
45
+ var explore_default = defineCommand({
46
+ id: "mind:explore",
47
+ description: "Task-orientation map \u2014 where to start and how involved a task looks",
48
+ handler: {
49
+ async execute(ctx, input) {
50
+ const { flags } = input;
51
+ const json = flags.format === "json" || flags.json;
52
+ try {
53
+ const req = ExploreRequestSchema.parse({
54
+ task: flags.task,
55
+ indexId: flags.index,
56
+ limit: flags.limit
57
+ });
58
+ const mind = await buildMind(ctx.cwd);
59
+ const res = await mind.explore(req);
60
+ if (json) {
61
+ ctx.ui?.json?.(res);
62
+ return { exitCode: 0, result: res };
63
+ }
64
+ if (res.files.length === 0) {
65
+ ctx.ui?.warn?.(`No relevant files in index "${res.indexId}"`);
66
+ } else {
67
+ ctx.ui?.success?.(
68
+ `${res.files.length} file(s) across ${res.meta.spread} dir(s) \u2014 confidence ${res.confidence.toFixed(2)}`,
69
+ {
70
+ sections: [
71
+ ...res.summary ? [{ header: "Orientation", items: [res.summary] }] : [],
72
+ {
73
+ header: `Index "${res.indexId}"`,
74
+ items: res.files.map((f) => {
75
+ const loc = `${f.file}:${f.lines[0]}-${f.lines[1]}`;
76
+ const tags = `[${f.matchedBy}${f.stale ? ", stale" : ""}]`;
77
+ return `${loc} ${tags}
78
+ ${f.why}`;
79
+ })
80
+ }
81
+ ]
82
+ }
83
+ );
84
+ }
85
+ return { exitCode: 0, result: res };
86
+ } catch (err) {
87
+ handleError(ctx, err, json);
88
+ return { exitCode: 1 };
89
+ }
90
+ }
91
+ }
92
+ });
93
+
94
+ export { explore_default as default };
95
+ //# sourceMappingURL=explore.js.map
96
+ //# sourceMappingURL=explore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/platform.ts","../../../src/cli/commands/explore.ts"],"names":[],"mappings":";;;;;AAqBO,SAAS,aAAA,GAA8B;AAC5C,EAAA,MAAM,cAAc,cAAA,EAAe;AACnC,EAAA,MAAM,aAAa,aAAA,EAAc;AACjC,EAAA,MAAM,UAAU,UAAA,EAAW;AAC3B,EAAA,MAAM,QAAQ,QAAA,EAAS;AACvB,EAAA,MAAM,MAAM,MAAA,EAAO;AACnB,EAAA,MAAM,SAAS,SAAA,EAAU;AAEzB,EAAA,MAAM,UAAoB,EAAC;AAC3B,EAAA,IAAI,CAAC,WAAA,EAAa;AAChB,IAAA,OAAA,CAAQ,KAAK,aAAa,CAAA;AAAA,EAC5B;AACA,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAA,CAAQ,KAAK,YAAY,CAAA;AAAA,EAC3B;AACA,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,OAAA,CAAQ,KAAK,SAAS,CAAA;AAAA,EACxB;AACA,EAAA,IAAI,CAAC,KAAA,EAAO;AACV,IAAA,OAAA,CAAQ,KAAK,OAAO,CAAA;AAAA,EACtB;AACA,EAAA,IAAI,CAAC,GAAA,EAAK;AACR,IAAA,OAAA,CAAQ,KAAK,KAAK,CAAA;AAAA,EACpB;AACA,EAAA,IAAI,OAAA,CAAQ,SAAS,CAAA,EAAG;AACtB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,iDAAA,EAAoD,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAC,CAAA,wDAAA;AAAA,KAExE;AAAA,EACF;AAEA,EAAA,OAAO,EAAE,WAAA,EAA2B,UAAA,EAAyB,OAAA,EAAmB,KA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AAAA,MACpC,SAAS,GAAA,EAAK;AACZ,QAAA,WAAA,CAAY,GAAA,EAAK,KAAK,IAAI,CAAA;AAC1B,QAAA,OAAO,EAAE,UAAU,CAAA,EAAE;AAAA,MACvB;AAAA,IACF;AAAA;AAEJ,CAAC","file":"explore.js","sourcesContent":["/**\n * The single place the plugin touches platform hooks.\n *\n * Assembles `MindServices` from `@kb-labs/sdk` hooks and resolves the plugin\n * config. CLI commands and REST handlers both call `buildMind(...)` so they\n * drive the exact same engine.\n */\n\nimport {\n useVectorStore,\n useEmbeddings,\n useStorage,\n useCache,\n useLLM,\n useLogger,\n useConfig,\n} from '@kb-labs/sdk';\nimport { createMind, type Mind, type MindServices } from '@kb-labs/mind-core';\nimport { resolveMindConfig, type MindConfigInput } from '@kb-labs/mind-contracts';\n\n/** Build MindServices from platform hooks, failing fast on missing required adapters. */\nexport function buildServices(): MindServices {\n const vectorStore = useVectorStore();\n const embeddings = useEmbeddings();\n const storage = useStorage();\n const cache = useCache();\n const llm = useLLM();\n const logger = useLogger();\n\n const missing: string[] = [];\n if (!vectorStore) {\n missing.push('vectorStore');\n }\n if (!embeddings) {\n missing.push('embeddings');\n }\n if (!storage) {\n missing.push('storage');\n }\n if (!cache) {\n missing.push('cache');\n }\n if (!llm) {\n missing.push('llm');\n }\n if (missing.length > 0) {\n throw new Error(\n `mind: required platform adapters not configured: ${missing.join(', ')}. ` +\n `Configure them in .kb/kb.config.json under \"adapters\".`,\n );\n }\n\n return { vectorStore: vectorStore!, embeddings: embeddings!, storage: storage!, cache: cache!, llm: llm!, logger };\n}\n\n/** Resolve the plugin config from the `mind` config section. */\nexport async function loadConfig() {\n const raw = await useConfig<MindConfigInput>();\n return resolveMindConfig(raw ?? {});\n}\n\n/**\n * Convenience: build the Mind facade (services + config) in one call.\n * `cwd` is the workspace root source paths resolve against (from `ctx.cwd`).\n */\nexport async function buildMind(cwd?: string): Promise<Mind> {\n return createMind(buildServices(), await loadConfig(), { cwd: cwd ?? process.cwd() });\n}\n","import { defineCommand, handleError, type CLIInput, type PluginContextV3 } from '@kb-labs/sdk';\nimport { ExploreRequestSchema, type ExploreFlags, type ExploreResponse } from '@kb-labs/mind-contracts';\nimport { buildMind } from '../../platform';\n\ntype ExploreResult = { exitCode: number; result?: ExploreResponse };\n\nexport default defineCommand<unknown, CLIInput<ExploreFlags>, ExploreResponse>({\n id: 'mind:explore',\n description: 'Task-orientation map — where to start and how involved a task looks',\n\n handler: {\n async execute(ctx: PluginContextV3, input: CLIInput<ExploreFlags>): Promise<ExploreResult> {\n const { flags } = input;\n const json = flags.format === 'json' || flags.json;\n try {\n const req = ExploreRequestSchema.parse({\n task: flags.task,\n indexId: flags.index,\n limit: flags.limit,\n });\n\n const mind = await buildMind(ctx.cwd);\n const res = await mind.explore(req);\n\n if (json) {\n ctx.ui?.json?.(res);\n return { exitCode: 0, result: res };\n }\n if (res.files.length === 0) {\n ctx.ui?.warn?.(`No relevant files in index \"${res.indexId}\"`);\n } else {\n ctx.ui?.success?.(\n `${res.files.length} file(s) across ${res.meta.spread} dir(s) — confidence ${res.confidence.toFixed(2)}`,\n {\n sections: [\n ...(res.summary ? [{ header: 'Orientation', items: [res.summary] }] : []),\n {\n header: `Index \"${res.indexId}\"`,\n items: res.files.map((f) => {\n const loc = `${f.file}:${f.lines[0]}-${f.lines[1]}`;\n const tags = `[${f.matchedBy}${f.stale ? ', stale' : ''}]`;\n return `${loc} ${tags}\\n ${f.why}`;\n }),\n },\n ],\n },\n );\n }\n return { exitCode: 0, result: res };\n } catch (err) {\n handleError(ctx, err, json);\n return { exitCode: 1 };\n }\n },\n },\n});\n"]}
@@ -0,0 +1,11 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+ import { CLIInput } from '@kb-labs/sdk';
3
+
4
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, CLIInput<any>, {
5
+ durationMs: number;
6
+ indexId: string;
7
+ filesIndexed: number;
8
+ chunks: number;
9
+ }>;
10
+
11
+ export { _default as default };