@jclaw/core 0.7.0 → 0.8.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/auto-skill/types.d.ts +15 -0
- package/dist/auto-skill/types.d.ts.map +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +5 -4
- package/dist/context/memsearch-ts-client.d.ts +37 -0
- package/dist/context/memsearch-ts-client.d.ts.map +1 -0
- package/dist/context/memsearch-ts-client.js +121 -0
- package/dist/evolution/mutation.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/planning/index.d.ts +8 -0
- package/dist/planning/index.d.ts.map +1 -0
- package/dist/planning/index.js +6 -0
- package/dist/planning/planner.d.ts +23 -0
- package/dist/planning/planner.d.ts.map +1 -0
- package/dist/planning/planner.js +184 -0
- package/dist/planning/types.d.ts +34 -0
- package/dist/planning/types.d.ts.map +1 -0
- package/dist/planning/types.js +6 -0
- package/dist/runtime/agent.d.ts +3 -3
- package/dist/runtime/agent.d.ts.map +1 -1
- package/dist/runtime/agent.js +83 -42
- package/dist/runtime/llm-client.d.ts +7 -0
- package/dist/runtime/llm-client.d.ts.map +1 -1
- package/dist/runtime/task-executor.d.ts +4 -0
- package/dist/runtime/task-executor.d.ts.map +1 -1
- package/dist/runtime/task-executor.js +35 -58
- package/package.json +3 -2
|
@@ -176,4 +176,19 @@ export interface SkillVersion {
|
|
|
176
176
|
/** 创建时间 */
|
|
177
177
|
createdAt: Date;
|
|
178
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* Skill.sh Adapter Configuration
|
|
181
|
+
*/
|
|
182
|
+
export interface SkillShAdapterConfig {
|
|
183
|
+
/** API base URL */
|
|
184
|
+
apiBase?: string;
|
|
185
|
+
/** API key for authentication */
|
|
186
|
+
apiKey?: string;
|
|
187
|
+
/** Request timeout in milliseconds */
|
|
188
|
+
timeout?: number;
|
|
189
|
+
/** Enable caching */
|
|
190
|
+
enableCache?: boolean;
|
|
191
|
+
/** Cache TTL in seconds */
|
|
192
|
+
cacheTtl?: number;
|
|
193
|
+
}
|
|
179
194
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auto-skill/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,WAAW;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,kBAAkB;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,YAAY;IACZ,UAAU,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IAC5C,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,aAAa;IACb,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,GAAG,EAAE,aAAa,CAAC;IACnB,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY;IACZ,WAAW,EAAE,IAAI,CAAC;IAClB,YAAY;IACZ,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,eAAe;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe;IACf,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,aAAa;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB;IACjB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AC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa;IACb,UAAU,CAAC,EAAE,IAAI,CAAC;IAClB,WAAW;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY;IACZ,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW;IACX,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,WAAW;IACX,UAAU,EAAE,eAAe,CAAC;IAC5B,YAAY;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,SAAS,EAAE,IAAI,CAAC;CACjB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auto-skill/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,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AW,iBAAiB;IAChC,YAAY;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY;IACZ,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,sBAAsB;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW;IACX,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,WAAW;IACX,UAAU,EAAE,eAAe,CAAC;IAC5B,YAAY;IACZ,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,UAAU;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW;IACX,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,mBAAmB;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Context Module
|
|
3
3
|
*/
|
|
4
|
+
export { MemSearchTsClient, type MemSearchTsConfig, createMemSearchTsClient } from './memsearch-ts-client.js';
|
|
4
5
|
export { SimpleMemoryClient, type SimpleMemoryConfig, createSimpleMemoryClient } from './simple-memory-client.js';
|
|
5
6
|
export { MockClient } from './mock-client.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,KAAK,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAG9G,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAQlH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/context/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Context Module
|
|
3
3
|
*/
|
|
4
|
-
//
|
|
4
|
+
// MemSearch-TS (推荐 - 纯 TypeScript,零 Python 依赖,语义搜索)
|
|
5
|
+
export { MemSearchTsClient, createMemSearchTsClient } from './memsearch-ts-client.js';
|
|
6
|
+
// SimpleMemory (备选 - 纯 JavaScript,无需向量数据库)
|
|
5
7
|
export { SimpleMemoryClient, createSimpleMemoryClient } from './simple-memory-client.js';
|
|
6
|
-
// MemSearch (需要 Python
|
|
8
|
+
// MemSearch (已弃用 - 需要 Python)
|
|
7
9
|
// export { MemSearchClient, type MemSearchConfig, createMemSearchClient } from './memsearch-client.js';
|
|
8
|
-
// OpenViking (已弃用 - 需要 Docker
|
|
10
|
+
// OpenViking (已弃用 - 需要 Docker)
|
|
9
11
|
// export { OpenVikingClient, type OpenVikingConfig } from './openviking-client.js';
|
|
10
|
-
// export { OpenVikingMCPClient, type OpenVikingMCPConfig, createOpenVikingMCPClient } from './openviking-mcp-client.js';
|
|
11
12
|
export { MockClient } from './mock-client.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MemSearch-TS Client
|
|
3
|
+
*
|
|
4
|
+
* TypeScript-native semantic memory client using memsearch-core.
|
|
5
|
+
* Zero Python dependency, built on Milvus vector database.
|
|
6
|
+
*
|
|
7
|
+
* @module @jclaw/core/context/memsearch-ts-client
|
|
8
|
+
*/
|
|
9
|
+
import type { ContextManager } from '../types.js';
|
|
10
|
+
export interface MemSearchTsConfig {
|
|
11
|
+
memoryPath?: string;
|
|
12
|
+
embeddingProvider?: 'openai' | 'ollama';
|
|
13
|
+
embeddingModel?: string;
|
|
14
|
+
milvusUri?: string;
|
|
15
|
+
collectionName?: string;
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class MemSearchTsClient implements ContextManager {
|
|
19
|
+
private initialized;
|
|
20
|
+
private readonly config;
|
|
21
|
+
private mem;
|
|
22
|
+
constructor(config?: MemSearchTsConfig);
|
|
23
|
+
connect(): Promise<void>;
|
|
24
|
+
disconnect(): Promise<void>;
|
|
25
|
+
query(question: string, options?: {
|
|
26
|
+
topK?: number;
|
|
27
|
+
}): Promise<string>;
|
|
28
|
+
saveMemory(content: string, title?: string): Promise<void>;
|
|
29
|
+
addResource(resourcePath: string): Promise<string>;
|
|
30
|
+
isConnected(): boolean;
|
|
31
|
+
getStats(): {
|
|
32
|
+
memoryPath: string;
|
|
33
|
+
connected: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare function createMemSearchTsClient(config?: MemSearchTsConfig): MemSearchTsClient;
|
|
37
|
+
//# sourceMappingURL=memsearch-ts-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memsearch-ts-client.d.ts","sourceRoot":"","sources":["../../src/context/memsearch-ts-client.ts"],"names":[],"mappings":"AAAA;;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ependency, built on Milvus vector database.
|
|
6
|
+
*
|
|
7
|
+
* @module @jclaw/core/context/memsearch-ts-client
|
|
8
|
+
*/
|
|
9
|
+
import { writeFile, mkdir } from 'fs/promises';
|
|
10
|
+
import { existsSync } from 'fs';
|
|
11
|
+
import { join } from 'path';
|
|
12
|
+
export class MemSearchTsClient {
|
|
13
|
+
initialized = false;
|
|
14
|
+
config;
|
|
15
|
+
mem = null;
|
|
16
|
+
constructor(config = {}) {
|
|
17
|
+
this.config = {
|
|
18
|
+
memoryPath: config.memoryPath || './.jclaw/memory',
|
|
19
|
+
embeddingProvider: config.embeddingProvider || 'openai',
|
|
20
|
+
embeddingModel: config.embeddingModel || 'text-embedding-3-small',
|
|
21
|
+
milvusUri: config.milvusUri || join(process.env.HOME || '.', '.jclaw', 'milvus.db'),
|
|
22
|
+
collectionName: config.collectionName || 'jclaw_memories',
|
|
23
|
+
verbose: config.verbose || false,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async connect() {
|
|
27
|
+
try {
|
|
28
|
+
if (!existsSync(this.config.memoryPath)) {
|
|
29
|
+
await mkdir(this.config.memoryPath, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
const { MemSearch } = await import('memsearch-core');
|
|
32
|
+
this.mem = new MemSearch({
|
|
33
|
+
paths: [this.config.memoryPath],
|
|
34
|
+
embedding: {
|
|
35
|
+
provider: this.config.embeddingProvider,
|
|
36
|
+
model: this.config.embeddingModel,
|
|
37
|
+
},
|
|
38
|
+
milvus: {
|
|
39
|
+
uri: this.config.milvusUri,
|
|
40
|
+
collection: this.config.collectionName,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
await this.mem.index();
|
|
44
|
+
this.initialized = true;
|
|
45
|
+
if (this.config.verbose) {
|
|
46
|
+
console.log('[MemSearch-TS] Connected, memory path: ' + this.config.memoryPath);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
51
|
+
throw new Error('Failed to initialize MemSearch-TS: ' + message);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async disconnect() {
|
|
55
|
+
if (this.mem) {
|
|
56
|
+
this.mem.close();
|
|
57
|
+
this.mem = null;
|
|
58
|
+
}
|
|
59
|
+
this.initialized = false;
|
|
60
|
+
}
|
|
61
|
+
async query(question, options) {
|
|
62
|
+
if (!this.initialized || !this.mem) {
|
|
63
|
+
throw new Error('MemSearch-TS client not initialized');
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await this.mem.index();
|
|
67
|
+
const results = await this.mem.search(question, { topK: options?.topK ?? 5 });
|
|
68
|
+
if (this.config.verbose) {
|
|
69
|
+
console.log('[MemSearch-TS] Found ' + results.length + ' results');
|
|
70
|
+
}
|
|
71
|
+
return results.map((r, i) => '[' + (i + 1) + '] (score: ' + r.score.toFixed(2) + ')\n' + r.content).join('\n\n---\n\n');
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (this.config.verbose) {
|
|
75
|
+
console.error('[MemSearch-TS] Search failed:', error);
|
|
76
|
+
}
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async saveMemory(content, title) {
|
|
81
|
+
const date = new Date().toISOString().split('T')[0];
|
|
82
|
+
const timestamp = new Date().toISOString();
|
|
83
|
+
const fileName = date + '.md';
|
|
84
|
+
const filePath = join(this.config.memoryPath, fileName);
|
|
85
|
+
const entry = title
|
|
86
|
+
? '\n## ' + title + '\n\n> Saved at: ' + timestamp + '\n\n' + content + '\n\n---\n'
|
|
87
|
+
: '\n> Saved at: ' + timestamp + '\n\n' + content + '\n\n---\n';
|
|
88
|
+
await writeFile(filePath, entry, { flag: 'a' });
|
|
89
|
+
if (this.config.verbose) {
|
|
90
|
+
console.log('[MemSearch-TS] Saved memory: ' + (title || 'untitled'));
|
|
91
|
+
}
|
|
92
|
+
if (this.mem) {
|
|
93
|
+
await this.mem.index();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async addResource(resourcePath) {
|
|
97
|
+
if (!this.initialized) {
|
|
98
|
+
throw new Error('MemSearch-TS client not initialized');
|
|
99
|
+
}
|
|
100
|
+
const { copyFile } = await import('fs/promises');
|
|
101
|
+
const { basename } = await import('path');
|
|
102
|
+
const destPath = join(this.config.memoryPath, basename(resourcePath));
|
|
103
|
+
await copyFile(resourcePath, destPath);
|
|
104
|
+
if (this.mem) {
|
|
105
|
+
await this.mem.index();
|
|
106
|
+
}
|
|
107
|
+
return destPath;
|
|
108
|
+
}
|
|
109
|
+
isConnected() {
|
|
110
|
+
return this.initialized;
|
|
111
|
+
}
|
|
112
|
+
getStats() {
|
|
113
|
+
return {
|
|
114
|
+
memoryPath: this.config.memoryPath,
|
|
115
|
+
connected: this.initialized,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function createMemSearchTsClient(config) {
|
|
120
|
+
return new MemSearchTsClient(config);
|
|
121
|
+
}
|
|
@@ -111,7 +111,7 @@ export class MutationGenerator {
|
|
|
111
111
|
},
|
|
112
112
|
];
|
|
113
113
|
try {
|
|
114
|
-
const response = await this.config.llmClient.chat(messages
|
|
114
|
+
const response = await this.config.llmClient.chat(messages);
|
|
115
115
|
return response.content.trim();
|
|
116
116
|
}
|
|
117
117
|
catch {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,5 @@ export { MutationGenerator, createMutationGenerator, type MutationGeneratorConfi
|
|
|
12
12
|
export { AutoSkillGenerator, createAutoSkillGenerator, AutoSkillInstaller, createAutoSkillInstaller, type AutoSkillConfig, type CapabilityGap, type DiscoveryResult, type GeneratedExtension, type GenerationResult, type GenerationStep, type InstallationResult, type SkillUsageStats, type AutoSkillMetadata, type SkillVersion, } from './auto-skill/index.js';
|
|
13
13
|
export { A2AProtocol, GEPProtocol, type A2AMessage, type A2AMessageType, type GEPPacket, type NodeInfo, type GeneSharePayload, type GeneRequestPayload, type TaskDelegatePayload, EvoMapClient, createEvoMapClient, type EvoMapConfig, type GeneResponse, } from './network/index.js';
|
|
14
14
|
export { fileOperationsExtension } from './extensions/built-in/file-operations.js';
|
|
15
|
+
export { Planner, createPlanner, type Step, type StepStatus, type Plan, type PlannerConfig, type PlanAdjustment, } from './planning/index.js';
|
|
15
16
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,YAAY,EACV,IAAI,EACJ,UAAU,EACV,cAAc,EACd,aAAa,EACb,QAAQ,EACR,cAAc,EACd,UAAU,EACV,SAAS,EACT,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAGzE,OAAO,EACL,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,wBAAwB,EACxB,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,YAAY,EACZ,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,UAAU,EACV,WAAW,EACX,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,gBAAgB,EAChB,aAAa,EACb,KAAK,aAAa,EAClB,eAAe,EACf,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAC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,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,cAAc,GACpB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,3 +18,5 @@ export { AutoSkillGenerator, createAutoSkillGenerator, AutoSkillInstaller, creat
|
|
|
18
18
|
// Network
|
|
19
19
|
export { A2AProtocol, GEPProtocol, EvoMapClient, createEvoMapClient, } from './network/index.js';
|
|
20
20
|
export { fileOperationsExtension } from './extensions/built-in/file-operations.js';
|
|
21
|
+
// Planning Module (任务规划)
|
|
22
|
+
export { Planner, createPlanner, } from './planning/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/planning/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Planner
|
|
3
|
+
*
|
|
4
|
+
* Breaks down tasks into executable steps using LLM.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/planning/planner
|
|
7
|
+
*/
|
|
8
|
+
import type { LLMClient } from '../runtime/llm-client.js';
|
|
9
|
+
import type { Plan, Step, PlannerConfig, PlanAdjustment } from './types.js';
|
|
10
|
+
export declare class Planner {
|
|
11
|
+
private readonly llmClient;
|
|
12
|
+
private readonly config;
|
|
13
|
+
constructor(llmClient: LLMClient, config?: PlannerConfig);
|
|
14
|
+
plan(taskPrompt: string, relevantExperiences?: string): Promise<Plan>;
|
|
15
|
+
adjust(plan: Plan, failedStep: Step, error: string): Promise<PlanAdjustment>;
|
|
16
|
+
getNextStep(plan: Plan): Step | null;
|
|
17
|
+
advanceStep(plan: Plan, output?: unknown): Plan;
|
|
18
|
+
markStepFailed(plan: Plan, error: string): Plan;
|
|
19
|
+
isComplete(plan: Plan): boolean;
|
|
20
|
+
private parseSteps;
|
|
21
|
+
}
|
|
22
|
+
export declare function createPlanner(llmClient: LLMClient, config?: PlannerConfig): Planner;
|
|
23
|
+
//# sourceMappingURL=planner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.d.ts","sourceRoot":"","sources":["../../src/planning/planner.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA+B5E,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;gBAErC,SAAS,EAAE,SAAS,EAAE,MAAM,GAAE,aAAkB;IAQtD,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmDrE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IA8BlF,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;IAOpC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IAkB/C,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAgB/C,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAI/B,OAAO,CAAC,UAAU;CA6BnB;AAED,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAEnF"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Planner
|
|
3
|
+
*
|
|
4
|
+
* Breaks down tasks into executable steps using LLM.
|
|
5
|
+
*
|
|
6
|
+
* @module @jclaw/core/planning/planner
|
|
7
|
+
*/
|
|
8
|
+
const PLANNING_PROMPT = `You are a task planner. Break down the given task into clear, sequential steps.
|
|
9
|
+
|
|
10
|
+
Available capabilities:
|
|
11
|
+
- file_read: Read file contents
|
|
12
|
+
- file_write: Write to file
|
|
13
|
+
- file_create: Create new file
|
|
14
|
+
- file_delete: Delete file
|
|
15
|
+
- dir_create: Create directory
|
|
16
|
+
- dir_list: List directory contents
|
|
17
|
+
- file_glob: Search files by pattern
|
|
18
|
+
- file_find: Find file by name
|
|
19
|
+
|
|
20
|
+
Task: {TASK}
|
|
21
|
+
|
|
22
|
+
{CONTEXT}
|
|
23
|
+
|
|
24
|
+
Output ONLY a JSON array of steps, each with:
|
|
25
|
+
- description: What to do (string)
|
|
26
|
+
- capability: Which capability to use (string, optional)
|
|
27
|
+
|
|
28
|
+
Example:
|
|
29
|
+
[
|
|
30
|
+
{"description": "Read the configuration file", "capability": "file_read"},
|
|
31
|
+
{"description": "Analyze the content and prepare modifications"},
|
|
32
|
+
{"description": "Write the updated configuration", "capability": "file_write"}
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
Steps:`;
|
|
36
|
+
export class Planner {
|
|
37
|
+
llmClient;
|
|
38
|
+
config;
|
|
39
|
+
constructor(llmClient, config = {}) {
|
|
40
|
+
this.llmClient = llmClient;
|
|
41
|
+
this.config = {
|
|
42
|
+
maxSteps: config.maxSteps ?? 5,
|
|
43
|
+
verbose: config.verbose ?? false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async plan(taskPrompt, relevantExperiences) {
|
|
47
|
+
const taskId = 'plan-' + Date.now() + '-' + Math.random().toString(36).substr(2, 9);
|
|
48
|
+
// Build prompt
|
|
49
|
+
let prompt = PLANNING_PROMPT.replace('{TASK}', taskPrompt);
|
|
50
|
+
prompt = prompt.replace('{CONTEXT}', relevantExperiences
|
|
51
|
+
? 'Relevant past experiences:\n' + relevantExperiences
|
|
52
|
+
: 'No relevant past experiences found.');
|
|
53
|
+
try {
|
|
54
|
+
// Get plan from LLM
|
|
55
|
+
const response = await this.llmClient.chat([
|
|
56
|
+
{ role: 'user', content: prompt }
|
|
57
|
+
]);
|
|
58
|
+
// Parse steps
|
|
59
|
+
const steps = this.parseSteps(response.content);
|
|
60
|
+
if (this.config.verbose) {
|
|
61
|
+
console.log('[Planner] Created plan with ' + steps.length + ' steps');
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
taskId,
|
|
65
|
+
taskPrompt,
|
|
66
|
+
steps,
|
|
67
|
+
currentStepIndex: 0,
|
|
68
|
+
createdAt: Date.now(),
|
|
69
|
+
relevantExperiences,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
// Fallback: single-step plan
|
|
74
|
+
if (this.config.verbose) {
|
|
75
|
+
console.log('[Planner] Using fallback single-step plan');
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
taskId,
|
|
79
|
+
taskPrompt,
|
|
80
|
+
steps: [{
|
|
81
|
+
id: 'step-1',
|
|
82
|
+
description: taskPrompt,
|
|
83
|
+
status: 'pending',
|
|
84
|
+
}],
|
|
85
|
+
currentStepIndex: 0,
|
|
86
|
+
createdAt: Date.now(),
|
|
87
|
+
relevantExperiences,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async adjust(plan, failedStep, error) {
|
|
92
|
+
// Simple adjustment logic
|
|
93
|
+
const stepIndex = plan.steps.findIndex(s => s.id === failedStep.id);
|
|
94
|
+
if (stepIndex === -1) {
|
|
95
|
+
return { type: 'abort', reason: 'Step not found in plan' };
|
|
96
|
+
}
|
|
97
|
+
// Check if we should retry
|
|
98
|
+
const retryCount = failedStep.retryCount || 0;
|
|
99
|
+
if (retryCount < 2) {
|
|
100
|
+
return {
|
|
101
|
+
type: 'retry',
|
|
102
|
+
reason: 'Retrying failed step',
|
|
103
|
+
newSteps: plan.steps.map(s => s.id === failedStep.id
|
|
104
|
+
? { ...s, retryCount: retryCount + 1 }
|
|
105
|
+
: s),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Check if we can skip
|
|
109
|
+
if (plan.steps.length > stepIndex + 1) {
|
|
110
|
+
return { type: 'skip', reason: 'Skipping failed step, continuing with next' };
|
|
111
|
+
}
|
|
112
|
+
return { type: 'abort', reason: error };
|
|
113
|
+
}
|
|
114
|
+
getNextStep(plan) {
|
|
115
|
+
if (plan.currentStepIndex >= plan.steps.length) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return plan.steps[plan.currentStepIndex];
|
|
119
|
+
}
|
|
120
|
+
advanceStep(plan, output) {
|
|
121
|
+
const updatedSteps = [...plan.steps];
|
|
122
|
+
if (output !== undefined && plan.currentStepIndex < updatedSteps.length) {
|
|
123
|
+
updatedSteps[plan.currentStepIndex] = {
|
|
124
|
+
...updatedSteps[plan.currentStepIndex],
|
|
125
|
+
status: 'completed',
|
|
126
|
+
output,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
...plan,
|
|
131
|
+
steps: updatedSteps,
|
|
132
|
+
currentStepIndex: plan.currentStepIndex + 1,
|
|
133
|
+
completedAt: plan.currentStepIndex + 1 >= plan.steps.length ? Date.now() : undefined,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
markStepFailed(plan, error) {
|
|
137
|
+
const updatedSteps = [...plan.steps];
|
|
138
|
+
if (plan.currentStepIndex < updatedSteps.length) {
|
|
139
|
+
updatedSteps[plan.currentStepIndex] = {
|
|
140
|
+
...updatedSteps[plan.currentStepIndex],
|
|
141
|
+
status: 'failed',
|
|
142
|
+
error,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
...plan,
|
|
147
|
+
steps: updatedSteps,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
isComplete(plan) {
|
|
151
|
+
return plan.currentStepIndex >= plan.steps.length;
|
|
152
|
+
}
|
|
153
|
+
parseSteps(content) {
|
|
154
|
+
try {
|
|
155
|
+
// Try to extract JSON array from response
|
|
156
|
+
const jsonMatch = content.match(/\[[\s\S]*\]/);
|
|
157
|
+
if (!jsonMatch) {
|
|
158
|
+
throw new Error('No JSON array found');
|
|
159
|
+
}
|
|
160
|
+
const parsed = JSON.parse(jsonMatch[0]);
|
|
161
|
+
if (!Array.isArray(parsed)) {
|
|
162
|
+
throw new Error('Parsed content is not an array');
|
|
163
|
+
}
|
|
164
|
+
return parsed.slice(0, this.config.maxSteps).map((step, i) => ({
|
|
165
|
+
id: 'step-' + (i + 1),
|
|
166
|
+
description: step.description || step,
|
|
167
|
+
status: 'pending',
|
|
168
|
+
capability: step.capability,
|
|
169
|
+
input: step.input,
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// Fallback: treat entire response as single step
|
|
174
|
+
return [{
|
|
175
|
+
id: 'step-1',
|
|
176
|
+
description: content.slice(0, 200),
|
|
177
|
+
status: 'pending',
|
|
178
|
+
}];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
export function createPlanner(llmClient, config) {
|
|
183
|
+
return new Planner(llmClient, config);
|
|
184
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planning Module Types
|
|
3
|
+
*
|
|
4
|
+
* @module @jclaw/core/planning/types
|
|
5
|
+
*/
|
|
6
|
+
export type StepStatus = 'pending' | 'running' | 'completed' | 'failed';
|
|
7
|
+
export interface Step {
|
|
8
|
+
id: string;
|
|
9
|
+
description: string;
|
|
10
|
+
status: StepStatus;
|
|
11
|
+
capability?: string;
|
|
12
|
+
input?: unknown;
|
|
13
|
+
output?: unknown;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface Plan {
|
|
17
|
+
taskId: string;
|
|
18
|
+
taskPrompt: string;
|
|
19
|
+
steps: Step[];
|
|
20
|
+
currentStepIndex: number;
|
|
21
|
+
createdAt: number;
|
|
22
|
+
completedAt?: number;
|
|
23
|
+
relevantExperiences?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PlannerConfig {
|
|
26
|
+
maxSteps?: number;
|
|
27
|
+
verbose?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface PlanAdjustment {
|
|
30
|
+
type: 'retry' | 'skip' | 'abort' | 'alternative';
|
|
31
|
+
reason: string;
|
|
32
|
+
newSteps?: Step[];
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/planning/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAExE,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,IAAI;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;IACjD,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC;CACnB"}
|
package/dist/runtime/agent.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface AgentConfig {
|
|
|
11
11
|
systemPrompt?: string;
|
|
12
12
|
verbose?: boolean;
|
|
13
13
|
enableAutoSkill?: boolean;
|
|
14
|
+
enablePlanning?: boolean;
|
|
14
15
|
autoSkillConfig?: Partial<AutoSkillConfig>;
|
|
15
16
|
skillShConfig?: Partial<SkillShAdapterConfig>;
|
|
16
17
|
extensionRegistry?: ExtensionRegistry;
|
|
@@ -20,6 +21,7 @@ export declare class JClawAgent implements AgentRuntime {
|
|
|
20
21
|
private readonly config;
|
|
21
22
|
private llmClient?;
|
|
22
23
|
private taskExecutor?;
|
|
24
|
+
private planner?;
|
|
23
25
|
private running;
|
|
24
26
|
private autoSkillGenerator?;
|
|
25
27
|
private autoSkillInstaller?;
|
|
@@ -32,9 +34,7 @@ export declare class JClawAgent implements AgentRuntime {
|
|
|
32
34
|
stop(): Promise<void>;
|
|
33
35
|
execute(task: Task): Promise<TaskResult>;
|
|
34
36
|
private executeWithAutoSkill;
|
|
35
|
-
|
|
36
|
-
get name(): string;
|
|
37
|
-
get version(): string;
|
|
37
|
+
private storeExperience;
|
|
38
38
|
}
|
|
39
39
|
export declare function createAgent(config?: AgentConfig): JClawAgent;
|
|
40
40
|
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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,MA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M;IAC7B,OAAO,CAAC,SAAS,CAAC,CAAY;IAC9B,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,OAAO,CAAC,CAAU;IAC1B,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;IAcpC,IAAI,OAAO,IAAI,cAAc,CAG5B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA4CtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAOrB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC;YAkChC,oBAAoB;YA6CpB,eAAe;CAgB9B;AAED,wBAAgB,WAAW,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,UAAU,CAE5D"}
|
package/dist/runtime/agent.js
CHANGED
|
@@ -8,11 +8,13 @@ import { createSkillDiscoveryEngine } from '../skill-sh/discovery.js';
|
|
|
8
8
|
import { createSkillShAdapter } from '../skill-sh/adapter.js';
|
|
9
9
|
import { createSkillConverter } from '../skill-sh/converter.js';
|
|
10
10
|
import { fileOperationsExtension } from '../extensions/built-in/file-operations.js';
|
|
11
|
+
import { createPlanner } from '../planning/index.js';
|
|
11
12
|
export class JClawAgent {
|
|
12
13
|
executionMode;
|
|
13
14
|
config;
|
|
14
15
|
llmClient;
|
|
15
16
|
taskExecutor;
|
|
17
|
+
planner;
|
|
16
18
|
running = false;
|
|
17
19
|
autoSkillGenerator;
|
|
18
20
|
autoSkillInstaller;
|
|
@@ -27,6 +29,7 @@ export class JClawAgent {
|
|
|
27
29
|
systemPrompt: 'You are JClaw, a self-evolving AI agent.',
|
|
28
30
|
verbose: false,
|
|
29
31
|
enableAutoSkill: false,
|
|
32
|
+
enablePlanning: true,
|
|
30
33
|
...config,
|
|
31
34
|
};
|
|
32
35
|
this.executionMode = config.executionMode ?? 'local';
|
|
@@ -39,10 +42,22 @@ export class JClawAgent {
|
|
|
39
42
|
async start() {
|
|
40
43
|
if (this.running)
|
|
41
44
|
return;
|
|
42
|
-
console.log(
|
|
45
|
+
console.log("Starting " + this.config.name + " v" + this.config.version + "...");
|
|
43
46
|
if (this.config.llm) {
|
|
44
47
|
this.llmClient = new LLMClient(this.config.llm);
|
|
45
|
-
console.log(
|
|
48
|
+
console.log("LLM client initialized");
|
|
49
|
+
}
|
|
50
|
+
this.extensionRegistry = this.config.extensionRegistry ?? new ExtensionRegistry();
|
|
51
|
+
try {
|
|
52
|
+
this.extensionRegistry.register(fileOperationsExtension);
|
|
53
|
+
console.log("Built-in file operations registered");
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.warn("Failed to register file operations:", error);
|
|
57
|
+
}
|
|
58
|
+
if (this.llmClient) {
|
|
59
|
+
this.planner = createPlanner(this.llmClient, { verbose: this.config.verbose });
|
|
60
|
+
console.log("Planner initialized");
|
|
46
61
|
}
|
|
47
62
|
this.taskExecutor = new TaskExecutor({
|
|
48
63
|
llmClient: this.llmClient,
|
|
@@ -51,36 +66,24 @@ export class JClawAgent {
|
|
|
51
66
|
verbose: this.config.verbose,
|
|
52
67
|
});
|
|
53
68
|
if (this.config.enableAutoSkill) {
|
|
54
|
-
console.log(
|
|
55
|
-
this.evolutionEngine = new EvolutionEngine({
|
|
56
|
-
this.extensionRegistry = this.config.extensionRegistry ?? new ExtensionRegistry();
|
|
69
|
+
console.log("AutoSkill enabled - initializing...");
|
|
70
|
+
this.evolutionEngine = new EvolutionEngine({ llmClient: this.llmClient, executor: { mode: 'local', execute: async () => ({ stdout: '', stderr: '', exitCode: 0, duration: 0 }) }, config: { maxMutations: 10, minFitness: 0.5 } });
|
|
57
71
|
const skillShAdapter = createSkillShAdapter(this.llmClient, this.config.skillShConfig);
|
|
58
72
|
const skillConverter = createSkillConverter(this.llmClient);
|
|
59
73
|
this.autoSkillGenerator = createAutoSkillGenerator(this.llmClient, this.extensionRegistry, this.evolutionEngine, this.config.autoSkillConfig);
|
|
60
74
|
this.autoSkillInstaller = createAutoSkillInstaller(this.extensionRegistry, this.config.autoSkillConfig?.storageDir);
|
|
61
75
|
this.skillDiscovery = createSkillDiscoveryEngine(this.llmClient, this.extensionRegistry, skillShAdapter, skillConverter, this.autoSkillGenerator);
|
|
62
|
-
console.log(
|
|
63
|
-
}
|
|
64
|
-
// Register built-in file operations extension
|
|
65
|
-
if (!this.extensionRegistry) {
|
|
66
|
-
this.extensionRegistry = new ExtensionRegistry();
|
|
67
|
-
}
|
|
68
|
-
try {
|
|
69
|
-
this.extensionRegistry.register(fileOperationsExtension);
|
|
70
|
-
console.log("📁 Built-in file operations registered\n");
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
console.warn("⚠️ Failed to register file operations:", error);
|
|
76
|
+
console.log("AutoSkill components initialized");
|
|
74
77
|
}
|
|
75
78
|
this.running = true;
|
|
76
|
-
console.log(
|
|
79
|
+
console.log("Agent started");
|
|
77
80
|
}
|
|
78
81
|
async stop() {
|
|
79
82
|
if (!this.running)
|
|
80
83
|
return;
|
|
81
|
-
console.log(
|
|
84
|
+
console.log("Stopping agent...");
|
|
82
85
|
this.running = false;
|
|
83
|
-
console.log(
|
|
86
|
+
console.log("Agent stopped");
|
|
84
87
|
}
|
|
85
88
|
async execute(task) {
|
|
86
89
|
if (!this.running)
|
|
@@ -88,10 +91,34 @@ export class JClawAgent {
|
|
|
88
91
|
if (!this.taskExecutor)
|
|
89
92
|
throw new Error('Task executor not initialized');
|
|
90
93
|
if (this.config.verbose)
|
|
91
|
-
console.log(
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
console.log("Executing task: " + task.prompt);
|
|
95
|
+
// Step 2: Retrieve relevant experiences
|
|
96
|
+
let relevantExperiences = '';
|
|
97
|
+
if (this.config.contextManager) {
|
|
98
|
+
try {
|
|
99
|
+
relevantExperiences = await this.config.contextManager.query(task.prompt, { topK: 3 });
|
|
100
|
+
if (relevantExperiences && this.config.verbose) {
|
|
101
|
+
console.log("Retrieved relevant experiences");
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (this.config.verbose)
|
|
106
|
+
console.log("Failed to retrieve experiences");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Execute task
|
|
110
|
+
let result;
|
|
111
|
+
if (this.config.enableAutoSkill) {
|
|
112
|
+
result = await this.executeWithAutoSkill(task);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
result = await this.taskExecutor.execute(task);
|
|
116
|
+
}
|
|
117
|
+
// Step 8: Store experience (only if successful)
|
|
118
|
+
if (result.success && this.config.contextManager) {
|
|
119
|
+
await this.storeExperience(task, result);
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
95
122
|
}
|
|
96
123
|
async executeWithAutoSkill(task) {
|
|
97
124
|
if (!this.taskExecutor)
|
|
@@ -99,48 +126,62 @@ export class JClawAgent {
|
|
|
99
126
|
const maxAttempts = this.config.autoSkillConfig?.maxGenerationAttempts || 3;
|
|
100
127
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
101
128
|
try {
|
|
102
|
-
console.log(
|
|
129
|
+
console.log("Attempt " + attempt + "/" + maxAttempts);
|
|
103
130
|
const result = await this.taskExecutor.execute(task);
|
|
104
131
|
if (result.success) {
|
|
105
|
-
console.log(
|
|
132
|
+
console.log("Task completed successfully");
|
|
106
133
|
return result;
|
|
107
134
|
}
|
|
108
|
-
console.log(
|
|
135
|
+
console.log("Task failed: " + result.error);
|
|
109
136
|
if (!this.skillDiscovery || !this.autoSkillInstaller) {
|
|
110
|
-
console.log(
|
|
137
|
+
console.log("AutoSkill components not available");
|
|
111
138
|
return result;
|
|
112
139
|
}
|
|
113
|
-
console.log(
|
|
140
|
+
console.log("Analyzing missing capabilities...");
|
|
114
141
|
const discovery = await this.skillDiscovery.discover(task.prompt);
|
|
115
142
|
if (discovery.recommended && discovery.confidence > 0.5) {
|
|
116
|
-
console.log(
|
|
117
|
-
console.log(
|
|
118
|
-
console.log(
|
|
119
|
-
console.log(
|
|
143
|
+
console.log("Found skill: " + discovery.recommended.name);
|
|
144
|
+
console.log("Source: " + discovery.source);
|
|
145
|
+
console.log("Confidence: " + (discovery.confidence * 100).toFixed(0) + "%");
|
|
146
|
+
console.log("Installing skill...");
|
|
120
147
|
const installed = await this.skillDiscovery.installSkill(discovery.recommended);
|
|
121
148
|
if (installed) {
|
|
122
|
-
console.log(
|
|
123
|
-
console.log(
|
|
149
|
+
console.log("Skill installed successfully");
|
|
150
|
+
console.log("Retrying task with new capability...");
|
|
124
151
|
continue;
|
|
125
152
|
}
|
|
126
153
|
}
|
|
127
154
|
if (attempt >= maxAttempts) {
|
|
128
|
-
return { taskId: task.id, success: false, output: '', error:
|
|
155
|
+
return { taskId: task.id, success: false, output: '', error: "Task failed after " + maxAttempts + " attempts. Last error: " + result.error, duration: 0 };
|
|
129
156
|
}
|
|
130
157
|
}
|
|
131
158
|
catch (error) {
|
|
132
159
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
133
|
-
console.log(
|
|
160
|
+
console.log("Attempt " + attempt + " failed: " + errorMessage);
|
|
134
161
|
if (attempt >= maxAttempts) {
|
|
135
|
-
return { taskId: task.id, success: false, output: '', error:
|
|
162
|
+
return { taskId: task.id, success: false, output: '', error: "Task failed after " + maxAttempts + " attempts. Last error: " + errorMessage, duration: 0 };
|
|
136
163
|
}
|
|
137
164
|
}
|
|
138
165
|
}
|
|
139
|
-
return { taskId: task.id, success: false, output: '', error:
|
|
166
|
+
return { taskId: task.id, success: false, output: '', error: "Task failed after " + maxAttempts + " attempts", duration: 0 };
|
|
167
|
+
}
|
|
168
|
+
async storeExperience(task, result) {
|
|
169
|
+
if (!this.config.contextManager)
|
|
170
|
+
return;
|
|
171
|
+
try {
|
|
172
|
+
const title = "Experience: " + task.prompt.slice(0, 50);
|
|
173
|
+
const content = "## Task\n" + task.prompt + "\n\n## Result\n" + (result.output || "") + "\n\n## Tags\n#experience";
|
|
174
|
+
await this.config.contextManager.saveMemory(content, title);
|
|
175
|
+
if (this.config.verbose) {
|
|
176
|
+
console.log("Experience stored successfully");
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (this.config.verbose) {
|
|
181
|
+
console.log("Failed to store experience");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
140
184
|
}
|
|
141
|
-
isRunning() { return this.running; }
|
|
142
|
-
get name() { return this.config.name; }
|
|
143
|
-
get version() { return this.config.version; }
|
|
144
185
|
}
|
|
145
186
|
export function createAgent(config) {
|
|
146
187
|
return new JClawAgent(config);
|
|
@@ -18,5 +18,12 @@ export declare class LLMClient {
|
|
|
18
18
|
content: string;
|
|
19
19
|
}>;
|
|
20
20
|
}
|
|
21
|
+
export interface ChatMessage {
|
|
22
|
+
role: string;
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
export interface LLMResponse {
|
|
26
|
+
content: string;
|
|
27
|
+
}
|
|
21
28
|
export declare function createLLMClient(config: LLMClientConfig): LLMClient;
|
|
22
29
|
//# sourceMappingURL=llm-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"llm-client.d.ts","sourceRoot":"","sources":["../../src/runtime/llm-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;gBAEU,MAAM,EAAE,eAAe;IAU7B,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CA2B7F;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAElE"}
|
|
1
|
+
{"version":3,"file":"llm-client.d.ts","sourceRoot":"","sources":["../../src/runtime/llm-client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;gBAEU,MAAM,EAAE,eAAe;IAU7B,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CA2B7F;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAElE"}
|
|
@@ -20,5 +20,9 @@ export declare class TaskExecutor {
|
|
|
20
20
|
private executeTask;
|
|
21
21
|
private buildSystemPrompt;
|
|
22
22
|
private extractCapabilityCall;
|
|
23
|
+
private extractCommands;
|
|
24
|
+
private log;
|
|
25
|
+
private sleep;
|
|
23
26
|
}
|
|
27
|
+
export declare function createTaskExecutor(config: TaskExecutorConfig): TaskExecutor;
|
|
24
28
|
//# sourceMappingURL=task-executor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"task-executor.d.ts","sourceRoot":"","sources":["../../src/runtime/task-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"task-executor.d.ts","sourceRoot":"","sources":["../../src/runtime/task-executor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIpE,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAIrB;gBAEU,MAAM,EAAE,kBAAkB;IAIhC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC;YAqBhC,WAAW;IAiDzB,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,KAAK;CAGd;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAE3E"}
|
|
@@ -1,141 +1,118 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Task Executor
|
|
2
|
+
* Task Executor - Enhanced with Capability Support
|
|
3
3
|
*/
|
|
4
|
+
const DEFAULT_SYSTEM_PROMPT = "You are JClaw, a self-evolving AI agent. You help users complete tasks.";
|
|
4
5
|
export class TaskExecutor {
|
|
6
|
+
config;
|
|
5
7
|
constructor(config) {
|
|
6
|
-
this.config = {
|
|
7
|
-
systemPrompt: `You are JClaw, a self-evolving AI agent.`,
|
|
8
|
-
maxRetries: 3,
|
|
9
|
-
verbose: false,
|
|
10
|
-
...config,
|
|
11
|
-
};
|
|
8
|
+
this.config = { systemPrompt: DEFAULT_SYSTEM_PROMPT, maxRetries: 3, verbose: false, ...config };
|
|
12
9
|
}
|
|
13
|
-
|
|
14
10
|
async execute(task) {
|
|
15
11
|
const startTime = Date.now();
|
|
16
12
|
let attempts = 0;
|
|
17
13
|
let lastError;
|
|
18
|
-
|
|
19
14
|
while (attempts < this.config.maxRetries) {
|
|
20
15
|
attempts++;
|
|
21
16
|
try {
|
|
22
17
|
const output = await this.executeTask(task);
|
|
23
|
-
return {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
output,
|
|
27
|
-
duration: Date.now() - startTime,
|
|
28
|
-
};
|
|
29
|
-
} catch (error) {
|
|
18
|
+
return { taskId: task.id, success: true, output, duration: Date.now() - startTime };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
30
21
|
lastError = error instanceof Error ? error.message : 'Unknown error';
|
|
31
22
|
if (attempts < this.config.maxRetries) {
|
|
32
23
|
await this.sleep(1000 * Math.pow(2, attempts - 1));
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
taskId: task.id,
|
|
39
|
-
success: false,
|
|
40
|
-
error: lastError,
|
|
41
|
-
duration: Date.now() - startTime,
|
|
42
|
-
};
|
|
27
|
+
return { taskId: task.id, success: false, error: lastError, duration: Date.now() - startTime };
|
|
43
28
|
}
|
|
44
|
-
|
|
45
29
|
async executeTask(task) {
|
|
46
|
-
const messages = [
|
|
47
|
-
{ role: 'system', content: this.buildSystemPrompt() },
|
|
48
|
-
];
|
|
49
|
-
|
|
30
|
+
const messages = [{ role: 'system', content: this.buildSystemPrompt() }];
|
|
50
31
|
if (this.config.contextManager) {
|
|
51
32
|
try {
|
|
52
33
|
const context = await this.config.contextManager.query(task.prompt, { topK: 5 });
|
|
53
|
-
if (context)
|
|
54
|
-
|
|
34
|
+
if (context)
|
|
35
|
+
messages.push({ role: 'system', content: 'Relevant context: ' + context });
|
|
36
|
+
}
|
|
37
|
+
catch { }
|
|
55
38
|
}
|
|
56
|
-
|
|
57
39
|
messages.push({ role: 'user', content: task.prompt });
|
|
58
|
-
|
|
40
|
+
if (task.context)
|
|
41
|
+
messages.push({ role: 'user', content: 'Additional context: ' + JSON.stringify(task.context) });
|
|
59
42
|
let iterationCount = 0;
|
|
60
43
|
const maxIterations = 5;
|
|
61
|
-
|
|
62
44
|
while (iterationCount < maxIterations) {
|
|
63
45
|
iterationCount++;
|
|
64
46
|
const response = await this.config.llmClient.chat(messages);
|
|
65
|
-
|
|
66
|
-
// Check for capability calls
|
|
67
47
|
const capabilityCall = this.extractCapabilityCall(response.content);
|
|
68
48
|
if (capabilityCall && this.config.extensionRegistry) {
|
|
69
49
|
const registeredCap = this.config.extensionRegistry.getCapability(capabilityCall.name);
|
|
70
|
-
if (registeredCap
|
|
50
|
+
if (registeredCap && registeredCap.capability && registeredCap.capability.handler) {
|
|
71
51
|
try {
|
|
72
52
|
const result = await registeredCap.capability.handler(capabilityCall.input);
|
|
73
53
|
messages.push({ role: 'assistant', content: response.content });
|
|
74
|
-
messages.push({ role: 'system', content: '
|
|
54
|
+
messages.push({ role: 'system', content: 'Capability result: ' + JSON.stringify(result) });
|
|
75
55
|
continue;
|
|
76
|
-
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
77
58
|
messages.push({ role: 'assistant', content: response.content });
|
|
78
|
-
messages.push({ role: 'system', content: '
|
|
59
|
+
messages.push({ role: 'system', content: 'Capability failed: ' + error.message });
|
|
79
60
|
continue;
|
|
80
61
|
}
|
|
81
62
|
}
|
|
82
63
|
}
|
|
83
|
-
|
|
84
|
-
// Check for commands
|
|
85
64
|
const commands = this.extractCommands(response.content);
|
|
86
65
|
if (commands.length > 0 && this.config.executor) {
|
|
87
66
|
return response.content;
|
|
88
67
|
}
|
|
89
|
-
|
|
90
68
|
return response.content;
|
|
91
69
|
}
|
|
92
|
-
|
|
93
|
-
return
|
|
70
|
+
const lastResponse = await this.config.llmClient.chat(messages);
|
|
71
|
+
return lastResponse.content;
|
|
94
72
|
}
|
|
95
|
-
|
|
96
73
|
buildSystemPrompt() {
|
|
97
74
|
let prompt = this.config.systemPrompt;
|
|
98
75
|
if (this.config.extensionRegistry) {
|
|
99
76
|
const capabilities = this.config.extensionRegistry.getCapabilityNames();
|
|
100
77
|
if (capabilities.length > 0) {
|
|
101
|
-
prompt
|
|
102
|
-
prompt
|
|
78
|
+
prompt = prompt + '\n\nAvailable Capabilities:\n' + capabilities.map(function (c) { return '- ' + c; }).join('\n');
|
|
79
|
+
prompt = prompt + '\n\nTo use a capability, respond with:\n```capability\n{\n "name": "capability_name",\n "input": {...}\n}\n```';
|
|
103
80
|
}
|
|
104
81
|
}
|
|
105
82
|
return prompt;
|
|
106
83
|
}
|
|
107
|
-
|
|
108
84
|
extractCapabilityCall(content) {
|
|
109
85
|
const match = /```capability\s*\n([\s\S]*?)\n\s*```/.exec(content);
|
|
110
86
|
if (match && match[1]) {
|
|
111
87
|
try {
|
|
112
88
|
const parsed = JSON.parse(match[1].trim());
|
|
113
|
-
if (parsed.name
|
|
114
|
-
|
|
89
|
+
if (parsed.name && typeof parsed.name === 'string') {
|
|
90
|
+
return { name: parsed.name, input: parsed.input || {} };
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (e) { }
|
|
115
94
|
}
|
|
116
95
|
return null;
|
|
117
96
|
}
|
|
118
|
-
|
|
119
97
|
extractCommands(content) {
|
|
120
98
|
const commands = [];
|
|
121
99
|
const regex = /```(?:shell|bash|sh)\n([\s\S]*?)```/g;
|
|
122
100
|
let match;
|
|
123
101
|
while ((match = regex.exec(content)) !== null) {
|
|
124
|
-
const cmd = match[1]
|
|
125
|
-
if (cmd && !cmd.startsWith('#'))
|
|
102
|
+
const cmd = match[1] && match[1].trim();
|
|
103
|
+
if (cmd && !cmd.startsWith('#'))
|
|
104
|
+
commands.push(cmd);
|
|
126
105
|
}
|
|
127
106
|
return commands;
|
|
128
107
|
}
|
|
129
|
-
|
|
130
108
|
log(message) {
|
|
131
|
-
if (this.config.verbose)
|
|
109
|
+
if (this.config.verbose)
|
|
110
|
+
console.log('[TaskExecutor] ' + message);
|
|
132
111
|
}
|
|
133
|
-
|
|
134
112
|
sleep(ms) {
|
|
135
|
-
return new Promise((resolve)
|
|
113
|
+
return new Promise(function (resolve) { setTimeout(resolve, ms); });
|
|
136
114
|
}
|
|
137
115
|
}
|
|
138
|
-
|
|
139
116
|
export function createTaskExecutor(config) {
|
|
140
117
|
return new TaskExecutor(config);
|
|
141
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jclaw/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Universal self-evolving Agent with improved AutoSkill retry logic",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"author": "JClaw Team",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"glob": "^10.3.10"
|
|
33
|
+
"glob": "^10.3.10",
|
|
34
|
+
"memsearch-core": "^1.0.5"
|
|
34
35
|
}
|
|
35
36
|
}
|