@tyvm/knowhow 0.0.22 → 0.0.23

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 (134) hide show
  1. package/package.json +1 -1
  2. package/src/agents/base/base.ts +16 -7
  3. package/src/agents/configurable/ConfigAgent.ts +5 -3
  4. package/src/agents/developer/developer.ts +3 -4
  5. package/src/agents/index.ts +26 -2
  6. package/src/agents/patcher/patcher.ts +3 -5
  7. package/src/agents/researcher/researcher.ts +3 -4
  8. package/src/agents/tools/agentCall.ts +5 -2
  9. package/src/agents/tools/executeScript/definition.ts +1 -1
  10. package/src/agents/tools/executeScript/examples/dependency-injection-validation.ts +272 -0
  11. package/src/agents/tools/executeScript/examples/quick-test.ts +9 -15
  12. package/src/agents/tools/executeScript/examples/serialization-test.ts +64 -52
  13. package/src/agents/tools/executeScript/examples/test-runner.ts +9 -16
  14. package/src/agents/tools/executeScript/index.ts +27 -8
  15. package/src/agents/vim/vim.ts +3 -4
  16. package/src/ai.ts +2 -1
  17. package/src/chat.ts +4 -2
  18. package/src/cli.ts +5 -9
  19. package/src/dataset/diffs/test.ts +2 -1
  20. package/src/index.ts +3 -3
  21. package/src/services/AgentService.ts +9 -10
  22. package/src/services/EventService.ts +0 -2
  23. package/src/services/GitHub.ts +0 -1
  24. package/src/services/KnowhowClient.ts +0 -3
  25. package/src/services/Mcp.ts +0 -2
  26. package/src/services/S3.ts +0 -1
  27. package/src/services/Tools.ts +44 -5
  28. package/src/services/flags.ts +0 -1
  29. package/src/services/index.ts +56 -0
  30. package/src/services/modules/index.ts +53 -0
  31. package/src/{modules → services/modules}/types.ts +16 -5
  32. package/src/services/script-execution/SandboxContext.ts +4 -4
  33. package/src/services/script-execution/ScriptExecutor.ts +12 -10
  34. package/src/worker.ts +3 -3
  35. package/tests/integration/fileblocks/readwrite.test.ts +2 -1
  36. package/tests/integration/patching.test.ts +5 -5
  37. package/ts_build/src/agents/base/base.d.ts +9 -4
  38. package/ts_build/src/agents/base/base.js +7 -10
  39. package/ts_build/src/agents/base/base.js.map +1 -1
  40. package/ts_build/src/agents/configurable/ConfigAgent.d.ts +2 -2
  41. package/ts_build/src/agents/configurable/ConfigAgent.js +2 -2
  42. package/ts_build/src/agents/configurable/ConfigAgent.js.map +1 -1
  43. package/ts_build/src/agents/developer/developer.d.ts +2 -3
  44. package/ts_build/src/agents/developer/developer.js +3 -4
  45. package/ts_build/src/agents/developer/developer.js.map +1 -1
  46. package/ts_build/src/agents/index.d.ts +11 -2
  47. package/ts_build/src/agents/index.js +19 -3
  48. package/ts_build/src/agents/index.js.map +1 -1
  49. package/ts_build/src/agents/patcher/patcher.d.ts +2 -3
  50. package/ts_build/src/agents/patcher/patcher.js +3 -4
  51. package/ts_build/src/agents/patcher/patcher.js.map +1 -1
  52. package/ts_build/src/agents/researcher/researcher.d.ts +2 -3
  53. package/ts_build/src/agents/researcher/researcher.js +3 -4
  54. package/ts_build/src/agents/researcher/researcher.js.map +1 -1
  55. package/ts_build/src/agents/tools/agentCall.js +4 -4
  56. package/ts_build/src/agents/tools/agentCall.js.map +1 -1
  57. package/ts_build/src/agents/tools/executeScript/definition.js +1 -1
  58. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.d.ts +18 -0
  59. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js +192 -0
  60. package/ts_build/src/agents/tools/executeScript/examples/dependency-injection-validation.js.map +1 -0
  61. package/ts_build/src/agents/tools/executeScript/examples/quick-test.js +1 -4
  62. package/ts_build/src/agents/tools/executeScript/examples/quick-test.js.map +1 -1
  63. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js +38 -39
  64. package/ts_build/src/agents/tools/executeScript/examples/serialization-test.js.map +1 -1
  65. package/ts_build/src/agents/tools/executeScript/examples/test-runner.js +3 -7
  66. package/ts_build/src/agents/tools/executeScript/examples/test-runner.js.map +1 -1
  67. package/ts_build/src/agents/tools/executeScript/index.d.ts +7 -7
  68. package/ts_build/src/agents/tools/executeScript/index.js +11 -5
  69. package/ts_build/src/agents/tools/executeScript/index.js.map +1 -1
  70. package/ts_build/src/agents/vim/vim.d.ts +2 -3
  71. package/ts_build/src/agents/vim/vim.js +3 -4
  72. package/ts_build/src/agents/vim/vim.js.map +1 -1
  73. package/ts_build/src/ai.js +2 -1
  74. package/ts_build/src/ai.js.map +1 -1
  75. package/ts_build/src/chat.js +10 -9
  76. package/ts_build/src/chat.js.map +1 -1
  77. package/ts_build/src/cli.js +11 -14
  78. package/ts_build/src/cli.js.map +1 -1
  79. package/ts_build/src/dataset/diffs/test.js +2 -1
  80. package/ts_build/src/dataset/diffs/test.js.map +1 -1
  81. package/ts_build/src/index.js +10 -10
  82. package/ts_build/src/index.js.map +1 -1
  83. package/ts_build/src/services/AgentService.d.ts +7 -3
  84. package/ts_build/src/services/AgentService.js +11 -10
  85. package/ts_build/src/services/AgentService.js.map +1 -1
  86. package/ts_build/src/services/EventService.d.ts +0 -1
  87. package/ts_build/src/services/EventService.js +1 -2
  88. package/ts_build/src/services/EventService.js.map +1 -1
  89. package/ts_build/src/services/GitHub.d.ts +0 -1
  90. package/ts_build/src/services/GitHub.js +1 -2
  91. package/ts_build/src/services/GitHub.js.map +1 -1
  92. package/ts_build/src/services/KnowhowClient.d.ts +0 -1
  93. package/ts_build/src/services/KnowhowClient.js +1 -2
  94. package/ts_build/src/services/KnowhowClient.js.map +1 -1
  95. package/ts_build/src/services/Mcp.d.ts +0 -1
  96. package/ts_build/src/services/Mcp.js +1 -2
  97. package/ts_build/src/services/Mcp.js.map +1 -1
  98. package/ts_build/src/services/S3.d.ts +0 -1
  99. package/ts_build/src/services/S3.js +1 -2
  100. package/ts_build/src/services/S3.js.map +1 -1
  101. package/ts_build/src/services/Tools.d.ts +19 -1
  102. package/ts_build/src/services/Tools.js +22 -4
  103. package/ts_build/src/services/Tools.js.map +1 -1
  104. package/ts_build/src/services/flags.d.ts +0 -1
  105. package/ts_build/src/services/flags.js +1 -2
  106. package/ts_build/src/services/flags.js.map +1 -1
  107. package/ts_build/src/services/index.d.ts +25 -0
  108. package/ts_build/src/services/index.js +42 -1
  109. package/ts_build/src/services/index.js.map +1 -1
  110. package/ts_build/src/services/modules/example-usage.d.ts +11 -0
  111. package/ts_build/src/services/modules/example-usage.js +43 -0
  112. package/ts_build/src/services/modules/example-usage.js.map +1 -0
  113. package/ts_build/src/services/modules/index.d.ts +4 -0
  114. package/ts_build/src/services/modules/index.js +44 -0
  115. package/ts_build/src/services/modules/index.js.map +1 -0
  116. package/ts_build/src/services/modules/types.d.ts +47 -0
  117. package/ts_build/src/services/modules/types.js +3 -0
  118. package/ts_build/src/services/modules/types.js.map +1 -0
  119. package/ts_build/src/services/script-execution/SandboxContext.d.ts +3 -3
  120. package/ts_build/src/services/script-execution/SandboxContext.js +1 -3
  121. package/ts_build/src/services/script-execution/SandboxContext.js.map +1 -1
  122. package/ts_build/src/services/script-execution/ScriptExecutor.d.ts +3 -3
  123. package/ts_build/src/services/script-execution/ScriptExecutor.js +6 -2
  124. package/ts_build/src/services/script-execution/ScriptExecutor.js.map +1 -1
  125. package/ts_build/src/services/singletons.d.ts +17 -0
  126. package/ts_build/src/services/singletons.js +28 -0
  127. package/ts_build/src/services/singletons.js.map +1 -0
  128. package/ts_build/src/worker.js +4 -3
  129. package/ts_build/src/worker.js.map +1 -1
  130. package/ts_build/tests/integration/fileblocks/readwrite.test.js +10 -9
  131. package/ts_build/tests/integration/fileblocks/readwrite.test.js.map +1 -1
  132. package/ts_build/tests/integration/patching.test.js +9 -10
  133. package/ts_build/tests/integration/patching.test.js.map +1 -1
  134. package/src/modules/index.ts +0 -37
