@vpxa/kb 0.1.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/LICENSE +21 -0
- package/README.md +1140 -0
- package/bin/kb.mjs +10 -0
- package/package.json +67 -0
- package/packages/analyzers/dist/blast-radius-analyzer.d.ts +23 -0
- package/packages/analyzers/dist/blast-radius-analyzer.js +114 -0
- package/packages/analyzers/dist/dependency-analyzer.d.ts +29 -0
- package/packages/analyzers/dist/dependency-analyzer.js +425 -0
- package/packages/analyzers/dist/diagram-generator.d.ts +13 -0
- package/packages/analyzers/dist/diagram-generator.js +86 -0
- package/packages/analyzers/dist/entry-point-analyzer.d.ts +19 -0
- package/packages/analyzers/dist/entry-point-analyzer.js +239 -0
- package/packages/analyzers/dist/index.d.ts +14 -0
- package/packages/analyzers/dist/index.js +23 -0
- package/packages/analyzers/dist/knowledge-producer.d.ts +32 -0
- package/packages/analyzers/dist/knowledge-producer.js +113 -0
- package/packages/analyzers/dist/pattern-analyzer.d.ts +12 -0
- package/packages/analyzers/dist/pattern-analyzer.js +359 -0
- package/packages/analyzers/dist/regex-call-graph.d.ts +17 -0
- package/packages/analyzers/dist/regex-call-graph.js +428 -0
- package/packages/analyzers/dist/structure-analyzer.d.ts +11 -0
- package/packages/analyzers/dist/structure-analyzer.js +258 -0
- package/packages/analyzers/dist/symbol-analyzer.d.ts +10 -0
- package/packages/analyzers/dist/symbol-analyzer.js +442 -0
- package/packages/analyzers/dist/ts-call-graph.d.ts +27 -0
- package/packages/analyzers/dist/ts-call-graph.js +160 -0
- package/packages/analyzers/dist/types.d.ts +98 -0
- package/packages/analyzers/dist/types.js +1 -0
- package/packages/chunker/dist/call-graph-extractor.d.ts +22 -0
- package/packages/chunker/dist/call-graph-extractor.js +90 -0
- package/packages/chunker/dist/chunker-factory.d.ts +7 -0
- package/packages/chunker/dist/chunker-factory.js +36 -0
- package/packages/chunker/dist/chunker.interface.d.ts +10 -0
- package/packages/chunker/dist/chunker.interface.js +1 -0
- package/packages/chunker/dist/code-chunker.d.ts +14 -0
- package/packages/chunker/dist/code-chunker.js +134 -0
- package/packages/chunker/dist/generic-chunker.d.ts +12 -0
- package/packages/chunker/dist/generic-chunker.js +72 -0
- package/packages/chunker/dist/index.d.ts +8 -0
- package/packages/chunker/dist/index.js +21 -0
- package/packages/chunker/dist/markdown-chunker.d.ts +14 -0
- package/packages/chunker/dist/markdown-chunker.js +122 -0
- package/packages/chunker/dist/treesitter-chunker.d.ts +47 -0
- package/packages/chunker/dist/treesitter-chunker.js +234 -0
- package/packages/cli/dist/commands/analyze.d.ts +3 -0
- package/packages/cli/dist/commands/analyze.js +112 -0
- package/packages/cli/dist/commands/context-cmds.d.ts +3 -0
- package/packages/cli/dist/commands/context-cmds.js +155 -0
- package/packages/cli/dist/commands/environment.d.ts +3 -0
- package/packages/cli/dist/commands/environment.js +204 -0
- package/packages/cli/dist/commands/execution.d.ts +3 -0
- package/packages/cli/dist/commands/execution.js +137 -0
- package/packages/cli/dist/commands/graph.d.ts +3 -0
- package/packages/cli/dist/commands/graph.js +81 -0
- package/packages/cli/dist/commands/init.d.ts +8 -0
- package/packages/cli/dist/commands/init.js +87 -0
- package/packages/cli/dist/commands/knowledge.d.ts +3 -0
- package/packages/cli/dist/commands/knowledge.js +139 -0
- package/packages/cli/dist/commands/search.d.ts +3 -0
- package/packages/cli/dist/commands/search.js +267 -0
- package/packages/cli/dist/commands/system.d.ts +3 -0
- package/packages/cli/dist/commands/system.js +241 -0
- package/packages/cli/dist/commands/workspace.d.ts +3 -0
- package/packages/cli/dist/commands/workspace.js +388 -0
- package/packages/cli/dist/context.d.ts +5 -0
- package/packages/cli/dist/context.js +14 -0
- package/packages/cli/dist/helpers.d.ts +52 -0
- package/packages/cli/dist/helpers.js +458 -0
- package/packages/cli/dist/index.d.ts +8 -0
- package/packages/cli/dist/index.js +69 -0
- package/packages/cli/dist/kb-init.d.ts +57 -0
- package/packages/cli/dist/kb-init.js +82 -0
- package/packages/cli/dist/types.d.ts +7 -0
- package/packages/cli/dist/types.js +1 -0
- package/packages/core/dist/constants.d.ts +49 -0
- package/packages/core/dist/constants.js +43 -0
- package/packages/core/dist/content-detector.d.ts +9 -0
- package/packages/core/dist/content-detector.js +79 -0
- package/packages/core/dist/errors.d.ts +18 -0
- package/packages/core/dist/errors.js +40 -0
- package/packages/core/dist/index.d.ts +6 -0
- package/packages/core/dist/index.js +9 -0
- package/packages/core/dist/logger.d.ts +9 -0
- package/packages/core/dist/logger.js +34 -0
- package/packages/core/dist/types.d.ts +108 -0
- package/packages/core/dist/types.js +1 -0
- package/packages/embeddings/dist/embedder.interface.d.ts +24 -0
- package/packages/embeddings/dist/embedder.interface.js +1 -0
- package/packages/embeddings/dist/index.d.ts +3 -0
- package/packages/embeddings/dist/index.js +5 -0
- package/packages/embeddings/dist/onnx-embedder.d.ts +24 -0
- package/packages/embeddings/dist/onnx-embedder.js +82 -0
- package/packages/indexer/dist/file-hasher.d.ts +11 -0
- package/packages/indexer/dist/file-hasher.js +13 -0
- package/packages/indexer/dist/filesystem-crawler.d.ts +27 -0
- package/packages/indexer/dist/filesystem-crawler.js +125 -0
- package/packages/indexer/dist/graph-extractor.d.ts +22 -0
- package/packages/indexer/dist/graph-extractor.js +111 -0
- package/packages/indexer/dist/incremental-indexer.d.ts +47 -0
- package/packages/indexer/dist/incremental-indexer.js +278 -0
- package/packages/indexer/dist/index.d.ts +5 -0
- package/packages/indexer/dist/index.js +14 -0
- package/packages/server/dist/api.d.ts +8 -0
- package/packages/server/dist/api.js +9 -0
- package/packages/server/dist/config.d.ts +3 -0
- package/packages/server/dist/config.js +75 -0
- package/packages/server/dist/curated-manager.d.ts +86 -0
- package/packages/server/dist/curated-manager.js +357 -0
- package/packages/server/dist/index.d.ts +2 -0
- package/packages/server/dist/index.js +134 -0
- package/packages/server/dist/replay-interceptor.d.ts +11 -0
- package/packages/server/dist/replay-interceptor.js +38 -0
- package/packages/server/dist/resources/resources.d.ts +4 -0
- package/packages/server/dist/resources/resources.js +40 -0
- package/packages/server/dist/server.d.ts +21 -0
- package/packages/server/dist/server.js +247 -0
- package/packages/server/dist/tools/analyze.tools.d.ts +11 -0
- package/packages/server/dist/tools/analyze.tools.js +288 -0
- package/packages/server/dist/tools/forge.tools.d.ts +12 -0
- package/packages/server/dist/tools/forge.tools.js +501 -0
- package/packages/server/dist/tools/forget.tool.d.ts +4 -0
- package/packages/server/dist/tools/forget.tool.js +43 -0
- package/packages/server/dist/tools/graph.tool.d.ts +4 -0
- package/packages/server/dist/tools/graph.tool.js +110 -0
- package/packages/server/dist/tools/list.tool.d.ts +4 -0
- package/packages/server/dist/tools/list.tool.js +56 -0
- package/packages/server/dist/tools/lookup.tool.d.ts +4 -0
- package/packages/server/dist/tools/lookup.tool.js +53 -0
- package/packages/server/dist/tools/onboard.tool.d.ts +5 -0
- package/packages/server/dist/tools/onboard.tool.js +112 -0
- package/packages/server/dist/tools/produce.tool.d.ts +3 -0
- package/packages/server/dist/tools/produce.tool.js +74 -0
- package/packages/server/dist/tools/read.tool.d.ts +4 -0
- package/packages/server/dist/tools/read.tool.js +49 -0
- package/packages/server/dist/tools/reindex.tool.d.ts +7 -0
- package/packages/server/dist/tools/reindex.tool.js +70 -0
- package/packages/server/dist/tools/remember.tool.d.ts +4 -0
- package/packages/server/dist/tools/remember.tool.js +45 -0
- package/packages/server/dist/tools/replay.tool.d.ts +3 -0
- package/packages/server/dist/tools/replay.tool.js +89 -0
- package/packages/server/dist/tools/search.tool.d.ts +5 -0
- package/packages/server/dist/tools/search.tool.js +331 -0
- package/packages/server/dist/tools/status.tool.d.ts +4 -0
- package/packages/server/dist/tools/status.tool.js +68 -0
- package/packages/server/dist/tools/toolkit.tools.d.ts +35 -0
- package/packages/server/dist/tools/toolkit.tools.js +1674 -0
- package/packages/server/dist/tools/update.tool.d.ts +4 -0
- package/packages/server/dist/tools/update.tool.js +42 -0
- package/packages/server/dist/tools/utility.tools.d.ts +15 -0
- package/packages/server/dist/tools/utility.tools.js +461 -0
- package/packages/store/dist/graph-store.interface.d.ts +104 -0
- package/packages/store/dist/graph-store.interface.js +1 -0
- package/packages/store/dist/index.d.ts +6 -0
- package/packages/store/dist/index.js +9 -0
- package/packages/store/dist/lance-store.d.ts +32 -0
- package/packages/store/dist/lance-store.js +258 -0
- package/packages/store/dist/sqlite-graph-store.d.ts +43 -0
- package/packages/store/dist/sqlite-graph-store.js +374 -0
- package/packages/store/dist/store-factory.d.ts +9 -0
- package/packages/store/dist/store-factory.js +14 -0
- package/packages/store/dist/store.interface.d.ts +48 -0
- package/packages/store/dist/store.interface.js +1 -0
- package/packages/tools/dist/batch.d.ts +21 -0
- package/packages/tools/dist/batch.js +45 -0
- package/packages/tools/dist/changelog.d.ts +34 -0
- package/packages/tools/dist/changelog.js +112 -0
- package/packages/tools/dist/check.d.ts +26 -0
- package/packages/tools/dist/check.js +59 -0
- package/packages/tools/dist/checkpoint.d.ts +17 -0
- package/packages/tools/dist/checkpoint.js +43 -0
- package/packages/tools/dist/codemod.d.ts +37 -0
- package/packages/tools/dist/codemod.js +69 -0
- package/packages/tools/dist/compact.d.ts +41 -0
- package/packages/tools/dist/compact.js +60 -0
- package/packages/tools/dist/data-transform.d.ts +10 -0
- package/packages/tools/dist/data-transform.js +124 -0
- package/packages/tools/dist/dead-symbols.d.ts +21 -0
- package/packages/tools/dist/dead-symbols.js +71 -0
- package/packages/tools/dist/delegate.d.ts +34 -0
- package/packages/tools/dist/delegate.js +130 -0
- package/packages/tools/dist/diff-parse.d.ts +26 -0
- package/packages/tools/dist/diff-parse.js +153 -0
- package/packages/tools/dist/digest.d.ts +53 -0
- package/packages/tools/dist/digest.js +242 -0
- package/packages/tools/dist/encode.d.ts +14 -0
- package/packages/tools/dist/encode.js +46 -0
- package/packages/tools/dist/env-info.d.ts +28 -0
- package/packages/tools/dist/env-info.js +58 -0
- package/packages/tools/dist/eval.d.ts +13 -0
- package/packages/tools/dist/eval.js +79 -0
- package/packages/tools/dist/evidence-map.d.ts +79 -0
- package/packages/tools/dist/evidence-map.js +203 -0
- package/packages/tools/dist/file-summary.d.ts +32 -0
- package/packages/tools/dist/file-summary.js +106 -0
- package/packages/tools/dist/file-walk.d.ts +4 -0
- package/packages/tools/dist/file-walk.js +75 -0
- package/packages/tools/dist/find-examples.d.ts +25 -0
- package/packages/tools/dist/find-examples.js +48 -0
- package/packages/tools/dist/find.d.ts +47 -0
- package/packages/tools/dist/find.js +120 -0
- package/packages/tools/dist/forge-classify.d.ts +44 -0
- package/packages/tools/dist/forge-classify.js +319 -0
- package/packages/tools/dist/forge-ground.d.ts +64 -0
- package/packages/tools/dist/forge-ground.js +184 -0
- package/packages/tools/dist/git-context.d.ts +22 -0
- package/packages/tools/dist/git-context.js +46 -0
- package/packages/tools/dist/graph-query.d.ts +89 -0
- package/packages/tools/dist/graph-query.js +194 -0
- package/packages/tools/dist/health.d.ts +14 -0
- package/packages/tools/dist/health.js +118 -0
- package/packages/tools/dist/http-request.d.ts +23 -0
- package/packages/tools/dist/http-request.js +58 -0
- package/packages/tools/dist/index.d.ts +49 -0
- package/packages/tools/dist/index.js +273 -0
- package/packages/tools/dist/lane.d.ts +39 -0
- package/packages/tools/dist/lane.js +227 -0
- package/packages/tools/dist/measure.d.ts +38 -0
- package/packages/tools/dist/measure.js +119 -0
- package/packages/tools/dist/onboard.d.ts +41 -0
- package/packages/tools/dist/onboard.js +1139 -0
- package/packages/tools/dist/parse-output.d.ts +80 -0
- package/packages/tools/dist/parse-output.js +158 -0
- package/packages/tools/dist/process-manager.d.ts +18 -0
- package/packages/tools/dist/process-manager.js +69 -0
- package/packages/tools/dist/queue.d.ts +38 -0
- package/packages/tools/dist/queue.js +126 -0
- package/packages/tools/dist/regex-test.d.ts +31 -0
- package/packages/tools/dist/regex-test.js +39 -0
- package/packages/tools/dist/rename.d.ts +29 -0
- package/packages/tools/dist/rename.js +70 -0
- package/packages/tools/dist/replay.d.ts +56 -0
- package/packages/tools/dist/replay.js +108 -0
- package/packages/tools/dist/schema-validate.d.ts +23 -0
- package/packages/tools/dist/schema-validate.js +141 -0
- package/packages/tools/dist/scope-map.d.ts +52 -0
- package/packages/tools/dist/scope-map.js +72 -0
- package/packages/tools/dist/snippet.d.ts +34 -0
- package/packages/tools/dist/snippet.js +80 -0
- package/packages/tools/dist/stash.d.ts +12 -0
- package/packages/tools/dist/stash.js +60 -0
- package/packages/tools/dist/stratum-card.d.ts +31 -0
- package/packages/tools/dist/stratum-card.js +239 -0
- package/packages/tools/dist/symbol.d.ts +28 -0
- package/packages/tools/dist/symbol.js +87 -0
- package/packages/tools/dist/test-run.d.ts +23 -0
- package/packages/tools/dist/test-run.js +55 -0
- package/packages/tools/dist/text-utils.d.ts +16 -0
- package/packages/tools/dist/text-utils.js +31 -0
- package/packages/tools/dist/time-utils.d.ts +18 -0
- package/packages/tools/dist/time-utils.js +135 -0
- package/packages/tools/dist/trace.d.ts +24 -0
- package/packages/tools/dist/trace.js +114 -0
- package/packages/tools/dist/truncation.d.ts +22 -0
- package/packages/tools/dist/truncation.js +45 -0
- package/packages/tools/dist/watch.d.ts +30 -0
- package/packages/tools/dist/watch.js +61 -0
- package/packages/tools/dist/web-fetch.d.ts +45 -0
- package/packages/tools/dist/web-fetch.js +249 -0
- package/packages/tools/dist/web-search.d.ts +23 -0
- package/packages/tools/dist/web-search.js +46 -0
- package/packages/tools/dist/workset.d.ts +45 -0
- package/packages/tools/dist/workset.js +77 -0
- package/packages/tui/dist/App.d.ts +8 -0
- package/packages/tui/dist/App.js +52659 -0
- package/packages/tui/dist/index.d.ts +19 -0
- package/packages/tui/dist/index.js +54742 -0
- package/packages/tui/dist/panels/CuratedPanel.d.ts +8 -0
- package/packages/tui/dist/panels/CuratedPanel.js +34452 -0
- package/packages/tui/dist/panels/LogPanel.d.ts +3 -0
- package/packages/tui/dist/panels/LogPanel.js +51894 -0
- package/packages/tui/dist/panels/SearchPanel.d.ts +10 -0
- package/packages/tui/dist/panels/SearchPanel.js +34985 -0
- package/packages/tui/dist/panels/StatusPanel.d.ts +8 -0
- package/packages/tui/dist/panels/StatusPanel.js +34465 -0
- package/skills/knowledge-base/SKILL.md +316 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Knowledge store abstraction — allows swapping vector DB backends.
|
|
3
|
+
*/
|
|
4
|
+
import type { IndexStats, KnowledgeRecord, SearchResult } from '@kb/core';
|
|
5
|
+
/** Options for searching the store */
|
|
6
|
+
export interface SearchOptions {
|
|
7
|
+
/** Maximum number of results to return */
|
|
8
|
+
limit?: number;
|
|
9
|
+
/** Minimum similarity score (0-1) */
|
|
10
|
+
minScore?: number;
|
|
11
|
+
/** Filter by content type */
|
|
12
|
+
contentType?: string;
|
|
13
|
+
/** Filter by origin */
|
|
14
|
+
origin?: string;
|
|
15
|
+
/** Filter by category */
|
|
16
|
+
category?: string;
|
|
17
|
+
/** Filter by tags (any match) */
|
|
18
|
+
tags?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface IKnowledgeStore {
|
|
21
|
+
/** Initialize the store (create tables, etc.) */
|
|
22
|
+
initialize(): Promise<void>;
|
|
23
|
+
/** Add or update records with their embedding vectors */
|
|
24
|
+
upsert(records: KnowledgeRecord[], vectors: Float32Array[]): Promise<void>;
|
|
25
|
+
/** Search by vector similarity */
|
|
26
|
+
search(queryVector: Float32Array, options?: SearchOptions): Promise<SearchResult[]>;
|
|
27
|
+
/** Get a specific record by ID */
|
|
28
|
+
getById(id: string): Promise<KnowledgeRecord | null>;
|
|
29
|
+
/** Delete records by source path (used during re-indexing) */
|
|
30
|
+
deleteBySourcePath(sourcePath: string): Promise<number>;
|
|
31
|
+
/** Delete a specific record by ID */
|
|
32
|
+
deleteById(id: string): Promise<boolean>;
|
|
33
|
+
/** Get all records for a source path */
|
|
34
|
+
getBySourcePath(sourcePath: string): Promise<KnowledgeRecord[]>;
|
|
35
|
+
/** Get index statistics */
|
|
36
|
+
getStats(): Promise<IndexStats>;
|
|
37
|
+
/** List all unique source paths in the store */
|
|
38
|
+
listSourcePaths(): Promise<string[]>;
|
|
39
|
+
/** Create a full-text search index on the content column for keyword search */
|
|
40
|
+
createFtsIndex(): Promise<void>;
|
|
41
|
+
/** Full-text keyword search (requires FTS index) */
|
|
42
|
+
ftsSearch(query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
43
|
+
/** Drop the backing table entirely — used for hard resets (e.g. dimension changes) */
|
|
44
|
+
dropTable(): Promise<void>;
|
|
45
|
+
/** Close the store connection */
|
|
46
|
+
close(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=store.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=store.interface.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface BatchOperation {
|
|
2
|
+
/** Unique ID for this operation */
|
|
3
|
+
id: string;
|
|
4
|
+
/** Operation type */
|
|
5
|
+
type: string;
|
|
6
|
+
/** Arguments for the operation */
|
|
7
|
+
args: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface BatchResult {
|
|
10
|
+
id: string;
|
|
11
|
+
status: 'success' | 'error';
|
|
12
|
+
result?: unknown;
|
|
13
|
+
error?: string;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
}
|
|
16
|
+
export interface BatchOptions {
|
|
17
|
+
/** Max concurrent operations (default: 4) */
|
|
18
|
+
concurrency?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function batch(operations: BatchOperation[], executor: (op: BatchOperation) => Promise<unknown>, options?: BatchOptions): Promise<BatchResult[]>;
|
|
21
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
async function batch(operations, executor, options = {}) {
|
|
2
|
+
const concurrency = Math.max(1, options.concurrency ?? 4);
|
|
3
|
+
const results = [];
|
|
4
|
+
const pending = [...operations];
|
|
5
|
+
async function runOne(op) {
|
|
6
|
+
const start = Date.now();
|
|
7
|
+
try {
|
|
8
|
+
const result = await executor(op);
|
|
9
|
+
return {
|
|
10
|
+
id: op.id,
|
|
11
|
+
status: "success",
|
|
12
|
+
result,
|
|
13
|
+
durationMs: Date.now() - start
|
|
14
|
+
};
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return {
|
|
17
|
+
id: op.id,
|
|
18
|
+
status: "error",
|
|
19
|
+
error: error instanceof Error ? error.message : String(error),
|
|
20
|
+
durationMs: Date.now() - start
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
while (pending.length > 0) {
|
|
25
|
+
const chunk = pending.splice(0, concurrency);
|
|
26
|
+
const chunkResults = await Promise.allSettled(chunk.map((operation) => runOne(operation)));
|
|
27
|
+
for (const result of chunkResults) {
|
|
28
|
+
if (result.status === "fulfilled") {
|
|
29
|
+
results.push(result.value);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
results.push({
|
|
33
|
+
id: "unknown",
|
|
34
|
+
status: "error",
|
|
35
|
+
error: result.reason instanceof Error ? result.reason.message : "Promise rejected",
|
|
36
|
+
durationMs: 0
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return results;
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
batch
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kb_changelog — Generate a changelog from git history.
|
|
3
|
+
*/
|
|
4
|
+
export type ChangelogFormat = 'grouped' | 'chronological' | 'per-scope';
|
|
5
|
+
export interface ChangelogOptions {
|
|
6
|
+
from: string;
|
|
7
|
+
to?: string;
|
|
8
|
+
format?: ChangelogFormat;
|
|
9
|
+
includeBreaking?: boolean;
|
|
10
|
+
cwd?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ChangelogEntry {
|
|
13
|
+
hash: string;
|
|
14
|
+
type: string;
|
|
15
|
+
scope: string;
|
|
16
|
+
subject: string;
|
|
17
|
+
body: string;
|
|
18
|
+
author: string;
|
|
19
|
+
date: string;
|
|
20
|
+
breaking: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface ChangelogResult {
|
|
23
|
+
entries: ChangelogEntry[];
|
|
24
|
+
markdown: string;
|
|
25
|
+
stats: {
|
|
26
|
+
total: number;
|
|
27
|
+
breaking: number;
|
|
28
|
+
types: Record<string, number>;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export declare function changelog(options: ChangelogOptions): ChangelogResult;
|
|
32
|
+
/** Exported for testing */
|
|
33
|
+
export declare function formatChangelog(entries: ChangelogEntry[], format: ChangelogFormat, includeBreaking: boolean): string;
|
|
34
|
+
//# sourceMappingURL=changelog.d.ts.map
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
const SAFE_REF = /^[a-zA-Z0-9_./\-~^@{}]+$/;
|
|
3
|
+
function changelog(options) {
|
|
4
|
+
const {
|
|
5
|
+
from,
|
|
6
|
+
to = "HEAD",
|
|
7
|
+
format = "grouped",
|
|
8
|
+
includeBreaking = true,
|
|
9
|
+
cwd = process.cwd()
|
|
10
|
+
} = options;
|
|
11
|
+
if (!SAFE_REF.test(from)) throw new Error(`Invalid git ref: ${from}`);
|
|
12
|
+
if (!SAFE_REF.test(to)) throw new Error(`Invalid git ref: ${to}`);
|
|
13
|
+
const FIELD = "";
|
|
14
|
+
const ENTRY = "";
|
|
15
|
+
const gitFormat = `%H${FIELD}%s${FIELD}%b${FIELD}%an${FIELD}%ai${ENTRY}`;
|
|
16
|
+
let output;
|
|
17
|
+
try {
|
|
18
|
+
output = execSync(`git log "${from}..${to}" --format="${gitFormat}"`, {
|
|
19
|
+
cwd,
|
|
20
|
+
encoding: "utf8",
|
|
21
|
+
maxBuffer: 10 * 1024 * 1024
|
|
22
|
+
});
|
|
23
|
+
} catch {
|
|
24
|
+
throw new Error(`Git log failed. Ensure "${from}" and "${to}" are valid refs.`);
|
|
25
|
+
}
|
|
26
|
+
const entries = output.split(ENTRY).map((b) => b.trim()).filter(Boolean).map((block) => {
|
|
27
|
+
const [hash = "", subject = "", body = "", author = "", date = ""] = block.split(FIELD);
|
|
28
|
+
const m = subject.match(/^(\w+)(?:\(([^)]*)\))?(!)?:\s*(.+)/);
|
|
29
|
+
return {
|
|
30
|
+
hash: hash.slice(0, 8),
|
|
31
|
+
type: m?.[1] ?? "other",
|
|
32
|
+
scope: m?.[2] ?? "",
|
|
33
|
+
subject: m?.[4] ?? subject,
|
|
34
|
+
body: body.trim(),
|
|
35
|
+
author: author.trim(),
|
|
36
|
+
date: date.trim().split(" ")[0],
|
|
37
|
+
breaking: !!(m?.[3] || /BREAKING[\s-]CHANGE/i.test(body))
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
const types = {};
|
|
41
|
+
let breakingCount = 0;
|
|
42
|
+
for (const e of entries) {
|
|
43
|
+
types[e.type] = (types[e.type] ?? 0) + 1;
|
|
44
|
+
if (e.breaking) breakingCount++;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
entries,
|
|
48
|
+
markdown: formatChangelog(entries, format, includeBreaking),
|
|
49
|
+
stats: { total: entries.length, breaking: breakingCount, types }
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function formatChangelog(entries, format, includeBreaking) {
|
|
53
|
+
const lines = ["# Changelog", ""];
|
|
54
|
+
if (includeBreaking) {
|
|
55
|
+
const breaking = entries.filter((e) => e.breaking);
|
|
56
|
+
if (breaking.length > 0) {
|
|
57
|
+
lines.push("## Breaking Changes", "");
|
|
58
|
+
for (const e of breaking) lines.push(`- ${e.subject} (${e.hash})`);
|
|
59
|
+
lines.push("");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (format === "grouped") {
|
|
63
|
+
const groups = {};
|
|
64
|
+
for (const e of entries) {
|
|
65
|
+
if (!groups[e.type]) groups[e.type] = [];
|
|
66
|
+
groups[e.type].push(e);
|
|
67
|
+
}
|
|
68
|
+
const order = ["feat", "fix", "refactor", "perf", "test", "docs", "chore"];
|
|
69
|
+
const labels = {
|
|
70
|
+
feat: "Features",
|
|
71
|
+
fix: "Bug Fixes",
|
|
72
|
+
refactor: "Refactoring",
|
|
73
|
+
perf: "Performance",
|
|
74
|
+
test: "Tests",
|
|
75
|
+
docs: "Documentation",
|
|
76
|
+
chore: "Chores",
|
|
77
|
+
other: "Other"
|
|
78
|
+
};
|
|
79
|
+
for (const type of [...order, ...Object.keys(groups).filter((k) => !order.includes(k))]) {
|
|
80
|
+
if (!groups[type]?.length) continue;
|
|
81
|
+
lines.push(`## ${labels[type] ?? type}`, "");
|
|
82
|
+
for (const e of groups[type]) {
|
|
83
|
+
const scope = e.scope ? `**${e.scope}:** ` : "";
|
|
84
|
+
lines.push(`- ${scope}${e.subject} (${e.hash})`);
|
|
85
|
+
}
|
|
86
|
+
lines.push("");
|
|
87
|
+
}
|
|
88
|
+
} else if (format === "chronological") {
|
|
89
|
+
for (const e of entries) {
|
|
90
|
+
const scope = e.scope ? `(${e.scope}) ` : "";
|
|
91
|
+
lines.push(`- \`${e.date}\` ${e.type}: ${scope}${e.subject} (${e.hash})`);
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
const byScope = {};
|
|
95
|
+
for (const e of entries) {
|
|
96
|
+
const key = e.scope || "general";
|
|
97
|
+
if (!byScope[key]) byScope[key] = [];
|
|
98
|
+
byScope[key].push(e);
|
|
99
|
+
}
|
|
100
|
+
for (const [scope, scopeEntries] of Object.entries(byScope)) {
|
|
101
|
+
lines.push(`## ${scope}`, "");
|
|
102
|
+
for (const e of scopeEntries) lines.push(`- ${e.type}: ${e.subject} (${e.hash})`);
|
|
103
|
+
lines.push("");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return lines.join("\n");
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
changelog,
|
|
110
|
+
formatChangelog
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=changelog.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ParsedError } from './parse-output.js';
|
|
2
|
+
export interface CheckOptions {
|
|
3
|
+
/** Specific files to check (if empty, checks all) */
|
|
4
|
+
files?: string[];
|
|
5
|
+
/** Working directory */
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/** Skip typecheck */
|
|
8
|
+
skipTypes?: boolean;
|
|
9
|
+
/** Skip lint */
|
|
10
|
+
skipLint?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface CheckResult {
|
|
13
|
+
tsc: {
|
|
14
|
+
errors: ParsedError[];
|
|
15
|
+
passed: boolean;
|
|
16
|
+
raw?: string;
|
|
17
|
+
};
|
|
18
|
+
biome: {
|
|
19
|
+
errors: ParsedError[];
|
|
20
|
+
passed: boolean;
|
|
21
|
+
raw?: string;
|
|
22
|
+
};
|
|
23
|
+
passed: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function check(options?: CheckOptions): Promise<CheckResult>;
|
|
26
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { readFile as readFileAsync } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { parseBiome, parseTsc } from "./parse-output.js";
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
function getProcessOutput(error) {
|
|
8
|
+
const candidate = error;
|
|
9
|
+
const stdout = candidate.stdout?.toString() ?? "";
|
|
10
|
+
const stderr = candidate.stderr?.toString() ?? "";
|
|
11
|
+
return [stdout, stderr].filter(Boolean).join("\n").trim() || candidate.message || "Command failed";
|
|
12
|
+
}
|
|
13
|
+
async function check(options = {}) {
|
|
14
|
+
const cwd = options.cwd ?? process.cwd();
|
|
15
|
+
const tscResult = { errors: [], passed: true, raw: "" };
|
|
16
|
+
const biomeResult = { errors: [], passed: true, raw: "" };
|
|
17
|
+
if (!options.skipTypes) {
|
|
18
|
+
try {
|
|
19
|
+
const pkgPath = join(cwd, "package.json");
|
|
20
|
+
let useProjectScript = false;
|
|
21
|
+
try {
|
|
22
|
+
const pkg = JSON.parse(await readFileAsync(pkgPath, "utf-8"));
|
|
23
|
+
useProjectScript = !!pkg.scripts?.typecheck;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
if (useProjectScript && !options.files?.length) {
|
|
27
|
+
await execFileAsync("npx", ["turbo", "run", "typecheck"], { cwd, shell: true });
|
|
28
|
+
} else {
|
|
29
|
+
const args = ["--noEmit"];
|
|
30
|
+
if (options.files?.length) args.push(...options.files);
|
|
31
|
+
await execFileAsync("npx", ["tsc", ...args], { cwd, shell: true });
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
tscResult.raw = getProcessOutput(error);
|
|
35
|
+
tscResult.errors = parseTsc(tscResult.raw);
|
|
36
|
+
tscResult.passed = tscResult.errors.length === 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!options.skipLint) {
|
|
40
|
+
try {
|
|
41
|
+
const args = ["check"];
|
|
42
|
+
if (options.files?.length) args.push(...options.files);
|
|
43
|
+
await execFileAsync("npx", ["biome", ...args], { cwd, shell: true });
|
|
44
|
+
} catch (error) {
|
|
45
|
+
biomeResult.raw = getProcessOutput(error);
|
|
46
|
+
biomeResult.errors = parseBiome(biomeResult.raw);
|
|
47
|
+
biomeResult.passed = biomeResult.errors.length === 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
tsc: tscResult,
|
|
52
|
+
biome: biomeResult,
|
|
53
|
+
passed: tscResult.passed && biomeResult.passed
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
check
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Checkpoint {
|
|
2
|
+
id: string;
|
|
3
|
+
label: string;
|
|
4
|
+
createdAt: string;
|
|
5
|
+
data: Record<string, unknown>;
|
|
6
|
+
files?: string[];
|
|
7
|
+
notes?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function checkpointSave(label: string, data: Record<string, unknown>, options?: {
|
|
10
|
+
files?: string[];
|
|
11
|
+
notes?: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
}): Checkpoint;
|
|
14
|
+
export declare function checkpointLoad(id: string, cwd?: string): Checkpoint | undefined;
|
|
15
|
+
export declare function checkpointList(cwd?: string): Checkpoint[];
|
|
16
|
+
export declare function checkpointLatest(cwd?: string): Checkpoint | undefined;
|
|
17
|
+
//# sourceMappingURL=checkpoint.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
const CHECKPOINT_DIR = ".kb-state/checkpoints";
|
|
4
|
+
function checkpointDir(cwd) {
|
|
5
|
+
const root = cwd ?? process.cwd();
|
|
6
|
+
const dir = resolve(root, CHECKPOINT_DIR);
|
|
7
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
8
|
+
return dir;
|
|
9
|
+
}
|
|
10
|
+
function checkpointSave(label, data, options) {
|
|
11
|
+
const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "checkpoint";
|
|
12
|
+
const checkpoint = {
|
|
13
|
+
id: `${Date.now()}-${slug}`,
|
|
14
|
+
label,
|
|
15
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
16
|
+
data,
|
|
17
|
+
files: options?.files,
|
|
18
|
+
notes: options?.notes
|
|
19
|
+
};
|
|
20
|
+
const filePath = resolve(checkpointDir(options?.cwd), `${checkpoint.id}.json`);
|
|
21
|
+
writeFileSync(filePath, `${JSON.stringify(checkpoint, null, 2)}
|
|
22
|
+
`, "utf-8");
|
|
23
|
+
return checkpoint;
|
|
24
|
+
}
|
|
25
|
+
function checkpointLoad(id, cwd) {
|
|
26
|
+
const filePath = resolve(checkpointDir(cwd), `${id}.json`);
|
|
27
|
+
if (!existsSync(filePath)) return void 0;
|
|
28
|
+
return JSON.parse(readFileSync(filePath, "utf-8"));
|
|
29
|
+
}
|
|
30
|
+
function checkpointList(cwd) {
|
|
31
|
+
const dir = checkpointDir(cwd);
|
|
32
|
+
return readdirSync(dir).filter((file) => file.endsWith(".json")).map((file) => JSON.parse(readFileSync(resolve(dir, file), "utf-8"))).sort((left, right) => right.createdAt.localeCompare(left.createdAt));
|
|
33
|
+
}
|
|
34
|
+
function checkpointLatest(cwd) {
|
|
35
|
+
return checkpointList(cwd)[0];
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
checkpointLatest,
|
|
39
|
+
checkpointList,
|
|
40
|
+
checkpointLoad,
|
|
41
|
+
checkpointSave
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=checkpoint.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface CodemodRule {
|
|
2
|
+
/** Description of what this rule does */
|
|
3
|
+
description: string;
|
|
4
|
+
/** Regex pattern to match (string form, will be compiled) */
|
|
5
|
+
pattern: string;
|
|
6
|
+
/** Replacement string (supports $1, $2 capture groups) */
|
|
7
|
+
replacement: string;
|
|
8
|
+
/** Optional: only apply to files matching this glob */
|
|
9
|
+
fileFilter?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface CodemodOptions {
|
|
12
|
+
/** Root directory to apply codemod in */
|
|
13
|
+
rootPath: string;
|
|
14
|
+
/** Rules to apply */
|
|
15
|
+
rules: CodemodRule[];
|
|
16
|
+
/** File extensions to process */
|
|
17
|
+
extensions?: string[];
|
|
18
|
+
/** Exclude patterns */
|
|
19
|
+
exclude?: string[];
|
|
20
|
+
/** Dry run */
|
|
21
|
+
dryRun?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface CodemodChange {
|
|
24
|
+
rule: string;
|
|
25
|
+
path: string;
|
|
26
|
+
line: number;
|
|
27
|
+
before: string;
|
|
28
|
+
after: string;
|
|
29
|
+
}
|
|
30
|
+
export interface CodemodResult {
|
|
31
|
+
changes: CodemodChange[];
|
|
32
|
+
rulesApplied: number;
|
|
33
|
+
filesModified: number;
|
|
34
|
+
dryRun: boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare function codemod(options: CodemodOptions): Promise<CodemodResult>;
|
|
37
|
+
//# sourceMappingURL=codemod.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { relative } from "node:path";
|
|
3
|
+
import { DEFAULT_TOOL_EXTENSIONS, matchesGlobPattern, walkFiles } from "./file-walk.js";
|
|
4
|
+
function normalizePath(path) {
|
|
5
|
+
return path.replace(/\\/g, "/");
|
|
6
|
+
}
|
|
7
|
+
async function codemod(options) {
|
|
8
|
+
const {
|
|
9
|
+
rootPath,
|
|
10
|
+
rules,
|
|
11
|
+
extensions = DEFAULT_TOOL_EXTENSIONS,
|
|
12
|
+
exclude = [],
|
|
13
|
+
dryRun = false
|
|
14
|
+
} = options;
|
|
15
|
+
const compiledRules = rules.map((rule) => ({
|
|
16
|
+
...rule,
|
|
17
|
+
regex: new RegExp(rule.pattern, "g")
|
|
18
|
+
}));
|
|
19
|
+
const filePaths = await walkFiles(rootPath, extensions, exclude);
|
|
20
|
+
const changes = [];
|
|
21
|
+
const appliedRules = /* @__PURE__ */ new Set();
|
|
22
|
+
let filesModified = 0;
|
|
23
|
+
for (const filePath of filePaths) {
|
|
24
|
+
const relativePath = normalizePath(relative(rootPath, filePath));
|
|
25
|
+
const originalContent = await readFile(filePath, "utf-8");
|
|
26
|
+
const lines = originalContent.split(/\r?\n/);
|
|
27
|
+
let fileChanged = false;
|
|
28
|
+
for (const [ruleIndex, rule] of compiledRules.entries()) {
|
|
29
|
+
if (rule.fileFilter && !matchesGlobPattern(relativePath, rule.fileFilter)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
for (let index = 0; index < lines.length; index++) {
|
|
33
|
+
const before = lines[index];
|
|
34
|
+
rule.regex.lastIndex = 0;
|
|
35
|
+
const after = before.replace(rule.regex, rule.replacement);
|
|
36
|
+
if (before === after) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
lines[index] = after;
|
|
40
|
+
fileChanged = true;
|
|
41
|
+
appliedRules.add(ruleIndex);
|
|
42
|
+
changes.push({
|
|
43
|
+
rule: rule.description,
|
|
44
|
+
path: relativePath,
|
|
45
|
+
line: index + 1,
|
|
46
|
+
before,
|
|
47
|
+
after
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!fileChanged) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
filesModified += 1;
|
|
55
|
+
if (!dryRun) {
|
|
56
|
+
await writeFile(filePath, lines.join("\n"), "utf-8");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
changes,
|
|
61
|
+
rulesApplied: appliedRules.size,
|
|
62
|
+
filesModified,
|
|
63
|
+
dryRun
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
codemod
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=codemod.js.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kb_compact — Extractive context compression.
|
|
3
|
+
*
|
|
4
|
+
* Takes a large text and a focus query, then extracts the most relevant
|
|
5
|
+
* sentences/paragraphs using the embedder for similarity scoring.
|
|
6
|
+
* No LLM needed — pure ONNX inference.
|
|
7
|
+
*
|
|
8
|
+
* Use case: compress a 50K-token file read down to the 2K tokens
|
|
9
|
+
* that actually matter for the current task.
|
|
10
|
+
*/
|
|
11
|
+
import type { IEmbedder } from '@kb/embeddings';
|
|
12
|
+
export interface CompactOptions {
|
|
13
|
+
/** The text to compress */
|
|
14
|
+
text: string;
|
|
15
|
+
/** The focus query — what are we trying to understand? */
|
|
16
|
+
query: string;
|
|
17
|
+
/** Target output size in characters (default: 3000) */
|
|
18
|
+
maxChars?: number;
|
|
19
|
+
/** Minimum similarity score to include a segment (0-1, default: 0.3) */
|
|
20
|
+
minScore?: number;
|
|
21
|
+
/** Segmentation strategy (default: 'paragraph') */
|
|
22
|
+
segmentation?: 'paragraph' | 'sentence' | 'line';
|
|
23
|
+
}
|
|
24
|
+
export interface CompactResult {
|
|
25
|
+
/** The compressed text */
|
|
26
|
+
text: string;
|
|
27
|
+
/** Original size in chars */
|
|
28
|
+
originalChars: number;
|
|
29
|
+
/** Compressed size in chars */
|
|
30
|
+
compressedChars: number;
|
|
31
|
+
/** Compression ratio (0-1, lower = more compressed) */
|
|
32
|
+
ratio: number;
|
|
33
|
+
/** Number of segments kept / total */
|
|
34
|
+
segmentsKept: number;
|
|
35
|
+
segmentsTotal: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compress text by extracting segments most relevant to a query.
|
|
39
|
+
*/
|
|
40
|
+
export declare function compact(embedder: IEmbedder, options: CompactOptions): Promise<CompactResult>;
|
|
41
|
+
//# sourceMappingURL=compact.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { cosineSimilarity, segment } from "./text-utils.js";
|
|
2
|
+
async function compact(embedder, options) {
|
|
3
|
+
const { text, query, maxChars = 3e3, minScore = 0.3, segmentation = "paragraph" } = options;
|
|
4
|
+
if (text.length <= maxChars) {
|
|
5
|
+
return {
|
|
6
|
+
text,
|
|
7
|
+
originalChars: text.length,
|
|
8
|
+
compressedChars: text.length,
|
|
9
|
+
ratio: 1,
|
|
10
|
+
segmentsKept: 1,
|
|
11
|
+
segmentsTotal: 1
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const segments = segment(text, segmentation);
|
|
15
|
+
if (segments.length === 0) {
|
|
16
|
+
return {
|
|
17
|
+
text: "",
|
|
18
|
+
originalChars: text.length,
|
|
19
|
+
compressedChars: 0,
|
|
20
|
+
ratio: 0,
|
|
21
|
+
segmentsKept: 0,
|
|
22
|
+
segmentsTotal: 0
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const queryVector = await embedder.embed(query);
|
|
26
|
+
const scored = [];
|
|
27
|
+
for (let i = 0; i < segments.length; i++) {
|
|
28
|
+
const segVector = await embedder.embed(segments[i]);
|
|
29
|
+
const score = cosineSimilarity(queryVector, segVector);
|
|
30
|
+
scored.push({ text: segments[i], score, index: i });
|
|
31
|
+
}
|
|
32
|
+
const sorted = scored.filter((s) => s.score >= minScore).sort((a, b) => b.score - a.score);
|
|
33
|
+
const selected = [];
|
|
34
|
+
let totalChars = 0;
|
|
35
|
+
for (const seg of sorted) {
|
|
36
|
+
if (totalChars + seg.text.length > maxChars) {
|
|
37
|
+
if (totalChars === 0) {
|
|
38
|
+
selected.push({ ...seg, text: seg.text.slice(0, maxChars) });
|
|
39
|
+
totalChars = maxChars;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
selected.push(seg);
|
|
44
|
+
totalChars += seg.text.length + 2;
|
|
45
|
+
}
|
|
46
|
+
selected.sort((a, b) => a.index - b.index);
|
|
47
|
+
const compressedText = selected.map((s) => s.text).join("\n\n");
|
|
48
|
+
return {
|
|
49
|
+
text: compressedText,
|
|
50
|
+
originalChars: text.length,
|
|
51
|
+
compressedChars: compressedText.length,
|
|
52
|
+
ratio: compressedText.length / text.length,
|
|
53
|
+
segmentsKept: selected.length,
|
|
54
|
+
segmentsTotal: segments.length
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export {
|
|
58
|
+
compact
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=compact.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface TransformOptions {
|
|
2
|
+
input: unknown;
|
|
3
|
+
expression: string;
|
|
4
|
+
}
|
|
5
|
+
export interface TransformResult {
|
|
6
|
+
output: unknown;
|
|
7
|
+
outputString: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function dataTransform(options: TransformOptions): TransformResult;
|
|
10
|
+
//# sourceMappingURL=data-transform.d.ts.map
|