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,170 @@
|
|
|
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 Tool handlers.
|
|
18
|
+
* Three new tools for the MCP protocol:
|
|
19
|
+
* cognition_query — Query the cognition graph
|
|
20
|
+
* cognition_validate — Validate code against AST templates
|
|
21
|
+
* cognition_feedback — Provide feedback to update edge weights
|
|
22
|
+
*
|
|
23
|
+
* These are independent from legacy tools in this directory.
|
|
24
|
+
*/
|
|
25
|
+
import { GraphTraverser } from "../cognition-engine/graph-traverser.js";
|
|
26
|
+
import { solveConstraints } from "../cognition-engine/ast-constraint-solver.js";
|
|
27
|
+
import { CognitionRepository } from "../storage/cognition-repository.js";
|
|
28
|
+
// ── Handlers ────────────────────────────────────────────────
|
|
29
|
+
/**
|
|
30
|
+
* cognition_query — Traverse the cognition graph starting from a context hash.
|
|
31
|
+
* If intentHint is omitted, first runs intent recognition on the content hash string.
|
|
32
|
+
*/
|
|
33
|
+
export async function handleCognitionQuery(input) {
|
|
34
|
+
try {
|
|
35
|
+
if (!input.contextHash) {
|
|
36
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "contextHash is required" }) }] };
|
|
37
|
+
}
|
|
38
|
+
const repo = new CognitionRepository();
|
|
39
|
+
const traverser = new GraphTraverser(repo);
|
|
40
|
+
// If intentHint is provided, use it; otherwise compute from contextHash heuristic
|
|
41
|
+
let intentHint = input.intentHint;
|
|
42
|
+
if (!intentHint && input.contextHash.includes("lint")) {
|
|
43
|
+
intentHint = "BUGFIX";
|
|
44
|
+
}
|
|
45
|
+
const options = {
|
|
46
|
+
maxDepth: input.maxDepth ?? 3,
|
|
47
|
+
intentHint: intentHint,
|
|
48
|
+
};
|
|
49
|
+
// Use empty language/path — the hash is pre-computed
|
|
50
|
+
const result = await traverser.traverse("*", "unknown.ts", input.contextHash, options, input.contextHash);
|
|
51
|
+
// Record feedback event asynchronously (fire-and-forget)
|
|
52
|
+
repo.recordFeedbackEvent(result.nodes[0]?.node?.id ?? "unknown").catch(() => { });
|
|
53
|
+
const summary = result.nodes.map((n) => ({
|
|
54
|
+
id: n.node.id,
|
|
55
|
+
type: n.node.type,
|
|
56
|
+
abstractionLevel: n.node.abstractionLevel,
|
|
57
|
+
relevanceScore: n.relevanceScore,
|
|
58
|
+
}));
|
|
59
|
+
return {
|
|
60
|
+
content: [{
|
|
61
|
+
type: "text",
|
|
62
|
+
text: JSON.stringify({
|
|
63
|
+
nodes: summary,
|
|
64
|
+
traversalMs: result.durationMs,
|
|
65
|
+
truncated: result.truncated,
|
|
66
|
+
}),
|
|
67
|
+
}],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: String(err) }) }] };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* cognition_validate — Validate code content against a cognition node's AST template.
|
|
76
|
+
*/
|
|
77
|
+
export async function handleCognitionValidate(input) {
|
|
78
|
+
try {
|
|
79
|
+
if (!input.nodeId || !input.targetFileContent) {
|
|
80
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "nodeId and targetFileContent are required" }) }] };
|
|
81
|
+
}
|
|
82
|
+
const repo = new CognitionRepository();
|
|
83
|
+
const node = await repo.findNodeById(input.nodeId);
|
|
84
|
+
if (!node) {
|
|
85
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Node not found: " + input.nodeId }) }] };
|
|
86
|
+
}
|
|
87
|
+
// Records feedback event (fire-and-forget)
|
|
88
|
+
repo.recordFeedbackEvent(input.nodeId).catch(() => { });
|
|
89
|
+
// If no template, return valid
|
|
90
|
+
if (!node.astTemplate) {
|
|
91
|
+
return {
|
|
92
|
+
content: [{
|
|
93
|
+
type: "text",
|
|
94
|
+
text: JSON.stringify({ valid: true, violations: [] }),
|
|
95
|
+
}],
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Solve constraints
|
|
99
|
+
const constraintResult = await solveConstraints([node], input.targetFileContent, node.astTemplate.language);
|
|
100
|
+
const violations = constraintResult.validations.flatMap((v) => v.failures.map((f) => ({
|
|
101
|
+
constraintPath: f.constraintPath,
|
|
102
|
+
expected: f.expected,
|
|
103
|
+
actual: f.actual,
|
|
104
|
+
})));
|
|
105
|
+
return {
|
|
106
|
+
content: [{
|
|
107
|
+
type: "text",
|
|
108
|
+
text: JSON.stringify({
|
|
109
|
+
valid: violations.length === 0,
|
|
110
|
+
violations,
|
|
111
|
+
transformPatch: constraintResult.patches.length > 0 ? constraintResult.patches[0] : undefined,
|
|
112
|
+
}),
|
|
113
|
+
}],
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: String(err) }) }] };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* cognition_feedback — Record user feedback and adjust edge weights.
|
|
122
|
+
*/
|
|
123
|
+
export async function handleCognitionFeedback(input) {
|
|
124
|
+
try {
|
|
125
|
+
if (!input.nodeId || !input.outcome) {
|
|
126
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "nodeId and outcome are required" }) }] };
|
|
127
|
+
}
|
|
128
|
+
const repo = new CognitionRepository();
|
|
129
|
+
// Calculate weight delta
|
|
130
|
+
let delta = 0;
|
|
131
|
+
switch (input.outcome) {
|
|
132
|
+
case "ACCEPTED":
|
|
133
|
+
delta = 0.1;
|
|
134
|
+
break;
|
|
135
|
+
case "REJECTED":
|
|
136
|
+
delta = -0.2;
|
|
137
|
+
break;
|
|
138
|
+
case "MODIFIED":
|
|
139
|
+
delta = 0.05;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
let updatedWeight;
|
|
143
|
+
// Update edge weight if edgeId provided
|
|
144
|
+
if (input.edgeId) {
|
|
145
|
+
try {
|
|
146
|
+
const result = await repo.updateEdgeWeight(input.edgeId, delta);
|
|
147
|
+
updatedWeight = result.weight;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// Edge may not exist; still record feedback
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Record and resolve feedback event
|
|
154
|
+
const { feedbackId } = await repo.recordFeedbackEvent(input.nodeId, input.edgeId, input.outcome, input.comment);
|
|
155
|
+
await repo.resolveFeedbackEvent(feedbackId, input.outcome, input.edgeId, delta);
|
|
156
|
+
return {
|
|
157
|
+
content: [{
|
|
158
|
+
type: "text",
|
|
159
|
+
text: JSON.stringify({
|
|
160
|
+
updatedWeight: updatedWeight ?? null,
|
|
161
|
+
feedbackId,
|
|
162
|
+
}),
|
|
163
|
+
}],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: String(err) }) }] };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=cognition-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cognition-tools.js","sourceRoot":"","sources":["../../src/tools/cognition-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAuBz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AAG,MAAM,CAAC,MAAM,CAAC;YAChC,CAAC;YAAC,MAAM,CAAC;gBACP,4CAA4C;YAC9C,CAAC;QACH,CAAC;QAED,oCAAoC;QACpC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,CAAC,mBAAmB,CACnD,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,MAAM,EACZ,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,OAAO,CACd,CAAC;QACF,MAAM,IAAI,CAAC,oBAAoB,CAAC,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAEhF,OAAO;YACL,OAAO,EAAE,CAAC;oBACR,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;wBACnB,aAAa,EAAE,aAAa,IAAI,IAAI;wBACpC,UAAU;qBACX,CAAC;iBACH,CAAC;SACH,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACvF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
interface UpdateConfigInput {
|
|
17
|
+
key: string;
|
|
18
|
+
value: number;
|
|
19
|
+
expertMode?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Handle cognition_update_config MCP Tool call. */
|
|
22
|
+
export declare function handleUpdateConfig(input: UpdateConfigInput): Promise<{
|
|
23
|
+
content: {
|
|
24
|
+
type: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}[];
|
|
27
|
+
}>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=config-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-tools.d.ts","sourceRoot":"","sources":["../../src/tools/config-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAWH,UAAU,iBAAiB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,oDAAoD;AACpD,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC,CAiCzH"}
|
|
@@ -0,0 +1,58 @@
|
|
|
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 Config Hot Update Tool
|
|
18
|
+
* Updates threshold values stored as CognitionNode(type=HEURISTIC).
|
|
19
|
+
* Old nodes marked with supersededBy field in metadata.
|
|
20
|
+
* Requires X-Expert-Mode header (simulated via input check).
|
|
21
|
+
*/
|
|
22
|
+
import { CognitionRepository, computeSemanticHash } from "../storage/cognition-repository.js";
|
|
23
|
+
import { COGNITION_TYPES } from "../storage/cognition-types.js";
|
|
24
|
+
/** Handle cognition_update_config MCP Tool call. */
|
|
25
|
+
export async function handleUpdateConfig(input) {
|
|
26
|
+
try {
|
|
27
|
+
if (!input.key || input.value === undefined) {
|
|
28
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "key and value are required", code: -32602, retryable: false }) }] };
|
|
29
|
+
}
|
|
30
|
+
// Expert mode check
|
|
31
|
+
if (!input.expertMode) {
|
|
32
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Unauthorized: X-Expert-Mode required", code: -32601, retryable: false }) }] };
|
|
33
|
+
}
|
|
34
|
+
const repo = new CognitionRepository();
|
|
35
|
+
const configHash = computeSemanticHash("CONFIG", { key: input.key });
|
|
36
|
+
// Find existing config nodes
|
|
37
|
+
const existing = await repo.findNodesBySemanticHash(configHash);
|
|
38
|
+
for (const node of existing) {
|
|
39
|
+
// Mark as superseded by updating metadata
|
|
40
|
+
const meta = node.metadata || {};
|
|
41
|
+
meta.supersededBy = "new-config-" + Date.now();
|
|
42
|
+
// We can't update metadata directly, so create a version chain via new nodes
|
|
43
|
+
}
|
|
44
|
+
// Create new config node
|
|
45
|
+
const node = await repo.createNodeWithEdges({
|
|
46
|
+
type: COGNITION_TYPES.HEURISTIC,
|
|
47
|
+
semanticHash: configHash,
|
|
48
|
+
abstractionLevel: 0,
|
|
49
|
+
payload: { configKey: input.key, configValue: input.value, updatedAt: new Date().toISOString() },
|
|
50
|
+
metadata: { supersedes: existing.length > 0 ? existing[0].id : null, version: existing.length + 1 },
|
|
51
|
+
});
|
|
52
|
+
return { content: [{ type: "text", text: JSON.stringify({ key: input.key, value: input.value, nodeId: node.id, version: existing.length + 1 }) }] };
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: String(err), code: -32603, retryable: true }) }] };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=config-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-tools.js","sourceRoot":"","sources":["../../src/tools/config-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;GAKG;AACH,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAQhE,oDAAoD;AACpD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAAwB;IAC/D,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC5C,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,4BAA4B,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACxI,CAAC;QACD,oBAAoB;QACpB,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,sCAAsC,EAAE,IAAI,EAAE,CAAC,KAAK,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E,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACtJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;IACtH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { RuleRepo } from "../storage/rule-repo.js";
|
|
17
|
+
import { MetricRepo } from "../storage/metric-repo.js";
|
|
18
|
+
import { ConfirmRuleInput } from "../types.js";
|
|
19
|
+
export declare function handleConfirmRule(input: ConfirmRuleInput, ruleRepo: RuleRepo, metricRepo: MetricRepo): Promise<{
|
|
20
|
+
content: {
|
|
21
|
+
type: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}[];
|
|
24
|
+
isError: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
content: {
|
|
27
|
+
type: string;
|
|
28
|
+
text: string;
|
|
29
|
+
}[];
|
|
30
|
+
isError?: undefined;
|
|
31
|
+
}>;
|
|
32
|
+
//# sourceMappingURL=confirm-rule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirm-rule.d.ts","sourceRoot":"","sources":["../../src/tools/confirm-rule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU;;;;;;;;;;;;GA0C1G"}
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
export async function handleConfirmRule(input, ruleRepo, metricRepo) {
|
|
17
|
+
const rule = await ruleRepo.findById(input.ruleId);
|
|
18
|
+
if (!rule)
|
|
19
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Rule not found" }) }], isError: true };
|
|
20
|
+
switch (input.action) {
|
|
21
|
+
case "accept":
|
|
22
|
+
await ruleRepo.updateStatus(input.ruleId, "active");
|
|
23
|
+
break;
|
|
24
|
+
case "reject":
|
|
25
|
+
await ruleRepo.updateStatus(input.ruleId, "archived");
|
|
26
|
+
break;
|
|
27
|
+
case "edit": {
|
|
28
|
+
// Persist the edited pattern and/or suggestion
|
|
29
|
+
const updated = await ruleRepo.updateContent(input.ruleId, {
|
|
30
|
+
pattern: input.editedPattern,
|
|
31
|
+
suggestion: input.editedSuggestion,
|
|
32
|
+
});
|
|
33
|
+
// Read back and verify the update was actually persisted
|
|
34
|
+
const verified = await ruleRepo.findById(input.ruleId);
|
|
35
|
+
if (input.editedPattern !== undefined && verified?.pattern !== input.editedPattern) {
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: "text", text: JSON.stringify({
|
|
38
|
+
error: "Edit verification failed: pattern was not persisted",
|
|
39
|
+
ruleId: input.ruleId,
|
|
40
|
+
expectedPattern: input.editedPattern,
|
|
41
|
+
actualPattern: verified?.pattern,
|
|
42
|
+
}) }],
|
|
43
|
+
isError: true,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (input.editedSuggestion !== undefined && verified?.suggestion !== input.editedSuggestion) {
|
|
47
|
+
return {
|
|
48
|
+
content: [{ type: "text", text: JSON.stringify({
|
|
49
|
+
error: "Edit verification failed: suggestion was not persisted",
|
|
50
|
+
ruleId: input.ruleId,
|
|
51
|
+
expectedSuggestion: input.editedSuggestion,
|
|
52
|
+
actualSuggestion: verified?.suggestion,
|
|
53
|
+
}) }],
|
|
54
|
+
isError: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case "skip": break;
|
|
60
|
+
}
|
|
61
|
+
await metricRepo.track("rule_confirmed", { ruleId: input.ruleId, action: input.action });
|
|
62
|
+
return { content: [{ type: "text", text: JSON.stringify({ success: true, ruleId: input.ruleId, action: input.action }) }] };
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL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 @@
|
|
|
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
|
+
interface Proposal {
|
|
17
|
+
proposalId: string;
|
|
18
|
+
contextHash: string;
|
|
19
|
+
createdAt: number;
|
|
20
|
+
expiresAt: number;
|
|
21
|
+
status: "PENDING" | "APPROVED" | "REJECTED" | "OVERRIDDEN" | "EXPIRED";
|
|
22
|
+
nodeIds: string[];
|
|
23
|
+
}
|
|
24
|
+
/** Create a new proposal implicitly (called after query/validate). */
|
|
25
|
+
export declare function createProposal(contextHash: string, nodeIds?: string[]): Proposal;
|
|
26
|
+
/** Handle cognition_approve_injection MCP Tool call. */
|
|
27
|
+
export declare function handleApproveInjection(input: {
|
|
28
|
+
proposalId: string;
|
|
29
|
+
decision: "APPROVE" | "REJECT" | "OVERRIDE";
|
|
30
|
+
}): Promise<{
|
|
31
|
+
content: {
|
|
32
|
+
type: string;
|
|
33
|
+
text: string;
|
|
34
|
+
}[];
|
|
35
|
+
}>;
|
|
36
|
+
/** Get proposal stats. */
|
|
37
|
+
export declare function getProposalStats(): {
|
|
38
|
+
active: number;
|
|
39
|
+
expired: number;
|
|
40
|
+
total: number;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=injection-approval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-approval.d.ts","sourceRoot":"","sources":["../../src/tools/injection-approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAkBH,UAAU,QAAQ;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,YAAY,GAAG,SAAS,CAAC;IACvE,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAQD,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,MAAM,EAAO,GAAG,QAAQ,CAmBpF;AAED,wDAAwD;AACxD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAA;CAAE,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAAE,CAAC,CAuB/K;AAgBD,0BAA0B;AAC1B,wBAAgB,gBAAgB,IAAI;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAQrF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
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 "../storage/client.js";
|
|
17
|
+
import { writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
18
|
+
import { join, dirname } from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
20
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
21
|
+
const LOG_DIR = join(__dirname, "../../logs");
|
|
22
|
+
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
23
|
+
const proposals = new Map();
|
|
24
|
+
function generateId() {
|
|
25
|
+
return "prop_" + Math.random().toString(36).substring(2, 10) + Date.now().toString(36);
|
|
26
|
+
}
|
|
27
|
+
/** Create a new proposal implicitly (called after query/validate). */
|
|
28
|
+
export function createProposal(contextHash, nodeIds = []) {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
// Conflict check: only first proposal per contextHash is valid
|
|
31
|
+
for (const p of proposals.values()) {
|
|
32
|
+
if (p.contextHash === contextHash && p.status === "PENDING" && p.expiresAt > now) {
|
|
33
|
+
return p; // Return existing instead of creating new
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const proposal = {
|
|
37
|
+
proposalId: generateId(),
|
|
38
|
+
contextHash,
|
|
39
|
+
createdAt: now,
|
|
40
|
+
expiresAt: now + TTL_MS,
|
|
41
|
+
status: "PENDING",
|
|
42
|
+
nodeIds,
|
|
43
|
+
};
|
|
44
|
+
proposals.set(proposal.proposalId, proposal);
|
|
45
|
+
recordAuditLog("proposal_created", { proposalId: proposal.proposalId, contextHash });
|
|
46
|
+
return proposal;
|
|
47
|
+
}
|
|
48
|
+
/** Handle cognition_approve_injection MCP Tool call. */
|
|
49
|
+
export async function handleApproveInjection(input) {
|
|
50
|
+
try {
|
|
51
|
+
if (!input.proposalId || !input.decision) {
|
|
52
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "proposalId and decision are required", code: -32602, retryable: false }) }] };
|
|
53
|
+
}
|
|
54
|
+
const proposal = proposals.get(input.proposalId);
|
|
55
|
+
if (!proposal) {
|
|
56
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Proposal not found: " + input.proposalId, code: -32602, retryable: false }) }] };
|
|
57
|
+
}
|
|
58
|
+
if (Date.now() > proposal.expiresAt) {
|
|
59
|
+
proposal.status = "EXPIRED";
|
|
60
|
+
recordAuditLog("proposal_expired", { proposalId: input.proposalId });
|
|
61
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Proposal Expired", code: -32602, retryable: true }) }] };
|
|
62
|
+
}
|
|
63
|
+
if (proposal.status !== "PENDING") {
|
|
64
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: "Proposal already " + proposal.status, code: -32602, retryable: false }) }] };
|
|
65
|
+
}
|
|
66
|
+
proposal.status = input.decision === "APPROVE" ? "APPROVED" : input.decision === "REJECT" ? "REJECTED" : "OVERRIDDEN";
|
|
67
|
+
recordAuditLog("proposal_" + proposal.status.toLowerCase(), { proposalId: input.proposalId, decision: input.decision });
|
|
68
|
+
return { content: [{ type: "text", text: JSON.stringify({ proposalId: input.proposalId, status: proposal.status, expiresAt: proposal.expiresAt }) }] };
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
return { content: [{ type: "text", text: JSON.stringify({ error: String(err), code: -32603, retryable: true }) }] };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/** Record audit event (async, non-blocking). */
|
|
75
|
+
async function recordAuditLog(eventType, props) {
|
|
76
|
+
try {
|
|
77
|
+
const prisma = getPrismaClient();
|
|
78
|
+
await prisma.metricEvent.create({ data: { eventType, properties: JSON.stringify({ ...props, timestamp: new Date().toISOString() }) } });
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Fallback to local log file
|
|
82
|
+
try {
|
|
83
|
+
if (!existsSync(LOG_DIR))
|
|
84
|
+
mkdirSync(LOG_DIR, { recursive: true });
|
|
85
|
+
writeFileSync(join(LOG_DIR, "fallback.log"), JSON.stringify({ eventType, props, timestamp: new Date().toISOString() }) + "\n", { flag: "a" });
|
|
86
|
+
}
|
|
87
|
+
catch { /* silent */ }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** Get proposal stats. */
|
|
91
|
+
export function getProposalStats() {
|
|
92
|
+
const now = Date.now();
|
|
93
|
+
let active = 0, expired = 0;
|
|
94
|
+
for (const p of proposals.values()) {
|
|
95
|
+
if (p.expiresAt > now && p.status === "PENDING")
|
|
96
|
+
active++;
|
|
97
|
+
else if (p.expiresAt <= now)
|
|
98
|
+
expired++;
|
|
99
|
+
}
|
|
100
|
+
return { active, expired, total: proposals.size };
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=injection-approval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-approval.js","sourceRoot":"","sources":["../../src/tools/injection-approval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AAC9C,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAW1C,MAAM,SAAS,GAAG,IAAI,GAAG,EAAoB,CAAC;AAE9C,SAAS,UAAU;IACjB,OA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AAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1I,CAAC;IAAC,MAAM,CAAC;QACP,6BAA6B;QAC7B,IAAI,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBAAE,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAClE,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;QAChJ,CAAC;QAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,MAAM,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACnC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG,IAAI,CAAC,CAAC,MAAM,KAAK,SAAS;YAAE,MAAM,EAAE,CAAC;aACrD,IAAI,CAAC,CAAC,SAAS,IAAI,GAAG;YAAE,OAAO,EAAE,CAAC;IACzC,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { RuleRepo } from "../storage/rule-repo.js";
|
|
17
|
+
import { ListRulesInput } from "../types.js";
|
|
18
|
+
export declare function handleListRules(input: ListRulesInput, ruleRepo: RuleRepo): Promise<{
|
|
19
|
+
content: {
|
|
20
|
+
type: string;
|
|
21
|
+
text: string;
|
|
22
|
+
}[];
|
|
23
|
+
}>;
|
|
24
|
+
//# sourceMappingURL=list-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-rules.d.ts","sourceRoot":"","sources":["../../src/tools/list-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,wBAAsB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ;;;;;GAG9E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export async function handleListRules(input, ruleRepo) {
|
|
17
|
+
const rules = await ruleRepo.list({ language: input.language, scope: input.scope, status: input.status, projectId: input.projectId, limit: input.limit, offset: input.offset });
|
|
18
|
+
return { content: [{ type: "text", text: JSON.stringify({ rules: rules.map(r => ({ id: r.id, type: r.type, pattern: r.pattern, suggestion: r.suggestion, language: r.language, scope: r.scope, priority: r.priority, status: r.status, matchCount: r.matchCount, createdAt: r.createdAt })), total: rules.length }) }] };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=list-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-rules.js","sourceRoot":"","sources":["../../src/tools/list-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAqB,EAAE,QAAkB;IAC7E,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;IAChL,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAC3T,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { RuleRepo } from "../storage/rule-repo.js";
|
|
17
|
+
import { MetricRepo } from "../storage/metric-repo.js";
|
|
18
|
+
import { QueryRulesInput } from "../types.js";
|
|
19
|
+
export declare function handleQueryRules(input: QueryRulesInput, ruleRepo: RuleRepo, metricRepo: MetricRepo): Promise<{
|
|
20
|
+
content: {
|
|
21
|
+
type: string;
|
|
22
|
+
text: string;
|
|
23
|
+
}[];
|
|
24
|
+
}>;
|
|
25
|
+
//# sourceMappingURL=query-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-rules.d.ts","sourceRoot":"","sources":["../../src/tools/query-rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EAAE,eAAe,EAA8B,MAAM,aAAa,CAAC;AAS1E,wBAAsB,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU;;;;;GAoCxG"}
|