@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.
Files changed (330) hide show
  1. package/README.md +19 -0
  2. package/dist/_concurrency.d.ts +16 -0
  3. package/dist/_concurrency.d.ts.map +1 -0
  4. package/dist/_danger-detect.d.ts +54 -0
  5. package/dist/_danger-detect.d.ts.map +1 -0
  6. package/dist/_edit-match.d.ts +86 -0
  7. package/dist/_edit-match.d.ts.map +1 -0
  8. package/dist/_env.d.ts +6 -0
  9. package/dist/_env.d.ts.map +1 -0
  10. package/dist/_fetch-guard.d.ts +31 -0
  11. package/dist/_fetch-guard.d.ts.map +1 -0
  12. package/dist/_output-spool.d.ts +38 -0
  13. package/dist/_output-spool.d.ts.map +1 -0
  14. package/dist/_redact-command.d.ts +6 -0
  15. package/dist/_redact-command.d.ts.map +1 -0
  16. package/dist/_regex.d.ts +39 -0
  17. package/dist/_regex.d.ts.map +1 -0
  18. package/dist/_session-shell.d.ts +73 -0
  19. package/dist/_session-shell.d.ts.map +1 -0
  20. package/dist/_shell-pick.d.ts +158 -0
  21. package/dist/_shell-pick.d.ts.map +1 -0
  22. package/dist/_spawn-stream.d.ts +32 -0
  23. package/dist/_spawn-stream.d.ts.map +1 -0
  24. package/dist/_syntax-check.d.ts +16 -0
  25. package/dist/_syntax-check.d.ts.map +1 -0
  26. package/dist/_util.d.ts +68 -0
  27. package/dist/_util.d.ts.map +1 -0
  28. package/dist/_win32-resolve.d.ts +42 -0
  29. package/dist/_win32-resolve.d.ts.map +1 -0
  30. package/dist/audit.d.ts +4 -5
  31. package/dist/audit.d.ts.map +1 -0
  32. package/dist/audit.js +2743 -28
  33. package/dist/audit.js.map +7 -1
  34. package/dist/bash-kill-guard.d.ts +62 -0
  35. package/dist/bash-kill-guard.d.ts.map +1 -0
  36. package/dist/bash.d.ts +4 -5
  37. package/dist/bash.d.ts.map +1 -0
  38. package/dist/bash.js +59 -30
  39. package/dist/bash.js.map +7 -1
  40. package/dist/batch-tool-use.d.ts +4 -5
  41. package/dist/batch-tool-use.d.ts.map +1 -0
  42. package/dist/batch-tool-use.js +3 -3
  43. package/dist/batch-tool-use.js.map +7 -1
  44. package/dist/browser/artifacts.d.ts +13 -0
  45. package/dist/browser/artifacts.d.ts.map +1 -0
  46. package/dist/browser/index.d.ts +7 -0
  47. package/dist/browser/index.d.ts.map +1 -0
  48. package/dist/browser/index.js +1264 -0
  49. package/dist/browser/index.js.map +7 -0
  50. package/dist/browser/manager.d.ts +57 -0
  51. package/dist/browser/manager.d.ts.map +1 -0
  52. package/dist/browser/network-guard-proxy.d.ts +23 -0
  53. package/dist/browser/network-guard-proxy.d.ts.map +1 -0
  54. package/dist/browser/security.d.ts +29 -0
  55. package/dist/browser/security.d.ts.map +1 -0
  56. package/dist/browser/tools.d.ts +62 -0
  57. package/dist/browser/tools.d.ts.map +1 -0
  58. package/dist/browser/types.d.ts +60 -0
  59. package/dist/browser/types.d.ts.map +1 -0
  60. package/dist/builtin.d.ts +11 -12
  61. package/dist/builtin.d.ts.map +1 -0
  62. package/dist/builtin.js +8099 -2178
  63. package/dist/builtin.js.map +7 -1
  64. package/dist/circuit-breaker.d.ts +4 -5
  65. package/dist/circuit-breaker.d.ts.map +1 -0
  66. package/dist/circuit-breaker.js +3 -3
  67. package/dist/circuit-breaker.js.map +7 -1
  68. package/dist/codebase-index/background-indexer.d.ts +116 -0
  69. package/dist/codebase-index/background-indexer.d.ts.map +1 -0
  70. package/dist/codebase-index/bm25.d.ts +40 -0
  71. package/dist/codebase-index/bm25.d.ts.map +1 -0
  72. package/dist/codebase-index/circuit-breaker.d.ts +94 -0
  73. package/dist/codebase-index/circuit-breaker.d.ts.map +1 -0
  74. package/dist/codebase-index/codebase-index-tool.d.ts +17 -0
  75. package/dist/codebase-index/codebase-index-tool.d.ts.map +1 -0
  76. package/dist/codebase-index/codebase-search-tool.d.ts +43 -0
  77. package/dist/codebase-index/codebase-search-tool.d.ts.map +1 -0
  78. package/dist/codebase-index/codebase-stats-tool.d.ts +23 -0
  79. package/dist/codebase-index/codebase-stats-tool.d.ts.map +1 -0
  80. package/dist/codebase-index/gitignore.d.ts +22 -0
  81. package/dist/codebase-index/gitignore.d.ts.map +1 -0
  82. package/dist/codebase-index/go-parser.d.ts +16 -0
  83. package/dist/codebase-index/go-parser.d.ts.map +1 -0
  84. package/dist/codebase-index/index-service.d.ts +25 -0
  85. package/dist/codebase-index/index-service.d.ts.map +1 -0
  86. package/dist/codebase-index/index.d.ts +23 -271
  87. package/dist/codebase-index/index.d.ts.map +1 -0
  88. package/dist/codebase-index/index.js +136 -68
  89. package/dist/codebase-index/index.js.map +7 -1
  90. package/dist/codebase-index/indexer.d.ts +28 -0
  91. package/dist/codebase-index/indexer.d.ts.map +1 -0
  92. package/dist/codebase-index/json-parser.d.ts +8 -0
  93. package/dist/codebase-index/json-parser.d.ts.map +1 -0
  94. package/dist/codebase-index/lsp-kind.d.ts +53 -0
  95. package/dist/codebase-index/lsp-kind.d.ts.map +1 -0
  96. package/dist/codebase-index/py-parser.d.ts +16 -0
  97. package/dist/codebase-index/py-parser.d.ts.map +1 -0
  98. package/dist/codebase-index/refs-extractor.d.ts +25 -0
  99. package/dist/codebase-index/refs-extractor.d.ts.map +1 -0
  100. package/dist/codebase-index/rs-parser.d.ts +8 -0
  101. package/dist/codebase-index/rs-parser.d.ts.map +1 -0
  102. package/dist/codebase-index/schema.d.ts +82 -0
  103. package/dist/codebase-index/schema.d.ts.map +1 -0
  104. package/dist/codebase-index/ts-parser.d.ts +30 -0
  105. package/dist/codebase-index/ts-parser.d.ts.map +1 -0
  106. package/dist/codebase-index/worker-protocol.d.ts +77 -0
  107. package/dist/codebase-index/worker-protocol.d.ts.map +1 -0
  108. package/dist/codebase-index/worker.d.ts +16 -2
  109. package/dist/codebase-index/worker.d.ts.map +1 -0
  110. package/dist/codebase-index/worker.js +103 -65
  111. package/dist/codebase-index/worker.js.map +7 -1
  112. package/dist/codebase-index/writer.d.ts +189 -0
  113. package/dist/codebase-index/writer.d.ts.map +1 -0
  114. package/dist/codebase-index/yaml-parser.d.ts +8 -0
  115. package/dist/codebase-index/yaml-parser.d.ts.map +1 -0
  116. package/dist/design.d.ts +38 -0
  117. package/dist/design.d.ts.map +1 -0
  118. package/dist/design.js +270 -0
  119. package/dist/design.js.map +7 -0
  120. package/dist/diff.d.ts +4 -5
  121. package/dist/diff.d.ts.map +1 -0
  122. package/dist/diff.js +14 -12
  123. package/dist/diff.js.map +7 -1
  124. package/dist/document.d.ts +4 -5
  125. package/dist/document.d.ts.map +1 -0
  126. package/dist/document.js +8 -7
  127. package/dist/document.js.map +7 -1
  128. package/dist/e2e.d.ts +56 -0
  129. package/dist/e2e.d.ts.map +1 -0
  130. package/dist/edit.d.ts +5 -36
  131. package/dist/edit.d.ts.map +1 -0
  132. package/dist/edit.js +28 -16
  133. package/dist/edit.js.map +7 -1
  134. package/dist/exec.d.ts +67 -2
  135. package/dist/exec.d.ts.map +1 -0
  136. package/dist/exec.js +51 -26
  137. package/dist/exec.js.map +7 -1
  138. package/dist/fetch.d.ts +4 -32
  139. package/dist/fetch.d.ts.map +1 -0
  140. package/dist/fetch.js +89 -77
  141. package/dist/fetch.js.map +7 -1
  142. package/dist/format.d.ts +4 -5
  143. package/dist/format.d.ts.map +1 -0
  144. package/dist/format.js +2415 -28
  145. package/dist/format.js.map +7 -1
  146. package/dist/git.d.ts +4 -5
  147. package/dist/git.d.ts.map +1 -0
  148. package/dist/git.js +10 -9
  149. package/dist/git.js.map +7 -1
  150. package/dist/glob.d.ts +4 -5
  151. package/dist/glob.d.ts.map +1 -0
  152. package/dist/glob.js +15 -12
  153. package/dist/glob.js.map +7 -1
  154. package/dist/grep.d.ts +4 -5
  155. package/dist/grep.d.ts.map +1 -0
  156. package/dist/grep.js +13 -10
  157. package/dist/grep.js.map +7 -1
  158. package/dist/index.d.ts +21 -724
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +8955 -2866
  161. package/dist/index.js.map +7 -1
  162. package/dist/install.d.ts +4 -5
  163. package/dist/install.d.ts.map +1 -0
  164. package/dist/install.js +2680 -31
  165. package/dist/install.js.map +7 -1
  166. package/dist/json.d.ts +4 -5
  167. package/dist/json.d.ts.map +1 -0
  168. package/dist/json.js +13 -11
  169. package/dist/json.js.map +7 -1
  170. package/dist/kanban.d.ts +107 -0
  171. package/dist/kanban.d.ts.map +1 -0
  172. package/dist/kanban.js +845 -0
  173. package/dist/kanban.js.map +7 -0
  174. package/dist/languages/detect.d.ts +3 -0
  175. package/dist/languages/detect.d.ts.map +1 -0
  176. package/dist/languages/diagnostics.d.ts +15 -0
  177. package/dist/languages/diagnostics.d.ts.map +1 -0
  178. package/dist/languages/execute-tool.d.ts +34 -0
  179. package/dist/languages/execute-tool.d.ts.map +1 -0
  180. package/dist/languages/execute.d.ts +18 -0
  181. package/dist/languages/execute.d.ts.map +1 -0
  182. package/dist/languages/index.d.ts +12 -0
  183. package/dist/languages/index.d.ts.map +1 -0
  184. package/dist/languages/index.js +4457 -0
  185. package/dist/languages/index.js.map +7 -0
  186. package/dist/languages/legacy-bridge.d.ts +29 -0
  187. package/dist/languages/legacy-bridge.d.ts.map +1 -0
  188. package/dist/languages/package-tool.d.ts +29 -0
  189. package/dist/languages/package-tool.d.ts.map +1 -0
  190. package/dist/languages/plan.d.ts +4 -0
  191. package/dist/languages/plan.d.ts.map +1 -0
  192. package/dist/languages/profile-helpers.d.ts +14 -0
  193. package/dist/languages/profile-helpers.d.ts.map +1 -0
  194. package/dist/languages/profiles/additional.d.ts +3 -0
  195. package/dist/languages/profiles/additional.d.ts.map +1 -0
  196. package/dist/languages/profiles/primary.d.ts +3 -0
  197. package/dist/languages/profiles/primary.d.ts.map +1 -0
  198. package/dist/languages/registry.d.ts +11 -0
  199. package/dist/languages/registry.d.ts.map +1 -0
  200. package/dist/languages/tool.d.ts +32 -0
  201. package/dist/languages/tool.d.ts.map +1 -0
  202. package/dist/languages/types.d.ts +207 -0
  203. package/dist/languages/types.d.ts.map +1 -0
  204. package/dist/lint.d.ts +4 -5
  205. package/dist/lint.d.ts.map +1 -0
  206. package/dist/lint.js +2415 -27
  207. package/dist/lint.js.map +7 -1
  208. package/dist/logs.d.ts +4 -5
  209. package/dist/logs.d.ts.map +1 -0
  210. package/dist/logs.js +16 -10
  211. package/dist/logs.js.map +7 -1
  212. package/dist/memory.d.ts +7 -8
  213. package/dist/memory.d.ts.map +1 -0
  214. package/dist/memory.js +7 -5
  215. package/dist/memory.js.map +7 -1
  216. package/dist/mode.d.ts +4 -5
  217. package/dist/mode.d.ts.map +1 -0
  218. package/dist/mode.js +3 -3
  219. package/dist/mode.js.map +7 -1
  220. package/dist/next-steps.d.ts +5 -6
  221. package/dist/next-steps.d.ts.map +1 -0
  222. package/dist/next-steps.js +5 -4
  223. package/dist/next-steps.js.map +7 -1
  224. package/dist/outdated.d.ts +4 -5
  225. package/dist/outdated.d.ts.map +1 -0
  226. package/dist/outdated.js +4777 -68
  227. package/dist/outdated.js.map +7 -1
  228. package/dist/pack.d.ts +3 -6
  229. package/dist/pack.d.ts.map +1 -0
  230. package/dist/pack.js +8134 -2204
  231. package/dist/pack.js.map +7 -1
  232. package/dist/patch.d.ts +4 -5
  233. package/dist/patch.d.ts.map +1 -0
  234. package/dist/patch.js +18 -16
  235. package/dist/patch.js.map +7 -1
  236. package/dist/plan.d.ts +55 -0
  237. package/dist/plan.d.ts.map +1 -0
  238. package/dist/plan.js +280 -0
  239. package/dist/plan.js.map +7 -0
  240. package/dist/process-guardian.d.ts +100 -0
  241. package/dist/process-guardian.d.ts.map +1 -0
  242. package/dist/process-registry-persistent.d.ts +121 -0
  243. package/dist/process-registry-persistent.d.ts.map +1 -0
  244. package/dist/process-registry.d.ts +13 -17
  245. package/dist/process-registry.d.ts.map +1 -0
  246. package/dist/process-registry.js +15 -9
  247. package/dist/process-registry.js.map +7 -1
  248. package/dist/ps-slash.d.ts +106 -0
  249. package/dist/ps-slash.d.ts.map +1 -0
  250. package/dist/ps-slash.js +1291 -0
  251. package/dist/ps-slash.js.map +7 -0
  252. package/dist/read.d.ts +4 -5
  253. package/dist/read.d.ts.map +1 -0
  254. package/dist/read.js +13 -11
  255. package/dist/read.js.map +7 -1
  256. package/dist/replace.d.ts +4 -5
  257. package/dist/replace.d.ts.map +1 -0
  258. package/dist/replace.js +26 -13
  259. package/dist/replace.js.map +7 -1
  260. package/dist/scaffold.d.ts +4 -5
  261. package/dist/scaffold.d.ts.map +1 -0
  262. package/dist/scaffold.js +16 -14
  263. package/dist/scaffold.js.map +7 -1
  264. package/dist/search.d.ts +5 -6
  265. package/dist/search.d.ts.map +1 -0
  266. package/dist/search.js +32 -27
  267. package/dist/search.js.map +7 -1
  268. package/dist/set-working-dir.d.ts +18 -0
  269. package/dist/set-working-dir.d.ts.map +1 -0
  270. package/dist/shim/node-sqlite.d.ts +3 -0
  271. package/dist/shim/node-sqlite.d.ts.map +1 -0
  272. package/dist/skill.d.ts +45 -0
  273. package/dist/skill.d.ts.map +1 -0
  274. package/dist/skill.js +175 -0
  275. package/dist/skill.js.map +7 -0
  276. package/dist/spawn-background.d.ts +80 -0
  277. package/dist/spawn-background.d.ts.map +1 -0
  278. package/dist/task.d.ts +35 -0
  279. package/dist/task.d.ts.map +1 -0
  280. package/dist/task.js +380 -0
  281. package/dist/task.js.map +7 -0
  282. package/dist/test.d.ts +4 -5
  283. package/dist/test.d.ts.map +1 -0
  284. package/dist/test.js +2419 -27
  285. package/dist/test.js.map +7 -1
  286. package/dist/todo.d.ts +4 -5
  287. package/dist/todo.d.ts.map +1 -0
  288. package/dist/todo.js +5 -5
  289. package/dist/todo.js.map +7 -1
  290. package/dist/tool-diff.d.ts +16 -17
  291. package/dist/tool-diff.d.ts.map +1 -0
  292. package/dist/tool-diff.js +11 -3
  293. package/dist/tool-diff.js.map +7 -1
  294. package/dist/tool-help.d.ts +4 -5
  295. package/dist/tool-help.d.ts.map +1 -0
  296. package/dist/tool-help.js +3 -3
  297. package/dist/tool-help.js.map +7 -1
  298. package/dist/tool-icon-map.d.ts +46 -0
  299. package/dist/tool-icon-map.d.ts.map +1 -0
  300. package/dist/tool-icons.d.ts +5 -6
  301. package/dist/tool-icons.d.ts.map +1 -0
  302. package/dist/tool-icons.js +16 -4
  303. package/dist/tool-icons.js.map +7 -1
  304. package/dist/tool-search.d.ts +4 -5
  305. package/dist/tool-search.d.ts.map +1 -0
  306. package/dist/tool-search.js +3 -3
  307. package/dist/tool-search.js.map +7 -1
  308. package/dist/tool-summary.d.ts +4 -5
  309. package/dist/tool-summary.d.ts.map +1 -0
  310. package/dist/tool-summary.js +5 -3
  311. package/dist/tool-summary.js.map +7 -1
  312. package/dist/tool-use.d.ts +4 -5
  313. package/dist/tool-use.d.ts.map +1 -0
  314. package/dist/tool-use.js +3 -3
  315. package/dist/tool-use.js.map +7 -1
  316. package/dist/tree.d.ts +4 -5
  317. package/dist/tree.d.ts.map +1 -0
  318. package/dist/tree.js +11 -9
  319. package/dist/tree.js.map +7 -1
  320. package/dist/typecheck.d.ts +4 -5
  321. package/dist/typecheck.d.ts.map +1 -0
  322. package/dist/typecheck.js +2416 -28
  323. package/dist/typecheck.js.map +7 -1
  324. package/dist/write.d.ts +4 -5
  325. package/dist/write.d.ts.map +1 -0
  326. package/dist/write.js +21 -16
  327. package/dist/write.js.map +7 -1
  328. package/package.json +39 -6
  329. package/dist/background-indexer-BeDBxfSh.d.ts +0 -371
  330. package/dist/exec-2OKoT6tk.d.ts +0 -121
