@zds-ai/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +497 -0
  3. package/dist/agent/grok-agent.d.ts +250 -0
  4. package/dist/agent/grok-agent.js +2480 -0
  5. package/dist/agent/grok-agent.js.map +1 -0
  6. package/dist/agent/index.d.ts +14 -0
  7. package/dist/agent/index.js +136 -0
  8. package/dist/agent/index.js.map +1 -0
  9. package/dist/commands/mcp.d.ts +2 -0
  10. package/dist/commands/mcp.js +239 -0
  11. package/dist/commands/mcp.js.map +1 -0
  12. package/dist/grok/client.d.ts +55 -0
  13. package/dist/grok/client.js +276 -0
  14. package/dist/grok/client.js.map +1 -0
  15. package/dist/grok/tools.d.ts +8 -0
  16. package/dist/grok/tools.js +878 -0
  17. package/dist/grok/tools.js.map +1 -0
  18. package/dist/hooks/use-enhanced-input.d.ts +38 -0
  19. package/dist/hooks/use-enhanced-input.js +228 -0
  20. package/dist/hooks/use-enhanced-input.js.map +1 -0
  21. package/dist/hooks/use-input-handler.d.ts +36 -0
  22. package/dist/hooks/use-input-handler.js +1099 -0
  23. package/dist/hooks/use-input-handler.js.map +1 -0
  24. package/dist/hooks/use-input-history.d.ts +9 -0
  25. package/dist/hooks/use-input-history.js +61 -0
  26. package/dist/hooks/use-input-history.js.map +1 -0
  27. package/dist/index.d.ts +2 -0
  28. package/dist/index.js +869 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/mcp/client.d.ts +41 -0
  31. package/dist/mcp/client.js +224 -0
  32. package/dist/mcp/client.js.map +1 -0
  33. package/dist/mcp/config.d.ts +13 -0
  34. package/dist/mcp/config.js +56 -0
  35. package/dist/mcp/config.js.map +1 -0
  36. package/dist/mcp/transports.d.ts +53 -0
  37. package/dist/mcp/transports.js +256 -0
  38. package/dist/mcp/transports.js.map +1 -0
  39. package/dist/tools/character-tool.d.ts +27 -0
  40. package/dist/tools/character-tool.js +194 -0
  41. package/dist/tools/character-tool.js.map +1 -0
  42. package/dist/tools/clear-cache-tool.d.ts +14 -0
  43. package/dist/tools/clear-cache-tool.js +82 -0
  44. package/dist/tools/clear-cache-tool.js.map +1 -0
  45. package/dist/tools/confirmation-tool.d.ts +16 -0
  46. package/dist/tools/confirmation-tool.js +72 -0
  47. package/dist/tools/confirmation-tool.js.map +1 -0
  48. package/dist/tools/env-tool.d.ts +17 -0
  49. package/dist/tools/env-tool.js +89 -0
  50. package/dist/tools/env-tool.js.map +1 -0
  51. package/dist/tools/file-conversion-tool.d.ts +16 -0
  52. package/dist/tools/file-conversion-tool.js +181 -0
  53. package/dist/tools/file-conversion-tool.js.map +1 -0
  54. package/dist/tools/image-tool.d.ts +22 -0
  55. package/dist/tools/image-tool.js +268 -0
  56. package/dist/tools/image-tool.js.map +1 -0
  57. package/dist/tools/index.d.ts +14 -0
  58. package/dist/tools/index.js +15 -0
  59. package/dist/tools/index.js.map +1 -0
  60. package/dist/tools/internet-tool.d.ts +11 -0
  61. package/dist/tools/internet-tool.js +108 -0
  62. package/dist/tools/internet-tool.js.map +1 -0
  63. package/dist/tools/introspect-tool.d.ts +11 -0
  64. package/dist/tools/introspect-tool.js +243 -0
  65. package/dist/tools/introspect-tool.js.map +1 -0
  66. package/dist/tools/morph-editor.d.ts +38 -0
  67. package/dist/tools/morph-editor.js +318 -0
  68. package/dist/tools/morph-editor.js.map +1 -0
  69. package/dist/tools/restart-tool.d.ts +7 -0
  70. package/dist/tools/restart-tool.js +24 -0
  71. package/dist/tools/restart-tool.js.map +1 -0
  72. package/dist/tools/search.d.ts +71 -0
  73. package/dist/tools/search.js +340 -0
  74. package/dist/tools/search.js.map +1 -0
  75. package/dist/tools/task-tool.d.ts +19 -0
  76. package/dist/tools/task-tool.js +115 -0
  77. package/dist/tools/task-tool.js.map +1 -0
  78. package/dist/tools/text-editor.d.ts +35 -0
  79. package/dist/tools/text-editor.js +669 -0
  80. package/dist/tools/text-editor.js.map +1 -0
  81. package/dist/tools/tool-discovery.d.ts +20 -0
  82. package/dist/tools/tool-discovery.js +45 -0
  83. package/dist/tools/tool-discovery.js.map +1 -0
  84. package/dist/tools/zsh.d.ts +13 -0
  85. package/dist/tools/zsh.js +168 -0
  86. package/dist/tools/zsh.js.map +1 -0
  87. package/dist/types/index.d.ts +31 -0
  88. package/dist/types/index.js +2 -0
  89. package/dist/types/index.js.map +1 -0
  90. package/dist/ui/app.d.ts +7 -0
  91. package/dist/ui/app.js +99 -0
  92. package/dist/ui/app.js.map +1 -0
  93. package/dist/ui/components/active-task-status.d.ts +7 -0
  94. package/dist/ui/components/active-task-status.js +37 -0
  95. package/dist/ui/components/active-task-status.js.map +1 -0
  96. package/dist/ui/components/api-key-input.d.ts +7 -0
  97. package/dist/ui/components/api-key-input.js +80 -0
  98. package/dist/ui/components/api-key-input.js.map +1 -0
  99. package/dist/ui/components/backend-status.d.ts +7 -0
  100. package/dist/ui/components/backend-status.js +85 -0
  101. package/dist/ui/components/backend-status.js.map +1 -0
  102. package/dist/ui/components/chat-history.d.ts +8 -0
  103. package/dist/ui/components/chat-history.js +187 -0
  104. package/dist/ui/components/chat-history.js.map +1 -0
  105. package/dist/ui/components/chat-input.d.ts +9 -0
  106. package/dist/ui/components/chat-input.js +63 -0
  107. package/dist/ui/components/chat-input.js.map +1 -0
  108. package/dist/ui/components/chat-interface.d.ts +9 -0
  109. package/dist/ui/components/chat-interface.js +389 -0
  110. package/dist/ui/components/chat-interface.js.map +1 -0
  111. package/dist/ui/components/command-suggestions.d.ts +17 -0
  112. package/dist/ui/components/command-suggestions.js +22 -0
  113. package/dist/ui/components/command-suggestions.js.map +1 -0
  114. package/dist/ui/components/confirmation-dialog.d.ts +11 -0
  115. package/dist/ui/components/confirmation-dialog.js +105 -0
  116. package/dist/ui/components/confirmation-dialog.js.map +1 -0
  117. package/dist/ui/components/context-status.d.ts +7 -0
  118. package/dist/ui/components/context-status.js +36 -0
  119. package/dist/ui/components/context-status.js.map +1 -0
  120. package/dist/ui/components/diff-renderer.d.ts +13 -0
  121. package/dist/ui/components/diff-renderer.js +206 -0
  122. package/dist/ui/components/diff-renderer.js.map +1 -0
  123. package/dist/ui/components/loading-spinner.d.ts +8 -0
  124. package/dist/ui/components/loading-spinner.js +64 -0
  125. package/dist/ui/components/loading-spinner.js.map +1 -0
  126. package/dist/ui/components/mcp-status.d.ts +5 -0
  127. package/dist/ui/components/mcp-status.js +57 -0
  128. package/dist/ui/components/mcp-status.js.map +1 -0
  129. package/dist/ui/components/model-selection.d.ts +12 -0
  130. package/dist/ui/components/model-selection.js +17 -0
  131. package/dist/ui/components/model-selection.js.map +1 -0
  132. package/dist/ui/components/mood-status.d.ts +7 -0
  133. package/dist/ui/components/mood-status.js +34 -0
  134. package/dist/ui/components/mood-status.js.map +1 -0
  135. package/dist/ui/components/persona-status.d.ts +7 -0
  136. package/dist/ui/components/persona-status.js +34 -0
  137. package/dist/ui/components/persona-status.js.map +1 -0
  138. package/dist/ui/shared/max-sized-box.d.ts +8 -0
  139. package/dist/ui/shared/max-sized-box.js +6 -0
  140. package/dist/ui/shared/max-sized-box.js.map +1 -0
  141. package/dist/ui/utils/code-colorizer.d.ts +2 -0
  142. package/dist/ui/utils/code-colorizer.js +7 -0
  143. package/dist/ui/utils/code-colorizer.js.map +1 -0
  144. package/dist/ui/utils/colors.d.ts +14 -0
  145. package/dist/ui/utils/colors.js +15 -0
  146. package/dist/ui/utils/colors.js.map +1 -0
  147. package/dist/ui/utils/markdown-renderer.d.ts +4 -0
  148. package/dist/ui/utils/markdown-renderer.js +40 -0
  149. package/dist/ui/utils/markdown-renderer.js.map +1 -0
  150. package/dist/utils/auth-helper.d.ts +63 -0
  151. package/dist/utils/auth-helper.js +129 -0
  152. package/dist/utils/auth-helper.js.map +1 -0
  153. package/dist/utils/chat-history-manager-sqlite.d.ts +92 -0
  154. package/dist/utils/chat-history-manager-sqlite.js +334 -0
  155. package/dist/utils/chat-history-manager-sqlite.js.map +1 -0
  156. package/dist/utils/chat-history-manager.d.ts +87 -0
  157. package/dist/utils/chat-history-manager.js +273 -0
  158. package/dist/utils/chat-history-manager.js.map +1 -0
  159. package/dist/utils/chat-history-manager.json-backup.d.ts +69 -0
  160. package/dist/utils/chat-history-manager.json-backup.js +215 -0
  161. package/dist/utils/chat-history-manager.json-backup.js.map +1 -0
  162. package/dist/utils/confirmation-service.d.ts +46 -0
  163. package/dist/utils/confirmation-service.js +165 -0
  164. package/dist/utils/confirmation-service.js.map +1 -0
  165. package/dist/utils/custom-instructions.d.ts +1 -0
  166. package/dist/utils/custom-instructions.js +30 -0
  167. package/dist/utils/custom-instructions.js.map +1 -0
  168. package/dist/utils/database-connection.d.ts +27 -0
  169. package/dist/utils/database-connection.js +81 -0
  170. package/dist/utils/database-connection.js.map +1 -0
  171. package/dist/utils/database-schema.d.ts +17 -0
  172. package/dist/utils/database-schema.js +93 -0
  173. package/dist/utils/database-schema.js.map +1 -0
  174. package/dist/utils/error-logger.d.ts +13 -0
  175. package/dist/utils/error-logger.js +56 -0
  176. package/dist/utils/error-logger.js.map +1 -0
  177. package/dist/utils/hook-executor.d.ts +59 -0
  178. package/dist/utils/hook-executor.js +351 -0
  179. package/dist/utils/hook-executor.js.map +1 -0
  180. package/dist/utils/model-config.d.ts +28 -0
  181. package/dist/utils/model-config.js +42 -0
  182. package/dist/utils/model-config.js.map +1 -0
  183. package/dist/utils/path-utils.d.ts +4 -0
  184. package/dist/utils/path-utils.js +12 -0
  185. package/dist/utils/path-utils.js.map +1 -0
  186. package/dist/utils/settings-manager.d.ts +169 -0
  187. package/dist/utils/settings-manager.js +403 -0
  188. package/dist/utils/settings-manager.js.map +1 -0
  189. package/dist/utils/settings.d.ts +1 -0
  190. package/dist/utils/settings.js +4 -0
  191. package/dist/utils/settings.js.map +1 -0
  192. package/dist/utils/slash-commands.d.ts +25 -0
  193. package/dist/utils/slash-commands.js +454 -0
  194. package/dist/utils/slash-commands.js.map +1 -0
  195. package/dist/utils/startup-hook.d.ts +13 -0
  196. package/dist/utils/startup-hook.js +44 -0
  197. package/dist/utils/startup-hook.js.map +1 -0
  198. package/dist/utils/text-utils.d.ts +80 -0
  199. package/dist/utils/text-utils.js +182 -0
  200. package/dist/utils/text-utils.js.map +1 -0
  201. package/dist/utils/token-counter.d.ts +33 -0
  202. package/dist/utils/token-counter.js +78 -0
  203. package/dist/utils/token-counter.js.map +1 -0
  204. package/package.json +102 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-history-manager.json-backup.js","sourceRoot":"","sources":["../../src/utils/chat-history-manager.json-backup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;AAgBrD;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAC,QAAQ,CAAqB;IACpC,MAAM,CAAC,qBAAqB,GAAkB,IAAI,CAAC;IACnD,eAAe,CAAS;IAEhC;QACE,IAAI,CAAC,eAAe,GAAG,kBAAkB,CAAC,qBAAqB,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;QAC7G,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,QAAgB;QAC1C,kBAAkB,CAAC,qBAAqB,GAAG,QAAQ,CAAC;IACtD,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,CAAC;YACjC,kBAAkB,CAAC,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACzD,CAAC;QACD,OAAO,kBAAkB,CA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,WAAW,EAAE,CAAC;QAClD,OAAO,QAAQ,CAAC,eAAe,EAAE,CAAC;IACpC,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { EventEmitter } from "events";
