@dikolab/kbdb 0.6.3 → 0.6.5

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 (79) hide show
  1. package/dist/cli.cjs +681 -249
  2. package/dist/cli.cjs.map +4 -4
  3. package/dist/cli.mjs +638 -206
  4. package/dist/cli.mjs.map +4 -4
  5. package/dist/kbdb-worker.cjs +49 -7
  6. package/dist/kbdb-worker.cjs.map +4 -4
  7. package/dist/mod.cjs +1 -1
  8. package/dist/mod.cjs.map +1 -1
  9. package/dist/mod.mjs +1 -1
  10. package/dist/mod.mjs.map +1 -1
  11. package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
  12. package/dist/src/shared/cli/functions/learn-markdown-document.function.d.ts +22 -0
  13. package/dist/src/shared/cli/functions/learn-structured-document.function.d.ts +10 -0
  14. package/dist/src/shared/cli/functions/learn-target-content.function.d.ts +12 -0
  15. package/dist/src/shared/cli/functions/map-add-section-result.function.d.ts +12 -0
  16. package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +13 -9
  17. package/dist/src/shared/cli/functions/run-learn.function.d.ts +10 -59
  18. package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +11 -7
  19. package/dist/src/shared/cli/functions/split-markdown-sections.function.d.ts +16 -0
  20. package/dist/src/shared/cli/typings/learn-client.interface.d.ts +16 -28
  21. package/dist/src/shared/cli/typings/learn-result.model.d.ts +2 -0
  22. package/dist/src/shared/cli/typings/markdown-section.interface.d.ts +23 -0
  23. package/dist/src/shared/content-splitter/classes/heading-parent-tracker.class.d.ts +20 -0
  24. package/dist/src/shared/content-splitter/constants/content-type-maps.constant.d.ts +5 -0
  25. package/dist/src/shared/content-splitter/constants/split-strategy-map.constant.d.ts +4 -0
  26. package/dist/src/shared/content-splitter/functions/detect-content-type.function.d.ts +13 -0
  27. package/dist/src/shared/content-splitter/functions/flush-markdown-draft.function.d.ts +14 -0
  28. package/dist/src/shared/content-splitter/functions/flush-toml-draft.function.d.ts +15 -0
  29. package/dist/src/shared/content-splitter/functions/push-content-section.function.d.ts +16 -0
  30. package/dist/src/shared/content-splitter/functions/resolve-parent-ids.function.d.ts +14 -0
  31. package/dist/src/shared/content-splitter/functions/split-content.function.d.ts +11 -0
  32. package/dist/src/shared/content-splitter/functions/split-html.function.d.ts +12 -0
  33. package/dist/src/shared/content-splitter/functions/split-markdown.function.d.ts +13 -0
  34. package/dist/src/shared/content-splitter/functions/split-plain-text.function.d.ts +8 -0
  35. package/dist/src/shared/content-splitter/functions/split-toml.function.d.ts +12 -0
  36. package/dist/src/shared/content-splitter/index.d.ts +11 -0
  37. package/dist/src/shared/content-splitter/typings/content-format.type.d.ts +2 -0
  38. package/dist/src/shared/content-splitter/typings/content-section.interface.d.ts +17 -0
  39. package/dist/src/shared/content-splitter/typings/markdown-draft.interface.d.ts +12 -0
  40. package/dist/src/shared/content-splitter/typings/split-result.interface.d.ts +8 -0
  41. package/dist/src/shared/content-splitter/typings/split-strategy.interface.d.ts +3 -0
  42. package/dist/src/shared/content-splitter/typings/toml-draft.interface.d.ts +15 -0
  43. package/dist/src/shared/mcp/functions/build-learn-payload.function.d.ts +24 -0
  44. package/dist/src/shared/mcp/functions/determine-learn-split.function.d.ts +18 -0
  45. package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +11 -21
  46. package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +1 -15
  47. package/dist/src/shared/mcp/functions/handle-tool-learn.function.d.ts +3 -1
  48. package/dist/src/shared/mcp/functions/handle-tool-skill-list.function.d.ts +13 -3
  49. package/dist/src/shared/mcp/functions/learn-with-splitting.function.d.ts +22 -0
  50. package/dist/src/shared/mcp/functions/parse-learn-args.function.d.ts +24 -0
  51. package/dist/src/shared/mcp/functions/store-split-learn-sections.function.d.ts +16 -0
  52. package/dist/src/shared/mcp/functions/unwrap-json-content.function.d.ts +9 -0
  53. package/dist/src/shared/mcp/typings/learn-section-params.interface.d.ts +20 -0
  54. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +4 -0
  55. package/dist/src/shared/mcp/typings/mcp-worker-client.interface.d.ts +4 -0
  56. package/dist/src/shared/query-filter/functions/matches-query.function.d.ts +17 -0
  57. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  58. package/dist/src/shared/wasm-codec/functions/decode-one-recall-result.function.d.ts +2 -1
  59. package/dist/src/shared/wasm-codec/functions/decode-recall-document.function.d.ts +2 -1
  60. package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +2 -0
  61. package/dist/src/shared/wasm-codec/functions/decode-recall-sibling.function.d.ts +2 -1
  62. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +6 -0
  63. package/dist/src/shared/wasm-codec/functions/decode-section-match.function.d.ts +2 -1
  64. package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
  65. package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +1 -0
  66. package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +2 -0
  67. package/dist/src/shared/wasm-codec/typings/section-match.model.d.ts +4 -0
  68. package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +2 -0
  69. package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +2 -0
  70. package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +12 -0
  71. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +4 -0
  72. package/dist/src/shared/worker-client/typings/section.model.d.ts +2 -0
  73. package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
  74. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  75. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  76. package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
  77. package/dist/worker.mjs +49 -7
  78. package/dist/worker.mjs.map +4 -4
  79. 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,10 @@
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
+ import type { SplitResult } from '../../content-splitter/index.ts';
5
+ /**
6
+ * Stores each section of a split result as a separate
7
+ * knowledge-base section with parent resolution, then
8
+ * groups them under one document.
9
+ */
10
+ export declare function learnStructuredDocument(client: LearnClient, options: CliOptions, path: string, splitResult: SplitResult, sourcePath?: string): Promise<LearnResult[]>;
@@ -0,0 +1,12 @@
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 as either a single section
6
+ * or, for eligible structured content (Markdown, HTML, TOML),
7
+ * a set of sections grouped under one document.
8
+ *
9
+ * Splitting is attempted when `options.title` is not set and
10
+ * the content produces 2+ sections with at least one heading.
11
+ */
12
+ 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,16 @@
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
+ * Thin backward-compatible wrapper over the shared
9
+ * `splitMarkdown` strategy in `content-splitter`, stripping its
10
+ * `parentIndex` field for callers that predate section nesting.
11
+ *
12
+ * @param content - raw markdown document text
13
+ * @returns sections in document order, with trailing whitespace
14
+ * trimmed from each section's body
15
+ */
16
+ 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,19 @@ 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
+ /** KBID of the parent section for nesting. */
32
+ parent?: string;
33
+ }): Promise<AddSectionResult>;
43
34
  /**
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.
35
+ * Groups a set of sections under a named document, creating the
36
+ * shared `DocumentManifest` for a markdown file split on
37
+ * headings.
38
+ *
39
+ * @param title - human-readable document title
40
+ * @param kbids - identifiers of the sections to group
41
+ * @returns the assigned document identifier
51
42
  */
