@knowledgine/core 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/config.d.ts +13 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +30 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +42 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +101 -0
- package/dist/errors.js.map +1 -0
- package/dist/extraction/context-analyzer.d.ts +21 -0
- package/dist/extraction/context-analyzer.d.ts.map +1 -0
- package/dist/extraction/context-analyzer.js +50 -0
- package/dist/extraction/context-analyzer.js.map +1 -0
- package/dist/extraction/default-patterns.d.ts +21 -0
- package/dist/extraction/default-patterns.d.ts.map +1 -0
- package/dist/extraction/default-patterns.js +121 -0
- package/dist/extraction/default-patterns.js.map +1 -0
- package/dist/extraction/pattern-extractor.d.ts +18 -0
- package/dist/extraction/pattern-extractor.d.ts.map +1 -0
- package/dist/extraction/pattern-extractor.js +182 -0
- package/dist/extraction/pattern-extractor.js.map +1 -0
- package/dist/extraction/psp-detector.d.ts +29 -0
- package/dist/extraction/psp-detector.d.ts.map +1 -0
- package/dist/extraction/psp-detector.js +49 -0
- package/dist/extraction/psp-detector.js.map +1 -0
- package/dist/extraction/rule-based-classifier.d.ts +13 -0
- package/dist/extraction/rule-based-classifier.d.ts.map +1 -0
- package/dist/extraction/rule-based-classifier.js +35 -0
- package/dist/extraction/rule-based-classifier.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +21 -0
- package/dist/memory/memory-manager.d.ts.map +1 -0
- package/dist/memory/memory-manager.js +206 -0
- package/dist/memory/memory-manager.js.map +1 -0
- package/dist/processing/file-processor.d.ts +15 -0
- package/dist/processing/file-processor.d.ts.map +1 -0
- package/dist/processing/file-processor.js +38 -0
- package/dist/processing/file-processor.js.map +1 -0
- package/dist/search/knowledge-searcher.d.ts +25 -0
- package/dist/search/knowledge-searcher.d.ts.map +1 -0
- package/dist/search/knowledge-searcher.js +45 -0
- package/dist/search/knowledge-searcher.js.map +1 -0
- package/dist/search/link-generator.d.ts +21 -0
- package/dist/search/link-generator.d.ts.map +1 -0
- package/dist/search/link-generator.js +131 -0
- package/dist/search/link-generator.js.map +1 -0
- package/dist/storage/database.d.ts +3 -0
- package/dist/storage/database.d.ts.map +1 -0
- package/dist/storage/database.js +14 -0
- package/dist/storage/database.js.map +1 -0
- package/dist/storage/knowledge-repository.d.ts +74 -0
- package/dist/storage/knowledge-repository.d.ts.map +1 -0
- package/dist/storage/knowledge-repository.js +244 -0
- package/dist/storage/knowledge-repository.js.map +1 -0
- package/dist/storage/migrations/001_initial.d.ts +3 -0
- package/dist/storage/migrations/001_initial.d.ts.map +1 -0
- package/dist/storage/migrations/001_initial.js +21 -0
- package/dist/storage/migrations/001_initial.js.map +1 -0
- package/dist/storage/migrations/002_memory_layers.d.ts +3 -0
- package/dist/storage/migrations/002_memory_layers.d.ts.map +1 -0
- package/dist/storage/migrations/002_memory_layers.js +55 -0
- package/dist/storage/migrations/002_memory_layers.js.map +1 -0
- package/dist/storage/migrator.d.ts +24 -0
- package/dist/storage/migrator.d.ts.map +1 -0
- package/dist/storage/migrator.js +68 -0
- package/dist/storage/migrator.js.map +1 -0
- package/dist/storage/schema.d.ts +2 -0
- package/dist/storage/schema.d.ts.map +1 -0
- package/dist/storage/schema.js +79 -0
- package/dist/storage/schema.js.map +1 -0
- package/dist/types.d.ts +119 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/code-block-detector.d.ts +25 -0
- package/dist/utils/code-block-detector.d.ts.map +1 -0
- package/dist/utils/code-block-detector.js +84 -0
- package/dist/utils/code-block-detector.js.map +1 -0
- package/package.json +53 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** Core pattern types (4 axes) */
|
|
2
|
+
export type PatternType = "problem" | "solution" | "learning" | "time";
|
|
3
|
+
/** Extracted pattern from note content */
|
|
4
|
+
export interface ExtractedPattern {
|
|
5
|
+
type: PatternType;
|
|
6
|
+
content: string;
|
|
7
|
+
confidence: number;
|
|
8
|
+
context?: string;
|
|
9
|
+
lineNumber?: number;
|
|
10
|
+
contextType?: "section_header" | "list_item" | "body_text" | "code_comment";
|
|
11
|
+
}
|
|
12
|
+
/** Problem-Solution pair */
|
|
13
|
+
export interface ProblemSolutionPair {
|
|
14
|
+
id?: number;
|
|
15
|
+
problemNoteId: number;
|
|
16
|
+
solutionNoteId: number;
|
|
17
|
+
problemPattern: string;
|
|
18
|
+
solutionPattern: string;
|
|
19
|
+
timeDiff?: number;
|
|
20
|
+
confidence: number;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}
|
|
23
|
+
/** Link between notes */
|
|
24
|
+
export interface NoteLink {
|
|
25
|
+
id?: number;
|
|
26
|
+
sourceNoteId: number;
|
|
27
|
+
targetNoteId: number;
|
|
28
|
+
linkType: "related" | "derived" | "references" | "auto-generated";
|
|
29
|
+
similarity?: number;
|
|
30
|
+
createdAt: string;
|
|
31
|
+
}
|
|
32
|
+
/** Core knowledge data structure */
|
|
33
|
+
export interface KnowledgeData {
|
|
34
|
+
id?: number;
|
|
35
|
+
filePath: string;
|
|
36
|
+
title: string;
|
|
37
|
+
content: string;
|
|
38
|
+
frontmatter: Record<string, unknown>;
|
|
39
|
+
createdAt: string;
|
|
40
|
+
updatedAt?: string;
|
|
41
|
+
}
|
|
42
|
+
/** Search result */
|
|
43
|
+
export interface SearchResult {
|
|
44
|
+
note: {
|
|
45
|
+
id: number;
|
|
46
|
+
filePath: string;
|
|
47
|
+
title: string;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
updatedAt: string;
|
|
50
|
+
};
|
|
51
|
+
score: number;
|
|
52
|
+
matchReason: string[];
|
|
53
|
+
}
|
|
54
|
+
export type EntityType = "person" | "project" | "technology" | "concept" | "tool" | "organization" | "event";
|
|
55
|
+
export type RelationType = "uses" | "implements" | "depends_on" | "related_to" | "created_by" | "works_on" | "solves" | "references" | "part_of" | "similar_to";
|
|
56
|
+
export type ObservationType = "fact" | "insight" | "learning" | "decision" | "performance";
|
|
57
|
+
export interface Entity {
|
|
58
|
+
id?: number;
|
|
59
|
+
name: string;
|
|
60
|
+
entityType: EntityType;
|
|
61
|
+
description?: string;
|
|
62
|
+
createdAt: string;
|
|
63
|
+
updatedAt?: string;
|
|
64
|
+
metadata?: Record<string, unknown>;
|
|
65
|
+
}
|
|
66
|
+
export interface Relation {
|
|
67
|
+
id?: number;
|
|
68
|
+
fromEntityId: number;
|
|
69
|
+
toEntityId: number;
|
|
70
|
+
relationType: RelationType;
|
|
71
|
+
strength?: number;
|
|
72
|
+
description?: string;
|
|
73
|
+
createdAt: string;
|
|
74
|
+
}
|
|
75
|
+
export interface Observation {
|
|
76
|
+
id?: number;
|
|
77
|
+
entityId: number;
|
|
78
|
+
content: string;
|
|
79
|
+
observationType: ObservationType;
|
|
80
|
+
confidence?: number;
|
|
81
|
+
sourceNoteId?: number;
|
|
82
|
+
sourcePatternId?: number;
|
|
83
|
+
createdAt: string;
|
|
84
|
+
metadata?: Record<string, unknown>;
|
|
85
|
+
}
|
|
86
|
+
export interface EntityWithGraph extends Entity {
|
|
87
|
+
observations: Observation[];
|
|
88
|
+
outgoingRelations: Array<Relation & {
|
|
89
|
+
targetEntity: Entity;
|
|
90
|
+
}>;
|
|
91
|
+
incomingRelations: Array<Relation & {
|
|
92
|
+
sourceEntity: Entity;
|
|
93
|
+
}>;
|
|
94
|
+
linkedNotes: Array<{
|
|
95
|
+
entityId: number;
|
|
96
|
+
noteId: number;
|
|
97
|
+
note: Partial<KnowledgeData>;
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
100
|
+
export type MemoryLayer = "episodic" | "semantic" | "procedural";
|
|
101
|
+
export interface MemoryEntry {
|
|
102
|
+
id?: number;
|
|
103
|
+
noteId?: number;
|
|
104
|
+
layer: MemoryLayer;
|
|
105
|
+
content: string;
|
|
106
|
+
summary?: string;
|
|
107
|
+
accessCount: number;
|
|
108
|
+
lastAccessedAt?: string;
|
|
109
|
+
promotedFrom?: number;
|
|
110
|
+
createdAt: string;
|
|
111
|
+
updatedAt?: string;
|
|
112
|
+
metadata?: Record<string, unknown>;
|
|
113
|
+
}
|
|
114
|
+
export interface MemoryContext {
|
|
115
|
+
episodic: MemoryEntry[];
|
|
116
|
+
semantic: MemoryEntry[];
|
|
117
|
+
procedural: MemoryEntry[];
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;AAEvE,0CAA0C;AAC1C,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,gBAAgB,GAAG,WAAW,GAAG,WAAW,GAAG,cAAc,CAAC;CAC7E;AAED,4BAA4B;AAC5B,MAAM,WAAW,mBAAmB;IAClC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,yBAAyB;AACzB,MAA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QAAC,IAAI,EAAE,OAAO,CAAC,aAAa,CAAC,CAAA;KAAE,CAAC,CAAC;CACxF;AAID,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,CAAC;AAEjE,MAAM,WAAW,WAAW;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,UAAU,EAAE,WAAW,EAAE,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface CodeBlockRange {
|
|
2
|
+
startLine: number;
|
|
3
|
+
endLine: number;
|
|
4
|
+
language?: string;
|
|
5
|
+
type: "fenced" | "inline";
|
|
6
|
+
}
|
|
7
|
+
export declare class CodeBlockDetector {
|
|
8
|
+
private static readonly CODE_BLOCK_START;
|
|
9
|
+
private static readonly CODE_BLOCK_END;
|
|
10
|
+
private static readonly INLINE_CODE;
|
|
11
|
+
detectCodeBlocks(content: string): CodeBlockRange[];
|
|
12
|
+
isInCodeBlock(lineNumber: number, codeBlocks: CodeBlockRange[]): boolean;
|
|
13
|
+
hasInlineCode(line: string): boolean;
|
|
14
|
+
removeInlineCode(line: string): string;
|
|
15
|
+
filterNonCodeLines(lines: string[], codeBlocks: CodeBlockRange[]): {
|
|
16
|
+
line: string;
|
|
17
|
+
originalLineNumber: number;
|
|
18
|
+
}[];
|
|
19
|
+
getCodeBlockStats(content: string): {
|
|
20
|
+
totalCodeBlocks: number;
|
|
21
|
+
totalCodeLines: number;
|
|
22
|
+
languages: Record<string, number>;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=code-block-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block-detector.d.ts","sourceRoot":"","sources":["../../src/utils/code-block-detector.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;CAC3B;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACxD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAc;IACpD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAA8B;IAEjE,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE;IA6CnD,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,OAAO;IAIxE,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAKpC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAItC,kBAAkB,CAChB,KAAK,EAAE,MAAM,EAAE,EACf,UAAU,EAAE,cAAc,EAAE,GAC3B;QACD,IAAI,EAAE,MAAM,CAAC;QACb,kBAAkB,EAAE,MAAM,CAAC;KAC5B,EAAE;IASH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;QAClC,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACnC;CAsBF"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export class CodeBlockDetector {
|
|
2
|
+
static CODE_BLOCK_START = /^```(\w+)?/;
|
|
3
|
+
static CODE_BLOCK_END = /^```\s*$/;
|
|
4
|
+
static INLINE_CODE = /(?<!`)`(?!`)[^`]+`(?!`)/g;
|
|
5
|
+
detectCodeBlocks(content) {
|
|
6
|
+
const lines = content.split("\n");
|
|
7
|
+
const codeBlocks = [];
|
|
8
|
+
let inCodeBlock = false;
|
|
9
|
+
let currentBlockStart = -1;
|
|
10
|
+
let currentLanguage;
|
|
11
|
+
for (let i = 0; i < lines.length; i++) {
|
|
12
|
+
const line = lines[i];
|
|
13
|
+
if (!line)
|
|
14
|
+
continue;
|
|
15
|
+
if (!inCodeBlock && CodeBlockDetector.CODE_BLOCK_START.test(line)) {
|
|
16
|
+
const match = line.match(CodeBlockDetector.CODE_BLOCK_START);
|
|
17
|
+
inCodeBlock = true;
|
|
18
|
+
currentBlockStart = i;
|
|
19
|
+
currentLanguage = match?.[1];
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (inCodeBlock && CodeBlockDetector.CODE_BLOCK_END.test(line)) {
|
|
23
|
+
codeBlocks.push({
|
|
24
|
+
startLine: currentBlockStart,
|
|
25
|
+
endLine: i,
|
|
26
|
+
...(currentLanguage !== undefined && { language: currentLanguage }),
|
|
27
|
+
type: "fenced",
|
|
28
|
+
});
|
|
29
|
+
inCodeBlock = false;
|
|
30
|
+
currentBlockStart = -1;
|
|
31
|
+
currentLanguage = undefined;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (inCodeBlock && currentBlockStart !== -1) {
|
|
36
|
+
codeBlocks.push({
|
|
37
|
+
startLine: currentBlockStart,
|
|
38
|
+
endLine: lines.length - 1,
|
|
39
|
+
...(currentLanguage !== undefined && { language: currentLanguage }),
|
|
40
|
+
type: "fenced",
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return codeBlocks;
|
|
44
|
+
}
|
|
45
|
+
isInCodeBlock(lineNumber, codeBlocks) {
|
|
46
|
+
return codeBlocks.some((block) => lineNumber >= block.startLine && lineNumber <= block.endLine);
|
|
47
|
+
}
|
|
48
|
+
hasInlineCode(line) {
|
|
49
|
+
const inlineCodeRegex = /(?<!`)`(?!`)[^`]+`(?!`)/;
|
|
50
|
+
return inlineCodeRegex.test(line);
|
|
51
|
+
}
|
|
52
|
+
removeInlineCode(line) {
|
|
53
|
+
return line.replace(CodeBlockDetector.INLINE_CODE, "");
|
|
54
|
+
}
|
|
55
|
+
filterNonCodeLines(lines, codeBlocks) {
|
|
56
|
+
return lines
|
|
57
|
+
.map((line, index) => ({
|
|
58
|
+
line,
|
|
59
|
+
originalLineNumber: index,
|
|
60
|
+
}))
|
|
61
|
+
.filter(({ originalLineNumber }) => !this.isInCodeBlock(originalLineNumber, codeBlocks));
|
|
62
|
+
}
|
|
63
|
+
getCodeBlockStats(content) {
|
|
64
|
+
const codeBlocks = this.detectCodeBlocks(content);
|
|
65
|
+
const languages = {};
|
|
66
|
+
let totalCodeLines = 0;
|
|
67
|
+
for (const block of codeBlocks) {
|
|
68
|
+
const blockLines = block.endLine - block.startLine + 1;
|
|
69
|
+
totalCodeLines += blockLines;
|
|
70
|
+
if (block.language) {
|
|
71
|
+
languages[block.language] = (languages[block.language] || 0) + 1;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
languages["unknown"] = (languages["unknown"] || 0) + 1;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
totalCodeBlocks: codeBlocks.length,
|
|
79
|
+
totalCodeLines,
|
|
80
|
+
languages,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=code-block-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-block-detector.js","sourceRoot":"","sources":["../../src/utils/code-block-detector.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,iBAAiB;IACpB,MAAM,CAAU,gBAAgB,GAAG,YAAY,CAAC;IAChD,MAAM,CAAU,cAAc,GAAG,UAAU,CAAC;IAC5C,MAAM,CAAU,WAAW,GAAG,0BAA0B,CAAC;IAEjE,gBAAgB,CAAC,OAAe;QAC9B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,UAAU,GAAqB,EAAE,CAAC;QACxC,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,iBAAiB,GAAG,CAAC,CAAC,CAAC;QAC3B,IAAI,eAAmC,CAAC;QAExC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,IAAI,CAAC,IAAI;gBAAE,SAAS;YAEpB,IAAI,CAAC,WAAW,IAAI,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAClE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;gBAC7D,WAAW,GAAG,IAAI,CAAC;gBACnB,iBAAiB,GAAG,CAAC,CAAC;gBACtB,eAAe,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC7B,SAAS;YACX,CAAC;YAED,IAAI,WAAW,IAAI,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC/D,UAAU,CAAC,IAAI,CAAC;oBACd,SAAS,EAAE,iBAAiB;oBAC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AAC,CAAC;aACF,MAAM,CAAC,CAAC,EAAE,kBAAkB,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC,CAAC;IAC7F,CAAC;IAED,iBAAiB,CAAC,OAAe;QAK/B,MAAM,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,SAAS,GAA2B,EAAE,CAAC;QAC7C,IAAI,cAAc,GAAG,CAAC,CAAC;QAEvB,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE,CAAC;YAC/B,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;YACvD,cAAc,IAAI,UAAU,CAAC;YAE7B,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACnB,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACnE,CAAC;iBAAM,CAAC;gBACN,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,OAAO;YACL,eAAe,EAAE,UAAU,CAAC,MAAM;YAClC,cAAc;YACd,SAAS;SACV,CAAC;IACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@knowledgine/core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"description": "Core library for extracting structured knowledge from markdown files",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"knowledge",
|
|
19
|
+
"extraction",
|
|
20
|
+
"mcp",
|
|
21
|
+
"ai",
|
|
22
|
+
"markdown",
|
|
23
|
+
"fts5"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/3062-in-zamud/knowledgine.git",
|
|
29
|
+
"directory": "packages/core"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/3062-in-zamud/knowledgine#readme",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/3062-in-zamud/knowledgine/issues"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"better-sqlite3": "^11.0.0",
|
|
43
|
+
"yaml": "^2.7.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/better-sqlite3": "^7.0.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc --build tsconfig.build.json",
|
|
50
|
+
"test": "vitest",
|
|
51
|
+
"test:run": "vitest run"
|
|
52
|
+
}
|
|
53
|
+
}
|