@knowledgine/cli 0.0.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/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +30 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/start.d.ts +5 -0
- package/dist/commands/start.d.ts.map +1 -0
- package/dist/commands/start.js +72 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/indexer.d.ts +14 -0
- package/dist/lib/indexer.d.ts.map +1 -0
- package/dist/lib/indexer.js +71 -0
- package/dist/lib/indexer.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 R.M
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BrE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { mkdirSync } from "fs";
|
|
3
|
+
import { defineConfig, createDatabase, Migrator, KnowledgeRepository, ALL_MIGRATIONS, } from "@knowledgine/core";
|
|
4
|
+
import { indexAll } from "../lib/indexer.js";
|
|
5
|
+
export async function initCommand(options) {
|
|
6
|
+
const rootPath = resolve(options.path ?? process.cwd());
|
|
7
|
+
// Create .knowledgine directory
|
|
8
|
+
const knowledgineDir = resolve(rootPath, ".knowledgine");
|
|
9
|
+
mkdirSync(knowledgineDir, { recursive: true });
|
|
10
|
+
// Initialize database
|
|
11
|
+
const config = defineConfig({ rootPath });
|
|
12
|
+
const db = createDatabase(config.dbPath);
|
|
13
|
+
new Migrator(db, ALL_MIGRATIONS).migrate();
|
|
14
|
+
const repository = new KnowledgeRepository(db);
|
|
15
|
+
// Index all markdown files
|
|
16
|
+
const summary = await indexAll(rootPath, repository);
|
|
17
|
+
// Display summary (stderr to avoid MCP stdout conflicts)
|
|
18
|
+
console.error(`Indexing complete:`);
|
|
19
|
+
console.error(` Files: ${summary.processedFiles}/${summary.totalFiles}`);
|
|
20
|
+
console.error(` Patterns: ${summary.totalPatterns}`);
|
|
21
|
+
console.error(` Time: ${summary.elapsedMs}ms`);
|
|
22
|
+
if (summary.errors.length > 0) {
|
|
23
|
+
console.error(` Errors: ${summary.errors.length}`);
|
|
24
|
+
for (const err of summary.errors) {
|
|
25
|
+
console.error(` - ${err}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
db.close();
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAM7C,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,OAAoB;IACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAExD,gCAAgC;IAChC,MAAM,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACzD,SAAS,CAAC,cAAc,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE/C,sBAAsB;IACtB,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACzC,IAAI,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,EAAE,CAAC,CAAC;IAE/C,2BAA2B;IAC3B,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAErD,yDAAyD;IACzD,OAAO,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IACpC,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAC7E,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IACtD,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,SAAS,IAAI,CAAC,CAAC;IAEpD,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;QACtD,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACjC,OAAO,CAAC,KAAK,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,EAAE,CAAC,KAAK,EAAE,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CA2EvE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { mkdirSync } from "fs";
|
|
3
|
+
import { watch } from "chokidar";
|
|
4
|
+
import { defineConfig, createDatabase, Migrator, KnowledgeRepository, FileProcessor, PatternExtractor, ALL_MIGRATIONS, } from "@knowledgine/core";
|
|
5
|
+
import { createKnowledgineMcpServer, StdioServerTransport } from "@knowledgine/mcp-server";
|
|
6
|
+
import { indexFile } from "../lib/indexer.js";
|
|
7
|
+
export async function startCommand(options) {
|
|
8
|
+
const rootPath = resolve(options.path ?? process.cwd());
|
|
9
|
+
// Ensure .knowledgine directory exists
|
|
10
|
+
mkdirSync(resolve(rootPath, ".knowledgine"), { recursive: true });
|
|
11
|
+
// Initialize database + migrations
|
|
12
|
+
const config = defineConfig({ rootPath });
|
|
13
|
+
const db = createDatabase(config.dbPath);
|
|
14
|
+
new Migrator(db, ALL_MIGRATIONS).migrate();
|
|
15
|
+
const repository = new KnowledgeRepository(db);
|
|
16
|
+
// Warn if no notes indexed (H-8)
|
|
17
|
+
const stats = repository.getStats();
|
|
18
|
+
if (stats.totalNotes === 0) {
|
|
19
|
+
console.error("Warning: No notes indexed. Run `knowledgine init` first.");
|
|
20
|
+
}
|
|
21
|
+
// Start MCP server via stdio
|
|
22
|
+
const server = createKnowledgineMcpServer(repository, rootPath);
|
|
23
|
+
const transport = new StdioServerTransport();
|
|
24
|
+
await server.connect(transport);
|
|
25
|
+
console.error("MCP server started on stdio");
|
|
26
|
+
// File watcher for auto-reindexing
|
|
27
|
+
const fileProcessor = new FileProcessor();
|
|
28
|
+
const patternExtractor = new PatternExtractor();
|
|
29
|
+
const watcher = watch("**/*.md", {
|
|
30
|
+
cwd: rootPath,
|
|
31
|
+
ignored: [/node_modules/, /\.knowledgine/],
|
|
32
|
+
persistent: true,
|
|
33
|
+
ignoreInitial: true,
|
|
34
|
+
});
|
|
35
|
+
watcher.on("add", async (filePath) => {
|
|
36
|
+
try {
|
|
37
|
+
await indexFile(filePath, rootPath, fileProcessor, patternExtractor, repository);
|
|
38
|
+
console.error(`Indexed: ${filePath}`);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error(`Error indexing ${filePath}:`, error instanceof Error ? error.message : error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
watcher.on("change", async (filePath) => {
|
|
45
|
+
try {
|
|
46
|
+
await indexFile(filePath, rootPath, fileProcessor, patternExtractor, repository);
|
|
47
|
+
console.error(`Re-indexed: ${filePath}`);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error(`Error re-indexing ${filePath}:`, error instanceof Error ? error.message : error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
watcher.on("unlink", (filePath) => {
|
|
54
|
+
try {
|
|
55
|
+
repository.deleteNoteByPath(filePath);
|
|
56
|
+
console.error(`Removed: ${filePath}`);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(`Error removing ${filePath}:`, error instanceof Error ? error.message : error);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// Graceful shutdown
|
|
63
|
+
const shutdown = async () => {
|
|
64
|
+
console.error("Shutting down...");
|
|
65
|
+
await watcher.close();
|
|
66
|
+
db.close();
|
|
67
|
+
process.exit(0);
|
|
68
|
+
};
|
|
69
|
+
process.on("SIGINT", shutdown);
|
|
70
|
+
process.on("SIGTERM", shutdown);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=start.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"start.js","sourceRoot":"","sources":["../../src/commands/start.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EACL,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAM9C,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAqB;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,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,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC/F,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,oBAAoB;IACpB,MAAM,QAAQ,GAAG,KAAK,IAAmB,EAAE;QACzC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAClC,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACtB,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { VERSION } from "@knowledgine/core";
|
|
4
|
+
import { initCommand } from "./commands/init.js";
|
|
5
|
+
import { startCommand } from "./commands/start.js";
|
|
6
|
+
const program = new Command();
|
|
7
|
+
program
|
|
8
|
+
.name("knowledgine")
|
|
9
|
+
.description("Developer Knowledge Infrastructure - Extract structured knowledge from your codebase")
|
|
10
|
+
.version(VERSION);
|
|
11
|
+
program
|
|
12
|
+
.command("init")
|
|
13
|
+
.description("Scan and index markdown files in the current directory")
|
|
14
|
+
.option("--path <dir>", "Root directory to scan")
|
|
15
|
+
.action(initCommand);
|
|
16
|
+
program
|
|
17
|
+
.command("start")
|
|
18
|
+
.description("Start MCP server with file watching")
|
|
19
|
+
.option("--path <dir>", "Root directory to serve")
|
|
20
|
+
.action(startCommand);
|
|
21
|
+
program.parse();
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,CACV,sFAAsF,CACvF;KACA,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,wDAAwD,CAAC;KACrE,MAAM,CAAC,cAAc,EAAE,wBAAwB,CAAC;KAChD,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,OAAO;KACJ,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,qCAAqC,CAAC;KAClD,MAAM,CAAC,cAAc,EAAE,yBAAyB,CAAC;KACjD,MAAM,CAAC,YAAY,CAAC,CAAC;AAExB,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FileProcessor, PatternExtractor, KnowledgeRepository } from "@knowledgine/core";
|
|
2
|
+
import type { ExtractedPattern } from "@knowledgine/core";
|
|
3
|
+
export interface IndexSummary {
|
|
4
|
+
totalFiles: number;
|
|
5
|
+
processedFiles: number;
|
|
6
|
+
totalPatterns: number;
|
|
7
|
+
elapsedMs: number;
|
|
8
|
+
errors: string[];
|
|
9
|
+
}
|
|
10
|
+
export declare function discoverMarkdownFiles(rootPath: string): Promise<string[]>;
|
|
11
|
+
export declare function deduplicatePatterns(patterns: ExtractedPattern[]): ExtractedPattern[];
|
|
12
|
+
export declare function indexFile(relativePath: string, rootPath: string, fileProcessor: FileProcessor, patternExtractor: PatternExtractor, repository: KnowledgeRepository): Promise<number>;
|
|
13
|
+
export declare function indexAll(rootPath: string, repository: KnowledgeRepository): Promise<IndexSummary>;
|
|
14
|
+
//# sourceMappingURL=indexer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.d.ts","sourceRoot":"","sources":["../../src/lib/indexer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,wBAAsB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAU/E;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAWpF;AAED,wBAAsB,SAAS,CAC7B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,aAAa,EAC5B,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,mBAAmB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,mBAAmB,GAC9B,OAAO,CAAC,YAAY,CAAC,CAiCvB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { readdir } from "fs/promises";
|
|
2
|
+
import { join, extname } from "path";
|
|
3
|
+
import { FileProcessor, PatternExtractor, KnowledgeRepository } from "@knowledgine/core";
|
|
4
|
+
export async function discoverMarkdownFiles(rootPath) {
|
|
5
|
+
const entries = await readdir(rootPath, { recursive: true });
|
|
6
|
+
return entries
|
|
7
|
+
.filter((entry) => typeof entry === "string")
|
|
8
|
+
.filter((entry) => {
|
|
9
|
+
if (extname(entry) !== ".md")
|
|
10
|
+
return false;
|
|
11
|
+
const parts = entry.split("/");
|
|
12
|
+
// Exclude node_modules and dot-prefixed directories
|
|
13
|
+
return !parts.some((part) => part === "node_modules" || part.startsWith("."));
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function deduplicatePatterns(patterns) {
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
const result = [];
|
|
19
|
+
for (const p of patterns) {
|
|
20
|
+
const key = JSON.stringify([p.type, p.lineNumber ?? null, p.content]);
|
|
21
|
+
if (!seen.has(key)) {
|
|
22
|
+
seen.add(key);
|
|
23
|
+
result.push(p);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export async function indexFile(relativePath, rootPath, fileProcessor, patternExtractor, repository) {
|
|
29
|
+
const absolutePath = join(rootPath, relativePath);
|
|
30
|
+
const processed = await fileProcessor.processFile(absolutePath);
|
|
31
|
+
const title = fileProcessor.extractTitle(processed.content, relativePath);
|
|
32
|
+
const noteId = repository.saveNote({
|
|
33
|
+
filePath: relativePath,
|
|
34
|
+
title,
|
|
35
|
+
content: processed.content,
|
|
36
|
+
frontmatter: processed.frontmatter,
|
|
37
|
+
createdAt: new Date().toISOString(),
|
|
38
|
+
});
|
|
39
|
+
const dailyPatterns = patternExtractor.extractDailyPatterns(processed.content);
|
|
40
|
+
const ticketPatterns = patternExtractor.extractTicketPatterns(processed.content);
|
|
41
|
+
const allPatterns = deduplicatePatterns([...dailyPatterns, ...ticketPatterns]);
|
|
42
|
+
repository.savePatterns(noteId, allPatterns);
|
|
43
|
+
return allPatterns.length;
|
|
44
|
+
}
|
|
45
|
+
export async function indexAll(rootPath, repository) {
|
|
46
|
+
const start = Date.now();
|
|
47
|
+
const fileProcessor = new FileProcessor();
|
|
48
|
+
const patternExtractor = new PatternExtractor();
|
|
49
|
+
const errors = [];
|
|
50
|
+
const files = await discoverMarkdownFiles(rootPath);
|
|
51
|
+
let processedFiles = 0;
|
|
52
|
+
let totalPatterns = 0;
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
try {
|
|
55
|
+
const patternCount = await indexFile(file, rootPath, fileProcessor, patternExtractor, repository);
|
|
56
|
+
processedFiles++;
|
|
57
|
+
totalPatterns += patternCount;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
errors.push(`${file}: ${error instanceof Error ? error.message : String(error)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
totalFiles: files.length,
|
|
65
|
+
processedFiles,
|
|
66
|
+
totalPatterns,
|
|
67
|
+
elapsedMs: Date.now() - start,
|
|
68
|
+
errors,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indexer.js","sourceRoot":"","sources":["../../src/lib/indexer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAWzF,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAgB;IAC1D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,KAAK,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;SAC7D,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QAChB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K,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;IAED,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,MAAM;QACxB,cAAc;QACd,aAAa;QACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;QAC7B,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knowledgine/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"knowledgine": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"chokidar": "^5.0.0",
|
|
18
|
+
"commander": "^14.0.3",
|
|
19
|
+
"@knowledgine/core": "0.0.1",
|
|
20
|
+
"@knowledgine/mcp-server": "0.0.1"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"description": "CLI for indexing markdown files and serving MCP knowledge tools",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"knowledgine",
|
|
28
|
+
"cli",
|
|
29
|
+
"mcp",
|
|
30
|
+
"knowledge",
|
|
31
|
+
"indexer"
|
|
32
|
+
],
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/3062-in-zamud/knowledgine.git",
|
|
37
|
+
"directory": "packages/cli"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/3062-in-zamud/knowledgine#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/3062-in-zamud/knowledgine/issues"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsc --build tsconfig.build.json",
|
|
51
|
+
"test": "vitest",
|
|
52
|
+
"test:run": "vitest run"
|
|
53
|
+
}
|
|
54
|
+
}
|