imlil 1.0.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 (175) hide show
  1. package/.eslintrc.cjs +40 -0
  2. package/DOCS.md +63 -0
  3. package/README.md +160 -0
  4. package/agentTestSandbox/cli-test-zone/README.md +0 -0
  5. package/agentTestSandbox/cli-test-zone/imlil.blueprint.json +5 -0
  6. package/agentTestSandbox/cli-test-zone/notes-warning.md +3 -0
  7. package/agentTestSandbox/cli-test-zone/package.json +0 -0
  8. package/agentTestSandbox/cli-test-zone/public/index.html +0 -0
  9. package/agentTestSandbox/cli-test-zone/src/App.js +0 -0
  10. package/agentTestSandbox/cli-test-zone/src/App.jsx +29 -0
  11. package/agentTestSandbox/cli-test-zone/src/__tests__/App.test.jsx +48 -0
  12. package/agentTestSandbox/cli-test-zone/src/components/AddTodo.js +0 -0
  13. package/agentTestSandbox/cli-test-zone/src/components/Navigation/Navigation.jsx +48 -0
  14. package/agentTestSandbox/cli-test-zone/src/components/Navigation/__tests__/Navigation.module.test.js +45 -0
  15. package/agentTestSandbox/cli-test-zone/src/components/Navigation/__tests__/Navigation.test.jsx +47 -0
  16. package/agentTestSandbox/cli-test-zone/src/components/Navigation.js +0 -0
  17. package/agentTestSandbox/cli-test-zone/src/components/TodoItem/TodoItem.jsx +41 -0
  18. package/agentTestSandbox/cli-test-zone/src/components/TodoItem/__tests__/TodoItem.test.jsx +65 -0
  19. package/agentTestSandbox/cli-test-zone/src/components/TodoItem.js +0 -0
  20. package/agentTestSandbox/cli-test-zone/src/components/TodoList/TodoList.module.css +62 -0
  21. package/agentTestSandbox/cli-test-zone/src/components/TodoList.js +0 -0
  22. package/agentTestSandbox/cli-test-zone/src/index.js +0 -0
  23. package/agentTestSandbox/cli-test-zone/src/pages/About.js +0 -0
  24. package/agentTestSandbox/cli-test-zone/src/pages/Home.js +0 -0
  25. package/agentTestSandbox/cli-test-zone/src/store/TodoContext.js +0 -0
  26. package/agentTestSandbox/cli-test-zone/src/styles/Todo.css +0 -0
  27. package/agentTestSandbox/cli-test-zone/src/styles/index.css +0 -0
  28. package/agentTestSandbox/cli-test-zone/src/utils/__tests__/localStorage.test.js +48 -0
  29. package/agentTestSandbox/cli-test-zone/src/utils/localStorage.js +38 -0
  30. package/agentTestSandbox/parallel-test/.env.example +0 -0
  31. package/agentTestSandbox/parallel-test/.eslintrc.json +0 -0
  32. package/agentTestSandbox/parallel-test/.github/workflows/__tests__/workflows.test.ts +115 -0
  33. package/agentTestSandbox/parallel-test/.github/workflows/cd.yml +0 -0
  34. package/agentTestSandbox/parallel-test/.github/workflows/ci.yml +4 -0
  35. package/agentTestSandbox/parallel-test/.imlil/plan-2026-02-08.md +186 -0
  36. package/agentTestSandbox/parallel-test/.prettierrc +0 -0
  37. package/agentTestSandbox/parallel-test/Dockerfile +0 -0
  38. package/agentTestSandbox/parallel-test/README.md +3 -0
  39. package/agentTestSandbox/parallel-test/ast.json +74 -0
  40. package/agentTestSandbox/parallel-test/docker-compose.yml +4 -0
  41. package/agentTestSandbox/parallel-test/jest.config.js +61 -0
  42. package/agentTestSandbox/parallel-test/k8s/__tests__/deployment.test.ts +168 -0
  43. package/agentTestSandbox/parallel-test/k8s/frontend-deployment.yaml +4 -0
  44. package/agentTestSandbox/parallel-test/nginx/nginx.conf +0 -0
  45. package/agentTestSandbox/parallel-test/package.json +50 -0
  46. package/agentTestSandbox/parallel-test/prisma/__tests__/schema.test.ts +176 -0
  47. package/agentTestSandbox/parallel-test/prisma/schema.prisma +109 -0
  48. package/agentTestSandbox/parallel-test/server/__tests__/controllers/dashboard.controller.test.ts +127 -0
  49. package/agentTestSandbox/parallel-test/server/__tests__/index.test.ts +60 -0
  50. package/agentTestSandbox/parallel-test/server/__tests__/models/user.model.test.ts +111 -0
  51. package/agentTestSandbox/parallel-test/server/config/__tests__/swagger.test.ts +128 -0
  52. package/agentTestSandbox/parallel-test/server/config/database.ts +0 -0
  53. package/agentTestSandbox/parallel-test/server/config/redis.ts +0 -0
  54. package/agentTestSandbox/parallel-test/server/config/swagger.ts +0 -0
  55. package/agentTestSandbox/parallel-test/server/controllers/__tests__/auth.controller.test.ts +178 -0
  56. package/agentTestSandbox/parallel-test/server/controllers/__tests__/user.controller.test.ts +105 -0
  57. package/agentTestSandbox/parallel-test/server/controllers/auth.controller.ts +148 -0
  58. package/agentTestSandbox/parallel-test/server/controllers/dashboard.controller.ts +137 -0
  59. package/agentTestSandbox/parallel-test/server/controllers/user.controller.ts +161 -0
  60. package/agentTestSandbox/parallel-test/server/index.ts +62 -0
  61. package/agentTestSandbox/parallel-test/server/middleware/__tests__/auth.middleware.test.ts +74 -0
  62. package/agentTestSandbox/parallel-test/server/middleware/auth.middleware.ts +55 -0
  63. package/agentTestSandbox/parallel-test/server/middleware/error.middleware.ts +0 -0
  64. package/agentTestSandbox/parallel-test/server/middleware/validation.middleware.ts +0 -0
  65. package/agentTestSandbox/parallel-test/server/models/analytics.model.ts +0 -0
  66. package/agentTestSandbox/parallel-test/server/models/profile.model.ts +0 -0
  67. package/agentTestSandbox/parallel-test/server/models/user.model.ts +78 -0
  68. package/agentTestSandbox/parallel-test/server/routes/auth.routes.ts +0 -0
  69. package/agentTestSandbox/parallel-test/server/routes/dashboard.routes.ts +0 -0
  70. package/agentTestSandbox/parallel-test/server/routes/user.routes.ts +0 -0
  71. package/agentTestSandbox/parallel-test/src/App.tsx +0 -0
  72. package/agentTestSandbox/parallel-test/src/__tests__/config.test.ts +127 -0
  73. package/agentTestSandbox/parallel-test/src/__tests__/index.test.tsx +36 -0
  74. package/agentTestSandbox/parallel-test/src/__tests__/setup.test.ts +34 -0
  75. package/agentTestSandbox/parallel-test/src/__tests__/setupTest.test.ts +44 -0
  76. package/agentTestSandbox/parallel-test/src/components/common/Button/Button.tsx +80 -0
  77. package/agentTestSandbox/parallel-test/src/components/common/Button/__tests__/Button.test.tsx +75 -0
  78. package/agentTestSandbox/parallel-test/src/components/common/Card/Card.tsx +0 -0
  79. package/agentTestSandbox/parallel-test/src/components/common/Input/Input.tsx +0 -0
  80. package/agentTestSandbox/parallel-test/src/components/common/Table/Table.tsx +0 -0
  81. package/agentTestSandbox/parallel-test/src/components/features/Authentication/LoginForm.tsx +75 -0
  82. package/agentTestSandbox/parallel-test/src/components/features/Authentication/RegisterForm.tsx +0 -0
  83. package/agentTestSandbox/parallel-test/src/components/features/Authentication/__tests__/LoginForm.test.tsx +101 -0
  84. package/agentTestSandbox/parallel-test/src/components/features/Dashboard/AnalyticsChart.tsx +0 -0
  85. package/agentTestSandbox/parallel-test/src/components/features/Dashboard/DashboardStats.tsx +81 -0
  86. package/agentTestSandbox/parallel-test/src/components/features/Dashboard/__tests__/DashboardStats.test.tsx +122 -0
  87. package/agentTestSandbox/parallel-test/src/components/layouts/Header.tsx +70 -0
  88. package/agentTestSandbox/parallel-test/src/components/layouts/MainLayout.tsx +0 -0
  89. package/agentTestSandbox/parallel-test/src/components/layouts/Sidebar.tsx +0 -0
  90. package/agentTestSandbox/parallel-test/src/components/layouts/__tests__/MainLayout.test.tsx +65 -0
  91. package/agentTestSandbox/parallel-test/src/hooks/__tests__/useAuth.test.ts +75 -0
  92. package/agentTestSandbox/parallel-test/src/hooks/useApi.ts +0 -0
  93. package/agentTestSandbox/parallel-test/src/hooks/useAuth.ts +54 -0
  94. package/agentTestSandbox/parallel-test/src/hooks/useTheme.ts +0 -0
  95. package/agentTestSandbox/parallel-test/src/index.tsx +0 -0
  96. package/agentTestSandbox/parallel-test/src/services/__tests__/api.service.test.ts +48 -0
  97. package/agentTestSandbox/parallel-test/src/services/analytics.service.ts +0 -0
  98. package/agentTestSandbox/parallel-test/src/services/api.service.ts +59 -0
  99. package/agentTestSandbox/parallel-test/src/services/api.ts +0 -0
  100. package/agentTestSandbox/parallel-test/src/services/auth.service.ts +0 -0
  101. package/agentTestSandbox/parallel-test/src/services/user.service.ts +0 -0
  102. package/agentTestSandbox/parallel-test/src/store/__tests__/store.test.ts +60 -0
  103. package/agentTestSandbox/parallel-test/src/store/index.ts +23 -0
  104. package/agentTestSandbox/parallel-test/src/store/slices/authSlice.ts +0 -0
  105. package/agentTestSandbox/parallel-test/src/store/slices/dashboardSlice.ts +0 -0
  106. package/agentTestSandbox/parallel-test/src/store/slices/userSlice.ts +0 -0
  107. package/agentTestSandbox/parallel-test/src/types/auth.types.ts +0 -0
  108. package/agentTestSandbox/parallel-test/src/types/dashboard.types.ts +0 -0
  109. package/agentTestSandbox/parallel-test/src/types/user.types.ts +0 -0
  110. package/agentTestSandbox/parallel-test/src/utils/constants.ts +0 -0
  111. package/agentTestSandbox/parallel-test/src/utils/formatters.ts +0 -0
  112. package/agentTestSandbox/parallel-test/src/utils/validation.ts +0 -0
  113. package/agentTestSandbox/parallel-test/src/views/Dashboard.tsx +0 -0
  114. package/agentTestSandbox/parallel-test/src/views/Login.tsx +31 -0
  115. package/agentTestSandbox/parallel-test/src/views/Profile.tsx +0 -0
  116. package/agentTestSandbox/parallel-test/src/views/Register.tsx +0 -0
  117. package/agentTestSandbox/parallel-test/src/views/Settings.tsx +0 -0
  118. package/agentTestSandbox/parallel-test/src/views/__tests__/Login.test.tsx +62 -0
  119. package/agentTestSandbox/parallel-test/src/vite-env.d.ts +1 -0
  120. package/agentTestSandbox/parallel-test/tailwind.config.js +0 -0
  121. package/agentTestSandbox/parallel-test/tests/integration/api/auth.test.ts +120 -0
  122. package/agentTestSandbox/parallel-test/tests/unit/components/Button.test.tsx +35 -0
  123. package/agentTestSandbox/parallel-test/tests/unit/config/jest.config.test.js +62 -0
  124. package/agentTestSandbox/parallel-test/tests/unit/config/jest.setup.test.js +52 -0
  125. package/agentTestSandbox/parallel-test/tests/unit/infrastructure/__tests__/docker-config.test.ts +107 -0
  126. package/agentTestSandbox/parallel-test/tsconfig.json +0 -0
  127. package/agentTestSandbox/zone2/Makefile +58 -0
  128. package/agentTestSandbox/zone2/README.md +0 -0
  129. package/agentTestSandbox/zone2/docs/API.md +0 -0
  130. package/agentTestSandbox/zone2/docs/CONTRIBUTING.md +0 -0
  131. package/agentTestSandbox/zone2/imlil.blueprint.json +5 -0
  132. package/agentTestSandbox/zone2/notes-warning.md +3 -0
  133. package/agentTestSandbox/zone2/src/calculator.c +0 -0
  134. package/agentTestSandbox/zone2/src/calculator.h +0 -0
  135. package/agentTestSandbox/zone2/src/core/__tests__/test_memory.c +89 -0
  136. package/agentTestSandbox/zone2/src/core/memory.c +60 -0
  137. package/agentTestSandbox/zone2/src/display.c +0 -0
  138. package/agentTestSandbox/zone2/src/display.h +0 -0
  139. package/agentTestSandbox/zone2/src/input_handler.c +0 -0
  140. package/agentTestSandbox/zone2/src/input_handler.h +0 -0
  141. package/agentTestSandbox/zone2/src/main.c +0 -0
  142. package/agentTestSandbox/zone2/src/utils/error_handling.c +0 -0
  143. package/agentTestSandbox/zone2/src/utils/error_handling.h +0 -0
  144. package/agentTestSandbox/zone2/src/utils/input.c +0 -0
  145. package/agentTestSandbox/zone2/src/utils/input.h +0 -0
  146. package/agentTestSandbox/zone2/src/utils/math_utils.c +0 -0
  147. package/agentTestSandbox/zone2/src/utils/math_utils.h +0 -0
  148. package/agentTestSandbox/zone2/src/utils/stack.c +0 -0
  149. package/agentTestSandbox/zone2/src/utils/stack.h +0 -0
  150. package/agentTestSandbox/zone2/src/utils.c +34 -0
  151. package/agentTestSandbox/zone2/tests/__tests__/test_makefile.c +58 -0
  152. package/agentTestSandbox/zone2/tests/calculator_tests.c +0 -0
  153. package/agentTestSandbox/zone2/tests/input_handler_tests.c +0 -0
  154. package/agentTestSandbox/zone2/tests/math_utils_tests.c +0 -0
  155. package/agentTestSandbox/zone2/tests/test_calculator.c +0 -0
  156. package/agentTestSandbox/zone2/tests/test_input.c +0 -0
  157. package/agentTestSandbox/zone2/tests/test_stack.c +0 -0
  158. package/agentTestSandbox/zone2/tests/test_utils.c +8 -0
  159. package/bin/cli.js +369 -0
  160. package/imlil.config.js +22 -0
  161. package/index.js +0 -0
  162. package/jest.config.js +5 -0
  163. package/package.json +45 -0
  164. package/src/__tests__/cli.test.js +5 -0
  165. package/src/actions/Action.js +125 -0
  166. package/src/agents/Agent.js +64 -0
  167. package/src/agents/Operator.js +147 -0
  168. package/src/agents/ScrumAgent.js +74 -0
  169. package/src/agents/SupervisorAgent.js +198 -0
  170. package/src/agents/ValidatorAgent.js +48 -0
  171. package/src/agents/coder.js +208 -0
  172. package/src/agents/worker.js +52 -0
  173. package/src/utils/db.js +40 -0
  174. package/src/utils/embedapi.js +19 -0
  175. package/test-api.js +24 -0
