@eddacraft/anvil-core 0.1.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 (215) hide show
  1. package/LICENSE +14 -0
  2. package/dist/antipattern/index.d.ts +11 -0
  3. package/dist/antipattern/index.d.ts.map +1 -0
  4. package/dist/antipattern/index.js +31 -0
  5. package/dist/antipattern/patterns-css.d.ts +17 -0
  6. package/dist/antipattern/patterns-css.d.ts.map +1 -0
  7. package/dist/antipattern/patterns-css.js +72 -0
  8. package/dist/antipattern/patterns-html.d.ts +21 -0
  9. package/dist/antipattern/patterns-html.d.ts.map +1 -0
  10. package/dist/antipattern/patterns-html.js +139 -0
  11. package/dist/antipattern/patterns.d.ts +72 -0
  12. package/dist/antipattern/patterns.d.ts.map +1 -0
  13. package/dist/antipattern/patterns.js +301 -0
  14. package/dist/antipattern/scanner.d.ts +32 -0
  15. package/dist/antipattern/scanner.d.ts.map +1 -0
  16. package/dist/antipattern/scanner.js +89 -0
  17. package/dist/antipattern/types.d.ts +318 -0
  18. package/dist/antipattern/types.d.ts.map +1 -0
  19. package/dist/antipattern/types.js +278 -0
  20. package/dist/architecture/analyzer.d.ts +123 -0
  21. package/dist/architecture/analyzer.d.ts.map +1 -0
  22. package/dist/architecture/analyzer.js +321 -0
  23. package/dist/architecture/baseline.d.ts +112 -0
  24. package/dist/architecture/baseline.d.ts.map +1 -0
  25. package/dist/architecture/baseline.js +245 -0
  26. package/dist/architecture/compiler.d.ts +24 -0
  27. package/dist/architecture/compiler.d.ts.map +1 -0
  28. package/dist/architecture/compiler.js +57 -0
  29. package/dist/architecture/context.d.ts +129 -0
  30. package/dist/architecture/context.d.ts.map +1 -0
  31. package/dist/architecture/context.js +116 -0
  32. package/dist/architecture/dc-generator.d.ts +9 -0
  33. package/dist/architecture/dc-generator.d.ts.map +1 -0
  34. package/dist/architecture/dc-generator.js +220 -0
  35. package/dist/architecture/definition-schema.d.ts +128 -0
  36. package/dist/architecture/definition-schema.d.ts.map +1 -0
  37. package/dist/architecture/definition-schema.js +94 -0
  38. package/dist/architecture/edge-detector-html.d.ts +6 -0
  39. package/dist/architecture/edge-detector-html.d.ts.map +1 -0
  40. package/dist/architecture/edge-detector-html.js +5 -0
  41. package/dist/architecture/edge-detector-web.d.ts +32 -0
  42. package/dist/architecture/edge-detector-web.d.ts.map +1 -0
  43. package/dist/architecture/edge-detector-web.js +133 -0
  44. package/dist/architecture/edge-detector.d.ts +116 -0
  45. package/dist/architecture/edge-detector.d.ts.map +1 -0
  46. package/dist/architecture/edge-detector.js +229 -0
  47. package/dist/architecture/entry-detector.d.ts +44 -0
  48. package/dist/architecture/entry-detector.d.ts.map +1 -0
  49. package/dist/architecture/entry-detector.js +263 -0
  50. package/dist/architecture/index.d.ts +21 -0
  51. package/dist/architecture/index.d.ts.map +1 -0
  52. package/dist/architecture/index.js +48 -0
  53. package/dist/architecture/layer-detector.d.ts +60 -0
  54. package/dist/architecture/layer-detector.d.ts.map +1 -0
  55. package/dist/architecture/layer-detector.js +331 -0
  56. package/dist/architecture/rego-generator.d.ts +25 -0
  57. package/dist/architecture/rego-generator.d.ts.map +1 -0
  58. package/dist/architecture/rego-generator.js +229 -0
  59. package/dist/architecture/templates/index.d.ts +39 -0
  60. package/dist/architecture/templates/index.d.ts.map +1 -0
  61. package/dist/architecture/templates/index.js +124 -0
  62. package/dist/architecture/types.d.ts +280 -0
  63. package/dist/architecture/types.d.ts.map +1 -0
  64. package/dist/architecture/types.js +269 -0
  65. package/dist/architecture/yaml-parser.d.ts +13 -0
  66. package/dist/architecture/yaml-parser.d.ts.map +1 -0
  67. package/dist/architecture/yaml-parser.js +234 -0
  68. package/dist/config/constants.d.ts +9 -0
  69. package/dist/config/constants.d.ts.map +1 -0
  70. package/dist/config/constants.js +20 -0
  71. package/dist/config/index.d.ts +9 -0
  72. package/dist/config/index.d.ts.map +1 -0
  73. package/dist/config/index.js +8 -0
  74. package/dist/config/loader.d.ts +41 -0
  75. package/dist/config/loader.d.ts.map +1 -0
  76. package/dist/config/loader.js +76 -0
  77. package/dist/config/nudge-config.d.ts +35 -0
  78. package/dist/config/nudge-config.d.ts.map +1 -0
  79. package/dist/config/nudge-config.js +34 -0
  80. package/dist/config/types.d.ts +30 -0
  81. package/dist/config/types.d.ts.map +1 -0
  82. package/dist/config/types.js +4 -0
  83. package/dist/contracts/index.d.ts +14 -0
  84. package/dist/contracts/index.d.ts.map +1 -0
  85. package/dist/contracts/index.js +13 -0
  86. package/dist/contracts/schemas/aps.schema.d.ts +269 -0
  87. package/dist/contracts/schemas/aps.schema.d.ts.map +1 -0
  88. package/dist/contracts/schemas/aps.schema.js +183 -0
  89. package/dist/contracts/schemas/index.d.ts +12 -0
  90. package/dist/contracts/schemas/index.d.ts.map +1 -0
  91. package/dist/contracts/schemas/index.js +14 -0
  92. package/dist/contracts/schemas/json-schema.d.ts +14 -0
  93. package/dist/contracts/schemas/json-schema.d.ts.map +1 -0
  94. package/dist/contracts/schemas/json-schema.js +31 -0
  95. package/dist/contracts/schemas/warning.schema.d.ts +171 -0
  96. package/dist/contracts/schemas/warning.schema.d.ts.map +1 -0
  97. package/dist/contracts/schemas/warning.schema.js +123 -0
  98. package/dist/contracts/types/gate.types.d.ts +194 -0
  99. package/dist/contracts/types/gate.types.d.ts.map +1 -0
  100. package/dist/contracts/types/gate.types.js +19 -0
  101. package/dist/contracts/types/index.d.ts +9 -0
  102. package/dist/contracts/types/index.d.ts.map +1 -0
  103. package/dist/contracts/types/index.js +8 -0
  104. package/dist/crypto/hash.d.ts +47 -0
  105. package/dist/crypto/hash.d.ts.map +1 -0
  106. package/dist/crypto/hash.js +110 -0
  107. package/dist/crypto/index.d.ts +7 -0
  108. package/dist/crypto/index.d.ts.map +1 -0
  109. package/dist/crypto/index.js +6 -0
  110. package/dist/drift/index.d.ts +6 -0
  111. package/dist/drift/index.d.ts.map +1 -0
  112. package/dist/drift/index.js +5 -0
  113. package/dist/drift/report-generator.d.ts +21 -0
  114. package/dist/drift/report-generator.d.ts.map +1 -0
  115. package/dist/drift/report-generator.js +240 -0
  116. package/dist/drift/snapshot-capture.d.ts +26 -0
  117. package/dist/drift/snapshot-capture.d.ts.map +1 -0
  118. package/dist/drift/snapshot-capture.js +195 -0
  119. package/dist/drift/snapshot-compare.d.ts +50 -0
  120. package/dist/drift/snapshot-compare.d.ts.map +1 -0
  121. package/dist/drift/snapshot-compare.js +142 -0
  122. package/dist/drift/snapshot-schema.d.ts +197 -0
  123. package/dist/drift/snapshot-schema.d.ts.map +1 -0
  124. package/dist/drift/snapshot-schema.js +193 -0
  125. package/dist/drift/snapshot-storage.d.ts +25 -0
  126. package/dist/drift/snapshot-storage.d.ts.map +1 -0
  127. package/dist/drift/snapshot-storage.js +179 -0
  128. package/dist/explain/antipattern-explainer.d.ts +4 -0
  129. package/dist/explain/antipattern-explainer.d.ts.map +1 -0
  130. package/dist/explain/antipattern-explainer.js +196 -0
  131. package/dist/explain/boundary-explainer.d.ts +5 -0
  132. package/dist/explain/boundary-explainer.d.ts.map +1 -0
  133. package/dist/explain/boundary-explainer.js +261 -0
  134. package/dist/explain/explain-service.d.ts +19 -0
  135. package/dist/explain/explain-service.d.ts.map +1 -0
  136. package/dist/explain/explain-service.js +106 -0
  137. package/dist/explain/index.d.ts +7 -0
  138. package/dist/explain/index.d.ts.map +1 -0
  139. package/dist/explain/index.js +5 -0
  140. package/dist/explain/template-loader.d.ts +9 -0
  141. package/dist/explain/template-loader.d.ts.map +1 -0
  142. package/dist/explain/template-loader.js +51 -0
  143. package/dist/explain/types.d.ts +46 -0
  144. package/dist/explain/types.d.ts.map +1 -0
  145. package/dist/explain/types.js +31 -0
  146. package/dist/index.d.ts +26 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +37 -0
  149. package/dist/provenance/collector.d.ts +86 -0
  150. package/dist/provenance/collector.d.ts.map +1 -0
  151. package/dist/provenance/collector.js +425 -0
  152. package/dist/provenance/git-ai-standard/git-notes.d.ts +85 -0
  153. package/dist/provenance/git-ai-standard/git-notes.d.ts.map +1 -0
  154. package/dist/provenance/git-ai-standard/git-notes.js +292 -0
  155. package/dist/provenance/git-ai-standard/index.d.ts +44 -0
  156. package/dist/provenance/git-ai-standard/index.d.ts.map +1 -0
  157. package/dist/provenance/git-ai-standard/index.js +47 -0
  158. package/dist/provenance/git-ai-standard/serializer.d.ts +54 -0
  159. package/dist/provenance/git-ai-standard/serializer.d.ts.map +1 -0
  160. package/dist/provenance/git-ai-standard/serializer.js +224 -0
  161. package/dist/provenance/git-ai-standard/session.d.ts +51 -0
  162. package/dist/provenance/git-ai-standard/session.d.ts.map +1 -0
  163. package/dist/provenance/git-ai-standard/session.js +118 -0
  164. package/dist/provenance/git-ai-standard/types.d.ts +173 -0
  165. package/dist/provenance/git-ai-standard/types.d.ts.map +1 -0
  166. package/dist/provenance/git-ai-standard/types.js +109 -0
  167. package/dist/provenance/index.d.ts +5 -0
  168. package/dist/provenance/index.d.ts.map +1 -0
  169. package/dist/provenance/index.js +6 -0
  170. package/dist/provenance/store.d.ts +83 -0
  171. package/dist/provenance/store.d.ts.map +1 -0
  172. package/dist/provenance/store.js +248 -0
  173. package/dist/provenance/types.d.ts +160 -0
  174. package/dist/provenance/types.d.ts.map +1 -0
  175. package/dist/provenance/types.js +112 -0
  176. package/dist/suppression/index.d.ts +4 -0
  177. package/dist/suppression/index.d.ts.map +1 -0
  178. package/dist/suppression/index.js +3 -0
  179. package/dist/suppression/parser.d.ts +31 -0
  180. package/dist/suppression/parser.d.ts.map +1 -0
  181. package/dist/suppression/parser.js +219 -0
  182. package/dist/suppression/service.d.ts +29 -0
  183. package/dist/suppression/service.d.ts.map +1 -0
  184. package/dist/suppression/service.js +132 -0
  185. package/dist/suppression/store.d.ts +61 -0
  186. package/dist/suppression/store.d.ts.map +1 -0
  187. package/dist/suppression/store.js +169 -0
  188. package/dist/utils/debug.d.ts +48 -0
  189. package/dist/utils/debug.d.ts.map +1 -0
  190. package/dist/utils/debug.js +100 -0
  191. package/dist/utils/index.d.ts +4 -0
  192. package/dist/utils/index.d.ts.map +1 -0
  193. package/dist/utils/index.js +3 -0
  194. package/dist/utils/path-safety.d.ts +21 -0
  195. package/dist/utils/path-safety.d.ts.map +1 -0
  196. package/dist/utils/path-safety.js +49 -0
  197. package/dist/utils/severity.d.ts +37 -0
  198. package/dist/utils/severity.d.ts.map +1 -0
  199. package/dist/utils/severity.js +22 -0
  200. package/dist/validation/aps-validator.d.ts +66 -0
  201. package/dist/validation/aps-validator.d.ts.map +1 -0
  202. package/dist/validation/aps-validator.js +173 -0
  203. package/dist/validation/errors.d.ts +52 -0
  204. package/dist/validation/errors.d.ts.map +1 -0
  205. package/dist/validation/errors.js +115 -0
  206. package/dist/validation/index.d.ts +8 -0
  207. package/dist/validation/index.d.ts.map +1 -0
  208. package/dist/validation/index.js +13 -0
  209. package/dist/warnings/index.d.ts +2 -0
  210. package/dist/warnings/index.d.ts.map +1 -0
  211. package/dist/warnings/index.js +1 -0
  212. package/dist/warnings/warning-id.d.ts +180 -0
  213. package/dist/warnings/warning-id.d.ts.map +1 -0
  214. package/dist/warnings/warning-id.js +257 -0
  215. package/package.json +79 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validation/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,EACL,YAAY,EACZ,SAAS,EACT,eAAe,EACf,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,eAAe,EACpB,sBAAsB,EACtB,eAAe,EACf,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Validation Module Public API
