@cogitator-ai/self-modifying 0.1.0 → 2.0.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.
- package/README.md +60 -50
- package/dist/architecture-evolution/capability-analyzer.d.ts.map +1 -1
- package/dist/architecture-evolution/capability-analyzer.js +105 -19
- package/dist/architecture-evolution/capability-analyzer.js.map +1 -1
- package/dist/architecture-evolution/evolution-strategy.d.ts.map +1 -1
- package/dist/architecture-evolution/evolution-strategy.js +2 -6
- package/dist/architecture-evolution/evolution-strategy.js.map +1 -1
- package/dist/architecture-evolution/index.d.ts +1 -1
- package/dist/architecture-evolution/index.d.ts.map +1 -1
- package/dist/architecture-evolution/index.js +1 -1
- package/dist/architecture-evolution/index.js.map +1 -1
- package/dist/architecture-evolution/parameter-optimizer.d.ts.map +1 -1
- package/dist/architecture-evolution/parameter-optimizer.js +1 -1
- package/dist/architecture-evolution/parameter-optimizer.js.map +1 -1
- package/dist/architecture-evolution/prompts.d.ts.map +1 -1
- package/dist/architecture-evolution/prompts.js +3 -3
- package/dist/architecture-evolution/prompts.js.map +1 -1
- package/dist/constraints/index.d.ts +1 -1
- package/dist/constraints/index.d.ts.map +1 -1
- package/dist/constraints/index.js +1 -1
- package/dist/constraints/index.js.map +1 -1
- package/dist/constraints/modification-validator.d.ts.map +1 -1
- package/dist/constraints/modification-validator.js +6 -7
- package/dist/constraints/modification-validator.js.map +1 -1
- package/dist/constraints/rollback-manager.d.ts.map +1 -1
- package/dist/constraints/rollback-manager.js.map +1 -1
- package/dist/constraints/safety-constraints.d.ts.map +1 -1
- package/dist/constraints/safety-constraints.js +1 -3
- package/dist/constraints/safety-constraints.js.map +1 -1
- package/dist/events/event-emitter.js +1 -1
- package/dist/events/event-emitter.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/meta-reasoning/meta-reasoner.d.ts.map +1 -1
- package/dist/meta-reasoning/meta-reasoner.js +6 -11
- package/dist/meta-reasoning/meta-reasoner.js.map +1 -1
- package/dist/meta-reasoning/observation-collector.d.ts.map +1 -1
- package/dist/meta-reasoning/observation-collector.js +1 -3
- package/dist/meta-reasoning/observation-collector.js.map +1 -1
- package/dist/meta-reasoning/prompts.d.ts.map +1 -1
- package/dist/meta-reasoning/prompts.js +5 -3
- package/dist/meta-reasoning/prompts.js.map +1 -1
- package/dist/meta-reasoning/strategy-selector.d.ts.map +1 -1
- package/dist/meta-reasoning/strategy-selector.js +3 -1
- package/dist/meta-reasoning/strategy-selector.js.map +1 -1
- package/dist/self-modifying-agent.d.ts.map +1 -1
- package/dist/self-modifying-agent.js +27 -23
- package/dist/self-modifying-agent.js.map +1 -1
- package/dist/tool-generation/gap-analyzer.d.ts.map +1 -1
- package/dist/tool-generation/gap-analyzer.js +5 -2
- package/dist/tool-generation/gap-analyzer.js.map +1 -1
- package/dist/tool-generation/generated-tool-store.d.ts.map +1 -1
- package/dist/tool-generation/generated-tool-store.js.map +1 -1
- package/dist/tool-generation/prompts.d.ts.map +1 -1
- package/dist/tool-generation/prompts.js +8 -18
- package/dist/tool-generation/prompts.js.map +1 -1
- package/dist/tool-generation/tool-generator.d.ts +1 -1
- package/dist/tool-generation/tool-generator.d.ts.map +1 -1
- package/dist/tool-generation/tool-generator.js +3 -2
- package/dist/tool-generation/tool-generator.js.map +1 -1
- package/dist/tool-generation/tool-sandbox.d.ts.map +1 -1
- package/dist/tool-generation/tool-sandbox.js +8 -9
- package/dist/tool-generation/tool-sandbox.js.map +1 -1
- package/dist/tool-generation/tool-validator.d.ts.map +1 -1
- package/dist/tool-generation/tool-validator.js +5 -5
- package/dist/tool-generation/tool-validator.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/architecture-evolution.test.ts +131 -30
- package/src/__tests__/constraints.test.ts +61 -46
- package/src/__tests__/index.test.ts +4 -17
- package/src/__tests__/meta-reasoning.test.ts +246 -155
- package/src/__tests__/tool-generation.test.ts +26 -7
- package/src/architecture-evolution/capability-analyzer.ts +113 -31
- package/src/architecture-evolution/evolution-strategy.ts +20 -13
- package/src/architecture-evolution/index.ts +1 -4
- package/src/architecture-evolution/parameter-optimizer.ts +44 -25
- package/src/architecture-evolution/prompts.ts +17 -18
- package/src/constraints/index.ts +1 -4
- package/src/constraints/modification-validator.ts +10 -23
- package/src/constraints/rollback-manager.ts +1 -3
- package/src/constraints/safety-constraints.ts +1 -3
- package/src/events/event-emitter.ts +1 -1
- package/src/index.ts +6 -5
- package/src/meta-reasoning/meta-reasoner.ts +10 -17
- package/src/meta-reasoning/observation-collector.ts +3 -12
- package/src/meta-reasoning/prompts.ts +10 -10
- package/src/meta-reasoning/strategy-selector.ts +5 -1
- package/src/self-modifying-agent.ts +38 -45
- package/src/tool-generation/gap-analyzer.ts +19 -15
- package/src/tool-generation/generated-tool-store.ts +5 -8
- package/src/tool-generation/prompts.ts +8 -18
- package/src/tool-generation/tool-generator.ts +18 -14
- package/src/tool-generation/tool-sandbox.ts +12 -23
- package/src/tool-generation/tool-validator.ts +22 -18
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ToolSandboxConfig,
|
|
3
|
-
ToolSandboxResult,
|
|
4
|
-
GeneratedTool,
|
|
5
|
-
} from '@cogitator-ai/types';
|
|
1
|
+
import type { ToolSandboxConfig, ToolSandboxResult, GeneratedTool } from '@cogitator-ai/types';
|
|
6
2
|
|
|
7
3
|
export const DEFAULT_SANDBOX_CONFIG: ToolSandboxConfig = {
|
|
8
4
|
enabled: true,
|
|
@@ -43,10 +39,7 @@ export class ToolSandbox {
|
|
|
43
39
|
this.config = { ...DEFAULT_SANDBOX_CONFIG, ...config };
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
async execute(
|
|
47
|
-
tool: GeneratedTool,
|
|
48
|
-
params: unknown
|
|
49
|
-
): Promise<ToolSandboxResult> {
|
|
42
|
+
async execute(tool: GeneratedTool, params: unknown): Promise<ToolSandboxResult> {
|
|
50
43
|
const startTime = Date.now();
|
|
51
44
|
this.logs.length = 0;
|
|
52
45
|
|
|
@@ -114,9 +107,7 @@ export class ToolSandbox {
|
|
|
114
107
|
if (testCase.shouldThrow) {
|
|
115
108
|
passed = !execResult.success;
|
|
116
109
|
} else if (testCase.expectedOutput !== undefined) {
|
|
117
|
-
passed =
|
|
118
|
-
execResult.success &&
|
|
119
|
-
this.deepEqual(execResult.result, testCase.expectedOutput);
|
|
110
|
+
passed = execResult.success && this.deepEqual(execResult.result, testCase.expectedOutput);
|
|
120
111
|
} else {
|
|
121
112
|
passed = execResult.success;
|
|
122
113
|
}
|
|
@@ -174,9 +165,7 @@ export class ToolSandbox {
|
|
|
174
165
|
|
|
175
166
|
for (const pattern of forbidden) {
|
|
176
167
|
if (pattern.test(code)) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
`Security violation: forbidden pattern detected - ${pattern.source}`
|
|
179
|
-
);
|
|
168
|
+
throw new Error(`Security violation: forbidden pattern detected - ${pattern.source}`);
|
|
180
169
|
}
|
|
181
170
|
}
|
|
182
171
|
|
|
@@ -187,18 +176,16 @@ export class ToolSandbox {
|
|
|
187
176
|
}
|
|
188
177
|
|
|
189
178
|
private createContext(): SandboxContext {
|
|
190
|
-
const sandbox = this;
|
|
191
|
-
|
|
192
179
|
return {
|
|
193
180
|
console: {
|
|
194
181
|
log: (...args: unknown[]) => {
|
|
195
|
-
|
|
182
|
+
this.logs.push(`[LOG] ${args.map(String).join(' ')}`);
|
|
196
183
|
},
|
|
197
184
|
warn: (...args: unknown[]) => {
|
|
198
|
-
|
|
185
|
+
this.logs.push(`[WARN] ${args.map(String).join(' ')}`);
|
|
199
186
|
},
|
|
200
187
|
error: (...args: unknown[]) => {
|
|
201
|
-
|
|
188
|
+
this.logs.push(`[ERROR] ${args.map(String).join(' ')}`);
|
|
202
189
|
},
|
|
203
190
|
},
|
|
204
191
|
Math,
|
|
@@ -247,6 +234,7 @@ export class ToolSandbox {
|
|
|
247
234
|
}, timeout);
|
|
248
235
|
|
|
249
236
|
try {
|
|
237
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
250
238
|
const factory = new Function(wrappedCode);
|
|
251
239
|
const executor = factory();
|
|
252
240
|
|
|
@@ -255,13 +243,13 @@ export class ToolSandbox {
|
|
|
255
243
|
clearTimeout(timer);
|
|
256
244
|
resolve(result);
|
|
257
245
|
})
|
|
258
|
-
.catch((error) => {
|
|
246
|
+
.catch((error: unknown) => {
|
|
259
247
|
clearTimeout(timer);
|
|
260
|
-
reject(error);
|
|
248
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
261
249
|
});
|
|
262
250
|
} catch (error) {
|
|
263
251
|
clearTimeout(timer);
|
|
264
|
-
reject(error);
|
|
252
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
265
253
|
}
|
|
266
254
|
});
|
|
267
255
|
}
|
|
@@ -272,6 +260,7 @@ export class ToolSandbox {
|
|
|
272
260
|
startTime: number
|
|
273
261
|
): Promise<ToolSandboxResult> {
|
|
274
262
|
try {
|
|
263
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
275
264
|
const factory = new Function(`
|
|
276
265
|
"use strict";
|
|
277
266
|
${tool.implementation}
|
|
@@ -56,9 +56,9 @@ const STATIC_VALIDATION_RULES: ValidationRule[] = [
|
|
|
56
56
|
name: 'No prototype pollution',
|
|
57
57
|
severity: 'error',
|
|
58
58
|
check: (code) => {
|
|
59
|
-
if (
|
|
59
|
+
if (code.includes('__proto__')) return 'Uses __proto__';
|
|
60
60
|
if (/\.prototype\s*=/.test(code)) return 'Modifies prototype';
|
|
61
|
-
if (
|
|
61
|
+
if (code.includes('Object.setPrototypeOf')) return 'Uses setPrototypeOf';
|
|
62
62
|
return null;
|
|
63
63
|
},
|
|
64
64
|
},
|
|
@@ -67,10 +67,10 @@ const STATIC_VALIDATION_RULES: ValidationRule[] = [
|
|
|
67
67
|
name: 'No obvious infinite loops',
|
|
68
68
|
severity: 'warning',
|
|
69
69
|
check: (code) => {
|
|
70
|
-
if (/while\s*\(\s*true\s*\)/.test(code) &&
|
|
70
|
+
if (/while\s*\(\s*true\s*\)/.test(code) && !code.includes('break')) {
|
|
71
71
|
return 'Contains while(true) without break';
|
|
72
72
|
}
|
|
73
|
-
if (/for\s*\(\s*;\s*;\s*\)/.test(code) &&
|
|
73
|
+
if (/for\s*\(\s*;\s*;\s*\)/.test(code) && !code.includes('break')) {
|
|
74
74
|
return 'Contains for(;;) without break';
|
|
75
75
|
}
|
|
76
76
|
return null;
|
|
@@ -107,7 +107,7 @@ const STATIC_VALIDATION_RULES: ValidationRule[] = [
|
|
|
107
107
|
name: 'No shell command execution',
|
|
108
108
|
severity: 'error',
|
|
109
109
|
check: (code) => {
|
|
110
|
-
if (
|
|
110
|
+
if (code.includes('child_process')) return 'Uses child_process';
|
|
111
111
|
if (/\bexec\s*\(/.test(code)) return 'Uses exec()';
|
|
112
112
|
if (/\bspawn\s*\(/.test(code)) return 'Uses spawn()';
|
|
113
113
|
if (/\bexecSync\s*\(/.test(code)) return 'Uses execSync()';
|
|
@@ -188,7 +188,10 @@ export class ToolValidator {
|
|
|
188
188
|
if (sandboxResult.failed > 0) {
|
|
189
189
|
const failedTests = sandboxResult.results.filter((r) => !r.passed);
|
|
190
190
|
logicIssues.push(
|
|
191
|
-
...failedTests.map(
|
|
191
|
+
...failedTests.map(
|
|
192
|
+
(t) =>
|
|
193
|
+
`Test failed for input ${JSON.stringify(t.input)}: ${t.error || 'unexpected output'}`
|
|
194
|
+
)
|
|
192
195
|
);
|
|
193
196
|
}
|
|
194
197
|
|
|
@@ -266,15 +269,18 @@ export class ToolValidator {
|
|
|
266
269
|
}))
|
|
267
270
|
);
|
|
268
271
|
|
|
269
|
-
const response = await this.callLLM(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
const response = await this.callLLM(
|
|
273
|
+
[
|
|
274
|
+
{
|
|
275
|
+
role: 'system',
|
|
276
|
+
content: `You are a security auditor and code reviewer.
|
|
273
277
|
Analyze code for security vulnerabilities, logic errors, and edge cases.
|
|
274
278
|
Be thorough but practical - focus on real issues.`,
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
279
|
+
},
|
|
280
|
+
{ role: 'user', content: prompt },
|
|
281
|
+
],
|
|
282
|
+
0.2
|
|
283
|
+
);
|
|
278
284
|
|
|
279
285
|
return response ? parseValidationResponse(response.content) : null;
|
|
280
286
|
} catch {
|
|
@@ -285,15 +291,13 @@ Be thorough but practical - focus on real issues.`,
|
|
|
285
291
|
private generateBasicTestCases(
|
|
286
292
|
tool: GeneratedTool
|
|
287
293
|
): Array<{ input: unknown; expectedOutput?: unknown; shouldThrow?: boolean }> {
|
|
288
|
-
const testCases: Array<{ input: unknown; expectedOutput?: unknown; shouldThrow?: boolean }> =
|
|
294
|
+
const testCases: Array<{ input: unknown; expectedOutput?: unknown; shouldThrow?: boolean }> =
|
|
295
|
+
[];
|
|
289
296
|
const params = tool.parameters;
|
|
290
297
|
|
|
291
298
|
if (params.type === 'object' && params.properties) {
|
|
292
299
|
const validInput: Record<string, unknown> = {};
|
|
293
|
-
const properties = params.properties as Record<
|
|
294
|
-
string,
|
|
295
|
-
{ type?: string; default?: unknown }
|
|
296
|
-
>;
|
|
300
|
+
const properties = params.properties as Record<string, { type?: string; default?: unknown }>;
|
|
297
301
|
|
|
298
302
|
for (const [key, schema] of Object.entries(properties)) {
|
|
299
303
|
validInput[key] = this.generateSampleValue(schema.type, schema.default);
|