critical-gate 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +240 -0
  3. package/dist/cli.d.ts +20 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +224 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/config/critical-gate-config.d.ts +21 -0
  8. package/dist/config/critical-gate-config.d.ts.map +1 -0
  9. package/dist/config/critical-gate-config.js +81 -0
  10. package/dist/config/critical-gate-config.js.map +1 -0
  11. package/dist/config/index.d.ts +2 -0
  12. package/dist/config/index.d.ts.map +1 -0
  13. package/dist/config/index.js +2 -0
  14. package/dist/config/index.js.map +1 -0
  15. package/dist/detectors/api-surface-detector.d.ts +3 -0
  16. package/dist/detectors/api-surface-detector.d.ts.map +1 -0
  17. package/dist/detectors/api-surface-detector.js +111 -0
  18. package/dist/detectors/api-surface-detector.js.map +1 -0
  19. package/dist/detectors/blast-radius-detector.d.ts +3 -0
  20. package/dist/detectors/blast-radius-detector.d.ts.map +1 -0
  21. package/dist/detectors/blast-radius-detector.js +90 -0
  22. package/dist/detectors/blast-radius-detector.js.map +1 -0
  23. package/dist/detectors/config-change-detector.d.ts +3 -0
  24. package/dist/detectors/config-change-detector.d.ts.map +1 -0
  25. package/dist/detectors/config-change-detector.js +68 -0
  26. package/dist/detectors/config-change-detector.js.map +1 -0
  27. package/dist/detectors/dependency-detector.d.ts +3 -0
  28. package/dist/detectors/dependency-detector.d.ts.map +1 -0
  29. package/dist/detectors/dependency-detector.js +98 -0
  30. package/dist/detectors/dependency-detector.js.map +1 -0
  31. package/dist/detectors/existing-solution-detector.d.ts +3 -0
  32. package/dist/detectors/existing-solution-detector.d.ts.map +1 -0
  33. package/dist/detectors/existing-solution-detector.js +87 -0
  34. package/dist/detectors/existing-solution-detector.js.map +1 -0
  35. package/dist/detectors/expected-companions-detector.d.ts +3 -0
  36. package/dist/detectors/expected-companions-detector.d.ts.map +1 -0
  37. package/dist/detectors/expected-companions-detector.js +65 -0
  38. package/dist/detectors/expected-companions-detector.js.map +1 -0
  39. package/dist/detectors/index.d.ts +17 -0
  40. package/dist/detectors/index.d.ts.map +1 -0
  41. package/dist/detectors/index.js +16 -0
  42. package/dist/detectors/index.js.map +1 -0
  43. package/dist/detectors/intent-verification-detector.d.ts +3 -0
  44. package/dist/detectors/intent-verification-detector.d.ts.map +1 -0
  45. package/dist/detectors/intent-verification-detector.js +43 -0
  46. package/dist/detectors/intent-verification-detector.js.map +1 -0
  47. package/dist/detectors/pattern-violation-detector.d.ts +3 -0
  48. package/dist/detectors/pattern-violation-detector.d.ts.map +1 -0
  49. package/dist/detectors/pattern-violation-detector.js +83 -0
  50. package/dist/detectors/pattern-violation-detector.js.map +1 -0
  51. package/dist/detectors/repository-intelligence-detector.d.ts +3 -0
  52. package/dist/detectors/repository-intelligence-detector.d.ts.map +1 -0
  53. package/dist/detectors/repository-intelligence-detector.js +51 -0
  54. package/dist/detectors/repository-intelligence-detector.js.map +1 -0
  55. package/dist/detectors/rewrite-detector.d.ts +3 -0
  56. package/dist/detectors/rewrite-detector.d.ts.map +1 -0
  57. package/dist/detectors/rewrite-detector.js +61 -0
  58. package/dist/detectors/rewrite-detector.js.map +1 -0
  59. package/dist/detectors/runner.d.ts +9 -0
  60. package/dist/detectors/runner.d.ts.map +1 -0
  61. package/dist/detectors/runner.js +96 -0
  62. package/dist/detectors/runner.js.map +1 -0
  63. package/dist/detectors/scope-detector.d.ts +3 -0
  64. package/dist/detectors/scope-detector.d.ts.map +1 -0
  65. package/dist/detectors/scope-detector.js +138 -0
  66. package/dist/detectors/scope-detector.js.map +1 -0
  67. package/dist/detectors/secret-path-detector.d.ts +5 -0
  68. package/dist/detectors/secret-path-detector.d.ts.map +1 -0
  69. package/dist/detectors/secret-path-detector.js +150 -0
  70. package/dist/detectors/secret-path-detector.js.map +1 -0
  71. package/dist/detectors/test-weakening-detector.d.ts +3 -0
  72. package/dist/detectors/test-weakening-detector.d.ts.map +1 -0
  73. package/dist/detectors/test-weakening-detector.js +91 -0
  74. package/dist/detectors/test-weakening-detector.js.map +1 -0
  75. package/dist/detectors/types.d.ts +15 -0
  76. package/dist/detectors/types.d.ts.map +1 -0
  77. package/dist/detectors/types.js +2 -0
  78. package/dist/detectors/types.js.map +1 -0
  79. package/dist/detectors/utility-reinvention-detector.d.ts +3 -0
  80. package/dist/detectors/utility-reinvention-detector.d.ts.map +1 -0
  81. package/dist/detectors/utility-reinvention-detector.js +78 -0
  82. package/dist/detectors/utility-reinvention-detector.js.map +1 -0
  83. package/dist/diff/git-diff-reader.d.ts +24 -0
  84. package/dist/diff/git-diff-reader.d.ts.map +1 -0
  85. package/dist/diff/git-diff-reader.js +81 -0
  86. package/dist/diff/git-diff-reader.js.map +1 -0
  87. package/dist/diff/index.d.ts +4 -0
  88. package/dist/diff/index.d.ts.map +1 -0
  89. package/dist/diff/index.js +4 -0
  90. package/dist/diff/index.js.map +1 -0
  91. package/dist/diff/parse-unified-diff.d.ts +3 -0
  92. package/dist/diff/parse-unified-diff.d.ts.map +1 -0
  93. package/dist/diff/parse-unified-diff.js +153 -0
  94. package/dist/diff/parse-unified-diff.js.map +1 -0
  95. package/dist/diff/path-classifier.d.ts +5 -0
  96. package/dist/diff/path-classifier.d.ts.map +1 -0
  97. package/dist/diff/path-classifier.js +86 -0
  98. package/dist/diff/path-classifier.js.map +1 -0
  99. package/dist/editor/diagnostics.d.ts +35 -0
  100. package/dist/editor/diagnostics.d.ts.map +1 -0
  101. package/dist/editor/diagnostics.js +55 -0
  102. package/dist/editor/diagnostics.js.map +1 -0
  103. package/dist/editor/index.d.ts +3 -0
  104. package/dist/editor/index.d.ts.map +1 -0
  105. package/dist/editor/index.js +2 -0
  106. package/dist/editor/index.js.map +1 -0
  107. package/dist/index.d.ts +11 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +11 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/intent/index.d.ts +5 -0
  112. package/dist/intent/index.d.ts.map +1 -0
  113. package/dist/intent/index.js +5 -0
  114. package/dist/intent/index.js.map +1 -0
  115. package/dist/intent/intent-core.d.ts +4 -0
  116. package/dist/intent/intent-core.d.ts.map +1 -0
  117. package/dist/intent/intent-core.js +58 -0
  118. package/dist/intent/intent-core.js.map +1 -0
  119. package/dist/intent/intent-model.d.ts +18 -0
  120. package/dist/intent/intent-model.d.ts.map +1 -0
  121. package/dist/intent/intent-model.js +74 -0
  122. package/dist/intent/intent-model.js.map +1 -0
  123. package/dist/intent/observed-actions.d.ts +17 -0
  124. package/dist/intent/observed-actions.d.ts.map +1 -0
  125. package/dist/intent/observed-actions.js +128 -0
  126. package/dist/intent/observed-actions.js.map +1 -0
  127. package/dist/intent/scope-expansion-score.d.ts +13 -0
  128. package/dist/intent/scope-expansion-score.d.ts.map +1 -0
  129. package/dist/intent/scope-expansion-score.js +87 -0
  130. package/dist/intent/scope-expansion-score.js.map +1 -0
  131. package/dist/intent/task-analysis.d.ts +18 -0
  132. package/dist/intent/task-analysis.d.ts.map +1 -0
  133. package/dist/intent/task-analysis.js +46 -0
  134. package/dist/intent/task-analysis.js.map +1 -0
  135. package/dist/knowledge/cache.d.ts +29 -0
  136. package/dist/knowledge/cache.d.ts.map +1 -0
  137. package/dist/knowledge/cache.js +85 -0
  138. package/dist/knowledge/cache.js.map +1 -0
  139. package/dist/knowledge/graph.d.ts +16 -0
  140. package/dist/knowledge/graph.d.ts.map +1 -0
  141. package/dist/knowledge/graph.js +139 -0
  142. package/dist/knowledge/graph.js.map +1 -0
  143. package/dist/knowledge/history-index.d.ts +20 -0
  144. package/dist/knowledge/history-index.d.ts.map +1 -0
  145. package/dist/knowledge/history-index.js +117 -0
  146. package/dist/knowledge/history-index.js.map +1 -0
  147. package/dist/knowledge/index.d.ts +9 -0
  148. package/dist/knowledge/index.d.ts.map +1 -0
  149. package/dist/knowledge/index.js +8 -0
  150. package/dist/knowledge/index.js.map +1 -0
  151. package/dist/knowledge/pattern-index.d.ts +14 -0
  152. package/dist/knowledge/pattern-index.d.ts.map +1 -0
  153. package/dist/knowledge/pattern-index.js +94 -0
  154. package/dist/knowledge/pattern-index.js.map +1 -0
  155. package/dist/knowledge/provider.d.ts +18 -0
  156. package/dist/knowledge/provider.d.ts.map +1 -0
  157. package/dist/knowledge/provider.js +83 -0
  158. package/dist/knowledge/provider.js.map +1 -0
  159. package/dist/knowledge/solution-index.d.ts +17 -0
  160. package/dist/knowledge/solution-index.d.ts.map +1 -0
  161. package/dist/knowledge/solution-index.js +170 -0
  162. package/dist/knowledge/solution-index.js.map +1 -0
  163. package/dist/knowledge/symbol-index.d.ts +4 -0
  164. package/dist/knowledge/symbol-index.d.ts.map +1 -0
  165. package/dist/knowledge/symbol-index.js +11 -0
  166. package/dist/knowledge/symbol-index.js.map +1 -0
  167. package/dist/knowledge/types.d.ts +100 -0
  168. package/dist/knowledge/types.d.ts.map +1 -0
  169. package/dist/knowledge/types.js +2 -0
  170. package/dist/knowledge/types.js.map +1 -0
  171. package/dist/llm/artifact.d.ts +6 -0
  172. package/dist/llm/artifact.d.ts.map +1 -0
  173. package/dist/llm/artifact.js +86 -0
  174. package/dist/llm/artifact.js.map +1 -0
  175. package/dist/llm/cache.d.ts +10 -0
  176. package/dist/llm/cache.d.ts.map +1 -0
  177. package/dist/llm/cache.js +24 -0
  178. package/dist/llm/cache.js.map +1 -0
  179. package/dist/llm/index.d.ts +8 -0
  180. package/dist/llm/index.d.ts.map +1 -0
  181. package/dist/llm/index.js +7 -0
  182. package/dist/llm/index.js.map +1 -0
  183. package/dist/llm/prompt.d.ts +7 -0
  184. package/dist/llm/prompt.d.ts.map +1 -0
  185. package/dist/llm/prompt.js +23 -0
  186. package/dist/llm/prompt.js.map +1 -0
  187. package/dist/llm/provider.d.ts +4 -0
  188. package/dist/llm/provider.d.ts.map +1 -0
  189. package/dist/llm/provider.js +43 -0
  190. package/dist/llm/provider.js.map +1 -0
  191. package/dist/llm/redaction.d.ts +3 -0
  192. package/dist/llm/redaction.d.ts.map +1 -0
  193. package/dist/llm/redaction.js +22 -0
  194. package/dist/llm/redaction.js.map +1 -0
  195. package/dist/llm/types.d.ts +89 -0
  196. package/dist/llm/types.d.ts.map +1 -0
  197. package/dist/llm/types.js +2 -0
  198. package/dist/llm/types.js.map +1 -0
  199. package/dist/reporters/index.d.ts +8 -0
  200. package/dist/reporters/index.d.ts.map +1 -0
  201. package/dist/reporters/index.js +21 -0
  202. package/dist/reporters/index.js.map +1 -0
  203. package/dist/reporters/json-reporter.d.ts +3 -0
  204. package/dist/reporters/json-reporter.d.ts.map +1 -0
  205. package/dist/reporters/json-reporter.js +4 -0
  206. package/dist/reporters/json-reporter.js.map +1 -0
  207. package/dist/reporters/markdown-reporter.d.ts +3 -0
  208. package/dist/reporters/markdown-reporter.d.ts.map +1 -0
  209. package/dist/reporters/markdown-reporter.js +76 -0
  210. package/dist/reporters/markdown-reporter.js.map +1 -0
  211. package/dist/reporters/repair-reporter.d.ts +3 -0
  212. package/dist/reporters/repair-reporter.d.ts.map +1 -0
  213. package/dist/reporters/repair-reporter.js +56 -0
  214. package/dist/reporters/repair-reporter.js.map +1 -0
  215. package/dist/reporters/sarif-reporter.d.ts +3 -0
  216. package/dist/reporters/sarif-reporter.d.ts.map +1 -0
  217. package/dist/reporters/sarif-reporter.js +161 -0
  218. package/dist/reporters/sarif-reporter.js.map +1 -0
  219. package/dist/repository/index.d.ts +3 -0
  220. package/dist/repository/index.d.ts.map +1 -0
  221. package/dist/repository/index.js +3 -0
  222. package/dist/repository/index.js.map +1 -0
  223. package/dist/repository/profile.d.ts +7 -0
  224. package/dist/repository/profile.d.ts.map +1 -0
  225. package/dist/repository/profile.js +6 -0
  226. package/dist/repository/profile.js.map +1 -0
  227. package/dist/repository/utility-index.d.ts +7 -0
  228. package/dist/repository/utility-index.d.ts.map +1 -0
  229. package/dist/repository/utility-index.js +6 -0
  230. package/dist/repository/utility-index.js.map +1 -0
  231. package/dist/schema/gate-result.schema.d.ts +514 -0
  232. package/dist/schema/gate-result.schema.d.ts.map +1 -0
  233. package/dist/schema/gate-result.schema.js +326 -0
  234. package/dist/schema/gate-result.schema.js.map +1 -0
  235. package/dist/schema/index.d.ts +4 -0
  236. package/dist/schema/index.d.ts.map +1 -0
  237. package/dist/schema/index.js +3 -0
  238. package/dist/schema/index.js.map +1 -0
  239. package/dist/schema/types.d.ts +136 -0
  240. package/dist/schema/types.d.ts.map +1 -0
  241. package/dist/schema/types.js +2 -0
  242. package/dist/schema/types.js.map +1 -0
  243. package/package.json +51 -0
