@grafema/util 0.3.0-beta

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 (324) hide show
  1. package/LICENSE +190 -0
  2. package/dist/api/GraphAPI.d.ts +87 -0
  3. package/dist/api/GraphAPI.d.ts.map +1 -0
  4. package/dist/api/GraphAPI.js +212 -0
  5. package/dist/api/GraphAPI.js.map +1 -0
  6. package/dist/api/GuaranteeAPI.d.ts +147 -0
  7. package/dist/api/GuaranteeAPI.d.ts.map +1 -0
  8. package/dist/api/GuaranteeAPI.js +290 -0
  9. package/dist/api/GuaranteeAPI.js.map +1 -0
  10. package/dist/config/ConfigLoader.d.ts +214 -0
  11. package/dist/config/ConfigLoader.d.ts.map +1 -0
  12. package/dist/config/ConfigLoader.js +441 -0
  13. package/dist/config/ConfigLoader.js.map +1 -0
  14. package/dist/config/index.d.ts +6 -0
  15. package/dist/config/index.d.ts.map +1 -0
  16. package/dist/config/index.js +5 -0
  17. package/dist/config/index.js.map +1 -0
  18. package/dist/core/CoverageAnalyzer.d.ts +65 -0
  19. package/dist/core/CoverageAnalyzer.d.ts.map +1 -0
  20. package/dist/core/CoverageAnalyzer.js +199 -0
  21. package/dist/core/CoverageAnalyzer.js.map +1 -0
  22. package/dist/core/FileExplainer.d.ts +101 -0
  23. package/dist/core/FileExplainer.d.ts.map +1 -0
  24. package/dist/core/FileExplainer.js +140 -0
  25. package/dist/core/FileExplainer.js.map +1 -0
  26. package/dist/core/FileOverview.d.ts +124 -0
  27. package/dist/core/FileOverview.d.ts.map +1 -0
  28. package/dist/core/FileOverview.js +279 -0
  29. package/dist/core/FileOverview.js.map +1 -0
  30. package/dist/core/GrafemaUri.d.ts +66 -0
  31. package/dist/core/GrafemaUri.d.ts.map +1 -0
  32. package/dist/core/GrafemaUri.js +191 -0
  33. package/dist/core/GrafemaUri.js.map +1 -0
  34. package/dist/core/GraphBackend.d.ts +158 -0
  35. package/dist/core/GraphBackend.d.ts.map +1 -0
  36. package/dist/core/GraphBackend.js +85 -0
  37. package/dist/core/GraphBackend.js.map +1 -0
  38. package/dist/core/GraphFreshnessChecker.d.ts +33 -0
  39. package/dist/core/GraphFreshnessChecker.d.ts.map +1 -0
  40. package/dist/core/GraphFreshnessChecker.js +104 -0
  41. package/dist/core/GraphFreshnessChecker.js.map +1 -0
  42. package/dist/core/GuaranteeManager.d.ts +254 -0
  43. package/dist/core/GuaranteeManager.d.ts.map +1 -0
  44. package/dist/core/GuaranteeManager.js +447 -0
  45. package/dist/core/GuaranteeManager.js.map +1 -0
  46. package/dist/core/HashUtils.d.ts +24 -0
  47. package/dist/core/HashUtils.d.ts.map +1 -0
  48. package/dist/core/HashUtils.js +46 -0
  49. package/dist/core/HashUtils.js.map +1 -0
  50. package/dist/core/IncrementalReanalyzer.d.ts +33 -0
  51. package/dist/core/IncrementalReanalyzer.d.ts.map +1 -0
  52. package/dist/core/IncrementalReanalyzer.js +67 -0
  53. package/dist/core/IncrementalReanalyzer.js.map +1 -0
  54. package/dist/core/ResourceRegistry.d.ts +17 -0
  55. package/dist/core/ResourceRegistry.d.ts.map +1 -0
  56. package/dist/core/ResourceRegistry.js +32 -0
  57. package/dist/core/ResourceRegistry.js.map +1 -0
  58. package/dist/core/SemanticId.d.ts +159 -0
  59. package/dist/core/SemanticId.d.ts.map +1 -0
  60. package/dist/core/SemanticId.js +291 -0
  61. package/dist/core/SemanticId.js.map +1 -0
  62. package/dist/core/VersionManager.d.ts +166 -0
  63. package/dist/core/VersionManager.d.ts.map +1 -0
  64. package/dist/core/VersionManager.js +239 -0
  65. package/dist/core/VersionManager.js.map +1 -0
  66. package/dist/core/brandNodeInternal.d.ts +14 -0
  67. package/dist/core/brandNodeInternal.d.ts.map +1 -0
  68. package/dist/core/brandNodeInternal.js +4 -0
  69. package/dist/core/brandNodeInternal.js.map +1 -0
  70. package/dist/core/nodes/GuaranteeNode.d.ts +76 -0
  71. package/dist/core/nodes/GuaranteeNode.d.ts.map +1 -0
  72. package/dist/core/nodes/GuaranteeNode.js +118 -0
  73. package/dist/core/nodes/GuaranteeNode.js.map +1 -0
  74. package/dist/core/nodes/IssueNode.d.ts +73 -0
  75. package/dist/core/nodes/IssueNode.d.ts.map +1 -0
  76. package/dist/core/nodes/IssueNode.js +130 -0
  77. package/dist/core/nodes/IssueNode.js.map +1 -0
  78. package/dist/core/nodes/NodeKind.d.ts +104 -0
  79. package/dist/core/nodes/NodeKind.d.ts.map +1 -0
  80. package/dist/core/nodes/NodeKind.js +166 -0
  81. package/dist/core/nodes/NodeKind.js.map +1 -0
  82. package/dist/diagnostics/DiagnosticCollector.d.ts +103 -0
  83. package/dist/diagnostics/DiagnosticCollector.d.ts.map +1 -0
  84. package/dist/diagnostics/DiagnosticCollector.js +133 -0
  85. package/dist/diagnostics/DiagnosticCollector.js.map +1 -0
  86. package/dist/diagnostics/DiagnosticReporter.d.ts +122 -0
  87. package/dist/diagnostics/DiagnosticReporter.d.ts.map +1 -0
  88. package/dist/diagnostics/DiagnosticReporter.js +300 -0
  89. package/dist/diagnostics/DiagnosticReporter.js.map +1 -0
  90. package/dist/diagnostics/DiagnosticWriter.d.ts +31 -0
  91. package/dist/diagnostics/DiagnosticWriter.d.ts.map +1 -0
  92. package/dist/diagnostics/DiagnosticWriter.js +44 -0
  93. package/dist/diagnostics/DiagnosticWriter.js.map +1 -0
  94. package/dist/diagnostics/categories.d.ts +57 -0
  95. package/dist/diagnostics/categories.d.ts.map +1 -0
  96. package/dist/diagnostics/categories.js +71 -0
  97. package/dist/diagnostics/categories.js.map +1 -0
  98. package/dist/diagnostics/index.d.ts +17 -0
  99. package/dist/diagnostics/index.d.ts.map +1 -0
  100. package/dist/diagnostics/index.js +15 -0
  101. package/dist/diagnostics/index.js.map +1 -0
  102. package/dist/errors/GrafemaError.d.ts +200 -0
  103. package/dist/errors/GrafemaError.d.ts.map +1 -0
  104. package/dist/errors/GrafemaError.js +209 -0
  105. package/dist/errors/GrafemaError.js.map +1 -0
  106. package/dist/index.d.ts +75 -0
  107. package/dist/index.d.ts.map +1 -0
  108. package/dist/index.js +76 -0
  109. package/dist/index.js.map +1 -0
  110. package/dist/instructions/index.d.ts +8 -0
  111. package/dist/instructions/index.d.ts.map +1 -0
  112. package/dist/instructions/index.js +20 -0
  113. package/dist/instructions/index.js.map +1 -0
  114. package/dist/instructions/onboarding.md +133 -0
  115. package/dist/knowledge/KnowledgeBase.d.ts +113 -0
  116. package/dist/knowledge/KnowledgeBase.d.ts.map +1 -0
  117. package/dist/knowledge/KnowledgeBase.js +420 -0
  118. package/dist/knowledge/KnowledgeBase.js.map +1 -0
  119. package/dist/knowledge/SemanticAddressResolver.d.ts +59 -0
  120. package/dist/knowledge/SemanticAddressResolver.d.ts.map +1 -0
  121. package/dist/knowledge/SemanticAddressResolver.js +160 -0
  122. package/dist/knowledge/SemanticAddressResolver.js.map +1 -0
  123. package/dist/knowledge/git-ingest.d.ts +58 -0
  124. package/dist/knowledge/git-ingest.d.ts.map +1 -0
  125. package/dist/knowledge/git-ingest.js +301 -0
  126. package/dist/knowledge/git-ingest.js.map +1 -0
  127. package/dist/knowledge/git-queries.d.ts +86 -0
  128. package/dist/knowledge/git-queries.d.ts.map +1 -0
  129. package/dist/knowledge/git-queries.js +177 -0
  130. package/dist/knowledge/git-queries.js.map +1 -0
  131. package/dist/knowledge/index.d.ts +14 -0
  132. package/dist/knowledge/index.d.ts.map +1 -0
  133. package/dist/knowledge/index.js +10 -0
  134. package/dist/knowledge/index.js.map +1 -0
  135. package/dist/knowledge/parser.d.ts +39 -0
  136. package/dist/knowledge/parser.d.ts.map +1 -0
  137. package/dist/knowledge/parser.js +292 -0
  138. package/dist/knowledge/parser.js.map +1 -0
  139. package/dist/knowledge/types.d.ts +133 -0
  140. package/dist/knowledge/types.d.ts.map +1 -0
  141. package/dist/knowledge/types.js +8 -0
  142. package/dist/knowledge/types.js.map +1 -0
  143. package/dist/logging/Logger.d.ts +98 -0
  144. package/dist/logging/Logger.d.ts.map +1 -0
  145. package/dist/logging/Logger.js +274 -0
  146. package/dist/logging/Logger.js.map +1 -0
  147. package/dist/notation/archetypes.d.ts +36 -0
  148. package/dist/notation/archetypes.d.ts.map +1 -0
  149. package/dist/notation/archetypes.js +173 -0
  150. package/dist/notation/archetypes.js.map +1 -0
  151. package/dist/notation/fold.d.ts +25 -0
  152. package/dist/notation/fold.d.ts.map +1 -0
  153. package/dist/notation/fold.js +598 -0
  154. package/dist/notation/fold.js.map +1 -0
  155. package/dist/notation/index.d.ts +18 -0
  156. package/dist/notation/index.d.ts.map +1 -0
  157. package/dist/notation/index.js +16 -0
  158. package/dist/notation/index.js.map +1 -0
  159. package/dist/notation/lodExtractor.d.ts +32 -0
  160. package/dist/notation/lodExtractor.d.ts.map +1 -0
  161. package/dist/notation/lodExtractor.js +149 -0
  162. package/dist/notation/lodExtractor.js.map +1 -0
  163. package/dist/notation/nameShortener.d.ts +22 -0
  164. package/dist/notation/nameShortener.d.ts.map +1 -0
  165. package/dist/notation/nameShortener.js +24 -0
  166. package/dist/notation/nameShortener.js.map +1 -0
  167. package/dist/notation/perspectives.d.ts +11 -0
  168. package/dist/notation/perspectives.d.ts.map +1 -0
  169. package/dist/notation/perspectives.js +16 -0
  170. package/dist/notation/perspectives.js.map +1 -0
  171. package/dist/notation/renderer.d.ts +31 -0
  172. package/dist/notation/renderer.d.ts.map +1 -0
  173. package/dist/notation/renderer.js +315 -0
  174. package/dist/notation/renderer.js.map +1 -0
  175. package/dist/notation/traceRenderer.d.ts +39 -0
  176. package/dist/notation/traceRenderer.d.ts.map +1 -0
  177. package/dist/notation/traceRenderer.js +358 -0
  178. package/dist/notation/traceRenderer.js.map +1 -0
  179. package/dist/notation/types.d.ts +66 -0
  180. package/dist/notation/types.d.ts.map +1 -0
  181. package/dist/notation/types.js +10 -0
  182. package/dist/notation/types.js.map +1 -0
  183. package/dist/queries/NodeContext.d.ts +81 -0
  184. package/dist/queries/NodeContext.d.ts.map +1 -0
  185. package/dist/queries/NodeContext.js +196 -0
  186. package/dist/queries/NodeContext.js.map +1 -0
  187. package/dist/queries/findCallsInFunction.d.ts +62 -0
  188. package/dist/queries/findCallsInFunction.d.ts.map +1 -0
  189. package/dist/queries/findCallsInFunction.js +169 -0
  190. package/dist/queries/findCallsInFunction.js.map +1 -0
  191. package/dist/queries/findContainingFunction.d.ts +57 -0
  192. package/dist/queries/findContainingFunction.d.ts.map +1 -0
  193. package/dist/queries/findContainingFunction.js +91 -0
  194. package/dist/queries/findContainingFunction.js.map +1 -0
  195. package/dist/queries/index.d.ts +18 -0
  196. package/dist/queries/index.d.ts.map +1 -0
  197. package/dist/queries/index.js +14 -0
  198. package/dist/queries/index.js.map +1 -0
  199. package/dist/queries/traceDataflow.d.ts +65 -0
  200. package/dist/queries/traceDataflow.d.ts.map +1 -0
  201. package/dist/queries/traceDataflow.js +754 -0
  202. package/dist/queries/traceDataflow.js.map +1 -0
  203. package/dist/queries/traceValues.d.ts +70 -0
  204. package/dist/queries/traceValues.d.ts.map +1 -0
  205. package/dist/queries/traceValues.js +373 -0
  206. package/dist/queries/traceValues.js.map +1 -0
  207. package/dist/queries/types.d.ts +166 -0
  208. package/dist/queries/types.d.ts.map +1 -0
  209. package/dist/queries/types.js +10 -0
  210. package/dist/queries/types.js.map +1 -0
  211. package/dist/schema/GraphSchemaExtractor.d.ts +53 -0
  212. package/dist/schema/GraphSchemaExtractor.d.ts.map +1 -0
  213. package/dist/schema/GraphSchemaExtractor.js +125 -0
  214. package/dist/schema/GraphSchemaExtractor.js.map +1 -0
  215. package/dist/schema/InterfaceSchemaExtractor.d.ts +73 -0
  216. package/dist/schema/InterfaceSchemaExtractor.d.ts.map +1 -0
  217. package/dist/schema/InterfaceSchemaExtractor.js +113 -0
  218. package/dist/schema/InterfaceSchemaExtractor.js.map +1 -0
  219. package/dist/schema/index.d.ts +5 -0
  220. package/dist/schema/index.d.ts.map +1 -0
  221. package/dist/schema/index.js +3 -0
  222. package/dist/schema/index.js.map +1 -0
  223. package/dist/storage/backends/RFDBServerBackend.d.ts +356 -0
  224. package/dist/storage/backends/RFDBServerBackend.d.ts.map +1 -0
  225. package/dist/storage/backends/RFDBServerBackend.js +748 -0
  226. package/dist/storage/backends/RFDBServerBackend.js.map +1 -0
  227. package/dist/storage/backends/typeValidation.d.ts +47 -0
  228. package/dist/storage/backends/typeValidation.d.ts.map +1 -0
  229. package/dist/storage/backends/typeValidation.js +141 -0
  230. package/dist/storage/backends/typeValidation.js.map +1 -0
  231. package/dist/utils/findRfdbBinary.d.ts +67 -0
  232. package/dist/utils/findRfdbBinary.d.ts.map +1 -0
  233. package/dist/utils/findRfdbBinary.js +261 -0
  234. package/dist/utils/findRfdbBinary.js.map +1 -0
  235. package/dist/utils/lazyDownload.d.ts +43 -0
  236. package/dist/utils/lazyDownload.d.ts.map +1 -0
  237. package/dist/utils/lazyDownload.js +175 -0
  238. package/dist/utils/lazyDownload.js.map +1 -0
  239. package/dist/utils/moduleResolution.d.ts +134 -0
  240. package/dist/utils/moduleResolution.d.ts.map +1 -0
  241. package/dist/utils/moduleResolution.js +189 -0
  242. package/dist/utils/moduleResolution.js.map +1 -0
  243. package/dist/utils/resolveNodeFile.d.ts +13 -0
  244. package/dist/utils/resolveNodeFile.d.ts.map +1 -0
  245. package/dist/utils/resolveNodeFile.js +18 -0
  246. package/dist/utils/resolveNodeFile.js.map +1 -0
  247. package/dist/utils/startRfdbServer.d.ts +63 -0
  248. package/dist/utils/startRfdbServer.d.ts.map +1 -0
  249. package/dist/utils/startRfdbServer.js +142 -0
  250. package/dist/utils/startRfdbServer.js.map +1 -0
  251. package/dist/validation/PathValidator.d.ts +80 -0
  252. package/dist/validation/PathValidator.d.ts.map +1 -0
  253. package/dist/validation/PathValidator.js +252 -0
  254. package/dist/validation/PathValidator.js.map +1 -0
  255. package/dist/version.d.ts +11 -0
  256. package/dist/version.d.ts.map +1 -0
  257. package/dist/version.js +26 -0
  258. package/dist/version.js.map +1 -0
  259. package/package.json +50 -0
  260. package/src/api/GraphAPI.ts +307 -0
  261. package/src/api/GuaranteeAPI.ts +402 -0
  262. package/src/config/ConfigLoader.ts +653 -0
  263. package/src/config/index.ts +13 -0
  264. package/src/core/CoverageAnalyzer.ts +243 -0
  265. package/src/core/FileExplainer.ts +179 -0
  266. package/src/core/FileOverview.ts +397 -0
  267. package/src/core/GrafemaUri.ts +216 -0
  268. package/src/core/GraphBackend.ts +266 -0
  269. package/src/core/GraphFreshnessChecker.ts +145 -0
  270. package/src/core/GuaranteeManager.ts +684 -0
  271. package/src/core/HashUtils.ts +48 -0
  272. package/src/core/IncrementalReanalyzer.ts +106 -0
  273. package/src/core/ResourceRegistry.ts +39 -0
  274. package/src/core/SemanticId.ts +423 -0
  275. package/src/core/VersionManager.ts +405 -0
  276. package/src/core/brandNodeInternal.ts +16 -0
  277. package/src/core/nodes/GuaranteeNode.ts +162 -0
  278. package/src/core/nodes/IssueNode.ts +177 -0
  279. package/src/core/nodes/NodeKind.ts +192 -0
  280. package/src/diagnostics/DiagnosticCollector.ts +170 -0
  281. package/src/diagnostics/DiagnosticReporter.ts +395 -0
  282. package/src/diagnostics/DiagnosticWriter.ts +50 -0
  283. package/src/diagnostics/categories.ts +104 -0
  284. package/src/diagnostics/index.ts +30 -0
  285. package/src/errors/GrafemaError.ts +297 -0
  286. package/src/index.ts +261 -0
  287. package/src/instructions/index.ts +21 -0
  288. package/src/instructions/onboarding.md +133 -0
  289. package/src/knowledge/KnowledgeBase.ts +486 -0
  290. package/src/knowledge/SemanticAddressResolver.ts +191 -0
  291. package/src/knowledge/git-ingest.ts +402 -0
  292. package/src/knowledge/git-queries.ts +269 -0
  293. package/src/knowledge/index.ts +29 -0
  294. package/src/knowledge/parser.ts +294 -0
  295. package/src/knowledge/types.ts +146 -0
  296. package/src/logging/Logger.ts +303 -0
  297. package/src/notation/archetypes.ts +189 -0
  298. package/src/notation/fold.ts +696 -0
  299. package/src/notation/index.ts +27 -0
  300. package/src/notation/lodExtractor.ts +177 -0
  301. package/src/notation/nameShortener.ts +24 -0
  302. package/src/notation/perspectives.ts +18 -0
  303. package/src/notation/renderer.ts +394 -0
  304. package/src/notation/traceRenderer.ts +458 -0
  305. package/src/notation/types.ts +79 -0
  306. package/src/queries/NodeContext.ts +280 -0
  307. package/src/queries/findCallsInFunction.ts +249 -0
  308. package/src/queries/findContainingFunction.ts +124 -0
  309. package/src/queries/index.ts +44 -0
  310. package/src/queries/traceDataflow.ts +838 -0
  311. package/src/queries/traceValues.ts +531 -0
  312. package/src/queries/types.ts +191 -0
  313. package/src/schema/GraphSchemaExtractor.ts +177 -0
  314. package/src/schema/InterfaceSchemaExtractor.ts +173 -0
  315. package/src/schema/index.ts +5 -0
  316. package/src/storage/backends/RFDBServerBackend.ts +895 -0
  317. package/src/storage/backends/typeValidation.ts +154 -0
  318. package/src/utils/findRfdbBinary.ts +288 -0
  319. package/src/utils/lazyDownload.ts +206 -0
  320. package/src/utils/moduleResolution.ts +271 -0
  321. package/src/utils/resolveNodeFile.ts +18 -0
  322. package/src/utils/startRfdbServer.ts +197 -0
  323. package/src/validation/PathValidator.ts +334 -0
  324. package/src/version.ts +28 -0
