actoviq-agent-sdk 0.2.0 → 0.3.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 (222) hide show
  1. package/README-zh.md +19 -3
  2. package/README.md +19 -3
  3. package/bin/actoviq-interactive-agent.js +5 -0
  4. package/bin/actoviq-link-runtime.js +74 -0
  5. package/bin/actoviq-react.js +5 -0
  6. package/dist/src/cli/actoviq-react.d.ts +3 -0
  7. package/dist/src/cli/actoviq-react.d.ts.map +1 -0
  8. package/dist/src/cli/actoviq-react.js +286 -0
  9. package/dist/src/cli/actoviq-react.js.map +1 -0
  10. package/dist/src/cli/bridge-interactive-agent.d.ts +2 -0
  11. package/dist/src/cli/bridge-interactive-agent.d.ts.map +1 -0
  12. package/dist/src/cli/bridge-interactive-agent.js +147 -0
  13. package/dist/src/cli/bridge-interactive-agent.js.map +1 -0
  14. package/dist/src/config/anthropicEnvMapping.d.ts +18 -0
  15. package/dist/src/config/anthropicEnvMapping.d.ts.map +1 -0
  16. package/dist/src/config/anthropicEnvMapping.js +40 -0
  17. package/dist/src/config/anthropicEnvMapping.js.map +1 -0
  18. package/dist/src/config/resolveRuntimeConfig.d.ts.map +1 -1
  19. package/dist/src/config/resolveRuntimeConfig.js +44 -23
  20. package/dist/src/config/resolveRuntimeConfig.js.map +1 -1
  21. package/dist/src/errors.d.ts +9 -0
  22. package/dist/src/errors.d.ts.map +1 -1
  23. package/dist/src/errors.js +9 -0
  24. package/dist/src/errors.js.map +1 -1
  25. package/dist/src/index.d.ts +23 -1
  26. package/dist/src/index.d.ts.map +1 -1
  27. package/dist/src/index.js +21 -1
  28. package/dist/src/index.js.map +1 -1
  29. package/dist/src/memory/actoviqMemory.d.ts.map +1 -1
  30. package/dist/src/memory/actoviqMemory.js +10 -6
  31. package/dist/src/memory/actoviqMemory.js.map +1 -1
  32. package/dist/src/memory/actoviqTranscriptLogger.d.ts.map +1 -1
  33. package/dist/src/memory/actoviqTranscriptLogger.js +2 -2
  34. package/dist/src/memory/actoviqTranscriptLogger.js.map +1 -1
  35. package/dist/src/parity/actoviqBridgeEvents.d.ts +7 -0
  36. package/dist/src/parity/actoviqBridgeEvents.d.ts.map +1 -0
  37. package/dist/src/parity/actoviqBridgeEvents.js +135 -0
  38. package/dist/src/parity/actoviqBridgeEvents.js.map +1 -0
  39. package/dist/src/parity/actoviqBridgeSdk.d.ts +179 -0
  40. package/dist/src/parity/actoviqBridgeSdk.d.ts.map +1 -0
  41. package/dist/src/parity/actoviqBridgeSdk.js +1275 -0
  42. package/dist/src/parity/actoviqBridgeSdk.js.map +1 -0
  43. package/dist/src/parity/actoviqCleanBridgeCompatSdk.d.ts +277 -0
  44. package/dist/src/parity/actoviqCleanBridgeCompatSdk.d.ts.map +1 -0
  45. package/dist/src/parity/actoviqCleanBridgeCompatSdk.js +1391 -0
  46. package/dist/src/parity/actoviqCleanBridgeCompatSdk.js.map +1 -0
  47. package/dist/src/parity/actoviqTranscripts.d.ts +44 -0
  48. package/dist/src/parity/actoviqTranscripts.d.ts.map +1 -0
  49. package/dist/src/parity/actoviqTranscripts.js +282 -0
  50. package/dist/src/parity/actoviqTranscripts.js.map +1 -0
  51. package/dist/src/parity/portableSessions.d.ts +35 -0
  52. package/dist/src/parity/portableSessions.d.ts.map +1 -0
  53. package/dist/src/parity/portableSessions.js +237 -0
  54. package/dist/src/parity/portableSessions.js.map +1 -0
  55. package/dist/src/prompts/systemPrompt.d.ts +15 -0
  56. package/dist/src/prompts/systemPrompt.d.ts.map +1 -0
  57. package/dist/src/prompts/systemPrompt.js +73 -0
  58. package/dist/src/prompts/systemPrompt.js.map +1 -0
  59. package/dist/src/provider/client.d.ts +4 -0
  60. package/dist/src/provider/client.d.ts.map +1 -1
  61. package/dist/src/provider/client.js +82 -10
  62. package/dist/src/provider/client.js.map +1 -1
  63. package/dist/src/provider/json-parse.d.ts +7 -0
  64. package/dist/src/provider/json-parse.d.ts.map +1 -0
  65. package/dist/src/provider/json-parse.js +69 -0
  66. package/dist/src/provider/json-parse.js.map +1 -0
  67. package/dist/src/provider/openai-client.d.ts.map +1 -1
  68. package/dist/src/provider/openai-client.js +45 -5
  69. package/dist/src/provider/openai-client.js.map +1 -1
  70. package/dist/src/provider/openai-model-api.d.ts.map +1 -1
  71. package/dist/src/provider/openai-model-api.js +2 -7
  72. package/dist/src/provider/openai-model-api.js.map +1 -1
  73. package/dist/src/runtime/actoviqAgents.d.ts +6 -0
  74. package/dist/src/runtime/actoviqAgents.d.ts.map +1 -1
  75. package/dist/src/runtime/actoviqAgents.js +110 -14
  76. package/dist/src/runtime/actoviqAgents.js.map +1 -1
  77. package/dist/src/runtime/actoviqApiMicrocompact.d.ts +14 -0
  78. package/dist/src/runtime/actoviqApiMicrocompact.d.ts.map +1 -1
  79. package/dist/src/runtime/actoviqApiMicrocompact.js +111 -16
  80. package/dist/src/runtime/actoviqApiMicrocompact.js.map +1 -1
  81. package/dist/src/runtime/actoviqBackgroundTasks.d.ts +1 -0
  82. package/dist/src/runtime/actoviqBackgroundTasks.d.ts.map +1 -1
  83. package/dist/src/runtime/actoviqBackgroundTasks.js +1 -0
  84. package/dist/src/runtime/actoviqBackgroundTasks.js.map +1 -1
  85. package/dist/src/runtime/actoviqCompact.d.ts +43 -0
  86. package/dist/src/runtime/actoviqCompact.d.ts.map +1 -1
  87. package/dist/src/runtime/actoviqCompact.js +290 -8
  88. package/dist/src/runtime/actoviqCompact.js.map +1 -1
  89. package/dist/src/runtime/actoviqPermissions.d.ts.map +1 -1
  90. package/dist/src/runtime/actoviqPermissions.js +121 -55
  91. package/dist/src/runtime/actoviqPermissions.js.map +1 -1
  92. package/dist/src/runtime/agentClient.d.ts +11 -0
  93. package/dist/src/runtime/agentClient.d.ts.map +1 -1
  94. package/dist/src/runtime/agentClient.js +332 -6
  95. package/dist/src/runtime/agentClient.js.map +1 -1
  96. package/dist/src/runtime/conversationEngine.d.ts.map +1 -1
  97. package/dist/src/runtime/conversationEngine.js +585 -33
  98. package/dist/src/runtime/conversationEngine.js.map +1 -1
  99. package/dist/src/runtime/defaultActoviqAgents.d.ts +3 -0
  100. package/dist/src/runtime/defaultActoviqAgents.d.ts.map +1 -0
  101. package/dist/src/runtime/defaultActoviqAgents.js +44 -0
  102. package/dist/src/runtime/defaultActoviqAgents.js.map +1 -0
  103. package/dist/src/runtime/denialTracking.d.ts +10 -0
  104. package/dist/src/runtime/denialTracking.d.ts.map +1 -0
  105. package/dist/src/runtime/denialTracking.js +27 -0
  106. package/dist/src/runtime/denialTracking.js.map +1 -0
  107. package/dist/src/runtime/safetyChecks.d.ts +12 -0
  108. package/dist/src/runtime/safetyChecks.d.ts.map +1 -0
  109. package/dist/src/runtime/safetyChecks.js +68 -0
  110. package/dist/src/runtime/safetyChecks.js.map +1 -0
  111. package/dist/src/runtime/sessionManager.d.ts.map +1 -1
  112. package/dist/src/runtime/sessionManager.js +10 -5
  113. package/dist/src/runtime/sessionManager.js.map +1 -1
  114. package/dist/src/runtime/tools.d.ts.map +1 -1
  115. package/dist/src/runtime/tools.js +62 -3
  116. package/dist/src/runtime/tools.js.map +1 -1
  117. package/dist/src/scheduling/cron.d.ts +14 -0
  118. package/dist/src/scheduling/cron.d.ts.map +1 -0
  119. package/dist/src/scheduling/cron.js +159 -0
  120. package/dist/src/scheduling/cron.js.map +1 -0
  121. package/dist/src/scheduling/index.d.ts +3 -0
  122. package/dist/src/scheduling/index.d.ts.map +1 -0
  123. package/dist/src/scheduling/index.js +3 -0
  124. package/dist/src/scheduling/index.js.map +1 -0
  125. package/dist/src/scheduling/scheduler.d.ts +32 -0
  126. package/dist/src/scheduling/scheduler.d.ts.map +1 -0
  127. package/dist/src/scheduling/scheduler.js +196 -0
  128. package/dist/src/scheduling/scheduler.js.map +1 -0
  129. package/dist/src/storage/backgroundTaskStore.d.ts.map +1 -1
  130. package/dist/src/storage/backgroundTaskStore.js +3 -2
  131. package/dist/src/storage/backgroundTaskStore.js.map +1 -1
  132. package/dist/src/storage/mailboxStore.d.ts.map +1 -1
  133. package/dist/src/storage/mailboxStore.js +3 -3
  134. package/dist/src/storage/mailboxStore.js.map +1 -1
  135. package/dist/src/storage/pathSafety.d.ts +4 -0
  136. package/dist/src/storage/pathSafety.d.ts.map +1 -0
  137. package/dist/src/storage/pathSafety.js +28 -0
  138. package/dist/src/storage/pathSafety.js.map +1 -0
  139. package/dist/src/storage/sessionStore.d.ts +2 -2
  140. package/dist/src/storage/sessionStore.d.ts.map +1 -1
  141. package/dist/src/storage/sessionStore.js +23 -8
  142. package/dist/src/storage/sessionStore.js.map +1 -1
  143. package/dist/src/storage/teammateStore.d.ts.map +1 -1
  144. package/dist/src/storage/teammateStore.js +3 -2
  145. package/dist/src/storage/teammateStore.js.map +1 -1
  146. package/dist/src/tools/actoviqCoreTools.d.ts +28 -0
  147. package/dist/src/tools/actoviqCoreTools.d.ts.map +1 -0
  148. package/dist/src/tools/actoviqCoreTools.js +32 -0
  149. package/dist/src/tools/actoviqCoreTools.js.map +1 -0
  150. package/dist/src/tools/actoviqFileTools.d.ts.map +1 -1
  151. package/dist/src/tools/actoviqFileTools.js +349 -373
  152. package/dist/src/tools/actoviqFileTools.js.map +1 -1
  153. package/dist/src/tools/actoviqMiscTools.d.ts +11 -0
  154. package/dist/src/tools/actoviqMiscTools.d.ts.map +1 -0
  155. package/dist/src/tools/actoviqMiscTools.js +89 -0
  156. package/dist/src/tools/actoviqMiscTools.js.map +1 -0
  157. package/dist/src/tools/actoviqNotebookEdit.d.ts +4 -0
  158. package/dist/src/tools/actoviqNotebookEdit.d.ts.map +1 -0
  159. package/dist/src/tools/actoviqNotebookEdit.js +140 -0
  160. package/dist/src/tools/actoviqNotebookEdit.js.map +1 -0
  161. package/dist/src/tools/actoviqShellTools.d.ts +5 -0
  162. package/dist/src/tools/actoviqShellTools.d.ts.map +1 -0
  163. package/dist/src/tools/actoviqShellTools.js +64 -0
  164. package/dist/src/tools/actoviqShellTools.js.map +1 -0
  165. package/dist/src/tools/actoviqTaskTools.d.ts +12 -0
  166. package/dist/src/tools/actoviqTaskTools.d.ts.map +1 -0
  167. package/dist/src/tools/actoviqTaskTools.js +108 -0
  168. package/dist/src/tools/actoviqTaskTools.js.map +1 -0
  169. package/dist/src/tools/actoviqWebTools.d.ts +15 -0
  170. package/dist/src/tools/actoviqWebTools.d.ts.map +1 -0
  171. package/dist/src/tools/actoviqWebTools.js +427 -0
  172. package/dist/src/tools/actoviqWebTools.js.map +1 -0
  173. package/dist/src/tools/askUserQuestion/AskUserQuestionTool.d.ts +6 -0
  174. package/dist/src/tools/askUserQuestion/AskUserQuestionTool.d.ts.map +1 -0
  175. package/dist/src/tools/askUserQuestion/AskUserQuestionTool.js +43 -0
  176. package/dist/src/tools/askUserQuestion/AskUserQuestionTool.js.map +1 -0
  177. package/dist/src/tools/bash/BashTool.d.ts +14 -0
  178. package/dist/src/tools/bash/BashTool.d.ts.map +1 -0
  179. package/dist/src/tools/bash/BashTool.js +60 -0
  180. package/dist/src/tools/bash/BashTool.js.map +1 -0
  181. package/dist/src/tools/bash/prompt.d.ts +3 -0
  182. package/dist/src/tools/bash/prompt.d.ts.map +1 -0
  183. package/dist/src/tools/bash/prompt.js +63 -0
  184. package/dist/src/tools/bash/prompt.js.map +1 -0
  185. package/dist/src/tools/prompts/fileEditPrompt.d.ts +3 -0
  186. package/dist/src/tools/prompts/fileEditPrompt.d.ts.map +1 -0
  187. package/dist/src/tools/prompts/fileEditPrompt.js +14 -0
  188. package/dist/src/tools/prompts/fileEditPrompt.js.map +1 -0
  189. package/dist/src/tools/prompts/fileReadPrompt.d.ts +3 -0
  190. package/dist/src/tools/prompts/fileReadPrompt.d.ts.map +1 -0
  191. package/dist/src/tools/prompts/fileReadPrompt.js +18 -0
  192. package/dist/src/tools/prompts/fileReadPrompt.js.map +1 -0
  193. package/dist/src/tools/prompts/fileSearchPrompt.d.ts +2 -0
  194. package/dist/src/tools/prompts/fileSearchPrompt.d.ts.map +1 -0
  195. package/dist/src/tools/prompts/fileSearchPrompt.js +21 -0
  196. package/dist/src/tools/prompts/fileSearchPrompt.js.map +1 -0
  197. package/dist/src/tools/prompts/fileWritePrompt.d.ts +3 -0
  198. package/dist/src/tools/prompts/fileWritePrompt.d.ts.map +1 -0
  199. package/dist/src/tools/prompts/fileWritePrompt.js +13 -0
  200. package/dist/src/tools/prompts/fileWritePrompt.js.map +1 -0
  201. package/dist/src/tools/prompts/webFetchPrompt.d.ts +3 -0
  202. package/dist/src/tools/prompts/webFetchPrompt.d.ts.map +1 -0
  203. package/dist/src/tools/prompts/webFetchPrompt.js +13 -0
  204. package/dist/src/tools/prompts/webFetchPrompt.js.map +1 -0
  205. package/dist/src/tools/prompts/webSearchPrompt.d.ts +3 -0
  206. package/dist/src/tools/prompts/webSearchPrompt.d.ts.map +1 -0
  207. package/dist/src/tools/prompts/webSearchPrompt.js +17 -0
  208. package/dist/src/tools/prompts/webSearchPrompt.js.map +1 -0
  209. package/dist/src/tools/todo/TodoWriteTool.d.ts +20 -0
  210. package/dist/src/tools/todo/TodoWriteTool.d.ts.map +1 -0
  211. package/dist/src/tools/todo/TodoWriteTool.js +105 -0
  212. package/dist/src/tools/todo/TodoWriteTool.js.map +1 -0
  213. package/dist/src/types.d.ts +425 -3
  214. package/dist/src/types.d.ts.map +1 -1
  215. package/dist/src/types.js.map +1 -1
  216. package/dist/src/workflow/workflowEngine.js +26 -3
  217. package/dist/src/workflow/workflowEngine.js.map +1 -1
  218. package/dist/src/workspace/actoviqWorkspace.d.ts.map +1 -1
  219. package/dist/src/workspace/actoviqWorkspace.js +25 -2
  220. package/dist/src/workspace/actoviqWorkspace.js.map +1 -1
  221. package/package.json +59 -11
  222. package/vendor/actoviq-runtime/cli.js +54 -0
