@jclaw/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.
- package/dist/auto-skill/generator.d.ts +30 -0
- package/dist/auto-skill/generator.d.ts.map +1 -0
- package/dist/auto-skill/generator.js +262 -0
- package/dist/auto-skill/generator.js.map +1 -0
- package/dist/auto-skill/index.d.ts +11 -0
- package/dist/auto-skill/index.d.ts.map +1 -0
- package/dist/auto-skill/index.js +10 -0
- package/dist/auto-skill/index.js.map +1 -0
- package/dist/auto-skill/installer.d.ts +44 -0
- package/dist/auto-skill/installer.d.ts.map +1 -0
- package/dist/auto-skill/installer.js +201 -0
- package/dist/auto-skill/installer.js.map +1 -0
- package/dist/auto-skill/types.d.ts +179 -0
- package/dist/auto-skill/types.d.ts.map +1 -0
- package/dist/auto-skill/types.js +9 -0
- package/dist/auto-skill/types.js.map +1 -0
- package/dist/cli/commands/config.d.ts +16 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +119 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/exec.d.ts +12 -0
- package/dist/cli/commands/exec.d.ts.map +1 -0
- package/dist/cli/commands/exec.js +41 -0
- package/dist/cli/commands/exec.js.map +1 -0
- package/dist/cli/index.d.ts +10 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +91 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/run.d.ts +9 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +13 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/context/index.d.ts +6 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +12 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/memsearch-client.d.ts +34 -0
- package/dist/context/memsearch-client.d.ts.map +1 -0
- package/dist/context/memsearch-client.js +182 -0
- package/dist/context/memsearch-client.js.map +1 -0
- package/dist/context/mock-client.d.ts +116 -0
- package/dist/context/mock-client.d.ts.map +1 -0
- package/dist/context/mock-client.js +150 -0
- package/dist/context/mock-client.js.map +1 -0
- package/dist/context/openviking-client.d.ts +87 -0
- package/dist/context/openviking-client.d.ts.map +1 -0
- package/dist/context/openviking-client.js +166 -0
- package/dist/context/openviking-client.js.map +1 -0
- package/dist/context/openviking-mcp-client.d.ts +29 -0
- package/dist/context/openviking-mcp-client.d.ts.map +1 -0
- package/dist/context/openviking-mcp-client.js +81 -0
- package/dist/context/openviking-mcp-client.js.map +1 -0
- package/dist/context/simple-memory-client.d.ts +43 -0
- package/dist/context/simple-memory-client.d.ts.map +1 -0
- package/dist/context/simple-memory-client.enhanced.d.ts +39 -0
- package/dist/context/simple-memory-client.enhanced.d.ts.map +1 -0
- package/dist/context/simple-memory-client.enhanced.js +207 -0
- package/dist/context/simple-memory-client.enhanced.js.map +1 -0
- package/dist/context/simple-memory-client.js +270 -0
- package/dist/context/simple-memory-client.js.map +1 -0
- package/dist/evolution/continuous.d.ts +127 -0
- package/dist/evolution/continuous.d.ts.map +1 -0
- package/dist/evolution/continuous.js +238 -0
- package/dist/evolution/continuous.js.map +1 -0
- package/dist/evolution/engine.d.ts +97 -0
- package/dist/evolution/engine.d.ts.map +1 -0
- package/dist/evolution/engine.js +187 -0
- package/dist/evolution/engine.js.map +1 -0
- package/dist/evolution/evolver-adapter.d.ts +104 -0
- package/dist/evolution/evolver-adapter.d.ts.map +1 -0
- package/dist/evolution/evolver-adapter.js +227 -0
- package/dist/evolution/evolver-adapter.js.map +1 -0
- package/dist/evolution/index.d.ts +9 -0
- package/dist/evolution/index.d.ts.map +1 -0
- package/dist/evolution/index.js +8 -0
- package/dist/evolution/index.js.map +1 -0
- package/dist/evolution/memory.d.ts +106 -0
- package/dist/evolution/memory.d.ts.map +1 -0
- package/dist/evolution/memory.js +232 -0
- package/dist/evolution/memory.js.map +1 -0
- package/dist/evolution/mutation.d.ts +66 -0
- package/dist/evolution/mutation.d.ts.map +1 -0
- package/dist/evolution/mutation.js +139 -0
- package/dist/evolution/mutation.js.map +1 -0
- package/dist/evolution/sandbox.d.ts +96 -0
- package/dist/evolution/sandbox.d.ts.map +1 -0
- package/dist/evolution/sandbox.js +194 -0
- package/dist/evolution/sandbox.js.map +1 -0
- package/dist/evolution/types.d.ts +93 -0
- package/dist/evolution/types.d.ts.map +1 -0
- package/dist/evolution/types.js +9 -0
- package/dist/evolution/types.js.map +1 -0
- package/dist/executor/index.d.ts +10 -0
- package/dist/executor/index.d.ts.map +1 -0
- package/dist/executor/index.js +10 -0
- package/dist/executor/index.js.map +1 -0
- package/dist/executor/interface.d.ts +9 -0
- package/dist/executor/interface.d.ts.map +1 -0
- package/dist/executor/interface.js +9 -0
- package/dist/executor/interface.js.map +1 -0
- package/dist/executor/local.d.ts +36 -0
- package/dist/executor/local.d.ts.map +1 -0
- package/dist/executor/local.js +95 -0
- package/dist/executor/local.js.map +1 -0
- package/dist/extension-system/capability-router.d.ts +106 -0
- package/dist/extension-system/capability-router.d.ts.map +1 -0
- package/dist/extension-system/capability-router.js +167 -0
- package/dist/extension-system/capability-router.js.map +1 -0
- package/dist/extension-system/index.d.ts +11 -0
- package/dist/extension-system/index.d.ts.map +1 -0
- package/dist/extension-system/index.js +11 -0
- package/dist/extension-system/index.js.map +1 -0
- package/dist/extension-system/loader.d.ts +93 -0
- package/dist/extension-system/loader.d.ts.map +1 -0
- package/dist/extension-system/loader.js +245 -0
- package/dist/extension-system/loader.js.map +1 -0
- package/dist/extension-system/registry.d.ts +112 -0
- package/dist/extension-system/registry.d.ts.map +1 -0
- package/dist/extension-system/registry.js +161 -0
- package/dist/extension-system/registry.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/network/client.d.ts +130 -0
- package/dist/network/client.d.ts.map +1 -0
- package/dist/network/client.js +230 -0
- package/dist/network/client.js.map +1 -0
- package/dist/network/index.d.ts +10 -0
- package/dist/network/index.d.ts.map +1 -0
- package/dist/network/index.js +10 -0
- package/dist/network/index.js.map +1 -0
- package/dist/network/protocol.d.ts +159 -0
- package/dist/network/protocol.d.ts.map +1 -0
- package/dist/network/protocol.js +118 -0
- package/dist/network/protocol.js.map +1 -0
- package/dist/runtime/agent.d.ts +124 -0
- package/dist/runtime/agent.d.ts.map +1 -0
- package/dist/runtime/agent.js +286 -0
- package/dist/runtime/agent.js.map +1 -0
- package/dist/runtime/agent_fixed.d.ts +39 -0
- package/dist/runtime/agent_fixed.d.ts.map +1 -0
- package/dist/runtime/agent_fixed.js +193 -0
- package/dist/runtime/agent_fixed.js.map +1 -0
- package/dist/runtime/index.d.ts +11 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +11 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/llm-client.d.ts +108 -0
- package/dist/runtime/llm-client.d.ts.map +1 -0
- package/dist/runtime/llm-client.js +125 -0
- package/dist/runtime/llm-client.js.map +1 -0
- package/dist/runtime/task-executor.d.ts +92 -0
- package/dist/runtime/task-executor.d.ts.map +1 -0
- package/dist/runtime/task-executor.js +203 -0
- package/dist/runtime/task-executor.js.map +1 -0
- package/dist/skill-sh/adapter.d.ts +40 -0
- package/dist/skill-sh/adapter.d.ts.map +1 -0
- package/dist/skill-sh/adapter.js +258 -0
- package/dist/skill-sh/adapter.js.map +1 -0
- package/dist/skill-sh/converter.d.ts +37 -0
- package/dist/skill-sh/converter.d.ts.map +1 -0
- package/dist/skill-sh/converter.js +175 -0
- package/dist/skill-sh/converter.js.map +1 -0
- package/dist/skill-sh/discovery.d.ts +29 -0
- package/dist/skill-sh/discovery.d.ts.map +1 -0
- package/dist/skill-sh/discovery.js +189 -0
- package/dist/skill-sh/discovery.js.map +1 -0
- package/dist/skill-sh/index.d.ts +19 -0
- package/dist/skill-sh/index.d.ts.map +1 -0
- package/dist/skill-sh/index.js +20 -0
- package/dist/skill-sh/index.js.map +1 -0
- package/dist/skill-sh/quality.d.ts +51 -0
- package/dist/skill-sh/quality.d.ts.map +1 -0
- package/dist/skill-sh/quality.js +146 -0
- package/dist/skill-sh/quality.js.map +1 -0
- package/dist/skill-sh/registry.d.ts +58 -0
- package/dist/skill-sh/registry.d.ts.map +1 -0
- package/dist/skill-sh/registry.js +118 -0
- package/dist/skill-sh/registry.js.map +1 -0
- package/dist/skill-sh/types.d.ts +228 -0
- package/dist/skill-sh/types.d.ts.map +1 -0
- package/dist/skill-sh/types.js +9 -0
- package/dist/skill-sh/types.js.map +1 -0
- package/dist/types.d.ts +199 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sandbox Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates mutations in an isolated environment.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/evolution/sandbox
|
|
7
|
+
*/
|
|
8
|
+
import path from 'path';
|
|
9
|
+
import fs from 'fs/promises';
|
|
10
|
+
import os from 'os';
|
|
11
|
+
/**
|
|
12
|
+
* Default test command template
|
|
13
|
+
*/
|
|
14
|
+
const DEFAULT_TEST_COMMAND = 'npm test -- --passWithNoTests';
|
|
15
|
+
/**
|
|
16
|
+
* Sandbox Validator
|
|
17
|
+
*
|
|
18
|
+
* Validates mutations by running tests in an isolated environment.
|
|
19
|
+
* Supports both local and docker execution modes.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const sandbox = new SandboxValidator({
|
|
24
|
+
* executor: localExecutor,
|
|
25
|
+
* testCommand: 'npm test'
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const result = await sandbox.validate(mutation);
|
|
29
|
+
* if (result.passed) {
|
|
30
|
+
* console.log('Mutation is safe to apply');
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export class SandboxValidator {
|
|
35
|
+
config;
|
|
36
|
+
/**
|
|
37
|
+
* Create a new sandbox validator.
|
|
38
|
+
*
|
|
39
|
+
* @param config - Configuration options
|
|
40
|
+
*/
|
|
41
|
+
constructor(config) {
|
|
42
|
+
this.config = {
|
|
43
|
+
timeout: 30000,
|
|
44
|
+
tempDir: os.tmpdir(),
|
|
45
|
+
testCommand: DEFAULT_TEST_COMMAND,
|
|
46
|
+
verbose: false,
|
|
47
|
+
...config,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validate a mutation in the sandbox.
|
|
52
|
+
*
|
|
53
|
+
* @param mutation - The mutation to validate
|
|
54
|
+
* @param targetPath - Path to the target file to mutate (optional)
|
|
55
|
+
* @returns Validation result
|
|
56
|
+
*/
|
|
57
|
+
async validate(mutation, targetPath) {
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
try {
|
|
60
|
+
// Create sandbox directory
|
|
61
|
+
const sandboxDir = await this.createSandbox();
|
|
62
|
+
// Apply mutation to sandbox
|
|
63
|
+
if (targetPath) {
|
|
64
|
+
await this.applyMutation(mutation, sandboxDir, targetPath);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// Create a test file for the mutation
|
|
68
|
+
const testFile = path.join(sandboxDir, 'mutation-test.ts');
|
|
69
|
+
await fs.writeFile(testFile, mutation.mutated, 'utf-8');
|
|
70
|
+
}
|
|
71
|
+
// Run validation tests
|
|
72
|
+
const result = await this.runTests(sandboxDir);
|
|
73
|
+
// Cleanup sandbox
|
|
74
|
+
await this.cleanup(sandboxDir);
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const duration = Date.now() - startTime;
|
|
79
|
+
return {
|
|
80
|
+
passed: false,
|
|
81
|
+
errors: [error instanceof Error ? error.message : 'Unknown error'],
|
|
82
|
+
duration,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Validate multiple mutations.
|
|
88
|
+
*
|
|
89
|
+
* @param mutations - Mutations to validate
|
|
90
|
+
* @param targetPath - Target file path
|
|
91
|
+
* @returns Array of validation results
|
|
92
|
+
*/
|
|
93
|
+
async validateBatch(mutations, targetPath) {
|
|
94
|
+
const results = new Map();
|
|
95
|
+
for (const mutation of mutations) {
|
|
96
|
+
const result = await this.validate(mutation, targetPath);
|
|
97
|
+
results.set(mutation.id, result);
|
|
98
|
+
}
|
|
99
|
+
return results;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Create a sandbox directory.
|
|
103
|
+
*/
|
|
104
|
+
async createSandbox() {
|
|
105
|
+
const sandboxDir = path.join(this.config.tempDir, `jclaw-sandbox-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
106
|
+
await fs.mkdir(sandboxDir, { recursive: true });
|
|
107
|
+
this.log(`Created sandbox: ${sandboxDir}`);
|
|
108
|
+
return sandboxDir;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Apply mutation to the sandbox.
|
|
112
|
+
*/
|
|
113
|
+
async applyMutation(mutation, sandboxDir, targetPath) {
|
|
114
|
+
// Get relative path
|
|
115
|
+
const fileName = path.basename(targetPath);
|
|
116
|
+
const sandboxTarget = path.join(sandboxDir, fileName);
|
|
117
|
+
// Write mutated content
|
|
118
|
+
await fs.writeFile(sandboxTarget, mutation.mutated, 'utf-8');
|
|
119
|
+
this.log(`Applied mutation to: ${sandboxTarget}`);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Run tests in the sandbox.
|
|
123
|
+
*/
|
|
124
|
+
async runTests(sandboxDir) {
|
|
125
|
+
const startTime = Date.now();
|
|
126
|
+
const errors = [];
|
|
127
|
+
let output = '';
|
|
128
|
+
try {
|
|
129
|
+
const result = await this.config.executor.execute(this.config.testCommand, {
|
|
130
|
+
cwd: sandboxDir,
|
|
131
|
+
timeout: this.config.timeout,
|
|
132
|
+
});
|
|
133
|
+
output = result.stdout + '\n' + result.stderr;
|
|
134
|
+
if (result.exitCode === 0) {
|
|
135
|
+
this.log('Tests passed');
|
|
136
|
+
return {
|
|
137
|
+
passed: true,
|
|
138
|
+
errors: [],
|
|
139
|
+
output,
|
|
140
|
+
duration: Date.now() - startTime,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.log(`Tests failed with exit code ${result.exitCode}`);
|
|
145
|
+
errors.push(`Test command exited with code ${result.exitCode}`);
|
|
146
|
+
return {
|
|
147
|
+
passed: false,
|
|
148
|
+
errors,
|
|
149
|
+
output,
|
|
150
|
+
duration: Date.now() - startTime,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
errors.push(error instanceof Error ? error.message : 'Unknown error');
|
|
156
|
+
return {
|
|
157
|
+
passed: false,
|
|
158
|
+
errors,
|
|
159
|
+
output,
|
|
160
|
+
duration: Date.now() - startTime,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Cleanup sandbox directory.
|
|
166
|
+
*/
|
|
167
|
+
async cleanup(sandboxDir) {
|
|
168
|
+
try {
|
|
169
|
+
await fs.rm(sandboxDir, { recursive: true, force: true });
|
|
170
|
+
this.log(`Cleaned up sandbox: ${sandboxDir}`);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
this.log(`Warning: Failed to cleanup sandbox: ${error}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Log message if verbose mode is enabled.
|
|
178
|
+
*/
|
|
179
|
+
log(message) {
|
|
180
|
+
if (this.config.verbose) {
|
|
181
|
+
console.log(`[SandboxValidator] ${message}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Create a new sandbox validator.
|
|
187
|
+
*
|
|
188
|
+
* @param config - Configuration options
|
|
189
|
+
* @returns New SandboxValidator instance
|
|
190
|
+
*/
|
|
191
|
+
export function createSandbox(config) {
|
|
192
|
+
return new SandboxValidator(config);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../src/evolution/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,MAAM,IAAI,CAAC;AAkBpB;;GAEG;AACH,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,gBAAgB;IACV,MAAM,CAAiE;IAExF;;;;OAIG;IACH,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,KAAK;YACd,OAAO,EAAE,EAAE,CAAC,MAAM,EAAE;YACpB,WAAW,EAAE,oBAAoB;YACjC,OAAO,EAAE,KAAK;YACd,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,CAAC,QAAkB,EAAE,UAAmB;QACpD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,2BAA2B;YAC3B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YAE9C,4BAA4B;YAC5B,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;YAC7D,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;gBAC3D,MAAM,EAAE,CAAC,SAAS,CAAC,QAA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ACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,MAAqB;IACjD,OAAO,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evolution Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for the evolution engine.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/evolution/types
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Evolution strategy types
|
|
10
|
+
*/
|
|
11
|
+
export type EvolutionStrategy = 'repair' | 'optimize' | 'innovate';
|
|
12
|
+
/**
|
|
13
|
+
* Represents a mutation in the evolution process
|
|
14
|
+
*/
|
|
15
|
+
export interface Mutation {
|
|
16
|
+
/** Unique identifier for the mutation */
|
|
17
|
+
id: string;
|
|
18
|
+
/** The strategy used to generate this mutation */
|
|
19
|
+
strategy: EvolutionStrategy;
|
|
20
|
+
/** Original code or behavior */
|
|
21
|
+
original: string;
|
|
22
|
+
/** Mutated code or behavior */
|
|
23
|
+
mutated: string;
|
|
24
|
+
/** Description of the change */
|
|
25
|
+
description: string;
|
|
26
|
+
/** Timestamp when mutation was created */
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
/** Fitness score (if evaluated) */
|
|
29
|
+
fitness?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Result of mutation validation in sandbox
|
|
33
|
+
*/
|
|
34
|
+
export interface ValidationResult {
|
|
35
|
+
/** Whether the mutation passed validation */
|
|
36
|
+
passed: boolean;
|
|
37
|
+
/** Error messages if validation failed */
|
|
38
|
+
errors: string[];
|
|
39
|
+
/** Output from validation tests */
|
|
40
|
+
output?: string;
|
|
41
|
+
/** Duration of validation in milliseconds */
|
|
42
|
+
duration: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Configuration for evolution engine
|
|
46
|
+
*/
|
|
47
|
+
export interface EvolutionConfig {
|
|
48
|
+
/** Maximum mutations per evolution cycle */
|
|
49
|
+
maxMutations?: number;
|
|
50
|
+
/** Minimum fitness threshold for accepting mutations */
|
|
51
|
+
minFitness?: number;
|
|
52
|
+
/** Enable sandbox validation */
|
|
53
|
+
enableSandbox?: boolean;
|
|
54
|
+
/** Timeout for sandbox validation in milliseconds */
|
|
55
|
+
sandboxTimeout?: number;
|
|
56
|
+
/** Strategies to use for evolution */
|
|
57
|
+
strategies?: EvolutionStrategy[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gene representation for EvoMap integration
|
|
61
|
+
*/
|
|
62
|
+
export interface Gene {
|
|
63
|
+
/** Unique gene identifier */
|
|
64
|
+
id: string;
|
|
65
|
+
/** Gene type (behavior, knowledge, skill) */
|
|
66
|
+
type: 'behavior' | 'knowledge' | 'skill';
|
|
67
|
+
/** Gene content/code */
|
|
68
|
+
content: string;
|
|
69
|
+
/** Fitness score */
|
|
70
|
+
fitness: number;
|
|
71
|
+
/** Generation number */
|
|
72
|
+
generation: number;
|
|
73
|
+
/** Parent gene IDs */
|
|
74
|
+
parents: string[];
|
|
75
|
+
/** Creation timestamp */
|
|
76
|
+
createdAt: Date;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Evolution cycle result
|
|
80
|
+
*/
|
|
81
|
+
export interface EvolutionResult {
|
|
82
|
+
/** Whether evolution produced any improvements */
|
|
83
|
+
improved: boolean;
|
|
84
|
+
/** Mutations generated in this cycle */
|
|
85
|
+
mutations: Mutation[];
|
|
86
|
+
/** Mutations that passed validation */
|
|
87
|
+
validatedMutations: Mutation[];
|
|
88
|
+
/** Best mutation (if any) */
|
|
89
|
+
bestMutation?: Mutation;
|
|
90
|
+
/** Duration of the evolution cycle */
|
|
91
|
+
duration: number;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["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AAC;IAChB,oBAAoB;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,yBAAyB;IACzB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC;IAClB,wCAAwC;IACxC,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,uCAAuC;IACvC,kBAAkB,EAAE,QAAQ,EAAE,CAAC;IAC/B,6BAA6B;IAC7B,YAAY,CAAC,EAAE,QAAQ,CAAC;IACxB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/evolution/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executor Module
|
|
3
|
+
*
|
|
4
|
+
* Re-exports executor interfaces and implementations.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/executor
|
|
7
|
+
*/
|
|
8
|
+
export type { Executor, ExecuteOptions, ExecuteResult } from './interface.js';
|
|
9
|
+
export { LocalExecutor, createLocalExecutor } from './local.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/executor/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG9E,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/executor/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,kBAAkB;AAClB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executor Interface Module
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the Executor interface and related types for the command execution system.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/executor/interface
|
|
7
|
+
*/
|
|
8
|
+
export type { Executor, ExecuteOptions, ExecuteResult } from '../types.js';
|
|
9
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../src/executor/interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../src/executor/interface.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Executor Implementation
|
|
3
|
+
*
|
|
4
|
+
* Executes shell commands locally using Node.js spawn.
|
|
5
|
+
* Supports Windows and Unix platforms with timeout control.
|
|
6
|
+
*
|
|
7
|
+
* @module @jclaw/core/executor/local
|
|
8
|
+
*/
|
|
9
|
+
import type { Executor, ExecuteOptions, ExecuteResult } from './interface.js';
|
|
10
|
+
/**
|
|
11
|
+
* Local command executor using Node.js spawn
|
|
12
|
+
*
|
|
13
|
+
* Executes shell commands on the local system with support for:
|
|
14
|
+
* - Cross-platform execution (Windows/Unix)
|
|
15
|
+
* - Configurable timeout
|
|
16
|
+
* - Working directory and environment variable customization
|
|
17
|
+
*/
|
|
18
|
+
export declare class LocalExecutor implements Executor {
|
|
19
|
+
/** Execution mode identifier */
|
|
20
|
+
readonly mode: "local";
|
|
21
|
+
/**
|
|
22
|
+
* Execute a shell command locally
|
|
23
|
+
*
|
|
24
|
+
* @param command - The command to execute
|
|
25
|
+
* @param options - Execution options (timeout, cwd, env, etc.)
|
|
26
|
+
* @returns Promise resolving to execution result
|
|
27
|
+
*/
|
|
28
|
+
execute(command: string, options?: ExecuteOptions): Promise<ExecuteResult>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a new LocalExecutor instance
|
|
32
|
+
*
|
|
33
|
+
* @returns A new LocalExecutor instance
|
|
34
|
+
*/
|
|
35
|
+
export declare function createLocalExecutor(): LocalExecutor;
|
|
36
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/executor/local.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAO9E;;;;;;;GAOG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAC5C,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAU;IAEjC;;;;;;OAMG;IACG,OAAO,CACX,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,aAAa,CAAC;CAgE1B;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAEnD"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Executor Implementation
|
|
3
|
+
*
|
|
4
|
+
* Executes shell commands locally using Node.js spawn.
|
|
5
|
+
* Supports Windows and Unix platforms with timeout control.
|
|
6
|
+
*
|
|
7
|
+
* @module @jclaw/core/executor/local
|
|
8
|
+
*/
|
|
9
|
+
import { spawn } from 'child_process';
|
|
10
|
+
/**
|
|
11
|
+
* Default timeout for command execution (5 minutes)
|
|
12
|
+
*/
|
|
13
|
+
const DEFAULT_TIMEOUT = 5 * 60 * 1000;
|
|
14
|
+
/**
|
|
15
|
+
* Local command executor using Node.js spawn
|
|
16
|
+
*
|
|
17
|
+
* Executes shell commands on the local system with support for:
|
|
18
|
+
* - Cross-platform execution (Windows/Unix)
|
|
19
|
+
* - Configurable timeout
|
|
20
|
+
* - Working directory and environment variable customization
|
|
21
|
+
*/
|
|
22
|
+
export class LocalExecutor {
|
|
23
|
+
/** Execution mode identifier */
|
|
24
|
+
mode = 'local';
|
|
25
|
+
/**
|
|
26
|
+
* Execute a shell command locally
|
|
27
|
+
*
|
|
28
|
+
* @param command - The command to execute
|
|
29
|
+
* @param options - Execution options (timeout, cwd, env, etc.)
|
|
30
|
+
* @returns Promise resolving to execution result
|
|
31
|
+
*/
|
|
32
|
+
async execute(command, options) {
|
|
33
|
+
const startTime = Date.now();
|
|
34
|
+
const timeout = options?.timeout ?? DEFAULT_TIMEOUT;
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
let stdout = '';
|
|
37
|
+
let stderr = '';
|
|
38
|
+
let timedOut = false;
|
|
39
|
+
// Determine shell based on platform
|
|
40
|
+
const isWindows = process.platform === 'win32';
|
|
41
|
+
const shell = isWindows ? 'cmd.exe' : '/bin/sh';
|
|
42
|
+
const shellArgs = isWindows ? ['/c', command] : ['-c', command];
|
|
43
|
+
// Spawn the process
|
|
44
|
+
const proc = spawn(shell, shellArgs, {
|
|
45
|
+
cwd: options?.cwd,
|
|
46
|
+
env: { ...process.env, ...options?.env },
|
|
47
|
+
windowsHide: true,
|
|
48
|
+
});
|
|
49
|
+
// Set up timeout handler
|
|
50
|
+
const timeoutId = setTimeout(() => {
|
|
51
|
+
timedOut = true;
|
|
52
|
+
proc.kill('SIGKILL');
|
|
53
|
+
}, timeout);
|
|
54
|
+
// Collect stdout
|
|
55
|
+
proc.stdout.on('data', (data) => {
|
|
56
|
+
stdout += data.toString('utf8');
|
|
57
|
+
});
|
|
58
|
+
// Collect stderr
|
|
59
|
+
proc.stderr.on('data', (data) => {
|
|
60
|
+
stderr += data.toString('utf8');
|
|
61
|
+
});
|
|
62
|
+
// Handle process completion
|
|
63
|
+
proc.on('close', (code) => {
|
|
64
|
+
clearTimeout(timeoutId);
|
|
65
|
+
const duration = Date.now() - startTime;
|
|
66
|
+
resolve({
|
|
67
|
+
stdout,
|
|
68
|
+
stderr,
|
|
69
|
+
exitCode: timedOut ? 124 : (code ?? 1),
|
|
70
|
+
duration,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
// Handle process errors
|
|
74
|
+
proc.on('error', (error) => {
|
|
75
|
+
clearTimeout(timeoutId);
|
|
76
|
+
const duration = Date.now() - startTime;
|
|
77
|
+
resolve({
|
|
78
|
+
stdout,
|
|
79
|
+
stderr: error.message,
|
|
80
|
+
exitCode: 1,
|
|
81
|
+
duration,
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Create a new LocalExecutor instance
|
|
89
|
+
*
|
|
90
|
+
* @returns A new LocalExecutor instance
|
|
91
|
+
*/
|
|
92
|
+
export function createLocalExecutor() {
|
|
93
|
+
return new LocalExecutor();
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/executor/local.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAGtC;;GAEG;AACH,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtC;;;;;;;GAOG;AACH,MAAM,OAAO,aAAa;IACxB,gCAAgC;IACvB,IAAI,GAAG,OAAgB,CAAC;IAEjC;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CACX,OAAe,EACf,OAAwB;QAExB,M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M,EAAE,CAAC,IAAY,EAAE,EAAE;gBACtC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAClC,CAAC,CAAC,CAAC;YAEH,4BAA4B;YAC5B,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAmB,EAAE,EAAE;gBACvC,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;gBAExC,OAAO,CAAC;oBACN,MAAM;oBACN,MAAM;oBACN,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;oBACtC,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,wBAAwB;YACxB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;gBAChC,YAAY,CAAC,SAAS,CAAC,CAAC;gBACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;gBAExC,OAAO,CAAC;oBACN,MAAM;oBACN,MAAM,EAAE,KAAK,CAAC,OAAO;oBACrB,QAAQ,EAAE,CAAC;oBACX,QAAQ;iBACT,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability Router
|
|
3
|
+
*
|
|
4
|
+
* Routes capability requests to the appropriate extension.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/extension-system/capability-router
|
|
7
|
+
*/
|
|
8
|
+
import type { Capability } from '../types.js';
|
|
9
|
+
import { ExtensionRegistry } from './registry.js';
|
|
10
|
+
/**
|
|
11
|
+
* Capability resolution result
|
|
12
|
+
*/
|
|
13
|
+
export interface CapabilityResolution {
|
|
14
|
+
/** Name of the extension providing the capability */
|
|
15
|
+
extensionName: string;
|
|
16
|
+
/** The resolved capability */
|
|
17
|
+
capability: Capability;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Capability Router
|
|
21
|
+
*
|
|
22
|
+
* Provides capability lookup and routing functionality.
|
|
23
|
+
* Acts as a query interface over the extension registry.
|
|
24
|
+
*/
|
|
25
|
+
export declare class CapabilityRouter {
|
|
26
|
+
private readonly registry;
|
|
27
|
+
constructor(registry: ExtensionRegistry);
|
|
28
|
+
/**
|
|
29
|
+
* Resolve a capability by name
|
|
30
|
+
*
|
|
31
|
+
* @param capabilityName - Name of the capability to resolve
|
|
32
|
+
* @returns Capability resolution or null if not found
|
|
33
|
+
*/
|
|
34
|
+
resolve(capabilityName: string): CapabilityResolution | null;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a capability is available
|
|
37
|
+
*
|
|
38
|
+
* @param name - Capability name
|
|
39
|
+
* @returns True if capability is registered
|
|
40
|
+
*/
|
|
41
|
+
hasCapability(name: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get all available capability names
|
|
44
|
+
*
|
|
45
|
+
* @returns Array of capability names
|
|
46
|
+
*/
|
|
47
|
+
getAvailableCapabilities(): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Get all capabilities with their providers
|
|
50
|
+
*
|
|
51
|
+
* @returns Array of capability resolutions
|
|
52
|
+
*/
|
|
53
|
+
getAllCapabilities(): CapabilityResolution[];
|
|
54
|
+
/**
|
|
55
|
+
* Get capabilities provided by a specific extension
|
|
56
|
+
*
|
|
57
|
+
* @param extensionName - Name of the extension
|
|
58
|
+
* @returns Array of capabilities or empty array if extension not found
|
|
59
|
+
*/
|
|
60
|
+
getCapabilitiesByExtension(extensionName: string): Capability[];
|
|
61
|
+
/**
|
|
62
|
+
* Check if an extension provides a specific capability
|
|
63
|
+
*
|
|
64
|
+
* @param extensionName - Name of the extension
|
|
65
|
+
* @param capabilityName - Name of the capability
|
|
66
|
+
* @returns True if the extension provides the capability
|
|
67
|
+
*/
|
|
68
|
+
extensionProvides(extensionName: string, capabilityName: string): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Find capability by partial name match
|
|
71
|
+
*
|
|
72
|
+
* @param partial - Partial capability name to search for
|
|
73
|
+
* @returns Array of matching capabilities
|
|
74
|
+
*/
|
|
75
|
+
searchCapabilities(partial: string): CapabilityResolution[];
|
|
76
|
+
/**
|
|
77
|
+
* Get the extension name that provides a capability
|
|
78
|
+
*
|
|
79
|
+
* @param capabilityName - Name of the capability
|
|
80
|
+
* @returns Extension name or undefined if not found
|
|
81
|
+
*/
|
|
82
|
+
getProvider(capabilityName: string): string | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Validate capability input against its schema
|
|
85
|
+
*
|
|
86
|
+
* @param capabilityName - Name of the capability
|
|
87
|
+
* @param input - Input to validate
|
|
88
|
+
* @returns True if valid, false if invalid or no schema defined
|
|
89
|
+
*/
|
|
90
|
+
validateInput(capabilityName: string, input: unknown): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Basic input validation against schema
|
|
93
|
+
*
|
|
94
|
+
* Note: This is a simplified validation. For production use,
|
|
95
|
+
* integrate a proper JSON Schema validator like ajv.
|
|
96
|
+
*/
|
|
97
|
+
private performBasicValidation;
|
|
98
|
+
/**
|
|
99
|
+
* Get capability statistics
|
|
100
|
+
*/
|
|
101
|
+
get stats(): {
|
|
102
|
+
totalCapabilities: number;
|
|
103
|
+
capabilitiesByExtension: Map<string, number>;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=capability-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capability-router.d.ts","sourceRoot":"","sources":["../../src/extension-system/capability-router.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAA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