@@ -2,14 +2,13 @@
2
2
  /**
3
3
  * Serialization Test for executeScript - demonstrates transfer issues
4
4
  * Usage: npx ts-node src/agents/tools/executeScript/examples/serialization-test.ts
5
- *
5
+ *
6
6
  * This test demonstrates the "A non-transferable value was passed" errors
7
7
  * that occur when trying to return complex objects from executeScript.
8
8
  */
9
9
 
10
10
  import { executeScript } from "../../executeScript";
11
- import { Tools } from "../../../../services";
12
- import { Clients } from "../../../../clients";
11
+ import { services } from "../../../../services";
13
12
 
14
13
  interface TestCase {
15
14
  name: string;
@@ -26,27 +25,27 @@ const testCases: TestCase[] = [
26
25
  script: `
27
26
  console.log("Testing primitive string return");
28
27
  return "Hello World";
29
- `
28
+ `,
30
29
  },
31
-
30
+
32
31
  {
33
- name: "primitive-number",
32
+ name: "primitive-number",
34
33
  expectedToWork: true,
35
34
  description: "Simple number return - should work",
36
35
  script: `
37
36
  console.log("Testing primitive number return");
38
37
  return 42;
39
- `
38
+ `,
40
39
  },
41
40
 
42
41
  {
43
42
  name: "primitive-boolean",
44
43
  expectedToWork: true,
45
- description: "Simple boolean return - should work",
44
+ description: "Simple boolean return - should work",
46
45
  script: `
47
46
  console.log("Testing primitive boolean return");
48
47
  return true;
49
- `
48
+ `,
50
49
  },
51
50
 
52
51
  {
@@ -56,21 +55,22 @@ const testCases: TestCase[] = [
56
55
  script: `
57
56
  console.log("Testing simple array return");
58
57
  return [1, 2, 3, "hello"];
59
- `
58
+ `,
60
59
  },
61
60
 
62
61
  {
63
62
  name: "simple-object",
64
63
  expectedToWork: false, // This is where I got errors
65
- description: "Simple object return - expected to fail with transferable error",
64
+ description:
65
+ "Simple object return - expected to fail with transferable error",
66
66
  script: `
67
67
  console.log("Testing simple object return");
68
- return {
69
- message: "Hello",
70
- count: 42,
71
- success: true
68
+ return {
69
+ message: "Hello",
70
+ count: 42,
71
+ success: true
72
72
  };
73
- `
73
+ `,
74
74
  },
75
75
 
76
76
  {
@@ -86,7 +86,7 @@ const testCases: TestCase[] = [
86
86
  },
87
87
  status: "success"
88
88
  };
89
- `
89
+ `,
90
90
  },
91
91
 
92
92
  {
@@ -100,7 +100,7 @@ const testCases: TestCase[] = [
100
100
  transform: function(x) { return x * 2; },
101
101
  helper: () => "test"
102
102
  };
103
- `
103
+ `,
104
104
  },
105
105
 
106
106
  {
@@ -114,7 +114,7 @@ const testCases: TestCase[] = [
114
114
  { id: 2, name: "Bob" },
115
115
  { id: 3, name: "Charlie" }
116
116
  ];
117
- `
117
+ `,
118
118
  },
119
119
 
120
120
  {
@@ -129,7 +129,7 @@ const testCases: TestCase[] = [
129
129
  nested: { key: "value" }
130
130
  };
131
131
  return JSON.stringify(data);
132
- `
132
+ `,
133
133
  },
134
134
 
135
135
  {
@@ -138,10 +138,10 @@ const testCases: TestCase[] = [
138
138
  description: "Tool call result object - expected to fail",
139
139
  script: `
140
140
  console.log("Testing tool call result return");
141
-
141
+
142
142
  try {
143
143
  const searchResult = await callTool("fileSearch", { searchTerm: "package.json" });
144
-
144
+
145
145
  // Try to return a structured response with the tool result
146
146
  return {
147
147
  success: true,
@@ -154,7 +154,7 @@ const testCases: TestCase[] = [
154
154
  error: error.message
155
155
  };
156
156
  }
157
- `
157
+ `,
158
158
  },
159
159
 
160
160
  {
@@ -164,7 +164,7 @@ const testCases: TestCase[] = [
164
164
  script: `
165
165
  console.log("Testing Date object return");
166
166
  return new Date();
167
- `
167
+ `,
168
168
  },
169
169
 
170
170
  {
@@ -177,36 +177,33 @@ const testCases: TestCase[] = [
177
177
  map.set("key1", "value1");
178
178
  map.set("key2", "value2");
179
179
  return map;
180
- `
181
- }
180
+ `,
181
+ },
182
182
  ];
183
183
 
184
184
  async function runSerializationTests() {
185
185
  console.log("🧪 Running executeScript Serialization Tests\\n");
186
- console.log("=" .repeat(80));
186
+ console.log("=".repeat(80));
187
187
 
188
188
  const results = {
189
189
  passed: 0,
190
190
  failed: 0,
191
191
  unexpected: 0,
192
- details: [] as any[]
192
+ details: [] as any[],
193
193
  };
194
194
 
195
195
  for (const testCase of testCases) {
196
196
  console.log(`\\n📋 Testing: ${testCase.name}`);
197
197
  console.log(`📝 Description: ${testCase.description}`);
198
198
  console.log(`🎯 Expected to work: ${testCase.expectedToWork}`);
199
-
199
+
200
200
  try {
201
201
  const result = await executeScript({
202
202
  script: testCase.script,
203
203
  maxToolCalls: 5,
204
204
  maxTokens: 500,
205
205
  maxExecutionTimeMs: 10000,
206
- maxCostUsd: 0.1
207
- }, {
208
- tools: Tools,
209
- clients: Clients,
206
+ maxCostUsd: 0.1,
210
207
  });
211
208
 
212
209
  const actualWorked = result.success;
@@ -217,7 +214,11 @@ async function runSerializationTests() {
217
214
  console.log(`✅ PASS - Behaved as expected`);
218
215
  } else {
219
216
  results.unexpected++;
220
- console.log(`⚠️ UNEXPECTED - Expected ${testCase.expectedToWork ? 'success' : 'failure'}, got ${actualWorked ? 'success' : 'failure'}`);
217
+ console.log(
218
+ `⚠️ UNEXPECTED - Expected ${
219
+ testCase.expectedToWork ? "success" : "failure"
220
+ }, got ${actualWorked ? "success" : "failure"}`
221
+ );
221
222
  }
222
223
 
223
224
  results.details.push({
@@ -227,24 +228,27 @@ async function runSerializationTests() {
227
228
  matches: matchesExpectation,
228
229
  result: actualWorked ? result.result : null,
229
230
  error: actualWorked ? null : result.error,
230
- consoleOutput: result.consoleOutput
231
+ consoleOutput: result.consoleOutput,
231
232
  });
232
233
 
233
234
  if (actualWorked) {
234
235
  console.log(`📊 Result type: ${typeof result.result}`);
235
- console.log(`📊 Result: ${JSON.stringify(result.result).substring(0, 200)}${JSON.stringify(result.result).length > 200 ? '...' : ''}`);
236
+ console.log(
237
+ `📊 Result: ${JSON.stringify(result.result).substring(0, 200)}${
238
+ JSON.stringify(result.result).length > 200 ? "..." : ""
239
+ }`
240
+ );
236
241
  } else {
237
242
  console.log(`❌ Error: ${result.error}`);
238
243
  }
239
244
 
240
245
  if (result.consoleOutput.length > 0) {
241
- console.log(`📝 Console: ${result.consoleOutput.join(', ')}`);
246
+ console.log(`📝 Console: ${result.consoleOutput.join(", ")}`);
242
247
  }
243
-
244
248
  } catch (error) {
245
249
  results.failed++;
246
250
  console.log(`💥 TEST FRAMEWORK ERROR: ${error.message}`);
247
-
251
+
248
252
  results.details.push({
249
253
  name: testCase.name,
250
254
  expected: testCase.expectedToWork,
@@ -252,7 +256,7 @@ async function runSerializationTests() {
252
256
  matches: !testCase.expectedToWork,
253
257
  result: null,
254
258
  error: error.message,
255
- consoleOutput: []
259
+ consoleOutput: [],
256
260
  });
257
261
  }
258
262
  }
@@ -269,9 +273,13 @@ async function runSerializationTests() {
269
273
  if (results.unexpected > 0) {
270
274
  console.log("\\n🔍 UNEXPECTED RESULTS:");
271
275
  results.details
272
- .filter(d => !d.matches)
273
- .forEach(detail => {
274
- console.log(` - ${detail.name}: Expected ${detail.expected ? 'success' : 'failure'}, got ${detail.actual ? 'success' : 'failure'}`);
276
+ .filter((d) => !d.matches)
277
+ .forEach((detail) => {
278
+ console.log(
279
+ ` - ${detail.name}: Expected ${
280
+ detail.expected ? "success" : "failure"
281
+ }, got ${detail.actual ? "success" : "failure"}`
282
+ );
275
283
  if (detail.error) {
276
284
  console.log(` Error: ${detail.error}`);
277
285
  }
@@ -280,15 +288,19 @@ async function runSerializationTests() {
280
288
 
281
289
  // Analysis and recommendations
282
290
  console.log("\\n🔬 ANALYSIS:");
283
-
284
- const workingTypes = results.details.filter(d => d.actual).map(d => d.name);
285
- const failingTypes = results.details.filter(d => !d.actual).map(d => d.name);
286
-
291
+
292
+ const workingTypes = results.details
293
+ .filter((d) => d.actual)
294
+ .map((d) => d.name);
295
+ const failingTypes = results.details
296
+ .filter((d) => !d.actual)
297
+ .map((d) => d.name);
298
+
287
299
  console.log("\\n✅ Types that work:");
288
- workingTypes.forEach(name => console.log(` - ${name}`));
289
-
300
+ workingTypes.forEach((name) => console.log(` - ${name}`));
301
+
290
302
  console.log("\\n❌ Types that fail:");
291
- failingTypes.forEach(name => console.log(` - ${name}`));
303
+ failingTypes.forEach((name) => console.log(` - ${name}`));
292
304
 
293
305
  console.log("\\n💡 RECOMMENDATIONS:");
294
306
  console.log(" 1. Use JSON.stringify() for complex objects");
@@ -300,10 +312,10 @@ async function runSerializationTests() {
300
312
  }
301
313
 
302
314
  if (require.main === module) {
303
- runSerializationTests().catch(error => {
315
+ runSerializationTests().catch((error) => {
304
316
  console.error("Test suite failed:", error);
305
317
  process.exit(1);
306
318
  });
307
319
  }
308
320
 
309
- export { runSerializationTests, testCases };
321
+ export { runSerializationTests, testCases };
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { executeScript } from "../../executeScript";
8
- import { Tools } from "../../../../services";
8
+ import { services } from "../../../../services";
9
9
  import { Clients } from "../../../../clients";
10
10
  import { includedTools } from "../../../tools/list";
11
11
  import * as allTools from "../../../tools";
@@ -105,15 +105,11 @@ await main().then(result => {
105
105
 
106
106
  async function runTest() {
107
107
  console.log("🚀 Starting executeScript test...\n");
108
+ const { Tools } = services();
108
109
 
109
110
  try {
110
111
  Tools.defineTools(includedTools, allTools);
111
112
 
112
- const context = {
113
- tools: Tools,
114
- clients: Clients,
115
- };
116
-
117
113
  console.log("📋 Test Parameters:");
118
114
  console.log("- Max Tool Calls: 10");
119
115
  console.log("- Max Tokens: 1000");
@@ -123,16 +119,13 @@ async function runTest() {
123
119
  const startTime = Date.now();
124
120
 
125
121
  // Execute the test script
126
- const result = await executeScript(
127
- {
128
- script: testScript,
129
- maxToolCalls: 10,
130
- maxTokens: 1000,
131
- maxExecutionTimeMs: 60000,
132
- maxCostUsd: 0.5,
133
- },
134
- context
135
- );
122
+ const result = await executeScript({
123
+ script: testScript,
124
+ maxToolCalls: 10,
125
+ maxTokens: 1000,
126
+ maxExecutionTimeMs: 60000,
127
+ maxCostUsd: 0.5,
128
+ });
136
129
 
137
130
  const executionTime = Date.now() - startTime;
138
131
 
@@ -1,17 +1,36 @@
1
1
  import { ScriptExecutor } from "../../../services/script-execution/ScriptExecutor";
2
- import { Tools } from "../../../services";
3
- import { Clients } from "../../../clients";
2
+ import { ToolsService } from "../../../services/Tools";
4
3
  import {
5
4
  ExecutionRequest,
6
5
  ExecutionResult,
7
6
  } from "../../../services/script-execution/types";
7
+ import { services } from "src/services";
8
8
 
9
-
10
- export const executeScript = async (
11
- { script, maxToolCalls, maxTokens, maxExecutionTimeMs, maxCostUsd },
12
- context
13
- ) => {
9
+ export async function executeScript({
10
+ script,
11
+ maxToolCalls,
12
+ maxTokens,
13
+ maxExecutionTimeMs,
14
+ maxCostUsd,
15
+ }: {
16
+ script: string;
17
+ maxToolCalls?: number;
18
+ maxTokens?: number;
19
+ maxExecutionTimeMs?: number;
20
+ maxCostUsd?: number;
21
+ }) {
14
22
  try {
23
+ // Get context from bound ToolsService
24
+ const toolService = (
25
+ this instanceof ToolsService ? this : services().Tools
26
+ ) as ToolsService;
27
+ const toolContext = toolService.getContext();
28
+ const { Clients, Tools } = toolContext;
29
+
30
+ if (!Clients) {
31
+ throw new Error("Clients not available in tool context");
32
+ }
33
+
15
34
  // Create script executor with access to tools and clients
16
35
  const executor = new ScriptExecutor(Tools, Clients);
17
36
 
@@ -71,4 +90,4 @@ export const executeScript = async (
71
90
  },
72
91
  };
73
92
  }
74
- };
93
+ }
@@ -1,6 +1,6 @@
1
1
  import * as fs from "fs";
2
2
  import { Message } from "../../clients/types";
3
- import { BaseAgent } from "../base/base";
3
+ import { AgentContext, BaseAgent } from "../base/base";
4
4
  import { readFile, writeFile, execAsync, mkdir } from "../../utils";
5
5
  import { openai, singlePrompt, Models } from "../../ai";
6
6
  import { BASE_PROMPT } from "../base/prompt";
@@ -11,8 +11,8 @@ export class VimAgent extends BaseAgent {
11
11
 
12
12
  toolPath = ".knowhow/tools/vim";
13
13
 
14
- constructor() {
15
- super();
14
+ constructor(context: AgentContext) {
15
+ super(context);
16
16
  // this.disableTool("patchFile");
17
17
  this.setModelPreferences([
18
18
  { model: Models.anthropic.Sonnet4, provider: "anthropic" },
@@ -150,4 +150,3 @@ export class VimAgent extends BaseAgent {
150
150
  }
151
151
  }
152
152
 
153
- export const Vimmer = new VimAgent();
package/src/ai.ts CHANGED
@@ -11,7 +11,7 @@ const config = getConfigSync();
11
11
  const OPENAI_KEY = process.env.OPENAI_KEY;
12
12
 
13
13
  import { Models } from "./types";
14
- import { Agents } from "./services";
14
+ import { services } from "./services";
15
15
  export { Models };
16
16
 
17
17
  export const openai = new OpenAI({
@@ -20,6 +20,7 @@ export const openai = new OpenAI({
20
20
  });
21
21
 
22
22
  export async function singlePrompt(userPrompt: string, model = "", agent = "") {
23
+ const { Agents } = services();
23
24
  if (agent) {
24
25
  const agentConfig = await Agents.getAgent(agent);
25
26
  if (!agentConfig) {
package/src/chat.ts CHANGED
@@ -13,10 +13,10 @@ import { Marked } from "./utils";
13
13
  import { ask } from "./utils";
14
14
  import { Plugins } from "./plugins/plugins";
15
15
  import { queryEmbedding, getConfiguredEmbeddingMap } from "./embeddings";
16
- import { Agents } from "./services/AgentService";
16
+ import { services } from "./services/";
17
17
  import { FlagsService } from "./services/flags";
18
18
  import { IAgent } from "./agents/interface";
19
- import { Clients, Message } from "./clients";
19
+ import { Message } from "./clients";
20
20
  import { recordAudio, voiceToText } from "./microphone";
21
21
  import { Models } from "./ai";
22
22
  import { BaseAgent } from "./agents";
@@ -129,6 +129,7 @@ The user has asked:
129
129
  { role: "user", content: gptPrompt },
130
130
  ] as Message[];
131
131
 
132
+ const { Clients } = services();
132
133
  const response = await Clients.createCompletion(provider, {
133
134
  messages: thread,
134
135
  model,
@@ -182,6 +183,7 @@ export async function chatLoop<E extends GptQuestionEmbedding>(
182
183
  embeddings: Embeddable<E>[],
183
184
  plugins: string[] = []
184
185
  ) {
186
+ const { Agents, Clients } = services();
185
187
  let activeAgent = Agents.getAgent("Developer") as BaseAgent;
186
188
  let provider = "openai" as keyof typeof Clients.clients;
187
189
  let model = ChatModelDefaults[provider];
package/src/cli.ts CHANGED
@@ -4,26 +4,22 @@ import { generate, embed, upload, chat } from "./index";
4
4
  import { init } from "./config";
5
5
 
6
6
  import { download, purge } from ".";
7
- import { Agents } from "./services/AgentService";
8
- import { Researcher } from "./agents/researcher/researcher";
9
- import { Patcher } from "./agents/patcher/patcher";
10
- import { Vimmer } from "./agents/vim/vim";
11
- import { Developer } from "./agents/developer/developer";
12
- import { Tools } from "./services";
13
7
  import { includedTools } from "./agents/tools/list";
14
8
  import * as allTools from "./agents/tools";
15
- import { Mcp } from "./services/Mcp";
9
+ import { services } from "./services";
16
10
  import { login } from "./login";
17
11
  import { worker } from "./worker";
18
- import { Clients } from "./clients";
12
+ import { agents } from "./agents";
19
13
 
20
14
  const command = process.argv[2];
21
15
 
22
16
  async function main() {
17
+ const { Tools, Agents, Mcp, Clients } = services();
18
+ const { Researcher, Developer, Patcher } = agents();
23
19
  Agents.registerAgent(Researcher);
24
20
  Agents.registerAgent(Patcher);
25
21
  Agents.registerAgent(Developer);
26
- Agents.loadAgentsFromConfig();
22
+ Agents.loadAgentsFromConfig(services());
27
23
 
28
24
  Tools.defineTools(includedTools, allTools);
29
25
 
@@ -15,6 +15,7 @@ import {
15
15
  hunksToPatch,
16
16
  } from "../../agents/tools/patch";
17
17
  import { md5Hash } from "../../hashes";
18
+ import { services } from "../../services";
18
19
  const dataset = [];
19
20
 
20
21
  class PatchTestAgent extends PatchingAgent {
@@ -44,7 +45,7 @@ class PatchTestAgent extends PatchingAgent {
44
45
  }
45
46
 
46
47
  async function testDataset() {
47
- const patchAgent = new PatchTestAgent();
48
+ const patchAgent = new PatchTestAgent(services());
48
49
 
49
50
  let successCount = 0;
50
51
  let attempts = 0;
package/src/index.ts CHANGED
@@ -42,10 +42,8 @@ import { abort } from "process";
42
42
  import { chatLoop } from "./chat";
43
43
  import { convertToText } from "./conversion";
44
44
  import { Plugins } from "./plugins/plugins";
45
- import { AwsS3 } from "./services/S3";
46
- import { GitHub } from "./services/GitHub";
47
45
  import { knowhowMcpClient } from "./services/Mcp";
48
- import { knowhowApiClient } from "./services/KnowhowClient";
46
+ import { services } from "./services/";
49
47
  import { Models } from "./types";
50
48
 
51
49
  export * as clients from "./clients";
@@ -96,6 +94,7 @@ export async function purge(globPath: string) {
96
94
 
97
95
  export async function upload() {
98
96
  const config = await getConfig();
97
+ const { AwsS3, knowhowApiClient } = services();
99
98
 
100
99
  for (const source of config.embedSources) {
101
100
  const bucketName = source.remote;
@@ -324,6 +323,7 @@ export async function chat() {
324
323
 
325
324
  export async function download() {
326
325
  const config = await getConfig();
326
+ const { AwsS3, GitHub, knowhowApiClient } = services();
327
327
 
328
328
  for (const source of config.embedSources) {
329
329
  const { remote, remoteType } = source;
@@ -1,18 +1,19 @@
1
1
  import { getConfigSync } from "../config";
2
2
  import { IAgent } from "../agents/interface";
3
+ import { EventService } from "./EventService";
4
+ import { ToolsService } from "./Tools";
3
5
  import { ConfigAgent } from "../agents/configurable/ConfigAgent";
4
- import { Events } from "./EventService";
5
- import { Tools } from "./Tools";
6
+ import { AgentContext } from "src/agents/base/base";
6
7
 
7
8
  export class AgentService {
8
9
  private agents: Map<string, IAgent> = new Map();
9
10
 
10
- constructor() {
11
+ constructor(private tools: ToolsService, private events: EventService) {
11
12
  this.wireUp();
12
13
  }
13
14
 
14
15
  public wireUp() {
15
- Tools.addTool({
16
+ this.tools.addTool({
16
17
  type: "function",
17
18
  function: {
18
19
  name: "agentCall",
@@ -35,13 +36,13 @@ export class AgentService {
35
36
  },
36
37
  },
37
38
  });
38
- Events.on("agents:register", (data) => {
39
+ this.events.on("agents:register", (data) => {
39
40
  console.log(`Agent registered: ${data.name}`);
40
41
  const { name, agent } = data;
41
42
  this.registerAgentByName(name, agent);
42
43
  });
43
44
 
44
- Events.on("agents:call", (data) => {
45
+ this.events.on("agents:call", (data) => {
45
46
  console.log(`Agent called: ${data.name}`);
46
47
  const { name, query, resolve, reject } = data;
47
48
  this.callAgent(name, query).then(resolve).catch(reject);
@@ -77,12 +78,12 @@ export class AgentService {
77
78
  });
78
79
  }
79
80
 
80
- public loadAgentsFromConfig() {
81
+ public loadAgentsFromConfig(context: AgentContext) {
81
82
  const config = getConfigSync();
82
83
  const agents = config.agents || [];
83
84
 
84
85
  for (const agent of agents) {
85
- this.registerAgent(new ConfigAgent(agent));
86
+ this.registerAgent(new ConfigAgent(agent, context));
86
87
  }
87
88
  }
88
89
 
@@ -94,5 +95,3 @@ export class AgentService {
94
95
  return agent.call(query);
95
96
  }
96
97
  }
97
-
98
- export const Agents = new AgentService();
@@ -16,5 +16,3 @@ export class EventService extends EventEmitter {
16
16
  });
17
17
  }
18
18
  }
19
-
20
- export const Events = new EventService();
@@ -57,4 +57,3 @@ export class GitHubService {
57
57
  }
58
58
  }
59
59
 
60
- export const GitHub = new GitHubService();
@@ -108,6 +108,3 @@ export class KnowhowSimpleClient {
108
108
  }
109
109
  }
110
110
 
111
- export const knowhowApiClient = new KnowhowSimpleClient(
112
- process.env.KNOWHOW_API_URL
113
- );
@@ -286,5 +286,3 @@ export class McpService {
286
286
  return transformed;
287
287
  }
288
288
  }
289
-
290
- export const Mcp = new McpService();
@@ -123,4 +123,3 @@ export class S3Service {
123
123
  }
124
124
  }
125
125
 
126
- export const AwsS3 = new S3Service();