@jclaw/core 0.4.2 ā 0.5.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.
- package/dist/runtime/agent.d.ts +3 -87
- package/dist/runtime/agent.d.ts.map +1 -1
- package/dist/runtime/agent.js +71 -222
- package/package.json +3 -3
package/dist/runtime/agent.d.ts
CHANGED
|
@@ -1,74 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Runtime
|
|
3
|
-
*
|
|
4
|
-
* Core implementation of the JClaw agent runtime.
|
|
5
|
-
* Provides task execution, context management, and lifecycle control.
|
|
6
|
-
* Now with AutoSkill support for self-evolving capabilities!
|
|
7
|
-
*
|
|
8
|
-
* @module @jclaw/core/runtime/agent
|
|
9
|
-
*/
|
|
10
1
|
import type { AgentRuntime, Task, TaskResult, ContextManager } from '../types.js';
|
|
11
2
|
import { type LLMClientConfig } from './llm-client.js';
|
|
12
3
|
import { ExtensionRegistry } from '../extension-system/registry.js';
|
|
13
|
-
import type { AutoSkillConfig,
|
|
14
|
-
import type { SkillShAdapterConfig } from '../skill-sh/types.js';
|
|
15
|
-
/**
|
|
16
|
-
* Configuration for the agent runtime
|
|
17
|
-
*/
|
|
4
|
+
import type { AutoSkillConfig, SkillShAdapterConfig } from '../auto-skill/types.js';
|
|
18
5
|
export interface AgentConfig {
|
|
19
|
-
/** Agent name */
|
|
20
6
|
name?: string;
|
|
21
|
-
/** Agent version */
|
|
22
7
|
version?: string;
|
|
23
|
-
/** Execution mode (default: 'local') */
|
|
24
8
|
executionMode?: 'local' | 'docker' | 'hybrid';
|
|
25
|
-
/** LLM client configuration */
|
|
26
9
|
llm?: LLMClientConfig;
|
|
27
|
-
/** Context manager instance */
|
|
28
10
|
contextManager?: ContextManager;
|
|
29
|
-
/** System prompt for the agent */
|
|
30
11
|
systemPrompt?: string;
|
|
31
|
-
/** Enable verbose logging */
|
|
32
12
|
verbose?: boolean;
|
|
33
|
-
/** Enable automatic skill generation */
|
|
34
13
|
enableAutoSkill?: boolean;
|
|
35
|
-
/** AutoSkill configuration */
|
|
36
14
|
autoSkillConfig?: Partial<AutoSkillConfig>;
|
|
37
|
-
/** Skill.sh configuration */
|
|
38
15
|
skillShConfig?: Partial<SkillShAdapterConfig>;
|
|
39
|
-
/** Extension registry for managing capabilities */
|
|
40
16
|
extensionRegistry?: ExtensionRegistry;
|
|
41
17
|
}
|
|
42
|
-
/**
|
|
43
|
-
* JClaw Agent Runtime
|
|
44
|
-
*
|
|
45
|
-
* The main runtime for executing tasks with the JClaw agent.
|
|
46
|
-
* Implements the AgentRuntime interface and provides:
|
|
47
|
-
* - Task execution with LLM integration
|
|
48
|
-
* - Context management through SimpleMemory
|
|
49
|
-
* - Command execution through local/docker executors
|
|
50
|
-
* - **NEW: AutoSkill for self-generating capabilities!**
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* const agent = new JClawAgent({
|
|
55
|
-
* name: 'my-agent',
|
|
56
|
-
* enableAutoSkill: true, // Enable self-evolution!
|
|
57
|
-
* llm: {
|
|
58
|
-
* apiBase: 'https://api.openai.com/v1',
|
|
59
|
-
* apiKey: process.env.OPENAI_API_KEY!,
|
|
60
|
-
* model: 'gpt-4'
|
|
61
|
-
* }
|
|
62
|
-
* });
|
|
63
|
-
*
|
|
64
|
-
* await agent.start();
|
|
65
|
-
* const result = await agent.execute({
|
|
66
|
-
* id: 'task-1',
|
|
67
|
-
* prompt: 'Analyze the project structure'
|
|
68
|
-
* });
|
|
69
|
-
* await agent.stop();
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
18
|
export declare class JClawAgent implements AgentRuntime {
|
|
73
19
|
readonly executionMode: 'local' | 'docker' | 'hybrid';
|
|
74
20
|
private readonly config;
|
|
@@ -77,48 +23,18 @@ export declare class JClawAgent implements AgentRuntime {
|
|
|
77
23
|
private running;
|
|
78
24
|
private autoSkillGenerator?;
|
|
79
25
|
private autoSkillInstaller?;
|
|
80
|
-
private
|
|
81
|
-
private _skillConverter?;
|
|
82
|
-
private _skillDiscovery?;
|
|
83
|
-
private _skillRegistry?;
|
|
26
|
+
private skillDiscovery?;
|
|
84
27
|
private evolutionEngine?;
|
|
85
|
-
|
|
86
|
-
* Create a new JClaw agent instance.
|
|
87
|
-
*
|
|
88
|
-
* @param config - Configuration options
|
|
89
|
-
*/
|
|
28
|
+
private extensionRegistry?;
|
|
90
29
|
constructor(config?: AgentConfig);
|
|
91
|
-
/**
|
|
92
|
-
* Get the context manager instance.
|
|
93
|
-
*/
|
|
94
30
|
get context(): ContextManager;
|
|
95
|
-
/**
|
|
96
|
-
* Start the agent runtime.
|
|
97
|
-
*/
|
|
98
31
|
start(): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Stop the agent runtime.
|
|
101
|
-
*/
|
|
102
32
|
stop(): Promise<void>;
|
|
103
|
-
/**
|
|
104
|
-
* Execute a task.
|
|
105
|
-
*
|
|
106
|
-
* @param task - The task to execute
|
|
107
|
-
* @returns Task execution result
|
|
108
|
-
*/
|
|
109
33
|
execute(task: Task): Promise<TaskResult>;
|
|
110
|
-
/**
|
|
111
|
-
* Execute a task with AutoSkill self-evolution support.
|
|
112
|
-
*
|
|
113
|
-
* This method attempts to execute the task, and if it fails due to missing
|
|
114
|
-
* capabilities, it will automatically discover, generate, and install new skills.
|
|
115
|
-
*/
|
|
116
34
|
private executeWithAutoSkill;
|
|
117
|
-
generateSkillsForTask(task: Task): Promise<GeneratedExtension[]>;
|
|
118
35
|
isRunning(): boolean;
|
|
119
36
|
get name(): string;
|
|
120
37
|
get version(): string;
|
|
121
|
-
private getDefaultSystemPrompt;
|
|
122
38
|
}
|
|
123
39
|
export declare function createAgent(config?: AgentConfig): JClawAgent;
|
|
124
40
|
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/runtime/agent.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/runtime/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAOpE,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC9C,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAC9C,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC;AAED,qBAAa,UAAW,YAAW,YAAY;IAC7C,QAAQ,CAAC,aAAa,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACtD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAM;IAC7B,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,kBAAkB,CAAC,CAAqB;IAChD,OAAO,CAAC,kBAAkB,CAAC,CAAqB;IAChD,OAAO,CAAC,cAAc,CAAC,CAAuB;IAC9C,OAAO,CAAC,eAAe,CAAC,CAAkB;IAC1C,OAAO,CAAC,iBAAiB,CAAC,CAAoB;gBAElC,MAAM,GAAE,WAAgB;IAapC,IAAI,OAAO,IAAI,cAAc,CAG5B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC;YAQhC,oBAAoB;IA6ClC,SAAS,IAAI,OAAO;IACpB,IAAI,IAAI,IAAI,MAAM,CAA6B;IAC/C,IAAI,OAAO,IAAI,MAAM,CAAgC;CACtD;AAED,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,CAE5D"}
|
package/dist/runtime/agent.js
CHANGED
|
@@ -1,284 +1,133 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Runtime
|
|
3
|
-
*
|
|
4
|
-
* Core implementation of the JClaw agent runtime.
|
|
5
|
-
* Provides task execution, context management, and lifecycle control.
|
|
6
|
-
* Now with AutoSkill support for self-evolving capabilities!
|
|
7
|
-
*
|
|
8
|
-
* @module @jclaw/core/runtime/agent
|
|
9
|
-
*/
|
|
10
1
|
import { TaskExecutor } from './task-executor.js';
|
|
11
2
|
import { LLMClient } from './llm-client.js';
|
|
12
|
-
import { LocalExecutor } from '../executor/local.js';
|
|
13
3
|
import { ExtensionRegistry } from '../extension-system/registry.js';
|
|
14
4
|
import { EvolutionEngine } from '../evolution/engine.js';
|
|
15
|
-
import { createAutoSkillGenerator
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Implements the AgentRuntime interface and provides:
|
|
21
|
-
* - Task execution with LLM integration
|
|
22
|
-
* - Context management through SimpleMemory
|
|
23
|
-
* - Command execution through local/docker executors
|
|
24
|
-
* - **NEW: AutoSkill for self-generating capabilities!**
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* const agent = new JClawAgent({
|
|
29
|
-
* name: 'my-agent',
|
|
30
|
-
* enableAutoSkill: true, // Enable self-evolution!
|
|
31
|
-
* llm: {
|
|
32
|
-
* apiBase: 'https://api.openai.com/v1',
|
|
33
|
-
* apiKey: process.env.OPENAI_API_KEY!,
|
|
34
|
-
* model: 'gpt-4'
|
|
35
|
-
* }
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* await agent.start();
|
|
39
|
-
* const result = await agent.execute({
|
|
40
|
-
* id: 'task-1',
|
|
41
|
-
* prompt: 'Analyze the project structure'
|
|
42
|
-
* });
|
|
43
|
-
* await agent.stop();
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
5
|
+
import { createAutoSkillGenerator } from '../auto-skill/generator.js';
|
|
6
|
+
import { createAutoSkillInstaller } from '../auto-skill/installer.js';
|
|
7
|
+
import { createSkillDiscoveryEngine } from '../skill-sh/discovery.js';
|
|
8
|
+
import { createSkillShAdapter } from '../skill-sh/adapter.js';
|
|
9
|
+
import { createSkillConverter } from '../skill-sh/converter.js';
|
|
46
10
|
export class JClawAgent {
|
|
47
11
|
executionMode;
|
|
48
12
|
config;
|
|
49
13
|
llmClient;
|
|
50
14
|
taskExecutor;
|
|
51
15
|
running = false;
|
|
52
|
-
// AutoSkill components
|
|
53
16
|
autoSkillGenerator;
|
|
54
17
|
autoSkillInstaller;
|
|
55
|
-
|
|
56
|
-
_skillShAdapter;
|
|
57
|
-
_skillConverter;
|
|
58
|
-
_skillDiscovery;
|
|
59
|
-
_skillRegistry;
|
|
18
|
+
skillDiscovery;
|
|
60
19
|
evolutionEngine;
|
|
61
|
-
|
|
62
|
-
* Create a new JClaw agent instance.
|
|
63
|
-
*
|
|
64
|
-
* @param config - Configuration options
|
|
65
|
-
*/
|
|
20
|
+
extensionRegistry;
|
|
66
21
|
constructor(config = {}) {
|
|
67
22
|
this.config = {
|
|
68
23
|
name: 'jclaw-agent',
|
|
69
24
|
version: '0.1.0',
|
|
70
25
|
executionMode: 'local',
|
|
71
|
-
systemPrompt:
|
|
26
|
+
systemPrompt: 'You are JClaw, a self-evolving AI agent.',
|
|
72
27
|
verbose: false,
|
|
73
28
|
enableAutoSkill: false,
|
|
74
|
-
autoSkillConfig: undefined,
|
|
75
29
|
...config,
|
|
76
30
|
};
|
|
77
31
|
this.executionMode = config.executionMode ?? 'local';
|
|
78
32
|
}
|
|
79
|
-
/**
|
|
80
|
-
* Get the context manager instance.
|
|
81
|
-
*/
|
|
82
33
|
get context() {
|
|
83
|
-
if (!this.config.contextManager)
|
|
34
|
+
if (!this.config.contextManager)
|
|
84
35
|
throw new Error('Context manager not configured');
|
|
85
|
-
}
|
|
86
36
|
return this.config.contextManager;
|
|
87
37
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Start the agent runtime.
|
|
90
|
-
*/
|
|
91
38
|
async start() {
|
|
92
|
-
if (this.running)
|
|
39
|
+
if (this.running)
|
|
93
40
|
return;
|
|
94
|
-
}
|
|
95
|
-
console.log(`š Starting ${this.config.name} v${this.config.version}...`);
|
|
96
|
-
// Initialize LLM client
|
|
41
|
+
console.log(`š Starting ${this.config.name} v${this.config.version}...\n`);
|
|
97
42
|
if (this.config.llm) {
|
|
98
43
|
this.llmClient = new LLMClient(this.config.llm);
|
|
99
|
-
console.log('ā
LLM client initialized');
|
|
44
|
+
console.log('ā
LLM client initialized\n');
|
|
100
45
|
}
|
|
101
|
-
// Initialize task executor
|
|
102
46
|
this.taskExecutor = new TaskExecutor({
|
|
103
47
|
llmClient: this.llmClient,
|
|
104
|
-
|
|
48
|
+
context: this.config.contextManager,
|
|
105
49
|
verbose: this.config.verbose,
|
|
106
50
|
});
|
|
107
|
-
// Initialize AutoSkill if enabled
|
|
108
51
|
if (this.config.enableAutoSkill) {
|
|
109
|
-
console.log('𧬠AutoSkill enabled - initializing self-evolution
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const registry = this.config.extensionRegistry ?? new ExtensionRegistry();
|
|
119
|
-
// Create AutoSkill components
|
|
120
|
-
this.autoSkillGenerator = createAutoSkillGenerator(this.llmClient, registry, this.evolutionEngine, this.config.autoSkillConfig);
|
|
121
|
-
this.autoSkillInstaller = createAutoSkillInstaller(registry, this.config.autoSkillConfig?.storageDir);
|
|
122
|
-
console.log('ā
AutoSkill components initialized');
|
|
52
|
+
console.log('𧬠AutoSkill enabled - initializing self-evolution...\n');
|
|
53
|
+
this.evolutionEngine = new EvolutionEngine({ populationSize: 10, mutationRate: 0.1, selectionPressure: 0.5 });
|
|
54
|
+
this.extensionRegistry = this.config.extensionRegistry ?? new ExtensionRegistry();
|
|
55
|
+
const skillShAdapter = createSkillShAdapter(this.llmClient, this.config.skillShConfig);
|
|
56
|
+
const skillConverter = createSkillConverter(this.llmClient);
|
|
57
|
+
this.autoSkillGenerator = createAutoSkillGenerator(this.llmClient, this.extensionRegistry, this.evolutionEngine, this.config.autoSkillConfig);
|
|
58
|
+
this.autoSkillInstaller = createAutoSkillInstaller(this.extensionRegistry, this.config.autoSkillConfig?.storageDir);
|
|
59
|
+
this.skillDiscovery = createSkillDiscoveryEngine(this.llmClient, this.extensionRegistry, skillShAdapter, skillConverter, this.autoSkillGenerator);
|
|
60
|
+
console.log('ā
AutoSkill components initialized\n');
|
|
123
61
|
}
|
|
124
62
|
this.running = true;
|
|
125
|
-
console.log('ā
Agent started');
|
|
63
|
+
console.log('ā
Agent started\n');
|
|
126
64
|
}
|
|
127
|
-
/**
|
|
128
|
-
* Stop the agent runtime.
|
|
129
|
-
*/
|
|
130
65
|
async stop() {
|
|
131
|
-
if (!this.running)
|
|
66
|
+
if (!this.running)
|
|
132
67
|
return;
|
|
133
|
-
}
|
|
134
68
|
console.log('š Stopping agent...');
|
|
135
69
|
this.running = false;
|
|
136
70
|
console.log('ā
Agent stopped');
|
|
137
71
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Execute a task.
|
|
140
|
-
*
|
|
141
|
-
* @param task - The task to execute
|
|
142
|
-
* @returns Task execution result
|
|
143
|
-
*/
|
|
144
72
|
async execute(task) {
|
|
145
|
-
if (!this.running)
|
|
146
|
-
throw new Error('Agent not started
|
|
147
|
-
|
|
148
|
-
if (!this.taskExecutor) {
|
|
73
|
+
if (!this.running)
|
|
74
|
+
throw new Error('Agent not started');
|
|
75
|
+
if (!this.taskExecutor)
|
|
149
76
|
throw new Error('Task executor not initialized');
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// Execute with AutoSkill retry logic if enabled
|
|
156
|
-
if (this.config.enableAutoSkill) {
|
|
157
|
-
return await this.executeWithAutoSkill(task);
|
|
158
|
-
}
|
|
159
|
-
// Simple execution without AutoSkill
|
|
160
|
-
return await this.taskExecutor.execute(task);
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
164
|
-
return {
|
|
165
|
-
taskId: task.id,
|
|
166
|
-
success: false,
|
|
167
|
-
output: '',
|
|
168
|
-
error: errorMessage,
|
|
169
|
-
duration: 0,
|
|
170
|
-
};
|
|
171
|
-
}
|
|
77
|
+
if (this.config.verbose)
|
|
78
|
+
console.log(`\nš Executing task: ${task.prompt}\n`);
|
|
79
|
+
if (this.config.enableAutoSkill)
|
|
80
|
+
return await this.executeWithAutoSkill(task);
|
|
81
|
+
return await this.taskExecutor.execute(task);
|
|
172
82
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Execute a task with AutoSkill self-evolution support.
|
|
175
|
-
*
|
|
176
|
-
* This method attempts to execute the task, and if it fails due to missing
|
|
177
|
-
* capabilities, it will automatically discover, generate, and install new skills.
|
|
178
|
-
*/
|
|
179
83
|
async executeWithAutoSkill(task) {
|
|
180
|
-
if (!this.taskExecutor)
|
|
84
|
+
if (!this.taskExecutor)
|
|
181
85
|
throw new Error('Task executor not initialized');
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// Check if error is due to missing capability
|
|
191
|
-
if (!this.autoSkillGenerator || !this.autoSkillInstaller) {
|
|
192
|
-
throw error; // AutoSkill not available
|
|
193
|
-
}
|
|
194
|
-
// Discover missing capabilities
|
|
195
|
-
console.log('š Discovering missing capabilities...');
|
|
196
|
-
const discovery = await this.autoSkillGenerator.discoverCapabilities(task);
|
|
197
|
-
if (discovery.gaps.length === 0) {
|
|
198
|
-
console.log(' No missing capabilities identified');
|
|
199
|
-
throw error; // Not a capability issue
|
|
200
|
-
}
|
|
201
|
-
console.log(` Found ${discovery.gaps.length} missing capabilities:`);
|
|
202
|
-
for (const gap of discovery.gaps) {
|
|
203
|
-
console.log(` - ${gap.capability}: ${gap.description}`);
|
|
204
|
-
}
|
|
205
|
-
// Generate and install each missing capability
|
|
206
|
-
for (const gap of discovery.gaps) {
|
|
207
|
-
console.log(`\nš§ Generating skill: ${gap.capability}...`);
|
|
208
|
-
const generation = await this.autoSkillGenerator.generateExtension(gap);
|
|
209
|
-
if (!generation.success || !generation.extension) {
|
|
210
|
-
console.error(` Failed to generate: ${generation.error}`);
|
|
211
|
-
continue;
|
|
86
|
+
const maxAttempts = this.config.autoSkillConfig?.maxGenerationAttempts || 3;
|
|
87
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
88
|
+
try {
|
|
89
|
+
console.log(`š Attempt ${attempt}/${maxAttempts}...\n`);
|
|
90
|
+
const result = await this.taskExecutor.execute(task);
|
|
91
|
+
if (result.success) {
|
|
92
|
+
console.log('ā
Task completed successfully!\n');
|
|
93
|
+
return result;
|
|
212
94
|
}
|
|
213
|
-
console.log(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
95
|
+
console.log(`ā Task failed: ${result.error}\n`);
|
|
96
|
+
if (!this.skillDiscovery || !this.autoSkillInstaller) {
|
|
97
|
+
console.log('ā ļø AutoSkill components not available\n');
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
console.log('š Analyzing missing capabilities...\n');
|
|
101
|
+
const discovery = await this.skillDiscovery.discover(task.prompt);
|
|
102
|
+
if (discovery.recommended && discovery.confidence > 0.5) {
|
|
103
|
+
console.log(`ā
Found skill: ${discovery.recommended.name}`);
|
|
104
|
+
console.log(` Source: ${discovery.source}`);
|
|
105
|
+
console.log(` Confidence: ${(discovery.confidence * 100).toFixed(0)}%\n`);
|
|
106
|
+
console.log('š¦ Installing skill...\n');
|
|
107
|
+
const installed = await this.skillDiscovery.installSkill(discovery.recommended);
|
|
108
|
+
if (installed) {
|
|
109
|
+
console.log('ā
Skill installed successfully!\n');
|
|
110
|
+
console.log('š Retrying task with new capability...\n');
|
|
111
|
+
continue;
|
|
225
112
|
}
|
|
226
113
|
}
|
|
114
|
+
if (attempt >= maxAttempts) {
|
|
115
|
+
return { taskId: task.id, success: false, output: '', error: `Task failed after ${maxAttempts} attempts. Last error: ${result.error}` };
|
|
116
|
+
}
|
|
227
117
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if (!this.autoSkillGenerator) {
|
|
235
|
-
throw new Error(`AutoSkill not enabled. Set enableAutoSkill: true in config.`);
|
|
236
|
-
}
|
|
237
|
-
console.log(`Analyzing task for skill generation...`);
|
|
238
|
-
const discovery = await this.autoSkillGenerator.discoverCapabilities(task);
|
|
239
|
-
const generated = [];
|
|
240
|
-
for (const gap of discovery.gaps) {
|
|
241
|
-
console.log(`Generating: ${gap.capability}`);
|
|
242
|
-
const result = await this.autoSkillGenerator.generateExtension(gap);
|
|
243
|
-
if (result.success && result.extension) {
|
|
244
|
-
generated.push(result.extension);
|
|
245
|
-
console.log(` Generated successfully`);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
console.error(` Failed: ${result.error}`);
|
|
118
|
+
catch (error) {
|
|
119
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
120
|
+
console.log(`ā Attempt ${attempt} failed: ${errorMessage}\n`);
|
|
121
|
+
if (attempt >= maxAttempts) {
|
|
122
|
+
return { taskId: task.id, success: false, output: '', error: `Task failed after ${maxAttempts} attempts. Last error: ${errorMessage}` };
|
|
123
|
+
}
|
|
249
124
|
}
|
|
250
125
|
}
|
|
251
|
-
return
|
|
252
|
-
}
|
|
253
|
-
isRunning() {
|
|
254
|
-
return this.running;
|
|
255
|
-
}
|
|
256
|
-
get name() {
|
|
257
|
-
return this.config.name;
|
|
258
|
-
}
|
|
259
|
-
get version() {
|
|
260
|
-
return this.config.version;
|
|
261
|
-
}
|
|
262
|
-
getDefaultSystemPrompt() {
|
|
263
|
-
return `You are JClaw, a self-evolving AI agent with persistent memory.
|
|
264
|
-
|
|
265
|
-
Core capabilities:
|
|
266
|
-
1. Understand and plan complex tasks
|
|
267
|
-
2. Execute shell commands safely
|
|
268
|
-
3. Learn from context and previous interactions
|
|
269
|
-
4. Adapt and improve over time
|
|
270
|
-
5. **Generate new skills when needed!**
|
|
271
|
-
|
|
272
|
-
Guidelines:
|
|
273
|
-
- Always think step by step
|
|
274
|
-
- Explain your reasoning clearly
|
|
275
|
-
- Use shell commands when appropriate
|
|
276
|
-
- Report errors honestly and suggest solutions
|
|
277
|
-
- Learn from mistakes and adapt
|
|
278
|
-
- **When facing a new challenge, suggest generating a new skill**
|
|
279
|
-
|
|
280
|
-
Remember: You have access to persistent memory and can evolve your own capabilities!`;
|
|
126
|
+
return { taskId: task.id, success: false, output: '', error: `Task failed after ${maxAttempts} attempts` };
|
|
281
127
|
}
|
|
128
|
+
isRunning() { return this.running; }
|
|
129
|
+
get name() { return this.config.name; }
|
|
130
|
+
get version() { return this.config.version; }
|
|
282
131
|
}
|
|
283
132
|
export function createAgent(config) {
|
|
284
133
|
return new JClawAgent(config);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jclaw/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Universal self-evolving Agent
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "Universal self-evolving Agent with improved AutoSkill retry logic",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
|
|
10
10
|
"files": ["dist", "README.md"],
|
|
11
11
|
"scripts": {"build": "tsc"},
|
|
12
|
-
"keywords": ["ai", "agent", "cli"],
|
|
12
|
+
"keywords": ["ai", "agent", "cli", "self-evolving"],
|
|
13
13
|
"author": "JClaw Team",
|
|
14
14
|
"license": "MIT"
|
|
15
15
|
}
|