gitx.do 0.0.3 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/README.md +319 -92
  2. package/dist/cli/commands/add.d.ts +176 -0
  3. package/dist/cli/commands/add.d.ts.map +1 -0
  4. package/dist/cli/commands/add.js +979 -0
  5. package/dist/cli/commands/add.js.map +1 -0
  6. package/dist/cli/commands/blame.d.ts +1 -1
  7. package/dist/cli/commands/blame.d.ts.map +1 -1
  8. package/dist/cli/commands/blame.js +1 -1
  9. package/dist/cli/commands/blame.js.map +1 -1
  10. package/dist/cli/commands/branch.d.ts +1 -1
  11. package/dist/cli/commands/branch.d.ts.map +1 -1
  12. package/dist/cli/commands/branch.js +2 -2
  13. package/dist/cli/commands/branch.js.map +1 -1
  14. package/dist/cli/commands/checkout.d.ts +73 -0
  15. package/dist/cli/commands/checkout.d.ts.map +1 -0
  16. package/dist/cli/commands/checkout.js +725 -0
  17. package/dist/cli/commands/checkout.js.map +1 -0
  18. package/dist/cli/commands/commit.d.ts.map +1 -1
  19. package/dist/cli/commands/commit.js +22 -2
  20. package/dist/cli/commands/commit.js.map +1 -1
  21. package/dist/cli/commands/diff.d.ts +4 -4
  22. package/dist/cli/commands/diff.d.ts.map +1 -1
  23. package/dist/cli/commands/diff.js +9 -8
  24. package/dist/cli/commands/diff.js.map +1 -1
  25. package/dist/cli/commands/log.d.ts +1 -1
  26. package/dist/cli/commands/log.d.ts.map +1 -1
  27. package/dist/cli/commands/log.js +1 -1
  28. package/dist/cli/commands/log.js.map +1 -1
  29. package/dist/cli/commands/merge.d.ts +106 -0
  30. package/dist/cli/commands/merge.d.ts.map +1 -0
  31. package/dist/cli/commands/merge.js +852 -0
  32. package/dist/cli/commands/merge.js.map +1 -0
  33. package/dist/cli/commands/review.d.ts +1 -1
  34. package/dist/cli/commands/review.d.ts.map +1 -1
  35. package/dist/cli/commands/review.js +26 -1
  36. package/dist/cli/commands/review.js.map +1 -1
  37. package/dist/cli/commands/stash.d.ts +157 -0
  38. package/dist/cli/commands/stash.d.ts.map +1 -0
  39. package/dist/cli/commands/stash.js +655 -0
  40. package/dist/cli/commands/stash.js.map +1 -0
  41. package/dist/cli/commands/status.d.ts.map +1 -1
  42. package/dist/cli/commands/status.js +1 -2
  43. package/dist/cli/commands/status.js.map +1 -1
  44. package/dist/cli/commands/web.d.ts.map +1 -1
  45. package/dist/cli/commands/web.js +3 -2
  46. package/dist/cli/commands/web.js.map +1 -1
  47. package/dist/cli/fs-adapter.d.ts.map +1 -1
  48. package/dist/cli/fs-adapter.js +3 -5
  49. package/dist/cli/fs-adapter.js.map +1 -1
  50. package/dist/cli/fsx-cli-adapter.d.ts +359 -0
  51. package/dist/cli/fsx-cli-adapter.d.ts.map +1 -0
  52. package/dist/cli/fsx-cli-adapter.js +619 -0
  53. package/dist/cli/fsx-cli-adapter.js.map +1 -0
  54. package/dist/cli/index.d.ts.map +1 -1
  55. package/dist/cli/index.js +68 -12
  56. package/dist/cli/index.js.map +1 -1
  57. package/dist/cli/ui/components/DiffView.d.ts +7 -2
  58. package/dist/cli/ui/components/DiffView.d.ts.map +1 -1
  59. package/dist/cli/ui/components/DiffView.js.map +1 -1
  60. package/dist/cli/ui/components/ErrorDisplay.d.ts +6 -2
  61. package/dist/cli/ui/components/ErrorDisplay.d.ts.map +1 -1
  62. package/dist/cli/ui/components/ErrorDisplay.js.map +1 -1
  63. package/dist/cli/ui/components/FuzzySearch.d.ts +8 -2
  64. package/dist/cli/ui/components/FuzzySearch.d.ts.map +1 -1
  65. package/dist/cli/ui/components/FuzzySearch.js.map +1 -1
  66. package/dist/cli/ui/components/LoadingSpinner.d.ts +6 -2
  67. package/dist/cli/ui/components/LoadingSpinner.d.ts.map +1 -1
  68. package/dist/cli/ui/components/LoadingSpinner.js.map +1 -1
  69. package/dist/cli/ui/components/NavigationList.d.ts +7 -2
  70. package/dist/cli/ui/components/NavigationList.d.ts.map +1 -1
  71. package/dist/cli/ui/components/NavigationList.js.map +1 -1
  72. package/dist/cli/ui/components/ScrollableContent.d.ts +7 -2
  73. package/dist/cli/ui/components/ScrollableContent.d.ts.map +1 -1
  74. package/dist/cli/ui/components/ScrollableContent.js.map +1 -1
  75. package/dist/cli/ui/terminal-ui.d.ts +42 -9
  76. package/dist/cli/ui/terminal-ui.d.ts.map +1 -1
  77. package/dist/cli/ui/terminal-ui.js.map +1 -1
  78. package/dist/do/BashModule.d.ts +871 -0
  79. package/dist/do/BashModule.d.ts.map +1 -0
  80. package/dist/do/BashModule.js +1143 -0
  81. package/dist/do/BashModule.js.map +1 -0
  82. package/dist/do/FsModule.d.ts +612 -0
  83. package/dist/do/FsModule.d.ts.map +1 -0
  84. package/dist/do/FsModule.js +1120 -0
  85. package/dist/do/FsModule.js.map +1 -0
  86. package/dist/do/GitModule.d.ts +635 -0
  87. package/dist/do/GitModule.d.ts.map +1 -0
  88. package/dist/do/GitModule.js +784 -0
  89. package/dist/do/GitModule.js.map +1 -0
  90. package/dist/do/GitRepoDO.d.ts +281 -0
  91. package/dist/do/GitRepoDO.d.ts.map +1 -0
  92. package/dist/do/GitRepoDO.js +479 -0
  93. package/dist/do/GitRepoDO.js.map +1 -0
  94. package/dist/do/bash-ast.d.ts +246 -0
  95. package/dist/do/bash-ast.d.ts.map +1 -0
  96. package/dist/do/bash-ast.js +888 -0
  97. package/dist/do/bash-ast.js.map +1 -0
  98. package/dist/do/container-executor.d.ts +491 -0
  99. package/dist/do/container-executor.d.ts.map +1 -0
  100. package/dist/do/container-executor.js +731 -0
  101. package/dist/do/container-executor.js.map +1 -0
  102. package/dist/do/index.d.ts +53 -0
  103. package/dist/do/index.d.ts.map +1 -0
  104. package/dist/do/index.js +91 -0
  105. package/dist/do/index.js.map +1 -0
  106. package/dist/do/tiered-storage.d.ts +403 -0
  107. package/dist/do/tiered-storage.d.ts.map +1 -0
  108. package/dist/do/tiered-storage.js +689 -0
  109. package/dist/do/tiered-storage.js.map +1 -0
  110. package/dist/do/withBash.d.ts +231 -0
  111. package/dist/do/withBash.d.ts.map +1 -0
  112. package/dist/do/withBash.js +244 -0
  113. package/dist/do/withBash.js.map +1 -0
  114. package/dist/do/withFs.d.ts +237 -0
  115. package/dist/do/withFs.d.ts.map +1 -0
  116. package/dist/do/withFs.js +387 -0
  117. package/dist/do/withFs.js.map +1 -0
  118. package/dist/do/withGit.d.ts +180 -0
  119. package/dist/do/withGit.d.ts.map +1 -0
  120. package/dist/do/withGit.js +271 -0
  121. package/dist/do/withGit.js.map +1 -0
  122. package/dist/durable-object/object-store.d.ts +157 -15
  123. package/dist/durable-object/object-store.d.ts.map +1 -1
  124. package/dist/durable-object/object-store.js +435 -47
  125. package/dist/durable-object/object-store.js.map +1 -1
  126. package/dist/durable-object/schema.d.ts +12 -1
  127. package/dist/durable-object/schema.d.ts.map +1 -1
  128. package/dist/durable-object/schema.js +87 -2
  129. package/dist/durable-object/schema.js.map +1 -1
  130. package/dist/index.d.ts +84 -1
  131. package/dist/index.d.ts.map +1 -1
  132. package/dist/index.js +34 -0
  133. package/dist/index.js.map +1 -1
  134. package/dist/mcp/sandbox/miniflare-evaluator.d.ts +22 -0
  135. package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +1 -0
  136. package/dist/mcp/sandbox/miniflare-evaluator.js +140 -0
  137. package/dist/mcp/sandbox/miniflare-evaluator.js.map +1 -0
  138. package/dist/mcp/sandbox/object-store-proxy.d.ts +32 -0
  139. package/dist/mcp/sandbox/object-store-proxy.d.ts.map +1 -0
  140. package/dist/mcp/sandbox/object-store-proxy.js +30 -0
  141. package/dist/mcp/sandbox/object-store-proxy.js.map +1 -0
  142. package/dist/mcp/sandbox/template.d.ts +17 -0
  143. package/dist/mcp/sandbox/template.d.ts.map +1 -0
  144. package/dist/mcp/sandbox/template.js +71 -0
  145. package/dist/mcp/sandbox/template.js.map +1 -0
  146. package/dist/mcp/sandbox.d.ts.map +1 -1
  147. package/dist/mcp/sandbox.js +16 -4
  148. package/dist/mcp/sandbox.js.map +1 -1
  149. package/dist/mcp/tools/do.d.ts +32 -0
  150. package/dist/mcp/tools/do.d.ts.map +1 -0
  151. package/dist/mcp/tools/do.js +117 -0
  152. package/dist/mcp/tools/do.js.map +1 -0
  153. package/dist/mcp/tools.d.ts.map +1 -1
  154. package/dist/mcp/tools.js +1258 -22
  155. package/dist/mcp/tools.js.map +1 -1
  156. package/dist/pack/delta.d.ts +8 -0
  157. package/dist/pack/delta.d.ts.map +1 -1
  158. package/dist/pack/delta.js +241 -30
  159. package/dist/pack/delta.js.map +1 -1
  160. package/dist/refs/branch.d.ts +38 -25
  161. package/dist/refs/branch.d.ts.map +1 -1
  162. package/dist/refs/branch.js +421 -94
  163. package/dist/refs/branch.js.map +1 -1
  164. package/dist/refs/storage.d.ts +77 -5
  165. package/dist/refs/storage.d.ts.map +1 -1
  166. package/dist/refs/storage.js +193 -43
  167. package/dist/refs/storage.js.map +1 -1
  168. package/dist/refs/tag.d.ts +44 -24
  169. package/dist/refs/tag.d.ts.map +1 -1
  170. package/dist/refs/tag.js +411 -70
  171. package/dist/refs/tag.js.map +1 -1
  172. package/dist/storage/backend.d.ts +425 -0
  173. package/dist/storage/backend.d.ts.map +1 -0
  174. package/dist/storage/backend.js +41 -0
  175. package/dist/storage/backend.js.map +1 -0
  176. package/dist/storage/fsx-adapter.d.ts +204 -0
  177. package/dist/storage/fsx-adapter.d.ts.map +1 -0
  178. package/dist/storage/fsx-adapter.js +518 -0
  179. package/dist/storage/fsx-adapter.js.map +1 -0
  180. package/dist/storage/r2-pack.d.ts.map +1 -1
  181. package/dist/storage/r2-pack.js +4 -1
  182. package/dist/storage/r2-pack.js.map +1 -1
  183. package/dist/tiered/cdc-pipeline.js +3 -3
  184. package/dist/tiered/cdc-pipeline.js.map +1 -1
  185. package/dist/tiered/migration.d.ts.map +1 -1
  186. package/dist/tiered/migration.js +4 -1
  187. package/dist/tiered/migration.js.map +1 -1
  188. package/dist/types/capability.d.ts +1385 -0
  189. package/dist/types/capability.d.ts.map +1 -0
  190. package/dist/types/capability.js +36 -0
  191. package/dist/types/capability.js.map +1 -0
  192. package/dist/types/index.d.ts +13 -0
  193. package/dist/types/index.d.ts.map +1 -0
  194. package/dist/types/index.js +18 -0
  195. package/dist/types/index.js.map +1 -0
  196. package/dist/types/interfaces.d.ts +673 -0
  197. package/dist/types/interfaces.d.ts.map +1 -0
  198. package/dist/types/interfaces.js +26 -0
  199. package/dist/types/interfaces.js.map +1 -0
  200. package/dist/types/objects.d.ts +182 -0
  201. package/dist/types/objects.d.ts.map +1 -1
  202. package/dist/types/objects.js +249 -4
  203. package/dist/types/objects.js.map +1 -1
  204. package/dist/types/storage.d.ts +114 -0
  205. package/dist/types/storage.d.ts.map +1 -1
  206. package/dist/types/storage.js +160 -1
  207. package/dist/types/storage.js.map +1 -1
  208. package/dist/types/worker-loader.d.ts +60 -0
  209. package/dist/types/worker-loader.d.ts.map +1 -0
  210. package/dist/types/worker-loader.js +62 -0
  211. package/dist/types/worker-loader.js.map +1 -0
  212. package/dist/utils/hash.d.ts +126 -80
  213. package/dist/utils/hash.d.ts.map +1 -1
  214. package/dist/utils/hash.js +191 -100
  215. package/dist/utils/hash.js.map +1 -1
  216. package/dist/utils/sha1.d.ts +206 -0
  217. package/dist/utils/sha1.d.ts.map +1 -1
  218. package/dist/utils/sha1.js +405 -0
  219. package/dist/utils/sha1.js.map +1 -1
  220. package/dist/wire/path-security.d.ts +157 -0
  221. package/dist/wire/path-security.d.ts.map +1 -0
  222. package/dist/wire/path-security.js +307 -0
  223. package/dist/wire/path-security.js.map +1 -0
  224. package/dist/wire/receive-pack.d.ts +7 -0
  225. package/dist/wire/receive-pack.d.ts.map +1 -1
  226. package/dist/wire/receive-pack.js +29 -1
  227. package/dist/wire/receive-pack.js.map +1 -1
  228. package/dist/wire/upload-pack.d.ts.map +1 -1
  229. package/dist/wire/upload-pack.js +4 -1
  230. package/dist/wire/upload-pack.js.map +1 -1
  231. package/package.json +10 -1
