@travisennis/acai 0.0.3 → 0.0.5

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 (316) hide show
  1. package/README.md +225 -6
  2. package/dist/api/exa/index.d.ts +177 -0
  3. package/dist/api/exa/index.d.ts.map +1 -0
  4. package/dist/api/exa/index.js +439 -0
  5. package/dist/cli.d.ts +3 -2
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/commands/application-log-command.d.ts +1 -0
  8. package/dist/commands/application-log-command.d.ts.map +1 -0
  9. package/dist/commands/application-log-command.js +5 -3
  10. package/dist/commands/clear-command.d.ts +1 -0
  11. package/dist/commands/clear-command.d.ts.map +1 -0
  12. package/dist/commands/clear-command.js +2 -3
  13. package/dist/commands/compact-command.d.ts +1 -0
  14. package/dist/commands/compact-command.d.ts.map +1 -0
  15. package/dist/commands/compact-command.js +1 -1
  16. package/dist/commands/copy-command.d.ts +1 -0
  17. package/dist/commands/copy-command.d.ts.map +1 -0
  18. package/dist/commands/copy-command.js +3 -2
  19. package/dist/commands/edit-command.d.ts +1 -0
  20. package/dist/commands/edit-command.d.ts.map +1 -0
  21. package/dist/commands/edit-command.js +7 -5
  22. package/dist/commands/edit-prompt-command.d.ts +2 -1
  23. package/dist/commands/edit-prompt-command.d.ts.map +1 -0
  24. package/dist/commands/edit-prompt-command.js +15 -7
  25. package/dist/commands/exit-command.d.ts +13 -2
  26. package/dist/commands/exit-command.d.ts.map +1 -0
  27. package/dist/commands/exit-command.js +14 -2
  28. package/dist/commands/files-command.d.ts +1 -0
  29. package/dist/commands/files-command.d.ts.map +1 -0
  30. package/dist/commands/files-command.js +9 -8
  31. package/dist/commands/generate-rules-command.d.ts +1 -0
  32. package/dist/commands/generate-rules-command.d.ts.map +1 -0
  33. package/dist/commands/generate-rules-command.js +4 -3
  34. package/dist/commands/health-command.d.ts +3 -1
  35. package/dist/commands/health-command.d.ts.map +1 -0
  36. package/dist/commands/health-command.js +42 -5
  37. package/dist/commands/help-command.d.ts +1 -0
  38. package/dist/commands/help-command.d.ts.map +1 -0
  39. package/dist/commands/help-command.js +2 -3
  40. package/dist/commands/init-command.d.ts +1 -0
  41. package/dist/commands/init-command.d.ts.map +1 -0
  42. package/dist/commands/init-command.js +1 -2
  43. package/dist/commands/last-log-command.d.ts +1 -0
  44. package/dist/commands/last-log-command.d.ts.map +1 -0
  45. package/dist/commands/last-log-command.js +12 -17
  46. package/dist/commands/list-tools-command.d.ts +3 -0
  47. package/dist/commands/list-tools-command.d.ts.map +1 -0
  48. package/dist/commands/list-tools-command.js +61 -0
  49. package/dist/commands/manager.d.ts +7 -2
  50. package/dist/commands/manager.d.ts.map +1 -0
  51. package/dist/commands/manager.js +43 -6
  52. package/dist/commands/model-command.d.ts +1 -0
  53. package/dist/commands/model-command.d.ts.map +1 -0
  54. package/dist/commands/model-command.js +5 -5
  55. package/dist/commands/paste-command.d.ts +1 -0
  56. package/dist/commands/paste-command.d.ts.map +1 -0
  57. package/dist/commands/paste-command.js +6 -5
  58. package/dist/commands/prompt-command.d.ts +2 -1
  59. package/dist/commands/prompt-command.d.ts.map +1 -0
  60. package/dist/commands/prompt-command.js +62 -8
  61. package/dist/commands/reset-command.d.ts +1 -0
  62. package/dist/commands/reset-command.d.ts.map +1 -0
  63. package/dist/commands/reset-command.js +1 -1
  64. package/dist/commands/rules-command.d.ts +1 -0
  65. package/dist/commands/rules-command.d.ts.map +1 -0
  66. package/dist/commands/rules-command.js +5 -3
  67. package/dist/commands/save-command.d.ts +1 -0
  68. package/dist/commands/save-command.d.ts.map +1 -0
  69. package/dist/commands/save-command.js +1 -1
  70. package/dist/commands/shell-command.d.ts +3 -0
  71. package/dist/commands/shell-command.d.ts.map +1 -0
  72. package/dist/commands/shell-command.js +60 -0
  73. package/dist/commands/types.d.ts +9 -6
  74. package/dist/commands/types.d.ts.map +1 -0
  75. package/dist/commands/usage-command.d.ts +1 -0
  76. package/dist/commands/usage-command.d.ts.map +1 -0
  77. package/dist/commands/usage-command.js +2 -3
  78. package/dist/config.d.ts +22 -34
  79. package/dist/config.d.ts.map +1 -0
  80. package/dist/config.js +61 -15
  81. package/dist/conversation-analyzer.d.ts +2 -1
  82. package/dist/conversation-analyzer.d.ts.map +1 -0
  83. package/dist/dedent.d.ts +1 -0
  84. package/dist/dedent.d.ts.map +1 -0
  85. package/dist/execution/index.d.ts +112 -0
  86. package/dist/execution/index.d.ts.map +1 -0
  87. package/dist/execution/index.js +432 -0
  88. package/dist/formatting.d.ts +2 -13
  89. package/dist/formatting.d.ts.map +1 -0
  90. package/dist/formatting.js +5 -64
  91. package/dist/index.d.ts +1 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +14 -4
  94. package/dist/logger.d.ts +1 -0
  95. package/dist/logger.d.ts.map +1 -0
  96. package/dist/mentions.d.ts +4 -0
  97. package/dist/mentions.d.ts.map +1 -0
  98. package/dist/mentions.js +42 -10
  99. package/dist/messages.d.ts +8 -20
  100. package/dist/messages.d.ts.map +1 -0
  101. package/dist/messages.js +33 -53
  102. package/dist/middleware/audit-message.d.ts +1 -0
  103. package/dist/middleware/audit-message.d.ts.map +1 -0
  104. package/dist/middleware/index.d.ts +1 -0
  105. package/dist/middleware/index.d.ts.map +1 -0
  106. package/dist/middleware/rate-limit.d.ts +1 -0
  107. package/dist/middleware/rate-limit.d.ts.map +1 -0
  108. package/dist/models/ai-config.d.ts +1 -0
  109. package/dist/models/ai-config.d.ts.map +1 -0
  110. package/dist/models/anthropic-provider.d.ts +1 -0
  111. package/dist/models/anthropic-provider.d.ts.map +1 -0
  112. package/dist/models/deepseek-provider.d.ts +1 -0
  113. package/dist/models/deepseek-provider.d.ts.map +1 -0
  114. package/dist/models/google-provider.d.ts +1 -0
  115. package/dist/models/google-provider.d.ts.map +1 -0
  116. package/dist/models/groq-provider.d.ts +20 -0
  117. package/dist/models/groq-provider.d.ts.map +1 -0
  118. package/dist/models/groq-provider.js +31 -0
  119. package/dist/models/manager.d.ts +1 -0
  120. package/dist/models/manager.d.ts.map +1 -0
  121. package/dist/models/openai-provider.d.ts +2 -1
  122. package/dist/models/openai-provider.d.ts.map +1 -0
  123. package/dist/models/openrouter-provider.d.ts +31 -22
  124. package/dist/models/openrouter-provider.d.ts.map +1 -0
  125. package/dist/models/openrouter-provider.js +115 -1
  126. package/dist/models/providers.d.ts +4 -5
  127. package/dist/models/providers.d.ts.map +1 -0
  128. package/dist/models/providers.js +7 -3
  129. package/dist/models/xai-provider.d.ts +1 -0
  130. package/dist/models/xai-provider.d.ts.map +1 -0
  131. package/dist/parsing.d.ts +2 -1
  132. package/dist/parsing.d.ts.map +1 -0
  133. package/dist/prompts/manager.d.ts +14 -2
  134. package/dist/prompts/manager.d.ts.map +1 -0
  135. package/dist/prompts.d.ts +1 -0
  136. package/dist/prompts.d.ts.map +1 -0
  137. package/dist/prompts.js +17 -11
  138. package/dist/repl/display-tool-messages.d.ts +4 -0
  139. package/dist/repl/display-tool-messages.d.ts.map +1 -0
  140. package/dist/repl/display-tool-messages.js +55 -0
  141. package/dist/repl/display-tool-use.d.ts +14 -0
  142. package/dist/repl/display-tool-use.d.ts.map +1 -0
  143. package/dist/repl/display-tool-use.js +63 -0
  144. package/dist/repl/get-prompt-header.d.ts +8 -0
  145. package/dist/repl/get-prompt-header.d.ts.map +1 -0
  146. package/dist/repl/get-prompt-header.js +38 -0
  147. package/dist/repl/tool-call-repair.d.ts +4 -0
  148. package/dist/repl/tool-call-repair.d.ts.map +1 -0
  149. package/dist/repl/tool-call-repair.js +50 -0
  150. package/dist/repl-prompt.d.ts +1 -0
  151. package/dist/repl-prompt.d.ts.map +1 -0
  152. package/dist/repl.d.ts +8 -4
  153. package/dist/repl.d.ts.map +1 -0
  154. package/dist/repl.js +108 -252
  155. package/dist/terminal/ansi-styles.d.ts +77 -0
  156. package/dist/terminal/ansi-styles.d.ts.map +1 -0
  157. package/dist/terminal/ansi-styles.js +215 -0
  158. package/dist/terminal/checkbox-prompt.d.ts +36 -0
  159. package/dist/terminal/checkbox-prompt.d.ts.map +1 -0
  160. package/dist/terminal/checkbox-prompt.js +362 -0
  161. package/dist/terminal/default-theme.d.ts +6 -0
  162. package/dist/terminal/default-theme.d.ts.map +1 -0
  163. package/dist/terminal/default-theme.js +182 -0
  164. package/dist/terminal/east-asian-width.d.ts +8 -0
  165. package/dist/terminal/east-asian-width.d.ts.map +1 -0
  166. package/dist/terminal/east-asian-width.js +409 -0
  167. package/dist/terminal/editor-prompt.d.ts +10 -0
  168. package/dist/terminal/editor-prompt.d.ts.map +1 -0
  169. package/dist/terminal/editor-prompt.js +61 -0
  170. package/dist/terminal/errors.d.ts +19 -0
  171. package/dist/terminal/errors.d.ts.map +1 -0
  172. package/dist/terminal/errors.js +37 -0
  173. package/dist/terminal/formatting.d.ts +1 -11
  174. package/dist/terminal/formatting.d.ts.map +1 -0
  175. package/dist/terminal/formatting.js +4 -20
  176. package/dist/terminal/highlight/index.d.ts +53 -0
  177. package/dist/terminal/highlight/index.d.ts.map +1 -0
  178. package/dist/terminal/highlight/index.js +90 -0
  179. package/dist/terminal/highlight/theme.d.ts +233 -0
  180. package/dist/terminal/highlight/theme.d.ts.map +1 -0
  181. package/dist/terminal/highlight/theme.js +83 -0
  182. package/dist/terminal/index.d.ts +16 -9
  183. package/dist/terminal/index.d.ts.map +1 -0
  184. package/dist/terminal/index.js +42 -126
  185. package/dist/terminal/input-prompt.d.ts +16 -0
  186. package/dist/terminal/input-prompt.d.ts.map +1 -0
  187. package/dist/terminal/input-prompt.js +181 -0
  188. package/dist/terminal/markdown-utils.d.ts +1 -0
  189. package/dist/terminal/markdown-utils.d.ts.map +1 -0
  190. package/dist/terminal/markdown.d.ts +1 -0
  191. package/dist/terminal/markdown.d.ts.map +1 -0
  192. package/dist/terminal/markdown.js +17 -12
  193. package/dist/terminal/search-prompt.d.ts +20 -0
  194. package/dist/terminal/search-prompt.d.ts.map +1 -0
  195. package/dist/terminal/search-prompt.js +279 -0
  196. package/dist/terminal/select-prompt.d.ts +26 -0
  197. package/dist/terminal/select-prompt.d.ts.map +1 -0
  198. package/dist/terminal/select-prompt.js +298 -0
  199. package/dist/terminal/string-width.d.ts +7 -0
  200. package/dist/terminal/string-width.d.ts.map +1 -0
  201. package/dist/terminal/string-width.js +61 -0
  202. package/dist/terminal/strip-ansi.d.ts +2 -0
  203. package/dist/terminal/strip-ansi.d.ts.map +1 -0
  204. package/dist/terminal/strip-ansi.js +20 -0
  205. package/dist/terminal/style.d.ts +191 -0
  206. package/dist/terminal/style.d.ts.map +1 -0
  207. package/dist/terminal/style.js +259 -0
  208. package/dist/terminal/supports-color.d.ts +1 -0
  209. package/dist/terminal/supports-color.d.ts.map +1 -0
  210. package/dist/terminal/supports-hyperlinks.d.ts +1 -3
  211. package/dist/terminal/supports-hyperlinks.d.ts.map +1 -0
  212. package/dist/terminal/supports-hyperlinks.js +1 -1
  213. package/dist/terminal/types.d.ts +1 -37
  214. package/dist/terminal/types.d.ts.map +1 -0
  215. package/dist/terminal/wrap-ansi.d.ts +8 -0
  216. package/dist/terminal/wrap-ansi.d.ts.map +1 -0
  217. package/dist/terminal/wrap-ansi.js +190 -0
  218. package/dist/{token-utils.d.ts → tokens/counter.d.ts} +1 -0
  219. package/dist/tokens/counter.d.ts.map +1 -0
  220. package/dist/{token-utils.js → tokens/counter.js} +1 -1
  221. package/dist/tokens/manage-output.d.ts +34 -0
  222. package/dist/tokens/manage-output.d.ts.map +1 -0
  223. package/dist/tokens/manage-output.js +44 -0
  224. package/dist/{token-tracker.d.ts → tokens/tracker.d.ts} +1 -0
  225. package/dist/tokens/tracker.d.ts.map +1 -0
  226. package/dist/tool-executor.d.ts +28 -0
  227. package/dist/tool-executor.d.ts.map +1 -0
  228. package/dist/tool-executor.js +74 -0
  229. package/dist/tools/agent.d.ts +3 -2
  230. package/dist/tools/agent.d.ts.map +1 -0
  231. package/dist/tools/agent.js +7 -4
  232. package/dist/tools/bash-utils.d.ts +7 -0
  233. package/dist/tools/bash-utils.d.ts.map +1 -0
  234. package/dist/tools/bash-utils.js +212 -0
  235. package/dist/tools/bash.d.ts +9 -7
  236. package/dist/tools/bash.d.ts.map +1 -0
  237. package/dist/tools/bash.js +95 -212
  238. package/dist/tools/code-interpreter.d.ts +1 -0
  239. package/dist/tools/code-interpreter.d.ts.map +1 -0
  240. package/dist/tools/code-interpreter.js +33 -8
  241. package/dist/tools/delete-file.d.ts +5 -3
  242. package/dist/tools/delete-file.d.ts.map +1 -0
  243. package/dist/tools/delete-file.js +47 -33
  244. package/dist/tools/directory-tree.d.ts +10 -1
  245. package/dist/tools/directory-tree.d.ts.map +1 -0
  246. package/dist/tools/directory-tree.js +91 -8
  247. package/dist/tools/dynamic-tool-loader.d.ts +12 -0
  248. package/dist/tools/dynamic-tool-loader.d.ts.map +1 -0
  249. package/dist/tools/dynamic-tool-loader.js +280 -0
  250. package/dist/tools/dynamic-tool-parser.d.ts +20 -0
  251. package/dist/tools/dynamic-tool-parser.d.ts.map +1 -0
  252. package/dist/tools/dynamic-tool-parser.js +21 -0
  253. package/dist/tools/edit-file.d.ts +10 -2
  254. package/dist/tools/edit-file.d.ts.map +1 -0
  255. package/dist/tools/edit-file.js +117 -40
  256. package/dist/tools/file-editing-utils.d.ts +2 -0
  257. package/dist/tools/file-editing-utils.d.ts.map +1 -0
  258. package/dist/tools/file-editing-utils.js +135 -0
  259. package/dist/tools/filesystem-utils.d.ts +6 -21
  260. package/dist/tools/filesystem-utils.d.ts.map +1 -0
  261. package/dist/tools/filesystem-utils.js +96 -148
  262. package/dist/tools/git-utils.d.ts +1 -0
  263. package/dist/tools/git-utils.d.ts.map +1 -0
  264. package/dist/tools/grep.d.ts +5 -3
  265. package/dist/tools/grep.d.ts.map +1 -0
  266. package/dist/tools/grep.js +67 -27
  267. package/dist/tools/index.d.ts +10 -14
  268. package/dist/tools/index.d.ts.map +1 -0
  269. package/dist/tools/index.js +33 -22
  270. package/dist/tools/move-file.d.ts +1 -0
  271. package/dist/tools/move-file.d.ts.map +1 -0
  272. package/dist/tools/move-file.js +12 -5
  273. package/dist/tools/read-file.d.ts +2 -1
  274. package/dist/tools/read-file.d.ts.map +1 -0
  275. package/dist/tools/read-file.js +13 -6
  276. package/dist/tools/read-multiple-files.d.ts +2 -1
  277. package/dist/tools/read-multiple-files.d.ts.map +1 -0
  278. package/dist/tools/read-multiple-files.js +90 -9
  279. package/dist/tools/save-file.d.ts +5 -3
  280. package/dist/tools/save-file.d.ts.map +1 -0
  281. package/dist/tools/save-file.js +64 -36
  282. package/dist/tools/think.d.ts +1 -0
  283. package/dist/tools/think.d.ts.map +1 -0
  284. package/dist/tools/think.js +5 -1
  285. package/dist/tools/types.d.ts +14 -1
  286. package/dist/tools/types.d.ts.map +1 -0
  287. package/dist/tools/web-fetch.d.ts +4 -2
  288. package/dist/tools/web-fetch.d.ts.map +1 -0
  289. package/dist/tools/web-fetch.js +2 -2
  290. package/dist/tools/web-search.d.ts +2 -1
  291. package/dist/tools/web-search.d.ts.map +1 -0
  292. package/dist/tools/web-search.js +46 -11
  293. package/dist/utils/filesystem.d.ts +23 -0
  294. package/dist/utils/filesystem.d.ts.map +1 -0
  295. package/dist/utils/filesystem.js +140 -0
  296. package/dist/utils/filetype-detection.d.ts +3 -0
  297. package/dist/utils/filetype-detection.d.ts.map +1 -0
  298. package/dist/utils/filetype-detection.js +112 -0
  299. package/dist/utils/glob.d.ts +52 -0
  300. package/dist/utils/glob.d.ts.map +1 -0
  301. package/dist/utils/glob.js +376 -0
  302. package/dist/utils/ignore.d.ts +104 -0
  303. package/dist/utils/ignore.d.ts.map +1 -0
  304. package/dist/utils/ignore.js +649 -0
  305. package/dist/utils/process.d.ts +10 -1
  306. package/dist/utils/process.d.ts.map +1 -0
  307. package/dist/utils/process.js +104 -5
  308. package/dist/utils/zod-utils.d.ts +4 -0
  309. package/dist/utils/zod-utils.d.ts.map +1 -0
  310. package/dist/utils/zod-utils.js +7 -0
  311. package/dist/version.d.ts +1 -0
  312. package/dist/version.d.ts.map +1 -0
  313. package/package.json +32 -30
  314. package/dist/tools/command-validation.d.ts +0 -12
  315. package/dist/tools/command-validation.js +0 -113
  316. /package/dist/{token-tracker.js → tokens/tracker.js} +0 -0