2
+ export interface ConfirmationOptions {
3
+ operation: string;
4
+ filename: string;
5
+ showVSCodeOpen?: boolean;
6
+ content?: string;
7
+ }
8
+ export interface ConfirmationResult {
9
+ confirmed: boolean;
10
+ dontAskAgain?: boolean;
11
+ feedback?: string;
12
+ }
13
+ export declare class ConfirmationService extends EventEmitter {
14
+ private static instance;
15
+ private skipConfirmationThisSession;
16
+ private pendingConfirmation;
17
+ private resolveConfirmation;
18
+ private sessionFlags;
19
+ private approvedCommands;
20
+ static getInstance(): ConfirmationService;
21
+ constructor();
22
+ requestConfirmation(options: ConfirmationOptions, operationType?: "file" | "zsh"): Promise<ConfirmationResult>;
23
+ confirmOperation(confirmed: boolean, dontAskAgain?: boolean): void;
24
+ rejectOperation(feedback?: string): void;
25
+ private openInVSCode;
26
+ isPending(): boolean;
27
+ resetSession(): void;
28
+ getSessionFlags(): {
29
+ fileOperations: boolean;
30
+ zshCommands: boolean;
31
+ allOperations: boolean;
32
+ };
33
+ setSessionFlag(flagType: "fileOperations" | "zshCommands" | "allOperations", value: boolean): void;
34
+ /**
35
+ * Set specific commands to auto-approve
36
+ */
37
+ setApprovedCommands(commands: string[]): void;
38
+ /**
39
+ * Check if a command should be auto-approved
40
+ */
41
+ private isCommandApproved;
42
+ /**
43
+ * Normalize operation names to match common command names
44
+ */
45
+ private normalizeOperation;
46
+ }
@@ -0,0 +1,165 @@
1
+ import { exec } from "child_process";
2
+ import { promisify } from "util";
3
+ import { EventEmitter } from "events";
4
+ const execAsync = promisify(exec);
5
+ export class ConfirmationService extends EventEmitter {
6
+ static instance;
7
+ skipConfirmationThisSession = false;
8
+ pendingConfirmation = null;
9
+ resolveConfirmation = null;
10
+ // Session flags for different operation types
11
+ sessionFlags = {
12
+ fileOperations: false,
13
+ zshCommands: false,
14
+ allOperations: false,
15
+ };
16
+ // List of specific commands to auto-approve
17
+ approvedCommands = new Set();
18
+ static getInstance() {
19
+ if (!ConfirmationService.instance) {
20
+ ConfirmationService.instance = new ConfirmationService();
21
+ }
22
+ return ConfirmationService.instance;
23
+ }
24
+ constructor() {
25
+ super();
26
+ }
27
+ async requestConfirmation(options, operationType = "file") {
28
+ // Check session flags
29
+ if (this.sessionFlags.allOperations ||
30
+ (operationType === "file" && this.sessionFlags.fileOperations) ||
31
+ (operationType === "zsh" && this.sessionFlags.zshCommands)) {
32
+ return { confirmed: true };
33
+ }
34
+ // Check if this specific command is approved
35
+ if (this.isCommandApproved(options.operation, options.filename)) {
36
+ return { confirmed: true };
37
+ }
38
+ // If VS Code should be opened, try to open it
39
+ if (options.showVSCodeOpen) {
40
+ try {
41
+ await this.openInVSCode(options.filename);
42
+ }
43
+ catch (error) {
44
+ // If VS Code opening fails, continue without it
45
+ options.showVSCodeOpen = false;
46
+ }
47
+ }
48
+ // Create a promise that will be resolved by the UI component
49
+ this.pendingConfirmation = new Promise((resolve) => {
50
+ this.resolveConfirmation = resolve;
51
+ });
52
+ // Emit custom event that the UI can listen to (using setImmediate to ensure the UI updates)
53
+ setImmediate(() => {
54
+ this.emit("confirmation-requested", options);
55
+ });
56
+ const result = await this.pendingConfirmation;
57
+ if (result.dontAskAgain) {
58
+ // Set the appropriate session flag based on operation type
59
+ if (operationType === "file") {
60
+ this.sessionFlags.fileOperations = true;
61
+ }
62
+ else if (operationType === "zsh") {
63
+ this.sessionFlags.zshCommands = true;
64
+ }
65
+ // Could also set allOperations for global skip
66
+ }
67
+ return result;
68
+ }
69
+ confirmOperation(confirmed, dontAskAgain) {
70
+ if (this.resolveConfirmation) {
71
+ this.resolveConfirmation({ confirmed, dontAskAgain });
72
+ this.resolveConfirmation = null;
73
+ this.pendingConfirmation = null;
74
+ }
75
+ }
76
+ rejectOperation(feedback) {
77
+ if (this.resolveConfirmation) {
78
+ this.resolveConfirmation({ confirmed: false, feedback });
79
+ this.resolveConfirmation = null;
80
+ this.pendingConfirmation = null;
81
+ }
82
+ }
83
+ async openInVSCode(filename) {
84
+ // Try different VS Code commands
85
+ const commands = ["code", "code-insiders", "codium"];
86
+ for (const cmd of commands) {
87
+ try {
88
+ await execAsync(`which ${cmd}`);
89
+ await execAsync(`${cmd} "${filename}"`);
90
+ return;
91
+ }
92
+ catch (error) {
93
+ // Continue to next command
94
+ continue;
95
+ }
96
+ }
97
+ throw new Error("VS Code not found");
98
+ }
99
+ isPending() {
100
+ return this.pendingConfirmation !== null;
101
+ }
102
+ resetSession() {
103
+ this.sessionFlags = {
104
+ fileOperations: false,
105
+ zshCommands: false,
106
+ allOperations: false,
107
+ };
108
+ this.approvedCommands.clear();
109
+ }
110
+ getSessionFlags() {
111
+ return { ...this.sessionFlags };
112
+ }
113
+ setSessionFlag(flagType, value) {
114
+ this.sessionFlags[flagType] = value;
115
+ }
116
+ /**
117
+ * Set specific commands to auto-approve
118
+ */
119
+ setApprovedCommands(commands) {
120
+ this.approvedCommands.clear();
121
+ commands.forEach(cmd => this.approvedCommands.add(cmd.toLowerCase()));
122
+ }
123
+ /**
124
+ * Check if a command should be auto-approved
125
+ */
126
+ isCommandApproved(operation, filename) {
127
+ // Check for exact operation matches
128
+ if (this.approvedCommands.has(operation.toLowerCase())) {
129
+ return true;
130
+ }
131
+ // Check for common command mappings
132
+ const normalizedOp = this.normalizeOperation(operation, filename);
133
+ return this.approvedCommands.has(normalizedOp);
134
+ }
135
+ /**
136
+ * Normalize operation names to match common command names
137
+ */
138
+ normalizeOperation(operation, filename) {
139
+ const op = operation.toLowerCase();
140
+ // Guard against undefined/null filename
141
+ if (!filename) {
142
+ return op;
143
+ }
144
+ // Map common operations to their command names
145
+ if (op.includes('run zsh command') || op.includes('execute')) {
146
+ // Extract actual command from filename for zsh operations
147
+ const cmd = filename.split(' ')[0]; // Get first word as command
148
+ return cmd.toLowerCase();
149
+ }
150
+ // Direct tool mappings
151
+ if (op.includes('edit file'))
152
+ return 'str_replace_editor';
153
+ if (op.includes('write'))
154
+ return 'create_file';
155
+ if (op.includes('view') || op.includes('read'))
156
+ return 'view_file';
157
+ // Handle specific commands that users might want to approve
158
+ if (filename.startsWith('ls '))
159
+ return 'list_files';
160
+ if (filename.startsWith('pwd'))
161
+ return 'pwd';
162
+ return op;
163
+ }
164
+ }
165
+ //# sourceMappingURL=confirmation-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmation-service.js","sourceRoot":"","sources":["../../src/utils/confirmation-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;AAelC,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IAC3C,MAAM,CAAC,QAAQ,CAAsB;IACrC,2BAA2B,GAAG,KAAK,CAAC;IACpC,mBAAmB,GAAuC,IAAI,CAAC;IAC/D,mBAAmB,GACzB,IAAI,CAAC;IAEP,8CAA8C;IACtC,YAAY,GAAG;QACrB,cAAc,EAAE,KAAK;QACrB,WAAW,EAAE,KAAK;QAClB,aAAa,EAAE,KAAK;KACrB,CAAC;IAEF,4CAA4C;IACpC,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7C,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC;YAClC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC3D,CAAC;QACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC;IACtC,CAAC;IAED;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,mBAAmB,CACvB,OAA4B,EAC5B,gBAAgC,MAAM;QAEtC,sBAAsB;QACtB,IACE,IAAI,CAAC,YAAY,CAAC,aAA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,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7D,0DAA0D;YAC1D,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,4BAA4B;YAChE,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC;QAED,uBAAuB;QACvB,IAAI,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC;YAAE,OAAO,oBAAoB,CAAC;QAC1D,IAAI,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,OAAO,aAAa,CAAC;QAC/C,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,WAAW,CAAC;QAEnE,4DAA4D;QAC5D,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;YAAE,OAAO,YAAY,CAAC;QACpD,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAE7C,OAAO,EAAE,CAAC;IACZ,CAAC;CACF"}
@@ -0,0 +1 @@
1
+ export declare function loadCustomInstructions(workingDirectory?: string): string | null;
@@ -0,0 +1,30 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as os from 'os';
4
+ export function loadCustomInstructions(workingDirectory = process.cwd()) {
5
+ try {
6
+ let instructions = '';
7
+ // Load user-level instructions first (~/.grok/GROK.md)
8
+ const userInstructionsPath = path.join(os.homedir(), '.grok', 'GROK.md');
9
+ if (fs.existsSync(userInstructionsPath)) {
10
+ const userInstructions = fs.readFileSync(userInstructionsPath, 'utf-8').trim();
11
+ if (userInstructions) {
12
+ instructions += userInstructions + '\n\n';
13
+ }
14
+ }
15
+ // Load project-level instructions (./.grok/GROK.md)
16
+ const projectInstructionsPath = path.join(workingDirectory, '.grok', 'GROK.md');
17
+ if ((userInstructionsPath !== projectInstructionsPath) && fs.existsSync(projectInstructionsPath)) {
18
+ const projectInstructions = fs.readFileSync(projectInstructionsPath, 'utf-8').trim();
19
+ if (projectInstructions) {
20
+ instructions += projectInstructions;
21
+ }
22
+ }
23
+ return instructions.trim() || null;
24
+ }
25
+ catch (error) {
26
+ console.warn('Failed to load custom instructions:', error);
27
+ return null;
28
+ }
29
+ }
30
+ //# sourceMappingURL=custom-instructions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-instructions.js","sourceRoot":"","sources":["../../src/utils/custom-instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,MAAM,UAAU,sBAAsB,CAAC,mBAA2B,OAAO,CAAC,GAAG,EAAE;IAC7E,IAAI,CAAC;QACH,IAAI,YAAY,GAAG,EAAE,CAAC;QAEtB,uDAAuD;QACvD,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QACzE,IAAI,EAAE,CAAC,UAAU,CAAC,oBAAoB,CAAC,EAAE,CAAC;YACxC,MAAM,gBAAgB,GAAG,EAAE,CAAC,YAAY,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YAC/E,IAAI,gBAAgB,EAAE,CAAC;gBACrB,YAAY,IAAI,gBAAgB,GAAG,MAAM,CAAC;YAC5C,CAAC;QACH,CAAC;QAED,oDAAoD;QACpD,MAAM,uBAAuB,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;QAChF,IAAI,CAAC,oBAAoB,KAAK,uBAAuB,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,uBAAuB,CAAC,EAAE,CAAC;YACjG,MAAM,mBAAmB,GAAG,EAAE,CAAC,YAAY,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;YACrF,IAAI,mBAAmB,EAAE,CAAC;gBACxB,YAAY,IAAI,mBAAmB,CAAC;YACtC,CAAC;QACH,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,EAAE,IAAI,IAAI,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,27 @@
1
+ import Database from "better-sqlite3";
2
+ /**
3
+ * Database connection manager with connection pooling and automatic schema initialization
4
+ */
5
+ export declare class DatabaseConnection {
6
+ private static connections;
7
+ /**
8
+ * Get or create a database connection for the given file path
9
+ */
10
+ static getConnection(dbPath: string): Database.Database;
11
+ /**
12
+ * Close a specific database connection
13
+ */
14
+ static closeConnection(dbPath: string): void;
15
+ /**
16
+ * Close all database connections
17
+ */
18
+ static closeAllConnections(): void;
19
+ /**
20
+ * Execute a function within a transaction
21
+ */
22
+ static transaction<T>(db: Database.Database, fn: () => T): T;
23
+ /**
24
+ * Backup database to a file
25
+ */
26
+ static backup(dbPath: string, backupPath: string): void;
27
+ }
@@ -0,0 +1,81 @@
1
+ import Database from "better-sqlite3";
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+ import { initializeSchema, runMigrations } from "./database-schema.js";
5
+ /**
6
+ * Database connection manager with connection pooling and automatic schema initialization
7
+ */
8
+ export class DatabaseConnection {
9
+ static connections = new Map();
10
+ /**
11
+ * Get or create a database connection for the given file path
12
+ */
13
+ static getConnection(dbPath) {
14
+ // Ensure directory exists
15
+ const dir = path.dirname(dbPath);
16
+ if (!fs.existsSync(dir)) {
17
+ fs.mkdirSync(dir, { recursive: true });
18
+ }
19
+ // Return existing connection if available
20
+ if (this.connections.has(dbPath)) {
21
+ return this.connections.get(dbPath);
22
+ }
23
+ // Create new connection
24
+ const db = new Database(dbPath);
25
+ // Initialize schema and run migrations
26
+ initializeSchema(db);
27
+ runMigrations(db);
28
+ // Store connection for reuse
29
+ this.connections.set(dbPath, db);
30
+ return db;
31
+ }
32
+ /**
33
+ * Close a specific database connection
34
+ */
35
+ static closeConnection(dbPath) {
36
+ const db = this.connections.get(dbPath);
37
+ if (db) {
38
+ db.close();
39
+ this.connections.delete(dbPath);
40
+ }
41
+ }
42
+ /**
43
+ * Close all database connections
44
+ */
45
+ static closeAllConnections() {
46
+ for (const [dbPath, db] of this.connections.entries()) {
47
+ db.close();
48
+ this.connections.delete(dbPath);
49
+ }
50
+ }
51
+ /**
52
+ * Execute a function within a transaction
53
+ */
54
+ static transaction(db, fn) {
55
+ const txn = db.transaction(fn);
56
+ return txn();
57
+ }
58
+ /**
59
+ * Backup database to a file
60
+ */
61
+ static backup(dbPath, backupPath) {
62
+ // Get database connection and checkpoint WAL
63
+ const db = this.connections.get(dbPath);
64
+ if (db) {
65
+ // Use checkpoint to ensure WAL is synced
66
+ db.pragma("wal_checkpoint(FULL)");
67
+ }
68
+ // Copy the main database file
69
+ fs.copyFileSync(dbPath, backupPath);
70
+ // Also copy WAL and SHM files if they exist
71
+ const walPath = `${dbPath}-wal`;
72
+ const shmPath = `${dbPath}-shm`;
73
+ if (fs.existsSync(walPath)) {
74
+ fs.copyFileSync(walPath, `${backupPath}-wal`);
75
+ }
76
+ if (fs.existsSync(shmPath)) {
77
+ fs.copyFileSync(shmPath, `${backupPath}-shm`);
78
+ }
79
+ }
80
+ }
81
+ //# sourceMappingURL=database-connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-connection.js","sourceRoot":"","sources":["../../src/utils/database-connection.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,gB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EAAE,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC;YACtD,EAAE,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,WAAW,CAChB,EAAqB,EACrB,EAAW;QAEX,MAAM,GAAG,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAc,EAAE,UAAkB;QAC9C,6CAA6C;QAC7C,MAAM,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxC,IAAI,EAAE,EAAE,CAAC;YACP,yCAAyC;YACzC,EAAE,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACpC,CAAC;QAED,8BAA8B;QAC9B,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAEpC,4CAA4C;QAC5C,MAAM,OAAO,GAAG,GAAG,MAAM,MAAM,CAAC;QAChC,MAAM,OAAO,GAAG,GAAG,MAAM,MAAM,CAAC;QAEhC,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,UAAU,MAAM,CAAC,CAAC;QAChD,CAAC;QACD,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,UAAU,MAAM,CAAC,CAAC;QAChD,CAAC;IACH,CAAC"}
@@ -0,0 +1,17 @@
1
+ import Database from "better-sqlite3";
2
+ /**
3
+ * Database schema version for migration tracking
4
+ */
5
+ export declare const SCHEMA_VERSION = 1;
6
+ /**
7
+ * Initialize the database schema with proper indexes and WAL mode for concurrency
8
+ */
9
+ export declare function initializeSchema(db: Database.Database): void;
10
+ /**
11
+ * Get the current schema version from the database
12
+ */
13
+ export declare function getSchemaVersion(db: Database.Database): number;
14
+ /**
15
+ * Run database migrations if needed
16
+ */
17
+ export declare function runMigrations(db: Database.Database): void;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Database schema version for migration tracking
3
+ */
4
+ export const SCHEMA_VERSION = 1;
5
+ /**
6
+ * Initialize the database schema with proper indexes and WAL mode for concurrency
7
+ */
8
+ export function initializeSchema(db) {
9
+ // Enable WAL mode for better concurrency (multiple readers + single writer)
10
+ db.pragma("journal_mode = WAL");
11
+ // Optimize for performance
12
+ db.pragma("synchronous = NORMAL");
13
+ db.pragma("cache_size = -64000"); // 64MB cache
14
+ db.pragma("busy_timeout = 5000"); // 5 second timeout for lock contention
15
+ // Create messages table
16
+ db.exec(`
17
+ CREATE TABLE IF NOT EXISTS messages (
18
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
19
+ message_id TEXT UNIQUE NOT NULL,
20
+ type TEXT NOT NULL, -- 'user', 'assistant', 'tool_result', 'tool_call', 'system'
21
+ content TEXT,
22
+ tool_calls TEXT, -- JSON array of tool calls
23
+ tool_call TEXT, -- JSON object for single tool call
24
+ tool_result TEXT, -- JSON object for tool result
25
+ is_streaming INTEGER DEFAULT 0, -- Boolean flag
26
+ timestamp INTEGER NOT NULL, -- Unix timestamp in milliseconds
27
+ created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
28
+ );
29
+ `);
30
+ // Create indexes for fast queries
31
+ db.exec(`
32
+ CREATE INDEX IF NOT EXISTS idx_timestamp ON messages(timestamp);
33
+ CREATE INDEX IF NOT EXISTS idx_type ON messages(type);
34
+ CREATE INDEX IF NOT EXISTS idx_message_id ON messages(message_id);
35
+ CREATE INDEX IF NOT EXISTS idx_created_at ON messages(created_at);
36
+ `);
37
+ // Create session_state table
38
+ db.exec(`
39
+ CREATE TABLE IF NOT EXISTS session_state (
40
+ key TEXT PRIMARY KEY,
41
+ value TEXT NOT NULL,
42
+ updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
43
+ );
44
+ `);
45
+ // Create session_metadata table
46
+ db.exec(`
47
+ CREATE TABLE IF NOT EXISTS session_metadata (
48
+ key TEXT PRIMARY KEY,
49
+ value TEXT NOT NULL,
50
+ updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
51
+ );
52
+ `);
53
+ // Create schema_version table
54
+ db.exec(`
55
+ CREATE TABLE IF NOT EXISTS schema_version (
56
+ version INTEGER PRIMARY KEY,
57
+ applied_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000)
58
+ );
59
+ `);
60
+ // Insert current schema version if not exists
61
+ const versionStmt = db.prepare(`
62
+ INSERT OR IGNORE INTO schema_version (version) VALUES (?)
63
+ `);
64
+ versionStmt.run(SCHEMA_VERSION);
65
+ }
66
+ /**
67
+ * Get the current schema version from the database
68
+ */
69
+ export function getSchemaVersion(db) {
70
+ try {
71
+ const row = db.prepare("SELECT version FROM schema_version ORDER BY version DESC LIMIT 1").get();
72
+ return row?.version ?? 0;
73
+ }
74
+ catch (error) {
75
+ // Table doesn't exist yet
76
+ return 0;
77
+ }
78
+ }
79
+ /**
80
+ * Run database migrations if needed
81
+ */
82
+ export function runMigrations(db) {
83
+ const currentVersion = getSchemaVersion(db);
84
+ if (currentVersion < SCHEMA_VERSION) {
85
+ console.log(`Migrating database from version ${currentVersion} to ${SCHEMA_VERSION}...`);
86
+ // Add future migrations here
87
+ // if (currentVersion < 2) {
88
+ // // Migration code for version 2
89
+ // }
90
+ console.log("Database migration complete.");
91
+ }
92
+ }
93
+ //# sourceMappingURL=database-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-schema.js","sourceRoot":"","sources":["../../src/utils/database-schema.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CA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,IAAI,cAAc,GAAG,cAAc,EAAE,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,mCAAmC,cAAc,OAAO,cAAc,KAAK,CAAC,CAAC;QAEzF,6BAA6B;QAC7B,4BAA4B;QAC5B,oCAAoC;QACpC,IAAI;QAEJ,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Log API error with full request/response for debugging
3
+ * @param requestPayload Request that was sent to the API
4
+ * @param error Error that occurred
5
+ * @param metadata Additional metadata about the error (testType, status code, etc.)
6
+ * @param prefix Filename prefix (e.g., "500", "test-fail")
7
+ * @returns Object with file paths and formatted error message
8
+ */
9
+ export declare function logApiError(requestPayload: any, error: any, metadata: Record<string, any>, prefix: string): Promise<{
10
+ requestFile: string;
11
+ responseFile: string;
12
+ message: string;
13
+ }>;
@@ -0,0 +1,56 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { ChatHistoryManager } from './chat-history-manager.js';
4
+ /**
5
+ * Log API error with full request/response for debugging
6
+ * @param requestPayload Request that was sent to the API
7
+ * @param error Error that occurred
8
+ * @param metadata Additional metadata about the error (testType, status code, etc.)
9
+ * @param prefix Filename prefix (e.g., "500", "test-fail")
10
+ * @returns Object with file paths and formatted error message
11
+ */
12
+ export async function logApiError(requestPayload, error, metadata, prefix) {
13
+ const timestamp = new Date().toISOString().replace(/:/g, '-').replace(/\./g, '-');
14
+ const historyManager = ChatHistoryManager.getInstance();
15
+ const contextPath = historyManager.getContextFilePath();
16
+ const errorDir = path.join(path.dirname(contextPath), 'error-logs');
17
+ // Ensure error-logs directory exists
18
+ try {
19
+ if (!fs.existsSync(errorDir)) {
20
+ fs.mkdirSync(errorDir, { recursive: true });
21
+ }
22
+ }
23
+ catch (mkdirErr) {
24
+ console.error('Failed to create error-logs directory:', mkdirErr);
25
+ }
26
+ const requestFile = `${errorDir}/${prefix}-${timestamp}-request.json`;
27
+ const responseFile = `${errorDir}/${prefix}-${timestamp}-response.txt`;
28
+ // Write request payload
29
+ try {
30
+ fs.writeFileSync(requestFile, JSON.stringify(requestPayload, null, 2));
31
+ }
32
+ catch (writeErr) {
33
+ console.error('Failed to write request file:', writeErr);
34
+ }
35
+ // Write response error details
36
+ try {
37
+ const responseData = {
38
+ ...metadata,
39
+ status: error.status,
40
+ message: error.message,
41
+ error: error.error,
42
+ response: error.response,
43
+ rawBody: error.response?.data || error.response?.body,
44
+ };
45
+ fs.writeFileSync(responseFile, JSON.stringify(responseData, null, 2));
46
+ }
47
+ catch (writeErr) {
48
+ console.error('Failed to write response file:', writeErr);
49
+ }
50
+ return {
51
+ requestFile,
52
+ responseFile,
53
+ message: `Request logged to: ${requestFile}\nResponse logged to: ${responseFile}`
54
+ };
55
+ }
56
+ //# sourceMappingURL=error-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-logger.js","sourceRoot":"","sources":["../../src/utils/error-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,cAAmB,EACnB,KAAU,EACV,QAA6B,EAC7B,MAAc;IAEd,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAClF,MAAM,cAAc,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;IACxD,MAAM,WAAW,GAAG,cAAc,CAAC,kBAAkB,EAAE,CAAC;IACxD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC,CAAC;IAEpE,q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gC,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO;QACL,WAAW;QACX,YAAY;QACZ,OAAO,EAAE,sBAAsB,WAAW,yBAAyB,YAAY,EAAE;KAClF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,59 @@
1
+ export interface HookResult {
2
+ approved: boolean;
3
+ reason?: string;
4
+ timedOut: boolean;
5
+ commands?: HookCommand[];
6
+ }
7
+ export interface HookCommand {
8
+ type: "ENV" | "TOOL_RESULT" | "ECHO" | "RUN" | "BACKEND" | "MODEL" | "SYSTEM" | "SYSTEM_FILE" | "BASE_URL" | "API_KEY_ENV_VAR";
9
+ value: string;
10
+ }
11
+ export interface HookCommandResults {
12
+ env: Record<string, string>;
13
+ toolResult: string;
14
+ system: string;
15
+ model?: string;
16
+ backend?: string;
17
+ baseUrl?: string;
18
+ apiKeyEnvVar?: string;
19
+ }
20
+ /**
21
+ * Apply hook commands and return extracted values
22
+ * ENV commands are applied to process.env (auto-prefixes ENV_PREFIX if not present)
23
+ * ENV VAR= (empty value) will unset the variable
24
+ * TOOL_RESULT commands are aggregated into a single string
25
+ * SYSTEM commands are aggregated into a single string
26
+ * SYSTEM_FILE commands read file contents (up to 20k) and add to system string
27
+ * MODEL commands set the model to use (last one wins if multiple)
28
+ * BACKEND commands set the backend to use (last one wins if multiple)
29
+ * BASE_URL commands set the base URL to use (last one wins if multiple)
30
+ * API_KEY_ENV_VAR commands set the env var name for API key (last one wins if multiple)
31
+ * Returns extracted values for caller to use
32
+ */
33
+ export declare function applyHookCommands(commands: HookCommand[]): HookCommandResults;
34
+ /**
35
+ * Apply extracted ENV variables to process.env
36
+ * Should be called AFTER model/backend tests succeed
37
+ * @param env Environment variables to apply
38
+ */
39
+ export declare function applyEnvVariables(env: Record<string, string>): void;
40
+ /**
41
+ * Execute a hook with operation details passed via environment variables
42
+ * Generic hook executor for operations that need validation
43
+ * @param hookPath Path to hook script (supports ~/ expansion)
44
+ * @param operation Operation type (e.g., "tool", "task", "persona", "mood")
45
+ * @param data Key-value pairs to pass as environment variables
46
+ * @param timeoutMs Timeout in milliseconds (default 30000)
47
+ * @param mandatory If true, timeout rejects instead of auto-approving
48
+ * @returns Promise<HookResult>
49
+ */
50
+ export declare function executeOperationHook(hookPath: string, operation: string, data: Record<string, any>, timeoutMs?: number, mandatory?: boolean, contextCurrent?: number, contextMax?: number): Promise<HookResult>;
51
+ /**
52
+ * Execute a tool approval hook with tool name and parameters passed via environment
53
+ * @param hookPath Path to hook script (supports ~/ expansion)
54
+ * @param toolName Name of the tool being executed
55
+ * @param parameters Tool parameters as key-value pairs
56
+ * @param timeoutMs Timeout in milliseconds (default 30000)
57
+ * @returns Promise<HookResult>
58
+ */
59
+ export declare function executeToolApprovalHook(hookPath: string, toolName: string, parameters: Record<string, any>, timeoutMs?: number, contextCurrent?: number, contextMax?: number): Promise<HookResult>;