@@ -0,0 +1,208 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import Agent from './Agent.js';
4
+ import Action from '../actions/Action.js';
5
+ import callEmbedApi from '../utils/embedapi.js';
6
+
7
+ export default class Coder extends Agent {
8
+ constructor(apiKey, statusCallback) {
9
+ super('Coder', 'Writes and modifies code based on a plan.');
10
+ this.apiKey = apiKey;
11
+ this.statusCallback = statusCallback || (() => {});
12
+ }
13
+
14
+ async run(task, config = {}) {
15
+ this.statusCallback(`Analyzing task: ${task.title}`);
16
+ console.log(`Coder agent is working on: ${task.title}`);
17
+
18
+ let blueprint = '';
19
+
20
+ // 1. Load AST (File Structure)
21
+ try {
22
+ const astData = await fs.readFile('ast.json', 'utf8');
23
+ blueprint += `\n**PROJECT FILE STRUCTURE (AST):**\n${astData}\n`;
24
+ } catch (e) {
25
+ console.error('Error loading ast.json:', e.message);
26
+ }
27
+
28
+ // 2. Load Detailed Plan
29
+ try {
30
+ const files = await fs.readdir('.imlil');
31
+ const planFile = files.filter((f) => f.startsWith('plan-') && f.endsWith('.md')).sort().pop();
32
+ if (planFile) {
33
+ const planData = await fs.readFile(path.join('.imlil', planFile), 'utf-8');
34
+ blueprint += `\n**PROJECT PLAN & CONTEXT:**\n${planData}\n`;
35
+ }
36
+ } catch (e) {
37
+ console.error('Error loading project plan:', e.message);
38
+ }
39
+
40
+ // 3. Legacy Fallback
41
+ try {
42
+ const blueprintData = await fs.readFile('imlil.blueprint.json', 'utf8');
43
+ blueprint += `\n**PROJECT BLUEPRINT (LEGACY):**\n${blueprintData}\n`;
44
+ } catch (e) {
45
+ console.error('Error loading legacy blueprint:', e.message);
46
+ }
47
+
48
+ const maxRetries = 3;
49
+
50
+ const callApiWithRetry = async (prompt, apiKey, attempt = 1) => {
51
+ if (attempt > maxRetries) {
52
+ throw new Error(`Failed to get valid response after ${maxRetries} attempts.`);
53
+ }
54
+
55
+ try {
56
+ const response = await callEmbedApi(prompt, apiKey);
57
+ if (config.debug) {
58
+ console.error(`-- DEBUG: Raw AI Response (Attempt ${attempt}) --\n${response}\n-- END DEBUG --`);
59
+ }
60
+
61
+ // 1. Extract JSON for metadata
62
+ const jsonRegex = /\{[\s\S]*?\}/;
63
+ // eslint-disable-next-line prefer-destructuring
64
+ const jsonMatch = response.match(jsonRegex);
65
+
66
+ if (!jsonMatch || !jsonMatch[0]) {
67
+ throw new Error('Could not find JSON object in response');
68
+ }
69
+
70
+ let action;
71
+ try {
72
+ action = JSON.parse(jsonMatch[0]);
73
+ } catch (e) {
74
+ throw new Error(`JSON parse error: ${e.message}`);
75
+ }
76
+
77
+ // 2. Extract Code Content (Robust Strategy)
78
+ // If content is not in JSON (or is empty), look for Markdown block
79
+ if (!action.content || action.content.trim() === '') {
80
+ const codeBlockRegex = /```(?:javascript|js|ts|typescript|jsx|tsx|css|html|json|bash|sh|text)?\n([\s\S]*?)```/i;
81
+ const codeMatch = response.match(codeBlockRegex);
82
+
83
+ if (codeMatch && codeMatch[1]) {
84
+ action.content = codeMatch[1];
85
+ } else if (action.action.startsWith('write') || action.action === 'modifyFile' || action.action === 'smartEdit') {
86
+ throw new Error('Missing file content. Content must be in a Markdown code block or in the JSON "content" field.');
87
+ }
88
+ }
89
+
90
+ return action;
91
+ } catch (error) {
92
+ console.error(`Attempt ${attempt} failed: ${error.message}. Retrying...`);
93
+ const newPrompt = `${prompt}\n\n**PREVIOUS ATTEMPT FAILED!**\nYour last response was invalid. Error: "${error.message}". \nPlease return a valid JSON object for the action/path, AND put the code content in a standard Markdown code block outside the JSON.`;
94
+ return callApiWithRetry(newPrompt, apiKey, attempt + 1);
95
+ }
96
+ };
97
+
98
+ const codePrompt = `
99
+ You are a specialized AI agent responsible for generating code.
100
+
101
+ **TASK:** "${task.title} - ${task.description}"
102
+ ${blueprint}
103
+
104
+ **AVAILABLE ACTIONS:**
105
+ 1. "writeFile": Create a NEW file.
106
+ 2. "modifyFile": Modify an EXISTING file surgically using jscodeshift (AST-based).
107
+ 3. "smartEdit": Specialized for complex refactoring/imports (uses tree-sitter + jscodeshift).
108
+
109
+ **STRATEGY:**
110
+ - For NEW files, use "writeFile".
111
+ - For EXISTING files, use "modifyFile" or "smartEdit". This is the PREFERRED way to edit.
112
+
113
+ **modifyFile INSTRUCTIONS:**
114
+ Your output must be the BODY of a jscodeshift transform function: \`(file, api) => string\`.
115
+ The API provides \`api.j\` (jscodeshift instance).
116
+
117
+ **Example (Adding an import):**
118
+ { "action": "modifyFile", "filePath": "src/App.js" }
119
+ \`\`\`javascript
120
+ const j = api.j;
121
+ const root = j(file.source);
122
+ const newImport = j.importDeclaration(
123
+ [j.importSpecifier(j.identifier('MyComp'))],
124
+ j.literal('./MyComp')
125
+ );
126
+ root.find(j.ImportDeclaration).at(0).insertBefore(newImport);
127
+ return root.toSource();
128
+ \`\`\`
129
+
130
+ **Example (Updating a value):**
131
+ { "action": "modifyFile", "filePath": "src/config.js" }
132
+ \`\`\`javascript
133
+ const j = api.j;
134
+ return j(file.source)
135
+ .find(j.Identifier, { name: 'VERSION' })
136
+ .replaceWith(j.literal('2.0.0'))
137
+ .toSource();
138
+ \`\`\`
139
+
140
+ **OUTPUT FORMAT:**
141
+ { "action": "modifyFile", "filePath": "path/to/file.js" }
142
+ \`\`\`javascript
143
+ // jscodeshift code here
144
+ \`\`\`
145
+ `;
146
+
147
+ const testPrompt = `
148
+ You are a specialized AI agent responsible for generating unit tests.
149
+
150
+ **TASK:** "${task.title} - ${task.description}"
151
+ ${blueprint}
152
+
153
+ **INSTRUCTIONS:**
154
+ 1. Write the unit test for this task.
155
+ 2. Output a JSON object with the 'action' ("writeTest") and 'filePath'.
156
+ 3. Output the *test code* in a Markdown code block.
157
+
158
+ **RULE:** Tests must be in a "__tests__" folder at the same level as the source file.
159
+
160
+ **REQUIRED OUTPUT FORMAT:**
161
+ { "action": "writeTest", "filePath": "src/__tests__/file.test.js" }
162
+ \`\`\`javascript
163
+ // Test content
164
+ \`\`\`
165
+ `;
166
+
167
+ try {
168
+ this.statusCallback(`Generating code for: ${task.title}`);
169
+ const codeAction = callApiWithRetry(codePrompt, this.apiKey);
170
+
171
+ this.statusCallback(`Generating tests for: ${task.title}`);
172
+ const testAction = callApiWithRetry(testPrompt, this.apiKey);
173
+
174
+ const codePath = codeAction.filePath;
175
+ const testPath = testAction.filePath;
176
+
177
+ if (!codePath || !testPath) {
178
+ throw new Error(`Missing file path in AI response. Code: ${codePath}, Test: ${testPath}`);
179
+ }
180
+
181
+ await this.executeAction(codeAction);
182
+ await this.executeAction(testAction);
183
+
184
+ return { codePath, testPath };
185
+ } catch (error) {
186
+ console.error(`Error in Coder.run for task "${task.title}": ${error.message}`);
187
+ throw error;
188
+ }
189
+ }
190
+
191
+ async executeAction(action) {
192
+ this.statusCallback(`Executing: ${action.action} on ${action.filePath}`);
193
+ console.log(`Executing action: ${action.action}`);
194
+ switch (action.action) {
195
+ case 'writeFile':
196
+ return Action.writeFile(action.filePath, action.content);
197
+ case 'writeTest':
198
+ return Action.writeTest(action.filePath, action.content);
199
+ case 'modifyFile':
200
+ return Action.modifyFile(action.filePath, action.content);
201
+ case 'smartEdit':
202
+ return Action.smartEdit(action.filePath, action.content);
203
+ default:
204
+ console.error(`Unknown action: ${action.action}`);
205
+ return { status: 'failed', error: `Unknown action: ${action.action}` };
206
+ }
207
+ }
208
+ }
@@ -0,0 +1,52 @@
1
+ import { parentPort } from 'worker_threads';
2
+ import Coder from './coder.js';
3
+ import { initializeDatabase } from '../utils/db.js';
4
+
5
+ let dbInitialized = false;
6
+
7
+ // Redirect console logs to parent thread (for general logging)
8
+
9
+ console.log = (...args) => {
10
+ const message = args.map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg))).join(' ');
11
+ parentPort.postMessage({ type: 'log', level: 'info', message });
12
+ };
13
+
14
+ console.error = (...args) => {
15
+ const message = args.map((arg) => {
16
+ if (arg instanceof Error) {
17
+ return `${arg.message}\n${arg.stack}`;
18
+ }
19
+ return typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg);
20
+ }).join(' ');
21
+ parentPort.postMessage({ type: 'log', level: 'error', message });
22
+ };
23
+
24
+ export default async ({ task, apiKey, config }) => {
25
+ if (!dbInitialized) {
26
+ await initializeDatabase();
27
+ dbInitialized = true;
28
+ }
29
+
30
+ const statusCallback = (activity) => {
31
+ parentPort.postMessage({
32
+ type: 'activity',
33
+ taskId: task.id,
34
+ action: activity,
35
+ });
36
+ };
37
+
38
+ // Create a new Coder instance for each task to bind the specific callback
39
+ const coder = new Coder(apiKey, statusCallback);
40
+
41
+ try {
42
+ const { codePath, testPath } = await coder.run(task, config);
43
+ return {
44
+ status: 'completed', task, codePath, testPath,
45
+ };
46
+ } catch (error) {
47
+ if (error.message.includes('timed out')) {
48
+ return { status: 'timed_out', task, error: error.message };
49
+ }
50
+ return { status: 'failed', task, error: error.message };
51
+ }
52
+ };
@@ -0,0 +1,40 @@
1
+ // src/utils/db.js
2
+ import sqlite3 from 'sqlite3';
3
+ import { open } from 'sqlite';
4
+
5
+ let db;
6
+
7
+ export async function initializeDatabase() {
8
+ db = await open({
9
+ filename: ':memory:',
10
+ driver: sqlite3.Database,
11
+ });
12
+
13
+ await db.exec(`
14
+ CREATE TABLE tasks (
15
+ id TEXT PRIMARY KEY,
16
+ title TEXT,
17
+ description TEXT,
18
+ status TEXT,
19
+ dependencies TEXT,
20
+ retries INTEGER DEFAULT 0
21
+ );
22
+
23
+ CREATE TABLE agents (
24
+ id TEXT PRIMARY KEY,
25
+ name TEXT,
26
+ purpose TEXT,
27
+ type TEXT,
28
+ status TEXT,
29
+ createdAt TEXT,
30
+ supervisorId TEXT
31
+ );
32
+ `);
33
+ }
34
+
35
+ export function getDb() {
36
+ if (!db) {
37
+ throw new Error('Database not initialized. Call initializeDatabase() first.');
38
+ }
39
+ return db;
40
+ }
@@ -0,0 +1,19 @@
1
+ import EmbedAPI from '@embedapi/core';
2
+
3
+ export default async function callEmbedApi(prompt, apiKey) {
4
+ const embedApi = new EmbedAPI(apiKey);
5
+ try {
6
+ const response = await embedApi.generate({
7
+ service: 'anthropic',
8
+ model: 'claude-3-5-sonnet-20241022',
9
+ messages: [{ role: 'user', content: prompt }],
10
+ maxTokens: 2048,
11
+ timeout: 120000, // 120 seconds
12
+ });
13
+ return response.data;
14
+ } catch (error) {
15
+ console.error('Error calling EmbedAPI SDK:', error);
16
+ // Let the worker handle the timeout error
17
+ throw error;
18
+ }
19
+ }
package/test-api.js ADDED
@@ -0,0 +1,24 @@
1
+ import dotenv from 'dotenv';
2
+ import EmbedAPI from '@embedapi/core';
3
+
4
+ dotenv.config();
5
+
6
+ async function testApi() {
7
+ const apiKey = process.env.EMBEDAPI_KEY;
8
+ console.log(`API Key: ${apiKey ? '******' : 'undefined/missing'}`);
9
+
10
+ const embedApi = new EmbedAPI(apiKey);
11
+ try {
12
+ const response = await embedApi.generate({
13
+ service: 'anthropic',
14
+ model: 'claude-3-5-sonnet-20241022',
15
+ messages: [{ role: 'user', content: 'Hello!' }],
16
+ maxTokens: 10
17
+ });
18
+ console.log('API call successful:', response.data);
19
+ } catch (error) {
20
+ console.error('API call failed:', error);
21
+ }
22
+ }
23
+
24
+ testApi();