mcp-cognition-engine 1.0.0-alpha.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 +201 -0
- package/README.md +281 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +66 -0
- package/dist/cli.js.map +1 -0
- package/dist/cognition-engine/ast-constraint-solver.d.ts +67 -0
- package/dist/cognition-engine/ast-constraint-solver.d.ts.map +1 -0
- package/dist/cognition-engine/ast-constraint-solver.js +294 -0
- package/dist/cognition-engine/ast-constraint-solver.js.map +1 -0
- package/dist/cognition-engine/constraint-validator.d.ts +35 -0
- package/dist/cognition-engine/constraint-validator.d.ts.map +1 -0
- package/dist/cognition-engine/constraint-validator.js +55 -0
- package/dist/cognition-engine/constraint-validator.js.map +1 -0
- package/dist/cognition-engine/graph-traverser.d.ts +43 -0
- package/dist/cognition-engine/graph-traverser.d.ts.map +1 -0
- package/dist/cognition-engine/graph-traverser.js +205 -0
- package/dist/cognition-engine/graph-traverser.js.map +1 -0
- package/dist/cognition-engine/index.d.ts +51 -0
- package/dist/cognition-engine/index.d.ts.map +1 -0
- package/dist/cognition-engine/index.js +60 -0
- package/dist/cognition-engine/index.js.map +1 -0
- package/dist/cognition-engine/intent-recognizer.d.ts +25 -0
- package/dist/cognition-engine/intent-recognizer.d.ts.map +1 -0
- package/dist/cognition-engine/intent-recognizer.js +226 -0
- package/dist/cognition-engine/intent-recognizer.js.map +1 -0
- package/dist/cognition-engine/types.d.ts +96 -0
- package/dist/cognition-engine/types.d.ts.map +1 -0
- package/dist/cognition-engine/types.js +17 -0
- package/dist/cognition-engine/types.js.map +1 -0
- package/dist/conflict/arbitrator.d.ts +24 -0
- package/dist/conflict/arbitrator.d.ts.map +1 -0
- package/dist/conflict/arbitrator.js +43 -0
- package/dist/conflict/arbitrator.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +90 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy-engine/ast-diff.d.ts +23 -0
- package/dist/legacy-engine/ast-diff.d.ts.map +1 -0
- package/dist/legacy-engine/ast-diff.js +146 -0
- package/dist/legacy-engine/ast-diff.js.map +1 -0
- package/dist/legacy-engine/ast-node.d.ts +24 -0
- package/dist/legacy-engine/ast-node.d.ts.map +1 -0
- package/dist/legacy-engine/ast-node.js +52 -0
- package/dist/legacy-engine/ast-node.js.map +1 -0
- package/dist/legacy-engine/parsers.d.ts +34 -0
- package/dist/legacy-engine/parsers.d.ts.map +1 -0
- package/dist/legacy-engine/parsers.js +134 -0
- package/dist/legacy-engine/parsers.js.map +1 -0
- package/dist/legacy-engine/regex-fallback.d.ts +23 -0
- package/dist/legacy-engine/regex-fallback.d.ts.map +1 -0
- package/dist/legacy-engine/regex-fallback.js +40 -0
- package/dist/legacy-engine/regex-fallback.js.map +1 -0
- package/dist/legacy-engine/rule-generator.d.ts +31 -0
- package/dist/legacy-engine/rule-generator.d.ts.map +1 -0
- package/dist/legacy-engine/rule-generator.js +54 -0
- package/dist/legacy-engine/rule-generator.js.map +1 -0
- package/dist/legacy-engine/rule-matcher.d.ts +28 -0
- package/dist/legacy-engine/rule-matcher.d.ts.map +1 -0
- package/dist/legacy-engine/rule-matcher.js +79 -0
- package/dist/legacy-engine/rule-matcher.js.map +1 -0
- package/dist/legacy-engine/token-controller.d.ts +31 -0
- package/dist/legacy-engine/token-controller.d.ts.map +1 -0
- package/dist/legacy-engine/token-controller.js +66 -0
- package/dist/legacy-engine/token-controller.js.map +1 -0
- package/dist/middleware/response-validation.d.ts +27 -0
- package/dist/middleware/response-validation.d.ts.map +1 -0
- package/dist/middleware/response-validation.js +50 -0
- package/dist/middleware/response-validation.js.map +1 -0
- package/dist/modes/confirm.d.ts +29 -0
- package/dist/modes/confirm.d.ts.map +1 -0
- package/dist/modes/confirm.js +27 -0
- package/dist/modes/confirm.js.map +1 -0
- package/dist/modes/silent.d.ts +24 -0
- package/dist/modes/silent.d.ts.map +1 -0
- package/dist/modes/silent.js +24 -0
- package/dist/modes/silent.js.map +1 -0
- package/dist/resources/cognition-resources.d.ts +28 -0
- package/dist/resources/cognition-resources.d.ts.map +1 -0
- package/dist/resources/cognition-resources.js +124 -0
- package/dist/resources/cognition-resources.js.map +1 -0
- package/dist/storage/client.d.ts +26 -0
- package/dist/storage/client.d.ts.map +1 -0
- package/dist/storage/client.js +45 -0
- package/dist/storage/client.js.map +1 -0
- package/dist/storage/cognition-repository.d.ts +55 -0
- package/dist/storage/cognition-repository.d.ts.map +1 -0
- package/dist/storage/cognition-repository.js +287 -0
- package/dist/storage/cognition-repository.js.map +1 -0
- package/dist/storage/cognition-types.d.ts +96 -0
- package/dist/storage/cognition-types.d.ts.map +1 -0
- package/dist/storage/cognition-types.js +41 -0
- package/dist/storage/cognition-types.js.map +1 -0
- package/dist/storage/conflict-repo.d.ts +41 -0
- package/dist/storage/conflict-repo.d.ts.map +1 -0
- package/dist/storage/conflict-repo.js +67 -0
- package/dist/storage/conflict-repo.js.map +1 -0
- package/dist/storage/diff-log-repo.d.ts +48 -0
- package/dist/storage/diff-log-repo.d.ts.map +1 -0
- package/dist/storage/diff-log-repo.js +51 -0
- package/dist/storage/diff-log-repo.js.map +1 -0
- package/dist/storage/metric-repo.d.ts +20 -0
- package/dist/storage/metric-repo.d.ts.map +1 -0
- package/dist/storage/metric-repo.js +36 -0
- package/dist/storage/metric-repo.js.map +1 -0
- package/dist/storage/rule-repo.d.ts +66 -0
- package/dist/storage/rule-repo.d.ts.map +1 -0
- package/dist/storage/rule-repo.js +188 -0
- package/dist/storage/rule-repo.js.map +1 -0
- package/dist/tools/analyze-workspace.d.ts +26 -0
- package/dist/tools/analyze-workspace.d.ts.map +1 -0
- package/dist/tools/analyze-workspace.js +147 -0
- package/dist/tools/analyze-workspace.js.map +1 -0
- package/dist/tools/capture-diff.d.ts +26 -0
- package/dist/tools/capture-diff.d.ts.map +1 -0
- package/dist/tools/capture-diff.js +58 -0
- package/dist/tools/capture-diff.js.map +1 -0
- package/dist/tools/cognition-tools.d.ts +60 -0
- package/dist/tools/cognition-tools.d.ts.map +1 -0
- package/dist/tools/cognition-tools.js +170 -0
- package/dist/tools/cognition-tools.js.map +1 -0
- package/dist/tools/config-tools.d.ts +29 -0
- package/dist/tools/config-tools.d.ts.map +1 -0
- package/dist/tools/config-tools.js +58 -0
- package/dist/tools/config-tools.js.map +1 -0
- package/dist/tools/confirm-rule.d.ts +32 -0
- package/dist/tools/confirm-rule.d.ts.map +1 -0
- package/dist/tools/confirm-rule.js +64 -0
- package/dist/tools/confirm-rule.js.map +1 -0
- package/dist/tools/injection-approval.d.ts +43 -0
- package/dist/tools/injection-approval.d.ts.map +1 -0
- package/dist/tools/injection-approval.js +102 -0
- package/dist/tools/injection-approval.js.map +1 -0
- package/dist/tools/list-rules.d.ts +24 -0
- package/dist/tools/list-rules.d.ts.map +1 -0
- package/dist/tools/list-rules.js +20 -0
- package/dist/tools/list-rules.js.map +1 -0
- package/dist/tools/query-rules.d.ts +25 -0
- package/dist/tools/query-rules.d.ts.map +1 -0
- package/dist/tools/query-rules.js +65 -0
- package/dist/tools/query-rules.js.map +1 -0
- package/dist/tools/resolve-conflict.d.ts +33 -0
- package/dist/tools/resolve-conflict.d.ts.map +1 -0
- package/dist/tools/resolve-conflict.js +35 -0
- package/dist/tools/resolve-conflict.js.map +1 -0
- package/dist/types.d.ts +190 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +50 -0
- package/dist/types.js.map +1 -0
- package/docs/api-reference.md +1229 -0
- package/docs/community/feedback-playbook.md +94 -0
- package/docs/integration-snippets.md +100 -0
- package/docs/mcp-integration-guide.md +151 -0
- package/docs/phase4-mcp-feedback.md +155 -0
- package/docs/trust-governance-protocol.md +72 -0
- package/package.json +74 -0
- package/prisma/schema.prisma +145 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 熊高锐
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* @file Cognition Engine MCP Resources
|
|
18
|
+
* Exposes three resources for Agent discovery:
|
|
19
|
+
* cognition://schema — Graph data model JSON Schema
|
|
20
|
+
* cognition://stats — Graph statistics (node/edge counts)
|
|
21
|
+
* cognition://docs — Integration documentation
|
|
22
|
+
*/
|
|
23
|
+
import { readFileSync } from "node:fs";
|
|
24
|
+
import { join, dirname } from "node:path";
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
26
|
+
import { getPrismaClient } from "../storage/client.js";
|
|
27
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
28
|
+
const projectRoot = join(__dirname, "../..");
|
|
29
|
+
// ── Resource Definitions ───────────────────────────────────
|
|
30
|
+
export const RESOURCES = [
|
|
31
|
+
{
|
|
32
|
+
uri: "cognition://schema",
|
|
33
|
+
name: "Cognition Graph Schema",
|
|
34
|
+
description: "JSON Schema of the cognition graph data model, including CognitionNode, CognitionEdge, and AstTemplate tables and their relationships.",
|
|
35
|
+
mimeType: "application/json",
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
uri: "cognition://stats",
|
|
39
|
+
name: "Cognition Engine Statistics",
|
|
40
|
+
description: "Current graph statistics: node count, edge count, feedback event count, and average traversal latency. Useful for health checks and capacity planning.",
|
|
41
|
+
mimeType: "application/json",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
uri: "cognition://docs",
|
|
45
|
+
name: "Cognition Engine Documentation",
|
|
46
|
+
description: "Full MCP tool documentation from docs/phase4-mcp-feedback.md. Agents can read this to learn how to use cognition_query, cognition_validate, and cognition_feedback.",
|
|
47
|
+
mimeType: "text/markdown",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
uri: "cognition://rules-changelog",
|
|
51
|
+
name: "Rules Changelog",
|
|
52
|
+
description: "Versioned changelog of global rule changes. Returns version = SHA-256 prefix of updated_at field. Agents must read this before making rule modifications.",
|
|
53
|
+
mimeType: "application/json",
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
// ── Resource Readers ──────────────────────────────────────
|
|
57
|
+
/** Return the JSON schema for the cognition graph data model. */
|
|
58
|
+
export async function readCognitionSchema() {
|
|
59
|
+
const schema = {
|
|
60
|
+
"": "http://json-schema.org/draft-07/schema#",
|
|
61
|
+
title: "CognitionGraph",
|
|
62
|
+
description: "Schema for the cognition graph data model",
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
CognitionNode: {
|
|
66
|
+
type: "object",
|
|
67
|
+
properties: {
|
|
68
|
+
id: { type: "string", description: "Unique node identifier (CUID)" },
|
|
69
|
+
type: { type: "string", enum: ["INTENT", "CONSTRAINT", "HEURISTIC", "PATTERN"], description: "Node type" },
|
|
70
|
+
semanticHash: { type: "string", description: "Semantic deduplication hash" },
|
|
71
|
+
abstractionLevel: { type: "integer", minimum: 0, maximum: 3, description: "0=code, 1=function, 2=module, 3=architecture" },
|
|
72
|
+
payload: { type: "object", description: "Structured AST/constraint data" },
|
|
73
|
+
createdAt: { type: "string", format: "date-time" },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
CognitionEdge: {
|
|
77
|
+
type: "object",
|
|
78
|
+
properties: {
|
|
79
|
+
id: { type: "string" },
|
|
80
|
+
sourceId: { type: "string", description: "Source node ID" },
|
|
81
|
+
targetId: { type: "string", description: "Target node ID" },
|
|
82
|
+
relation: { type: "string", enum: ["CAUSES", "PRECEDES", "MUTEX", "GENERALIZES", "REFINES"] },
|
|
83
|
+
weight: { type: "number", minimum: 0, maximum: 10, default: 1.0 },
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
AstTemplate: {
|
|
87
|
+
type: "object",
|
|
88
|
+
properties: {
|
|
89
|
+
nodeId: { type: "string" },
|
|
90
|
+
language: { type: "string" },
|
|
91
|
+
templateDsl: { type: "string", description: "AST constraint DSL" },
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
return JSON.stringify(schema, null, 2);
|
|
97
|
+
}
|
|
98
|
+
/** Return current graph statistics with approval rate. */
|
|
99
|
+
export async function readCognitionStats() {
|
|
100
|
+
const prisma = getPrismaClient();
|
|
101
|
+
const sevenDaysAgo = new Date(Date.now() - 7 * 86400000);
|
|
102
|
+
const [nodeCount, edgeCount, feedbackCount, recentFeedback, approvedCount] = await Promise.all([
|
|
103
|
+
prisma.cognitionNode.count(),
|
|
104
|
+
prisma.cognitionEdge.count(),
|
|
105
|
+
prisma.metricEvent.count({ where: { eventType: { startsWith: "cognition_feedback" } } }),
|
|
106
|
+
prisma.metricEvent.count({ where: { eventType: { startsWith: "cognition_feedback" }, createdAt: { gte: sevenDaysAgo } } }),
|
|
107
|
+
prisma.metricEvent.count({ where: { eventType: { startsWith: "cognition_feedback" }, properties: { contains: "APPROVED" }, createdAt: { gte: sevenDaysAgo } } }),
|
|
108
|
+
]);
|
|
109
|
+
const approvalRate7d = recentFeedback > 0 ? approvedCount / recentFeedback : 0;
|
|
110
|
+
const thresholdAdjustmentSuggestion = approvalRate7d > 0.4 || approvalRate7d < 0.05
|
|
111
|
+
? "Threshold adjustment recommended: approvalRate7d = " + (approvalRate7d * 100).toFixed(1) + "%"
|
|
112
|
+
: undefined;
|
|
113
|
+
return JSON.stringify({ nodeCount, edgeCount, feedbackCount, approvalRate7d: Math.round(approvalRate7d * 100) / 100, thresholdAdjustmentSuggestion, timestamp: new Date().toISOString() }, null, 2);
|
|
114
|
+
}
|
|
115
|
+
/** Return the integration documentation markdown. */
|
|
116
|
+
export async function readCognitionDocs() {
|
|
117
|
+
try {
|
|
118
|
+
return readFileSync(join(projectRoot, "docs", "phase4-mcp-feedback.md"), "utf-8");
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return "# Cognition Engine APInnDocumentation file not found. See docs/phase4-mcp-feedback.mdn";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=cognition-resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognition-resources.js","sourceRoot":"","sources":["../../src/resources/cognition-resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;AAE7C,8DAA8D;AAE9D,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;QACE,GAAG,EAAE,oBAAoB;QACzB,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EAAE,wIAAwI;QACrJ,QAAQ,EAAE,kBAAkB;KAC7B;IACD;QACE,GAAG,EAAE,mBAAmB;QACxB,IAAI,EAAE,6BAA6B;QACnC,WAAW,EAAE,wJAAwJ;QACrK,QAAQ,EAAE,kBAAkB;KAC7B;IACD;QACE,GAAG,EAAE,kBAAkB;QACvB,IAAI,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,CAAC;QACP,OAAO,wFAAwF,CAAC;IAClG,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 熊高锐
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { PrismaClient } from "@prisma/client";
|
|
17
|
+
export declare function getPrismaClient(): PrismaClient;
|
|
18
|
+
export declare function disconnectPrisma(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Reset the Prisma client singleton, optionally with a new DATABASE_URL.
|
|
21
|
+
* Used by vitest setup to give each worker an isolated database file,
|
|
22
|
+
* preventing cross-worker FK race conditions.
|
|
23
|
+
* Calling with no URL re-creates the client with the current env var value.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resetPrismaClient(databaseUrl?: string): Promise<PrismaClient>;
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/storage/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,wBAAgB,eAAe,IAAI,YAAY,CAO9C;AAED,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKtD;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAMnF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 熊高锐
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { PrismaClient } from "@prisma/client";
|
|
17
|
+
let client = null;
|
|
18
|
+
export function getPrismaClient() {
|
|
19
|
+
if (!client) {
|
|
20
|
+
client = new PrismaClient({ log: ["warn", "error"] });
|
|
21
|
+
// Enable SQLite WAL mode for concurrent read/write performance (P1)
|
|
22
|
+
client.$queryRawUnsafe("PRAGMA journal_mode=WAL").catch(() => { });
|
|
23
|
+
}
|
|
24
|
+
return client;
|
|
25
|
+
}
|
|
26
|
+
export async function disconnectPrisma() {
|
|
27
|
+
if (client) {
|
|
28
|
+
await client.$disconnect();
|
|
29
|
+
client = null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Reset the Prisma client singleton, optionally with a new DATABASE_URL.
|
|
34
|
+
* Used by vitest setup to give each worker an isolated database file,
|
|
35
|
+
* preventing cross-worker FK race conditions.
|
|
36
|
+
* Calling with no URL re-creates the client with the current env var value.
|
|
37
|
+
*/
|
|
38
|
+
export async function resetPrismaClient(databaseUrl) {
|
|
39
|
+
await disconnectPrisma();
|
|
40
|
+
if (databaseUrl !== undefined) {
|
|
41
|
+
process.env.DATABASE_URL = databaseUrl;
|
|
42
|
+
}
|
|
43
|
+
return getPrismaClient();
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/storage/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,IAAI,MAAM,GAAwB,IAAI,CAAC;AAEvC,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,IAAI,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QACtD,oEAAoE;QACpE,MAAM,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC;QAC3B,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,WAAoB;IAC1D,MAAM,gBAAgB,EAAE,CAAC;IACzB,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,WAAW,CAAC;IACzC,CAAC;IACD,OAAO,eAAe,EAAE,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 熊高锐
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { CognitionTypeStr, EdgeRelationStr, CognitionNodeInput, CognitionEdgeInput, AstTemplateInput, CognitionNodeData, CognitionEdgeData, AstTemplateData, SubgraphResult } from "./cognition-types.js";
|
|
17
|
+
/** Generate a semantic hash from type + payload for deduplication. */
|
|
18
|
+
export declare function computeSemanticHash(type: string, payload: Record<string, unknown>): string;
|
|
19
|
+
/** Validate that a type string is a valid CognitionType. */
|
|
20
|
+
export declare function isValidCognitionType(s: string): s is CognitionTypeStr;
|
|
21
|
+
/** Validate that a relation string is a valid EdgeRelation. */
|
|
22
|
+
export declare function isValidEdgeRelation(s: string): s is EdgeRelationStr;
|
|
23
|
+
export declare class CognitionRepository {
|
|
24
|
+
/**
|
|
25
|
+
* Atomically create a cognition node and its associated edges.
|
|
26
|
+
* Uses a Prisma for atomicity.
|
|
27
|
+
*/
|
|
28
|
+
createNodeWithEdges(nodeInput: CognitionNodeInput, edgeInputs?: CognitionEdgeInput[]): Promise<CognitionNodeData>;
|
|
29
|
+
findNodesBySemanticHash(hash: string): Promise<CognitionNodeData[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Get a subgraph starting from a root node, following outgoing edges up to maxDepth.
|
|
32
|
+
* Uses level-based BFS (no DB-side recursive CTE needed).
|
|
33
|
+
*/
|
|
34
|
+
getSubgraph(rootNodeId: string, maxDepth?: number): Promise<SubgraphResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Adjust an edge's weight by a delta (positive or negative).
|
|
37
|
+
* Prepares for the feedback loop in Phase 4.
|
|
38
|
+
*/
|
|
39
|
+
updateEdgeWeight(edgeId: string, delta: number): Promise<CognitionEdgeData>;
|
|
40
|
+
/** Create an AST template linked to a cognition node. */
|
|
41
|
+
createAstTemplate(input: AstTemplateInput): Promise<AstTemplateData>;
|
|
42
|
+
/** Find a node by its database ID. */
|
|
43
|
+
findNodeById(id: string): Promise<CognitionNodeData | null>;
|
|
44
|
+
/** Find edges by relation type. */
|
|
45
|
+
findEdgesByRelation(relation: EdgeRelationStr): Promise<CognitionEdgeData[]>;
|
|
46
|
+
/** Delete a node and cascade-delete its edges and template. */
|
|
47
|
+
deleteNode(id: string): Promise<void>;
|
|
48
|
+
/** Record a feedback event (async, non-blocking, fire-and-forget). */
|
|
49
|
+
recordFeedbackEvent(nodeId: string, edgeId?: string, outcome?: string, comment?: string): Promise<{
|
|
50
|
+
feedbackId: string;
|
|
51
|
+
}>;
|
|
52
|
+
/** Resolve a pending feedback event with the final outcome. */
|
|
53
|
+
resolveFeedbackEvent(feedbackId: string, outcome: string, edgeId?: string, weightDelta?: number): Promise<void>;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=cognition-repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognition-repository.d.ts","sourceRoot":"","sources":["../../src/storage/cognition-repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,cAAc,EAGf,MAAM,sBAAsB,CAAC;AAe9B,sEAAsE;AACtE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAG1F;AAED,4DAA4D;AAC5D,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,G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ACf,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC;CAejB"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2026 熊高锐
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { getPrismaClient } from "./client.js";
|
|
17
|
+
import { COGNITION_TYPES, EDGE_RELATIONS, } from "./cognition-types.js";
|
|
18
|
+
// ── Helpers ────────────────────────────────────────────────
|
|
19
|
+
/** Simple hash for semantic dedup. Consistent with ast-node.ts legacy style. */
|
|
20
|
+
function simpleHash(s) {
|
|
21
|
+
if (!s)
|
|
22
|
+
return "0";
|
|
23
|
+
let hash = 0;
|
|
24
|
+
for (let i = 0; i < s.length; i++) {
|
|
25
|
+
hash = ((hash << 5) - hash) + s.charCodeAt(i);
|
|
26
|
+
hash |= 0;
|
|
27
|
+
}
|
|
28
|
+
return Math.abs(hash).toString(16);
|
|
29
|
+
}
|
|
30
|
+
/** Generate a semantic hash from type + payload for deduplication. */
|
|
31
|
+
export function computeSemanticHash(type, payload) {
|
|
32
|
+
const normalized = JSON.stringify(payload, Object.keys(payload).sort());
|
|
33
|
+
return simpleHash(type + ":" + normalized);
|
|
34
|
+
}
|
|
35
|
+
/** Validate that a type string is a valid CognitionType. */
|
|
36
|
+
export function isValidCognitionType(s) {
|
|
37
|
+
return Object.values(COGNITION_TYPES).includes(s);
|
|
38
|
+
}
|
|
39
|
+
/** Validate that a relation string is a valid EdgeRelation. */
|
|
40
|
+
export function isValidEdgeRelation(s) {
|
|
41
|
+
return Object.values(EDGE_RELATIONS).includes(s);
|
|
42
|
+
}
|
|
43
|
+
function parseJsonField(val) {
|
|
44
|
+
if (!val)
|
|
45
|
+
return null;
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(val);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function toCognitionNode(r) {
|
|
54
|
+
return {
|
|
55
|
+
id: r.id,
|
|
56
|
+
type: r.type,
|
|
57
|
+
semanticHash: r.semanticHash,
|
|
58
|
+
abstractionLevel: r.abstractionLevel,
|
|
59
|
+
payload: parseJsonField(r.payload) ?? {},
|
|
60
|
+
metadata: parseJsonField(r.metadata),
|
|
61
|
+
createdAt: r.createdAt,
|
|
62
|
+
updatedAt: r.updatedAt,
|
|
63
|
+
astTemplate: r.astTemplate ? toAstTemplate(r.astTemplate) : null,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function toCognitionNodeBasic(r) {
|
|
67
|
+
return {
|
|
68
|
+
id: r.id,
|
|
69
|
+
type: r.type,
|
|
70
|
+
semanticHash: r.semanticHash,
|
|
71
|
+
abstractionLevel: r.abstractionLevel,
|
|
72
|
+
payload: parseJsonField(r.payload) ?? {},
|
|
73
|
+
metadata: parseJsonField(r.metadata),
|
|
74
|
+
createdAt: r.createdAt,
|
|
75
|
+
updatedAt: r.updatedAt,
|
|
76
|
+
astTemplate: null,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function toCognitionEdge(r) {
|
|
80
|
+
return {
|
|
81
|
+
id: r.id,
|
|
82
|
+
sourceId: r.sourceId,
|
|
83
|
+
targetId: r.targetId,
|
|
84
|
+
relation: r.relation,
|
|
85
|
+
weight: r.weight,
|
|
86
|
+
metadata: parseJsonField(r.metadata),
|
|
87
|
+
createdAt: r.createdAt,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function toAstTemplate(r) {
|
|
91
|
+
return {
|
|
92
|
+
id: r.id,
|
|
93
|
+
nodeId: r.nodeId,
|
|
94
|
+
language: r.language,
|
|
95
|
+
templateDsl: r.templateDsl,
|
|
96
|
+
validationSchema: parseJsonField(r.validationSchema),
|
|
97
|
+
createdAt: r.createdAt,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
// ── Repository ─────────────────────────────────────────────
|
|
101
|
+
export class CognitionRepository {
|
|
102
|
+
/**
|
|
103
|
+
* Atomically create a cognition node and its associated edges.
|
|
104
|
+
* Uses a Prisma for atomicity.
|
|
105
|
+
*/
|
|
106
|
+
async createNodeWithEdges(nodeInput, edgeInputs = []) {
|
|
107
|
+
const prisma = getPrismaClient();
|
|
108
|
+
const payloadStr = JSON.stringify(nodeInput.payload);
|
|
109
|
+
const metadataStr = nodeInput.metadata ? JSON.stringify(nodeInput.metadata) : null;
|
|
110
|
+
return prisma.$transaction(async (tx) => {
|
|
111
|
+
const node = await tx.cognitionNode.create({
|
|
112
|
+
data: {
|
|
113
|
+
type: nodeInput.type,
|
|
114
|
+
semanticHash: nodeInput.semanticHash,
|
|
115
|
+
abstractionLevel: nodeInput.abstractionLevel,
|
|
116
|
+
payload: payloadStr,
|
|
117
|
+
metadata: metadataStr,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
if (edgeInputs.length > 0) {
|
|
121
|
+
await tx.cognitionEdge.createMany({
|
|
122
|
+
data: edgeInputs.map((e) => ({
|
|
123
|
+
sourceId: e.sourceId,
|
|
124
|
+
targetId: e.targetId,
|
|
125
|
+
relation: e.relation,
|
|
126
|
+
weight: e.weight ?? 1.0,
|
|
127
|
+
metadata: e.metadata ? JSON.stringify(e.metadata) : null,
|
|
128
|
+
})),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
const withTemplate = await tx.cognitionNode.findUnique({
|
|
132
|
+
where: { id: node.id },
|
|
133
|
+
include: { astTemplate: true },
|
|
134
|
+
});
|
|
135
|
+
return toCognitionNode(withTemplate);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async findNodesBySemanticHash(hash) {
|
|
139
|
+
const prisma = getPrismaClient();
|
|
140
|
+
const rows = await prisma.cognitionNode.findMany({
|
|
141
|
+
where: { semanticHash: hash },
|
|
142
|
+
include: { astTemplate: true },
|
|
143
|
+
});
|
|
144
|
+
return rows.map(toCognitionNode);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get a subgraph starting from a root node, following outgoing edges up to maxDepth.
|
|
148
|
+
* Uses level-based BFS (no DB-side recursive CTE needed).
|
|
149
|
+
*/
|
|
150
|
+
async getSubgraph(rootNodeId, maxDepth = 3) {
|
|
151
|
+
const prisma = getPrismaClient();
|
|
152
|
+
// 1. Fetch root node
|
|
153
|
+
const rootNode = await prisma.cognitionNode.findUnique({
|
|
154
|
+
where: { id: rootNodeId },
|
|
155
|
+
include: { astTemplate: true },
|
|
156
|
+
});
|
|
157
|
+
if (!rootNode) {
|
|
158
|
+
return { nodes: [], edges: [] };
|
|
159
|
+
}
|
|
160
|
+
const visitedNodeIds = new Set([rootNode.id]);
|
|
161
|
+
const visitedEdgeIds = new Set();
|
|
162
|
+
const nodes = [toCognitionNode(rootNode)];
|
|
163
|
+
const edges = [];
|
|
164
|
+
let frontier = [rootNode.id];
|
|
165
|
+
// BFS traversal level by level
|
|
166
|
+
for (let depth = 0; depth < maxDepth && frontier.length > 0; depth++) {
|
|
167
|
+
// Fetch all outgoing edges from frontier nodes
|
|
168
|
+
const outgoingEdges = await prisma.cognitionEdge.findMany({
|
|
169
|
+
where: { sourceId: { in: frontier } },
|
|
170
|
+
});
|
|
171
|
+
const nextFrontier = [];
|
|
172
|
+
for (const edge of outgoingEdges) {
|
|
173
|
+
if (!visitedEdgeIds.has(edge.id)) {
|
|
174
|
+
visitedEdgeIds.add(edge.id);
|
|
175
|
+
edges.push(toCognitionEdge(edge));
|
|
176
|
+
if (!visitedNodeIds.has(edge.targetId)) {
|
|
177
|
+
visitedNodeIds.add(edge.targetId);
|
|
178
|
+
nextFrontier.push(edge.targetId);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// Fetch target nodes for the next frontier
|
|
183
|
+
if (nextFrontier.length > 0) {
|
|
184
|
+
const targetNodes = await prisma.cognitionNode.findMany({
|
|
185
|
+
where: { id: { in: nextFrontier } },
|
|
186
|
+
include: { astTemplate: true },
|
|
187
|
+
});
|
|
188
|
+
for (const n of targetNodes) {
|
|
189
|
+
nodes.push(toCognitionNode(n));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
frontier = nextFrontier;
|
|
193
|
+
}
|
|
194
|
+
return { nodes, edges };
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Adjust an edge's weight by a delta (positive or negative).
|
|
198
|
+
* Prepares for the feedback loop in Phase 4.
|
|
199
|
+
*/
|
|
200
|
+
async updateEdgeWeight(edgeId, delta) {
|
|
201
|
+
const prisma = getPrismaClient();
|
|
202
|
+
const edge = await prisma.cognitionEdge.findUnique({ where: { id: edgeId } });
|
|
203
|
+
if (!edge) {
|
|
204
|
+
throw new Error(`Edge not found: ${edgeId}`);
|
|
205
|
+
}
|
|
206
|
+
const newWeight = Math.max(0, Math.min(10, edge.weight + delta));
|
|
207
|
+
const updated = await prisma.cognitionEdge.update({
|
|
208
|
+
where: { id: edgeId },
|
|
209
|
+
data: { weight: newWeight },
|
|
210
|
+
});
|
|
211
|
+
return toCognitionEdge(updated);
|
|
212
|
+
}
|
|
213
|
+
/** Create an AST template linked to a cognition node. */
|
|
214
|
+
async createAstTemplate(input) {
|
|
215
|
+
const prisma = getPrismaClient();
|
|
216
|
+
const tmpl = await prisma.astTemplate.create({
|
|
217
|
+
data: {
|
|
218
|
+
nodeId: input.nodeId,
|
|
219
|
+
language: input.language,
|
|
220
|
+
templateDsl: input.templateDsl,
|
|
221
|
+
validationSchema: input.validationSchema ? JSON.stringify(input.validationSchema) : null,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
return toAstTemplate(tmpl);
|
|
225
|
+
}
|
|
226
|
+
/** Find a node by its database ID. */
|
|
227
|
+
async findNodeById(id) {
|
|
228
|
+
const prisma = getPrismaClient();
|
|
229
|
+
const row = await prisma.cognitionNode.findUnique({
|
|
230
|
+
where: { id },
|
|
231
|
+
include: { astTemplate: true },
|
|
232
|
+
});
|
|
233
|
+
return row ? toCognitionNode(row) : null;
|
|
234
|
+
}
|
|
235
|
+
/** Find edges by relation type. */
|
|
236
|
+
async findEdgesByRelation(relation) {
|
|
237
|
+
const prisma = getPrismaClient();
|
|
238
|
+
const rows = await prisma.cognitionEdge.findMany({
|
|
239
|
+
where: { relation },
|
|
240
|
+
});
|
|
241
|
+
return rows.map(toCognitionEdge);
|
|
242
|
+
}
|
|
243
|
+
/** Delete a node and cascade-delete its edges and template. */
|
|
244
|
+
async deleteNode(id) {
|
|
245
|
+
const prisma = getPrismaClient();
|
|
246
|
+
await prisma.cognitionNode.delete({ where: { id } });
|
|
247
|
+
}
|
|
248
|
+
// ── Feedback Event Tracking ────────────────────────────
|
|
249
|
+
/** Record a feedback event (async, non-blocking, fire-and-forget). */
|
|
250
|
+
async recordFeedbackEvent(nodeId, edgeId, outcome, comment) {
|
|
251
|
+
const prisma = getPrismaClient();
|
|
252
|
+
const event = await prisma.metricEvent.create({
|
|
253
|
+
data: {
|
|
254
|
+
eventType: "cognition_feedback_pending",
|
|
255
|
+
properties: JSON.stringify({
|
|
256
|
+
nodeId,
|
|
257
|
+
edgeId: edgeId ?? null,
|
|
258
|
+
outcome: outcome ?? "PENDING",
|
|
259
|
+
comment: comment ?? null,
|
|
260
|
+
status: "PENDING",
|
|
261
|
+
createdAt: new Date().toISOString(),
|
|
262
|
+
}),
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
return { feedbackId: event.id };
|
|
266
|
+
}
|
|
267
|
+
/** Resolve a pending feedback event with the final outcome. */
|
|
268
|
+
async resolveFeedbackEvent(feedbackId, outcome, edgeId, weightDelta) {
|
|
269
|
+
const prisma = getPrismaClient();
|
|
270
|
+
const existing = await prisma.metricEvent.findUnique({ where: { id: feedbackId } });
|
|
271
|
+
if (!existing)
|
|
272
|
+
return;
|
|
273
|
+
const props = JSON.parse(existing.properties || "{}");
|
|
274
|
+
props.status = "RESOLVED";
|
|
275
|
+
props.outcome = outcome;
|
|
276
|
+
props.resolvedAt = new Date().toISOString();
|
|
277
|
+
if (weightDelta !== undefined)
|
|
278
|
+
props.weightDelta = weightDelta;
|
|
279
|
+
if (edgeId)
|
|
280
|
+
props.edgeId = edgeId;
|
|
281
|
+
await prisma.metricEvent.update({
|
|
282
|
+
where: { id: feedbackId },
|
|
283
|
+
data: { properties: JSON.stringify(props) },
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
//# sourceMappingURL=cognition-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognition-repository.js","sourceRoot":"","sources":["../../src/storage/cognition-repository.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAUL,eAAe,EACf,cAAc,GACf,MAAM,sBAAsB,CAAC;AAE9B,8DAA8D;AAE9D,gFAAgF;AAChF,SAAS,UAAU,CAAC,CAAS;IAC3B,IAAI,CAAC,CAAC;QAAE,OAAO,GAAG,CAAC;IACnB,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC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