@travisennis/acai 0.0.12 → 0.0.14

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 (242) hide show
  1. package/README.md +5 -2
  2. package/dist/agent/index.d.ts.map +1 -1
  3. package/dist/agent/index.js +91 -5
  4. package/dist/commands/history/types.d.ts +3 -2
  5. package/dist/commands/history/types.d.ts.map +1 -1
  6. package/dist/commands/init-project/utils.d.ts +0 -1
  7. package/dist/commands/init-project/utils.d.ts.map +1 -1
  8. package/dist/commands/init-project/utils.js +1 -1
  9. package/dist/commands/manager.d.ts.map +1 -1
  10. package/dist/commands/manager.js +0 -18
  11. package/dist/commands/share/html-renderer.d.ts.map +1 -1
  12. package/dist/commands/share/html-renderer.js +54 -48
  13. package/dist/commands/tools/index.js +39 -38
  14. package/dist/config/index.d.ts +0 -2
  15. package/dist/config/index.d.ts.map +1 -1
  16. package/dist/config/index.js +3 -7
  17. package/dist/index.d.ts +14 -0
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +94 -76
  20. package/dist/models/manager.d.ts +1 -10
  21. package/dist/models/manager.d.ts.map +1 -1
  22. package/dist/models/manager.js +2 -2
  23. package/dist/models/opencode-go-provider.d.ts +6 -4
  24. package/dist/models/opencode-go-provider.d.ts.map +1 -1
  25. package/dist/models/opencode-go-provider.js +55 -35
  26. package/dist/models/providers.d.ts +1 -1
  27. package/dist/models/providers.d.ts.map +1 -1
  28. package/dist/prompts/system-prompt.d.ts +0 -2
  29. package/dist/prompts/system-prompt.d.ts.map +1 -1
  30. package/dist/prompts/system-prompt.js +6 -10
  31. package/dist/repl/index.d.ts +27 -11
  32. package/dist/repl/index.d.ts.map +1 -1
  33. package/dist/repl/index.js +238 -254
  34. package/dist/sessions/manager.d.ts +41 -0
  35. package/dist/sessions/manager.d.ts.map +1 -1
  36. package/dist/sessions/manager.js +53 -0
  37. package/dist/sessions/summary.d.ts.map +1 -1
  38. package/dist/sessions/summary.js +18 -0
  39. package/dist/skills/index.d.ts +12 -2
  40. package/dist/skills/index.d.ts.map +1 -1
  41. package/dist/skills/index.js +123 -73
  42. package/dist/terminal/control.d.ts +1 -21
  43. package/dist/terminal/control.d.ts.map +1 -1
  44. package/dist/terminal/control.js +1 -32
  45. package/dist/terminal/formatting.d.ts +0 -33
  46. package/dist/terminal/formatting.d.ts.map +1 -1
  47. package/dist/terminal/formatting.js +0 -91
  48. package/dist/terminal/highlight/theme.d.ts +0 -37
  49. package/dist/terminal/highlight/theme.d.ts.map +1 -1
  50. package/dist/terminal/highlight/theme.js +1 -79
  51. package/dist/terminal/keys.d.ts +0 -97
  52. package/dist/terminal/keys.d.ts.map +1 -1
  53. package/dist/terminal/keys.js +0 -194
  54. package/dist/terminal/select-prompt.d.ts.map +1 -1
  55. package/dist/terminal/select-prompt.js +65 -51
  56. package/dist/terminal/style.d.ts +1 -1
  57. package/dist/terminal/style.d.ts.map +1 -1
  58. package/dist/terminal/supports-color.d.ts.map +1 -1
  59. package/dist/terminal/supports-color.js +38 -20
  60. package/dist/terminal/supports-hyperlinks.d.ts +3 -0
  61. package/dist/terminal/supports-hyperlinks.d.ts.map +1 -1
  62. package/dist/terminal/supports-hyperlinks.js +72 -31
  63. package/dist/terminal/table/layout-manager.d.ts +0 -20
  64. package/dist/terminal/table/layout-manager.d.ts.map +1 -1
  65. package/dist/terminal/table/layout-manager.js +68 -44
  66. package/dist/terminal/table/utils.d.ts +0 -1
  67. package/dist/terminal/table/utils.d.ts.map +1 -1
  68. package/dist/terminal/table/utils.js +2 -4
  69. package/dist/tools/apply-patch.d.ts +5 -3
  70. package/dist/tools/apply-patch.d.ts.map +1 -1
  71. package/dist/tools/apply-patch.js +154 -123
  72. package/dist/tools/bash.d.ts.map +1 -1
  73. package/dist/tools/bash.js +11 -8
  74. package/dist/tools/dynamic-tool-loader.d.ts +6 -1
  75. package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
  76. package/dist/tools/dynamic-tool-loader.js +154 -135
  77. package/dist/tools/index.d.ts +3 -133
  78. package/dist/tools/index.d.ts.map +1 -1
  79. package/dist/tools/index.js +0 -20
  80. package/dist/tools/read-file.d.ts.map +1 -1
  81. package/dist/tools/read-file.js +32 -13
  82. package/dist/tools/skill.d.ts.map +1 -1
  83. package/dist/tools/skill.js +20 -13
  84. package/dist/tools/web-fetch.d.ts +2 -6
  85. package/dist/tools/web-fetch.d.ts.map +1 -1
  86. package/dist/tools/web-fetch.js +59 -36
  87. package/dist/tools/web-search.d.ts +0 -4
  88. package/dist/tools/web-search.d.ts.map +1 -1
  89. package/dist/tools/web-search.js +40 -32
  90. package/dist/tui/autocomplete/utils.d.ts +0 -15
  91. package/dist/tui/autocomplete/utils.d.ts.map +1 -1
  92. package/dist/tui/autocomplete/utils.js +0 -85
  93. package/dist/tui/autocomplete.d.ts +1 -1
  94. package/dist/tui/autocomplete.d.ts.map +1 -1
  95. package/dist/tui/autocomplete.js +1 -1
  96. package/dist/tui/components/editor.d.ts +12 -0
  97. package/dist/tui/components/editor.d.ts.map +1 -1
  98. package/dist/tui/components/editor.js +181 -195
  99. package/dist/tui/components/input.d.ts +4 -0
  100. package/dist/tui/components/input.d.ts.map +1 -1
  101. package/dist/tui/components/input.js +33 -31
  102. package/dist/tui/components/markdown.d.ts +30 -0
  103. package/dist/tui/components/markdown.d.ts.map +1 -1
  104. package/dist/tui/components/markdown.js +274 -242
  105. package/dist/tui/components/modal.d.ts.map +1 -1
  106. package/dist/tui/components/modal.js +11 -11
  107. package/dist/tui/components/select-list.d.ts +5 -0
  108. package/dist/tui/components/select-list.d.ts.map +1 -1
  109. package/dist/tui/components/select-list.js +69 -98
  110. package/dist/tui/components/table.d.ts +6 -0
  111. package/dist/tui/components/table.d.ts.map +1 -1
  112. package/dist/tui/components/table.js +61 -52
  113. package/dist/tui/index.d.ts +1 -8
  114. package/dist/tui/index.d.ts.map +1 -1
  115. package/dist/tui/index.js +0 -8
  116. package/dist/tui/tui.d.ts +9 -0
  117. package/dist/tui/tui.d.ts.map +1 -1
  118. package/dist/tui/tui.js +78 -48
  119. package/dist/tui/utils.d.ts +7 -0
  120. package/dist/tui/utils.d.ts.map +1 -1
  121. package/dist/tui/utils.js +117 -53
  122. package/dist/utils/bash.d.ts.map +1 -1
  123. package/dist/utils/bash.js +156 -104
  124. package/dist/utils/command-protection.d.ts +3 -6
  125. package/dist/utils/command-protection.d.ts.map +1 -1
  126. package/dist/utils/command-protection.js +213 -100
  127. package/dist/utils/filesystem/operations.d.ts +0 -15
  128. package/dist/utils/filesystem/operations.d.ts.map +1 -1
  129. package/dist/utils/filesystem/operations.js +1 -38
  130. package/dist/utils/filesystem/security.d.ts.map +1 -1
  131. package/dist/utils/filesystem/security.js +22 -15
  132. package/dist/utils/filetype-detection.d.ts +0 -1
  133. package/dist/utils/filetype-detection.d.ts.map +1 -1
  134. package/dist/utils/filetype-detection.js +0 -12
  135. package/dist/utils/formatting.d.ts +0 -30
  136. package/dist/utils/formatting.d.ts.map +1 -1
  137. package/dist/utils/formatting.js +0 -44
  138. package/dist/utils/git.d.ts +4 -6
  139. package/dist/utils/git.d.ts.map +1 -1
  140. package/dist/utils/git.js +36 -46
  141. package/dist/utils/ignore.d.ts +1 -1
  142. package/dist/utils/ignore.d.ts.map +1 -1
  143. package/dist/utils/ignore.js +1 -1
  144. package/dist/utils/process.d.ts.map +1 -1
  145. package/dist/utils/process.js +77 -79
  146. package/dist/utils/yaml.d.ts +0 -1
  147. package/dist/utils/yaml.d.ts.map +1 -1
  148. package/dist/utils/yaml.js +80 -89
  149. package/dist/utils/zod.d.ts +0 -3
  150. package/dist/utils/zod.d.ts.map +1 -1
  151. package/dist/utils/zod.js +0 -7
  152. package/package.json +25 -24
  153. package/dist/agent/sub-agent.d.ts +0 -23
  154. package/dist/agent/sub-agent.d.ts.map +0 -1
  155. package/dist/agent/sub-agent.js +0 -109
  156. package/dist/commands/add-directory/index.d.ts +0 -3
  157. package/dist/commands/add-directory/index.d.ts.map +0 -1
  158. package/dist/commands/add-directory/index.js +0 -50
  159. package/dist/commands/add-directory/utils.d.ts +0 -3
  160. package/dist/commands/add-directory/utils.d.ts.map +0 -1
  161. package/dist/commands/add-directory/utils.js +0 -15
  162. package/dist/commands/clear/index.d.ts +0 -3
  163. package/dist/commands/clear/index.d.ts.map +0 -1
  164. package/dist/commands/clear/index.js +0 -13
  165. package/dist/commands/generate-rules/index.d.ts +0 -3
  166. package/dist/commands/generate-rules/index.d.ts.map +0 -1
  167. package/dist/commands/generate-rules/index.js +0 -206
  168. package/dist/commands/generate-rules/service.d.ts +0 -22
  169. package/dist/commands/generate-rules/service.d.ts.map +0 -1
  170. package/dist/commands/generate-rules/service.js +0 -103
  171. package/dist/commands/generate-rules/utils.d.ts +0 -5
  172. package/dist/commands/generate-rules/utils.d.ts.map +0 -1
  173. package/dist/commands/generate-rules/utils.js +0 -25
  174. package/dist/commands/handoff/index.d.ts +0 -3
  175. package/dist/commands/handoff/index.d.ts.map +0 -1
  176. package/dist/commands/handoff/index.js +0 -97
  177. package/dist/commands/handoff/utils.d.ts +0 -4
  178. package/dist/commands/handoff/utils.d.ts.map +0 -1
  179. package/dist/commands/handoff/utils.js +0 -123
  180. package/dist/commands/list-directories/index.d.ts +0 -3
  181. package/dist/commands/list-directories/index.d.ts.map +0 -1
  182. package/dist/commands/list-directories/index.js +0 -35
  183. package/dist/commands/pickup/index.d.ts +0 -3
  184. package/dist/commands/pickup/index.d.ts.map +0 -1
  185. package/dist/commands/pickup/index.js +0 -141
  186. package/dist/commands/pickup/types.d.ts +0 -6
  187. package/dist/commands/pickup/types.d.ts.map +0 -1
  188. package/dist/commands/pickup/types.js +0 -1
  189. package/dist/commands/pickup/utils.d.ts +0 -7
  190. package/dist/commands/pickup/utils.d.ts.map +0 -1
  191. package/dist/commands/pickup/utils.js +0 -56
  192. package/dist/commands/remove-directory/index.d.ts +0 -3
  193. package/dist/commands/remove-directory/index.d.ts.map +0 -1
  194. package/dist/commands/remove-directory/index.js +0 -55
  195. package/dist/commands/review/index.d.ts +0 -3
  196. package/dist/commands/review/index.d.ts.map +0 -1
  197. package/dist/commands/review/index.js +0 -12
  198. package/dist/commands/review/review-panel.d.ts +0 -3
  199. package/dist/commands/review/review-panel.d.ts.map +0 -1
  200. package/dist/commands/review/review-panel.js +0 -186
  201. package/dist/commands/review/utils.d.ts +0 -18
  202. package/dist/commands/review/utils.d.ts.map +0 -1
  203. package/dist/commands/review/utils.js +0 -146
  204. package/dist/commands/shell/index.d.ts +0 -3
  205. package/dist/commands/shell/index.d.ts.map +0 -1
  206. package/dist/commands/shell/index.js +0 -96
  207. package/dist/subagents/index.d.ts +0 -16
  208. package/dist/subagents/index.d.ts.map +0 -1
  209. package/dist/subagents/index.js +0 -231
  210. package/dist/terminal/index.d.ts +0 -9
  211. package/dist/terminal/index.d.ts.map +0 -1
  212. package/dist/terminal/index.js +0 -8
  213. package/dist/tools/agent.d.ts +0 -27
  214. package/dist/tools/agent.d.ts.map +0 -1
  215. package/dist/tools/agent.js +0 -81
  216. package/dist/tools/directory-tree.d.ts +0 -28
  217. package/dist/tools/directory-tree.d.ts.map +0 -1
  218. package/dist/tools/directory-tree.js +0 -154
  219. package/dist/tools/glob.d.ts +0 -35
  220. package/dist/tools/glob.d.ts.map +0 -1
  221. package/dist/tools/glob.js +0 -167
  222. package/dist/tools/grep.d.ts +0 -100
  223. package/dist/tools/grep.d.ts.map +0 -1
  224. package/dist/tools/grep.js +0 -608
  225. package/dist/tools/ls.d.ts +0 -26
  226. package/dist/tools/ls.d.ts.map +0 -1
  227. package/dist/tools/ls.js +0 -83
  228. package/dist/tui/components/header.d.ts +0 -21
  229. package/dist/tui/components/header.d.ts.map +0 -1
  230. package/dist/tui/components/header.js +0 -63
  231. package/dist/utils/bash/parse.d.ts +0 -19
  232. package/dist/utils/bash/parse.d.ts.map +0 -1
  233. package/dist/utils/bash/parse.js +0 -223
  234. package/dist/utils/bash/quote.d.ts +0 -6
  235. package/dist/utils/bash/quote.d.ts.map +0 -1
  236. package/dist/utils/bash/quote.js +0 -23
  237. package/dist/utils/generators.d.ts +0 -3
  238. package/dist/utils/generators.d.ts.map +0 -1
  239. package/dist/utils/generators.js +0 -25
  240. package/dist/utils/glob.d.ts +0 -52
  241. package/dist/utils/glob.d.ts.map +0 -1
  242. package/dist/utils/glob.js +0 -376
