@dikolab/kbdb 0.1.6 → 0.2.1
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 +30 -9
- package/dist/cli.cjs +181 -50
- package/dist/cli.cjs.map +3 -3
- package/dist/cli.mjs +181 -50
- package/dist/cli.mjs.map +3 -3
- package/dist/kbdb-worker.cjs +283 -29
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +13 -2
- package/dist/mod.cjs.map +2 -2
- package/dist/mod.d.ts +25 -0
- package/dist/mod.mjs +13 -2
- package/dist/mod.mjs.map +2 -2
- package/dist/src/cli.d.ts +8 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
- package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
- package/dist/src/shared/cli/index.d.ts +1 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
- package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
- package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
- package/dist/src/shared/wasm-codec/index.d.ts +5 -2
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
- package/dist/src/shared/worker-client/index.d.ts +2 -1
- package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
- package/dist/src/worker.d.ts +7 -0
- package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
- package/dist/worker.mjs +283 -29
- package/dist/worker.mjs.map +4 -4
- package/docs/details/README.md +26 -0
- package/docs/details/cli.md +608 -0
- package/docs/details/library-api.md +406 -0
- package/docs/details/mcp-server.md +430 -0
- package/docs/details/search-and-ranking.md +457 -0
- package/docs/details/storage.md +529 -0
- package/docs/goals/agents.md +751 -0
- package/docs/goals/architecture.svg +198 -0
- package/docs/goals/cli.md +2308 -0
- package/docs/goals/content-composer.md +609 -0
- package/docs/goals/content-parser.md +279 -0
- package/docs/goals/database.md +1452 -0
- package/docs/goals/document.md +368 -0
- package/docs/goals/mcp.md +1467 -0
- package/docs/goals/overview.md +124 -0
- package/docs/goals/query-parser.md +271 -0
- package/docs/goals/query-result.md +693 -0
- package/docs/goals/skills.md +738 -0
- package/docs/goals/worker-client.md +944 -0
- package/docs/goals/worker-daemon.md +1447 -0
- package/docs/modules/overview.md +298 -0
- package/docs/modules/rust/fs-database/functions/document.md +48 -0
- package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
- package/docs/modules/rust/fs-database/functions/io.md +87 -0
- package/docs/modules/rust/fs-database/functions/module.md +22 -0
- package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
- package/docs/modules/rust/fs-database/functions/section.md +59 -0
- package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
- package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
- package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
- package/docs/modules/rust/fs-database/indexes/module.md +64 -0
- package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
- package/docs/modules/rust/fs-database/module.md +149 -0
- package/docs/modules/rust/fs-database/types/catalog.md +53 -0
- package/docs/modules/rust/fs-database/types/module.md +12 -0
- package/docs/modules/rust/fs-database/types/section.md +101 -0
- package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
- package/docs/modules/rust/kb-worker/functions/module.md +20 -0
- package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
- package/docs/modules/rust/kb-worker/functions/search.md +173 -0
- package/docs/modules/rust/kb-worker/functions/write.md +172 -0
- package/docs/modules/rust/kb-worker/module.md +171 -0
- package/docs/modules/rust/kb-worker/types/cache.md +90 -0
- package/docs/modules/rust/kb-worker/types/context.md +26 -0
- package/docs/modules/rust/kb-worker/types/module.md +16 -0
- package/docs/modules/rust/kb-worker/types/status.md +29 -0
- package/docs/modules/rust/kb-worker/types/token.md +50 -0
- package/docs/modules/rust/overview.md +495 -0
- package/docs/modules/rust/query-parser/functions/extract.md +56 -0
- package/docs/modules/rust/query-parser/functions/module.md +16 -0
- package/docs/modules/rust/query-parser/functions/parse.md +33 -0
- package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
- package/docs/modules/rust/query-parser/functions/rank.md +85 -0
- package/docs/modules/rust/query-parser/module.md +136 -0
- package/docs/modules/rust/query-parser/types/cache.md +39 -0
- package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
- package/docs/modules/rust/query-parser/types/module.md +17 -0
- package/docs/modules/rust/query-parser/types/token.md +42 -0
- package/docs/modules/rust/shared/content-composer/functions.md +114 -0
- package/docs/modules/rust/shared/content-composer/module.md +147 -0
- package/docs/modules/rust/shared/content-composer/types.md +93 -0
- package/docs/modules/rust/shared/content-parser/functions.md +72 -0
- package/docs/modules/rust/shared/content-parser/module.md +99 -0
- package/docs/modules/rust/shared/content-parser/types.md +71 -0
- package/docs/modules/rust/shared/corpus/module.md +24 -0
- package/docs/modules/rust/shared/corpus/types.md +141 -0
- package/docs/modules/rust/shared/document/module.md +25 -0
- package/docs/modules/rust/shared/document/types.md +154 -0
- package/docs/modules/rust/shared/encode/module.md +22 -0
- package/docs/modules/rust/shared/encode/traits.md +304 -0
- package/docs/modules/rust/shared/error/module.md +28 -0
- package/docs/modules/rust/shared/error/types.md +302 -0
- package/docs/modules/rust/shared/kbid/module.md +24 -0
- package/docs/modules/rust/shared/kbid/types.md +147 -0
- package/docs/modules/rust/shared/memory/functions.md +209 -0
- package/docs/modules/rust/shared/memory/module.md +24 -0
- package/docs/modules/rust/shared/module.md +168 -0
- package/docs/modules/rust/shared/query/module.md +27 -0
- package/docs/modules/rust/shared/query/types.md +236 -0
- package/docs/modules/rust/shared/section/module.md +25 -0
- package/docs/modules/rust/shared/section/types.md +294 -0
- package/docs/modules/rust/shared/term/module.md +25 -0
- package/docs/modules/rust/shared/term/types.md +139 -0
- package/docs/modules/typescript/cli.md +129 -0
- package/docs/modules/typescript/kbdb-worker.md +135 -0
- package/docs/modules/typescript/overview.md +378 -0
- package/docs/modules/typescript/shared/cli/constants.md +23 -0
- package/docs/modules/typescript/shared/cli/functions.md +630 -0
- package/docs/modules/typescript/shared/cli/module.md +125 -0
- package/docs/modules/typescript/shared/cli/typings.md +172 -0
- package/docs/modules/typescript/shared/hash/functions.md +20 -0
- package/docs/modules/typescript/shared/hash/module.md +21 -0
- package/docs/modules/typescript/shared/mcp/classes.md +179 -0
- package/docs/modules/typescript/shared/mcp/functions.md +386 -0
- package/docs/modules/typescript/shared/mcp/module.md +160 -0
- package/docs/modules/typescript/shared/mcp/typings.md +522 -0
- package/docs/modules/typescript/shared/module.md +94 -0
- package/docs/modules/typescript/shared/platform/functions.md +42 -0
- package/docs/modules/typescript/shared/platform/module.md +25 -0
- package/docs/modules/typescript/shared/runtime/functions.md +26 -0
- package/docs/modules/typescript/shared/runtime/module.md +27 -0
- package/docs/modules/typescript/shared/runtime/typings.md +13 -0
- package/docs/modules/typescript/shared/version/module.md +27 -0
- package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
- package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
- package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
- package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
- package/docs/modules/typescript/shared/worker-client/module.md +84 -0
- package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
- package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
- package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
- package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
- package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
- package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
- package/docs/overview.md +188 -0
- package/docs/release-notes/0.1.0.md +189 -0
- package/docs/release-notes/0.1.1.md +46 -0
- package/docs/release-notes/0.1.2.md +38 -0
- package/docs/release-notes/0.1.3.md +42 -0
- package/docs/release-notes/0.2.0.md +147 -0
- package/docs/release-notes/README.md +9 -0
- package/mod.ts +26 -0
- package/package.json +8 -2
- package/src/cli.ts +9 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
- package/src/shared/cli/functions/format-output.function.ts +41 -34
- package/src/shared/cli/functions/parse-args.function.ts +7 -0
- package/src/shared/cli/functions/run-search.function.ts +53 -27
- package/src/shared/cli/index.ts +4 -1
- package/src/shared/cli/typings/cli-options.interface.ts +2 -0
- package/src/shared/cli/typings/search-display.model.ts +26 -7
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
- package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
- package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
- package/src/shared/version/constants/version.constant.ts +1 -1
- package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
- package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
- package/src/shared/wasm-codec/index.ts +11 -3
- package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
- package/src/shared/worker-client/index.ts +11 -1
- package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
- package/src/shared/worker-client/typings/search-params.model.ts +2 -0
- package/src/shared/worker-client/typings/search-result.model.ts +24 -7
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
- package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
- package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
- package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
- package/src/wasm/kb-worker/kbdb_worker.js +56 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
- package/src/worker.ts +8 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# src/worker.ts -- Worker Daemon Executable
|
|
2
|
+
|
|
3
|
+
*Thin entry point for the detached daemon process that
|
|
4
|
+
loads WASM modules and serves IPC requests.*
|
|
5
|
+
|
|
6
|
+
## File
|
|
7
|
+
|
|
8
|
+
`src/worker.ts`
|
|
9
|
+
|
|
10
|
+
## Built To
|
|
11
|
+
|
|
12
|
+
| Format | Output | Notes |
|
|
13
|
+
|--------|--------------------------|---------|
|
|
14
|
+
| ESM | `dist/worker.mjs` | shebang |
|
|
15
|
+
| CJS | `dist/worker.cjs` | shebang |
|
|
16
|
+
| `.d.ts`| `dist/worker.d.ts` | |
|
|
17
|
+
|
|
18
|
+
Not registered as an npm `bin` -- this executable is
|
|
19
|
+
not invoked directly by users. It is spawned as a
|
|
20
|
+
detached child process by `shared/worker-client/`.
|
|
21
|
+
|
|
22
|
+
## How It Is Spawned
|
|
23
|
+
|
|
24
|
+
The worker-client module spawns this executable when
|
|
25
|
+
no running daemon is found for the target database:
|
|
26
|
+
|
|
27
|
+
**Node.js:**
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
spawn(
|
|
31
|
+
'node',
|
|
32
|
+
['kbdb-worker.js', contextPath],
|
|
33
|
+
{ detached: true, stdio: ['ignore', 'ignore', 'pipe'] },
|
|
34
|
+
).unref();
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Deno:**
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
new Deno.Command('deno', {
|
|
41
|
+
args: [
|
|
42
|
+
'run', '--allow-all',
|
|
43
|
+
'src/worker.ts', contextPath,
|
|
44
|
+
],
|
|
45
|
+
stdin: 'null',
|
|
46
|
+
stdout: 'null',
|
|
47
|
+
stderr: 'piped',
|
|
48
|
+
}).spawn().unref();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The sole command-line argument is the **context path**
|
|
52
|
+
-- the absolute path to the `.kbdb` database directory.
|
|
53
|
+
|
|
54
|
+
## Execution Flow
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
src/worker.ts
|
|
58
|
+
│
|
|
59
|
+
├─ import startDaemon from shared/worker-daemon/
|
|
60
|
+
│
|
|
61
|
+
├─ read contextPath from argv[0]
|
|
62
|
+
├─ validate contextPath exists
|
|
63
|
+
│
|
|
64
|
+
└─ await startDaemon(contextPath)
|
|
65
|
+
│
|
|
66
|
+
├─ readConfig(contextPath)
|
|
67
|
+
│ └─ parse .kbdb/worker.toml
|
|
68
|
+
│
|
|
69
|
+
├─ loadWasmModules(config)
|
|
70
|
+
│ ├─ allocate shared WebAssembly.Memory
|
|
71
|
+
│ ├─ compile query-parser.wasm (standalone)
|
|
72
|
+
│ ├─ compile fs-database.wasm (standalone)
|
|
73
|
+
│ └─ compile kb-worker.wasm
|
|
74
|
+
│ (imports both modules)
|
|
75
|
+
│
|
|
76
|
+
├─ write PID file
|
|
77
|
+
│ └─ kb-worker-{ctx}.pid in tmpdir
|
|
78
|
+
│
|
|
79
|
+
├─ createIpcServer(ctx, handler)
|
|
80
|
+
│ └─ Unix socket or named pipe
|
|
81
|
+
│
|
|
82
|
+
├─ listen for connections
|
|
83
|
+
│ └─ JSON-RPC 2.0, newline-delimited
|
|
84
|
+
│
|
|
85
|
+
└─ on idle timeout or signal:
|
|
86
|
+
├─ stop accepting connections
|
|
87
|
+
├─ wait for in-flight requests
|
|
88
|
+
├─ purge cache
|
|
89
|
+
├─ remove PID file
|
|
90
|
+
├─ remove IPC socket
|
|
91
|
+
└─ exit
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Imports
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import {
|
|
98
|
+
startDaemon,
|
|
99
|
+
} from './src/shared/worker-daemon/functions/start-daemon.function.ts';
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## No Business Logic
|
|
103
|
+
|
|
104
|
+
This file contains **only** argument reading and a
|
|
105
|
+
single function call. All daemon logic lives in
|
|
106
|
+
`shared/worker-daemon/`:
|
|
107
|
+
|
|
108
|
+
| Concern | Module |
|
|
109
|
+
|--------------------|-----------------------------|
|
|
110
|
+
| WASM loading | `shared/worker-daemon/` |
|
|
111
|
+
| IPC server | `shared/worker-daemon/` |
|
|
112
|
+
| Config reading | `shared/worker-daemon/` |
|
|
113
|
+
| Cache management | WASM (`kb-worker.wasm`) |
|
|
114
|
+
| Query orchestration| WASM (`kb-worker.wasm`) |
|
|
115
|
+
| Index operations | WASM (`fs-database.wasm`) |
|
|
116
|
+
| Tokenization | WASM (`query-parser.wasm`) |
|
|
117
|
+
| Platform helpers | `shared/platform/` |
|
|
118
|
+
|
|
119
|
+
## Lifecycle
|
|
120
|
+
|
|
121
|
+
1. Spawned by worker-client as detached child process
|
|
122
|
+
2. Loads and compiles 3 WASM modules (once)
|
|
123
|
+
3. Serves IPC requests from any connected client
|
|
124
|
+
4. Shuts down after idle timeout (`timeout_ms`) or
|
|
125
|
+
OS signal (SIGTERM, SIGINT)
|
|
126
|
+
5. Cleans up PID file and IPC socket on exit
|
|
127
|
+
|
|
128
|
+
Multiple daemons can run simultaneously on the same
|
|
129
|
+
machine, each serving a different database directory.
|
|
130
|
+
Each daemon is identified by its **context ID**
|
|
131
|
+
(SHA-256 of the database path, truncated to 16 hex
|
|
132
|
+
chars).
|
|
133
|
+
|
|
134
|
+
See [Worker Daemon](../../goals/worker-daemon.md) for
|
|
135
|
+
the full behavioral specification.
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
# TypeScript Layer -- Overview
|
|
2
|
+
|
|
3
|
+
*Module structure, file conventions, and source layout
|
|
4
|
+
for the TypeScript executables and shared modules.*
|
|
5
|
+
|
|
6
|
+
## Architecture
|
|
7
|
+
|
|
8
|
+
Two thin executables, all logic in `src/shared/`
|
|
9
|
+
sub-modules. Heavy computation (keyword extraction,
|
|
10
|
+
indexing, ranking) runs in the Rust/WASM engine.
|
|
11
|
+
TypeScript handles CLI parsing, MCP protocol, IPC
|
|
12
|
+
transport, and WASM module loading.
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
src/cli.ts ──────────────────────────────────┐
|
|
16
|
+
│ (CLI mode or MCP mode) │
|
|
17
|
+
├─ imports shared/cli/ │
|
|
18
|
+
├─ imports shared/mcp/ │
|
|
19
|
+
└─ imports shared/worker-client/ ──IPC──→ │
|
|
20
|
+
│
|
|
21
|
+
src/worker.ts ───────────────────────────────┤
|
|
22
|
+
│ (detached daemon process) │
|
|
23
|
+
└─ imports shared/worker-daemon/ │
|
|
24
|
+
└─ loads WASM modules │
|
|
25
|
+
(query-parser, fs-database, │
|
|
26
|
+
kb-worker) │
|
|
27
|
+
│
|
|
28
|
+
mod.ts ──→ library API (npm/JSR) │
|
|
29
|
+
└─ re-exports from shared/version/ │
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Entry Points
|
|
33
|
+
|
|
34
|
+
Two executable entry points at the project root. Both
|
|
35
|
+
are bundled by esbuild into `dist/` as ESM + CJS.
|
|
36
|
+
|
|
37
|
+
| Entry | Purpose | Lifecycle |
|
|
38
|
+
|-----------------------|------------------------|-------------|
|
|
39
|
+
| `src/cli.ts` | CLI + MCP executable | Short or long-lived |
|
|
40
|
+
| `src/worker.ts` | Worker daemon | Detached background |
|
|
41
|
+
| `mod.ts` | Library API (npm/JSR) | Import only |
|
|
42
|
+
|
|
43
|
+
### `src/cli.ts`
|
|
44
|
+
|
|
45
|
+
The `kbdb` command. Detects the run mode from the
|
|
46
|
+
first argument:
|
|
47
|
+
|
|
48
|
+
- `kbdb mcp [--db <path>]` → MCP server mode
|
|
49
|
+
(long-lived, stdio JSON-RPC 2.0)
|
|
50
|
+
- `kbdb <command> [options]` → CLI mode
|
|
51
|
+
(short-lived, runs one command and exits)
|
|
52
|
+
|
|
53
|
+
Both modes create a `WorkerClient` and delegate all
|
|
54
|
+
operations to the daemon. The executable itself
|
|
55
|
+
contains no business logic -- it dispatches to
|
|
56
|
+
`shared/cli/` or `shared/mcp/`.
|
|
57
|
+
|
|
58
|
+
### `src/worker.ts`
|
|
59
|
+
|
|
60
|
+
The worker daemon. Spawned as a detached child process
|
|
61
|
+
by the worker-client module. Loads the three WASM
|
|
62
|
+
modules, listens on a local IPC socket, and serves
|
|
63
|
+
JSON-RPC 2.0 requests until idle timeout.
|
|
64
|
+
|
|
65
|
+
Contains no business logic -- dispatches to
|
|
66
|
+
`shared/worker-daemon/`.
|
|
67
|
+
|
|
68
|
+
## Source Layout
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
src/cli.ts ← executable
|
|
72
|
+
src/worker.ts ← executable
|
|
73
|
+
mod.ts ← library API
|
|
74
|
+
|
|
75
|
+
src/shared/
|
|
76
|
+
├── cli/ ← CLI commands
|
|
77
|
+
│ ├── index.ts
|
|
78
|
+
│ ├── constants/
|
|
79
|
+
│ │ ├── defaults.constant.ts
|
|
80
|
+
│ │ └── help-text.constant.ts
|
|
81
|
+
│ ├── functions/
|
|
82
|
+
│ │ ├── dispatch-command.function.ts
|
|
83
|
+
│ │ ├── ensure-db.function.ts
|
|
84
|
+
│ │ ├── error-to-message.function.ts
|
|
85
|
+
│ │ ├── find-db.function.ts
|
|
86
|
+
│ │ ├── format-output.function.ts
|
|
87
|
+
│ │ ├── is-stdin-tty.function.ts
|
|
88
|
+
│ │ ├── parse-args.function.ts
|
|
89
|
+
│ │ ├── prompt-user.function.ts
|
|
90
|
+
│ │ ├── run-agent-create.function.ts
|
|
91
|
+
│ │ ├── run-agent-delete.function.ts
|
|
92
|
+
│ │ ├── run-agent-get.function.ts
|
|
93
|
+
│ │ ├── run-agent-list.function.ts
|
|
94
|
+
│ │ ├── run-check.function.ts
|
|
95
|
+
│ │ ├── run-cli.function.ts
|
|
96
|
+
│ │ ├── run-content.function.ts
|
|
97
|
+
│ │ ├── run-db-init.function.ts
|
|
98
|
+
│ │ ├── run-db-migrate.function.ts
|
|
99
|
+
│ │ ├── run-gc.function.ts
|
|
100
|
+
│ │ ├── run-init.function.ts
|
|
101
|
+
│ │ ├── run-learn.function.ts
|
|
102
|
+
│ │ ├── run-migrate.function.ts
|
|
103
|
+
│ │ ├── run-rebuild.function.ts
|
|
104
|
+
│ │ ├── run-search.function.ts
|
|
105
|
+
│ │ ├── run-skill-delete.function.ts
|
|
106
|
+
│ │ ├── run-skill-get.function.ts
|
|
107
|
+
│ │ ├── run-skill-learn.function.ts
|
|
108
|
+
│ │ ├── run-skill-list.function.ts
|
|
109
|
+
│ │ └── run-unlearn.function.ts
|
|
110
|
+
│ └── typings/
|
|
111
|
+
│ ├── cli-options.interface.ts
|
|
112
|
+
│ ├── command-result.model.ts
|
|
113
|
+
│ ├── learn-result.model.ts
|
|
114
|
+
│ └── search-display.model.ts
|
|
115
|
+
│
|
|
116
|
+
├── mcp/ ← MCP server
|
|
117
|
+
│ ├── index.ts
|
|
118
|
+
│ ├── classes/
|
|
119
|
+
│ │ └── mcp-server.class.ts
|
|
120
|
+
│ ├── functions/
|
|
121
|
+
│ │ ├── create-mcp-server.function.ts
|
|
122
|
+
│ │ ├── create-prompt-definitions.function.ts
|
|
123
|
+
│ │ ├── create-resource-templates.function.ts
|
|
124
|
+
│ │ ├── create-tool-definitions.function.ts
|
|
125
|
+
│ │ ├── handle-agent-create.function.ts
|
|
126
|
+
│ │ ├── handle-agent-delete.function.ts
|
|
127
|
+
│ │ ├── handle-agent-get.function.ts
|
|
128
|
+
│ │ ├── handle-agent-list.function.ts
|
|
129
|
+
│ │ ├── handle-completion.function.ts
|
|
130
|
+
│ │ ├── handle-prompt-get.function.ts
|
|
131
|
+
│ │ ├── handle-resource-read.function.ts
|
|
132
|
+
│ │ ├── handle-skill-delete.function.ts
|
|
133
|
+
│ │ ├── handle-skill-get.function.ts
|
|
134
|
+
│ │ ├── handle-skill-learn.function.ts
|
|
135
|
+
│ │ ├── handle-skill-list.function.ts
|
|
136
|
+
│ │ ├── handle-tool-call.function.ts
|
|
137
|
+
│ │ ├── parse-skill-content.function.ts
|
|
138
|
+
│ │ └── serialize-skill-content.function.ts
|
|
139
|
+
│ └── typings/
|
|
140
|
+
│ ├── mcp-client.interface.ts
|
|
141
|
+
│ └── mcp-types.interface.ts
|
|
142
|
+
│
|
|
143
|
+
├── worker-client/ ← IPC client
|
|
144
|
+
│ ├── index.ts
|
|
145
|
+
│ ├── classes/
|
|
146
|
+
│ │ └── worker-client.class.ts
|
|
147
|
+
│ ├── functions/
|
|
148
|
+
│ │ ├── compute-context-id.function.ts
|
|
149
|
+
│ │ ├── create-worker-client.function.ts
|
|
150
|
+
│ │ ├── discover-daemon.function.ts
|
|
151
|
+
│ │ ├── resolve-db-path.function.ts
|
|
152
|
+
│ │ ├── spawn-daemon.function.ts
|
|
153
|
+
│ │ └── wait-for-daemon.function.ts
|
|
154
|
+
│ └── typings/
|
|
155
|
+
│ ├── add-section-result.model.ts
|
|
156
|
+
│ ├── content-result.model.ts
|
|
157
|
+
│ ├── daemon-info.model.ts
|
|
158
|
+
│ ├── gc-result.model.ts
|
|
159
|
+
│ ├── integrity-check-result.model.ts
|
|
160
|
+
│ ├── migrate-result.model.ts
|
|
161
|
+
│ ├── rebuild-result.model.ts
|
|
162
|
+
│ ├── remove-section-result.model.ts
|
|
163
|
+
│ ├── search-params.model.ts
|
|
164
|
+
│ ├── search-result.model.ts
|
|
165
|
+
│ ├── section.model.ts
|
|
166
|
+
│ ├── status-result.model.ts
|
|
167
|
+
│ ├── version-status.model.ts
|
|
168
|
+
│ ├── worker-client-error.interface.ts
|
|
169
|
+
│ └── worker-client-options.interface.ts
|
|
170
|
+
│
|
|
171
|
+
├── worker-daemon/ ← Daemon process
|
|
172
|
+
│ ├── index.ts
|
|
173
|
+
│ ├── classes/
|
|
174
|
+
│ │ └── worker-daemon.class.ts
|
|
175
|
+
│ ├── functions/
|
|
176
|
+
│ │ ├── create-host-imports.function.ts
|
|
177
|
+
│ │ ├── create-ipc-server.function.ts
|
|
178
|
+
│ │ ├── load-wasm-modules.function.ts
|
|
179
|
+
│ │ ├── read-config.function.ts
|
|
180
|
+
│ │ ├── run-worker.function.ts
|
|
181
|
+
│ │ └── start-daemon.function.ts
|
|
182
|
+
│ ├── typings/
|
|
183
|
+
│ │ ├── daemon-config.interface.ts
|
|
184
|
+
│ │ ├── ipc-handler.interface.ts
|
|
185
|
+
│ │ └── wasm-modules.interface.ts
|
|
186
|
+
│ └── constants/
|
|
187
|
+
│ └── daemon-defaults.constant.ts
|
|
188
|
+
│
|
|
189
|
+
├── wasm-codec/ ← WASM binary codec
|
|
190
|
+
│ ├── index.ts
|
|
191
|
+
│ └── functions/
|
|
192
|
+
│ ├── decode-compose-output.function.ts
|
|
193
|
+
│ ├── decode-document-manifest.function.ts
|
|
194
|
+
│ ├── decode-f32.function.ts
|
|
195
|
+
│ ├── decode-key-value-text.function.ts
|
|
196
|
+
│ ├── decode-remove-flag.function.ts
|
|
197
|
+
│ ├── decode-scored-results.function.ts
|
|
198
|
+
│ ├── decode-section-records.function.ts
|
|
199
|
+
│ ├── decode-string.function.ts
|
|
200
|
+
│ ├── decode-u32.function.ts
|
|
201
|
+
│ ├── decode-u64.function.ts
|
|
202
|
+
│ ├── encode-add-section-params.function.ts
|
|
203
|
+
│ ├── encode-group-params.function.ts
|
|
204
|
+
│ ├── encode-identifier-list.function.ts
|
|
205
|
+
│ ├── encode-kbid-list.function.ts
|
|
206
|
+
│ ├── encode-option-string.function.ts
|
|
207
|
+
│ ├── encode-search-params.function.ts
|
|
208
|
+
│ ├── encode-section-type.function.ts
|
|
209
|
+
│ ├── encode-string.function.ts
|
|
210
|
+
│ ├── encode-u32.function.ts
|
|
211
|
+
│ └── encode-update-section-params.function.ts
|
|
212
|
+
│
|
|
213
|
+
├── version/ ← Package version
|
|
214
|
+
│ ├── index.ts
|
|
215
|
+
│ └── constants/
|
|
216
|
+
│ └── version.constant.ts
|
|
217
|
+
│
|
|
218
|
+
├── runtime/ ← Runtime detection
|
|
219
|
+
│ ├── index.ts
|
|
220
|
+
│ ├── functions/
|
|
221
|
+
│ │ ├── detect-runtime.function.ts
|
|
222
|
+
│ │ └── get-args.function.ts
|
|
223
|
+
│ └── typings/
|
|
224
|
+
│ └── runtime.type.ts
|
|
225
|
+
│
|
|
226
|
+
├── platform/ ← OS abstractions
|
|
227
|
+
│ ├── index.ts
|
|
228
|
+
│ └── functions/
|
|
229
|
+
│ ├── get-ipc-path.function.ts
|
|
230
|
+
│ ├── get-tmpdir.function.ts
|
|
231
|
+
│ └── is-process-alive.function.ts
|
|
232
|
+
│
|
|
233
|
+
└── hash/ ← SHA-256 hashing
|
|
234
|
+
├── index.ts
|
|
235
|
+
└── functions/
|
|
236
|
+
└── compute-sha256.function.ts
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Module Conventions
|
|
240
|
+
|
|
241
|
+
Every module follows the directory structure defined
|
|
242
|
+
in the TypeScript skill (`.claude/skills/typescript.md`).
|
|
243
|
+
|
|
244
|
+
### Directory Roles
|
|
245
|
+
|
|
246
|
+
| Directory | Contents | File suffix |
|
|
247
|
+
|---------------|----------------------------|---------------------|
|
|
248
|
+
| `classes/` | One class per file | `.class.ts` |
|
|
249
|
+
| `functions/` | One function per file | `.function.ts` |
|
|
250
|
+
| `constants/` | Related constants grouped | `.constant.ts` |
|
|
251
|
+
| `typings/` | Type declarations | `.type.ts`, `.enum.ts`, `.interface.ts`, `.model.ts` |
|
|
252
|
+
| `tests/` | BDD module integration | `.spec.ts` |
|
|
253
|
+
| (root) | TDD unit specs + barrel | `.spec.ts`, `index.ts` |
|
|
254
|
+
|
|
255
|
+
### Import Conventions
|
|
256
|
+
|
|
257
|
+
All imports go to `src/shared/[module]/` -- there is
|
|
258
|
+
**no** `src/shared/index.ts` barrel.
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
// Import from sub-module barrel
|
|
262
|
+
import {
|
|
263
|
+
WorkerClient,
|
|
264
|
+
} from './shared/worker-client/index.ts';
|
|
265
|
+
|
|
266
|
+
// Import from specific file
|
|
267
|
+
import {
|
|
268
|
+
createWorkerClient,
|
|
269
|
+
} from './shared/worker-client/functions/create-worker-client.function.ts';
|
|
270
|
+
|
|
271
|
+
// Import shared utility
|
|
272
|
+
import {
|
|
273
|
+
computeSha256,
|
|
274
|
+
} from './shared/hash/functions/compute-sha256.function.ts';
|
|
275
|
+
|
|
276
|
+
// Type-only imports (separate statement)
|
|
277
|
+
import type {
|
|
278
|
+
WorkerClientOptions,
|
|
279
|
+
} from './shared/worker-client/typings/worker-client-options.interface.ts';
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
All imports use `.ts` extensions (Deno requires them).
|
|
283
|
+
Type-only imports use separate `import type`
|
|
284
|
+
statements.
|
|
285
|
+
|
|
286
|
+
### File Naming
|
|
287
|
+
|
|
288
|
+
| Category | Convention | Example |
|
|
289
|
+
|------------|---------------------|----------------------------|
|
|
290
|
+
| Module dir | kebab-case | `worker-client/` |
|
|
291
|
+
| Class file | `<name>.class.ts` | `worker-client.class.ts` |
|
|
292
|
+
| Function | `<name>.function.ts`| `spawn-daemon.function.ts` |
|
|
293
|
+
| Constant | `<name>.constant.ts`| `defaults.constant.ts` |
|
|
294
|
+
| Interface | `<name>.interface.ts`| `cli-options.interface.ts` |
|
|
295
|
+
| Type alias | `<name>.type.ts` | `daemon-status.type.ts` |
|
|
296
|
+
| Enum | `<name>.enum.ts` | `output-format.enum.ts` |
|
|
297
|
+
| Model | `<name>.model.ts` | `search-result.model.ts` |
|
|
298
|
+
| TDD spec | `<name>.spec.ts` | `spawn-daemon.spec.ts` |
|
|
299
|
+
| BDD spec | `<scenario>.spec.ts`| `search-workflow.spec.ts` |
|
|
300
|
+
| Barrel | `index.ts` | `index.ts` |
|
|
301
|
+
|
|
302
|
+
### Dual Runtime
|
|
303
|
+
|
|
304
|
+
All code must work on both Deno and Node.js >= 20:
|
|
305
|
+
|
|
306
|
+
- No `node:` protocol in library code
|
|
307
|
+
- No Deno-specific APIs (`Deno.readTextFile`) in
|
|
308
|
+
library code
|
|
309
|
+
- Runtime detection via `typeof Deno !== 'undefined'`
|
|
310
|
+
- Platform abstractions in `shared/platform/`
|
|
311
|
+
|
|
312
|
+
## Build Output
|
|
313
|
+
|
|
314
|
+
```
|
|
315
|
+
dist/
|
|
316
|
+
├── mod.mjs ← ESM library
|
|
317
|
+
├── mod.cjs ← CJS library
|
|
318
|
+
├── mod.d.ts ← declarations
|
|
319
|
+
├── cli.mjs ← ESM CLI+MCP (shebang)
|
|
320
|
+
├── cli.cjs ← CJS CLI+MCP (shebang)
|
|
321
|
+
├── worker.mjs ← ESM daemon (shebang)
|
|
322
|
+
├── worker.cjs ← CJS daemon (shebang)
|
|
323
|
+
├── chunk-*.mjs ← shared code chunks
|
|
324
|
+
└── src/
|
|
325
|
+
└── **/*.d.ts ← per-file declarations
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Doc Directory Structure
|
|
329
|
+
|
|
330
|
+
Documentation mirrors the source layout. All module
|
|
331
|
+
docs live under `shared/`, matching the source tree.
|
|
332
|
+
|
|
333
|
+
```
|
|
334
|
+
docs/modules/typescript/
|
|
335
|
+
├── overview.md ← this file
|
|
336
|
+
└── shared/
|
|
337
|
+
├── module.md ← shared overview
|
|
338
|
+
├── cli/
|
|
339
|
+
│ ├── module.md
|
|
340
|
+
│ ├── functions.md
|
|
341
|
+
│ ├── typings.md
|
|
342
|
+
│ └── constants.md
|
|
343
|
+
├── mcp/
|
|
344
|
+
│ ├── module.md
|
|
345
|
+
│ ├── classes.md
|
|
346
|
+
│ ├── functions.md
|
|
347
|
+
│ └── typings.md
|
|
348
|
+
├── worker-client/
|
|
349
|
+
│ ├── module.md
|
|
350
|
+
│ ├── classes.md
|
|
351
|
+
│ ├── functions.md
|
|
352
|
+
│ └── typings.md
|
|
353
|
+
├── worker-daemon/
|
|
354
|
+
│ ├── module.md
|
|
355
|
+
│ ├── classes.md
|
|
356
|
+
│ ├── functions.md
|
|
357
|
+
│ ├── typings.md
|
|
358
|
+
│ └── constants.md
|
|
359
|
+
├── wasm-codec/
|
|
360
|
+
│ ├── module.md
|
|
361
|
+
│ └── functions.md
|
|
362
|
+
├── version/
|
|
363
|
+
│ └── module.md
|
|
364
|
+
├── runtime/
|
|
365
|
+
│ ├── module.md
|
|
366
|
+
│ ├── functions.md
|
|
367
|
+
│ └── typings.md
|
|
368
|
+
├── platform/
|
|
369
|
+
│ ├── module.md
|
|
370
|
+
│ └── functions.md
|
|
371
|
+
└── hash/
|
|
372
|
+
├── module.md
|
|
373
|
+
└── functions.md
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
`module.md` = `index.ts` (module entry point).
|
|
377
|
+
Category files document the implementations within
|
|
378
|
+
each subdirectory.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# cli/constants -- CLI Defaults
|
|
2
|
+
|
|
3
|
+
*Default values for CLI options.*
|
|
4
|
+
|
|
5
|
+
## Source
|
|
6
|
+
|
|
7
|
+
`src/shared/cli/constants/`
|
|
8
|
+
|
|
9
|
+
### `defaults`
|
|
10
|
+
|
|
11
|
+
**File:** `defaults.constant.ts`
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
const DEFAULT_LIMIT = 20;
|
|
15
|
+
const DEFAULT_FORMAT = OutputFormat.Json;
|
|
16
|
+
const DEFAULT_MODE = 'sections';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| Constant | Value | Used by |
|
|
20
|
+
|------------------|-------------|--------------|
|
|
21
|
+
| `DEFAULT_LIMIT` | `20` | `parseArgs` |
|
|
22
|
+
| `DEFAULT_FORMAT` | `'json'` | `parseArgs` |
|
|
23
|
+
| `DEFAULT_MODE` | `'sections'`| `parseArgs` |
|