@wrongstack/tools 0.313.0 → 0.316.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 (182) hide show
  1. package/dist/_edit-match.d.ts +3 -2
  2. package/dist/_output-spool.d.ts +4 -3
  3. package/dist/_shell-pick.d.ts +2 -1
  4. package/dist/_spawn-stream.d.ts +2 -1
  5. package/dist/_syntax-check.d.ts +2 -1
  6. package/dist/audit.js +10 -4055
  7. package/dist/bash-kill-guard.d.ts +3 -6
  8. package/dist/bash.js +9 -2308
  9. package/dist/batch-tool-use.js +2 -187
  10. package/dist/browser/index.js +25 -1339
  11. package/dist/browser/network-guard-proxy.d.ts +2 -1
  12. package/dist/builtin.js +69 -33949
  13. package/dist/chunk-22B7GE5T.js +260 -0
  14. package/dist/chunk-2VSZC6QM.js +113 -0
  15. package/dist/chunk-3PVYQFRQ.js +472 -0
  16. package/dist/chunk-42BHI7TN.js +337 -0
  17. package/dist/chunk-4BHUSMNL.js +104 -0
  18. package/dist/chunk-4I4LWFOO.js +431 -0
  19. package/dist/chunk-4UESMQDP.js +122 -0
  20. package/dist/chunk-553IQUMO.js +478 -0
  21. package/dist/chunk-5H4GSJAI.js +223 -0
  22. package/dist/chunk-6RNIFLG4.js +305 -0
  23. package/dist/chunk-7EY5DCRO.js +434 -0
  24. package/dist/chunk-A6BRWIXN.js +317 -0
  25. package/dist/chunk-AHHDWNXC.js +200 -0
  26. package/dist/chunk-BSLVR56S.js +199 -0
  27. package/dist/chunk-BTSFTGIL.js +7 -0
  28. package/dist/chunk-D33S4RQG.js +222 -0
  29. package/dist/chunk-DA4KNE2H.js +4412 -0
  30. package/dist/chunk-DR7JOQTC.js +520 -0
  31. package/dist/chunk-EEOFQDT6.js +898 -0
  32. package/dist/chunk-EJWSCQ6D.js +137 -0
  33. package/dist/chunk-EMRGN4KM.js +170 -0
  34. package/dist/chunk-FQZOHLG3.js +89 -0
  35. package/dist/chunk-GOIZNNOA.js +221 -0
  36. package/dist/chunk-HFXSNKCV.js +196 -0
  37. package/dist/chunk-HYX2TZ7O.js +1272 -0
  38. package/dist/chunk-I64BS3VC.js +15 -0
  39. package/dist/chunk-IVWV2UM6.js +955 -0
  40. package/dist/chunk-IXMNTNW5.js +238 -0
  41. package/dist/chunk-IYK7XGDZ.js +892 -0
  42. package/dist/chunk-J5SKD6LN.js +235 -0
  43. package/dist/chunk-JNNVRHMV.js +2111 -0
  44. package/dist/chunk-JOHXDF3D.js +295 -0
  45. package/dist/chunk-JRJJX3L5.js +424 -0
  46. package/dist/chunk-K3WNSHUF.js +1371 -0
  47. package/dist/chunk-L25CVUVR.js +2830 -0
  48. package/dist/chunk-LIJQMYYX.js +59 -0
  49. package/dist/chunk-LWKUTMD5.js +197 -0
  50. package/dist/chunk-MQX2KXVW.js +54 -0
  51. package/dist/chunk-MZZN7VCD.js +359 -0
  52. package/dist/chunk-NBDZMMG2.js +169 -0
  53. package/dist/chunk-NKJW5GFO.js +366 -0
  54. package/dist/chunk-NKNOBUBU.js +522 -0
  55. package/dist/chunk-O4MBV4AX.js +134 -0
  56. package/dist/chunk-OUBDL3WH.js +3515 -0
  57. package/dist/chunk-PQKK5JH7.js +101 -0
  58. package/dist/chunk-PY2IOS7C.js +1000 -0
  59. package/dist/chunk-Q5JPPCZC.js +12 -0
  60. package/dist/chunk-QBV725YG.js +128 -0
  61. package/dist/chunk-QZQSPUBF.js +315 -0
  62. package/dist/chunk-RGISBZBD.js +231 -0
  63. package/dist/chunk-RJZQWEMS.js +84 -0
  64. package/dist/chunk-RXISBFR5.js +315 -0
  65. package/dist/chunk-S5CCLZL3.js +99 -0
  66. package/dist/chunk-SDLVH5RZ.js +178 -0
  67. package/dist/chunk-T2F4S7U4.js +1723 -0
  68. package/dist/chunk-TEBQ4VPZ.js +163 -0
  69. package/dist/chunk-U4D5S3VQ.js +21 -0
  70. package/dist/chunk-U4VAATKP.js +193 -0
  71. package/dist/chunk-UCYQTZ7F.js +113 -0
  72. package/dist/chunk-UKU2ZX4C.js +203 -0
  73. package/dist/chunk-UNSKG6DC.js +159 -0
  74. package/dist/chunk-V43EQ6VR.js +68 -0
  75. package/dist/chunk-VB3MJGCV.js +610 -0
  76. package/dist/chunk-VFKPWSOX.js +154 -0
  77. package/dist/chunk-VJNHFZ7J.js +190 -0
  78. package/dist/chunk-VXECAJJ7.js +1091 -0
  79. package/dist/chunk-WHIIIREL.js +223 -0
  80. package/dist/chunk-Z6DAKQ3U.js +1 -0
  81. package/dist/chunk-ZJQ4IGXK.js +474 -0
  82. package/dist/chunk-ZLTFLC25.js +385 -0
  83. package/dist/circuit-breaker.js +3 -191
  84. package/dist/codebase-index/ast-invariant-engine.d.ts +5 -4
  85. package/dist/codebase-index/binary-frame.d.ts +0 -2
  86. package/dist/codebase-index/bm25.d.ts +1 -1
  87. package/dist/codebase-index/circuit-breaker.d.ts +2 -1
  88. package/dist/codebase-index/codebase-ast-replace-tool.d.ts +3 -2
  89. package/dist/codebase-index/codebase-impact-analysis-tool.d.ts +4 -3
  90. package/dist/codebase-index/codebase-invariant-check-tool.d.ts +3 -2
  91. package/dist/codebase-index/codebase-repo-map-tool.d.ts +3 -2
  92. package/dist/codebase-index/codebase-skeleton-tool.d.ts +3 -2
  93. package/dist/codebase-index/codebase-targeted-test-tool.d.ts +3 -2
  94. package/dist/codebase-index/content-hash.d.ts +0 -2
  95. package/dist/codebase-index/import-extractor.d.ts +0 -13
  96. package/dist/codebase-index/index-service.d.ts +1 -1
  97. package/dist/codebase-index/index.js +84 -13688
  98. package/dist/codebase-index/languages.d.ts +2 -1
  99. package/dist/codebase-index/module-roots.d.ts +3 -2
  100. package/dist/codebase-index/parser-batch.d.ts +0 -5
  101. package/dist/codebase-index/parser-dispatch.d.ts +2 -1
  102. package/dist/codebase-index/parser-output.d.ts +4 -3
  103. package/dist/codebase-index/parser-worker-pool.d.ts +0 -2
  104. package/dist/codebase-index/parser-worker-script.d.ts +1 -16
  105. package/dist/codebase-index/parser-worker-script.js +8 -3995
  106. package/dist/codebase-index/project-server-client-state.d.ts +2 -2
  107. package/dist/codebase-index/project-server-endpoint.d.ts +0 -15
  108. package/dist/codebase-index/project-server.js +60 -8548
  109. package/dist/codebase-index/tree-sitter/visitor.d.ts +2 -1
  110. package/dist/codebase-index/tree-sitter-parser.d.ts +0 -2
  111. package/dist/codebase-index/ts-parser.d.ts +1 -1
  112. package/dist/codebase-index/vector-search.d.ts +2 -1
  113. package/dist/codebase-index/wal-maintenance.d.ts +3 -2
  114. package/dist/codebase-index/worker.js +20 -8416
  115. package/dist/codebase-index/writer-admin.d.ts +0 -1
  116. package/dist/codebase-index/writer-search.d.ts +0 -9
  117. package/dist/design.js +2 -299
  118. package/dist/diff.js +4 -256
  119. package/dist/document.js +4 -222
  120. package/dist/e2e.js +5 -476
  121. package/dist/edit.js +14 -10200
  122. package/dist/exec.js +16 -3131
  123. package/dist/fetch.js +8 -398
  124. package/dist/format.js +10 -3750
  125. package/dist/generic-parser-VUXDIAOZ.js +13 -0
  126. package/dist/git.js +4 -380
  127. package/dist/glob.js +6 -280
  128. package/dist/go-parser-JXYKJHRC.js +469 -0
  129. package/dist/grep.js +7 -604
  130. package/dist/index.js +318 -35387
  131. package/dist/install.js +10 -4091
  132. package/dist/json-parser-IBHZ4BZC.js +213 -0
  133. package/dist/json.js +4 -665
  134. package/dist/kanban-contract-actions.d.ts +1 -1
  135. package/dist/kanban-detail-actions.d.ts +2 -1
  136. package/dist/kanban-presence.d.ts +2 -1
  137. package/dist/kanban-serializer.d.ts +0 -8
  138. package/dist/kanban-split-task-handler.d.ts +2 -2
  139. package/dist/kanban-tool-types.d.ts +2 -1
  140. package/dist/kanban.js +3 -2096
  141. package/dist/languages/diagnostics.d.ts +2 -1
  142. package/dist/languages/index.js +23 -4664
  143. package/dist/languages/legacy-bridge.d.ts +3 -2
  144. package/dist/languages/types.d.ts +2 -1
  145. package/dist/legacy-bridge-7M6QLUQN.js +18 -0
  146. package/dist/lint.js +10 -3706
  147. package/dist/logs.js +4 -287
  148. package/dist/memory.js +6 -215
  149. package/dist/mode.js +3 -99
  150. package/dist/outdated.js +4 -5170
  151. package/dist/pack.js +65 -33897
  152. package/dist/parser-dispatch-QH4XPGG6.js +14 -0
  153. package/dist/patch.js +13 -9935
  154. package/dist/plan.js +5 -3286
  155. package/dist/process-registry.js +8 -651
  156. package/dist/ps-slash.js +12 -1439
  157. package/dist/pwsh.d.ts +0 -1
  158. package/dist/py-parser-IS4HKYMF.js +16 -0
  159. package/dist/read.js +13 -9816
  160. package/dist/replace.js +15 -10014
  161. package/dist/rs-parser-XHUUO2KZ.js +81 -0
  162. package/dist/scaffold.js +4 -253
  163. package/dist/search.js +5 -585
  164. package/dist/session-kanban-sync.d.ts +0 -6
  165. package/dist/session-kanban.js +30 -972
  166. package/dist/skill.js +2 -215
  167. package/dist/spawn-background.d.ts +1 -1
  168. package/dist/task.js +5 -3410
  169. package/dist/test.js +10 -3773
  170. package/dist/todo.js +4 -2891
  171. package/dist/tool-help.js +3 -123
  172. package/dist/tool-search.js +3 -79
  173. package/dist/tool-tier.js +68 -33984
  174. package/dist/tool-use.js +2 -93
  175. package/dist/tree-sitter-parser-AIERW3YI.js +15 -0
  176. package/dist/tree.js +4 -288
  177. package/dist/ts-parser-RCTYKSVI.js +232 -0
  178. package/dist/typecheck.js +10 -3753
  179. package/dist/win32.js +6 -60
  180. package/dist/write.js +14 -9882
  181. package/dist/yaml-parser-4SAXV3PL.js +157 -0
  182. 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