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.
Files changed (158) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +281 -0
  3. package/dist/cli.d.ts +18 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +66 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cognition-engine/ast-constraint-solver.d.ts +67 -0
  8. package/dist/cognition-engine/ast-constraint-solver.d.ts.map +1 -0
  9. package/dist/cognition-engine/ast-constraint-solver.js +294 -0
  10. package/dist/cognition-engine/ast-constraint-solver.js.map +1 -0
  11. package/dist/cognition-engine/constraint-validator.d.ts +35 -0
  12. package/dist/cognition-engine/constraint-validator.d.ts.map +1 -0
  13. package/dist/cognition-engine/constraint-validator.js +55 -0
  14. package/dist/cognition-engine/constraint-validator.js.map +1 -0
  15. package/dist/cognition-engine/graph-traverser.d.ts +43 -0
  16. package/dist/cognition-engine/graph-traverser.d.ts.map +1 -0
  17. package/dist/cognition-engine/graph-traverser.js +205 -0
  18. package/dist/cognition-engine/graph-traverser.js.map +1 -0
  19. package/dist/cognition-engine/index.d.ts +51 -0
  20. package/dist/cognition-engine/index.d.ts.map +1 -0
  21. package/dist/cognition-engine/index.js +60 -0
  22. package/dist/cognition-engine/index.js.map +1 -0
  23. package/dist/cognition-engine/intent-recognizer.d.ts +25 -0
  24. package/dist/cognition-engine/intent-recognizer.d.ts.map +1 -0
  25. package/dist/cognition-engine/intent-recognizer.js +226 -0
  26. package/dist/cognition-engine/intent-recognizer.js.map +1 -0
  27. package/dist/cognition-engine/types.d.ts +96 -0
  28. package/dist/cognition-engine/types.d.ts.map +1 -0
  29. package/dist/cognition-engine/types.js +17 -0
  30. package/dist/cognition-engine/types.js.map +1 -0
  31. package/dist/conflict/arbitrator.d.ts +24 -0
  32. package/dist/conflict/arbitrator.d.ts.map +1 -0
  33. package/dist/conflict/arbitrator.js +43 -0
  34. package/dist/conflict/arbitrator.js.map +1 -0
  35. package/dist/index.d.ts +17 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +90 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/legacy-engine/ast-diff.d.ts +23 -0
  40. package/dist/legacy-engine/ast-diff.d.ts.map +1 -0
  41. package/dist/legacy-engine/ast-diff.js +146 -0
  42. package/dist/legacy-engine/ast-diff.js.map +1 -0
  43. package/dist/legacy-engine/ast-node.d.ts +24 -0
  44. package/dist/legacy-engine/ast-node.d.ts.map +1 -0
  45. package/dist/legacy-engine/ast-node.js +52 -0
  46. package/dist/legacy-engine/ast-node.js.map +1 -0
  47. package/dist/legacy-engine/parsers.d.ts +34 -0
  48. package/dist/legacy-engine/parsers.d.ts.map +1 -0
  49. package/dist/legacy-engine/parsers.js +134 -0
  50. package/dist/legacy-engine/parsers.js.map +1 -0
  51. package/dist/legacy-engine/regex-fallback.d.ts +23 -0
  52. package/dist/legacy-engine/regex-fallback.d.ts.map +1 -0
  53. package/dist/legacy-engine/regex-fallback.js +40 -0
  54. package/dist/legacy-engine/regex-fallback.js.map +1 -0
  55. package/dist/legacy-engine/rule-generator.d.ts +31 -0
  56. package/dist/legacy-engine/rule-generator.d.ts.map +1 -0
  57. package/dist/legacy-engine/rule-generator.js +54 -0
  58. package/dist/legacy-engine/rule-generator.js.map +1 -0
  59. package/dist/legacy-engine/rule-matcher.d.ts +28 -0
  60. package/dist/legacy-engine/rule-matcher.d.ts.map +1 -0
  61. package/dist/legacy-engine/rule-matcher.js +79 -0
  62. package/dist/legacy-engine/rule-matcher.js.map +1 -0
  63. package/dist/legacy-engine/token-controller.d.ts +31 -0
  64. package/dist/legacy-engine/token-controller.d.ts.map +1 -0
  65. package/dist/legacy-engine/token-controller.js +66 -0
  66. package/dist/legacy-engine/token-controller.js.map +1 -0
  67. package/dist/middleware/response-validation.d.ts +27 -0
  68. package/dist/middleware/response-validation.d.ts.map +1 -0
  69. package/dist/middleware/response-validation.js +50 -0
  70. package/dist/middleware/response-validation.js.map +1 -0
  71. package/dist/modes/confirm.d.ts +29 -0
  72. package/dist/modes/confirm.d.ts.map +1 -0
  73. package/dist/modes/confirm.js +27 -0
  74. package/dist/modes/confirm.js.map +1 -0
  75. package/dist/modes/silent.d.ts +24 -0
  76. package/dist/modes/silent.d.ts.map +1 -0
  77. package/dist/modes/silent.js +24 -0
  78. package/dist/modes/silent.js.map +1 -0
  79. package/dist/resources/cognition-resources.d.ts +28 -0
  80. package/dist/resources/cognition-resources.d.ts.map +1 -0
  81. package/dist/resources/cognition-resources.js +124 -0
  82. package/dist/resources/cognition-resources.js.map +1 -0
  83. package/dist/storage/client.d.ts +26 -0
  84. package/dist/storage/client.d.ts.map +1 -0
  85. package/dist/storage/client.js +45 -0
  86. package/dist/storage/client.js.map +1 -0
  87. package/dist/storage/cognition-repository.d.ts +55 -0
  88. package/dist/storage/cognition-repository.d.ts.map +1 -0
  89. package/dist/storage/cognition-repository.js +287 -0
  90. package/dist/storage/cognition-repository.js.map +1 -0
  91. package/dist/storage/cognition-types.d.ts +96 -0
  92. package/dist/storage/cognition-types.d.ts.map +1 -0
  93. package/dist/storage/cognition-types.js +41 -0
  94. package/dist/storage/cognition-types.js.map +1 -0
  95. package/dist/storage/conflict-repo.d.ts +41 -0
  96. package/dist/storage/conflict-repo.d.ts.map +1 -0
  97. package/dist/storage/conflict-repo.js +67 -0
  98. package/dist/storage/conflict-repo.js.map +1 -0
  99. package/dist/storage/diff-log-repo.d.ts +48 -0
  100. package/dist/storage/diff-log-repo.d.ts.map +1 -0
  101. package/dist/storage/diff-log-repo.js +51 -0
  102. package/dist/storage/diff-log-repo.js.map +1 -0
  103. package/dist/storage/metric-repo.d.ts +20 -0
  104. package/dist/storage/metric-repo.d.ts.map +1 -0
  105. package/dist/storage/metric-repo.js +36 -0
  106. package/dist/storage/metric-repo.js.map +1 -0
  107. package/dist/storage/rule-repo.d.ts +66 -0
  108. package/dist/storage/rule-repo.d.ts.map +1 -0
  109. package/dist/storage/rule-repo.js +188 -0
  110. package/dist/storage/rule-repo.js.map +1 -0
  111. package/dist/tools/analyze-workspace.d.ts +26 -0
  112. package/dist/tools/analyze-workspace.d.ts.map +1 -0
  113. package/dist/tools/analyze-workspace.js +147 -0
  114. package/dist/tools/analyze-workspace.js.map +1 -0
  115. package/dist/tools/capture-diff.d.ts +26 -0
  116. package/dist/tools/capture-diff.d.ts.map +1 -0
  117. package/dist/tools/capture-diff.js +58 -0
  118. package/dist/tools/capture-diff.js.map +1 -0
  119. package/dist/tools/cognition-tools.d.ts +60 -0
  120. package/dist/tools/cognition-tools.d.ts.map +1 -0
  121. package/dist/tools/cognition-tools.js +170 -0
  122. package/dist/tools/cognition-tools.js.map +1 -0
  123. package/dist/tools/config-tools.d.ts +29 -0
  124. package/dist/tools/config-tools.d.ts.map +1 -0
  125. package/dist/tools/config-tools.js +58 -0
  126. package/dist/tools/config-tools.js.map +1 -0
  127. package/dist/tools/confirm-rule.d.ts +32 -0
  128. package/dist/tools/confirm-rule.d.ts.map +1 -0
  129. package/dist/tools/confirm-rule.js +64 -0
  130. package/dist/tools/confirm-rule.js.map +1 -0
  131. package/dist/tools/injection-approval.d.ts +43 -0
  132. package/dist/tools/injection-approval.d.ts.map +1 -0
  133. package/dist/tools/injection-approval.js +102 -0
  134. package/dist/tools/injection-approval.js.map +1 -0
  135. package/dist/tools/list-rules.d.ts +24 -0
  136. package/dist/tools/list-rules.d.ts.map +1 -0
  137. package/dist/tools/list-rules.js +20 -0
  138. package/dist/tools/list-rules.js.map +1 -0
  139. package/dist/tools/query-rules.d.ts +25 -0
  140. package/dist/tools/query-rules.d.ts.map +1 -0
  141. package/dist/tools/query-rules.js +65 -0
  142. package/dist/tools/query-rules.js.map +1 -0
  143. package/dist/tools/resolve-conflict.d.ts +33 -0
  144. package/dist/tools/resolve-conflict.d.ts.map +1 -0
  145. package/dist/tools/resolve-conflict.js +35 -0
  146. package/dist/tools/resolve-conflict.js.map +1 -0
  147. package/dist/types.d.ts +190 -0
  148. package/dist/types.d.ts.map +1 -0
  149. package/dist/types.js +50 -0
  150. package/dist/types.js.map +1 -0
  151. package/docs/api-reference.md +1229 -0
  152. package/docs/community/feedback-playbook.md +94 -0
  153. package/docs/integration-snippets.md +100 -0
  154. package/docs/mcp-integration-guide.md +151 -0
  155. package/docs/phase4-mcp-feedback.md +155 -0
  156. package/docs/trust-governance-protocol.md +72 -0
  157. package/package.json +74 -0
  158. package/prisma/schema.prisma +145 -0
