zen-code 4.0.0 → 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.
@@ -1,4 +1,4 @@
1
- import { r as P, u as d, s as _ } from "./graphBuilder-ulTm2bmI.mjs";
1
+ import { r as P, u as d, s as _ } from "./graphBuilder-BSX1uOgk.mjs";
2
2
  var v, m, g = 0, O = 0;
3
3
  function s(r, e, n) {
4
4
  var f = 0, t = e || new Array(16);
@@ -1,6 +1,6 @@
1
- import { u as C } from "./id-BHzJB_zk.mjs";
2
- import { B as v, c as x, T as $, m as I } from "./app-QzdcE86p.mjs";
3
- import "./graphBuilder-ulTm2bmI.mjs";
1
+ import { u as C } from "./id-CW5jldpA.mjs";
2
+ import { B as v, c as x, T as $, m as I } from "./app-C-NaCZSh.mjs";
3
+ import "./graphBuilder-BSX1uOgk.mjs";
4
4
  import { createClient as O, createCluster as N } from "redis";
5
5
  const W = [
6
6
  {
@@ -327,7 +327,7 @@ class S {
327
327
  }
328
328
  }
329
329
  async function w() {
330
- const { FileSystemConfigStore: s } = await import("./FileSystemConfigStore-Bog5vylu.mjs"), { FileSystemSkillStore: t } = await import("./FileSystemSkillStore-yvEvcRxB.mjs"), { FileSystemPluginStore: e } = await import("./FileSystemPluginStore-ChortK7z.mjs"), a = new s(), n = new t(), r = new e(), l = new S(a, n, r);
330
+ const { FileSystemConfigStore: s } = await import("./FileSystemConfigStore-ezrLDNGJ.mjs"), { FileSystemSkillStore: t } = await import("./FileSystemSkillStore-yvEvcRxB.mjs"), { FileSystemPluginStore: e } = await import("./FileSystemPluginStore-ChortK7z.mjs"), a = new s(), n = new t(), r = new e(), l = new S(a, n, r);
331
331
  return await l.initialize(), l;
332
332
  }
333
333
  const y = i.enum(["idea", "bug_report", "feature", "refactor"]), k = i.enum(["low", "medium", "high", "critical"]), z = i.enum(["pending", "planned", "archived"]), C = i.enum(["user_input", "ai_suggestion", "conversation_derived"]), P = i.object({
@@ -364,24 +364,25 @@ const d = i.enum([
364
364
  // 待审核(完成,等待人工确认)
365
365
  "feedback"
366
366
  // 待反馈(agent 卡住,需要人工输入)
367
- ]), m = i.enum([
367
+ ]), p = i.enum([
368
368
  "default",
369
369
  "planner",
370
370
  "reviewer",
371
371
  "refactor",
372
372
  "finder",
373
- "debugger"
374
- ]), b = i.enum(["serial", "parallel"]), g = i.lazy(
373
+ "debugger",
374
+ "architect"
375
+ ]), I = i.enum(["serial", "parallel"]), g = i.lazy(
375
376
  () => i.object({
376
377
  // 基本信息
377
378
  id: i.string(),
378
379
  title: i.string().min(1).max(200),
379
380
  description: i.string(),
380
381
  // 执行控制
381
- execution: b.optional(),
382
+ execution: I.optional(),
382
383
  children: i.array(i.lazy(() => g)).optional(),
383
384
  // Agent 分配
384
- agentType: m.optional(),
385
+ agentType: p.optional(),
385
386
  threadId: i.string().optional(),
386
387
  // 元数据
387
388
  estimatedTime: i.string().optional(),
@@ -392,19 +393,19 @@ const d = i.enum([
392
393
  status: d.optional(),
393
394
  startedAt: i.string().datetime().optional(),
394
395
  completedAt: i.string().datetime().optional(),
395
- assignedTo: m.optional(),
396
+ assignedTo: p.optional(),
396
397
  error: i.object({
397
398
  message: i.string(),
398
399
  stack: i.string().optional(),
399
400
  retryCount: i.number().optional()
400
401
  }).optional()
401
402
  })
402
- ), I = i.object({
403
+ ), b = i.object({
403
404
  taskId: i.string(),
404
405
  planId: i.string(),
405
406
  threadId: i.string(),
406
407
  // 关联的 LangGraph thread ID
407
- agentType: m,
408
+ agentType: p,
408
409
  // 改为类型安全的 AgentType
409
410
  status: d,
410
411
  startedAt: i.string().datetime(),
@@ -420,7 +421,7 @@ i.object({
420
421
  activePlanId: i.string().optional(),
421
422
  tasks: i.record(i.string(), g),
422
423
  // 执行历史
423
- history: i.array(I),
424
+ history: i.array(b),
424
425
  // 全局配置
425
426
  config: i.object({
426
427
  maxConcurrentAgents: i.number().min(1).max(10).default(3),
@@ -428,22 +429,14 @@ i.object({
428
429
  autoResume: i.boolean().default(!1)
429
430
  })
430
431
  });
431
- const p = await w(), v = async () => {
432
- await p.initialize();
433
- }, R = async () => await p.getConfig(), j = async (s) => {
434
- await p.updateConfig(s);
435
- }, E = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
436
- __proto__: null,
437
- configStore: p,
438
- getConfig: R,
439
- initDb: v,
440
- updateConfig: j
441
- }, Symbol.toStringTag, { value: "Module" }));
432
+ const m = await w(), A = async () => {
433
+ await m.initialize();
434
+ }, T = async () => await m.getConfig(), B = async (s) => {
435
+ await m.updateConfig(s);
436
+ };
442
437
  export {
443
- g as T,
444
- E as a,
445
- p as c,
446
- R as g,
447
- v as i,
448
- j as u
438
+ m as configStore,
439
+ T as getConfig,
440
+ A as initDb,
441
+ B as updateConfig
449
442
  };
@@ -1,5 +1,5 @@
1
- import { S as n } from "./graphBuilder-ulTm2bmI.mjs";
2
- import { n as b, f as j, k as v, A as R, m as T, l as L, B as A, o as x, d as $, i as C, e as _, M as I, P as E, j as U, b as z, h as F, a as W, q as K, p as Y } from "./graphBuilder-ulTm2bmI.mjs";
1
+ import { S as n } from "./graphBuilder-BSX1uOgk.mjs";
2
+ import { n as b, f as j, k as T, A as v, m as R, l as L, B as A, o as x, d as $, i as C, e as _, M as I, P as E, j as U, b as z, h as F, T as W, q as K, p as Y } from "./graphBuilder-BSX1uOgk.mjs";
3
3
  import r from "node:fs/promises";
4
4
  import { join as p } from "node:path";
5
5
  import { l as d } from "./load-Cjl9cJ0o.mjs";
@@ -189,9 +189,9 @@ class P {
189
189
  export {
190
190
  b as AgentPackage,
191
191
  j as AgentPackageSchema,
192
- v as AgentRepository,
193
- R as AgentSchema,
194
- T as AgentSerializer,
192
+ T as AgentRepository,
193
+ v as AgentSchema,
194
+ R as AgentSerializer,
195
195
  L as AgentValidator,
196
196
  g as AgentsMdMiddleware,
197
197
  A as BaseStorage,
@@ -1,5 +1,5 @@
1
1
  import { l } from "./load-Bh8eo6qE.mjs";
2
- import { S as h } from "./graphBuilder-ulTm2bmI.mjs";
2
+ import { S as h } from "./graphBuilder-BSX1uOgk.mjs";
3
3
  const M = `## Memory System
4
4
 
5
5
  你可以访问一个包含之前任务和经验知识的记忆库。
@@ -1,48 +1,48 @@
1
1
  import { HumanMessage as c } from "langchain";
2
- import { g as m } from "./graphBuilder-ulTm2bmI.mjs";
2
+ import { g as m } from "./graphBuilder-BSX1uOgk.mjs";
3
3
  import "@langchain/langgraph";
4
4
  import "zod";
5
5
  import "@langchain/openai";
6
6
  import "@langchain/anthropic";
7
7
  import "yaml";
8
- import "./ask_agents-bHg8fyUp.mjs";
9
8
  import "micromatch";
10
- import { i as p, g as l } from "./index-BG-c4_r3.mjs";
9
+ import { initDb as d, getConfig as p } from "./index-DFARkGOA.mjs";
11
10
  import "lowdb";
12
11
  import "lowdb/node";
13
- async function g() {
14
- return new Promise((e, n) => {
15
- let r = "";
16
- process.stdin.setEncoding("utf8"), process.stdin.on("data", (t) => {
17
- r += t;
12
+ async function l() {
13
+ return new Promise((t, n) => {
14
+ let e = "";
15
+ process.stdin.setEncoding("utf8"), process.stdin.on("data", (r) => {
16
+ e += r;
18
17
  }), process.stdin.on("end", () => {
19
- e(r);
20
- }), process.stdin.on("error", (t) => {
21
- n(t);
18
+ t(e);
19
+ }), process.stdin.on("error", (r) => {
20
+ n(r);
22
21
  });
23
22
  });
24
23
  }
25
- async function v(e, n = !1) {
26
- await p();
27
- const r = await l();
28
- let t = e || "";
24
+ async function C(t, n = !1) {
25
+ await d();
26
+ const e = await p();
27
+ let r = t || "";
29
28
  if (n)
30
29
  try {
31
- t = (await g()).trim();
30
+ r = (await l()).trim();
32
31
  } catch (o) {
33
32
  throw console.error("❌ 读取 stdin 失败:", o), o;
34
33
  }
35
- t || (console.error("❌ 错误: 未提供输入内容"), console.error(`
34
+ r || (console.error("❌ 错误: 未提供输入内容"), console.error(`
36
35
  用法:`), console.error(' zen-code -p "你的任务描述"'), console.error(' echo "内容" | zen-code'), process.exit(1));
37
36
  try {
38
37
  const o = {
39
- messages: [new c(t)],
40
- main_model: r.main_model,
41
- enable_thinking: r.enable_thinking
42
- }, s = await m.invoke(o, {
38
+ messages: [new c(r)],
39
+ provider_id: e.provider_id,
40
+ model_id: e.model_id,
41
+ enable_thinking: e.enable_thinking
42
+ }, i = await m.invoke(o, {
43
43
  recursionLimit: 500
44
- }), i = s.messages || [], a = i[i.length - 1];
45
- return a && console.log(a.text), s;
44
+ }), s = i.messages || [], a = s[s.length - 1];
45
+ return a && console.log(a.text), i;
46
46
  } catch (o) {
47
47
  throw console.error(`
48
48
  ❌ 执行失败: ${o instanceof Error ? o.message : String(o)}
@@ -50,5 +50,5 @@ async function v(e, n = !1) {
50
50
  }
51
51
  }
52
52
  export {
53
- v as runNonInteractive
53
+ C as runNonInteractive
54
54
  };
@@ -1,4 +1,4 @@
1
- import { a as h, C as u } from "./app-QzdcE86p.mjs";
1
+ import { a as h, C as u } from "./app-C-NaCZSh.mjs";
2
2
  import { createClient as c } from "redis";
3
3
  class n extends h {
4
4
  constructor(s, e = !0, i = 300) {
@@ -1,6 +1,6 @@
1
- import { u as $ } from "./id-BHzJB_zk.mjs";
2
- import { B as g } from "./app-QzdcE86p.mjs";
3
- import "./graphBuilder-ulTm2bmI.mjs";
1
+ import { u as $ } from "./id-CW5jldpA.mjs";
2
+ import { B as g } from "./app-C-NaCZSh.mjs";
3
+ import "./graphBuilder-BSX1uOgk.mjs";
4
4
  import { createClient as T } from "redis";
5
5
  function k(u) {
6
6
  if (u === null || typeof u != "object") return JSON.stringify(u);
@@ -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
+ };