zen-code 3.0.5 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,210 @@
1
+ import { tool as p, HumanMessage as d, SystemMessage as m } from "langchain";
2
+ import { Command as f, Annotation as b } from "@langchain/langgraph";
3
+ import { z as i } from "zod";
4
+ import { c as w, a as y } from "./graphBuilder-BSX1uOgk.mjs";
5
+ import "@langchain/openai";
6
+ const k = i.object({
7
+ task_store: i.record(i.string(), i.any()).default({})
8
+ });
9
+ w().build({
10
+ task_store: b({
11
+ reducer: (r, t) => ({ ...r, ...t }),
12
+ default: () => ({})
13
+ })
14
+ });
15
+ const _ = i.object({
16
+ task_id: i.string().optional().describe("The task id to ask the subagent, if not provided, will use the tool call id"),
17
+ subagent_type: i.string().describe(
18
+ "The type of subagent to use. Must be one of the available agent types listed in the tool description."
19
+ ),
20
+ task_description: i.string().describe("Describe the user state and what you want the subagent to do."),
21
+ data_transfer: i.any().optional().describe("Data to transfer to the subagent.")
22
+ }), v = (r, t) => p(
23
+ async (e, s) => {
24
+ const a = s.state, o = e.task_id || s.toolCall.id;
25
+ let n = {
26
+ messages: []
27
+ };
28
+ o && a?.task_store?.[o] ? n = a?.task_store[o] : (n = JSON.parse(JSON.stringify(a)), n.messages = [], n.task_store = {});
29
+ const u = await r(o, e, a);
30
+ n.messages.push(new d({ content: e.task_description })), e.data_transfer && n.messages.push(
31
+ new d({
32
+ content: `Here is the data to help you complete the task: ${JSON.stringify(
33
+ e.data_transfer,
34
+ null,
35
+ 2
36
+ )}`
37
+ })
38
+ );
39
+ const l = await u.invoke(n), g = l.messages.at(-1), c = {
40
+ task_store: {
41
+ ...a?.task_store || {},
42
+ [o]: l
43
+ },
44
+ messages: [
45
+ {
46
+ role: "tool",
47
+ content: `task_id: ${o}
48
+ ---
49
+ ` + (g?.text || ""),
50
+ tool_call_id: s.toolCall.id
51
+ }
52
+ ]
53
+ };
54
+ return t?.pass_through_keys?.forEach((h) => {
55
+ h in l && (c[h] = l[h]);
56
+ }), new f({
57
+ update: c
58
+ });
59
+ },
60
+ {
61
+ name: "task",
62
+ description: `Launch a new agent to handle complex, multi-step tasks autonomously.
63
+
64
+ Available agent types and the tools they have access to:
65
+ - general-purpose: General-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. When you are searching for a keyword or file and are not confident that you will find the right match in the first few tries use this agent to perform the search for you. (Tools: *)
66
+ - statusline-setup: Use this agent to configure the user's Claude Code status line setting. (Tools: Read, Edit)
67
+ - output-style-setup: Use this agent to create a Claude Code output style. (Tools: Read, Write, Edit, Glob, LS, Grep)
68
+
69
+ When using the Task tool, you must specify a subagent_type parameter to select which agent type to use.
70
+
71
+
72
+
73
+ When NOT to use the Agent tool:
74
+ - If you want to read a specific file path, use the Read or Glob tool instead of the Agent tool, to find the match more quickly
75
+ - If you are searching for a specific class definition like "class Foo", use the Glob tool instead, to find the match more quickly
76
+ - If you are searching for code within a specific file or set of 2-3 files, use the Read tool instead of the Agent tool, to find the match more quickly
77
+ - Other tasks that are not related to the agent descriptions above
78
+
79
+
80
+ Usage notes:
81
+ 1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
82
+ 2. When the agent is done, it will return a single message back to you. The result returned by the agent is not visible to the user. To show the user the result, you should send a text message back to the user with a concise summary of the result.
83
+ 3. Each agent invocation is stateless. You will not be able to send additional messages to the agent, nor will the agent be able to communicate with you outside of its final report. Therefore, your prompt should contain a highly detailed task description for the agent to perform autonomously and you should specify exactly what information the agent should return back to you in its final and only message to you.
84
+ 4. The agent's outputs should generally be trusted
85
+ 5. Clearly tell the agent whether you expect it to write code or just to do research (search, file reads, web fetches, etc.), since it is not aware of the user's intent
86
+ 6. If the agent description mentions that it should be used proactively, then you should try your best to use it without the user having to ask for it first. Use your judgement.
87
+
88
+ Example usage:
89
+
90
+ <example_agent_descriptions>
91
+ "code-reviewer": use this agent after you are done writing a significant piece of code
92
+ "greeting-responder": use this agent when to respond to user greetings with a friendly joke
93
+ </example_agent_description>
94
+
95
+ <example>
96
+ user: "Please write a function that checks if a number is prime"
97
+ assistant: Sure let me write a function that checks if a number is prime
98
+ assistant: First let me use the Write tool to write a function that checks if a number is prime
99
+ assistant: I'm going to use the Write tool to write the following code:
100
+ <code>
101
+ function isPrime(n) {
102
+ if (n <= 1) return false
103
+ for (let i = 2; i * i <= n; i++) {
104
+ if (n % i === 0) return false
105
+ }
106
+ return true
107
+ }
108
+ </code>
109
+ <commentary>
110
+ Since a signficant piece of code was written and the task was completed, now use the code-reviewer agent to review the code
111
+ </commentary>
112
+ assistant: Now let me use the code-reviewer agent to review the code
113
+ assistant: Uses the Task tool to launch the with the code-reviewer agent
114
+ </example>
115
+
116
+ <example>
117
+ user: "Hello"
118
+ <commentary>
119
+ Since the user is greeting, use the greeting-responder agent to respond with a friendly joke
120
+ </commentary>
121
+ assistant: "I'm going to use the Task tool to launch the with the greeting-responder agent"
122
+ </example>
123
+ `,
124
+ schema: _
125
+ }
126
+ ), S = `
127
+
128
+ ## SubAgents System
129
+
130
+ You have access to a subagent system that can delegate specialized tasks to other agents.
131
+
132
+ **Available SubAgents:**
133
+
134
+ {subagents_list}
135
+
136
+ **How to Use SubAgents (Progressive Disclosure):**
137
+
138
+ SubAgents follow a **progressive disclosure** pattern - you know they exist (name + description above), but you only delegate tasks when needed:
139
+
140
+ 1. **Recognize when to delegate**: Check if the user's task matches a subagent's specialization
141
+ 2. **Use the ask_subagents tool**: Call the tool with the subagent's ID and a clear task description
142
+ 3. **Provide context**: Use the \`data_transfer\` parameter to pass relevant information
143
+ 4. **Get results**: The subagent will process the task and return results
144
+
145
+ **When to Use SubAgents:**
146
+ - When the user's request requires specialized knowledge or workflows
147
+ - When a task is complex and can be broken down into subtasks
148
+ - When you need parallel processing or different expertise areas
149
+ - When a subagent provides proven patterns for specific domains
150
+
151
+ **SubAgent Tool Usage:**
152
+
153
+ The \`ask_subagents\` tool is available for delegation:
154
+
155
+ - **subagent_id**: The ID of the subagent to delegate to
156
+ - **task_description**: Clear description of what needs to be done
157
+ - **task_id** (optional): Identifier for tracking, it will automatically be generated after you run a subagent.
158
+ - **data_transfer** (optional): Context/data to pass to the subagent
159
+
160
+ **Example Workflow:**
161
+
162
+ User: "Can you have the research agent look into quantum computing developments?"
163
+
164
+ 1. Check available subagents above → See "research" subagent with ID
165
+ 2. Use ask_subagents tool with appropriate parameters
166
+ 3. Provide clear task description and any necessary context
167
+ 4. Process the results from the subagent
168
+
169
+ Remember: SubAgents are tools to distribute work and leverage specialized capabilities. When in doubt, check if a subagent exists for the task!
170
+ `;
171
+ class W {
172
+ name = "SubAgentsMiddleware";
173
+ stateSchema = k;
174
+ contextSchema = void 0;
175
+ tools = [];
176
+ agentList = Promise.resolve("");
177
+ constructor(t) {
178
+ this.agentList = this.formatSubAgentsList(t), this.tools.push(
179
+ v(
180
+ async (e, s, a) => await y("agents/default", t, a, {}, { subagent_id: e }),
181
+ {}
182
+ )
183
+ );
184
+ }
185
+ /**
186
+ * Format subagents metadata for display in system prompt.
187
+ */
188
+ async formatSubAgentsList(t) {
189
+ const e = [];
190
+ for (const s of await t.listAgents())
191
+ e.push(`- **${s.id}**: ${s.description}`), e.push(` → Use ask_subagents with subagent_id: "${s.id}"`);
192
+ return e.join(`
193
+ `);
194
+ }
195
+ async wrapModelCall(t, e) {
196
+ const s = await this.agentList, a = S.replace("{subagents_list}", s);
197
+ let o;
198
+ t.systemPrompt ? o = t.systemPrompt + `
199
+
200
+ ` + a : o = a;
201
+ const n = new m(o), u = {
202
+ ...t,
203
+ systemMessage: n
204
+ };
205
+ return await e(u);
206
+ }
207
+ }
208
+ export {
209
+ W as SubAgentsMiddleware
210
+ };
@@ -0,0 +1,237 @@
1
+ import "micromatch";
2
+ import "./index-DFARkGOA.mjs";
3
+ import { Low as n } from "lowdb";
4
+ import { JSONFile as d } from "lowdb/node";
5
+ import "yaml";
6
+ import r from "node:path";
7
+ class h {
8
+ db;
9
+ dbPath;
10
+ constructor(t) {
11
+ this.dbPath = r.join(t, ".claude", "task.json");
12
+ const a = new d(this.dbPath);
13
+ this.db = new n(a, this.getDefaultData());
14
+ }
15
+ getDefaultData() {
16
+ return {
17
+ version: "1.0",
18
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString(),
19
+ tasks: {},
20
+ history: [],
21
+ config: {
22
+ maxConcurrentAgents: 3,
23
+ retryLimit: 3,
24
+ autoResume: !1
25
+ }
26
+ };
27
+ }
28
+ /**
29
+ * 初始化数据库
30
+ */
31
+ async initialize() {
32
+ const t = await import("node:fs"), a = r.dirname(this.dbPath);
33
+ t.existsSync(a) || t.mkdirSync(a, { recursive: !0 }), await this.db.read(), this.db.data || (this.db.data = this.getDefaultData(), await this.db.write());
34
+ }
35
+ /**
36
+ * 获取单个任务
37
+ */
38
+ async getTask(t) {
39
+ return await this.db.read(), this.db.data.tasks[t];
40
+ }
41
+ /**
42
+ * 更新任务
43
+ */
44
+ async updateTask(t, a) {
45
+ await this.db.read();
46
+ const i = this.db.data.tasks[t];
47
+ return i ? (this.db.data.tasks[t] = {
48
+ ...i,
49
+ ...a
50
+ }, a.status && (a.status === "running" && !i.startedAt ? this.db.data.tasks[t].startedAt = (/* @__PURE__ */ new Date()).toISOString() : ["complete", "error", "review"].includes(a.status) && !i.completedAt && (this.db.data.tasks[t].completedAt = (/* @__PURE__ */ new Date()).toISOString())), this.db.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString(), await this.db.write(), !0) : !1;
51
+ }
52
+ /**
53
+ * 批量添加任务(用于 Plan 初始化)
54
+ */
55
+ async addTasks(t) {
56
+ await this.db.read();
57
+ for (const a of t)
58
+ this.db.data.tasks[a.id] = a;
59
+ this.db.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString(), await this.db.write();
60
+ }
61
+ /**
62
+ * 根据 status 获取任务列表
63
+ */
64
+ async getTasksByStatus(t) {
65
+ return await this.db.read(), Object.values(this.db.data.tasks).filter((a) => a.status === t);
66
+ }
67
+ /**
68
+ * 获取所有任务
69
+ */
70
+ async getAllTasks() {
71
+ return await this.db.read(), Object.values(this.db.data.tasks);
72
+ }
73
+ /**
74
+ * 添加执行记录
75
+ */
76
+ async addHistory(t) {
77
+ await this.db.read(), this.db.data.history.push(t), await this.db.write();
78
+ }
79
+ /**
80
+ * 获取执行历史
81
+ */
82
+ async getHistory(t) {
83
+ return await this.db.read(), t ? this.db.data.history.filter((a) => a.planId === t) : this.db.data.history;
84
+ }
85
+ /**
86
+ * 设置活跃 Plan ID
87
+ */
88
+ async setActivePlan(t) {
89
+ await this.db.read(), this.db.data.activePlanId = t, this.db.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString(), await this.db.write();
90
+ }
91
+ /**
92
+ * 获取活跃 Plan ID
93
+ */
94
+ async getActivePlan() {
95
+ return await this.db.read(), this.db.data.activePlanId;
96
+ }
97
+ /**
98
+ * 更新配置
99
+ */
100
+ async updateConfig(t) {
101
+ await this.db.read(), this.db.data.config = {
102
+ ...this.db.data.config,
103
+ ...t
104
+ }, this.db.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString(), await this.db.write();
105
+ }
106
+ /**
107
+ * 获取配置
108
+ */
109
+ async getConfig() {
110
+ return await this.db.read(), this.db.data.config;
111
+ }
112
+ /**
113
+ * 清空所有任务(慎用)
114
+ */
115
+ async clearAllTasks() {
116
+ await this.db.read(), this.db.data.tasks = {}, this.db.data.activePlanId = void 0, this.db.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString(), await this.db.write();
117
+ }
118
+ /**
119
+ * 删除单个任务
120
+ */
121
+ async deleteTask(t) {
122
+ return await this.db.read(), this.db.data.tasks[t] ? (delete this.db.data.tasks[t], this.db.data.lastUpdated = (/* @__PURE__ */ new Date()).toISOString(), await this.db.write(), !0) : !1;
123
+ }
124
+ /**
125
+ * 获取数据库路径(用于测试)
126
+ */
127
+ getDbPath() {
128
+ return this.dbPath;
129
+ }
130
+ }
131
+ class o {
132
+ store = null;
133
+ projectRoot;
134
+ constructor(t) {
135
+ this.projectRoot = t;
136
+ }
137
+ /**
138
+ * 初始化 Store
139
+ */
140
+ async initialize() {
141
+ this.store || (this.store = new h(this.projectRoot), await this.store.initialize());
142
+ }
143
+ /**
144
+ * 确保 Store 已初始化
145
+ */
146
+ ensureInitialized() {
147
+ if (!this.store)
148
+ throw new Error("TasksStore not initialized. Call initialize() first.");
149
+ }
150
+ /**
151
+ * 获取所有任务
152
+ */
153
+ async getAllTasks() {
154
+ return this.ensureInitialized(), await this.store.getAllTasks();
155
+ }
156
+ /**
157
+ * 根据 status 获取任务
158
+ */
159
+ async getTasksByStatus(t) {
160
+ return this.ensureInitialized(), await this.store.getTasksByStatus(t);
161
+ }
162
+ /**
163
+ * 获取单个任务
164
+ */
165
+ async getTask(t) {
166
+ return this.ensureInitialized(), await this.store.getTask(t);
167
+ }
168
+ /**
169
+ * 更新任务状态
170
+ */
171
+ async updateTaskStatus(t, a) {
172
+ return this.ensureInitialized(), await this.store.updateTask(t, { status: a });
173
+ }
174
+ /**
175
+ * 删除任务
176
+ */
177
+ async deleteTask(t) {
178
+ return this.ensureInitialized(), await this.store.deleteTask(t);
179
+ }
180
+ /**
181
+ * 批量添加任务
182
+ */
183
+ async addTasks(t) {
184
+ this.ensureInitialized(), await this.store.addTasks(t);
185
+ }
186
+ /**
187
+ * 获取活跃 Plan ID
188
+ */
189
+ async getActivePlan() {
190
+ return this.ensureInitialized(), await this.store.getActivePlan();
191
+ }
192
+ /**
193
+ * 设置活跃 Plan ID
194
+ */
195
+ async setActivePlan(t) {
196
+ this.ensureInitialized(), await this.store.setActivePlan(t);
197
+ }
198
+ /**
199
+ * 获取任务统计
200
+ */
201
+ async getTaskStats() {
202
+ const t = await this.getAllTasks();
203
+ return {
204
+ total: t.length,
205
+ pickup: t.filter((a) => a.status === "pickup").length,
206
+ running: t.filter((a) => a.status === "running").length,
207
+ complete: t.filter((a) => a.status === "complete").length,
208
+ error: t.filter((a) => a.status === "error").length,
209
+ review: t.filter((a) => a.status === "review").length,
210
+ feedback: t.filter((a) => a.status === "feedback").length
211
+ };
212
+ }
213
+ /**
214
+ * 获取执行历史
215
+ */
216
+ async getHistory(t) {
217
+ return this.ensureInitialized(), await this.store.getHistory(t);
218
+ }
219
+ /**
220
+ * 清空所有任务(慎用)
221
+ */
222
+ async clearAllTasks() {
223
+ this.ensureInitialized(), await this.store.clearAllTasks();
224
+ }
225
+ }
226
+ let e = null;
227
+ function k(s) {
228
+ if (!e) {
229
+ if (!s)
230
+ throw new Error("projectRoot is required for first initialization");
231
+ e = new o(s);
232
+ }
233
+ return e;
234
+ }
235
+ export {
236
+ k as getTasksStore
237
+ };
package/dist/zen-code.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import "./use-input-1eSjZocJ.mjs";
1
+ import "./MultiLineTextInput-DjNvaZzA.mjs";
2
2
  import "chalk";
3
- import "./app-p0LqnAgS.mjs";
3
+ import "./app-C-NaCZSh.mjs";