@@ -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
+ /** Valid cognition node type values. */
17
+ export declare const COGNITION_TYPES: {
18
+ readonly INTENT: "INTENT";
19
+ readonly CONSTRAINT: "CONSTRAINT";
20
+ readonly HEURISTIC: "HEURISTIC";
21
+ readonly PATTERN: "PATTERN";
22
+ };
23
+ export type CognitionTypeStr = (typeof COGNITION_TYPES)[keyof typeof COGNITION_TYPES];
24
+ /** Valid edge relation values. */
25
+ export declare const EDGE_RELATIONS: {
26
+ readonly CAUSES: "CAUSES";
27
+ readonly PRECEDES: "PRECEDES";
28
+ readonly MUTEX: "MUTEX";
29
+ readonly GENERALIZES: "GENERALIZES";
30
+ readonly REFINES: "REFINES";
31
+ };
32
+ export type EdgeRelationStr = (typeof EDGE_RELATIONS)[keyof typeof EDGE_RELATIONS];
33
+ /** Abstraction levels for cognition nodes. */
34
+ export declare const ABSTRACTION_LEVELS: {
35
+ readonly CONCRETE: 0;
36
+ readonly FUNCTION: 1;
37
+ readonly MODULE: 2;
38
+ readonly ARCHITECTURE: 3;
39
+ };
40
+ export interface CognitionNodeInput {
41
+ type: CognitionTypeStr;
42
+ semanticHash: string;
43
+ abstractionLevel: number;
44
+ /** Structured data only (AST template JSON, constraint expressions). NEVER natural language. */
45
+ payload: Record<string, unknown>;
46
+ metadata?: Record<string, unknown>;
47
+ }
48
+ export interface CognitionEdgeInput {
49
+ sourceId: string;
50
+ targetId: string;
51
+ relation: EdgeRelationStr;
52
+ weight?: number;
53
+ metadata?: Record<string, unknown>;
54
+ }
55
+ export interface AstTemplateInput {
56
+ nodeId: string;
57
+ language: string;
58
+ /** DSL/JSON pattern for AST-level validation or transformation. NEVER natural language. */
59
+ templateDsl: string;
60
+ /** JSON Schema for validating templateDsl content. */
61
+ validationSchema?: Record<string, unknown>;
62
+ }
63
+ export interface CognitionNodeData {
64
+ id: string;
65
+ type: CognitionTypeStr;
66
+ semanticHash: string;
67
+ abstractionLevel: number;
68
+ payload: Record<string, unknown>;
69
+ metadata: Record<string, unknown> | null;
70
+ createdAt: Date;
71
+ updatedAt: Date;
72
+ astTemplate: AstTemplateData | null;
73
+ }
74
+ export interface CognitionEdgeData {
75
+ id: string;
76
+ sourceId: string;
77
+ targetId: string;
78
+ relation: EdgeRelationStr;
79
+ weight: number;
80
+ metadata: Record<string, unknown> | null;
81
+ createdAt: Date;
82
+ }
83
+ export interface AstTemplateData {
84
+ id: string;
85
+ nodeId: string;
86
+ language: string;
87
+ templateDsl: string;
88
+ validationSchema: Record<string, unknown> | null;
89
+ createdAt: Date;
90
+ }
91
+ /** Result of a subgraph traversal. */
92
+ export interface SubgraphResult {
93
+ nodes: CognitionNodeData[];
94
+ edges: CognitionEdgeData[];
95
+ }
96
+ //# sourceMappingURL=cognition-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognition-types.d.ts","sourceRoot":"","sources":["../../src/storage/cognition-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA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B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,WAAW,EAAE,eAAe,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACjD,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B"}
@@ -0,0 +1,41 @@
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
+ // ── Cognition Graph Type Definitions ───────────────────────
17
+ // Independent from src/types.ts. Do NOT modify existing types.
18
+ // Use String for JSON fields (SQLite limitation, consistent with codebase conventions).
19
+ /** Valid cognition node type values. */
20
+ export const COGNITION_TYPES = {
21
+ INTENT: "INTENT",
22
+ CONSTRAINT: "CONSTRAINT",
23
+ HEURISTIC: "HEURISTIC",
24
+ PATTERN: "PATTERN",
25
+ };
26
+ /** Valid edge relation values. */
27
+ export const EDGE_RELATIONS = {
28
+ CAUSES: "CAUSES",
29
+ PRECEDES: "PRECEDES",
30
+ MUTEX: "MUTEX",
31
+ GENERALIZES: "GENERALIZES",
32
+ REFINES: "REFINES",
33
+ };
34
+ /** Abstraction levels for cognition nodes. */
35
+ export const ABSTRACTION_LEVELS = {
36
+ CONCRETE: 0,
37
+ FUNCTION: 1,
38
+ MODULE: 2,
39
+ ARCHITECTURE: 3,
40
+ };
41
+ //# sourceMappingURL=cognition-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cognition-types.js","sourceRoot":"","sources":["../../src/storage/cognition-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,8DAA8D;AAC9D,+DAA+D;AAC/D,wFAAwF;AAExF,wCAAwC;AACxC,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;CACV,CAAC;AAIX,kCAAkC;AAClC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;CACV,CAAC;AAIX,8CAA8C;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,QAAQ,EAAE,CAAC;IACX,QAAQ,EAAE,CAAC;IACX,MAAM,EAAE,CAAC;IACT,YAAY,EAAE,CAAC;CACP,CAAC"}
@@ -0,0 +1,41 @@
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 { ConflictResolution } from "../types.js";
17
+ import { RuleRepo } from "./rule-repo.js";
18
+ export interface ConflictRecord {
19
+ id: string;
20
+ ruleAId: string;
21
+ ruleBId: string;
22
+ scopeKey: string;
23
+ resolution?: ConflictResolution;
24
+ batchChoice?: string;
25
+ resolvedAt?: Date;
26
+ createdAt: Date;
27
+ }
28
+ export declare class ConflictRepo {
29
+ private ruleRepo;
30
+ constructor(ruleRepo: RuleRepo);
31
+ findById(id: string): Promise<ConflictRecord | null>;
32
+ findExisting(ruleAId: string, ruleBId: string): Promise<ConflictRecord | null>;
33
+ create(data: {
34
+ ruleAId: string;
35
+ ruleBId: string;
36
+ scopeKey: string;
37
+ }): Promise<ConflictRecord>;
38
+ resolve(id: string, resolution: ConflictResolution): Promise<void>;
39
+ setBatchChoice(id: string, choice: string): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=conflict-repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conflict-repo.d.ts","sourceRoot":"","sources":["../../src/storage/conflict-repo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAC7C,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,IAAI,CAAC;CAC1D;AAED,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,QAAQ;IAEhC,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAYpD,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAe9E,MAAM,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAM7F,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlE,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAMhE"}
@@ -0,0 +1,67 @@
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
+ export class ConflictRepo {
18
+ ruleRepo;
19
+ constructor(ruleRepo) {
20
+ this.ruleRepo = ruleRepo;
21
+ }
22
+ async findById(id) {
23
+ const prisma = getPrismaClient();
24
+ const r = await prisma.conflictRecord.findUnique({ where: { id } });
25
+ if (!r)
26
+ return null;
27
+ return {
28
+ id: r.id, ruleAId: r.ruleAId, ruleBId: r.ruleBId,
29
+ scopeKey: r.scopeKey, resolution: r.resolution,
30
+ batchChoice: r.batchChoice ?? undefined, resolvedAt: r.resolvedAt ?? undefined,
31
+ createdAt: r.createdAt,
32
+ };
33
+ }
34
+ async findExisting(ruleAId, ruleBId) {
35
+ const prisma = getPrismaClient();
36
+ const r = await prisma.conflictRecord.findFirst({
37
+ where: { OR: [{ ruleAId, ruleBId }, { ruleAId: ruleBId, ruleBId: ruleAId }] },
38
+ orderBy: { createdAt: "desc" },
39
+ });
40
+ if (!r)
41
+ return null;
42
+ return {
43
+ id: r.id, ruleAId: r.ruleAId, ruleBId: r.ruleBId,
44
+ scopeKey: r.scopeKey, resolution: r.resolution,
45
+ batchChoice: r.batchChoice ?? undefined, resolvedAt: r.resolvedAt ?? undefined,
46
+ createdAt: r.createdAt,
47
+ };
48
+ }
49
+ async create(data) {
50
+ const prisma = getPrismaClient();
51
+ const r = await prisma.conflictRecord.create({ data });
52
+ return { id: r.id, ruleAId: r.ruleAId, ruleBId: r.ruleBId, scopeKey: r.scopeKey, createdAt: r.createdAt };
53
+ }
54
+ async resolve(id, resolution) {
55
+ const prisma = getPrismaClient();
56
+ await prisma.conflictRecord.update({
57
+ where: { id }, data: { resolution, resolvedAt: new Date() },
58
+ });
59
+ }
60
+ async setBatchChoice(id, choice) {
61
+ const prisma = getPrismaClient();
62
+ await prisma.conflictRecord.update({
63
+ where: { id }, data: { batchChoice: choice },
64
+ });
65
+ }
66
+ }
67
+ //# sourceMappingURL=conflict-repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conflict-repo.js","sourceRoot":"","sources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AM,EAAE;SAC7C,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,48 @@
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 interface DiffLogRecord {
17
+ id: string;
18
+ ruleId?: string;
19
+ filePath: string;
20
+ fileExtension: string;
21
+ language: string;
22
+ projectId?: string;
23
+ originalHash: string;
24
+ modifiedHash: string;
25
+ diffContent: string;
26
+ astStatus?: string;
27
+ diffType: string;
28
+ operations?: string;
29
+ createdAt: Date;
30
+ }
31
+ export declare class DiffLogRepo {
32
+ create(data: {
33
+ filePath: string;
34
+ fileExtension: string;
35
+ language: string;
36
+ projectId?: string;
37
+ originalHash: string;
38
+ modifiedHash: string;
39
+ diffContent: string;
40
+ astStatus?: string;
41
+ diffType: string;
42
+ operations?: string;
43
+ ruleId?: string;
44
+ }): Promise<DiffLogRecord>;
45
+ countByPattern(language: string, patternHash: string, sinceDays: number): Promise<number>;
46
+ countDistinctFiles(language: string, patternHash: string, sinceDays: number): Promise<number>;
47
+ }
48
+ //# sourceMappingURL=diff-log-repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-log-repo.d.ts","sourceRoot":"","sources":["../../src/storage/diff-log-repo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IACzD,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IACrC,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAChE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC1D,SAAS,EAAE,IAAI,CAAC;CACjB;AAcD,qBAAa,WAAW;IAChB,MAAM,CAAC,IAAI,EAAE;QACjB,QAAQ,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAC/D,WAAW,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;KACtC,GAAG,OAAO,CAAC,aAAa,CAAC;IAMpB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQzF,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CASpG"}
@@ -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
+ import { getPrismaClient } from "./client.js";
17
+ function toRecord(r) {
18
+ return {
19
+ id: r.id, ruleId: r.ruleId ?? undefined,
20
+ filePath: r.filePath, fileExtension: r.fileExtension,
21
+ language: r.language, projectId: r.projectId ?? undefined,
22
+ originalHash: r.originalHash, modifiedHash: r.modifiedHash,
23
+ diffContent: r.diffContent, astStatus: r.astStatus ?? undefined,
24
+ diffType: r.diffType, operations: r.operations ?? undefined,
25
+ createdAt: r.createdAt,
26
+ };
27
+ }
28
+ export class DiffLogRepo {
29
+ async create(data) {
30
+ const prisma = getPrismaClient();
31
+ const r = await prisma.diffLog.create({ data });
32
+ return toRecord(r);
33
+ }
34
+ async countByPattern(language, patternHash, sinceDays) {
35
+ const prisma = getPrismaClient();
36
+ const since = new Date(Date.now() - sinceDays * 86400000);
37
+ return prisma.diffLog.count({
38
+ where: { language, originalHash: patternHash, createdAt: { gte: since } },
39
+ });
40
+ }
41
+ async countDistinctFiles(language, patternHash, sinceDays) {
42
+ const prisma = getPrismaClient();
43
+ const since = new Date(Date.now() - sinceDays * 86400000);
44
+ const rows = await prisma.diffLog.findMany({
45
+ where: { language, originalHash: patternHash, createdAt: { gte: since } },
46
+ select: { filePath: true }, distinct: ["filePath"],
47
+ });
48
+ return rows.length;
49
+ }
50
+ }
51
+ //# sourceMappingURL=diff-log-repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diff-log-repo.js","sourceRoot":"","sources":["../../src/storage/diff-log-repo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAW9C,SAAS,QAAQ,CAAC,CAA+B;IAC/C,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC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Ae,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC;QAC1D,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;YACzC,KAAK,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;YACzE,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC;SACnD,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
@@ -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 declare class MetricRepo {
17
+ track(eventType: string, properties?: Record<string, unknown>): Promise<void>;
18
+ count(eventType: string, sinceMinutes?: number): Promise<number>;
19
+ }
20
+ //# sourceMappingURL=metric-repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metric-repo.d.ts","sourceRoot":"","sources":["../../src/storage/metric-repo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,qBAAa,UAAU;IACf,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7E,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQvE"}
@@ -0,0 +1,36 @@
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
+ export class MetricRepo {
18
+ async track(eventType, properties) {
19
+ const prisma = getPrismaClient();
20
+ await prisma.metricEvent.create({
21
+ data: {
22
+ eventType,
23
+ properties: properties ? JSON.stringify(properties) : null,
24
+ },
25
+ });
26
+ }
27
+ async count(eventType, sinceMinutes) {
28
+ const prisma = getPrismaClient();
29
+ const where = { eventType };
30
+ if (sinceMinutes) {
31
+ where.createdAt = { gte: new Date(Date.now() - sinceMinutes * 60000) };
32
+ }
33
+ return prisma.metricEvent.count({ where: where });
34
+ }
35
+ }
36
+ //# sourceMappingURL=metric-repo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metric-repo.js","sourceRoot":"","sources":["../../src/storage/metric-repo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,UAAU;IACrB,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,UAAoC;QACjE,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;QACjC,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC;YAC9B,IAAI,EAAE;gBACJ,SAAS;gBACT,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;aAC3D;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,SAAiB,EAAE,YAAqB;QAClD,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC;QACjC,MAAM,KAAK,GAA4B,EAAE,SAAS,EAAE,CAAC;QACrD,IAAI,YAAY,EAAE,CAAC;YACjB,KAAK,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,GAAG,KAAK,CAAC,EAAE,CAAC;QACzE,CAAC;QACD,OAAO,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,KAAY,EAAE,CAAC,CAAC;IAC3D,CAAC;CACF"}
@@ -0,0 +1,66 @@
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 { Prisma } from "@prisma/client";
17
+ import { Rule, RuleScope, RuleStatus, RuleSpec } from "../types.js";
18
+ export declare function toRule(r: Prisma.RuleGetPayload<{}>): Rule;
19
+ export declare class RuleRepo {
20
+ create(spec: RuleSpec & {
21
+ projectId?: string;
22
+ }): Promise<Rule>;
23
+ /** Batch create rules inside a single transaction to prevent duplicates under WAL mode. */
24
+ batchCreate(specs: (RuleSpec & {
25
+ projectId?: string;
26
+ })[]): Promise<Rule[]>;
27
+ findById(id: string): Promise<Rule | null>;
28
+ updateStatus(id: string, status: RuleStatus): Promise<Rule>;
29
+ incrementMatchCount(id: string): Promise<void>;
30
+ countByScope(scope: RuleScope): Promise<number>;
31
+ isLimitReached(): Promise<boolean>;
32
+ /** Return detailed limit info including current counts and max thresholds. */
33
+ getLimitInfo(projectId?: string): Promise<{
34
+ reached: boolean;
35
+ globalCount: number;
36
+ globalMax: number;
37
+ projectCount: number;
38
+ projectMax: number;
39
+ }>;
40
+ findConflicting(type: string, language: string, pattern: string): Promise<Rule[]>;
41
+ /** Update a rule's pattern, suggestion, and/or category. Returns the updated rule. */
42
+ updateContent(id: string, data: {
43
+ pattern?: string;
44
+ suggestion?: string;
45
+ category?: string;
46
+ editedBy?: string;
47
+ }): Promise<Rule>;
48
+ getRuleVersions(ruleId: string): Promise<{
49
+ id: string;
50
+ ruleId: string;
51
+ pattern: string;
52
+ suggestion: string | null;
53
+ editedBy: string | null;
54
+ createdAt: Date;
55
+ }[]>;
56
+ queryByMatch(language: string, fileExtension: string, projectId?: string, tags?: string[]): Promise<Rule[]>;
57
+ list(filters: {
58
+ language?: string;
59
+ scope?: RuleScope;
60
+ status?: RuleStatus;
61
+ projectId?: string;
62
+ limit?: number;
63
+ offset?: number;
64
+ }): Promise<Rule[]>;
65
+ }
66
+ //# sourceMappingURL=rule-repo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rule-repo.d.ts","sourceRoot":"","sources":["../../src/storage/rule-repo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAgB,MAAM,aAAa,CAAC;AAElF,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,GAAG,IAAI,CAqBzD;AAED,qBAAa,QAAQ;IACb,MAAM,CAAC,IAAI,EAAE,QAAQ,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,C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