@wrongstack/tools 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/audit.js +19 -17
  2. package/dist/audit.js.map +1 -1
  3. package/dist/bash.js +2 -80
  4. package/dist/bash.js.map +1 -1
  5. package/dist/batch-tool-use.js.map +1 -1
  6. package/dist/builtin.js +2897 -2866
  7. package/dist/builtin.js.map +1 -1
  8. package/dist/diff.js +8 -3
  9. package/dist/diff.js.map +1 -1
  10. package/dist/document.js +31 -5
  11. package/dist/document.js.map +1 -1
  12. package/dist/edit.js +1 -3
  13. package/dist/edit.js.map +1 -1
  14. package/dist/exec.js +25 -81
  15. package/dist/exec.js.map +1 -1
  16. package/dist/fetch.js +5 -1
  17. package/dist/fetch.js.map +1 -1
  18. package/dist/format.js +24 -18
  19. package/dist/format.js.map +1 -1
  20. package/dist/git.js +6 -6
  21. package/dist/git.js.map +1 -1
  22. package/dist/glob.js.map +1 -1
  23. package/dist/grep.js +23 -23
  24. package/dist/grep.js.map +1 -1
  25. package/dist/index.js +197 -160
  26. package/dist/index.js.map +1 -1
  27. package/dist/install.js +31 -20
  28. package/dist/install.js.map +1 -1
  29. package/dist/json.js +4 -1
  30. package/dist/json.js.map +1 -1
  31. package/dist/lint.js +19 -17
  32. package/dist/lint.js.map +1 -1
  33. package/dist/logs.js +25 -22
  34. package/dist/logs.js.map +1 -1
  35. package/dist/memory.js.map +1 -1
  36. package/dist/mode.js +5 -1
  37. package/dist/mode.js.map +1 -1
  38. package/dist/outdated.js +10 -7
  39. package/dist/outdated.js.map +1 -1
  40. package/dist/patch.js +4 -9
  41. package/dist/patch.js.map +1 -1
  42. package/dist/read.js +5 -1
  43. package/dist/read.js.map +1 -1
  44. package/dist/replace.js +32 -25
  45. package/dist/replace.js.map +1 -1
  46. package/dist/scaffold.js +35 -20
  47. package/dist/scaffold.js.map +1 -1
  48. package/dist/search.js +5 -1
  49. package/dist/search.js.map +1 -1
  50. package/dist/test.js +17 -15
  51. package/dist/test.js.map +1 -1
  52. package/dist/todo.js.map +1 -1
  53. package/dist/tool-help.js +10 -8
  54. package/dist/tool-help.js.map +1 -1
  55. package/dist/tool-search.js.map +1 -1
  56. package/dist/tool-use.js.map +1 -1
  57. package/dist/tree.js +9 -1
  58. package/dist/tree.js.map +1 -1
  59. package/dist/typecheck.js +17 -15
  60. package/dist/typecheck.js.map +1 -1
  61. package/dist/write.js.map +1 -1
  62. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as fs4 from 'fs/promises';
2
2
  import * as path from 'path';
3
3
  import { dirname } from 'path';
4
- import { atomicWrite, unifiedDiff, detectNewlineStyle, normalizeToLf, toStyle, compileGlob, stripAnsi } from '@wrongstack/core';
4
+ import { atomicWrite, unifiedDiff, detectNewlineStyle, normalizeToLf, toStyle, compileGlob, buildChildEnv, stripAnsi } from '@wrongstack/core';
5
5
  import { spawn } from 'child_process';
6
6
  import * as os from 'os';
7
7
  import * as dns from 'dns/promises';
