@wrongstack/tools 0.284.1 → 0.286.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.
- package/README.md +19 -0
- package/dist/_concurrency.d.ts +16 -0
- package/dist/_concurrency.d.ts.map +1 -0
- package/dist/_danger-detect.d.ts +54 -0
- package/dist/_danger-detect.d.ts.map +1 -0
- package/dist/_edit-match.d.ts +86 -0
- package/dist/_edit-match.d.ts.map +1 -0
- package/dist/_env.d.ts +6 -0
- package/dist/_env.d.ts.map +1 -0
- package/dist/_fetch-guard.d.ts +31 -0
- package/dist/_fetch-guard.d.ts.map +1 -0
- package/dist/_output-spool.d.ts +38 -0
- package/dist/_output-spool.d.ts.map +1 -0
- package/dist/_redact-command.d.ts +6 -0
- package/dist/_redact-command.d.ts.map +1 -0
- package/dist/_regex.d.ts +39 -0
- package/dist/_regex.d.ts.map +1 -0
- package/dist/_session-shell.d.ts +73 -0
- package/dist/_session-shell.d.ts.map +1 -0
- package/dist/_shell-pick.d.ts +158 -0
- package/dist/_shell-pick.d.ts.map +1 -0
- package/dist/_spawn-stream.d.ts +32 -0
- package/dist/_spawn-stream.d.ts.map +1 -0
- package/dist/_syntax-check.d.ts +16 -0
- package/dist/_syntax-check.d.ts.map +1 -0
- package/dist/_util.d.ts +68 -0
- package/dist/_util.d.ts.map +1 -0
- package/dist/_win32-resolve.d.ts +42 -0
- package/dist/_win32-resolve.d.ts.map +1 -0
- package/dist/audit.d.ts +4 -5
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +2743 -28
- package/dist/audit.js.map +7 -1
- package/dist/bash-kill-guard.d.ts +62 -0
- package/dist/bash-kill-guard.d.ts.map +1 -0
- package/dist/bash.d.ts +4 -5
- package/dist/bash.d.ts.map +1 -0
- package/dist/bash.js +59 -30
- package/dist/bash.js.map +7 -1
- package/dist/batch-tool-use.d.ts +4 -5
- package/dist/batch-tool-use.d.ts.map +1 -0
- package/dist/batch-tool-use.js +3 -3
- package/dist/batch-tool-use.js.map +7 -1
- package/dist/browser/artifacts.d.ts +13 -0
- package/dist/browser/artifacts.d.ts.map +1 -0
- package/dist/browser/index.d.ts +7 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +1264 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/manager.d.ts +57 -0
- package/dist/browser/manager.d.ts.map +1 -0
- package/dist/browser/network-guard-proxy.d.ts +23 -0
- package/dist/browser/network-guard-proxy.d.ts.map +1 -0
- package/dist/browser/security.d.ts +29 -0
- package/dist/browser/security.d.ts.map +1 -0
- package/dist/browser/tools.d.ts +62 -0
- package/dist/browser/tools.d.ts.map +1 -0
- package/dist/browser/types.d.ts +60 -0
- package/dist/browser/types.d.ts.map +1 -0
- package/dist/builtin.d.ts +11 -12
- package/dist/builtin.d.ts.map +1 -0
- package/dist/builtin.js +8099 -2178
- package/dist/builtin.js.map +7 -1
- package/dist/circuit-breaker.d.ts +4 -5
- package/dist/circuit-breaker.d.ts.map +1 -0
- package/dist/circuit-breaker.js +3 -3
- package/dist/circuit-breaker.js.map +7 -1
- package/dist/codebase-index/background-indexer.d.ts +116 -0
- package/dist/codebase-index/background-indexer.d.ts.map +1 -0
- package/dist/codebase-index/bm25.d.ts +40 -0
- package/dist/codebase-index/bm25.d.ts.map +1 -0
- package/dist/codebase-index/circuit-breaker.d.ts +94 -0
- package/dist/codebase-index/circuit-breaker.d.ts.map +1 -0
- package/dist/codebase-index/codebase-index-tool.d.ts +17 -0
- package/dist/codebase-index/codebase-index-tool.d.ts.map +1 -0
- package/dist/codebase-index/codebase-search-tool.d.ts +43 -0
- package/dist/codebase-index/codebase-search-tool.d.ts.map +1 -0
- package/dist/codebase-index/codebase-stats-tool.d.ts +23 -0
- package/dist/codebase-index/codebase-stats-tool.d.ts.map +1 -0
- package/dist/codebase-index/gitignore.d.ts +22 -0
- package/dist/codebase-index/gitignore.d.ts.map +1 -0
- package/dist/codebase-index/go-parser.d.ts +16 -0
- package/dist/codebase-index/go-parser.d.ts.map +1 -0
- package/dist/codebase-index/index-service.d.ts +25 -0
- package/dist/codebase-index/index-service.d.ts.map +1 -0
- package/dist/codebase-index/index.d.ts +23 -271
- package/dist/codebase-index/index.d.ts.map +1 -0
- package/dist/codebase-index/index.js +136 -68
- package/dist/codebase-index/index.js.map +7 -1
- package/dist/codebase-index/indexer.d.ts +28 -0
- package/dist/codebase-index/indexer.d.ts.map +1 -0
- package/dist/codebase-index/json-parser.d.ts +8 -0
- package/dist/codebase-index/json-parser.d.ts.map +1 -0
- package/dist/codebase-index/lsp-kind.d.ts +53 -0
- package/dist/codebase-index/lsp-kind.d.ts.map +1 -0
- package/dist/codebase-index/py-parser.d.ts +16 -0
- package/dist/codebase-index/py-parser.d.ts.map +1 -0
- package/dist/codebase-index/refs-extractor.d.ts +25 -0
- package/dist/codebase-index/refs-extractor.d.ts.map +1 -0
- package/dist/codebase-index/rs-parser.d.ts +8 -0
- package/dist/codebase-index/rs-parser.d.ts.map +1 -0
- package/dist/codebase-index/schema.d.ts +82 -0
- package/dist/codebase-index/schema.d.ts.map +1 -0
- package/dist/codebase-index/ts-parser.d.ts +30 -0
- package/dist/codebase-index/ts-parser.d.ts.map +1 -0
- package/dist/codebase-index/worker-protocol.d.ts +77 -0
- package/dist/codebase-index/worker-protocol.d.ts.map +1 -0
- package/dist/codebase-index/worker.d.ts +16 -2
- package/dist/codebase-index/worker.d.ts.map +1 -0
- package/dist/codebase-index/worker.js +103 -65
- package/dist/codebase-index/worker.js.map +7 -1
- package/dist/codebase-index/writer.d.ts +189 -0
- package/dist/codebase-index/writer.d.ts.map +1 -0
- package/dist/codebase-index/yaml-parser.d.ts +8 -0
- package/dist/codebase-index/yaml-parser.d.ts.map +1 -0
- package/dist/design.d.ts +38 -0
- package/dist/design.d.ts.map +1 -0
- package/dist/design.js +270 -0
- package/dist/design.js.map +7 -0
- package/dist/diff.d.ts +4 -5
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +14 -12
- package/dist/diff.js.map +7 -1
- package/dist/document.d.ts +4 -5
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +8 -7
- package/dist/document.js.map +7 -1
- package/dist/e2e.d.ts +56 -0
- package/dist/e2e.d.ts.map +1 -0
- package/dist/edit.d.ts +5 -36
- package/dist/edit.d.ts.map +1 -0
- package/dist/edit.js +28 -16
- package/dist/edit.js.map +7 -1
- package/dist/exec.d.ts +67 -2
- package/dist/exec.d.ts.map +1 -0
- package/dist/exec.js +51 -26
- package/dist/exec.js.map +7 -1
- package/dist/fetch.d.ts +4 -32
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +89 -77
- package/dist/fetch.js.map +7 -1
- package/dist/format.d.ts +4 -5
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +2415 -28
- package/dist/format.js.map +7 -1
- package/dist/git.d.ts +4 -5
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +10 -9
- package/dist/git.js.map +7 -1
- package/dist/glob.d.ts +4 -5
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +15 -12
- package/dist/glob.js.map +7 -1
- package/dist/grep.d.ts +4 -5
- package/dist/grep.d.ts.map +1 -0
- package/dist/grep.js +13 -10
- package/dist/grep.js.map +7 -1
- package/dist/index.d.ts +21 -724
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8955 -2866
- package/dist/index.js.map +7 -1
- package/dist/install.d.ts +4 -5
- package/dist/install.d.ts.map +1 -0
- package/dist/install.js +2680 -31
- package/dist/install.js.map +7 -1
- package/dist/json.d.ts +4 -5
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +13 -11
- package/dist/json.js.map +7 -1
- package/dist/kanban.d.ts +107 -0
- package/dist/kanban.d.ts.map +1 -0
- package/dist/kanban.js +845 -0
- package/dist/kanban.js.map +7 -0
- package/dist/languages/detect.d.ts +3 -0
- package/dist/languages/detect.d.ts.map +1 -0
- package/dist/languages/diagnostics.d.ts +15 -0
- package/dist/languages/diagnostics.d.ts.map +1 -0
- package/dist/languages/execute-tool.d.ts +34 -0
- package/dist/languages/execute-tool.d.ts.map +1 -0
- package/dist/languages/execute.d.ts +18 -0
- package/dist/languages/execute.d.ts.map +1 -0
- package/dist/languages/index.d.ts +12 -0
- package/dist/languages/index.d.ts.map +1 -0
- package/dist/languages/index.js +4457 -0
- package/dist/languages/index.js.map +7 -0
- package/dist/languages/legacy-bridge.d.ts +29 -0
- package/dist/languages/legacy-bridge.d.ts.map +1 -0
- package/dist/languages/package-tool.d.ts +29 -0
- package/dist/languages/package-tool.d.ts.map +1 -0
- package/dist/languages/plan.d.ts +4 -0
- package/dist/languages/plan.d.ts.map +1 -0
- package/dist/languages/profile-helpers.d.ts +14 -0
- package/dist/languages/profile-helpers.d.ts.map +1 -0
- package/dist/languages/profiles/additional.d.ts +3 -0
- package/dist/languages/profiles/additional.d.ts.map +1 -0
- package/dist/languages/profiles/primary.d.ts +3 -0
- package/dist/languages/profiles/primary.d.ts.map +1 -0
- package/dist/languages/registry.d.ts +11 -0
- package/dist/languages/registry.d.ts.map +1 -0
- package/dist/languages/tool.d.ts +32 -0
- package/dist/languages/tool.d.ts.map +1 -0
- package/dist/languages/types.d.ts +207 -0
- package/dist/languages/types.d.ts.map +1 -0
- package/dist/lint.d.ts +4 -5
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +2415 -27
- package/dist/lint.js.map +7 -1
- package/dist/logs.d.ts +4 -5
- package/dist/logs.d.ts.map +1 -0
- package/dist/logs.js +16 -10
- package/dist/logs.js.map +7 -1
- package/dist/memory.d.ts +7 -8
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +7 -5
- package/dist/memory.js.map +7 -1
- package/dist/mode.d.ts +4 -5
- package/dist/mode.d.ts.map +1 -0
- package/dist/mode.js +3 -3
- package/dist/mode.js.map +7 -1
- package/dist/next-steps.d.ts +5 -6
- package/dist/next-steps.d.ts.map +1 -0
- package/dist/next-steps.js +5 -4
- package/dist/next-steps.js.map +7 -1
- package/dist/outdated.d.ts +4 -5
- package/dist/outdated.d.ts.map +1 -0
- package/dist/outdated.js +4777 -68
- package/dist/outdated.js.map +7 -1
- package/dist/pack.d.ts +3 -6
- package/dist/pack.d.ts.map +1 -0
- package/dist/pack.js +8134 -2204
- package/dist/pack.js.map +7 -1
- package/dist/patch.d.ts +4 -5
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +18 -16
- package/dist/patch.js.map +7 -1
- package/dist/plan.d.ts +55 -0
- package/dist/plan.d.ts.map +1 -0
- package/dist/plan.js +280 -0
- package/dist/plan.js.map +7 -0
- package/dist/process-guardian.d.ts +100 -0
- package/dist/process-guardian.d.ts.map +1 -0
- package/dist/process-registry-persistent.d.ts +121 -0
- package/dist/process-registry-persistent.d.ts.map +1 -0
- package/dist/process-registry.d.ts +13 -17
- package/dist/process-registry.d.ts.map +1 -0
- package/dist/process-registry.js +15 -9
- package/dist/process-registry.js.map +7 -1
- package/dist/ps-slash.d.ts +106 -0
- package/dist/ps-slash.d.ts.map +1 -0
- package/dist/ps-slash.js +1291 -0
- package/dist/ps-slash.js.map +7 -0
- package/dist/read.d.ts +4 -5
- package/dist/read.d.ts.map +1 -0
- package/dist/read.js +13 -11
- package/dist/read.js.map +7 -1
- package/dist/replace.d.ts +4 -5
- package/dist/replace.d.ts.map +1 -0
- package/dist/replace.js +26 -13
- package/dist/replace.js.map +7 -1
- package/dist/scaffold.d.ts +4 -5
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +16 -14
- package/dist/scaffold.js.map +7 -1
- package/dist/search.d.ts +5 -6
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +32 -27
- package/dist/search.js.map +7 -1
- package/dist/set-working-dir.d.ts +18 -0
- package/dist/set-working-dir.d.ts.map +1 -0
- package/dist/shim/node-sqlite.d.ts +3 -0
- package/dist/shim/node-sqlite.d.ts.map +1 -0
- package/dist/skill.d.ts +45 -0
- package/dist/skill.d.ts.map +1 -0
- package/dist/skill.js +175 -0
- package/dist/skill.js.map +7 -0
- package/dist/spawn-background.d.ts +80 -0
- package/dist/spawn-background.d.ts.map +1 -0
- package/dist/task.d.ts +35 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +380 -0
- package/dist/task.js.map +7 -0
- package/dist/test.d.ts +4 -5
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +2419 -27
- package/dist/test.js.map +7 -1
- package/dist/todo.d.ts +4 -5
- package/dist/todo.d.ts.map +1 -0
- package/dist/todo.js +5 -5
- package/dist/todo.js.map +7 -1
- package/dist/tool-diff.d.ts +16 -17
- package/dist/tool-diff.d.ts.map +1 -0
- package/dist/tool-diff.js +11 -3
- package/dist/tool-diff.js.map +7 -1
- package/dist/tool-help.d.ts +4 -5
- package/dist/tool-help.d.ts.map +1 -0
- package/dist/tool-help.js +3 -3
- package/dist/tool-help.js.map +7 -1
- package/dist/tool-icon-map.d.ts +46 -0
- package/dist/tool-icon-map.d.ts.map +1 -0
- package/dist/tool-icons.d.ts +5 -6
- package/dist/tool-icons.d.ts.map +1 -0
- package/dist/tool-icons.js +16 -4
- package/dist/tool-icons.js.map +7 -1
- package/dist/tool-search.d.ts +4 -5
- package/dist/tool-search.d.ts.map +1 -0
- package/dist/tool-search.js +3 -3
- package/dist/tool-search.js.map +7 -1
- package/dist/tool-summary.d.ts +4 -5
- package/dist/tool-summary.d.ts.map +1 -0
- package/dist/tool-summary.js +5 -3
- package/dist/tool-summary.js.map +7 -1
- package/dist/tool-use.d.ts +4 -5
- package/dist/tool-use.d.ts.map +1 -0
- package/dist/tool-use.js +3 -3
- package/dist/tool-use.js.map +7 -1
- package/dist/tree.d.ts +4 -5
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +11 -9
- package/dist/tree.js.map +7 -1
- package/dist/typecheck.d.ts +4 -5
- package/dist/typecheck.d.ts.map +1 -0
- package/dist/typecheck.js +2416 -28
- package/dist/typecheck.js.map +7 -1
- package/dist/write.d.ts +4 -5
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +21 -16
- package/dist/write.js.map +7 -1
- package/package.json +39 -6
- package/dist/background-indexer-BeDBxfSh.d.ts +0 -371
- package/dist/exec-2OKoT6tk.d.ts +0 -121
package/dist/test.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import * as path3 from 'node:path';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import * as Core from '@wrongstack/core';
|
|
4
|
-
import { buildChildEnv, expectDefined, wstackGlobalRoot } from '@wrongstack/core';
|
|
5
|
-
import * as fs from 'node:fs';
|
|
6
|
-
import { mkdirSync, createWriteStream } from 'node:fs';
|
|
7
|
-
import * as fsp from 'node:fs/promises';
|
|
8
|
-
import * as os from 'node:os';
|
|
9
|
-
|
|
10
1
|
// src/test.ts
|
|
2
|
+
import * as path9 from "node:path";
|
|
3
|
+
|
|
4
|
+
// src/_spawn-stream.ts
|
|
5
|
+
import { spawn as spawn2 } from "node:child_process";
|
|
6
|
+
import { buildChildEnv } from "@wrongstack/core";
|
|
7
|
+
|
|
8
|
+
// src/_output-spool.ts
|
|
9
|
+
import { createWriteStream, mkdirSync } from "node:fs";
|
|
10
|
+
import * as fsp from "node:fs/promises";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import { wstackGlobalRoot } from "@wrongstack/core";
|
|
11
13
|
var SPOOL_RETENTION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
12
14
|
var SPOOL_WRITE_HWM_BYTES = 4 * 1024 * 1024;
|
|
13
15
|
var sweepStarted = false;
|
|
14
16
|
function toolOutputDir() {
|
|
15
|
-
return
|
|
17
|
+
return path.join(wstackGlobalRoot(), "tool-output");
|
|
16
18
|
}
|
|
17
19
|
function sweepOldSpoolFiles(dir) {
|
|
18
20
|
if (sweepStarted) return;
|
|
@@ -22,7 +24,7 @@ function sweepOldSpoolFiles(dir) {
|
|
|
22
24
|
const now = Date.now();
|
|
23
25
|
for (const name of await fsp.readdir(dir)) {
|
|
24
26
|
if (!name.endsWith(".log")) continue;
|
|
25
|
-
const p =
|
|
27
|
+
const p = path.join(dir, name);
|
|
26
28
|
try {
|
|
27
29
|
const st = await fsp.stat(p);
|
|
28
30
|
if (now - st.mtimeMs > SPOOL_RETENTION_MS) await fsp.unlink(p);
|
|
@@ -39,7 +41,7 @@ function spoolNote(info) {
|
|
|
39
41
|
[output truncated \u2014 full ${info.bytes} bytes at ${info.path}${dropped}; read/grep that file selectively instead of re-running with more output]`;
|
|
40
42
|
}
|
|
41
43
|
function createOutputSpool(opts) {
|
|
42
|
-
const threshold = opts.thresholdBytes;
|
|
44
|
+
const threshold = opts.thresholdBytes ?? 32768;
|
|
43
45
|
const safeTool = opts.tool.replace(/[^a-zA-Z0-9._-]+/g, "_").slice(0, 40) || "tool";
|
|
44
46
|
let head = "";
|
|
45
47
|
let headBytes = 0;
|
|
@@ -57,7 +59,7 @@ function createOutputSpool(opts) {
|
|
|
57
59
|
sweepOldSpoolFiles(dir);
|
|
58
60
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
59
61
|
const rand = Math.random().toString(36).slice(2, 6);
|
|
60
|
-
filePath =
|
|
62
|
+
filePath = path.join(dir, `${stamp}-${safeTool}-${rand}.log`);
|
|
61
63
|
stream = createWriteStream(filePath, { flags: "w", encoding: "utf8" });
|
|
62
64
|
stream.on("error", () => {
|
|
63
65
|
failed = true;
|
|
@@ -110,6 +112,10 @@ function createOutputSpool(opts) {
|
|
|
110
112
|
};
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
// src/process-registry.ts
|
|
116
|
+
import { spawn } from "node:child_process";
|
|
117
|
+
import * as os from "node:os";
|
|
118
|
+
|
|
113
119
|
// src/circuit-breaker.ts
|
|
114
120
|
var DEFAULT_MAX_CONSECUTIVE_FAILURES = 5;
|
|
115
121
|
var DEFAULT_SLOW_CALL_THRESHOLD_MS = 18e4;
|
|
@@ -302,7 +308,8 @@ var CircuitBreaker = class {
|
|
|
302
308
|
}
|
|
303
309
|
};
|
|
304
310
|
|
|
305
|
-
// src/
|
|
311
|
+
// src/_redact-command.ts
|
|
312
|
+
import { expectDefined } from "@wrongstack/core";
|
|
306
313
|
var SENSITIVE_FLAG_PATTERNS = [
|
|
307
314
|
// --flag=value or --flag "value" (value captured up to next space or comma)
|
|
308
315
|
/--(?:token|password|passwd|pwd|secret|api[-_]?key|api[-_]?secret|auth|credential|private[-_]?key|access[-_]?key|github[-_]?token|gh[-_]?token|bearer|jwt|oauth|pin|pincode|passphrase|access[-_]?token)(?:[=\s,][^\s]*)?/gi,
|
|
@@ -332,6 +339,8 @@ function redactCommand(cmd) {
|
|
|
332
339
|
}
|
|
333
340
|
return result;
|
|
334
341
|
}
|
|
342
|
+
|
|
343
|
+
// src/process-registry.ts
|
|
335
344
|
var DEFAULT_GRACE_MS = 2e3;
|
|
336
345
|
var WIN32_TASKKILL_TIMEOUT_MS = 5e3;
|
|
337
346
|
function killWin32Tree(pid, opts = {}) {
|
|
@@ -601,7 +610,8 @@ var ProcessRegistryImpl = class {
|
|
|
601
610
|
if (liveRealChild && killWin32Tree(pid, {
|
|
602
611
|
timeoutMs: Math.max(graceMs, WIN32_TASKKILL_TIMEOUT_MS),
|
|
603
612
|
onSettled: directFallback
|
|
604
|
-
}))
|
|
613
|
+
})) {
|
|
614
|
+
} else {
|
|
605
615
|
try {
|
|
606
616
|
p.child.kill(force ? "SIGKILL" : "SIGTERM");
|
|
607
617
|
} catch {
|
|
@@ -688,15 +698,19 @@ function getProcessRegistry() {
|
|
|
688
698
|
}
|
|
689
699
|
return _registry;
|
|
690
700
|
}
|
|
701
|
+
|
|
702
|
+
// src/_win32-resolve.ts
|
|
703
|
+
import * as fs from "node:fs";
|
|
704
|
+
import * as path2 from "node:path";
|
|
691
705
|
function resolveWin32Command(cmd) {
|
|
692
706
|
if (process.platform !== "win32") return cmd;
|
|
693
|
-
if (cmd.includes("/") || cmd.includes("\\") ||
|
|
707
|
+
if (cmd.includes("/") || cmd.includes("\\") || path2.extname(cmd.replace(/\//g, "\\"))) {
|
|
694
708
|
return cmd;
|
|
695
709
|
}
|
|
696
710
|
const pathext = (process.env["PATHEXT"] ?? ".COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC").toLowerCase().split(";");
|
|
697
|
-
const pathDirs = (process.env["PATH"] ?? "").split(
|
|
711
|
+
const pathDirs = (process.env["PATH"] ?? "").split(path2.delimiter);
|
|
698
712
|
for (const dir of pathDirs) {
|
|
699
|
-
const base =
|
|
713
|
+
const base = path2.join(dir, cmd);
|
|
700
714
|
for (const ext of pathext) {
|
|
701
715
|
const full = `${base}${ext}`;
|
|
702
716
|
try {
|
|
@@ -734,7 +748,7 @@ function quoteWin32CmdArg(arg) {
|
|
|
734
748
|
// src/_spawn-stream.ts
|
|
735
749
|
var isWin = process.platform === "win32";
|
|
736
750
|
async function* spawnStream(opts) {
|
|
737
|
-
const max = opts.maxBytes;
|
|
751
|
+
const max = opts.maxBytes ?? 2e5;
|
|
738
752
|
const flushAt = opts.flushBytes ?? 4 * 1024;
|
|
739
753
|
const maxQueue = opts.maxQueueSize ?? 500;
|
|
740
754
|
let stdout = "";
|
|
@@ -747,7 +761,7 @@ async function* spawnStream(opts) {
|
|
|
747
761
|
const shim = needsShell ? buildWin32CmdShimInvocation(resolved, opts.args) : null;
|
|
748
762
|
const cmd = shim?.command ?? resolved;
|
|
749
763
|
const args = shim?.args ?? opts.args;
|
|
750
|
-
const child =
|
|
764
|
+
const child = spawn2(cmd, args, {
|
|
751
765
|
cwd: opts.cwd,
|
|
752
766
|
env: buildChildEnv(),
|
|
753
767
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -840,8 +854,8 @@ async function* spawnStream(opts) {
|
|
|
840
854
|
try {
|
|
841
855
|
for (; ; ) {
|
|
842
856
|
while (queue.length === 0) {
|
|
843
|
-
await new Promise((
|
|
844
|
-
waiter =
|
|
857
|
+
await new Promise((resolve6) => {
|
|
858
|
+
waiter = resolve6;
|
|
845
859
|
});
|
|
846
860
|
}
|
|
847
861
|
const chunk = queue.shift();
|
|
@@ -895,6 +909,10 @@ async function* spawnStream(opts) {
|
|
|
895
909
|
}
|
|
896
910
|
}
|
|
897
911
|
}
|
|
912
|
+
|
|
913
|
+
// src/_util.ts
|
|
914
|
+
import * as path3 from "node:path";
|
|
915
|
+
import * as Core from "@wrongstack/core";
|
|
898
916
|
function resolvePath(input, ctx) {
|
|
899
917
|
return path3.isAbsolute(input) ? path3.normalize(input) : path3.resolve(ctx.workingDir ?? ctx.cwd, input);
|
|
900
918
|
}
|
|
@@ -987,6 +1005,2356 @@ function normalizeCommandOutput(raw, opts = {}) {
|
|
|
987
1005
|
return truncateHeadTail(text, opts.maxBytes ?? COMMAND_OUTPUT_MAX_BYTES);
|
|
988
1006
|
}
|
|
989
1007
|
|
|
1008
|
+
// src/languages/legacy-bridge.ts
|
|
1009
|
+
import * as fs5 from "node:fs/promises";
|
|
1010
|
+
import * as path8 from "node:path";
|
|
1011
|
+
|
|
1012
|
+
// src/languages/detect.ts
|
|
1013
|
+
import { createHash } from "node:crypto";
|
|
1014
|
+
import * as fs2 from "node:fs/promises";
|
|
1015
|
+
import * as path4 from "node:path";
|
|
1016
|
+
|
|
1017
|
+
// src/languages/profile-helpers.ts
|
|
1018
|
+
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
1019
|
+
var DEFAULT_OUTPUT_LIMIT_BYTES = 2e5;
|
|
1020
|
+
function processPlan(ctx, operation, command, args, options) {
|
|
1021
|
+
return {
|
|
1022
|
+
profileId: ctx.workspace.language,
|
|
1023
|
+
workspaceId: ctx.workspace.id,
|
|
1024
|
+
operation,
|
|
1025
|
+
kind: "process",
|
|
1026
|
+
command,
|
|
1027
|
+
args: Object.freeze([...args]),
|
|
1028
|
+
cwd: ctx.workspace.root,
|
|
1029
|
+
env: Object.freeze({}),
|
|
1030
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
1031
|
+
outputLimitBytes: DEFAULT_OUTPUT_LIMIT_BYTES,
|
|
1032
|
+
mutating: options.mutating ?? false,
|
|
1033
|
+
network: options.network ?? false,
|
|
1034
|
+
executesProjectCode: options.executesProjectCode ?? false,
|
|
1035
|
+
reason: options.reason,
|
|
1036
|
+
evidence: ctx.workspace.evidence,
|
|
1037
|
+
parser: options.parser
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
function internalPlan(ctx, operation, parser, reason) {
|
|
1041
|
+
return {
|
|
1042
|
+
profileId: ctx.workspace.language,
|
|
1043
|
+
workspaceId: ctx.workspace.id,
|
|
1044
|
+
operation,
|
|
1045
|
+
kind: "internal",
|
|
1046
|
+
command: null,
|
|
1047
|
+
args: Object.freeze([]),
|
|
1048
|
+
cwd: ctx.workspace.root,
|
|
1049
|
+
env: Object.freeze({}),
|
|
1050
|
+
timeoutMs: 5e3,
|
|
1051
|
+
outputLimitBytes: 32768,
|
|
1052
|
+
mutating: false,
|
|
1053
|
+
network: false,
|
|
1054
|
+
executesProjectCode: false,
|
|
1055
|
+
reason,
|
|
1056
|
+
evidence: ctx.workspace.evidence,
|
|
1057
|
+
parser
|
|
1058
|
+
};
|
|
1059
|
+
}
|
|
1060
|
+
function unavailable(ctx, operation, reason) {
|
|
1061
|
+
return {
|
|
1062
|
+
status: "unavailable",
|
|
1063
|
+
profileId: ctx.workspace.language,
|
|
1064
|
+
workspaceId: ctx.workspace.id,
|
|
1065
|
+
operation,
|
|
1066
|
+
reason
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
function packageNames(ctx) {
|
|
1070
|
+
return ctx.options.packages ?? [];
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// src/languages/profiles/additional.ts
|
|
1074
|
+
var IGNORES = Object.freeze([
|
|
1075
|
+
".git",
|
|
1076
|
+
".wrongstack",
|
|
1077
|
+
"node_modules",
|
|
1078
|
+
"vendor",
|
|
1079
|
+
"dist",
|
|
1080
|
+
"build",
|
|
1081
|
+
"coverage"
|
|
1082
|
+
]);
|
|
1083
|
+
function pythonProfile() {
|
|
1084
|
+
return {
|
|
1085
|
+
id: "python",
|
|
1086
|
+
displayName: "Python",
|
|
1087
|
+
extensions: Object.freeze([".py", ".pyi"]),
|
|
1088
|
+
lspLanguageIds: Object.freeze(["python"]),
|
|
1089
|
+
detectors: Object.freeze([
|
|
1090
|
+
{ kind: "config", filename: "pyproject.toml", weight: 90 },
|
|
1091
|
+
{ kind: "config", filename: "setup.py", weight: 70 },
|
|
1092
|
+
{ kind: "config", filename: "setup.cfg", weight: 60 },
|
|
1093
|
+
{ kind: "manifest", filename: "requirements.txt", weight: 55 },
|
|
1094
|
+
{ kind: "manifest", filename: "Pipfile", weight: 50 },
|
|
1095
|
+
{ kind: "lockfile", filename: "poetry.lock", weight: 30 },
|
|
1096
|
+
{ kind: "lockfile", filename: "Pipfile.lock", weight: 30 },
|
|
1097
|
+
{ kind: "lockfile", filename: "uv.lock", weight: 30 }
|
|
1098
|
+
]),
|
|
1099
|
+
ignoredDirectories: IGNORES,
|
|
1100
|
+
packageManagers: Object.freeze(["pip", "poetry", "pipenv", "uv"]),
|
|
1101
|
+
executables: Object.freeze(["python", "python3", "ruff", "black", "pytest", "mypy", "pyright"]),
|
|
1102
|
+
operations: Object.freeze({
|
|
1103
|
+
syntax: async (ctx) => {
|
|
1104
|
+
const py = ctx.options.target ? "python3" : "python3";
|
|
1105
|
+
return ctx.options.target ? processPlan(ctx, "syntax", py, ["-m", "py_compile", ctx.options.target], {
|
|
1106
|
+
parser: "python",
|
|
1107
|
+
reason: "Compile the target file to check for syntax errors."
|
|
1108
|
+
}) : unavailable(ctx, "syntax", "Python syntax check requires an explicit target file.");
|
|
1109
|
+
},
|
|
1110
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "mypy", [".", "--no-error-summary"], {
|
|
1111
|
+
parser: "mypy",
|
|
1112
|
+
reason: "Run mypy type checking on the workspace.",
|
|
1113
|
+
executesProjectCode: true
|
|
1114
|
+
}),
|
|
1115
|
+
lint: async (ctx) => processPlan(ctx, "lint", "ruff", ["check", "."], {
|
|
1116
|
+
parser: "ruff",
|
|
1117
|
+
reason: "Run the Ruff linter on the workspace."
|
|
1118
|
+
}),
|
|
1119
|
+
"format-check": async (ctx) => processPlan(ctx, "format-check", "ruff", ["format", "--check", "."], {
|
|
1120
|
+
parser: "ruff",
|
|
1121
|
+
reason: "Check Python formatting without writing files."
|
|
1122
|
+
}),
|
|
1123
|
+
"format-write": async (ctx) => processPlan(ctx, "format-write", "ruff", ["format", "."], {
|
|
1124
|
+
parser: "ruff",
|
|
1125
|
+
reason: "Format Python source files.",
|
|
1126
|
+
mutating: true
|
|
1127
|
+
}),
|
|
1128
|
+
test: async (ctx) => processPlan(
|
|
1129
|
+
ctx,
|
|
1130
|
+
"test",
|
|
1131
|
+
"pytest",
|
|
1132
|
+
[...ctx.options.filter ? ["-k", ctx.options.filter] : [], "."],
|
|
1133
|
+
{
|
|
1134
|
+
parser: "pytest",
|
|
1135
|
+
reason: ctx.options.filter ? "Run filtered Python tests." : "Run all Python tests.",
|
|
1136
|
+
mutating: true,
|
|
1137
|
+
executesProjectCode: true
|
|
1138
|
+
}
|
|
1139
|
+
),
|
|
1140
|
+
build: async (ctx) => unavailable(ctx, "build", "Python is interpreted; use semantic or test instead."),
|
|
1141
|
+
"debug-compile": async (ctx) => processPlan(ctx, "debug-compile", "mypy", [".", "--no-error-summary"], {
|
|
1142
|
+
parser: "mypy",
|
|
1143
|
+
reason: "Collect mypy type diagnostics.",
|
|
1144
|
+
executesProjectCode: true
|
|
1145
|
+
}),
|
|
1146
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "pip", ["install", "--no-cache-dir"], {
|
|
1147
|
+
parser: "package-text",
|
|
1148
|
+
reason: "Install dependencies from requirements.",
|
|
1149
|
+
mutating: true,
|
|
1150
|
+
network: true
|
|
1151
|
+
}),
|
|
1152
|
+
"package-add": async (ctx) => {
|
|
1153
|
+
const names = packageNames(ctx);
|
|
1154
|
+
return names.length === 0 ? unavailable(ctx, "package-add", "At least one package name is required.") : processPlan(ctx, "package-add", "pip", ["install", ...names], {
|
|
1155
|
+
parser: "package-text",
|
|
1156
|
+
reason: "Install specified Python packages.",
|
|
1157
|
+
mutating: true,
|
|
1158
|
+
network: true
|
|
1159
|
+
});
|
|
1160
|
+
},
|
|
1161
|
+
"package-audit": async (ctx) => processPlan(ctx, "package-audit", "pip", ["audit"], {
|
|
1162
|
+
parser: "pip-audit",
|
|
1163
|
+
reason: "Audit Python dependencies for vulnerabilities.",
|
|
1164
|
+
network: true
|
|
1165
|
+
}),
|
|
1166
|
+
run: async (ctx) => {
|
|
1167
|
+
const entries = ["main.py", "app.py", "__main__.py", "manage.py"];
|
|
1168
|
+
const first = (await Promise.all(
|
|
1169
|
+
entries.map((name) => ctx.pathExists(name).then((ok) => ok ? name : void 0))
|
|
1170
|
+
)).find(Boolean);
|
|
1171
|
+
const args = first ? [first] : [];
|
|
1172
|
+
return processPlan(ctx, "run", "python3", args, {
|
|
1173
|
+
parser: "command-text",
|
|
1174
|
+
reason: first ? `Run the Python entry point ${first}.` : "Run the Python project (no common entry point detected \u2014 add the module path manually).",
|
|
1175
|
+
executesProjectCode: true,
|
|
1176
|
+
mutating: true
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
})
|
|
1180
|
+
};
|
|
1181
|
+
}
|
|
1182
|
+
function hasGradleEvidence(ctx) {
|
|
1183
|
+
return ctx.workspace.evidence.some(
|
|
1184
|
+
(e) => e.kind === "manifest" && (e.value === "build.gradle" || e.value === "build.gradle.kts" || e.value === "settings.gradle") || e.kind === "lockfile" && e.value === "gradle.lockfile"
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
async function gradleRunner(ctx) {
|
|
1188
|
+
if (await ctx.pathExists("gradlew")) return "gradlew";
|
|
1189
|
+
return "gradle";
|
|
1190
|
+
}
|
|
1191
|
+
function javaProfile() {
|
|
1192
|
+
return {
|
|
1193
|
+
id: "java",
|
|
1194
|
+
displayName: "Java / Kotlin",
|
|
1195
|
+
extensions: Object.freeze([".java", ".kt", ".kts", ".scala"]),
|
|
1196
|
+
lspLanguageIds: Object.freeze(["java", "kotlin"]),
|
|
1197
|
+
detectors: Object.freeze([
|
|
1198
|
+
{ kind: "manifest", filename: "pom.xml", weight: 90 },
|
|
1199
|
+
{ kind: "manifest", filename: "build.gradle", weight: 85 },
|
|
1200
|
+
{ kind: "manifest", filename: "build.gradle.kts", weight: 85 },
|
|
1201
|
+
{ kind: "manifest", filename: "settings.gradle", weight: 50 },
|
|
1202
|
+
{ kind: "lockfile", filename: "gradle.lockfile", weight: 30 }
|
|
1203
|
+
]),
|
|
1204
|
+
ignoredDirectories: IGNORES,
|
|
1205
|
+
packageManagers: Object.freeze(["maven", "gradle"]),
|
|
1206
|
+
executables: Object.freeze(["mvn", "gradle", "gradlew", "java", "kotlinc"]),
|
|
1207
|
+
operations: Object.freeze({
|
|
1208
|
+
semantic: async (ctx) => {
|
|
1209
|
+
const isGradle = hasGradleEvidence(ctx);
|
|
1210
|
+
const runner = isGradle ? await gradleRunner(ctx) : "mvn";
|
|
1211
|
+
const args = isGradle ? ["compileJava"] : ["compile", "-q"];
|
|
1212
|
+
const reason = isGradle ? "Compile the Gradle project." : "Compile the Maven project.";
|
|
1213
|
+
return processPlan(ctx, "semantic", runner, args, {
|
|
1214
|
+
parser: isGradle ? "gradle" : "maven",
|
|
1215
|
+
reason,
|
|
1216
|
+
mutating: true,
|
|
1217
|
+
executesProjectCode: true
|
|
1218
|
+
});
|
|
1219
|
+
},
|
|
1220
|
+
lint: async (ctx) => unavailable(
|
|
1221
|
+
ctx,
|
|
1222
|
+
"lint",
|
|
1223
|
+
"Java linting requires a configured checkstyle or spotbugs plugin."
|
|
1224
|
+
),
|
|
1225
|
+
"format-check": async (ctx) => unavailable(
|
|
1226
|
+
ctx,
|
|
1227
|
+
"format-check",
|
|
1228
|
+
"Java formatting check requires a configured spotless or google-java-format plugin."
|
|
1229
|
+
),
|
|
1230
|
+
test: async (ctx) => {
|
|
1231
|
+
const isGradle = hasGradleEvidence(ctx);
|
|
1232
|
+
const runner = isGradle ? await gradleRunner(ctx) : "mvn";
|
|
1233
|
+
const args = isGradle ? ["test"] : ["test", "-q"];
|
|
1234
|
+
const reason = isGradle ? "Run Gradle tests." : "Run Maven tests.";
|
|
1235
|
+
return processPlan(ctx, "test", runner, args, {
|
|
1236
|
+
parser: isGradle ? "gradle" : "maven",
|
|
1237
|
+
reason,
|
|
1238
|
+
mutating: true,
|
|
1239
|
+
executesProjectCode: true
|
|
1240
|
+
});
|
|
1241
|
+
},
|
|
1242
|
+
build: async (ctx) => {
|
|
1243
|
+
const isGradle = hasGradleEvidence(ctx);
|
|
1244
|
+
const runner = isGradle ? await gradleRunner(ctx) : "mvn";
|
|
1245
|
+
const args = isGradle ? ["build"] : ["package", "-q", "-DskipTests"];
|
|
1246
|
+
const reason = isGradle ? "Build the Gradle project." : "Build the Maven project, skipping tests.";
|
|
1247
|
+
return processPlan(ctx, "build", runner, args, {
|
|
1248
|
+
parser: isGradle ? "gradle" : "maven",
|
|
1249
|
+
reason,
|
|
1250
|
+
mutating: true,
|
|
1251
|
+
executesProjectCode: true
|
|
1252
|
+
});
|
|
1253
|
+
},
|
|
1254
|
+
run: async (ctx) => {
|
|
1255
|
+
if (!hasGradleEvidence(ctx))
|
|
1256
|
+
return unavailable(
|
|
1257
|
+
ctx,
|
|
1258
|
+
"run",
|
|
1259
|
+
"Maven run requires exec-maven-plugin configuration. Use `mvn exec:java -q` manually."
|
|
1260
|
+
);
|
|
1261
|
+
const runner = await gradleRunner(ctx);
|
|
1262
|
+
return processPlan(ctx, "run", runner, ["run"], {
|
|
1263
|
+
parser: "command-text",
|
|
1264
|
+
reason: `Run the Gradle project entry point via ${runner}.`,
|
|
1265
|
+
executesProjectCode: true,
|
|
1266
|
+
mutating: true
|
|
1267
|
+
});
|
|
1268
|
+
},
|
|
1269
|
+
"package-install": async (ctx) => unavailable(
|
|
1270
|
+
ctx,
|
|
1271
|
+
"package-install",
|
|
1272
|
+
"JVM dependency installation happens through build or dependency:get."
|
|
1273
|
+
),
|
|
1274
|
+
"package-add": async (ctx) => {
|
|
1275
|
+
const names = packageNames(ctx);
|
|
1276
|
+
return names.length === 0 ? unavailable(ctx, "package-add", "At least one dependency coordinate is required.") : processPlan(ctx, "package-add", "mvn", ["dependency:get", `-Dartifact=${names[0]}`], {
|
|
1277
|
+
parser: "maven",
|
|
1278
|
+
reason: "Resolve and fetch a Maven dependency.",
|
|
1279
|
+
mutating: true,
|
|
1280
|
+
network: true
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
})
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1286
|
+
function rubyProfile() {
|
|
1287
|
+
return {
|
|
1288
|
+
id: "ruby",
|
|
1289
|
+
displayName: "Ruby",
|
|
1290
|
+
extensions: Object.freeze([".rb"]),
|
|
1291
|
+
lspLanguageIds: Object.freeze(["ruby"]),
|
|
1292
|
+
detectors: Object.freeze([
|
|
1293
|
+
{ kind: "manifest", filename: "Gemfile", weight: 90 },
|
|
1294
|
+
{ kind: "config", filename: ".ruby-version", weight: 40 },
|
|
1295
|
+
{ kind: "lockfile", filename: "Gemfile.lock", weight: 30 }
|
|
1296
|
+
]),
|
|
1297
|
+
ignoredDirectories: IGNORES,
|
|
1298
|
+
packageManagers: Object.freeze(["gem", "bundler"]),
|
|
1299
|
+
executables: Object.freeze(["ruby", "gem", "bundle", "rubocop", "rspec"]),
|
|
1300
|
+
operations: Object.freeze({
|
|
1301
|
+
syntax: async (ctx) => ctx.options.target ? processPlan(ctx, "syntax", "ruby", ["-c", ctx.options.target], {
|
|
1302
|
+
parser: "ruby",
|
|
1303
|
+
reason: "Check the target Ruby file for syntax errors."
|
|
1304
|
+
}) : unavailable(ctx, "syntax", "Ruby syntax check requires an explicit target file."),
|
|
1305
|
+
lint: async (ctx) => processPlan(ctx, "lint", "rubocop", ["--format=json"], {
|
|
1306
|
+
parser: "rubocop",
|
|
1307
|
+
reason: "Run RuboCop linter.",
|
|
1308
|
+
executesProjectCode: true
|
|
1309
|
+
}),
|
|
1310
|
+
"format-write": async (ctx) => processPlan(ctx, "format-write", "rubocop", ["--auto-correct"], {
|
|
1311
|
+
parser: "rubocop",
|
|
1312
|
+
reason: "Auto-correct RuboCop violations.",
|
|
1313
|
+
mutating: true,
|
|
1314
|
+
executesProjectCode: true
|
|
1315
|
+
}),
|
|
1316
|
+
test: async (ctx) => processPlan(ctx, "test", "rspec", [], {
|
|
1317
|
+
parser: "rspec",
|
|
1318
|
+
reason: "Run the RSpec test suite.",
|
|
1319
|
+
mutating: true,
|
|
1320
|
+
executesProjectCode: true
|
|
1321
|
+
}),
|
|
1322
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "bundle", ["install"], {
|
|
1323
|
+
parser: "package-text",
|
|
1324
|
+
reason: "Install Ruby gem dependencies.",
|
|
1325
|
+
mutating: true,
|
|
1326
|
+
network: true,
|
|
1327
|
+
executesProjectCode: true
|
|
1328
|
+
}),
|
|
1329
|
+
"package-add": async (ctx) => {
|
|
1330
|
+
const names = packageNames(ctx);
|
|
1331
|
+
return names.length === 0 ? unavailable(ctx, "package-add", "At least one gem name is required.") : processPlan(ctx, "package-add", "gem", ["install", ...names], {
|
|
1332
|
+
parser: "package-text",
|
|
1333
|
+
reason: "Install specified Ruby gems.",
|
|
1334
|
+
mutating: true,
|
|
1335
|
+
network: true
|
|
1336
|
+
});
|
|
1337
|
+
},
|
|
1338
|
+
"package-audit": async (ctx) => processPlan(ctx, "package-audit", "bundle", ["audit", "--format=json"], {
|
|
1339
|
+
parser: "bundler-audit",
|
|
1340
|
+
reason: "Audit Ruby gems for vulnerabilities.",
|
|
1341
|
+
network: true
|
|
1342
|
+
}),
|
|
1343
|
+
run: async (ctx) => {
|
|
1344
|
+
const entries = ["main.rb", "app.rb", "server.rb", "config.ru"];
|
|
1345
|
+
const first = (await Promise.all(
|
|
1346
|
+
entries.map((name) => ctx.pathExists(name).then((ok) => ok ? name : void 0))
|
|
1347
|
+
)).find(Boolean);
|
|
1348
|
+
const hasGemfile = await ctx.pathExists("Gemfile");
|
|
1349
|
+
const cmd = hasGemfile ? "bundle" : "ruby";
|
|
1350
|
+
const args = hasGemfile ? ["exec", "ruby", first ?? ""] : [first ?? ""];
|
|
1351
|
+
return processPlan(ctx, "run", cmd, args, {
|
|
1352
|
+
parser: "command-text",
|
|
1353
|
+
reason: first ? `Run the Ruby entry point ${first}.` : "Run the Ruby project (no common entry point detected \u2014 add the file path manually).",
|
|
1354
|
+
executesProjectCode: true,
|
|
1355
|
+
mutating: true
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
})
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
function cProfile() {
|
|
1362
|
+
return {
|
|
1363
|
+
id: "c",
|
|
1364
|
+
displayName: "C / C++",
|
|
1365
|
+
extensions: Object.freeze([".c", ".h"]),
|
|
1366
|
+
lspLanguageIds: Object.freeze(["c"]),
|
|
1367
|
+
detectors: Object.freeze([
|
|
1368
|
+
{ kind: "manifest", filename: "CMakeLists.txt", weight: 85 },
|
|
1369
|
+
{ kind: "manifest", filename: "Makefile", weight: 60 },
|
|
1370
|
+
{ kind: "config", suffix: ".cmake", weight: 50 }
|
|
1371
|
+
]),
|
|
1372
|
+
ignoredDirectories: IGNORES,
|
|
1373
|
+
packageManagers: Object.freeze([]),
|
|
1374
|
+
executables: Object.freeze(["cc", "gcc", "clang", "cmake", "make"]),
|
|
1375
|
+
operations: Object.freeze({
|
|
1376
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "cmake", ["--build", ".", "--target", "all"], {
|
|
1377
|
+
parser: "cmake",
|
|
1378
|
+
reason: "Build C project to collect compiler diagnostics.",
|
|
1379
|
+
mutating: true,
|
|
1380
|
+
executesProjectCode: true
|
|
1381
|
+
}),
|
|
1382
|
+
test: async (ctx) => unavailable(
|
|
1383
|
+
ctx,
|
|
1384
|
+
"test",
|
|
1385
|
+
"C test execution requires a configured test runner (ctest, etc.)."
|
|
1386
|
+
),
|
|
1387
|
+
build: async (ctx) => processPlan(ctx, "build", "cmake", ["--build", "."], {
|
|
1388
|
+
parser: "cmake",
|
|
1389
|
+
reason: "Build the C project.",
|
|
1390
|
+
mutating: true,
|
|
1391
|
+
executesProjectCode: true
|
|
1392
|
+
})
|
|
1393
|
+
})
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
function cppProfile() {
|
|
1397
|
+
return {
|
|
1398
|
+
...cProfile(),
|
|
1399
|
+
id: "cpp",
|
|
1400
|
+
displayName: "C++",
|
|
1401
|
+
extensions: Object.freeze([".cpp", ".cc", ".cxx", ".hpp", ".hxx"]),
|
|
1402
|
+
lspLanguageIds: Object.freeze(["cpp"]),
|
|
1403
|
+
detectors: Object.freeze([
|
|
1404
|
+
{ kind: "manifest", filename: "CMakeLists.txt", weight: 85 },
|
|
1405
|
+
{ kind: "manifest", filename: "Makefile", weight: 50 }
|
|
1406
|
+
]),
|
|
1407
|
+
executables: Object.freeze(["c++", "g++", "clang++", "cmake", "make"])
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
function swiftProfile() {
|
|
1411
|
+
return {
|
|
1412
|
+
id: "swift",
|
|
1413
|
+
displayName: "Swift",
|
|
1414
|
+
extensions: Object.freeze([".swift"]),
|
|
1415
|
+
lspLanguageIds: Object.freeze(["swift"]),
|
|
1416
|
+
detectors: Object.freeze([{ kind: "manifest", filename: "Package.swift", weight: 90 }]),
|
|
1417
|
+
ignoredDirectories: IGNORES,
|
|
1418
|
+
packageManagers: Object.freeze(["swift"]),
|
|
1419
|
+
executables: Object.freeze(["swift", "swiftc"]),
|
|
1420
|
+
operations: Object.freeze({
|
|
1421
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "swift", ["build"], {
|
|
1422
|
+
parser: "swift",
|
|
1423
|
+
reason: "Build Swift package to collect compiler diagnostics.",
|
|
1424
|
+
mutating: true,
|
|
1425
|
+
executesProjectCode: true
|
|
1426
|
+
}),
|
|
1427
|
+
test: async (ctx) => processPlan(ctx, "test", "swift", ["test"], {
|
|
1428
|
+
parser: "swift-test",
|
|
1429
|
+
reason: "Run Swift tests.",
|
|
1430
|
+
mutating: true,
|
|
1431
|
+
executesProjectCode: true
|
|
1432
|
+
}),
|
|
1433
|
+
build: async (ctx) => processPlan(ctx, "build", "swift", ["build", "-c", "release"], {
|
|
1434
|
+
parser: "swift",
|
|
1435
|
+
reason: "Build the Swift package in release mode.",
|
|
1436
|
+
mutating: true,
|
|
1437
|
+
executesProjectCode: true
|
|
1438
|
+
}),
|
|
1439
|
+
run: async (ctx) => processPlan(ctx, "run", "swift", ["run"], {
|
|
1440
|
+
parser: "command-text",
|
|
1441
|
+
reason: "Run the Swift package entry point.",
|
|
1442
|
+
executesProjectCode: true
|
|
1443
|
+
})
|
|
1444
|
+
})
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1447
|
+
function dartProfile() {
|
|
1448
|
+
return {
|
|
1449
|
+
id: "dart",
|
|
1450
|
+
displayName: "Dart / Flutter",
|
|
1451
|
+
extensions: Object.freeze([".dart"]),
|
|
1452
|
+
lspLanguageIds: Object.freeze(["dart"]),
|
|
1453
|
+
detectors: Object.freeze([
|
|
1454
|
+
{ kind: "manifest", filename: "pubspec.yaml", weight: 90 },
|
|
1455
|
+
{ kind: "lockfile", filename: "pubspec.lock", weight: 30 }
|
|
1456
|
+
]),
|
|
1457
|
+
ignoredDirectories: IGNORES,
|
|
1458
|
+
packageManagers: Object.freeze(["pub"]),
|
|
1459
|
+
executables: Object.freeze(["dart", "flutter"]),
|
|
1460
|
+
operations: Object.freeze({
|
|
1461
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "dart", ["analyze"], {
|
|
1462
|
+
parser: "dart-analyze",
|
|
1463
|
+
reason: "Run Dart static analysis."
|
|
1464
|
+
}),
|
|
1465
|
+
"format-check": async (ctx) => processPlan(
|
|
1466
|
+
ctx,
|
|
1467
|
+
"format-check",
|
|
1468
|
+
"dart",
|
|
1469
|
+
["format", "--output=none", "--set-exit-if-changed", "."],
|
|
1470
|
+
{
|
|
1471
|
+
parser: "dart-format",
|
|
1472
|
+
reason: "Check Dart formatting without writing files."
|
|
1473
|
+
}
|
|
1474
|
+
),
|
|
1475
|
+
"format-write": async (ctx) => processPlan(ctx, "format-write", "dart", ["format", "."], {
|
|
1476
|
+
parser: "dart-format",
|
|
1477
|
+
reason: "Format Dart source files.",
|
|
1478
|
+
mutating: true
|
|
1479
|
+
}),
|
|
1480
|
+
test: async (ctx) => processPlan(ctx, "test", "dart", ["test"], {
|
|
1481
|
+
parser: "dart-test",
|
|
1482
|
+
reason: "Run Dart tests.",
|
|
1483
|
+
mutating: true,
|
|
1484
|
+
executesProjectCode: true
|
|
1485
|
+
}),
|
|
1486
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "dart", ["pub", "get"], {
|
|
1487
|
+
parser: "package-text",
|
|
1488
|
+
reason: "Fetch Dart package dependencies.",
|
|
1489
|
+
mutating: true,
|
|
1490
|
+
network: true
|
|
1491
|
+
}),
|
|
1492
|
+
"package-outdated": async (ctx) => processPlan(ctx, "package-outdated", "dart", ["pub", "outdated"], {
|
|
1493
|
+
parser: "dart-outdated",
|
|
1494
|
+
reason: "Check for outdated Dart packages.",
|
|
1495
|
+
network: true
|
|
1496
|
+
}),
|
|
1497
|
+
run: async (ctx) => processPlan(ctx, "run", "dart", ["run"], {
|
|
1498
|
+
parser: "command-text",
|
|
1499
|
+
reason: "Run the Dart / Flutter project entry point.",
|
|
1500
|
+
executesProjectCode: true
|
|
1501
|
+
})
|
|
1502
|
+
})
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
function denoProfile() {
|
|
1506
|
+
return {
|
|
1507
|
+
id: "deno",
|
|
1508
|
+
displayName: "Deno",
|
|
1509
|
+
extensions: Object.freeze([".ts", ".tsx", ".js", ".jsx"]),
|
|
1510
|
+
lspLanguageIds: Object.freeze(["typescript", "javascript"]),
|
|
1511
|
+
detectors: Object.freeze([
|
|
1512
|
+
{ kind: "config", filename: "deno.json", weight: 90 },
|
|
1513
|
+
{ kind: "config", filename: "deno.jsonc", weight: 90 },
|
|
1514
|
+
{ kind: "config", filename: "import_map.json", weight: 60 }
|
|
1515
|
+
]),
|
|
1516
|
+
ignoredDirectories: IGNORES,
|
|
1517
|
+
packageManagers: Object.freeze([]),
|
|
1518
|
+
executables: Object.freeze(["deno"]),
|
|
1519
|
+
// .ts/.js extensions are shared with the TypeScript/JavaScript profiles;
|
|
1520
|
+
// only a deno.json(c)/import_map.json detector hit may establish a workspace.
|
|
1521
|
+
sourceFallback: false,
|
|
1522
|
+
operations: Object.freeze({
|
|
1523
|
+
test: async (ctx) => processPlan(ctx, "test", "deno", ["test"], {
|
|
1524
|
+
parser: "deno-test",
|
|
1525
|
+
reason: "Run Deno tests.",
|
|
1526
|
+
mutating: true,
|
|
1527
|
+
executesProjectCode: true
|
|
1528
|
+
}),
|
|
1529
|
+
run: async (ctx) => processPlan(ctx, "run", "deno", ["run", "--allow-all", "main.ts"], {
|
|
1530
|
+
parser: "command-text",
|
|
1531
|
+
reason: "Run the Deno project entry point with full permission.",
|
|
1532
|
+
executesProjectCode: true,
|
|
1533
|
+
mutating: true
|
|
1534
|
+
})
|
|
1535
|
+
})
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
function elixirProfile() {
|
|
1539
|
+
return {
|
|
1540
|
+
id: "elixir",
|
|
1541
|
+
displayName: "Elixir",
|
|
1542
|
+
extensions: Object.freeze([".ex", ".exs"]),
|
|
1543
|
+
lspLanguageIds: Object.freeze(["elixir"]),
|
|
1544
|
+
detectors: Object.freeze([
|
|
1545
|
+
{ kind: "manifest", filename: "mix.exs", weight: 90 },
|
|
1546
|
+
{ kind: "lockfile", filename: "mix.lock", weight: 30 }
|
|
1547
|
+
]),
|
|
1548
|
+
ignoredDirectories: IGNORES,
|
|
1549
|
+
packageManagers: Object.freeze(["mix"]),
|
|
1550
|
+
executables: Object.freeze(["mix", "elixir"]),
|
|
1551
|
+
operations: Object.freeze({
|
|
1552
|
+
semantic: async (ctx) => unavailable(ctx, "semantic", "Elixir compilation is handled by the build operation."),
|
|
1553
|
+
lint: async (ctx) => unavailable(ctx, "lint", "Elixir linting requires the credo package."),
|
|
1554
|
+
test: async (ctx) => processPlan(ctx, "test", "mix", ["test"], {
|
|
1555
|
+
parser: "mix-test",
|
|
1556
|
+
reason: "Run ExUnit tests.",
|
|
1557
|
+
mutating: true,
|
|
1558
|
+
executesProjectCode: true
|
|
1559
|
+
}),
|
|
1560
|
+
build: async (ctx) => processPlan(ctx, "build", "mix", ["compile"], {
|
|
1561
|
+
parser: "mix",
|
|
1562
|
+
reason: "Compile the Mix project.",
|
|
1563
|
+
mutating: true,
|
|
1564
|
+
executesProjectCode: true
|
|
1565
|
+
}),
|
|
1566
|
+
run: async (ctx) => processPlan(ctx, "run", "mix", ["run"], {
|
|
1567
|
+
parser: "command-text",
|
|
1568
|
+
reason: "Run the Mix project entry point.",
|
|
1569
|
+
executesProjectCode: true
|
|
1570
|
+
}),
|
|
1571
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "mix", ["deps.get"], {
|
|
1572
|
+
parser: "package-text",
|
|
1573
|
+
reason: "Fetch Elixir dependencies.",
|
|
1574
|
+
mutating: true,
|
|
1575
|
+
network: true
|
|
1576
|
+
})
|
|
1577
|
+
})
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
function shellProfile() {
|
|
1581
|
+
return {
|
|
1582
|
+
id: "shell",
|
|
1583
|
+
displayName: "Shell",
|
|
1584
|
+
extensions: Object.freeze([".sh", ".bash"]),
|
|
1585
|
+
lspLanguageIds: Object.freeze(["shellscript"]),
|
|
1586
|
+
detectors: Object.freeze([{ kind: "config", filename: "ShellCheckrc", weight: 50 }]),
|
|
1587
|
+
ignoredDirectories: IGNORES,
|
|
1588
|
+
packageManagers: Object.freeze([]),
|
|
1589
|
+
executables: Object.freeze(["bash", "sh", "shellcheck", "shfmt"]),
|
|
1590
|
+
operations: Object.freeze({
|
|
1591
|
+
syntax: async (ctx) => ctx.options.target ? processPlan(ctx, "syntax", "bash", ["-n", ctx.options.target], {
|
|
1592
|
+
parser: "shell",
|
|
1593
|
+
reason: "Check the shell script for syntax errors."
|
|
1594
|
+
}) : unavailable(ctx, "syntax", "Shell syntax check requires an explicit target file."),
|
|
1595
|
+
lint: async (ctx) => ctx.options.target ? processPlan(ctx, "lint", "shellcheck", ["--format=json", ctx.options.target], {
|
|
1596
|
+
parser: "shellcheck",
|
|
1597
|
+
reason: "Run ShellCheck on the target script."
|
|
1598
|
+
}) : unavailable(ctx, "lint", "Shell linting requires an explicit target file."),
|
|
1599
|
+
"format-check": async (ctx) => ctx.options.target ? processPlan(ctx, "format-check", "shfmt", ["-d", ctx.options.target], {
|
|
1600
|
+
parser: "shell",
|
|
1601
|
+
reason: "Check shell formatting without writing."
|
|
1602
|
+
}) : unavailable(
|
|
1603
|
+
ctx,
|
|
1604
|
+
"format-check",
|
|
1605
|
+
"Shell formatting check requires an explicit target file."
|
|
1606
|
+
),
|
|
1607
|
+
"format-write": async (ctx) => ctx.options.target ? processPlan(ctx, "format-write", "shfmt", ["-w", ctx.options.target], {
|
|
1608
|
+
parser: "shell",
|
|
1609
|
+
reason: "Format the shell script.",
|
|
1610
|
+
mutating: true
|
|
1611
|
+
}) : unavailable(ctx, "format-write", "Shell formatting requires an explicit target file.")
|
|
1612
|
+
})
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
var ADDITIONAL_LANGUAGE_PROFILES = Object.freeze([
|
|
1616
|
+
pythonProfile(),
|
|
1617
|
+
javaProfile(),
|
|
1618
|
+
rubyProfile(),
|
|
1619
|
+
cProfile(),
|
|
1620
|
+
cppProfile(),
|
|
1621
|
+
swiftProfile(),
|
|
1622
|
+
dartProfile(),
|
|
1623
|
+
denoProfile(),
|
|
1624
|
+
elixirProfile(),
|
|
1625
|
+
shellProfile()
|
|
1626
|
+
]);
|
|
1627
|
+
|
|
1628
|
+
// src/languages/profiles/primary.ts
|
|
1629
|
+
var COMMON_IGNORES = Object.freeze([
|
|
1630
|
+
".git",
|
|
1631
|
+
".wrongstack",
|
|
1632
|
+
"node_modules",
|
|
1633
|
+
"vendor",
|
|
1634
|
+
"target",
|
|
1635
|
+
"bin",
|
|
1636
|
+
"obj",
|
|
1637
|
+
"dist",
|
|
1638
|
+
"build",
|
|
1639
|
+
"coverage"
|
|
1640
|
+
]);
|
|
1641
|
+
function nodeManager(ctx) {
|
|
1642
|
+
const lockfiles = new Set(
|
|
1643
|
+
ctx.workspace.evidence.filter((evidence) => evidence.kind === "lockfile").map((evidence) => evidence.value.toLowerCase())
|
|
1644
|
+
);
|
|
1645
|
+
if (lockfiles.size > 1 && !ctx.workspace.packageManager) return void 0;
|
|
1646
|
+
return ctx.workspace.packageManager ?? "npm";
|
|
1647
|
+
}
|
|
1648
|
+
function scriptPlan(ctx, operation, script) {
|
|
1649
|
+
const manager = nodeManager(ctx);
|
|
1650
|
+
if (!manager)
|
|
1651
|
+
return unavailable(
|
|
1652
|
+
ctx,
|
|
1653
|
+
operation,
|
|
1654
|
+
"Conflicting Node lockfiles make the package manager ambiguous."
|
|
1655
|
+
);
|
|
1656
|
+
const args = manager === "npm" ? ["run", script] : [script];
|
|
1657
|
+
return processPlan(ctx, operation, manager, args, {
|
|
1658
|
+
parser: "command-text",
|
|
1659
|
+
reason: `Run the detected ${manager} ${script} script for this workspace.`,
|
|
1660
|
+
mutating: true,
|
|
1661
|
+
executesProjectCode: true
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
function nodeExec(ctx, executable, args) {
|
|
1665
|
+
const manager = ctx.workspace.packageManager ?? "npm";
|
|
1666
|
+
if (manager === "pnpm") return { command: "pnpm", args: ["exec", executable, ...args] };
|
|
1667
|
+
if (manager === "yarn") return { command: "yarn", args: ["exec", executable, ...args] };
|
|
1668
|
+
if (manager === "bun") return { command: "bun", args: ["x", executable, ...args] };
|
|
1669
|
+
return { command: "npx", args: ["--no-install", executable, ...args] };
|
|
1670
|
+
}
|
|
1671
|
+
function typescriptProfile() {
|
|
1672
|
+
return {
|
|
1673
|
+
id: "typescript",
|
|
1674
|
+
displayName: "TypeScript",
|
|
1675
|
+
extensions: Object.freeze([".ts", ".tsx", ".mts", ".cts"]),
|
|
1676
|
+
lspLanguageIds: Object.freeze(["typescript", "typescriptreact"]),
|
|
1677
|
+
detectors: Object.freeze([
|
|
1678
|
+
{ kind: "config", filename: "tsconfig.json", weight: 90 },
|
|
1679
|
+
{ kind: "manifest", filename: "package.json", weight: 55 },
|
|
1680
|
+
{ kind: "lockfile", filename: "pnpm-lock.yaml", weight: 30 },
|
|
1681
|
+
{ kind: "lockfile", filename: "yarn.lock", weight: 30 },
|
|
1682
|
+
{ kind: "lockfile", filename: "package-lock.json", weight: 30 },
|
|
1683
|
+
{ kind: "lockfile", filename: "bun.lock", weight: 30 },
|
|
1684
|
+
{ kind: "lockfile", filename: "bun.lockb", weight: 30 }
|
|
1685
|
+
]),
|
|
1686
|
+
ignoredDirectories: COMMON_IGNORES,
|
|
1687
|
+
packageManagers: Object.freeze(["pnpm", "yarn", "bun", "npm"]),
|
|
1688
|
+
executables: Object.freeze(["pnpm", "yarn", "bun", "npx", "npm"]),
|
|
1689
|
+
operations: Object.freeze({
|
|
1690
|
+
syntax: async (ctx) => internalPlan(
|
|
1691
|
+
ctx,
|
|
1692
|
+
"syntax",
|
|
1693
|
+
"typescript-parser",
|
|
1694
|
+
"Parse the target with the TypeScript compiler API."
|
|
1695
|
+
),
|
|
1696
|
+
semantic: async (ctx) => {
|
|
1697
|
+
const run = nodeExec(ctx, "tsc", ["--noEmit", "--pretty", "false"]);
|
|
1698
|
+
return processPlan(ctx, "semantic", run.command, run.args, {
|
|
1699
|
+
parser: "typescript",
|
|
1700
|
+
reason: "Run the workspace TypeScript compiler without emitting files.",
|
|
1701
|
+
executesProjectCode: true
|
|
1702
|
+
});
|
|
1703
|
+
},
|
|
1704
|
+
lint: async (ctx) => {
|
|
1705
|
+
const run = nodeExec(ctx, "biome", ["lint", "."]);
|
|
1706
|
+
return processPlan(ctx, "lint", run.command, run.args, {
|
|
1707
|
+
parser: "biome",
|
|
1708
|
+
reason: "Run the project-local Biome linter.",
|
|
1709
|
+
executesProjectCode: true
|
|
1710
|
+
});
|
|
1711
|
+
},
|
|
1712
|
+
"format-check": async (ctx) => {
|
|
1713
|
+
const run = nodeExec(ctx, "biome", ["format", "--check", "."]);
|
|
1714
|
+
return processPlan(ctx, "format-check", run.command, run.args, {
|
|
1715
|
+
parser: "biome",
|
|
1716
|
+
reason: "Check formatting with the project-local Biome formatter.",
|
|
1717
|
+
executesProjectCode: true
|
|
1718
|
+
});
|
|
1719
|
+
},
|
|
1720
|
+
"format-write": async (ctx) => {
|
|
1721
|
+
const run = nodeExec(ctx, "biome", ["format", "--write", "."]);
|
|
1722
|
+
return processPlan(ctx, "format-write", run.command, run.args, {
|
|
1723
|
+
parser: "biome",
|
|
1724
|
+
reason: "Format the workspace with the project-local Biome formatter.",
|
|
1725
|
+
mutating: true,
|
|
1726
|
+
executesProjectCode: true
|
|
1727
|
+
});
|
|
1728
|
+
},
|
|
1729
|
+
test: async (ctx) => ctx.options.filter || ctx.options.coverage ? unavailable(
|
|
1730
|
+
ctx,
|
|
1731
|
+
"test",
|
|
1732
|
+
"The detected package script does not expose deterministic filter or coverage adapters."
|
|
1733
|
+
) : scriptPlan(ctx, "test", "test"),
|
|
1734
|
+
build: async (ctx) => scriptPlan(ctx, "build", "build"),
|
|
1735
|
+
run: async (ctx) => scriptPlan(ctx, "run", "dev"),
|
|
1736
|
+
"debug-compile": async (ctx) => {
|
|
1737
|
+
const run = nodeExec(ctx, "tsc", ["--noEmit", "--pretty", "false"]);
|
|
1738
|
+
return processPlan(ctx, "debug-compile", run.command, run.args, {
|
|
1739
|
+
parser: "typescript",
|
|
1740
|
+
reason: "Collect deterministic TypeScript compiler diagnostics.",
|
|
1741
|
+
executesProjectCode: true
|
|
1742
|
+
});
|
|
1743
|
+
},
|
|
1744
|
+
"package-install": async (ctx) => {
|
|
1745
|
+
const manager = ctx.workspace.packageManager ?? "npm";
|
|
1746
|
+
const args = manager === "yarn" ? ["install", "--ignore-scripts"] : ["install", "--ignore-scripts"];
|
|
1747
|
+
return processPlan(ctx, "package-install", manager, args, {
|
|
1748
|
+
parser: "package-text",
|
|
1749
|
+
reason: `Restore declared dependencies with ${manager} and lifecycle scripts disabled.`,
|
|
1750
|
+
mutating: true,
|
|
1751
|
+
network: true,
|
|
1752
|
+
executesProjectCode: false
|
|
1753
|
+
});
|
|
1754
|
+
},
|
|
1755
|
+
"package-add": async (ctx) => {
|
|
1756
|
+
const names = packageNames(ctx);
|
|
1757
|
+
if (names.length === 0)
|
|
1758
|
+
return unavailable(ctx, "package-add", "At least one package name is required.");
|
|
1759
|
+
const manager = ctx.workspace.packageManager ?? "npm";
|
|
1760
|
+
const args = manager === "npm" ? ["install", "--ignore-scripts", ...names] : ["add", "--ignore-scripts", ...names];
|
|
1761
|
+
return processPlan(ctx, "package-add", manager, args, {
|
|
1762
|
+
parser: "package-text",
|
|
1763
|
+
reason: `Add validated packages with ${manager} and lifecycle scripts disabled.`,
|
|
1764
|
+
mutating: true,
|
|
1765
|
+
network: true
|
|
1766
|
+
});
|
|
1767
|
+
},
|
|
1768
|
+
"package-audit": async (ctx) => {
|
|
1769
|
+
const manager = ctx.workspace.packageManager ?? "npm";
|
|
1770
|
+
return processPlan(ctx, "package-audit", manager, ["audit", "--json"], {
|
|
1771
|
+
parser: "npm-audit",
|
|
1772
|
+
reason: `Audit dependencies with the detected ${manager} package manager.`,
|
|
1773
|
+
network: true
|
|
1774
|
+
});
|
|
1775
|
+
},
|
|
1776
|
+
"package-outdated": async (ctx) => {
|
|
1777
|
+
const manager = ctx.workspace.packageManager ?? "npm";
|
|
1778
|
+
return processPlan(ctx, "package-outdated", manager, ["outdated", "--json"], {
|
|
1779
|
+
parser: "npm-outdated",
|
|
1780
|
+
reason: `Check outdated dependencies with ${manager}.`,
|
|
1781
|
+
network: true
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
})
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
function javascriptProfile() {
|
|
1788
|
+
const ts = typescriptProfile();
|
|
1789
|
+
return {
|
|
1790
|
+
...ts,
|
|
1791
|
+
id: "javascript",
|
|
1792
|
+
displayName: "JavaScript",
|
|
1793
|
+
extensions: Object.freeze([".js", ".jsx", ".mjs", ".cjs"]),
|
|
1794
|
+
lspLanguageIds: Object.freeze(["javascript", "javascriptreact"]),
|
|
1795
|
+
detectors: Object.freeze([
|
|
1796
|
+
{ kind: "config", filename: "jsconfig.json", weight: 90 },
|
|
1797
|
+
{ kind: "manifest", filename: "package.json", weight: 70 },
|
|
1798
|
+
{ kind: "lockfile", filename: "pnpm-lock.yaml", weight: 30 },
|
|
1799
|
+
{ kind: "lockfile", filename: "yarn.lock", weight: 30 },
|
|
1800
|
+
{ kind: "lockfile", filename: "package-lock.json", weight: 30 },
|
|
1801
|
+
{ kind: "lockfile", filename: "bun.lock", weight: 30 },
|
|
1802
|
+
{ kind: "lockfile", filename: "bun.lockb", weight: 30 }
|
|
1803
|
+
]),
|
|
1804
|
+
operations: Object.freeze({
|
|
1805
|
+
...ts.operations,
|
|
1806
|
+
syntax: async (ctx) => internalPlan(
|
|
1807
|
+
ctx,
|
|
1808
|
+
"syntax",
|
|
1809
|
+
"typescript-parser",
|
|
1810
|
+
"Parse JavaScript with the TypeScript compiler API."
|
|
1811
|
+
)
|
|
1812
|
+
})
|
|
1813
|
+
};
|
|
1814
|
+
}
|
|
1815
|
+
var goProfile = {
|
|
1816
|
+
id: "go",
|
|
1817
|
+
displayName: "Go",
|
|
1818
|
+
extensions: Object.freeze([".go"]),
|
|
1819
|
+
lspLanguageIds: Object.freeze(["go"]),
|
|
1820
|
+
detectors: Object.freeze([
|
|
1821
|
+
{ kind: "manifest", filename: "go.mod", weight: 90 },
|
|
1822
|
+
{ kind: "manifest", filename: "go.work", weight: 95 },
|
|
1823
|
+
{ kind: "lockfile", filename: "go.sum", weight: 30 }
|
|
1824
|
+
]),
|
|
1825
|
+
ignoredDirectories: COMMON_IGNORES,
|
|
1826
|
+
packageManagers: Object.freeze(["go"]),
|
|
1827
|
+
executables: Object.freeze(["go", "gofmt"]),
|
|
1828
|
+
operations: Object.freeze({
|
|
1829
|
+
syntax: async (ctx) => {
|
|
1830
|
+
if (!ctx.target)
|
|
1831
|
+
return unavailable(ctx, "syntax", "Go syntax planning requires a target file.");
|
|
1832
|
+
return processPlan(ctx, "syntax", "gofmt", ["-e", "-d", ctx.target], {
|
|
1833
|
+
parser: "gofmt",
|
|
1834
|
+
reason: "Parse the target and report syntax errors without writing it."
|
|
1835
|
+
});
|
|
1836
|
+
},
|
|
1837
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "go", ["test", "-run", "^$", "./..."], {
|
|
1838
|
+
parser: "go-test",
|
|
1839
|
+
reason: "Compile all Go packages without selecting tests.",
|
|
1840
|
+
mutating: true,
|
|
1841
|
+
executesProjectCode: true
|
|
1842
|
+
}),
|
|
1843
|
+
lint: async (ctx) => processPlan(ctx, "lint", "go", ["vet", "./..."], {
|
|
1844
|
+
parser: "go-compiler",
|
|
1845
|
+
reason: "Run the standard Go vet checks.",
|
|
1846
|
+
mutating: true,
|
|
1847
|
+
executesProjectCode: true
|
|
1848
|
+
}),
|
|
1849
|
+
"format-check": async (ctx) => ctx.target ? processPlan(ctx, "format-check", "gofmt", ["-d", ctx.target], {
|
|
1850
|
+
parser: "gofmt",
|
|
1851
|
+
reason: "Report Go formatting differences for the target without writing it."
|
|
1852
|
+
}) : unavailable(ctx, "format-check", "Go formatting requires an explicit target file."),
|
|
1853
|
+
"format-write": async (ctx) => ctx.target ? processPlan(ctx, "format-write", "gofmt", ["-w", ctx.target], {
|
|
1854
|
+
parser: "gofmt",
|
|
1855
|
+
reason: "Format the target Go source file.",
|
|
1856
|
+
mutating: true
|
|
1857
|
+
}) : unavailable(ctx, "format-write", "Go formatting requires an explicit target file."),
|
|
1858
|
+
test: async (ctx) => processPlan(
|
|
1859
|
+
ctx,
|
|
1860
|
+
"test",
|
|
1861
|
+
"go",
|
|
1862
|
+
["test", ...ctx.options.filter ? ["-run", ctx.options.filter] : [], "./..."],
|
|
1863
|
+
{
|
|
1864
|
+
parser: "go-test",
|
|
1865
|
+
reason: ctx.options.filter ? "Run filtered Go tests." : "Run all Go tests.",
|
|
1866
|
+
mutating: true,
|
|
1867
|
+
executesProjectCode: true
|
|
1868
|
+
}
|
|
1869
|
+
),
|
|
1870
|
+
build: async (ctx) => processPlan(ctx, "build", "go", ["build", "./..."], {
|
|
1871
|
+
parser: "go-compiler",
|
|
1872
|
+
reason: "Build all Go packages.",
|
|
1873
|
+
mutating: true,
|
|
1874
|
+
executesProjectCode: true
|
|
1875
|
+
}),
|
|
1876
|
+
run: async (ctx) => processPlan(ctx, "run", "go", ["run", "."], {
|
|
1877
|
+
parser: "command-text",
|
|
1878
|
+
reason: "Run the Go module entry point.",
|
|
1879
|
+
executesProjectCode: true
|
|
1880
|
+
}),
|
|
1881
|
+
"debug-race": async (ctx) => processPlan(ctx, "debug-race", "go", ["test", "-race", "./..."], {
|
|
1882
|
+
parser: "go-test",
|
|
1883
|
+
reason: "Collect Go race-detector evidence.",
|
|
1884
|
+
mutating: true,
|
|
1885
|
+
executesProjectCode: true
|
|
1886
|
+
}),
|
|
1887
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "go", ["mod", "download"], {
|
|
1888
|
+
parser: "go-module",
|
|
1889
|
+
reason: "Download the dependencies declared by go.mod.",
|
|
1890
|
+
mutating: true,
|
|
1891
|
+
network: true
|
|
1892
|
+
}),
|
|
1893
|
+
"package-add": async (ctx) => {
|
|
1894
|
+
const names = packageNames(ctx);
|
|
1895
|
+
if (names.length === 0)
|
|
1896
|
+
return unavailable(ctx, "package-add", "At least one Go module is required.");
|
|
1897
|
+
return processPlan(ctx, "package-add", "go", ["get", ...names], {
|
|
1898
|
+
parser: "go-module",
|
|
1899
|
+
reason: "Add validated Go modules.",
|
|
1900
|
+
mutating: true,
|
|
1901
|
+
network: true
|
|
1902
|
+
});
|
|
1903
|
+
},
|
|
1904
|
+
"package-update": async (ctx) => processPlan(ctx, "package-update", "go", ["get", "-u", "./..."], {
|
|
1905
|
+
parser: "go-module",
|
|
1906
|
+
reason: "Update dependencies of all Go packages.",
|
|
1907
|
+
mutating: true,
|
|
1908
|
+
network: true
|
|
1909
|
+
})
|
|
1910
|
+
})
|
|
1911
|
+
};
|
|
1912
|
+
var rustProfile = {
|
|
1913
|
+
id: "rust",
|
|
1914
|
+
displayName: "Rust",
|
|
1915
|
+
extensions: Object.freeze([".rs"]),
|
|
1916
|
+
lspLanguageIds: Object.freeze(["rust"]),
|
|
1917
|
+
detectors: Object.freeze([
|
|
1918
|
+
{ kind: "manifest", filename: "Cargo.toml", weight: 90 },
|
|
1919
|
+
{ kind: "lockfile", filename: "Cargo.lock", weight: 30 }
|
|
1920
|
+
]),
|
|
1921
|
+
ignoredDirectories: COMMON_IGNORES,
|
|
1922
|
+
packageManagers: Object.freeze(["cargo"]),
|
|
1923
|
+
executables: Object.freeze(["cargo"]),
|
|
1924
|
+
operations: Object.freeze({
|
|
1925
|
+
syntax: async (ctx) => processPlan(ctx, "syntax", "cargo", ["check", "--message-format=json"], {
|
|
1926
|
+
parser: "cargo-json",
|
|
1927
|
+
reason: "Check Rust syntax and semantics with Cargo.",
|
|
1928
|
+
mutating: true,
|
|
1929
|
+
executesProjectCode: true
|
|
1930
|
+
}),
|
|
1931
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "cargo", ["check", "--message-format=json"], {
|
|
1932
|
+
parser: "cargo-json",
|
|
1933
|
+
reason: "Collect Rust compiler diagnostics with Cargo check.",
|
|
1934
|
+
mutating: true,
|
|
1935
|
+
executesProjectCode: true
|
|
1936
|
+
}),
|
|
1937
|
+
lint: async (ctx) => processPlan(ctx, "lint", "cargo", ["clippy", "--message-format=json"], {
|
|
1938
|
+
parser: "cargo-json",
|
|
1939
|
+
reason: "Run Clippy for this crate.",
|
|
1940
|
+
mutating: true,
|
|
1941
|
+
executesProjectCode: true
|
|
1942
|
+
}),
|
|
1943
|
+
"format-check": async (ctx) => processPlan(ctx, "format-check", "cargo", ["fmt", "--check"], {
|
|
1944
|
+
parser: "cargo-fmt",
|
|
1945
|
+
reason: "Check Rust formatting without writing files."
|
|
1946
|
+
}),
|
|
1947
|
+
"format-write": async (ctx) => processPlan(ctx, "format-write", "cargo", ["fmt"], {
|
|
1948
|
+
parser: "cargo-fmt",
|
|
1949
|
+
reason: "Format Rust source files in the workspace.",
|
|
1950
|
+
mutating: true
|
|
1951
|
+
}),
|
|
1952
|
+
"test-compile": async (ctx) => processPlan(ctx, "test-compile", "cargo", ["test", "--no-run", "--message-format=json"], {
|
|
1953
|
+
parser: "cargo-json",
|
|
1954
|
+
reason: "Compile Rust tests without running them.",
|
|
1955
|
+
mutating: true,
|
|
1956
|
+
executesProjectCode: true
|
|
1957
|
+
}),
|
|
1958
|
+
test: async (ctx) => processPlan(
|
|
1959
|
+
ctx,
|
|
1960
|
+
"test",
|
|
1961
|
+
"cargo",
|
|
1962
|
+
["test", ...ctx.options.filter ? [ctx.options.filter] : []],
|
|
1963
|
+
{
|
|
1964
|
+
parser: "cargo-test",
|
|
1965
|
+
reason: ctx.options.filter ? "Run filtered Rust tests." : "Run Rust tests.",
|
|
1966
|
+
mutating: true,
|
|
1967
|
+
executesProjectCode: true
|
|
1968
|
+
}
|
|
1969
|
+
),
|
|
1970
|
+
build: async (ctx) => processPlan(ctx, "build", "cargo", ["build", "--message-format=json"], {
|
|
1971
|
+
parser: "cargo-json",
|
|
1972
|
+
reason: "Build the Rust workspace.",
|
|
1973
|
+
mutating: true,
|
|
1974
|
+
executesProjectCode: true
|
|
1975
|
+
}),
|
|
1976
|
+
run: async (ctx) => processPlan(ctx, "run", "cargo", ["run"], {
|
|
1977
|
+
parser: "command-text",
|
|
1978
|
+
reason: "Run the Rust workspace entry point.",
|
|
1979
|
+
executesProjectCode: true
|
|
1980
|
+
}),
|
|
1981
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "cargo", ["fetch", "--locked"], {
|
|
1982
|
+
parser: "cargo-json",
|
|
1983
|
+
reason: "Fetch locked Rust dependencies.",
|
|
1984
|
+
mutating: true,
|
|
1985
|
+
network: true
|
|
1986
|
+
}),
|
|
1987
|
+
"package-add": async (ctx) => {
|
|
1988
|
+
const names = packageNames(ctx);
|
|
1989
|
+
return names.length === 0 ? unavailable(ctx, "package-add", "At least one crate is required.") : processPlan(ctx, "package-add", "cargo", ["add", ...names], {
|
|
1990
|
+
parser: "cargo-text",
|
|
1991
|
+
reason: "Add validated Rust crates.",
|
|
1992
|
+
mutating: true,
|
|
1993
|
+
network: true
|
|
1994
|
+
});
|
|
1995
|
+
},
|
|
1996
|
+
"package-remove": async (ctx) => {
|
|
1997
|
+
const names = packageNames(ctx);
|
|
1998
|
+
return names.length === 0 ? unavailable(ctx, "package-remove", "At least one crate is required.") : processPlan(ctx, "package-remove", "cargo", ["remove", ...names], {
|
|
1999
|
+
parser: "cargo-text",
|
|
2000
|
+
reason: "Remove validated Rust crates.",
|
|
2001
|
+
mutating: true
|
|
2002
|
+
});
|
|
2003
|
+
},
|
|
2004
|
+
"package-update": async (ctx) => processPlan(ctx, "package-update", "cargo", ["update"], {
|
|
2005
|
+
parser: "cargo-text",
|
|
2006
|
+
reason: "Update the Cargo lockfile.",
|
|
2007
|
+
mutating: true,
|
|
2008
|
+
network: true
|
|
2009
|
+
}),
|
|
2010
|
+
"package-audit": async (ctx) => processPlan(ctx, "package-audit", "cargo", ["audit", "--json"], {
|
|
2011
|
+
parser: "cargo-audit",
|
|
2012
|
+
reason: "Audit Rust dependencies when cargo-audit is installed.",
|
|
2013
|
+
network: true
|
|
2014
|
+
})
|
|
2015
|
+
})
|
|
2016
|
+
};
|
|
2017
|
+
var phpProfile = {
|
|
2018
|
+
id: "php",
|
|
2019
|
+
displayName: "PHP",
|
|
2020
|
+
extensions: Object.freeze([".php"]),
|
|
2021
|
+
lspLanguageIds: Object.freeze(["php"]),
|
|
2022
|
+
detectors: Object.freeze([
|
|
2023
|
+
{ kind: "manifest", filename: "composer.json", weight: 90 },
|
|
2024
|
+
{ kind: "lockfile", filename: "composer.lock", weight: 30 },
|
|
2025
|
+
{ kind: "config", filename: "phpunit.xml", weight: 25 },
|
|
2026
|
+
{ kind: "config", filename: "phpunit.xml.dist", weight: 25 }
|
|
2027
|
+
]),
|
|
2028
|
+
ignoredDirectories: COMMON_IGNORES,
|
|
2029
|
+
packageManagers: Object.freeze(["composer"]),
|
|
2030
|
+
executables: Object.freeze(["php", "composer"]),
|
|
2031
|
+
operations: Object.freeze({
|
|
2032
|
+
syntax: async (ctx) => ctx.target ? processPlan(ctx, "syntax", "php", ["-l", ctx.target], {
|
|
2033
|
+
parser: "php-lint",
|
|
2034
|
+
reason: "Lint the target PHP file without executing it."
|
|
2035
|
+
}) : unavailable(ctx, "syntax", "PHP syntax planning requires a target file."),
|
|
2036
|
+
semantic: async (ctx) => unavailable(
|
|
2037
|
+
ctx,
|
|
2038
|
+
"semantic",
|
|
2039
|
+
"No configured PHPStan or Psalm adapter was detected in Phase 1."
|
|
2040
|
+
),
|
|
2041
|
+
test: async (ctx) => processPlan(
|
|
2042
|
+
ctx,
|
|
2043
|
+
"test",
|
|
2044
|
+
"php",
|
|
2045
|
+
["vendor/bin/phpunit", ...ctx.options.filter ? ["--filter", ctx.options.filter] : []],
|
|
2046
|
+
{
|
|
2047
|
+
parser: "phpunit",
|
|
2048
|
+
reason: ctx.options.filter ? "Run filtered tests with the project-local PHPUnit runner." : "Run the project-local PHPUnit test runner.",
|
|
2049
|
+
executesProjectCode: true
|
|
2050
|
+
}
|
|
2051
|
+
),
|
|
2052
|
+
"package-install": async (ctx) => processPlan(
|
|
2053
|
+
ctx,
|
|
2054
|
+
"package-install",
|
|
2055
|
+
"composer",
|
|
2056
|
+
["install", "--no-interaction", "--no-scripts"],
|
|
2057
|
+
{
|
|
2058
|
+
parser: "composer",
|
|
2059
|
+
reason: "Restore Composer dependencies without scripts.",
|
|
2060
|
+
mutating: true,
|
|
2061
|
+
network: true
|
|
2062
|
+
}
|
|
2063
|
+
),
|
|
2064
|
+
"package-add": async (ctx) => {
|
|
2065
|
+
const names = packageNames(ctx);
|
|
2066
|
+
return names.length === 0 ? unavailable(ctx, "package-add", "At least one Composer package is required.") : processPlan(
|
|
2067
|
+
ctx,
|
|
2068
|
+
"package-add",
|
|
2069
|
+
"composer",
|
|
2070
|
+
["require", "--no-interaction", "--no-scripts", ...names],
|
|
2071
|
+
{
|
|
2072
|
+
parser: "composer",
|
|
2073
|
+
reason: "Add validated Composer packages without scripts.",
|
|
2074
|
+
mutating: true,
|
|
2075
|
+
network: true
|
|
2076
|
+
}
|
|
2077
|
+
);
|
|
2078
|
+
},
|
|
2079
|
+
"package-remove": async (ctx) => {
|
|
2080
|
+
const names = packageNames(ctx);
|
|
2081
|
+
return names.length === 0 ? unavailable(ctx, "package-remove", "At least one Composer package is required.") : processPlan(
|
|
2082
|
+
ctx,
|
|
2083
|
+
"package-remove",
|
|
2084
|
+
"composer",
|
|
2085
|
+
["remove", "--no-interaction", "--no-scripts", ...names],
|
|
2086
|
+
{
|
|
2087
|
+
parser: "composer",
|
|
2088
|
+
reason: "Remove validated Composer packages without scripts.",
|
|
2089
|
+
mutating: true
|
|
2090
|
+
}
|
|
2091
|
+
);
|
|
2092
|
+
},
|
|
2093
|
+
"package-update": async (ctx) => processPlan(
|
|
2094
|
+
ctx,
|
|
2095
|
+
"package-update",
|
|
2096
|
+
"composer",
|
|
2097
|
+
["update", "--no-interaction", "--no-scripts"],
|
|
2098
|
+
{
|
|
2099
|
+
parser: "composer",
|
|
2100
|
+
reason: "Update Composer dependencies without scripts.",
|
|
2101
|
+
mutating: true,
|
|
2102
|
+
network: true
|
|
2103
|
+
}
|
|
2104
|
+
),
|
|
2105
|
+
"package-audit": async (ctx) => processPlan(ctx, "package-audit", "composer", ["audit", "--format=json"], {
|
|
2106
|
+
parser: "composer-audit",
|
|
2107
|
+
reason: "Audit Composer dependencies.",
|
|
2108
|
+
network: true
|
|
2109
|
+
}),
|
|
2110
|
+
"package-outdated": async (ctx) => processPlan(ctx, "package-outdated", "composer", ["outdated", "--format=json"], {
|
|
2111
|
+
parser: "composer-outdated",
|
|
2112
|
+
reason: "Check outdated Composer dependencies.",
|
|
2113
|
+
network: true
|
|
2114
|
+
})
|
|
2115
|
+
})
|
|
2116
|
+
};
|
|
2117
|
+
var csharpProfile = {
|
|
2118
|
+
id: "csharp",
|
|
2119
|
+
displayName: "C# / .NET",
|
|
2120
|
+
extensions: Object.freeze([".cs"]),
|
|
2121
|
+
lspLanguageIds: Object.freeze(["csharp"]),
|
|
2122
|
+
detectors: Object.freeze([
|
|
2123
|
+
{ kind: "config", filename: "global.json", weight: 25 },
|
|
2124
|
+
{ kind: "manifest", suffix: ".slnx", weight: 95 },
|
|
2125
|
+
{ kind: "manifest", suffix: ".sln", weight: 95 },
|
|
2126
|
+
{ kind: "manifest", suffix: ".csproj", weight: 90 },
|
|
2127
|
+
{ kind: "manifest", suffix: ".fsproj", weight: 90 },
|
|
2128
|
+
{ kind: "lockfile", filename: "packages.lock.json", weight: 30 }
|
|
2129
|
+
]),
|
|
2130
|
+
ignoredDirectories: COMMON_IGNORES,
|
|
2131
|
+
packageManagers: Object.freeze(["dotnet"]),
|
|
2132
|
+
executables: Object.freeze(["dotnet"]),
|
|
2133
|
+
operations: Object.freeze({
|
|
2134
|
+
syntax: async (ctx) => processPlan(ctx, "syntax", "dotnet", ["build", "--no-restore"], {
|
|
2135
|
+
parser: "dotnet-build",
|
|
2136
|
+
reason: "Use the nearest project or solution to collect C# syntax diagnostics.",
|
|
2137
|
+
mutating: true,
|
|
2138
|
+
executesProjectCode: true
|
|
2139
|
+
}),
|
|
2140
|
+
semantic: async (ctx) => processPlan(ctx, "semantic", "dotnet", ["build", "--no-restore"], {
|
|
2141
|
+
parser: "dotnet-build",
|
|
2142
|
+
reason: "Build without restoring to collect .NET compiler diagnostics.",
|
|
2143
|
+
mutating: true,
|
|
2144
|
+
executesProjectCode: true
|
|
2145
|
+
}),
|
|
2146
|
+
lint: async (ctx) => processPlan(ctx, "lint", "dotnet", ["format", "--verify-no-changes", "--no-restore"], {
|
|
2147
|
+
parser: "dotnet-format",
|
|
2148
|
+
reason: "Verify .NET formatting and analyzers without writing source files.",
|
|
2149
|
+
mutating: true,
|
|
2150
|
+
executesProjectCode: true
|
|
2151
|
+
}),
|
|
2152
|
+
"format-check": async (ctx) => processPlan(
|
|
2153
|
+
ctx,
|
|
2154
|
+
"format-check",
|
|
2155
|
+
"dotnet",
|
|
2156
|
+
["format", "--verify-no-changes", "--no-restore"],
|
|
2157
|
+
{
|
|
2158
|
+
parser: "dotnet-format",
|
|
2159
|
+
reason: "Verify .NET formatting without source writes.",
|
|
2160
|
+
mutating: true,
|
|
2161
|
+
executesProjectCode: true
|
|
2162
|
+
}
|
|
2163
|
+
),
|
|
2164
|
+
"format-write": async (ctx) => processPlan(ctx, "format-write", "dotnet", ["format", "--no-restore"], {
|
|
2165
|
+
parser: "dotnet-format",
|
|
2166
|
+
reason: "Format .NET source files without restoring packages.",
|
|
2167
|
+
mutating: true,
|
|
2168
|
+
executesProjectCode: true
|
|
2169
|
+
}),
|
|
2170
|
+
test: async (ctx) => processPlan(
|
|
2171
|
+
ctx,
|
|
2172
|
+
"test",
|
|
2173
|
+
"dotnet",
|
|
2174
|
+
["test", "--no-restore", ...ctx.options.filter ? ["--filter", ctx.options.filter] : []],
|
|
2175
|
+
{
|
|
2176
|
+
parser: "dotnet-test",
|
|
2177
|
+
reason: ctx.options.filter ? "Run filtered .NET tests without restoring packages." : "Run .NET tests without restoring packages.",
|
|
2178
|
+
mutating: true,
|
|
2179
|
+
executesProjectCode: true
|
|
2180
|
+
}
|
|
2181
|
+
),
|
|
2182
|
+
build: async (ctx) => processPlan(ctx, "build", "dotnet", ["build", "--no-restore"], {
|
|
2183
|
+
parser: "dotnet-build",
|
|
2184
|
+
reason: "Build the nearest .NET project or solution without restoring packages.",
|
|
2185
|
+
mutating: true,
|
|
2186
|
+
executesProjectCode: true
|
|
2187
|
+
}),
|
|
2188
|
+
run: async (ctx) => processPlan(ctx, "run", "dotnet", ["run", "--no-restore"], {
|
|
2189
|
+
parser: "command-text",
|
|
2190
|
+
reason: "Run the .NET project entry point.",
|
|
2191
|
+
mutating: true,
|
|
2192
|
+
executesProjectCode: true
|
|
2193
|
+
}),
|
|
2194
|
+
"package-install": async (ctx) => processPlan(ctx, "package-install", "dotnet", ["restore", "--locked-mode"], {
|
|
2195
|
+
parser: "dotnet-restore",
|
|
2196
|
+
reason: "Restore locked .NET dependencies.",
|
|
2197
|
+
mutating: true,
|
|
2198
|
+
network: true,
|
|
2199
|
+
executesProjectCode: true
|
|
2200
|
+
}),
|
|
2201
|
+
"package-add": async (ctx) => {
|
|
2202
|
+
const names = packageNames(ctx);
|
|
2203
|
+
return names.length === 0 ? unavailable(ctx, "package-add", "At least one NuGet package is required.") : processPlan(ctx, "package-add", "dotnet", ["add", "package", ...names], {
|
|
2204
|
+
parser: "dotnet-package",
|
|
2205
|
+
reason: "Add validated NuGet packages.",
|
|
2206
|
+
mutating: true,
|
|
2207
|
+
network: true,
|
|
2208
|
+
executesProjectCode: true
|
|
2209
|
+
});
|
|
2210
|
+
},
|
|
2211
|
+
"package-remove": async (ctx) => {
|
|
2212
|
+
const names = packageNames(ctx);
|
|
2213
|
+
return names.length === 0 ? unavailable(ctx, "package-remove", "At least one NuGet package is required.") : processPlan(ctx, "package-remove", "dotnet", ["remove", "package", ...names], {
|
|
2214
|
+
parser: "dotnet-package",
|
|
2215
|
+
reason: "Remove validated NuGet packages.",
|
|
2216
|
+
mutating: true
|
|
2217
|
+
});
|
|
2218
|
+
},
|
|
2219
|
+
"package-audit": async (ctx) => processPlan(
|
|
2220
|
+
ctx,
|
|
2221
|
+
"package-audit",
|
|
2222
|
+
"dotnet",
|
|
2223
|
+
["list", "package", "--vulnerable", "--format", "json"],
|
|
2224
|
+
{ parser: "dotnet-package", reason: "List vulnerable NuGet dependencies.", network: true }
|
|
2225
|
+
),
|
|
2226
|
+
"package-outdated": async (ctx) => processPlan(
|
|
2227
|
+
ctx,
|
|
2228
|
+
"package-outdated",
|
|
2229
|
+
"dotnet",
|
|
2230
|
+
["list", "package", "--outdated", "--format", "json"],
|
|
2231
|
+
{ parser: "dotnet-package", reason: "List outdated NuGet dependencies.", network: true }
|
|
2232
|
+
)
|
|
2233
|
+
})
|
|
2234
|
+
};
|
|
2235
|
+
var PRIMARY_LANGUAGE_PROFILES = Object.freeze([
|
|
2236
|
+
Object.freeze(typescriptProfile()),
|
|
2237
|
+
Object.freeze(javascriptProfile()),
|
|
2238
|
+
Object.freeze(goProfile),
|
|
2239
|
+
Object.freeze(rustProfile),
|
|
2240
|
+
Object.freeze(phpProfile),
|
|
2241
|
+
Object.freeze(csharpProfile)
|
|
2242
|
+
]);
|
|
2243
|
+
|
|
2244
|
+
// src/languages/registry.ts
|
|
2245
|
+
var PROFILE_ID_RE = /^[a-z][a-z0-9-]{0,63}$/;
|
|
2246
|
+
var EXECUTABLE_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/;
|
|
2247
|
+
var KNOWN_OPERATIONS = /* @__PURE__ */ new Set([
|
|
2248
|
+
"syntax",
|
|
2249
|
+
"semantic",
|
|
2250
|
+
"lint",
|
|
2251
|
+
"format-check",
|
|
2252
|
+
"format-write",
|
|
2253
|
+
"test-compile",
|
|
2254
|
+
"test",
|
|
2255
|
+
"build",
|
|
2256
|
+
"run",
|
|
2257
|
+
"debug-compile",
|
|
2258
|
+
"debug-test",
|
|
2259
|
+
"debug-runtime",
|
|
2260
|
+
"debug-race",
|
|
2261
|
+
"package-install",
|
|
2262
|
+
"package-add",
|
|
2263
|
+
"package-remove",
|
|
2264
|
+
"package-update",
|
|
2265
|
+
"package-audit",
|
|
2266
|
+
"package-outdated"
|
|
2267
|
+
]);
|
|
2268
|
+
var LanguageProfileRegistry = class {
|
|
2269
|
+
#profiles = /* @__PURE__ */ new Map();
|
|
2270
|
+
constructor(profiles = []) {
|
|
2271
|
+
for (const profile of profiles) this.register(profile);
|
|
2272
|
+
}
|
|
2273
|
+
register(profile) {
|
|
2274
|
+
const errors = validateLanguageProfile(profile);
|
|
2275
|
+
if (errors.length > 0) {
|
|
2276
|
+
throw new Error(`Invalid language profile "${profile.id}": ${errors.join("; ")}`);
|
|
2277
|
+
}
|
|
2278
|
+
if (this.#profiles.has(profile.id)) {
|
|
2279
|
+
throw new Error(`Language profile "${profile.id}" is already registered`);
|
|
2280
|
+
}
|
|
2281
|
+
this.#profiles.set(profile.id, freezeProfile(profile));
|
|
2282
|
+
}
|
|
2283
|
+
get(id) {
|
|
2284
|
+
return this.#profiles.get(id);
|
|
2285
|
+
}
|
|
2286
|
+
list() {
|
|
2287
|
+
return Object.freeze([...this.#profiles.values()]);
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
function validateLanguageProfile(profile) {
|
|
2291
|
+
const errors = [];
|
|
2292
|
+
if (!PROFILE_ID_RE.test(profile.id)) errors.push("id must be a lowercase stable identifier");
|
|
2293
|
+
if (!profile.displayName.trim()) errors.push("displayName is required");
|
|
2294
|
+
if (profile.extensions.length === 0) errors.push("at least one extension is required");
|
|
2295
|
+
for (const ext of profile.extensions) {
|
|
2296
|
+
if (!/^\.[a-z0-9+.-]+$/i.test(ext)) errors.push(`invalid extension "${ext}"`);
|
|
2297
|
+
}
|
|
2298
|
+
if (profile.detectors.length === 0) errors.push("at least one detector is required");
|
|
2299
|
+
for (const detector of profile.detectors) {
|
|
2300
|
+
if ((detector.filename ? 1 : 0) + (detector.suffix ? 1 : 0) !== 1) {
|
|
2301
|
+
errors.push("each detector must declare exactly one of filename or suffix");
|
|
2302
|
+
}
|
|
2303
|
+
if (!Number.isFinite(detector.weight) || detector.weight <= 0 || detector.weight > 100) {
|
|
2304
|
+
errors.push("detector weights must be in the range 1..100");
|
|
2305
|
+
}
|
|
2306
|
+
const marker = detector.filename ?? detector.suffix ?? "";
|
|
2307
|
+
if (marker.includes("/") || marker.includes("\\") || marker.includes("\0")) {
|
|
2308
|
+
errors.push(`detector marker "${marker}" must be a basename or suffix`);
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
if (profile.executables.length === 0) errors.push("at least one executable is required");
|
|
2312
|
+
for (const executable of profile.executables) {
|
|
2313
|
+
if (!EXECUTABLE_RE.test(executable)) errors.push(`invalid executable token "${executable}"`);
|
|
2314
|
+
}
|
|
2315
|
+
for (const operation of Object.keys(profile.operations)) {
|
|
2316
|
+
if (!KNOWN_OPERATIONS.has(operation)) {
|
|
2317
|
+
errors.push(`unknown operation "${operation}"`);
|
|
2318
|
+
}
|
|
2319
|
+
if (typeof profile.operations[operation] !== "function") {
|
|
2320
|
+
errors.push(`operation "${operation}" must be a resolver function`);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
return [...new Set(errors)];
|
|
2324
|
+
}
|
|
2325
|
+
function freezeProfile(profile) {
|
|
2326
|
+
const detectors = Object.freeze(profile.detectors.map((item) => Object.freeze({ ...item })));
|
|
2327
|
+
const operations = Object.freeze({ ...profile.operations });
|
|
2328
|
+
return Object.freeze({
|
|
2329
|
+
...profile,
|
|
2330
|
+
extensions: Object.freeze([...profile.extensions]),
|
|
2331
|
+
lspLanguageIds: Object.freeze([...profile.lspLanguageIds]),
|
|
2332
|
+
detectors,
|
|
2333
|
+
ignoredDirectories: Object.freeze([...profile.ignoredDirectories]),
|
|
2334
|
+
packageManagers: Object.freeze([...profile.packageManagers]),
|
|
2335
|
+
executables: Object.freeze([...profile.executables]),
|
|
2336
|
+
operations
|
|
2337
|
+
});
|
|
2338
|
+
}
|
|
2339
|
+
var languageProfileRegistry = new LanguageProfileRegistry([
|
|
2340
|
+
...PRIMARY_LANGUAGE_PROFILES,
|
|
2341
|
+
...ADDITIONAL_LANGUAGE_PROFILES
|
|
2342
|
+
]);
|
|
2343
|
+
|
|
2344
|
+
// src/languages/detect.ts
|
|
2345
|
+
var DEFAULT_LIMITS = { maxDepth: 6, maxEntries: 5e3 };
|
|
2346
|
+
var SOURCE_WEIGHT = 5;
|
|
2347
|
+
var SOURCE_WEIGHT_CAP = 25;
|
|
2348
|
+
var TARGET_WEIGHT = 100;
|
|
2349
|
+
var GLOBAL_IGNORES = /* @__PURE__ */ new Set([
|
|
2350
|
+
".git",
|
|
2351
|
+
".wrongstack",
|
|
2352
|
+
"node_modules",
|
|
2353
|
+
"vendor",
|
|
2354
|
+
"target",
|
|
2355
|
+
"bin",
|
|
2356
|
+
"obj",
|
|
2357
|
+
"dist",
|
|
2358
|
+
"build",
|
|
2359
|
+
"out",
|
|
2360
|
+
"coverage",
|
|
2361
|
+
".cache",
|
|
2362
|
+
".idea",
|
|
2363
|
+
".vscode",
|
|
2364
|
+
".next",
|
|
2365
|
+
".nuxt"
|
|
2366
|
+
]);
|
|
2367
|
+
async function detectLanguageWorkspaces(options) {
|
|
2368
|
+
const projectRoot = await canonicalDirectory(options.projectRoot);
|
|
2369
|
+
const cwdInput = options.cwd ? path4.isAbsolute(options.cwd) ? options.cwd : path4.resolve(projectRoot, options.cwd) : projectRoot;
|
|
2370
|
+
const cwd = await canonicalInside(cwdInput, projectRoot, "cwd");
|
|
2371
|
+
const target = options.target ? await canonicalInside(resolveFrom(cwd, options.target), projectRoot, "target") : void 0;
|
|
2372
|
+
const profiles = (options.profiles ?? languageProfileRegistry.list()).filter((profile) => !options.language || profile.id === options.language).slice().sort((a, b) => a.id.localeCompare(b.id));
|
|
2373
|
+
const limits = normalizeLimits(options.limits);
|
|
2374
|
+
const state = {
|
|
2375
|
+
entries: 0,
|
|
2376
|
+
truncated: false,
|
|
2377
|
+
sourcePaths: /* @__PURE__ */ new Map(),
|
|
2378
|
+
candidates: /* @__PURE__ */ new Map()
|
|
2379
|
+
};
|
|
2380
|
+
await scanDirectory(projectRoot, 0, profiles, limits, state, options.signal);
|
|
2381
|
+
addSourceFallbacks(projectRoot, profiles, state);
|
|
2382
|
+
if (target) addTargetEvidence(target, projectRoot, profiles, state);
|
|
2383
|
+
const workspaces = await Promise.all(
|
|
2384
|
+
[...state.candidates.values()].map((candidate) => finalizeCandidate(candidate, projectRoot))
|
|
2385
|
+
);
|
|
2386
|
+
workspaces.sort(compareWorkspaces);
|
|
2387
|
+
return {
|
|
2388
|
+
projectRoot,
|
|
2389
|
+
scannedEntries: state.entries,
|
|
2390
|
+
truncated: state.truncated,
|
|
2391
|
+
workspaces
|
|
2392
|
+
};
|
|
2393
|
+
}
|
|
2394
|
+
async function scanDirectory(directory, depth, profiles, limits, state, signal) {
|
|
2395
|
+
signal?.throwIfAborted();
|
|
2396
|
+
if (depth > limits.maxDepth || state.entries >= limits.maxEntries) {
|
|
2397
|
+
state.truncated = true;
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2400
|
+
let entries;
|
|
2401
|
+
try {
|
|
2402
|
+
entries = await fs2.readdir(directory, { withFileTypes: true });
|
|
2403
|
+
} catch {
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
2407
|
+
for (const entry of entries) {
|
|
2408
|
+
signal?.throwIfAborted();
|
|
2409
|
+
if (state.entries >= limits.maxEntries) {
|
|
2410
|
+
state.truncated = true;
|
|
2411
|
+
return;
|
|
2412
|
+
}
|
|
2413
|
+
state.entries++;
|
|
2414
|
+
const fullPath = path4.join(directory, entry.name);
|
|
2415
|
+
if (entry.isSymbolicLink()) continue;
|
|
2416
|
+
if (entry.isDirectory()) {
|
|
2417
|
+
if (shouldIgnoreDirectory(entry.name, profiles)) continue;
|
|
2418
|
+
if (depth >= limits.maxDepth) {
|
|
2419
|
+
state.truncated = true;
|
|
2420
|
+
continue;
|
|
2421
|
+
}
|
|
2422
|
+
await scanDirectory(fullPath, depth + 1, profiles, limits, state, signal);
|
|
2423
|
+
continue;
|
|
2424
|
+
}
|
|
2425
|
+
if (!entry.isFile()) continue;
|
|
2426
|
+
collectFileEvidence(directory, fullPath, entry.name, profiles, state);
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
function collectFileEvidence(directory, fullPath, basename4, profiles, state) {
|
|
2430
|
+
const lower = basename4.toLowerCase();
|
|
2431
|
+
const extension = path4.extname(lower);
|
|
2432
|
+
for (const profile of profiles) {
|
|
2433
|
+
const detector = profile.detectors.find(
|
|
2434
|
+
(rule) => rule.filename ? lower === rule.filename.toLowerCase() : lower.endsWith(rule.suffix.toLowerCase())
|
|
2435
|
+
);
|
|
2436
|
+
if (detector) {
|
|
2437
|
+
const candidate = getCandidate(state, profile, directory);
|
|
2438
|
+
candidate.evidence.push({
|
|
2439
|
+
kind: detector.kind,
|
|
2440
|
+
path: fullPath,
|
|
2441
|
+
value: basename4,
|
|
2442
|
+
weight: detector.weight
|
|
2443
|
+
});
|
|
2444
|
+
if (detector.kind === "manifest" || detector.kind === "config") {
|
|
2445
|
+
candidate.manifests.push(fullPath);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
if (profile.extensions.includes(extension)) {
|
|
2449
|
+
const paths = state.sourcePaths.get(profile.id) ?? [];
|
|
2450
|
+
if (paths.length < SOURCE_WEIGHT_CAP / SOURCE_WEIGHT) paths.push(fullPath);
|
|
2451
|
+
state.sourcePaths.set(profile.id, paths);
|
|
2452
|
+
}
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
function addSourceFallbacks(projectRoot, profiles, state) {
|
|
2456
|
+
for (const profile of profiles) {
|
|
2457
|
+
const sources = state.sourcePaths.get(profile.id) ?? [];
|
|
2458
|
+
if (sources.length === 0) continue;
|
|
2459
|
+
const profileCandidates = [...state.candidates.values()].filter(
|
|
2460
|
+
(item) => item.profile.id === profile.id
|
|
2461
|
+
);
|
|
2462
|
+
for (const source of sources) {
|
|
2463
|
+
const containing = profileCandidates.filter((candidate2) => isInside(source, candidate2.root)).sort(
|
|
2464
|
+
(a, b) => pathDepth(b.root, projectRoot) - pathDepth(a.root, projectRoot) || a.root.localeCompare(b.root)
|
|
2465
|
+
);
|
|
2466
|
+
const candidate = containing[0] ?? (profile.sourceFallback === false ? void 0 : getCandidate(state, profile, projectRoot));
|
|
2467
|
+
if (!candidate) continue;
|
|
2468
|
+
candidate.evidence.push({
|
|
2469
|
+
kind: "source",
|
|
2470
|
+
path: source,
|
|
2471
|
+
value: path4.extname(source),
|
|
2472
|
+
weight: SOURCE_WEIGHT
|
|
2473
|
+
});
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
function addTargetEvidence(target, projectRoot, profiles, state) {
|
|
2478
|
+
const extension = path4.extname(target).toLowerCase();
|
|
2479
|
+
for (const profile of profiles) {
|
|
2480
|
+
if (!profile.extensions.includes(extension)) continue;
|
|
2481
|
+
const candidates = [...state.candidates.values()].filter(
|
|
2482
|
+
(candidate2) => candidate2.profile.id === profile.id && isInside(target, candidate2.root)
|
|
2483
|
+
);
|
|
2484
|
+
const candidate = candidates.length > 0 ? candidates.sort(
|
|
2485
|
+
(a, b) => pathDepth(b.root, projectRoot) - pathDepth(a.root, projectRoot) || a.root.localeCompare(b.root)
|
|
2486
|
+
)[0] : profile.sourceFallback === false ? void 0 : getCandidate(state, profile, path4.dirname(target));
|
|
2487
|
+
if (!candidate) continue;
|
|
2488
|
+
candidate.evidence.push({
|
|
2489
|
+
kind: "target",
|
|
2490
|
+
path: target,
|
|
2491
|
+
value: extension,
|
|
2492
|
+
weight: TARGET_WEIGHT
|
|
2493
|
+
});
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
async function finalizeCandidate(candidate, projectRoot) {
|
|
2497
|
+
const evidence = dedupeEvidence(candidate.evidence).sort(compareEvidence);
|
|
2498
|
+
const manifests = [...new Set(candidate.manifests)].sort();
|
|
2499
|
+
const confidence = Math.min(1, evidence.reduce((sum, item) => sum + item.weight, 0) / 100);
|
|
2500
|
+
const packageManager = await detectPackageManager(candidate.profile, candidate.root, evidence);
|
|
2501
|
+
const id = createHash("sha256").update(`${candidate.profile.id}\0${path4.relative(projectRoot, candidate.root)}`).digest("hex").slice(0, 16);
|
|
2502
|
+
return Object.freeze({
|
|
2503
|
+
id,
|
|
2504
|
+
language: candidate.profile.id,
|
|
2505
|
+
root: candidate.root,
|
|
2506
|
+
confidence,
|
|
2507
|
+
evidence: Object.freeze(evidence.map((item) => Object.freeze(item))),
|
|
2508
|
+
...packageManager ? { packageManager } : {},
|
|
2509
|
+
manifests: Object.freeze(manifests),
|
|
2510
|
+
capabilities: Object.freeze(
|
|
2511
|
+
Object.keys(candidate.profile.operations).sort()
|
|
2512
|
+
)
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
async function detectPackageManager(profile, root, evidence) {
|
|
2516
|
+
if (profile.packageManagers.length === 1) return profile.packageManagers[0];
|
|
2517
|
+
if (profile.id !== "typescript" && profile.id !== "javascript") return void 0;
|
|
2518
|
+
let declared;
|
|
2519
|
+
try {
|
|
2520
|
+
const pkg = JSON.parse(await fs2.readFile(path4.join(root, "package.json"), "utf8"));
|
|
2521
|
+
if (typeof pkg.packageManager === "string") {
|
|
2522
|
+
const manager = pkg.packageManager.split("@")[0];
|
|
2523
|
+
if (manager && profile.packageManagers.includes(manager)) declared = manager;
|
|
2524
|
+
}
|
|
2525
|
+
} catch {
|
|
2526
|
+
}
|
|
2527
|
+
const lockManagers = /* @__PURE__ */ new Set();
|
|
2528
|
+
for (const item of evidence) {
|
|
2529
|
+
const name = path4.basename(item.path).toLowerCase();
|
|
2530
|
+
if (name === "pnpm-lock.yaml") lockManagers.add("pnpm");
|
|
2531
|
+
else if (name === "yarn.lock") lockManagers.add("yarn");
|
|
2532
|
+
else if (name === "bun.lock" || name === "bun.lockb") lockManagers.add("bun");
|
|
2533
|
+
else if (name === "package-lock.json") lockManagers.add("npm");
|
|
2534
|
+
}
|
|
2535
|
+
if (declared && (lockManagers.size === 0 || lockManagers.size === 1 && lockManagers.has(declared))) {
|
|
2536
|
+
return declared;
|
|
2537
|
+
}
|
|
2538
|
+
if (lockManagers.size === 1) return [...lockManagers][0];
|
|
2539
|
+
if (lockManagers.size > 1) return void 0;
|
|
2540
|
+
return declared ?? "npm";
|
|
2541
|
+
}
|
|
2542
|
+
function getCandidate(state, profile, root) {
|
|
2543
|
+
const key = `${profile.id}\0${root}`;
|
|
2544
|
+
let candidate = state.candidates.get(key);
|
|
2545
|
+
if (!candidate) {
|
|
2546
|
+
candidate = { profile, root, evidence: [], manifests: [] };
|
|
2547
|
+
state.candidates.set(key, candidate);
|
|
2548
|
+
}
|
|
2549
|
+
return candidate;
|
|
2550
|
+
}
|
|
2551
|
+
function shouldIgnoreDirectory(name, profiles) {
|
|
2552
|
+
if (GLOBAL_IGNORES.has(name) || name.startsWith(".")) return true;
|
|
2553
|
+
return profiles.some((profile) => profile.ignoredDirectories.includes(name));
|
|
2554
|
+
}
|
|
2555
|
+
function normalizeLimits(input) {
|
|
2556
|
+
const maxDepth = Math.max(
|
|
2557
|
+
0,
|
|
2558
|
+
Math.min(12, Math.trunc(input?.maxDepth ?? DEFAULT_LIMITS.maxDepth))
|
|
2559
|
+
);
|
|
2560
|
+
const maxEntries = Math.max(
|
|
2561
|
+
1,
|
|
2562
|
+
Math.min(5e4, Math.trunc(input?.maxEntries ?? DEFAULT_LIMITS.maxEntries))
|
|
2563
|
+
);
|
|
2564
|
+
return { maxDepth, maxEntries };
|
|
2565
|
+
}
|
|
2566
|
+
async function canonicalDirectory(input) {
|
|
2567
|
+
const resolved = path4.resolve(input);
|
|
2568
|
+
const real = await fs2.realpath(resolved);
|
|
2569
|
+
const stat5 = await fs2.stat(real);
|
|
2570
|
+
if (!stat5.isDirectory()) throw new Error(`Project root is not a directory: ${input}`);
|
|
2571
|
+
return real;
|
|
2572
|
+
}
|
|
2573
|
+
async function canonicalInside(input, root, label) {
|
|
2574
|
+
const resolved = path4.resolve(input);
|
|
2575
|
+
let real;
|
|
2576
|
+
try {
|
|
2577
|
+
real = await fs2.realpath(resolved);
|
|
2578
|
+
} catch (error) {
|
|
2579
|
+
if (error.code !== "ENOENT") throw error;
|
|
2580
|
+
const parent = await fs2.realpath(path4.dirname(resolved));
|
|
2581
|
+
real = path4.join(parent, path4.basename(resolved));
|
|
2582
|
+
}
|
|
2583
|
+
if (!isInside(real, root)) throw new Error(`${label} is outside project root: ${input}`);
|
|
2584
|
+
return real;
|
|
2585
|
+
}
|
|
2586
|
+
function resolveFrom(cwd, input) {
|
|
2587
|
+
return path4.isAbsolute(input) ? input : path4.resolve(cwd, input);
|
|
2588
|
+
}
|
|
2589
|
+
function isInside(candidate, root) {
|
|
2590
|
+
const relative5 = path4.relative(root, candidate);
|
|
2591
|
+
return relative5 === "" || !relative5.startsWith("..") && !path4.isAbsolute(relative5);
|
|
2592
|
+
}
|
|
2593
|
+
function pathDepth(candidate, root) {
|
|
2594
|
+
const relative5 = path4.relative(root, candidate);
|
|
2595
|
+
return relative5 === "" ? 0 : relative5.split(path4.sep).length;
|
|
2596
|
+
}
|
|
2597
|
+
function dedupeEvidence(items) {
|
|
2598
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2599
|
+
return items.filter((item) => {
|
|
2600
|
+
const key = `${item.kind}\0${item.path}\0${item.value}\0${item.weight}`;
|
|
2601
|
+
if (seen.has(key)) return false;
|
|
2602
|
+
seen.add(key);
|
|
2603
|
+
return true;
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
function compareEvidence(a, b) {
|
|
2607
|
+
return a.path.localeCompare(b.path) || a.kind.localeCompare(b.kind) || b.weight - a.weight;
|
|
2608
|
+
}
|
|
2609
|
+
function compareWorkspaces(a, b) {
|
|
2610
|
+
return b.confidence - a.confidence || a.language.localeCompare(b.language) || a.root.localeCompare(b.root) || a.id.localeCompare(b.id);
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
// src/languages/diagnostics.ts
|
|
2614
|
+
import * as path5 from "node:path";
|
|
2615
|
+
var MAX_DIAGNOSTICS = 200;
|
|
2616
|
+
function parseLanguageDiagnostics(parser, stdout, stderr, workspaceRoot) {
|
|
2617
|
+
const text = `${stdout}${stdout && stderr ? "\n" : ""}${stderr}`;
|
|
2618
|
+
let diagnostics;
|
|
2619
|
+
switch (parser) {
|
|
2620
|
+
case "typescript":
|
|
2621
|
+
diagnostics = parseTypeScript(text, workspaceRoot);
|
|
2622
|
+
break;
|
|
2623
|
+
case "cargo-json":
|
|
2624
|
+
diagnostics = parseCargoJson(text, workspaceRoot);
|
|
2625
|
+
break;
|
|
2626
|
+
case "php-lint":
|
|
2627
|
+
diagnostics = parsePhpLint(text, workspaceRoot);
|
|
2628
|
+
break;
|
|
2629
|
+
case "dotnet-build":
|
|
2630
|
+
case "dotnet-format":
|
|
2631
|
+
case "dotnet-test":
|
|
2632
|
+
diagnostics = parseDotnet(text, workspaceRoot);
|
|
2633
|
+
break;
|
|
2634
|
+
case "go-test":
|
|
2635
|
+
case "go-compiler":
|
|
2636
|
+
case "gofmt":
|
|
2637
|
+
diagnostics = parseGo(text, workspaceRoot);
|
|
2638
|
+
break;
|
|
2639
|
+
case "biome":
|
|
2640
|
+
diagnostics = parseBiome(text, workspaceRoot);
|
|
2641
|
+
break;
|
|
2642
|
+
default:
|
|
2643
|
+
diagnostics = parseGeneric(text, parser, workspaceRoot);
|
|
2644
|
+
break;
|
|
2645
|
+
}
|
|
2646
|
+
const sorted = dedupeDiagnostics(diagnostics).sort(compareDiagnostics);
|
|
2647
|
+
const omitted = Math.max(0, sorted.length - MAX_DIAGNOSTICS);
|
|
2648
|
+
const kept = Object.freeze(sorted.slice(0, MAX_DIAGNOSTICS).map((item) => Object.freeze(item)));
|
|
2649
|
+
return {
|
|
2650
|
+
diagnostics: kept,
|
|
2651
|
+
omitted,
|
|
2652
|
+
summary: summarize(kept)
|
|
2653
|
+
};
|
|
2654
|
+
}
|
|
2655
|
+
function diagnosticsForInternalSyntax(language, target, sourceText) {
|
|
2656
|
+
if (language !== "typescript" && language !== "javascript") {
|
|
2657
|
+
return Promise.resolve({ diagnostics: [], omitted: 0, summary: emptySummary() });
|
|
2658
|
+
}
|
|
2659
|
+
return import("@typescript/typescript6").then((tsModule) => {
|
|
2660
|
+
const ts = tsModule.default ?? tsModule;
|
|
2661
|
+
const extension = path5.extname(target).toLowerCase();
|
|
2662
|
+
const scriptKind = extension === ".tsx" ? ts.ScriptKind.TSX : extension === ".ts" || extension === ".mts" || extension === ".cts" ? ts.ScriptKind.TS : ts.ScriptKind.JSX;
|
|
2663
|
+
const sourceFile = ts.createSourceFile(
|
|
2664
|
+
path5.basename(target),
|
|
2665
|
+
sourceText,
|
|
2666
|
+
ts.ScriptTarget.Latest,
|
|
2667
|
+
false,
|
|
2668
|
+
scriptKind
|
|
2669
|
+
);
|
|
2670
|
+
const native = sourceFile.parseDiagnostics ?? [];
|
|
2671
|
+
const diagnostics = native.map((diagnostic) => {
|
|
2672
|
+
const start = diagnostic.start ?? 0;
|
|
2673
|
+
const location = sourceFile.getLineAndCharacterOfPosition(start);
|
|
2674
|
+
return {
|
|
2675
|
+
severity: diagnostic.category === ts.DiagnosticCategory.Warning ? "warning" : "error",
|
|
2676
|
+
...diagnostic.code ? { code: `TS${diagnostic.code}` } : {},
|
|
2677
|
+
message: ts.flattenDiagnosticMessageText(diagnostic.messageText, " "),
|
|
2678
|
+
file: target,
|
|
2679
|
+
range: { start: { line: location.line + 1, column: location.character + 1 } },
|
|
2680
|
+
source: "typescript-parser"
|
|
2681
|
+
};
|
|
2682
|
+
});
|
|
2683
|
+
const sorted = dedupeDiagnostics(diagnostics).sort(compareDiagnostics);
|
|
2684
|
+
const omitted = Math.max(0, sorted.length - MAX_DIAGNOSTICS);
|
|
2685
|
+
const kept = Object.freeze(sorted.slice(0, MAX_DIAGNOSTICS).map((item) => Object.freeze(item)));
|
|
2686
|
+
return { diagnostics: kept, omitted, summary: summarize(kept) };
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
function parseTypeScript(text, root) {
|
|
2690
|
+
const diagnostics = [];
|
|
2691
|
+
const regex = /^(.+?)\((\d+),(\d+)\):\s+(error|warning)\s+(TS\d+):\s*(.+)$/gm;
|
|
2692
|
+
for (const match of text.matchAll(regex)) {
|
|
2693
|
+
diagnostics.push({
|
|
2694
|
+
severity: match[4] === "warning" ? "warning" : "error",
|
|
2695
|
+
code: match[5],
|
|
2696
|
+
message: match[6].trim(),
|
|
2697
|
+
file: normalizeDiagnosticPath(match[1], root),
|
|
2698
|
+
range: { start: { line: toPositiveInt(match[2]), column: toPositiveInt(match[3]) } },
|
|
2699
|
+
source: "typescript"
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
return diagnostics;
|
|
2703
|
+
}
|
|
2704
|
+
function parseCargoJson(text, root) {
|
|
2705
|
+
const diagnostics = [];
|
|
2706
|
+
for (const line of text.split(/\r?\n/)) {
|
|
2707
|
+
if (!line.trim().startsWith("{")) continue;
|
|
2708
|
+
try {
|
|
2709
|
+
const value = JSON.parse(line);
|
|
2710
|
+
if (value.reason !== "compiler-message" || !value.message?.message) continue;
|
|
2711
|
+
const primary = value.message.spans?.find((span) => span.is_primary) ?? value.message.spans?.[0];
|
|
2712
|
+
diagnostics.push({
|
|
2713
|
+
severity: normalizeSeverity(value.message.level),
|
|
2714
|
+
...value.message.code?.code ? { code: value.message.code.code } : {},
|
|
2715
|
+
message: value.message.message,
|
|
2716
|
+
...primary?.file_name ? { file: normalizeDiagnosticPath(primary.file_name, root) } : {},
|
|
2717
|
+
...primary?.line_start ? { range: { start: { line: primary.line_start, column: primary.column_start ?? 1 } } } : {},
|
|
2718
|
+
source: "rustc"
|
|
2719
|
+
});
|
|
2720
|
+
} catch {
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
return diagnostics;
|
|
2724
|
+
}
|
|
2725
|
+
function parseGo(text, root) {
|
|
2726
|
+
return parseLinePattern(
|
|
2727
|
+
text,
|
|
2728
|
+
/^(.*?\.go):(\d+):(\d+):\s*(.+)$/gm,
|
|
2729
|
+
root,
|
|
2730
|
+
"go",
|
|
2731
|
+
(_match, message) => ({ message, severity: /warning/i.test(message) ? "warning" : "error" })
|
|
2732
|
+
);
|
|
2733
|
+
}
|
|
2734
|
+
function parsePhpLint(text, root) {
|
|
2735
|
+
const diagnostics = [];
|
|
2736
|
+
const regex = /(?:PHP\s+)?(?:Parse|Fatal) error:\s*(.+?)\s+in\s+(.+?)\s+on line\s+(\d+)/gi;
|
|
2737
|
+
for (const match of text.matchAll(regex)) {
|
|
2738
|
+
diagnostics.push({
|
|
2739
|
+
severity: "error",
|
|
2740
|
+
message: match[1].trim(),
|
|
2741
|
+
file: normalizeDiagnosticPath(match[2], root),
|
|
2742
|
+
range: { start: { line: toPositiveInt(match[3]), column: 1 } },
|
|
2743
|
+
source: "php"
|
|
2744
|
+
});
|
|
2745
|
+
}
|
|
2746
|
+
return diagnostics;
|
|
2747
|
+
}
|
|
2748
|
+
function parseDotnet(text, root) {
|
|
2749
|
+
const diagnostics = [];
|
|
2750
|
+
const regex = /^(.+?)\((\d+),(\d+)\):\s*(error|warning)\s+([A-Z]+\d+):\s*(.+?)(?:\s+\[.+\])?$/gm;
|
|
2751
|
+
for (const match of text.matchAll(regex)) {
|
|
2752
|
+
diagnostics.push({
|
|
2753
|
+
severity: match[4] === "warning" ? "warning" : "error",
|
|
2754
|
+
code: match[5],
|
|
2755
|
+
message: match[6].trim(),
|
|
2756
|
+
file: normalizeDiagnosticPath(match[1], root),
|
|
2757
|
+
range: { start: { line: toPositiveInt(match[2]), column: toPositiveInt(match[3]) } },
|
|
2758
|
+
source: "dotnet"
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
return diagnostics;
|
|
2762
|
+
}
|
|
2763
|
+
function parseBiome(text, root) {
|
|
2764
|
+
const diagnostics = [];
|
|
2765
|
+
const regex = /^(.+?):(\d+):(\d+)\s+(lint\/[^\s]+|format)\s+(.+)$/gm;
|
|
2766
|
+
for (const match of text.matchAll(regex)) {
|
|
2767
|
+
diagnostics.push({
|
|
2768
|
+
severity: "warning",
|
|
2769
|
+
code: match[4],
|
|
2770
|
+
message: match[5].trim(),
|
|
2771
|
+
file: normalizeDiagnosticPath(match[1], root),
|
|
2772
|
+
range: { start: { line: toPositiveInt(match[2]), column: toPositiveInt(match[3]) } },
|
|
2773
|
+
source: "biome"
|
|
2774
|
+
});
|
|
2775
|
+
}
|
|
2776
|
+
return diagnostics;
|
|
2777
|
+
}
|
|
2778
|
+
function parseGeneric(text, source, root) {
|
|
2779
|
+
return parseLinePattern(
|
|
2780
|
+
text,
|
|
2781
|
+
/^(.+?):(\d+):(\d+):\s*(?:(error|warning|info):\s*)?(.+)$/gm,
|
|
2782
|
+
root,
|
|
2783
|
+
source,
|
|
2784
|
+
(match, fallback) => ({
|
|
2785
|
+
severity: normalizeSeverity(match[4]),
|
|
2786
|
+
message: match[5]?.trim() || fallback
|
|
2787
|
+
})
|
|
2788
|
+
);
|
|
2789
|
+
}
|
|
2790
|
+
function parseLinePattern(text, regex, root, source, details) {
|
|
2791
|
+
const diagnostics = [];
|
|
2792
|
+
for (const match of text.matchAll(regex)) {
|
|
2793
|
+
const parsed = details(match, match.at(-1)?.trim() ?? "Diagnostic");
|
|
2794
|
+
diagnostics.push({
|
|
2795
|
+
severity: parsed.severity,
|
|
2796
|
+
message: parsed.message,
|
|
2797
|
+
file: normalizeDiagnosticPath(match[1], root),
|
|
2798
|
+
range: { start: { line: toPositiveInt(match[2]), column: toPositiveInt(match[3]) } },
|
|
2799
|
+
source
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
return diagnostics;
|
|
2803
|
+
}
|
|
2804
|
+
function normalizeDiagnosticPath(value, root) {
|
|
2805
|
+
const clean = value.trim().replace(/^['"]|['"]$/g, "");
|
|
2806
|
+
return path5.resolve(root, clean);
|
|
2807
|
+
}
|
|
2808
|
+
function normalizeSeverity(value) {
|
|
2809
|
+
if (value === "warning" || value === "warn") return "warning";
|
|
2810
|
+
if (value === "info" || value === "note" || value === "help") return "info";
|
|
2811
|
+
if (value === "hint") return "hint";
|
|
2812
|
+
return "error";
|
|
2813
|
+
}
|
|
2814
|
+
function toPositiveInt(value) {
|
|
2815
|
+
return Math.max(1, Number.parseInt(value ?? "1", 10) || 1);
|
|
2816
|
+
}
|
|
2817
|
+
function summarize(diagnostics) {
|
|
2818
|
+
return {
|
|
2819
|
+
errors: diagnostics.filter((item) => item.severity === "error").length,
|
|
2820
|
+
warnings: diagnostics.filter((item) => item.severity === "warning").length,
|
|
2821
|
+
infos: diagnostics.filter((item) => item.severity === "info" || item.severity === "hint").length
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
function emptySummary() {
|
|
2825
|
+
return { errors: 0, warnings: 0, infos: 0 };
|
|
2826
|
+
}
|
|
2827
|
+
function dedupeDiagnostics(items) {
|
|
2828
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2829
|
+
return items.filter((item) => {
|
|
2830
|
+
const key = [
|
|
2831
|
+
item.source,
|
|
2832
|
+
item.code ?? "",
|
|
2833
|
+
item.file ?? "",
|
|
2834
|
+
item.range?.start.line ?? 0,
|
|
2835
|
+
item.range?.start.column ?? 0,
|
|
2836
|
+
item.message
|
|
2837
|
+
].join("\0");
|
|
2838
|
+
if (seen.has(key)) return false;
|
|
2839
|
+
seen.add(key);
|
|
2840
|
+
return true;
|
|
2841
|
+
});
|
|
2842
|
+
}
|
|
2843
|
+
function compareDiagnostics(a, b) {
|
|
2844
|
+
return (a.file ?? "").localeCompare(b.file ?? "") || (a.range?.start.line ?? 0) - (b.range?.start.line ?? 0) || (a.range?.start.column ?? 0) - (b.range?.start.column ?? 0) || severityRank(a.severity) - severityRank(b.severity) || (a.code ?? "").localeCompare(b.code ?? "") || a.message.localeCompare(b.message);
|
|
2845
|
+
}
|
|
2846
|
+
function severityRank(value) {
|
|
2847
|
+
return value === "error" ? 0 : value === "warning" ? 1 : value === "info" ? 2 : 3;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
// src/languages/execute.ts
|
|
2851
|
+
import * as fs4 from "node:fs/promises";
|
|
2852
|
+
import * as path7 from "node:path";
|
|
2853
|
+
|
|
2854
|
+
// src/languages/plan.ts
|
|
2855
|
+
import * as fs3 from "node:fs/promises";
|
|
2856
|
+
import * as path6 from "node:path";
|
|
2857
|
+
var MAX_ARGUMENTS = 128;
|
|
2858
|
+
var MAX_ARGUMENT_LENGTH = 4096;
|
|
2859
|
+
var PACKAGE_NAME_RE = /^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+(?:@[a-z0-9*+._~^<>=|-]+)?$/i;
|
|
2860
|
+
var COMPOSER_PACKAGE_RE = /^[a-z0-9_.-]+\/[a-z0-9_.-]+(?::[a-z0-9*+._~^<>=|-]+)?$/i;
|
|
2861
|
+
var GO_MODULE_RE = /^(?:[a-z0-9.-]+\.)+[a-z0-9.-]+\/[a-z0-9._~+/@-]+$/i;
|
|
2862
|
+
async function planLanguageOperation(options) {
|
|
2863
|
+
validateOperationOptions(options.operation, options.operationOptions?.packages);
|
|
2864
|
+
const detection = await detectLanguageWorkspaces(options);
|
|
2865
|
+
const candidates = detection.workspaces.filter(
|
|
2866
|
+
(workspace) => workspace.capabilities.includes(options.operation)
|
|
2867
|
+
);
|
|
2868
|
+
const selected = selectWorkspace(candidates, options);
|
|
2869
|
+
if (selected.status !== "selected") return selected.result;
|
|
2870
|
+
const profile = (options.profiles ?? languageProfileRegistry.list()).find(
|
|
2871
|
+
(item) => item.id === selected.workspace.language
|
|
2872
|
+
);
|
|
2873
|
+
if (!profile) {
|
|
2874
|
+
return {
|
|
2875
|
+
status: "not_found",
|
|
2876
|
+
reason: `Profile ${selected.workspace.language} is unavailable.`,
|
|
2877
|
+
candidates
|
|
2878
|
+
};
|
|
2879
|
+
}
|
|
2880
|
+
if ((profile.id === "typescript" || profile.id === "javascript") && options.operation !== "syntax" && selected.workspace.packageManager === void 0 && new Set(
|
|
2881
|
+
selected.workspace.evidence.filter((evidence) => evidence.kind === "lockfile").map((evidence) => evidence.value.toLowerCase())
|
|
2882
|
+
).size > 1) {
|
|
2883
|
+
return {
|
|
2884
|
+
status: "unavailable",
|
|
2885
|
+
workspace: selected.workspace,
|
|
2886
|
+
unavailable: {
|
|
2887
|
+
status: "unavailable",
|
|
2888
|
+
profileId: profile.id,
|
|
2889
|
+
workspaceId: selected.workspace.id,
|
|
2890
|
+
operation: options.operation,
|
|
2891
|
+
reason: "Conflicting Node lockfiles make the package manager ambiguous."
|
|
2892
|
+
}
|
|
2893
|
+
};
|
|
2894
|
+
}
|
|
2895
|
+
const resolver = profile.operations[options.operation];
|
|
2896
|
+
if (!resolver) {
|
|
2897
|
+
return {
|
|
2898
|
+
status: "unavailable",
|
|
2899
|
+
workspace: selected.workspace,
|
|
2900
|
+
unavailable: {
|
|
2901
|
+
status: "unavailable",
|
|
2902
|
+
profileId: profile.id,
|
|
2903
|
+
workspaceId: selected.workspace.id,
|
|
2904
|
+
operation: options.operation,
|
|
2905
|
+
reason: `${profile.displayName} does not define ${options.operation}.`
|
|
2906
|
+
}
|
|
2907
|
+
};
|
|
2908
|
+
}
|
|
2909
|
+
const canonicalCwd = options.cwd ? path6.isAbsolute(options.cwd) ? options.cwd : path6.resolve(detection.projectRoot, options.cwd) : detection.projectRoot;
|
|
2910
|
+
const target = options.target ? await canonicalTarget(canonicalCwd, options.target, detection.projectRoot) : void 0;
|
|
2911
|
+
const ctx = {
|
|
2912
|
+
projectRoot: detection.projectRoot,
|
|
2913
|
+
workspace: selected.workspace,
|
|
2914
|
+
...target ? { target } : {},
|
|
2915
|
+
mode: options.mode ?? "standard",
|
|
2916
|
+
options: options.operationOptions ?? {},
|
|
2917
|
+
platform: process.platform,
|
|
2918
|
+
pathExists: async (candidate) => {
|
|
2919
|
+
try {
|
|
2920
|
+
await fs3.access(path6.resolve(detection.projectRoot, candidate));
|
|
2921
|
+
return true;
|
|
2922
|
+
} catch {
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2925
|
+
}
|
|
2926
|
+
};
|
|
2927
|
+
const result = await resolver(ctx);
|
|
2928
|
+
if ("status" in result) {
|
|
2929
|
+
return { status: "unavailable", workspace: selected.workspace, unavailable: result };
|
|
2930
|
+
}
|
|
2931
|
+
const errors = validateCommandPlan(result, profile, detection.projectRoot);
|
|
2932
|
+
if (errors.length > 0) {
|
|
2933
|
+
return {
|
|
2934
|
+
status: "unavailable",
|
|
2935
|
+
workspace: selected.workspace,
|
|
2936
|
+
unavailable: {
|
|
2937
|
+
status: "unavailable",
|
|
2938
|
+
profileId: profile.id,
|
|
2939
|
+
workspaceId: selected.workspace.id,
|
|
2940
|
+
operation: options.operation,
|
|
2941
|
+
reason: `Generated plan failed validation: ${errors.join("; ")}`
|
|
2942
|
+
}
|
|
2943
|
+
};
|
|
2944
|
+
}
|
|
2945
|
+
return { status: "planned", workspace: selected.workspace, plan: Object.freeze(result) };
|
|
2946
|
+
}
|
|
2947
|
+
function validateCommandPlan(plan, profile, projectRoot) {
|
|
2948
|
+
const errors = [];
|
|
2949
|
+
if (plan.profileId !== profile.id) errors.push("profile id does not match");
|
|
2950
|
+
if (!isInside2(plan.cwd, projectRoot)) errors.push("cwd is outside project root");
|
|
2951
|
+
if (plan.args.length > MAX_ARGUMENTS) errors.push(`argument count exceeds ${MAX_ARGUMENTS}`);
|
|
2952
|
+
if (plan.args.some((arg) => arg.length > MAX_ARGUMENT_LENGTH || /[\r\n\0]/.test(arg))) {
|
|
2953
|
+
errors.push("arguments contain an invalid or oversized value");
|
|
2954
|
+
}
|
|
2955
|
+
if (!Number.isFinite(plan.timeoutMs) || plan.timeoutMs < 1 || plan.timeoutMs > 6e5) {
|
|
2956
|
+
errors.push("timeout is outside 1..600000ms");
|
|
2957
|
+
}
|
|
2958
|
+
if (!Number.isFinite(plan.outputLimitBytes) || plan.outputLimitBytes < 1 || plan.outputLimitBytes > 1e6) {
|
|
2959
|
+
errors.push("output limit is outside 1..1000000 bytes");
|
|
2960
|
+
}
|
|
2961
|
+
if (plan.kind === "internal") {
|
|
2962
|
+
if (plan.command !== null || plan.args.length !== 0)
|
|
2963
|
+
errors.push("internal plans cannot declare a command");
|
|
2964
|
+
} else {
|
|
2965
|
+
if (!plan.command || !profile.executables.includes(plan.command)) {
|
|
2966
|
+
errors.push(`executable "${plan.command ?? ""}" is not allowlisted by the profile`);
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
if (Object.keys(plan.env).length > 0)
|
|
2970
|
+
errors.push("Phase 1 plans cannot override environment variables");
|
|
2971
|
+
return errors;
|
|
2972
|
+
}
|
|
2973
|
+
function selectWorkspace(candidates, options) {
|
|
2974
|
+
if (candidates.length === 0) {
|
|
2975
|
+
return {
|
|
2976
|
+
status: "result",
|
|
2977
|
+
result: {
|
|
2978
|
+
status: "not_found",
|
|
2979
|
+
reason: `No workspace supports ${options.operation}.`,
|
|
2980
|
+
candidates: []
|
|
2981
|
+
}
|
|
2982
|
+
};
|
|
2983
|
+
}
|
|
2984
|
+
if (options.workspace) {
|
|
2985
|
+
const requested = path6.isAbsolute(options.workspace) ? path6.resolve(options.workspace) : path6.resolve(options.projectRoot, options.workspace);
|
|
2986
|
+
const matches = candidates.filter(
|
|
2987
|
+
(item) => item.id === options.workspace || path6.resolve(item.root) === requested
|
|
2988
|
+
);
|
|
2989
|
+
if (matches.length === 1) return { status: "selected", workspace: matches[0] };
|
|
2990
|
+
return {
|
|
2991
|
+
status: "result",
|
|
2992
|
+
result: {
|
|
2993
|
+
status: "not_found",
|
|
2994
|
+
reason: `Requested workspace "${options.workspace}" was not detected.`,
|
|
2995
|
+
candidates: [...candidates]
|
|
2996
|
+
}
|
|
2997
|
+
};
|
|
2998
|
+
}
|
|
2999
|
+
if (options.target) {
|
|
3000
|
+
const base = options.cwd ? path6.isAbsolute(options.cwd) ? path6.resolve(options.cwd) : path6.resolve(options.projectRoot, options.cwd) : path6.resolve(options.projectRoot);
|
|
3001
|
+
const target = path6.isAbsolute(options.target) ? path6.resolve(options.target) : path6.resolve(base, options.target);
|
|
3002
|
+
const targeted = candidates.filter((item) => item.evidence.some((evidence) => evidence.kind === "target")).sort(
|
|
3003
|
+
(a, b) => workspaceDepth(b.root, options.projectRoot) - workspaceDepth(a.root, options.projectRoot) || compareCandidates(a, b)
|
|
3004
|
+
);
|
|
3005
|
+
if (targeted[0]) return { status: "selected", workspace: targeted[0] };
|
|
3006
|
+
const containing = candidates.filter((item) => isInside2(target, item.root)).sort(
|
|
3007
|
+
(a, b) => workspaceDepth(b.root, options.projectRoot) - workspaceDepth(a.root, options.projectRoot) || compareCandidates(a, b)
|
|
3008
|
+
);
|
|
3009
|
+
if (containing[0]) return { status: "selected", workspace: containing[0] };
|
|
3010
|
+
}
|
|
3011
|
+
const sorted = [...candidates].sort(compareCandidates);
|
|
3012
|
+
const first = sorted[0];
|
|
3013
|
+
const firstDepth = workspaceDepth(first.root, options.projectRoot);
|
|
3014
|
+
const tied = sorted.filter(
|
|
3015
|
+
(item) => item.confidence === first.confidence && workspaceDepth(item.root, options.projectRoot) === firstDepth
|
|
3016
|
+
);
|
|
3017
|
+
if (tied.length > 1) {
|
|
3018
|
+
return {
|
|
3019
|
+
status: "result",
|
|
3020
|
+
result: {
|
|
3021
|
+
status: "ambiguous",
|
|
3022
|
+
reason: "Multiple workspaces have equal confidence; provide target, language, or workspace.",
|
|
3023
|
+
candidates: tied
|
|
3024
|
+
}
|
|
3025
|
+
};
|
|
3026
|
+
}
|
|
3027
|
+
return { status: "selected", workspace: first };
|
|
3028
|
+
}
|
|
3029
|
+
function compareCandidates(a, b) {
|
|
3030
|
+
return b.confidence - a.confidence || a.language.localeCompare(b.language) || a.root.localeCompare(b.root);
|
|
3031
|
+
}
|
|
3032
|
+
function workspaceDepth(workspaceRoot, projectRoot) {
|
|
3033
|
+
const relative5 = path6.relative(path6.resolve(projectRoot), path6.resolve(workspaceRoot));
|
|
3034
|
+
return relative5 === "" ? 0 : relative5.split(path6.sep).length;
|
|
3035
|
+
}
|
|
3036
|
+
function validateOperationOptions(operation, packages) {
|
|
3037
|
+
if (!operation.startsWith("package-") || !packages) return;
|
|
3038
|
+
for (const value of packages) {
|
|
3039
|
+
if (!value || value.length > 214 || value.startsWith("-") || /[\r\n\0;&|`$<>\\]/.test(value)) {
|
|
3040
|
+
throw new Error(`Invalid package identifier "${value}"`);
|
|
3041
|
+
}
|
|
3042
|
+
if (value.startsWith(".") || value.startsWith("/") || /^[A-Za-z]:/.test(value) || value.includes("://")) {
|
|
3043
|
+
throw new Error(`Package paths and URLs are not supported: "${value}"`);
|
|
3044
|
+
}
|
|
3045
|
+
if (!PACKAGE_NAME_RE.test(value) && !COMPOSER_PACKAGE_RE.test(value) && !GO_MODULE_RE.test(value)) {
|
|
3046
|
+
throw new Error(`Invalid package identifier "${value}"`);
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
async function canonicalTarget(cwd, target, projectRoot) {
|
|
3051
|
+
const resolved = path6.isAbsolute(target) ? path6.resolve(target) : path6.resolve(cwd, target);
|
|
3052
|
+
let real;
|
|
3053
|
+
try {
|
|
3054
|
+
real = await fs3.realpath(resolved);
|
|
3055
|
+
} catch (error) {
|
|
3056
|
+
if (error.code !== "ENOENT") throw error;
|
|
3057
|
+
const parent = await fs3.realpath(path6.dirname(resolved));
|
|
3058
|
+
real = path6.join(parent, path6.basename(resolved));
|
|
3059
|
+
}
|
|
3060
|
+
if (!isInside2(real, projectRoot)) throw new Error(`target is outside project root: ${target}`);
|
|
3061
|
+
return real;
|
|
3062
|
+
}
|
|
3063
|
+
function isInside2(candidate, root) {
|
|
3064
|
+
const relative5 = path6.relative(path6.resolve(root), path6.resolve(candidate));
|
|
3065
|
+
return relative5 === "" || !relative5.startsWith("..") && !path6.isAbsolute(relative5);
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
// src/languages/execute.ts
|
|
3069
|
+
var MAX_INTERNAL_SOURCE_BYTES = 15e5;
|
|
3070
|
+
async function* executeLanguagePlan(options) {
|
|
3071
|
+
const { plan, workspace } = options;
|
|
3072
|
+
if (options.signal.aborted) {
|
|
3073
|
+
return terminalResult(options, "cancelled", options.signal.reason);
|
|
3074
|
+
}
|
|
3075
|
+
const profile = languageProfileRegistry.get(plan.profileId);
|
|
3076
|
+
if (!profile) return unavailableResult(options, `Unknown language profile: ${plan.profileId}`);
|
|
3077
|
+
if (workspace.id !== plan.workspaceId || workspace.language !== plan.profileId) {
|
|
3078
|
+
return unavailableResult(options, "Plan and workspace identity do not match.");
|
|
3079
|
+
}
|
|
3080
|
+
const validation = validateCommandPlan(plan, profile, options.projectRoot);
|
|
3081
|
+
if (validation.length > 0) {
|
|
3082
|
+
return unavailableResult(options, `Plan failed execution validation: ${validation.join("; ")}`);
|
|
3083
|
+
}
|
|
3084
|
+
const containmentError = await validatePlanRealpaths(plan, options.projectRoot);
|
|
3085
|
+
if (containmentError) return unavailableResult(options, containmentError);
|
|
3086
|
+
if (plan.operation.startsWith("package-") || plan.network) {
|
|
3087
|
+
return terminalNonPackageResult(
|
|
3088
|
+
options,
|
|
3089
|
+
"Package and network plans require the separate language_package tool (Phase 3)."
|
|
3090
|
+
);
|
|
3091
|
+
}
|
|
3092
|
+
const startedAt = Date.now();
|
|
3093
|
+
yield {
|
|
3094
|
+
type: "log",
|
|
3095
|
+
text: plan.kind === "internal" ? `Running ${plan.parser}\u2026` : `${plan.command} ${plan.args.join(" ")}`,
|
|
3096
|
+
data: { language: plan.profileId, operation: plan.operation, workspace: workspace.root }
|
|
3097
|
+
};
|
|
3098
|
+
if (plan.kind === "internal") {
|
|
3099
|
+
try {
|
|
3100
|
+
return await executeInternal(options, startedAt);
|
|
3101
|
+
} catch (error) {
|
|
3102
|
+
return unavailableResult(options, error instanceof Error ? error.message : String(error));
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
const timeoutController = new AbortController();
|
|
3106
|
+
const timer = setTimeout(
|
|
3107
|
+
() => timeoutController.abort(new Error("language plan timed out")),
|
|
3108
|
+
plan.timeoutMs
|
|
3109
|
+
);
|
|
3110
|
+
timer.unref?.();
|
|
3111
|
+
const signal = AbortSignal.any([options.signal, timeoutController.signal]);
|
|
3112
|
+
let spawned;
|
|
3113
|
+
try {
|
|
3114
|
+
const stream = spawnStream({
|
|
3115
|
+
cmd: plan.command,
|
|
3116
|
+
args: [...plan.args],
|
|
3117
|
+
cwd: plan.cwd,
|
|
3118
|
+
signal,
|
|
3119
|
+
maxBytes: plan.outputLimitBytes
|
|
3120
|
+
});
|
|
3121
|
+
for (; ; ) {
|
|
3122
|
+
const next = await stream.next();
|
|
3123
|
+
if (next.done) {
|
|
3124
|
+
spawned = next.value;
|
|
3125
|
+
break;
|
|
3126
|
+
}
|
|
3127
|
+
yield next.value;
|
|
3128
|
+
}
|
|
3129
|
+
} catch (error) {
|
|
3130
|
+
const timedOut2 = timeoutController.signal.aborted && !options.signal.aborted;
|
|
3131
|
+
const cancelled2 = options.signal.aborted;
|
|
3132
|
+
return {
|
|
3133
|
+
status: timedOut2 ? "timed_out" : cancelled2 ? "cancelled" : "failed",
|
|
3134
|
+
language: plan.profileId,
|
|
3135
|
+
workspace,
|
|
3136
|
+
plan,
|
|
3137
|
+
exitCode: null,
|
|
3138
|
+
durationMs: Date.now() - startedAt,
|
|
3139
|
+
diagnostics: Object.freeze([]),
|
|
3140
|
+
omittedDiagnostics: 0,
|
|
3141
|
+
summary: emptySummary2(),
|
|
3142
|
+
output: "",
|
|
3143
|
+
truncated: false,
|
|
3144
|
+
error: error instanceof Error ? error.message : String(error)
|
|
3145
|
+
};
|
|
3146
|
+
} finally {
|
|
3147
|
+
clearTimeout(timer);
|
|
3148
|
+
}
|
|
3149
|
+
const parsed = parseLanguageDiagnostics(
|
|
3150
|
+
plan.parser,
|
|
3151
|
+
spawned.stdout,
|
|
3152
|
+
spawned.stderr,
|
|
3153
|
+
workspace.root
|
|
3154
|
+
);
|
|
3155
|
+
const timedOut = timeoutController.signal.aborted && !options.signal.aborted;
|
|
3156
|
+
const cancelled = options.signal.aborted;
|
|
3157
|
+
const spawnUnavailable = Boolean(
|
|
3158
|
+
spawned.error && /ENOENT|not found|cannot find/i.test(spawned.error)
|
|
3159
|
+
);
|
|
3160
|
+
const status = timedOut ? "timed_out" : cancelled ? "cancelled" : spawnUnavailable ? "unavailable" : spawned.exitCode === 0 ? "passed" : "failed";
|
|
3161
|
+
const raw = [spawned.stdout, spawned.stderr, spawned.error].filter(Boolean).join("\n");
|
|
3162
|
+
return {
|
|
3163
|
+
status,
|
|
3164
|
+
language: plan.profileId,
|
|
3165
|
+
workspace,
|
|
3166
|
+
plan,
|
|
3167
|
+
exitCode: spawned.exitCode,
|
|
3168
|
+
durationMs: Date.now() - startedAt,
|
|
3169
|
+
diagnostics: parsed.diagnostics,
|
|
3170
|
+
omittedDiagnostics: parsed.omitted,
|
|
3171
|
+
summary: parsed.summary,
|
|
3172
|
+
output: normalizeCommandOutput(raw, { maxBytes: plan.outputLimitBytes }),
|
|
3173
|
+
truncated: spawned.truncated,
|
|
3174
|
+
...spawned.spoolPath ? { spoolPath: spawned.spoolPath } : {},
|
|
3175
|
+
...spawned.error ? { error: spawned.error } : {}
|
|
3176
|
+
};
|
|
3177
|
+
}
|
|
3178
|
+
async function executeInternal(options, startedAt) {
|
|
3179
|
+
const target = options.plan.evidence.find((item) => item.kind === "target")?.path;
|
|
3180
|
+
if (!target) return unavailableResult(options, "Internal syntax plan has no target evidence.");
|
|
3181
|
+
const safeTarget = await assertContainedFile(target, options.projectRoot);
|
|
3182
|
+
const stat5 = await fs4.stat(safeTarget);
|
|
3183
|
+
if (stat5.size > MAX_INTERNAL_SOURCE_BYTES) {
|
|
3184
|
+
return unavailableResult(
|
|
3185
|
+
options,
|
|
3186
|
+
`Internal syntax target exceeds ${MAX_INTERNAL_SOURCE_BYTES} bytes.`
|
|
3187
|
+
);
|
|
3188
|
+
}
|
|
3189
|
+
const source = await fs4.readFile(safeTarget, "utf8");
|
|
3190
|
+
const parsed = await diagnosticsForInternalSyntax(options.plan.profileId, safeTarget, source);
|
|
3191
|
+
return {
|
|
3192
|
+
status: parsed.summary.errors > 0 ? "failed" : "passed",
|
|
3193
|
+
language: options.plan.profileId,
|
|
3194
|
+
workspace: options.workspace,
|
|
3195
|
+
plan: options.plan,
|
|
3196
|
+
exitCode: parsed.summary.errors > 0 ? 1 : 0,
|
|
3197
|
+
durationMs: Date.now() - startedAt,
|
|
3198
|
+
diagnostics: parsed.diagnostics,
|
|
3199
|
+
omittedDiagnostics: parsed.omitted,
|
|
3200
|
+
summary: parsed.summary,
|
|
3201
|
+
output: parsed.summary.errors > 0 ? `${parsed.summary.errors} syntax error(s) found.` : "Syntax check passed.",
|
|
3202
|
+
truncated: false
|
|
3203
|
+
};
|
|
3204
|
+
}
|
|
3205
|
+
async function validatePlanRealpaths(plan, projectRoot) {
|
|
3206
|
+
const realRoot = await fs4.realpath(projectRoot);
|
|
3207
|
+
let realCwd;
|
|
3208
|
+
try {
|
|
3209
|
+
realCwd = await fs4.realpath(plan.cwd);
|
|
3210
|
+
} catch (error) {
|
|
3211
|
+
return `Plan cwd is unavailable: ${error instanceof Error ? error.message : String(error)}`;
|
|
3212
|
+
}
|
|
3213
|
+
if (!isRealInside(realCwd, realRoot)) return "Plan cwd resolves outside project root.";
|
|
3214
|
+
for (const argument of plan.args) {
|
|
3215
|
+
if (!path7.isAbsolute(argument)) continue;
|
|
3216
|
+
try {
|
|
3217
|
+
const realArgument = await fs4.realpath(argument);
|
|
3218
|
+
if (!isRealInside(realArgument, realRoot)) {
|
|
3219
|
+
return `Plan argument resolves outside project root: ${argument}`;
|
|
3220
|
+
}
|
|
3221
|
+
} catch (error) {
|
|
3222
|
+
if (error.code !== "ENOENT") {
|
|
3223
|
+
return `Plan argument could not be resolved safely: ${argument}`;
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
return void 0;
|
|
3228
|
+
}
|
|
3229
|
+
function isRealInside(candidate, root) {
|
|
3230
|
+
const relative5 = path7.relative(root, candidate);
|
|
3231
|
+
return relative5 === "" || !relative5.startsWith("..") && !path7.isAbsolute(relative5);
|
|
3232
|
+
}
|
|
3233
|
+
async function assertContainedFile(candidate, projectRoot) {
|
|
3234
|
+
const realRoot = await fs4.realpath(projectRoot);
|
|
3235
|
+
const realTarget = await fs4.realpath(candidate);
|
|
3236
|
+
const relative5 = path7.relative(realRoot, realTarget);
|
|
3237
|
+
if (relative5.startsWith("..") || path7.isAbsolute(relative5)) {
|
|
3238
|
+
throw new Error(`Internal syntax target resolves outside project root: ${candidate}`);
|
|
3239
|
+
}
|
|
3240
|
+
return realTarget;
|
|
3241
|
+
}
|
|
3242
|
+
function terminalResult(options, status, reason) {
|
|
3243
|
+
const message = reason instanceof Error ? reason.message : reason ? String(reason) : status;
|
|
3244
|
+
return {
|
|
3245
|
+
status,
|
|
3246
|
+
language: options.plan.profileId,
|
|
3247
|
+
workspace: options.workspace,
|
|
3248
|
+
plan: options.plan,
|
|
3249
|
+
exitCode: null,
|
|
3250
|
+
durationMs: 0,
|
|
3251
|
+
diagnostics: Object.freeze([]),
|
|
3252
|
+
omittedDiagnostics: 0,
|
|
3253
|
+
summary: emptySummary2(),
|
|
3254
|
+
output: "",
|
|
3255
|
+
truncated: false,
|
|
3256
|
+
error: message
|
|
3257
|
+
};
|
|
3258
|
+
}
|
|
3259
|
+
function unavailableResult(options, reason) {
|
|
3260
|
+
return {
|
|
3261
|
+
status: "unavailable",
|
|
3262
|
+
language: options.plan.profileId,
|
|
3263
|
+
workspace: options.workspace,
|
|
3264
|
+
plan: options.plan,
|
|
3265
|
+
exitCode: null,
|
|
3266
|
+
durationMs: 0,
|
|
3267
|
+
diagnostics: Object.freeze([]),
|
|
3268
|
+
omittedDiagnostics: 0,
|
|
3269
|
+
summary: emptySummary2(),
|
|
3270
|
+
output: reason,
|
|
3271
|
+
truncated: false,
|
|
3272
|
+
error: reason
|
|
3273
|
+
};
|
|
3274
|
+
}
|
|
3275
|
+
function emptySummary2() {
|
|
3276
|
+
return { errors: 0, warnings: 0, infos: 0 };
|
|
3277
|
+
}
|
|
3278
|
+
function terminalNonPackageResult(options, reason) {
|
|
3279
|
+
return {
|
|
3280
|
+
status: "unavailable",
|
|
3281
|
+
language: options.plan.profileId,
|
|
3282
|
+
workspace: options.workspace,
|
|
3283
|
+
plan: options.plan,
|
|
3284
|
+
exitCode: null,
|
|
3285
|
+
durationMs: 0,
|
|
3286
|
+
diagnostics: Object.freeze([]),
|
|
3287
|
+
omittedDiagnostics: 0,
|
|
3288
|
+
summary: emptySummary2(),
|
|
3289
|
+
output: reason,
|
|
3290
|
+
truncated: false,
|
|
3291
|
+
error: reason
|
|
3292
|
+
};
|
|
3293
|
+
}
|
|
3294
|
+
|
|
3295
|
+
// src/languages/legacy-bridge.ts
|
|
3296
|
+
var NON_JS_MARKERS = [
|
|
3297
|
+
{ filename: "go.mod", language: "go" },
|
|
3298
|
+
{ filename: "go.work", language: "go" },
|
|
3299
|
+
{ filename: "Cargo.toml", language: "rust" },
|
|
3300
|
+
{ filename: "composer.json", language: "php" }
|
|
3301
|
+
];
|
|
3302
|
+
var NON_JS_SUFFIXES = [
|
|
3303
|
+
{ suffix: ".csproj", language: "csharp" },
|
|
3304
|
+
{ suffix: ".fsproj", language: "csharp" }
|
|
3305
|
+
];
|
|
3306
|
+
async function detectNonJsEcosystem(cwd, projectRoot) {
|
|
3307
|
+
try {
|
|
3308
|
+
let dir = path8.resolve(cwd);
|
|
3309
|
+
const root = path8.resolve(projectRoot);
|
|
3310
|
+
for (let depth = 0; depth <= 4 && dir.startsWith(root); depth++) {
|
|
3311
|
+
for (const marker of NON_JS_MARKERS) {
|
|
3312
|
+
try {
|
|
3313
|
+
const s = await fs5.stat(path8.join(dir, marker.filename));
|
|
3314
|
+
if (s.isFile()) return marker.language;
|
|
3315
|
+
} catch {
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
try {
|
|
3319
|
+
const entries = await fs5.readdir(dir);
|
|
3320
|
+
for (const entry of entries) {
|
|
3321
|
+
for (const suffix of NON_JS_SUFFIXES) {
|
|
3322
|
+
if (entry.toLowerCase().endsWith(suffix.suffix)) return suffix.language;
|
|
3323
|
+
}
|
|
3324
|
+
}
|
|
3325
|
+
} catch {
|
|
3326
|
+
}
|
|
3327
|
+
if (dir === root) break;
|
|
3328
|
+
dir = path8.dirname(dir);
|
|
3329
|
+
}
|
|
3330
|
+
} catch {
|
|
3331
|
+
}
|
|
3332
|
+
return null;
|
|
3333
|
+
}
|
|
3334
|
+
async function tryLegacyCodeOperation(operation, ctx) {
|
|
3335
|
+
const language = await detectNonJsEcosystem(ctx.cwd, ctx.projectRoot);
|
|
3336
|
+
if (!language) return null;
|
|
3337
|
+
const planResult = await planLanguageOperation({
|
|
3338
|
+
projectRoot: ctx.projectRoot,
|
|
3339
|
+
cwd: ctx.cwd,
|
|
3340
|
+
operation,
|
|
3341
|
+
language,
|
|
3342
|
+
...ctx.target ? { target: ctx.target } : {},
|
|
3343
|
+
signal: ctx.signal
|
|
3344
|
+
});
|
|
3345
|
+
if (planResult.status !== "planned") return null;
|
|
3346
|
+
const runner = executeLanguagePlan({
|
|
3347
|
+
projectRoot: ctx.projectRoot,
|
|
3348
|
+
workspace: planResult.workspace,
|
|
3349
|
+
plan: planResult.plan,
|
|
3350
|
+
signal: ctx.signal
|
|
3351
|
+
});
|
|
3352
|
+
for (; ; ) {
|
|
3353
|
+
const next = await runner.next();
|
|
3354
|
+
if (next.done) return { language, run: next.value };
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
|
|
990
3358
|
// src/test.ts
|
|
991
3359
|
var testTool = {
|
|
992
3360
|
name: "test",
|
|
@@ -1034,6 +3402,30 @@ var testTool = {
|
|
|
1034
3402
|
async *executeStream(input, ctx, opts) {
|
|
1035
3403
|
const cwd = input.cwd ? safeResolve(input.cwd, ctx) : ctx.cwd;
|
|
1036
3404
|
const runner = input.runner ?? "auto";
|
|
3405
|
+
if (runner === "auto") {
|
|
3406
|
+
const bridge = await tryLegacyCodeOperation("test", {
|
|
3407
|
+
cwd,
|
|
3408
|
+
projectRoot: ctx.projectRoot,
|
|
3409
|
+
signal: opts.signal
|
|
3410
|
+
});
|
|
3411
|
+
if (bridge?.run) {
|
|
3412
|
+
const run = bridge.run;
|
|
3413
|
+
yield {
|
|
3414
|
+
type: "final",
|
|
3415
|
+
output: {
|
|
3416
|
+
runner: bridge.language,
|
|
3417
|
+
exit_code: run.exitCode ?? 0,
|
|
3418
|
+
tests_run: (run.summary.passed ?? 0) + (run.summary.failed ?? 0),
|
|
3419
|
+
passed: run.summary.passed ?? 0,
|
|
3420
|
+
failed: run.summary.failed ?? 0,
|
|
3421
|
+
duration_ms: run.durationMs,
|
|
3422
|
+
output: normalizeCommandOutput(run.output || run.error || ""),
|
|
3423
|
+
truncated: run.truncated
|
|
3424
|
+
}
|
|
3425
|
+
};
|
|
3426
|
+
return;
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
1037
3429
|
const detected = runner === "auto" ? await detectRunner(cwd) : runner;
|
|
1038
3430
|
if (!detected) {
|
|
1039
3431
|
yield {
|
|
@@ -1066,11 +3458,11 @@ var testTool = {
|
|
|
1066
3458
|
}
|
|
1067
3459
|
};
|
|
1068
3460
|
async function detectRunner(cwd) {
|
|
1069
|
-
const { stat:
|
|
3461
|
+
const { stat: stat5 } = await import("node:fs/promises");
|
|
1070
3462
|
const candidates = ["vitest.config.ts", "jest.config.js", ".mocharc.json"];
|
|
1071
3463
|
for (const f of candidates) {
|
|
1072
3464
|
try {
|
|
1073
|
-
await
|
|
3465
|
+
await stat5(path9.join(cwd, f));
|
|
1074
3466
|
if (f.includes("vitest")) return "vitest";
|
|
1075
3467
|
if (f.includes("jest")) return "jest";
|
|
1076
3468
|
if (f.includes("mocha")) return "mocha";
|
|
@@ -1145,7 +3537,7 @@ function parseResult(runner, result, duration) {
|
|
|
1145
3537
|
truncated: result.truncated
|
|
1146
3538
|
};
|
|
1147
3539
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
3540
|
+
export {
|
|
3541
|
+
testTool
|
|
3542
|
+
};
|
|
1150
3543
|
//# sourceMappingURL=test.js.map
|
|
1151
|
-
//# sourceMappingURL=test.js.map
|