@agentvibes/guardrails 0.2.7 → 0.3.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 (265) hide show
  1. package/README.md +252 -5
  2. package/candidates/README.md +13 -13
  3. package/candidates/r10-as-cast.yml +4 -4
  4. package/candidates/r1d-scattered-numeric-const-in-component.yml +3 -3
  5. package/candidates/r2-helper-fn-in-tsx.yml +3 -3
  6. package/candidates/r3-hooks-outside-layout.yml +4 -4
  7. package/candidates/r6-jsx-comment-smell.yml +2 -2
  8. package/candidates/r7-raw-hsl-outside-tokens.yml +3 -3
  9. package/candidates/r8-inline-style-prop.yml +2 -2
  10. package/candidates/r9-optional-store-arg.yml +2 -2
  11. package/dist/astGrep.js +4 -2
  12. package/dist/astGrep.js.map +1 -1
  13. package/dist/cli.js +89 -6
  14. package/dist/cli.js.map +1 -1
  15. package/dist/cliArgsTest.d.ts +1 -0
  16. package/dist/cliArgsTest.js +44 -0
  17. package/dist/cliArgsTest.js.map +1 -0
  18. package/dist/doctor.d.ts +1 -1
  19. package/dist/doctor.js +58 -6
  20. package/dist/doctor.js.map +1 -1
  21. package/dist/fileSloc.d.ts +28 -0
  22. package/dist/fileSloc.js +72 -0
  23. package/dist/fileSloc.js.map +1 -0
  24. package/dist/fileSlocBaseline.d.ts +78 -0
  25. package/dist/fileSlocBaseline.js +173 -0
  26. package/dist/fileSlocBaseline.js.map +1 -0
  27. package/dist/fileSlocGate.d.ts +17 -0
  28. package/dist/fileSlocGate.js +75 -0
  29. package/dist/fileSlocGate.js.map +1 -0
  30. package/dist/fileSlocTest.d.ts +1 -0
  31. package/dist/fileSlocTest.js +172 -0
  32. package/dist/fileSlocTest.js.map +1 -0
  33. package/dist/fileWalk.js +1 -1
  34. package/dist/fileWalk.js.map +1 -1
  35. package/dist/findings.d.ts +1 -1
  36. package/dist/gateRed.d.ts +1 -1
  37. package/dist/gateRed.js +1 -0
  38. package/dist/gateRed.js.map +1 -1
  39. package/dist/gitDiff.d.ts +6 -0
  40. package/dist/gitDiff.js +25 -0
  41. package/dist/gitDiff.js.map +1 -1
  42. package/dist/hookStop.d.ts +2 -1
  43. package/dist/hookStop.js +7 -1
  44. package/dist/hookStop.js.map +1 -1
  45. package/dist/hookStopTest.d.ts +1 -1
  46. package/dist/hookStopTest.js +1 -0
  47. package/dist/hookStopTest.js.map +1 -1
  48. package/dist/init.js +1 -1
  49. package/dist/init.js.map +1 -1
  50. package/dist/initTest.d.ts +1 -1
  51. package/dist/initTest.js +2 -1
  52. package/dist/initTest.js.map +1 -1
  53. package/dist/iterateTest.d.ts +1 -1
  54. package/dist/iterateTest.js +1 -0
  55. package/dist/iterateTest.js.map +1 -1
  56. package/dist/jsxSuppress.js +1 -1
  57. package/dist/jsxSuppress.js.map +1 -1
  58. package/dist/jsxSuppressTest.d.ts +1 -1
  59. package/dist/jsxSuppressTest.js +4 -2
  60. package/dist/jsxSuppressTest.js.map +1 -1
  61. package/dist/leaksRed.d.ts +1 -1
  62. package/dist/leaksRed.js +1 -0
  63. package/dist/leaksRed.js.map +1 -1
  64. package/dist/metrics.d.ts +9 -0
  65. package/dist/metrics.js +96 -7
  66. package/dist/metrics.js.map +1 -1
  67. package/dist/metricsBaseline.js +1 -1
  68. package/dist/metricsBaseline.js.map +1 -1
  69. package/dist/metricsCollect.js +2 -45
  70. package/dist/metricsCollect.js.map +1 -1
  71. package/dist/metricsCycle.d.ts +1 -1
  72. package/dist/metricsCycle.js +1 -0
  73. package/dist/metricsCycle.js.map +1 -1
  74. package/dist/metricsTypes.d.ts +1 -1
  75. package/dist/overrideDeclarations.d.ts +35 -0
  76. package/dist/overrideDeclarations.js +94 -0
  77. package/dist/overrideDeclarations.js.map +1 -0
  78. package/dist/overrides.d.ts +35 -0
  79. package/dist/overrides.js +284 -0
  80. package/dist/overrides.js.map +1 -0
  81. package/dist/overridesTest.d.ts +1 -0
  82. package/dist/overridesTest.js +183 -0
  83. package/dist/overridesTest.js.map +1 -0
  84. package/dist/pipeOutputTest.d.ts +1 -1
  85. package/dist/pipeOutputTest.js +2 -1
  86. package/dist/pipeOutputTest.js.map +1 -1
  87. package/dist/presetDrift.d.ts +8 -0
  88. package/dist/presetDrift.js +91 -34
  89. package/dist/presetDrift.js.map +1 -1
  90. package/dist/presetDriftTest.d.ts +1 -1
  91. package/dist/presetDriftTest.js +3 -3
  92. package/dist/presetDriftTest.js.map +1 -1
  93. package/dist/record/config.d.ts +17 -0
  94. package/dist/record/config.js +83 -0
  95. package/dist/record/config.js.map +1 -0
  96. package/dist/record/index.d.ts +69 -0
  97. package/dist/record/index.js +8 -0
  98. package/dist/record/index.js.map +1 -0
  99. package/dist/record/record.d.ts +56 -0
  100. package/dist/record/record.js +111 -0
  101. package/dist/record/record.js.map +1 -0
  102. package/dist/record/repoKey.d.ts +8 -0
  103. package/dist/record/repoKey.js +70 -0
  104. package/dist/record/repoKey.js.map +1 -0
  105. package/dist/record/repoMetrics.d.ts +14 -0
  106. package/dist/record/repoMetrics.js +124 -0
  107. package/dist/record/repoMetrics.js.map +1 -0
  108. package/dist/record/runRecord.d.ts +60 -0
  109. package/dist/record/runRecord.js +2 -0
  110. package/dist/record/runRecord.js.map +1 -0
  111. package/dist/record/schema.d.ts +31 -0
  112. package/dist/record/schema.js +201 -0
  113. package/dist/record/schema.js.map +1 -0
  114. package/dist/record/writer.d.ts +22 -0
  115. package/dist/record/writer.js +341 -0
  116. package/dist/record/writer.js.map +1 -0
  117. package/dist/recordTest.d.ts +1 -0
  118. package/dist/recordTest.js +422 -0
  119. package/dist/recordTest.js.map +1 -0
  120. package/dist/renameDiffTest.d.ts +1 -1
  121. package/dist/renameDiffTest.js +2 -1
  122. package/dist/renameDiffTest.js.map +1 -1
  123. package/dist/repoRules.js +1 -1
  124. package/dist/repoRules.js.map +1 -1
  125. package/dist/repoRulesTest.d.ts +1 -1
  126. package/dist/repoRulesTest.js +2 -1
  127. package/dist/repoRulesTest.js.map +1 -1
  128. package/dist/screenScope.js +4 -5
  129. package/dist/screenScope.js.map +1 -1
  130. package/dist/screenScopeTest.d.ts +1 -1
  131. package/dist/screenScopeTest.js +2 -1
  132. package/dist/screenScopeTest.js.map +1 -1
  133. package/dist/severityTest.d.ts +1 -1
  134. package/dist/severityTest.js +1 -0
  135. package/dist/severityTest.js.map +1 -1
  136. package/dist/siblingCloneTest.js +12 -12
  137. package/dist/siblingCloneTest.js.map +1 -1
  138. package/dist/snapshot.d.ts +2 -0
  139. package/dist/snapshot.js +118 -0
  140. package/dist/snapshot.js.map +1 -0
  141. package/dist/snapshotTest.d.ts +1 -0
  142. package/dist/snapshotTest.js +194 -0
  143. package/dist/snapshotTest.js.map +1 -0
  144. package/dist/structure.js +2 -2
  145. package/dist/structure.js.map +1 -1
  146. package/dist/testIsolation.d.ts +1 -0
  147. package/dist/testIsolation.js +7 -0
  148. package/dist/testIsolation.js.map +1 -0
  149. package/dist/testPaths.d.ts +4 -0
  150. package/dist/testPaths.js +9 -0
  151. package/dist/testPaths.js.map +1 -0
  152. package/dist/testRules.js +33 -3
  153. package/dist/testRules.js.map +1 -1
  154. package/dist/time.d.ts +22 -0
  155. package/dist/time.js +77 -0
  156. package/dist/time.js.map +1 -0
  157. package/dist/timeTest.d.ts +1 -0
  158. package/dist/timeTest.js +103 -0
  159. package/dist/timeTest.js.map +1 -0
  160. package/dist/tomlTable.d.ts +1 -1
  161. package/dist/tomlTable.js +6 -3
  162. package/dist/tomlTable.js.map +1 -1
  163. package/dist/toolResolve.d.ts +6 -0
  164. package/dist/toolResolve.js +18 -0
  165. package/dist/toolResolve.js.map +1 -1
  166. package/dist/twinCoverageTest.js +2 -20
  167. package/dist/twinCoverageTest.js.map +1 -1
  168. package/dist/verify.d.ts +2 -1
  169. package/dist/verify.js +33 -5
  170. package/dist/verify.js.map +1 -1
  171. package/dist/verifyDiff.d.ts +3 -2
  172. package/dist/verifyDiff.js +58 -8
  173. package/dist/verifyDiff.js.map +1 -1
  174. package/dist/wiring.d.ts +31 -0
  175. package/dist/wiring.js +262 -0
  176. package/dist/wiring.js.map +1 -0
  177. package/dist/wiringTest.d.ts +1 -0
  178. package/dist/wiringTest.js +127 -0
  179. package/dist/wiringTest.js.map +1 -0
  180. package/package.json +18 -6
  181. package/rules/__fixtures__/demo-mode-by-default/bad.ts +1 -1
  182. package/rules/__fixtures__/demo-mode-by-default/bad.tsx +1 -1
  183. package/rules/__fixtures__/direct-store-import/bad.tsx +1 -1
  184. package/rules/__fixtures__/direct-store-import/good.tsx +2 -2
  185. package/rules/__fixtures__/discriminator-ternary/bad.ts +9 -0
  186. package/rules/__fixtures__/discriminator-ternary/bad.tsx +1 -1
  187. package/rules/__fixtures__/discriminator-ternary/good.ts +17 -0
  188. package/rules/__fixtures__/discriminator-ternary/good.tsx +1 -1
  189. package/rules/__fixtures__/hardcoded-url-in-component/components/bad.ts +9 -0
  190. package/rules/__fixtures__/hardcoded-url-in-component/components/good.ts +13 -0
  191. package/rules/__fixtures__/inline-map-row/bad.tsx +1 -1
  192. package/rules/__fixtures__/inline-map-row/good.tsx +1 -1
  193. package/rules/__fixtures__/match-bool-to-null/bad.ts +14 -0
  194. package/rules/__fixtures__/match-bool-to-null/bad.tsx +8 -0
  195. package/rules/__fixtures__/match-bool-to-null/good.ts +12 -0
  196. package/rules/__fixtures__/match-bool-to-null/good.tsx +12 -0
  197. package/rules/__fixtures__/missing-observer/bad.tsx +2 -2
  198. package/rules/__fixtures__/missing-observer/good.tsx +2 -2
  199. package/rules/__fixtures__/no-local-kit-clone/bad.ts +2 -2
  200. package/rules/__fixtures__/no-local-kit-clone/bad.tsx +2 -2
  201. package/rules/__fixtures__/state-loading-boolean-shape/good.ts +1 -1
  202. package/rules/__fixtures__/state-loading-boolean-shape/good.tsx +1 -1
  203. package/rules/__fixtures__/store-async-method/good.ts +1 -1
  204. package/rules/__fixtures__/store-async-method/good.tsx +1 -1
  205. package/rules/__fixtures__/store-context-provider/bad.ts +1 -1
  206. package/rules/__fixtures__/store-delegation-getter/bad.ts +1 -1
  207. package/rules/__fixtures__/store-delegation-getter/bad.tsx +1 -1
  208. package/rules/__fixtures__/store-delegation-getter/good.ts +3 -3
  209. package/rules/__fixtures__/store-delegation-getter/good.tsx +3 -3
  210. package/rules/__fixtures__/store-no-runinaction/bad.ts +1 -1
  211. package/rules/__fixtures__/store-no-runinaction/bad.tsx +1 -1
  212. package/rules/__fixtures__/store-no-runinaction/good.ts +1 -1
  213. package/rules/__fixtures__/store-no-runinaction/good.tsx +1 -1
  214. package/rules/__fixtures__/ts-pattern-dangling-match/bad.ts +1 -1
  215. package/rules/__fixtures__/ts-pattern-dangling-match/good.ts +2 -2
  216. package/rules/__fixtures__/ui-imports-app-store/src/ui/bad.ts +11 -0
  217. package/rules/__fixtures__/ui-imports-app-store/src/ui/good.ts +13 -0
  218. package/rules/__fixtures__/ui-imports-app-store/src/ui/good.tsx +1 -1
  219. package/rules/__fixtures__/view-imports-store/good.view.tsx +1 -1
  220. package/rules/as-any-escape-tsx.yml +2 -2
  221. package/rules/as-any-escape.yml +2 -2
  222. package/rules/catch-empty-tsx.yml +3 -3
  223. package/rules/catch-empty.yml +3 -3
  224. package/rules/demo-mode-by-default-ts.yml +6 -7
  225. package/rules/demo-mode-by-default.yml +6 -7
  226. package/rules/direct-store-import.yml +15 -16
  227. package/rules/discriminator-ternary-ts.yml +46 -0
  228. package/rules/discriminator-ternary.yml +3 -3
  229. package/rules/hardcoded-url-in-component-ts.yml +40 -0
  230. package/rules/hardcoded-url-in-component.yml +5 -8
  231. package/rules/inline-map-row.yml +7 -7
  232. package/rules/instanceof-map-set-tsx.yml +2 -2
  233. package/rules/instanceof-map-set.yml +2 -2
  234. package/rules/kind-if-without-match-tsx.yml +1 -1
  235. package/rules/literal-union-in-component-tsx.yml +2 -2
  236. package/rules/literal-union-in-component.yml +7 -7
  237. package/rules/match-bool-to-null-ts.yml +27 -0
  238. package/rules/missing-observer.yml +5 -5
  239. package/rules/no-local-kit-clone-tsx.yml +2 -2
  240. package/rules/no-local-kit-clone.yml +2 -2
  241. package/rules/non-exhaustive-match-tsx.yml +4 -7
  242. package/rules/non-exhaustive-match.yml +2 -2
  243. package/rules/page-store-bare-usememo-tsx.yml +1 -1
  244. package/rules/page-store-bare-usememo.yml +1 -1
  245. package/rules/screen-file-styling.yml +3 -3
  246. package/rules/silent-default-return-tsx.yml +1 -1
  247. package/rules/store-async-method-tsx.yml +1 -1
  248. package/rules/store-async-method.yml +1 -1
  249. package/rules/store-context-provider-tsx.yml +3 -3
  250. package/rules/store-context-provider.yml +5 -5
  251. package/rules/store-delegation-getter-tsx.yml +2 -2
  252. package/rules/store-delegation-getter.yml +2 -2
  253. package/rules/store-no-runinaction-tsx.yml +2 -2
  254. package/rules/store-no-runinaction.yml +2 -2
  255. package/rules/store-no-setinterval-poll-tsx.yml +1 -1
  256. package/rules/store-no-setinterval-poll.yml +1 -1
  257. package/rules/ts-pattern-dangling-match-tsx.yml +4 -4
  258. package/rules/ts-pattern-dangling-match.yml +4 -4
  259. package/rules/ui-imports-app-store-ts.yml +61 -0
  260. package/rules/ui-imports-app-store.yml +1 -1
  261. package/rules/view-file-logic.yml +5 -5
  262. package/rules/view-imports-store.yml +4 -5
  263. package/rules/zod-optional-nullable-tsx.yml +2 -2
  264. package/rules/zod-optional-nullable.yml +2 -2
  265. package/structure/rules/component-decl.yml +1 -1
