@vyuhlabs/dxkit 2.6.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/CHANGELOG.md +103 -13
  2. package/README.md +208 -459
  3. package/dist/analyzers/bom/discovery.d.ts +3 -4
  4. package/dist/analyzers/bom/discovery.d.ts.map +1 -1
  5. package/dist/analyzers/bom/discovery.js +3 -4
  6. package/dist/analyzers/bom/discovery.js.map +1 -1
  7. package/dist/analyzers/bom/types.d.ts +1 -1
  8. package/dist/analyzers/dashboard/index.d.ts.map +1 -1
  9. package/dist/analyzers/dashboard/index.js +42 -5
  10. package/dist/analyzers/dashboard/index.js.map +1 -1
  11. package/dist/analyzers/developer/gather.d.ts.map +1 -1
  12. package/dist/analyzers/developer/gather.js +9 -9
  13. package/dist/analyzers/developer/gather.js.map +1 -1
  14. package/dist/analyzers/quality/detailed.d.ts +8 -1
  15. package/dist/analyzers/quality/detailed.d.ts.map +1 -1
  16. package/dist/analyzers/quality/detailed.js +43 -10
  17. package/dist/analyzers/quality/detailed.js.map +1 -1
  18. package/dist/analyzers/quality/gather.js +3 -3
  19. package/dist/analyzers/quality/gather.js.map +1 -1
  20. package/dist/analyzers/security/detailed.d.ts +8 -1
  21. package/dist/analyzers/security/detailed.d.ts.map +1 -1
  22. package/dist/analyzers/security/detailed.js +14 -1
  23. package/dist/analyzers/security/detailed.js.map +1 -1
  24. package/dist/analyzers/security/gather.d.ts.map +1 -1
  25. package/dist/analyzers/security/gather.js +12 -3
  26. package/dist/analyzers/security/gather.js.map +1 -1
  27. package/dist/analyzers/tests/detailed.d.ts +8 -1
  28. package/dist/analyzers/tests/detailed.d.ts.map +1 -1
  29. package/dist/analyzers/tests/detailed.js +26 -7
  30. package/dist/analyzers/tests/detailed.js.map +1 -1
  31. package/dist/analyzers/tools/cloc.js +5 -5
  32. package/dist/analyzers/tools/cloc.js.map +1 -1
  33. package/dist/analyzers/tools/exclusions.d.ts +12 -12
  34. package/dist/analyzers/tools/exclusions.d.ts.map +1 -1
  35. package/dist/analyzers/tools/exclusions.js +27 -13
  36. package/dist/analyzers/tools/exclusions.js.map +1 -1
  37. package/dist/analyzers/tools/generic.d.ts.map +1 -1
  38. package/dist/analyzers/tools/generic.js +52 -14
  39. package/dist/analyzers/tools/generic.js.map +1 -1
  40. package/dist/analyzers/tools/gitleaks.d.ts.map +1 -1
  41. package/dist/analyzers/tools/gitleaks.js +28 -3
  42. package/dist/analyzers/tools/gitleaks.js.map +1 -1
  43. package/dist/analyzers/tools/graphify.d.ts +39 -5
  44. package/dist/analyzers/tools/graphify.d.ts.map +1 -1
  45. package/dist/analyzers/tools/graphify.js +609 -45
  46. package/dist/analyzers/tools/graphify.js.map +1 -1
  47. package/dist/analyzers/tools/grep-secrets.d.ts.map +1 -1
  48. package/dist/analyzers/tools/grep-secrets.js +1 -1
  49. package/dist/analyzers/tools/grep-secrets.js.map +1 -1
  50. package/dist/analyzers/tools/jscpd.d.ts.map +1 -1
  51. package/dist/analyzers/tools/jscpd.js +2 -1
  52. package/dist/analyzers/tools/jscpd.js.map +1 -1
  53. package/dist/analyzers/tools/nuget-package-reference.d.ts +4 -4
  54. package/dist/analyzers/tools/nuget-package-reference.js +4 -4
  55. package/dist/analyzers/tools/osv-scanner-deps.d.ts.map +1 -1
  56. package/dist/analyzers/tools/osv-scanner-deps.js +1 -1
  57. package/dist/analyzers/tools/osv-scanner-deps.js.map +1 -1
  58. package/dist/analyzers/tools/osv-scanner-fix.d.ts +4 -5
  59. package/dist/analyzers/tools/osv-scanner-fix.d.ts.map +1 -1
  60. package/dist/analyzers/tools/osv-scanner-fix.js +4 -5
  61. package/dist/analyzers/tools/osv-scanner-fix.js.map +1 -1
  62. package/dist/analyzers/tools/parallel.d.ts.map +1 -1
  63. package/dist/analyzers/tools/parallel.js +7 -0
  64. package/dist/analyzers/tools/parallel.js.map +1 -1
  65. package/dist/analyzers/tools/runner.d.ts +35 -2
  66. package/dist/analyzers/tools/runner.d.ts.map +1 -1
  67. package/dist/analyzers/tools/runner.js +112 -3
  68. package/dist/analyzers/tools/runner.js.map +1 -1
  69. package/dist/analyzers/tools/semgrep.d.ts.map +1 -1
  70. package/dist/analyzers/tools/semgrep.js +3 -1
  71. package/dist/analyzers/tools/semgrep.js.map +1 -1
  72. package/dist/analyzers/tools/tool-registry.d.ts +18 -0
  73. package/dist/analyzers/tools/tool-registry.d.ts.map +1 -1
  74. package/dist/analyzers/tools/tool-registry.js +140 -53
  75. package/dist/analyzers/tools/tool-registry.js.map +1 -1
  76. package/dist/analyzers/tools/tools-config.d.ts +46 -0
  77. package/dist/analyzers/tools/tools-config.d.ts.map +1 -0
  78. package/dist/analyzers/tools/tools-config.js +129 -0
  79. package/dist/analyzers/tools/tools-config.js.map +1 -0
  80. package/dist/analyzers/tools/vendored-advisor.d.ts.map +1 -1
  81. package/dist/analyzers/tools/vendored-advisor.js +3 -4
  82. package/dist/analyzers/tools/vendored-advisor.js.map +1 -1
  83. package/dist/analyzers/tools/walk-source-files.d.ts +8 -0
  84. package/dist/analyzers/tools/walk-source-files.d.ts.map +1 -1
  85. package/dist/analyzers/tools/walk-source-files.js +49 -4
  86. package/dist/analyzers/tools/walk-source-files.js.map +1 -1
  87. package/dist/analyzers/xlsx/licenses.d.ts +7 -7
  88. package/dist/analyzers/xlsx/licenses.js +7 -7
  89. package/dist/baseline/baseline-file.d.ts +8 -0
  90. package/dist/baseline/baseline-file.d.ts.map +1 -1
  91. package/dist/baseline/baseline-file.js.map +1 -1
  92. package/dist/baseline/check-renderers.d.ts.map +1 -1
  93. package/dist/baseline/check-renderers.js +10 -0
  94. package/dist/baseline/check-renderers.js.map +1 -1
  95. package/dist/baseline/check.d.ts +7 -0
  96. package/dist/baseline/check.d.ts.map +1 -1
  97. package/dist/baseline/check.js +2 -0
  98. package/dist/baseline/check.js.map +1 -1
  99. package/dist/baseline/coverage.d.ts +57 -0
  100. package/dist/baseline/coverage.d.ts.map +1 -0
  101. package/dist/baseline/coverage.js +62 -0
  102. package/dist/baseline/coverage.js.map +1 -0
  103. package/dist/baseline/create.d.ts +13 -0
  104. package/dist/baseline/create.d.ts.map +1 -1
  105. package/dist/baseline/create.js +21 -0
  106. package/dist/baseline/create.js.map +1 -1
  107. package/dist/cli.d.ts.map +1 -1
  108. package/dist/cli.js +123 -4
  109. package/dist/cli.js.map +1 -1
  110. package/dist/dashboard/graph-adapter.d.ts +151 -0
  111. package/dist/dashboard/graph-adapter.d.ts.map +1 -0
  112. package/dist/dashboard/graph-adapter.js +415 -0
  113. package/dist/dashboard/graph-adapter.js.map +1 -0
  114. package/dist/dashboard/graph-tab.d.ts +109 -0
  115. package/dist/dashboard/graph-tab.d.ts.map +1 -0
  116. package/dist/dashboard/graph-tab.js +297 -0
  117. package/dist/dashboard/graph-tab.js.map +1 -0
  118. package/dist/dashboard/vendor/vis-network.min.js +34 -0
  119. package/dist/doctor.d.ts.map +1 -1
  120. package/dist/doctor.js +6 -7
  121. package/dist/doctor.js.map +1 -1
  122. package/dist/explore/cli/api-surface.d.ts +12 -0
  123. package/dist/explore/cli/api-surface.d.ts.map +1 -0
  124. package/dist/explore/cli/api-surface.js +57 -0
  125. package/dist/explore/cli/api-surface.js.map +1 -0
  126. package/dist/explore/cli/communities.d.ts +10 -0
  127. package/dist/explore/cli/communities.d.ts.map +1 -0
  128. package/dist/explore/cli/communities.js +47 -0
  129. package/dist/explore/cli/communities.js.map +1 -0
  130. package/dist/explore/cli/context.d.ts +16 -0
  131. package/dist/explore/cli/context.d.ts.map +1 -0
  132. package/dist/explore/cli/context.js +118 -0
  133. package/dist/explore/cli/context.js.map +1 -0
  134. package/dist/explore/cli/entry-points.d.ts +12 -0
  135. package/dist/explore/cli/entry-points.d.ts.map +1 -0
  136. package/dist/explore/cli/entry-points.js +85 -0
  137. package/dist/explore/cli/entry-points.js.map +1 -0
  138. package/dist/explore/cli/feature.d.ts +16 -0
  139. package/dist/explore/cli/feature.d.ts.map +1 -0
  140. package/dist/explore/cli/feature.js +89 -0
  141. package/dist/explore/cli/feature.js.map +1 -0
  142. package/dist/explore/cli/file.d.ts +12 -0
  143. package/dist/explore/cli/file.d.ts.map +1 -0
  144. package/dist/explore/cli/file.js +139 -0
  145. package/dist/explore/cli/file.js.map +1 -0
  146. package/dist/explore/cli/hot-files.d.ts +11 -0
  147. package/dist/explore/cli/hot-files.d.ts.map +1 -0
  148. package/dist/explore/cli/hot-files.js +63 -0
  149. package/dist/explore/cli/hot-files.js.map +1 -0
  150. package/dist/explore/context-hook.d.ts +42 -0
  151. package/dist/explore/context-hook.d.ts.map +1 -0
  152. package/dist/explore/context-hook.js +131 -0
  153. package/dist/explore/context-hook.js.map +1 -0
  154. package/dist/explore/finding-context.d.ts +69 -0
  155. package/dist/explore/finding-context.d.ts.map +1 -0
  156. package/dist/explore/finding-context.js +102 -0
  157. package/dist/explore/finding-context.js.map +1 -0
  158. package/dist/explore/format.d.ts +64 -0
  159. package/dist/explore/format.d.ts.map +1 -0
  160. package/dist/explore/format.js +99 -0
  161. package/dist/explore/format.js.map +1 -0
  162. package/dist/explore/load.d.ts +50 -0
  163. package/dist/explore/load.d.ts.map +1 -0
  164. package/dist/explore/load.js +197 -0
  165. package/dist/explore/load.js.map +1 -0
  166. package/dist/explore/queries.d.ts +413 -0
  167. package/dist/explore/queries.d.ts.map +1 -0
  168. package/dist/explore/queries.js +855 -0
  169. package/dist/explore/queries.js.map +1 -0
  170. package/dist/explore/types.d.ts +130 -0
  171. package/dist/explore/types.d.ts.map +1 -0
  172. package/dist/explore/types.js +28 -0
  173. package/dist/explore/types.js.map +1 -0
  174. package/dist/explore-cli.d.ts +45 -0
  175. package/dist/explore-cli.d.ts.map +1 -0
  176. package/dist/explore-cli.js +213 -0
  177. package/dist/explore-cli.js.map +1 -0
  178. package/dist/generator.d.ts.map +1 -1
  179. package/dist/generator.js +19 -0
  180. package/dist/generator.js.map +1 -1
  181. package/dist/languages/csharp.d.ts.map +1 -1
  182. package/dist/languages/csharp.js +58 -26
  183. package/dist/languages/csharp.js.map +1 -1
  184. package/dist/languages/go.d.ts.map +1 -1
  185. package/dist/languages/go.js +17 -14
  186. package/dist/languages/go.js.map +1 -1
  187. package/dist/languages/index.d.ts +27 -0
  188. package/dist/languages/index.d.ts.map +1 -1
  189. package/dist/languages/index.js +35 -0
  190. package/dist/languages/index.js.map +1 -1
  191. package/dist/languages/java.d.ts.map +1 -1
  192. package/dist/languages/java.js +13 -10
  193. package/dist/languages/java.js.map +1 -1
  194. package/dist/languages/kotlin.d.ts.map +1 -1
  195. package/dist/languages/kotlin.js +13 -10
  196. package/dist/languages/kotlin.js.map +1 -1
  197. package/dist/languages/python.d.ts.map +1 -1
  198. package/dist/languages/python.js +31 -20
  199. package/dist/languages/python.js.map +1 -1
  200. package/dist/languages/ruby.d.ts.map +1 -1
  201. package/dist/languages/ruby.js +30 -16
  202. package/dist/languages/ruby.js.map +1 -1
  203. package/dist/languages/rust.d.ts.map +1 -1
  204. package/dist/languages/rust.js +16 -13
  205. package/dist/languages/rust.js.map +1 -1
  206. package/dist/languages/types.d.ts +54 -0
  207. package/dist/languages/types.d.ts.map +1 -1
  208. package/dist/languages/typescript.d.ts.map +1 -1
  209. package/dist/languages/typescript.js +22 -19
  210. package/dist/languages/typescript.js.map +1 -1
  211. package/dist/tools-cli.d.ts.map +1 -1
  212. package/dist/tools-cli.js +10 -4
  213. package/dist/tools-cli.js.map +1 -1
  214. package/dist/upgrade.js +2 -2
  215. package/dist/upgrade.js.map +1 -1
  216. package/package.json +2 -1
  217. package/templates/.claude/skills/dxkit-action/SKILL.md +21 -1
  218. package/templates/.claude/skills/dxkit-config/SKILL.md +26 -0
  219. package/templates/.claude/skills/dxkit-fix/SKILL.md +10 -0
  220. package/templates/.claude/skills/dxkit-reports/SKILL.md +3 -1
  221. package/templates/AGENTS.md.template +8 -1
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * Finding-enrichment adapter — attaches graph context (module
4
+ * membership + blast radius + enclosing symbol) to analyzer findings
5
+ * that carry a `file` (+ optional `line`). Consumed by the detailed
6
+ * report builders for the `vuln` / `test-gaps` / `quality` commands
7
+ * when the user passes `--graph-context`.
8
+ *
9
+ * Per CLAUDE.md Rule 12 this is the only layer (alongside the context
10
+ * hook + dashboard adapter) that loads the graph for finding
11
+ * enrichment; analyzers receive the pre-built `DetailedGraphContext`
12
+ * and never touch graph.json themselves. All graph math stays in
13
+ * `queries.ts:findingContextQuery`.
14
+ *
15
+ * THE CONTRACT IS FAIL-OPEN + ADDITIVE, like the context hook: a
16
+ * missing / corrupt / stale graph degrades to `undefined` (no
17
+ * enrichment), never an error. Findings render exactly as they do
18
+ * today whenever the graph is absent.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.locationKey = locationKey;
22
+ exports.buildFindingContextMap = buildFindingContextMap;
23
+ exports.formatGraphContextCell = formatGraphContextCell;
24
+ exports.graphContextProvenanceLine = graphContextProvenanceLine;
25
+ const load_1 = require("./load");
26
+ const queries_1 = require("./queries");
27
+ const languages_1 = require("../languages");
28
+ /** Stable lookup key for a finding location. */
29
+ function locationKey(file, line) {
30
+ return typeof line === 'number' ? `${file}:${line}` : file;
31
+ }
32
+ /**
33
+ * Build per-finding graph context for a list of finding locations.
34
+ * Fail-open: returns `undefined` when the graph can't be loaded.
35
+ *
36
+ * Dedupes identical locations (same file:line surfaced by multiple
37
+ * tools) and budget-caps the work at `maxFindings` unique locations.
38
+ * Only `found: true` contexts are stored — a finding in a file the
39
+ * graph never parsed contributes no key, keeping the payload lean on
40
+ * repos where graphify covers only part of the tree.
41
+ */
42
+ function buildFindingContextMap(cwd, locations, opts = {}) {
43
+ const graph = (0, load_1.tryLoadGraph)(cwd);
44
+ if (!graph)
45
+ return undefined;
46
+ const max = opts.maxFindings ?? 200;
47
+ const contexts = {};
48
+ let enriched = 0;
49
+ for (const loc of locations) {
50
+ if (enriched >= max)
51
+ break;
52
+ const key = locationKey(loc.file, loc.line);
53
+ if (key in contexts)
54
+ continue;
55
+ const ctx = (0, queries_1.findingContextQuery)(graph, loc.file, loc.line, {
56
+ topCallerFiles: opts.topCallerFiles,
57
+ });
58
+ enriched++;
59
+ if (!ctx.found)
60
+ continue;
61
+ // Stamp the file's call-graph reliability (Rule 6: the fact comes
62
+ // from the language pack, not a hardcoded table here). Only record
63
+ // the non-default values to keep the payload lean — absent ⇒ 'full'.
64
+ const rel = (0, languages_1.languageForFile)(loc.file)?.callGraphReliability;
65
+ contexts[key] = rel && rel !== 'full' ? { ...ctx, callGraphReliability: rel } : ctx;
66
+ }
67
+ return {
68
+ generatedAt: graph.meta.generatedAt,
69
+ truncated: graph.meta.truncated,
70
+ contexts,
71
+ };
72
+ }
73
+ /**
74
+ * Compact one-cell rendering for a markdown table: `role · N caller
75
+ * files`. Returns `—` when there's no context for the location (file
76
+ * not in the graph). Used by the detailed report renderers.
77
+ */
78
+ function formatGraphContextCell(ctx) {
79
+ if (!ctx || !ctx.found)
80
+ return '—';
81
+ const role = ctx.community?.role ?? 'unclustered';
82
+ // For languages graphify can't resolve call edges for (C#), the
83
+ // caller count is untrustworthy — suppress it rather than print a
84
+ // misleading "0 caller files" (which a fixing agent could read as
85
+ // "safe to change"). The module/role label is still reliable.
86
+ if (ctx.callGraphReliability === 'unreliable') {
87
+ return `${role} · blast radius n/a (call graph)`;
88
+ }
89
+ const n = ctx.blastRadius.callerFiles;
90
+ return `${role} · ${n} caller file${n === 1 ? '' : 's'}`;
91
+ }
92
+ /**
93
+ * Provenance + honesty line printed above an enriched section so the
94
+ * reader knows the context is a structural hint tied to a specific
95
+ * graph snapshot (and that graphify can conflate same-name symbols).
96
+ */
97
+ function graphContextProvenanceLine(gc) {
98
+ const date = gc.generatedAt.slice(0, 10);
99
+ const stale = gc.truncated ? ' (graph truncated — coverage partial)' : '';
100
+ return `_Graph context column from \`.dxkit/reports/graph.json\` (generated ${date}${stale}) — structural hint; blast radius is file-level, same-name symbols may conflate call edges, and it reads \`n/a\` for languages whose call graph graphify can't resolve (a blank is not "0 callers"/"safe to change")._`;
101
+ }
102
+ //# sourceMappingURL=finding-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finding-context.js","sourceRoot":"","sources":["../../src/explore/finding-context.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;AAkCH,kCAEC;AAYD,wDAgCC;AAOD,wDAYC;AAOD,gEAIC;AA5GD,iCAAsC;AACtC,uCAAqE;AACrE,4CAA+C;AA6B/C,gDAAgD;AAChD,SAAgB,WAAW,CAAC,IAAY,EAAE,IAAa;IACrD,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC7D,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,sBAAsB,CACpC,GAAW,EACX,SAAyC,EACzC,OAAgC,EAAE;IAElC,MAAM,KAAK,GAAG,IAAA,mBAAY,EAAC,GAAG,CAAC,CAAC;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAE7B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC;IACpC,MAAM,QAAQ,GAAmC,EAAE,CAAC;IACpD,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;QAC5B,IAAI,QAAQ,IAAI,GAAG;YAAE,MAAM;QAC3B,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,GAAG,IAAI,QAAQ;YAAE,SAAS;QAC9B,MAAM,GAAG,GAAG,IAAA,6BAAmB,EAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE;YACzD,cAAc,EAAE,IAAI,CAAC,cAAc;SACpC,CAAC,CAAC;QACH,QAAQ,EAAE,CAAC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C,SAAS,CAAC,CAAC,CAAC,uCAAuC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1E,OAAO,uEAAuE,IAAI,GAAG,KAAK,wNAAwN,CAAC;AACrT,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Shared output helpers for the explore CLI subcommands. Pure
3
+ * formatters — JSON envelope shape + markdown table builders — so
4
+ * each subcommand handler stays a thin pipeline (parse args → call
5
+ * queries → format output).
6
+ *
7
+ * Per the Sprint 0 design (`tmp/2.7-explore-cli-design.md`):
8
+ * - JSON mode emits a stable envelope: command / args / meta / results
9
+ * - Markdown mode emits header → meta line → result block → footer hint
10
+ * - Adding fields later is additive; never mutate existing field
11
+ * names within v1
12
+ */
13
+ import type { Graph } from './types';
14
+ /**
15
+ * Stable JSON envelope every `--json` mode subcommand emits. Skills
16
+ * and scripts consume `results` directly; `meta` carries the artifact
17
+ * provenance so consumers can detect a stale graph + decide whether
18
+ * to suggest `--refresh`.
19
+ */
20
+ export interface ExploreEnvelope<T> {
21
+ command: string;
22
+ args: Record<string, unknown>;
23
+ meta: {
24
+ schemaVersion: number;
25
+ graphGeneratedAt: string;
26
+ truncated: boolean;
27
+ };
28
+ results: T;
29
+ }
30
+ /**
31
+ * Build the JSON envelope from a query result + the graph metadata.
32
+ * Pure function — no I/O, no side effects. Subcommands call this in
33
+ * `--json` mode and print the result via `JSON.stringify`.
34
+ */
35
+ export declare function envelope<T>(command: string, args: Record<string, unknown>, graph: Graph, results: T): ExploreEnvelope<T>;
36
+ /**
37
+ * Build the standard markdown header that every subcommand emits.
38
+ * Includes the meta line (file count + node count + generation
39
+ * timestamp) so the reader knows what artifact they're looking at,
40
+ * plus a truncation note when applicable.
41
+ */
42
+ export declare function markdownHeader(title: string, framing: string, graph: Graph): string;
43
+ /**
44
+ * Build a markdown table from a row set. `headers` defines the
45
+ * column order; `rows` is an array of records keyed by the same
46
+ * header strings. Missing values render as empty strings.
47
+ */
48
+ export declare function markdownTable<R extends Record<string, string | number>>(headers: ReadonlyArray<keyof R & string>, rows: ReadonlyArray<R>): string;
49
+ /**
50
+ * Build the standard footer hint pointing at the natural next
51
+ * subcommand. Optional; subcommands omit when no clear next step.
52
+ */
53
+ export declare function markdownFooter(hint: string): string;
54
+ /**
55
+ * Print a JSON envelope to stdout. Output is single-line (no
56
+ * pretty-print) so it stays pipe-friendly for `jq` consumers.
57
+ */
58
+ export declare function printJson<T>(env: ExploreEnvelope<T>): void;
59
+ /**
60
+ * Print markdown sections to stdout, joined by a blank line. Each
61
+ * section is a multi-line string built by the helpers above.
62
+ */
63
+ export declare function printMarkdown(...sections: string[]): void;
64
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/explore/format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;GAKG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,IAAI,EAAE;QACJ,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;QACzB,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;IACF,OAAO,EAAE,CAAC,CAAC;CACZ;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EACxB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,CAAC,GACT,eAAe,CAAC,CAAC,CAAC,CAWpB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,MAAM,CAanF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EACrE,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EACxC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACrB,MAAM,CAaR;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,IAAI,CAE1D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAEzD"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Shared output helpers for the explore CLI subcommands. Pure
4
+ * formatters — JSON envelope shape + markdown table builders — so
5
+ * each subcommand handler stays a thin pipeline (parse args → call
6
+ * queries → format output).
7
+ *
8
+ * Per the Sprint 0 design (`tmp/2.7-explore-cli-design.md`):
9
+ * - JSON mode emits a stable envelope: command / args / meta / results
10
+ * - Markdown mode emits header → meta line → result block → footer hint
11
+ * - Adding fields later is additive; never mutate existing field
12
+ * names within v1
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.envelope = envelope;
16
+ exports.markdownHeader = markdownHeader;
17
+ exports.markdownTable = markdownTable;
18
+ exports.markdownFooter = markdownFooter;
19
+ exports.printJson = printJson;
20
+ exports.printMarkdown = printMarkdown;
21
+ /**
22
+ * Build the JSON envelope from a query result + the graph metadata.
23
+ * Pure function — no I/O, no side effects. Subcommands call this in
24
+ * `--json` mode and print the result via `JSON.stringify`.
25
+ */
26
+ function envelope(command, args, graph, results) {
27
+ return {
28
+ command,
29
+ args,
30
+ meta: {
31
+ schemaVersion: graph.schemaVersion,
32
+ graphGeneratedAt: graph.meta.generatedAt,
33
+ truncated: graph.meta.truncated,
34
+ },
35
+ results,
36
+ };
37
+ }
38
+ /**
39
+ * Build the standard markdown header that every subcommand emits.
40
+ * Includes the meta line (file count + node count + generation
41
+ * timestamp) so the reader knows what artifact they're looking at,
42
+ * plus a truncation note when applicable.
43
+ */
44
+ function markdownHeader(title, framing, graph) {
45
+ const m = graph.meta;
46
+ const dateOnly = m.generatedAt.slice(0, 10);
47
+ const lines = [
48
+ `## ${title} — ${framing}`,
49
+ '',
50
+ `From .dxkit/reports/graph.json (generated ${dateOnly}, ${m.sourceFilesInGraph} source files, ${graph.nodes.length} nodes).`,
51
+ ];
52
+ if (m.truncated) {
53
+ lines.push('');
54
+ lines.push(`> ⚠ Graph is truncated: ${m.truncatedReason}. Results may be incomplete.`);
55
+ }
56
+ return lines.join('\n');
57
+ }
58
+ /**
59
+ * Build a markdown table from a row set. `headers` defines the
60
+ * column order; `rows` is an array of records keyed by the same
61
+ * header strings. Missing values render as empty strings.
62
+ */
63
+ function markdownTable(headers, rows) {
64
+ if (rows.length === 0)
65
+ return '';
66
+ const lines = [];
67
+ lines.push('| ' + headers.join(' | ') + ' |');
68
+ lines.push('|' + headers.map(() => '---').join('|') + '|');
69
+ for (const row of rows) {
70
+ const cells = headers.map((h) => {
71
+ const v = row[h];
72
+ return v === undefined || v === null ? '' : String(v);
73
+ });
74
+ lines.push('| ' + cells.join(' | ') + ' |');
75
+ }
76
+ return lines.join('\n');
77
+ }
78
+ /**
79
+ * Build the standard footer hint pointing at the natural next
80
+ * subcommand. Optional; subcommands omit when no clear next step.
81
+ */
82
+ function markdownFooter(hint) {
83
+ return `\n${hint}`;
84
+ }
85
+ /**
86
+ * Print a JSON envelope to stdout. Output is single-line (no
87
+ * pretty-print) so it stays pipe-friendly for `jq` consumers.
88
+ */
89
+ function printJson(env) {
90
+ process.stdout.write(JSON.stringify(env) + '\n');
91
+ }
92
+ /**
93
+ * Print markdown sections to stdout, joined by a blank line. Each
94
+ * section is a multi-line string built by the helpers above.
95
+ */
96
+ function printMarkdown(...sections) {
97
+ process.stdout.write(sections.filter((s) => s && s.length > 0).join('\n\n') + '\n');
98
+ }
99
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../src/explore/format.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;AA0BH,4BAgBC;AAQD,wCAaC;AAOD,sCAgBC;AAMD,wCAEC;AAMD,8BAEC;AAMD,sCAEC;AAzFD;;;;GAIG;AACH,SAAgB,QAAQ,CACtB,OAAe,EACf,IAA6B,EAC7B,KAAY,EACZ,OAAU;IAEV,OAAO;QACL,OAAO;QACP,IAAI;QACJ,IAAI,EAAE;YACJ,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,gBAAgB,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW;YACxC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS;SAChC;QACD,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAa,EAAE,OAAe,EAAE,KAAY;IACzE,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;IACrB,MAAM,QAAQ,GAAG,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG;QACZ,MAAM,KAAK,MAAM,OAAO,EAAE;QAC1B,EAAE;QACF,6CAA6C,QAAQ,KAAK,CAAC,CAAC,kBAAkB,kBAAkB,KAAK,CAAC,KAAK,CAAC,MAAM,UAAU;KAC7H,CAAC;IACF,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,eAAe,8BAA8B,CAAC,CAAC;IACzF,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED;;;;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AAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;AACtF,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Canonical graph loader. Per CLAUDE.md Rule 12, every consumer of
3
+ * `.dxkit/reports/graph.json` reads via `loadGraph(cwd)` — never
4
+ * `JSON.parse` directly. Arch-check enforces; this is the only file
5
+ * that may parse the artifact.
6
+ *
7
+ * Throws typed errors so callers can react precisely:
8
+ * - GraphNotFoundError → file doesn't exist (suggest --refresh)
9
+ * - GraphSchemaVersionError → wire-format newer than the loader knows
10
+ * - GraphCorruptError → missing/malformed required field
11
+ */
12
+ import { GRAPH_REPORT_PATH, type Graph } from './types';
13
+ export { GRAPH_REPORT_PATH };
14
+ export declare class GraphNotFoundError extends Error {
15
+ readonly absPath: string;
16
+ constructor(absPath: string);
17
+ }
18
+ export declare class GraphSchemaVersionError extends Error {
19
+ readonly absPath: string;
20
+ readonly found: unknown;
21
+ readonly expected: number;
22
+ constructor(absPath: string, found: unknown, expected: number);
23
+ }
24
+ export declare class GraphCorruptError extends Error {
25
+ readonly absPath: string;
26
+ readonly detail: string;
27
+ constructor(absPath: string, detail: string);
28
+ }
29
+ /**
30
+ * Read + validate + index the graph artifact. The returned `Graph`
31
+ * carries convenience indices (`nodeById`, `edgesFromNode`, ...)
32
+ * built once at load time; queries in `./queries.ts` read from these
33
+ * maps for O(1) traversal rather than repeatedly scanning the arrays.
34
+ *
35
+ * Validation is intentionally lightweight — top-level shape + required
36
+ * fields per node/edge. Deep schema validation (every optional field's
37
+ * types, referential integrity of every edge endpoint) would catch
38
+ * more but cost more on every load; instead we trust the producer and
39
+ * surface unexpected shapes as runtime errors at the query layer.
40
+ */
41
+ export declare function loadGraph(cwd: string): Graph;
42
+ /**
43
+ * Fail-open variant of {@link loadGraph}: returns undefined on ANY
44
+ * error (missing file, parse failure, schema mismatch) instead of
45
+ * throwing. For additive, never-block consumers — the PreToolUse
46
+ * context hook and the finding-enrichment pass — where a missing or
47
+ * stale graph must degrade to "no context", never an error.
48
+ */
49
+ export declare function tryLoadGraph(cwd: string): Graph | undefined;
50
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/explore/load.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EACL,iBAAiB,EAGjB,KAAK,KAAK,EAIX,MAAM,SAAS,CAAC;AAIjB,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAE7B,qBAAa,kBAAmB,SAAQ,KAAK;aACf,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;CAM5C;AAED,qBAAa,uBAAwB,SAAQ,KAAK;aAE9B,OAAO,EAAE,MAAM;aACf,KAAK,EAAE,OAAO;aACd,QAAQ,EAAE,MAAM;gBAFhB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,MAAM;CAOnC;AAED,qBAAa,iBAAkB,SAAQ,KAAK;aAExB,OAAO,EAAE,MAAM;aACf,MAAM,EAAE,MAAM;gBADd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;CAKjC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAa5C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAM3D"}
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /**
3
+ * Canonical graph loader. Per CLAUDE.md Rule 12, every consumer of
4
+ * `.dxkit/reports/graph.json` reads via `loadGraph(cwd)` — never
5
+ * `JSON.parse` directly. Arch-check enforces; this is the only file
6
+ * that may parse the artifact.
7
+ *
8
+ * Throws typed errors so callers can react precisely:
9
+ * - GraphNotFoundError → file doesn't exist (suggest --refresh)
10
+ * - GraphSchemaVersionError → wire-format newer than the loader knows
11
+ * - GraphCorruptError → missing/malformed required field
12
+ */
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
46
+ Object.defineProperty(exports, "__esModule", { value: true });
47
+ exports.GraphCorruptError = exports.GraphSchemaVersionError = exports.GraphNotFoundError = exports.GRAPH_REPORT_PATH = void 0;
48
+ exports.loadGraph = loadGraph;
49
+ exports.tryLoadGraph = tryLoadGraph;
50
+ const fs = __importStar(require("fs"));
51
+ const path = __importStar(require("path"));
52
+ const types_1 = require("./types");
53
+ Object.defineProperty(exports, "GRAPH_REPORT_PATH", { enumerable: true, get: function () { return types_1.GRAPH_REPORT_PATH; } });
54
+ class GraphNotFoundError extends Error {
55
+ absPath;
56
+ constructor(absPath) {
57
+ super(`No graph.json at ${absPath}. Run \`vyuh-dxkit health\` or pass \`--refresh\` to regenerate.`);
58
+ this.absPath = absPath;
59
+ this.name = 'GraphNotFoundError';
60
+ }
61
+ }
62
+ exports.GraphNotFoundError = GraphNotFoundError;
63
+ class GraphSchemaVersionError extends Error {
64
+ absPath;
65
+ found;
66
+ expected;
67
+ constructor(absPath, found, expected) {
68
+ super(`graph.json at ${absPath} declares schemaVersion=${String(found)}; this dxkit reads schemaVersion=${expected}. Upgrade dxkit (\`npm install -g @vyuhlabs/dxkit@latest\`) to read newer artifacts.`);
69
+ this.absPath = absPath;
70
+ this.found = found;
71
+ this.expected = expected;
72
+ this.name = 'GraphSchemaVersionError';
73
+ }
74
+ }
75
+ exports.GraphSchemaVersionError = GraphSchemaVersionError;
76
+ class GraphCorruptError extends Error {
77
+ absPath;
78
+ detail;
79
+ constructor(absPath, detail) {
80
+ super(`graph.json at ${absPath} is malformed: ${detail}. Regenerate with \`--refresh\`.`);
81
+ this.absPath = absPath;
82
+ this.detail = detail;
83
+ this.name = 'GraphCorruptError';
84
+ }
85
+ }
86
+ exports.GraphCorruptError = GraphCorruptError;
87
+ /**
88
+ * Read + validate + index the graph artifact. The returned `Graph`
89
+ * carries convenience indices (`nodeById`, `edgesFromNode`, ...)
90
+ * built once at load time; queries in `./queries.ts` read from these
91
+ * maps for O(1) traversal rather than repeatedly scanning the arrays.
92
+ *
93
+ * Validation is intentionally lightweight — top-level shape + required
94
+ * fields per node/edge. Deep schema validation (every optional field's
95
+ * types, referential integrity of every edge endpoint) would catch
96
+ * more but cost more on every load; instead we trust the producer and
97
+ * surface unexpected shapes as runtime errors at the query layer.
98
+ */
99
+ function loadGraph(cwd) {
100
+ const absPath = path.join(cwd, types_1.GRAPH_REPORT_PATH);
101
+ if (!fs.existsSync(absPath)) {
102
+ throw new GraphNotFoundError(absPath);
103
+ }
104
+ let raw;
105
+ try {
106
+ raw = JSON.parse(fs.readFileSync(absPath, 'utf-8'));
107
+ }
108
+ catch (err) {
109
+ throw new GraphCorruptError(absPath, err instanceof Error ? err.message : 'JSON parse failed');
110
+ }
111
+ const json = validateAndUpgrade(absPath, raw);
112
+ return indexGraph(json);
113
+ }
114
+ /**
115
+ * Fail-open variant of {@link loadGraph}: returns undefined on ANY
116
+ * error (missing file, parse failure, schema mismatch) instead of
117
+ * throwing. For additive, never-block consumers — the PreToolUse
118
+ * context hook and the finding-enrichment pass — where a missing or
119
+ * stale graph must degrade to "no context", never an error.
120
+ */
121
+ function tryLoadGraph(cwd) {
122
+ try {
123
+ return loadGraph(cwd);
124
+ }
125
+ catch {
126
+ return undefined;
127
+ }
128
+ }
129
+ function validateAndUpgrade(absPath, raw) {
130
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
131
+ throw new GraphCorruptError(absPath, 'top-level value is not an object');
132
+ }
133
+ const obj = raw;
134
+ const v = obj.schemaVersion;
135
+ if (typeof v !== 'number') {
136
+ throw new GraphCorruptError(absPath, 'schemaVersion is missing or not a number');
137
+ }
138
+ if (v > types_1.GRAPH_SCHEMA_VERSION) {
139
+ throw new GraphSchemaVersionError(absPath, v, types_1.GRAPH_SCHEMA_VERSION);
140
+ }
141
+ // Future migrations: switch on v here when v2+ lands. Today v === 1
142
+ // is the only supported version; no migration needed.
143
+ for (const key of ['meta', 'nodes', 'edges', 'communities', 'symbolIndex']) {
144
+ if (!(key in obj)) {
145
+ throw new GraphCorruptError(absPath, `missing required top-level field "${key}"`);
146
+ }
147
+ }
148
+ if (!Array.isArray(obj.nodes)) {
149
+ throw new GraphCorruptError(absPath, '"nodes" is not an array');
150
+ }
151
+ if (!Array.isArray(obj.edges)) {
152
+ throw new GraphCorruptError(absPath, '"edges" is not an array');
153
+ }
154
+ if (!Array.isArray(obj.communities)) {
155
+ throw new GraphCorruptError(absPath, '"communities" is not an array');
156
+ }
157
+ // Trust the rest; runtime errors in queries surface deeper issues.
158
+ return raw;
159
+ }
160
+ function indexGraph(json) {
161
+ const nodeById = new Map();
162
+ for (const n of json.nodes)
163
+ nodeById.set(n.id, n);
164
+ const edgesFromNode = new Map();
165
+ const edgesToNode = new Map();
166
+ for (const e of json.edges) {
167
+ const fromList = edgesFromNode.get(e.from) ?? [];
168
+ fromList.push(e);
169
+ edgesFromNode.set(e.from, fromList);
170
+ const toList = edgesToNode.get(e.to) ?? [];
171
+ toList.push(e);
172
+ edgesToNode.set(e.to, toList);
173
+ }
174
+ const nodesByFile = new Map();
175
+ for (const n of json.nodes) {
176
+ const list = nodesByFile.get(n.sourceFile) ?? [];
177
+ list.push(n);
178
+ nodesByFile.set(n.sourceFile, list);
179
+ }
180
+ const communityById = new Map();
181
+ const communityByNode = new Map();
182
+ for (const c of json.communities) {
183
+ communityById.set(c.id, c);
184
+ for (const nid of c.nodeIds)
185
+ communityByNode.set(nid, c);
186
+ }
187
+ return {
188
+ ...json,
189
+ nodeById,
190
+ edgesFromNode,
191
+ edgesToNode,
192
+ nodesByFile,
193
+ communityById,
194
+ communityByNode,
195
+ };
196
+ }
197
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/explore/load.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8DH,8BAaC;AASD,oCAMC;AAxFD,uCAAyB;AACzB,2CAA6B;AAC7B,mCAQiB;AAIR,kGAXP,yBAAiB,OAWO;AAE1B,MAAa,kBAAmB,SAAQ,KAAK;IACf;IAA5B,YAA4B,OAAe;QACzC,KAAK,CACH,oBAAoB,OAAO,kEAAkE,CAC9F,CAAC;QAHwB,YAAO,GAAP,OAAO,CAAQ;QAIzC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAPD,gDAOC;AAED,MAAa,uBAA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