@dikolab/kbdb 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/cli.cjs +268 -144
  2. package/dist/cli.cjs.map +4 -4
  3. package/dist/cli.mjs +225 -101
  4. package/dist/cli.mjs.map +4 -4
  5. package/dist/kbdb-worker.cjs +0 -0
  6. package/dist/mod.cjs +1 -1
  7. package/dist/mod.cjs.map +1 -1
  8. package/dist/mod.mjs +1 -1
  9. package/dist/mod.mjs.map +1 -1
  10. package/dist/src/shared/cli/functions/learn-markdown-document.function.d.ts +22 -0
  11. package/dist/src/shared/cli/functions/learn-target-content.function.d.ts +24 -0
  12. package/dist/src/shared/cli/functions/map-add-section-result.function.d.ts +12 -0
  13. package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +13 -9
  14. package/dist/src/shared/cli/functions/run-learn.function.d.ts +10 -59
  15. package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +11 -7
  16. package/dist/src/shared/cli/functions/split-markdown-sections.function.d.ts +12 -0
  17. package/dist/src/shared/cli/typings/learn-client.interface.d.ts +14 -28
  18. package/dist/src/shared/cli/typings/markdown-section.interface.d.ts +23 -0
  19. package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +11 -21
  20. package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +1 -15
  21. package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +13 -3
  22. package/dist/src/shared/query-filter/functions/matches-query.function.d.ts +17 -0
  23. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  24. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  25. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  26. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  27. package/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ import type { LearnClient } from '../typings/learn-client.interface.ts';
2
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
3
+ import type { LearnResult } from '../typings/learn-result.model.ts';
4
+ /**
5
+ * Attempts to ingest `content` as a multi-section markdown
6
+ * document, splitting on ATX headings and grouping the resulting
7
+ * sections under one shared document via `client.groupSections()`.
8
+ *
9
+ * Returns `undefined` when splitting does not apply -- fewer than
10
+ * two sections, or none carry a heading title -- signalling that
11
+ * the caller should fall back to single-section ingestion.
12
+ *
13
+ * @param client - learn client used to add and group sections
14
+ * @param options - parsed CLI options (tags, replace, description)
15
+ * @param path - source file path, or `'-'` for stdin
16
+ * @param content - raw markdown document text
17
+ * @param sourcePath - absolute file path for supersession, or
18
+ * `undefined` for stdin input
19
+ * @returns one `LearnResult` per section, or `undefined` when the
20
+ * document does not warrant splitting
21
+ */
22
+ export declare function learnMarkdownDocument(client: LearnClient, options: CliOptions, path: string, content: string, sourcePath?: string): Promise<LearnResult[] | undefined>;
@@ -0,0 +1,24 @@
1
+ import type { LearnClient } from '../typings/learn-client.interface.ts';
2
+ import type { CliOptions } from '../typings/cli-options.interface.ts';
3
+ import type { LearnResult } from '../typings/learn-result.model.ts';
4
+ /**
5
+ * Ingests one already-read target (a file's content, or stdin) as
6
+ * either a single section or, for eligible markdown input, a set
7
+ * of sections grouped under one document.
8
+ *
9
+ * Markdown splitting is attempted when `path` is `'-'` (stdin) or
10
+ * ends with `.md`, and `options.title` was not set explicitly --
11
+ * an explicit title always maps to a single section. When splitting
12
+ * does not apply, `content` is ingested as-is via `addSection()`.
13
+ *
14
+ * @param client - learn client to delegate ingestion to
15
+ * @param options - parsed CLI options for this invocation
16
+ * @param path - source file path, or `'-'` for stdin
17
+ * @param content - raw text content already read from `path`
18
+ * @param sourcePath - absolute file path for supersession, or
19
+ * `undefined` for stdin input
20
+ * @param level - hierarchical level for the single-section
21
+ * fallback; ignored when markdown splitting applies
22
+ * @returns one `LearnResult` per ingested section
23
+ */
24
+ export declare function learnTargetContent(client: LearnClient, options: CliOptions, path: string, content: string, sourcePath?: string, level?: number): Promise<LearnResult[]>;
@@ -0,0 +1,12 @@
1
+ import type { AddSectionResult } from '../../worker-client/typings/add-section-result.model.ts';
2
+ import type { LearnResult } from '../typings/learn-result.model.ts';
3
+ /**
4
+ * Maps an `AddSectionResult` returned by the worker daemon to the
5
+ * `LearnResult` record consumed by the `learn` CLI command.
6
+ *
7
+ * @param result - raw result from `client.addSection()`
8
+ * @param path - source file path, or `'-'` for stdin
9
+ * @param size - UTF-8 character count of the ingested content
10
+ * @param sectionType - semantic type used for ingestion
11
+ */
12
+ export declare function mapAddSectionResult(result: AddSectionResult, path: string, size: number, sectionType: string): LearnResult;
@@ -28,18 +28,22 @@ export interface AgentListClient {
28
28
  listDocumentsByType(docType: string): Promise<DocumentSummary[]>;
29
29
  }
