@wrongstack/tools 0.313.0 → 0.313.1

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 (134) hide show
  1. package/dist/audit.js +10 -4055
  2. package/dist/bash.js +9 -2308
  3. package/dist/batch-tool-use.js +2 -187
  4. package/dist/browser/index.js +25 -1339
  5. package/dist/builtin.js +69 -33949
  6. package/dist/chunk-2CTB3UK5.js +197 -0
  7. package/dist/chunk-2ME7ZWDD.js +1272 -0
  8. package/dist/chunk-2TFQDEPU.js +113 -0
  9. package/dist/chunk-2ZCJNKFE.js +315 -0
  10. package/dist/chunk-3PVYQFRQ.js +472 -0
  11. package/dist/chunk-3QMQBO5Z.js +89 -0
  12. package/dist/chunk-42AKKX7O.js +385 -0
  13. package/dist/chunk-42SKEETB.js +113 -0
  14. package/dist/chunk-4BHUSMNL.js +104 -0
  15. package/dist/chunk-4I4LWFOO.js +431 -0
  16. package/dist/chunk-553IQUMO.js +478 -0
  17. package/dist/chunk-55KF77OK.js +1944 -0
  18. package/dist/chunk-6HLZK37X.js +359 -0
  19. package/dist/chunk-6RNIFLG4.js +305 -0
  20. package/dist/chunk-A6BRWIXN.js +317 -0
  21. package/dist/chunk-AHHDWNXC.js +200 -0
  22. package/dist/chunk-B2CIOKWP.js +899 -0
  23. package/dist/chunk-BTSFTGIL.js +7 -0
  24. package/dist/chunk-D33S4RQG.js +222 -0
  25. package/dist/chunk-DIJKHSUO.js +134 -0
  26. package/dist/chunk-DPL47QGS.js +3515 -0
  27. package/dist/chunk-EMRGN4KM.js +170 -0
  28. package/dist/chunk-FGOABE4Z.js +955 -0
  29. package/dist/chunk-FW65TP4G.js +520 -0
  30. package/dist/chunk-GOIZNNOA.js +221 -0
  31. package/dist/chunk-H5MJUAA6.js +295 -0
  32. package/dist/chunk-H5OHH6F4.js +223 -0
  33. package/dist/chunk-HC5RM4WY.js +199 -0
  34. package/dist/chunk-HEQFMLZ7.js +190 -0
  35. package/dist/chunk-HFXSNKCV.js +196 -0
  36. package/dist/chunk-HXSBQ2SE.js +1723 -0
  37. package/dist/chunk-ILESNGNM.js +163 -0
  38. package/dist/chunk-INF5CGAO.js +137 -0
  39. package/dist/chunk-IWDFZ6XR.js +337 -0
  40. package/dist/chunk-IXMNTNW5.js +238 -0
  41. package/dist/chunk-J4SRJKBW.js +428 -0
  42. package/dist/chunk-J5SKD6LN.js +235 -0
  43. package/dist/chunk-JRJJX3L5.js +424 -0
  44. package/dist/chunk-KXNDHMUB.js +366 -0
  45. package/dist/chunk-LIJQMYYX.js +59 -0
  46. package/dist/chunk-MAN26PZ5.js +260 -0
  47. package/dist/chunk-MKRQMLZA.js +474 -0
  48. package/dist/chunk-NBDZMMG2.js +169 -0
  49. package/dist/chunk-NHA6BEIH.js +101 -0
  50. package/dist/chunk-OA6YJIWL.js +4412 -0
  51. package/dist/chunk-OZC255IC.js +2830 -0
  52. package/dist/chunk-PUR6WU2B.js +154 -0
  53. package/dist/chunk-Q5JPPCZC.js +12 -0
  54. package/dist/chunk-QBV725YG.js +128 -0
  55. package/dist/chunk-QHVW4AAM.js +892 -0
  56. package/dist/chunk-QNJ7AQ4B.js +1000 -0
  57. package/dist/chunk-RGISBZBD.js +231 -0
  58. package/dist/chunk-RJZQWEMS.js +84 -0
  59. package/dist/chunk-RP2ZA47V.js +15 -0
  60. package/dist/chunk-RXISBFR5.js +315 -0
  61. package/dist/chunk-S5CCLZL3.js +99 -0
  62. package/dist/chunk-TVTCSBJF.js +122 -0
  63. package/dist/chunk-U4D5S3VQ.js +21 -0
  64. package/dist/chunk-U4VAATKP.js +193 -0
  65. package/dist/chunk-UKU2ZX4C.js +203 -0
  66. package/dist/chunk-UNSKG6DC.js +159 -0
  67. package/dist/chunk-URFKEIHM.js +1091 -0
  68. package/dist/chunk-UTV7YAW7.js +178 -0
  69. package/dist/chunk-V43EQ6VR.js +68 -0
  70. package/dist/chunk-VB3MJGCV.js +610 -0
  71. package/dist/chunk-WHIIIREL.js +223 -0
  72. package/dist/chunk-XMIFYKUT.js +1371 -0
  73. package/dist/chunk-YF2RSV34.js +54 -0
  74. package/dist/chunk-Z6DAKQ3U.js +1 -0
  75. package/dist/chunk-ZIGAZFWE.js +522 -0
  76. package/dist/circuit-breaker.js +3 -191
  77. package/dist/codebase-index/index.js +84 -13688
  78. package/dist/codebase-index/parser-worker-script.js +8 -3995
  79. package/dist/codebase-index/project-server.js +60 -8548
  80. package/dist/codebase-index/worker.js +20 -8416
  81. package/dist/design.js +2 -299
  82. package/dist/diff.js +4 -256
  83. package/dist/document.js +4 -222
  84. package/dist/e2e.js +5 -476
  85. package/dist/edit.js +14 -10200
  86. package/dist/exec.js +16 -3131
  87. package/dist/fetch.js +8 -398
  88. package/dist/format.js +10 -3750
  89. package/dist/generic-parser-VUXDIAOZ.js +13 -0
  90. package/dist/git.js +4 -380
  91. package/dist/glob.js +6 -280
  92. package/dist/go-parser-6CA77WZ4.js +469 -0
  93. package/dist/grep.js +7 -604
  94. package/dist/index.js +318 -35387
  95. package/dist/install.js +10 -4091
  96. package/dist/json-parser-7YMDJSBJ.js +213 -0
  97. package/dist/json.js +4 -665
  98. package/dist/kanban.js +3 -2096
  99. package/dist/languages/index.js +23 -4664
  100. package/dist/legacy-bridge-7UKZT46G.js +18 -0
  101. package/dist/lint.js +10 -3706
  102. package/dist/logs.js +4 -287
  103. package/dist/memory.js +6 -215
  104. package/dist/mode.js +3 -99
  105. package/dist/outdated.js +4 -5170
  106. package/dist/pack.js +65 -33897
  107. package/dist/parser-dispatch-VPOFDO2U.js +14 -0
  108. package/dist/patch.js +13 -9935
  109. package/dist/plan.js +5 -3286
  110. package/dist/process-registry.js +8 -651
  111. package/dist/ps-slash.js +12 -1439
  112. package/dist/py-parser-GPM5VYRG.js +16 -0
  113. package/dist/read.js +13 -9816
  114. package/dist/replace.js +15 -10014
  115. package/dist/rs-parser-WVQ4KYCX.js +81 -0
  116. package/dist/scaffold.js +4 -253
  117. package/dist/search.js +5 -585
  118. package/dist/session-kanban.js +30 -972
  119. package/dist/skill.js +2 -215
  120. package/dist/task.js +5 -3410
  121. package/dist/test.js +10 -3773
  122. package/dist/todo.js +4 -2891
  123. package/dist/tool-help.js +3 -123
  124. package/dist/tool-search.js +3 -79
  125. package/dist/tool-tier.js +68 -33984
  126. package/dist/tool-use.js +2 -93
  127. package/dist/tree-sitter-parser-YCILHGZD.js +17 -0
  128. package/dist/tree.js +4 -288
  129. package/dist/ts-parser-YH4ZMWMH.js +232 -0
  130. package/dist/typecheck.js +10 -3753
  131. package/dist/win32.js +6 -60
  132. package/dist/write.js +14 -9882
  133. package/dist/yaml-parser-GFAOKV53.js +157 -0
  134. package/package.json +5 -5