@@ -1,10 +1,11 @@
1
1
  import { type ModelMessage } from "ai";
2
2
  import type { ModelManager } from "./models/manager.ts";
3
3
  import type { Terminal } from "./terminal/index.ts";
4
- import type { TokenTracker } from "./token-tracker.ts";
4
+ import type { TokenTracker } from "./tokens/tracker.ts";
5
5
  export declare function analyzeConversation({ modelManager, messages, tokenTracker, }: {
6
6
  modelManager: ModelManager;
7
7
  messages: ModelMessage[];
8
8
  terminal?: Terminal | undefined;
9
9
  tokenTracker: TokenTracker;
10
10
  }): Promise<string[]>;
11
+ //# sourceMappingURL=conversation-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-analyzer.d.ts","sourceRoot":"","sources":["../source/conversation-analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,IAAI,CAAC;AAGrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAyCxD,wBAAsB,mBAAmB,CAAC,EACxC,YAAY,EACZ,QAAQ,EACR,YAAY,GACb,EAAE;IACD,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC;IAChC,YAAY,EAAE,YAAY,CAAC;CAC5B,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA0DpB"}
package/dist/dedent.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  type Dedent = (strings: TemplateStringsArray, ...values: unknown[]) => string;
2
2
  export declare const dedent: Dedent;
