@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
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AuditReport, Fact, FactInput, RecallQuery, RecallResult, VerifyResult } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* CognitiveStore — the core port interface for the cognitive database.
|
|
4
|
+
*
|
|
5
|
+
* This is the MOST IMPORTANT contract in the system. Both SqliteStore
|
|
6
|
+
* (Level 3) and future WeaviateStore (Level 4) implement this interface.
|
|
7
|
+
*
|
|
8
|
+
* Changing this file = changing the API for ALL adapters.
|
|
9
|
+
*/
|
|
10
|
+
export interface CognitiveStore {
|
|
11
|
+
/** Store a new fact. Generates id and timestamps automatically. */
|
|
12
|
+
store(input: FactInput): Promise<Fact>;
|
|
13
|
+
/** Update an existing fact by id. Only provided fields are changed. */
|
|
14
|
+
update(id: string, patch: Partial<FactInput>): Promise<Fact>;
|
|
15
|
+
/** Archive a fact (soft delete with reason). */
|
|
16
|
+
archive(id: string, reason: string): Promise<void>;
|
|
17
|
+
/** Recall facts matching a query. Updates recall metadata as side effect. */
|
|
18
|
+
recall(query: RecallQuery): Promise<RecallResult>;
|
|
19
|
+
/** Verify citations for a single fact. */
|
|
20
|
+
verify(factId: string): Promise<VerifyResult>;
|
|
21
|
+
/** Verify citations for ALL active facts. */
|
|
22
|
+
verifyAll(): Promise<VerifyResult[]>;
|
|
23
|
+
/** Generate a full health audit report. */
|
|
24
|
+
audit(): Promise<AuditReport>;
|
|
25
|
+
/** Check for facts that should be marked stale based on TTL rules. */
|
|
26
|
+
decayCheck(): Promise<Fact[]>;
|
|
27
|
+
/** Bulk import facts (for migration from Copilot Memory or other sources). */
|
|
28
|
+
migrate(facts: readonly FactInput[]): Promise<void>;
|
|
29
|
+
/** Export all facts (for migration to Weaviate or backup). */
|
|
30
|
+
exportAll(): Promise<Fact[]>;
|
|
31
|
+
/** Count total facts (all statuses). */
|
|
32
|
+
count(): Promise<number>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=cognitive-store.port.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognitive-store.port.d.ts","sourceRoot":"","sources":["../../src/ports/cognitive-store.port.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,IAAI,EACJ,SAAS,EACT,WAAW,EACX,YAAY,EACZ,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAG7B,mEAAmE;IACnE,KAAK,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvC,uEAAuE;IACvE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7D,gDAAgD;IAChD,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAInD,6EAA6E;IAC7E,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAIlD,0CAA0C;IAC1C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE9C,6CAA6C;IAC7C,SAAS,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAErC,2CAA2C;IAC3C,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;IAI9B,sEAAsE;IACtE,UAAU,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAE9B,8EAA8E;IAC9E,OAAO,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAIpD,8DAA8D;IAC9D,SAAS,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAE7B,wCAAwC;IACxC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognitive-store.port.js","sourceRoot":"","sources":["../../src/ports/cognitive-store.port.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Module } from '../types.js';
|
|
2
|
+
/** Agent-specific recall preferences for optimizing context relevance */
|
|
3
|
+
export interface AgentProfile {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly priorityTypes: readonly string[];
|
|
6
|
+
readonly boostTags: readonly string[];
|
|
7
|
+
readonly suppressTags: readonly string[];
|
|
8
|
+
readonly defaultModule?: Module;
|
|
9
|
+
readonly maxRecall: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get the agent profile for a given agent name.
|
|
13
|
+
* Falls back to 'default' if the agent is unknown.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAgentProfile(agentName?: string): AgentProfile;
|
|
16
|
+
/**
|
|
17
|
+
* Get all registered agent profiles.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getAllProfiles(): AgentProfile[];
|
|
20
|
+
//# sourceMappingURL=agent-profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-profiles.d.ts","sourceRoot":"","sources":["../../src/profiles/agent-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,yEAAyE;AACzE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AA6DD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,YAAY,CAGhE;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,YAAY,EAAE,CAE/C"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const AGENT_PROFILES = {
|
|
2
|
+
'implement-subagent': {
|
|
3
|
+
name: 'implement-subagent',
|
|
4
|
+
priorityTypes: ['invariant', 'policy', 'convention'],
|
|
5
|
+
boostTags: ['architecture', 'ports', 'cross-bc', 'dependency-rule', 'value-object'],
|
|
6
|
+
suppressTags: ['e2e-only', 'test-only'],
|
|
7
|
+
maxRecall: 7,
|
|
8
|
+
},
|
|
9
|
+
'test-E2E-subagent': {
|
|
10
|
+
name: 'test-E2E-subagent',
|
|
11
|
+
priorityTypes: ['convention', 'observation'],
|
|
12
|
+
boostTags: ['test', 'e2e', 'flaky', 'serial', 'uuid', 'playwright'],
|
|
13
|
+
suppressTags: ['architecture-only'],
|
|
14
|
+
maxRecall: 10,
|
|
15
|
+
},
|
|
16
|
+
'review-guard-subagent': {
|
|
17
|
+
name: 'review-guard-subagent',
|
|
18
|
+
priorityTypes: ['invariant', 'policy'],
|
|
19
|
+
boostTags: ['cross-bc', 'dependency-rule', 'domain-purity', 'architecture'],
|
|
20
|
+
suppressTags: ['ephemeral'],
|
|
21
|
+
maxRecall: 5,
|
|
22
|
+
},
|
|
23
|
+
'fixTypecheck-subagent': {
|
|
24
|
+
name: 'fixTypecheck-subagent',
|
|
25
|
+
priorityTypes: ['observation', 'convention'],
|
|
26
|
+
boostTags: ['typescript', 'type-error', 'enum', 'zod', 'prisma'],
|
|
27
|
+
suppressTags: ['e2e-only'],
|
|
28
|
+
maxRecall: 5,
|
|
29
|
+
},
|
|
30
|
+
'fixLinters-subagent': {
|
|
31
|
+
name: 'fixLinters-subagent',
|
|
32
|
+
priorityTypes: ['convention', 'observation'],
|
|
33
|
+
boostTags: ['eslint', 'lint', 'enum', 'i18n', 'import'],
|
|
34
|
+
suppressTags: ['e2e-only'],
|
|
35
|
+
maxRecall: 5,
|
|
36
|
+
},
|
|
37
|
+
'test-subagent': {
|
|
38
|
+
name: 'test-subagent',
|
|
39
|
+
priorityTypes: ['convention', 'observation', 'policy'],
|
|
40
|
+
boostTags: ['test', 'uuid', 'serial', 'mock', 'fixture'],
|
|
41
|
+
suppressTags: ['architecture-only'],
|
|
42
|
+
maxRecall: 7,
|
|
43
|
+
},
|
|
44
|
+
'planning-subagent': {
|
|
45
|
+
name: 'planning-subagent',
|
|
46
|
+
priorityTypes: ['invariant', 'policy', 'convention'],
|
|
47
|
+
boostTags: ['architecture', 'cross-bc', 'module', 'domain'],
|
|
48
|
+
suppressTags: ['ephemeral'],
|
|
49
|
+
maxRecall: 10,
|
|
50
|
+
},
|
|
51
|
+
'default': {
|
|
52
|
+
name: 'default',
|
|
53
|
+
priorityTypes: ['invariant', 'policy', 'convention', 'observation'],
|
|
54
|
+
boostTags: [],
|
|
55
|
+
suppressTags: ['ephemeral'],
|
|
56
|
+
maxRecall: 5,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Get the agent profile for a given agent name.
|
|
61
|
+
* Falls back to 'default' if the agent is unknown.
|
|
62
|
+
*/
|
|
63
|
+
export function getAgentProfile(agentName) {
|
|
64
|
+
if (!agentName)
|
|
65
|
+
return AGENT_PROFILES['default'];
|
|
66
|
+
return AGENT_PROFILES[agentName] ?? AGENT_PROFILES['default'];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get all registered agent profiles.
|
|
70
|
+
*/
|
|
71
|
+
export function getAllProfiles() {
|
|
72
|
+
return Object.values(AGENT_PROFILES);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=agent-profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-profiles.js","sourceRoot":"","sources":["../../src/profiles/agent-profiles.ts"],"names":[],"mappings":"AAYA,MAAM,cAAc,GAAiC;IACnD,oBAAoB,EAAE;QACpB,IAAI,EAAE,oBAAoB;QAC1B,aAAa,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAC;QACpD,SAAS,EAAE,CAAC,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,CAAC;QACnF,YAAY,EAAE,CAAC,UAAU,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D,YAAY,EAAE,CAAC,mBAAmB,CAAC;QACnC,SAAS,EAAE,CAAC;KACb;IACD,mBAAmB,EAAE;QACnB,IAAI,EAAE,mBAAmB;QACzB,aAAa,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,CAAC;QACpD,SAAS,EAAE,CAAC,cAAc,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC;QAC3D,YAAY,EAAE,CAAC,WAAW,CAAC;QAC3B,SAAS,EAAE,EAAE;KACd;IACD,SAAS,EAAE;QACT,IAAI,EAAE,SAAS;QACf,aAAa,EAAE,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,CAAC;QACnE,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,CAAC,WAAW,CAAC;QAC3B,SAAS,EAAE,CAAC;KACb;CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,SAAkB;IAChD,IAAI,CAAC,SAAS;QAAE,OAAO,cAAc,CAAC,SAAS,CAAE,CAAC;IAClD,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,cAAc,CAAC,SAAS,CAAE,CAAC;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":""}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { SqliteStore } from './adapters/sqlite.adapter.js';
|
|
5
|
+
import { WeaviateStore } from './adapters/weaviate.adapter.js';
|
|
6
|
+
import { auditInputSchema, auditToolDescription, auditToolName, executeAudit, } from './tools/audit.tool.js';
|
|
7
|
+
import { executeRecall, recallInputSchema, recallToolDescription, recallToolName, } from './tools/recall.tool.js';
|
|
8
|
+
import { executeStore, storeInputSchema, storeToolDescription, storeToolName, } from './tools/store.tool.js';
|
|
9
|
+
import { executeVerify, verifyInputSchema, verifyToolDescription, verifyToolName, } from './tools/verify.tool.js';
|
|
10
|
+
// ─── Configuration ──────────────────────────────────────────────────────────
|
|
11
|
+
const WORKSPACE_ROOT = process.env['WORKSPACE_ROOT'] ?? process.cwd();
|
|
12
|
+
const DB_PATH = process.env['COGNITIVE_DB_PATH'] ?? '.cognitive/facts.sqlite';
|
|
13
|
+
const resolvedDbPath = resolve(WORKSPACE_ROOT, DB_PATH);
|
|
14
|
+
// ─── Store initialization ────────────────────────────────────────────────────
|
|
15
|
+
async function createStore() {
|
|
16
|
+
const useWeaviate = process.env['USE_WEAVIATE'] === 'true';
|
|
17
|
+
const weaviateUrl = process.env['WEAVIATE_URL'] ?? 'localhost:8200';
|
|
18
|
+
if (useWeaviate) {
|
|
19
|
+
try {
|
|
20
|
+
return await WeaviateStore.create(weaviateUrl, WORKSPACE_ROOT);
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
24
|
+
console.warn(`WARN: Weaviate unavailable, falling back to SQLite: ${message}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return await SqliteStore.create(resolvedDbPath, WORKSPACE_ROOT);
|
|
28
|
+
}
|
|
29
|
+
// ─── MCP Server ──────────────────────────────────────────────────────────────
|
|
30
|
+
async function main() {
|
|
31
|
+
const store = await createStore();
|
|
32
|
+
const server = new McpServer({
|
|
33
|
+
name: 'cognitive-db',
|
|
34
|
+
version: '0.1.0',
|
|
35
|
+
});
|
|
36
|
+
// Register tools
|
|
37
|
+
server.tool(recallToolName, recallToolDescription, recallInputSchema.shape, async (input) => ({
|
|
38
|
+
content: [{ type: 'text', text: await executeRecall(store, input) }],
|
|
39
|
+
}));
|
|
40
|
+
server.tool(storeToolName, storeToolDescription, storeInputSchema.shape, async (input) => ({
|
|
41
|
+
content: [{ type: 'text', text: await executeStore(store, input) }],
|
|
42
|
+
}));
|
|
43
|
+
server.tool(verifyToolName, verifyToolDescription, verifyInputSchema.shape, async (input) => ({
|
|
44
|
+
content: [{ type: 'text', text: await executeVerify(store, input) }],
|
|
45
|
+
}));
|
|
46
|
+
server.tool(auditToolName, auditToolDescription, auditInputSchema.shape, async (input) => ({
|
|
47
|
+
content: [{ type: 'text', text: await executeAudit(store, input) }],
|
|
48
|
+
}));
|
|
49
|
+
// Start server with stdio transport
|
|
50
|
+
const transport = new StdioServerTransport();
|
|
51
|
+
await server.connect(transport);
|
|
52
|
+
// Stderr for logging (stdout is reserved for MCP protocol)
|
|
53
|
+
console.error(`[cognitive-db] MCP server started (db: ${resolvedDbPath})`);
|
|
54
|
+
}
|
|
55
|
+
main().catch((err) => {
|
|
56
|
+
console.error('[cognitive-db] Fatal error:', err);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG/D,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,YAAY,GACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,GACf,MA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E,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,2DAA2D;IAC3D,OAAO,CAAC,KAAK,CAAC,0CAA0C,cAAc,GAAG,CAAC,CAAC;AAC7E,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;IAClD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CognitiveStore } from '../ports/cognitive-store.port.js';
|
|
3
|
+
export declare const auditToolName = "cognitive_audit";
|
|
4
|
+
export declare const auditToolDescription: string;
|
|
5
|
+
export declare const auditInputSchema: z.ZodObject<{}, z.core.$strip>;
|
|
6
|
+
export type AuditInput = z.infer<typeof auditInputSchema>;
|
|
7
|
+
export declare function executeAudit(store: CognitiveStore, _input: AuditInput): Promise<string>;
|
|
8
|
+
//# sourceMappingURL=audit.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.tool.d.ts","sourceRoot":"","sources":["../../src/tools/audit.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAE/C,eAAO,MAAM,oBAAoB,QAEoD,CAAC;AAEtF,eAAO,MAAM,gBAAgB,gCAAe,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,wBAAsB,YAAY,CAChC,KAAK,EAAE,cAAc,EACrB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,MAAM,CAAC,CAqDjB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const auditToolName = 'cognitive_audit';
|
|
3
|
+
export const auditToolDescription = 'Generate a health audit report for the cognitive knowledge base. ' +
|
|
4
|
+
'Shows fact distribution, stale facts, broken citations, and duplicate candidates.';
|
|
5
|
+
export const auditInputSchema = z.object({});
|
|
6
|
+
export async function executeAudit(store, _input) {
|
|
7
|
+
const report = await store.audit();
|
|
8
|
+
const lines = [
|
|
9
|
+
'═══ Cognitive Database Audit Report ═══',
|
|
10
|
+
`Generated: ${report.generatedAt}`,
|
|
11
|
+
'',
|
|
12
|
+
`Total facts: ${report.totalFacts}`,
|
|
13
|
+
'',
|
|
14
|
+
'── By Status ──',
|
|
15
|
+
` Active: ${report.byStatus.active}`,
|
|
16
|
+
` Stale: ${report.byStatus.stale}`,
|
|
17
|
+
` Archived: ${report.byStatus.archived}`,
|
|
18
|
+
'',
|
|
19
|
+
'── By Type ──',
|
|
20
|
+
` Invariant: ${report.byType.invariant}`,
|
|
21
|
+
` Policy: ${report.byType.policy}`,
|
|
22
|
+
` Convention: ${report.byType.convention}`,
|
|
23
|
+
` Observation: ${report.byType.observation}`,
|
|
24
|
+
` Ephemeral: ${report.byType.ephemeral}`,
|
|
25
|
+
'',
|
|
26
|
+
'── By Module ──',
|
|
27
|
+
];
|
|
28
|
+
for (const [mod, count] of Object.entries(report.byModule)) {
|
|
29
|
+
lines.push(` ${mod}: ${count}`);
|
|
30
|
+
}
|
|
31
|
+
if (report.staleFacts.length > 0) {
|
|
32
|
+
lines.push('', `── Stale Facts (${report.staleFacts.length}) ──`);
|
|
33
|
+
for (const fact of report.staleFacts) {
|
|
34
|
+
lines.push(` ⚠ [${fact.type}] ${fact.fact.substring(0, 80)}...`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (report.brokenCitations.length > 0) {
|
|
38
|
+
lines.push('', `── Broken Citations (${report.brokenCitations.length}) ──`);
|
|
39
|
+
for (const v of report.brokenCitations) {
|
|
40
|
+
lines.push(` ✗ ${v.factId}: "${v.factSnippet}..."`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (report.duplicateCandidates.length > 0) {
|
|
44
|
+
lines.push('', `── Duplicate Candidates (${report.duplicateCandidates.length}) ──`);
|
|
45
|
+
for (const d of report.duplicateCandidates) {
|
|
46
|
+
lines.push(` ~ ${d.a} ↔ ${d.b} (${d.similarity} overlap)`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const healthScore = calculateHealthScore(report);
|
|
50
|
+
lines.push('', `── Health Score: ${healthScore}/100 ──`);
|
|
51
|
+
return lines.join('\n');
|
|
52
|
+
}
|
|
53
|
+
function calculateHealthScore(report) {
|
|
54
|
+
if (report.totalFacts === 0)
|
|
55
|
+
return 100;
|
|
56
|
+
let score = 100;
|
|
57
|
+
// Penalize stale facts (max -30)
|
|
58
|
+
const staleRatio = report.byStatus.stale / report.totalFacts;
|
|
59
|
+
score -= Math.min(30, Math.round(staleRatio * 100));
|
|
60
|
+
// Penalize broken citations (max -40)
|
|
61
|
+
const brokenRatio = report.brokenCitations.length / report.totalFacts;
|
|
62
|
+
score -= Math.min(40, Math.round(brokenRatio * 200));
|
|
63
|
+
// Penalize duplicates (max -20)
|
|
64
|
+
const dupRatio = report.duplicateCandidates.length / report.totalFacts;
|
|
65
|
+
score -= Math.min(20, Math.round(dupRatio * 100));
|
|
66
|
+
// Bonus for having enough facts (+10)
|
|
67
|
+
if (report.byStatus.active >= 50)
|
|
68
|
+
score = Math.min(100, score + 10);
|
|
69
|
+
return Math.max(0, score);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=audit.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.tool.js","sourceRoot":"","sources":["../../src/tools/audit.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAA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,IAAI,MAAM,CAAC,UAAU,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAExC,IAAI,KAAK,GAAG,GAAG,CAAC;IAEhB,iCAAiC;IACjC,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC;IAC7D,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC;IAEpD,sCAAsC;IACtC,MAAM,WAAW,GAAG,MAAM,CAAC,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;IACtE,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,CAAC,CAAC;IAErD,gCAAgC;IAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC;IACvE,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC;IAElD,sCAAsC;IACtC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE;QAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,CAAC;IAEpE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CognitiveStore } from '../ports/cognitive-store.port.js';
|
|
3
|
+
export declare const recallToolName = "cognitive_recall";
|
|
4
|
+
export declare const recallToolDescription: string;
|
|
5
|
+
export declare const recallInputSchema: z.ZodObject<{
|
|
6
|
+
query: z.ZodString;
|
|
7
|
+
agent: z.ZodOptional<z.ZodString>;
|
|
8
|
+
module: z.ZodOptional<z.ZodEnum<{
|
|
9
|
+
identity: "identity";
|
|
10
|
+
organization: "organization";
|
|
11
|
+
platform: "platform";
|
|
12
|
+
infrastructure: "infrastructure";
|
|
13
|
+
tooling: "tooling";
|
|
14
|
+
testing: "testing";
|
|
15
|
+
general: "general";
|
|
16
|
+
}>>;
|
|
17
|
+
types: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
18
|
+
invariant: "invariant";
|
|
19
|
+
policy: "policy";
|
|
20
|
+
convention: "convention";
|
|
21
|
+
observation: "observation";
|
|
22
|
+
ephemeral: "ephemeral";
|
|
23
|
+
}>>>;
|
|
24
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
minConfidence: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
26
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
export type RecallInput = z.infer<typeof recallInputSchema>;
|
|
29
|
+
export declare function executeRecall(store: CognitiveStore, input: RecallInput): Promise<string>;
|
|
30
|
+
//# sourceMappingURL=recall.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.tool.d.ts","sourceRoot":"","sources":["../../src/tools/recall.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAIvE,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD,eAAO,MAAM,qBAAqB,QAEiE,CAAC;AAEpG,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;iBAQ5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,wBAAsB,aAAa,CACjC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getAgentProfile } from '../profiles/agent-profiles.js';
|
|
3
|
+
export const recallToolName = 'cognitive_recall';
|
|
4
|
+
export const recallToolDescription = 'Search the cognitive knowledge base for relevant facts. ' +
|
|
5
|
+
'Returns facts matching a keyword query, optionally filtered by module, type, and agent profile.';
|
|
6
|
+
export const recallInputSchema = z.object({
|
|
7
|
+
query: z.string().min(2).describe('Keywords to search for in facts and tags (e.g. "cross-bc isolation", "password reset serial")'),
|
|
8
|
+
agent: z.string().optional().describe('Agent name for profile-based filtering (e.g. "implement-subagent", "test-E2E-subagent")'),
|
|
9
|
+
module: z.enum(['identity', 'organization', 'platform', 'infrastructure', 'tooling', 'testing', 'general']).optional().describe('Filter by bounded context or area'),
|
|
10
|
+
types: z.array(z.enum(['invariant', 'policy', 'convention', 'observation', 'ephemeral'])).optional().describe('Filter by fact types'),
|
|
11
|
+
tags: z.array(z.string()).max(5).optional().describe('Filter by tags (all must match)'),
|
|
12
|
+
minConfidence: z.number().min(0).max(1).optional().default(0).describe('Minimum confidence threshold (0-1)'),
|
|
13
|
+
limit: z.number().min(1).max(50).optional().default(10).describe('Maximum number of results'),
|
|
14
|
+
});
|
|
15
|
+
export async function executeRecall(store, input) {
|
|
16
|
+
const profile = getAgentProfile(input.agent);
|
|
17
|
+
const query = {
|
|
18
|
+
query: input.query,
|
|
19
|
+
...(input.agent !== undefined ? { agent: input.agent } : {}),
|
|
20
|
+
...(input.module !== undefined ? { module: input.module } : {}),
|
|
21
|
+
types: input.types ?? profile.priorityTypes,
|
|
22
|
+
...(input.tags !== undefined ? { tags: input.tags } : {}),
|
|
23
|
+
...(input.minConfidence !== undefined ? { minConfidence: input.minConfidence } : {}),
|
|
24
|
+
limit: input.limit ?? profile.maxRecall,
|
|
25
|
+
};
|
|
26
|
+
const result = await store.recall(query);
|
|
27
|
+
if (result.facts.length === 0) {
|
|
28
|
+
return `No facts found for query: "${input.query}"`;
|
|
29
|
+
}
|
|
30
|
+
const lines = [
|
|
31
|
+
`Found ${result.totalMatches} facts (showing ${result.facts.length}, ${result.queryTimeMs}ms):`,
|
|
32
|
+
'',
|
|
33
|
+
];
|
|
34
|
+
for (const fact of result.facts) {
|
|
35
|
+
const tags = fact.tags.length > 0 ? ` [${fact.tags.join(', ')}]` : '';
|
|
36
|
+
const citations = fact.citations.length > 0
|
|
37
|
+
? `\n Citations: ${fact.citations.map((c) => c.line ? `${c.file}:L${c.line}` : c.file).join(', ')}`
|
|
38
|
+
: '';
|
|
39
|
+
lines.push(`• [${fact.type}/${fact.module}] (${Math.round(fact.confidence * 100)}%) ${fact.fact}${tags}${citations}`);
|
|
40
|
+
}
|
|
41
|
+
return lines.join('\n');
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=recall.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recall.tool.js","sourceRoot":"","sources":["../../src/tools/recall.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,qBAAqB,GAChC,0DAA0D;IAC1D,iGAAiG,CAAC;AAEpG,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,+FAA+F,CAAC;IAClI,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,yFAAyF,CAAC;IAChI,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,E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,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtG,CAAC,CAAC,EAAE,CAAC;QACP,KAAK,CAAC,IAAI,CACR,MAAM,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,CAC1G,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CognitiveStore } from '../ports/cognitive-store.port.js';
|
|
3
|
+
export declare const storeToolName = "cognitive_store";
|
|
4
|
+
export declare const storeToolDescription: string;
|
|
5
|
+
export declare const storeInputSchema: z.ZodObject<{
|
|
6
|
+
fact: z.ZodString;
|
|
7
|
+
type: z.ZodEnum<{
|
|
8
|
+
invariant: "invariant";
|
|
9
|
+
policy: "policy";
|
|
10
|
+
convention: "convention";
|
|
11
|
+
observation: "observation";
|
|
12
|
+
ephemeral: "ephemeral";
|
|
13
|
+
}>;
|
|
14
|
+
module: z.ZodEnum<{
|
|
15
|
+
identity: "identity";
|
|
16
|
+
organization: "organization";
|
|
17
|
+
platform: "platform";
|
|
18
|
+
infrastructure: "infrastructure";
|
|
19
|
+
tooling: "tooling";
|
|
20
|
+
testing: "testing";
|
|
21
|
+
general: "general";
|
|
22
|
+
}>;
|
|
23
|
+
confidence: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
24
|
+
citations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
25
|
+
file: z.ZodString;
|
|
26
|
+
line: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
context: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strip>>>;
|
|
29
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
30
|
+
supersedes: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
export type StoreInput = z.infer<typeof storeInputSchema>;
|
|
33
|
+
export declare function executeStore(store: CognitiveStore, input: StoreInput): Promise<string>;
|
|
34
|
+
//# sourceMappingURL=store.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.tool.d.ts","sourceRoot":"","sources":["../../src/tools/store.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAGvE,eAAO,MAAM,aAAa,oBAAoB,CAAC;AAE/C,eAAO,MAAM,oBAAoB,QAGsB,CAAC;AAExD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;iBAe3B,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,wBAAsB,YAAY,CAChC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,UAAU,GAChB,OAAO,CAAC,MAAM,CAAC,CAgCjB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const storeToolName = 'cognitive_store';
|
|
3
|
+
export const storeToolDescription = 'Store a new fact in the cognitive knowledge base. ' +
|
|
4
|
+
'Facts should be actionable, verifiable, and scoped. ' +
|
|
5
|
+
'Include citations (file:line) and appropriate tags.';
|
|
6
|
+
export const storeInputSchema = z.object({
|
|
7
|
+
fact: z.string().min(10).max(500).describe('The fact text — must be actionable and verifiable (e.g. "oRPC 500 with OK use case = missing return in router handler")'),
|
|
8
|
+
type: z.enum(['invariant', 'policy', 'convention', 'observation', 'ephemeral'])
|
|
9
|
+
.describe('Fact classification: invariant (permanent arch rule), policy (until business decision change), convention (6mo audit), observation (30d re-verify), ephemeral (7d auto-expire)'),
|
|
10
|
+
module: z.enum(['identity', 'organization', 'platform', 'infrastructure', 'tooling', 'testing', 'general'])
|
|
11
|
+
.describe('Which bounded context or area this fact belongs to'),
|
|
12
|
+
confidence: z.number().min(0).max(1).optional().default(0.8)
|
|
13
|
+
.describe('Confidence level 0.0-1.0. Use 1.0 for invariants, 0.9-0.95 for verified conventions, 0.7-0.8 for observations'),
|
|
14
|
+
citations: z.array(z.object({
|
|
15
|
+
file: z.string().min(1).describe('Relative file path from workspace root (e.g. "apps/web/lib/modules/identity/domain/user.ts")'),
|
|
16
|
+
line: z.number().min(1).optional().describe('Line number (1-based)'),
|
|
17
|
+
context: z.string().max(200).optional().describe('What this citation proves'),
|
|
18
|
+
})).min(1).optional().describe('File:line citations that support this fact — at least 1 recommended'),
|
|
19
|
+
tags: z.array(z.string().min(1).max(30)).max(10).optional().describe('Searchable tags for categorization (e.g. ["architecture", "cross-bc", "ddd"])'),
|
|
20
|
+
supersedes: z.string().optional().describe('UUID of fact this replaces — old fact will be archived'),
|
|
21
|
+
});
|
|
22
|
+
export async function executeStore(store, input) {
|
|
23
|
+
const factInput = {
|
|
24
|
+
fact: input.fact,
|
|
25
|
+
type: input.type,
|
|
26
|
+
module: input.module,
|
|
27
|
+
...(input.confidence !== undefined ? { confidence: input.confidence } : {}),
|
|
28
|
+
...(input.citations !== undefined ? { citations: input.citations } : {}),
|
|
29
|
+
...(input.tags !== undefined ? { tags: input.tags } : {}),
|
|
30
|
+
...(input.supersedes !== undefined ? { supersedes: input.supersedes } : {}),
|
|
31
|
+
};
|
|
32
|
+
const stored = await store.store(factInput);
|
|
33
|
+
const lines = [
|
|
34
|
+
`✓ Fact stored successfully:`,
|
|
35
|
+
` ID: ${stored.id}`,
|
|
36
|
+
` Type: ${stored.type}`,
|
|
37
|
+
` Module: ${stored.module}`,
|
|
38
|
+
` Confidence: ${Math.round(stored.confidence * 100)}%`,
|
|
39
|
+
];
|
|
40
|
+
if (stored.tags.length > 0) {
|
|
41
|
+
lines.push(` Tags: ${stored.tags.join(', ')}`);
|
|
42
|
+
}
|
|
43
|
+
if (stored.citations.length > 0) {
|
|
44
|
+
lines.push(` Citations: ${stored.citations.length}`);
|
|
45
|
+
}
|
|
46
|
+
if (stored.supersedes) {
|
|
47
|
+
lines.push(` Supersedes: ${stored.supersedes} (old fact archived)`);
|
|
48
|
+
}
|
|
49
|
+
return lines.join('\n');
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=store.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.tool.js","sourceRoot":"","sources":["../../src/tools/store.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE/C,MAAM,CAAC,MAAM,oBAAoB,GAC/B,oDAAoD;IACpD,sDAAsD;IACtD,qDAAqD,CAAC;AAExD,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,yHAAyH,CAAC;IACrK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;SAC5E,QAAQ,CAAC,gLAAgL,CAAC;IAC7L,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,SAAS,EAAE,S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MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC,iBAAiB,MAAM,CAAC,UAAU,sBAAsB,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { CognitiveStore } from '../ports/cognitive-store.port.js';
|
|
3
|
+
export declare const verifyToolName = "cognitive_verify";
|
|
4
|
+
export declare const verifyToolDescription: string;
|
|
5
|
+
export declare const verifyInputSchema: z.ZodObject<{
|
|
6
|
+
factId: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type VerifyInput = z.infer<typeof verifyInputSchema>;
|
|
9
|
+
export declare function executeVerify(store: CognitiveStore, input: VerifyInput): Promise<string>;
|
|
10
|
+
//# sourceMappingURL=verify.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.tool.d.ts","sourceRoot":"","sources":["../../src/tools/verify.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAEvE,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD,eAAO,MAAM,qBAAqB,QAGkC,CAAC;AAErE,eAAO,MAAM,iBAAiB;;iBAG5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,wBAAsB,aAAa,CACjC,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,WAAW,GACjB,OAAO,CAAC,MAAM,CAAC,CAuDjB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const verifyToolName = 'cognitive_verify';
|
|
3
|
+
export const verifyToolDescription = 'Verify citation integrity for facts in the cognitive knowledge base. ' +
|
|
4
|
+
'Checks if referenced files and lines still exist and are valid. ' +
|
|
5
|
+
'Call with a factId to verify one fact, or without to verify all.';
|
|
6
|
+
export const verifyInputSchema = z.object({
|
|
7
|
+
factId: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).optional()
|
|
8
|
+
.describe('UUID of specific fact to verify. Omit to verify all active facts with citations.'),
|
|
9
|
+
});
|
|
10
|
+
export async function executeVerify(store, input) {
|
|
11
|
+
if (input.factId) {
|
|
12
|
+
const result = await store.verify(input.factId);
|
|
13
|
+
if (result.citations.length === 0) {
|
|
14
|
+
return `Fact ${result.factId}: No citations to verify.\n"${result.factSnippet}..."`;
|
|
15
|
+
}
|
|
16
|
+
const lines = [
|
|
17
|
+
`Fact ${result.factId}: ${result.overallStatus.toUpperCase()}`,
|
|
18
|
+
`"${result.factSnippet}..."`,
|
|
19
|
+
'',
|
|
20
|
+
];
|
|
21
|
+
for (const c of result.citations) {
|
|
22
|
+
const loc = c.citation.line ? `${c.citation.file}:L${c.citation.line}` : c.citation.file;
|
|
23
|
+
lines.push(` ${c.status === 'valid' ? '✓' : c.status === 'stale' ? '⚠' : '✗'} ${loc} → ${c.status}${c.detail ? ` (${c.detail})` : ''}`);
|
|
24
|
+
}
|
|
25
|
+
return lines.join('\n');
|
|
26
|
+
}
|
|
27
|
+
// Verify all
|
|
28
|
+
const results = await store.verifyAll();
|
|
29
|
+
if (results.length === 0) {
|
|
30
|
+
return 'No active facts with citations to verify.';
|
|
31
|
+
}
|
|
32
|
+
const valid = results.filter((r) => r.overallStatus === 'valid').length;
|
|
33
|
+
const stale = results.filter((r) => r.overallStatus === 'stale').length;
|
|
34
|
+
const broken = results.filter((r) => r.overallStatus === 'broken').length;
|
|
35
|
+
const lines = [
|
|
36
|
+
`Citation Verification Report:`,
|
|
37
|
+
` ✓ Valid: ${valid}`,
|
|
38
|
+
` ⚠ Stale: ${stale}`,
|
|
39
|
+
` ✗ Broken: ${broken}`,
|
|
40
|
+
` Total checked: ${results.length}`,
|
|
41
|
+
];
|
|
42
|
+
// Show details for broken/stale only
|
|
43
|
+
const problems = results.filter((r) => r.overallStatus !== 'valid');
|
|
44
|
+
if (problems.length > 0) {
|
|
45
|
+
lines.push('', 'Problems:');
|
|
46
|
+
for (const result of problems) {
|
|
47
|
+
lines.push(` [${result.overallStatus}] ${result.factId}: "${result.factSnippet}..."`);
|
|
48
|
+
for (const c of result.citations.filter((ci) => ci.status !== 'valid')) {
|
|
49
|
+
const loc = c.citation.line ? `${c.citation.file}:L${c.citation.line}` : c.citation.file;
|
|
50
|
+
lines.push(` ${c.status === 'stale' ? '⚠' : '✗'} ${loc}: ${c.detail ?? c.status}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return lines.join('\n');
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=verify.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.tool.js","sourceRoot":"","sources":["../../src/tools/verify.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,qBAAqB,GAChC,uEAAuE;IACvE,kEAAkE;IAClE,kEAAkE,CAAC;AAErE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,iEAAiE,CAAC,CAAC,QAAQ,EAAE;SACnG,QAAQ,CAAC,kFAAkF,CAAC;CAChG,CAAC,CAAC;AAIH,MAAM,CAAC,KAAK,UAAU,aAAa,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