@@ -79,7 +79,11 @@ var readTool = {
79
79
  const allLines = text.split(/\r\n|\r|\n/);
80
80
  const total = allLines.length;
81
81
  const offset = Math.max(1, input.offset ?? 1);
82
- const limit = Math.max(1, Math.min(input.limit ?? 2e3, 5e3));
82
+ const limit = Math.max(0, Math.min(input.limit ?? 2e3, 5e3));
83
+ if (limit === 0) {
84
+ ctx.recordRead(absPath, stat9.mtimeMs);
85
+ return { text: "", total_lines: total, encoding: "utf8", truncated: total > 0 };
86
+ }
83
87
  const slice = allLines.slice(offset - 1, offset - 1 + limit);
84
88
  const truncated = offset - 1 + slice.length < total;
85
89
  const width = String(offset + slice.length - 1).length;
@@ -174,9 +178,7 @@ var editTool = {
174
178
  });
175
179
  if (!stat9.isFile()) throw new Error(`edit: "${input.path}" is not a regular file`);
176
180
  if (!ctx.hasRead(absPath)) {
177
- throw new Error(
178
- `edit: file "${input.path}" was not read in this session. Read it first.`
179
- );
181
+ throw new Error(`edit: file "${input.path}" was not read in this session. Read it first.`);
180
182
  }
181
183
  const lastReadMtime = ctx.lastReadMtime(absPath);
182
184
  const mtimeTolerance = process.platform === "win32" ? 2e3 : 1;
@@ -315,7 +317,10 @@ var replaceTool = {
315
317
  description: "File(s) to target: single path, comma-separated list, or glob pattern"
316
318
  },
317
319
  glob: { type: "string", description: 'Additional glob filter (e.g. "*.ts")' },
318
- replace_all: { type: "boolean", description: "Replace all occurrences in each file (default: true)" },
320
+ replace_all: {
321
+ type: "boolean",
322
+ description: "Replace all occurrences in each file (default: true)"
323
+ },
319
324
  dry_run: { type: "boolean", description: "Preview changes without writing" }
320
325
  },
321
326
  required: ["pattern", "replacement", "files"]
@@ -373,7 +378,10 @@ var replaceTool = {
373
378
  const newContent = toStyle(newContentLf, style);
374
379
  await atomicWrite(realPath, newContent, { mode: stat9.mode & 511 });
375
380
  }
