@wrongstack/plugins 0.295.0 → 0.296.2

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 (110) hide show
  1. package/dist/accessibility-auditor/index.d.ts.map +1 -1
  2. package/dist/accessibility-auditor.js +31 -3
  3. package/dist/agent-handoff/index.d.ts.map +1 -1
  4. package/dist/agent-handoff.js +30 -1
  5. package/dist/auto-doc/index.d.ts.map +1 -1
  6. package/dist/auto-doc.js +3 -1
  7. package/dist/auto-i18n-extractor.js +5 -0
  8. package/dist/branch-guard/index.d.ts.map +1 -1
  9. package/dist/branch-guard.js +116 -3
  10. package/dist/changelog-writer/index.d.ts.map +1 -1
  11. package/dist/changelog-writer.js +137 -3
  12. package/dist/checkpoint/index.d.ts +2 -0
  13. package/dist/checkpoint/index.d.ts.map +1 -1
  14. package/dist/checkpoint.js +34 -8
  15. package/dist/code-metrics.js +5 -0
  16. package/dist/commit-validator/index.d.ts.map +1 -1
  17. package/dist/commit-validator.js +35 -8
  18. package/dist/context-pins/index.d.ts.map +1 -1
  19. package/dist/context-pins.js +6 -5
  20. package/dist/cost-tracker/index.d.ts.map +1 -1
  21. package/dist/cost-tracker.js +101 -1
  22. package/dist/cron/index.d.ts.map +1 -1
  23. package/dist/cron.js +1 -0
  24. package/dist/dead-code-detector/index.d.ts.map +1 -1
  25. package/dist/dead-code-detector.js +9 -1
  26. package/dist/dependency-vulnerability-gate/index.d.ts.map +1 -1
  27. package/dist/dependency-vulnerability-gate.js +43 -8
  28. package/dist/diff-summary/index.d.ts.map +1 -1
  29. package/dist/diff-summary.js +112 -2
  30. package/dist/doc-sync-guard.js +17 -1
  31. package/dist/duplicate-code-detector/index.d.ts.map +1 -1
  32. package/dist/duplicate-code-detector.js +102 -2
  33. package/dist/feature-flag-tracker/index.d.ts.map +1 -1
  34. package/dist/feature-flag-tracker.js +30 -4
  35. package/dist/file-watcher/index.d.ts.map +1 -1
  36. package/dist/file-watcher.js +6 -7
  37. package/dist/format-on-save/index.d.ts +2 -0
  38. package/dist/format-on-save/index.d.ts.map +1 -1
  39. package/dist/format-on-save.js +288 -59
  40. package/dist/git-autocommit/index.d.ts +12 -0
  41. package/dist/git-autocommit/index.d.ts.map +1 -1
  42. package/dist/git-autocommit.js +58 -4
  43. package/dist/import-organizer/index.d.ts.map +1 -1
  44. package/dist/import-organizer.js +152 -21
  45. package/dist/index.js +1413 -590
  46. package/dist/injection-shield/index.d.ts +16 -0
  47. package/dist/injection-shield/index.d.ts.map +1 -1
  48. package/dist/injection-shield.js +12 -4
  49. package/dist/interface-contract-guard/index.d.ts.map +1 -1
  50. package/dist/interface-contract-guard.js +60 -26
  51. package/dist/knowledge-graph/index.d.ts.map +1 -1
  52. package/dist/knowledge-graph.js +7 -6
  53. package/dist/lint-gate/index.d.ts.map +1 -1
  54. package/dist/lint-gate.js +115 -2
  55. package/dist/loop-breaker/index.d.ts.map +1 -1
  56. package/dist/loop-breaker.js +15 -5
  57. package/dist/migration-planner.js +15 -1
  58. package/dist/notify-hub/index.d.ts.map +1 -1
  59. package/dist/notify-hub.js +41 -4
  60. package/dist/pr-drafter/index.d.ts.map +1 -1
  61. package/dist/pr-drafter.js +20 -1
  62. package/dist/prompt-firewall/index.d.ts.map +1 -1
  63. package/dist/prompt-firewall.js +140 -11
  64. package/dist/refactor-suggester/index.d.ts.map +1 -1
  65. package/dist/refactor-suggester.js +119 -4
  66. package/dist/runtime/bounded-map.d.ts +86 -0
  67. package/dist/runtime/bounded-map.d.ts.map +1 -0
  68. package/dist/runtime/credential-patterns.d.ts +42 -0
  69. package/dist/runtime/credential-patterns.d.ts.map +1 -0
  70. package/dist/runtime/handles.d.ts +46 -0
  71. package/dist/runtime/handles.d.ts.map +1 -0
  72. package/dist/runtime/index.d.ts +4 -0
  73. package/dist/runtime/index.d.ts.map +1 -1
  74. package/dist/runtime/local-bin.d.ts +120 -0
  75. package/dist/runtime/local-bin.d.ts.map +1 -0
  76. package/dist/runtime/safe-json.d.ts +25 -0
  77. package/dist/runtime/safe-json.d.ts.map +1 -0
  78. package/dist/runtime.js +309 -22
  79. package/dist/schema-evolution-guard.js +5 -0
  80. package/dist/secret-scanner/index.d.ts.map +1 -1
  81. package/dist/secret-scanner.js +194 -50
  82. package/dist/security-hotspot-scanner/index.d.ts.map +1 -1
  83. package/dist/security-hotspot-scanner.js +132 -1
  84. package/dist/semantic-search-indexer/index.d.ts.map +1 -1
  85. package/dist/semantic-search-indexer.js +7 -1
  86. package/dist/semver-bump/index.d.ts.map +1 -1
  87. package/dist/semver-bump.js +21 -2
  88. package/dist/session-recap/index.d.ts.map +1 -1
  89. package/dist/session-recap.js +18 -1
  90. package/dist/smart-rename/index.d.ts +2 -0
  91. package/dist/smart-rename/index.d.ts.map +1 -1
  92. package/dist/smart-rename.js +16 -2
  93. package/dist/spec-linker/index.d.ts.map +1 -1
  94. package/dist/spec-linker.js +19 -2
  95. package/dist/template-engine/index.d.ts.map +1 -1
  96. package/dist/template-engine.js +45 -3
  97. package/dist/test-coverage-gate.js +17 -1
  98. package/dist/test-runner-gate/index.d.ts.map +1 -1
  99. package/dist/test-runner-gate.js +142 -9
  100. package/dist/todo-listener/index.d.ts.map +1 -1
  101. package/dist/todo-listener.js +42 -2
  102. package/dist/todo-tracker/index.d.ts.map +1 -1
  103. package/dist/todo-tracker.js +3 -4
  104. package/dist/token-budget/index.d.ts.map +1 -1
  105. package/dist/token-budget.js +31 -19
  106. package/dist/token-throttle/index.d.ts.map +1 -1
  107. package/dist/token-throttle.js +17 -2
  108. package/dist/type-gate/index.d.ts.map +1 -1
  109. package/dist/type-gate.js +108 -17
  110. package/package.json +3 -3