@@ -0,0 +1,317 @@
1
+ // src/codebase-index/generic-parser.ts
2
+ var C_LIKE = [
3
+ { re: /\b(?:class|struct|enum|interface|union)\s+([A-Za-z_]\w*)/g, kind: "class" },
4
+ {
5
+ re: /\b(?:public|private|protected|static|final|async|override|virtual|inline|export)?\s*(?:[\w:<>[\]\s*&]+)\s+([A-Za-z_]\w*)\s*\([^;{]*\)\s*(?:const)?\s*[{;]/g,
6
+ kind: "function"
7
+ },
8
+ { re: /\b(?:namespace)\s+([A-Za-z_]\w*)/g, kind: "namespace" }
9
+ ];
10
+ var LANG_PATTERNS = {
11
+ py: [
12
+ { re: /^(?:async\s+)?def\s+([A-Za-z_]\w*)/gm, kind: "function" },
13
+ { re: /^class\s+([A-Za-z_]\w*)/gm, kind: "class" },
14
+ { re: /^([A-Za-z_]\w*)\s*=/gm, kind: "var" }
15
+ ],
16
+ go: [
17
+ { re: /^func\s+(?:\([^)]*\)\s*)?([A-Za-z_]\w*)\s*\(/gm, kind: "function" },
18
+ { re: /^type\s+([A-Za-z_]\w*)\b/gm, kind: "type" },
19
+ { re: /^(?:const|var)\s+([A-Za-z_]\w*)\b/gm, kind: "const" },
20
+ { re: /^package\s+([A-Za-z_]\w*)/gm, kind: "namespace" }
21
+ ],
22
+ rs: [
23
+ { re: /\bfn\s+([A-Za-z_]\w*)/g, kind: "function" },
24
+ { re: /\bstruct\s+([A-Za-z_]\w*)/g, kind: "struct" },
25
+ { re: /\benum\s+([A-Za-z_]\w*)/g, kind: "enum" },
26
+ { re: /\btrait\s+([A-Za-z_]\w*)/g, kind: "trait" },
27
+ { re: /\bimpl(?:\s*<[^>]+>)?\s+([A-Za-z_]\w*)/g, kind: "impl" },
28
+ { re: /\b(?:const|static)\s+([A-Za-z_]\w*)/g, kind: "const" },
29
+ { re: /\bmod\s+([A-Za-z_]\w*)/g, kind: "mod" }
30
+ ],
31
+ c: C_LIKE,
32
+ cpp: C_LIKE,
33
+ java: [
34
+ { re: /\b(?:class|interface|enum|record)\s+([A-Za-z_]\w*)/g, kind: "class" },
35
+ {
36
+ re: /\b(?:public|private|protected|static|final|abstract|synchronized|native|default|\s)+\s*[\w.<>,[\]\s]+\s+([A-Za-z_]\w*)\s*\(/g,
37
+ kind: "method"
38
+ }
39
+ ],
40
+ csharp: [
41
+ { re: /\b(?:class|interface|struct|enum|record)\s+([A-Za-z_]\w*)/g, kind: "class" },
42
+ { re: /\bnamespace\s+([A-Za-z_.\w]+)/g, kind: "namespace" },
43
+ {
44
+ re: /\b(?:public|private|protected|internal|static|async|override|virtual|\s)+\s*[\w.<>,[\]\s]+\s+([A-Za-z_]\w*)\s*\(/g,
45
+ kind: "method"
46
+ }
47
+ ],
48
+ php: [
49
+ { re: /\bfunction\s+([A-Za-z_]\w*)/g, kind: "function" },
50
+ { re: /\bclass\s+([A-Za-z_]\w*)/g, kind: "class" },
51
+ { re: /\binterface\s+([A-Za-z_]\w*)/g, kind: "interface" },
52
+ { re: /\bnamespace\s+([A-Za-z_\\]+)/g, kind: "namespace" }
53
+ ],
54
+ ruby: [
55
+ { re: /^\s*def\s+(?:self\.)?([A-Za-z_]\w*[!?]?)/gm, kind: "function" },
56
+ { re: /^\s*class\s+([A-Za-z_]\w*)/gm, kind: "class" },
57
+ { re: /^\s*module\s+([A-Za-z_]\w*)/gm, kind: "namespace" }
58
+ ],
59
+ swift: [
60
+ { re: /\b(?:func)\s+([A-Za-z_]\w*)/g, kind: "function" },
61
+ { re: /\b(?:class|struct|enum|protocol|actor)\s+([A-Za-z_]\w*)/g, kind: "class" }
62
+ ],
63
+ kotlin: [
64
+ { re: /\b(?:fun)\s+([A-Za-z_]\w*)/g, kind: "function" },
65
+ {
66
+ re: /\b(?:class|interface|object|enum\s+class|data\s+class)\s+([A-Za-z_]\w*)/g,
67
+ kind: "class"
68
+ }
69
+ ],
70
+ scala: [
71
+ { re: /\b(?:def)\s+([A-Za-z_]\w*)/g, kind: "function" },
72
+ { re: /\b(?:class|object|trait|enum)\s+([A-Za-z_]\w*)/g, kind: "class" }
73
+ ],
74
+ shell: [
75
+ { re: /^(?:function\s+)?([A-Za-z_]\w*)\s*\(\)\s*\{/gm, kind: "function" },
76
+ { re: /^([A-Za-z_][\w]*)\s*\(\)\s*\{/gm, kind: "function" }
77
+ ],
78
+ sql: [
79
+ {
80
+ re: /\bCREATE\s+(?:OR\s+REPLACE\s+)?(?:TABLE|VIEW|INDEX|FUNCTION|PROCEDURE|TRIGGER)\s+(?:IF\s+NOT\s+EXISTS\s+)?([A-Za-z_"][\w."]*)/gi,
81
+ kind: "type"
82
+ }
83
+ ],
84
+ md: [{ re: /^(#{1,6})\s+(.+)$/gm, kind: "namespace" }],
85
+ toml: [{ re: /^\[([^\]]+)\]/gm, kind: "namespace" }],
86
+ html: [
87
+ { re: /\bid\s*=\s*["']([^"']+)["']/gi, kind: "property" },
88
+ { re: /<(?:script|template|style)\b/gi, kind: "namespace" }
89
+ ],
90
+ css: [
91
+ { re: /^\s*([.#]?[A-Za-z_][\w-]*)\s*\{/gm, kind: "type" },
92
+ { re: /@(?:keyframes|media|supports)\s+([^{\s]+)/g, kind: "namespace" }
93
+ ],
94
+ vue: [
95
+ {
96
+ re: /\b(?:function|const|let|var|class|export\s+(?:default\s+)?(?:function|class|const))\s+([A-Za-z_]\w*)/g,
97
+ kind: "function"
98
+ },
99
+ { re: /<(?:script|template|style)\b/gi, kind: "namespace" }
100
+ ],
101
+ svelte: [
102
+ {
103
+ re: /\b(?:function|const|let|var|class|export\s+(?:default\s+)?(?:function|class|const))\s+([A-Za-z_]\w*)/g,
104
+ kind: "function"
105
+ }
106
+ ],
107
+ dart: [
108
+ { re: /\b(?:class|enum|mixin|extension)\s+([A-Za-z_]\w*)/g, kind: "class" },
109
+ { re: /\b([A-Za-z_]\w*)\s*\([^;]*\)\s*(?:async\s*)?\{/g, kind: "function" }
110
+ ],
111
+ lua: [
112
+ { re: /\bfunction\s+([A-Za-z_.:]\w*)/g, kind: "function" },
113
+ { re: /\blocal\s+function\s+([A-Za-z_]\w*)/g, kind: "function" }
114
+ ],
115
+ r: [
116
+ { re: /([A-Za-z.]\w*)\s*<-\s*function\s*\(/g, kind: "function" },
117
+ { re: /([A-Za-z.]\w*)\s*=\s*function\s*\(/g, kind: "function" }
118
+ ],
119
+ proto: [
120
+ { re: /\b(?:message|service|enum)\s+([A-Za-z_]\w*)/g, kind: "type" },
121
+ { re: /\brpc\s+([A-Za-z_]\w*)/g, kind: "function" }
122
+ ],
123
+ graphql: [
124
+ { re: /\b(?:type|interface|enum|input|union|scalar)\s+([A-Za-z_]\w*)/g, kind: "type" },
125
+ { re: /\b(?:query|mutation|subscription)\s+([A-Za-z_]\w*)/g, kind: "function" }
126
+ ],
127
+ zig: [
128
+ { re: /\b(?:fn|pub\s+fn)\s+([A-Za-z_]\w*)/g, kind: "function" },
129
+ { re: /\b(?:const|var)\s+([A-Za-z_]\w*)/g, kind: "const" },
130
+ { re: /\b(?:struct|enum|union)\s*\{/g, kind: "type" }
131
+ ],
132
+ elixir: [
133
+ { re: /\bdef(?:p|macro|macrop)?\s+([A-Za-z_]\w*[!?]?)/g, kind: "function" },
134
+ // Dotted module names must be captured whole: `alias Foo.Bar` resolves
135
+ // against this symbol, and a `Foo`-only capture never matches it.
136
+ { re: /\bdefmodule\s+([A-Z][\w.]*)/g, kind: "namespace" }
137
+ ],
138
+ haskell: [
139
+ // Target of `import Data.List`.
140
+ { re: /^module\s+([A-Z][\w.]*)/gm, kind: "namespace" },
141
+ { re: /^([A-Za-z_]\w*)\s*::/gm, kind: "function" },
142
+ { re: /\bdata\s+([A-Za-z_]\w*)/g, kind: "type" },
143
+ { re: /\btype\s+(?:family\s+)?([A-Za-z_]\w*)/g, kind: "type" },
144
+ { re: /\bclass\s+([A-Za-z_]\w*)/g, kind: "class" }
145
+ ],
146
+ other: [
147
+ { re: /^(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_]\w*)/gm, kind: "function" },
148
+ { re: /^(?:export\s+)?class\s+([A-Za-z_]\w*)/gm, kind: "class" },
149
+ { re: /^(?:export\s+)?(?:const|let|var)\s+([A-Za-z_]\w*)/gm, kind: "const" },
150
+ { re: /^(?:async\s+)?def\s+([A-Za-z_]\w*)/gm, kind: "function" },
151
+ { re: /^func\s+(?:\([^)]*\)\s*)?([A-Za-z_]\w*)/gm, kind: "function" },
152
+ { re: /\bfn\s+([A-Za-z_]\w*)/g, kind: "function" },
153
+ { re: /^(?:target|PHONY)\s*:/gm, kind: "namespace" }
154
+ ]
155
+ };
156
+ var KEYWORDS = /* @__PURE__ */ new Set([
157
+ "if",
158
+ "else",
159
+ "for",
160
+ "while",
161
+ "switch",
162
+ "case",
163
+ "return",
164
+ "break",
165
+ "continue",
166
+ "new",
167
+ "delete",
168
+ "typeof",
169
+ "instanceof",
170
+ "void",
171
+ "null",
172
+ "true",
173
+ "false",
174
+ "this",
175
+ "super",
176
+ "import",
177
+ "export",
178
+ "from",
179
+ "as",
180
+ "default",
181
+ "public",
182
+ "private",
183
+ "protected",
184
+ "static",
185
+ "final",
186
+ "class",
187
+ "struct",
188
+ "enum",
189
+ "interface",
190
+ "function",
191
+ "def",
192
+ "fn",
193
+ "func",
194
+ "var",
195
+ "let",
196
+ "const",
197
+ "package",
198
+ "namespace",
199
+ "module",
200
+ "using",
201
+ "include",
202
+ "require",
203
+ "select",
204
+ "from",
205
+ "where",
206
+ "and",
207
+ "or",
208
+ "not",
209
+ "in",
210
+ "is",
211
+ "try",
212
+ "catch",
213
+ "finally",
214
+ "throw",
215
+ "async",
216
+ "await",
217
+ "yield"
218
+ ]);
219
+ function patternsFor(lang) {
220
+ return LANG_PATTERNS[lang] ?? LANG_PATTERNS.other ?? [];
221
+ }
222
+ function looksBinary(content) {
223
+ if (content.includes("\0")) return true;
224
+ const sample = content.slice(0, 2048);
225
+ if (sample.length === 0) return false;
226
+ let bad = 0;
227
+ for (let i = 0; i < sample.length; i++) {
228
+ const c = sample.charCodeAt(i);
229
+ if (c === 9 || c === 10 || c === 13) continue;
230
+ if (c < 32 || c === 127) bad++;
231
+ }
232
+ return bad / sample.length > 0.1;
233
+ }
234
+ function newlineOffsets(content) {
235
+ const offsets = [];
236
+ for (let i = 0; i < content.length; i++) {
237
+ if (content.charCodeAt(i) === 10) offsets.push(i);
238
+ }
239
+ return offsets;
240
+ }
241
+ function lineColAt(offsets, index) {
242
+ let low = 0;
243
+ let high = offsets.length;
244
+ while (low < high) {
245
+ const mid = low + high >>> 1;
246
+ if ((offsets[mid] ?? 0) < index) low = mid + 1;
247
+ else high = mid;
248
+ }
249
+ const lastNl = low > 0 ? offsets[low - 1] : -1;
250
+ return { line: low + 1, col: index - lastNl };
251
+ }
252
+ var GENERIC_MAX_SYMBOLS_DEFAULT = 500;
253
+ var GENERIC_MAX_FILE_CHARS = 512 * 1024;
254
+ function parseGeneric(opts) {
255
+ const { file, lang } = opts;
256
+ const maxSymbols = opts.maxSymbols ?? GENERIC_MAX_SYMBOLS_DEFAULT;
257
+ const mtimeMs = Date.now();
258
+ if (!opts.content || looksBinary(opts.content)) {
259
+ return { file, lang, symbols: [], mtimeMs };
260
+ }
261
+ const content = opts.content.length > GENERIC_MAX_FILE_CHARS ? opts.content.slice(0, GENERIC_MAX_FILE_CHARS) : opts.content;
262
+ const patterns = patternsFor(lang);
263
+ const symbols = [];
264
+ const seen = /* @__PURE__ */ new Set();
265
+ const nlOffsets = newlineOffsets(content);
266
+ for (const pattern of patterns) {
267
+ const re = new RegExp(
268
+ pattern.re.source,
269
+ pattern.re.flags.includes("g") ? pattern.re.flags : `${pattern.re.flags}g`
270
+ );
271
+ re.lastIndex = 0;
272
+ for (const match of content.matchAll(re)) {
273
+ if (symbols.length >= maxSymbols) break;
274
+ let name = (match[1] ?? match[2] ?? "").trim();
275
+ if (lang === "md" && match[2]) name = match[2].trim();
276
+ if (!name || name.length > 200) continue;
277
+ name = name.replace(/^#+\s*/, "").replace(/["'`]/g, "");
278
+ if (!name || KEYWORDS.has(name.toLowerCase())) continue;
279
+ if (!/^[A-Za-z_#.@/\w][\w.\-:/#!?]*$/.test(name) && lang !== "md" && lang !== "toml") {
280
+ continue;
281
+ }
282
+ const { line, col } = lineColAt(nlOffsets, match.index ?? 0);
283
+ const key = `${name}\0${line}\0${pattern.kind}`;
284
+ if (seen.has(key)) continue;
285
+ seen.add(key);
286
+ const nl = content.indexOf("\n", match.index);
287
+ const lineText = content.slice(match.index, nl === -1 ? content.length : nl);
288
+ const signature = (lineText || name).trim().slice(0, 500);
289
+ symbols.push({
290
+ id: 0,
291
+ lang,
292
+ kind: lang === "md" ? "namespace" : pattern.kind,
293
+ name: name.slice(0, 200),
294
+ file,
295
+ line,
296
+ col,
297
+ signature,
298
+ docComment: "",
299
+ scope: "",
300
+ text: `${name} ${signature}`.trim().slice(0, 1e3)
301
+ });
302
+ }
303
+ if (symbols.length >= maxSymbols) break;
304
+ }
305
+ return { file, lang, symbols, mtimeMs };
306
+ }
307
+ async function parseSymbols(opts) {
308
+ return parseGeneric(opts);
309
+ }
310
+
311
+ export {
312
+ GENERIC_MAX_SYMBOLS_DEFAULT,
313
+ GENERIC_MAX_FILE_CHARS,
314
+ parseGeneric,
315
+ parseSymbols
316
+ };
317
+ //# sourceMappingURL=chunk-A6BRWIXN.js.map
@@ -0,0 +1,200 @@
1
+ import {
2
+ safeResolveReal
3
+ } from "./chunk-D33S4RQG.js";
4
+
5
+ // src/scaffold.ts
6
+ import * as fs from "node:fs/promises";
7
+ import * as path from "node:path";
8
+ import { atomicWrite } from "@wrongstack/core/utils";
9
+ var BUILT_IN_TEMPLATES = {
10
+ "npm-package": {
11
+ description: "Basic npm package with ESM",
12
+ files: {
13
+ "package.json": JSON.stringify(
14
+ {
15
+ name: "{{name}}",
16
+ version: "0.1.1",
17
+ type: "module",
18
+ main: "./dist/index.js",
19
+ scripts: { build: "tsc", test: "vitest run" },
20
+ devDependencies: { typescript: "^5.0.0" }
21
+ },
22
+ null,
23
+ 2
24
+ ),
25
+ "tsconfig.json": JSON.stringify(
26
+ {
27
+ compilerOptions: { target: "ES2022", module: "ESNext", strict: true },
28
+ include: ["src"]
29
+ },
30
+ null,
31
+ 2
32
+ ),
33
+ "src/index.ts": `export function hello() {
34
+ return 'Hello from {{name}}';
35
+ }
36
+ `,
37
+ "src/index.test.ts": `import { hello } from './index';
38
+ import { describe, it, expect } from 'vitest';
39
+
40
+ describe('hello', () => {
41
+ it('returns greeting', () => {
42
+ expect(hello()).toBe('Hello from {{name}}');
43
+ });
44
+ });
45
+ `
46
+ }
47
+ },
48
+ "cli-tool": {
49
+ description: "CLI tool with argparse",
50
+ files: {
51
+ "package.json": JSON.stringify(
52
+ {
53
+ name: "{{name}}",
54
+ version: "0.1.1",
55
+ type: "module",
56
+ bin: { "{{name}}": "./src/index.js" },
57
+ scripts: { build: "tsc", start: "node dist/index.js" }
58
+ },
59
+ null,
60
+ 2
61
+ ),
62
+ "src/index.ts": `#!/usr/bin/env node
63
+
64
+ async function main() {
65
+ console.log('Hello from {{name}}');
66
+ }
67
+
68
+ main();
69
+ `
70
+ }
71
+ },
72
+ "react-component": {
73
+ description: "React component with TypeScript",
74
+ files: {
75
+ "{{name}}.tsx": `interface {{Name}}Props {
76
+ className?: string;
77
+ }
78
+
79
+ export function {{Name}}({ className }: {{Name}}Props) {
80
+ return (
81
+ <div className={className}>
82
+ {{Name}} Component
83
+ </div>
84
+ );
85
+ }
86
+ `,
87
+ "{{name}}.test.tsx": `import { render, screen } from '@testing-library/react';
88
+ import { {{Name}} } from './{{Name}}';
89
+
90
+ describe('{{Name}}', () => {
91
+ it('renders', () => {
92
+ render(<{{Name}} />);
93
+ expect(screen.getByText('{{Name}} Component')).toBeInTheDocument();
94
+ });
95
+ });
96
+ `
97
+ }
98
+ }
99
+ };
100
+ var scaffoldTool = {
101
+ name: "scaffold",
102
+ category: "Project",
103
+ description: "Generate new files and folder structures from built-in templates or custom definitions. This is the recommended way to bootstrap new packages, components, or modules instead of creating files one by one with `write`.",
104
+ usageHint: "PREFERRED FOR SCAFFOLDING:\n\n- Use built-in templates when they match your needs (e.g. react-component, npm-package).\n- Supports `dry_run` so you can preview exactly what will be created.\n- Has the powerful `fs.write.outside-project` capability \u2014 review paths carefully.\nMuch cleaner and safer than manually writing multiple files.",
105
+ permission: "confirm",
106
+ mutating: true,
107
+ subjectKey: "name",
108
+ capabilities: ["fs.write.outside-project", "fs.write"],
109
+ icon: "scaffold",
110
+ timeoutMs: 3e4,
111
+ inputSchema: {
112
+ type: "object",
113
+ properties: {
114
+ template: {
115
+ type: "string",
116
+ description: "Template name (npm-package, cli-tool, react-component) or path to template directory"
117
+ },
118
+ name: {
119
+ type: "string",
120
+ description: "Project/component name (used in generated files)"
121
+ },
122
+ cwd: { type: "string", description: "Working directory (default: cwd)" },
123
+ vars: {
124
+ type: "object",
125
+ additionalProperties: { type: "string" },
126
+ description: "Template variables for custom templates"
127
+ },
128
+ dry_run: {
129
+ type: "boolean",
130
+ description: "Preview generated files without creating (default: false)"
131
+ }
132
+ },
133
+ required: ["template", "name"]
134
+ },
135
+ async execute(input, ctx) {
136
+ const cwd = input.cwd ? await safeResolveReal(input.cwd, ctx) : ctx.cwd;
137
+ const name = input.name;
138
+ const vars = { name, ...input.vars };
139
+ const builtIn = BUILT_IN_TEMPLATES[input.template];
140
+ if (builtIn) {
141
+ return await handleBuiltIn(name, builtIn.files, cwd, ctx, input.dry_run ?? false, vars);
142
+ }
143
+ return {
144
+ template: input.template,
145
+ name,
146
+ files_created: 0,
147
+ files: [],
148
+ dry_run: input.dry_run ?? false,
149
+ output: `Template "${input.template}" not found. Available: ${Object.keys(BUILT_IN_TEMPLATES).join(", ")}`
150
+ };
151
+ }
152
+ };
153
+ async function handleBuiltIn(name, templateFiles, cwd, ctx, dryRun, vars) {
154
+ const files = [];
155
+ let filesCreated = 0;
156
+ for (const [filePath, content] of Object.entries(templateFiles)) {
157
+ const resolvedPath = substituteVars(filePath, name, vars);
158
+ const joinedPath = path.join(cwd, resolvedPath);
159
+ const root = path.resolve(ctx.projectRoot);
160
+ const target = path.resolve(joinedPath);
161
+ const rel = path.relative(root, target);
162
+ if (rel.startsWith("..") || path.isAbsolute(rel)) {
163
+ throw new Error(`scaffold: generated path "${resolvedPath}" would escape project root`);
164
+ }
165
+ const fullPath = target;
166
+ if (!dryRun) {
167
+ await fs.mkdir(path.dirname(fullPath), { recursive: true });
168
+ await atomicWrite(fullPath, substituteVars(content, name, vars));
169
+ }
170
+ files.push(resolvedPath);
171
+ filesCreated++;
172
+ }
173
+ return {
174
+ template: "built-in",
175
+ name,
176
+ files_created: filesCreated,
177
+ files,
178
+ dry_run: dryRun,
179
+ output: dryRun ? `Would create ${filesCreated} files: ${files.join(", ")}` : `Created ${filesCreated} files: ${files.join(", ")}`
180
+ };
181
+ }
182
+ function escapeRegexLiteral(value) {
183
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
184
+ }
185
+ function substituteVars(content, name, vars) {
186
+ const kebab = name.toLowerCase().replace(/\s+/g, "-");
187
+ const pascal = name.replace(/(?:^|[-_\s]+)([a-z])/g, (_, c) => c.toUpperCase());
188
+ let result = content;
189
+ result = result.replace(/\{\{name\}\}/g, () => kebab);
190
+ result = result.replace(/\{\{Name\}\}/g, () => pascal);
191
+ for (const [k, v] of Object.entries(vars)) {
192
+ result = result.replace(new RegExp(`\\{\\{${escapeRegexLiteral(k)}\\}\\}`, "g"), () => v);
193
+ }
194
+ return result;
195
+ }
196
+
197
+ export {
198
+ scaffoldTool
199
+ };
200
+ //# sourceMappingURL=chunk-AHHDWNXC.js.map