@@ -0,0 +1,871 @@
1
+ /**
2
+ * @fileoverview BashModule for Durable Object Integration
3
+ *
4
+ * This module provides a BashModule class that integrates with dotdo's $ WorkflowContext,
5
+ * providing $.bash.exec(), $.bash.run(), and bash execution functionality.
6
+ *
7
+ * The module depends on FsModule for file system operations during command execution,
8
+ * enabling sandboxed bash operations within the DO's virtual filesystem.
9
+ *
10
+ * Features:
11
+ * - AST-based safety analysis for command parsing
12
+ * - Configurable command blocking and confirmation requirements
13
+ * - Support for database-backed execution policies
14
+ *
15
+ * @module do/BashModule
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { BashModule } from 'gitx.do/do'
20
+ *
21
+ * class MyDO extends DO {
22
+ * bash = new BashModule({
23
+ * executor: myExecutor,
24
+ * fs: this.$.fs
25
+ * })
26
+ *
27
+ * async buildProject() {
28
+ * const result = await this.bash.exec('npm', ['run', 'build'])
29
+ * if (result.exitCode !== 0) {
30
+ * throw new Error(`Build failed: ${result.stderr}`)
31
+ * }
32
+ * }
33
+ * }
34
+ * ```
35
+ */
36
+ import { type SafetyIssue } from './bash-ast';
37
+ /**
38
+ * Filesystem capability interface that BashModule depends on.
39
+ * Mirrors the FsCapability from dotdo's WorkflowContext.
40
+ */
41
+ export interface FsCapability {
42
+ readFile(path: string): Promise<string | Buffer>;
43
+ writeFile(path: string, content: string | Buffer): Promise<void>;
44
+ readDir(path: string): Promise<string[]>;
45
+ exists(path: string): Promise<boolean>;
46
+ mkdir(path: string, options?: {
47
+ recursive?: boolean;
48
+ }): Promise<void>;
49
+ rm(path: string, options?: {
50
+ recursive?: boolean;
51
+ force?: boolean;
52
+ }): Promise<void>;
53
+ }
54
+ /**
55
+ * Result of a bash command execution.
56
+ */
57
+ export interface BashResult {
58
+ /**
59
+ * The original command that was executed.
60
+ */
61
+ command: string;
62
+ /**
63
+ * Standard output from the command.
64
+ */
65
+ stdout: string;
66
+ /**
67
+ * Standard error from the command.
68
+ */
69
+ stderr: string;
70
+ /**
71
+ * Exit code of the command. 0 typically indicates success.
72
+ */
73
+ exitCode: number;
74
+ /**
75
+ * Whether the command was blocked due to safety concerns.
76
+ */
77
+ blocked?: boolean;
78
+ /**
79
+ * Reason the command was blocked, if applicable.
80
+ */
81
+ blockReason?: string;
82
+ }
83
+ /**
84
+ * Options for executing bash commands.
85
+ */
86
+ export interface ExecOptions {
87
+ /**
88
+ * Maximum execution time in milliseconds.
89
+ * @default 30000
90
+ */
91
+ timeout?: number;
92
+ /**
93
+ * Working directory for command execution.
94
+ */
95
+ cwd?: string;
96
+ /**
97
+ * Environment variables to set for the command.
98
+ */
99
+ env?: Record<string, string>;
100
+ /**
101
+ * Confirm execution of dangerous commands.
102
+ * @default false
103
+ */
104
+ confirm?: boolean;
105
+ /**
106
+ * Run in dry-run mode - analyze without executing.
107
+ * @default false
108
+ */
109
+ dryRun?: boolean;
110
+ /**
111
+ * Provide stdin input for the command.
112
+ */
113
+ stdin?: string;
114
+ }
115
+ /**
116
+ * Options for streaming command execution.
117
+ */
118
+ export interface SpawnOptions extends ExecOptions {
119
+ /**
120
+ * Callback for stdout data chunks.
121
+ */
122
+ onStdout?: (chunk: string) => void;
123
+ /**
124
+ * Callback for stderr data chunks.
125
+ */
126
+ onStderr?: (chunk: string) => void;
127
+ /**
128
+ * Callback when the process exits.
129
+ */
130
+ onExit?: (exitCode: number) => void;
131
+ }
132
+ /**
133
+ * Handle for a spawned process.
134
+ */
135
+ export interface SpawnHandle {
136
+ /**
137
+ * Process ID of the spawned process.
138
+ */
139
+ pid: number;
140
+ /**
141
+ * Promise that resolves when the process exits.
142
+ */
143
+ done: Promise<BashResult>;
144
+ /**
145
+ * Kill the spawned process.
146
+ */
147
+ kill(signal?: 'SIGTERM' | 'SIGKILL' | 'SIGINT'): void;
148
+ /**
149
+ * Write to the process stdin.
150
+ */
151
+ write(data: string): void;
152
+ /**
153
+ * Close stdin to signal end of input.
154
+ */
155
+ closeStdin(): void;
156
+ }
157
+ /**
158
+ * Interface for external command executors.
159
+ * BashModule delegates actual command execution to an executor.
160
+ */
161
+ export interface BashExecutor {
162
+ /**
163
+ * Execute a command and return the result.
164
+ */
165
+ execute(command: string, options?: ExecOptions): Promise<BashResult>;
166
+ /**
167
+ * Spawn a command for streaming execution (optional).
168
+ */
169
+ spawn?(command: string, args?: string[], options?: SpawnOptions): Promise<SpawnHandle>;
170
+ }
171
+ /**
172
+ * Database storage interface for BashModule persistence.
173
+ * Provides access to the exec table for safety settings and policies.
174
+ */
175
+ export interface BashStorage {
176
+ /**
177
+ * SQL execution interface.
178
+ */
179
+ sql: {
180
+ /**
181
+ * Execute a SQL query with optional parameters.
182
+ * @param query - SQL query string (can use ? placeholders)
183
+ * @param params - Parameter values for placeholders
184
+ * @returns Result object with toArray() method for reading rows
185
+ */
186
+ exec(query: string, ...params: unknown[]): {
187
+ toArray(): unknown[];
188
+ };
189
+ };
190
+ }
191
+ /**
192
+ * Row structure for the exec table.
193
+ * Represents an execution policy with safety settings.
194
+ */
195
+ export interface ExecRow {
196
+ id: number;
197
+ name: string;
198
+ blocked_commands: string | null;
199
+ require_confirmation: number;
200
+ default_timeout: number;
201
+ default_cwd: string;
202
+ allowed_patterns: string | null;
203
+ denied_patterns: string | null;
204
+ max_concurrent: number;
205
+ enabled: number;
206
+ created_at: number | null;
207
+ updated_at: number | null;
208
+ }
209
+ /**
210
+ * Execution policy configuration.
211
+ * Used to define and persist execution safety settings.
212
+ */
213
+ export interface ExecPolicy {
214
+ /**
215
+ * Unique name for this policy.
216
+ */
217
+ name: string;
218
+ /**
219
+ * List of commands that are blocked from execution.
220
+ */
221
+ blockedCommands: string[];
222
+ /**
223
+ * Whether to require confirmation for dangerous commands.
224
+ * @default true
225
+ */
226
+ requireConfirmation: boolean;
227
+ /**
228
+ * Default timeout for commands in milliseconds.
229
+ * @default 30000
230
+ */
231
+ defaultTimeout: number;
232
+ /**
233
+ * Default working directory for commands.
234
+ * @default '/'
235
+ */
236
+ defaultCwd: string;
237
+ /**
238
+ * Regex patterns for allowed commands.
239
+ * If specified, only matching commands are allowed.
240
+ */
241
+ allowedPatterns?: string[];
242
+ /**
243
+ * Regex patterns for denied commands.
244
+ * Matching commands are blocked regardless of other settings.
245
+ */
246
+ deniedPatterns?: string[];
247
+ /**
248
+ * Maximum number of concurrent executions.
249
+ * @default 5
250
+ */
251
+ maxConcurrent: number;
252
+ /**
253
+ * Whether this policy is enabled.
254
+ * @default true
255
+ */
256
+ enabled: boolean;
257
+ }
258
+ /**
259
+ * Configuration options for BashModule.
260
+ */
261
+ export interface BashModuleOptions {
262
+ /**
263
+ * The executor to use for running commands.
264
+ * Required for actual command execution.
265
+ */
266
+ executor?: BashExecutor;
267
+ /**
268
+ * Filesystem capability for file operations.
269
+ * Used for cwd management and file-based command I/O.
270
+ */
271
+ fs?: FsCapability;
272
+ /**
273
+ * Default working directory for commands.
274
+ * @default '/'
275
+ */
276
+ cwd?: string;
277
+ /**
278
+ * Default timeout for commands in milliseconds.
279
+ * @default 30000
280
+ */
281
+ defaultTimeout?: number;
282
+ /**
283
+ * List of commands that are blocked from execution.
284
+ */
285
+ blockedCommands?: string[];
286
+ /**
287
+ * Whether to require confirmation for dangerous commands.
288
+ * @default true
289
+ */
290
+ requireConfirmation?: boolean;
291
+ /**
292
+ * Database storage for persistent settings.
293
+ * When provided, BashModule will persist settings to the exec table.
294
+ */
295
+ storage?: BashStorage;
296
+ /**
297
+ * Policy name to use when persisting settings.
298
+ * @default 'default'
299
+ */
300
+ policyName?: string;
301
+ /**
302
+ * Whether to use AST-based safety analysis.
303
+ * When true, commands are parsed into an AST for more accurate safety analysis.
304
+ * @default true
305
+ */
306
+ useAST?: boolean;
307
+ }
308
+ /**
309
+ * Safety level classification for commands.
310
+ * - 'safe': Command can be executed without confirmation
311
+ * - 'dangerous': Command requires confirmation but can be executed with confirm flag
312
+ * - 'critical': Command is ALWAYS blocked regardless of confirmation
313
+ */
314
+ export type SafetyLevel = 'safe' | 'dangerous' | 'critical';
315
+ /**
316
+ * Safety analysis result for a command.
317
+ */
318
+ export interface SafetyAnalysis {
319
+ /**
320
+ * Whether the command is considered dangerous.
321
+ */
322
+ dangerous: boolean;
323
+ /**
324
+ * Safety level classification.
325
+ * - 'safe': Can execute without confirmation
326
+ * - 'dangerous': Requires confirmation (confirm flag allows execution)
327
+ * - 'critical': Always blocked, cannot be executed even with confirmation
328
+ */
329
+ safetyLevel?: SafetyLevel;
330
+ /**
331
+ * Reason for the classification.
332
+ */
333
+ reason?: string;
334
+ /**
335
+ * Commands identified in the input.
336
+ */
337
+ commands: string[];
338
+ /**
339
+ * Impact level of the command.
340
+ */
341
+ impact: 'none' | 'low' | 'medium' | 'high' | 'critical';
342
+ /**
343
+ * Detailed issues found during AST analysis.
344
+ * Only populated when useAST option is true.
345
+ */
346
+ issues?: SafetyIssue[];
347
+ /**
348
+ * Whether AST-based analysis was used.
349
+ */
350
+ usedAST?: boolean;
351
+ }
352
+ /**
353
+ * BashModule class for integration with dotdo's $ WorkflowContext.
354
+ *
355
+ * @description
356
+ * Provides bash execution functionality as a capability module that integrates
357
+ * with dotdo's Durable Object framework. The module:
358
+ *
359
+ * - Depends on FsModule for file system operations during execution
360
+ * - Delegates actual command execution to a configurable executor
361
+ * - Provides safety analysis and command blocking
362
+ * - Supports both exec (wait for completion) and spawn (streaming) modes
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * // In a Durable Object
367
+ * class MyDO extends DO {
368
+ * private bash: BashModule
369
+ *
370
+ * constructor(state: DurableObjectState, env: Env) {
371
+ * super(state, env)
372
+ * this.bash = new BashModule({
373
+ * executor: containerExecutor,
374
+ * fs: this.$.fs,
375
+ * cwd: '/app'
376
+ * })
377
+ * }
378
+ *
379
+ * async fetch(request: Request) {
380
+ * // Execute a command
381
+ * const result = await this.bash.exec('npm', ['install'])
382
+ *
383
+ * // Run a script
384
+ * await this.bash.run(`
385
+ * set -e
386
+ * npm run build
387
+ * npm run test
388
+ * `)
389
+ *
390
+ * return new Response('OK')
391
+ * }
392
+ * }
393
+ * ```
394
+ */
395
+ export declare class BashModule {
396
+ /**
397
+ * Capability module name for identification.
398
+ */
399
+ readonly name: "bash";
400
+ /**
401
+ * The executor used for running commands.
402
+ */
403
+ private readonly executor?;
404
+ /**
405
+ * Filesystem capability for file operations.
406
+ */
407
+ private readonly fs?;
408
+ /**
409
+ * Default working directory.
410
+ */
411
+ private defaultCwd;
412
+ /**
413
+ * Default timeout in milliseconds.
414
+ */
415
+ private defaultTimeout;
416
+ /**
417
+ * List of blocked commands.
418
+ */
419
+ private blockedCommands;
420
+ /**
421
+ * Whether to require confirmation for dangerous commands.
422
+ */
423
+ private requireConfirmation;
424
+ /**
425
+ * Database storage for persistence.
426
+ */
427
+ private readonly storage?;
428
+ /**
429
+ * Policy name for database operations.
430
+ */
431
+ private readonly policyName;
432
+ /**
433
+ * Database row ID for this policy.
434
+ */
435
+ private policyId?;
436
+ /**
437
+ * Allowed command patterns (regex).
438
+ */
439
+ private allowedPatterns;
440
+ /**
441
+ * Denied command patterns (regex).
442
+ */
443
+ private deniedPatterns;
444
+ /**
445
+ * Maximum concurrent executions.
446
+ */
447
+ private maxConcurrent;
448
+ /**
449
+ * Whether the policy is enabled.
450
+ */
451
+ private enabled;
452
+ /**
453
+ * Whether to use AST-based safety analysis.
454
+ */
455
+ private readonly useAST;
456
+ /**
457
+ * Commands considered dangerous and requiring confirmation.
458
+ */
459
+ private static readonly DANGEROUS_COMMANDS;
460
+ /**
461
+ * Critical patterns that should ALWAYS be blocked, regardless of confirmation.
462
+ * These patterns represent commands that could cause catastrophic, irreversible damage.
463
+ */
464
+ private static readonly CRITICAL_PATTERNS;
465
+ /**
466
+ * Dangerous flag patterns (require confirmation but can be executed with confirm).
467
+ */
468
+ private static readonly DANGEROUS_PATTERNS;
469
+ /**
470
+ * Create a new BashModule instance.
471
+ *
472
+ * @param options - Configuration options
473
+ *
474
+ * @example
475
+ * ```typescript
476
+ * const bash = new BashModule({
477
+ * executor: containerExecutor,
478
+ * fs: workflowContext.fs,
479
+ * cwd: '/app'
480
+ * })
481
+ * ```
482
+ */
483
+ constructor(options?: BashModuleOptions);
484
+ /**
485
+ * Optional initialization hook.
486
+ * Called when the module is first loaded.
487
+ * When storage is provided, loads or creates the execution policy from the database.
488
+ */
489
+ initialize(): Promise<void>;
490
+ /**
491
+ * Load settings from a database row.
492
+ */
493
+ private loadFromRow;
494
+ /**
495
+ * Persist current policy settings to the database.
496
+ */
497
+ private persistPolicy;
498
+ /**
499
+ * Optional cleanup hook.
500
+ * Called when the capability is unloaded.
501
+ */
502
+ dispose(): Promise<void>;
503
+ /**
504
+ * Check if FsCapability is available.
505
+ *
506
+ * @returns True if FsCapability is configured
507
+ */
508
+ get hasFsCapability(): boolean;
509
+ /**
510
+ * Check if an executor is available.
511
+ *
512
+ * @returns True if an executor is configured
513
+ */
514
+ get hasExecutor(): boolean;
515
+ /**
516
+ * Execute a command and wait for completion.
517
+ *
518
+ * @param command - The command to execute (e.g., 'git', 'npm', 'ls')
519
+ * @param args - Optional array of command arguments
520
+ * @param options - Optional execution options
521
+ * @returns Promise resolving to the execution result
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * // Simple command
526
+ * const result = await bash.exec('ls')
527
+ *
528
+ * // With arguments
529
+ * const result = await bash.exec('git', ['status', '--short'])
530
+ *
531
+ * // With options
532
+ * const result = await bash.exec('npm', ['install'], {
533
+ * cwd: '/app',
534
+ * timeout: 60000
535
+ * })
536
+ * ```
537
+ */
538
+ exec(command: string, args?: string[], options?: ExecOptions): Promise<BashResult>;
539
+ /**
540
+ * Spawn a command for streaming execution.
541
+ *
542
+ * @param command - The command to spawn
543
+ * @param args - Optional array of command arguments
544
+ * @param options - Optional spawn options including stream callbacks
545
+ * @returns Promise resolving to a spawn handle
546
+ *
547
+ * @example
548
+ * ```typescript
549
+ * const handle = await bash.spawn('tail', ['-f', '/var/log/app.log'], {
550
+ * onStdout: (chunk) => console.log(chunk),
551
+ * onStderr: (chunk) => console.error(chunk)
552
+ * })
553
+ *
554
+ * // Later, stop the process
555
+ * handle.kill()
556
+ *
557
+ * // Wait for it to finish
558
+ * const result = await handle.done
559
+ * ```
560
+ */
561
+ spawn(command: string, args?: string[], options?: SpawnOptions): Promise<SpawnHandle>;
562
+ /**
563
+ * Run a shell script.
564
+ *
565
+ * @param script - The bash script to execute
566
+ * @param options - Optional execution options
567
+ * @returns Promise resolving to the execution result
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * const result = await bash.run(`
572
+ * set -e
573
+ * cd /app
574
+ * npm install
575
+ * npm run build
576
+ * `)
577
+ * ```
578
+ */
579
+ run(script: string, options?: ExecOptions): Promise<BashResult>;
580
+ /**
581
+ * Analyze a command for safety.
582
+ *
583
+ * Uses AST-based analysis by default for more accurate command parsing
584
+ * and safety classification. Falls back to regex-based analysis if
585
+ * useAST is disabled.
586
+ *
587
+ * @param input - The command or script to analyze
588
+ * @returns Safety analysis result
589
+ *
590
+ * @example
591
+ * ```typescript
592
+ * const analysis = bash.analyze('rm -rf /')
593
+ * if (analysis.dangerous) {
594
+ * console.warn(analysis.reason)
595
+ * }
596
+ * ```
597
+ */
598
+ analyze(input: string): SafetyAnalysis;
599
+ /**
600
+ * Analyze a command using AST-based parsing.
601
+ *
602
+ * Parses the command into an AST and inspects nodes for safety issues.
603
+ * This provides more accurate analysis than regex patterns because it
604
+ * understands command structure, arguments, and pipelines.
605
+ *
606
+ * @param input - The command or script to analyze
607
+ * @returns Safety analysis result with AST details
608
+ * @internal
609
+ */
610
+ private analyzeWithAST;
611
+ /**
612
+ * Analyze a command using regex patterns.
613
+ *
614
+ * This is the fallback analysis method when AST parsing is disabled
615
+ * or fails. It uses simple pattern matching.
616
+ *
617
+ * @param input - The command or script to analyze
618
+ * @returns Safety analysis result
619
+ * @internal
620
+ */
621
+ private analyzeWithRegex;
622
+ /**
623
+ * Check if a command is dangerous.
624
+ *
625
+ * @param input - The command to check
626
+ * @returns Object indicating if dangerous and why
627
+ *
628
+ * @example
629
+ * ```typescript
630
+ * const check = bash.isDangerous('rm -rf /')
631
+ * if (check.dangerous) {
632
+ * console.warn(check.reason)
633
+ * }
634
+ * ```
635
+ */
636
+ isDangerous(input: string): {
637
+ dangerous: boolean;
638
+ reason?: string;
639
+ };
640
+ /**
641
+ * Add a command to the blocked list.
642
+ * Persists the change to the database if storage is configured.
643
+ *
644
+ * @param command - Command to block
645
+ */
646
+ block(command: string): void;
647
+ /**
648
+ * Remove a command from the blocked list.
649
+ * Persists the change to the database if storage is configured.
650
+ *
651
+ * @param command - Command to unblock
652
+ */
653
+ unblock(command: string): void;
654
+ /**
655
+ * Get the list of blocked commands.
656
+ *
657
+ * @returns Array of blocked command names
658
+ */
659
+ getBlockedCommands(): string[];
660
+ /**
661
+ * Get the current execution policy.
662
+ *
663
+ * @returns Current policy configuration
664
+ */
665
+ getPolicy(): ExecPolicy;
666
+ /**
667
+ * Update the execution policy.
668
+ * Persists the changes to the database if storage is configured.
669
+ *
670
+ * @param policy - Partial policy configuration to update
671
+ */
672
+ updatePolicy(policy: Partial<Omit<ExecPolicy, 'name'>>): Promise<void>;
673
+ /**
674
+ * Check if the policy is enabled.
675
+ *
676
+ * @returns True if the policy is enabled
677
+ */
678
+ isEnabled(): boolean;
679
+ /**
680
+ * Check if database storage is available.
681
+ *
682
+ * @returns True if storage is configured
683
+ */
684
+ hasStorage(): boolean;
685
+ /**
686
+ * Extract the base command name from a command string.
687
+ */
688
+ private extractBaseCommand;
689
+ /**
690
+ * Extract all command names from a script.
691
+ */
692
+ private extractCommands;
693
+ /**
694
+ * Escape an argument for safe shell use.
695
+ */
696
+ private escapeArg;
697
+ /**
698
+ * Tagged template literal for safe bash command execution.
699
+ *
700
+ * This method allows using template literal syntax for bash commands with
701
+ * automatic variable interpolation and escaping. Variables are safely
702
+ * escaped to prevent shell injection attacks.
703
+ *
704
+ * @param strings - Template literal string parts
705
+ * @param values - Interpolated values
706
+ * @returns Promise resolving to the execution result
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * // Simple usage
711
+ * const result = await this.$.bash`ls -la`
712
+ *
713
+ * // With interpolation
714
+ * const dir = '/tmp/my folder'
715
+ * const result = await this.$.bash`ls -la ${dir}`
716
+ *
717
+ * // With multiple variables
718
+ * const src = 'file.txt'
719
+ * const dest = 'backup/file.txt'
720
+ * const result = await this.$.bash`cp ${src} ${dest}`
721
+ * ```
722
+ */
723
+ tag(strings: TemplateStringsArray, ...values: unknown[]): Promise<BashResult>;
724
+ /**
725
+ * Build a command string from template literal parts with safe escaping.
726
+ *
727
+ * @param strings - Template literal string parts
728
+ * @param values - Interpolated values
729
+ * @returns The constructed command string with escaped values
730
+ * @internal
731
+ */
732
+ private buildCommandFromTemplate;
733
+ /**
734
+ * Escape a template literal value for safe shell interpolation.
735
+ *
736
+ * Handles various types of values:
737
+ * - null/undefined: empty string
738
+ * - string: escaped with single quotes if needed
739
+ * - number/boolean: converted to string directly
740
+ * - array: each element escaped and joined with spaces
741
+ * - object: JSON stringified and escaped
742
+ *
743
+ * @param value - The value to escape
744
+ * @returns The escaped string representation
745
+ * @internal
746
+ */
747
+ private escapeTemplateValue;
748
+ /**
749
+ * Escape a string for safe shell use.
750
+ *
751
+ * Uses single-quote escaping which is the safest form of escaping
752
+ * for bash. Single quotes prevent all special character interpretation
753
+ * except for the single quote itself.
754
+ *
755
+ * @param str - The string to escape
756
+ * @returns The escaped string
757
+ * @internal
758
+ */
759
+ private escapeShellString;
760
+ }
761
+ /**
762
+ * Create a BashModule instance with the given options.
763
+ *
764
+ * @param options - Configuration options for the module
765
+ * @returns A new BashModule instance
766
+ *
767
+ * @example
768
+ * ```typescript
769
+ * import { createBashModule } from 'gitx.do/do'
770
+ *
771
+ * const bash = createBashModule({
772
+ * executor: containerExecutor,
773
+ * fs: workflowContext.fs,
774
+ * cwd: '/app'
775
+ * })
776
+ * ```
777
+ */
778
+ export declare function createBashModule(options?: BashModuleOptions): BashModule;
779
+ /**
780
+ * Tagged template function signature for bash commands.
781
+ *
782
+ * @example
783
+ * ```typescript
784
+ * const result = await bash`ls -la ${dir}`
785
+ * ```
786
+ */
787
+ export interface BashTagFunction {
788
+ (strings: TemplateStringsArray, ...values: unknown[]): Promise<BashResult>;
789
+ }
790
+ /**
791
+ * A BashModule that can also be called directly as a tagged template literal.
792
+ *
793
+ * This type represents a BashModule instance that has been wrapped with
794
+ * a Proxy to enable both direct method calls and tagged template syntax.
795
+ *
796
+ * @example
797
+ * ```typescript
798
+ * // Create a callable bash module
799
+ * const bash = createCallableBashModule({ executor })
800
+ *
801
+ * // Use as tagged template
802
+ * const result = await bash`ls -la ${dir}`
803
+ *
804
+ * // Use as regular module
805
+ * const result2 = await bash.exec('git', ['status'])
806
+ * ```
807
+ */
808
+ export type CallableBashModule = BashModule & BashTagFunction;
809
+ /**
810
+ * Create a callable BashModule instance that supports tagged template literals.
811
+ *
812
+ * This factory creates a BashModule wrapped in a Proxy that allows both:
813
+ * - Standard method calls: `bash.exec('ls', ['-la'])`
814
+ * - Tagged template syntax: `bash\`ls -la ${dir}\``
815
+ *
816
+ * The tagged template syntax automatically escapes interpolated values
817
+ * to prevent shell injection attacks.
818
+ *
819
+ * @param options - Configuration options for the module
820
+ * @returns A callable BashModule instance
821
+ *
822
+ * @example
823
+ * ```typescript
824
+ * import { createCallableBashModule } from 'gitx.do/do'
825
+ *
826
+ * // In a Durable Object
827
+ * class MyDO extends DO {
828
+ * bash = createCallableBashModule({
829
+ * executor: containerExecutor,
830
+ * fs: this.$.fs,
831
+ * cwd: '/app'
832
+ * })
833
+ *
834
+ * async listFiles(dir: string) {
835
+ * // Use tagged template syntax
836
+ * const result = await this.bash`ls -la ${dir}`
837
+ * return result.stdout
838
+ * }
839
+ *
840
+ * async runWithArgs() {
841
+ * // Or use regular methods
842
+ * const result = await this.bash.exec('npm', ['install'])
843
+ * return result
844
+ * }
845
+ * }
846
+ * ```
847
+ *
848
+ * @example
849
+ * ```typescript
850
+ * // Handle special characters safely
851
+ * const filename = "file with 'quotes' and spaces"
852
+ * const result = await bash`cat ${filename}`
853
+ * // Executes: cat 'file with '\''quotes'\'' and spaces'
854
+ * ```
855
+ */
856
+ export declare function createCallableBashModule(options?: BashModuleOptions): CallableBashModule;
857
+ /**
858
+ * Check if a value is a BashModule instance.
859
+ *
860
+ * @param value - Value to check
861
+ * @returns True if value is a BashModule
862
+ */
863
+ export declare function isBashModule(value: unknown): value is BashModule;
864
+ /**
865
+ * Check if a value is a CallableBashModule.
866
+ *
867
+ * @param value - Value to check
868
+ * @returns True if value is a CallableBashModule
869
+ */
870
+ export declare function isCallableBashModule(value: unknown): value is CallableBashModule;
871
+ //# sourceMappingURL=BashModule.d.ts.map