3
3
  export {};
4
+ //# sourceMappingURL=dedent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dedent.d.ts","sourceRoot":"","sources":["../source/dedent.ts"],"names":[],"mappings":"AAAA,KAAK,MAAM,GAAG,CAAC,OAAO,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,KAAK,MAAM,CAAC;AAI9E,eAAO,MAAM,MAAM,EAAE,MAgDpB,CAAC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Result of a command execution
3
+ */
4
+ interface ExecutionResult {
5
+ output: string;
6
+ exitCode: number;
7
+ error?: Error;
8
+ command: string;
9
+ duration: number;
10
+ }
11
+ /**
12
+ * Command execution options
13
+ */
14
+ interface ExecutionOptions {
15
+ /** Working directory where the command will be executed */
16
+ cwd?: string;
17
+ env?: Record<string, string>;
18
+ /** Timeout in milliseconds before killing the process */
19
+ timeout?: number;
20
+ shell?: string;
21
+ /** Maximum buffer size in bytes (defaults to 1MB) */
22
+ maxBuffer?: number;
23
+ captureStderr?: boolean;
24
+ /** Whether to include stdout/stderr in the result even when there's an error (defaults to true) */
25
+ preserveOutputOnError?: boolean;
26
+ /** AbortSignal to cancel the execution */
27
+ abortSignal?: AbortSignal;
28
+ /** Whether to throw an error on non-zero exit codes (defaults to false) */
29
+ throwOnError?: boolean;
30
+ }
31
+ /**
32
+ * Background process options
33
+ */
34
+ interface BackgroundProcessOptions extends ExecutionOptions {
35
+ onOutput?: (output: string) => void;
36
+ onError?: (error: string) => void;
37
+ onExit?: (code: number | null) => void;
38
+ }
39
+ /**
40
+ * Background process handle
41
+ */
42
+ interface BackgroundProcess {
43
+ pid: number;
44
+ kill: () => boolean;
45
+ isRunning: boolean;
46
+ }
47
+ /**
48
+ * Execution environment manager
49
+ */
50
+ interface ExecutionConfig {
51
+ env?: string;
52
+ execution?: {
53
+ cwd?: string;
54
+ env?: Record<string, string>;
55
+ shell?: string;
56
+ allowedCommands?: Array<string | RegExp>;
57
+ };
58
+ }
59
+ export declare class ExecutionEnvironment {
60
+ private config;
61
+ private backgroundProcesses;
62
+ private executionCount;
63
+ private workingDirectory;
64
+ private environmentVariables;
65
+ /**
66
+ * Create a new execution environment
67
+ */
68
+ constructor(config?: ExecutionConfig);
69
+ /**
70
+ * Initialize the execution environment
71
+ */
72
+ initialize(): Promise<void>;
73
+ /**
74
+ * Execute a shell command
75
+ */
76
+ executeCommand(command: string, options?: ExecutionOptions): Promise<ExecutionResult>;
77
+ /**
78
+ * Execute a command in the background
79
+ */
80
+ executeCommandInBackground(command: string, options?: BackgroundProcessOptions): BackgroundProcess;
81
+ /**
82
+ * Kill all running background processes
83
+ */
84
+ killAllBackgroundProcesses(): void;
85
+ /**
86
+ * Validate a command for safety
87
+ */
88
+ validateCommand(command: string): void;
89
+ /**
90
+ * Set the working directory
91
+ */
92
+ setWorkingDirectory(directory: string): void;
93
+ /**
94
+ * Get the working directory
95
+ */
96
+ getWorkingDirectory(): string;
97
+ /**
98
+ * Set an environment variable
99
+ */
100
+ setEnvironmentVariable(name: string, value: string): void;
101
+ /**
102
+ * Get an environment variable
103
+ */
104
+ getEnvironmentVariable(name: string): string | undefined;
105
+ }
106
+ /**
107
+ * Initialize the execution environment
108
+ */
109
+ export declare function initExecutionEnvironment(config?: ExecutionConfig): Promise<ExecutionEnvironment>;
110
+ export declare function setupProcessCleanup(executionEnv: ExecutionEnvironment): void;
111
+ export {};
112
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/execution/index.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,UAAU,gBAAgB;IACxB,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mGAAmG;IACnG,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,0CAA0C;IAC1C,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,2EAA2E;IAC3E,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,UAAU,wBAAyB,SAAQ,gBAAgB;IACzD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACxC;AAED;;GAEG;AACH,UAAU,iBAAiB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;CACpB;AAwBD;;GAEG;AACH,UAAU,eAAe;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE;QACV,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,eAAe,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;KAC1C,CAAC;CACH;AAwBD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,mBAAmB,CAA6C;IACxE,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,oBAAoB,CAAyB;IAErD;;OAEG;gBACS,MAAM,GAAE,eAAoB;IAoBxC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBjC;;OAEG;IACG,cAAc,CAClB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAkJ3B;;OAEG;IACH,0BAA0B,CACxB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,wBAA6B,GACrC,iBAAiB;IAoIpB;;OAEG;IACH,0BAA0B,IAAI,IAAI;IAgBlC;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAgCtC;;OAEG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAK5C;;OAEG;IACH,mBAAmB,IAAI,MAAM;IAI7B;;OAEG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAKzD;;OAEG;IACH,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGzD;AAED;;GAEG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,GAAE,eAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,CAgB/B;AAwBD,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,oBAAoB,GAAG,IAAI,CAc5E"}
@@ -0,0 +1,432 @@
1
+ /**
2
+ * Execution Environment Module
3
+ *
4
+ * Provides functionality for executing shell commands and scripts
5
+ * in a controlled environment with proper error handling.
6
+ */
7
+ import { exec, spawn } from "node:child_process";
8
+ import { logger } from "../logger.js";
9
+ /**
10
+ * List of dangerous commands that shouldn't be executed
11
+ */
12
+ const DANGEROUS_COMMANDS = [
13
+ /^\s*rm\s+(-rf?|--recursive)\s+[/~]/i, // rm -rf / or similar
14
+ /^\s*dd\s+.*of=\/dev\/(disk|hd|sd)/i, // dd to a device
15
+ /^\s*mkfs/i, // Format a filesystem
16
+ /^\s*:\(\)\{\s*:\|:\s*&\s*\}\s*;/, // Fork bomb
17
+ /^\s*>(\/dev\/sd|\/dev\/hd)/, // Overwrite disk device
18
+ /^\s*sudo\s+.*(rm|mkfs|dd|chmod|chown)/i, // sudo with dangerous commands
19
+ ];
20
+ /**
21
+ * Maximum command execution time (30 seconds by default)
22
+ */
23
+ const DEFAULT_TIMEOUT = 30000;
24
+ /**
25
+ * Maximum output buffer size (5MB by default)
26
+ */
27
+ const DEFAULT_MAX_BUFFER = 5 * 1024 * 1024;
28
+ function getShell() {
29
+ return process.env["ZSH_VERSION"] ? "zsh" : process.env["SHELL"] || "bash";
30
+ }
31
+ function ttySizeEnv() {
32
+ const env = {};
33
+ if (process.stdout.isTTY &&
34
+ typeof process.stdout.columns === "number" &&
35
+ typeof process.stdout.rows === "number") {
36
+ env["COLUMNS"] = String(process.stdout.columns - 2);
37
+ env["LINES"] = String(process.stdout.rows);
38
+ }
39
+ else {
40
+ if (typeof process.env["COLUMNS"] === "string")
41
+ env["COLUMNS"] = process.env["COLUMNS"];
42
+ if (typeof process.env["LINES"] === "string")
43
+ env["LINES"] = process.env["LINES"];
44
+ }
45
+ return env;
46
+ }
47
+ export class ExecutionEnvironment {
48
+ config;
49
+ backgroundProcesses = new Map();
50
+ executionCount = 0;
51
+ workingDirectory;
52
+ environmentVariables;
53
+ /**
54
+ * Create a new execution environment
55
+ */
56
+ constructor(config = {}) {
57
+ this.config = config;
58
+ this.workingDirectory = config.execution?.cwd || process.cwd();
59
+ // Set up environment variables
60
+ this.environmentVariables = {
61
+ ...process.env,
62
+ // biome-ignore lint/style/useNamingConvention: environment variable.
63
+ NODE_ENV: config.env || "production",
64
+ ...(config.execution?.env || {}),
65
+ };
66
+ logger.debug({
67
+ workingDirectory: this.workingDirectory,
68
+ }, "Execution environment created");
69
+ }
70
+ /**
71
+ * Initialize the execution environment
72
+ */
73
+ async initialize() {
74
+ logger.info("Initializing execution environment");
75
+ try {
76
+ // Verify shell is available
77
+ const shell = this.config.execution?.shell || getShell();
78
+ await this.executeCommand(`${shell} -c "echo Shell is available"`, {
79
+ timeout: 5000,
80
+ });
81
+ logger.info("Execution environment initialized successfully");
82
+ }
83
+ catch (error) {
84
+ logger.error(error, "Failed to initialize execution environment");
85
+ throw new Error("Failed to initialize command execution environment", {
86
+ cause: error,
87
+ });
88
+ }
89
+ }
90
+ /**
91
+ * Execute a shell command
92
+ */
93
+ async executeCommand(command, options = {}) {
94
+ // Increment execution count
95
+ this.executionCount++;
96
+ // Validate command for safety
97
+ this.validateCommand(command);
98
+ const cwd = options.cwd || this.workingDirectory;
99
+ const env = {
100
+ ...this.environmentVariables,
101
+ ...ttySizeEnv(),
102
+ ...(options.env || {}),
103
+ };
104
+ const timeout = options.timeout || DEFAULT_TIMEOUT;
105
+ const maxBuffer = options.maxBuffer || DEFAULT_MAX_BUFFER;
106
+ const shell = options.shell || this.config.execution?.shell || getShell();
107
+ const captureStderr = options.captureStderr !== false;
108
+ const preserveOutputOnError = options.preserveOutputOnError !== false;
109
+ const throwOnError = options.throwOnError === true;
110
+ logger.debug({
111
+ command,
112
+ cwd,
113
+ shell,
114
+ timeout,
115
+ executionCount: this.executionCount,
116
+ hasAbortSignal: !!options.abortSignal,
117
+ }, "Executing command");
118
+ const startTime = Date.now();
119
+ return new Promise((resolve, reject) => {
120
+ // Check if already aborted
121
+ if (options.abortSignal?.aborted) {
122
+ const error = new Error("Command execution aborted");
123
+ logger.warn({ command }, "Command execution aborted before starting");
124
+ resolve({
125
+ output: "",
126
+ exitCode: 1,
127
+ error,
128
+ command,
129
+ duration: 0,
130
+ });
131
+ return;
132
+ }
133
+ const childProcess = exec(command, {
134
+ cwd,
135
+ env,
136
+ timeout,
137
+ maxBuffer,
138
+ shell,
139
+ windowsHide: true,
140
+ encoding: "utf8",
141
+ }, (error, stdout, stderr) => {
142
+ const duration = Date.now() - startTime;
143
+ // Combine stdout and stderr if requested
144
+ const output = captureStderr
145
+ ? `${stdout}${stderr ? stderr : ""}`
146
+ : stdout;
147
+ if (error) {
148
+ logger.error({
149
+ error: error.message,
150
+ exitCode: error.code,
151
+ duration,
152
+ }, `Command execution failed: ${command}`);
153
+ const result = {
154
+ output: preserveOutputOnError ? output : "",
155
+ exitCode: error.code || 1,
156
+ error,
157
+ command,
158
+ duration,
159
+ };
160
+ if (throwOnError) {
161
+ reject(error);
162
+ }
163
+ else {
164
+ resolve(result);
165
+ }
166
+ }
167
+ else {
168
+ logger.debug({
169
+ duration,
170
+ outputLength: output.length,
171
+ }, `Command executed successfully: ${command}`);
172
+ resolve({
173
+ output,
174
+ exitCode: 0,
175
+ command,
176
+ duration,
177
+ });
178
+ }
179
+ });
180
+ // Handle abort signal
181
+ if (options.abortSignal) {
182
+ const abortHandler = () => {
183
+ logger.warn({ command, pid: childProcess.pid }, "Command execution aborted");
184
+ childProcess.kill("SIGTERM");
185
+ const error = new Error("Command execution aborted");
186
+ const result = {
187
+ output: preserveOutputOnError ? "" : "",
188
+ exitCode: 1,
189
+ error,
190
+ command,
191
+ duration: Date.now() - startTime,
192
+ };
193
+ if (throwOnError) {
194
+ reject(error);
195
+ }
196
+ else {
197
+ resolve(result);
198
+ }
199
+ };
200
+ options.abortSignal.addEventListener("abort", abortHandler, {
201
+ once: true,
202
+ });
203
+ // Clean up abort listener when process completes
204
+ childProcess.on("exit", () => {
205
+ options.abortSignal?.removeEventListener("abort", abortHandler);
206
+ });
207
+ }
208
+ });
209
+ }
210
+ /**
211
+ * Execute a command in the background
212
+ */
213
+ executeCommandInBackground(command, options = {}) {
214
+ // Validate command for safety
215
+ this.validateCommand(command);
216
+ const cwd = options.cwd || this.workingDirectory;
217
+ const env = {
218
+ ...this.environmentVariables,
219
+ ...ttySizeEnv(),
220
+ ...(options.env || {}),
221
+ };
222
+ const shell = options.shell ||
223
+ this.config.execution?.shell ||
224
+ process.env["SHELL"] ||
225
+ "bash";
226
+ logger.debug({
227
+ command,
228
+ cwd,
229
+ shell,
230
+ hasAbortSignal: !!options.abortSignal,
231
+ }, "Executing command in background");
232
+ // Check if already aborted
233
+ if (options.abortSignal?.aborted) {
234
+ logger.warn({ command }, "Background command execution aborted before starting");
235
+ throw new Error("Background command execution aborted");
236
+ }
237
+ // Spawn the process
238
+ const childProcess = spawn(command, [], {
239
+ cwd,
240
+ env,
241
+ shell,
242
+ detached: true,
243
+ stdio: ["ignore", "pipe", "pipe"],
244
+ });
245
+ const pid = childProcess.pid ?? -1;
246
+ let isRunning = true;
247
+ // Set up output handlers
248
+ if (childProcess.stdout) {
249
+ childProcess.stdout.on("data", (data) => {
250
+ const output = data.toString("utf8");
251
+ logger.debug({ output }, `Background command (pid ${pid}) output:`);
252
+ if (options.onOutput) {
253
+ options.onOutput(output);
254
+ }
255
+ });
256
+ }
257
+ if (childProcess.stderr) {
258
+ childProcess.stderr.on("data", (data) => {
259
+ const errorOutput = data.toString("utf8");
260
+ logger.debug({ errorOutput }, `Background command (pid ${pid}) error:`);
261
+ if (options.onError) {
262
+ options.onError(errorOutput);
263
+ }
264
+ });
265
+ }
266
+ // Set up exit handler
267
+ childProcess.on("exit", (code) => {
268
+ isRunning = false;
269
+ logger.debug(`Background command (pid ${pid}) exited with code ${code}`);
270
+ // Remove from tracked processes
271
+ this.backgroundProcesses.delete(pid);
272
+ // Clean up abort listener
273
+ if (abortHandler) {
274
+ options.abortSignal?.removeEventListener("abort", abortHandler);
275
+ }
276
+ if (options.onExit) {
277
+ options.onExit(code);
278
+ }
279
+ });
280
+ // Handle abort signal for background process
281
+ let abortHandler;
282
+ if (options.abortSignal) {
283
+ abortHandler = () => {
284
+ logger.warn({ command, pid }, "Background command execution aborted");
285
+ if (isRunning) {
286
+ childProcess.kill("SIGTERM");
287
+ isRunning = false;
288
+ this.backgroundProcesses.delete(pid);
289
+ }
290
+ };
291
+ options.abortSignal.addEventListener("abort", abortHandler, {
292
+ once: true,
293
+ });
294
+ }
295
+ // Create the process handle
296
+ const backgroundProcess = {
297
+ pid,
298
+ kill: () => {
299
+ if (isRunning) {
300
+ childProcess.kill();
301
+ isRunning = false;
302
+ this.backgroundProcesses.delete(pid);
303
+ // Clean up abort listener
304
+ if (abortHandler) {
305
+ options.abortSignal?.removeEventListener("abort", abortHandler);
306
+ }
307
+ return true;
308
+ }
309
+ return false;
310
+ },
311
+ isRunning: true,
312
+ };
313
+ // Track the process
314
+ this.backgroundProcesses.set(pid, backgroundProcess);
315
+ return backgroundProcess;
316
+ }
317
+ /**
318
+ * Kill all running background processes
319
+ */
320
+ killAllBackgroundProcesses() {
321
+ logger.info(`Killing ${this.backgroundProcesses.size} background processes`);
322
+ for (const process of this.backgroundProcesses.values()) {
323
+ try {
324
+ process.kill();
325
+ }
326
+ catch (error) {
327
+ logger.warn(error, `Failed to kill process ${process.pid}`);
328
+ }
329
+ }
330
+ this.backgroundProcesses.clear();
331
+ }
332
+ /**
333
+ * Validate a command for safety
334
+ */
335
+ validateCommand(command) {
336
+ // Check if command is in the denied list
337
+ for (const pattern of DANGEROUS_COMMANDS) {
338
+ if (pattern.test(command)) {
339
+ throw new Error(`Command execution blocked: '${command}' matches dangerous pattern`);
340
+ }
341
+ }
342
+ // Check if command is in allowed list (if configured)
343
+ if (this.config.execution?.allowedCommands &&
344
+ this.config.execution.allowedCommands.length > 0) {
345
+ const allowed = this.config.execution.allowedCommands.some((allowedPattern) => {
346
+ if (typeof allowedPattern === "string") {
347
+ return command.startsWith(allowedPattern);
348
+ }
349
+ return allowedPattern.test(command);
350
+ });
351
+ if (!allowed) {
352
+ throw new Error(`Command execution blocked: '${command}' is not in the allowed list`);
353
+ }
354
+ }
355
+ }
356
+ /**
357
+ * Set the working directory
358
+ */
359
+ setWorkingDirectory(directory) {
360
+ this.workingDirectory = directory;
361
+ logger.debug(`Working directory set to: ${directory}`);
362
+ }
363
+ /**
364
+ * Get the working directory
365
+ */
366
+ getWorkingDirectory() {
367
+ return this.workingDirectory;
368
+ }
369
+ /**
370
+ * Set an environment variable
371
+ */
372
+ setEnvironmentVariable(name, value) {
373
+ this.environmentVariables[name] = value;
374
+ logger.debug(`Environment variable set: ${name}=${value}`);
375
+ }
376
+ /**
377
+ * Get an environment variable
378
+ */
379
+ getEnvironmentVariable(name) {
380
+ return this.environmentVariables[name];
381
+ }
382
+ }
383
+ /**
384
+ * Initialize the execution environment
385
+ */
386
+ export async function initExecutionEnvironment(config = {}) {
387
+ logger.info("Initializing execution environment");
388
+ try {
389
+ const executionEnv = new ExecutionEnvironment(config);
390
+ await executionEnv.initialize();
391
+ logger.info("Execution environment initialized successfully");
392
+ return executionEnv;
393
+ }
394
+ catch (error) {
395
+ logger.error(error, "Failed to initialize execution environment");
396
+ // Return a minimal execution environment even if initialization failed
397
+ return new ExecutionEnvironment(config);
398
+ }
399
+ }
400
+ // const platformName = process.platform;
401
+ // let cmd: string;
402
+ // let args: string[] = [];
403
+ // const useShellOption = false;
404
+ // if (platformName === "win32") {
405
+ // const { execSync } = await import("node:child_process");
406
+ // try {
407
+ // execSync("where wsl", { stdio: "ignore" });
408
+ // cmd = "wsl.exe";
409
+ // args = ["--", command];
410
+ // } catch {
411
+ // cmd = "powershell.exe";
412
+ // args = ["-NoProfile", "-NonInteractive", "-Command", command];
413
+ // }
414
+ // } else {
415
+ // const shell = process.env["SHELL"] || "/bin/bash";
416
+ // cmd = shell;
417
+ // args = ["-c", command];
418
+ // }
419
+ // Set up cleanup on process exit
420
+ export function setupProcessCleanup(executionEnv) {
421
+ process.on("exit", () => {
422
+ executionEnv.killAllBackgroundProcesses();
423
+ });
424
+ process.on("SIGINT", () => {
425
+ executionEnv.killAllBackgroundProcesses();
426
+ process.exit(0);
427
+ });
428
+ process.on("SIGTERM", () => {
429
+ executionEnv.killAllBackgroundProcesses();
430
+ process.exit(0);
431
+ });
432
+ }
@@ -1,17 +1,6 @@
1
- /**
2
- * Extracts the first code block content from the given text.
3
- * If a Markdown-style triple backtick code block is found, returns its inner content.
4
- * Otherwise, returns the original text unchanged.
5
- *
6
- * @param text - The input string potentially containing a Markdown code block.
7
- * @returns The extracted code inside the first code block, or the original text if no block is found.
8
- */
9
- export declare const extractCodeBlock: (text: string) => string;
10
- export declare function extractXml(text: string, tag: string): string;
11
- export declare function removeAllLineBreaks(text: string): string;
12
- export declare function removeHtmlTags(text: string): string;
13
1
  export type FormatType = "xml" | "markdown" | "bracket";
