@c4ccz/zero 1.0.0 → 1.0.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/package.json +10 -7
- package/packages/core/src/agent/config-loader.ts +174 -0
- package/packages/core/src/agent/engine.ts +266 -0
- package/packages/core/src/agent/registry-tools.ts +58 -0
- package/packages/core/src/agent/registry.ts +213 -0
- package/packages/core/src/commands/index.ts +116 -0
- package/packages/core/src/config/index.ts +139 -0
- package/packages/core/src/confirmation/message-bus.ts +206 -0
- package/packages/core/src/diff/index.ts +232 -0
- package/packages/core/src/diff-detect/index.ts +207 -0
- package/packages/core/src/edit-coder/index.ts +194 -0
- package/packages/core/src/events/index.ts +151 -0
- package/packages/core/src/file-tracker/index.ts +183 -0
- package/packages/core/src/git/index.ts +305 -0
- package/packages/core/src/history/index.ts +236 -0
- package/packages/core/src/image/index.ts +131 -0
- package/packages/core/src/index.ts +131 -0
- package/packages/core/src/lsp/index.ts +251 -0
- package/packages/core/src/mcp/index.ts +186 -0
- package/packages/core/src/memory/index.ts +141 -0
- package/packages/core/src/memory/prompts.ts +52 -0
- package/packages/core/src/orchestrator/protocol.ts +140 -0
- package/packages/core/src/orchestrator/server.ts +319 -0
- package/packages/core/src/output/index.ts +164 -0
- package/packages/core/src/permissions/index.ts +126 -0
- package/packages/core/src/prompts/engine.ts +188 -0
- package/packages/core/src/providers/extended.ts +8 -0
- package/packages/core/src/providers/registry.ts +687 -0
- package/packages/core/src/routing/model-router.ts +160 -0
- package/packages/core/src/server/index.ts +232 -0
- package/packages/core/src/session/index.ts +174 -0
- package/packages/core/src/session/service.ts +322 -0
- package/packages/core/src/skills/index.ts +205 -0
- package/packages/core/src/streaming/index.ts +166 -0
- package/packages/core/src/sub-agent/index.ts +179 -0
- package/packages/core/src/tools/builtin.ts +568 -0
- package/packages/core/src/tools/linter.ts +26 -0
- package/packages/core/src/tools/repo-map.ts +11 -0
- package/packages/core/src/types.ts +356 -0
- package/packages/sdk/src/index.ts +247 -0
- package/packages/tui/src/index.ts +141 -0
- package/bun.lock +0 -35
- package/bunfig.toml +0 -6
- package/packages/cli/package.json +0 -23
- package/packages/core/package.json +0 -41
- package/packages/sdk/package.json +0 -16
- package/packages/tui/package.json +0 -19
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ZERO Sub-Agent System
|
|
3
|
+
* Adapted from: cline - Apache 2.0
|
|
4
|
+
*
|
|
5
|
+
* Full sub-agent delegation with config loading,
|
|
6
|
+
* tool scoping, and result aggregation.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
AgentConfig,
|
|
11
|
+
AgentResult,
|
|
12
|
+
Message,
|
|
13
|
+
ToolDefinition,
|
|
14
|
+
ToolResult,
|
|
15
|
+
PermissionHandler,
|
|
16
|
+
LLMClient,
|
|
17
|
+
} from "../types.js";
|
|
18
|
+
import { AgentEngine } from "../agent/engine.js";
|
|
19
|
+
|
|
20
|
+
export interface SubAgentTask {
|
|
21
|
+
agentId: string;
|
|
22
|
+
task: string;
|
|
23
|
+
context?: string;
|
|
24
|
+
maxTurns?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SubAgentResult {
|
|
28
|
+
agentId: string;
|
|
29
|
+
success: boolean;
|
|
30
|
+
output: string;
|
|
31
|
+
tokenUsage: { inputTokens: number; outputTokens: number };
|
|
32
|
+
duration: number;
|
|
33
|
+
error?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SubAgentOptions {
|
|
37
|
+
agents: Map<string, AgentConfig>;
|
|
38
|
+
tools: Map<string, ToolDefinition>;
|
|
39
|
+
clientFactory: (model: string) => LLMClient;
|
|
40
|
+
permissionHandler: PermissionHandler;
|
|
41
|
+
workingDirectory: string;
|
|
42
|
+
sessionId: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sub-Agent Manager
|
|
47
|
+
*/
|
|
48
|
+
export class SubAgentManager {
|
|
49
|
+
private options: SubAgentOptions;
|
|
50
|
+
|
|
51
|
+
constructor(options: SubAgentOptions) {
|
|
52
|
+
this.options = options;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Execute a task with a specific sub-agent
|
|
57
|
+
*/
|
|
58
|
+
async execute(task: SubAgentTask): Promise<SubAgentResult> {
|
|
59
|
+
const agentConfig = this.options.agents.get(task.agentId);
|
|
60
|
+
if (!agentConfig) {
|
|
61
|
+
return {
|
|
62
|
+
agentId: task.agentId,
|
|
63
|
+
success: false,
|
|
64
|
+
output: "",
|
|
65
|
+
tokenUsage: { inputTokens: 0, outputTokens: 0 },
|
|
66
|
+
duration: 0,
|
|
67
|
+
error: `Agent "${task.agentId}" not found`,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const config: AgentConfig = {
|
|
72
|
+
...agentConfig,
|
|
73
|
+
maxTurns: task.maxTurns || agentConfig.maxTurns || 20,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const engine = new AgentEngine({
|
|
77
|
+
config,
|
|
78
|
+
client: this.options.clientFactory(config.model),
|
|
79
|
+
tools: this.getScopedTools(config.tools),
|
|
80
|
+
permissionHandler: this.options.permissionHandler,
|
|
81
|
+
workingDirectory: this.options.workingDirectory,
|
|
82
|
+
sessionId: `${this.options.sessionId}_sub_${task.agentId}`,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const prompt = task.context
|
|
86
|
+
? `${task.task}\n\n## Context:\n${task.context}`
|
|
87
|
+
: task.task;
|
|
88
|
+
|
|
89
|
+
const result = await engine.run(prompt);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
agentId: task.agentId,
|
|
93
|
+
success: result.success,
|
|
94
|
+
output: this.extractOutput(result),
|
|
95
|
+
tokenUsage: result.tokenUsage,
|
|
96
|
+
duration: result.duration,
|
|
97
|
+
error: result.error,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Execute multiple tasks in parallel
|
|
103
|
+
*/
|
|
104
|
+
async executeParallel(tasks: SubAgentTask[]): Promise<SubAgentResult[]> {
|
|
105
|
+
return Promise.all(tasks.map((task) => this.execute(task)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Execute tasks sequentially
|
|
110
|
+
*/
|
|
111
|
+
async executeSequential(tasks: SubAgentTask[]): Promise<SubAgentResult[]> {
|
|
112
|
+
const results: SubAgentResult[] = [];
|
|
113
|
+
for (const task of tasks) {
|
|
114
|
+
results.push(await this.execute(task));
|
|
115
|
+
}
|
|
116
|
+
return results;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private getScopedTools(toolNames: string[]): Map<string, ToolDefinition> {
|
|
120
|
+
const scoped = new Map<string, ToolDefinition>();
|
|
121
|
+
for (const name of toolNames) {
|
|
122
|
+
const tool = this.options.tools.get(name);
|
|
123
|
+
if (tool) scoped.set(name, tool);
|
|
124
|
+
}
|
|
125
|
+
return scoped;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private extractOutput(result: AgentResult): string {
|
|
129
|
+
return result.messages
|
|
130
|
+
.filter((m) => m.role === "assistant")
|
|
131
|
+
.flatMap((m) => m.content)
|
|
132
|
+
.filter((c) => c.type === "text")
|
|
133
|
+
.map((c) => (c as any).text)
|
|
134
|
+
.join("\n");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Create a delegate_to_agent tool
|
|
140
|
+
*/
|
|
141
|
+
export function createDelegateTool(manager: SubAgentManager): ToolDefinition {
|
|
142
|
+
return {
|
|
143
|
+
name: "delegate_to_agent",
|
|
144
|
+
description: "Delegate a sub-task to a specialized agent. The sub-agent will work independently and return results.",
|
|
145
|
+
parameters: {
|
|
146
|
+
agentId: {
|
|
147
|
+
type: "string",
|
|
148
|
+
description: "ID of the agent to delegate to (reviewer, researcher)",
|
|
149
|
+
required: true,
|
|
150
|
+
enum: ["reviewer", "researcher"],
|
|
151
|
+
},
|
|
152
|
+
task: {
|
|
153
|
+
type: "string",
|
|
154
|
+
description: "The task description for the sub-agent",
|
|
155
|
+
required: true,
|
|
156
|
+
},
|
|
157
|
+
context: {
|
|
158
|
+
type: "string",
|
|
159
|
+
description: "Additional context for the sub-agent",
|
|
160
|
+
required: false,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
category: "system",
|
|
164
|
+
requiresApproval: false,
|
|
165
|
+
handler: async (args): Promise<ToolResult> => {
|
|
166
|
+
const result = await manager.execute({
|
|
167
|
+
agentId: args.agentId as string,
|
|
168
|
+
task: args.task as string,
|
|
169
|
+
context: args.context as string | undefined,
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
success: result.success,
|
|
174
|
+
output: result.output || result.error || "No output",
|
|
175
|
+
data: result,
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|