@@ -4,6 +4,11 @@ import { isAbsolute as isAbsolute2, relative as relative2, resolve as resolve2 }
4
4
 
5
5
  // src/runtime/index.ts
6
6
  import { basename, extname, isAbsolute, relative, resolve } from "node:path";
7
+
8
+ // src/runtime/local-bin.ts
9
+ import { buildWin32CmdShimInvocation, resolveWin32Command } from "@wrongstack/tools/win32";
10
+
11
+ // src/runtime/index.ts
7
12
  var MAX_BUFFER_BYTES = 16 * 1024 * 1024;
8
13
  function hasLeadingDash(arg) {
9
14
  return arg.length > 0 && arg.startsWith("-");
@@ -103,8 +108,14 @@ function relativePath(p) {
103
108
  return toPosix(relative2(process.cwd(), p));
104
109
  }
105
110
  function compilePatterns(patterns) {
106
- const sources = [...DEFAULT_PATTERNS, ...patterns];
107
- return sources.map((src) => new RegExp(src, "g"));
111
+ const out = [];
112
+ for (const src of [...DEFAULT_PATTERNS, ...patterns]) {
113
+ try {
114
+ out.push(new RegExp(src, "g"));
115
+ } catch {
116
+ }
117
+ }
118
+ return out;
108
119
  }
109
120
  function scanFile(filePath, content, patterns, maxFindings) {
110
121
  const usages = [];
@@ -135,15 +146,26 @@ async function scanPath(rawPath, cfg) {
135
146
  const files = await collectSourceFilesAsync(resolved, { extensions: exts });
136
147
  const patterns = compilePatterns(cfg.patterns);
137
148
  const usages = [];
149
+ let scannedFiles = 0;
150
+ let truncated = false;
138
151
  for (const p of files) {
139
152
  try {
140
153
  const content = await readFile(p, "utf-8");
154
+ scannedFiles += 1;
141
155
  usages.push(...scanFile(p, content, patterns, cfg.maxFindings));
142
- if (usages.length >= cfg.maxFindings) break;
156
+ if (usages.length >= cfg.maxFindings) {
157
+ truncated = scannedFiles < files.length;
158
+ break;
159
+ }
143
160
  } catch {
144
161
  }
145
162
  }
146
- return { usages: usages.slice(0, cfg.maxFindings), scannedFiles: files.length };
163
+ return {
164
+ usages: usages.slice(0, cfg.maxFindings),
165
+ scannedFiles,
166
+ discoveredFiles: files.length,
167
+ truncated
168
+ };
147
169
  }
148
170
  var plugin = {
149
171
  name: "feature-flag-tracker",
@@ -252,6 +274,10 @@ Make sure flag behavior is intentional and consider updating flag inventory/docs
252
274
  ok: true,
253
275
  path: relativePath(resolve2(process.cwd(), rawPath)),
254
276
  scannedFiles: result.scannedFiles,
277
+ discoveredFiles: result.discoveredFiles,
278
+ // Say so when the cap stopped the walk early: a partial scan
279
+ // that reports few findings must not read as a clean result.
280
+ truncated: result.truncated,
255
281
  usages: result.usages
256
282
  };
257
283
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file-watcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAqErD,QAAA,MAAM,MAAM,EAAE,MA8Yb,CAAC;eAEa,MAAM"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file-watcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAqErD,QAAA,MAAM,MAAM,EAAE,MA+Yb,CAAC;eAEa,MAAM"}
@@ -80,13 +80,12 @@ var plugin = {
80
80
  function debounceEvent(key, fn, ms) {
81
81
  const existing = debounceTimers.get(key);
82
82
  if (existing) clearTimeout(existing);
83
- debounceTimers.set(
84
- key,
85
- setTimeout(() => {
86
- debounceTimers.delete(key);
87
- fn();
88
- }, ms)
89
- );
83
+ const timer = setTimeout(() => {
84
+ debounceTimers.delete(key);
85
+ fn();
86
+ }, ms);
87
+ timer.unref?.();
88
+ debounceTimers.set(key, timer);
90
89
  }
91
90
  const autoIndex = api.config.extensions?.["file-watcher"]?.["autoIndex"] ?? false;
92
91
  const indexProjectRoot = api.config.extensions?.["file-watcher"]?.["indexProjectRoot"] ?? "";
@@ -28,6 +28,8 @@
28
28
  * @public
29
29
  */
30
30
  import type { Plugin } from '@wrongstack/core/types';
31
+ /** Which formatter is currently in use — surfaced by health()/status. */
32
+ export declare function activeFormatterLabel(): string | null;
31
33
  declare const plugin: Plugin;
32
34
  export default plugin;
33
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/format-on-save/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AA0PrD,QAAA,MAAM,MAAM,EAAE,MAuPb,CAAC;eAEa,MAAM"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/format-on-save/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAmPrD,yEAAyE;AACzE,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,IAAI,CAEpD;AAsGD,QAAA,MAAM,MAAM,EAAE,MAsPb,CAAC;eAEa,MAAM"}
@@ -1,9 +1,200 @@
1
1
  // src/format-on-save/index.ts
2
2
  import { execFile } from "node:child_process";
3
- import { access, stat } from "node:fs/promises";
3
+ import { createHash } from "node:crypto";
4
+ import { access, readFile, stat } from "node:fs/promises";
5
+
6
+ // src/runtime/index.ts
7
+ import { basename, extname as extname2, isAbsolute as isAbsolute2, relative as relative2, resolve as resolve2 } from "node:path";
8
+
9
+ // src/runtime/local-bin.ts
10
+ import { createRequire } from "node:module";
11
+ import { delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
12
+ import { accessSync, constants, readFileSync } from "node:fs";
13
+ import { buildWin32CmdShimInvocation, resolveWin32Command } from "@wrongstack/tools/win32";
14
+ function resolveExecInvocation(command, args = []) {
15
+ const resolved = resolveWin32Command(command);
16
+ const normalizedResolved = resolved.toLowerCase();
17
+ const needsShell = process.platform === "win32" && (normalizedResolved.endsWith(".cmd") || normalizedResolved.endsWith(".bat"));
18
+ if (needsShell) {
19
+ const shim = buildWin32CmdShimInvocation(resolved, args);
20
+ return { cmd: shim.command, args: shim.args, windowsVerbatimArguments: true };
21
+ }
22
+ return { cmd: resolved, args: [...args], windowsVerbatimArguments: false };
23
+ }
24
+ function findOnPath(cmd) {
25
+ if (!cmd) return null;
26
+ const exists = (p) => {
27
+ try {
28
+ accessSync(p, constants.X_OK);
29
+ return true;
30
+ } catch {
31
+ return false;
32
+ }
33
+ };
34
+ if (cmd.includes("/") || cmd.includes("\\")) {
35
+ return exists(cmd) ? resolve(cmd) : null;
36
+ }
37
+ const suffixes = process.platform === "win32" && extname(cmd) === "" ? (process.env["PATHEXT"] ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
38
+ for (const dir of (process.env["PATH"] ?? "").split(delimiter)) {
39
+ if (!dir) continue;
40
+ const base = join(dir, cmd);
41
+ for (const suffix of suffixes) {
42
+ const candidate = `${base}${suffix}`;
43
+ if (exists(candidate)) return candidate;
44
+ }
45
+ }
46
+ return null;
47
+ }
48
+ function isInside(parent, candidate) {
49
+ const rel = relative(parent, candidate);
50
+ return rel === "" || !rel.startsWith(`..${sep}`) && rel !== ".." && !isAbsolute(rel);
51
+ }
52
+ var binCache = /* @__PURE__ */ new Map();
53
+ var BIN_CACHE_MAX = 64;
54
+ var NEGATIVE_BIN_CACHE_TTL_MS = 5e3;
55
+ function cachePut(key, value) {
56
+ while (binCache.size >= BIN_CACHE_MAX) {
57
+ const oldest = binCache.keys().next().value;
58
+ if (oldest === void 0) break;
59
+ binCache.delete(oldest);
60
+ }
61
+ binCache.set(key, { value, cachedAt: Date.now() });
62
+ return value;
63
+ }
64
+ function clearLocalBinCache() {
65
+ binCache.clear();
66
+ }
67
+ function resolveNodeBin(packageName, binName, cwd, extraArgs = []) {
68
+ const key = `${packageName}|${binName}|${cwd}`;
69
+ const cached = binCache.get(key);
70
+ if (cached !== void 0) {
71
+ if (cached.value !== null || Date.now() - cached.cachedAt < NEGATIVE_BIN_CACHE_TTL_MS) {
72
+ return cached.value === null ? null : { ...cached.value, args: [cached.value.entry, ...extraArgs] };
73
+ }
74
+ binCache.delete(key);
75
+ }
76
+ let resolved = null;
77
+ try {
78
+ const requireFromProject = createRequire(resolve(cwd, "package.json"));
79
+ const packagePath = requireFromProject.resolve(`${packageName}/package.json`);
80
+ const packageJson = JSON.parse(readFileSync(packagePath, "utf-8"));
81
+ const relativeBin = typeof packageJson.bin === "string" ? packageJson.bin : packageJson.bin?.[binName] ?? Object.values(packageJson.bin ?? {})[0];
82
+ if (relativeBin && !isAbsolute(relativeBin)) {
83
+ const packageDir = dirname(packagePath);
84
+ const entry = resolve(packageDir, relativeBin);
85
+ if (isInside(packageDir, entry)) {
86
+ resolved = { cmd: process.execPath, args: [entry], entry };
87
+ }
88
+ }
89
+ } catch {
90
+ resolved = null;
91
+ }
92
+ cachePut(key, resolved);
93
+ return resolved === null ? null : { ...resolved, args: [resolved.entry, ...extraArgs] };
94
+ }
95
+ function resolveFirstNodeBin(candidates, cwd) {
96
+ for (const c of candidates) {
97
+ const hit = resolveNodeBin(c.packageName, c.binName, cwd, c.args ?? []);
98
+ if (hit) return { ...hit, packageName: c.packageName, binName: c.binName };
99
+ }
100
+ return null;
101
+ }
102
+
103
+ // src/runtime/bounded-map.ts
104
+ var BoundedMap = class {
105
+ map = /* @__PURE__ */ new Map();
106
+ max;
107
+ ttlMs;
108
+ now;
109
+ /** Entries dropped to stay under `max`. Surfaced by plugin health(). */
110
+ evictions = 0;
111
+ constructor(options) {
112
+ const normalizedMax = Math.floor(options.max);
113
+ this.max = Number.isSafeInteger(normalizedMax) ? Math.max(1, normalizedMax) : 1;
114
+ this.ttlMs = options.ttlMs;
115
+ this.now = options.now ?? Date.now;
116
+ }
117
+ expired(entry) {
118
+ return this.ttlMs !== void 0 && this.now() - entry.storedAt > this.ttlMs;
119
+ }
120
+ get(key) {
121
+ const entry = this.map.get(key);
122
+ if (entry === void 0) return void 0;
123
+ if (this.expired(entry)) {
124
+ this.map.delete(key);
125
+ return void 0;
126
+ }
127
+ this.map.delete(key);
128
+ this.map.set(key, entry);
129
+ return entry.value;
130
+ }
131
+ /**
132
+ * Read without promoting the key to most-recently-used. Use for
133
+ * diagnostics that must not perturb the eviction order.
134
+ */
135
+ peek(key) {
136
+ const entry = this.map.get(key);
137
+ if (entry === void 0 || this.expired(entry)) return void 0;
138
+ return entry.value;
139
+ }
140
+ has(key) {
141
+ const entry = this.map.get(key);
142
+ if (entry === void 0) return false;
143
+ if (this.expired(entry)) {
144
+ this.map.delete(key);
145
+ return false;
146
+ }
147
+ return true;
148
+ }
149
+ set(key, value) {
150
+ this.map.delete(key);
151
+ this.map.set(key, { value, storedAt: this.now() });
152
+ while (this.map.size > this.max) {
153
+ const coldest = this.map.keys().next().value;
154
+ if (coldest === void 0) break;
155
+ this.map.delete(coldest);
156
+ this.evictions += 1;
157
+ }
158
+ return this;
159
+ }
160
+ delete(key) {
161
+ return this.map.delete(key);
162
+ }
163
+ clear() {
164
+ this.map.clear();
165
+ this.evictions = 0;
166
+ }
167
+ get size() {
168
+ return this.map.size;
169
+ }
170
+ /** How many entries have been dropped to respect `max`, since the last clear. */
171
+ get evictionCount() {
172
+ return this.evictions;
173
+ }
174
+ /** Drop every expired entry. Cheap enough to call from a status tool. */
175
+ prune() {
176
+ if (this.ttlMs === void 0) return 0;
177
+ let removed = 0;
178
+ for (const [key, entry] of this.map) {
179
+ if (this.expired(entry)) {
180
+ this.map.delete(key);
181
+ removed += 1;
182
+ }
183
+ }
184
+ return removed;
185
+ }
186
+ /** Live (non-expired) entries, coldest first. */
187
+ *entries() {
188
+ for (const [key, entry] of this.map) {
189
+ if (!this.expired(entry)) yield [key, entry.value];
190
+ }
191
+ }
192
+ [Symbol.iterator]() {
193
+ return this.entries();
194
+ }
195
+ };
4
196
 
5
197
  // src/runtime/index.ts
6
- import { basename, extname, isAbsolute, relative, resolve } from "node:path";
7
198
  var MAX_BUFFER_BYTES = 16 * 1024 * 1024;
8
199
  function hasLeadingDash(arg) {
9
200
  return arg.length > 0 && arg.startsWith("-");
@@ -11,13 +202,13 @@ function hasLeadingDash(arg) {
11
202
  function withinProjectPath(projectRoot, candidate) {
12
203
  if (candidate.length === 0 || candidate.length > 4096) return false;
13
204
  if (hasLeadingDash(candidate)) return false;
14
- const resolved = isAbsolute(candidate) ? resolve(candidate) : resolve(projectRoot, candidate);
15
- const rel = relative(projectRoot, resolved);
16
- return rel === "" || !rel.startsWith("..") && !isAbsolute(rel);
205
+ const resolved = isAbsolute2(candidate) ? resolve2(candidate) : resolve2(projectRoot, candidate);
206
+ const rel = relative2(projectRoot, resolved);
207
+ return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
17
208
  }
18
209
  function withinProject(p) {
19
210
  const cwd = process.cwd();
20
- return withinProjectPath(cwd, p) || relative(cwd, p) === ".";
211
+ return withinProjectPath(cwd, p) || relative2(cwd, p) === ".";
21
212
  }
22
213
 
23
214
  // src/format-on-save/index.ts
@@ -56,7 +247,7 @@ function readConfig(raw) {
56
247
  skipTtlMs: typeof r["skipTtlMs"] === "number" && r["skipTtlMs"] >= 0 ? r["skipTtlMs"] : DEFAULTS.skipTtlMs
57
248
  };
58
249
  }
59
- var recentlyCovered = /* @__PURE__ */ new Map();
250
+ var recentlyCovered = new BoundedMap({ max: 256 });
60
251
  function clearRegistrations() {
61
252
  if (state.hookUnregister) {
62
253
  try {
@@ -79,6 +270,55 @@ function evictExpired(ttlMs) {
79
270
  if (ts < cutoff) recentlyCovered.delete(path);
80
271
  }
81
272
  }
273
+ var FORMATTERS = [
274
+ {
275
+ packageName: "@biomejs/biome",
276
+ binName: "biome",
277
+ writeArgs: ["format", "--write"],
278
+ label: "biome"
279
+ },
280
+ { packageName: "prettier", binName: "prettier", writeArgs: ["--write"], label: "prettier" },
281
+ { packageName: "dprint", binName: "dprint", writeArgs: ["fmt"], label: "dprint" }
282
+ ];
283
+ var activeFormatter;
284
+ function resetFormatter() {
285
+ activeFormatter = void 0;
286
+ clearLocalBinCache();
287
+ }
288
+ function resolveFormatter() {
289
+ if (activeFormatter !== void 0) return activeFormatter;
290
+ const cwd = process.cwd();
291
+ for (const f of FORMATTERS) {
292
+ const local = resolveNodeBinFor(f, cwd);
293
+ if (local) {
294
+ activeFormatter = local;
295
+ return local;
296
+ }
297
+ }
298
+ for (const f of FORMATTERS) {
299
+ const onPath = findOnPath(f.binName);
300
+ if (!onPath) continue;
301
+ activeFormatter = { cmd: onPath, args: [...f.writeArgs], label: f.label };
302
+ return activeFormatter;
303
+ }
304
+ activeFormatter = null;
305
+ return null;
306
+ }
307
+ function resolveNodeBinFor(f, cwd) {
308
+ const hit = resolveFirstNodeBin([{ packageName: f.packageName, binName: f.binName }], cwd);
309
+ if (!hit) return null;
310
+ return { cmd: hit.cmd, args: [...hit.args, ...f.writeArgs], label: f.label };
311
+ }
312
+ function activeFormatterLabel() {
313
+ return activeFormatter?.label ?? null;
314
+ }
315
+ async function sha256File(filePath) {
316
+ try {
317
+ return createHash("sha256").update(await readFile(filePath)).digest("hex");
318
+ } catch {
319
+ return null;
320
+ }
321
+ }
82
322
  async function formatFile(filePath, timeoutMs) {
83
323
  if (!withinProject(filePath)) return null;
84
324
  try {
@@ -86,30 +326,40 @@ async function formatFile(filePath, timeoutMs) {
86
326
  } catch {
87
327
  return null;
88
328
  }
329
+ const formatter = resolveFormatter();
330
+ if (!formatter) return null;
89
331
  let bytesBefore;
90
332
  try {
91
333
  bytesBefore = (await stat(filePath)).size;
92
334
  } catch {
93
335
  return null;
94
336
  }
337
+ const hashBefore = await sha256File(filePath);
338
+ let invocation;
339
+ try {
340
+ invocation = resolveExecInvocation(formatter.cmd, [...formatter.args, filePath]);
341
+ } catch {
342
+ return null;
343
+ }
95
344
  try {
96
- await new Promise((resolve2, reject) => {
345
+ await new Promise((resolve3, reject) => {
97
346
  execFile(
98
- "npx",
99
- ["biome", "format", "--write", filePath],
347
+ invocation.cmd,
348
+ invocation.args,
100
349
  {
101
350
  encoding: "utf-8",
102
351
  timeout: timeoutMs,
103
352
  cwd: process.cwd(),
104
353
  windowsHide: true,
105
- maxBuffer: 16 * 1024 * 1024
354
+ maxBuffer: 16 * 1024 * 1024,
355
+ ...invocation.windowsVerbatimArguments ? { windowsVerbatimArguments: true } : {}
106
356
  },
107
357
  (err) => {
108
358
  if (err) {
109
359
  const e = err;
110
360
  if (e.killed) return reject(err);
111
361
  }
112
- resolve2();
362
+ resolve3();
113
363
  }
114
364
  );
115
365
  });
@@ -125,28 +375,11 @@ async function formatFile(filePath, timeoutMs) {
125
375
  if (bytesAfter !== bytesBefore) {
126
376
  return { changed: true, bytesBefore, bytesAfter };
127
377
  }
128
- try {
129
- await new Promise((resolve2, reject) => {
130
- execFile(
131
- "npx",
132
- ["biome", "format", filePath],
133
- {
134
- encoding: "utf-8",
135
- timeout: timeoutMs,
136
- cwd: process.cwd(),
137
- windowsHide: true,
138
- maxBuffer: 16 * 1024 * 1024
139
- },
140
- (err) => {
141
- if (err) return reject(err);
142
- resolve2();
143
- }
144
- );
145
- });
378
+ const hashAfter = await sha256File(filePath);
379
+ if (hashBefore === null || hashAfter === null) {
146
380
  return { changed: false, bytesBefore, bytesAfter };
147
- } catch {
148
- return { changed: true, bytesBefore, bytesAfter };
149
381
  }
382
+ return { changed: hashBefore !== hashAfter, bytesBefore, bytesAfter };
150
383
  }
151
384
  var plugin = {
152
385
  name: "format-on-save",
@@ -192,32 +425,18 @@ var plugin = {
192
425
  state.lastResult = null;
193
426
  recentlyCovered.clear();
194
427
  const cfg = readConfig(api.config.extensions?.["format-on-save"]);
195
- let biomeAvailable = false;
196
- try {
197
- await new Promise((resolve2, reject) => {
198
- execFile(
199
- "npx",
200
- ["biome", "--version"],
201
- {
202
- encoding: "utf-8",
203
- timeout: 5e3,
204
- cwd: process.cwd(),
205
- windowsHide: true
206
- },
207
- (err) => {
208
- if (err) reject(err);
209
- else resolve2();
210
- }
211
- );
212
- });
213
- biomeAvailable = true;
214
- api.log.info("format-on-save: biome detected");
215
- } catch {
216
- biomeAvailable = false;
217
- api.log.warn("format-on-save: biome not found \u2014 hook will be a no-op");
428
+ resetFormatter();
429
+ const formatter = resolveFormatter();
430
+ const formatterAvailable = formatter !== null;
431
+ if (formatter) {
432
+ api.log.info(`format-on-save: ${formatter.label} detected`);
433
+ } else {
434
+ api.log.warn(
435
+ "format-on-save: no formatter found (biome, prettier, dprint) \u2014 hook will be a no-op"
436
+ );
218
437
  }
219
438
  const hook = async (input) => {
220
- if (!cfg.enabled || !biomeAvailable) return;
439
+ if (!cfg.enabled || !formatterAvailable) return;
221
440
  if (input.toolResult?.isError) return;
222
441
  const toolName = input.toolName ?? "";
223
442
  const inp = input.toolInput ?? {};
@@ -278,7 +497,7 @@ var plugin = {
278
497
  );
279
498
  api.tools.register({
280
499
  name: "format_on_save_status",
281
- description: "Reports format-on-save state: biome availability, and per-session formatted/clean/error/skipped counters.",
500
+ description: "Reports format-on-save state: which formatter is active, and per-session formatted/clean/error/skipped counters.",
282
501
  inputSchema: { type: "object", properties: {} },
283
502
  permission: "auto",
284
503
  category: "Code Quality",
@@ -287,7 +506,14 @@ var plugin = {
287
506
  return {
288
507
  ok: true,
289
508
  enabled: cfg.enabled,
290
- biomeAvailable,
509
+ formatterAvailable,
510
+ formatter: activeFormatterLabel(),
511
+ /**
512
+ * Back-compat alias for the pre-multi-formatter status shape.
513
+ * Now accurate rather than assumed: true only when the resolved
514
+ * formatter really is biome.
515
+ */
516
+ biomeAvailable: activeFormatterLabel() === "biome",
291
517
  timeoutMs: cfg.timeoutMs,
292
518
  skipWhenCoveredBy: cfg.skipWhenCoveredBy,
293
519
  skipTtlMs: cfg.skipTtlMs,
@@ -305,11 +531,13 @@ var plugin = {
305
531
  api.log.info("format-on-save plugin loaded", {
306
532
  version: "0.1.0",
307
533
  enabled: cfg.enabled,
308
- biomeAvailable
534
+ formatterAvailable,
535
+ formatter: activeFormatterLabel()
309
536
  });
310
537
  },
311
538
  teardown(api) {
312
539
  clearRegistrations();
540
+ resetFormatter();
313
541
  const final = {
314
542
  invocations: state.invocationCount,
315
543
  formatted: state.formattedCount,
@@ -343,5 +571,6 @@ var plugin = {
343
571
  };
344
572
  var format_on_save_default = plugin;
345
573
  export {
574
+ activeFormatterLabel,
346
575
  format_on_save_default as default
347
576
  };
@@ -10,6 +10,18 @@
10
10
  * - For status: use the built-in `git` tool with `command: "status"` or `command: "diff"`.
11
11
  */
12
12
  import type { Plugin } from '@wrongstack/core/types';
13
+ /**
14
+ * Parse one `git status --porcelain` line into the path to stage.
15
+ *
16
+ * Two shapes the naive `line.slice(3)` got wrong:
17
+ * - **Renames/copies** print `R old -> new`. Slicing produced the literal
18
+ * string `"old -> new"`, which matches no file on disk, so the rename was
19
+ * dropped from the commit entirely. The path that must be staged is the
20
+ * NEW one.
21
+ * - **Quoted paths** (spaces, unicode, control chars) keep their quotes,
22
+ * likewise matching nothing.
23
+ */
24
+ export declare function parsePorcelainLine(line: string): string | null;
13
25
  declare const plugin: Plugin;
14
26
  export default plugin;
15
27
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/git-autocommit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAoTrD,QAAA,MAAM,MAAM,EAAE,MAsXb,CAAC;eAEa,MAAM"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/git-autocommit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AA+IrD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAW9D;AA2OD,QAAA,MAAM,MAAM,EAAE,MAsXb,CAAC;eAEa,MAAM"}
@@ -34,10 +34,63 @@ async function runGit(args, cwd, timeoutMs = DEFAULT_GIT_TIMEOUT_MS) {
34
34
  );
35
35
  });
36
36
  }
37
+ function unquotePorcelainPath(raw) {
38
+ if (!raw.startsWith('"') || !raw.endsWith('"') || raw.length < 2) return raw;
39
+ const inner = raw.slice(1, -1);
40
+ const bytes = [];
41
+ for (let i = 0; i < inner.length; i++) {
42
+ const ch = inner[i];
43
+ if (ch !== "\\") {
44
+ for (const b of Buffer.from(ch, "utf8")) bytes.push(b);
45
+ continue;
46
+ }
47
+ const next = inner[i + 1];
48
+ if (next === void 0) {
49
+ bytes.push(92);
50
+ break;
51
+ }
52
+ const simple = {
53
+ n: 10,
54
+ t: 9,
55
+ r: 13,
56
+ a: 7,
57
+ b: 8,
58
+ f: 12,
59
+ v: 11,
60
+ '"': 34,
61
+ "\\": 92
62
+ };
63
+ const mapped = simple[next];
64
+ if (mapped !== void 0) {
65
+ bytes.push(mapped);
66
+ i += 1;
67
+ continue;
68
+ }
69
+ const octal = /^[0-7]{1,3}/.exec(inner.slice(i + 1));
70
+ if (octal) {
71
+ bytes.push(Number.parseInt(octal[0], 8) & 255);
72
+ i += octal[0].length;
73
+ continue;
74
+ }
75
+ for (const b of Buffer.from(next, "utf8")) bytes.push(b);
76
+ i += 1;
77
+ }
78
+ return Buffer.from(bytes).toString("utf8");
79
+ }
80
+ function parsePorcelainLine(line) {
81
+ const body = line.slice(3);
82
+ if (!body) return null;
83
+ const status = line.slice(0, 2);
84
+ if (status.includes("R") || status.includes("C")) {
85
+ const arrow = body.lastIndexOf(" -> ");
86
+ if (arrow !== -1) return unquotePorcelainPath(body.slice(arrow + 4).trim());
87
+ }
88
+ return unquotePorcelainPath(body.trim());
89
+ }
37
90
  async function getChangedFiles(cwd) {
38
91
  const output = await runGit(["status", "--porcelain"], cwd);
39
92
  if (!output) return [];
40
- return output.split("\n").filter((l) => l.trim()).map((l) => l.slice(3).trim());
93
+ return output.split("\n").filter((l) => l.trim()).map((l) => parsePorcelainLine(l)).filter((p) => p !== null && p.length > 0);
41
94
  }
42
95
  async function getStagedFiles(cwd) {
43
96
  const output = await runGit(["diff", "--cached", "--name-only"], cwd);
@@ -53,7 +106,7 @@ async function stageFiles(files, cwd) {
53
106
  }
54
107
  });
55
108
  if (existing.length === 0) throw new Error("No files exist to stage");
56
- await runGit(["add", ...existing], cwd);
109
+ await runGit(["add", "--", ...existing], cwd);
57
110
  }
58
111
  async function commitWithMessage(message, cwd) {
59
112
  return await runGit(["commit", "-m", message], cwd, GIT_COMMIT_TIMEOUT_MS);
@@ -106,7 +159,7 @@ async function externalChangesSinceStage(cwd) {
106
159
  const unstaged = out.split("\n").filter((l) => l.trim()).filter((l) => {
107
160
  const idx = l[0] ?? " ";
108
161
  return idx === " " || idx === "?";
109
- }).map((l) => l.slice(3).trim());
162
+ }).map((l) => parsePorcelainLine(l)).filter((p) => p !== null && p.length > 0);
110
163
  return unstaged.length > 0 ? unstaged : null;
111
164
  } catch {
112
165
  return null;
@@ -470,5 +523,6 @@ ${preCommitDiff}
470
523
  };
471
524
  var git_autocommit_default = plugin;
472
525
  export {
473
- git_autocommit_default as default
526
+ git_autocommit_default as default,
527
+ parsePorcelainLine
474
528
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/import-organizer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAoRrD,QAAA,MAAM,MAAM,EAAE,MA8Nb,CAAC;eAEa,MAAM"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/import-organizer/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAKH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAiXrD,QAAA,MAAM,MAAM,EAAE,MA8Nb,CAAC;eAEa,MAAM"}