14
2
  export declare function formatFile(file: string, content: string, format: FormatType): string;
15
3
  export declare function formatUrl(siteUrl: string, content: string, format: FormatType): string;
16
- export declare function formatCodeSnippet(file: string, content: string, format: FormatType): string;
4
+ export declare function formatCodeBlock(file: string, content: string): string;
17
5
  export declare function formatBlock(content: string, blockName: string, format: FormatType): string;
6
+ //# sourceMappingURL=formatting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../source/formatting.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAExD,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,GACjB,MAAM,CAaR;AAED,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,GACjB,MAAM,CAWR;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,UAAU,GACjB,MAAM,CAWR"}
@@ -1,57 +1,8 @@
1
1
  import path from "node:path";
2
- const MD_CODE_BLOCK = /```(?:[\w-]+)?\n(.*?)```/s;
3
- /**
4
- * Extracts the first code block content from the given text.
5
- * If a Markdown-style triple backtick code block is found, returns its inner content.
6
- * Otherwise, returns the original text unchanged.
7
- *
8
- * @param text - The input string potentially containing a Markdown code block.
9
- * @returns The extracted code inside the first code block, or the original text if no block is found.
10
- */
11
- export const extractCodeBlock = (text) => {
12
- const pattern = MD_CODE_BLOCK;
13
- const match = text.match(pattern);
14
- if (match) {
15
- return match[1] ?? "";
16
- }
17
- return text;
18
- };
19
- export function extractXml(text, tag) {
20
- const match = text.match(new RegExp(`<${tag}>(.*?)</${tag}>`, "s"));
21
- return match ? (match[1] ?? "") : "";
22
- }
23
- export function removeAllLineBreaks(text) {
24
- return text.replace(/(\r\n|\n|\r)/gm, " ");
25
- }
26
- export function removeHtmlTags(text) {
27
- return text.replace(/<[^>]*>?/gm, "");
28
- }
2
+ import { getCodeblockFromFilePath } from "./utils/filetype-detection.js";
29
3
  const MD_TRIPLE_QUOTE = "```";
