@visulima/vis 1.0.0-alpha.11 → 1.0.0-alpha.13

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 (116) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/LICENSE.md +559 -186
  3. package/README.md +18 -0
  4. package/dist/bin.js +1 -9
  5. package/dist/config/index.d.ts +477 -556
  6. package/dist/config/index.js +1 -2
  7. package/dist/generate/index.js +1 -3
  8. package/dist/packem_chunks/applyDefaults.js +2 -336
  9. package/dist/packem_chunks/bin.js +234 -9552
  10. package/dist/packem_chunks/doctor-probe.js +2 -112
  11. package/dist/packem_chunks/fix.js +11 -234
  12. package/dist/packem_chunks/handler.js +1 -99
  13. package/dist/packem_chunks/handler10.js +2 -53
  14. package/dist/packem_chunks/handler11.js +1 -32
  15. package/dist/packem_chunks/handler12.js +5 -100
  16. package/dist/packem_chunks/handler13.js +1 -25
  17. package/dist/packem_chunks/handler14.js +18 -916
  18. package/dist/packem_chunks/handler15.js +15 -201
  19. package/dist/packem_chunks/handler16.js +1 -124
  20. package/dist/packem_chunks/handler17.js +1 -13
  21. package/dist/packem_chunks/handler18.js +1 -106
  22. package/dist/packem_chunks/handler19.js +1 -19
  23. package/dist/packem_chunks/handler2.js +2 -75
  24. package/dist/packem_chunks/handler20.js +5 -29
  25. package/dist/packem_chunks/handler21.js +1 -222
  26. package/dist/packem_chunks/handler22.js +1 -237
  27. package/dist/packem_chunks/handler23.js +5 -101
  28. package/dist/packem_chunks/handler24.js +1 -110
  29. package/dist/packem_chunks/handler25.js +3 -402
  30. package/dist/packem_chunks/handler26.js +1 -13
  31. package/dist/packem_chunks/handler27.js +1 -63
  32. package/dist/packem_chunks/handler28.js +7 -34
  33. package/dist/packem_chunks/handler29.js +21 -456
  34. package/dist/packem_chunks/handler3.js +4 -95
  35. package/dist/packem_chunks/handler30.js +3 -170
  36. package/dist/packem_chunks/handler31.js +1 -530
  37. package/dist/packem_chunks/handler32.js +2 -214
  38. package/dist/packem_chunks/handler33.js +25 -119
  39. package/dist/packem_chunks/handler34.js +2 -630
  40. package/dist/packem_chunks/handler35.js +3 -283
  41. package/dist/packem_chunks/handler36.js +22 -542
  42. package/dist/packem_chunks/handler37.js +410 -744
  43. package/dist/packem_chunks/handler38.js +22 -989
  44. package/dist/packem_chunks/handler39.js +22 -574
  45. package/dist/packem_chunks/handler4.js +2 -90
  46. package/dist/packem_chunks/handler40.js +22 -1685
  47. package/dist/packem_chunks/handler41.js +6 -1088
  48. package/dist/packem_chunks/handler42.js +5 -797
  49. package/dist/packem_chunks/handler43.js +10 -2658
  50. package/dist/packem_chunks/handler44.js +51 -3784
  51. package/dist/packem_chunks/handler45.js +25 -2574
  52. package/dist/packem_chunks/handler46.js +3 -3769
  53. package/dist/packem_chunks/handler47.js +21 -1485
  54. package/dist/packem_chunks/handler48.js +42 -0
  55. package/dist/packem_chunks/handler5.js +8 -174
  56. package/dist/packem_chunks/handler6.js +1 -95
  57. package/dist/packem_chunks/handler7.js +1 -115
  58. package/dist/packem_chunks/handler8.js +1 -12
  59. package/dist/packem_chunks/handler9.js +1 -29
  60. package/dist/packem_chunks/heal-accept.js +10 -522
  61. package/dist/packem_chunks/heal.js +14 -673
  62. package/dist/packem_chunks/index.js +7 -873
  63. package/dist/packem_chunks/loader.js +1 -23
  64. package/dist/packem_chunks/tar.js +3 -0
  65. package/dist/packem_shared/ai-analysis-hm8d2W7z.js +67 -0
  66. package/dist/packem_shared/ai-cache-DoiF80AR.js +1 -0
  67. package/dist/packem_shared/ai-fix-nn4zOE95.js +43 -0
  68. package/dist/packem_shared/cache-directory-CwHlJhgx.js +1 -0
  69. package/dist/packem_shared/dependency-scan-COr5n63B.js +2 -0
  70. package/dist/packem_shared/docker-D6OGr5_S.js +2 -0
  71. package/dist/packem_shared/failure-log-iUVLf6ts.js +2 -0
  72. package/dist/packem_shared/flakiness-D9wf0t56.js +1 -0
  73. package/dist/packem_shared/giget-CcEy_Elm.js +2 -0
  74. package/dist/packem_shared/index-DH-5hsrC.js +1 -0
  75. package/dist/packem_shared/otel-DxDUPJJH.js +6 -0
  76. package/dist/packem_shared/otelPlugin-CQq6poq8.js +1 -0
  77. package/dist/packem_shared/registry-CkubDdiY.js +2 -0
  78. package/dist/packem_shared/run-summary-utils-BfBvjzhY.js +1 -0
  79. package/dist/packem_shared/runtime-check-BXZ43CBW.js +1 -0
  80. package/dist/packem_shared/selectors-BylODRiM.js +3 -0
  81. package/dist/packem_shared/symbols-CQmER5MT.js +1 -0
  82. package/dist/packem_shared/toolchain-BgBOUHII.js +5 -0
  83. package/dist/packem_shared/typosquats-CcZl99B1.js +1 -0
  84. package/dist/packem_shared/use-measured-height-DjYgUOKk.js +1 -0
  85. package/dist/packem_shared/utils-DrNg0XTR.js +1 -0
  86. package/dist/packem_shared/verify-Baj5mFJ7.js +1 -0
  87. package/dist/packem_shared/vis-update-app-D1jl0UZZ.js +1 -0
  88. package/dist/packem_shared/xxh3-DrAUNq4n.js +1 -0
  89. package/index.js +556 -727
  90. package/package.json +19 -29
  91. package/schemas/project.schema.json +739 -297
  92. package/schemas/vis-config.schema.json +3365 -384
  93. package/templates/buildkite-ci/template.yml +20 -20
  94. package/dist/packem_shared/VisUpdateApp-D-Yz_wvg.js +0 -1316
  95. package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
  96. package/dist/packem_shared/ai-analysis-CHeB1joD.js +0 -367
  97. package/dist/packem_shared/ai-cache-Be_jexe4.js +0 -142
  98. package/dist/packem_shared/ai-fix-B9iQVcD2.js +0 -379
  99. package/dist/packem_shared/cache-directory-2qvs4goY.js +0 -98
  100. package/dist/packem_shared/catalog-BJTtyi-O.js +0 -1371
  101. package/dist/packem_shared/dependency-scan-A0KSklpG.js +0 -188
  102. package/dist/packem_shared/docker-2iZzc280.js +0 -181
  103. package/dist/packem_shared/failure-log-Cz3Z4SKL.js +0 -100
  104. package/dist/packem_shared/flakiness-goTxXuCX.js +0 -180
  105. package/dist/packem_shared/otel-DCvqCTz_.js +0 -158
  106. package/dist/packem_shared/otelPlugin-DFaLDvJf.js +0 -3
  107. package/dist/packem_shared/registry-CbqXI0rc.js +0 -272
  108. package/dist/packem_shared/run-summary-utils-PVMl4aIh.js +0 -130
  109. package/dist/packem_shared/runtime-check-Cobi3p6l.js +0 -127
  110. package/dist/packem_shared/selectors-SM69TfqC.js +0 -194
  111. package/dist/packem_shared/symbols-Ta7g2nU-.js +0 -14
  112. package/dist/packem_shared/toolchain-BdZd9eBi.js +0 -975
  113. package/dist/packem_shared/typosquats-C-bCh3PX.js +0 -1210
  114. package/dist/packem_shared/use-measured-height-CNP0vT4M.js +0 -20
  115. package/dist/packem_shared/utils-CthVdBPS.js +0 -40
  116. package/dist/packem_shared/xxh3-Ck8mXNg1.js +0 -239