3
+ *
4
+ * Exports validation utilities for APS plans.
5
+ */
6
+ import { generateHash } from '../crypto/index.js';
7
+ import { validator as defaultValidator } from './aps-validator.js';
8
+ // Main validator
9
+ export { APSValidator, validator, validateAPSPlan, } from './aps-validator.js';
10
+ // Error types and formatters
11
+ export { ValidationError, SchemaValidationError, HashValidationError, formatValidationErrors, formatZodErrors, createValidationSummary, } from './errors.js';
12
+ // Initialize the validator with the hash function
13
+ defaultValidator.setHashValidator(generateHash);
@@ -0,0 +1,2 @@
1
+ export { WARNING_ID_PATTERN, ParsedWarningIdSchema, type ParsedWarningId, generateWarningId, createWarningId, parseWarningId, isValidWarningId, findWarningById, findWarningsByRule, findWarningsByFile, indexWarningsById, getWarningIds, generateShortId, resolveShortId, } from './warning-id.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/warnings/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,eAAe,EACpB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,cAAc,GACf,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export { WARNING_ID_PATTERN, ParsedWarningIdSchema, generateWarningId, createWarningId, parseWarningId, isValidWarningId, findWarningById, findWarningsByRule, findWarningsByFile, indexWarningsById, getWarningIds, generateShortId, resolveShortId, } from './warning-id.js';
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Warning ID System
3
+ *
4
+ * Provides unique, stable warning identifiers for the explain command.
5
+ * Warning IDs encode the rule, file, and line number to enable precise lookup.
6
+ *
7
+ * Format: {rule}-{file}:{line}
8
+ * Example: AP-003-src/utils/helpers.ts:42
9
+ *
10
+ * @module warnings/warning-id
11
+ */
12
+ import { z } from 'zod';
13
+ import type { Warning } from '../antipattern/types.js';
14
+ /**
15
+ * Pattern for valid warning IDs
16
+ * Format: {RULE}-{FILE}:{LINE}
17
+ * Examples:
18
+ * - AP-003-src/utils/helpers.ts:42
19
+ * - ARCH-001-src/api/handler.ts:15
20
+ * - BOUND-001-src/db/queries.ts:100
21
+ */
22
+ export declare const WARNING_ID_PATTERN: RegExp;
23
+ /**
24
+ * Schema for parsed warning ID components
25
+ */
26
+ export declare const ParsedWarningIdSchema: z.ZodObject<{
27
+ rule: z.ZodString;
28
+ file: z.ZodString;
29
+ line: z.ZodNumber;
30
+ }, z.core.$strip>;
31
+ export type ParsedWarningId = z.infer<typeof ParsedWarningIdSchema>;
32
+ /**
33
+ * Generate a unique warning ID from a warning object
34
+ *
35
+ * The ID format is: {rule}-{file}:{line}
36
+ * This ensures uniqueness per warning instance while remaining human-readable.
37
+ *
38
+ * @param warning - The warning object
39
+ * @returns A unique warning ID string
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const warning = {
44
+ * id: 'AP-003',
45
+ * location: { file: 'src/utils/helpers.ts', line: 42 }
46
+ * };
47
+ * const warningId = generateWarningId(warning);
48
+ * // Returns: 'AP-003-src/utils/helpers.ts:42'
49
+ * ```
50
+ */
51
+ export declare function generateWarningId(warning: Pick<Warning, 'id' | 'location'>): string;
52
+ /**
53
+ * Generate a warning ID from components
54
+ *
55
+ * @param rule - The rule ID (e.g., 'AP-003', 'ARCH-001')
56
+ * @param file - File path relative to workspace root
57
+ * @param line - Line number (1-based)
58
+ * @returns A unique warning ID string
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const warningId = createWarningId('AP-003', 'src/utils/helpers.ts', 42);
63
+ * // Returns: 'AP-003-src/utils/helpers.ts:42'
64
+ * ```
65
+ */
66
+ export declare function createWarningId(rule: string, file: string, line: number): string;
67
+ /**
68
+ * Parse a warning ID into its components
69
+ *
70
+ * @param warningId - The warning ID to parse
71
+ * @returns Parsed components (rule, file, line) or null if invalid
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * const parsed = parseWarningId('AP-003-src/utils/helpers.ts:42');
76
+ * // Returns: { rule: 'AP-003', file: 'src/utils/helpers.ts', line: 42 }
77
+ *
78
+ * const invalid = parseWarningId('invalid-id');
79
+ * // Returns: null
80
+ * ```
81
+ */
82
+ export declare function parseWarningId(warningId: string): ParsedWarningId | null;
83
+ /**
84
+ * Validate a warning ID string
85
+ *
86
+ * @param warningId - The warning ID to validate
87
+ * @returns true if the ID is valid, false otherwise
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * isValidWarningId('AP-003-src/utils/helpers.ts:42'); // true
92
+ * isValidWarningId('invalid'); // false
93
+ * isValidWarningId('AP-003'); // false (missing file:line)
94
+ * ```
95
+ */
96
+ export declare function isValidWarningId(warningId: string): boolean;
97
+ /**
98
+ * Find a warning in a list by its warning ID
99
+ *
100
+ * @param warnings - Array of warnings to search
101
+ * @param warningId - The warning ID to find
102
+ * @returns The matching warning or undefined
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const warnings = [...]; // From check results
107
+ * const warning = findWarningById(warnings, 'AP-003-src/utils/helpers.ts:42');
108
+ * if (warning) {
109
+ * console.log(warning.message);
110
+ * }
111
+ * ```
112
+ */
113
+ export declare function findWarningById(warnings: Warning[], warningId: string): Warning | undefined;
114
+ /**
115
+ * Find all warnings matching a rule ID (partial match)
116
+ *
117
+ * @param warnings - Array of warnings to search
118
+ * @param ruleId - The rule ID to match (e.g., 'AP-003')
119
+ * @returns Array of matching warnings
120
+ *
121
+ * @example
122
+ * ```ts
123
+ * const warnings = [...]; // From check results
124
+ * const anyWarnings = findWarningsByRule(warnings, 'AP-003');
125
+ * console.log(`Found ${anyWarnings.length} explicit any types`);
126
+ * ```
127
+ */
128
+ export declare function findWarningsByRule(warnings: Warning[], ruleId: string): Warning[];
129
+ /**
130
+ * Find all warnings in a specific file
131
+ *
132
+ * @param warnings - Array of warnings to search
133
+ * @param file - File path to match
134
+ * @returns Array of matching warnings
135
+ */
136
+ export declare function findWarningsByFile(warnings: Warning[], file: string): Warning[];
137
+ /**
138
+ * Generate warning IDs for all warnings in a list
139
+ *
140
+ * @param warnings - Array of warnings
141
+ * @returns Map of warning ID to warning
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const warnings = [...]; // From check results
146
+ * const warningMap = indexWarningsById(warnings);
147
+ *
148
+ * // Quick lookup by ID
149
+ * const warning = warningMap.get('AP-003-src/utils/helpers.ts:42');
150
+ * ```
151
+ */
152
+ export declare function indexWarningsById(warnings: Warning[]): Map<string, Warning>;
153
+ /**
154
+ * Get all warning IDs from a list of warnings
155
+ *
156
+ * @param warnings - Array of warnings
157
+ * @returns Array of warning IDs
158
+ */
159
+ export declare function getWarningIds(warnings: Warning[]): string[];
160
+ /**
161
+ * Generate a short ID for display purposes
162
+ *
163
+ * Useful when the full warning ID is too long for terminal display.
164
+ * Format: {rule}:{line} (e.g., AP-003:42)
165
+ *
166
+ * @param warning - The warning object
167
+ * @returns A shortened warning ID
168
+ */
169
+ export declare function generateShortId(warning: Pick<Warning, 'id' | 'location'>): string;
170
+ /**
171
+ * Attempt to resolve a short ID to a full warning ID
172
+ *
173
+ * Searches warnings by rule and line, returns full ID if unique match found.
174
+ *
175
+ * @param warnings - Array of warnings to search
176
+ * @param shortId - Short ID in format RULE:LINE (e.g., 'AP-003:42')
177
+ * @returns Full warning ID, array of matches if ambiguous, or null if not found
178
+ */
179
+ export declare function resolveShortId(warnings: Warning[], shortId: string): string | string[] | null;
180
+ //# sourceMappingURL=warning-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warning-id.d.ts","sourceRoot":"","sources":["../../src/warnings/warning-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAMvD;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;iBAOhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAMpE;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,CAAC,GAAG,MAAM,CAGnF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhF;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAmBxE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3D;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAU3F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,EAAE,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,EAAE,CAE/E;AAMD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAO3E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAE3D;AAMD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,UAAU,CAAC,GAAG,MAAM,CAEjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAqB7F"}
@@ -0,0 +1,257 @@
1
+ /**
2
+ * Warning ID System
3
+ *
4
+ * Provides unique, stable warning identifiers for the explain command.
5
+ * Warning IDs encode the rule, file, and line number to enable precise lookup.
6
+ *
7
+ * Format: {rule}-{file}:{line}
8
+ * Example: AP-003-src/utils/helpers.ts:42
9
+ *
10
+ * @module warnings/warning-id
11
+ */
12
+ import { z } from 'zod';
13
+ // =============================================================================
14
+ // Warning ID Schema
15
+ // =============================================================================
16
+ /**
17
+ * Pattern for valid warning IDs
18
+ * Format: {RULE}-{FILE}:{LINE}
19
+ * Examples:
20
+ * - AP-003-src/utils/helpers.ts:42
21
+ * - ARCH-001-src/api/handler.ts:15
22
+ * - BOUND-001-src/db/queries.ts:100
23
+ */
24
+ export const WARNING_ID_PATTERN = /^(AP|ARCH|BOUND)-\d{3}-[^:]+:\d+$/;
25
+ /**
26
+ * Schema for parsed warning ID components
27
+ */
28
+ export const ParsedWarningIdSchema = z.object({
29
+ rule: z
30
+ .string()
31
+ .regex(/^(AP|ARCH|BOUND)-\d{3}$/)
32
+ .describe('The rule ID (e.g., AP-003, ARCH-001)'),
33
+ file: z.string().min(1).describe('File path relative to workspace root'),
34
+ line: z.number().int().positive().describe('Line number (1-based)'),
35
+ });
36
+ // =============================================================================
37
+ // Warning ID Generation
38
+ // =============================================================================
39
+ /**
40
+ * Generate a unique warning ID from a warning object
41
+ *
42
+ * The ID format is: {rule}-{file}:{line}
43
+ * This ensures uniqueness per warning instance while remaining human-readable.
44
+ *
45
+ * @param warning - The warning object
46
+ * @returns A unique warning ID string
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * const warning = {
51
+ * id: 'AP-003',
52
+ * location: { file: 'src/utils/helpers.ts', line: 42 }
53
+ * };
54
+ * const warningId = generateWarningId(warning);
55
+ * // Returns: 'AP-003-src/utils/helpers.ts:42'
56
+ * ```
57
+ */
58
+ export function generateWarningId(warning) {
59
+ const { id, location } = warning;
60
+ return `${id}-${location.file}:${location.line}`;
61
+ }
62
+ /**
63
+ * Generate a warning ID from components
64
+ *
65
+ * @param rule - The rule ID (e.g., 'AP-003', 'ARCH-001')
66
+ * @param file - File path relative to workspace root
67
+ * @param line - Line number (1-based)
68
+ * @returns A unique warning ID string
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const warningId = createWarningId('AP-003', 'src/utils/helpers.ts', 42);
73
+ * // Returns: 'AP-003-src/utils/helpers.ts:42'
74
+ * ```
75
+ */
76
+ export function createWarningId(rule, file, line) {
77
+ return `${rule}-${file}:${line}`;
78
+ }
79
+ // =============================================================================
80
+ // Warning ID Parsing
81
+ // =============================================================================
82
+ /**
83
+ * Parse a warning ID into its components
84
+ *
85
+ * @param warningId - The warning ID to parse
86
+ * @returns Parsed components (rule, file, line) or null if invalid
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * const parsed = parseWarningId('AP-003-src/utils/helpers.ts:42');
91
+ * // Returns: { rule: 'AP-003', file: 'src/utils/helpers.ts', line: 42 }
92
+ *
93
+ * const invalid = parseWarningId('invalid-id');
94
+ * // Returns: null
95
+ * ```
96
+ */
97
+ export function parseWarningId(warningId) {
98
+ // Match the pattern: RULE-FILE:LINE
99
+ // RULE is like AP-003 or ARCH-001 (letters-digits)
100
+ // FILE can contain any characters except :
101
+ // LINE is a positive integer
102
+ const match = warningId.match(/^((?:AP|ARCH|BOUND)-\d{3})-(.+):(\d+)$/);
103
+ if (!match) {
104
+ return null;
105
+ }
106
+ const [, rule, file, lineStr] = match;
107
+ const line = parseInt(lineStr, 10);
108
+ if (isNaN(line) || line <= 0) {
109
+ return null;
110
+ }
111
+ return { rule, file, line };
112
+ }
113
+ /**
114
+ * Validate a warning ID string
115
+ *
116
+ * @param warningId - The warning ID to validate
117
+ * @returns true if the ID is valid, false otherwise
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * isValidWarningId('AP-003-src/utils/helpers.ts:42'); // true
122
+ * isValidWarningId('invalid'); // false
123
+ * isValidWarningId('AP-003'); // false (missing file:line)
124
+ * ```
125
+ */
126
+ export function isValidWarningId(warningId) {
127
+ return parseWarningId(warningId) !== null;
128
+ }
129
+ // =============================================================================
130
+ // Warning Lookup
131
+ // =============================================================================
132
+ /**
133
+ * Find a warning in a list by its warning ID
134
+ *
135
+ * @param warnings - Array of warnings to search
136
+ * @param warningId - The warning ID to find
137
+ * @returns The matching warning or undefined
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const warnings = [...]; // From check results
142
+ * const warning = findWarningById(warnings, 'AP-003-src/utils/helpers.ts:42');
143
+ * if (warning) {
144
+ * console.log(warning.message);
145
+ * }
146
+ * ```
147
+ */
148
+ export function findWarningById(warnings, warningId) {
149
+ const parsed = parseWarningId(warningId);
150
+ if (!parsed) {
151
+ return undefined;
152
+ }
153
+ return warnings.find((w) => w.id === parsed.rule && w.location.file === parsed.file && w.location.line === parsed.line);
154
+ }
155
+ /**
156
+ * Find all warnings matching a rule ID (partial match)
157
+ *
158
+ * @param warnings - Array of warnings to search
159
+ * @param ruleId - The rule ID to match (e.g., 'AP-003')
160
+ * @returns Array of matching warnings
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * const warnings = [...]; // From check results
165
+ * const anyWarnings = findWarningsByRule(warnings, 'AP-003');
166
+ * console.log(`Found ${anyWarnings.length} explicit any types`);
167
+ * ```
168
+ */
169
+ export function findWarningsByRule(warnings, ruleId) {
170
+ return warnings.filter((w) => w.id === ruleId);
171
+ }
172
+ /**
173
+ * Find all warnings in a specific file
174
+ *
175
+ * @param warnings - Array of warnings to search
176
+ * @param file - File path to match
177
+ * @returns Array of matching warnings
178
+ */
179
+ export function findWarningsByFile(warnings, file) {
180
+ return warnings.filter((w) => w.location.file === file);
181
+ }
182
+ // =============================================================================
183
+ // Warning ID Collection
184
+ // =============================================================================
185
+ /**
186
+ * Generate warning IDs for all warnings in a list
187
+ *
188
+ * @param warnings - Array of warnings
189
+ * @returns Map of warning ID to warning
190
+ *
191
+ * @example
192
+ * ```ts
193
+ * const warnings = [...]; // From check results
194
+ * const warningMap = indexWarningsById(warnings);
195
+ *
196
+ * // Quick lookup by ID
197
+ * const warning = warningMap.get('AP-003-src/utils/helpers.ts:42');
198
+ * ```
199
+ */
200
+ export function indexWarningsById(warnings) {
201
+ const map = new Map();
202
+ for (const warning of warnings) {
203
+ const id = generateWarningId(warning);
204
+ map.set(id, warning);
205
+ }
206
+ return map;
207
+ }
208
+ /**
209
+ * Get all warning IDs from a list of warnings
210
+ *
211
+ * @param warnings - Array of warnings
212
+ * @returns Array of warning IDs
213
+ */
214
+ export function getWarningIds(warnings) {
215
+ return warnings.map(generateWarningId);
216
+ }
217
+ // =============================================================================
218
+ // Short ID Support
219
+ // =============================================================================
220
+ /**
221
+ * Generate a short ID for display purposes
222
+ *
223
+ * Useful when the full warning ID is too long for terminal display.
224
+ * Format: {rule}:{line} (e.g., AP-003:42)
225
+ *
226
+ * @param warning - The warning object
227
+ * @returns A shortened warning ID
228
+ */
229
+ export function generateShortId(warning) {
230
+ return `${warning.id}:${warning.location.line}`;
231
+ }
232
+ /**
233
+ * Attempt to resolve a short ID to a full warning ID
234
+ *
235
+ * Searches warnings by rule and line, returns full ID if unique match found.
236
+ *
237
+ * @param warnings - Array of warnings to search
238
+ * @param shortId - Short ID in format RULE:LINE (e.g., 'AP-003:42')
239
+ * @returns Full warning ID, array of matches if ambiguous, or null if not found
240
+ */
241
+ export function resolveShortId(warnings, shortId) {
242
+ const match = shortId.match(/^((?:AP|ARCH|BOUND)-\d{3}):(\d+)$/);
243
+ if (!match) {
244
+ return null;
245
+ }
246
+ const [, rule, lineStr] = match;
247
+ const line = parseInt(lineStr, 10);
248
+ const matches = warnings.filter((w) => w.id === rule && w.location.line === line);
249
+ if (matches.length === 0) {
250
+ return null;
251
+ }
252
+ if (matches.length === 1) {
253
+ return generateWarningId(matches[0]);
254
+ }
255
+ // Multiple matches - return all full IDs for disambiguation
256
+ return matches.map(generateWarningId);
257
+ }
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@eddacraft/anvil-core",
3
+ "version": "0.1.0",
4
+ "description": "Core domain logic for Anvil — schemas, types, analysis, and validation",
5
+ "license": "PROPRIETARY",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./antipattern": {
15
+ "types": "./dist/antipattern/index.d.ts",
16
+ "import": "./dist/antipattern/index.js"
17
+ },
18
+ "./suppression": {
19
+ "types": "./dist/suppression/index.d.ts",
20
+ "import": "./dist/suppression/index.js"
21
+ },
22
+ "./architecture": {
23
+ "types": "./dist/architecture/index.d.ts",
24
+ "import": "./dist/architecture/index.js"
25
+ },
26
+ "./drift": {
27
+ "types": "./dist/drift/index.d.ts",
28
+ "import": "./dist/drift/index.js"
29
+ },
30
+ "./validation": {
31
+ "types": "./dist/validation/index.d.ts",
32
+ "import": "./dist/validation/index.js"
33
+ },
34
+ "./warnings": {
35
+ "types": "./dist/warnings/index.d.ts",
36
+ "import": "./dist/warnings/index.js"
37
+ },
38
+ "./explain": {
39
+ "types": "./dist/explain/index.d.ts",
40
+ "import": "./dist/explain/index.js"
41
+ },
42
+ "./provenance": {
43
+ "types": "./dist/provenance/index.d.ts",
44
+ "import": "./dist/provenance/index.js"
45
+ },
46
+ "./crypto": {
47
+ "types": "./dist/crypto/index.d.ts",
48
+ "import": "./dist/crypto/index.js"
49
+ },
50
+ "./utils": {
51
+ "types": "./dist/utils/index.d.ts",
52
+ "import": "./dist/utils/index.js"
53
+ }
54
+ },
55
+ "dependencies": {
56
+ "json-schema": "^0.4.0",
57
+ "minimatch": "^10.2.0",
58
+ "yaml": "^2.8.2",
59
+ "zod": "^4.3.6"
60
+ },
61
+ "devDependencies": {
62
+ "vitest": "^4.0.18"
63
+ },
64
+ "files": [
65
+ "dist",
66
+ "README.md"
67
+ ],
68
+ "keywords": [
69
+ "anvil",
70
+ "core",
71
+ "domain"
72
+ ],
73
+ "scripts": {
74
+ "build": "tsc -p tsconfig.lib.json",
75
+ "test": "vitest run",
76
+ "test:watch": "vitest",
77
+ "typecheck": "tsc --noEmit"
78
+ }
79
+ }