30
30
  /**
31
- * Lists all agents stored in the knowledge base.
31
+ * Lists agents stored in the knowledge base.
32
32
  *
33
33
  * Retrieves all documents with `doc_type: 'agent'` and returns a
34
- * summary list. The `skillCount` for each agent is
35
- * `Math.max(0, sections.length - 1)` because the first section
36
- * always holds the agent's metadata JSON rather than a skill
37
- * reference.
34
+ * JSON envelope of matching agent names. When `options.args` is
35
+ * non-empty, the positional arguments are joined with a space
36
+ * and used as a case-insensitive substring filter against each
37
+ * agent's name. An empty query returns every agent. Filtering by
38
+ * description is not available here because it would require an
39
+ * extra `readSections` call per agent; use the MCP `agent-list`
40
+ * tool for description filtering.
38
41
  *
39
42
  * @param client - agent list client to delegate retrieval to
40
- * @param _options - parsed CLI options (unused; reserved for future
41
- * filtering flags)
42
- * @returns a `CommandResult` with serialised agent summary list
43
+ * @param options - parsed CLI options; positional `args` build
44
+ * the filter query
45
+ * @returns a `CommandResult` with a JSON envelope
46
+ * (`{ items, total, offset }`) of matching agent names
43
47
  */
44
- export declare function runAgentList(client: AgentListClient, _options: CliOptions): Promise<CommandResult>;
48
+ export declare function runAgentList(client: AgentListClient, options: CliOptions): Promise<CommandResult>;
45
49
  export {};
@@ -1,62 +1,9 @@
1
1
  import type { CliOptions } from '../typings/cli-options.interface.ts';
2
2
  import type { LearnResult } from '../typings/learn-result.model.ts';