@@ -0,0 +1,20 @@
1
+ import type { RepositoryProfile } from "../schema/index.js";
2
+ import type { HistoryIndex } from "./types.js";
3
+ export interface HistoryCommandRunner {
4
+ execFile: (file: string, args: string[], options?: {
5
+ cwd?: string;
6
+ }) => string;
7
+ }
8
+ export interface BuildHistoryIndexOptions {
9
+ root: string;
10
+ runner: HistoryCommandRunner;
11
+ maxCommits?: number;
12
+ minConfidenceCommitCount?: number;
13
+ minCompanionSupport?: number;
14
+ minCompanionConfidence?: number;
15
+ }
16
+ export declare function createEmptyHistoryIndex(): HistoryIndex;
17
+ export declare function buildHistoryIndex(options: BuildHistoryIndexOptions): HistoryIndex;
18
+ export declare function buildRepositoryProfileFromHistoryIndex(index: HistoryIndex): RepositoryProfile;
19
+ export declare function parseNameOnlyLog(logOutput: string): string[][];
20
+ //# sourceMappingURL=history-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history-index.d.ts","sourceRoot":"","sources":["../../src/knowledge/history-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CAChF;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,wBAAgB,uBAAuB,IAAI,YAAY,CAKtD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,YAAY,CA2DjF;AAED,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAQ7F;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAyB9D"}
@@ -0,0 +1,117 @@
1
+ export function createEmptyHistoryIndex() {
2
+ return {
3
+ coChanges: [],
4
+ companionRules: []
5
+ };
6
+ }
7
+ export function buildHistoryIndex(options) {
8
+ const maxCommits = options.maxCommits ?? 200;
9
+ const minConfidenceCommitCount = options.minConfidenceCommitCount ?? 20;
10
+ const minCompanionSupport = options.minCompanionSupport ?? 2;
11
+ const minCompanionConfidence = options.minCompanionConfidence ?? 0.4;
12
+ const logOutput = getOptionalGitOutput(options.runner, ["log", `--max-count=${maxCommits}`, "--name-only", "--pretty=format:__COMMIT__"], options.root);
13
+ if (logOutput === undefined) {
14
+ return {
15
+ profile: {
16
+ commitCount: 0,
17
+ minConfidenceCommitCount,
18
+ coChanges: []
19
+ },
20
+ coChanges: [],
21
+ companionRules: []
22
+ };
23
+ }
24
+ const commits = parseNameOnlyLog(logOutput);
25
+ const coChangeMap = new Map();
26
+ const changeCounts = new Map();
27
+ for (const commit of commits) {
28
+ const files = [...new Set(commit)].sort();
29
+ for (const file of files) {
30
+ changeCounts.set(file, (changeCounts.get(file) ?? 0) + 1);
31
+ const related = coChangeMap.get(file) ?? new Map();
32
+ for (const other of files) {
33
+ if (other === file) {
34
+ continue;
35
+ }
36
+ related.set(other, (related.get(other) ?? 0) + 1);
37
+ }
38
+ coChangeMap.set(file, related);
39
+ }
40
+ }
41
+ const coChanges = [...coChangeMap.entries()]
42
+ .map(([path, related]) => toCoChange(path, changeCounts.get(path) ?? 0, related))
43
+ .sort((left, right) => left.path.localeCompare(right.path));
44
+ return {
45
+ profile: {
46
+ commitCount: commits.length,
47
+ minConfidenceCommitCount,
48
+ coChanges
49
+ },
50
+ coChanges,
51
+ companionRules: toCompanionRules(coChanges, minCompanionSupport, minCompanionConfidence)
52
+ };
53
+ }
54
+ export function buildRepositoryProfileFromHistoryIndex(index) {
55
+ return (index.profile ?? {
56
+ commitCount: 0,
57
+ minConfidenceCommitCount: 20,
58
+ coChanges: index.coChanges
59
+ });
60
+ }
61
+ export function parseNameOnlyLog(logOutput) {
62
+ const commits = [];
63
+ let currentCommit = [];
64
+ for (const rawLine of logOutput.split(/\r?\n/)) {
65
+ const line = rawLine.trim();
66
+ if (line === "__COMMIT__") {
67
+ if (currentCommit.length > 0) {
68
+ commits.push(currentCommit);
69
+ }
70
+ currentCommit = [];
71
+ continue;
72
+ }
73
+ if (line.length > 0) {
74
+ currentCommit.push(line);
75
+ }
76
+ }
77
+ if (currentCommit.length > 0) {
78
+ commits.push(currentCommit);
79
+ }
80
+ return commits;
81
+ }
82
+ function toCoChange(path, count, related) {
83
+ return {
84
+ path,
85
+ count,
86
+ relatedPaths: [...related.entries()]
87
+ .map(([relatedPath, relatedCount]) => ({
88
+ path: relatedPath,
89
+ count: relatedCount
90
+ }))
91
+ .sort((left, right) => right.count - left.count || left.path.localeCompare(right.path))
92
+ .slice(0, 10)
93
+ };
94
+ }
95
+ function toCompanionRules(coChanges, minSupport, minConfidence) {
96
+ return coChanges
97
+ .flatMap((coChange) => coChange.relatedPaths.map((related) => ({
98
+ sourcePath: coChange.path,
99
+ expectedPath: related.path,
100
+ support: related.count,
101
+ confidence: coChange.count > 0 ? related.count / coChange.count : 0
102
+ })))
103
+ .filter((rule) => rule.support >= minSupport && rule.confidence >= minConfidence)
104
+ .sort((left, right) => left.sourcePath.localeCompare(right.sourcePath) ||
105
+ right.confidence - left.confidence ||
106
+ left.expectedPath.localeCompare(right.expectedPath));
107
+ }
108
+ function getOptionalGitOutput(runner, args, cwd) {
109
+ try {
110
+ const output = runner.execFile("git", args, { cwd }).trim();
111
+ return output.length > 0 ? output : undefined;
112
+ }
113
+ catch {
114
+ return undefined;
115
+ }
116
+ }
117
+ //# sourceMappingURL=history-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history-index.js","sourceRoot":"","sources":["../../src/knowledge/history-index.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,uBAAuB;IACrC,OAAO;QACL,SAAS,EAAE,EAAE;QACb,cAAc,EAAE,EAAE;KACnB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAiC;IACjE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC;IAC7C,MAAM,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,IAAI,EAAE,CAAC;IACxE,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,CAAC,CAAC;IAC7D,MAAM,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,IAAI,GAAG,CAAC;IACrE,MAAM,SAAS,GAAG,oBAAoB,CACpC,OAAO,CAAC,MAAM,EACd,CAAC,KAAK,EAAE,eAAe,UAAU,EAAE,EAAE,aAAa,EAAE,4BAA4B,CAAC,EACjF,OAAO,CAAC,IAAI,CACb,CAAC;IAEF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO;YACL,OAAO,EAAE;gBACP,WAAW,EAAE,CAAC;gBACd,wBAAwB;gBACxB,SAAS,EAAE,EAAE;aACd;YACD,SAAS,EAAE,EAAE;YACb,cAAc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KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU;QAClC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,CACtD,CAAC;AACN,CAAC;AAED,SAAS,oBAAoB,CAC3B,MAA4B,EAC5B,IAAc,EACd,GAAW;IAEX,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC5D,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAChD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { KNOWLEDGE_CACHE_DIR, KNOWLEDGE_CACHE_SCHEMA_VERSION, buildKnowledgeCacheKey, createFileKnowledgeCache, createMemoryKnowledgeCache, serializeKnowledgeCacheKey, type KnowledgeCacheEntry, type KnowledgeCacheKeyOptions, type KnowledgeCache } from "./cache.js";
2
+ export { buildFileGraph, createEmptyFileGraph, createFileGraph, type BuildFileGraphOptions, type FileGraphRunner } from "./graph.js";
3
+ export { buildHistoryIndex, buildRepositoryProfileFromHistoryIndex, createEmptyHistoryIndex, parseNameOnlyLog, type BuildHistoryIndexOptions, type HistoryCommandRunner } from "./history-index.js";
4
+ export { buildSolutionIndex, extractExportedNames, extractSolutionEntries, solutionIndexToUtilityIndex, type BuildSolutionIndexOptions, type SolutionIndexRunner } from "./solution-index.js";
5
+ export { createLazyKnowledgeProvider, type CreateLazyKnowledgeProviderOptions, type KnowledgeProviderRunner } from "./provider.js";
6
+ export { buildPatternIndex, type BuildPatternIndexOptions, type PatternIndexRunner } from "./pattern-index.js";
7
+ export { createEmptySymbolIndex, createSymbolIndex } from "./symbol-index.js";
8
+ export type { CompanionRule, FileGraph, FileGraphEdge, FileGraphEdgeKind, FileGraphNode, HistoryIndex, KnowledgeCacheKey, KnowledgeIndexKind, KnowledgeProvider, KnowledgeRequest, PatternIndex, RepositoryKnowledge, RepositoryPattern, RepositoryPatternKind, SolutionClass, SolutionEntry, SolutionIndex, SymbolEntry, SymbolEntryKind, SymbolIndex } from "./types.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/knowledge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,sBAAsB,EACtB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACpB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,sCAAsC,EACtC,uBAAuB,EACvB,gBAAgB,EAChB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,2BAA2B,EAC3B,KAAK,kCAAkC,EACvC,KAAK,uBAAuB,EAC7B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC9E,YAAY,EACV,aAAa,EACb,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,eAAe,EACf,WAAW,EACZ,MAAM,YAAY,CAAC"}
@@ -0,0 +1,8 @@
1
+ export { KNOWLEDGE_CACHE_DIR, KNOWLEDGE_CACHE_SCHEMA_VERSION, buildKnowledgeCacheKey, createFileKnowledgeCache, createMemoryKnowledgeCache, serializeKnowledgeCacheKey } from "./cache.js";
2
+ export { buildFileGraph, createEmptyFileGraph, createFileGraph } from "./graph.js";
3
+ export { buildHistoryIndex, buildRepositoryProfileFromHistoryIndex, createEmptyHistoryIndex, parseNameOnlyLog } from "./history-index.js";
4
+ export { buildSolutionIndex, extractExportedNames, extractSolutionEntries, solutionIndexToUtilityIndex } from "./solution-index.js";
5
+ export { createLazyKnowledgeProvider } from "./provider.js";
6
+ export { buildPatternIndex } from "./pattern-index.js";
7
+ export { createEmptySymbolIndex, createSymbolIndex } from "./symbol-index.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/knowledge/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,sBAAsB,EACtB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAI3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,EAGhB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,sCAAsC,EACtC,uBAAuB,EACvB,gBAAgB,EAGjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,2BAA2B,EAG5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,2BAA2B,EAG5B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EAGlB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { CriticalGateConfig } from "../config/index.js";
2
+ import type { PatternIndex } from "./types.js";
3
+ export interface PatternIndexRunner {
4
+ execFile: (file: string, args: string[], options?: {
5
+ cwd?: string;
6
+ }) => string;
7
+ }
8
+ export interface BuildPatternIndexOptions {
9
+ root: string;
10
+ runner: PatternIndexRunner;
11
+ config?: CriticalGateConfig;
12
+ }
13
+ export declare function buildPatternIndex(options: BuildPatternIndexOptions): PatternIndex;
14
+ //# sourceMappingURL=pattern-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-index.d.ts","sourceRoot":"","sources":["../../src/knowledge/pattern-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAA4C,MAAM,YAAY,CAAC;AAEzF,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;CAChF;AAED,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,kBAAkB,CAAC;IAC3B,MAAM,CAAC,EAAE,kBAAkB,CAAC;CAC7B;AAWD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,YAAY,CAejF"}
@@ -0,0 +1,94 @@
1
+ const patternRules = [
2
+ { kind: "service", segment: /^services?$/i },
3
+ { kind: "hook", segment: /^hooks?$/i },
4
+ { kind: "query", segment: /^(queries|api)$/i },
5
+ { kind: "validator", segment: /^(validators?|validation)$/i },
6
+ { kind: "schema", segment: /^schemas?$/i },
7
+ { kind: "adapter", segment: /^adapters?$/i }
8
+ ];
9
+ export function buildPatternIndex(options) {
10
+ const files = getTrackedSourceFiles(options).filter((path) => !isExcluded(path, options.config?.excludePatterns ?? []));
11
+ const patterns = [
12
+ ...inferClassPatterns(files),
13
+ ...inferConfiguredRootPatterns(files, "service", options.config?.serviceRoots ?? []),
14
+ ...inferConfiguredRootPatterns(files, "validator", options.config?.validatorRoots ?? []),
15
+ ...inferFeatureRootPatterns(files),
16
+ ...inferConfiguredRootPatterns(files, "feature-root", options.config?.featureRoots ?? [])
17
+ ].sort((left, right) => left.kind.localeCompare(right.kind) || left.root.localeCompare(right.root));
18
+ return { patterns };
19
+ }
20
+ function inferConfiguredRootPatterns(files, kind, roots) {
21
+ return roots
22
+ .map((root) => {
23
+ const examples = files.filter((file) => file === root || file.startsWith(`${root}/`));
24
+ return examples.length === 0 ? undefined : toPattern(kind, root, examples);
25
+ })
26
+ .filter((pattern) => pattern !== undefined);
27
+ }
28
+ function inferClassPatterns(files) {
29
+ const groups = new Map();
30
+ for (const file of files) {
31
+ const segments = file.split("/");
32
+ const matched = segments
33
+ .map((segment, index) => ({
34
+ segment,
35
+ index,
36
+ rule: patternRules.find((rule) => rule.segment.test(segment))
37
+ }))
38
+ .find((entry) => entry.rule !== undefined);
39
+ if (matched?.rule === undefined) {
40
+ continue;
41
+ }
42
+ const root = segments.slice(0, matched.index + 1).join("/");
43
+ const key = `${matched.rule.kind}:${root}`;
44
+ const current = groups.get(key) ?? { kind: matched.rule.kind, examples: [] };
45
+ current.examples.push(file);
46
+ groups.set(key, current);
47
+ }
48
+ return [...groups.entries()].map(([key, value]) => {
49
+ const [, root = ""] = key.split(":");
50
+ return toPattern(value.kind, root, value.examples);
51
+ });
52
+ }
53
+ function inferFeatureRootPatterns(files) {
54
+ const groups = new Map();
55
+ for (const file of files) {
56
+ const segments = file.split("/");
57
+ if (segments[0] !== "src" ||
58
+ segments.length < 3 ||
59
+ patternRules.some((rule) => rule.segment.test(segments[1] ?? ""))) {
60
+ continue;
61
+ }
62
+ const root = segments.slice(0, 2).join("/");
63
+ groups.set(root, [...(groups.get(root) ?? []), file]);
64
+ }
65
+ return [...groups.entries()]
66
+ .filter(([, examples]) => examples.length >= 2)
67
+ .map(([root, examples]) => toPattern("feature-root", root, examples));
68
+ }
69
+ function toPattern(kind, root, examples) {
70
+ const sortedExamples = [...examples].sort();
71
+ return {
72
+ kind,
73
+ root,
74
+ examples: sortedExamples.slice(0, 5),
75
+ confidence: Math.round(Math.min(1, 0.45 + sortedExamples.length * 0.15) * 100) / 100
76
+ };
77
+ }
78
+ function getTrackedSourceFiles(options) {
79
+ try {
80
+ return options.runner
81
+ .execFile("git", ["ls-files"], { cwd: options.root })
82
+ .split(/\r?\n/)
83
+ .map((path) => path.trim().replaceAll("\\", "/"))
84
+ .filter((path) => /\.(?:[cm]?[jt]sx?)$/.test(path))
85
+ .sort();
86
+ }
87
+ catch {
88
+ return [];
89
+ }
90
+ }
91
+ function isExcluded(path, excludePatterns) {
92
+ return excludePatterns.some((pattern) => path.includes(pattern));
93
+ }
94
+ //# sourceMappingURL=pattern-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-index.js","sourceRoot":"","sources":["../../src/knowledge/pattern-index.ts"],"names":[],"mappings":"AAaA,MAAM,YAAY,GAA4D;IAC5E,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE;IAC5C,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE;IACtC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE;IAC9C,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,6BAA6B,EAAE;IAC7D,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE;IAC1C,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE;CAC7C,CAAC;A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AAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type KnowledgeCache } from "./cache.js";
2
+ import type { KnowledgeProvider } from "./types.js";
3
+ export interface KnowledgeProviderRunner {
4
+ execFile: (file: string, args: string[], options?: {
5
+ cwd?: string;
6
+ }) => string;
7
+ readFile?: (path: string) => string;
8
+ }
9
+ export interface CreateLazyKnowledgeProviderOptions {
10
+ root: string;
11
+ runner: KnowledgeProviderRunner;
12
+ baseRef?: string;
13
+ headRef?: string;
14
+ cache?: KnowledgeCache;
15
+ useCache?: boolean;
16
+ }
17
+ export declare function createLazyKnowledgeProvider(options: CreateLazyKnowledgeProviderOptions): KnowledgeProvider;
18
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/knowledge/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,cAAc,EAEpB,MAAM,YAAY,CAAC;AAKpB,OAAO,KAAK,EAIV,iBAAiB,EAGlB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IAC/E,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,uBAAuB,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,kCAAkC,GAC1C,iBAAiB,CAsDnB"}
@@ -0,0 +1,83 @@
1
+ import { buildKnowledgeCacheKey, createFileKnowledgeCache } from "./cache.js";
2
+ import { buildFileGraph } from "./graph.js";
3
+ import { buildHistoryIndex } from "./history-index.js";
4
+ import { buildPatternIndex } from "./pattern-index.js";
5
+ import { buildSolutionIndex } from "./solution-index.js";
6
+ export function createLazyKnowledgeProvider(options) {
7
+ let historyIndex;
8
+ let solutionIndex;
9
+ let patternIndex;
10
+ let fileGraph;
11
+ let cacheKey;
12
+ const cacheEnabled = options.useCache !== false && process.env.CRITICAL_GATE_DISABLE_CACHE !== "true";
13
+ const cache = cacheEnabled
14
+ ? (options.cache ?? createFileKnowledgeCache(options.root))
15
+ : undefined;
16
+ return {
17
+ getFileGraph: () => {
18
+ const cached = cache?.get(getCacheKey());
19
+ historyIndex ??= cached?.history;
20
+ fileGraph ??= cached?.graph;
21
+ if (fileGraph === undefined) {
22
+ historyIndex ??= buildAndCacheHistory(options, cache, getCacheKey);
23
+ fileGraph = buildFileGraph({ ...options, history: historyIndex });
24
+ const key = cache === undefined ? undefined : getCacheKey();
25
+ if (key !== undefined) {
26
+ cache?.set(key, { ...(cache.get(key) ?? {}), graph: fileGraph, history: historyIndex });
27
+ }
28
+ }
29
+ return fileGraph;
30
+ },
31
+ getHistoryIndex: () => {
32
+ historyIndex ??=
33
+ cache?.get(getCacheKey())?.history ?? buildAndCacheHistory(options, cache, getCacheKey);
34
+ return historyIndex;
35
+ },
36
+ getPatternIndex: () => {
37
+ patternIndex ??=
38
+ cache?.get(getCacheKey())?.patterns ?? buildAndCachePatterns(options, cache, getCacheKey);
39
+ return patternIndex;
40
+ },
41
+ getSolutionIndex: () => {
42
+ solutionIndex ??=
43
+ cache?.get(getCacheKey())?.solutions ?? buildAndCacheSolutions(options, cache, getCacheKey);
44
+ return solutionIndex;
45
+ },
46
+ getLoadedFileGraph: () => fileGraph,
47
+ getLoadedHistoryIndex: () => historyIndex,
48
+ getLoadedPatternIndex: () => patternIndex,
49
+ getLoadedSolutionIndex: () => solutionIndex
50
+ };
51
+ function getCacheKey() {
52
+ cacheKey ??= buildKnowledgeCacheKey(options);
53
+ return cacheKey;
54
+ }
55
+ }
56
+ function buildAndCachePatterns(options, cache, getCacheKey) {
57
+ const patterns = buildPatternIndex(options);
58
+ const key = cache === undefined ? undefined : getCacheKey();
59
+ const current = key === undefined ? {} : (cache?.get(key) ?? {});
60
+ if (key !== undefined) {
61
+ cache?.set(key, { ...current, patterns });
62
+ }
63
+ return patterns;
64
+ }
65
+ function buildAndCacheHistory(options, cache, getCacheKey) {
66
+ const history = buildHistoryIndex(options);
67
+ const key = cache === undefined ? undefined : getCacheKey();
68
+ const current = key === undefined ? {} : (cache?.get(key) ?? {});
69
+ if (key !== undefined) {
70
+ cache?.set(key, { ...current, history });
71
+ }
72
+ return history;
73
+ }
74
+ function buildAndCacheSolutions(options, cache, getCacheKey) {
75
+ const solutions = buildSolutionIndex(options);
76
+ const key = cache === undefined ? undefined : getCacheKey();
77
+ const current = key === undefined ? {} : (cache?.get(key) ?? {});
78
+ if (key !== undefined) {
79
+ cache?.set(key, { ...current, solutions });
80
+ }
81
+ return solutions;
82
+ }
83
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/knowledge/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EAGzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAwBzD,MAAM,UAAU,2BAA2B,CACzC,OAA2C;IAE3C,IAA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,SAAS,EAAE,CAAC,CAAC;IAC7C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { UtilityIndex } from "../schema/index.js";
2
+ import type { SolutionEntry, SolutionIndex } from "./types.js";
3
+ export interface SolutionIndexRunner {
4
+ execFile: (file: string, args: string[], options?: {
5
+ cwd?: string;
6
+ }) => string;
7
+ readFile?: (path: string) => string;
8
+ }
9
+ export interface BuildSolutionIndexOptions {
10
+ root: string;
11
+ runner: SolutionIndexRunner;
12
+ }
13
+ export declare function buildSolutionIndex(options: BuildSolutionIndexOptions): SolutionIndex;
14
+ export declare function solutionIndexToUtilityIndex(index: SolutionIndex): UtilityIndex;
15
+ export declare function extractExportedNames(sourceText: string): string[];
16
+ export declare function extractSolutionEntries(path: string, sourceText: string): SolutionEntry[];
17
+ //# sourceMappingURL=solution-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solution-index.d.ts","sourceRoot":"","sources":["../../src/knowledge/solution-index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAiB,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,MAAM,CAAC;IAC/E,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,mBAAmB,CAAC;CAC7B;AAsBD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,aAAa,CAcpF;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAuB9E;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAwBjE;AAmBD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,aAAa,EAAE,CAwBxF"}
@@ -0,0 +1,170 @@
1
+ import { join } from "node:path";
2
+ const sourcePathPattern = /\.(?:[cm]?[jt]sx?)$/;
3
+ const exportDeclarationPattern = /^\s*export\s+(?:async\s+)?(?:declare\s+)?(?:function|class|interface|type|enum|const|let|var)\s+([A-Za-z_$][\w$]*)/gm;
4
+ const namedExportPattern = /^\s*export\s*\{([^}]+)\}/gm;
5
+ const importTokenPattern = /^\s*(?:import|export)\s+(?:[^'"]+\s+from\s+)?["']([^"']+)["']/gm;
6
+ const exportedFunctionPattern = /^\s*export\s+(?:async\s+)?function\s+([A-Za-z_$][\w$]*)\s*\(([^)]*)\)\s*(?::\s*([^{]+))?/m;
7
+ const exportedConstFunctionPattern = /^\s*export\s+const\s+([A-Za-z_$][\w$]*)\s*=\s*(?:async\s*)?(?:\(([^)]*)\)|([A-Za-z_$][\w$]*))\s*(?::\s*([^=]+))?\s*=>/m;
8
+ const solutionPathPatterns = [
9
+ { class: "utility", pattern: /(^|\/)(utils?|helpers?|lib|shared)\//i },
10
+ { class: "hook", pattern: /(^|\/)hooks?\//i },
11
+ { class: "service", pattern: /(^|\/)services?\//i },
12
+ { class: "query", pattern: /(^|\/)(queries|api)\//i },
13
+ { class: "validator", pattern: /(^|\/)(validators?|validation)\//i },
14
+ { class: "schema", pattern: /(^|\/)schemas?\//i },
15
+ { class: "adapter", pattern: /(^|\/)adapters?\//i }
16
+ ];
17
+ export function buildSolutionIndex(options) {
18
+ const solutions = getTrackedSourceFiles(options)
19
+ .flatMap((path) => toSolutionEntries(path, options))
20
+ .sort((left, right) => left.path.localeCompare(right.path) ||
21
+ left.class.localeCompare(right.class) ||
22
+ left.normalizedName.localeCompare(right.normalizedName));
23
+ return {
24
+ solutions,
25
+ utilityIndex: solutionIndexToUtilityIndex({ solutions })
26
+ };
27
+ }
28
+ export function solutionIndexToUtilityIndex(index) {
29
+ const utilityMap = new Map();
30
+ for (const solution of index.solutions) {
31
+ if (solution.class !== "utility" || solution.exportedName === undefined) {
32
+ continue;
33
+ }
34
+ const exportedNames = utilityMap.get(solution.path) ?? new Set();
35
+ exportedNames.add(solution.exportedName);
36
+ utilityMap.set(solution.path, exportedNames);
37
+ }
38
+ return {
39
+ utilities: [...utilityMap.entries()]
40
+ .map(([path, exportedNames]) => ({
41
+ path,
42
+ exportedNames: [...exportedNames].sort()
43
+ }))
44
+ .sort((left, right) => left.path.localeCompare(right.path))
45
+ };
46
+ }
47
+ export function extractExportedNames(sourceText) {
48
+ const names = new Set();
49
+ for (const match of sourceText.matchAll(exportDeclarationPattern)) {
50
+ const name = match[1];
51
+ if (name !== undefined) {
52
+ names.add(name);
53
+ }
54
+ }
55
+ for (const match of sourceText.matchAll(namedExportPattern)) {
56
+ const exportedNames = match[1] ?? "";
57
+ for (const rawName of exportedNames.split(",")) {
58
+ const name = rawName
59
+ .trim()
60
+ .split(/\s+as\s+/i)[0]
61
+ ?.trim();
62
+ if (name !== undefined && name.length > 0) {
63
+ names.add(name);
64
+ }
65
+ }
66
+ }
67
+ return [...names].sort();
68
+ }
69
+ function getTrackedSourceFiles(options) {
70
+ try {
71
+ return options.runner
72
+ .execFile("git", ["ls-files"], { cwd: options.root })
73
+ .split(/\r?\n/)
74
+ .map((path) => path.trim())
75
+ .filter((path) => sourcePathPattern.test(path));
76
+ }
77
+ catch {
78
+ return [];
79
+ }
80
+ }
81
+ function toSolutionEntries(path, options) {
82
+ const sourceText = options.runner.readFile?.(join(options.root, path)) ?? "";
83
+ return extractSolutionEntries(path, sourceText);
84
+ }
85
+ export function extractSolutionEntries(path, sourceText) {
86
+ const solutionClass = classifySolutionPath(path);
87
+ if (solutionClass === undefined) {
88
+ return [];
89
+ }
90
+ const exportedNames = extractExportedNames(sourceText);
91
+ const importTokens = extractImportTokens(sourceText);
92
+ return exportedNames.map((exportedName) => {
93
+ const metadata = getExportMetadata(sourceText, exportedName);
94
+ return {
95
+ path,
96
+ class: solutionClass,
97
+ normalizedName: normalizeName(exportedName),
98
+ exportedName,
99
+ arity: metadata.arity,
100
+ returnType: metadata.returnType,
101
+ importTokens,
102
+ domainTokens: pathToDomainTokens(path, exportedName)
103
+ };
104
+ });
105
+ }
106
+ function classifySolutionPath(path) {
107
+ return solutionPathPatterns.find((entry) => entry.pattern.test(path))?.class;
108
+ }
109
+ function normalizeName(name) {
110
+ return name.toLowerCase().replaceAll(/[^a-z0-9]/g, "");
111
+ }
112
+ function extractImportTokens(sourceText) {
113
+ const tokens = new Set();
114
+ for (const match of sourceText.matchAll(importTokenPattern)) {
115
+ const specifier = match[1];
116
+ if (specifier === undefined) {
117
+ continue;
118
+ }
119
+ for (const token of specifier.split(/[/.\\_-]+/).map(normalizeName)) {
120
+ if (token.length > 0) {
121
+ tokens.add(token);
122
+ }
123
+ }
124
+ }
125
+ return [...tokens].sort();
126
+ }
127
+ function getExportMetadata(sourceText, exportedName) {
128
+ const functionMatch = findNamedMatch(sourceText, exportedFunctionPattern, exportedName);
129
+ if (functionMatch !== undefined) {
130
+ return {
131
+ arity: countParameters(functionMatch[2] ?? ""),
132
+ returnType: normalizeReturnType(functionMatch[3])
133
+ };
134
+ }
135
+ const constFunctionMatch = findNamedMatch(sourceText, exportedConstFunctionPattern, exportedName);
136
+ if (constFunctionMatch !== undefined) {
137
+ return {
138
+ arity: countParameters(constFunctionMatch[2] ?? constFunctionMatch[3] ?? ""),
139
+ returnType: normalizeReturnType(constFunctionMatch[4])
140
+ };
141
+ }
142
+ return {};
143
+ }
144
+ function findNamedMatch(sourceText, pattern, exportedName) {
145
+ for (const match of sourceText.matchAll(new RegExp(pattern.source, "gm"))) {
146
+ if (match[1] === exportedName) {
147
+ return match;
148
+ }
149
+ }
150
+ return undefined;
151
+ }
152
+ function countParameters(parameterText) {
153
+ const trimmed = parameterText.trim();
154
+ if (trimmed.length === 0) {
155
+ return 0;
156
+ }
157
+ return trimmed.split(",").filter((parameter) => parameter.trim().length > 0).length;
158
+ }
159
+ function normalizeReturnType(returnType) {
160
+ const normalized = returnType?.trim().replace(/\s+/g, " ");
161
+ return normalized === undefined || normalized.length === 0 ? undefined : normalized;
162
+ }
163
+ function pathToDomainTokens(path, exportedName) {
164
+ return [
165
+ ...new Set([...path.split(/[/.\\_-]+/), ...exportedName.split(/(?=[A-Z])|[_-]+/)].map(normalizeName))
166
+ ]
167
+ .filter((token) => token.length > 0)
168
+ .sort();
169
+ }
170
+ //# sourceMappingURL=solution-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solution-index.js","sourceRoot":"","sources":["../../src/knowledge/solution-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAejC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAChD,MAAM,wBAAwB,GAC5B,sHAAsH,CAAC;AACzH,MAAM,kBAAkB,GAAG,4BAA4B,CAAC;AACxD,MAAM,kBAAkB,GAAG,iEAAiE,CAAC;AAC7F,MAAM,uBAAuB,GAC3B,2FAA2F,CAAC;AAC9F,MAAM,4BAA4B,GAChC,wHAAwH,CAAC;AAE3H,MAAM,oBAAoB,GAAqD;IAC7E,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,uCAAuC,EAAE;IACtE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE;IAC7C,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAE;IACnD,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,wBAAwB,EAAE;IACrD,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,mCAAmC,EAAE;IACpE,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,mBAAmB,EAA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AG,CAAC,CAAC,CAAC,MAAM,CAAC;AACtF,CAAC;AAED,SAAS,mBAAmB,CAAC,UAA8B;IACzD,MAAM,UAAU,GAAG,UAAU,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3D,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC;AACtF,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY,EAAE,YAAoB;IAC5D,OAAO;QACL,GAAG,IAAI,GAAG,CACR,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAC1F;KACF;SACE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;SACnC,IAAI,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { SymbolEntry, SymbolIndex } from "./types.js";
2
+ export declare function createEmptySymbolIndex(): SymbolIndex;
3
+ export declare function createSymbolIndex(symbols?: SymbolEntry[]): SymbolIndex;
4
+ //# sourceMappingURL=symbol-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbol-index.d.ts","sourceRoot":"","sources":["../../src/knowledge/symbol-index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE3D,wBAAgB,sBAAsB,IAAI,WAAW,CAIpD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,WAAW,EAAO,GAAG,WAAW,CAM1E"}