@codyswann/lisa 2.241.0 → 2.242.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 (80) hide show
  1. package/package.json +1 -1
  2. package/plugins/lisa/.claude-plugin/plugin.json +10 -1
  3. package/plugins/lisa/.codex-plugin/hooks.json +9 -0
  4. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  5. package/plugins/lisa/hooks/threshold-ratchet-compare.mjs +315 -0
  6. package/plugins/lisa/hooks/threshold-ratchet-families.mjs +295 -0
  7. package/plugins/lisa/hooks/threshold-ratchet.mjs +213 -0
  8. package/plugins/lisa/hooks/threshold-ratchet.sh +22 -0
  9. package/plugins/lisa-agy/plugin.json +1 -1
  10. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  11. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  12. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  13. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  14. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  15. package/plugins/lisa-copilot/.claude-plugin/plugin.json +10 -1
  16. package/plugins/lisa-copilot/hooks/threshold-ratchet-compare.mjs +315 -0
  17. package/plugins/lisa-copilot/hooks/threshold-ratchet-families.mjs +295 -0
  18. package/plugins/lisa-copilot/hooks/threshold-ratchet.mjs +213 -0
  19. package/plugins/lisa-copilot/hooks/threshold-ratchet.sh +22 -0
  20. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-cursor/hooks/hooks.json +4 -0
  22. package/plugins/lisa-cursor/hooks/threshold-ratchet-compare.mjs +315 -0
  23. package/plugins/lisa-cursor/hooks/threshold-ratchet-families.mjs +295 -0
  24. package/plugins/lisa-cursor/hooks/threshold-ratchet.mjs +213 -0
  25. package/plugins/lisa-cursor/hooks/threshold-ratchet.sh +22 -0
  26. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  28. package/plugins/lisa-expo-agy/plugin.json +1 -1
  29. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  31. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  32. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  33. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  34. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  35. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  38. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  39. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  43. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  44. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  48. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  49. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  50. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  53. package/plugins/lisa-rails-agy/plugin.json +1 -1
  54. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  58. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  59. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  63. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  64. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  66. package/plugins/src/base/.claude-plugin/plugin.json +9 -0
  67. package/plugins/src/base/hooks/threshold-ratchet-compare.mjs +315 -0
  68. package/plugins/src/base/hooks/threshold-ratchet-families.mjs +295 -0
  69. package/plugins/src/base/hooks/threshold-ratchet.mjs +213 -0
  70. package/plugins/src/base/hooks/threshold-ratchet.sh +22 -0
  71. package/rails/copy-overwrite/lefthook.yml +6 -0
  72. package/rails/copy-overwrite/scripts/check-threshold-ratchet.mjs +213 -0
  73. package/rails/copy-overwrite/scripts/threshold-ratchet-compare.mjs +315 -0
  74. package/rails/copy-overwrite/scripts/threshold-ratchet-families.mjs +295 -0
  75. package/scripts/build-plugins.sh +20 -0
  76. package/scripts/lib/per-agent-hook-filter.mjs +7 -0
  77. package/typescript/copy-contents/.husky/pre-commit +17 -0
  78. package/typescript/copy-overwrite/scripts/check-threshold-ratchet.mjs +213 -0
  79. package/typescript/copy-overwrite/scripts/threshold-ratchet-compare.mjs +315 -0
  80. package/typescript/copy-overwrite/scripts/threshold-ratchet-families.mjs +295 -0
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Threshold ratchet — watched file families and value extractors.
3
+ *
4
+ * Pure extraction layer: given file contents, produce comparable constraint
5
+ * maps. No filesystem or git access. See threshold-ratchet.mjs for the CLI
6
+ * and threshold-ratchet-compare.mjs for the comparison rules.
7
+ */
8
+
9
+ /**
10
+ * File families the ratchet watches. `kind` selects the extractor;
11
+ * `direction` applies to numeric-leaf kinds ("min" values may only rise,
12
+ * "max" values may only fall).
13
+ */
14
+ export const FAMILIES = [
15
+ {
16
+ id: "coverage",
17
+ match: /(^|\/)(vitest|jest)\.thresholds\.json$/,
18
+ kind: "json-num",
19
+ direction: "min",
20
+ },
21
+ {
22
+ id: "simplecov",
23
+ match: /(^|\/)simplecov\.thresholds\.json$/,
24
+ kind: "json-num",
25
+ direction: "min",
26
+ },
27
+ {
28
+ id: "e2e",
29
+ match: /(^|\/)e2e\.thresholds\.json$/,
30
+ kind: "json-num",
31
+ direction: "min",
32
+ },
33
+ {
34
+ id: "eslint",
35
+ match: /(^|\/)eslint\.thresholds\.json$/,
36
+ kind: "json-num",
37
+ direction: "max",
38
+ },
39
+ {
40
+ id: "rubocop",
41
+ match: /(^|\/)rubocop\.thresholds\.yml$/,
42
+ kind: "rubocop-yaml",
43
+ direction: "max",
44
+ },
45
+ { id: "stryker", match: /(^|\/)stryker\.conf\.json$/, kind: "stryker" },
46
+ {
47
+ id: "k6",
48
+ match: /(^|\/)\.github\/k6\/thresholds\/[^/]+\.json$/,
49
+ kind: "k6",
50
+ },
51
+ {
52
+ id: "audit-ignore",
53
+ match: /(^|\/)audit\.ignore\.(config|local)\.json$/,
54
+ kind: "exemption-list",
55
+ },
56
+ {
57
+ id: "lisa-config",
58
+ match: /(^|\/)\.lisa\.config\.json$/,
59
+ kind: "allow-list",
60
+ },
61
+ ];
62
+
63
+ /**
64
+ * Find the family a repo-relative path belongs to.
65
+ * @param {string} relPath Repo-relative path (forward slashes)
66
+ * @returns {(typeof FAMILIES)[number] | undefined} The matching family, or
67
+ * undefined when the path is not a watched gate file
68
+ */
69
+ export function familyFor(relPath) {
70
+ return FAMILIES.find(f => f.match.test(relPath));
71
+ }
72
+
73
+ /**
74
+ * Safe JSON parse.
75
+ * @param {string | null | undefined} text JSON text
76
+ * @returns {unknown | undefined} Parsed value, or undefined on failure
77
+ */
78
+ export function parseJson(text) {
79
+ if (typeof text !== "string") return undefined;
80
+ try {
81
+ return JSON.parse(text);
82
+ } catch {
83
+ return undefined;
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Walk a JSON object and collect numeric leaves as dotted-path constraints.
89
+ * Keys starting with "_" (e.g. `_comment`) are documentation, not thresholds.
90
+ * @param {unknown} node Parsed JSON value
91
+ * @param {"min"|"max"} direction Ratchet direction for every leaf
92
+ * @param {string} [prefix] Dotted path accumulated so far
93
+ * @returns {Map<string, { value: number, direction: "min"|"max" }>} Dotted
94
+ * path → numeric constraint for every finite numeric leaf
95
+ */
96
+ export function extractNumericLeaves(node, direction, prefix = "") {
97
+ const out = new Map();
98
+ if (node === null || typeof node !== "object" || Array.isArray(node)) {
99
+ return out;
100
+ }
101
+ for (const [key, value] of Object.entries(node)) {
102
+ if (key.startsWith("_")) continue;
103
+ const p = prefix ? `${prefix}.${key}` : key;
104
+ if (typeof value === "number" && Number.isFinite(value)) {
105
+ out.set(p, { value, direction });
106
+ } else if (value && typeof value === "object" && !Array.isArray(value)) {
107
+ for (const [cp, c] of extractNumericLeaves(value, direction, p)) {
108
+ out.set(cp, c);
109
+ }
110
+ }
111
+ }
112
+ return out;
113
+ }
114
+
115
+ /**
116
+ * Minimal parser for rubocop.thresholds.yml — a two-level document of
117
+ * `Section:` headers with indented `Key: <number>` scalars (comments and
118
+ * blank lines ignored). Deliberately NOT a general YAML parser: the file is
119
+ * Lisa-authored with this exact shape, and hand-parsing keeps the gate
120
+ * dependency-free with no backtracking-prone regexes.
121
+ * @param {string} text File contents
122
+ * @param {"min"|"max"} direction Ratchet direction for every scalar
123
+ * @returns {Map<string, { value: number, direction: "min"|"max" }>} Dotted
124
+ * `Section.Key` path → numeric constraint
125
+ */
126
+ export function extractRubocopThresholds(text, direction) {
127
+ const out = new Map();
128
+ const state = { section: "" };
129
+ for (const rawLine of text.split("\n")) {
130
+ const hash = rawLine.indexOf("#");
131
+ const line = (hash >= 0 ? rawLine.slice(0, hash) : rawLine).trimEnd();
132
+ if (!line.trim()) continue;
133
+ const indented = line.startsWith(" ") || line.startsWith("\t");
134
+ if (!indented && line.endsWith(":")) {
135
+ state.section = line.slice(0, -1).trim();
136
+ continue;
137
+ }
138
+ const colon = line.indexOf(":");
139
+ if (!indented || colon < 0 || !state.section) continue;
140
+ const key = line.slice(0, colon).trim();
141
+ const rawValue = line.slice(colon + 1).trim();
142
+ // Number("") is 0, so an empty value (e.g. a nested `Exclude:` list
143
+ // header) must be skipped, not recorded as a zero threshold.
144
+ const value = Number(rawValue);
145
+ if (key && rawValue !== "" && Number.isFinite(value)) {
146
+ out.set(`${state.section}.${key}`, { value, direction });
147
+ }
148
+ }
149
+ return out;
150
+ }
151
+
152
+ /**
153
+ * Extract the gating constraint from stryker.conf.json: only
154
+ * `thresholds.break` fails a run (`high`/`low` are reporting bands).
155
+ * @param {unknown} conf Parsed stryker.conf.json
156
+ * @returns {Map<string, { value: number, direction: "min"|"max" }>} The
157
+ * `thresholds.break` constraint when present, otherwise an empty map
158
+ */
159
+ export function extractStrykerConstraints(conf) {
160
+ const out = new Map();
161
+ const breakValue = conf?.thresholds?.break;
162
+ if (typeof breakValue === "number" && Number.isFinite(breakValue)) {
163
+ out.set("thresholds.break", { value: breakValue, direction: "min" });
164
+ }
165
+ return out;
166
+ }
167
+
168
+ /**
169
+ * Split a stryker `mutate` array into positive globs and negations.
170
+ * @param {unknown} conf Parsed stryker.conf.json
171
+ * @returns {{ positives: Set<string>, negations: Set<string> }} Globs that
172
+ * include files vs. `!`-prefixed globs that exclude them
173
+ */
174
+ export function extractStrykerMutate(conf) {
175
+ const positives = new Set();
176
+ const negations = new Set();
177
+ const mutate = Array.isArray(conf?.mutate) ? conf.mutate : [];
178
+ for (const glob of mutate) {
179
+ if (typeof glob !== "string") continue;
180
+ if (glob.startsWith("!")) negations.add(glob);
181
+ else positives.add(glob);
182
+ }
183
+ return { positives, negations };
184
+ }
185
+
186
+ /**
187
+ * Parse one k6 threshold expression (`p(95)<1000`, `rate>=0.99`, …) into a
188
+ * ratchet constraint. Upper bounds (`<`, `<=`) may only decrease; lower
189
+ * bounds (`>`, `>=`) may only increase. Hand-parsed — no regex.
190
+ * @param {string} expr Threshold expression
191
+ * @returns {{ value: number, direction: "min"|"max" } | undefined} The bound
192
+ * as a constraint, or undefined when the expression has no numeric bound
193
+ */
194
+ export function parseK6Expression(expr) {
195
+ for (const op of ["<=", ">=", "<", ">"]) {
196
+ const idx = expr.indexOf(op);
197
+ if (idx < 0) continue;
198
+ const value = Number(expr.slice(idx + op.length).trim());
199
+ if (!Number.isFinite(value)) return undefined;
200
+ return { value, direction: op.startsWith("<") ? "max" : "min" };
201
+ }
202
+ return undefined;
203
+ }
204
+
205
+ /**
206
+ * Extract constraints from a k6 thresholds file. Each metric contributes its
207
+ * expression bound(s) plus (when present) `abortOnFail` boolean constraints —
208
+ * turning abortOnFail off makes the gate advisory, which is a weakening.
209
+ * Handles every documented k6 shape: a bare expression string, a single long
210
+ * form `{ threshold, abortOnFail }` object, and arrays mixing both.
211
+ * @param {unknown} conf Parsed k6 thresholds JSON
212
+ * @returns {{
213
+ * numeric: Map<string, { value: number, direction: "min"|"max" }>,
214
+ * booleans: Map<string, boolean>,
215
+ * }} Numeric bounds keyed by `<metric>.threshold[i]` and abortOnFail flags
216
+ * keyed by `<metric>.abortOnFail` (`[i]`-suffixed for array items)
217
+ */
218
+ export function extractK6Constraints(conf) {
219
+ const numeric = new Map();
220
+ const booleans = new Map();
221
+ const thresholds = conf?.thresholds;
222
+ if (thresholds && typeof thresholds === "object") {
223
+ for (const [metric, spec] of Object.entries(thresholds)) {
224
+ const isArray = Array.isArray(spec);
225
+ const items = isArray ? spec : [spec];
226
+ items.forEach((item, i) => {
227
+ const expr =
228
+ typeof item === "string"
229
+ ? item
230
+ : item && typeof item === "object" && !Array.isArray(item)
231
+ ? item.threshold
232
+ : undefined;
233
+ if (typeof expr === "string") {
234
+ const c = parseK6Expression(expr);
235
+ if (c) numeric.set(`${metric}.threshold[${i}]`, c);
236
+ }
237
+ if (
238
+ item &&
239
+ typeof item === "object" &&
240
+ !Array.isArray(item) &&
241
+ typeof item.abortOnFail === "boolean"
242
+ ) {
243
+ booleans.set(
244
+ isArray ? `${metric}.abortOnFail[${i}]` : `${metric}.abortOnFail`,
245
+ item.abortOnFail
246
+ );
247
+ }
248
+ });
249
+ }
250
+ }
251
+ return { numeric, booleans };
252
+ }
253
+
254
+ /**
255
+ * Flatten an exemption file (audit ignore list) into a set of entry tokens.
256
+ * Arrays contribute their string items; objects contribute their keys.
257
+ * @param {unknown} conf Parsed JSON
258
+ * @returns {Set<string>} One token per exemption entry
259
+ */
260
+ export function extractExemptionEntries(conf) {
261
+ const out = new Set();
262
+ if (Array.isArray(conf)) {
263
+ for (const item of conf) {
264
+ if (typeof item === "string") out.add(item);
265
+ else if (item && typeof item === "object") out.add(JSON.stringify(item));
266
+ }
267
+ } else if (conf && typeof conf === "object") {
268
+ for (const [key, value] of Object.entries(conf)) {
269
+ if (Array.isArray(value)) {
270
+ for (const item of value) {
271
+ out.add(
272
+ `${key}:${typeof item === "string" ? item : JSON.stringify(item)}`
273
+ );
274
+ }
275
+ } else {
276
+ out.add(key);
277
+ }
278
+ }
279
+ }
280
+ return out;
281
+ }
282
+
283
+ /**
284
+ * Extract thresholdRatchet.allow entries from parsed .lisa.config.json.
285
+ * @param {unknown} config Parsed config (may be undefined)
286
+ * @returns {Array<{ file: string, key: string, reason?: string }>} The
287
+ * well-formed allow entries; malformed entries are dropped
288
+ */
289
+ export function extractAllowEntries(config) {
290
+ const raw = config?.thresholdRatchet?.allow;
291
+ if (!Array.isArray(raw)) return [];
292
+ return raw.filter(
293
+ e => e && typeof e.file === "string" && typeof e.key === "string"
294
+ );
295
+ }