3
- /** Enriched add-section result returned by the daemon. */
4
- interface AddSectionResult {
5
- /** List of knowledge-base identifiers assigned. */
6
- readonly items: string[];
7
- /** Number of items in the result set. */
8
- readonly total: number;
9
- /** Offset into the result set (always 0 for learn). */
10
- readonly offset: number;
11
- /**
12
- * Kbid of the section superseded via `--replace`,
13
- * or `null` / `undefined` when none.
14
- */
15
- readonly superseded?: string | null;
16
- /**
17
- * Advisory warning strings (e.g. `"heading_missing"`).
18
- * May be absent from older daemon versions.
19
- */
20
- readonly warnings?: string[];
21
- /**
22
- * Near-duplicate sections with similarity >= 0.85.
23
- * May be absent from older daemon versions.
24
- */
25
- readonly near_duplicates?: {
26
- readonly kbid: string;
27
- readonly similarity: number;
28
- }[];
29
- }
30
- /**
31
- * Minimal client interface required by `runLearn`.
32
- *
33
- * Decouples the CLI function from the concrete `WorkerClient`
34
- * implementation, making it straightforward to test with mocks.
35
- */
36
- export interface LearnClient {
37
- /**
38
- * Ingests a content section into the knowledge base.
39
- *
40
- * @param params - section metadata and raw text content
41
- * @returns enriched result containing the new kbid plus
42
- * optional supersession, warnings, and near-duplicate info
43
- */
44
- addSection(params: {
45
- sectionType: string;
46
- content: string;
47
- title?: string;
48
- description?: string;
49
- docid?: string;
50
- tags?: string[];
51
- replace?: boolean;
52
- sourcePath?: string;
53
- level?: number;
54
- }): Promise<AddSectionResult>;
55
- }
56
- /** Injectable I/O for testing without real stdin. */
57
- export interface LearnIO {
58
- readStdin: () => Promise<string>;
59
- }
3
+ import type { LearnClient } from '../typings/learn-client.interface.ts';
4
+ import type { LearnIO } from '../typings/learn-io.interface.ts';
5
+ export type { LearnClient } from '../typings/learn-client.interface.ts';
6
+ export type { LearnIO } from '../typings/learn-io.interface.ts';
60
7
  /**
61
8
  * Ingests one or more files or directories listed in `options.args`
62
9
  * into the knowledge base via the provided client.
@@ -72,11 +19,15 @@ export interface LearnIO {
72
19
  * directory to derive a level from, so it is sent unset unless
73
20
  * `options.level` is explicit.
74
21
  *
22
+ * `.md` files and stdin input are split into multiple sections on
23
+ * ATX headings and grouped under one document when the content has
24
+ * 2+ headings and `options.title` is not set explicitly -- see
25
+ * `learnTargetContent()` for the exact rule.
26
+ *
75
27
  * @param client - learn client to delegate ingestion to
76
28
  * @param options - parsed CLI options whose `args` list targets to
77
29
  * ingest
78
30
  * @param io - injectable I/O (defaults to reading process.stdin)
79
- * @returns one `LearnResult` per file successfully ingested
31
+ * @returns one `LearnResult` per section successfully ingested
80
32
  */
81
33
  export declare function runLearn(client: LearnClient, options: CliOptions, io?: LearnIO): Promise<LearnResult[]>;
82
- export {};
@@ -29,15 +29,19 @@ export interface SkillListClient {
29
29
  listByType(sectionType: string): Promise<SkillRecord[]>;
30
30
  }
31
31
  /**
32
- * Lists all skill definitions stored in the knowledge base.
32
+ * Lists skill definitions stored in the knowledge base.
33
33
  *
34
- * Calls `client.listByType('skill')` and maps each record to a
35
- * summary that includes the argument count parsed from the JSON
36
- * content. Parse errors default the argument count to `0`.
34
+ * Calls `client.listByType('skill')` and returns a JSON envelope
35
+ * of matching skill names. When `options.args` is non-empty, the
36
+ * positional arguments are joined with a space and used as a
37
+ * case-insensitive substring filter against each skill's name
38
+ * and description. An empty query returns every skill.
37
39
  *
38
40
  * @param client - client used to list skill sections
39
- * @param _options - parsed CLI options (unused; reserved for future flags)
40
- * @returns a `CommandResult` containing a JSON array of skill summaries
41
+ * @param options - parsed CLI options; positional `args` build
42
+ * the filter query
43
+ * @returns a `CommandResult` with a JSON envelope
44
+ * (`{ items, total, offset }`) of matching skill names
41
45
  */
42
- export declare function runSkillList(client: SkillListClient, _options: CliOptions): Promise<CommandResult>;
46
+ export declare function runSkillList(client: SkillListClient, options: CliOptions): Promise<CommandResult>;
43
47
  export {};
@@ -0,0 +1,12 @@
1
+ import type { MarkdownSection } from '../typings/markdown-section.interface.ts';
2
+ /**
3
+ * Splits markdown content into sections on ATX heading
4
+ * boundaries (`# Title` through `###### Title`). Headings inside
5
+ * fenced code blocks are treated as plain text. A document with
6
+ * no headings is returned as one titleless section.
7
+ *
8
+ * @param content - raw markdown document text
9
+ * @returns sections in document order, with trailing whitespace
10
+ * trimmed from each section's body
11
+ */
12
+ export declare function splitMarkdownSections(content: string): MarkdownSection[];
@@ -1,3 +1,4 @@
1
+ import type { AddSectionResult } from '../../worker-client/typings/add-section-result.model.ts';
1
2
  /**
2
3
  * Minimal client interface required by `runLearn`.
3
4
  *
@@ -9,8 +10,8 @@ export interface LearnClient {
9
10
  * Ingests a content section into the knowledge base.
10
11
  *
11
12
  * @param params - section metadata and raw text content
12
- * @returns enriched result containing the new kbid plus
13
- * optional supersession, warnings, and near-duplicate info
13
+ * @returns result containing the new kbid plus optional
14
+ * supersession, warnings, and near-duplicate info
14
15
  */
