@dikolab/kbdb 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLA.md +68 -0
- package/LICENSE +676 -12
- package/LICENSING.md +58 -0
- package/README.md +47 -24
- package/README.md.bak +320 -0
- package/dist/README.md +320 -0
- package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
- package/dist/chunk-QLJ33C74.mjs.map +7 -0
- package/dist/cli.cjs +550 -232
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.d.ts +0 -8
- package/dist/cli.mjs +483 -154
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +36 -5
- package/dist/kbdb-worker.cjs.map +3 -3
- package/dist/mod.cjs +89 -30
- package/dist/mod.cjs.map +4 -4
- package/dist/mod.mjs +88 -30
- package/dist/mod.mjs.map +4 -4
- package/dist/src/cli.d.ts +0 -8
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
- package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
- package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
- package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
- package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
- package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
- package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
- package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
- package/dist/src/shared/cli/index.d.ts +4 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
- package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
- package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
- package/dist/src/shared/wasm-codec/index.d.ts +1 -1
- package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
- package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
- package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
- package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
- package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
- package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
- package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
- package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
- package/dist/src/worker.d.ts +0 -7
- package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
- package/dist/wasm/default-embedding/package.json +1 -1
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/package.json +1 -1
- package/dist/wasm/fs-migration/package.json +1 -1
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/package.json +1 -1
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/wasm/query-parser/package.json +1 -1
- package/dist/worker.d.ts +0 -7
- package/dist/worker.mjs +37 -6
- package/dist/worker.mjs.map +3 -3
- package/package.json +10 -9
- package/dist/chunk-BJXEVALU.mjs.map +0 -7
- package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
- package/docs/details/README.md +0 -30
- package/docs/details/agent-tooling.md +0 -132
- package/docs/details/cli.md +0 -777
- package/docs/details/knowledge-base.md +0 -180
- package/docs/details/library-api.md +0 -495
- package/docs/details/mcp-server.md +0 -482
- package/docs/details/search-and-ranking.md +0 -575
- package/docs/details/storage.md +0 -531
- package/docs/goals/agents.md +0 -751
- package/docs/goals/architecture.svg +0 -198
- package/docs/goals/auto-capture.md +0 -378
- package/docs/goals/benchmarking.md +0 -296
- package/docs/goals/cli.md +0 -2654
- package/docs/goals/concurrency.md +0 -259
- package/docs/goals/content-composer.md +0 -609
- package/docs/goals/content-parser.md +0 -279
- package/docs/goals/database.md +0 -1679
- package/docs/goals/document.md +0 -368
- package/docs/goals/hybrid-search.md +0 -465
- package/docs/goals/mcp.md +0 -1541
- package/docs/goals/overview.md +0 -124
- package/docs/goals/query-parser.md +0 -373
- package/docs/goals/query-result.md +0 -860
- package/docs/goals/semantic-dedup.md +0 -233
- package/docs/goals/skills.md +0 -810
- package/docs/goals/sync.md +0 -217
- package/docs/goals/worker-client.md +0 -1005
- package/docs/goals/worker-daemon.md +0 -1547
- package/docs/modules/overview.md +0 -319
- package/docs/modules/rust/embedding/module.md +0 -91
- package/docs/modules/rust/fs-database/functions/document.md +0 -48
- package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
- package/docs/modules/rust/fs-database/functions/io.md +0 -87
- package/docs/modules/rust/fs-database/functions/module.md +0 -22
- package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
- package/docs/modules/rust/fs-database/functions/section.md +0 -76
- package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
- package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
- package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
- package/docs/modules/rust/fs-database/indexes/module.md +0 -64
- package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
- package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
- package/docs/modules/rust/fs-database/module.md +0 -150
- package/docs/modules/rust/fs-database/types/catalog.md +0 -53
- package/docs/modules/rust/fs-database/types/module.md +0 -12
- package/docs/modules/rust/fs-database/types/section.md +0 -127
- package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
- package/docs/modules/rust/kb-worker/functions/module.md +0 -20
- package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
- package/docs/modules/rust/kb-worker/functions/search.md +0 -173
- package/docs/modules/rust/kb-worker/functions/write.md +0 -172
- package/docs/modules/rust/kb-worker/module.md +0 -171
- package/docs/modules/rust/kb-worker/types/cache.md +0 -90
- package/docs/modules/rust/kb-worker/types/context.md +0 -26
- package/docs/modules/rust/kb-worker/types/module.md +0 -16
- package/docs/modules/rust/kb-worker/types/status.md +0 -29
- package/docs/modules/rust/kb-worker/types/token.md +0 -50
- package/docs/modules/rust/overview.md +0 -531
- package/docs/modules/rust/query-parser/functions/extract.md +0 -56
- package/docs/modules/rust/query-parser/functions/module.md +0 -18
- package/docs/modules/rust/query-parser/functions/parse.md +0 -33
- package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
- package/docs/modules/rust/query-parser/functions/rank.md +0 -85
- package/docs/modules/rust/query-parser/module.md +0 -131
- package/docs/modules/rust/query-parser/types/cache.md +0 -39
- package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
- package/docs/modules/rust/query-parser/types/module.md +0 -18
- package/docs/modules/rust/query-parser/types/token.md +0 -46
- package/docs/modules/rust/shared/content-composer/functions.md +0 -114
- package/docs/modules/rust/shared/content-composer/module.md +0 -147
- package/docs/modules/rust/shared/content-composer/types.md +0 -93
- package/docs/modules/rust/shared/content-parser/functions.md +0 -72
- package/docs/modules/rust/shared/content-parser/module.md +0 -99
- package/docs/modules/rust/shared/content-parser/types.md +0 -71
- package/docs/modules/rust/shared/corpus/module.md +0 -24
- package/docs/modules/rust/shared/corpus/types.md +0 -141
- package/docs/modules/rust/shared/document/module.md +0 -25
- package/docs/modules/rust/shared/document/types.md +0 -154
- package/docs/modules/rust/shared/encode/module.md +0 -22
- package/docs/modules/rust/shared/encode/traits.md +0 -304
- package/docs/modules/rust/shared/error/module.md +0 -28
- package/docs/modules/rust/shared/error/types.md +0 -302
- package/docs/modules/rust/shared/kbid/module.md +0 -24
- package/docs/modules/rust/shared/kbid/types.md +0 -147
- package/docs/modules/rust/shared/memory/functions.md +0 -209
- package/docs/modules/rust/shared/memory/module.md +0 -24
- package/docs/modules/rust/shared/module.md +0 -196
- package/docs/modules/rust/shared/pipeline/functions.md +0 -141
- package/docs/modules/rust/shared/pipeline/module.md +0 -62
- package/docs/modules/rust/shared/pipeline/types.md +0 -43
- package/docs/modules/rust/shared/query/module.md +0 -27
- package/docs/modules/rust/shared/query/types.md +0 -236
- package/docs/modules/rust/shared/section/module.md +0 -25
- package/docs/modules/rust/shared/section/types.md +0 -294
- package/docs/modules/rust/shared/term/module.md +0 -25
- package/docs/modules/rust/shared/term/types.md +0 -139
- package/docs/modules/typescript/cli.md +0 -131
- package/docs/modules/typescript/kbdb-worker.md +0 -150
- package/docs/modules/typescript/overview.md +0 -400
- package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
- package/docs/modules/typescript/shared/cli/constants.md +0 -23
- package/docs/modules/typescript/shared/cli/functions.md +0 -809
- package/docs/modules/typescript/shared/cli/module.md +0 -138
- package/docs/modules/typescript/shared/cli/typings.md +0 -197
- package/docs/modules/typescript/shared/embedding/functions.md +0 -200
- package/docs/modules/typescript/shared/embedding/module.md +0 -77
- package/docs/modules/typescript/shared/embedding/typings.md +0 -124
- package/docs/modules/typescript/shared/hash/functions.md +0 -20
- package/docs/modules/typescript/shared/hash/module.md +0 -21
- package/docs/modules/typescript/shared/log/constants.md +0 -82
- package/docs/modules/typescript/shared/log/functions.md +0 -131
- package/docs/modules/typescript/shared/log/module.md +0 -153
- package/docs/modules/typescript/shared/log/typings.md +0 -82
- package/docs/modules/typescript/shared/mcp/classes.md +0 -179
- package/docs/modules/typescript/shared/mcp/functions.md +0 -386
- package/docs/modules/typescript/shared/mcp/module.md +0 -160
- package/docs/modules/typescript/shared/mcp/typings.md +0 -529
- package/docs/modules/typescript/shared/module.md +0 -110
- package/docs/modules/typescript/shared/platform/functions.md +0 -42
- package/docs/modules/typescript/shared/platform/module.md +0 -25
- package/docs/modules/typescript/shared/runtime/functions.md +0 -26
- package/docs/modules/typescript/shared/runtime/module.md +0 -27
- package/docs/modules/typescript/shared/runtime/typings.md +0 -13
- package/docs/modules/typescript/shared/version/module.md +0 -27
- package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
- package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
- package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
- package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
- package/docs/modules/typescript/shared/worker-client/module.md +0 -92
- package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
- package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
- package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
- package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
- package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
- package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
- package/docs/overview.md +0 -191
- package/docs/release-notes/0.1.0.md +0 -189
- package/docs/release-notes/0.1.1.md +0 -46
- package/docs/release-notes/0.1.2.md +0 -38
- package/docs/release-notes/0.1.3.md +0 -42
- package/docs/release-notes/0.2.0.md +0 -147
- package/docs/release-notes/0.3.0.md +0 -89
- package/docs/release-notes/0.3.1.md +0 -121
- package/docs/release-notes/0.3.2.md +0 -64
- package/docs/release-notes/0.4.0.md +0 -80
- package/docs/release-notes/0.4.1.md +0 -149
- package/docs/release-notes/0.4.3.md +0 -60
- package/docs/release-notes/0.5.0.md +0 -41
- package/docs/release-notes/README.md +0 -16
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# embedding/typings -- Embedding Type Definitions
|
|
2
|
-
|
|
3
|
-
*Interfaces and type aliases for the embedding
|
|
4
|
-
module's providers, configuration, and search
|
|
5
|
-
results.*
|
|
6
|
-
|
|
7
|
-
## Source
|
|
8
|
-
|
|
9
|
-
`src/shared/embedding/typings/`
|
|
10
|
-
|
|
11
|
-
## Typings
|
|
12
|
-
|
|
13
|
-
### `EmbeddingProvider`
|
|
14
|
-
|
|
15
|
-
**File:** `embedding-provider.typing.ts`
|
|
16
|
-
|
|
17
|
-
Core abstraction for text embedding. Accepts a batch
|
|
18
|
-
of texts and returns a vector for each. Implemented
|
|
19
|
-
by `TfidfEmbeddingProvider` (built-in default),
|
|
20
|
-
`NullEmbeddingProvider`, `OnnxEmbeddingProvider`,
|
|
21
|
-
and `ApiEmbeddingProvider`.
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
interface EmbeddingProvider {
|
|
25
|
-
embed(texts: string[]): Promise<Float32Array[]>;
|
|
26
|
-
dimensions(): number;
|
|
27
|
-
modelName(): string;
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
| Member | Description |
|
|
32
|
-
|--------------|-----------------------------------------|
|
|
33
|
-
| `embed` | Produces one embedding vector per input |
|
|
34
|
-
| | text; accepts an array for batching |
|
|
35
|
-
| | efficiency |
|
|
36
|
-
| `dimensions` | Returns the length of each vector |
|
|
37
|
-
| | (e.g. 384 for MiniLM) |
|
|
38
|
-
| `modelName` | Returns a stable identifier stored in |
|
|
39
|
-
| | `vectors-meta.toml`; used to detect |
|
|
40
|
-
| | model changes that require a rebuild |
|
|
41
|
-
|
|
42
|
-
### `EmbeddingConfig`
|
|
43
|
-
|
|
44
|
-
**File:** `embedding-config.typing.ts`
|
|
45
|
-
|
|
46
|
-
Configuration read from the `[embedding]` section
|
|
47
|
-
of `worker.toml`. Determines which `EmbeddingProvider`
|
|
48
|
-
implementation to instantiate at daemon startup.
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
interface EmbeddingConfig {
|
|
52
|
-
provider: 'none' | 'onnx' | 'api';
|
|
53
|
-
model?: string;
|
|
54
|
-
apiEndpoint?: string;
|
|
55
|
-
apiKey?: string;
|
|
56
|
-
dimensions?: number;
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
| Property | Description |
|
|
61
|
-
|---------------|------------------------------------------|
|
|
62
|
-
| `provider` | Selects the backend: missing → |
|
|
63
|
-
| | `TfidfEmbeddingProvider`; `'none'` → |
|
|
64
|
-
| | `NullEmbeddingProvider`; |
|
|
65
|
-
| | `'onnx'` → `OnnxEmbeddingProvider`; |
|
|
66
|
-
| | `'api'` → `ApiEmbeddingProvider` |
|
|
67
|
-
| `model` | Path to the local ONNX model file; |
|
|
68
|
-
| | required when `provider` is `'onnx'` |
|
|
69
|
-
| `apiEndpoint` | Remote HTTP API URL; required when |
|
|
70
|
-
| | `provider` is `'api'` |
|
|
71
|
-
| `apiKey` | Bearer token for the remote API; |
|
|
72
|
-
| | required when `provider` is `'api'` |
|
|
73
|
-
| `dimensions` | Vector length; inferred from the model |
|
|
74
|
-
| | when possible; required for API |
|
|
75
|
-
| | providers that do not report dimensions |
|
|
76
|
-
|
|
77
|
-
### `VectorSearchResult`
|
|
78
|
-
|
|
79
|
-
**File:** `vector-search-result.typing.ts`
|
|
80
|
-
|
|
81
|
-
A single result from a vector similarity search.
|
|
82
|
-
Used as input to the RRF fusion step alongside
|
|
83
|
-
lexical search results.
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
interface VectorSearchResult {
|
|
87
|
-
kbid: string;
|
|
88
|
-
similarity: number;
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
| Property | Description |
|
|
93
|
-
|--------------|-----------------------------------------|
|
|
94
|
-
| `kbid` | Knowledge-base identifier of the |
|
|
95
|
-
| | matched section |
|
|
96
|
-
| `similarity` | Cosine similarity score in [-1, 1] |
|
|
97
|
-
|
|
98
|
-
### `VectorIndexMeta`
|
|
99
|
-
|
|
100
|
-
**File:** `vector-index-meta.typing.ts`
|
|
101
|
-
|
|
102
|
-
Metadata stored in `vectors-meta.toml` alongside
|
|
103
|
-
`vectors.idx`. Used to detect stale indexes: when
|
|
104
|
-
`model` differs from the current provider's
|
|
105
|
-
`modelName()`, vectors must be rebuilt.
|
|
106
|
-
|
|
107
|
-
```ts
|
|
108
|
-
interface VectorIndexMeta {
|
|
109
|
-
model: string;
|
|
110
|
-
dimensions: number;
|
|
111
|
-
recordCount: number;
|
|
112
|
-
version: number;
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
| Property | Description |
|
|
117
|
-
|---------------|-----------------------------------------|
|
|
118
|
-
| `model` | `modelName()` value at index build time |
|
|
119
|
-
| `dimensions` | Vector length used when building the |
|
|
120
|
-
| | index |
|
|
121
|
-
| `recordCount` | Number of vectors stored in the index |
|
|
122
|
-
| `version` | Format version; currently `1` |
|
|
123
|
-
|
|
124
|
-
No spec -- typings are compile-time only.
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# hash/functions -- Hash Functions
|
|
2
|
-
|
|
3
|
-
**Source:** `src/shared/hash/functions/`
|
|
4
|
-
|
|
5
|
-
## computeSha256
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
computeSha256(input: string): Promise<string>
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Returns a hex-encoded SHA-256 hash of the input string.
|
|
12
|
-
|
|
13
|
-
Uses the Web Crypto API
|
|
14
|
-
(`globalThis.crypto.subtle.digest`), which is available
|
|
15
|
-
in both Deno and Node.js >= 20.
|
|
16
|
-
|
|
17
|
-
### Usage
|
|
18
|
-
|
|
19
|
-
Used by `compute-context-id.function.ts` (truncated to
|
|
20
|
-
16 hex chars) and content hashing.
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# hash -- Hashing Utilities
|
|
2
|
-
|
|
3
|
-
**Source:** `src/shared/hash/`
|
|
4
|
-
|
|
5
|
-
## Responsibility
|
|
6
|
-
|
|
7
|
-
SHA-256 hashing for context ID computation and
|
|
8
|
-
content-addressable storage.
|
|
9
|
-
|
|
10
|
-
## Directory Layout
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
src/shared/hash/
|
|
14
|
-
index.ts
|
|
15
|
-
functions/
|
|
16
|
-
compute-sha256.function.ts
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Exports
|
|
20
|
-
|
|
21
|
-
- [Functions](functions.md) -- `computeSha256`
|
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
```
|
|
@@ -1,131 +0,0 @@
|
|
|
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.
|
|
@@ -1,153 +0,0 @@
|
|
|
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.
|
|
@@ -1,82 +0,0 @@
|
|
|
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.
|