@puukis/core 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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/dist/brain/Brain.d.ts +39 -0
  3. package/dist/brain/Brain.d.ts.map +1 -0
  4. package/dist/brain/Brain.js +284 -0
  5. package/dist/brain/Brain.js.map +1 -0
  6. package/dist/brain/index.d.ts +2 -0
  7. package/dist/brain/index.d.ts.map +1 -0
  8. package/dist/brain/index.js +2 -0
  9. package/dist/brain/index.js.map +1 -0
  10. package/dist/cli/argv.d.ts +8 -0
  11. package/dist/cli/argv.d.ts.map +1 -0
  12. package/dist/cli/argv.js +41 -0
  13. package/dist/cli/argv.js.map +1 -0
  14. package/dist/cli/codexInstall.d.ts +17 -0
  15. package/dist/cli/codexInstall.d.ts.map +1 -0
  16. package/dist/cli/codexInstall.js +106 -0
  17. package/dist/cli/codexInstall.js.map +1 -0
  18. package/dist/cli/commands/auth.d.ts +3 -0
  19. package/dist/cli/commands/auth.d.ts.map +1 -0
  20. package/dist/cli/commands/auth.js +66 -0
  21. package/dist/cli/commands/auth.js.map +1 -0
  22. package/dist/cli/commands/install.d.ts +3 -0
  23. package/dist/cli/commands/install.d.ts.map +1 -0
  24. package/dist/cli/commands/install.js +21 -0
  25. package/dist/cli/commands/install.js.map +1 -0
  26. package/dist/cli/commands/onboard.d.ts +3 -0
  27. package/dist/cli/commands/onboard.d.ts.map +1 -0
  28. package/dist/cli/commands/onboard.js +43 -0
  29. package/dist/cli/commands/onboard.js.map +1 -0
  30. package/dist/cli/commands/uninstall.d.ts +3 -0
  31. package/dist/cli/commands/uninstall.d.ts.map +1 -0
  32. package/dist/cli/commands/uninstall.js +193 -0
  33. package/dist/cli/commands/uninstall.js.map +1 -0
  34. package/dist/cli/commands/update.d.ts +3 -0
  35. package/dist/cli/commands/update.d.ts.map +1 -0
  36. package/dist/cli/commands/update.js +314 -0
  37. package/dist/cli/commands/update.js.map +1 -0
  38. package/dist/cli/index.d.ts +3 -0
  39. package/dist/cli/index.d.ts.map +1 -0
  40. package/dist/cli/index.js +60 -0
  41. package/dist/cli/index.js.map +1 -0
  42. package/dist/codex/CodexRpcClient.d.ts +65 -0
  43. package/dist/codex/CodexRpcClient.d.ts.map +1 -0
  44. package/dist/codex/CodexRpcClient.js +395 -0
  45. package/dist/codex/CodexRpcClient.js.map +1 -0
  46. package/dist/codex/codexModels.d.ts +33 -0
  47. package/dist/codex/codexModels.d.ts.map +1 -0
  48. package/dist/codex/codexModels.js +226 -0
  49. package/dist/codex/codexModels.js.map +1 -0
  50. package/dist/codex/index.d.ts +5 -0
  51. package/dist/codex/index.d.ts.map +1 -0
  52. package/dist/codex/index.js +3 -0
  53. package/dist/codex/index.js.map +1 -0
  54. package/dist/codex/types.d.ts +97 -0
  55. package/dist/codex/types.d.ts.map +1 -0
  56. package/dist/codex/types.js +2 -0
  57. package/dist/codex/types.js.map +1 -0
  58. package/dist/config/env.d.ts +8 -0
  59. package/dist/config/env.d.ts.map +1 -0
  60. package/dist/config/env.js +130 -0
  61. package/dist/config/env.js.map +1 -0
  62. package/dist/config/index.d.ts +2 -0
  63. package/dist/config/index.d.ts.map +1 -0
  64. package/dist/config/index.js +2 -0
  65. package/dist/config/index.js.map +1 -0
  66. package/dist/db/index.d.ts +48 -0
  67. package/dist/db/index.d.ts.map +1 -0
  68. package/dist/db/index.js +147 -0
  69. package/dist/db/index.js.map +1 -0
  70. package/dist/gateway/Gateway.d.ts +69 -0
  71. package/dist/gateway/Gateway.d.ts.map +1 -0
  72. package/dist/gateway/Gateway.js +239 -0
  73. package/dist/gateway/Gateway.js.map +1 -0
  74. package/dist/gateway/LaneQueue.d.ts +24 -0
  75. package/dist/gateway/LaneQueue.d.ts.map +1 -0
  76. package/dist/gateway/LaneQueue.js +59 -0
  77. package/dist/gateway/LaneQueue.js.map +1 -0
  78. package/dist/gateway/index.d.ts +3 -0
  79. package/dist/gateway/index.d.ts.map +1 -0
  80. package/dist/gateway/index.js +3 -0
  81. package/dist/gateway/index.js.map +1 -0
  82. package/dist/index.d.ts +13 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +14 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/llm/GeminiProvider.d.ts +16 -0
  87. package/dist/llm/GeminiProvider.d.ts.map +1 -0
  88. package/dist/llm/GeminiProvider.js +172 -0
  89. package/dist/llm/GeminiProvider.js.map +1 -0
  90. package/dist/llm/OllamaProvider.d.ts +15 -0
  91. package/dist/llm/OllamaProvider.d.ts.map +1 -0
  92. package/dist/llm/OllamaProvider.js +108 -0
  93. package/dist/llm/OllamaProvider.js.map +1 -0
  94. package/dist/llm/OpenAICodexProvider.d.ts +51 -0
  95. package/dist/llm/OpenAICodexProvider.d.ts.map +1 -0
  96. package/dist/llm/OpenAICodexProvider.js +620 -0
  97. package/dist/llm/OpenAICodexProvider.js.map +1 -0
  98. package/dist/llm/OpenAIProvider.d.ts +16 -0
  99. package/dist/llm/OpenAIProvider.d.ts.map +1 -0
  100. package/dist/llm/OpenAIProvider.js +134 -0
  101. package/dist/llm/OpenAIProvider.js.map +1 -0
  102. package/dist/llm/index.d.ts +10 -0
  103. package/dist/llm/index.d.ts.map +1 -0
  104. package/dist/llm/index.js +30 -0
  105. package/dist/llm/index.js.map +1 -0
  106. package/dist/main.d.ts +7 -0
  107. package/dist/main.d.ts.map +1 -0
  108. package/dist/main.js +88 -0
  109. package/dist/main.js.map +1 -0
  110. package/dist/pipeline/index.d.ts +2 -0
  111. package/dist/pipeline/index.d.ts.map +1 -0
  112. package/dist/pipeline/index.js +2 -0
  113. package/dist/pipeline/index.js.map +1 -0
  114. package/dist/pipeline/normalize.d.ts +19 -0
  115. package/dist/pipeline/normalize.d.ts.map +1 -0
  116. package/dist/pipeline/normalize.js +34 -0
  117. package/dist/pipeline/normalize.js.map +1 -0
  118. package/dist/server/index.d.ts +28 -0
  119. package/dist/server/index.d.ts.map +1 -0
  120. package/dist/server/index.js +389 -0
  121. package/dist/server/index.js.map +1 -0
  122. package/dist/tools/ToolExecutor.d.ts +68 -0
  123. package/dist/tools/ToolExecutor.d.ts.map +1 -0
  124. package/dist/tools/ToolExecutor.js +177 -0
  125. package/dist/tools/ToolExecutor.js.map +1 -0
  126. package/dist/tools/builtin/browser.d.ts +27 -0
  127. package/dist/tools/builtin/browser.d.ts.map +1 -0
  128. package/dist/tools/builtin/browser.js +222 -0
  129. package/dist/tools/builtin/browser.js.map +1 -0
  130. package/dist/tools/builtin/filesystem.d.ts +22 -0
  131. package/dist/tools/builtin/filesystem.d.ts.map +1 -0
  132. package/dist/tools/builtin/filesystem.js +151 -0
  133. package/dist/tools/builtin/filesystem.js.map +1 -0
  134. package/dist/tools/builtin/index.d.ts +10 -0
  135. package/dist/tools/builtin/index.d.ts.map +1 -0
  136. package/dist/tools/builtin/index.js +21 -0
  137. package/dist/tools/builtin/index.js.map +1 -0
  138. package/dist/tools/builtin/sandbox.d.ts +11 -0
  139. package/dist/tools/builtin/sandbox.d.ts.map +1 -0
  140. package/dist/tools/builtin/sandbox.js +166 -0
  141. package/dist/tools/builtin/sandbox.js.map +1 -0
  142. package/dist/tools/builtin/search.d.ts +7 -0
  143. package/dist/tools/builtin/search.d.ts.map +1 -0
  144. package/dist/tools/builtin/search.js +76 -0
  145. package/dist/tools/builtin/search.js.map +1 -0
  146. package/dist/tools/builtin/shell.d.ts +7 -0
  147. package/dist/tools/builtin/shell.d.ts.map +1 -0
  148. package/dist/tools/builtin/shell.js +71 -0
  149. package/dist/tools/builtin/shell.js.map +1 -0
  150. package/dist/tools/index.d.ts +3 -0
  151. package/dist/tools/index.d.ts.map +1 -0
  152. package/dist/tools/index.js +3 -0
  153. package/dist/tools/index.js.map +1 -0
  154. package/dist/types.d.ts +167 -0
  155. package/dist/types.d.ts.map +1 -0
  156. package/dist/types.js +3 -0
  157. package/dist/types.js.map +1 -0
  158. package/dist/workspace/agentWorkspace.d.ts +24 -0
  159. package/dist/workspace/agentWorkspace.d.ts.map +1 -0
  160. package/dist/workspace/agentWorkspace.js +210 -0
  161. package/dist/workspace/agentWorkspace.js.map +1 -0
  162. package/package.json +45 -0