package/dist/tui/utils.js CHANGED
@@ -123,6 +123,20 @@ function truncateSimple(text, targetWidth, maxWidth) {
123
123
  visibleSoFar: state.visibleSoFar,
124
124
  };
125
125
  }
126
+ /**
127
+ * Find the end of the current text segment (until tab or ANSI code).
128
+ */
129
+ function findSegmentEnd(text, start) {
130
+ let end = start;
131
+ while (end < text.length && text[end] !== "\t") {
132
+ const nextAnsi = extractAnsiCode(text, end);
133
+ if (nextAnsi) {
134
+ return end;
135
+ }
136
+ end++;
137
+ }
138
+ return end;
139
+ }
126
140
  function truncateComplex(text, targetWidth, maxWidth) {
127
141
  const state = createInitialState();
128
142
  let i = 0;
@@ -140,14 +154,7 @@ function truncateComplex(text, targetWidth, maxWidth) {
140
154
  continue;
141
155
  }
142
156
  // Find end of current text segment (until tab or ANSI)
143
- let end = i;
144
- while (end < text.length && text[end] !== "\t") {
145
- const nextAnsi = extractAnsiCode(text, end);
146
- if (nextAnsi) {
147
- break;
148
- }
149
- end++;
150
- }
157
+ const end = findSegmentEnd(text, i);
151
158
  // Process graphemes in this segment
152
159
  for (const { segment } of getSegmenter().segment(text.slice(i, end))) {
153
160
  if (processGraphemeSegment(state, segment, targetWidth, maxWidth)) {
@@ -192,12 +199,24 @@ export function truncateToWidth(text, maxWidth, ellipsis = "...", pad = false) {
192
199
  }
193
200
  // Fast path: pure ASCII printable
194
201
  if (isPrintableAscii(text)) {
195
- if (text.length <= maxWidth) {
196
- return pad ? text + " ".repeat(maxWidth - text.length) : text;
197
- }
198
- const targetWidth = maxWidth - ellipsisWidth;
199
- return finalizeTruncatedResult(text.slice(0, targetWidth), targetWidth, ellipsis, ellipsisWidth, maxWidth, pad);
202
+ return truncateAscii(text, maxWidth, ellipsis, ellipsisWidth, pad);
203
+ }
204
+ return truncateNonAscii(text, maxWidth, ellipsis, ellipsisWidth, pad);
205
+ }
206
+ /**
207
+ * Truncate ASCII-only text with ellipsis.
208
+ */
209
+ function truncateAscii(text, maxWidth, ellipsis, ellipsisWidth, pad) {
210
+ if (text.length <= maxWidth) {
211
+ return pad ? text + " ".repeat(maxWidth - text.length) : text;
200
212
  }
213
+ const targetWidth = maxWidth - ellipsisWidth;
214
+ return finalizeTruncatedResult(text.slice(0, targetWidth), targetWidth, ellipsis, ellipsisWidth, maxWidth, pad);
215
+ }
216
+ /**
217
+ * Truncate text that may contain ANSI codes, tabs, or Unicode wide characters.
218
+ */
219
+ function truncateNonAscii(text, maxWidth, ellipsis, ellipsisWidth, pad) {
201
220
  const targetWidth = maxWidth - ellipsisWidth;
202
221
  const hasAnsi = text.includes("\x1b");
203
222
  const hasTabs = text.includes("\t");
@@ -221,31 +240,71 @@ export function truncateToWidth(text, maxWidth, ellipsis = "...", pad = false) {
221
240
  return finalizeTruncatedResult(truncatedResult.result, truncatedResult.keptWidth, ellipsis, ellipsisWidth, maxWidth, pad);
222
241
  }
223
242
  /**
224
- * Truncate a single fragment to a maximum width.
243
+ * Truncate text that contains only graphemes (no ANSI, no tabs) by
244
+ * iterating grapheme clusters up to maxWidth.
225
245
  */
226
- function truncateFragmentToWidth(text, maxWidth) {
227
- if (maxWidth <= 0 || text.length === 0) {
228
- return { text: "", width: 0 };
246
+ function truncateGraphemesOnly(text, maxWidth) {
247
+ let result = "";
248
+ let width = 0;
249
+ for (const { segment } of getSegmenter().segment(text)) {
250
+ const w = graphemeWidth(segment);
251
+ if (width + w > maxWidth) {
252
+ break;
253
+ }
254
+ result += segment;
255
+ width += w;
229
256
  }
230
- if (isPrintableAscii(text)) {
231
- const clipped = text.slice(0, maxWidth);
232
- return { text: clipped, width: clipped.length };
257
+ return { text: result, width };
258
+ }
259
+ /**
260
+ * Process a contiguous text segment (no tabs, no ANSI codes) within the
261
+ * larger ANSI/tab-aware truncation loop. Returns the consumed portion and
262
+ * updated state.
263
+ */
264
+ function processTextSegment(text, start, maxWidth, currentWidth, pendingAnsi) {
265
+ // Find end of current text segment (until tab or ANSI code)
266
+ let end = start;
267
+ while (end < text.length && text[end] !== "\t") {
268
+ const nextAnsi = extractAnsiCode(text, end);
269
+ if (nextAnsi) {
270
+ break;
271
+ }
272
+ end++;
233
273
  }
234
- const hasAnsi = text.includes("\x1b");
235
- const hasTabs = text.includes("\t");
236
- if (!hasAnsi && !hasTabs) {
237
- let result = "";
238
- let width = 0;
239
- for (const { segment } of getSegmenter().segment(text)) {
240
- const w = graphemeWidth(segment);
241
- if (width + w > maxWidth) {
242
- break;
243
- }
244
- result += segment;
245
- width += w;
274
+ let result = "";
275
+ let width = currentWidth;
276
+ let pending = pendingAnsi;
277
+ for (const { segment } of getSegmenter().segment(text.slice(start, end))) {
278
+ const w = graphemeWidth(segment);
279
+ if (width + w > maxWidth) {
280
+ return {
281
+ text: result,
282
+ width,
283
+ pendingAnsi: pending,
284
+ nextIndex: end,
285
+ exhausted: true,
286
+ };
287
+ }
288
+ if (pending) {
289
+ result += pending;
290
+ pending = "";
246
291
  }
247
- return { text: result, width };
292
+ result += segment;
293
+ width += w;
248
294
  }
295
+ return {
296
+ text: result,
297
+ width,
298
+ pendingAnsi: pending,
299
+ nextIndex: end,
300
+ exhausted: false,
301
+ };
302
+ }
303
+ /**
304
+ * Truncate text that contains ANSI codes and/or tab characters,
305
+ * correctly measuring visible width.
306
+ */
307
+ function truncateWithAnsiAndTabs(text, maxWidth) {
249
308
  let result = "";
250
309
  let width = 0;
251
310
  let i = 0;
@@ -270,30 +329,35 @@ function truncateFragmentToWidth(text, maxWidth) {
270
329
  i++;
271
330
  continue;
272
331
  }
273
- let end = i;
274
- while (end < text.length && text[end] !== "\t") {
275
- const nextAnsi = extractAnsiCode(text, end);
276
- if (nextAnsi) {
277
- break;
278
- }
279
- end++;
280
- }
281
- for (const { segment } of getSegmenter().segment(text.slice(i, end))) {
282
- const w = graphemeWidth(segment);
283
- if (width + w > maxWidth) {
284
- return { text: result, width };
285
- }
286
- if (pendingAnsi) {
287
- result += pendingAnsi;
288
- pendingAnsi = "";
289
- }
290
- result += segment;
291
- width += w;
332
+ const segmentResult = processTextSegment(text, i, maxWidth, width, pendingAnsi);
333
+ result += segmentResult.text;
334
+ width = segmentResult.width;
335
+ pendingAnsi = segmentResult.pendingAnsi;
336
+ i = segmentResult.nextIndex;
337
+ if (segmentResult.exhausted) {
338
+ break;
292
339
  }
293
- i = end;
294
340
  }
295
341
  return { text: result, width };
296
342
  }
343
+ /**
344
+ * Truncate a single fragment to a maximum width.
345
+ */
346
+ export function truncateFragmentToWidth(text, maxWidth) {
347
+ if (maxWidth <= 0 || text.length === 0) {
348
+ return { text: "", width: 0 };
349
+ }
350
+ if (isPrintableAscii(text)) {
351
+ const clipped = text.slice(0, maxWidth);
352
+ return { text: clipped, width: clipped.length };
353
+ }
354
+ const hasAnsi = text.includes("\x1b");
355
+ const hasTabs = text.includes("\t");
356
+ if (!hasAnsi && !hasTabs) {
357
+ return truncateGraphemesOnly(text, maxWidth);
358
+ }
359
+ return truncateWithAnsiAndTabs(text, maxWidth);
360
+ }
297
361
  /**
298
362
  * Finalize a truncated result with proper ANSI reset codes.
299
363
  * Only adds reset codes if the prefix contains ANSI sequences.
@@ -1 +1 @@
1
- {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../source/utils/bash.ts"],"names":[],"mappings":"AAuJA,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EAAE,EACrB,GAAG,EAAE,MAAM,GACV;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAiDtC;AAED,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,YAAY,MAAM,EAClB,cAAc,MAAM,EAAE,KACrB,MAkEF,CAAC;AA6FF,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,OAetD,CAAC"}
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../source/utils/bash.ts"],"names":[],"mappings":"AAgQA,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EAAE,EACrB,GAAG,EAAE,MAAM,GACV;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAiBtC;AAiFD,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,GAAG,IAAI,GAAG,SAAS,EACnC,YAAY,MAAM,EAClB,cAAc,MAAM,EAAE,KACrB,MAaF,CAAC;AA8EF,eAAO,MAAM,iBAAiB,GAAI,YAAY,MAAM,KAAG,OAetD,CAAC"}
@@ -81,6 +81,33 @@ function isFullyQuoted(token) {
81
81
  const last = token[token.length - 1];
82
82
  return (first === '"' && last === '"') || (first === "'" && last === "'");
83
83
  }
84
+ // Process a single git message flag token and update skip mask
85
+ // Returns true if the token was recognized as a message flag
86
+ function processGitMessageToken(tokens, i, t, skip) {
87
+ // --message=<msg> - skip this entire token
88
+ if (t.startsWith("--message=")) {
89
+ skip[i] = true;
90
+ return true;
91
+ }
92
+ // -m<msg> (attached message) - skip this entire token
93
+ if (/^-m.+/.test(t)) {
94
+ skip[i] = true;
95
+ return true;
96
+ }
97
+ // -m or --message consumes next token
98
+ if (t === "-m" || t === "--message") {
99
+ if (i + 1 < tokens.length)
100
+ skip[i + 1] = true;
101
+ return true;
102
+ }
103
+ // Combined short opts containing m, e.g. -am, -avm
104
+ if (/^-[^-]+$/.test(t) && t.includes("m")) {
105
+ if (i + 1 < tokens.length)
106
+ skip[i + 1] = true;
107
+ return true;
108
+ }
109
+ return false;
110
+ }
84
111
  // Compute which tokens should be skipped from path validation
85
112
  function computeSkipTokenMask(tokens) {
86
113
  const skip = new Array(tokens.length).fill(false);
@@ -88,41 +115,87 @@ function computeSkipTokenMask(tokens) {
88
115
  const sub = stripQuotes(tokens[1] ?? "");
89
116
  // Commands where -m/--message is a string argument (not a path)
90
117
  const gitMessageSubs = new Set(["commit", "merge", "tag", "revert", "notes"]);
91
- if (bin === "git" && gitMessageSubs.has(sub)) {
92
- let seenDoubleDash = false;
93
- for (let i = 2; i < tokens.length; i++) {
94
- const t = stripQuotes(tokens[i] ?? "");
95
- if (t === "--") {
96
- seenDoubleDash = true;
97
- continue;
98
- }
99
- if (seenDoubleDash)
100
- continue;
101
- // --message=<msg> - skip this entire token
102
- if (t.startsWith("--message=")) {
103
- skip[i] = true;
104
- continue;
105
- }
106
- // -m<msg> (attached message) - skip this entire token
107
- if (/^-m.+/.test(t)) {
108
- skip[i] = true;
109
- continue;
110
- }
111
- // -m or --message consumes next token
112
- if (t === "-m" || t === "--message") {
113
- if (i + 1 < tokens.length)
114
- skip[i + 1] = true;
115
- continue;
116
- }
117
- // Combined short opts containing m, e.g. -am, -avm
118
- if (/^-[^-]+$/.test(t) && t.includes("m")) {
119
- if (i + 1 < tokens.length)
120
- skip[i + 1] = true;
121
- }
118
+ if (bin !== "git" || !gitMessageSubs.has(sub)) {
119
+ return skip;
120
+ }
121
+ let seenDoubleDash = false;
122
+ for (let i = 2; i < tokens.length; i++) {
123
+ const t = stripQuotes(tokens[i] ?? "");
124
+ if (t === "--") {
125
+ seenDoubleDash = true;
126
+ continue;
122
127
  }
128
+ if (seenDoubleDash)
129
+ continue;
130
+ processGitMessageToken(tokens, i, t, skip);
123
131
  }
124
132
  return skip;
125
133
  }
134
+ // Extract a path embedded in a flag-style argument (--key=value or -X/path).
135
+ // Returns null if no path-like segment is found.
136
+ function extractPathFromFlag(flag) {
137
+ // --key=value style: extract and de-quote the value side
138
+ const eqIndex = flag.indexOf("=");
139
+ if (eqIndex !== -1) {
140
+ const value = stripQuotes(flag.slice(eqIndex + 1));
141
+ // Only treat as a path if it starts with a path-identifying prefix
142
+ // to avoid validating string arguments that happen to contain "/"
143
+ if (value.startsWith("/") ||
144
+ value.startsWith("~") ||
145
+ value.startsWith("./") ||
146
+ value.startsWith("../")) {
147
+ return value;
148
+ }
149
+ return null;
150
+ }
151
+ // -X/path style: single letter flag directly attached to a path
152
+ if (/^-[a-zA-Z]\//.test(flag)) {
153
+ return flag.slice(2);
154
+ }
155
+ return null;
156
+ }
157
+ function validatePathValue(rawPath, allowedDirs, cwd) {
158
+ try {
159
+ // Expand ~ to home directory for proper validation
160
+ const expandedPath = rawPath.startsWith("~/") || rawPath === "~"
161
+ ? path.join(os.homedir(), rawPath.slice(1))
162
+ : rawPath;
163
+ const resolvedPath = path.resolve(cwd, expandedPath);
164
+ if (!isPathWithinAllowedDirs(resolvedPath, allowedDirs)) {
165
+ return {
166
+ isValid: false,
167
+ error: `Path '${rawPath}' resolves outside the allowed directories (${resolvedPath}). All paths must be within ${allowedDirs.join(", ")}`,
168
+ };
169
+ }
170
+ }
171
+ catch (_e) { }
172
+ return { isValid: true };
173
+ }
174
+ function validateToken(token, allowedDirs, cwd) {
175
+ // Skip fully quoted tokens - they're string arguments, not paths
176
+ // (paths are typically unquoted or only quoted to handle spaces)
177
+ if (isFullyQuoted(token)) {
178
+ return { isValid: true };
179
+ }
180
+ // Remove quotes for path checking
181
+ const cleanToken = stripQuotes(token);
182
+ // Skip URLs and non-path tokens
183
+ if (cleanToken.includes("://") ||
184
+ (!cleanToken.includes("/") && cleanToken !== "~")) {
185
+ return { isValid: true };
186
+ }
187
+ // For flag-style tokens that embed paths (e.g., --file=/etc/passwd, -o/tmp/x),
188
+ // extract the embedded path for validation.
189
+ if (cleanToken.startsWith("-")) {
190
+ const embeddedPath = extractPathFromFlag(cleanToken);
191
+ if (!embeddedPath) {
192
+ // No embedded path found — just a flag
193
+ return { isValid: true };
194
+ }
195
+ return validatePathValue(embeddedPath, allowedDirs, cwd);
196
+ }
197
+ return validatePathValue(cleanToken, allowedDirs, cwd);
198
+ }
126
199
  // Validate path arguments to ensure they're within the project
127
200
  export function validatePaths(command, allowedDirs, cwd) {
128
201
  const tokens = tokenizeShellWords(command);
@@ -135,75 +208,52 @@ export function validatePaths(command, allowedDirs, cwd) {
135
208
  // Skip tokens marked by command-aware logic
136
209
  if (skip[i])
137
210
  continue;
138
- // Skip fully quoted tokens - they're string arguments, not paths
139
- // (paths are typically unquoted or only quoted to handle spaces)
140
- if (isFullyQuoted(token) && token.includes("\n")) {
141
- continue;
142
- }
143
- // Remove quotes for path checking
144
- const cleanToken = stripQuotes(token);
145
- // Skip if it's clearly not a path
146
- if (cleanToken.startsWith("-") ||
147
- cleanToken.includes("://") ||
148
- (!cleanToken.includes("/") && cleanToken !== "~")) {
149
- continue;
150
- }
151
- try {
152
- // Expand ~ to home directory for proper validation
153
- const expandedToken = cleanToken.startsWith("~/") || cleanToken === "~"
154
- ? path.join(os.homedir(), cleanToken.slice(1))
155
- : cleanToken;
156
- const resolvedPath = path.resolve(cwd, expandedToken);
157
- if (!isPathWithinAllowedDirs(resolvedPath, allowedDirs)) {
158
- return {
159
- isValid: false,
160
- error: `Path '${cleanToken}' resolves outside the allowed directories (${resolvedPath}). All paths must be within ${allowedDirs.join(", ")}`,
161
- };
162
- }
163
- }
164
- catch (_e) { }
211
+ const result = validateToken(token, allowedDirs, cwd);
212
+ if (!result.isValid)
213
+ return result;
165
214
  }
166
215
  return { isValid: true };
167
216
  }
168
- export const resolveCwd = (cwdInput, workingDir, allowedDirs) => {
169
- // Determine which directory to use as the base for resolving relative paths
170
- // If allowedDirs is provided and non-empty, use the first allowed directory
171
- // Otherwise use the workingDir parameter (backward compatibility)
217
+ function resolveBaseDir(allowedDirs, workingDir) {
172
218
  const baseDirForResolution = allowedDirs && allowedDirs.length > 0 ? allowedDirs[0] : workingDir;
173
219
  const projectRootAbs = path.resolve(baseDirForResolution);
174
- let projectRoot = projectRootAbs;
175
220
  try {
176
- projectRoot = fs.realpathSync(projectRootAbs);
221
+ return fs.realpathSync(projectRootAbs);
177
222
  }
178
223
  catch {
179
- // Fallback to resolved path
224
+ return projectRootAbs;
180
225
  }
181
- const raw = typeof cwdInput === "string" && cwdInput.trim() !== ""
182
- ? cwdInput.trim()
183
- : projectRoot;
184
- const abs = path.isAbsolute(raw) ? raw : path.resolve(projectRoot, raw);
185
- let target = abs;
226
+ }
227
+ function resolveRawCwd(cwdInput, projectRoot) {
228
+ if (typeof cwdInput === "string" && cwdInput.trim() !== "") {
229
+ const trimmed = cwdInput.trim();
230
+ return path.isAbsolute(trimmed)
231
+ ? trimmed
232
+ : path.resolve(projectRoot, trimmed);
233
+ }
234
+ return projectRoot;
235
+ }
236
+ function resolveRealTarget(raw) {
186
237
  try {
187
- target = fs.realpathSync(abs);
238
+ return fs.realpathSync(raw);
188
239
  }
189
240
  catch {
190
- // If the path doesn't exist entirely, validate intended path
241
+ return raw;
191
242
  }
192
- // Check if within allowed directories if provided, otherwise check project root
193
- if (allowedDirs && allowedDirs.length > 0) {
194
- if (!isPathWithinAllowedDirs(target, allowedDirs)) {
195
- throw new Error(`Working directory must be within the allowed directories: ${allowedDirs.join(", ")}. Received: ${cwdInput ?? "<default>"} -> ${target}`);
196
- }
243
+ }
244
+ function assertWithinAllowedDirs(target, allowedDirs, cwdInput) {
245
+ if (!isPathWithinAllowedDirs(target, allowedDirs)) {
246
+ throw new Error(`Working directory must be within the allowed directories: ${allowedDirs.join(", ")}. Received: ${cwdInput ?? "<default>"} -> ${target}`);
197
247
  }
198
- else {
199
- // Fallback to original behavior: check within project root
200
- const rel = path.relative(projectRoot, target);
201
- const inside = rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
202
- if (!inside) {
203
- throw new Error(`Working directory must be within the project directory: ${projectRoot}. Received: ${cwdInput ?? "<default>"} -> ${target}`);
204
- }
248
+ }
249
+ function assertWithinProjectRoot(target, projectRoot, cwdInput) {
250
+ const rel = path.relative(projectRoot, target);
251
+ const inside = rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
252
+ if (!inside) {
253
+ throw new Error(`Working directory must be within the project directory: ${projectRoot}. Received: ${cwdInput ?? "<default>"} -> ${target}`);
205
254
  }
206
- // Check existence and that it's a directory
255
+ }
256
+ function assertDirectoryExists(target) {
207
257
  let stats;
208
258
  try {
209
259
  stats = fs.statSync(target);
@@ -211,13 +261,26 @@ export const resolveCwd = (cwdInput, workingDir, allowedDirs) => {
211
261
  catch (err) {
212
262
  const error = err;
213
263
  if (error.code === "ENOENT") {
214
- throw new Error(`Working directory does not exist: ${target} (from ${cwdInput ?? "<default>"})`);
264
+ throw new Error(`Working directory does not exist: ${target}`);
215
265
  }
216
266
  throw error;
217
267
  }
218
268
  if (!stats.isDirectory()) {
219
269
  throw new Error(`Working directory is not a directory: ${target}`);
220
270
  }
271
+ return stats;
272
+ }
273
+ export const resolveCwd = (cwdInput, workingDir, allowedDirs) => {
274
+ const projectRoot = resolveBaseDir(allowedDirs, workingDir);
275
+ const raw = resolveRawCwd(cwdInput, projectRoot);
276
+ const target = resolveRealTarget(raw);
277
+ if (allowedDirs && allowedDirs.length > 0) {
278
+ assertWithinAllowedDirs(target, allowedDirs, cwdInput);
279
+ }
280
+ else {
281
+ assertWithinProjectRoot(target, projectRoot, cwdInput);
282
+ }
283
+ assertDirectoryExists(target);
221
284
  return target;
222
285
  };
223
286
  const mutatingBinaries = new Set([
@@ -278,27 +341,16 @@ function isSegmentMutating(seg) {
278
341
  const bin = tokens[0];
279
342
  if (!bin)
280
343
  return false;
281
- if (tokens.some((t) => actionMutating.has(t))) {
344
+ if (tokens.some((t) => actionMutating.has(t)))
282
345
  return true;
283
- }
284
- if (bin === "sed" && tokens.some((t) => /^-i/.test(t))) {
346
+ if (bin === "sed" && tokens.some((t) => /^-i/.test(t)))
285
347
  return true;
286
- }
287
- if (mutatingBinaries.has(bin)) {
348
+ if (mutatingBinaries.has(bin))
349
+ return true;
350
+ if (bin === "git" && tokens[1] && gitMutating.has(tokens[1]))
351
+ return true;
352
+ if (packageManagers.has(bin) && tokens[1] && npmMutating.has(tokens[1]))
288
353
  return true;
289
- }
290
- if (bin === "git" && tokens.length > 1) {
291
- const sub = tokens[1];
292
- if (typeof sub === "string" && gitMutating.has(sub)) {
293
- return true;
294
- }
295
- }
296
- if (packageManagers.has(bin) && tokens.length > 1) {
297
- const sub = tokens[1];
298
- if (typeof sub === "string" && npmMutating.has(sub)) {
299
- return true;
300
- }
301
- }
302
354
  return false;
303
355
  }
304
356
  export const isMutatingCommand = (rawCommand) => {
@@ -1,20 +1,16 @@
1
- /**
2
- * Command Protection Module
3
- * Detects and blocks destructive commands that could cause data loss
4
- */
5
1
  export interface BlockedCommandResult {
6
2
  blocked: true;
7
3
  reason: string;
8
4
  command: string;
9
5
  tip: string;
10
6
  }
11
- export interface SafeCommandResult {
7
+ interface SafeCommandResult {
12
8
  blocked: false;
13
9
  }
14
10
  /**
15
11
  * Result type for command safety check
16
12
  */
17
- export type CommandSafetyResult = BlockedCommandResult | SafeCommandResult;
13
+ type CommandSafetyResult = BlockedCommandResult | SafeCommandResult;
18
14
  /**
19
15
  * Detects if a command is destructive and should be blocked
20
16
  * @param command - The full command string to check
@@ -25,4 +21,5 @@ export declare function detectDestructiveCommand(command: string): CommandSafety
25
21
  * Generate a user-friendly blocked command message
26
22
  */
27
23
  export declare function formatBlockedCommandMessage(result: BlockedCommandResult): string;
24
+ export {};
28
25
  //# sourceMappingURL=command-protection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"command-protection.d.ts","sourceRoot":"","sources":["../../source/utils/command-protection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,KAAK,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AA0E3E;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CA4B7E;AA8WD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,oBAAoB,GAC3B,MAAM,CAQR"}
1
+ {"version":3,"file":"command-protection.d.ts","sourceRoot":"","sources":["../../source/utils/command-protection.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE,KAAK,CAAC;CAChB;AAoBD;;GAEG;AACH,KAAK,mBAAmB,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AA0EpE;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CA4B7E;AA0fD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,oBAAoB,GAC3B,MAAM,CAQR"}