@@ -1,379 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- import { readLastRunSummary } from '@visulima/task-runner';
21
- import { a as loadFailureLog } from './failure-log-Cz3Z4SKL.js';
22
- import { f as findTaskInSummary, a as readPreviousRunSummary, d as diffHashDetails, r as readRunSummaryById } from './run-summary-utils-PVMl4aIh.js';
23
- const {
24
- readFile,
25
- writeFile
26
- } = __cjs_getBuiltinModule("node:fs/promises");
27
- import { isAbsolute, resolve, join, relative } from '@visulima/path';
28
- import { a as resolveProvider, b as runWithRetry, e as extractJson } from './ai-analysis-CHeB1joD.js';
29
- import { e as getCachedJson, f as setCachedJson, h as buildHashCacheKey } from './ai-cache-Be_jexe4.js';
30
-
31
- const DEFAULT_TERMINAL_OUTPUT_LIMIT = 32 * 1024;
32
- const truncateHead = (output, limit) => {
33
- if (output.length <= limit) {
34
- return output;
35
- }
36
- const tail = output.slice(-limit);
37
- const dropped = output.length - tail.length;
38
- return `[…${String(dropped)} bytes truncated from head…]
39
- ${tail}`;
40
- };
41
- const loadSummary = async (workspaceRoot, runId) => {
42
- if (runId === void 0) {
43
- return readLastRunSummary(workspaceRoot);
44
- }
45
- return readRunSummaryById(workspaceRoot, runId);
46
- };
47
- const aggregateFailureContext = async (workspaceRoot, taskId, options = {}) => {
48
- const limit = options.terminalOutputLimit ?? DEFAULT_TERMINAL_OUTPUT_LIMIT;
49
- const [failureLog, summary] = await Promise.all([loadFailureLog(workspaceRoot, taskId), loadSummary(workspaceRoot, options.runId)]);
50
- const summaryTask = summary ? findTaskInSummary(summary, taskId) : void 0;
51
- if (!failureLog && !summaryTask) {
52
- return void 0;
53
- }
54
- let hashDiff;
55
- let previousRunId;
56
- if (summary && summaryTask) {
57
- const previousSummary = await readPreviousRunSummary(workspaceRoot, summary.id);
58
- const previousTask = previousSummary ? findTaskInSummary(previousSummary, taskId) : void 0;
59
- hashDiff = diffHashDetails(summaryTask.hashDetails, previousTask?.hashDetails);
60
- previousRunId = previousSummary?.id;
61
- }
62
- const terminalOutput = failureLog?.terminalOutput ?? "";
63
- return {
64
- command: failureLog?.command ?? void 0,
65
- cwd: failureLog?.cwd ?? void 0,
66
- dependencies: summaryTask?.dependencies ?? [],
67
- duration: summaryTask?.duration,
68
- exitCode: failureLog?.exitCode ?? summaryTask?.exitCode,
69
- hash: summaryTask?.hash ?? failureLog?.hash,
70
- hashDetails: summaryTask?.hashDetails,
71
- hashDiff,
72
- previousRunId,
73
- project: summaryTask?.target.project,
74
- runId: summary?.id ?? failureLog?.runId,
75
- status: failureLog?.status ?? (summaryTask ? mapCacheStatusToTaskStatus(summaryTask) : void 0),
76
- target: summaryTask?.target.target,
77
- taskId,
78
- terminalOutput: truncateHead(terminalOutput, limit),
79
- terminalOutputCaptured: Boolean(failureLog),
80
- timestamp: failureLog?.timestamp ?? summaryTask?.endTime ?? summaryTask?.startTime
81
- };
82
- };
83
- const mapCacheStatusToTaskStatus = (summaryTask) => {
84
- if (summaryTask.exitCode !== void 0 && summaryTask.exitCode !== 0) {
85
- return "failure";
86
- }
87
- switch (summaryTask.cacheStatus) {
88
- case "HIT": {
89
- return "local-cache";
90
- }
91
- case "REMOTE_HIT": {
92
- return "remote-cache";
93
- }
94
- case "SKIPPED": {
95
- return "skipped";
96
- }
97
- default: {
98
- return summaryTask.exitCode === 0 ? "success" : void 0;
99
- }
100
- }
101
- };
102
-
103
- const FIX_CACHE_TTL_MS = 60 * 60 * 1e3;
104
- const PREVIEW_CONTEXT_CHARS = 80;
105
- const VALID_CONFIDENCE = /* @__PURE__ */ new Set(["high", "low", "medium"]);
106
- const buildSystemPrompt = () => `You are an expert software engineer helping fix a failing build/test/lint task.
107
-
108
- You will be given:
109
- - The terminal output (stdout/stderr) from the failed task.
110
- - Optional metadata: command, working directory, project, task hash, and a diff describing what changed in the task's hash inputs since the previous run that did not fail.
111
-
112
- Your job:
113
- 1. Identify the root cause from the terminal output.
114
- 2. Propose a minimal set of source-file patches that fix the cause.
115
- 3. If you cannot determine a safe fix, set "cannotFix" with a clear, actionable explanation.
116
-
117
- Constraints:
118
- - Patches MUST be exact string replacements. The "oldString" must appear verbatim in the named file. Paths are relative to the working directory.
119
- - Each "oldString" must be unique within its file. Include surrounding context so the match is unambiguous.
120
- - Do NOT include unrelated cleanup, formatting changes, or speculative refactors.
121
- - If the failure is environmental (missing tool, network) or requires running commands, prefer "cannotFix" over a guess.
122
- - Keep "explanation" short (1-3 sentences). Reserve "reason" on each patch for why that specific edit fixes the cause.
123
-
124
- Respond ONLY with valid JSON in this exact structure:
125
- {
126
- "explanation": "Brief root-cause analysis and what the fix does.",
127
- "confidence": "low|medium|high",
128
- "patches": [
129
- {
130
- "file": "path/relative/to/cwd.ts",
131
- "oldString": "exact text to find",
132
- "newString": "exact replacement text",
133
- "reason": "why this change fixes it"
134
- }
135
- ],
136
- "cannotFix": "optional — set when no safe patch can be proposed"
137
- }`;
138
- const formatBucket = (label, bucket) => {
139
- const lines = [];
140
- if (bucket.added.length > 0) {
141
- lines.push(` added: ${bucket.added.join(", ")}`);
142
- }
143
- if (bucket.changed.length > 0) {
144
- lines.push(` changed: ${bucket.changed.join(", ")}`);
145
- }
146
- if (bucket.removed.length > 0) {
147
- lines.push(` removed: ${bucket.removed.join(", ")}`);
148
- }
149
- if (lines.length === 0) {
150
- return void 0;
151
- }
152
- return `- ${label}:
153
- ${lines.join("\n")}`;
154
- };
155
- const buildHashDiffSummary = (failureContext) => {
156
- if (!failureContext.hashDiff) {
157
- return "No hash-diff available — there is no previous run to compare against.";
158
- }
159
- const parts = [];
160
- if (failureContext.hashDiff.commandChanged) {
161
- parts.push("- command line changed since previous run");
162
- }
163
- const nodes = formatBucket("file inputs", failureContext.hashDiff.nodes);
164
- const implicit = formatBucket("implicit deps", failureContext.hashDiff.implicitDeps);
165
- const runtime = formatBucket("runtime/env", failureContext.hashDiff.runtime);
166
- if (nodes) {
167
- parts.push(nodes);
168
- }
169
- if (implicit) {
170
- parts.push(implicit);
171
- }
172
- if (runtime) {
173
- parts.push(runtime);
174
- }
175
- return parts.length === 0 ? "No detectable changes between this run and the previous run." : parts.join("\n");
176
- };
177
- const buildUserPrompt = (failureContext) => {
178
- const lines = [];
179
- lines.push(`Task: ${failureContext.taskId}`);
180
- if (failureContext.project) {
181
- lines.push(`Project: ${failureContext.project}`);
182
- }
183
- if (failureContext.target) {
184
- lines.push(`Target: ${failureContext.target}`);
185
- }
186
- if (failureContext.command) {
187
- lines.push(`Command: ${failureContext.command}`);
188
- }
189
- if (failureContext.cwd) {
190
- lines.push(`CWD: ${failureContext.cwd}`);
191
- }
192
- if (failureContext.exitCode !== void 0) {
193
- lines.push(`Exit code: ${String(failureContext.exitCode)}`);
194
- }
195
- if (failureContext.hash) {
196
- lines.push(`Task hash: ${failureContext.hash}`);
197
- }
198
- lines.push("", "Hash-diff since previous run:", buildHashDiffSummary(failureContext), "");
199
- if (failureContext.terminalOutputCaptured) {
200
- lines.push("Terminal output:", "```", failureContext.terminalOutput, "```");
201
- } else {
202
- lines.push(
203
- "Terminal output: <no failure log was captured for this task>",
204
- 'Set "cannotFix" and tell the user to re-run with `vis run` so logs can be captured.'
205
- );
206
- }
207
- return lines.join("\n");
208
- };
209
- const buildFixPrompt = (failureContext) => `${buildSystemPrompt()}
210
-
211
- ${buildUserPrompt(failureContext)}`;
212
- const normalizeFixProposal = (raw, provider) => {
213
- const rawPatches = Array.isArray(raw.patches) ? raw.patches : [];
214
- const patches = [];
215
- for (const rawPatch of rawPatches) {
216
- if (typeof rawPatch.file !== "string" || rawPatch.file.length === 0) {
217
- continue;
218
- }
219
- if (typeof rawPatch.oldString !== "string" || rawPatch.oldString.length === 0) {
220
- continue;
221
- }
222
- if (typeof rawPatch.newString !== "string") {
223
- continue;
224
- }
225
- patches.push({
226
- file: rawPatch.file,
227
- newString: rawPatch.newString,
228
- oldString: rawPatch.oldString,
229
- reason: typeof rawPatch.reason === "string" && rawPatch.reason.length > 0 ? rawPatch.reason : void 0
230
- });
231
- }
232
- const cannotFixRaw = typeof raw.cannotFix === "string" && raw.cannotFix.length > 0 ? raw.cannotFix : void 0;
233
- return {
234
- cannotFix: cannotFixRaw,
235
- confidence: VALID_CONFIDENCE.has(raw.confidence) ? raw.confidence : "low",
236
- explanation: typeof raw.explanation === "string" ? raw.explanation : "",
237
- // Enforce the FixProposal invariant: when `cannotFix` is set,
238
- // `patches` must be empty. Some AI responses include both
239
- // (e.g. "I'm not sure but here's a guess") — drop the guess
240
- // so downstream consumers can rely on the invariant.
241
- patches: cannotFixRaw ? [] : patches,
242
- provider
243
- };
244
- };
245
- const parseFixResponse = (text, provider) => {
246
- const parsed = extractJson(text);
247
- if (!parsed || typeof parsed !== "object") {
248
- return {
249
- cannotFix: "AI response was not valid JSON.",
250
- confidence: "low",
251
- explanation: "Failed to parse AI response.",
252
- patches: [],
253
- provider
254
- };
255
- }
256
- return normalizeFixProposal(parsed, provider);
257
- };
258
- const buildFixCacheKey = (provider, failureContext) => buildHashCacheKey({
259
- cwd: failureContext.cwd ?? null,
260
- flow: "ai-fix",
261
- hash: failureContext.hash ?? null,
262
- provider,
263
- taskId: failureContext.taskId,
264
- terminalOutput: failureContext.terminalOutput,
265
- terminalOutputCaptured: failureContext.terminalOutputCaptured
266
- });
267
- const runFixAnalysis = async (failureContext, logger, options = {}) => {
268
- const provider = resolveProvider(options.config);
269
- if (!provider) {
270
- logger.warn("No AI provider available — install one of: claude, gemini, copilot, codex.\n");
271
- return void 0;
272
- }
273
- const useCache = options.cache !== false;
274
- const cacheKey = buildFixCacheKey(provider.name, failureContext);
275
- if (useCache) {
276
- const cached = getCachedJson(cacheKey);
277
- if (cached) {
278
- logger.info(`Using cached fix proposal from ${cached.provider}.
279
- `);
280
- return cached;
281
- }
282
- }
283
- logger.info(`Generating fix proposal with ${provider.name}...
284
- `);
285
- try {
286
- const stdout = await runWithRetry(provider, buildFixPrompt(failureContext));
287
- const proposal = parseFixResponse(stdout, provider.name);
288
- if (useCache && proposal.patches.length > 0 && !proposal.cannotFix) {
289
- setCachedJson(cacheKey, proposal, FIX_CACHE_TTL_MS);
290
- }
291
- return proposal;
292
- } catch (error) {
293
- const message = error instanceof Error ? error.message : String(error);
294
- logger.warn(`AI fix proposal failed (${message}).
295
- `);
296
- return void 0;
297
- }
298
- };
299
- const resolvePatchPath = (workspaceRoot, cwd, file) => {
300
- if (isAbsolute(file)) {
301
- return resolve(file);
302
- }
303
- const base = cwd ?? workspaceRoot;
304
- return resolve(join(base, file));
305
- };
306
- const isInsideWorkspace = (workspaceRoot, absolutePath) => {
307
- const rel = relative(workspaceRoot, absolutePath);
308
- if (rel === "") {
309
- return true;
310
- }
311
- return !rel.startsWith("..") && !isAbsolute(rel);
312
- };
313
- const buildPreview = (content, oldString, newString) => {
314
- const index = content.indexOf(oldString);
315
- const start = Math.max(0, index - PREVIEW_CONTEXT_CHARS);
316
- const endBefore = Math.min(content.length, index + oldString.length + PREVIEW_CONTEXT_CHARS);
317
- const before = content.slice(start, endBefore);
318
- const replaced = `${content.slice(start, index)}${newString}${content.slice(index + oldString.length, endBefore)}`;
319
- return { previewAfter: replaced, previewBefore: before };
320
- };
321
- const applyFixProposal = async (workspaceRoot, cwd, proposal, options = {}) => {
322
- const dryRun = options.dryRun === true;
323
- const fileCache = /* @__PURE__ */ new Map();
324
- const results = [];
325
- for (const patch of proposal.patches) {
326
- const absolutePath = resolvePatchPath(workspaceRoot, cwd, patch.file);
327
- if (!isInsideWorkspace(workspaceRoot, absolutePath)) {
328
- results.push({ absolutePath, patch, status: "outside-workspace" });
329
- continue;
330
- }
331
- let content = fileCache.get(absolutePath);
332
- if (content === void 0) {
333
- try {
334
- content = await readFile(absolutePath, "utf8");
335
- } catch (error) {
336
- const errorCode = error.code;
337
- results.push({
338
- absolutePath,
339
- error: errorCode === "ENOENT" ? void 0 : error.message,
340
- patch,
341
- status: errorCode === "ENOENT" ? "missing-file" : "error"
342
- });
343
- continue;
344
- }
345
- fileCache.set(absolutePath, content);
346
- }
347
- const firstIndex = content.indexOf(patch.oldString);
348
- if (firstIndex === -1) {
349
- results.push({ absolutePath, patch, status: "no-match" });
350
- continue;
351
- }
352
- const secondIndex = content.indexOf(patch.oldString, firstIndex + patch.oldString.length);
353
- if (secondIndex !== -1) {
354
- results.push({ absolutePath, patch, status: "ambiguous-match" });
355
- continue;
356
- }
357
- const { previewAfter, previewBefore } = buildPreview(content, patch.oldString, patch.newString);
358
- const updated = `${content.slice(0, firstIndex)}${patch.newString}${content.slice(firstIndex + patch.oldString.length)}`;
359
- if (!dryRun) {
360
- try {
361
- await writeFile(absolutePath, updated, "utf8");
362
- } catch (error) {
363
- fileCache.delete(absolutePath);
364
- results.push({
365
- absolutePath,
366
- error: error.message,
367
- patch,
368
- status: "error"
369
- });
370
- continue;
371
- }
372
- }
373
- fileCache.set(absolutePath, updated);
374
- results.push({ absolutePath, patch, previewAfter, previewBefore, status: "applied" });
375
- }
376
- return results;
377
- };
378
-
379
- export { aggregateFailureContext as a, applyFixProposal as b, resolvePatchPath as c, runFixAnalysis as r };
@@ -1,98 +0,0 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
2
-
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
4
-
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
-
7
- const __cjs_getBuiltinModule = (module) => {
8
- // Check if we're in Node.js and version supports getBuiltinModule
9
- if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
- const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
- // Node.js 20.16.0+ and 22.3.0+
12
- if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
- return __cjs_getProcess.getBuiltinModule(module);
14
- }
15
- }
16
- // Fallback to createRequire
17
- return __cjs_require(module);
18
- };
19
-
20
- const {
21
- execFileSync
22
- } = __cjs_getBuiltinModule("node:child_process");
23
- import { resolve, relative, isAbsolute } from '@visulima/path';
24
- import { DEFAULT_CACHE_DIRECTORY_NAME, getMainWorktreeRoot } from '@visulima/task-runner';
25
-
26
- const resolveCacheDirectory = (workspaceRoot, optionsCacheDir, configCacheDir) => {
27
- const normalize = (value) => isAbsolute(value) ? value : resolve(workspaceRoot, value);
28
- if (optionsCacheDir && optionsCacheDir.length > 0) {
29
- return normalize(optionsCacheDir);
30
- }
31
- if (configCacheDir && configCacheDir.length > 0) {
32
- return normalize(configCacheDir);
33
- }
34
- const envOverride = process.env["VIS_CACHE_DIRECTORY"];
35
- if (envOverride && envOverride.length > 0) {
36
- return normalize(envOverride);
37
- }
38
- return resolve(workspaceRoot, DEFAULT_CACHE_DIRECTORY_NAME);
39
- };
40
- const resolveSharedCacheRoot = (workspaceRoot, enabled) => {
41
- if (enabled === false) {
42
- return workspaceRoot;
43
- }
44
- const mainRoot = getMainWorktreeRoot(workspaceRoot);
45
- return mainRoot ?? workspaceRoot;
46
- };
47
- const resolveSharedCacheDirectory = (workspaceRoot, optionsCacheDir, configCacheDir, sharedWorktreeCache) => {
48
- const explicit = optionsCacheDir ?? configCacheDir ?? process.env["VIS_CACHE_DIRECTORY"];
49
- if (explicit && explicit.length > 0) {
50
- return resolveCacheDirectory(workspaceRoot, optionsCacheDir, configCacheDir);
51
- }
52
- const anchor = resolveSharedCacheRoot(workspaceRoot, sharedWorktreeCache);
53
- return resolve(anchor, DEFAULT_CACHE_DIRECTORY_NAME);
54
- };
55
- const BRANCH_SLUG_RE = /[^\w.-]+/g;
56
- const LEADING_TRAILING_DASH_RE = /^-+|-+$/g;
57
- const sanitizeBranchSegment = (branch) => {
58
- const slug = branch.trim().replaceAll(BRANCH_SLUG_RE, "-").replaceAll(LEADING_TRAILING_DASH_RE, "");
59
- return slug.slice(0, 64);
60
- };
61
- const detectGitBranch = (cwd) => {
62
- try {
63
- const branch = execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
64
- cwd,
65
- encoding: "utf8",
66
- stdio: ["ignore", "pipe", "ignore"]
67
- }).trim();
68
- if (!branch || branch === "HEAD") {
69
- return void 0;
70
- }
71
- return branch;
72
- } catch {
73
- return void 0;
74
- }
75
- };
76
- const applyBranchScope = (cacheDirectory, workspaceRoot, enabled) => {
77
- if (enabled !== true) {
78
- return cacheDirectory;
79
- }
80
- const branch = detectGitBranch(workspaceRoot);
81
- if (!branch) {
82
- return cacheDirectory;
83
- }
84
- const slug = sanitizeBranchSegment(branch);
85
- if (slug.length === 0) {
86
- return cacheDirectory;
87
- }
88
- return resolve(cacheDirectory, "branches", slug);
89
- };
90
- const isCacheDirectoryInsideWorkspace = (cacheDirectory, workspaceRoot) => {
91
- const rel = relative(workspaceRoot, cacheDirectory);
92
- if (rel.length === 0) {
93
- return false;
94
- }
95
- return rel !== ".." && !rel.startsWith("../") && !isAbsolute(rel);
96
- };
97
-
98
- export { applyBranchScope as a, isCacheDirectoryInsideWorkspace as i, resolveSharedCacheDirectory as r };