@@ -0,0 +1,27 @@
1
+ import type { Tool } from '../../types.js';
2
+ /**
3
+ * Navigate to a URL
4
+ */
5
+ export declare const navigateTool: Tool;
6
+ /**
7
+ * Take a screenshot
8
+ */
9
+ export declare const screenshotTool: Tool;
10
+ /**
11
+ * Click an element
12
+ */
13
+ export declare const clickTool: Tool;
14
+ /**
15
+ * Type text into an element
16
+ */
17
+ export declare const typeTool: Tool;
18
+ /**
19
+ * Get page content/text
20
+ */
21
+ export declare const getContentTool: Tool;
22
+ /**
23
+ * Close the browser
24
+ */
25
+ export declare function closeBrowser(): Promise<void>;
26
+ export declare const browserTools: Tool[];
27
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/tools/builtin/browser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,gBAAgB,CAAC;AAqBvD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,IA8B1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,IAmC5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,IA6BvB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,IAkCtB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,IAmC5B,CAAC;AAEF;;GAEG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAMlD;AAED,eAAO,MAAM,YAAY,EAAE,IAAI,EAM9B,CAAC"}
@@ -0,0 +1,222 @@
1
+ import { chromium } from 'playwright';
2
+ // Singleton browser instance
3
+ let browser = null;
4
+ let currentPage = null;
5
+ async function getBrowser() {
6
+ if (!browser) {
7
+ browser = await chromium.launch({ headless: true });
8
+ }
9
+ return browser;
10
+ }
11
+ async function getPage() {
12
+ if (!currentPage || currentPage.isClosed()) {
13
+ const b = await getBrowser();
14
+ currentPage = await b.newPage();
15
+ }
16
+ return currentPage;
17
+ }
18
+ /**
19
+ * Navigate to a URL
20
+ */
21
+ export const navigateTool = {
22
+ name: 'browser_navigate',
23
+ description: 'Navigate the browser to a URL',
24
+ parameters: {
25
+ type: 'object',
26
+ properties: {
27
+ url: {
28
+ type: 'string',
29
+ description: 'The URL to navigate to',
30
+ },
31
+ },
32
+ required: ['url'],
33
+ },
34
+ requiresConfirmation: false,
35
+ type: 'browser',
36
+ handler: async (args) => {
37
+ const url = args['url'];
38
+ try {
39
+ const page = await getPage();
40
+ await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
41
+ const title = await page.title();
42
+ return { success: true, output: `Navigated to: ${title} (${url})` };
43
+ }
44
+ catch (error) {
45
+ return {
46
+ success: false,
47
+ output: '',
48
+ error: error instanceof Error ? error.message : 'Navigation failed',
49
+ };
50
+ }
51
+ },
52
+ };
53
+ /**
54
+ * Take a screenshot
55
+ */
56
+ export const screenshotTool = {
57
+ name: 'browser_screenshot',
58
+ description: 'Take a screenshot of the current page',
59
+ parameters: {
60
+ type: 'object',
61
+ properties: {
62
+ path: {
63
+ type: 'string',
64
+ description: 'Path to save the screenshot (optional, defaults to temp file)',
65
+ },
66
+ fullPage: {
67
+ type: 'boolean',
68
+ description: 'Whether to take a full page screenshot (default: false)',
69
+ },
70
+ },
71
+ required: [],
72
+ },
73
+ requiresConfirmation: false,
74
+ type: 'browser',
75
+ handler: async (args) => {
76
+ try {
77
+ const page = await getPage();
78
+ const outputPath = args['path'] || `/tmp/screenshot-${Date.now()}.png`;
79
+ const fullPage = args['fullPage'] ?? false;
80
+ await page.screenshot({ path: outputPath, fullPage });
81
+ return { success: true, output: `Screenshot saved to: ${outputPath}` };
82
+ }
83
+ catch (error) {
84
+ return {
85
+ success: false,
86
+ output: '',
87
+ error: error instanceof Error ? error.message : 'Screenshot failed',
88
+ };
89
+ }
90
+ },
91
+ };
92
+ /**
93
+ * Click an element
94
+ */
95
+ export const clickTool = {
96
+ name: 'browser_click',
97
+ description: 'Click an element on the page using a CSS selector',
98
+ parameters: {
99
+ type: 'object',
100
+ properties: {
101
+ selector: {
102
+ type: 'string',
103
+ description: 'CSS selector for the element to click',
104
+ },
105
+ },
106
+ required: ['selector'],
107
+ },
108
+ requiresConfirmation: true,
109
+ type: 'browser',
110
+ handler: async (args) => {
111
+ const selector = args['selector'];
112
+ try {
113
+ const page = await getPage();
114
+ await page.click(selector, { timeout: 10000 });
115
+ return { success: true, output: `Clicked element: ${selector}` };
116
+ }
117
+ catch (error) {
118
+ return {
119
+ success: false,
120
+ output: '',
121
+ error: error instanceof Error ? error.message : 'Click failed',
122
+ };
123
+ }
124
+ },
125
+ };
126
+ /**
127
+ * Type text into an element
128
+ */
129
+ export const typeTool = {
130
+ name: 'browser_type',
131
+ description: 'Type text into an input element',
132
+ parameters: {
133
+ type: 'object',
134
+ properties: {
135
+ selector: {
136
+ type: 'string',
137
+ description: 'CSS selector for the input element',
138
+ },
139
+ text: {
140
+ type: 'string',
141
+ description: 'Text to type',
142
+ },
143
+ },
144
+ required: ['selector', 'text'],
145
+ },
146
+ requiresConfirmation: true,
147
+ type: 'browser',
148
+ handler: async (args) => {
149
+ const selector = args['selector'];
150
+ const text = args['text'];
151
+ try {
152
+ const page = await getPage();
153
+ await page.fill(selector, text);
154
+ return { success: true, output: `Typed "${text}" into ${selector}` };
155
+ }
156
+ catch (error) {
157
+ return {
158
+ success: false,
159
+ output: '',
160
+ error: error instanceof Error ? error.message : 'Type failed',
161
+ };
162
+ }
163
+ },
164
+ };
165
+ /**
166
+ * Get page content/text
167
+ */
168
+ export const getContentTool = {
169
+ name: 'browser_get_content',
170
+ description: 'Get the text content of the current page or a specific element',
171
+ parameters: {
172
+ type: 'object',
173
+ properties: {
174
+ selector: {
175
+ type: 'string',
176
+ description: 'CSS selector for a specific element (optional, defaults to body)',
177
+ },
178
+ },
179
+ required: [],
180
+ },
181
+ requiresConfirmation: false,
182
+ type: 'browser',
183
+ handler: async (args) => {
184
+ const selector = args['selector'] || 'body';
185
+ try {
186
+ const page = await getPage();
187
+ const element = await page.$(selector);
188
+ if (!element) {
189
+ return { success: false, output: '', error: `Element not found: ${selector}` };
190
+ }
191
+ const text = await element.innerText();
192
+ // Truncate very long content
193
+ const truncated = text.length > 5000 ? text.slice(0, 5000) + '...(truncated)' : text;
194
+ return { success: true, output: truncated };
195
+ }
196
+ catch (error) {
197
+ return {
198
+ success: false,
199
+ output: '',
200
+ error: error instanceof Error ? error.message : 'Failed to get content',
201
+ };
202
+ }
203
+ },
204
+ };
205
+ /**
206
+ * Close the browser
207
+ */
208
+ export async function closeBrowser() {
209
+ if (browser) {
210
+ await browser.close();
211
+ browser = null;
212
+ currentPage = null;
213
+ }
214
+ }
215
+ export const browserTools = [
216
+ navigateTool,
217
+ screenshotTool,
218
+ clickTool,
219
+ typeTool,
220
+ getContentTool,
221
+ ];
222
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../src/tools/builtin/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA2B,MAAM,YAAY,CAAC;AAG/D,6BAA6B;AAC7B,IAAI,OAAO,GAAmB,IAAI,CAAC;AACnC,IAAI,WAAW,GAAgB,IAAI,CAAC;AAEpC,KAAK,UAAU,UAAU;IACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,KAAK,UAAU,OAAO;IACpB,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC3C,MAAM,CAAC,GAAG,MAAM,UAAU,EAAE,CAA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E,EAAE,CAAC;YACjF,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,SAAS,EAAE,CAAC;YACvC,6BAA6B;YAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC;YACrF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;aACxE,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,IAAI,OAAO,EAAE,CAAC;QACZ,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,GAAG,IAAI,CAAC;QACf,WAAW,GAAG,IAAI,CAAC;IACrB,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAW;IAClC,YAAY;IACZ,cAAc;IACd,SAAS;IACT,QAAQ;IACR,cAAc;CACf,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Tool } from '../../types.js';
2
+ /**
3
+ * Read file contents
4
+ */
5
+ export declare const readFileTool: Tool;
6
+ /**
7
+ * Write content to a file
8
+ */
9
+ export declare const writeFileTool: Tool;
10
+ /**
11
+ * List directory contents
12
+ */
13
+ export declare const listDirectoryTool: Tool;
14
+ /**
15
+ * Delete a file
16
+ */
17
+ export declare const deleteFileTool: Tool;
18
+ /**
19
+ * All filesystem tools
20
+ */
21
+ export declare const filesystemTools: Tool[];
22
+ //# sourceMappingURL=filesystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../../src/tools/builtin/filesystem.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,gBAAgB,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,IA4B1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,IAkC3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,IA+B/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,IA4B5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,IAAI,EAKjC,CAAC"}
@@ -0,0 +1,151 @@
1
+ import * as fs from 'node:fs/promises';
2
+ import * as path from 'node:path';
3
+ /**
4
+ * Read file contents
5
+ */
6
+ export const readFileTool = {
7
+ name: 'read_file',
8
+ description: 'Read the contents of a file',
9
+ parameters: {
10
+ type: 'object',
11
+ properties: {
12
+ path: {
13
+ type: 'string',
14
+ description: 'The path to the file to read',
15
+ },
16
+ },
17
+ required: ['path'],
18
+ },
19
+ requiresConfirmation: false,
20
+ type: 'filesystem',
21
+ handler: async (args) => {
22
+ const filePath = args['path'];
23
+ try {
24
+ const content = await fs.readFile(filePath, 'utf-8');
25
+ return { success: true, output: content };
26
+ }
27
+ catch (error) {
28
+ return {
29
+ success: false,
30
+ output: '',
31
+ error: error instanceof Error ? error.message : 'Failed to read file',
32
+ };
33
+ }
34
+ },
35
+ };
36
+ /**
37
+ * Write content to a file
38
+ */
39
+ export const writeFileTool = {
40
+ name: 'write_file',
41
+ description: 'Write content to a file. Creates the file and parent directories if they do not exist.',
42
+ parameters: {
43
+ type: 'object',
44
+ properties: {
45
+ path: {
46
+ type: 'string',
47
+ description: 'The path to the file to write',
48
+ },
49
+ content: {
50
+ type: 'string',
51
+ description: 'The content to write to the file',
52
+ },
53
+ },
54
+ required: ['path', 'content'],
55
+ },
56
+ requiresConfirmation: true,
57
+ type: 'filesystem',
58
+ handler: async (args) => {
59
+ const filePath = args['path'];
60
+ const content = args['content'];
61
+ try {
62
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
63
+ await fs.writeFile(filePath, content, 'utf-8');
64
+ return { success: true, output: `File written: ${filePath}` };
65
+ }
66
+ catch (error) {
67
+ return {
68
+ success: false,
69
+ output: '',
70
+ error: error instanceof Error ? error.message : 'Failed to write file',
71
+ };
72
+ }
73
+ },
74
+ };
75
+ /**
76
+ * List directory contents
77
+ */
78
+ export const listDirectoryTool = {
79
+ name: 'list_directory',
80
+ description: 'List the contents of a directory',
81
+ parameters: {
82
+ type: 'object',
83
+ properties: {
84
+ path: {
85
+ type: 'string',
86
+ description: 'The path to the directory to list',
87
+ },
88
+ },
89
+ required: ['path'],
90
+ },
91
+ requiresConfirmation: false,
92
+ type: 'filesystem',
93
+ handler: async (args) => {
94
+ const dirPath = args['path'];
95
+ try {
96
+ const entries = await fs.readdir(dirPath, { withFileTypes: true });
97
+ const formatted = entries.map(e => `${e.isDirectory() ? '📁' : '📄'} ${e.name}`).join('\n');
98
+ return { success: true, output: formatted || '(empty directory)' };
99
+ }
100
+ catch (error) {
101
+ return {
102
+ success: false,
103
+ output: '',
104
+ error: error instanceof Error ? error.message : 'Failed to list directory',
105
+ };
106
+ }
107
+ },
108
+ };
109
+ /**
110
+ * Delete a file
111
+ */
112
+ export const deleteFileTool = {
113
+ name: 'delete_file',
114
+ description: 'Delete a file',
115
+ parameters: {
116
+ type: 'object',
117
+ properties: {
118
+ path: {
119
+ type: 'string',
120
+ description: 'The path to the file to delete',
121
+ },
122
+ },
123
+ required: ['path'],
124
+ },
125
+ requiresConfirmation: true,
126
+ type: 'filesystem',
127
+ handler: async (args) => {
128
+ const filePath = args['path'];
129
+ try {
130
+ await fs.unlink(filePath);
131
+ return { success: true, output: `File deleted: ${filePath}` };
132
+ }
133
+ catch (error) {
134
+ return {
135
+ success: false,
136
+ output: '',
137
+ error: error instanceof Error ? error.message : 'Failed to delete file',
138
+ };
139
+ }
140
+ },
141
+ };
142
+ /**
143
+ * All filesystem tools
144
+ */
145
+ export const filesystemTools = [
146
+ readFileTool,
147
+ writeFileTool,
148
+ listDirectoryTool,
149
+ deleteFileTool,
150
+ ];
151
+ //# sourceMappingURL=filesystem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filesystem.js","sourceRoot":"","sources":["../../../src/tools/builtin/filesystem.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAGlC;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAS;IAChC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,6BAA6B;IAC1C,UAAU,EAAE;QACV,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE;gBACJ,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,8BAA8B;aAC5C;SACF;QACD,QAAQ,EAAE,CAAC,MAAM,CAAC;KACnB;IACD,oBAAoB,EAAE,KAAK;IAC3B,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAuB,EAAE;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAW,CAAC;QACxC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YACrD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB;aACtE,CAAC;QACJ,C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IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;aAC9C;SACF;QACD,QAAQ,EAAE,CAAC,MAAM,CAAC;KACnB;IACD,oBAAoB,EAAE,IAAI;IAC1B,IAAI,EAAE,YAAY;IAClB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAuB,EAAE;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAW,CAAC;QACxC,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC1B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,iBAAiB,QAAQ,EAAE,EAAE,CAAC;QAChE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,EAAE;gBACV,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB;aACxE,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAW;IACrC,YAAY;IACZ,aAAa;IACb,iBAAiB;IACjB,cAAc;CACf,CAAC"}
@@ -0,0 +1,10 @@
1
+ export { filesystemTools } from './filesystem.js';
2
+ export { shellTools } from './shell.js';
3
+ export { sandboxTools } from './sandbox.js';
4
+ export { searchTools } from './search.js';
5
+ export { browserTools, closeBrowser } from './browser.js';
6
+ /**
7
+ * All built-in tools combined
8
+ */
9
+ export declare const allBuiltinTools: import("../../types.js").Tool[];
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/builtin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQ1D;;GAEG;AACH,eAAO,MAAM,eAAe,iCAM3B,CAAC"}
@@ -0,0 +1,21 @@
1
+ export { filesystemTools } from './filesystem.js';
2
+ export { shellTools } from './shell.js';
3
+ export { sandboxTools } from './sandbox.js';
4
+ export { searchTools } from './search.js';
5
+ export { browserTools, closeBrowser } from './browser.js';
6
+ import { filesystemTools } from './filesystem.js';
7
+ import { shellTools } from './shell.js';
8
+ import { sandboxTools } from './sandbox.js';
9
+ import { searchTools } from './search.js';
10
+ import { browserTools } from './browser.js';
11
+ /**
12
+ * All built-in tools combined
13
+ */
14
+ export const allBuiltinTools = [
15
+ ...filesystemTools,
16
+ ...shellTools,
17
+ ...sandboxTools,
18
+ ...searchTools,
19
+ ...browserTools,
20
+ ];
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/builtin/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,GAAG,eAAe;IAClB,GAAG,UAAU;IACb,GAAG,YAAY;IACf,GAAG,WAAW;IACd,GAAG,YAAY;CAChB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { Tool } from '../../types.js';
2
+ /**
3
+ * Execute JavaScript code in isolation using Node's subprocess
4
+ */
5
+ export declare const runJavaScriptTool: Tool;
6
+ /**
7
+ * Execute Python code in isolation
8
+ */
9
+ export declare const runPythonTool: Tool;
10
+ export declare const sandboxTools: Tool[];
11
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../src/tools/builtin/sandbox.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,gBAAgB,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,IA2F/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,IA4E3B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,IAAI,EAAuC,CAAC"}
@@ -0,0 +1,166 @@
1
+ import { spawn } from 'node:child_process';
2
+ import * as fs from 'node:fs/promises';
3
+ import * as path from 'node:path';
4
+ import * as os from 'node:os';
5
+ /**
6
+ * Execute JavaScript code in isolation using Node's subprocess
7
+ */
8
+ export const runJavaScriptTool = {
9
+ name: 'run_javascript',
10
+ description: 'Execute JavaScript code in an isolated subprocess and return the result',
11
+ parameters: {
12
+ type: 'object',
13
+ properties: {
14
+ code: {
15
+ type: 'string',
16
+ description: 'The JavaScript code to execute',
17
+ },
18
+ },
19
+ required: ['code'],
20
+ },
21
+ requiresConfirmation: true,
22
+ type: 'sandbox',
23
+ handler: async (args) => {
24
+ const code = args['code'];
25
+ // Create a temp file for the code
26
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'keygate-js-'));
27
+ const tmpFile = path.join(tmpDir, 'script.mjs');
28
+ // Wrap code to capture output
29
+ const wrappedCode = `
30
+ const __result = (async () => {
31
+ ${code}
32
+ })();
33
+ __result.then(r => {
34
+ if (r !== undefined) console.log(JSON.stringify(r, null, 2));
35
+ }).catch(e => {
36
+ console.error(e.message);
37
+ process.exit(1);
38
+ });
39
+ `;
40
+ try {
41
+ await fs.writeFile(tmpFile, wrappedCode, 'utf-8');
42
+ return new Promise((resolve) => {
43
+ const proc = spawn('node', [tmpFile], {
44
+ timeout: 30000, // 30 second timeout
45
+ cwd: tmpDir,
46
+ });
47
+ let stdout = '';
48
+ let stderr = '';
49
+ proc.stdout.on('data', (data) => {
50
+ stdout += data.toString();
51
+ });
52
+ proc.stderr.on('data', (data) => {
53
+ stderr += data.toString();
54
+ });
55
+ proc.on('close', async (code) => {
56
+ // Cleanup
57
+ await fs.rm(tmpDir, { recursive: true, force: true });
58
+ if (code === 0) {
59
+ resolve({
60
+ success: true,
61
+ output: stdout.trim() || '(no output)',
62
+ });
63
+ }
64
+ else {
65
+ resolve({
66
+ success: false,
67
+ output: stdout,
68
+ error: stderr || `Script exited with code ${code}`,
69
+ });
70
+ }
71
+ });
72
+ proc.on('error', async (error) => {
73
+ await fs.rm(tmpDir, { recursive: true, force: true });
74
+ resolve({
75
+ success: false,
76
+ output: '',
77
+ error: error.message,
78
+ });
79
+ });
80
+ });
81
+ }
82
+ catch (error) {
83
+ await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => { });
84
+ return {
85
+ success: false,
86
+ output: '',
87
+ error: error instanceof Error ? error.message : 'Failed to execute JavaScript',
88
+ };
89
+ }
90
+ },
91
+ };
92
+ /**
93
+ * Execute Python code in isolation
94
+ */
95
+ export const runPythonTool = {
96
+ name: 'run_python',
97
+ description: 'Execute Python code in an isolated subprocess and return the result',
98
+ parameters: {
99
+ type: 'object',
100
+ properties: {
101
+ code: {
102
+ type: 'string',
103
+ description: 'The Python code to execute',
104
+ },
105
+ },
106
+ required: ['code'],
107
+ },
108
+ requiresConfirmation: true,
109
+ type: 'sandbox',
110
+ handler: async (args) => {
111
+ const code = args['code'];
112
+ const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'keygate-py-'));
113
+ const tmpFile = path.join(tmpDir, 'script.py');
114
+ try {
115
+ await fs.writeFile(tmpFile, code, 'utf-8');
116
+ return new Promise((resolve) => {
117
+ const proc = spawn('python3', [tmpFile], {
118
+ timeout: 30000,
119
+ cwd: tmpDir,
120
+ });
121
+ let stdout = '';
122
+ let stderr = '';
123
+ proc.stdout.on('data', (data) => {
124
+ stdout += data.toString();
125
+ });
126
+ proc.stderr.on('data', (data) => {
127
+ stderr += data.toString();
128
+ });
129
+ proc.on('close', async (code) => {
130
+ await fs.rm(tmpDir, { recursive: true, force: true });
131
+ if (code === 0) {
132
+ resolve({
133
+ success: true,
134
+ output: stdout.trim() || '(no output)',
135
+ });
136
+ }
137
+ else {
138
+ resolve({
139
+ success: false,
140
+ output: stdout,
141
+ error: stderr || `Script exited with code ${code}`,
142
+ });
143
+ }
144
+ });
145
+ proc.on('error', async (error) => {
146
+ await fs.rm(tmpDir, { recursive: true, force: true });
147
+ resolve({
148
+ success: false,
149
+ output: '',
150
+ error: error.message,
151
+ });
152
+ });
153
+ });
154
+ }
155
+ catch (error) {
156
+ await fs.rm(tmpDir, { recursive: true, force: true }).catch(() => { });
157
+ return {
158
+ success: false,
159
+ output: '',
160
+ error: error instanceof Error ? error.message : 'Failed to execute Python',
161
+ };
162
+ }
163
+ },
164
+ };
165
+ export const sandboxTools = [runJavaScriptTool, runPythonTool];
166
+ //# sourceMappingURL=sandbox.js.map