@porast1/mcp-cognitive 1.0.0
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 +142 -0
- package/dist/adapters/sqlite.adapter.d.ts +29 -0
- package/dist/adapters/sqlite.adapter.d.ts.map +1 -0
- package/dist/adapters/sqlite.adapter.js +450 -0
- package/dist/adapters/sqlite.adapter.js.map +1 -0
- package/dist/adapters/weaviate.adapter.d.ts +43 -0
- package/dist/adapters/weaviate.adapter.d.ts.map +1 -0
- package/dist/adapters/weaviate.adapter.js +678 -0
- package/dist/adapters/weaviate.adapter.js.map +1 -0
- package/dist/cli/audit.d.ts +2 -0
- package/dist/cli/audit.d.ts.map +1 -0
- package/dist/cli/audit.js +50 -0
- package/dist/cli/audit.js.map +1 -0
- package/dist/cli/migrate-to-weaviate.d.ts +2 -0
- package/dist/cli/migrate-to-weaviate.d.ts.map +1 -0
- package/dist/cli/migrate-to-weaviate.js +65 -0
- package/dist/cli/migrate-to-weaviate.js.map +1 -0
- package/dist/cli/stale.d.ts +2 -0
- package/dist/cli/stale.d.ts.map +1 -0
- package/dist/cli/stale.js +27 -0
- package/dist/cli/stale.js.map +1 -0
- package/dist/cli/sync-ddd-docs.d.ts +2 -0
- package/dist/cli/sync-ddd-docs.d.ts.map +1 -0
- package/dist/cli/sync-ddd-docs.js +88 -0
- package/dist/cli/sync-ddd-docs.js.map +1 -0
- package/dist/cli/verify.d.ts +2 -0
- package/dist/cli/verify.d.ts.map +1 -0
- package/dist/cli/verify.js +36 -0
- package/dist/cli/verify.js.map +1 -0
- package/dist/hooks/post-commit.d.ts +13 -0
- package/dist/hooks/post-commit.d.ts.map +1 -0
- package/dist/hooks/post-commit.js +197 -0
- package/dist/hooks/post-commit.js.map +1 -0
- package/dist/ports/cognitive-store.port.d.ts +34 -0
- package/dist/ports/cognitive-store.port.d.ts.map +1 -0
- package/dist/ports/cognitive-store.port.js +2 -0
- package/dist/ports/cognitive-store.port.js.map +1 -0
- package/dist/profiles/agent-profiles.d.ts +20 -0
- package/dist/profiles/agent-profiles.d.ts.map +1 -0
- package/dist/profiles/agent-profiles.js +74 -0
- package/dist/profiles/agent-profiles.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +59 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/audit.tool.d.ts +8 -0
- package/dist/tools/audit.tool.d.ts.map +1 -0
- package/dist/tools/audit.tool.js +71 -0
- package/dist/tools/audit.tool.js.map +1 -0
- package/dist/tools/recall.tool.d.ts +30 -0
- package/dist/tools/recall.tool.d.ts.map +1 -0
- package/dist/tools/recall.tool.js +43 -0
- package/dist/tools/recall.tool.js.map +1 -0
- package/dist/tools/store.tool.d.ts +34 -0
- package/dist/tools/store.tool.d.ts.map +1 -0
- package/dist/tools/store.tool.js +51 -0
- package/dist/tools/store.tool.js.map +1 -0
- package/dist/tools/verify.tool.d.ts +10 -0
- package/dist/tools/verify.tool.d.ts.map +1 -0
- package/dist/tools/verify.tool.js +56 -0
- package/dist/tools/verify.tool.js.map +1 -0
- package/dist/types.d.ts +85 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/citation-checker.d.ts +21 -0
- package/dist/utils/citation-checker.d.ts.map +1 -0
- package/dist/utils/citation-checker.js +84 -0
- package/dist/utils/citation-checker.js.map +1 -0
- package/dist/utils/decay.d.ts +16 -0
- package/dist/utils/decay.d.ts.map +1 -0
- package/dist/utils/decay.js +62 -0
- package/dist/utils/decay.js.map +1 -0
- package/package.json +57 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Fact type determines TTL and lifecycle rules */
|
|
2
|
+
export type FactType = 'invariant' | 'policy' | 'convention' | 'observation' | 'ephemeral';
|
|
3
|
+
/** Fact lifecycle status */
|
|
4
|
+
export type FactStatus = 'active' | 'stale' | 'archived';
|
|
5
|
+
/** Known bounded-context modules */
|
|
6
|
+
export type Module = 'identity' | 'organization' | 'platform' | 'infrastructure' | 'tooling' | 'testing' | 'general';
|
|
7
|
+
/** File/line citation for fact verification */
|
|
8
|
+
export interface Citation {
|
|
9
|
+
readonly file: string;
|
|
10
|
+
readonly line?: number;
|
|
11
|
+
readonly context?: string;
|
|
12
|
+
}
|
|
13
|
+
/** A stored knowledge fact */
|
|
14
|
+
export interface Fact {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly fact: string;
|
|
17
|
+
readonly type: FactType;
|
|
18
|
+
readonly module: Module;
|
|
19
|
+
readonly confidence: number;
|
|
20
|
+
readonly citations: readonly Citation[];
|
|
21
|
+
readonly tags: readonly string[];
|
|
22
|
+
readonly epoch: number;
|
|
23
|
+
readonly createdAt: string;
|
|
24
|
+
readonly updatedAt: string;
|
|
25
|
+
readonly lastRecalled: string | null;
|
|
26
|
+
readonly recallCount: number;
|
|
27
|
+
readonly supersedes: string | null;
|
|
28
|
+
readonly status: FactStatus;
|
|
29
|
+
}
|
|
30
|
+
/** Input for creating a new fact (id and timestamps generated) */
|
|
31
|
+
export interface FactInput {
|
|
32
|
+
readonly fact: string;
|
|
33
|
+
readonly type: FactType;
|
|
34
|
+
readonly module: Module;
|
|
35
|
+
readonly confidence?: number;
|
|
36
|
+
readonly citations?: readonly Citation[];
|
|
37
|
+
readonly tags?: readonly string[];
|
|
38
|
+
readonly epoch?: number;
|
|
39
|
+
readonly supersedes?: string;
|
|
40
|
+
}
|
|
41
|
+
/** Parameters for recalling facts from the store */
|
|
42
|
+
export interface RecallQuery {
|
|
43
|
+
readonly query: string;
|
|
44
|
+
readonly agent?: string;
|
|
45
|
+
readonly module?: Module;
|
|
46
|
+
readonly types?: readonly FactType[];
|
|
47
|
+
readonly tags?: readonly string[];
|
|
48
|
+
readonly minConfidence?: number;
|
|
49
|
+
readonly limit?: number;
|
|
50
|
+
}
|
|
51
|
+
/** Result of a recall operation */
|
|
52
|
+
export interface RecallResult {
|
|
53
|
+
readonly facts: readonly Fact[];
|
|
54
|
+
readonly totalMatches: number;
|
|
55
|
+
readonly queryTimeMs: number;
|
|
56
|
+
}
|
|
57
|
+
/** Citation verification status */
|
|
58
|
+
export type CitationStatus = 'valid' | 'stale' | 'broken';
|
|
59
|
+
/** Result of verifying a single fact's citations */
|
|
60
|
+
export interface VerifyResult {
|
|
61
|
+
readonly factId: string;
|
|
62
|
+
readonly factSnippet: string;
|
|
63
|
+
readonly citations: readonly {
|
|
64
|
+
readonly citation: Citation;
|
|
65
|
+
readonly status: CitationStatus;
|
|
66
|
+
readonly detail?: string;
|
|
67
|
+
}[];
|
|
68
|
+
readonly overallStatus: CitationStatus;
|
|
69
|
+
}
|
|
70
|
+
/** Health report for the entire cognitive database */
|
|
71
|
+
export interface AuditReport {
|
|
72
|
+
readonly totalFacts: number;
|
|
73
|
+
readonly byStatus: Readonly<Record<FactStatus, number>>;
|
|
74
|
+
readonly byType: Readonly<Record<FactType, number>>;
|
|
75
|
+
readonly byModule: Readonly<Partial<Record<Module, number>>>;
|
|
76
|
+
readonly staleFacts: readonly Fact[];
|
|
77
|
+
readonly brokenCitations: readonly VerifyResult[];
|
|
78
|
+
readonly duplicateCandidates: readonly {
|
|
79
|
+
readonly a: string;
|
|
80
|
+
readonly b: string;
|
|
81
|
+
readonly similarity: string;
|
|
82
|
+
}[];
|
|
83
|
+
readonly generatedAt: string;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,mDAAmD;AACnD,MAAM,MAAM,QAAQ,GAChB,WAAW,GACX,QAAQ,GACR,YAAY,GACZ,aAAa,GACb,WAAW,CAAC;AAEhB,4BAA4B;AAC5B,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,oCAAoC;AACpC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Q,CAAC,aAAa,EAAE,cAAc,CAAC;CACxC;AAED,sDAAsD;AACtD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,UAAU,EAAE,SAAS,IAAI,EAAE,CAAC;IACrC,QAAQ,CAAC,eAAe,EAAE,SAAS,YAAY,EAAE,CAAC;IAClD,QAAQ,CAAC,mBAAmB,EAAE,SAAS;QAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACjH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Citation, CitationStatus } from '../types.js';
|
|
2
|
+
export interface CitationCheckResult {
|
|
3
|
+
readonly citation: Citation;
|
|
4
|
+
readonly status: CitationStatus;
|
|
5
|
+
readonly detail?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Verify a single citation: check file exists and optionally that the line content is meaningful.
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkCitation(citation: Citation, workspaceRoot: string): CitationCheckResult;
|
|
11
|
+
/**
|
|
12
|
+
* Check all citations for a fact, returning individual results
|
|
13
|
+
* and an overall status (worst status wins).
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkCitations(citations: readonly Citation[], workspaceRoot: string): CitationCheckResult[];
|
|
16
|
+
/**
|
|
17
|
+
* Determine overall citation status from individual results.
|
|
18
|
+
* broken > stale > valid
|
|
19
|
+
*/
|
|
20
|
+
export declare function overallCitationStatus(results: readonly CitationCheckResult[]): CitationStatus;
|
|
21
|
+
//# sourceMappingURL=citation-checker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citation-checker.d.ts","sourceRoot":"","sources":["../../src/utils/citation-checker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE5D,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAYD;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,GAAG,mBAAmB,CAqD5F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,SAAS,QAAQ,EAAE,EAC9B,aAAa,EAAE,MAAM,GACpB,mBAAmB,EAAE,CAEvB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,mBAAmB,EAAE,GAAG,cAAc,CAK7F"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Parse a citation file path, resolving relative to workspace root.
|
|
5
|
+
*/
|
|
6
|
+
function resolveFilePath(file, workspaceRoot) {
|
|
7
|
+
if (file.startsWith('/') || file.match(/^[A-Za-z]:\\/)) {
|
|
8
|
+
return file;
|
|
9
|
+
}
|
|
10
|
+
return resolve(workspaceRoot, file);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Verify a single citation: check file exists and optionally that the line content is meaningful.
|
|
14
|
+
*/
|
|
15
|
+
export function checkCitation(citation, workspaceRoot) {
|
|
16
|
+
const filePath = resolveFilePath(citation.file, workspaceRoot);
|
|
17
|
+
if (!existsSync(filePath)) {
|
|
18
|
+
return {
|
|
19
|
+
citation,
|
|
20
|
+
status: 'broken',
|
|
21
|
+
detail: `File not found: ${filePath}`,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (citation.line === undefined) {
|
|
25
|
+
return {
|
|
26
|
+
citation,
|
|
27
|
+
status: 'valid',
|
|
28
|
+
detail: 'File exists (no line specified)',
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
33
|
+
const lines = content.split('\n');
|
|
34
|
+
const lineIndex = citation.line - 1;
|
|
35
|
+
if (lineIndex < 0 || lineIndex >= lines.length) {
|
|
36
|
+
return {
|
|
37
|
+
citation,
|
|
38
|
+
status: 'stale',
|
|
39
|
+
detail: `Line ${citation.line} out of range (file has ${lines.length} lines)`,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const lineContent = lines[lineIndex]?.trim() ?? '';
|
|
43
|
+
if (lineContent === '') {
|
|
44
|
+
return {
|
|
45
|
+
citation,
|
|
46
|
+
status: 'stale',
|
|
47
|
+
detail: `Line ${citation.line} is empty`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
citation,
|
|
52
|
+
status: 'valid',
|
|
53
|
+
detail: `L${citation.line}: ${lineContent.substring(0, 80)}`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return {
|
|
58
|
+
citation,
|
|
59
|
+
status: 'broken',
|
|
60
|
+
detail: `Error reading file: ${err instanceof Error ? err.message : String(err)}`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check all citations for a fact, returning individual results
|
|
66
|
+
* and an overall status (worst status wins).
|
|
67
|
+
*/
|
|
68
|
+
export function checkCitations(citations, workspaceRoot) {
|
|
69
|
+
return citations.map((c) => checkCitation(c, workspaceRoot));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Determine overall citation status from individual results.
|
|
73
|
+
* broken > stale > valid
|
|
74
|
+
*/
|
|
75
|
+
export function overallCitationStatus(results) {
|
|
76
|
+
if (results.length === 0)
|
|
77
|
+
return 'valid';
|
|
78
|
+
if (results.some((r) => r.status === 'broken'))
|
|
79
|
+
return 'broken';
|
|
80
|
+
if (results.some((r) => r.status === 'stale'))
|
|
81
|
+
return 'stale';
|
|
82
|
+
return 'valid';
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=citation-checker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"citation-checker.js","sourceRoot":"","sources":["../../src/utils/citation-checker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC;;GAEG;AACH,SAAS,eAAe,CAAC,IAAY,EAAE,aAAqB;IAC1D,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,QAAkB,EAAE,aAAqB;IACrE,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAA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AO;YACL,QAAQ;YACR,MAAM,EAAE,QAAQ;YAChB,MAAM,EAAE,uBAAuB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;SAClF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,SAA8B,EAC9B,aAAqB;IAErB,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAuC;IAC3E,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAChE,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAC9D,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Fact } from '../types.js';
|
|
2
|
+
export interface DecayAction {
|
|
3
|
+
readonly fact: Fact;
|
|
4
|
+
readonly action: 'mark-stale' | 'archive';
|
|
5
|
+
readonly reason: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check a fact against decay rules. Uses lastRecalled (or createdAt if never recalled)
|
|
9
|
+
* for observation/convention types, and createdAt for ephemeral.
|
|
10
|
+
*/
|
|
11
|
+
export declare function checkDecay(fact: Fact): DecayAction | null;
|
|
12
|
+
/**
|
|
13
|
+
* Batch check all provided facts for decay.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkDecayBatch(facts: readonly Fact[]): DecayAction[];
|
|
16
|
+
//# sourceMappingURL=decay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decay.d.ts","sourceRoot":"","sources":["../../src/utils/decay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,aAAa,CAAC;AAkBlD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,IAAI,CAgCzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,WAAW,EAAE,CASrE"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** TTL rules per fact type (in days) */
|
|
2
|
+
const DECAY_RULES = {
|
|
3
|
+
ephemeral: { staleAfterDays: 7, archiveAfterDays: 14 },
|
|
4
|
+
observation: { staleAfterDays: 30, archiveAfterDays: 90 },
|
|
5
|
+
convention: { staleAfterDays: 180, archiveAfterDays: null },
|
|
6
|
+
policy: { staleAfterDays: null, archiveAfterDays: null },
|
|
7
|
+
invariant: { staleAfterDays: null, archiveAfterDays: null },
|
|
8
|
+
};
|
|
9
|
+
function daysSince(dateStr) {
|
|
10
|
+
if (dateStr === null)
|
|
11
|
+
return null;
|
|
12
|
+
const then = new Date(dateStr).getTime();
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
return Math.floor((now - then) / (1000 * 60 * 60 * 24));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Check a fact against decay rules. Uses lastRecalled (or createdAt if never recalled)
|
|
18
|
+
* for observation/convention types, and createdAt for ephemeral.
|
|
19
|
+
*/
|
|
20
|
+
export function checkDecay(fact) {
|
|
21
|
+
if (fact.status !== 'active' && fact.status !== 'stale')
|
|
22
|
+
return null;
|
|
23
|
+
const rules = DECAY_RULES[fact.type];
|
|
24
|
+
// Ephemeral uses createdAt, others use lastRecalled (or createdAt if never recalled)
|
|
25
|
+
const referenceDate = fact.type === 'ephemeral'
|
|
26
|
+
? fact.createdAt
|
|
27
|
+
: (fact.lastRecalled ?? fact.createdAt);
|
|
28
|
+
const days = daysSince(referenceDate);
|
|
29
|
+
if (days === null)
|
|
30
|
+
return null;
|
|
31
|
+
// Check archive first (takes priority)
|
|
32
|
+
if (rules.archiveAfterDays !== null && days >= rules.archiveAfterDays && fact.status === 'stale') {
|
|
33
|
+
return {
|
|
34
|
+
fact,
|
|
35
|
+
action: 'archive',
|
|
36
|
+
reason: `${fact.type} fact not recalled for ${days} days (threshold: ${rules.archiveAfterDays})`,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Check stale
|
|
40
|
+
if (rules.staleAfterDays !== null && days >= rules.staleAfterDays && fact.status === 'active') {
|
|
41
|
+
return {
|
|
42
|
+
fact,
|
|
43
|
+
action: 'mark-stale',
|
|
44
|
+
reason: `${fact.type} fact not recalled for ${days} days (threshold: ${rules.staleAfterDays})`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Batch check all provided facts for decay.
|
|
51
|
+
*/
|
|
52
|
+
export function checkDecayBatch(facts) {
|
|
53
|
+
const actions = [];
|
|
54
|
+
for (const fact of facts) {
|
|
55
|
+
const action = checkDecay(fact);
|
|
56
|
+
if (action !== null) {
|
|
57
|
+
actions.push(action);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return actions;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=decay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decay.js","sourceRoot":"","sources":["../../src/utils/decay.ts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I,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IACtC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAE/B,uCAAuC;IACvC,IAAI,KAAK,CAAC,gBAAgB,KAAK,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,gBAAgB,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QACjG,OAAO;YACL,IAAI;YACJ,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,0BAA0B,IAAI,qBAAqB,KAAK,CAAC,gBAAgB,GAAG;SACjG,CAAC;IACJ,CAAC;IAED,cAAc;IACd,IAAI,KAAK,CAAC,cAAc,KAAK,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC,cAAc,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9F,OAAO;YACL,IAAI;YACJ,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,0BAA0B,IAAI,qBAAqB,KAAK,CAAC,cAAc,GAAG;SAC/F,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAsB;IACpD,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@porast1/mcp-cognitive",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Universal MCP server for AI knowledge persistence with SQLite fallback and Weaviate hybrid search",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/server.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mcp-cognitive": "dist/server.js",
|
|
9
|
+
"mcp-cognitive-migrate": "dist/cli/migrate-to-weaviate.js",
|
|
10
|
+
"mcp-cognitive-sync": "dist/cli/sync-ddd-docs.js",
|
|
11
|
+
"mcp-cognitive-audit": "dist/cli/audit.js",
|
|
12
|
+
"mcp-cognitive-verify": "dist/cli/verify.js",
|
|
13
|
+
"mcp-cognitive-stale": "dist/cli/stale.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist/",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"mcp",
|
|
28
|
+
"cognitive",
|
|
29
|
+
"knowledge-base",
|
|
30
|
+
"weaviate",
|
|
31
|
+
"sqlite",
|
|
32
|
+
"ai",
|
|
33
|
+
"hybrid-search"
|
|
34
|
+
],
|
|
35
|
+
"author": "Your Name",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/YOUR_USERNAME/mcp-cognitive"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@modelcontextprotocol/sdk": "1.27.0",
|
|
43
|
+
"sql.js": "1.12.0",
|
|
44
|
+
"weaviate-ts-client": "2.2.0",
|
|
45
|
+
"zod": "4.3.6"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "22.0.0",
|
|
49
|
+
"@types/sql.js": "1.4.9",
|
|
50
|
+
"tsx": "4.21.0",
|
|
51
|
+
"typescript": "5.8.2",
|
|
52
|
+
"vitest": "4.0.17"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=20.0.0"
|
|
56
|
+
}
|
|
57
|
+
}
|