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 @@
|
|
|
1
|
+
{"version":3,"file":"graph-traverser.js","sourceRoot":"","sources":["../../src/cognition-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I,CAAC,WAAW;YAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC;QAE7D,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC;IACvC,CAAC;CACF;AAED,6DAA6D;AAE7D,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;QAC9C,IAAI,IAAI,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 — unified entry point.
|
|
18
|
+
*
|
|
19
|
+
* The cognition engine replaces the legacy rule-matcher with a
|
|
20
|
+
* three-component pipeline:
|
|
21
|
+
*
|
|
22
|
+
* 1. IntentRecognizer — classifies diff type (REFACTOR / BUGFIX / BOILERPLATE)
|
|
23
|
+
* 2. GraphTraverser — weighted BFS over cognition graph
|
|
24
|
+
* 3. AstConstraintSolver — transforms templates into AST-level checks
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
* import { analyzeCodeContext } from "./cognition-engine/index.js";
|
|
28
|
+
* const result = await analyzeCodeContext(lang, path, content);
|
|
29
|
+
*/
|
|
30
|
+
export { recognizeIntent } from "./intent-recognizer.js";
|
|
31
|
+
export type { IntentResult, IntentType } from "./types.js";
|
|
32
|
+
export { GraphTraverser } from "./graph-traverser.js";
|
|
33
|
+
export type { TraversalOptions, TraversalResult, ScoredCognitionNode } from "./types.js";
|
|
34
|
+
export { solveConstraints, parseConstraintDsl, bindConstraints, validateConstraints, generatePatchFromFailures, } from "./ast-constraint-solver.js";
|
|
35
|
+
export type { AstConstraint, FieldConstraint, ValidationResult, TransformPatch } from "./types.js";
|
|
36
|
+
import type { TraversalResult, ValidationResult, TransformPatch, IntentResult } from "./types.js";
|
|
37
|
+
/**
|
|
38
|
+
* Full pipeline: analyze diff → traverse graph → solve AST constraints.
|
|
39
|
+
* The one-shot entry point for the cognition engine.
|
|
40
|
+
*/
|
|
41
|
+
export declare function analyzeCodeContext(diffContent: string, filePath: string, language: string, fileContent: string): Promise<{
|
|
42
|
+
intent: IntentResult;
|
|
43
|
+
traversal: TraversalResult;
|
|
44
|
+
constraints: {
|
|
45
|
+
validations: ValidationResult[];
|
|
46
|
+
patches: TransformPatch[];
|
|
47
|
+
boundValues: Record<string, string>;
|
|
48
|
+
};
|
|
49
|
+
durationMs: number;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cognition-engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEzF,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAKnG,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElG;;;GAGG;AACH,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC;IACT,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,EAAE,eAAe,CAAC;IAC3B,WAAW,EAAE;QACX,WAAW,EAAE,gBAAgB,EAAE,CAAC;QAChC,OAAO,EAAE,cAAc,EAAE,CAAC;QAC1B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACrC,CAAC;IACF,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAuBD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 — unified entry point.
|
|
18
|
+
*
|
|
19
|
+
* The cognition engine replaces the legacy rule-matcher with a
|
|
20
|
+
* three-component pipeline:
|
|
21
|
+
*
|
|
22
|
+
* 1. IntentRecognizer — classifies diff type (REFACTOR / BUGFIX / BOILERPLATE)
|
|
23
|
+
* 2. GraphTraverser — weighted BFS over cognition graph
|
|
24
|
+
* 3. AstConstraintSolver — transforms templates into AST-level checks
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
* import { analyzeCodeContext } from "./cognition-engine/index.js";
|
|
28
|
+
* const result = await analyzeCodeContext(lang, path, content);
|
|
29
|
+
*/
|
|
30
|
+
export { recognizeIntent } from "./intent-recognizer.js";
|
|
31
|
+
export { GraphTraverser } from "./graph-traverser.js";
|
|
32
|
+
export { solveConstraints, parseConstraintDsl, bindConstraints, validateConstraints, generatePatchFromFailures, } from "./ast-constraint-solver.js";
|
|
33
|
+
import { recognizeIntent } from "./intent-recognizer.js";
|
|
34
|
+
import { GraphTraverser } from "./graph-traverser.js";
|
|
35
|
+
import { solveConstraints } from "./ast-constraint-solver.js";
|
|
36
|
+
/**
|
|
37
|
+
* Full pipeline: analyze diff → traverse graph → solve AST constraints.
|
|
38
|
+
* The one-shot entry point for the cognition engine.
|
|
39
|
+
*/
|
|
40
|
+
export async function analyzeCodeContext(diffContent, filePath, language, fileContent) {
|
|
41
|
+
const startTime = performance.now();
|
|
42
|
+
// Stage 1: Intent Recognition
|
|
43
|
+
const intent = await recognizeIntent(diffContent, filePath);
|
|
44
|
+
// Stage 2: Graph Traversal (biased by recognized intent)
|
|
45
|
+
const traverser = new GraphTraverser();
|
|
46
|
+
const traversal = await traverser.traverse(language, filePath, diffContent, {
|
|
47
|
+
intentHint: intent.intent,
|
|
48
|
+
maxDepth: intent.intent === "REFACTOR" ? 5 : 3,
|
|
49
|
+
});
|
|
50
|
+
// Stage 3: AST Constraint Solving
|
|
51
|
+
const nodeDataList = traversal.nodes.map((sn) => sn.node);
|
|
52
|
+
const constraints = await solveConstraints(nodeDataList, fileContent, language);
|
|
53
|
+
return {
|
|
54
|
+
intent,
|
|
55
|
+
traversal,
|
|
56
|
+
constraints,
|
|
57
|
+
durationMs: performance.now() - startTime,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cognition-engine/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAG9D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,WAAmB,EACnB,QAAgB,EAChB,QAAgB,EAChB,WAAmB;IAWnB,MAAM,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAEpC,8BAA8B;IAC9B,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAE5D,yDAAyD;IACzD,MAAM,SAAS,GAAG,IAAI,cAAc,EAAE,CAAC;IACvC,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE;QAC1E,UAAU,EAAE,MAAM,CAAC,MAAM;QACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC/C,CAAC,CAAC;IAEH,kCAAkC;IAClC,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,WAAW,GAAG,MAAM,gBAAgB,CAAC,YAAY,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IAEhF,OAAO;QACL,MAAM;QACN,SAAS;QACT,WAAW;QACX,UAAU,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS;KAC1C,CAAC;AACJ,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 type { IntentResult } from "./types.js";
|
|
17
|
+
/**
|
|
18
|
+
* Analyze a code diff and classify the developer intent.
|
|
19
|
+
*
|
|
20
|
+
* @param diffContent Unified diff text (from git diff output)
|
|
21
|
+
* @param filePath Optional file path for AST analysis
|
|
22
|
+
* @returns Structured intent classification
|
|
23
|
+
*/
|
|
24
|
+
export declare function recognizeIntent(diffContent: string, filePath?: string): Promise<IntentResult>;
|
|
25
|
+
//# sourceMappingURL=intent-recognizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-recognizer.d.ts","sourceRoot":"","sources":["../../src/cognition-engine/intent-recognizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAaH,OAAO,KAAK,EAAE,YAAY,EAAc,MAAM,YAAY,CAAC;AAiN3D;;;;;;GAMG;AACH,wBAAsB,eAAe,CACnC,WAAW,EAAE,MAAM,EACnB,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,YAAY,CAAC,CAgBvB"}
|
|
@@ -0,0 +1,226 @@
|
|
|
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 Intent Recognizer
|
|
18
|
+
* Analyzes code diffs and classifies the developer intent behind them.
|
|
19
|
+
* Maps to three intent levels: REFACTOR, BUGFIX, BOILERPLATE.
|
|
20
|
+
* The result biases Graph Traverser traversal strategy.
|
|
21
|
+
*
|
|
22
|
+
* Reuses: legacy-engine/parsers.ts (parseToAST) for optional AST analysis
|
|
23
|
+
*/
|
|
24
|
+
import { parseToAST } from "../legacy-engine/parsers.js";
|
|
25
|
+
// ── Constants ─────────────────────────────────────────────
|
|
26
|
+
const REFACTOR_THRESHOLD = { minFiles: 2, minAddedRatio: 0.3, minNodeTypes: 3 };
|
|
27
|
+
const BUGFIX_THRESHOLD = { maxFiles: 2, maxChangedLines: 50, errorKeywordRatio: 0.1 };
|
|
28
|
+
const BOILERPLATE_THRESHOLD = { addRemoveRatio: 5.0, minAddedLines: 20 };
|
|
29
|
+
const ERROR_KEYWORDS = [
|
|
30
|
+
"error", "undefined", "null", "catch", "throw", "try",
|
|
31
|
+
"fail", "invalid", "missing", "fallback", "guard", "check",
|
|
32
|
+
"assert", "validate", "optional", "??", "?. ", "??=",
|
|
33
|
+
];
|
|
34
|
+
const REFACTOR_KEYWORDS = [
|
|
35
|
+
"extract", "rename", "move", "split", "merge", "inline",
|
|
36
|
+
"abstract", "interface", "type",
|
|
37
|
+
];
|
|
38
|
+
function parseDiffStats(diffContent) {
|
|
39
|
+
const stats = {
|
|
40
|
+
filesChanged: 0,
|
|
41
|
+
addedLines: 0,
|
|
42
|
+
removedLines: 0,
|
|
43
|
+
perFile: new Map(),
|
|
44
|
+
hunks: 0,
|
|
45
|
+
};
|
|
46
|
+
let currentFile = "unknown";
|
|
47
|
+
for (const line of diffContent.split("\n")) {
|
|
48
|
+
if (line.startsWith("diff --git ")) {
|
|
49
|
+
stats.filesChanged++;
|
|
50
|
+
const match = line.match(/diff --git a\/(.+) b\//);
|
|
51
|
+
if (match)
|
|
52
|
+
currentFile = match[1];
|
|
53
|
+
if (!stats.perFile.has(currentFile)) {
|
|
54
|
+
stats.perFile.set(currentFile, { added: 0, removed: 0 });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (line.startsWith("@@ ")) {
|
|
58
|
+
stats.hunks++;
|
|
59
|
+
}
|
|
60
|
+
else if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
61
|
+
stats.addedLines++;
|
|
62
|
+
const pf = stats.perFile.get(currentFile);
|
|
63
|
+
if (pf)
|
|
64
|
+
pf.added++;
|
|
65
|
+
}
|
|
66
|
+
else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
67
|
+
stats.removedLines++;
|
|
68
|
+
const pf = stats.perFile.get(currentFile);
|
|
69
|
+
if (pf)
|
|
70
|
+
pf.removed++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return stats;
|
|
74
|
+
}
|
|
75
|
+
// ── Node Type Analysis ────────────────────────────────────
|
|
76
|
+
async function analyzeNodeTypes(diffContent, filePath) {
|
|
77
|
+
const nodeTypes = new Set();
|
|
78
|
+
const lines = diffContent.split("\n");
|
|
79
|
+
// Try AST analysis on file content (best effort)
|
|
80
|
+
if (filePath) {
|
|
81
|
+
for (const line of lines) {
|
|
82
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
83
|
+
const code = line.slice(1).trim();
|
|
84
|
+
if (code.length > 3) {
|
|
85
|
+
try {
|
|
86
|
+
const lang = filePath.endsWith(".ts") || filePath.endsWith(".tsx")
|
|
87
|
+
? "typescript" : filePath.endsWith(".py") ? "python" : "javascript";
|
|
88
|
+
const result = await parseToAST(code, lang);
|
|
89
|
+
collectNodeTypes(result.ast, nodeTypes);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Silently continue — AST analysis is best-effort
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// Fallback: keyword-based detection
|
|
99
|
+
const allText = lines.filter(l => l.startsWith("+") || l.startsWith("-")).join(" ").toLowerCase();
|
|
100
|
+
if (!nodeTypes.size) {
|
|
101
|
+
const keywordMap = {
|
|
102
|
+
function_declaration: ["function", "=>", "=>"],
|
|
103
|
+
class_declaration: ["class "],
|
|
104
|
+
variable_declaration: ["const ", "let ", "var "],
|
|
105
|
+
if_statement: ["if ", "else "],
|
|
106
|
+
try_statement: ["try ", "catch ", "finally"],
|
|
107
|
+
import_statement: ["import ", "require("],
|
|
108
|
+
export_statement: ["export "],
|
|
109
|
+
interface_declaration: ["interface "],
|
|
110
|
+
type_alias: ["type ", "| ", "& "],
|
|
111
|
+
return_statement: ["return "],
|
|
112
|
+
};
|
|
113
|
+
for (const [nt, keywords] of Object.entries(keywordMap)) {
|
|
114
|
+
if (keywords.some(k => allText.includes(k))) {
|
|
115
|
+
nodeTypes.add(nt);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return [...nodeTypes];
|
|
120
|
+
}
|
|
121
|
+
function collectNodeTypes(node, types) {
|
|
122
|
+
types.add(node.type);
|
|
123
|
+
for (const child of node.children) {
|
|
124
|
+
collectNodeTypes(child, types);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// ── Intent Classification ─────────────────────────────────
|
|
128
|
+
function classifyIntent(stats, nodeTypes, diffContent) {
|
|
129
|
+
const totalChanged = stats.addedLines + stats.removedLines;
|
|
130
|
+
const addRemoveRatio = stats.removedLines > 0
|
|
131
|
+
? stats.addedLines / stats.removedLines
|
|
132
|
+
: stats.addedLines > 0 ? Infinity : 0;
|
|
133
|
+
const allText = diffContent.toLowerCase();
|
|
134
|
+
const errorHits = ERROR_KEYWORDS.filter(k => allText.includes(k)).length;
|
|
135
|
+
const errorRatio = allText.length > 0 ? errorHits / (allText.split("\n").length) : 0;
|
|
136
|
+
const refactorHits = REFACTOR_KEYWORDS.filter(k => allText.includes(k)).length;
|
|
137
|
+
const uniqueNodeTypes = new Set(nodeTypes);
|
|
138
|
+
const reasoning = [];
|
|
139
|
+
let scores = { refactor: 0, bugfix: 0, boilerplate: 0 };
|
|
140
|
+
// REFACTOR signals
|
|
141
|
+
if (stats.filesChanged >= REFACTOR_THRESHOLD.minFiles) {
|
|
142
|
+
scores.refactor += 0.3;
|
|
143
|
+
reasoning.push(`multi-file change (${stats.filesChanged} files)`);
|
|
144
|
+
}
|
|
145
|
+
if (uniqueNodeTypes.size >= REFACTOR_THRESHOLD.minNodeTypes) {
|
|
146
|
+
scores.refactor += 0.2;
|
|
147
|
+
reasoning.push(`diverse AST types affected (${uniqueNodeTypes.size} types)`);
|
|
148
|
+
}
|
|
149
|
+
if (refactorHits > 2) {
|
|
150
|
+
scores.refactor += 0.2;
|
|
151
|
+
reasoning.push('refactoring keywords detected');
|
|
152
|
+
}
|
|
153
|
+
if (stats.hunks > 3 && stats.filesChanged > 1) {
|
|
154
|
+
scores.refactor += 0.3;
|
|
155
|
+
reasoning.push('cross-module structural changes');
|
|
156
|
+
}
|
|
157
|
+
// BUGFIX signals
|
|
158
|
+
if (totalChanged <= BUGFIX_THRESHOLD.maxChangedLines) {
|
|
159
|
+
scores.bugfix += 0.2;
|
|
160
|
+
reasoning.push(`small change footprint (${totalChanged} lines)`);
|
|
161
|
+
}
|
|
162
|
+
if (stats.filesChanged <= BUGFIX_THRESHOLD.maxFiles) {
|
|
163
|
+
scores.bugfix += 0.1;
|
|
164
|
+
}
|
|
165
|
+
if (errorRatio >= BUGFIX_THRESHOLD.errorKeywordRatio) {
|
|
166
|
+
scores.bugfix += 0.3;
|
|
167
|
+
reasoning.push('error-handling keywords present');
|
|
168
|
+
}
|
|
169
|
+
if (uniqueNodeTypes.has("try_statement") || uniqueNodeTypes.has("if_statement")) {
|
|
170
|
+
scores.bugfix += 0.2;
|
|
171
|
+
reasoning.push(`conditional / guard patterns`);
|
|
172
|
+
}
|
|
173
|
+
// BOILERPLATE signals
|
|
174
|
+
if (addRemoveRatio >= BOILERPLATE_THRESHOLD.addRemoveRatio) {
|
|
175
|
+
scores.boilerplate += 0.3;
|
|
176
|
+
reasoning.push(`high add/remove ratio (${addRemoveRatio.toFixed(1)})`);
|
|
177
|
+
}
|
|
178
|
+
if (stats.addedLines >= BOILERPLATE_THRESHOLD.minAddedLines && stats.removedLines < 5) {
|
|
179
|
+
scores.boilerplate += 0.3;
|
|
180
|
+
reasoning.push('net-new code addition');
|
|
181
|
+
}
|
|
182
|
+
if (uniqueNodeTypes.size <= 2 && stats.addedLines > 10) {
|
|
183
|
+
scores.boilerplate += 0.2;
|
|
184
|
+
reasoning.push('repetitive / template-like structure');
|
|
185
|
+
}
|
|
186
|
+
const maxScore = Math.max(scores.refactor, scores.bugfix, scores.boilerplate);
|
|
187
|
+
if (maxScore === 0) {
|
|
188
|
+
return { intent: "BUGFIX", confidence: 0.3, reasoning: ["no clear signal"] };
|
|
189
|
+
}
|
|
190
|
+
let intent;
|
|
191
|
+
if (scores.refactor >= maxScore && scores.refactor >= 0.4)
|
|
192
|
+
intent = "REFACTOR";
|
|
193
|
+
else if (scores.boilerplate >= maxScore && scores.boilerplate >= 0.3)
|
|
194
|
+
intent = "BOILERPLATE";
|
|
195
|
+
else
|
|
196
|
+
intent = "BUGFIX";
|
|
197
|
+
const confidence = Math.min(0.95, maxScore + 0.2);
|
|
198
|
+
if (reasoning.length === 0)
|
|
199
|
+
reasoning.push("default classification");
|
|
200
|
+
return { intent, confidence, reasoning };
|
|
201
|
+
}
|
|
202
|
+
// ── Public API ────────────────────────────────────────────
|
|
203
|
+
/**
|
|
204
|
+
* Analyze a code diff and classify the developer intent.
|
|
205
|
+
*
|
|
206
|
+
* @param diffContent Unified diff text (from git diff output)
|
|
207
|
+
* @param filePath Optional file path for AST analysis
|
|
208
|
+
* @returns Structured intent classification
|
|
209
|
+
*/
|
|
210
|
+
export async function recognizeIntent(diffContent, filePath) {
|
|
211
|
+
const stats = parseDiffStats(diffContent);
|
|
212
|
+
const nodeTypes = await analyzeNodeTypes(diffContent, filePath);
|
|
213
|
+
const { intent, confidence, reasoning } = classifyIntent(stats, nodeTypes, diffContent);
|
|
214
|
+
return {
|
|
215
|
+
intent,
|
|
216
|
+
confidence,
|
|
217
|
+
reasoning,
|
|
218
|
+
stats: {
|
|
219
|
+
addedLines: stats.addedLines,
|
|
220
|
+
removedLines: stats.removedLines,
|
|
221
|
+
filesChanged: stats.filesChanged,
|
|
222
|
+
nodeTypeChanges: nodeTypes,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=intent-recognizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent-recognizer.js","sourceRoot":"","sources":["../../src/cognition-engine/intent-recognizer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAIzD,6DAA6D;AAE7D,MAAM,kBAAkB,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,aAAa,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;AAChF,MAAM,gBAAgB,GAAG,EAAE,QAAQ,EAAE,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,iBAAiB,EAAE,GAAG,EAAE,CAAC;AACtF,MAAM,qBAAqB,GAAG,EAAE,cAAc,EAAE,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;AAEzE,MAAM,cAAc,GAAG;IACrB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK;IACrD,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO;IAC1D,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK;CACrD,CAAC;AAEF,MAAM,iBAAiB,GAAG;IACxB,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ;IACvD,UAAU,EAAE,WAAW,EAAE,MAAM;CAChC,CAAC;AAYF,SAAS,cAAc,CAAC,WAAmB;IACzC,MAAM,KAAK,GAAc;QACvB,YAAY,EAAE,CAAC;QACf,UAAU,EAAE,CAAC;QACb,YAAY,EAAE,CAAC;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AC;SAC1E,IAAI,MAAM,CAAC,WAAW,IAAI,QAAQ,IAAI,MAAM,CAAC,WAAW,IAAI,GAAG;QAAE,MAAM,GAAG,aAAa,CAAC;;QACxF,MAAM,GAAG,QAAQ,CAAC;IAEvB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,GAAG,CAAC,CAAC;IAElD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,SAAS,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACrE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAC3C,CAAC;AAED,6DAA6D;AAE7D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,WAAmB,EACnB,QAAiB;IAEjB,MAAM,KAAK,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAChE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;IAExF,OAAO;QACL,MAAM;QACN,UAAU;QACV,SAAS;QACT,KAAK,EAAE;YACL,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,YAAY,EAAE,KAAK,CAAC,YAAY;YAChC,eAAe,EAAE,SAAS;SAC3B;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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 — type definitions.
|
|
18
|
+
* These types are specific to the cognition engine pipeline.
|
|
19
|
+
* Shared types consumed by tools live in ../types.js.
|
|
20
|
+
*/
|
|
21
|
+
import type { CognitionNodeData, CognitionEdgeData } from "../storage/cognition-types.js";
|
|
22
|
+
export type IntentType = "REFACTOR" | "BUGFIX" | "BOILERPLATE";
|
|
23
|
+
export interface IntentResult {
|
|
24
|
+
intent: IntentType;
|
|
25
|
+
confidence: number;
|
|
26
|
+
reasoning: string[];
|
|
27
|
+
/** Diff statistics used for classification. */
|
|
28
|
+
stats: {
|
|
29
|
+
addedLines: number;
|
|
30
|
+
removedLines: number;
|
|
31
|
+
filesChanged: number;
|
|
32
|
+
nodeTypeChanges: string[];
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface TraversalOptions {
|
|
36
|
+
/** Max BFS depth. Default 5. */
|
|
37
|
+
maxDepth?: number;
|
|
38
|
+
/** Minimum relevance score [0, 1] to include in results. */
|
|
39
|
+
minRelevance?: number;
|
|
40
|
+
/** Optional intent hint to bias edge weights. */
|
|
41
|
+
intentHint?: IntentType;
|
|
42
|
+
/** If set, only include nodes at these abstraction levels. */
|
|
43
|
+
abstractionLevelFilter?: number[];
|
|
44
|
+
/** Hard timeout in ms. Default 500. */
|
|
45
|
+
maxDurationMs?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface ScoredCognitionNode {
|
|
48
|
+
node: CognitionNodeData;
|
|
49
|
+
relevanceScore: number;
|
|
50
|
+
/** Path trace: how this node was reached (edge trail). */
|
|
51
|
+
trace: string[];
|
|
52
|
+
}
|
|
53
|
+
export interface TraversalResult {
|
|
54
|
+
nodes: ScoredCognitionNode[];
|
|
55
|
+
edges: CognitionEdgeData[];
|
|
56
|
+
durationMs: number;
|
|
57
|
+
truncated: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** DSL constraint: must be JSON-serializable for storage. */
|
|
60
|
+
export interface AstConstraint {
|
|
61
|
+
nodeType: string;
|
|
62
|
+
fields: Record<string, FieldConstraint>;
|
|
63
|
+
}
|
|
64
|
+
export interface FieldConstraint {
|
|
65
|
+
match?: string;
|
|
66
|
+
exists?: boolean;
|
|
67
|
+
childType?: string;
|
|
68
|
+
childCount?: {
|
|
69
|
+
min?: number;
|
|
70
|
+
max?: number;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export interface ValidationFailure {
|
|
74
|
+
nodeId: string;
|
|
75
|
+
templateDsl: string;
|
|
76
|
+
constraintPath: string;
|
|
77
|
+
expected: string;
|
|
78
|
+
actual: string;
|
|
79
|
+
}
|
|
80
|
+
export interface ValidationResult {
|
|
81
|
+
isValid: boolean;
|
|
82
|
+
failures: ValidationFailure[];
|
|
83
|
+
}
|
|
84
|
+
export type TransformOpType = "REPLACE" | "INSERT" | "DELETE";
|
|
85
|
+
export interface TransformOp {
|
|
86
|
+
type: TransformOpType;
|
|
87
|
+
path: string;
|
|
88
|
+
value?: string;
|
|
89
|
+
originalText?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface TransformPatch {
|
|
92
|
+
nodeId: string;
|
|
93
|
+
operations: TransformOp[];
|
|
94
|
+
description: string;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/cognition-engine/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAGlB,MAAM,+BAA+B,CAAC;AAIvC,MAA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CAAC;IACnB,UAAU,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAED,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE9D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,eAAe,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,WAAW,EAAE,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {};
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/cognition-engine/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|
|
@@ -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 { Rule, ConflictResolution, RuleSpec } from "../types.js";
|
|
17
|
+
export interface ConflictCheck {
|
|
18
|
+
hasConflict: boolean;
|
|
19
|
+
reason?: string;
|
|
20
|
+
scopeKey?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function detectConflict(ruleA: Rule, ruleB: Rule): ConflictCheck;
|
|
23
|
+
export declare function applyResolution(ruleA: Rule, ruleB: Rule, resolution: ConflictResolution): RuleSpec | undefined;
|
|
24
|
+
//# sourceMappingURL=arbitrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arbitrator.d.ts","sourceRoot":"","sources":["../../src/conflict/arbitrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEjE,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;CAC1D;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,aAAa,CAUtE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,kBAAkB,GAAG,QAAQ,GAAG,SAAS,CAW9G"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 function detectConflict(ruleA, ruleB) {
|
|
17
|
+
if (ruleA.type !== ruleB.type)
|
|
18
|
+
return { hasConflict: false };
|
|
19
|
+
if (ruleA.language !== ruleB.language)
|
|
20
|
+
return { hasConflict: false };
|
|
21
|
+
if (ruleA.pattern !== ruleB.pattern)
|
|
22
|
+
return { hasConflict: false };
|
|
23
|
+
if (ruleA.suggestion === ruleB.suggestion)
|
|
24
|
+
return { hasConflict: false };
|
|
25
|
+
return {
|
|
26
|
+
hasConflict: true,
|
|
27
|
+
reason: `same scope with different suggestions: "${ruleA.suggestion}" vs "${ruleB.suggestion}"`,
|
|
28
|
+
scopeKey: `${ruleA.scope}:${ruleB.scope}:${ruleA.type}:${ruleA.language}:${ruleA.pattern}`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function applyResolution(ruleA, ruleB, resolution) {
|
|
32
|
+
if (resolution === "keep_a") {
|
|
33
|
+
return { type: ruleA.type, pattern: ruleA.pattern, suggestion: ruleA.suggestion, language: ruleA.language, scope: ruleA.scope, tags: [...new Set([...(ruleA.tags ?? []), ...(ruleB.tags ?? [])])], category: "arbitration", source: "arbitration" };
|
|
34
|
+
}
|
|
35
|
+
if (resolution === "keep_b") {
|
|
36
|
+
return { type: ruleB.type, pattern: ruleB.pattern, suggestion: ruleB.suggestion, language: ruleB.language, scope: ruleB.scope, tags: [...new Set([...(ruleA.tags ?? []), ...(ruleB.tags ?? [])])], category: "arbitration", source: "arbitration" };
|
|
37
|
+
}
|
|
38
|
+
if (resolution === "merge") {
|
|
39
|
+
return { type: "convention", pattern: ruleA.pattern, suggestion: `${ruleA.suggestion}\n// Alternative: ${ruleB.suggestion}`, language: ruleA.language, confidence: "medium", category: "arbitration", source: "arbitration" };
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=arbitrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arbitrator.js","sourceRoot":"","sources":["../../src/conflict/arbitrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAQH,MAAM,UAAU,cAAc,CAAC,KAAW,EAAE,KAAW;IACrD,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI;QAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IAC7D,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ;QAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IACrE,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO;QAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC;IACnE,IAAI,KAA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,IAAI,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IACtP,CAAC;IACD,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,UAAU,qBAAqB,KAAK,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;IAChO,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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 {};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
|