376
- const diff = dryRun || matches.length > 0 ? unifiedDiff(content, toStyle(newContentLf, style), { fromFile: absPath, toFile: absPath }) : void 0;
381
+ const diff = dryRun || matches.length > 0 ? unifiedDiff(content, toStyle(newContentLf, style), {
382
+ fromFile: absPath,
383
+ toFile: absPath
384
+ }) : void 0;
377
385
  results.push({
378
386
  path: absPath,
379
387
  replacements: matches.length,
@@ -457,6 +465,7 @@ async function globNative(pattern, base, extraGlob) {
457
465
  for (const e of entries) {
458
466
  if (DEFAULT_IGNORE.includes(e.name)) continue;
459
467
  const full = path.join(dir, e.name);
468
+ if (e.isSymbolicLink()) continue;
460
469
  if (e.isDirectory()) {
461
470
  await walk(full);
462
471
  } else if (e.isFile()) {
@@ -793,84 +802,6 @@ async function runNative(input, base, mode, limit, signal) {
793
802
  };
794
803
  }
795
804
 
796
- // src/_env.ts
797
- var ALLOWED_KEYS = /* @__PURE__ */ new Set([
798
- "PATH",
799
- "HOME",
800
- "USER",
801
- "USERNAME",
802
- "LOGNAME",
803
- "SHELL",
804
- "LANG",
805
- "LC_ALL",
806
- "LC_CTYPE",
807
- "TERM",
808
- "TZ",
809
- "TMPDIR",
810
- "TEMP",
811
- "TMP",
812
- "PWD",
813
- "OLDPWD",
814
- "COMSPEC",
815
- "SYSTEMROOT",
816
- "SYSTEMDRIVE",
817
- "WINDIR",
818
- "PROGRAMFILES",
819
- "PROGRAMFILES(X86)",
820
- "PROGRAMDATA",
821
- "APPDATA",
822
- "LOCALAPPDATA",
823
- "USERPROFILE",
824
- "PUBLIC",
825
- "PATHEXT"
826
- ]);
827
- var SECRET_NAME_PARTS = [
828
- "TOKEN",
829
- "SECRET",
830
- "PASSWORD",
831
- "PASSWD",
832
- "AUTH",
833
- "CRED",
834
- "BEARER",
835
- "COOKIE",
836
- "PRIVATE"
837
- ];
838
- function looksSecret(name) {
839
- const upper = name.toUpperCase();
840
- for (const p of SECRET_NAME_PARTS) {
841
- if (upper.includes(p)) return true;
842
- }
843
- if (/(?:^|_)KEY(?:$|_|S$)/i.test(upper)) return true;
844
- if (/API[_-]?KEY/i.test(upper)) return true;
845
- if (/ACCESS[_-]?KEY/i.test(upper)) return true;
846
- if (/SESSION[_-]?ID/i.test(upper) === false && /SESSION/i.test(upper)) {
847
- return true;
848
- }
849
- return false;
850
- }
851
- function buildChildEnv(sessionId) {
852
- const passthrough = process.env["WRONGSTACK_BASH_ENV_PASSTHROUGH"] === "1";
853
- const out = {};
854
- for (const [k, v] of Object.entries(process.env)) {
855
- if (v === void 0) continue;
856
- if (passthrough) {
857
- out[k] = v;
858
- continue;
859
- }
860
- const upper = k.toUpperCase();
861
- if (ALLOWED_KEYS.has(upper)) {
862
- out[k] = v;
863
- continue;
864
- }
865
- if (looksSecret(upper)) continue;
866
- if (upper.startsWith("NODE_") || upper.startsWith("NPM_") || upper.startsWith("PNPM_") || upper.startsWith("YARN_") || upper.startsWith("GIT_") || upper.startsWith("CI") || upper.startsWith("XDG_") || upper === "EDITOR" || upper === "VISUAL" || upper === "PAGER") {
867
- out[k] = v;
868
- }
869
- }
870
- if (sessionId) out["WRONGSTACK_SESSION_ID"] = sessionId;
871
- return out;
872
- }
873
-
874
805
  // src/bash.ts
875
806
  var MAX_OUTPUT = 32768;
876
807
  var DEFAULT_TIMEOUT = 3e4;
@@ -908,7 +839,7 @@ var bashTool = {
908
839
  },
909
840
  async *executeStream(input, ctx, opts) {
910
841
  if (!input?.command) throw new Error("bash: command is required");
911
- const timeoutMs = Math.min(input.timeout_ms ?? DEFAULT_TIMEOUT, 6e5);
842
+ const timeoutMs = Math.max(1, Math.min(input.timeout_ms ?? DEFAULT_TIMEOUT, 6e5));
912
843
  const isWin = os.platform() === "win32";
913
844
  const shell = isWin ? process.env["COMSPEC"] ?? "cmd.exe" : process.env["SHELL"] ?? "/bin/bash";
914
845
  const args = isWin ? ["/c", input.command] : ["-c", input.command];
@@ -1058,7 +989,19 @@ var ALLOWED_COMMANDS = {
1058
989
  npm: ["--version", "init", "install", "test", "run", "list", "pkg", "doctor"],
1059
990
  pnpm: ["--version", "init", "install", "add", "remove", "exec", "list", "run", "dlx"],
1060
991
  npx: ["--version"],
1061
- git: ["--version", "status", "log", "diff", "branch", "checkout", "stash", "add", "commit", "push", "pull"],
992
+ git: [
993
+ "--version",
994
+ "status",
995
+ "log",
996
+ "diff",
997
+ "branch",
998
+ "checkout",
999
+ "stash",
1000
+ "add",
1001
+ "commit",
1002
+ "push",
1003
+ "pull"
1004
+ ],
1062
1005
  ls: ["-la", "-l", "-a"],
1063
1006
  cat: [],
1064
1007
  head: ["-n"],
@@ -1106,7 +1049,16 @@ var execTool = {
1106
1049
  },
1107
1050
  async execute(input, ctx, opts) {
1108
1051
  const cmd = input.command.trim();
1109
- if (!cmd) return { command: cmd, args: [], stdout: "", stderr: "Empty command", exitCode: 1, truncated: false, allowed: false };
1052
+ if (!cmd)
1053
+ return {
1054
+ command: cmd,
1055
+ args: [],
1056
+ stdout: "",
1057
+ stderr: "Empty command",
1058
+ exitCode: 1,
1059
+ truncated: false,
1060
+ allowed: false
1061
+ };
1110
1062
  if (!(cmd in ALLOWED_COMMANDS)) {
1111
1063
  return {
1112
1064
  command: cmd,
@@ -1119,7 +1071,7 @@ var execTool = {
1119
1071
  };
1120
1072
  }
1121
1073
  const args = (input.args ?? []).slice(0, MAX_ARGS);
1122
- const timeout = Math.min(input.timeout ?? TIMEOUT_MS, TIMEOUT_MS);
1074
+ const timeout = Math.max(1, Math.min(input.timeout ?? TIMEOUT_MS, TIMEOUT_MS));
1123
1075
  const requestedCwd = input.cwd ? path.resolve(ctx.projectRoot, input.cwd) : ctx.cwd;
1124
1076
  const rel = path.relative(ctx.projectRoot, requestedCwd);
1125
1077
  if (rel.startsWith("..") || path.isAbsolute(rel)) {
@@ -1272,7 +1224,11 @@ var fetchTool = {
1272
1224
  if (/^image\/|^audio\/|^video\/|application\/octet-stream/.test(ct)) {
1273
1225
  throw new Error(`fetch: refusing to read binary content-type "${ct}"`);
1274
1226
  }
1275
- yield { type: "log", text: `HTTP ${res.status} ${ct}`, data: { status: res.status, contentType: ct } };
1227
+ yield {
1228
+ type: "log",
1229
+ text: `HTTP ${res.status} ${ct}`,
1230
+ data: { status: res.status, contentType: ct }
1231
+ };
1276
1232
  const reader = res.body?.getReader();
1277
1233
  let received = 0;
1278
1234
  const chunks = [];
@@ -1507,7 +1463,11 @@ var searchTool = {
1507
1463
  if (!input?.query) throw new Error("search: query is required");
1508
1464
  const num = Math.max(1, Math.min(input.num_results ?? DEFAULT_NUM, MAX_RESULTS));
1509
1465
  const source = input.source ?? "duckduckgo";
1510
- yield { type: "log", text: `Querying ${source} for "${input.query}"\u2026`, data: { source, query: input.query } };
1466
+ yield {
1467
+ type: "log",
1468
+ text: `Querying ${source} for "${input.query}"\u2026`,
1469
+ data: { source, query: input.query }
1470
+ };
1511
1471
  let output;
1512
1472
  switch (source) {
1513
1473
  case "duckduckgo":
@@ -1820,11 +1780,7 @@ function buildArgs(input) {
1820
1780
  ...input.format === "short" || !input.format ? [] : []
1821
1781
  ];
1822
1782
  case "diff":
1823
- return [
1824
- "diff",
1825
- "--no-color",
1826
- ...files.length ? ["--", ...files] : []
1827
- ];
1783
+ return ["diff", "--no-color", ...files.length ? ["--", ...files] : []];
1828
1784
  case "commit":
1829
1785
  return [
1830
1786
  "commit",
@@ -1835,7 +1791,11 @@ function buildArgs(input) {
1835
1791
  case "branch":
1836
1792
  return input.branch ? ["branch", input.branch] : ["branch"];
1837
1793
  case "checkout":
1838
- return ["checkout", ...input.branch ? [input.branch] : [], ...files.length ? ["--", ...files] : []];
1794
+ return [
1795
+ "checkout",
1796
+ ...input.branch ? [input.branch] : [],
1797
+ ...files.length ? ["--", ...files] : []
1798
+ ];
1839
1799
  case "stash":
1840
1800
  return input.message ? ["stash", "push", "-m", input.message] : ["stash", "push"];
1841
1801
  case "push":
@@ -1933,13 +1893,7 @@ var patchTool = {
1933
1893
  });
1934
1894
  const patchFile = path.join(tmpDir, "in.diff");
1935
1895
  await fs4.writeFile(patchFile, input.patch, { mode: 384 });
1936
- const args = [
1937
- `-p${strip}`,
1938
- "--merge",
1939
- ...dryRun ? ["--dry-run"] : [],
1940
- "-i",
1941
- patchFile
1942
- ];
1896
+ const args = [`-p${strip}`, "--merge", ...dryRun ? ["--dry-run"] : [], "-i", patchFile];
1943
1897
  const result = await runPatch(args, dir, opts.signal);
1944
1898
  if (result.exitCode !== 0 && !dryRun) {
1945
1899
  return {
@@ -1983,7 +1937,7 @@ function runPatch(args, cwd, signal) {
1983
1937
  return new Promise((resolve4) => {
1984
1938
  let stdout = "";
1985
1939
  let stderr = "";
1986
- const env = { ...process.env, LANG: "C", LC_ALL: "C" };
1940
+ const env = { ...buildChildEnv(), LANG: "C", LC_ALL: "C" };
1987
1941
  const child = spawn("patch", args, { cwd, signal, env, stdio: ["pipe", "pipe", "pipe"] });
1988
1942
  child.stdout?.on("data", (c) => {
1989
1943
  stdout += c.toString();
@@ -2015,7 +1969,10 @@ var jsonTool = {
2015
1969
  properties: {
2016
1970
  file: { type: "string", description: "Path to JSON/JSON5/YAML file" },
2017
1971
  data: { type: "string", description: "JSON/JSON5/YAML string (alternative to file)" },
2018
- query: { type: "string", description: 'JMESPath-like query (e.g. "a.b[0].c" or "a[*].name")' },
1972
+ query: {
1973
+ type: "string",
1974
+ description: 'JMESPath-like query (e.g. "a.b[0].c" or "a[*].name")'
1975
+ },
2019
1976
  format: {
2020
1977
  type: "string",
2021
1978
  enum: ["json", "json5", "yaml"],
@@ -2208,7 +2165,12 @@ async function fileDiff(input, ctx, signal) {
2208
2165
  input.context ?? 3;
2209
2166
  const files = input.files ? (Array.isArray(input.files) ? input.files : input.files.split(",")).map((f) => f.trim()).filter(Boolean) : [];
2210
2167
  if (files.length === 0) {
2211
- return { diff: "No files specified", files: [], truncated: false, mode: input.mode ?? "unified" };
2168
+ return {
2169
+ diff: "No files specified",
2170
+ files: [],
2171
+ truncated: false,
2172
+ mode: input.mode ?? "unified"
2173
+ };
2212
2174
  }
2213
2175
  const results = [];
2214
2176
  for (const file of files) {
@@ -2231,7 +2193,15 @@ ${formatUnified(lines)}`);
2231
2193
  function formatUnified(lines, context) {
2232
2194
  return lines.map((line, i) => ` ${line}`).join("\n");
2233
2195
  }
2234
- var DEFAULT_IGNORE4 = ["node_modules", ".git", "dist", "build", ".next", "coverage", "__pycache__"];
2196
+ var DEFAULT_IGNORE4 = [
2197
+ "node_modules",
2198
+ ".git",
2199
+ "dist",
2200
+ "build",
2201
+ ".next",
2202
+ "coverage",
2203
+ "__pycache__"
2204
+ ];
2235
2205
  var treeTool = {
2236
2206
  name: "tree",
2237
2207
  description: "Display directory structure as an ASCII tree. Shows files and folders with indentation.",
@@ -2396,6 +2366,7 @@ async function* spawnStream(opts) {
2396
2366
  const child = spawn(opts.cmd, opts.args, {
2397
2367
  cwd: opts.cwd,
2398
2368
  signal: opts.signal,
2369
+ env: buildChildEnv(),
2399
2370
  stdio: ["ignore", "pipe", "pipe"]
2400
2371
  });
2401
2372
  const queue = [];
@@ -2607,7 +2578,11 @@ var formatTool = {
2607
2578
  };
2608
2579
  return;
2609
2580
  }
2610
- yield { type: "log", text: `Running ${detected}\u2026`, data: { fixer: detected, check: !!input.check } };
2581
+ yield {
2582
+ type: "log",
2583
+ text: `Running ${detected}\u2026`,
2584
+ data: { fixer: detected, check: !!input.check }
2585
+ };
2611
2586
  const args = ["format", "--write"];
2612
2587
  if (input.check) args[args.length - 1] = "--check";
2613
2588
  if (input.files) {
@@ -2894,7 +2869,10 @@ var installTool = {
2894
2869
  description: "Save as regular, dev, or optional dependency"
2895
2870
  },
2896
2871
  cwd: { type: "string", description: "Working directory (default: cwd)" },
2897
- dry_run: { type: "boolean", description: "Preview install without modifying (default: false)" },
2872
+ dry_run: {
2873
+ type: "boolean",
2874
+ description: "Preview install without modifying (default: false)"
2875
+ },
2898
2876
  global: { type: "boolean", description: "Install globally (default: false)" }
2899
2877
  }
2900
2878
  },
@@ -2922,9 +2900,15 @@ var installTool = {
2922
2900
  } else {
2923
2901
  args.push("install", ...globalFlag);
2924
2902
  }
2925
- const pkgList = input.packages ? (Array.isArray(input.packages) ? input.packages : input.packages.split(",")).map((p) => p.trim()) : [];
2903
+ const pkgList = input.packages ? (Array.isArray(input.packages) ? input.packages : input.packages.split(",")).map(
2904
+ (p) => p.trim()
2905
+ ) : [];
2926
2906
  if (pkgList.length > 0) args.push(...pkgList);
2927
- yield { type: "log", text: `Fetching ${pkgList.length || "all"} packages\u2026`, data: { phase: "fetch" } };
2907
+ yield {
2908
+ type: "log",
2909
+ text: `Fetching ${pkgList.length || "all"} packages\u2026`,
2910
+ data: { phase: "fetch" }
2911
+ };
2928
2912
  const result = yield* spawnStream({
2929
2913
  cmd: pkgManager,
2930
2914
  args,
@@ -3132,13 +3116,16 @@ function runOutdated(manager, args, cwd, signal) {
3132
3116
  const result = parseOutdatedOutput(stdout, code ?? 0);
3133
3117
  resolve4(result);
3134
3118
  });
3135
- child.on("error", (e) => resolve4({
3136
- exit_code: 1,
3137
- packages: [],
3138
- total: 0,
3139
- output: e.message,
3140
- truncated: false
3141
- }));
3119
+ child.on(
3120
+ "error",
3121
+ (e) => resolve4({
3122
+ exit_code: 1,
3123
+ packages: [],
3124
+ total: 0,
3125
+ output: e.message,
3126
+ truncated: false
3127
+ })
3128
+ );
3142
3129
  });
3143
3130
  }
3144
3131
  function parseOutdatedOutput(json, exitCode) {
@@ -3267,13 +3254,16 @@ async function dockerLogs(service, lines, filterRe, cwd, signal, since) {
3267
3254
  stream_mode: false
3268
3255
  });
3269
3256
  });
3270
- child.on("error", (e) => resolve4({
3271
- source: `docker:${service}`,
3272
- entries: [],
3273
- total: 0,
3274
- truncated: false,
3275
- stream_mode: false
3276
- }));
3257
+ child.on(
3258
+ "error",
3259
+ (e) => resolve4({
3260
+ source: `docker:${service}`,
3261
+ entries: [],
3262
+ total: 0,
3263
+ truncated: false,
3264
+ stream_mode: false
3265
+ })
3266
+ );
3277
3267
  });
3278
3268
  }
3279
3269
  var MAX_TAIL_LINES = 1e5;
@@ -3395,7 +3385,13 @@ var documentTool = {
3395
3385
  try {
3396
3386
  const content = await fs4.readFile(absPath, "utf8");
3397
3387
  filesProcessed++;
3398
- const processed = processFile(content, absPath, style, input.overwrite ?? false, input.target ?? "all");
3388
+ const processed = processFile(
3389
+ content,
3390
+ absPath,
3391
+ style,
3392
+ input.overwrite ?? false,
3393
+ input.target ?? "all"
3394
+ );
3399
3395
  results.push(...processed);
3400
3396
  itemsDocumented += processed.filter((r) => r.status === "documented").length;
3401
3397
  } catch (e) {
@@ -3441,23 +3437,43 @@ function processFile(content, absPath, style, overwrite, target) {
3441
3437
  if (target === "all" || target === "function") {
3442
3438
  for (const m of content.matchAll(functionRegex)) {
3443
3439
  if (!m[1]) continue;
3444
- allMatches.push({ name: m[1], sig: m[2] ?? "", type: "function", line: content.slice(0, m.index).split("\n").length });
3440
+ allMatches.push({
3441
+ name: m[1],
3442
+ sig: m[2] ?? "",
3443
+ type: "function",
3444
+ line: content.slice(0, m.index).split("\n").length
3445
+ });
3445
3446
  }
3446
3447
  for (const m of content.matchAll(arrowRegex)) {
3447
3448
  if (!m[1]) continue;
3448
- allMatches.push({ name: m[1], sig: m[2] ?? "", type: "arrow", line: content.slice(0, m.index).split("\n").length });
3449
+ allMatches.push({
3450
+ name: m[1],
3451
+ sig: m[2] ?? "",
3452
+ type: "arrow",
3453
+ line: content.slice(0, m.index).split("\n").length
3454
+ });
3449
3455
  }
3450
3456
  }
3451
3457
  if (target === "all" || target === "class") {
3452
3458
  for (const m of content.matchAll(classRegex)) {
3453
3459
  if (!m[1]) continue;
3454
- allMatches.push({ name: m[1], sig: "", type: "class", line: content.slice(0, m.index).split("\n").length });
3460
+ allMatches.push({
3461
+ name: m[1],
3462
+ sig: "",
3463
+ type: "class",
3464
+ line: content.slice(0, m.index).split("\n").length
3465
+ });
3455
3466
  }
3456
3467
  }
3457
3468
  if (target === "all" || target === "type") {
3458
3469
  for (const m of content.matchAll(typeRegex)) {
3459
3470
  if (!m[1]) continue;
3460
- allMatches.push({ name: m[1], sig: m[0] ?? "", type: "type", line: content.slice(0, m.index).split("\n").length });
3471
+ allMatches.push({
3472
+ name: m[1],
3473
+ sig: m[0] ?? "",
3474
+ type: "type",
3475
+ line: content.slice(0, m.index).split("\n").length
3476
+ });
3461
3477
  }
3462
3478
  }
3463
3479
  for (const m of allMatches) {
@@ -3475,18 +3491,26 @@ var BUILT_IN_TEMPLATES = {
3475
3491
  "npm-package": {
3476
3492
  description: "Basic npm package with ESM",
3477
3493
  files: {
3478
- "package.json": JSON.stringify({
3479
- name: "{{name}}",
3480
- version: "0.1.1",
3481
- type: "module",
3482
- main: "./dist/index.js",
3483
- scripts: { build: "tsc", test: "vitest run" },
3484
- devDependencies: { typescript: "^5.0.0" }
3485
- }, null, 2),
3486
- "tsconfig.json": JSON.stringify({
3487
- compilerOptions: { target: "ES2022", module: "ESNext", strict: true },
3488
- include: ["src"]
3489
- }, null, 2),
3494
+ "package.json": JSON.stringify(
3495
+ {
3496
+ name: "{{name}}",
3497
+ version: "0.1.1",
3498
+ type: "module",
3499
+ main: "./dist/index.js",
3500
+ scripts: { build: "tsc", test: "vitest run" },
3501
+ devDependencies: { typescript: "^5.0.0" }
3502
+ },
3503
+ null,
3504
+ 2
3505
+ ),
3506
+ "tsconfig.json": JSON.stringify(
3507
+ {
3508
+ compilerOptions: { target: "ES2022", module: "ESNext", strict: true },
3509
+ include: ["src"]
3510
+ },
3511
+ null,
3512
+ 2
3513
+ ),
3490
3514
  "src/index.ts": `export function hello() {
3491
3515
  return 'Hello from {{name}}';
3492
3516
  }
@@ -3505,13 +3529,17 @@ describe('hello', () => {
3505
3529
  "cli-tool": {
3506
3530
  description: "CLI tool with argparse",
3507
3531
  files: {
3508
- "package.json": JSON.stringify({
3509
- name: "{{name}}",
3510
- version: "0.1.1",
3511
- type: "module",
3512
- bin: { "{{name}}": "./src/index.js" },
3513
- scripts: { build: "tsc", start: "node dist/index.js" }
3514
- }, null, 2),
3532
+ "package.json": JSON.stringify(
3533
+ {
3534
+ name: "{{name}}",
3535
+ version: "0.1.1",
3536
+ type: "module",
3537
+ bin: { "{{name}}": "./src/index.js" },
3538
+ scripts: { build: "tsc", start: "node dist/index.js" }
3539
+ },
3540
+ null,
3541
+ 2
3542
+ ),
3515
3543
  "src/index.ts": `#!/usr/bin/env node
3516
3544
 
3517
3545
  async function main() {
@@ -3624,7 +3652,10 @@ async function handleBuiltIn(name, templateFiles, cwd, dryRun, vars) {
3624
3652
  function substituteVars(content, name, vars) {
3625
3653
  let result = content;
3626
3654
  result = result.replace(/\{\{name\}\}/g, name.toLowerCase().replace(/\s+/g, "-"));
3627
- result = result.replace(/\{\{Name\}\}/g, name.replace(/(?:^|[-_\s]+)([a-z])/g, (_, c) => c.toUpperCase()));
3655
+ result = result.replace(
3656
+ /\{\{Name\}\}/g,
3657
+ name.replace(/(?:^|[-_\s]+)([a-z])/g, (_, c) => c.toUpperCase())
3658
+ );
3628
3659
  for (const [k, v] of Object.entries(vars)) {
3629
3660
  result = result.replace(new RegExp(`\\{\\{${k}\\}\\}`, "g"), v);
3630
3661
  }
@@ -3911,14 +3942,16 @@ var toolHelpTool = {
3911
3942
  return {
3912
3943
  tool: tool.name,
3913
3944
  help: formatToolHelp(tool, format, includeExamples),
3914
- tools: [{
3915
- name: tool.name,
3916
- description: tool.description,
3917
- usageHint: tool.usageHint ?? "",
3918
- inputSchema: tool.inputSchema,
3919
- permission: tool.permission,
3920
- mutating: tool.mutating
3921
- }],
3945
+ tools: [
3946
+ {
3947
+ name: tool.name,
3948
+ description: tool.description,
3949
+ usageHint: tool.usageHint ?? "",
3950
+ inputSchema: tool.inputSchema,
3951
+ permission: tool.permission,
3952
+ mutating: tool.mutating
3953
+ }
3954
+ ],
3922
3955
  total: 1
3923
3956
  };
3924
3957
  }
@@ -4110,7 +4143,11 @@ ${mode.description}`
4110
4143
  };
4111
4144
  }
4112
4145
  default:
4113
- return { action: input.action, success: false, message: `Unknown action "${input.action}"` };
4146
+ return {
4147
+ action: input.action,
4148
+ success: false,
4149
+ message: `Unknown action "${input.action}"`
4150
+ };
4114
4151
  }
4115
4152
  }
4116
4153
  };