@dikolab/kbdb 0.4.0 → 0.4.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 +13 -5
- package/dist/{chunk-BJPSPNGX.mjs → chunk-BJXEVALU.mjs} +115 -1
- package/dist/chunk-BJXEVALU.mjs.map +7 -0
- package/dist/cli.cjs +462 -79
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.mjs +356 -79
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +413 -53
- package/dist/kbdb-worker.cjs.map +4 -4
- package/dist/mod.cjs +230 -54
- package/dist/mod.cjs.map +4 -4
- package/dist/mod.mjs +229 -53
- package/dist/mod.mjs.map +4 -4
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +5 -0
- package/dist/src/shared/embedding/classes/tfidf-embedding-provider.class.d.ts +28 -0
- package/dist/src/shared/embedding/constants/tfidf-defaults.constant.d.ts +4 -0
- package/dist/src/shared/embedding/functions/create-embedding-provider.function.d.ts +5 -2
- package/dist/src/shared/embedding/index.d.ts +2 -0
- package/dist/src/shared/log/constants/log-colors.constant.d.ts +5 -0
- package/dist/src/shared/log/constants/log-defaults.constant.d.ts +3 -0
- package/dist/src/shared/log/constants/log-icons.constant.d.ts +3 -0
- package/dist/src/shared/log/functions/configure-log.function.d.ts +12 -0
- package/dist/src/shared/log/functions/log.function.d.ts +28 -0
- package/dist/src/shared/log/functions/parse-log-level.function.d.ts +10 -0
- package/dist/src/shared/log/functions/resolve-log-level.function.d.ts +12 -0
- package/dist/src/shared/log/functions/write-stderr.function.d.ts +10 -0
- package/dist/src/shared/log/index.d.ts +10 -0
- package/dist/src/shared/log/typings/log-config.interface.d.ts +7 -0
- package/dist/src/shared/log/typings/log-level.type.d.ts +7 -0
- package/dist/src/shared/log/typings/log-output.interface.d.ts +4 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +7 -0
- package/dist/src/shared/worker-client/functions/retry-on-timeout.function.d.ts +1 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
- package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +6 -1
- package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +5 -0
- package/dist/wasm/default-embedding/kbdb_default_embedding.d.ts +55 -0
- package/dist/wasm/default-embedding/kbdb_default_embedding.js +156 -0
- package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
- package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm.d.ts +12 -0
- package/dist/wasm/default-embedding/package.json +13 -0
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-migration/kbdb_fs_migration.d.ts +38 -0
- package/dist/wasm/fs-migration/kbdb_fs_migration.js +130 -0
- package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm +0 -0
- package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm.d.ts +9 -0
- package/dist/wasm/fs-migration/package.json +13 -0
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/worker.mjs +306 -54
- package/dist/worker.mjs.map +4 -4
- package/docs/details/agent-tooling.md +10 -0
- package/docs/details/cli.md +29 -13
- package/docs/details/knowledge-base.md +15 -8
- package/docs/details/mcp-server.md +16 -1
- package/docs/details/search-and-ranking.md +6 -2
- package/docs/goals/cli.md +33 -4
- package/docs/goals/content-parser.md +1 -1
- package/docs/goals/hybrid-search.md +71 -42
- package/docs/goals/mcp.md +3 -1
- package/docs/goals/overview.md +1 -1
- package/docs/goals/query-parser.md +1 -1
- package/docs/goals/semantic-dedup.md +7 -3
- package/docs/goals/worker-daemon.md +31 -20
- package/docs/modules/overview.md +43 -22
- package/docs/modules/rust/embedding/module.md +91 -0
- package/docs/modules/rust/overview.md +56 -21
- package/docs/modules/rust/query-parser/functions/module.md +7 -5
- package/docs/modules/rust/query-parser/functions/pipeline.md +6 -138
- package/docs/modules/rust/query-parser/module.md +16 -22
- package/docs/modules/rust/query-parser/types/module.md +5 -4
- package/docs/modules/rust/query-parser/types/token.md +5 -1
- package/docs/modules/rust/shared/content-parser/functions.md +1 -1
- package/docs/modules/rust/shared/memory/module.md +1 -1
- package/docs/modules/rust/shared/module.md +33 -5
- package/docs/modules/rust/shared/pipeline/functions.md +141 -0
- package/docs/modules/rust/shared/pipeline/module.md +62 -0
- package/docs/modules/rust/shared/pipeline/types.md +43 -0
- package/docs/modules/rust/shared/section/module.md +1 -1
- package/docs/modules/rust/shared/section/types.md +1 -1
- package/docs/modules/typescript/cli.md +4 -2
- package/docs/modules/typescript/kbdb-worker.md +20 -5
- package/docs/modules/typescript/overview.md +28 -6
- package/docs/modules/typescript/shared/cli/functions.md +15 -4
- package/docs/modules/typescript/shared/cli/typings.md +21 -0
- package/docs/modules/typescript/shared/embedding/functions.md +30 -3
- package/docs/modules/typescript/shared/embedding/module.md +10 -4
- package/docs/modules/typescript/shared/embedding/typings.md +7 -5
- package/docs/modules/typescript/shared/log/constants.md +82 -0
- package/docs/modules/typescript/shared/log/functions.md +131 -0
- package/docs/modules/typescript/shared/log/module.md +153 -0
- package/docs/modules/typescript/shared/log/typings.md +82 -0
- package/docs/modules/typescript/shared/module.md +22 -6
- package/docs/modules/typescript/shared/worker-daemon/functions.md +19 -6
- package/docs/modules/typescript/shared/worker-daemon/module.md +5 -2
- package/docs/modules/typescript/shared/worker-daemon/typings.md +13 -7
- package/docs/release-notes/0.4.1.md +149 -0
- package/package.json +2 -2
- package/dist/chunk-BJPSPNGX.mjs.map +0 -7
|
@@ -16,7 +16,8 @@ results.*
|
|
|
16
16
|
|
|
17
17
|
Core abstraction for text embedding. Accepts a batch
|
|
18
18
|
of texts and returns a vector for each. Implemented
|
|
19
|
-
by `
|
|
19
|
+
by `TfidfEmbeddingProvider` (built-in default),
|
|
20
|
+
`NullEmbeddingProvider`, `OnnxEmbeddingProvider`,
|
|
20
21
|
and `ApiEmbeddingProvider`.
|
|
21
22
|
|
|
22
23
|
```ts
|
|
@@ -58,10 +59,11 @@ interface EmbeddingConfig {
|
|
|
58
59
|
|
|
59
60
|
| Property | Description |
|
|
60
61
|
|---------------|------------------------------------------|
|
|
61
|
-
| `provider` | Selects the backend:
|
|
62
|
-
| | `
|
|
63
|
-
| | `
|
|
64
|
-
| | `
|
|
62
|
+
| `provider` | Selects the backend: missing → |
|
|
63
|
+
| | `TfidfEmbeddingProvider`; `'none'` → |
|
|
64
|
+
| | `NullEmbeddingProvider`; |
|
|
65
|
+
| | `'onnx'` → `OnnxEmbeddingProvider`; |
|
|
66
|
+
| | `'api'` → `ApiEmbeddingProvider` |
|
|
65
67
|
| `model` | Path to the local ONNX model file; |
|
|
66
68
|
| | required when `provider` is `'onnx'` |
|
|
67
69
|
| `apiEndpoint` | Remote HTTP API URL; required when |
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# log/constants -- Log Constants
|
|
2
|
+
|
|
3
|
+
*Default log level, per-level Unicode icons, and per-level
|
|
4
|
+
ANSI color codes.*
|
|
5
|
+
|
|
6
|
+
## Source
|
|
7
|
+
|
|
8
|
+
`src/shared/log/constants/`
|
|
9
|
+
|
|
10
|
+
## Constants
|
|
11
|
+
|
|
12
|
+
### `DEFAULT_LOG_LEVEL`
|
|
13
|
+
|
|
14
|
+
**File:** `log-defaults.constant.ts`
|
|
15
|
+
|
|
16
|
+
Default log level used when no CLI flag or `KBDB_LOG_LEVEL`
|
|
17
|
+
environment variable is set.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const DEFAULT_LOG_LEVEL = LogLevel.ERROR;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Evaluated by `resolveLogLevel` as the lowest-priority
|
|
24
|
+
fallback.
|
|
25
|
+
|
|
26
|
+
### `LOG_ICONS`
|
|
27
|
+
|
|
28
|
+
**File:** `log-icons.constant.ts`
|
|
29
|
+
|
|
30
|
+
Single-character Unicode icon used as the visual prefix
|
|
31
|
+
for each log level's output line.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const LOG_ICONS: Record<LogLevel, string> = {
|
|
35
|
+
[LogLevel.DEBUG]: '▸',
|
|
36
|
+
[LogLevel.INFO]: 'ℹ',
|
|
37
|
+
[LogLevel.WARNING]: '⚠',
|
|
38
|
+
[LogLevel.ERROR]: '✖',
|
|
39
|
+
};
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
| Level | Icon | Meaning |
|
|
43
|
+
|-----------|------|-------------------|
|
|
44
|
+
| `DEBUG` | `▸` | Right arrow |
|
|
45
|
+
| `INFO` | `ℹ` | Information sign |
|
|
46
|
+
| `WARNING` | `⚠` | Warning sign |
|
|
47
|
+
| `ERROR` | `✖` | Multiplication X |
|
|
48
|
+
|
|
49
|
+
### `LOG_COLORS`
|
|
50
|
+
|
|
51
|
+
**File:** `log-colors.constant.ts`
|
|
52
|
+
|
|
53
|
+
ANSI foreground color escape sequence applied before
|
|
54
|
+
each log line's content.
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
const LOG_COLORS: Record<LogLevel, string> = {
|
|
58
|
+
[LogLevel.DEBUG]: '\x1b[37m',
|
|
59
|
+
[LogLevel.INFO]: '\x1b[36m',
|
|
60
|
+
[LogLevel.WARNING]: '\x1b[33m',
|
|
61
|
+
[LogLevel.ERROR]: '\x1b[91m',
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Level | Code | Color |
|
|
66
|
+
|-----------|------------|-------------|
|
|
67
|
+
| `DEBUG` | `\x1b[37m` | White |
|
|
68
|
+
| `INFO` | `\x1b[36m` | Cyan |
|
|
69
|
+
| `WARNING` | `\x1b[33m` | Yellow |
|
|
70
|
+
| `ERROR` | `\x1b[91m` | Bright red |
|
|
71
|
+
|
|
72
|
+
### `ANSI_RESET`
|
|
73
|
+
|
|
74
|
+
**File:** `log-colors.constant.ts`
|
|
75
|
+
|
|
76
|
+
ANSI escape sequence that resets all text formatting.
|
|
77
|
+
Appended at the end of every log line so subsequent
|
|
78
|
+
terminal output is unaffected.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const ANSI_RESET = '\x1b[0m';
|
|
82
|
+
```
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# log/functions -- Logging Functions
|
|
2
|
+
|
|
3
|
+
*Core log emitter, configuration applier, level parser,
|
|
4
|
+
level resolver, and cross-runtime stderr writer.*
|
|
5
|
+
|
|
6
|
+
## Source
|
|
7
|
+
|
|
8
|
+
`src/shared/log/functions/`
|
|
9
|
+
|
|
10
|
+
## Functions
|
|
11
|
+
|
|
12
|
+
### `log`
|
|
13
|
+
|
|
14
|
+
**File:** `log.function.ts`
|
|
15
|
+
|
|
16
|
+
Writes a formatted, colorized message to the configured
|
|
17
|
+
output for the given level. Messages below the current
|
|
18
|
+
minimum level are silently discarded.
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
function log(
|
|
22
|
+
message: string,
|
|
23
|
+
level: LogLevel = LogLevel.ERROR,
|
|
24
|
+
): void;
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Output format:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
<ANSI_COLOR><ICON> [LEVEL_NAME] message<ANSI_RESET>\n
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The level defaults to `LogLevel.ERROR` when omitted.
|
|
34
|
+
The output target and minimum level are module-level
|
|
35
|
+
state managed by `configureLog`.
|
|
36
|
+
|
|
37
|
+
### `configureLog`
|
|
38
|
+
|
|
39
|
+
**File:** `configure-log.function.ts`
|
|
40
|
+
|
|
41
|
+
Applies a log configuration, setting the active log
|
|
42
|
+
level and optionally overriding the output target for
|
|
43
|
+
individual levels.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
function configureLog(config: LogConfig): void;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Only levels listed in `config.outputs` are affected;
|
|
50
|
+
all other level outputs remain unchanged. Calling this
|
|
51
|
+
function multiple times is safe -- the last call's
|
|
52
|
+
settings take effect.
|
|
53
|
+
|
|
54
|
+
### `parseLogLevel`
|
|
55
|
+
|
|
56
|
+
**File:** `parse-log-level.function.ts`
|
|
57
|
+
|
|
58
|
+
Parses a string into a `LogLevel` enum value.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
function parseLogLevel(value: string): LogLevel;
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Matching is case-insensitive. Recognized values are
|
|
65
|
+
`'debug'`, `'info'`, `'warning'`, and `'error'`.
|
|
66
|
+
Returns `LogLevel.WARNING` for any unrecognized value,
|
|
67
|
+
including empty strings.
|
|
68
|
+
|
|
69
|
+
| Input | Result |
|
|
70
|
+
|-------------|---------------------|
|
|
71
|
+
| `'debug'` | `LogLevel.DEBUG` |
|
|
72
|
+
| `'info'` | `LogLevel.INFO` |
|
|
73
|
+
| `'warning'` | `LogLevel.WARNING` |
|
|
74
|
+
| `'error'` | `LogLevel.ERROR` |
|
|
75
|
+
| `'ERROR'` | `LogLevel.ERROR` |
|
|
76
|
+
| `'unknown'` | `LogLevel.WARNING` |
|
|
77
|
+
| `''` | `LogLevel.WARNING` |
|
|
78
|
+
|
|
79
|
+
### `resolveLogLevel`
|
|
80
|
+
|
|
81
|
+
**File:** `resolve-log-level.function.ts`
|
|
82
|
+
|
|
83
|
+
Resolves the active log level from a CLI flag or the
|
|
84
|
+
`KBDB_LOG_LEVEL` environment variable, falling back to
|
|
85
|
+
`DEFAULT_LOG_LEVEL`.
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
function resolveLogLevel(
|
|
89
|
+
cliLevel?: LogLevel,
|
|
90
|
+
): LogLevel;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Priority order:
|
|
94
|
+
|
|
95
|
+
1. `cliLevel` when provided (highest priority)
|
|
96
|
+
2. `KBDB_LOG_LEVEL` environment variable, parsed via
|
|
97
|
+
`parseLogLevel`
|
|
98
|
+
3. `DEFAULT_LOG_LEVEL` (`LogLevel.ERROR`) when neither
|
|
99
|
+
is set
|
|
100
|
+
|
|
101
|
+
### `writeStderr`
|
|
102
|
+
|
|
103
|
+
**File:** `write-stderr.function.ts`
|
|
104
|
+
|
|
105
|
+
Writes a string to the process standard error stream.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
function writeStderr(message: string): void;
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Works on both Node.js (via `process.stderr.write`) and
|
|
112
|
+
Deno (via `Deno.stderr.writeSync`). Silently does
|
|
113
|
+
nothing when neither runtime API is available. Both
|
|
114
|
+
runtime APIs are accessed through `globalThis` to avoid
|
|
115
|
+
hard references to platform-specific globals.
|
|
116
|
+
|
|
117
|
+
## Testing
|
|
118
|
+
|
|
119
|
+
Each function has a `.spec.ts` in the functions
|
|
120
|
+
directory:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
src/shared/log/functions/
|
|
124
|
+
├── configure-log.spec.ts
|
|
125
|
+
├── log.spec.ts
|
|
126
|
+
├── parse-log-level.spec.ts
|
|
127
|
+
└── resolve-log-level.spec.ts
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`write-stderr.function.ts` is covered through the
|
|
131
|
+
`log.spec.ts` integration path.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# log -- Structured Logging
|
|
2
|
+
|
|
3
|
+
*Formats and routes diagnostic messages to stderr with
|
|
4
|
+
per-level ANSI color coding, Unicode icons, and a
|
|
5
|
+
configurable minimum verbosity threshold.*
|
|
6
|
+
|
|
7
|
+
## Source
|
|
8
|
+
|
|
9
|
+
`src/shared/log/`
|
|
10
|
+
|
|
11
|
+
## Responsibility
|
|
12
|
+
|
|
13
|
+
Provides a single `log(message, level)` entry point
|
|
14
|
+
that formats and emits a colorized line to the active
|
|
15
|
+
output for the given level. Messages below the current
|
|
16
|
+
minimum level are silently discarded.
|
|
17
|
+
|
|
18
|
+
The module owns its own mutable state (current level,
|
|
19
|
+
per-level output functions) and exposes `configureLog`
|
|
20
|
+
to replace that state at startup. All formatting
|
|
21
|
+
constants (icons, ANSI colors) are kept in dedicated
|
|
22
|
+
constant files so they can be consumed independently.
|
|
23
|
+
|
|
24
|
+
The module does **not** buffer messages, write to
|
|
25
|
+
stdout, or interact with the filesystem. All output is
|
|
26
|
+
written to stderr.
|
|
27
|
+
|
|
28
|
+
## Directory Layout
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
src/shared/log/
|
|
32
|
+
├── index.ts
|
|
33
|
+
├── constants/
|
|
34
|
+
│ ├── log-colors.constant.ts
|
|
35
|
+
│ ├── log-defaults.constant.ts
|
|
36
|
+
│ └── log-icons.constant.ts
|
|
37
|
+
├── functions/
|
|
38
|
+
│ ├── configure-log.function.ts
|
|
39
|
+
│ ├── configure-log.spec.ts
|
|
40
|
+
│ ├── log.function.ts
|
|
41
|
+
│ ├── log.spec.ts
|
|
42
|
+
│ ├── parse-log-level.function.ts
|
|
43
|
+
│ ├── parse-log-level.spec.ts
|
|
44
|
+
│ ├── resolve-log-level.function.ts
|
|
45
|
+
│ ├── resolve-log-level.spec.ts
|
|
46
|
+
│ └── write-stderr.function.ts
|
|
47
|
+
└── typings/
|
|
48
|
+
├── log-config.interface.ts
|
|
49
|
+
├── log-level.type.ts
|
|
50
|
+
└── log-output.interface.ts
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Exports
|
|
54
|
+
|
|
55
|
+
- **[functions.md](functions.md)** -- `log`,
|
|
56
|
+
`configureLog`, `parseLogLevel`, `resolveLogLevel`,
|
|
57
|
+
`writeStderr`.
|
|
58
|
+
- **[typings.md](typings.md)** -- `LogLevel`,
|
|
59
|
+
`LogOutput`, `LogConfig`.
|
|
60
|
+
- **[constants.md](constants.md)** -- `DEFAULT_LOG_LEVEL`,
|
|
61
|
+
`LOG_ICONS`, `LOG_COLORS`, `ANSI_RESET`.
|
|
62
|
+
|
|
63
|
+
## How Logging Works
|
|
64
|
+
|
|
65
|
+
### Level Filtering
|
|
66
|
+
|
|
67
|
+
`LogLevel` is a numeric enum ordered from most verbose
|
|
68
|
+
to least:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
DEBUG (0) < INFO (1) < WARNING (2) < ERROR (3)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
When `log(message, level)` is called, the level is
|
|
75
|
+
compared against the current minimum level. Messages
|
|
76
|
+
with a level strictly below the minimum are dropped
|
|
77
|
+
without any output.
|
|
78
|
+
|
|
79
|
+
### Output Format
|
|
80
|
+
|
|
81
|
+
Each accepted message is formatted as a single line:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
<ANSI_COLOR><ICON> [LEVEL_NAME] message<ANSI_RESET>\n
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
For example, an `ERROR` message renders as:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
\x1b[91m✖ [ERROR] something went wrong\x1b[0m\n
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Icons
|
|
94
|
+
|
|
95
|
+
Each level has a distinct Unicode icon from
|
|
96
|
+
`LOG_ICONS`:
|
|
97
|
+
|
|
98
|
+
| Level | Icon |
|
|
99
|
+
|---------|------|
|
|
100
|
+
| DEBUG | `▸` |
|
|
101
|
+
| INFO | `ℹ` |
|
|
102
|
+
| WARNING | `⚠` |
|
|
103
|
+
| ERROR | `✖` |
|
|
104
|
+
|
|
105
|
+
### ANSI Colors
|
|
106
|
+
|
|
107
|
+
Each level has a distinct foreground color from
|
|
108
|
+
`LOG_COLORS`:
|
|
109
|
+
|
|
110
|
+
| Level | ANSI Code | Appearance |
|
|
111
|
+
|---------|---------------|----------------|
|
|
112
|
+
| DEBUG | `\x1b[37m` | White |
|
|
113
|
+
| INFO | `\x1b[36m` | Cyan |
|
|
114
|
+
| WARNING | `\x1b[33m` | Yellow |
|
|
115
|
+
| ERROR | `\x1b[91m` | Bright red |
|
|
116
|
+
|
|
117
|
+
`ANSI_RESET` (`\x1b[0m`) is appended after every
|
|
118
|
+
message to restore the terminal's default style.
|
|
119
|
+
|
|
120
|
+
## Configuration Flow
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
CLI flag (--log-level) → resolveLogLevel(cliLevel)
|
|
124
|
+
↓
|
|
125
|
+
KBDB_LOG_LEVEL env var (if no CLI flag)
|
|
126
|
+
↓
|
|
127
|
+
DEFAULT_LOG_LEVEL = LogLevel.ERROR (fallback)
|
|
128
|
+
↓
|
|
129
|
+
configureLog({ level })
|
|
130
|
+
↓
|
|
131
|
+
log() uses the resolved level
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Priority order inside `resolveLogLevel`:
|
|
135
|
+
|
|
136
|
+
1. `cliLevel` argument -- highest priority
|
|
137
|
+
2. `KBDB_LOG_LEVEL` environment variable, parsed by
|
|
138
|
+
`parseLogLevel`
|
|
139
|
+
3. `DEFAULT_LOG_LEVEL` (`LogLevel.ERROR`) -- fallback
|
|
140
|
+
|
|
141
|
+
## Dependency Direction
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
cli.ts / worker.ts
|
|
145
|
+
└─ resolveLogLevel (reads env var + CLI flag)
|
|
146
|
+
└─ configureLog (writes module state)
|
|
147
|
+
└─ log (emits formatted lines)
|
|
148
|
+
└─ writeStderr (cross-runtime stderr write)
|
|
149
|
+
└─ LOG_COLORS, LOG_ICONS (formatting constants)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The `log` module has no dependency on any other
|
|
153
|
+
`src/shared/` module.
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# log/typings -- Log Type Definitions
|
|
2
|
+
|
|
3
|
+
*Enum, interface, and configuration shape for the log
|
|
4
|
+
module.*
|
|
5
|
+
|
|
6
|
+
## Source
|
|
7
|
+
|
|
8
|
+
`src/shared/log/typings/`
|
|
9
|
+
|
|
10
|
+
## Typings
|
|
11
|
+
|
|
12
|
+
### `LogLevel`
|
|
13
|
+
|
|
14
|
+
**File:** `log-level.type.ts`
|
|
15
|
+
|
|
16
|
+
Verbosity levels, ordered from most to least verbose.
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
enum LogLevel {
|
|
20
|
+
DEBUG = 0,
|
|
21
|
+
INFO = 1,
|
|
22
|
+
WARNING = 2,
|
|
23
|
+
ERROR = 3,
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Member | Value | Description |
|
|
28
|
+
|-----------|-------|-------------------------------------|
|
|
29
|
+
| `DEBUG` | `0` | Verbose diagnostic messages |
|
|
30
|
+
| `INFO` | `1` | Informational progress messages |
|
|
31
|
+
| `WARNING` | `2` | Non-fatal conditions worth noting |
|
|
32
|
+
| `ERROR` | `3` | Failures and unexpected conditions |
|
|
33
|
+
|
|
34
|
+
Numeric ordering enables threshold comparisons:
|
|
35
|
+
`level < currentLevel` discards messages below the
|
|
36
|
+
configured minimum.
|
|
37
|
+
|
|
38
|
+
### `LogOutput`
|
|
39
|
+
|
|
40
|
+
**File:** `log-output.interface.ts`
|
|
41
|
+
|
|
42
|
+
Writable target for a single log level.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
interface LogOutput {
|
|
46
|
+
readonly write: (message: string) => void;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
| Member | Description |
|
|
51
|
+
|---------|------------------------------------------|
|
|
52
|
+
| `write` | Receives a fully formatted log line |
|
|
53
|
+
|
|
54
|
+
`LogOutput` is the unit of per-level output override
|
|
55
|
+
passed in `LogConfig.outputs`. The default output for
|
|
56
|
+
all levels is `writeStderr`.
|
|
57
|
+
|
|
58
|
+
### `LogConfig`
|
|
59
|
+
|
|
60
|
+
**File:** `log-config.interface.ts`
|
|
61
|
+
|
|
62
|
+
Configuration for the log module, accepted by
|
|
63
|
+
`configureLog`.
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
interface LogConfig {
|
|
67
|
+
readonly level: LogLevel;
|
|
68
|
+
readonly outputs?: Partial<Record<LogLevel, LogOutput>>;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
| Property | Description |
|
|
73
|
+
|-----------|-------------------------------------------|
|
|
74
|
+
| `level` | Minimum level; messages below are dropped |
|
|
75
|
+
| `outputs` | Optional per-level output overrides |
|
|
76
|
+
|
|
77
|
+
`outputs` is a partial record keyed by `LogLevel`.
|
|
78
|
+
Only levels present in the record are affected;
|
|
79
|
+
unspecified levels keep their existing output target.
|
|
80
|
+
Omitting `outputs` entirely changes only the level.
|
|
81
|
+
|
|
82
|
+
No spec -- typings are compile-time only.
|
|
@@ -33,7 +33,8 @@ src/shared/
|
|
|
33
33
|
├── version/ ← Package version constant
|
|
34
34
|
├── runtime/ ← Deno / Node.js detection
|
|
35
35
|
├── platform/ ← OS abstractions
|
|
36
|
-
|
|
36
|
+
├── hash/ ← SHA-256 hashing
|
|
37
|
+
└── log/ ← Structured logging
|
|
37
38
|
```
|
|
38
39
|
|
|
39
40
|
## Modules
|
|
@@ -63,6 +64,9 @@ src/shared/
|
|
|
63
64
|
helpers (tmpdir, PID checks, IPC socket paths).
|
|
64
65
|
- **[hash/](hash/module.md)** -- SHA-256 hashing via
|
|
65
66
|
Web Crypto API.
|
|
67
|
+
- **[log/](log/module.md)** -- Structured logging with
|
|
68
|
+
configurable levels, ANSI colors, and per-level
|
|
69
|
+
Unicode icons.
|
|
66
70
|
|
|
67
71
|
## Dependency Direction
|
|
68
72
|
|
|
@@ -78,17 +82,29 @@ src/worker.ts
|
|
|
78
82
|
|
|
79
83
|
shared/worker-client/
|
|
80
84
|
├── shared/platform/
|
|
81
|
-
|
|
85
|
+
├── shared/hash/
|
|
86
|
+
└── shared/log/
|
|
82
87
|
|
|
83
88
|
shared/worker-daemon/
|
|
84
|
-
|
|
89
|
+
├── shared/platform/
|
|
90
|
+
└── shared/log/
|
|
91
|
+
|
|
92
|
+
shared/cli/
|
|
93
|
+
└── shared/log/
|
|
94
|
+
|
|
95
|
+
shared/mcp/
|
|
96
|
+
└── shared/log/
|
|
85
97
|
|
|
86
98
|
mod.ts
|
|
87
99
|
└── shared/version/
|
|
88
100
|
```
|
|
89
101
|
|
|
90
102
|
Utility modules (`version`, `runtime`, `platform`,
|
|
91
|
-
`hash`) have no dependencies on application
|
|
92
|
-
Application modules may depend on utility
|
|
93
|
-
but not on each other, except through the
|
|
103
|
+
`hash`, `log`) have no dependencies on application
|
|
104
|
+
modules. Application modules may depend on utility
|
|
105
|
+
modules but not on each other, except through the
|
|
94
106
|
worker-client which both `cli` and `mcp` share.
|
|
107
|
+
`shared/log/` is a standalone utility with no
|
|
108
|
+
dependencies; `cli/`, `mcp/`, `worker-daemon/`, and
|
|
109
|
+
`worker-client/` all depend on it for structured
|
|
110
|
+
output.
|
|
@@ -15,9 +15,12 @@ and configuration reading.*
|
|
|
15
15
|
**File:** `run-worker.function.ts`
|
|
16
16
|
|
|
17
17
|
Worker daemon entry point extracted from
|
|
18
|
-
`src/worker.ts`.
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
`src/worker.ts`. Parses `argv` for the context path
|
|
19
|
+
and the optional `--log-level <level>` argument,
|
|
20
|
+
configures the log level, validates the context path,
|
|
21
|
+
and delegates to `startDaemon`.
|
|
22
|
+
|
|
23
|
+
Usage: `kbdb-worker <context-path> [--log-level <level>]`
|
|
21
24
|
|
|
22
25
|
```ts
|
|
23
26
|
async function runWorker(
|
|
@@ -39,9 +42,15 @@ interface WorkerDeps {
|
|
|
39
42
|
interface WorkerResult {
|
|
40
43
|
error?: string;
|
|
41
44
|
exitCode: number;
|
|
45
|
+
logLevel?: LogLevel;
|
|
42
46
|
}
|
|
43
47
|
```
|
|
44
48
|
|
|
49
|
+
`LogLevel` is `'debug' | 'info' | 'warning' | 'error'`.
|
|
50
|
+
The log level is resolved from the `--log-level` CLI
|
|
51
|
+
argument, then the `KBDB_LOG_LEVEL` environment
|
|
52
|
+
variable, then defaults to `'error'`.
|
|
53
|
+
|
|
45
54
|
Returns a `WorkerResult` without touching process
|
|
46
55
|
globals, making it fully testable.
|
|
47
56
|
|
|
@@ -139,8 +148,8 @@ interface AllocatorRef {
|
|
|
139
148
|
|
|
140
149
|
**File:** `load-wasm-modules.function.ts`
|
|
141
150
|
|
|
142
|
-
Compiles and instantiates the
|
|
143
|
-
|
|
151
|
+
Compiles and instantiates the WASM modules used by
|
|
152
|
+
the worker daemon.
|
|
144
153
|
|
|
145
154
|
```ts
|
|
146
155
|
async function loadWasmModules(
|
|
@@ -157,9 +166,13 @@ Loading sequence:
|
|
|
157
166
|
passing host imports.
|
|
158
167
|
3. Wires the exported `memory` and `kbdb_alloc`
|
|
159
168
|
function back into the deferred refs.
|
|
169
|
+
4. Compiles and instantiates
|
|
170
|
+
`default-embedding.wasm` -- no host imports
|
|
171
|
+
needed (pure computation). The module is
|
|
172
|
+
instantiated with an empty import object.
|
|
160
173
|
|
|
161
174
|
Returns a `WasmModules` object containing the
|
|
162
|
-
instantiated
|
|
175
|
+
instantiated modules and their shared memory.
|
|
163
176
|
|
|
164
177
|
### `createIpcServer`
|
|
165
178
|
|
|
@@ -15,9 +15,9 @@ signal.*
|
|
|
15
15
|
The worker-daemon module implements a detached
|
|
16
16
|
background process that:
|
|
17
17
|
|
|
18
|
-
- Loads and compiles the
|
|
18
|
+
- Loads and compiles the four WASM modules once at
|
|
19
19
|
startup (`query-parser.wasm`, `fs-database.wasm`,
|
|
20
|
-
`kb-worker.wasm`).
|
|
20
|
+
`default-embedding.wasm`, `kb-worker.wasm`).
|
|
21
21
|
- Reads configuration from `worker.toml` in the
|
|
22
22
|
context directory.
|
|
23
23
|
- Listens on a local IPC socket (Unix domain socket
|
|
@@ -91,6 +91,9 @@ src/worker.ts (entry point)
|
|
|
91
91
|
│ │ ├─ compile fs-database.wasm ──┤
|
|
92
92
|
│ │ │ (parallel, standalone, │
|
|
93
93
|
│ │ │ shared memory) │
|
|
94
|
+
│ │ ├─ compile default-embedding ─┤
|
|
95
|
+
│ │ │ (standalone, no host │
|
|
96
|
+
│ │ │ imports, pure computation)│
|
|
94
97
|
│ │ └─ compile kb-worker.wasm ────┘
|
|
95
98
|
│ │ (imports both modules)
|
|
96
99
|
│ ├─ init cache
|
|
@@ -105,21 +105,27 @@ type and is passed to `createIpcServer`.
|
|
|
105
105
|
**File:** `wasm-modules.interface.ts`
|
|
106
106
|
|
|
107
107
|
References to the compiled and instantiated WASM
|
|
108
|
-
|
|
108
|
+
modules and their shared exported memory.
|
|
109
109
|
|
|
110
110
|
```ts
|
|
111
111
|
interface WasmModules {
|
|
112
112
|
readonly memory: WebAssembly.Memory;
|
|
113
113
|
readonly kbWorker: WebAssembly.Instance;
|
|
114
|
+
readonly embedding?: WebAssembly.Instance;
|
|
114
115
|
}
|
|
115
116
|
```
|
|
116
117
|
|
|
117
|
-
| Property
|
|
118
|
-
|
|
119
|
-
| `memory`
|
|
120
|
-
|
|
|
121
|
-
| `kbWorker`
|
|
122
|
-
|
|
|
118
|
+
| Property | Type | Description |
|
|
119
|
+
|-------------|------------------------|------------------------|
|
|
120
|
+
| `memory` | `WebAssembly.Memory` | Linear memory exported |
|
|
121
|
+
| | | by `kb-worker.wasm` |
|
|
122
|
+
| `kbWorker` | `WebAssembly.Instance` | Instantiated |
|
|
123
|
+
| | | `kb-worker.wasm` |
|
|
124
|
+
| `embedding` | `WebAssembly.Instance?`| Instantiated |
|
|
125
|
+
| | | `default-embedding.wasm`. |
|
|
126
|
+
| | | Optional -- absent only |
|
|
127
|
+
| | | when build omits the |
|
|
128
|
+
| | | embedding crate. |
|
|
123
129
|
|
|
124
130
|
Returned by `loadWasmModules()`.
|
|
125
131
|
|