15
16
  addSection(params: {
16
17
  sectionType: string;
@@ -25,32 +26,17 @@ export interface LearnClient {
25
26
  * via source key when `replace` is `true`.
26
27
  */
27
28
  sourcePath?: string;
28
- }): Promise<LearnAddSectionResult>;
29
- }
30
- /** Enriched add-section result returned by the daemon. */
31
- export interface LearnAddSectionResult {
32
- /** List of knowledge-base identifiers assigned. */
33
- readonly items: string[];
34
- /** Number of items in the result set. */
35
- readonly total: number;
36
- /** Offset into the result set (always 0 for learn). */
37
- readonly offset: number;
38
- /**
39
- * Kbid of the section superseded via `--replace`,
40
- * or `null` / `undefined` when none.
41
- */
42
- readonly superseded?: string | null;
29
+ /** Hierarchical level (1-6) assigned to the section. */
30
+ level?: number;
31
+ }): Promise<AddSectionResult>;
43
32
  /**
44
- * Advisory warning strings (e.g. `"heading_missing"`).
45
- * May be absent from older daemon versions.
46
- */
47
- readonly warnings?: string[];
48
- /**
49
- * Near-duplicate sections with similarity >= 0.85.
50
- * May be absent from older daemon versions.
33
+ * Groups a set of sections under a named document, creating the
34
+ * shared `DocumentManifest` for a markdown file split on
35
+ * headings.
36
+ *
37
+ * @param title - human-readable document title
38
+ * @param kbids - identifiers of the sections to group
39
+ * @returns the assigned document identifier
51
40
  */
52
- readonly near_duplicates?: {
53
- readonly kbid: string;
54
- readonly similarity: number;
55
- }[];
41
+ groupSections(title: string, kbids: string[]): Promise<string>;
56
42
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * A single section of a markdown document produced by splitting
3
+ * on ATX heading boundaries (`# Title` through `###### Title`).
4
+ */
5
+ export interface MarkdownSection {
6
+ /**
7
+ * Heading text for this section, trimmed of surrounding
8
+ * whitespace. Omitted for content that precedes the first
9
+ * heading in the document.
10
+ */
11
+ title?: string;
12
+ /**
13
+ * ATX heading depth (1-6), derived from the number of `#`
14
+ * characters. Omitted when `title` is omitted.
15
+ */
16
+ level?: number;
17
+ /**
18
+ * Body text belonging to this section -- everything between
19
+ * this section's heading (exclusive) and the next heading
20
+ * (exclusive), with trailing whitespace trimmed.
21
+ */
22
+ content: string;
23
+ }
@@ -1,27 +1,17 @@
1
1
  import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
- /** Shape of a content item in an MCP tool call response. */
3
- interface ToolContent {
4
- /** Content type identifier, typically `'text'`. */
5
- readonly type: string;
6
- /** The text payload. */
7
- readonly text: string;
8
- }
9
- /** Result returned by the agent-list tool handler. */
10
- interface ToolCallResult {
11
- /** One or more content items describing the result. */
12
- readonly content: ToolContent[];
13
- /** Set to `true` when the tool encountered an error. */
14
- readonly isError?: boolean;
15
- }
2
+ import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
16
3
  /**
17
- * Handles the `agent:list` MCP tool call.
4
+ * Handles the `agent-list` MCP tool call.
18
5
  *
19
- * Retrieves all documents with `doc_type: 'agent'` and returns a
20
- * numbered, human-readable list of each agent's name and
21
- * description.
6
+ * Retrieves all documents with `doc_type: 'agent'`. When
7
+ * `args.query` is a non-empty string, results are filtered by a
8
+ * case-insensitive substring match against each agent's name or
9
+ * description before being returned.
22
10
  *
23
11
  * @param client - the worker client used to execute operations
24
- * @returns content items with the formatted agent list
12
+ * @param args - tool arguments; a string `query` filters results
13
+ * by name or description
14
+ * @returns content items with a JSON envelope
15
+ * (`{ items, total, offset }`) of matching agent names
25
16
  */