@@ -0,0 +1,83 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { isAbsolute, join, resolve } from "node:path";
4
+ import { parse as parseToml } from "smol-toml";
5
+ import { z } from "zod";
6
+ // Where a run is recorded, if anywhere.
7
+ //
8
+ // GUARDRAILS_RECORD unset, "" or "0" → nothing is recorded
9
+ // GUARDRAILS_RECORD=1 → the configured or default database
10
+ // GUARDRAILS_RECORD=<path> → that database
11
+ //
12
+ // The configured database is `[record] db = "<path>"` in
13
+ // $XDG_CONFIG_HOME/agentvibes/guardrails.toml (default ~/.config/…). The
14
+ // default database is $XDG_STATE_HOME/agentvibes/guardrails.sqlite (default
15
+ // ~/.local/state/…). Every path is computed at run time; `~/` is expanded.
16
+ // `guardrails snapshot` records whatever the variable says, because recording
17
+ // is the whole point of that command.
18
+ export class RecordConfigError extends Error {
19
+ }
20
+ const UserConfig = z
21
+ .object({
22
+ record: z
23
+ .object({ db: z.string().min(1) })
24
+ .partial()
25
+ .strict()
26
+ .default({}),
27
+ })
28
+ .loose();
29
+ function expand(path, env) {
30
+ const home = env.HOME ?? homedir();
31
+ if (path === "~")
32
+ return home;
33
+ if (path.startsWith("~/"))
34
+ return join(home, path.slice(2));
35
+ return isAbsolute(path) ? path : resolve(path);
36
+ }
37
+ function xdg(env, key, fallback) {
38
+ const v = env[key];
39
+ // The XDG spec: a relative value is invalid and must be ignored.
40
+ if (v !== undefined && v !== "" && isAbsolute(v))
41
+ return v;
42
+ return join(env.HOME ?? homedir(), fallback);
43
+ }
44
+ export function userConfigPath(env = process.env) {
45
+ return join(xdg(env, "XDG_CONFIG_HOME", ".config"), "agentvibes", "guardrails.toml");
46
+ }
47
+ export function defaultDbPath(env = process.env) {
48
+ return join(xdg(env, "XDG_STATE_HOME", ".local/state"), "agentvibes", "guardrails.sqlite");
49
+ }
50
+ /** `[record] db` from the user config, expanded; undefined when unset. Throws on a bad file. */
51
+ export function configuredDb(env = process.env) {
52
+ const path = userConfigPath(env);
53
+ if (!existsSync(path))
54
+ return undefined;
55
+ let doc;
56
+ try {
57
+ doc = parseToml(readFileSync(path, "utf8"));
58
+ }
59
+ catch (err) {
60
+ throw new RecordConfigError(`${path} is not valid TOML: ${err.message.split("\n")[0]}`);
61
+ }
62
+ const parsed = UserConfig.safeParse(doc);
63
+ if (!parsed.success) {
64
+ const issue = parsed.error.issues[0];
65
+ throw new RecordConfigError(`${path}: [record] ${issue?.path.join(".") ?? ""} ${issue?.message ?? "invalid"}`);
66
+ }
67
+ const db = parsed.data.record.db;
68
+ return db === undefined ? undefined : expand(db, env);
69
+ }
70
+ /** The database this run records to. `force` (snapshot) records even when the variable is unset. */
71
+ export function recordTarget(env = process.env, force = false) {
72
+ const raw = (env.GUARDRAILS_RECORD ?? "").trim();
73
+ const off = raw === "" || raw === "0";
74
+ if (off && !force)
75
+ return { status: "off" };
76
+ if (!off && raw !== "1")
77
+ return { status: "on", db: expand(raw, env), source: "env-path" };
78
+ const configured = configuredDb(env);
79
+ return configured === undefined
80
+ ? { status: "on", db: defaultDbPath(env), source: "default" }
81
+ : { status: "on", db: configured, source: "config" };
82
+ }
83
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/record/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wCAAwC;AACxC,EAAE;AACF,8DAA8D;AAC9D,6EAA6E;AAC7E,wDAAwD;AACxD,EAAE;AACF,yDAAyD;AACzD,yEAAyE;AACzE,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,sCAAsC;AAEtC,MAAM,OAAO,iBAAkB,SAAQ,KAAK;CAAG;AAM/C,MAAM,UAAU,GAAG,CAAC;KACjB,MAAM,CAAC;IACN,MAAM,EAAE,CAAC;SACN,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;SACjC,OAAO,EAAE;SACT,MAAM,EAAE;SACR,OAAO,CAAC,EAAE,CAAC;CACf,CAAC;KACD,KAAK,EAAE,CAAC;AAIX,SAAS,MAAM,CAAC,IAAY,EAAE,GAAQ;IAC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AC;IAC5C,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,GAAG;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;IAC3F,MAAM,UAAU,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,UAAU,KAAK,SAAS;QAC7B,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE;QAC7D,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACzD,CAAC"}
@@ -0,0 +1,69 @@
1
+ export { configuredDb, defaultDbPath, RecordConfigError, type RecordTarget, recordTarget, userConfigPath, } from "./config.js";
2
+ export { parseRemote, repoIdentity } from "./repoKey.js";
3
+ export { LANGUAGES } from "./repoMetrics.js";
4
+ export type { FindingsData, Part, RepoIdentity, RunRecord, RunScope, ToolVersions, } from "./runRecord.js";
5
+ export { FACET_TABLES, METRIC_COLUMNS, SCHEMA_VERSION, TOP_FINDINGS_CAP, WIRING_COLUMNS, } from "./schema.js";
6
+ /** 0 or 1; NULL (null) where the part was never measured. */
7
+ type Flag = 0 | 1 | null;
8
+ export interface ProjectLatestRow {
9
+ id: number;
10
+ key: string;
11
+ host: string;
12
+ owner: string;
13
+ name: string;
14
+ wiring: "off" | "partial" | "on" | null;
15
+ wiring_installed: Flag;
16
+ wiring_sgconfig_canon: Flag;
17
+ wiring_lint_script: Flag;
18
+ wiring_ci: Flag;
19
+ wiring_hook_postedit: Flag;
20
+ wiring_hook_stop: Flag;
21
+ wiring_preset: Flag;
22
+ errors: number | null;
23
+ warnings: number | null;
24
+ overrides: number | null;
25
+ overrides_without_reason: number | null;
26
+ sloc: number | null;
27
+ files: number | null;
28
+ avg_file_sloc: number | null;
29
+ files_over_sloc_limit: number | null;
30
+ run_in_action: number | null;
31
+ worktrees: number | null;
32
+ local_branches: number | null;
33
+ build_ms: number | null;
34
+ last_run_at: string;
35
+ last_sha: string | null;
36
+ last_branch: string | null;
37
+ last_command: string;
38
+ wiring_run_id: number | null;
39
+ findings_run_id: number | null;
40
+ overrides_run_id: number | null;
41
+ }
42
+ export interface FindingLatestRow {
43
+ id: number;
44
+ repo: string;
45
+ rule: string;
46
+ tier: "error" | "warning" | "info" | "hint";
47
+ file: string;
48
+ line: number;
49
+ message: string;
50
+ }
51
+ export interface OverrideLatestRow {
52
+ id: number;
53
+ repo: string;
54
+ kind: "ast-grep-ignore" | "biome-ignore" | "verify-scope" | "biome-rule" | "repo-rule-shadow" | "metrics-limit";
55
+ rule: string;
56
+ where: string;
57
+ reason: string | null;
58
+ has_reason: 0 | 1;
59
+ file: string;
60
+ line: number;
61
+ }
62
+ export interface MetricHistoryRow {
63
+ id: number;
64
+ run_id: number;
65
+ repo: string;
66
+ at: string;
67
+ metric: string;
68
+ value: number;
69
+ }
@@ -0,0 +1,8 @@
1
+ // `@agentvibes/guardrails/record`: what a dashboard or TUI needs to read the
2
+ // recording database — where it is, which schema version it speaks, and the
3
+ // row shape of each latest table. README "Recording" is the prose contract.
4
+ export { configuredDb, defaultDbPath, RecordConfigError, recordTarget, userConfigPath, } from "./config.js";
5
+ export { parseRemote, repoIdentity } from "./repoKey.js";
6
+ export { LANGUAGES } from "./repoMetrics.js";
7
+ export { FACET_TABLES, METRIC_COLUMNS, SCHEMA_VERSION, TOP_FINDINGS_CAP, WIRING_COLUMNS, } from "./schema.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/record/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAE5E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,iBAAiB,EAEjB,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAS7C,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC"}
@@ -0,0 +1,56 @@
1
+ import type { Override } from "../overrides.js";
2
+ import type { WiringReport } from "../wiring.js";
3
+ import { type RecordTarget } from "./config.js";
4
+ import type { FindingsData, Part, RunScope } from "./runRecord.js";
5
+ /**
6
+ * Where this run records, resolved ONCE when the run starts: `snapshot`
7
+ * changes directory into the repo it observes, and a relative
8
+ * GUARDRAILS_RECORD must keep meaning what it meant where it was typed. A
9
+ * user config that cannot be read is `broken`: the run goes on and the
10
+ * error is reported when the record would be written.
11
+ */
12
+ export type ResolvedTarget = RecordTarget | {
13
+ status: "broken";
14
+ error: string;
15
+ };
16
+ export declare function resolveTarget(force?: boolean): ResolvedTarget;
17
+ export declare const NOT_RECORDING: ResolvedTarget;
18
+ export declare class RunCollector {
19
+ readonly target: ResolvedTarget;
20
+ findings: Part<FindingsData>;
21
+ overrides: Part<Override[]>;
22
+ wiring: Part<WiringReport>;
23
+ metrics: Part<Record<string, number>>;
24
+ /** The checkout the run observes; `snapshot` points it at another directory. */
25
+ root: string;
26
+ constructor(target: ResolvedTarget);
27
+ /** Whether this run will be recorded, so record-only work is worth doing. */
28
+ get recording(): boolean;
29
+ /** Records metrics by name. Several calls in one run merge, the later value winning. */
30
+ addMetrics(scope: RunScope, values: Record<string, number>): void;
31
+ }
32
+ /** `full` when the run looked at the whole checkout, `paths` when it was given a subset. */
33
+ export declare function scopeOf(targets: readonly string[]): RunScope;
34
+ export type RecordOutcome = {
35
+ status: "off";
36
+ } | {
37
+ status: "recorded";
38
+ db: string;
39
+ runId: number;
40
+ } | {
41
+ status: "failed";
42
+ db: string | undefined;
43
+ error: string;
44
+ };
45
+ export interface RunMeta {
46
+ command: string;
47
+ exitCode: number;
48
+ durationMs: number;
49
+ startedAt: Date;
50
+ }
51
+ /**
52
+ * Stores what the collector saw. It never throws: a database that cannot be
53
+ * written must not change a gate's verdict, so a failure is one line on
54
+ * stderr and an outcome the caller may act on (snapshot exits non-zero).
55
+ */
56
+ export declare function recordRun(c: RunCollector, meta: RunMeta): Promise<RecordOutcome>;
@@ -0,0 +1,111 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { match } from "ts-pattern";
4
+ import { packageRoot } from "../packagePaths.js";
5
+ import { resolvedVersion } from "../toolResolve.js";
6
+ import { recordTarget } from "./config.js";
7
+ import { currentBranch, headSha, repoIdentity } from "./repoKey.js";
8
+ import { SKIPPED } from "./runRecord.js";
9
+ import { openDatabase, writeRun } from "./writer.js";
10
+ export function resolveTarget(force = false) {
11
+ try {
12
+ return recordTarget(process.env, force);
13
+ }
14
+ catch (err) {
15
+ return { status: "broken", error: err.message };
16
+ }
17
+ }
18
+ export const NOT_RECORDING = { status: "off" };
19
+ export class RunCollector {
20
+ target;
21
+ findings = SKIPPED;
22
+ overrides = SKIPPED;
23
+ wiring = SKIPPED;
24
+ metrics = SKIPPED;
25
+ /** The checkout the run observes; `snapshot` points it at another directory. */
26
+ root = process.cwd();
27
+ constructor(target) {
28
+ this.target = target;
29
+ }
30
+ /** Whether this run will be recorded, so record-only work is worth doing. */
31
+ get recording() {
32
+ return match(this.target)
33
+ .with({ status: "off" }, () => false)
34
+ .with({ status: "on" }, { status: "broken" }, () => true)
35
+ .exhaustive();
36
+ }
37
+ /** Records metrics by name. Several calls in one run merge, the later value winning. */
38
+ addMetrics(scope, values) {
39
+ const finite = Object.entries(values).filter(([, n]) => Number.isFinite(n));
40
+ const previous = match(this.metrics)
41
+ .with({ status: "measured" }, (p) => p.data)
42
+ .with({ status: "unavailable" }, { status: "skipped" }, () => ({}))
43
+ .exhaustive();
44
+ this.metrics = {
45
+ status: "measured",
46
+ scope,
47
+ data: { ...previous, ...Object.fromEntries(finite) },
48
+ };
49
+ }
50
+ }
51
+ /** `full` when the run looked at the whole checkout, `paths` when it was given a subset. */
52
+ export function scopeOf(targets) {
53
+ const whole = targets.every((t) => resolve(t) === resolve("."));
54
+ return whole ? "full" : "paths";
55
+ }
56
+ function guardrailsVersion() {
57
+ const pkg = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
58
+ return pkg.version;
59
+ }
60
+ /**
61
+ * Stores what the collector saw. It never throws: a database that cannot be
62
+ * written must not change a gate's verdict, so a failure is one line on
63
+ * stderr and an outcome the caller may act on (snapshot exits non-zero).
64
+ */
65
+ export async function recordRun(c, meta) {
66
+ let db;
67
+ try {
68
+ return await match(c.target)
69
+ .with({ status: "off" }, async () => ({ status: "off" }))
70
+ .with({ status: "broken" }, async (t) => {
71
+ throw new Error(t.error);
72
+ })
73
+ .with({ status: "on" }, async (t) => {
74
+ db = t.db;
75
+ const record = {
76
+ repo: repoIdentity(c.root),
77
+ root: resolve(c.root),
78
+ command: meta.command,
79
+ at: meta.startedAt.toISOString(),
80
+ sha: headSha(c.root),
81
+ branch: currentBranch(c.root),
82
+ durationMs: meta.durationMs,
83
+ exitCode: meta.exitCode,
84
+ tools: {
85
+ guardrails: guardrailsVersion(),
86
+ node: process.version,
87
+ astGrep: resolvedVersion("ast-grep"),
88
+ biome: resolvedVersion("biome"),
89
+ },
90
+ findings: c.findings,
91
+ overrides: c.overrides,
92
+ wiring: c.wiring,
93
+ metrics: c.metrics,
94
+ };
95
+ const handle = await openDatabase(t.db);
96
+ try {
97
+ return { status: "recorded", db: t.db, runId: writeRun(handle, record) };
98
+ }
99
+ finally {
100
+ handle.close();
101
+ }
102
+ })
103
+ .exhaustive();
104
+ }
105
+ catch (err) {
106
+ const error = err.message.split("\n")[0] ?? String(err);
107
+ console.error(`guardrails: recording ${meta.command} to ${db ?? "the database"} failed: ${error}`);
108
+ return { status: "failed", db, error };
109
+ }
110
+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): Omit<RepoIdentity, "key"> | undefined;
3
+ export declare function identityFor(parsed: Omit<RepoIdentity, "key">): RepoIdentity;
4
+ /** The identity of the checkout at `root`. */
5
+ export declare function repoIdentity(root: string): RepoIdentity;
6
+ export declare function headSha(root: string): string | undefined;
7
+ /** The current branch; undefined on a detached HEAD. */
8
+ export declare function currentBranch(root: string): string | undefined;
@@ -0,0 +1,70 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { basename, resolve } from "node:path";
3
+ // The repo key: `host/owner/name` from the `origin` remote, lowercase, without
4
+ // `.git` and without any `user:token@` credentials. Accepted remote forms:
5
+ //
6
+ // https://host/owner/name(.git) http(s) with user, token or port
7
+ // ssh://git@host:2222/owner/name.git ssh:// with a port (port dropped)
8
+ // git@host:owner/name.git scp form
9
+ // https://host/group/sub/name GitLab subgroups: owner = "group/sub"
10
+ //
11
+ // A checkout with no origin is `local/<directory name>`.
12
+ export function parseRemote(url) {
13
+ const u = url.trim();
14
+ let host;
15
+ let path;
16
+ const scp = /^(?:[^@/\s]+@)?([^:/\s]+):(?!\/\/)(.+)$/.exec(u);
17
+ const withScheme = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]*@)?([^/:]+)(?::\d+)?\/(.+)$/i.exec(u);
18
+ if (withScheme?.[1] !== undefined && withScheme[2] !== undefined) {
19
+ host = withScheme[1];
20
+ path = withScheme[2];
21
+ }
22
+ else if (scp?.[1] !== undefined && scp[2] !== undefined) {
23
+ host = scp[1];
24
+ path = scp[2];
25
+ }
26
+ else {
27
+ return undefined;
28
+ }
29
+ const segments = path
30
+ .replace(/\/+$/, "")
31
+ .replace(/\.git$/i, "")
32
+ .split("/")
33
+ .filter((s) => s !== "");
34
+ const name = segments.pop();
35
+ if (name === undefined || segments.length === 0)
36
+ return undefined;
37
+ return {
38
+ host: host.toLowerCase(),
39
+ owner: segments.join("/").toLowerCase(),
40
+ name: name.toLowerCase(),
41
+ };
42
+ }
43
+ export function identityFor(parsed) {
44
+ return { ...parsed, key: `${parsed.host}/${parsed.owner}/${parsed.name}` };
45
+ }
46
+ function git(root, args) {
47
+ const res = spawnSync("git", ["-C", root, ...args], { encoding: "utf8" });
48
+ if (res.error || res.status !== 0)
49
+ return undefined;
50
+ const out = res.stdout.trim();
51
+ return out === "" ? undefined : out;
52
+ }
53
+ /** The identity of the checkout at `root`. */
54
+ export function repoIdentity(root) {
55
+ const url = git(root, ["remote", "get-url", "origin"]);
56
+ const parsed = url === undefined ? undefined : parseRemote(url);
57
+ if (parsed !== undefined)
58
+ return identityFor(parsed);
59
+ const name = basename(resolve(root)).toLowerCase();
60
+ return { key: `local/${name}`, host: "local", owner: "", name };
61
+ }
62
+ export function headSha(root) {
63
+ return git(root, ["rev-parse", "HEAD"]);
64
+ }
65
+ /** The current branch; undefined on a detached HEAD. */
66
+ export function currentBranch(root) {
67
+ const b = git(root, ["rev-parse", "--abbrev-ref", "HEAD"]);
68
+ return b === "HEAD" ? undefined : b;
69
+ }
70
+ //# sourceMappingURL=repoKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repoKey.js","sourceRoot":"","sources":["../../src/record/repoKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG9C,+EAA+E;AAC/E,2EAA2E;AAC3E,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,kDAAkD;AAClD,+EAA+E;AAC/E,EAAE;AACF,yDAAyD;AAEzD,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACrB,IAAI,IAAY,CAAC;IACjB,IAAI,IAAY,CAAC;IACjB,MAAM,GAAG,GAAG,yCAAyC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9D,MAAM,UAAU,GAAG,8DAA8D,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;I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AAC,WAAW,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,OAAO,CAAC,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ProjectMetrics } from "../metricsTypes.js";
2
+ /** File extension → language, for the LOC breakdown. Anything else is not counted. */
3
+ export declare const LANGUAGES: Readonly<Record<string, string>>;
4
+ /** `loc` (non-blank lines), `loc_files`, and `loc.<language>` for every language present. */
5
+ export declare function locMetrics(root: string): Record<string, number>;
6
+ /**
7
+ * The SLOC `metrics` already measured per production file (fileSloc.ts:
8
+ * imports, blank and comment lines excluded): total, mean per file, and how
9
+ * many files exceed the repo's `max_file_sloc`.
10
+ */
11
+ export declare function slocMetrics(m: ProjectMetrics, root: string): Record<string, number>;
12
+ /** Open worktrees (the main one included) and local branches; absent outside git. */
13
+ export declare function gitMetrics(root: string): Record<string, number>;
14
+ export declare function repoMetrics(m: ProjectMetrics, root: string): Record<string, number>;
@@ -0,0 +1,124 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { lstatSync, readFileSync } from "node:fs";
3
+ import { extname, join } from "node:path";
4
+ import { baselineKey, lengthGated, maxFileSloc } from "../fileSlocBaseline.js";
5
+ import { collectFiles } from "../fileWalk.js";
6
+ // Whole-repo metrics that only the record needs. `metrics` and `snapshot`
7
+ // add them when a run records; none of them is gated. Names are stable API
8
+ // (README "Recording"): the projects_latest columns read `sloc`,
9
+ // `avg_file_sloc`, `files_over_sloc_limit`, `git_worktrees` and
10
+ // `git_local_branches` by exactly these names (METRIC_COLUMNS in schema.ts).
11
+ /** File extension → language, for the LOC breakdown. Anything else is not counted. */
12
+ export const LANGUAGES = {
13
+ ".ts": "typescript",
14
+ ".mts": "typescript",
15
+ ".cts": "typescript",
16
+ ".tsx": "tsx",
17
+ ".js": "javascript",
18
+ ".mjs": "javascript",
19
+ ".cjs": "javascript",
20
+ ".jsx": "jsx",
21
+ ".vue": "vue",
22
+ ".svelte": "svelte",
23
+ ".css": "css",
24
+ ".scss": "scss",
25
+ ".html": "html",
26
+ ".rs": "rust",
27
+ ".go": "go",
28
+ ".py": "python",
29
+ ".rb": "ruby",
30
+ ".java": "java",
31
+ ".kt": "kotlin",
32
+ ".swift": "swift",
33
+ ".c": "c",
34
+ ".h": "c",
35
+ ".cc": "cpp",
36
+ ".cpp": "cpp",
37
+ ".hpp": "cpp",
38
+ ".cs": "csharp",
39
+ ".sh": "shell",
40
+ ".sql": "sql",
41
+ };
42
+ /** Bigger files are generated or vendored (bundles, dumps), not written code. */
43
+ const MAX_COUNTED_BYTES = 2 * 1024 * 1024;
44
+ /**
45
+ * The project's files: tracked plus untracked-but-not-ignored, as git sees
46
+ * them. Outside a git checkout, every file under root (minus the walker's
47
+ * build and dependency directories).
48
+ */
49
+ function projectFiles(root) {
50
+ const res = spawnSync("git", ["-C", root, "ls-files", "-z", "--cached", "--others", "--exclude-standard"], { encoding: "utf8", maxBuffer: 256 * 1024 * 1024 });
51
+ if (!res.error && res.status === 0) {
52
+ return res.stdout
53
+ .split("\0")
54
+ .filter((f) => f !== "")
55
+ .map((f) => join(root, f));
56
+ }
57
+ return collectFiles([root], Object.keys(LANGUAGES));
58
+ }
59
+ /** `loc` (non-blank lines), `loc_files`, and `loc.<language>` for every language present. */
60
+ export function locMetrics(root) {
61
+ const out = { loc: 0, loc_files: 0 };
62
+ for (const file of projectFiles(root)) {
63
+ const lang = LANGUAGES[extname(file).toLowerCase()];
64
+ if (lang === undefined)
65
+ continue;
66
+ let text;
67
+ try {
68
+ const st = lstatSync(file);
69
+ if (!st.isFile() || st.size > MAX_COUNTED_BYTES)
70
+ continue;
71
+ text = readFileSync(file, "utf8");
72
+ }
73
+ catch {
74
+ // ast-grep-ignore: catch-empty -- a tracked file deleted in the work tree has no lines to count
75
+ continue;
76
+ }
77
+ let lines = 0;
78
+ for (const line of text.split("\n"))
79
+ if (line.trim() !== "")
80
+ lines += 1;
81
+ out.loc = (out.loc ?? 0) + lines;
82
+ out.loc_files = (out.loc_files ?? 0) + 1;
83
+ out[`loc.${lang}`] = (out[`loc.${lang}`] ?? 0) + lines;
84
+ }
85
+ return out;
86
+ }
87
+ /**
88
+ * The SLOC `metrics` already measured per production file (fileSloc.ts:
89
+ * imports, blank and comment lines excluded): total, mean per file, and how
90
+ * many files exceed the repo's `max_file_sloc`.
91
+ */
92
+ export function slocMetrics(m, root) {
93
+ const limit = maxFileSloc(root);
94
+ const sloc = m.files.reduce((sum, f) => sum + f.fileSloc, 0);
95
+ const out = {
96
+ sloc,
97
+ // The same files the length ratchet gates, so the two counts agree.
98
+ files_over_sloc_limit: m.files.filter((f) => f.fileSloc > limit && lengthGated(baselineKey(root, f.file))).length,
99
+ };
100
+ if (m.files.length > 0)
101
+ out.avg_file_sloc = Math.round((sloc / m.files.length) * 10) / 10;
102
+ return out;
103
+ }
104
+ function gitCount(root, args, line) {
105
+ const res = spawnSync("git", ["-C", root, ...args], { encoding: "utf8" });
106
+ if (res.error || res.status !== 0)
107
+ return undefined;
108
+ return res.stdout.split("\n").filter((l) => line.test(l)).length;
109
+ }
110
+ /** Open worktrees (the main one included) and local branches; absent outside git. */
111
+ export function gitMetrics(root) {
112
+ const out = {};
113
+ const worktrees = gitCount(root, ["worktree", "list", "--porcelain"], /^worktree /);
114
+ const branches = gitCount(root, ["for-each-ref", "--format=%(refname)", "refs/heads"], /\S/);
115
+ if (worktrees !== undefined)
116
+ out.git_worktrees = worktrees;
117
+ if (branches !== undefined)
118
+ out.git_local_branches = branches;
119
+ return out;
120
+ }
121
+ export function repoMetrics(m, root) {
122
+ return { ...slocMetrics(m, root), ...locMetrics(root), ...gitMetrics(root) };
123
+ }
124
+ //# sourceMappingURL=repoMetrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repoMetrics.js","sourceRoot":"","sources":["../../src/record/repoMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,o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,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,60 @@
1
+ import type { Finding, Severity } from "../findings.js";
2
+ import type { Override } from "../overrides.js";
3
+ import type { WiringReport } from "../wiring.js";
4
+ /** How much of the repo a run looked at. Only `full` runs refresh the latest tables. */
5
+ export type RunScope = "full" | "diff" | "paths";
6
+ export type Part<T> = {
7
+ status: "measured";
8
+ scope: RunScope;
9
+ data: T;
10
+ } | {
11
+ status: "unavailable";
12
+ reason: string;
13
+ } | {
14
+ status: "skipped";
15
+ };
16
+ export declare const SKIPPED: {
17
+ readonly status: "skipped";
18
+ };
19
+ export interface RepoIdentity {
20
+ /** `host/owner/name`, lowercase, no `.git`; `local/<dir>` when there is no origin. */
21
+ key: string;
22
+ host: string;
23
+ /** All path segments but the last (GitLab subgroups stay joined with `/`). */
24
+ owner: string;
25
+ name: string;
26
+ }
27
+ /**
28
+ * The findings a run measured. `error-only`: the run looked for error-tier
29
+ * findings only (the diff ratchet), so it says nothing about warnings.
30
+ */
31
+ export interface FindingsData {
32
+ tiers: "all" | "error-only";
33
+ list: Finding[];
34
+ }
35
+ export interface ToolVersions {
36
+ guardrails: string;
37
+ node: string;
38
+ astGrep: string | undefined;
39
+ biome: string | undefined;
40
+ }
41
+ export interface RunRecord {
42
+ repo: RepoIdentity;
43
+ /** Absolute path of the checkout the run looked at. */
44
+ root: string;
45
+ /** The subcommand, e.g. `verify`, `snapshot`, `time`. */
46
+ command: string;
47
+ /** ISO-8601 UTC, millisecond precision. */
48
+ at: string;
49
+ sha: string | undefined;
50
+ branch: string | undefined;
51
+ durationMs: number;
52
+ exitCode: number;
53
+ tools: ToolVersions;
54
+ findings: Part<FindingsData>;
55
+ overrides: Part<Override[]>;
56
+ wiring: Part<WiringReport>;
57
+ /** Metric name → value. Names are stable API: see METRIC_COLUMNS in schema.ts. */
58
+ metrics: Part<Record<string, number>>;
59
+ }
60
+ export type Tier = Severity;
@@ -0,0 +1,2 @@
1
+ export const SKIPPED = { status: "skipped" };
2
+ //# sourceMappingURL=runRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runRecord.js","sourceRoot":"","sources":["../../src/record/runRecord.ts"],"names":[],"mappings":"AAsBA,MAAM,CAAC,MAAM,OAAO,GAAG,EAAE,MAAM,EAAE,SAAS,EAAW,CAAC"}