30
- const codeBlockExtensions = {
31
- js: "javascript",
32
- ts: "typescript",
33
- py: "python",
34
- rb: "ruby",
35
- java: "java",
36
- cpp: "cpp",
37
- cs: "csharp",
38
- go: "go",
39
- rs: "rust",
40
- php: "php",
41
- html: "html",
42
- css: "css",
43
- json: "json",
44
- yml: "yaml",
45
- yaml: "yaml",
46
- md: "markdown",
47
- sql: "sql",
48
- sh: "bash",
49
- bash: "bash",
50
- txt: "text",
51
- };
52
4
  export function formatFile(file, content, format) {
53
- const fileExtension = path.extname(file).slice(1);
54
- const codeBlockName = codeBlockExtensions[fileExtension] || fileExtension;
5
+ const codeBlockName = getCodeblockFromFilePath(file) || path.extname(file).slice(1);
55
6
  switch (format) {
56
7
  case "xml":
57
8
  return `<file>\n<name>${file}</name>\n<content>\n${content}\n</content>\n</file>`;
@@ -75,19 +26,9 @@ export function formatUrl(siteUrl, content, format) {
75
26
  throw new Error(`Unsupported format: ${format}`);
76
27
  }
77
28
  }
78
- export function formatCodeSnippet(file, content, format) {
79
- const fileExtension = path.extname(file).slice(1);
80
- const codeBlockName = codeBlockExtensions[fileExtension] || fileExtension;
81
- switch (format) {
82
- case "xml":
83
- return `<code>\n${content}\n</code>`;
84
- case "markdown":
85
- return `${MD_TRIPLE_QUOTE} ${codeBlockName}\n${content}\n${MD_TRIPLE_QUOTE}`;
86
- case "bracket":
87
- return `[code begin]\n${content}\n[code end]`;
88
- default:
89
- throw new Error(`Unsupported format: ${format}`);
90
- }
29
+ export function formatCodeBlock(file, content) {
30
+ const codeBlockName = getCodeblockFromFilePath(file) || path.extname(file).slice(1);
31
+ return `${MD_TRIPLE_QUOTE} ${codeBlockName}\n${content}\n${MD_TRIPLE_QUOTE}`;
91
32
  }
92
33
  export function formatBlock(content, blockName, format) {
93
34
  switch (format) {
package/dist/index.d.ts CHANGED
@@ -17,3 +17,4 @@ declare const flags: {
17
17
  export declare function handleError(error: Error): void;
18
18
  export type Flags = typeof flags;
19
19
  export {};
20
+ //# sourceMappingURL=index.d.ts.map