skyloom 1.11.0 → 1.13.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/.github/workflows/ci.yml +36 -36
- package/README.md +142 -46
- package/config/default.yaml +43 -47
- package/config/models.yaml +155 -0
- package/config/providers.yaml +39 -39
- package/config/skills/api_integrator/SKILL.md +15 -15
- package/config/skills/arch_designer/SKILL.md +13 -13
- package/config/skills/ci_cd_manager/SKILL.md +14 -14
- package/config/skills/code_analysis/SKILL.md +13 -13
- package/config/skills/code_generator/SKILL.md +12 -12
- package/config/skills/code_reviewer/SKILL.md +13 -13
- package/config/skills/content_writer/SKILL.md +14 -14
- package/config/skills/data_transformer/SKILL.md +15 -15
- package/config/skills/document_analysis/SKILL.md +13 -13
- package/config/skills/emotional_companion/SKILL.md +15 -15
- package/config/skills/performance_checker/SKILL.md +14 -14
- package/config/skills/security_auditor/SKILL.md +14 -14
- package/config/skills/self_evolve/SKILL.md +13 -13
- package/config/skills/sys_operator/SKILL.md +15 -15
- package/config/skills/task_planner/SKILL.md +14 -14
- package/config/skills/web_research/SKILL.md +14 -14
- package/config/skills/workflow_designer/SKILL.md +13 -13
- package/dist/agents/dew.js +52 -52
- package/dist/agents/fair.js +84 -84
- package/dist/agents/fog.js +30 -30
- package/dist/agents/frost.js +32 -32
- package/dist/agents/rain.js +32 -32
- package/dist/agents/snow.js +68 -68
- package/dist/cli/main.js +172 -47
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/tui.d.ts.map +1 -1
- package/dist/cli/tui.js +9 -1
- package/dist/cli/tui.js.map +1 -1
- package/dist/core/agent/task.d.ts +58 -0
- package/dist/core/agent/task.d.ts.map +1 -0
- package/dist/core/agent/task.js +83 -0
- package/dist/core/agent/task.js.map +1 -0
- package/dist/core/agent.d.ts +2 -45
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +61 -145
- package/dist/core/agent.js.map +1 -1
- package/dist/core/agent_helpers.d.ts +10 -0
- package/dist/core/agent_helpers.d.ts.map +1 -1
- package/dist/core/agent_helpers.js +39 -0
- package/dist/core/agent_helpers.js.map +1 -1
- package/dist/core/catalog.d.ts +71 -0
- package/dist/core/catalog.d.ts.map +1 -0
- package/dist/core/catalog.js +176 -0
- package/dist/core/catalog.js.map +1 -0
- package/dist/core/config.d.ts +8 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +12 -4
- package/dist/core/config.js.map +1 -1
- package/dist/core/factory.js +16 -16
- package/dist/core/llm.d.ts +7 -0
- package/dist/core/llm.d.ts.map +1 -1
- package/dist/core/llm.js +139 -7
- package/dist/core/llm.js.map +1 -1
- package/dist/core/longdoc.js +5 -5
- package/dist/core/memory.d.ts.map +1 -1
- package/dist/core/memory.js +69 -62
- package/dist/core/memory.js.map +1 -1
- package/dist/core/theme.d.ts +46 -0
- package/dist/core/theme.d.ts.map +1 -0
- package/dist/core/theme.js +42 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/web/server.js +542 -519
- package/dist/web/server.js.map +1 -1
- package/docs/AESTHETIC_DESIGN.md +144 -0
- package/docs/OPTIMIZATION_PLAN.md +178 -0
- package/package.json +60 -60
- package/scripts/install.js +48 -48
- package/scripts/link.js +10 -10
- package/setup.bat +79 -79
- package/skill-test-ty2fOA/test.md +10 -10
- package/src/agents/dew.ts +70 -70
- package/src/agents/fair.ts +102 -102
- package/src/agents/fog.ts +48 -48
- package/src/agents/frost.ts +50 -50
- package/src/agents/rain.ts +50 -50
- package/src/agents/snow.ts +239 -239
- package/src/cli/main.ts +425 -316
- package/src/cli/mode.ts +58 -58
- package/src/cli/tui.ts +272 -268
- package/src/core/agent/task.ts +100 -0
- package/src/core/agent.ts +1446 -1549
- package/src/core/agent_helpers.ts +496 -461
- package/src/core/arbitrate.ts +162 -162
- package/src/core/catalog.ts +178 -0
- package/src/core/checkpoint.ts +94 -94
- package/src/core/config.ts +20 -4
- package/src/core/estimate.ts +104 -104
- package/src/core/evolve.ts +191 -191
- package/src/core/factory.ts +627 -627
- package/src/core/filter.ts +103 -103
- package/src/core/graph.ts +156 -156
- package/src/core/icons.ts +53 -53
- package/src/core/index.ts +37 -37
- package/src/core/learn.ts +146 -146
- package/src/core/llm.ts +108 -5
- package/src/core/longdoc.ts +155 -155
- package/src/core/mcp_server.ts +176 -176
- package/src/core/memory.ts +1178 -1171
- package/src/core/profile.ts +255 -255
- package/src/core/router.ts +124 -124
- package/src/core/sandbox.ts +142 -142
- package/src/core/security.ts +243 -243
- package/src/core/skill.ts +342 -342
- package/src/core/theme.ts +65 -0
- package/src/core/tool_router.ts +193 -193
- package/src/core/vector.ts +152 -152
- package/src/core/workspace.ts +150 -150
- package/src/plugins/loader.ts +66 -66
- package/src/skills/loader.ts +46 -46
- package/src/sql.js.d.ts +29 -29
- package/src/tools/builtin.ts +380 -380
- package/src/tools/computer.ts +269 -269
- package/src/tools/delegate.ts +49 -49
- package/src/web/server.ts +660 -634
- package/src/web/tts.ts +93 -93
- package/tests/agent_helpers.test.ts +48 -0
- package/tests/bus.test.ts +121 -121
- package/tests/catalog.test.ts +86 -0
- package/tests/config.test.ts +41 -0
- package/tests/icons.test.ts +45 -45
- package/tests/memory.test.ts +147 -0
- package/tests/router.test.ts +86 -86
- package/tests/schemas.test.ts +51 -51
- package/tests/semantic.test.ts +83 -83
- package/tests/setup.ts +10 -10
- package/tests/skill.test.ts +172 -172
- package/tests/task.test.ts +60 -0
- package/tests/tool.test.ts +108 -108
- package/tests/tool_router.test.ts +71 -71
- package/vitest.config.ts +17 -17
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agent domain model — states and the Task DAG node.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from the monolithic agent.ts (Phase 3). Pure, dependency-free,
|
|
6
|
+
* and unit-testable in isolation. `agent.ts` re-exports these so external
|
|
7
|
+
* importers of `../core/agent` are unaffected.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TaskResult = exports.Task = exports.VALID_TRANSITIONS = exports.TaskState = exports.AgentState = void 0;
|
|
11
|
+
/** Lifecycle state of a running agent. */
|
|
12
|
+
var AgentState;
|
|
13
|
+
(function (AgentState) {
|
|
14
|
+
AgentState["IDLE"] = "idle";
|
|
15
|
+
AgentState["THINKING"] = "thinking";
|
|
16
|
+
AgentState["ACTING"] = "acting";
|
|
17
|
+
AgentState["WAITING"] = "waiting";
|
|
18
|
+
AgentState["ERROR"] = "error";
|
|
19
|
+
})(AgentState || (exports.AgentState = AgentState = {}));
|
|
20
|
+
/** Lifecycle state of an orchestrated task. */
|
|
21
|
+
var TaskState;
|
|
22
|
+
(function (TaskState) {
|
|
23
|
+
TaskState["PENDING"] = "pending";
|
|
24
|
+
TaskState["RUNNING"] = "running";
|
|
25
|
+
TaskState["COMPLETED"] = "completed";
|
|
26
|
+
TaskState["FAILED"] = "failed";
|
|
27
|
+
TaskState["SKIPPED"] = "skipped";
|
|
28
|
+
})(TaskState || (exports.TaskState = TaskState = {}));
|
|
29
|
+
/** Allowed task state transitions. A terminal state has no outgoing edges. */
|
|
30
|
+
exports.VALID_TRANSITIONS = {
|
|
31
|
+
[TaskState.PENDING]: new Set([TaskState.RUNNING, TaskState.SKIPPED, TaskState.FAILED]),
|
|
32
|
+
[TaskState.RUNNING]: new Set([TaskState.RUNNING, TaskState.COMPLETED, TaskState.FAILED]),
|
|
33
|
+
[TaskState.FAILED]: new Set([TaskState.RUNNING, TaskState.SKIPPED]),
|
|
34
|
+
[TaskState.COMPLETED]: new Set(),
|
|
35
|
+
[TaskState.SKIPPED]: new Set(),
|
|
36
|
+
};
|
|
37
|
+
/** A node in the orchestration DAG. */
|
|
38
|
+
class Task {
|
|
39
|
+
constructor(config) {
|
|
40
|
+
this.assignedTo = null;
|
|
41
|
+
this.parentId = null;
|
|
42
|
+
this.dependsOn = [];
|
|
43
|
+
this.status = TaskState.PENDING;
|
|
44
|
+
this.priority = 0;
|
|
45
|
+
this.result = null;
|
|
46
|
+
this.metadata = {};
|
|
47
|
+
this.id = config.id;
|
|
48
|
+
this.description = config.description;
|
|
49
|
+
this.assignedTo = config.assignedTo ?? null;
|
|
50
|
+
this.parentId = config.parentId ?? null;
|
|
51
|
+
this.dependsOn = config.dependsOn || [];
|
|
52
|
+
this.status = config.status ?? TaskState.PENDING;
|
|
53
|
+
this.priority = config.priority ?? 0;
|
|
54
|
+
this.result = config.result ?? null;
|
|
55
|
+
this.metadata = config.metadata || {};
|
|
56
|
+
}
|
|
57
|
+
transitionTo(newState) {
|
|
58
|
+
const allowed = exports.VALID_TRANSITIONS[this.status] || new Set();
|
|
59
|
+
if (!allowed.has(newState)) {
|
|
60
|
+
throw new Error(`Invalid task state transition: ${this.status} -> ${newState}`);
|
|
61
|
+
}
|
|
62
|
+
this.status = newState;
|
|
63
|
+
}
|
|
64
|
+
get allDeps() {
|
|
65
|
+
const deps = [...this.dependsOn];
|
|
66
|
+
if (this.parentId && !deps.includes(this.parentId)) {
|
|
67
|
+
deps.push(this.parentId);
|
|
68
|
+
}
|
|
69
|
+
return deps;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.Task = Task;
|
|
73
|
+
/** Result of executing a single task. */
|
|
74
|
+
class TaskResult {
|
|
75
|
+
constructor(success, content, data) {
|
|
76
|
+
this.data = {};
|
|
77
|
+
this.success = success;
|
|
78
|
+
this.content = content;
|
|
79
|
+
this.data = data || {};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.TaskResult = TaskResult;
|
|
83
|
+
//# sourceMappingURL=task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.js","sourceRoot":"","sources":["../../../src/core/agent/task.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,0CAA0C;AAC1C,IAAY,UAMX;AAND,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,mCAAqB,CAAA;IACrB,+BAAiB,CAAA;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E,OAAe,EAAE,IAA0B;QAFzE,SAAI,GAAwB,EAAE,CAAC;QAG7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IACzB,CAAC;CACF;AAVD,gCAUC"}
|
package/dist/core/agent.d.ts
CHANGED
|
@@ -9,50 +9,8 @@ import { LLMClient, type LLMResponse, type ToolCall } from './llm';
|
|
|
9
9
|
import { Memory, Message } from './memory';
|
|
10
10
|
import { Skill, SkillRegistry } from './skill';
|
|
11
11
|
import { type ToolDefinition, ToolRegistry } from './tool';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
THINKING = "thinking",
|
|
15
|
-
ACTING = "acting",
|
|
16
|
-
WAITING = "waiting",
|
|
17
|
-
ERROR = "error"
|
|
18
|
-
}
|
|
19
|
-
export declare enum TaskState {
|
|
20
|
-
PENDING = "pending",
|
|
21
|
-
RUNNING = "running",
|
|
22
|
-
COMPLETED = "completed",
|
|
23
|
-
FAILED = "failed",
|
|
24
|
-
SKIPPED = "skipped"
|
|
25
|
-
}
|
|
26
|
-
export declare class Task {
|
|
27
|
-
id: string;
|
|
28
|
-
description: string;
|
|
29
|
-
assignedTo: string | null;
|
|
30
|
-
parentId: string | null;
|
|
31
|
-
dependsOn: string[];
|
|
32
|
-
status: TaskState;
|
|
33
|
-
priority: number;
|
|
34
|
-
result: string | null;
|
|
35
|
-
metadata: Record<string, any>;
|
|
36
|
-
constructor(config: {
|
|
37
|
-
id: string;
|
|
38
|
-
description: string;
|
|
39
|
-
assignedTo?: string | null;
|
|
40
|
-
parentId?: string | null;
|
|
41
|
-
dependsOn?: string[];
|
|
42
|
-
status?: TaskState;
|
|
43
|
-
priority?: number;
|
|
44
|
-
result?: string | null;
|
|
45
|
-
metadata?: Record<string, any>;
|
|
46
|
-
});
|
|
47
|
-
transitionTo(newState: TaskState): void;
|
|
48
|
-
get allDeps(): string[];
|
|
49
|
-
}
|
|
50
|
-
export declare class TaskResult {
|
|
51
|
-
success: boolean;
|
|
52
|
-
content: string;
|
|
53
|
-
data: Record<string, any>;
|
|
54
|
-
constructor(success: boolean, content: string, data?: Record<string, any>);
|
|
55
|
-
}
|
|
12
|
+
import { AgentState, TaskState, Task, TaskResult } from './agent/task';
|
|
13
|
+
export { AgentState, TaskState, Task, TaskResult };
|
|
56
14
|
export type { Message };
|
|
57
15
|
export declare class BaseAgent {
|
|
58
16
|
name: string;
|
|
@@ -155,7 +113,6 @@ export declare class BaseAgent {
|
|
|
155
113
|
private readonly EXTRACT_PROMPT;
|
|
156
114
|
protected maybeExtractFacts(): void;
|
|
157
115
|
private extractFactsAsync;
|
|
158
|
-
private parseExtractedFacts;
|
|
159
116
|
protected messagesWithRecall(): Promise<Record<string, any>[]>;
|
|
160
117
|
protected llmLoop(options?: {
|
|
161
118
|
maxIterations?: number;
|
package/dist/core/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEnE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAa,UAAU,EAAE,MAAM,OAAO,CAAC;AAErD,OAAO,EAAE,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ool_router");
|
|
17
17
|
const log = (0, logger_1.getLogger)('agent');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})(AgentState || (exports.AgentState = AgentState = {}));
|
|
26
|
-
var TaskState;
|
|
27
|
-
(function (TaskState) {
|
|
28
|
-
TaskState["PENDING"] = "pending";
|
|
29
|
-
TaskState["RUNNING"] = "running";
|
|
30
|
-
TaskState["COMPLETED"] = "completed";
|
|
31
|
-
TaskState["FAILED"] = "failed";
|
|
32
|
-
TaskState["SKIPPED"] = "skipped";
|
|
33
|
-
})(TaskState || (exports.TaskState = TaskState = {}));
|
|
34
|
-
const VALID_TRANSITIONS = {
|
|
35
|
-
[TaskState.PENDING]: new Set([TaskState.RUNNING, TaskState.SKIPPED, TaskState.FAILED]),
|
|
36
|
-
[TaskState.RUNNING]: new Set([TaskState.RUNNING, TaskState.COMPLETED, TaskState.FAILED]),
|
|
37
|
-
[TaskState.FAILED]: new Set([TaskState.RUNNING, TaskState.SKIPPED]),
|
|
38
|
-
[TaskState.COMPLETED]: new Set(),
|
|
39
|
-
[TaskState.SKIPPED]: new Set(),
|
|
40
|
-
};
|
|
41
|
-
class Task {
|
|
42
|
-
constructor(config) {
|
|
43
|
-
this.assignedTo = null;
|
|
44
|
-
this.parentId = null;
|
|
45
|
-
this.dependsOn = [];
|
|
46
|
-
this.status = TaskState.PENDING;
|
|
47
|
-
this.priority = 0;
|
|
48
|
-
this.result = null;
|
|
49
|
-
this.metadata = {};
|
|
50
|
-
this.id = config.id;
|
|
51
|
-
this.description = config.description;
|
|
52
|
-
this.assignedTo = config.assignedTo ?? null;
|
|
53
|
-
this.parentId = config.parentId ?? null;
|
|
54
|
-
this.dependsOn = config.dependsOn || [];
|
|
55
|
-
this.status = config.status ?? TaskState.PENDING;
|
|
56
|
-
this.priority = config.priority ?? 0;
|
|
57
|
-
this.result = config.result ?? null;
|
|
58
|
-
this.metadata = config.metadata || {};
|
|
59
|
-
}
|
|
60
|
-
transitionTo(newState) {
|
|
61
|
-
const allowed = VALID_TRANSITIONS[this.status] || new Set();
|
|
62
|
-
if (!allowed.has(newState)) {
|
|
63
|
-
throw new Error(`Invalid task state transition: ${this.status} -> ${newState}`);
|
|
64
|
-
}
|
|
65
|
-
this.status = newState;
|
|
66
|
-
}
|
|
67
|
-
get allDeps() {
|
|
68
|
-
const deps = [...this.dependsOn];
|
|
69
|
-
if (this.parentId && !deps.includes(this.parentId)) {
|
|
70
|
-
deps.push(this.parentId);
|
|
71
|
-
}
|
|
72
|
-
return deps;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.Task = Task;
|
|
76
|
-
class TaskResult {
|
|
77
|
-
constructor(success, content, data) {
|
|
78
|
-
this.data = {};
|
|
79
|
-
this.success = success;
|
|
80
|
-
this.content = content;
|
|
81
|
-
this.data = data || {};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.TaskResult = TaskResult;
|
|
18
|
+
// Domain model lives in ./agent/task — re-exported here so importers of
|
|
19
|
+
// '../core/agent' are unaffected by the Phase 3 split.
|
|
20
|
+
const task_1 = require("./agent/task");
|
|
21
|
+
Object.defineProperty(exports, "AgentState", { enumerable: true, get: function () { return task_1.AgentState; } });
|
|
22
|
+
Object.defineProperty(exports, "TaskState", { enumerable: true, get: function () { return task_1.TaskState; } });
|
|
23
|
+
Object.defineProperty(exports, "Task", { enumerable: true, get: function () { return task_1.Task; } });
|
|
24
|
+
Object.defineProperty(exports, "TaskResult", { enumerable: true, get: function () { return task_1.TaskResult; } });
|
|
85
25
|
class BaseAgent {
|
|
86
26
|
constructor(config, llm, bus, toolRegistry, skillRegistry) {
|
|
87
27
|
this.name = '';
|
|
@@ -91,7 +31,7 @@ class BaseAgent {
|
|
|
91
31
|
this.systemPrompt = '';
|
|
92
32
|
this.toolNames = [];
|
|
93
33
|
this.skillNames = [];
|
|
94
|
-
this.state = AgentState.IDLE;
|
|
34
|
+
this.state = task_1.AgentState.IDLE;
|
|
95
35
|
this._tools = [];
|
|
96
36
|
this._skills = [];
|
|
97
37
|
this._activeSkills = new Set();
|
|
@@ -109,20 +49,20 @@ class BaseAgent {
|
|
|
109
49
|
this._turnLockCounter = 0;
|
|
110
50
|
this._turnLockResolve = null;
|
|
111
51
|
// ── Fact extraction ──
|
|
112
|
-
this.EXTRACT_PROMPT = `你是一个事实抽取助手。从下面的对话中抽取**用户透露的稳定、可复用的事实**。
|
|
113
|
-
|
|
114
|
-
**应该抽取**:
|
|
115
|
-
- 工具/技术偏好(pkg_mgr=pnpm, editor=neovim, framework=FastAPI)
|
|
116
|
-
- 项目信息(project_lang=Python, project_name=skyloom)
|
|
117
|
-
- 长期目标(goal=build_url_shortener)
|
|
118
|
-
- 关键约束(os=Windows, python_version=3.13)
|
|
119
|
-
|
|
120
|
-
**输出格式**:纯 JSON 数组:
|
|
121
|
-
[{"key": "pkg_mgr", "value": "pnpm", "category": "user_pref"}]
|
|
122
|
-
|
|
123
|
-
对话:
|
|
124
|
-
{conversation}
|
|
125
|
-
|
|
52
|
+
this.EXTRACT_PROMPT = `你是一个事实抽取助手。从下面的对话中抽取**用户透露的稳定、可复用的事实**。
|
|
53
|
+
|
|
54
|
+
**应该抽取**:
|
|
55
|
+
- 工具/技术偏好(pkg_mgr=pnpm, editor=neovim, framework=FastAPI)
|
|
56
|
+
- 项目信息(project_lang=Python, project_name=skyloom)
|
|
57
|
+
- 长期目标(goal=build_url_shortener)
|
|
58
|
+
- 关键约束(os=Windows, python_version=3.13)
|
|
59
|
+
|
|
60
|
+
**输出格式**:纯 JSON 数组:
|
|
61
|
+
[{"key": "pkg_mgr", "value": "pnpm", "category": "user_pref"}]
|
|
62
|
+
|
|
63
|
+
对话:
|
|
64
|
+
{conversation}
|
|
65
|
+
|
|
126
66
|
输出:`;
|
|
127
67
|
this._security = null;
|
|
128
68
|
this.config = config;
|
|
@@ -130,7 +70,15 @@ class BaseAgent {
|
|
|
130
70
|
this.bus = bus;
|
|
131
71
|
this.toolRegistry = toolRegistry;
|
|
132
72
|
this.skillRegistry = skillRegistry || new skill_1.SkillRegistry();
|
|
133
|
-
|
|
73
|
+
// Normalize the memory config — YAML uses snake_case (db_path/short_term_limit)
|
|
74
|
+
// while Memory expects camelCase. Tolerate both so a preserved config block
|
|
75
|
+
// doesn't break construction.
|
|
76
|
+
const mc = config.memory || {};
|
|
77
|
+
this.memory = new memory_1.Memory({
|
|
78
|
+
dbPath: mc.dbPath || mc.db_path || '~/.skyloom',
|
|
79
|
+
shortTermLimit: mc.shortTermLimit || mc.short_term_limit || 100,
|
|
80
|
+
maxPersistedMessages: mc.maxPersistedMessages || mc.max_persisted_messages,
|
|
81
|
+
}, this.name);
|
|
134
82
|
this._maxToolRounds = 20;
|
|
135
83
|
}
|
|
136
84
|
// ── System prompt resolution ──
|
|
@@ -559,7 +507,7 @@ class BaseAgent {
|
|
|
559
507
|
}
|
|
560
508
|
if (onStatus)
|
|
561
509
|
onStatus(p.label);
|
|
562
|
-
await this.setState(AgentState.ACTING);
|
|
510
|
+
await this.setState(task_1.AgentState.ACTING);
|
|
563
511
|
try {
|
|
564
512
|
const toolResult = await this.toolRegistry.execute(p.toolName, p.toolArgs || {});
|
|
565
513
|
const resultStr = toolResult.result || toolResult.error || '(no output)';
|
|
@@ -622,7 +570,7 @@ class BaseAgent {
|
|
|
622
570
|
}
|
|
623
571
|
async handleEvent(event) {
|
|
624
572
|
if (event.type === bus_1.EventType.TASK_ASSIGNED && event.target === this.name) {
|
|
625
|
-
const task = new Task(event.data);
|
|
573
|
+
const task = new task_1.Task(event.data);
|
|
626
574
|
const result = await this.executeTask(task);
|
|
627
575
|
await this.bus.publish(new bus_1.Event(bus_1.EventType.TASK_COMPLETED, this.name, event.source, { task_id: task.id, success: result.success, content: result.content }));
|
|
628
576
|
}
|
|
@@ -651,7 +599,7 @@ class BaseAgent {
|
|
|
651
599
|
return this.withTurnLock(() => this.chatImpl(message, onStatus));
|
|
652
600
|
}
|
|
653
601
|
async chatImpl(message, onStatus) {
|
|
654
|
-
await this.setState(AgentState.THINKING);
|
|
602
|
+
await this.setState(task_1.AgentState.THINKING);
|
|
655
603
|
this.memory.addMessage('user', message);
|
|
656
604
|
if (this.shouldAutoCompact()) {
|
|
657
605
|
try {
|
|
@@ -678,12 +626,12 @@ class BaseAgent {
|
|
|
678
626
|
toolCalls: response?.toolCalls || [],
|
|
679
627
|
reasoningContent: response?.reasoningContent,
|
|
680
628
|
});
|
|
681
|
-
await this.setState(AgentState.IDLE);
|
|
629
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
682
630
|
this.maybeExtractFacts();
|
|
683
631
|
return content;
|
|
684
632
|
}
|
|
685
633
|
catch (e) {
|
|
686
|
-
await this.setState(AgentState.ERROR);
|
|
634
|
+
await this.setState(task_1.AgentState.ERROR);
|
|
687
635
|
this.popLastUserMessage();
|
|
688
636
|
this.memory.pruneToolMessages();
|
|
689
637
|
const errorMsg = `[${this.displayName}] Error: ${e}`;
|
|
@@ -708,7 +656,7 @@ class BaseAgent {
|
|
|
708
656
|
}
|
|
709
657
|
}
|
|
710
658
|
async *chatStreamImpl(message, autoActivated) {
|
|
711
|
-
await this.setState(AgentState.THINKING);
|
|
659
|
+
await this.setState(task_1.AgentState.THINKING);
|
|
712
660
|
this.memory.addMessage('user', message);
|
|
713
661
|
let assistantStored = false;
|
|
714
662
|
if (this.shouldAutoCompact()) {
|
|
@@ -785,7 +733,7 @@ class BaseAgent {
|
|
|
785
733
|
yield { type: 'content', text: `\n[Error: ${event.text}]` };
|
|
786
734
|
if (!assistantStored)
|
|
787
735
|
this.popLastUserMessage();
|
|
788
|
-
await this.setState(AgentState.IDLE);
|
|
736
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
789
737
|
return;
|
|
790
738
|
}
|
|
791
739
|
else if (event.type === 'reasoning' && event.text) {
|
|
@@ -803,7 +751,7 @@ class BaseAgent {
|
|
|
803
751
|
}
|
|
804
752
|
this.memory.addMessage('assistant', finalContent, { reasoningContent: streamingReasoning });
|
|
805
753
|
assistantStored = true;
|
|
806
|
-
await this.setState(AgentState.IDLE);
|
|
754
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
807
755
|
this.maybeExtractFacts();
|
|
808
756
|
if (finalContent !== roundContent)
|
|
809
757
|
yield { type: 'content', text: finalContent };
|
|
@@ -862,7 +810,7 @@ class BaseAgent {
|
|
|
862
810
|
if (taskCompleted) {
|
|
863
811
|
if (!assistantStored)
|
|
864
812
|
this.popLastUserMessage();
|
|
865
|
-
await this.setState(AgentState.IDLE);
|
|
813
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
866
814
|
yield { type: 'done' };
|
|
867
815
|
return;
|
|
868
816
|
}
|
|
@@ -911,7 +859,7 @@ class BaseAgent {
|
|
|
911
859
|
if (topCount >= agent_helpers_1.SIG_LOOP_HARDSTOP) {
|
|
912
860
|
this.memory.addMessage('assistant', `I have repeated \`${topSig}\` ${topCount} times without converging. Stopping.`);
|
|
913
861
|
yield { type: 'content', text: `\n\n[stuck] tool \`${topSig}\` repeated ${topCount}x — stopping.` };
|
|
914
|
-
await this.setState(AgentState.IDLE);
|
|
862
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
915
863
|
yield { type: 'done' };
|
|
916
864
|
return;
|
|
917
865
|
}
|
|
@@ -933,7 +881,7 @@ class BaseAgent {
|
|
|
933
881
|
if (recentToolOutcomes.length >= 8 && recentToolOutcomes.every(x => !x)) {
|
|
934
882
|
this.memory.addMessage('assistant', 'Every recent tool call failed. Please give me more context.');
|
|
935
883
|
yield { type: 'content', text: '\n\n[stuck] every recent tool call failed — stopping.\n' };
|
|
936
|
-
await this.setState(AgentState.IDLE);
|
|
884
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
937
885
|
yield { type: 'done' };
|
|
938
886
|
return;
|
|
939
887
|
}
|
|
@@ -946,7 +894,7 @@ class BaseAgent {
|
|
|
946
894
|
if (searchStormCount >= 12) {
|
|
947
895
|
this.memory.addMessage('assistant', 'Too many search requests. Synthesizing best answer.');
|
|
948
896
|
yield { type: 'content', text: `\n\n[stuck] excessive web searching (${searchStormCount} calls) — stopping.\n` };
|
|
949
|
-
await this.setState(AgentState.IDLE);
|
|
897
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
950
898
|
yield { type: 'done' };
|
|
951
899
|
return;
|
|
952
900
|
}
|
|
@@ -954,7 +902,7 @@ class BaseAgent {
|
|
|
954
902
|
// Max iterations reached
|
|
955
903
|
if (!assistantStored)
|
|
956
904
|
this.popLastUserMessage();
|
|
957
|
-
await this.setState(AgentState.IDLE);
|
|
905
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
958
906
|
if (!fullContent.trim() && delegations.length > 0) {
|
|
959
907
|
const synth = (0, agent_helpers_1.synthesizeDelegationSummary)(delegations);
|
|
960
908
|
this.memory.addMessage('assistant', synth);
|
|
@@ -966,7 +914,7 @@ class BaseAgent {
|
|
|
966
914
|
catch (e) {
|
|
967
915
|
if (!assistantStored)
|
|
968
916
|
this.popLastUserMessage();
|
|
969
|
-
await this.setState(AgentState.ERROR);
|
|
917
|
+
await this.setState(task_1.AgentState.ERROR);
|
|
970
918
|
yield { type: 'content', text: `\n[Error: ${e.message || e}]` };
|
|
971
919
|
}
|
|
972
920
|
finally {
|
|
@@ -1094,7 +1042,7 @@ class BaseAgent {
|
|
|
1094
1042
|
const convoText = convoMsgs.map(m => `${m.role}: ${(m.content || '').slice(0, 500)}`).join('\n');
|
|
1095
1043
|
const prompt = this.EXTRACT_PROMPT.replace('{conversation}', convoText);
|
|
1096
1044
|
const response = await this.llm.complete([{ role: 'user', content: prompt }], `${this.name}_extract`, undefined);
|
|
1097
|
-
const facts =
|
|
1045
|
+
const facts = (0, agent_helpers_1.parseExtractedFacts)(response.content);
|
|
1098
1046
|
let written = 0;
|
|
1099
1047
|
for (const f of facts) {
|
|
1100
1048
|
const key = f.key;
|
|
@@ -1114,47 +1062,15 @@ class BaseAgent {
|
|
|
1114
1062
|
return 0;
|
|
1115
1063
|
}
|
|
1116
1064
|
}
|
|
1117
|
-
parseExtractedFacts(content) {
|
|
1118
|
-
const text = (content || '').trim();
|
|
1119
|
-
if (!text)
|
|
1120
|
-
return [];
|
|
1121
|
-
// 1. Direct parse
|
|
1122
|
-
try {
|
|
1123
|
-
const data = JSON.parse(text);
|
|
1124
|
-
if (Array.isArray(data))
|
|
1125
|
-
return data.filter(f => typeof f === 'object');
|
|
1126
|
-
}
|
|
1127
|
-
catch { /* continue */ }
|
|
1128
|
-
// 2. Markdown-fenced JSON
|
|
1129
|
-
const fenceMatch = text.match(/```(?:json)?\s*(\[[\s\S]*?\])\s*```/);
|
|
1130
|
-
if (fenceMatch) {
|
|
1131
|
-
try {
|
|
1132
|
-
const data = JSON.parse(fenceMatch[1]);
|
|
1133
|
-
if (Array.isArray(data))
|
|
1134
|
-
return data.filter(f => typeof f === 'object');
|
|
1135
|
-
}
|
|
1136
|
-
catch { /* continue */ }
|
|
1137
|
-
}
|
|
1138
|
-
// 3. First JSON array substring
|
|
1139
|
-
const arrayMatch = text.match(/\[[\s\S]*?\]/);
|
|
1140
|
-
if (arrayMatch) {
|
|
1141
|
-
try {
|
|
1142
|
-
const data = JSON.parse(arrayMatch[0]);
|
|
1143
|
-
if (Array.isArray(data))
|
|
1144
|
-
return data.filter(f => typeof f === 'object');
|
|
1145
|
-
}
|
|
1146
|
-
catch { /* continue */ }
|
|
1147
|
-
}
|
|
1148
|
-
return [];
|
|
1149
|
-
}
|
|
1150
1065
|
async messagesWithRecall() {
|
|
1151
1066
|
const messages = this.memory.getMessages();
|
|
1152
1067
|
if (!messages || process.env.WA_NO_RECALL === '1')
|
|
1153
1068
|
return messages;
|
|
1154
|
-
const
|
|
1155
|
-
if (
|
|
1156
|
-
return messages;
|
|
1157
|
-
const
|
|
1069
|
+
const revIdx = [...messages].reverse().findIndex(m => m.role === 'user');
|
|
1070
|
+
if (revIdx < 0)
|
|
1071
|
+
return messages; // no user message yet — nothing to recall against
|
|
1072
|
+
const lastUserIdx = messages.length - 1 - revIdx;
|
|
1073
|
+
const query = String(messages[lastUserIdx]?.content || '').slice(0, 200);
|
|
1158
1074
|
const stripped = query.trim();
|
|
1159
1075
|
if (stripped.length < 4)
|
|
1160
1076
|
return messages;
|
|
@@ -1218,7 +1134,7 @@ class BaseAgent {
|
|
|
1218
1134
|
});
|
|
1219
1135
|
// ── Execute all tools via shared pipeline ──
|
|
1220
1136
|
await this.executeToolCalls(response.toolCalls, { onStatus: onStatus ?? undefined, ephemeral });
|
|
1221
|
-
await this.setState(AgentState.THINKING);
|
|
1137
|
+
await this.setState(task_1.AgentState.THINKING);
|
|
1222
1138
|
}
|
|
1223
1139
|
response.truncated = true;
|
|
1224
1140
|
if (!response.content) {
|
|
@@ -1235,8 +1151,8 @@ class BaseAgent {
|
|
|
1235
1151
|
return this.withTurnLock(() => this.executeTaskImpl(task, onStatus));
|
|
1236
1152
|
}
|
|
1237
1153
|
async executeTaskImpl(task, onStatus) {
|
|
1238
|
-
await this.setState(AgentState.THINKING);
|
|
1239
|
-
task.transitionTo(TaskState.RUNNING);
|
|
1154
|
+
await this.setState(task_1.AgentState.THINKING);
|
|
1155
|
+
task.transitionTo(task_1.TaskState.RUNNING);
|
|
1240
1156
|
this.memory.setWorking('current_task', task);
|
|
1241
1157
|
const prompt = `Complete this task NOW using your available tools. Then write the actual deliverable content in your final reply.\n\nTask: ${task.description}`;
|
|
1242
1158
|
if (task.metadata) {
|
|
@@ -1267,17 +1183,17 @@ class BaseAgent {
|
|
|
1267
1183
|
const filePaths = (0, agent_helpers_1.extractFilePathsFromMessages)(this.memory.shortTerm.slice(preLen));
|
|
1268
1184
|
const enriched = (0, agent_helpers_1.enrichResponseWithArtifacts)(response.content, filePaths);
|
|
1269
1185
|
this.memory.addMessage('assistant', enriched, { toolCalls: response.toolCalls, reasoningContent: response.reasoningContent });
|
|
1270
|
-
task.transitionTo(TaskState.COMPLETED);
|
|
1186
|
+
task.transitionTo(task_1.TaskState.COMPLETED);
|
|
1271
1187
|
task.result = enriched;
|
|
1272
|
-
await this.setState(AgentState.IDLE);
|
|
1273
|
-
return new TaskResult(true, enriched);
|
|
1188
|
+
await this.setState(task_1.AgentState.IDLE);
|
|
1189
|
+
return new task_1.TaskResult(true, enriched);
|
|
1274
1190
|
}
|
|
1275
1191
|
catch (e) {
|
|
1276
|
-
task.transitionTo(TaskState.FAILED);
|
|
1192
|
+
task.transitionTo(task_1.TaskState.FAILED);
|
|
1277
1193
|
task.result = String(e);
|
|
1278
1194
|
this.memory.pruneToolMessages();
|
|
1279
|
-
await this.setState(AgentState.ERROR);
|
|
1280
|
-
return new TaskResult(false, String(e));
|
|
1195
|
+
await this.setState(task_1.AgentState.ERROR);
|
|
1196
|
+
return new task_1.TaskResult(false, String(e));
|
|
1281
1197
|
}
|
|
1282
1198
|
finally {
|
|
1283
1199
|
// Restore chat history
|
|
@@ -1333,7 +1249,7 @@ class BaseAgent {
|
|
|
1333
1249
|
const source = event.data?.source || '';
|
|
1334
1250
|
if (!correlationId)
|
|
1335
1251
|
return;
|
|
1336
|
-
const task = new Task({
|
|
1252
|
+
const task = new task_1.Task({
|
|
1337
1253
|
id: `req-${correlationId.slice(0, 8)}`,
|
|
1338
1254
|
description,
|
|
1339
1255
|
assignedTo: this.name,
|