@@ -0,0 +1,297 @@
1
+ /**
2
+ * GrafemaError - Error hierarchy for Grafema
3
+ *
4
+ * All errors extend the native JavaScript Error class for compatibility
5
+ * with PluginResult.errors[] (Error[]).
6
+ *
7
+ * Error types:
8
+ * - ConfigError: Configuration parsing/validation errors (fatal)
9
+ * - FileAccessError: File system access errors (error)
10
+ * - LanguageError: Unsupported language/parsing errors (warning)
11
+ * - DatabaseError: RFDB database errors (fatal)
12
+ * - PluginError: Plugin execution errors (error)
13
+ * - AnalysisError: Analysis/timeout errors (error)
14
+ */
15
+
16
+ import type { PluginPhase } from '@grafema/types';
17
+ import type { Diagnostic } from '../diagnostics/DiagnosticCollector.js';
18
+
19
+ /**
20
+ * Context for error reporting
21
+ */
22
+ export interface ErrorContext {
23
+ filePath?: string;
24
+ lineNumber?: number;
25
+ phase?: PluginPhase;
26
+ plugin?: string;
27
+ [key: string]: unknown;
28
+ }
29
+
30
+ /**
31
+ * JSON representation of GrafemaError
32
+ */
33
+ export interface GrafemaErrorJSON {
34
+ code: string;
35
+ severity: 'fatal' | 'error' | 'warning';
36
+ message: string;
37
+ context: ErrorContext;
38
+ suggestion?: string;
39
+ }
40
+
41
+ /**
42
+ * Abstract base class for all Grafema errors.
43
+ *
44
+ * Extends native Error for compatibility with PluginResult.errors[].
45
+ */
46
+ export abstract class GrafemaError extends Error {
47
+ abstract readonly code: string;
48
+ abstract readonly severity: 'fatal' | 'error' | 'warning';
49
+ readonly context: ErrorContext;
50
+ readonly suggestion?: string;
51
+
52
+ constructor(message: string, context: ErrorContext = {}, suggestion?: string) {
53
+ super(message);
54
+ this.name = this.constructor.name;
55
+ this.context = context;
56
+ this.suggestion = suggestion;
57
+
58
+ // Ensure proper prototype chain for instanceof checks
59
+ Object.setPrototypeOf(this, new.target.prototype);
60
+
61
+ // Capture stack trace (V8 specific)
62
+ if (Error.captureStackTrace) {
63
+ Error.captureStackTrace(this, this.constructor);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Serialize error to JSON for diagnostics.log
69
+ */
70
+ toJSON(): GrafemaErrorJSON {
71
+ return {
72
+ code: this.code,
73
+ severity: this.severity,
74
+ message: this.message,
75
+ context: this.context,
76
+ suggestion: this.suggestion,
77
+ };
78
+ }
79
+ }
80
+
81
+ /**
82
+ * Configuration error - config.json parsing, validation, missing required fields
83
+ *
84
+ * Severity: fatal (always)
85
+ * Codes: ERR_CONFIG_INVALID, ERR_CONFIG_MISSING_FIELD
86
+ */
87
+ export class ConfigError extends GrafemaError {
88
+ readonly code: string;
89
+ readonly severity = 'fatal' as const;
90
+
91
+ constructor(message: string, code: string, context: ErrorContext = {}, suggestion?: string) {
92
+ super(message, context, suggestion);
93
+ this.code = code;
94
+ }
95
+ }
96
+
97
+ /**
98
+ * File access error - unreadable files, missing git, permissions
99
+ *
100
+ * Severity: error (default)
101
+ * Codes: ERR_FILE_UNREADABLE, ERR_GIT_NOT_FOUND, ERR_GIT_ACCESS_DENIED
102
+ */
103
+ export class FileAccessError extends GrafemaError {
104
+ readonly code: string;
105
+ readonly severity = 'error' as const;
106
+
107
+ constructor(message: string, code: string, context: ErrorContext = {}, suggestion?: string) {
108
+ super(message, context, suggestion);
109
+ this.code = code;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Language error - unsupported file type, unparseable syntax
115
+ *
116
+ * Severity: warning (always)
117
+ * Codes: ERR_UNSUPPORTED_LANG, ERR_PARSE_FAILURE
118
+ */
119
+ export class LanguageError extends GrafemaError {
120
+ readonly code: string;
121
+ readonly severity = 'warning' as const;
122
+
123
+ constructor(message: string, code: string, context: ErrorContext = {}, suggestion?: string) {
124
+ super(message, context, suggestion);
125
+ this.code = code;
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Database error - RFDB connection, corruption, lock
131
+ *
132
+ * Severity: fatal (always)
133
+ * Codes: ERR_DATABASE_LOCKED, ERR_DATABASE_CORRUPTED
134
+ */
135
+ export class DatabaseError extends GrafemaError {
136
+ readonly code: string;
137
+ readonly severity = 'fatal' as const;
138
+
139
+ constructor(message: string, code: string, context: ErrorContext = {}, suggestion?: string) {
140
+ super(message, context, suggestion);
141
+ this.code = code;
142
+ }
143
+ }
144
+
145
+ /**
146
+ * Plugin error - plugin execution failed, dependency missing
147
+ *
148
+ * Severity: error (default)
149
+ * Codes: ERR_PLUGIN_FAILED, ERR_PLUGIN_DEPENDENCY_MISSING
150
+ */
151
+ export class PluginError extends GrafemaError {
152
+ readonly code: string;
153
+ readonly severity = 'error' as const;
154
+
155
+ constructor(message: string, code: string, context: ErrorContext = {}, suggestion?: string) {
156
+ super(message, context, suggestion);
157
+ this.code = code;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Analysis error - internal analyzer failure, timeout
163
+ *
164
+ * Severity: error (default)
165
+ * Codes: ERR_ANALYSIS_TIMEOUT, ERR_ANALYSIS_INTERNAL
166
+ */
167
+ export class AnalysisError extends GrafemaError {
168
+ readonly code: string;
169
+ readonly severity = 'error' as const;
170
+
171
+ constructor(message: string, code: string, context: ErrorContext = {}, suggestion?: string) {
172
+ super(message, context, suggestion);
173
+ this.code = code;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Validation error - issues found by validators during VALIDATION phase
179
+ *
180
+ * Unlike other error classes, ValidationError has CONFIGURABLE severity because
181
+ * validators report issues of varying importance:
182
+ * - warning: informational issues (unresolved calls, missing assignments)
183
+ * - error: problems that may indicate bugs (broken references)
184
+ * - fatal: critical issues that should fail the analysis
185
+ *
186
+ * Codes:
187
+ * - ERR_UNRESOLVED_CALL: function call doesn't resolve to definition
188
+ * - ERR_DISCONNECTED_NODES: graph nodes not connected to root
189
+ * - ERR_DISCONNECTED_NODE: individual disconnected node
190
+ * - ERR_MISSING_ASSIGNMENT: variable has no ASSIGNED_FROM edge
191
+ * - ERR_BROKEN_REFERENCE: reference to non-existent node
192
+ * - ERR_NO_LEAF_NODE: data flow doesn't reach leaf node
193
+ */
194
+ export class ValidationError extends GrafemaError {
195
+ readonly code: string;
196
+ readonly severity: 'fatal' | 'error' | 'warning';
197
+
198
+ constructor(
199
+ message: string,
200
+ code: string,
201
+ context: ErrorContext = {},
202
+ suggestion?: string,
203
+ severity: 'fatal' | 'error' | 'warning' = 'warning'
204
+ ) {
205
+ super(message, context, suggestion);
206
+ this.code = code;
207
+ this.severity = severity;
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Strict mode error - reported when strictMode=true and an enricher
213
+ * cannot resolve a reference.
214
+ *
215
+ * Unlike other errors, StrictModeError is used to collect issues that
216
+ * would normally be silently skipped. All collected StrictModeErrors
217
+ * cause analysis to fail after the ENRICHMENT phase completes.
218
+ *
219
+ * Severity: fatal (always)
220
+ * Codes:
221
+ * - STRICT_UNRESOLVED_METHOD: Method call cannot be resolved to definition
222
+ * - STRICT_UNRESOLVED_CALL: Function call cannot be resolved to definition
223
+ * - STRICT_UNRESOLVED_ARGUMENT: Argument cannot be linked to parameter
224
+ * - STRICT_ALIAS_DEPTH_EXCEEDED: Alias chain too deep (potential cycle)
225
+ * - STRICT_BROKEN_IMPORT: Import/re-export chain broken
226
+ */
227
+ export class StrictModeError extends GrafemaError {
228
+ readonly code: string;
229
+ readonly severity = 'fatal' as const;
230
+
231
+ constructor(
232
+ message: string,
233
+ code: string,
234
+ context: ErrorContext = {},
235
+ suggestion?: string
236
+ ) {
237
+ super(message, context, suggestion);
238
+ this.code = code;
239
+ }
240
+ }
241
+
242
+ /**
243
+ * A step in the resolution chain showing what was resolved before failure.
244
+ * Used by StrictModeError to provide context-aware error messages (REG-332).
245
+ */
246
+ export interface ResolutionStep {
247
+ /** Description of what was resolved, e.g., "getUser() return" */
248
+ step: string;
249
+ /** Result of resolution, e.g., "unknown" or "User class" */
250
+ result: string;
251
+ /** File where this step occurred */
252
+ file?: string;
253
+ /** Line number */
254
+ line?: number;
255
+ }
256
+
257
+ /**
258
+ * Reasons why resolution can fail.
259
+ * Used by StrictModeError for context-aware suggestions (REG-332).
260
+ */
261
+ export type ResolutionFailureReason =
262
+ | 'unknown_object_type' // getUser() return unknown
263
+ | 'class_not_imported' // User class not in scope
264
+ | 'method_not_found' // Class exists but no such method
265
+ | 'external_dependency' // From node_modules
266
+ | 'circular_reference' // Alias chain too deep
267
+ | 'builtin_method' // Built-in prototype method (not an error)
268
+ | 'unknown'; // Catch-all
269
+
270
+ /**
271
+ * StrictModeFailure - thrown when strict mode stops analysis due to fatal errors.
272
+ *
273
+ * Unlike other errors, this carries a reference to the fatal diagnostic(s)
274
+ * rather than duplicating the message. The CLI formats output from
275
+ * the diagnostic, not from error.message.
276
+ *
277
+ * This prevents the duplication issue where both error.message and
278
+ * DiagnosticReporter show the same error (REG-332).
279
+ */
280
+ export class StrictModeFailure extends Error {
281
+ /** The fatal diagnostics that caused the failure */
282
+ readonly diagnostics: Diagnostic[];
283
+ /** Error count for summary */
284
+ readonly count: number;
285
+ /** REG-332: Number of errors suppressed by grafema-ignore comments */
286
+ readonly suppressedCount: number;
287
+
288
+ constructor(diagnostics: Diagnostic[], suppressedCount: number = 0) {
289
+ // Keep message minimal - CLI will format from diagnostics
290
+ super(`Strict mode: ${diagnostics.length} unresolved reference(s) found`);
291
+ this.name = 'StrictModeFailure';
292
+ this.diagnostics = diagnostics;
293
+ this.count = diagnostics.length;
294
+ this.suppressedCount = suppressedCount;
295
+ Object.setPrototypeOf(this, new.target.prototype);
296
+ }
297
+ }
package/src/index.ts ADDED
@@ -0,0 +1,261 @@
1
+ /**
2
+ * @grafema/util - Query, config, and guarantee utilities for Grafema
3
+ *
4
+ * This package contains the live query layer, configuration, diagnostics,
5
+ * and guarantee management. Analysis is handled by grafema-orchestrator (Rust).
6
+ */
7
+
8
+ // Error types
9
+ export {
10
+ GrafemaError,
11
+ ConfigError,
12
+ FileAccessError,
13
+ LanguageError,
14
+ DatabaseError,
15
+ PluginError,
16
+ AnalysisError,
17
+ ValidationError,
18
+ StrictModeError,
19
+ StrictModeFailure,
20
+ } from './errors/GrafemaError.js';
21
+ export type {
22
+ ErrorContext,
23
+ GrafemaErrorJSON,
24
+ ResolutionStep,
25
+ ResolutionFailureReason,
26
+ } from './errors/GrafemaError.js';
27
+
28
+ // Logging
29
+ export { ConsoleLogger, FileLogger, MultiLogger, createLogger } from './logging/Logger.js';
30
+ export type { Logger, LogLevel } from './logging/Logger.js';
31
+
32
+ // Diagnostics
33
+ export { DiagnosticCollector, DiagnosticReporter, DiagnosticWriter } from './diagnostics/index.js';
34
+ export type { Diagnostic, DiagnosticInput, ReportOptions, SummaryStats } from './diagnostics/index.js';
35
+ export { DIAGNOSTIC_CATEGORIES, CODE_TO_CATEGORY, getCategoryForCode, getCodesForCategory } from './diagnostics/index.js';
36
+ export type { DiagnosticCategory, DiagnosticCategoryKey, CodeCategoryInfo } from './diagnostics/index.js';
37
+
38
+ // Config
39
+ export {
40
+ loadConfig,
41
+ DEFAULT_CONFIG,
42
+ validateVersion,
43
+ validateServices,
44
+ validatePatterns,
45
+ validateWorkspace,
46
+ validateRouting,
47
+ } from './config/index.js';
48
+ export type { GrafemaConfig } from './config/index.js';
49
+
50
+ // Version
51
+ export { GRAFEMA_VERSION, getSchemaVersion } from './version.js';
52
+
53
+ // Instructions (for AI agents)
54
+ export { getOnboardingInstruction } from './instructions/index.js';
55
+
56
+ // Graph backend
57
+ export { GraphBackend, typeToKind, edgeTypeToNumber } from './core/GraphBackend.js';
58
+ export type { Node, Edge, EdgeType, AttrQuery, GraphStats, GraphExport } from './core/GraphBackend.js';
59
+
60
+ // RFDB
61
+ export { RFDBClient } from '@grafema/rfdb-client';
62
+ export { RFDBServerBackend } from './storage/backends/RFDBServerBackend.js';
63
+
64
+ // Core utilities
65
+ export {
66
+ computeSemanticId,
67
+ parseSemanticId,
68
+ computeDiscriminator,
69
+ computeSemanticIdV2,
70
+ parseSemanticIdV2,
71
+ computeContentHash
72
+ } from './core/SemanticId.js';
73
+ export type {
74
+ Location,
75
+ ScopeContext,
76
+ SemanticIdOptions,
77
+ ParsedSemanticId,
78
+ LocatedItem,
79
+ ParsedSemanticIdV2,
80
+ ContentHashHints
81
+ } from './core/SemanticId.js';
82
+
83
+ // URI format
84
+ export {
85
+ isGrafemaUri,
86
+ encodeFragment,
87
+ decodeFragment,
88
+ toGrafemaUri,
89
+ parseGrafemaUri,
90
+ toCompactSemanticId,
91
+ normalizeSemanticId
92
+ } from './core/GrafemaUri.js';
93
+ export type { ParsedGrafemaUri } from './core/GrafemaUri.js';
94
+
95
+ export { GuaranteeManager } from './core/GuaranteeManager.js';
96
+ export type { GuaranteeGraph } from './core/GuaranteeManager.js';
97
+
98
+ // Hash utilities
99
+ export { calculateFileHash, calculateFileHashAsync, calculateContentHash } from './core/HashUtils.js';
100
+
101
+ // Binary finder utilities
102
+ export { findBinary, findAnalyzerBinary, findRfdbBinary, findOrchestratorBinary, getBinaryNotFoundMessage, getPlatformDir, getPlatformPackageName } from './utils/findRfdbBinary.js';
103
+ export type { FindBinaryOptions, BinaryName } from './utils/findRfdbBinary.js';
104
+
105
+ // Lazy download
106
+ export { ensureBinary, downloadBinary, isDownloadable, findInGrafemaBin, getGrafemaBinDir } from './utils/lazyDownload.js';
107
+
108
+ // RFDB server lifecycle
109
+ export { startRfdbServer, checkExistingServer } from './utils/startRfdbServer.js';
110
+ export type { StartRfdbServerOptions } from './utils/startRfdbServer.js';
111
+
112
+ // Module resolution utilities
113
+ export {
114
+ resolveModulePath,
115
+ isRelativeImport,
116
+ resolveRelativeSpecifier,
117
+ DEFAULT_EXTENSIONS,
118
+ DEFAULT_INDEX_FILES
119
+ } from './utils/moduleResolution.js';
120
+ export type { ModuleResolutionOptions } from './utils/moduleResolution.js';
121
+
122
+ // Node file path resolution
123
+ export { resolveNodeFile } from './utils/resolveNodeFile.js';
124
+
125
+ // Type validation and path validation
126
+ export {
127
+ levenshtein,
128
+ checkTypoAgainstKnownTypes,
129
+ resetKnownNodeTypes,
130
+ getKnownNodeTypes
131
+ } from './storage/backends/typeValidation.js';
132
+ export { PathValidator } from './validation/PathValidator.js';
133
+ export type { PathValidationResult, EndpointDiff } from './validation/PathValidator.js';
134
+
135
+ // Version management
136
+ export { VersionManager, versionManager } from './core/VersionManager.js';
137
+ export type { VersionedNode, VersionConstants, EnrichOptions, ModifiedNodeInfo, ChangesSummary, ClassifyChangesResult } from './core/VersionManager.js';
138
+
139
+ // Freshness checking and incremental reanalysis
140
+ export { GraphFreshnessChecker } from './core/GraphFreshnessChecker.js';
141
+ export type { FreshnessGraph, FreshnessResult, StaleModule } from './core/GraphFreshnessChecker.js';
142
+ export { IncrementalReanalyzer } from './core/IncrementalReanalyzer.js';
143
+ export type { ReanalysisOptions, ReanalysisProgress, ReanalysisResult } from './core/IncrementalReanalyzer.js';
144
+
145
+ // Coverage
146
+ export { CoverageAnalyzer } from './core/CoverageAnalyzer.js';
147
+ export type { CoverageResult } from './core/CoverageAnalyzer.js';
148
+
149
+ // File analysis utilities
150
+ export { FileExplainer } from './core/FileExplainer.js';
151
+ export type { FileExplainResult, EnhancedNode } from './core/FileExplainer.js';
152
+ export { FileOverview } from './core/FileOverview.js';
153
+ export type {
154
+ FileOverviewResult,
155
+ ImportInfo,
156
+ ExportInfo,
157
+ FunctionOverview,
158
+ ClassOverview,
159
+ VariableOverview,
160
+ } from './core/FileOverview.js';
161
+
162
+ // Resource system
163
+ export { ResourceRegistryImpl } from './core/ResourceRegistry.js';
164
+
165
+ // API
166
+ export { GraphAPI } from './api/GraphAPI.js';
167
+ export { GuaranteeAPI } from './api/GuaranteeAPI.js';
168
+ export type { GuaranteeGraphBackend } from './api/GuaranteeAPI.js';
169
+
170
+ // Node kinds
171
+ export { isGuaranteeType, isGrafemaType } from './core/nodes/NodeKind.js';
172
+
173
+ // Issue nodes (detected problems)
174
+ export { IssueNode, type IssueNodeRecord, type IssueSeverity, type IssueType } from './core/nodes/IssueNode.js';
175
+
176
+ // Guarantee nodes (contract-based)
177
+ export { GuaranteeNode } from './core/nodes/GuaranteeNode.js';
178
+ export type {
179
+ GuaranteeNodeRecord,
180
+ GuaranteeNodeOptions,
181
+ GuaranteePriority,
182
+ GuaranteeStatus,
183
+ GuaranteeType,
184
+ } from './core/nodes/GuaranteeNode.js';
185
+
186
+ // Schema extraction
187
+ export { InterfaceSchemaExtractor, GraphSchemaExtractor } from './schema/index.js';
188
+ export type {
189
+ InterfaceSchema,
190
+ PropertySchema,
191
+ ExtractOptions,
192
+ GraphSchema,
193
+ NodeTypeSchema,
194
+ EdgeTypeSchema,
195
+ GraphExtractOptions,
196
+ } from './schema/index.js';
197
+
198
+ // Knowledge Base
199
+ export { KnowledgeBase, SemanticAddressResolver, parseSemanticAddress, parseFrontmatter, parseKBNode, serializeKBNode, parseEdgesFile, appendEdge, parseYamlArrayFile, GitIngest, parseGitLog, normalizeAuthors, getChurn, getCoChanges, getOwnership, getArchaeology } from './knowledge/index.js';
200
+ export type { ResolverBackend } from './knowledge/index.js';
201
+ export type {
202
+ KBNodeType,
203
+ KBLifecycle,
204
+ KBScope,
205
+ KBNodeBase,
206
+ KBDecision,
207
+ KBFact,
208
+ KBSession,
209
+ KBNode,
210
+ KBEdge,
211
+ KBStats,
212
+ KBQueryFilter,
213
+ ParsedSemanticAddress,
214
+ ResolvedAddress,
215
+ DanglingCodeRef,
216
+ } from './knowledge/index.js';
217
+ export type { RawCommit, FileChange, AuthorEntry, CommitEntry, IngestResult, Meta } from './knowledge/index.js';
218
+ export type { ChurnEntry, CoChangeEntry, OwnershipEntry, ArchaeologyEntry } from './knowledge/index.js';
219
+
220
+ // Graph Query Utilities
221
+ export { findCallsInFunction, findContainingFunction, traceValues, aggregateValues, NONDETERMINISTIC_PATTERNS, NONDETERMINISTIC_OBJECTS } from './queries/index.js';
222
+ export { traceDataflow, traceForwardBFS, traceBackwardBFS } from './queries/index.js';
223
+ export { buildNodeContext, getNodeDisplayName, formatEdgeMetadata, STRUCTURAL_EDGE_TYPES } from './queries/index.js';
224
+ export type {
225
+ CallInfo,
226
+ CallerInfo,
227
+ FindCallsOptions,
228
+ TracedValue,
229
+ ValueSource,
230
+ UnknownReason,
231
+ TraceValuesOptions,
232
+ ValueSetResult,
233
+ TraceValuesGraphBackend,
234
+ NondeterministicPattern,
235
+ EdgeWithNode,
236
+ EdgeGroup,
237
+ SourcePreview,
238
+ NodeContext,
239
+ BuildNodeContextOptions,
240
+ DataflowNode,
241
+ DataflowEdge,
242
+ DataflowBackend,
243
+ TraceDataflowOptions,
244
+ TraceDataflowResult,
245
+ } from './queries/index.js';
246
+
247
+ // Notation — DSL rendering engine
248
+ export { EDGE_ARCHETYPE_MAP, lookupEdge, generateLegend, PERSPECTIVES, renderNotation, extractSubgraph, shortenName, renderTraceNarrative } from './notation/index.js';
249
+ export type {
250
+ Archetype,
251
+ EdgeMapping,
252
+ DescribeOptions,
253
+ SubgraphData,
254
+ NotationBlock,
255
+ NotationLine,
256
+ TraceDetail,
257
+ TraceNarrativeOptions,
258
+ } from './notation/index.js';
259
+
260
+ // Re-export types for convenience
261
+ export type * from '@grafema/types';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Grafema instruction documents for AI agents.
3
+ *
4
+ * Instructions are markdown documents that guide agent behavior.
5
+ * They are read at runtime from the installed package.
6
+ */
7
+ import { readFileSync } from 'fs';
8
+ import { join, dirname } from 'path';
9
+ import { fileURLToPath } from 'url';
10
+
11
+ const __dirname = dirname(fileURLToPath(import.meta.url));
12
+
13
+ /**
14
+ * Get the onboarding instruction document.
15
+ *
16
+ * Returns the full markdown text of the onboarding procedure
17
+ * that guides an AI agent through project study and configuration.
18
+ */
19
+ export function getOnboardingInstruction(): string {
20
+ return readFileSync(join(__dirname, 'onboarding.md'), 'utf-8');
21
+ }