@@ -0,0 +1,427 @@
1
+ import { z } from 'zod';
2
+ import { tool } from '../runtime/tools.js';
3
+ import { webFetchPrompt } from './prompts/webFetchPrompt.js';
4
+ import { webSearchPrompt } from './prompts/webSearchPrompt.js';
5
+ const DEFAULT_FETCH_TIMEOUT = 15000;
6
+ const DEFAULT_MAX_CONTENT = 50000;
7
+ function createToolAbortSignal(timeoutMs, parentSignal) {
8
+ const controller = new AbortController();
9
+ let didTimeOut = false;
10
+ const timeout = setTimeout(() => {
11
+ didTimeOut = true;
12
+ controller.abort();
13
+ }, timeoutMs);
14
+ if (typeof timeout === 'object') {
15
+ timeout.unref?.();
16
+ }
17
+ const abortFromParent = () => controller.abort();
18
+ if (parentSignal?.aborted) {
19
+ abortFromParent();
20
+ }
21
+ else {
22
+ parentSignal?.addEventListener('abort', abortFromParent, { once: true });
23
+ }
24
+ return {
25
+ signal: controller.signal,
26
+ timedOut: () => didTimeOut,
27
+ cleanup: () => {
28
+ clearTimeout(timeout);
29
+ parentSignal?.removeEventListener('abort', abortFromParent);
30
+ },
31
+ };
32
+ }
33
+ function createWebFetch(options = {}) {
34
+ const timeoutMs = options.timeoutMs ?? DEFAULT_FETCH_TIMEOUT;
35
+ const maxContentLength = options.maxContentLength ?? DEFAULT_MAX_CONTENT;
36
+ return tool({
37
+ name: 'WebFetch',
38
+ description: 'Fetches content from a URL and processes it. ' +
39
+ 'The URL must be a fully-formed valid URL. HTTP URLs are upgraded to HTTPS. ' +
40
+ 'Provide a prompt to extract specific information from the page. ' +
41
+ 'IMPORTANT: You MUST never generate or guess URLs. ' +
42
+ 'Only use URLs provided by the user or found in previous tool results.',
43
+ inputSchema: z.object({
44
+ url: z.string().describe('The URL to fetch content from'),
45
+ prompt: z
46
+ .string()
47
+ .optional()
48
+ .describe('What information to extract from the page. If omitted, returns the full text content.'),
49
+ }),
50
+ isReadOnly: () => true,
51
+ serialize: (output) => output.isError
52
+ ? `Error fetching ${output.url}: ${output.error}`
53
+ : `Fetched ${output.url} (${output.contentLength} chars)`,
54
+ prompt: webFetchPrompt,
55
+ }, async (input, context, onProgress) => {
56
+ const url = normalizeUrl(input.url);
57
+ onProgress?.({
58
+ toolUseID: '',
59
+ data: { type: 'fetching', message: `Fetching ${url}`, url },
60
+ });
61
+ let abortSignal;
62
+ try {
63
+ abortSignal = createToolAbortSignal(timeoutMs, context.signal);
64
+ const response = await fetch(url, {
65
+ signal: abortSignal.signal,
66
+ headers: {
67
+ 'User-Agent': 'ActoviqAgent/1.0',
68
+ Accept: 'text/html, text/plain, */*',
69
+ },
70
+ redirect: 'follow',
71
+ });
72
+ if (!response.ok) {
73
+ return {
74
+ url,
75
+ content: '',
76
+ contentLength: 0,
77
+ isError: true,
78
+ error: `HTTP ${response.status} ${response.statusText}. The page could not be fetched. Try a different URL.`,
79
+ };
80
+ }
81
+ const contentType = response.headers.get('content-type') ?? '';
82
+ const raw = await response.text();
83
+ let content;
84
+ if (contentType.includes('text/html')) {
85
+ content = stripHtml(raw);
86
+ }
87
+ else {
88
+ content = raw;
89
+ }
90
+ if (content.length > maxContentLength) {
91
+ content = content.slice(0, maxContentLength) + '\n... (truncated)';
92
+ }
93
+ const resultText = input.prompt
94
+ ? `URL: ${url}\n\nContent:\n${content}`
95
+ : content;
96
+ return {
97
+ url,
98
+ content: resultText,
99
+ contentLength: resultText.length,
100
+ isError: false,
101
+ };
102
+ }
103
+ catch (err) {
104
+ const message = err instanceof Error ? err.message : String(err);
105
+ const isTimeout = abortSignal?.timedOut() ?? false;
106
+ return {
107
+ url,
108
+ content: '',
109
+ contentLength: 0,
110
+ isError: true,
111
+ error: isTimeout
112
+ ? `Request timed out after ${timeoutMs}ms. The server did not respond. Try a different URL.`
113
+ : `Fetch failed: ${message}`,
114
+ };
115
+ }
116
+ finally {
117
+ abortSignal?.cleanup();
118
+ }
119
+ });
120
+ }
121
+ const DEFAULT_SEARCH_TIMEOUT = 20000;
122
+ const DEFAULT_MAX_RESULTS = 5;
123
+ function createWebSearch(options = {}) {
124
+ const timeoutMs = options.timeoutMs ?? DEFAULT_SEARCH_TIMEOUT;
125
+ const maxResults = options.maxResults ?? DEFAULT_MAX_RESULTS;
126
+ return tool({
127
+ name: 'WebSearch',
128
+ description: 'Search the web and return results with titles, URLs, and snippets. ' +
129
+ 'IMPORTANT: You MUST include a "Sources:" section at the end of your response ' +
130
+ 'listing all relevant URLs from the search results as markdown hyperlinks.',
131
+ inputSchema: z.object({
132
+ query: z.string().min(2).describe('The search query'),
133
+ limit: z
134
+ .number()
135
+ .int()
136
+ .positive()
137
+ .optional()
138
+ .describe(`Maximum number of results. Defaults to ${maxResults}.`),
139
+ }),
140
+ isReadOnly: () => true,
141
+ serialize: (output) => output.isError
142
+ ? `Search error: ${output.error}`
143
+ : output.results.length === 0
144
+ ? `No results found for "${output.query}". Try a more specific or different query.`
145
+ : output.results
146
+ .map((r, i) => `${i + 1}. ${r.title}\n ${r.url}\n ${r.snippet}`)
147
+ .join('\n\n'),
148
+ prompt: webSearchPrompt,
149
+ }, async (input, context, onProgress) => {
150
+ const limit = input.limit ?? maxResults;
151
+ const query = input.query;
152
+ onProgress?.({
153
+ toolUseID: '',
154
+ data: { type: 'searching', message: `Searching for "${query}"`, query },
155
+ });
156
+ // ── Server-side search via API proxy (like Claude Code) ──
157
+ if (context.modelApi && context.provider !== 'openai') {
158
+ const serverResult = await tryServerSearch(query, limit, context);
159
+ if (serverResult && serverResult.results.length > 0) {
160
+ return serverResult;
161
+ }
162
+ // Server search failed with an actual error (not just empty results)
163
+ if (serverResult?.isError) {
164
+ // Fall through to local search
165
+ }
166
+ else if (serverResult && !serverResult.isError) {
167
+ return serverResult;
168
+ }
169
+ }
170
+ // ── Local search (DuckDuckGo) ──
171
+ const jsonResults = await tryJsonApi(query, limit, timeoutMs, context.signal);
172
+ if (jsonResults.results.length > 0) {
173
+ return jsonResults;
174
+ }
175
+ const htmlResults = await tryHtmlSearch(query, limit, timeoutMs, context.signal);
176
+ if (htmlResults.results.length > 0) {
177
+ return htmlResults;
178
+ }
179
+ const error = jsonResults.isError
180
+ ? jsonResults.error
181
+ : htmlResults.isError
182
+ ? htmlResults.error
183
+ : `No results found for "${query}"`;
184
+ return {
185
+ query,
186
+ results: [],
187
+ isError: true,
188
+ error,
189
+ };
190
+ });
191
+ }
192
+ async function tryServerSearch(query, limit, context) {
193
+ try {
194
+ const request = {
195
+ model: context.model ?? '',
196
+ messages: [
197
+ {
198
+ role: 'user',
199
+ content: `Perform a web search for the query: ${query}`,
200
+ },
201
+ ],
202
+ max_tokens: 4096,
203
+ system: 'You are an assistant for performing a web search tool use.',
204
+ extra_tool_schemas: [
205
+ { type: 'web_search_20250305', name: 'web_search', max_uses: 1 },
206
+ ],
207
+ tool_choice: { type: 'tool', name: 'web_search' },
208
+ signal: context.signal,
209
+ };
210
+ const message = await context.modelApi.createMessage(request);
211
+ // Extract web_search_tool_result blocks from the response
212
+ const results = [];
213
+ if (Array.isArray(message.content)) {
214
+ for (const block of message.content) {
215
+ if (block.type === 'web_search_tool_result' && Array.isArray(block.content)) {
216
+ for (const hit of block.content) {
217
+ if (results.length >= limit)
218
+ break;
219
+ if (hit.url) {
220
+ results.push({
221
+ title: hit.title ?? hit.url,
222
+ url: hit.url,
223
+ snippet: hit.snippet ?? '',
224
+ });
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ if (results.length === 0) {
231
+ // Server search returned no structured results — try extracting from text
232
+ const text = message.content
233
+ .filter((b) => b.type === 'text' && typeof b.text === 'string')
234
+ .map((b) => b.text)
235
+ .join('\n')
236
+ .slice(0, 2000);
237
+ return { query, results: [], isError: true, error: `Server search returned no results. Text: ${text.slice(0, 500)}` };
238
+ }
239
+ return {
240
+ query,
241
+ results: results.slice(0, limit),
242
+ isError: false,
243
+ };
244
+ }
245
+ catch (err) {
246
+ const message = err instanceof Error ? err.message : String(err);
247
+ return { query, results: [], isError: true, error: `Server search failed: ${message}` };
248
+ }
249
+ }
250
+ async function tryJsonApi(query, limit, timeoutMs, parentSignal) {
251
+ let abortSignal;
252
+ try {
253
+ abortSignal = createToolAbortSignal(timeoutMs, parentSignal);
254
+ const url = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_html=1&skip_disambig=1`;
255
+ const response = await fetch(url, {
256
+ signal: abortSignal.signal,
257
+ headers: { 'User-Agent': 'ActoviqAgent/1.0' },
258
+ });
259
+ if (!response.ok) {
260
+ return { query, results: [], isError: true, error: `HTTP ${response.status}` };
261
+ }
262
+ const data = (await response.json());
263
+ const results = [];
264
+ // Abstract (instant answer)
265
+ if (data.AbstractText && data.AbstractURL) {
266
+ results.push({
267
+ title: data.Heading || data.AbstractSource || 'Result',
268
+ url: data.AbstractURL,
269
+ snippet: data.AbstractText.slice(0, 300),
270
+ });
271
+ }
272
+ // Related topics
273
+ for (const topic of data.RelatedTopics ?? []) {
274
+ if (results.length >= limit)
275
+ break;
276
+ if (!topic.FirstURL || !topic.Text)
277
+ continue;
278
+ results.push({
279
+ title: topic.Text.split(' - ')[0]?.slice(0, 80) ?? topic.Text.slice(0, 80),
280
+ url: topic.FirstURL,
281
+ snippet: topic.Text.slice(0, 200),
282
+ });
283
+ }
284
+ // Results array
285
+ if (data.Results) {
286
+ for (const item of data.Results) {
287
+ if (results.length >= limit)
288
+ break;
289
+ if (!item.FirstURL || !item.Text)
290
+ continue;
291
+ // Dedup
292
+ if (results.some((r) => r.url === item.FirstURL))
293
+ continue;
294
+ results.push({
295
+ title: item.Text.split(' - ')[0]?.slice(0, 80) ?? item.Text.slice(0, 80),
296
+ url: item.FirstURL,
297
+ snippet: item.Text.slice(0, 200),
298
+ });
299
+ }
300
+ }
301
+ if (results.length === 0) {
302
+ return { query, results: [], isError: true, error: 'No results found from search API.' };
303
+ }
304
+ return { query, results: results.slice(0, limit), isError: false };
305
+ }
306
+ catch (err) {
307
+ const message = err instanceof Error ? err.message : String(err);
308
+ return { query, results: [], isError: true, error: `Search API failed: ${message}` };
309
+ }
310
+ finally {
311
+ abortSignal?.cleanup();
312
+ }
313
+ }
314
+ async function tryHtmlSearch(query, limit, timeoutMs, parentSignal) {
315
+ let abortSignal;
316
+ try {
317
+ abortSignal = createToolAbortSignal(timeoutMs, parentSignal);
318
+ const url = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
319
+ const response = await fetch(url, {
320
+ signal: abortSignal.signal,
321
+ headers: { 'User-Agent': 'ActoviqAgent/1.0' },
322
+ });
323
+ if (!response.ok) {
324
+ return { query, results: [], isError: true, error: `HTTP ${response.status}` };
325
+ }
326
+ const html = await response.text();
327
+ const results = parseHtmlSearchResults(html, limit);
328
+ if (results.length === 0) {
329
+ return { query, results: [], isError: true, error: 'No results parsed from search page.' };
330
+ }
331
+ return { query, results, isError: false };
332
+ }
333
+ catch (err) {
334
+ const message = err instanceof Error ? err.message : String(err);
335
+ return { query, results: [], isError: true, error: `HTML search failed: ${message}` };
336
+ }
337
+ finally {
338
+ abortSignal?.cleanup();
339
+ }
340
+ }
341
+ export function createActoviqWebTools(options = {}) {
342
+ return [createWebFetch(options.webFetch), createWebSearch(options.webSearch)];
343
+ }
344
+ // ── HTML helpers ──────────────────────────────────────────────────
345
+ function stripHtml(html) {
346
+ return html
347
+ .replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '')
348
+ .replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '')
349
+ .replace(/<[^>]+>/g, ' ')
350
+ .replace(/&amp;/g, '&')
351
+ .replace(/&lt;/g, '<')
352
+ .replace(/&gt;/g, '>')
353
+ .replace(/&quot;/g, '"')
354
+ .replace(/&#39;/g, "'")
355
+ .replace(/&nbsp;/g, ' ')
356
+ .replace(/\s+/g, ' ')
357
+ .replace(/\n\s*\n/g, '\n')
358
+ .trim();
359
+ }
360
+ function parseHtmlSearchResults(html, limit) {
361
+ const results = [];
362
+ // html.duckduckgo.com returns results in:
363
+ // <a rel="nofollow" class="result__a" href="...">title</a>
364
+ // <a class="result__snippet">snippet</a>
365
+ const linkPattern = /<a[^>]*class="[^"]*result__a[^"]*"[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi;
366
+ const snippetPattern = /<a[^>]*class="[^"]*result__snippet[^"]*"[^>]*>([\s\S]*?)<\/a>/gi;
367
+ const linkMatches = [...html.matchAll(linkPattern)];
368
+ const snippetMatches = [...html.matchAll(snippetPattern)];
369
+ for (let i = 0; i < linkMatches.length && results.length < limit; i++) {
370
+ const link = linkMatches[i];
371
+ const snippet = snippetMatches[i];
372
+ if (!link?.[1])
373
+ continue;
374
+ const url = decodeURIComponent(new URL(link[1], 'https://html.duckduckgo.com').searchParams.get('uddg') ?? link[1]);
375
+ if (!url.startsWith('http'))
376
+ continue;
377
+ const title = stripHtml(decodeHtmlEntities(link[2]?.trim() ?? ''));
378
+ if (!title || title.length < 2)
379
+ continue;
380
+ results.push({
381
+ title,
382
+ url,
383
+ snippet: snippet?.[1]
384
+ ? stripHtml(decodeHtmlEntities(snippet[1].trim())).slice(0, 200)
385
+ : url,
386
+ });
387
+ }
388
+ // Fallback: generic link extraction
389
+ if (results.length === 0) {
390
+ const genericLinks = html.match(/<a[^>]*href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi) ?? [];
391
+ for (const rawLink of genericLinks) {
392
+ if (results.length >= limit)
393
+ break;
394
+ const href = rawLink.match(/href="([^"]*)"/)?.[1];
395
+ const text = rawLink.match(/>([\s\S]*?)</)?.[1];
396
+ if (!href || !text)
397
+ continue;
398
+ const url = decodeURIComponent(new URL(href, 'https://html.duckduckgo.com').searchParams.get('uddg') ?? href);
399
+ if (!url.startsWith('http'))
400
+ continue;
401
+ const cleanText = stripHtml(decodeHtmlEntities(text.trim()));
402
+ if (cleanText.length < 3)
403
+ continue;
404
+ results.push({ title: cleanText.slice(0, 80), url, snippet: url });
405
+ }
406
+ }
407
+ return results;
408
+ }
409
+ function decodeHtmlEntities(text) {
410
+ return text
411
+ .replace(/&amp;/g, '&')
412
+ .replace(/&lt;/g, '<')
413
+ .replace(/&gt;/g, '>')
414
+ .replace(/&quot;/g, '"')
415
+ .replace(/&#39;/g, "'")
416
+ .replace(/&#x27;/g, "'")
417
+ .replace(/&nbsp;/g, ' ');
418
+ }
419
+ function normalizeUrl(rawUrl) {
420
+ let url = rawUrl.trim();
421
+ if (/^https?:\/\//i.test(url))
422
+ return url;
423
+ if (url.startsWith('//'))
424
+ return `https:${url}`;
425
+ return `https://${url}`;
426
+ }
427
+ //# sourceMappingURL=actoviqWebTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actoviqWebTools.js","sourceRoot":"","sources":["../../../src/tools/actoviqWebTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAQ3C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAS/D,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,SAAS,qBAAqB,CAC5B,SAAiB,EACjB,YAA0B;IAE1B,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;QAC9B,UAAU,GAAG,IAAI,CAAC;QAClB,UAAU,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC,EAAE,SAAS,CAAC,CAAC;IACd,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;IACpB,CAAC;IACD,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAEjD,IAAI,YAAY,EAAE,OAAO,EAAE,CAAC;QAC1B,eAAe,EAAE,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,YAAY,EAAE,gBAAgB,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,OAAO;QACL,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,QAAQ,EAAE,GAAG,EAAE,CAAC,UAAU;QAC1B,OAAO,EAAE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AAY;IACtC,OAAO,IAAI;SACR,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;IACxB,IAAI,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAC1C,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,GAAG,EAAE,CAAC;IAChD,OAAO,WAAW,GAAG,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { AgentToolDefinition } from '../../types.js';
2
+ export declare const ASK_USER_QUESTION_TOOL_NAME = "AskUserQuestion";
3
+ export declare const ASK_USER_QUESTION_PROMPT = "Use this tool when you need to ask the user questions during execution. This allows you to:\n1. Gather user preferences or requirements\n2. Clarify ambiguous instructions\n3. Get decisions on implementation choices as you work\n4. Offer choices to the user about what direction to take.\n\nUsage notes:\n- Users will always be able to select \"Other\" to provide custom text input\n- Use multiSelect: true to allow multiple answers to be selected for a question\n- If you recommend a specific option, make it the first option and add \"(Recommended)\" at the end\n\nPlan mode note: Use to clarify requirements or choose between approaches BEFORE finalizing your plan.\nPreview feature: Use the optional preview field on options when presenting concrete artifacts.";
4
+ export declare const ASK_USER_QUESTION_DESCRIPTION = "Ask the user multiple-choice questions. Use for gathering preferences, clarifying ambiguous instructions, or getting decisions on implementation choices.";
5
+ export declare function createAskUserQuestionTool(): AgentToolDefinition;
6
+ //# sourceMappingURL=AskUserQuestionTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AskUserQuestionTool.d.ts","sourceRoot":"","sources":["../../../../src/tools/askUserQuestion/AskUserQuestionTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAe7D,eAAO,MAAM,wBAAwB,gwBAY0D,CAAC;AAEhG,eAAO,MAAM,6BAA6B,8JACmH,CAAC;AAE9J,wBAAgB,yBAAyB,IAAI,mBAAmB,CAgB/D"}
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ import { tool } from '../../runtime/tools.js';
3
+ export const ASK_USER_QUESTION_TOOL_NAME = 'AskUserQuestion';
4
+ const QuestionOptionSchema = z.object({
5
+ label: z.string().describe('The display text for this option (1-5 words).'),
6
+ description: z.string().describe('Explanation of what this option means.'),
7
+ preview: z.string().optional().describe('Optional preview content rendered when focused (mockups, code snippets, etc.).'),
8
+ });
9
+ const QuestionSchema = z.object({
10
+ question: z.string().describe('The complete question to ask. Should be clear, specific, and end with a question mark.'),
11
+ header: z.string().describe('Very short label displayed as a chip/tag (max 12 chars). Examples: "Auth method", "Library", "Approach".'),
12
+ options: z.array(QuestionOptionSchema).min(2).max(4).describe('Available choices (2-4 options). Each should be distinct, mutually exclusive (unless multiSelect). No "Other" option — provided automatically.'),
13
+ multiSelect: z.boolean().default(false).describe('Set to true to allow multiple selections.'),
14
+ });
15
+ export const ASK_USER_QUESTION_PROMPT = `Use this tool when you need to ask the user questions during execution. This allows you to:
16
+ 1. Gather user preferences or requirements
17
+ 2. Clarify ambiguous instructions
18
+ 3. Get decisions on implementation choices as you work
19
+ 4. Offer choices to the user about what direction to take.
20
+
21
+ Usage notes:
22
+ - Users will always be able to select "Other" to provide custom text input
23
+ - Use multiSelect: true to allow multiple answers to be selected for a question
24
+ - If you recommend a specific option, make it the first option and add "(Recommended)" at the end
25
+
26
+ Plan mode note: Use to clarify requirements or choose between approaches BEFORE finalizing your plan.
27
+ Preview feature: Use the optional preview field on options when presenting concrete artifacts.`;
28
+ export const ASK_USER_QUESTION_DESCRIPTION = 'Ask the user multiple-choice questions. Use for gathering preferences, clarifying ambiguous instructions, or getting decisions on implementation choices.';
29
+ export function createAskUserQuestionTool() {
30
+ return tool({
31
+ name: ASK_USER_QUESTION_TOOL_NAME,
32
+ description: ASK_USER_QUESTION_DESCRIPTION,
33
+ inputSchema: z.strictObject({
34
+ questions: z.array(QuestionSchema).min(1).max(4).describe('Questions to ask the user (1-4 questions)'),
35
+ answers: z.record(z.string(), z.string()).optional().describe('User answers collected by the permission component'),
36
+ }),
37
+ isReadOnly: () => true,
38
+ prompt: () => ASK_USER_QUESTION_PROMPT,
39
+ }, async ({ questions, answers }) => {
40
+ return { questions, answers: answers ?? {} };
41
+ });
42
+ }
43
+ //# sourceMappingURL=AskUserQuestionTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AskUserQuestionTool.js","sourceRoot":"","sources":["../../../../src/tools/askUserQuestion/AskUserQuestionTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAG9C,MAAM,CAAC,MAAM,2BAA2B,GAAG,iBAAiB,CAAC;AAE7D,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;IAC3E,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;IAC1E,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gFAAgF,CAAC;CAC1H,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,Q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C/C,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { z } from 'zod';
2
+ import type { AgentToolDefinition } from '../../types.js';
3
+ export declare const BASH_TOOL_NAME = "Bash";
4
+ declare const inputSchema: z.ZodObject<{
5
+ command: z.ZodString;
6
+ timeout: z.ZodOptional<z.ZodNumber>;
7
+ description: z.ZodOptional<z.ZodString>;
8
+ run_in_background: z.ZodOptional<z.ZodBoolean>;
9
+ dangerouslyDisableSandbox: z.ZodOptional<z.ZodBoolean>;
10
+ }, z.core.$strict>;
11
+ export type BashInput = z.infer<typeof inputSchema>;
12
+ export declare function createBashTool(): AgentToolDefinition;
13
+ export {};
14
+ //# sourceMappingURL=BashTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BashTool.d.ts","sourceRoot":"","sources":["../../../../src/tools/bash/BashTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,QAAA,MAAM,WAAW;;;;;;kBAgBf,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEpD,wBAAgB,cAAc,IAAI,mBAAmB,CAyCpD"}
@@ -0,0 +1,60 @@
1
+ import { z } from 'zod';
2
+ import { execSync, spawn } from 'node:child_process';
3
+ import { tool } from '../../runtime/tools.js';
4
+ import { BASH_DESCRIPTION } from './prompt.js';
5
+ export const BASH_TOOL_NAME = 'Bash';
6
+ const inputSchema = z.strictObject({
7
+ command: z.string().describe('The command to execute'),
8
+ timeout: z.number().optional().describe('Optional timeout in milliseconds (max 600000)'),
9
+ description: z.string().optional().describe('Clear, concise description of what this command does in active voice.\n\n' +
10
+ 'For simple commands (git, npm, standard CLI tools), keep it brief (5-10 words):\n' +
11
+ '- ls → "List files in current directory"\n' +
12
+ '- git status → "Show working tree status"\n' +
13
+ '- npm install → "Install package dependencies"\n\n' +
14
+ 'For commands that are harder to parse at a glance (piped commands, obscure flags, etc.), add enough context to clarify what it does:\n' +
15
+ '- find . -name "*.tmp" -exec rm {} \\; → "Find and delete all .tmp files recursively"\n' +
16
+ '- git reset --hard origin/main → "Discard all local changes and match remote main"\n' +
17
+ '- curl -s url | jq \'.data[]\' → "Fetch JSON from URL and extract data array elements"'),
18
+ run_in_background: z.boolean().optional().describe('Set to true to run this command in the background. Use Read to read the output later.'),
19
+ dangerouslyDisableSandbox: z.boolean().optional().describe('Set this to true to override sandbox mode and run commands without sandboxing.'),
20
+ });
21
+ export function createBashTool() {
22
+ return tool({
23
+ name: BASH_TOOL_NAME,
24
+ description: BASH_DESCRIPTION,
25
+ inputSchema,
26
+ isDestructive: () => true,
27
+ prompt: () => BASH_DESCRIPTION,
28
+ }, async (input, context) => {
29
+ const timeoutMs = Math.min(Math.max(1, input.timeout ?? 120_000), 600_000);
30
+ try {
31
+ if (input.run_in_background) {
32
+ // For background execution, spawn detached and return immediately
33
+ const child = spawn(input.command, {
34
+ cwd: context.cwd,
35
+ shell: true,
36
+ stdio: 'ignore',
37
+ detached: true,
38
+ });
39
+ child.unref();
40
+ return { stdout: '', stderr: '', exitCode: 0, backgroundTaskId: child.pid?.toString() };
41
+ }
42
+ const output = execSync(input.command, {
43
+ cwd: context.cwd,
44
+ encoding: 'utf-8',
45
+ timeout: timeoutMs,
46
+ maxBuffer: 10 * 1024 * 1024, // 10MB
47
+ stdio: ['ignore', 'pipe', 'pipe'],
48
+ });
49
+ return { stdout: output.trim(), stderr: '', exitCode: 0 };
50
+ }
51
+ catch (e) {
52
+ return {
53
+ stdout: (e.stdout ?? '').trim(),
54
+ stderr: (e.stderr ?? e.message ?? String(e)).trim(),
55
+ exitCode: e.status ?? 1,
56
+ };
57
+ }
58
+ });
59
+ }
60
+ //# sourceMappingURL=BashTool.js.map
@@ -0,0 +1 @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C,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;gBACnD,QAAQ,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC;aACxB,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare const BASH_TOOL_NAME = "Bash";
2
+ export declare const BASH_DESCRIPTION = "Executes a given bash command and returns its output.\n\nThe working directory persists between commands, but shell state does not. The shell environment is initialized from the user's profile (bash or zsh).\n\nIMPORTANT: Avoid using this tool to run `find`, `grep`, `cat`, `head`, `tail`, `sed`, `awk`, or `echo` commands, unless explicitly instructed or after you have verified that a dedicated tool cannot accomplish your task. Instead, use the appropriate dedicated tool as this will provide a much better experience for the user:\n\n- File search: Use Glob (NOT find or ls)\n- Content search: Use Grep (NOT grep or rg)\n- Read files: Use Read (NOT cat/head/tail)\n- Edit files: Use Edit (NOT sed/awk)\n- Write files: Use Write (NOT echo >/cat <<EOF)\n- Communication: Output text directly (NOT echo/printf)\n\nWhile the Bash tool can do similar things, it's better to use the built-in tools as they provide a better user experience and make it easier to review tool calls and give permission.\n\n# Instructions\n\n- If your command will create new directories or files, first use this tool to run `ls` to verify the parent directory exists and is the correct location.\n- Always quote file paths that contain spaces with double quotes in your command (e.g., cd \"path with spaces/file.txt\")\n- Try to maintain your current working directory throughout the session by using absolute paths and avoiding usage of `cd`. You may use `cd` if the User explicitly requests it.\n- You may specify an optional timeout in milliseconds (up to 600000ms / 10 minutes). By default, your command will timeout after 120000ms (2 minutes).\n- You can use the `run_in_background` parameter to run the command in the background. Only use this if you don't need the result immediately and are OK being notified when the command completes later. You do not need to check the output right away - you'll be notified when it finishes. You do not need to use '&' at the end of the command when using this parameter.\n- When issuing multiple commands:\n - If the commands are independent and can run in parallel, make multiple Bash tool calls in a single message. Example: if you need to run \"git status\" and \"git diff\", send a single message with two Bash tool calls in parallel.\n - If the commands depend on each other and must run sequentially, use a single Bash call with '&&' to chain them together.\n - Use ';' only when you need to run commands sequentially but don't care if earlier commands fail.\n - DO NOT use newlines to separate commands (newlines are ok in quoted strings).\n- For git commands:\n - Prefer to create a new commit rather than amending an existing commit.\n - Before running destructive operations (e.g., git reset --hard, git push --force, git checkout --), consider whether there is a safer alternative that achieves the same goal. Only use destructive operations when they are truly the best approach.\n - Never skip hooks (--no-verify) or bypass signing (--no-gpg-sign, -c commit.gpgsign=false) unless the user has explicitly asked for it. If a hook fails, investigate and fix the underlying issue.\n- Avoid unnecessary `sleep` commands:\n - Do not sleep between commands that can run immediately \u2014 just run them.\n - If your command is long running and you would like to be notified when it finishes \u2014 use `run_in_background`. No sleep needed.\n - Do not retry failing commands in a sleep loop \u2014 diagnose the root cause.\n - If waiting for a background task you started with `run_in_background`, you will be notified when it completes \u2014 do not poll.\n - If you must poll an external process, use a check command rather than sleeping first.\n - If you must sleep, keep the duration short to avoid blocking the user.\n\n# Committing changes with git\n\nOnly create commits when requested by the user. If unclear, ask first. When the user asks you to create a new git commit, follow these steps carefully:\n\nGit Safety Protocol:\n- NEVER update the git config\n- NEVER run destructive git commands (push --force, reset --hard, checkout ., restore ., clean -f, branch -D) unless the user explicitly requests these actions.\n- NEVER skip hooks (--no-verify, --no-gpg-sign, etc) unless the user explicitly requests it\n- NEVER run force push to main/master, warn the user if they request it\n- CRITICAL: Always create NEW commits rather than amending, unless the user explicitly requests a git amend.\n- When staging files, prefer adding specific files by name rather than using \"git add -A\" or \"git add .\"\n- NEVER commit changes unless the user explicitly asks you to.\n\n1. Run the following bash commands in parallel:\n - git status to see all untracked files (never use -uall flag)\n - git diff to see both staged and unstaged changes\n - git log to see recent commit messages\n2. Draft a commit message (1-2 sentences) focusing on \"why\" rather than \"what\"\n3. Create the commit and run git status to verify.\n4. If the commit fails due to pre-commit hook: fix the issue and create a NEW commit\n\nImportant: NEVER use git commands with the -i flag since they require interactive input. If there are no changes to commit, do not create an empty commit. ALWAYS pass the commit message via a HEREDOC.";
3
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/tools/bash/prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,eAAO,MAAM,gBAAgB,+oKA4D4K,CAAC"}