@@ -1,371 +0,0 @@
1
- import { Tool } from '@wrongstack/core';
2
-
3
- declare const codebaseIndexTool: Tool<CodebaseIndexInput, CodebaseIndexOutput>;
4
- interface CodebaseIndexInput {
5
- force?: boolean | undefined;
6
- langs?: string[] | undefined;
7
- }
8
- interface CodebaseIndexOutput {
9
- filesIndexed: number;
10
- symbolsIndexed: number;
11
- langStats: Record<string, number>;
12
- durationMs: number;
13
- errors: string[];
14
- /** Advisory note when the indexer was skipped (e.g. another index in progress). */
15
- note?: string | undefined;
16
- }
17
-
18
- /** Language a symbol belongs to. */
19
- type SymbolLang = 'ts' | 'js' | 'tsx' | 'jsx' | 'go' | 'py' | 'rs' | 'json' | 'yaml';
20
- /** What kind of symbol this is. */
21
- type SymbolKind = 'class' | 'interface' | 'enum' | 'type' | 'function' | 'method' | 'var' | 'const' | 'let' | 'property' | 'parameter' | 'namespace' | 'object' | 'literal' | 'schema' | 'struct' | 'trait' | 'impl' | 'static' | 'mod';
22
- /** A single indexed code symbol. */
23
- interface Symbol {
24
- id: number;
25
- lang: SymbolLang;
26
- kind: SymbolKind;
27
- name: string;
28
- file: string;
29
- line: number;
30
- col: number;
31
- signature: string;
32
- docComment: string;
33
- scope: string;
34
- text: string;
35
- }
36
- /** Extracted symbols and cross-references for one file. */
37
- interface FileSymbols {
38
- file: string;
39
- lang: SymbolLang;
40
- symbols: Symbol[];
41
- refs?: Ref[] | undefined;
42
- mtimeMs: number;
43
- }
44
- /** Source file metadata tracked for incremental indexing. */
45
- interface FileMeta {
46
- file: string;
47
- lang: SymbolLang;
48
- mtimeMs: number;
49
- symbolCount: number;
50
- lastIndexed: number;
51
- }
52
- /** Statistics about the index. */
53
- interface IndexStats {
54
- totalSymbols: number;
55
- totalFiles: number;
56
- byLang: Record<SymbolLang, number>;
57
- byKind: Record<SymbolKind, number>;
58
- indexPath: string;
59
- lastIndexed: number | null;
60
- sizeBytes: number;
61
- version: number;
62
- }
63
- /** Result of a search query. */
64
- interface SearchResult {
65
- id: number;
66
- name: string;
67
- kind: SymbolKind;
68
- lang: SymbolLang;
69
- file: string;
70
- line: number;
71
- col: number;
72
- signature: string;
73
- docComment: string;
74
- score: number;
75
- snippet: string;
76
- /** Original LSP SymbolKind number if the result was filtered by an LSP kind. */
77
- lspKind?: number | undefined;
78
- }
79
- /** Result of a full reindex. */
80
- interface IndexResult {
81
- filesIndexed: number;
82
- symbolsIndexed: number;
83
- langStats: Record<SymbolLang, number>;
84
- durationMs: number;
85
- errors: string[];
86
- }
87
- /** What kind of reference this is. */
88
- type CallType = 'call' | 'type_ref' | 'inherit' | 'implement' | 'import';
89
- /** A cross-reference between two symbols (who references whom). */
90
- interface Ref {
91
- id?: number | undefined;
92
- fromId: number;
93
- toName: string;
94
- toId?: number | undefined;
95
- callType: CallType;
96
- line: number;
97
- }
98
- declare const SCHEMA_VERSION = 2;
99
-
100
- /**
101
- * `codebase-search` tool — search the symbol index with BM25 ranking.
102
- *
103
- * Usage: codebase-search({
104
- * query: string, // search terms
105
- * kind?: string, // class|function|interface|method|const|...
106
- * lang?: string, // ts|tsx|js|jsx|go|py|rs
107
- * file?: string, // filter to a specific file path (substring match)
108
- * limit?: number, // max results (default 20, max 100)
109
- * })
110
- *
111
- * Returns: [{ name, kind, lang, file, line, signature, snippet, score }, ...]
112
- *
113
- * The query executes in the index worker via FTS5 (`MATCH` + native `bm25()`)
114
- * — the main thread never opens SQLite, so a contended or wedged index can
115
- * slow this tool down but can never freeze the terminal.
116
- */
117
-
118
- declare const codebaseSearchTool: Tool<CodebaseSearchInput, CodebaseSearchOutput>;
119
- interface CodebaseSearchInput {
120
- query: string;
121
- kind?: string | undefined;
122
- lang?: string | undefined;
123
- file?: string | undefined;
124
- limit?: number | undefined;
125
- lspKind?: number | undefined;
126
- /**
127
- * When true, hints that LSP-based search should be preferred over the index.
128
- * The built-in tool ignores this (index-only), but when the LSP plugin is
129
- * active it intercepts the tool and provides live LSP workspaceSymbol results.
130
- */
131
- preferLsp?: boolean | undefined;
132
- }
133
- interface CodebaseSearchOutput {
134
- results: SearchResult[];
135
- total: number;
136
- query: string;
137
- /** Non-empty when the index blocked the search (not ready, indexing, failed). */
138
- indexStatus?: string | undefined;
139
- }
140
-
141
- /**
142
- * `codebase-stats` tool — report index health and statistics.
143
- *
144
- * Usage: codebase-stats({})
145
- *
146
- * Returns: { totalSymbols, totalFiles, byLang, byKind, lastIndexed, sizeBytes, version }
147
- */
148
-
149
- declare const codebaseStatsTool: Tool<Record<string, never>, CodebaseStatsOutput>;
150
- interface CodebaseStatsOutput {
151
- totalSymbols: number;
152
- totalFiles: number;
153
- byLang: Record<string, number>;
154
- byKind: Record<string, number>;
155
- lastIndexed: number | null;
156
- sizeBytes: number;
157
- indexPath: string;
158
- version: number;
159
- /** Non-empty when the index is not ready or is still building. */
160
- indexStatus?: string | undefined;
161
- }
162
-
163
- /**
164
- * Circuit breaker for the codebase indexer.
165
- *
166
- * The indexer can wedge: a hung filesystem, a parser pathology, or another
167
- * wstack process holding the SQLite write lock (several surfaces — TUI, WebUI,
168
- * parallel terminals — share one per-project `index.db`). Without protection,
169
- * every queued reindex piles up behind the process-wide mutex, `isIndexing()`
170
- * stays true forever, and anything that awaits an index run (the startup scan,
171
- * `/codebase-reindex`) locks its terminal.
172
- *
173
- * Standard three-state breaker:
174
- *
175
- * closed — normal operation; consecutive failures are counted.
176
- * open — after `failureThreshold` consecutive failures, every request
177
- * is rejected fast ({@link CircuitOpenError}) for `cooldownMs`.
178
- * half-open — after the cooldown exactly one probe run is admitted;
179
- * success closes the circuit, failure re-opens it.
180
- *
181
- * Watchdog timeouts ({@link IndexTimeoutError}) count as failures;
182
- * caller-initiated aborts (session teardown) do not — the background indexer
183
- * makes that distinction before recording.
184
- *
185
- * Lock conflicts ({@link LockError}) do NOT count as failures — they are expected
186
- * transient conditions when multiple wstack surfaces share the same `index.db`.
187
- * The index store retries automatically; a LockError only reaches the circuit
188
- * breaker when all retries are exhausted.
189
- */
190
- type CircuitState = 'closed' | 'open' | 'half-open';
191
- interface CircuitSnapshot {
192
- state: CircuitState;
193
- consecutiveFailures: number;
194
- lastFailure: string | null;
195
- /** ms until an open circuit admits a half-open probe (0 unless open). */
196
- cooldownRemainingMs: number;
197
- }
198
- /** Thrown when a run is rejected because the circuit is open. */
199
- declare class CircuitOpenError extends Error {
200
- readonly name = "CircuitOpenError";
201
- }
202
- /** Thrown by the background indexer's watchdog when a run exceeds its timeout. */
203
- declare class IndexTimeoutError extends Error {
204
- readonly name = "IndexTimeoutError";
205
- }
206
- interface CircuitBreakerOptions {
207
- /** Consecutive failures before the circuit opens. Default: 3. */
208
- failureThreshold?: number | undefined;
209
- /** How long an open circuit rejects requests before allowing a probe. Default: 60s. */
210
- cooldownMs?: number | undefined;
211
- /** Injectable clock for tests. Default: Date.now. */
212
- now?: (() => number) | undefined;
213
- }
214
- declare class IndexCircuitBreaker {
215
- private readonly failureThreshold;
216
- private readonly cooldownMs;
217
- private readonly now;
218
- private state;
219
- private consecutiveFailures;
220
- private openedAt;
221
- private lastFailure;
222
- private probeInFlight;
223
- constructor(opts?: CircuitBreakerOptions);
224
- /**
225
- * True when a run may proceed. An open circuit transitions to half-open once
226
- * the cooldown has elapsed, admitting exactly one probe; further requests
227
- * are rejected until that probe settles via recordSuccess/recordFailure.
228
- */
229
- allowRequest(): boolean;
230
- recordSuccess(): void;
231
- recordFailure(err: unknown): void;
232
- /** Force-close the circuit (manual recovery: `/codebase-reindex`). */
233
- reset(): void;
234
- snapshot(): CircuitSnapshot;
235
- }
236
- /**
237
- * Process-wide breaker shared by every index path (startup scan, per-edit
238
- * incremental, external watcher, the `codebase-index` tool). Module-level for
239
- * the same reason the mutex is: there is one `index.db` per project and one
240
- * indexing pipeline per process.
241
- */
242
- declare const indexCircuitBreaker: IndexCircuitBreaker;
243
- /** Reset the shared breaker — used by `/codebase-reindex` and tests. */
244
- declare function resetIndexCircuitBreaker(): void;
245
-
246
- /**
247
- * Message protocol between the index host (main thread) and the index worker.
248
- *
249
- * Plain structured-cloneable shapes only — no class instances, no functions.
250
- * Errors cross the boundary as strings and are re-wrapped by the host.
251
- */
252
-
253
- interface SearchOpArgs {
254
- projectRoot: string;
255
- indexDir?: string | undefined;
256
- query: string;
257
- kind?: string | undefined;
258
- lang?: string | undefined;
259
- file?: string | undefined;
260
- lspKind?: number | undefined;
261
- limit: number;
262
- }
263
- interface StatsOpArgs {
264
- projectRoot: string;
265
- indexDir?: string | undefined;
266
- }
267
- interface SearchOpResult {
268
- results: SearchResult[];
269
- total: number;
270
- }
271
-
272
- /**
273
- * Index host — the main-thread coordinator for all codebase-index operations.
274
- *
275
- * Production mode runs every operation (full scans, per-file reindexes,
276
- * searches, stats) in a dedicated worker thread (`worker.ts`), so the
277
- * synchronous `node:sqlite` calls and the TypeScript parser can never block
278
- * the main event loop — the failure mode that used to freeze terminals is
279
- * structurally impossible. When the built worker file is not present (tests
280
- * run from source, exotic runtimes) or `WRONGSTACK_INDEX_INLINE=1` is set,
281
- * operations fall back to running inline through the same service layer.
282
- *
283
- * Concerns owned here, in front of either execution mode:
284
- *
285
- * 1. **Serialization** — every write run (startup scan, per-edit incremental,
286
- * external file-watch, manual reindex) goes through one process-wide
287
- * promise-chain mutex so two runs never race the same `index.db` writer.
288
- * 2. **Debounce** — rapid successive edits to the same file coalesce into a
289
- * single reindex, keyed per `(indexDir, file)`.
290
- * 3. **Watchdog** — every operation is raced against a timeout. In worker
291
- * mode a timeout hard-terminates the worker (it respawns lazily on the
292
- * next request); inline it aborts the run's signal. Either way the mutex
293
- * chain always advances and the promise always settles.
294
- * 4. **Circuit breaker** — repeated failures/timeouts pause indexing instead
295
- * of queuing more work behind a wedged pipeline. See circuit-breaker.ts.
296
- * 5. **State tracking** — ready/indexing/progress flags + change listeners
297
- * for the TUI status chip and the search/stats tools' gating.
298
- */
299
-
300
- /** True once the first full-project index has completed (success or failure). */
301
- declare function isIndexReady(): boolean;
302
- /** True while an index build is actively running. */
303
- declare function isIndexing(): boolean;
304
- /** Current indexing progress: { currentFile, totalFiles, ready, indexing, circuit }. */
305
- declare function getIndexState(): {
306
- ready: boolean;
307
- indexing: boolean;
308
- currentFile: number;
309
- totalFiles: number;
310
- lastError: string | null;
311
- /** Circuit-breaker state — `open` means indexing is paused after repeated failures. */
312
- circuit: CircuitSnapshot;
313
- };
314
- /**
315
- * Optional callback fired on every lifecycle transition (started, progress,
316
- * completed, failed). Plug into the event bus or a TUI dispatcher to surface
317
- * the indexing state in real time.
318
- */
319
- type IndexStateListener = (state: ReturnType<typeof getIndexState>) => void;
320
- declare function onIndexStateChange(listener: IndexStateListener): () => void;
321
- /**
322
- * Tear down the index host (worker + pending debounces). Call on process
323
- * shutdown; safe to call when nothing is running.
324
- */
325
- declare function shutdownCodebaseIndexHost(): void;
326
- /** True when the file's extension maps to a language the indexer can parse. */
327
- declare function isIndexableFile(filePath: string): boolean;
328
- declare function runStartupIndex(opts: {
329
- projectRoot: string;
330
- indexDir?: string | undefined;
331
- force?: boolean | undefined;
332
- langs?: string[] | undefined;
333
- signal?: AbortSignal | undefined;
334
- /** Watchdog timeout for the whole run. Default: 120s. */
335
- timeoutMs?: number | undefined;
336
- }): Promise<IndexResult>;
337
- /**
338
- * Debounced, fire-and-forget incremental reindex of specific files. Used by the
339
- * per-edit toolCall middleware and the external file watcher. Non-indexable
340
- * paths are dropped. Errors are reported via the optional `onError` callback and
341
- * never thrown to the caller (background work must not crash a turn).
342
- */
343
- declare function enqueueReindex(opts: {
344
- projectRoot: string;
345
- files: string[];
346
- indexDir?: string | undefined;
347
- debounceMs?: number | undefined;
348
- /** Watchdog timeout per file. Default: 30s. */
349
- timeoutMs?: number | undefined;
350
- onError?: ((err: unknown) => void) | undefined;
351
- }): void;
352
- /** Cancel all pending debounced reindexes. For teardown / tests. */
353
- declare function cancelPendingReindexes(): void;
354
- /**
355
- * Ranked symbol search against the index. The query runs in the index worker
356
- * (or inline in fallback mode) — the main thread never opens SQLite. Reads
357
- * don't take the write mutex (WAL readers don't block the writer) and don't
358
- * feed the circuit breaker; a wedged read still trips the watchdog, which
359
- * recycles the worker.
360
- */
361
- declare function searchCodebaseIndex(args: SearchOpArgs, opts?: {
362
- timeoutMs?: number | undefined;
363
- signal?: AbortSignal | undefined;
364
- }): Promise<SearchOpResult>;
365
- /** Index health/statistics, fetched off the main thread like searches. */
366
- declare function codebaseIndexStats(args: StatsOpArgs, opts?: {
367
- timeoutMs?: number | undefined;
368
- signal?: AbortSignal | undefined;
369
- }): Promise<IndexStats>;
370
-
371
- export { CircuitOpenError as C, type FileMeta as F, type IndexResult as I, type Ref as R, type Symbol as S, type SymbolKind as a, type SymbolLang as b, type SearchResult as c, type IndexStats as d, type CircuitSnapshot as e, type CircuitState as f, type FileSymbols as g, IndexCircuitBreaker as h, IndexTimeoutError as i, SCHEMA_VERSION as j, cancelPendingReindexes as k, codebaseIndexStats as l, codebaseIndexTool as m, codebaseSearchTool as n, codebaseStatsTool as o, enqueueReindex as p, getIndexState as q, indexCircuitBreaker as r, isIndexReady as s, isIndexableFile as t, isIndexing as u, onIndexStateChange as v, resetIndexCircuitBreaker as w, runStartupIndex as x, searchCodebaseIndex as y, shutdownCodebaseIndexHost as z };
@@ -1,121 +0,0 @@
1
- import { Tool } from '@wrongstack/core';
2
-
3
- /**
4
- * Heuristic danger detection for `exec` tool commands.
5
- *
6
- * Layered on top of `BLOCKED_ARG_PATTERNS` (which is a hard-deny list for
7
- * clear sandbox escapes) and `bash-kill-guard.ts` (which protects WrongStack
8
- * itself from kill). This module assigns a danger level to a command/arg
9
- * pair so the caller can decide whether to:
10
- *
11
- * - 'safe' → execute normally
12
- * - 'caution' → execute and emit a warning line to the tool output
13
- * - 'destructive' → route through the existing confirm flow
14
- * (`execTool.permission === 'confirm'`) instead of
15
- * hard-deny, so the user can still proceed if intentional
16
- *
17
- * Design constraints:
18
- * - Deterministic: no randomness, no I/O, no time. Same input → same output.
19
- * - No LLM calls. Patterns are regex / exact-match.
20
- * - Per-rule `id` so config can override specific rules via
21
- * `tools.exec.danger.bypass`.
22
- * - Reasons are human-readable, joined with "; " for the confirm prompt.
23
- *
24
- * Caution rules are deliberately permissive — they execute and emit a
25
- * warning rather than blocking. The rationale: many of these patterns
26
- * (python -c, sudo) are part of legitimate dev workflows,
27
- * so a hard deny would block too much. A warning gives the user a
28
- * chance to notice "wait, I didn't mean to do that" without forcing
29
- * them to add a config override for every script.
30
- */
31
- type DangerLevel = 'safe' | 'caution' | 'destructive';
32
- interface DangerAssessment {
33
- level: DangerLevel;
34
- reasons: string[];
35
- /** Stable id of the matched rule, for tests and config-override. */
36
- matchedRule?: string;
37
- }
38
- /**
39
- * Evaluate the danger level of a (cmd, args) pair.
40
- *
41
- * Returns 'safe' if no rule fires, otherwise the highest level among all
42
- * matching rules. The 'matchedRule' field is the *last* rule that fired
43
- * (stable, since rules are evaluated in declaration order).
44
- *
45
- * Optional `bypass` argument: a set of rule ids that should be SKIPPED
46
- * even if they would otherwise match. Wired from
47
- * `config.tools.exec.danger.bypass` (see `ExecDangerConfig` in
48
- * `@wrongstack/core/src/types/config.ts`). Unknown ids are silently
49
- * ignored — forward-compat: a rule added in a future version can be
50
- * referenced before the user upgrades their config schema.
51
- *
52
- * This function is the single source of truth for danger classification;
53
- * it is pure (no side effects) and unit-tested in `danger-detect.test.ts`.
54
- */
55
- declare function detectDanger(cmd: string, args: readonly string[], bypass?: ReadonlySet<string>): DangerAssessment;
56
-
57
- /**
58
- * Apply the configured exec command policy. Recomputes the effective allowlist
59
- * as `DEFAULT ∪ allow − deny`. Call once at boot from
60
- * `config.tools.exec.{allow,deny}`. Idempotent (always rebuilt from defaults).
61
- *
62
- * SECURITY: `allow` must originate from TRUSTED config only — the config loader
63
- * strips `tools.exec.allow` from the untrusted in-project repo config before it
64
- * reaches here. `deny` is safe from any source (it only narrows).
65
- */
66
- declare function configureExecPolicy(opts?: {
67
- allow?: readonly string[] | undefined;
68
- deny?: readonly string[] | undefined;
69
- }): void;
70
- /** Reset the exec allowlist to the built-in defaults (tests / re-init). */
71
- declare function resetExecPolicy(): void;
72
- /**
73
- * Apply the configured danger-bypass policy. Each id in `bypass` is
74
- * added to the effective skip set; duplicates are fine. Idempotent.
75
- *
76
- * Call once at boot from `config.tools.exec.danger.bypass`.
77
- */
78
- declare function configureDangerBypass(opts?: {
79
- bypass?: readonly string[] | undefined;
80
- }): void;
81
- /** Reset the danger-bypass set to empty (tests / re-init). */
82
- declare function resetDangerBypass(): void;
83
- /**
84
- * Read-only view of the active bypass set. `detectDanger()` takes a
85
- * `bypass` argument directly, so consumers should prefer passing this
86
- * rather than reading the set and matching themselves.
87
- */
88
- declare function getDangerBypass(): ReadonlySet<string>;
89
- /** Whether `cmd` is currently in the effective exec allowlist. */
90
- declare function isExecCommandAllowed(cmd: string): boolean;
91
- /** Snapshot of the effective allowlist (sorted) — for tests / diagnostics. */
92
- declare function getExecAllowlist(): string[];
93
- interface ExecInput {
94
- command: string;
95
- args?: string[] | undefined;
96
- cwd?: string | undefined;
97
- timeout?: number | undefined;
98
- }
99
- interface ExecOutput {
100
- command: string;
101
- args: string[];
102
- stdout: string;
103
- stderr: string;
104
- exitCode: number;
105
- truncated: boolean;
106
- allowed: boolean;
107
- /**
108
- * Heuristic danger assessment of the (cmd, args) pair. Populated for every
109
- * call (not just blocked ones) so the UI/TUI can render a banner when the
110
- * level is 'caution' or 'destructive'. See `_danger-detect.ts` for the
111
- * rule set.
112
- *
113
- * Pre-execution error returns (allowlist miss, circuit breaker, etc.)
114
- * report `level: 'safe'` because the command never actually ran; the UI
115
- * should surface the error separately and not also a danger warning.
116
- */
117
- danger: DangerAssessment;
118
- }
119
- declare const execTool: Tool<ExecInput, ExecOutput>;
120
-
121
- export { type DangerAssessment as D, type DangerLevel as a, configureExecPolicy as b, configureDangerBypass as c, detectDanger as d, execTool as e, getExecAllowlist as f, getDangerBypass as g, resetExecPolicy as h, isExecCommandAllowed as i, resetDangerBypass as r };