26
- export declare function handleAgentList(client: McpWorkerClient): Promise<ToolCallResult>;
27
- export {};
17
+ export declare function handleAgentList(client: McpWorkerClient, args?: Record<string, unknown>): Promise<ToolCallResult>;
@@ -1,18 +1,5 @@
1
1
  import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
2
- /** Shape of a content item in an MCP tool call response. */
3
- interface ToolContent {
4
- /** Content type identifier, typically 'text'. */
5
- readonly type: string;
6
- /** The text payload. */
7
- readonly text: string;
8
- }
9
- /** Result returned by a tool call handler. */
10
- interface ToolCallResult {
11
- /** One or more content items describing the result. */
12
- readonly content: ToolContent[];
13
- /** Set to `true` when the tool encountered an error. */
14
- readonly isError?: boolean;
15
- }
2
+ import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
16
3
  /**
17
4
  * Dispatches an MCP tool call to the appropriate knowledge-base
18
5
  * operation and returns the result formatted as MCP content.
@@ -23,4 +10,3 @@ interface ToolCallResult {
23
10
  * @returns content items with optional isError flag
24
11
  */
25
12
  export declare function handleToolCall(client: McpWorkerClient, name: string, args: Record<string, unknown>): Promise<ToolCallResult>;
26
- export {};
@@ -3,9 +3,19 @@ import type { ToolCallResult } from '../typings/tool-call-result.model.ts';
3
3
  /**
4
4
  * Handles the `skill-list` MCP tool call.
5
5
  *
6
- * Lists all skills stored in the knowledge base, including the
7
- * argument count extracted from each skill's JSON content.
6
+ * Lists skills stored in the knowledge base as a JSON envelope
7
+ * of matching skill names. When `args.query` is a non-empty
8
+ * string, results are filtered by a case-insensitive substring
9
+ * match against each skill's name or description.
10
+ *
11
+ * This handler is not currently wired into `handleToolCall`'s
12
+ * dispatch (see `handle-tool-call.function.ts`'s inline
13
+ * `handleSkillList`), but is kept behaviourally in sync with it.
8
14
  *
9
15
  * @param client - the worker client used to execute operations
16
+ * @param args - tool arguments; a string `query` filters results
17
+ * by name or description
18
+ * @returns content items with a JSON envelope
19
+ * (`{ items, total, offset }`) of matching skill names
10
20
  */
11
- export declare function handleToolSkillList(client: McpWorkerClient): Promise<ToolCallResult>;
21
+ export declare function handleToolSkillList(client: McpWorkerClient, args?: Record<string, unknown>): Promise<ToolCallResult>;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Tests whether any of the given fields contains `query` as a
3
+ * case-insensitive substring.
4
+ *
5
+ * Used to filter list results (skills, agents) against a
6
+ * free-text query built from CLI positional arguments or an MCP
7
+ * tool's `query` parameter. An empty `query` always matches,
8
+ * which lets callers filter unconditionally without a separate
9
+ * "no filter" branch. `null` and `undefined` fields never match
10
+ * a non-empty query.
11
+ *
12
+ * @param query - the substring to search for; matches
13
+ * everything when empty
14
+ * @param fields - candidate field values to search, in order
15
+ * @returns `true` when `query` is empty or found in any field
16
+ */
17
+ export declare function matchesQuery(query: string, ...fields: readonly (string | null | undefined)[]): boolean;
@@ -1,2 +1,2 @@
1
1
  /** Current package version, kept in sync with package.json. */
2
- export declare const VERSION = "0.6.1";
2
+ export declare const VERSION = "0.6.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dikolab/kbdb",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "CLI tool and MCP server for a file-based knowledge base database -- index documents, search with ranked results, and recall context for AI agents",
5
5
  "publishConfig": {
6
6
  "access": "public"