52
- readonly near_duplicates?: {
53
- readonly kbid: string;
54
- readonly similarity: number;
55
- }[];
43
+ groupSections(title: string, kbids: string[]): Promise<string>;
56
44
  }
@@ -31,4 +31,6 @@ export interface LearnResult {
31
31
  kbid: string;
32
32
  similarity: number;
33
33
  }[];
34
+ /** Kbid of the parent section for nesting, or `undefined`. */
35
+ parent?: string;
34
36
  }
@@ -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
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Tracks nesting of headings by depth to resolve each new
3
+ * heading's parent section index. Shared by splitters whose
4
+ * sections nest by a numeric depth (markdown, HTML).
5
+ */
6
+ export declare class HeadingParentTracker {
7
+ private readonly stack;
8
+ /**
9
+ * Resolves the parent index for a heading at `level`
10
+ * appearing at output position `index`, then records the
11
+ * heading so subsequent, deeper headings can nest under it.
12
+ *
13
+ * @param level - heading depth, shallower is smaller
14
+ * @param index - position of this heading in the output
15
+ * sections array
16
+ * @returns the parent's output index, or `null` when the
17
+ * heading is at the root
18
+ */
19
+ resolve(level: number, index: number): number | null;
20
+ }
@@ -0,0 +1,5 @@
1
+ import type { ContentFormat } from '../typings/content-format.type.ts';
2
+ /** Explicit type hints (MIME or short-form) mapped to format. */
3
+ export declare const HINT_FORMAT_MAP: Record<string, ContentFormat>;
4
+ /** File extensions (without the leading dot) mapped to format. */
5
+ export declare const EXTENSION_FORMAT_MAP: Record<string, ContentFormat>;
@@ -0,0 +1,4 @@
1
+ import type { ContentFormat } from '../typings/content-format.type.ts';
2
+ import type { SplitStrategy } from '../typings/split-strategy.interface.ts';
3
+ /** Maps each recognized content format to its split strategy. */
4
+ export declare const SPLIT_STRATEGY_MAP: Record<ContentFormat, SplitStrategy>;
@@ -0,0 +1,13 @@
1
+ import type { ContentFormat } from '../typings/content-format.type.ts';
2
+ /**
3
+ * Detects the content format of a document, preferring an
4
+ * explicit type hint, then a file extension, then sniffing
5
+ * the content itself, and finally falling back to plain text.
6
+ *
7
+ * @param content - raw document text
8
+ * @param typeHint - explicit MIME type or short-form hint
9
+ * (e.g. `'text/markdown'`, `'markdown'`)
10
+ * @param filePath - source file path used to infer format
11
+ * from its extension
12
+ */
13
+ export declare function detectContentType(content: string, typeHint?: string, filePath?: string): ContentFormat;
@@ -0,0 +1,14 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ import type { HeadingParentTracker } from '../classes/heading-parent-tracker.class.ts';
3
+ import type { MarkdownDraft } from '../typings/markdown-draft.interface.ts';
4
+ /**
5
+ * Appends `draft` to `sections`, resolving its parent index
6
+ * via `tracker`. An empty, titleless draft (no accumulated
7
+ * preamble) is skipped.
8
+ *
9
+ * @param draft - accumulated section awaiting output
10
+ * @param sections - output array to append to, mutated in
11
+ * place
12
+ * @param tracker - depth stack shared across a single split
13
+ */
14
+ export declare function flushMarkdownDraft(draft: MarkdownDraft, sections: ContentSection[], tracker: HeadingParentTracker): void;
@@ -0,0 +1,15 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ import type { TomlDraft } from '../typings/toml-draft.interface.ts';
3
+ /**
4
+ * Appends `draft` to `sections`, resolving its parent index
5
+ * via `pathIndex`. An empty, titleless draft (no accumulated
6
+ * preamble) is skipped. Registers titled drafts in
7
+ * `pathIndex` so later dotted headers can nest under them.
8
+ *
9
+ * @param draft - accumulated section awaiting output
10
+ * @param sections - output array to append to, mutated in
11
+ * place
12
+ * @param pathIndex - lookup from header path to output index,
13
+ * mutated in place
14
+ */
15
+ export declare function flushTomlDraft(draft: TomlDraft, sections: ContentSection[], pathIndex: Map<string, number>): void;
@@ -0,0 +1,16 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ import type { HeadingParentTracker } from '../classes/heading-parent-tracker.class.ts';
3
+ /**
4
+ * Appends a section to `sections`, resolving its
5
+ * `parentIndex` via `tracker` when it carries a heading
6
+ * `level`. Shared by depth-nested splitters (markdown, HTML)
7
+ * so nesting logic is defined once.
8
+ *
9
+ * @param sections - output array to append to, mutated in
10
+ * place
11
+ * @param tracker - depth stack shared across a single split
12
+ * @param content - section body content
13
+ * @param title - heading text, omitted for root content
14
+ * @param level - heading depth, omitted for root content
15
+ */
16
+ export declare function pushContentSection(sections: ContentSection[], tracker: HeadingParentTracker, content: string, title?: string, level?: number): void;
@@ -0,0 +1,14 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ /**
3
+ * Resolves each section's `parentIndex` to the KBDB id of the
4
+ * section that was stored at that index. Used after sections
5
+ * have been persisted in order, to link children to parents.
6
+ *
7
+ * @param sections - split sections, in the same order as
8
+ * `kbids`
9
+ * @param kbids - persisted section ids, one per `sections`
10
+ * entry
11
+ * @returns one parent id per section, or `null` for
12
+ * root-level sections
13
+ */
14
+ export declare function resolveParentIds(sections: readonly ContentSection[], kbids: readonly string[]): (string | null)[];
@@ -0,0 +1,11 @@
1
+ import type { SplitResult } from '../typings/split-result.interface.ts';
2
+ /**
3
+ * Splits `content` into sections using the strategy matching
4
+ * its detected format. Detection prefers `typeHint`, then
5
+ * `filePath`'s extension, then sniffs the content itself.
6
+ *
7
+ * @param content - raw document text
8
+ * @param typeHint - explicit MIME type or short-form hint
9
+ * @param filePath - source file path used to infer format
10
+ */
11
+ export declare function splitContent(content: string, typeHint?: string, filePath?: string): SplitResult;
@@ -0,0 +1,12 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ /**
3
+ * Splits HTML content into sections on `<h1>` through `<h6>`
4
+ * tag boundaries, using regex matching rather than DOM
5
+ * parsing. Each heading section's `parentIndex` points to the
6
+ * nearest enclosing heading of a shallower depth.
7
+ *
8
+ * @param content - raw HTML document text
9
+ * @returns sections in document order, trailing whitespace
10
+ * trimmed from each section's body
11
+ */
12
+ export declare function splitHtml(content: string): ContentSection[];
@@ -0,0 +1,13 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ /**
3
+ * Splits markdown content into sections on ATX heading
4
+ * boundaries (`# Title` through `###### Title`). Headings
5
+ * inside fenced code blocks are treated as plain text. Each
6
+ * heading section's `parentIndex` points to the nearest
7
+ * enclosing heading of a shallower depth.
8
+ *
9
+ * @param content - raw markdown document text
10
+ * @returns sections in document order, trailing whitespace
11
+ * trimmed from each section's body
12
+ */
13
+ export declare function splitMarkdown(content: string): ContentSection[];
@@ -0,0 +1,8 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ /**
3
+ * Passthrough splitter for unrecognized content formats.
4
+ * Wraps the entire input in a single root-level section.
5
+ *
6
+ * @param content - raw document text
7
+ */
8
+ export declare function splitPlainText(content: string): ContentSection[];
@@ -0,0 +1,12 @@
1
+ import type { ContentSection } from '../typings/content-section.interface.ts';
2
+ /**
3
+ * Splits TOML content into sections on `[table]` header
4
+ * boundaries. A dotted header (`[a.b]`) nests under the
5
+ * section matching its prefix (`[a]`); an undotted or quoted
6
+ * header is a root-level section.
7
+ *
8
+ * @param content - raw TOML document text
9
+ * @returns sections in document order, trailing whitespace
10
+ * trimmed from each section's body
11
+ */
12
+ export declare function splitToml(content: string): ContentSection[];
@@ -0,0 +1,11 @@
1
+ export { splitContent } from './functions/split-content.function.ts';
2
+ export { splitMarkdown } from './functions/split-markdown.function.ts';
3
+ export { splitHtml } from './functions/split-html.function.ts';
4
+ export { splitToml } from './functions/split-toml.function.ts';
5
+ export { splitPlainText } from './functions/split-plain-text.function.ts';
6
+ export { detectContentType } from './functions/detect-content-type.function.ts';
7
+ export { resolveParentIds } from './functions/resolve-parent-ids.function.ts';
8
+ export type { ContentSection } from './typings/content-section.interface.ts';
9
+ export type { SplitResult } from './typings/split-result.interface.ts';
10
+ export type { SplitStrategy } from './typings/split-strategy.interface.ts';
11
+ export type { ContentFormat } from './typings/content-format.type.ts';
@@ -0,0 +1,2 @@
1
+ /** Content formats recognized by the content splitter. */
2
+ export type ContentFormat = 'markdown' | 'html' | 'toml' | 'plain-text';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * A section produced by a content splitter.
3
+ * Depth-first ordered within the document.
4
+ */
5
+ export interface ContentSection {
6
+ /** Section heading text, if any. */
7
+ title?: string;
8
+ /** Heading depth (1-6), if detected. */
9
+ level?: number;
10
+ /** Section body content. */
11
+ content: string;
12
+ /**
13
+ * Index of the parent section in the output
14
+ * array, or `null` for root-level sections.
15
+ */
16
+ parentIndex: number | null;
17
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * In-progress markdown section accumulated while scanning
3
+ * document lines, before it is flushed into a `ContentSection`.
4
+ */
5
+ export interface MarkdownDraft {
6
+ /** Heading text, omitted while accumulating preamble. */
7
+ title?: string;
8
+ /** Heading depth (1-6), omitted while accumulating preamble. */
9
+ level?: number;
10
+ /** Body lines collected since the last heading. */
11
+ lines: string[];
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { ContentSection } from './content-section.interface.ts';
2
+ /** Result of splitting content by format. */
3
+ export interface SplitResult {
4
+ /** Extracted sections, depth-first ordered. */
5
+ sections: ContentSection[];
6
+ /** Detected content format identifier. */
7
+ format: string;
8
+ }
@@ -0,0 +1,3 @@
1
+ import type { ContentSection } from './content-section.interface.ts';
2
+ /** Splits raw content into sections. */
3
+ export type SplitStrategy = (content: string) => ContentSection[];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * In-progress TOML section accumulated while scanning
3
+ * document lines, before it is flushed into a `ContentSection`.
4
+ */
5
+ export interface TomlDraft {
6
+ /** Header text, omitted while accumulating preamble. */
7
+ title?: string;
8
+ /**
9
+ * Header text used for dotted-parent lookup, identical to
10
+ * `title` unless the header is quoted.
11
+ */
12
+ path?: string;
13
+ /** Body lines collected since the last header. */
14
+ lines: string[];
15
+ }
@@ -0,0 +1,24 @@
1
+ import type { AddSectionResult, NearDuplicateEntry } from '../../worker-client/typings/add-section-result.model.ts';
2
+ /** JSON-serializable result envelope returned by the `learn` tool. */
3
+ export interface LearnPayload {
4
+ /** Knowledge-base identifiers of all stored sections. */
5
+ readonly items: string[];
6
+ /** Number of items in the result set. */
7
+ readonly total: number;
8
+ /** Offset into the result set (always 0 for learn). */
9
+ readonly offset: number;
10
+ /** Kbid of a superseded section, or `null` if none. */
11
+ readonly superseded: string | null;
12
+ /** Advisory warnings emitted during indexing. */
13
+ readonly warnings: string[];
14
+ /** Near-duplicate sections detected above the threshold. */
15
+ readonly near_duplicates: NearDuplicateEntry[];
16
+ }
17
+ /**
18
+ * Normalizes an `AddSectionResult` into the `learn` tool's JSON
19
+ * result envelope, defaulting optional fields to their empty
20
+ * representation.
21
+ *
22
+ * @param result - the raw result from storing one or more sections
23
+ */
24
+ export declare function buildLearnPayload(result: AddSectionResult): LearnPayload;
@@ -0,0 +1,18 @@
1
+ import type { SplitResult } from '../../content-splitter/index.ts';
2
+ /**
3
+ * Determines whether `learn` content should be imported as
4
+ * multiple linked sections instead of one, and returns the split
5
+ * result when it should.
6
+ *
7
+ * Splitting applies only when no explicit `title` is given, the
8
+ * section type is a splittable text format (`text/*` or the bare
9
+ * `'markdown'` alias), and splitting produces at least two
10
+ * sections with at least one heading title.
11
+ *
12
+ * @param content - raw content to evaluate for splitting
13
+ * @param sectionType - the section's semantic type label
14
+ * @param title - explicit title from the caller, if any
15
+ * @returns the split result when splitting should apply,
16
+ * otherwise `undefined`
17
+ */
18
+ export declare function determineLearnSplit(content: string, sectionType: string, title: string | undefined): SplitResult | undefined;