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,47 +0,0 @@
1
- import { Low as a } from "lowdb";
2
- import { JSONFile as r } from "lowdb/node";
3
- import s from "node:os";
4
- import t from "node:path";
5
- import d from "node:fs";
6
- const o = {
7
- config: {
8
- main_model: "claude-sonnet-4-5",
9
- model_provider: "openai"
10
- }
11
- };
12
- class g {
13
- db;
14
- zenConfigDir;
15
- dbPath;
16
- constructor() {
17
- const i = s.homedir();
18
- this.zenConfigDir = t.join(i, ".zen-code");
19
- const e = t.join(this.zenConfigDir, "settings.json"), n = new r(e);
20
- this.dbPath = e, this.db = new a(n, o);
21
- }
22
- async initialize() {
23
- await d.promises.mkdir(this.zenConfigDir, { recursive: !0 }), await this.db.read(), (!this.db.data || !this.db.data.config) && (this.db.data = o, await this.db.write()), this.syncEnvFromConfig();
24
- }
25
- async getConfig() {
26
- return await this.db.read(), this.db.data.config;
27
- }
28
- async updateConfig(i) {
29
- await this.db.read(), Object.assign(this.db.data.config, i), await this.db.write(), this.syncEnvFromConfig();
30
- }
31
- /**
32
- * 将配置同步到环境变量
33
- */
34
- syncEnvFromConfig() {
35
- const i = this.db.data.config;
36
- i.model_provider && (process.env.MODEL_PROVIDER = i.model_provider), i.openai_api_key && (process.env.OPENAI_API_KEY = i.openai_api_key), i.openai_base_url && (process.env.OPENAI_BASE_URL = i.openai_base_url), i.anthropic_api_key && (process.env.ANTHROPIC_API_KEY = i.anthropic_api_key), i.anthropic_base_url && (process.env.ANTHROPIC_BASE_URL = i.anthropic_base_url);
37
- }
38
- /**
39
- * 获取配置目录路径
40
- */
41
- getZenConfigDir() {
42
- return this.zenConfigDir;
43
- }
44
- }
45
- export {
46
- g as FileSystemConfigStore
47
- };
@@ -1,67 +0,0 @@
1
- import { Command as p, Annotation as h } from "@langchain/langgraph";
2
- import { tool as k, HumanMessage as m } from "langchain";
3
- import { z as t } from "zod";
4
- import { c as g } from "./graphBuilder-ulTm2bmI.mjs";
5
- import "@langchain/openai";
6
- const J = t.object({
7
- task_store: t.record(t.string(), t.any()).default({})
8
- });
9
- g().build({
10
- task_store: h({
11
- reducer: (i, a) => ({ ...i, ...a }),
12
- default: () => ({})
13
- })
14
- });
15
- const f = t.object({
16
- task_id: t.string().optional().describe("The task id to ask the subagent, if not provided, will use the tool call id"),
17
- subagent_id: t.string(),
18
- task_description: t.string().describe("Describe the user state and what you want the subagent to do."),
19
- data_transfer: t.any().optional().describe("Data to transfer to the subagent.")
20
- }), N = (i, a) => k(
21
- async (o, d) => {
22
- const n = d.state, s = o.task_id || d.toolCall.id;
23
- let e = {
24
- messages: []
25
- };
26
- s && n?.task_store?.[s] ? e = n?.task_store[s] : (e = JSON.parse(JSON.stringify(n)), e.messages = [], e.task_store = {});
27
- const _ = await i(s, o, n);
28
- e.messages.push(new m({ content: o.task_description })), o.data_transfer && e.messages.push(
29
- new m({
30
- content: `Here is the data to help you complete the task: ${JSON.stringify(
31
- o.data_transfer,
32
- null,
33
- 2
34
- )}`
35
- })
36
- );
37
- const r = await _.invoke(e), u = r.messages.at(-1), l = {
38
- task_store: {
39
- ...n?.task_store || {},
40
- [s]: r
41
- },
42
- messages: [
43
- {
44
- role: "tool",
45
- content: `task_id: ${s}
46
- ---
47
- ` + (u?.text || ""),
48
- tool_call_id: d.toolCall.id
49
- }
50
- ]
51
- };
52
- return a?.pass_through_keys?.forEach((c) => {
53
- c in r && (l[c] = r[c]);
54
- }), new p({
55
- update: l
56
- });
57
- },
58
- {
59
- name: a?.name,
60
- description: a?.description,
61
- schema: f
62
- }
63
- );
64
- export {
65
- J as S,
66
- N as a
67
- };
@@ -1,95 +0,0 @@
1
- import { HumanMessage as r, SystemMessage as u } from "langchain";
2
- import { S as l, a as g } from "./ask_agents-bHg8fyUp.mjs";
3
- const b = `
4
-
5
- ## SubAgents System
6
-
7
- You have access to a subagent system that can delegate specialized tasks to other agents.
8
-
9
- **Available SubAgents:**
10
-
11
- {subagents_list}
12
-
13
- **How to Use SubAgents (Progressive Disclosure):**
14
-
15
- SubAgents follow a **progressive disclosure** pattern - you know they exist (name + description above), but you only delegate tasks when needed:
16
-
17
- 1. **Recognize when to delegate**: Check if the user's task matches a subagent's specialization
18
- 2. **Use the ask_subagents tool**: Call the tool with the subagent's ID and a clear task description
19
- 3. **Provide context**: Use the \`data_transfer\` parameter to pass relevant information
20
- 4. **Get results**: The subagent will process the task and return results
21
-
22
- **When to Use SubAgents:**
23
- - When the user's request requires specialized knowledge or workflows
24
- - When a task is complex and can be broken down into subtasks
25
- - When you need parallel processing or different expertise areas
26
- - When a subagent provides proven patterns for specific domains
27
-
28
- **SubAgent Tool Usage:**
29
-
30
- The \`ask_subagents\` tool is available for delegation:
31
-
32
- - **subagent_id**: The ID of the subagent to delegate to
33
- - **task_description**: Clear description of what needs to be done
34
- - **task_id** (optional): Identifier for tracking, it will automatically be generated after you run a subagent.
35
- - **data_transfer** (optional): Context/data to pass to the subagent
36
-
37
- **Example Workflow:**
38
-
39
- User: "Can you have the research agent look into quantum computing developments?"
40
-
41
- 1. Check available subagents above → See "research" subagent with ID
42
- 2. Use ask_subagents tool with appropriate parameters
43
- 3. Provide clear task description and any necessary context
44
- 4. Process the results from the subagent
45
-
46
- Remember: SubAgents are tools to distribute work and leverage specialized capabilities. When in doubt, check if a subagent exists for the task!
47
- `;
48
- class p {
49
- name = "SubAgentsMiddleware";
50
- stateSchema = l;
51
- contextSchema = void 0;
52
- tools = [];
53
- constructor() {
54
- this.tools.push(
55
- g(
56
- async (e, s, t) => await this.selectSubAgent(e, s, t),
57
- { name: "ask_subagents", description: "ask subagents to help you" }
58
- )
59
- );
60
- }
61
- subAgents = /* @__PURE__ */ new Map();
62
- addSubAgents(e, s) {
63
- this.subAgents.set(e, s);
64
- }
65
- /**
66
- * Format subagents metadata for display in system prompt.
67
- */
68
- formatSubAgentsList() {
69
- if (this.subAgents.size === 0)
70
- return "(No subagents available yet. You can add subagents using the addSubAgents method)";
71
- const e = [];
72
- for (const [s, t] of this.subAgents)
73
- e.push(`- **${s}**: Subagent for specialized tasks`), e.push(` → Use ask_subagents with subagent_id: "${s}"`);
74
- return e.join(`
75
- `);
76
- }
77
- async selectSubAgent(e, s, t) {
78
- return t.messages.push(new r(s.task_description)), this.subAgents.get(s.subagent_id)(e, s, t);
79
- }
80
- async wrapModelCall(e, s) {
81
- const t = this.formatSubAgentsList(), n = b.replace("{subagents_list}", t);
82
- let a;
83
- e.systemPrompt ? a = e.systemPrompt + `
84
-
85
- ` + n : a = n;
86
- const o = new u(a), i = {
87
- ...e,
88
- systemMessage: o
89
- };
90
- return await s(i);
91
- }
92
- }
93
- export {
94
- p as SubAgentsMiddleware
95
- };
@@ -1,113 +0,0 @@
1
- import "micromatch";
2
- import "./index-BG-c4_r3.mjs";
3
- import "lowdb";
4
- import "lowdb/node";
5
- import "yaml";
6
- import { T as a } from "./graphBuilder-ulTm2bmI.mjs";
7
- class r {
8
- store = null;
9
- projectRoot;
10
- constructor(t) {
11
- this.projectRoot = t;
12
- }
13
- /**
14
- * 初始化 Store
15
- */
16
- async initialize() {
17
- this.store || (this.store = new a(this.projectRoot), await this.store.initialize());
18
- }
19
- /**
20
- * 确保 Store 已初始化
21
- */
22
- ensureInitialized() {
23
- if (!this.store)
24
- throw new Error("TasksStore not initialized. Call initialize() first.");
25
- }
26
- /**
27
- * 获取所有任务
28
- */
29
- async getAllTasks() {
30
- return this.ensureInitialized(), await this.store.getAllTasks();
31
- }
32
- /**
33
- * 根据 status 获取任务
34
- */
35
- async getTasksByStatus(t) {
36
- return this.ensureInitialized(), await this.store.getTasksByStatus(t);
37
- }
38
- /**
39
- * 获取单个任务
40
- */
41
- async getTask(t) {
42
- return this.ensureInitialized(), await this.store.getTask(t);
43
- }
44
- /**
45
- * 更新任务状态
46
- */
47
- async updateTaskStatus(t, e) {
48
- return this.ensureInitialized(), await this.store.updateTask(t, { status: e });
49
- }
50
- /**
51
- * 删除任务
52
- */
53
- async deleteTask(t) {
54
- return this.ensureInitialized(), await this.store.deleteTask(t);
55
- }
56
- /**
57
- * 批量添加任务
58
- */
59
- async addTasks(t) {
60
- this.ensureInitialized(), await this.store.addTasks(t);
61
- }
62
- /**
63
- * 获取活跃 Plan ID
64
- */
65
- async getActivePlan() {
66
- return this.ensureInitialized(), await this.store.getActivePlan();
67
- }
68
- /**
69
- * 设置活跃 Plan ID
70
- */
71
- async setActivePlan(t) {
72
- this.ensureInitialized(), await this.store.setActivePlan(t);
73
- }
74
- /**
75
- * 获取任务统计
76
- */
77
- async getTaskStats() {
78
- const t = await this.getAllTasks();
79
- return {
80
- total: t.length,
81
- pickup: t.filter((e) => e.status === "pickup").length,
82
- running: t.filter((e) => e.status === "running").length,
83
- complete: t.filter((e) => e.status === "complete").length,
84
- error: t.filter((e) => e.status === "error").length,
85
- review: t.filter((e) => e.status === "review").length,
86
- feedback: t.filter((e) => e.status === "feedback").length
87
- };
88
- }
89
- /**
90
- * 获取执行历史
91
- */
92
- async getHistory(t) {
93
- return this.ensureInitialized(), await this.store.getHistory(t);
94
- }
95
- /**
96
- * 清空所有任务(慎用)
97
- */
98
- async clearAllTasks() {
99
- this.ensureInitialized(), await this.store.clearAllTasks();
100
- }
101
- }
102
- let i = null;
103
- function k(s) {
104
- if (!i) {
105
- if (!s)
106
- throw new Error("projectRoot is required for first initialization");
107
- i = new r(s);
108
- }
109
- return i;
110
- }
111
- export {
112
- k as getTasksStore
113
- };