zen-code 4.6.2 → 4.7.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/README.md +52 -27
- package/dist/FileSystemSkillStore-Dl5briBv.mjs +108 -0
- package/dist/{app-Cynj004J.mjs → app-CcnStH9S.mjs} +4963 -4152
- package/dist/{checkpoint-1sAx_j1E-DMtqyBT9.mjs → checkpoint-C5AFBYE--BbnaceZj.mjs} +160 -123
- package/dist/{checkpoint-DxiUsHMy-DqfBiLDW.mjs → checkpoint-DxiUsHMy-Cep4XMTK.mjs} +2 -2
- package/dist/{graphBuilder-mpLrx9tk.mjs → graphBuilder-skVEY6RJ.mjs} +12044 -26952
- package/dist/{index-BW3-KScB.mjs → index-BeLj9JYN.mjs} +2 -2
- package/dist/{index-B6kFMamn.mjs → index-D_dnZWV3.mjs} +2 -2
- package/dist/{load-Bh8eo6qE.mjs → load-iYJqYrjn.mjs} +1 -1
- package/dist/{memories-DirsFRdm.mjs → memories-CSOPZKuJ.mjs} +2 -2
- package/dist/nonInteractive.mjs +26 -22
- package/dist/{queue-Cu_nO_wt-DVTcONlE.mjs → queue-DySatFkr-DjaRbjhM.mjs} +1 -1
- package/dist/{shallow-BQy_8shO.mjs → shallow-CqCGqQDo.mjs} +2 -2
- package/dist/shallow-checkpoint-BEhTdp7z-CquyGG0C.mjs +383 -0
- package/dist/{sqlite-adapter-BKOLSdoL-5XOA6_0i.mjs → sqlite-adapter-oBA95xba-BrBWorSV.mjs} +22 -11
- package/dist/subTasks-DEZYN-F3.mjs +18 -0
- package/dist/zen-code.mjs +1 -1
- package/package.json +4 -4
- package/dist/FileSystemSkillStore-yvEvcRxB.mjs +0 -94
- package/dist/index-FHDPQ2Qk.mjs +0 -211
- package/dist/load-Cjl9cJ0o.mjs +0 -105
- package/dist/subTasks-Bt97OwvY.mjs +0 -209
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import n from "node:fs/promises";
|
|
2
|
-
import e from "node:path";
|
|
3
|
-
import m from "node:os";
|
|
4
|
-
import o from "yaml";
|
|
5
|
-
class f {
|
|
6
|
-
skillsDir;
|
|
7
|
-
projectSkillsDir;
|
|
8
|
-
constructor() {
|
|
9
|
-
const t = m.homedir();
|
|
10
|
-
this.skillsDir = e.join(t, ".deepagents", "code", "skills"), this.projectSkillsDir = e.join(process.cwd(), ".claude", "skills");
|
|
11
|
-
}
|
|
12
|
-
async listSkills() {
|
|
13
|
-
const t = [], i = await this.listSkillsInDir(this.skillsDir);
|
|
14
|
-
t.push(...i);
|
|
15
|
-
const s = await this.listSkillsInDir(this.projectSkillsDir);
|
|
16
|
-
return t.push(...s), t;
|
|
17
|
-
}
|
|
18
|
-
async listSkillsInDir(t) {
|
|
19
|
-
try {
|
|
20
|
-
const i = await n.readdir(t, { withFileTypes: !0 }), s = [];
|
|
21
|
-
for (const r of i)
|
|
22
|
-
if (r.isDirectory()) {
|
|
23
|
-
const l = e.join(t, r.name, "SKILL.md");
|
|
24
|
-
try {
|
|
25
|
-
const a = await n.readFile(l, "utf-8"), c = this.parseFrontmatter(a);
|
|
26
|
-
s.push({
|
|
27
|
-
name: r.name,
|
|
28
|
-
description: c.description || "",
|
|
29
|
-
path: l
|
|
30
|
-
});
|
|
31
|
-
} catch {
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return s;
|
|
35
|
-
} catch {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async getSkill(t) {
|
|
40
|
-
const i = e.join(this.projectSkillsDir, t, "SKILL.md");
|
|
41
|
-
try {
|
|
42
|
-
const r = await n.readFile(i, "utf-8");
|
|
43
|
-
return this.parseSkillContent(r);
|
|
44
|
-
} catch {
|
|
45
|
-
}
|
|
46
|
-
const s = e.join(this.skillsDir, t, "SKILL.md");
|
|
47
|
-
try {
|
|
48
|
-
const r = await n.readFile(s, "utf-8");
|
|
49
|
-
return this.parseSkillContent(r);
|
|
50
|
-
} catch {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
async saveSkill(t, i) {
|
|
55
|
-
const s = e.join(this.skillsDir, t);
|
|
56
|
-
await n.mkdir(s, { recursive: !0 });
|
|
57
|
-
const r = this.formatSkillContent(i);
|
|
58
|
-
await n.writeFile(e.join(s, "SKILL.md"), r, "utf-8");
|
|
59
|
-
}
|
|
60
|
-
async deleteSkill(t) {
|
|
61
|
-
const i = e.join(this.skillsDir, t);
|
|
62
|
-
await n.rm(i, { recursive: !0, force: !0 });
|
|
63
|
-
}
|
|
64
|
-
async syncFromRemote(t) {
|
|
65
|
-
const i = await t.listRemoteSkills();
|
|
66
|
-
for (const s of i) {
|
|
67
|
-
const r = await t.fetchSkill(s.name);
|
|
68
|
-
r && await this.saveSkill(s.name, r);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
parseFrontmatter(t) {
|
|
72
|
-
const i = t.match(/^---\n(.+?)\n---/s);
|
|
73
|
-
if (!i) return {};
|
|
74
|
-
try {
|
|
75
|
-
return o.parse(i[1]);
|
|
76
|
-
} catch {
|
|
77
|
-
return {};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
parseSkillContent(t) {
|
|
81
|
-
const i = this.parseFrontmatter(t), s = t.replace(/^---\n.+?\n---\n*/s, "");
|
|
82
|
-
return { frontmatter: i, markdown: s };
|
|
83
|
-
}
|
|
84
|
-
formatSkillContent(t) {
|
|
85
|
-
return `---
|
|
86
|
-
${o.stringify(t.frontmatter).trim()}
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
${t.markdown}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export {
|
|
93
|
-
f as FileSystemSkillStore
|
|
94
|
-
};
|
package/dist/index-FHDPQ2Qk.mjs
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { l as n } from "./graphBuilder-mpLrx9tk.mjs";
|
|
2
|
-
import { D as b, u as j, y as v, t as R, B as T, z as L, E as x, G as A, r as $, w as _, s as C, M as I, P as E, x as z, q as U, v as F, p as W, H as K } from "./graphBuilder-mpLrx9tk.mjs";
|
|
3
|
-
import r from "node:fs/promises";
|
|
4
|
-
import { join as m } from "node:path";
|
|
5
|
-
import { l as d } from "./load-Cjl9cJ0o.mjs";
|
|
6
|
-
const k = `
|
|
7
|
-
|
|
8
|
-
## Project Documentation
|
|
9
|
-
|
|
10
|
-
{docs_content}`;
|
|
11
|
-
class g {
|
|
12
|
-
name = "AgentsMdMiddleware";
|
|
13
|
-
stateSchema = void 0;
|
|
14
|
-
contextSchema = void 0;
|
|
15
|
-
tools = [];
|
|
16
|
-
projectRoot;
|
|
17
|
-
systemPromptTemplate;
|
|
18
|
-
/**
|
|
19
|
-
* Initialize the documentation middleware.
|
|
20
|
-
*
|
|
21
|
-
* @param projectRoot - Path to the project root directory (defaults to process.cwd())
|
|
22
|
-
*/
|
|
23
|
-
constructor(s = {}) {
|
|
24
|
-
this.projectRoot = s.projectRoot || process.cwd(), this.systemPromptTemplate = k;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Find and read the project documentation file.
|
|
28
|
-
* Priority: CLAUDE.md > AGENTS.md
|
|
29
|
-
*
|
|
30
|
-
* @returns The content of the first found documentation file, or null if none exist
|
|
31
|
-
*/
|
|
32
|
-
async findDocumentationFile() {
|
|
33
|
-
const s = ["CLAUDE.md", "AGENTS.md"];
|
|
34
|
-
for (const i of s) {
|
|
35
|
-
const l = m(this.projectRoot, i);
|
|
36
|
-
try {
|
|
37
|
-
return await r.access(l), { content: await r.readFile(l, "utf-8"), filename: i };
|
|
38
|
-
} catch {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Inject project documentation into the system prompt.
|
|
46
|
-
*
|
|
47
|
-
* This runs on every model call to ensure documentation info is always available.
|
|
48
|
-
*
|
|
49
|
-
* @param request - The model request being processed
|
|
50
|
-
* @param handler - The handler function to call with the modified request
|
|
51
|
-
* @returns The model response from the handler
|
|
52
|
-
*/
|
|
53
|
-
async wrapModelCall(s, i) {
|
|
54
|
-
const l = await this.findDocumentationFile();
|
|
55
|
-
if (!l)
|
|
56
|
-
return await i(s);
|
|
57
|
-
const t = this.systemPromptTemplate.replace("{docs_content}", l.content);
|
|
58
|
-
let e;
|
|
59
|
-
s.systemPrompt ? e = s.systemPrompt + `
|
|
60
|
-
|
|
61
|
-
` + t : e = t;
|
|
62
|
-
const a = new n(e), o = {
|
|
63
|
-
...s,
|
|
64
|
-
systemMessage: a
|
|
65
|
-
};
|
|
66
|
-
return await i(o);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const u = `
|
|
70
|
-
|
|
71
|
-
## Skills System
|
|
72
|
-
|
|
73
|
-
You have access to a skills library that provides specialized capabilities and domain knowledge.
|
|
74
|
-
|
|
75
|
-
{skills_locations}
|
|
76
|
-
|
|
77
|
-
**Available Skills:**
|
|
78
|
-
|
|
79
|
-
{skills_list}
|
|
80
|
-
|
|
81
|
-
**How to Use Skills (Progressive Disclosure):**
|
|
82
|
-
|
|
83
|
-
Skills follow a **progressive disclosure** pattern - you know they exist (name + description above), but you only read the full instructions when needed:
|
|
84
|
-
|
|
85
|
-
1. **Recognize when a skill applies**: Check if the user's task matches any skill's description
|
|
86
|
-
2. **Read the skill's full instructions**: The skill list above shows the exact path to use with read_file
|
|
87
|
-
3. **Follow the skill's instructions**: SKILL.md contains step-by-step workflows, best practices, and examples
|
|
88
|
-
4. **Access supporting files**: Skills may include Python scripts, configs, or reference docs - use absolute paths
|
|
89
|
-
|
|
90
|
-
**When to Use Skills:**
|
|
91
|
-
- When the user's request matches a skill's domain (e.g., "research X" → web-research skill)
|
|
92
|
-
- When you need specialized knowledge or structured workflows
|
|
93
|
-
- When a skill provides proven patterns for complex tasks
|
|
94
|
-
|
|
95
|
-
**Skills are Self-Documenting:**
|
|
96
|
-
- Each SKILL.md tells you exactly what the skill does and how to use it
|
|
97
|
-
- The skill list above shows the full path for each skill's SKILL.md file
|
|
98
|
-
|
|
99
|
-
**Executing Skill Scripts:**
|
|
100
|
-
Skills may contain Python scripts or other executable files. Always use absolute paths from the skill list.
|
|
101
|
-
|
|
102
|
-
**Example Workflow:**
|
|
103
|
-
|
|
104
|
-
User: "Can you research the latest developments in quantum computing?"
|
|
105
|
-
|
|
106
|
-
1. Check available skills above → See "web-research" skill with its full path
|
|
107
|
-
2. Read the skill using the path shown in the list
|
|
108
|
-
3. Follow the skill's research workflow (search → organize → synthesize)
|
|
109
|
-
4. Use any helper scripts with absolute paths
|
|
110
|
-
|
|
111
|
-
Remember: Skills are tools to make you more capable and consistent. When in doubt, check if a skill exists for the task!
|
|
112
|
-
`;
|
|
113
|
-
class P {
|
|
114
|
-
name = "SkillsMiddleware";
|
|
115
|
-
// No context schema needed
|
|
116
|
-
stateSchema = void 0;
|
|
117
|
-
// No context schema needed
|
|
118
|
-
contextSchema = void 0;
|
|
119
|
-
// No additional tools
|
|
120
|
-
tools = [];
|
|
121
|
-
skillsDir;
|
|
122
|
-
assistantId;
|
|
123
|
-
projectSkillsDir;
|
|
124
|
-
userSkillsDisplay;
|
|
125
|
-
systemPromptTemplate;
|
|
126
|
-
/**
|
|
127
|
-
* Initialize the skills middleware.
|
|
128
|
-
*
|
|
129
|
-
* @param skillsDir - Path to the user-level skills directory (per-agent)
|
|
130
|
-
* @param assistantId - The agent identifier for path references in prompts
|
|
131
|
-
* @param projectSkillsDir - Optional path to project-level skills directory
|
|
132
|
-
*/
|
|
133
|
-
constructor(s = {}) {
|
|
134
|
-
this.skillsDir = s.skillsDir, this.assistantId = s.assistantId, this.projectSkillsDir = s.projectSkillsDir || "./.claude/skills", this.skillsDir && !this.assistantId && console.warn("user skills directory is provided, but assistant id is not provided"), this.assistantId && (this.userSkillsDisplay = `~/.claude/${this.assistantId}/skills`), this.systemPromptTemplate = u;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Format skills locations for display in system prompt.
|
|
138
|
-
*/
|
|
139
|
-
formatSkillsLocations() {
|
|
140
|
-
const s = [];
|
|
141
|
-
return this.userSkillsDisplay && s.push(`**User Skills**: \`${this.userSkillsDisplay}\``), this.projectSkillsDir && s.push(`**Project Skills**: \`${this.projectSkillsDir}\` (overrides user skills)`), s.join(`
|
|
142
|
-
`);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Format skills metadata for display in system prompt.
|
|
146
|
-
*/
|
|
147
|
-
formatSkillsList(s) {
|
|
148
|
-
if (!s.length) {
|
|
149
|
-
const e = [`${this.userSkillsDisplay}/`];
|
|
150
|
-
return this.projectSkillsDir && e.push(`${this.projectSkillsDir}/`), `(No skills available yet. You can create skills in ${e.join(" or ")})`;
|
|
151
|
-
}
|
|
152
|
-
const i = s.filter((e) => e.source === "user"), l = s.filter((e) => e.source === "project"), t = [];
|
|
153
|
-
if (i.length) {
|
|
154
|
-
t.push("**User Skills:**");
|
|
155
|
-
for (const e of i)
|
|
156
|
-
t.push(`- **${e.name}**: ${e.description}`), t.push(` → Read \`${e.path}\` for full instructions`);
|
|
157
|
-
t.push("");
|
|
158
|
-
}
|
|
159
|
-
if (l.length) {
|
|
160
|
-
t.push("**Project Skills:**");
|
|
161
|
-
for (const e of l)
|
|
162
|
-
t.push(`- **${e.name}**: ${e.description}`), t.push(` → Read \`${e.path}\` for full instructions`);
|
|
163
|
-
}
|
|
164
|
-
return t.join(`
|
|
165
|
-
`);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Inject skills documentation into the system prompt.
|
|
169
|
-
*
|
|
170
|
-
* This runs on every model call to ensure skills info is always available.
|
|
171
|
-
*
|
|
172
|
-
* @param request - The model request being processed
|
|
173
|
-
* @param handler - The handler function to call with the modified request
|
|
174
|
-
* @returns The model response from the handler
|
|
175
|
-
*/
|
|
176
|
-
async wrapModelCall(s, i) {
|
|
177
|
-
const l = d(this.skillsDir, this.projectSkillsDir), t = this.formatSkillsLocations(), e = this.formatSkillsList(l), a = this.systemPromptTemplate.replace("{skills_locations}", t).replace("{skills_list}", e);
|
|
178
|
-
let o;
|
|
179
|
-
s.systemPrompt ? o = s.systemPrompt + `
|
|
180
|
-
|
|
181
|
-
` + a : o = a;
|
|
182
|
-
const h = new n(o), p = {
|
|
183
|
-
...s,
|
|
184
|
-
systemMessage: h
|
|
185
|
-
};
|
|
186
|
-
return await i(p);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
export {
|
|
190
|
-
b as AgentPackage,
|
|
191
|
-
j as AgentPackageSchema,
|
|
192
|
-
v as AgentRepository,
|
|
193
|
-
R as AgentSchema,
|
|
194
|
-
T as AgentSerializer,
|
|
195
|
-
L as AgentValidator,
|
|
196
|
-
g as AgentsMdMiddleware,
|
|
197
|
-
x as BaseStorage,
|
|
198
|
-
A as MemoryStorage,
|
|
199
|
-
$ as MiddlewareCustomParamsSchema,
|
|
200
|
-
_ as MiddlewareRegistry,
|
|
201
|
-
C as MiddlewareSchema,
|
|
202
|
-
I as ModelSchema,
|
|
203
|
-
E as PromptSchema,
|
|
204
|
-
P as SkillsMiddleware,
|
|
205
|
-
z as StandardAgent,
|
|
206
|
-
U as ToolCustomParamsSchema,
|
|
207
|
-
F as ToolRegistry,
|
|
208
|
-
W as ToolSchema,
|
|
209
|
-
K as anthropicPromptCachingMiddleware,
|
|
210
|
-
d as listSkills
|
|
211
|
-
};
|
package/dist/load-Cjl9cJ0o.mjs
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { existsSync as S, readdirSync as _, lstatSync as L, statSync as v, readFileSync as I } from "node:fs";
|
|
2
|
-
import { resolve as m, join as d } from "node:path";
|
|
3
|
-
import { parse as b } from "yaml";
|
|
4
|
-
const A = 10 * 1024 * 1024, E = 64, f = 1024;
|
|
5
|
-
function g(t, o) {
|
|
6
|
-
try {
|
|
7
|
-
const n = m(t), s = m(o), e = n.substring(s.length);
|
|
8
|
-
return n === s || e.startsWith("/") || e === "";
|
|
9
|
-
} catch {
|
|
10
|
-
return !1;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function N(t, o) {
|
|
14
|
-
return t ? t.length > E ? [!1, "name exceeds 64 characters"] : /^[a-z0-9]+(-[a-z0-9]+)*$/.test(t) ? t !== o ? [!1, `name '${t}' must match directory name '${o}'`] : [!0, ""] : [!1, "name must be lowercase alphanumeric with single hyphens only"] : [!1, "name is required"];
|
|
15
|
-
}
|
|
16
|
-
function x(t, o) {
|
|
17
|
-
try {
|
|
18
|
-
const n = v(t);
|
|
19
|
-
if (n.size > A)
|
|
20
|
-
return console.warn(`Skipping ${t}: file too large (${n.size} bytes)`), null;
|
|
21
|
-
const s = I(t, "utf-8"), e = /^---\s*\n(.*?)\n---\s*\n/s, c = s.match(e);
|
|
22
|
-
if (!c)
|
|
23
|
-
return console.warn(`Skipping ${t}: no valid YAML frontmatter found`), null;
|
|
24
|
-
const a = c[1];
|
|
25
|
-
let r;
|
|
26
|
-
try {
|
|
27
|
-
r = b(a);
|
|
28
|
-
} catch (w) {
|
|
29
|
-
return console.warn(`Invalid YAML in ${t}: ${w}`), null;
|
|
30
|
-
}
|
|
31
|
-
if (typeof r != "object" || r === null)
|
|
32
|
-
return console.warn(`Skipping ${t}: frontmatter is not a mapping`), null;
|
|
33
|
-
const i = r.name, l = r.description;
|
|
34
|
-
if (!i || !l)
|
|
35
|
-
return console.warn(`Skipping ${t}: missing required 'name' or 'description'`), null;
|
|
36
|
-
const p = t.split("/").slice(-2)[0], [$, h] = N(String(i), p);
|
|
37
|
-
$ || console.warn(`Skill '${i}' in ${t} does not follow Agent Skills spec: ${h}. Consider renaming to be spec-compliant.`);
|
|
38
|
-
let u = String(l);
|
|
39
|
-
return u.length > f && (console.warn(`Description exceeds ${f} chars in ${t}, truncating`), u = u.substring(0, f)), {
|
|
40
|
-
name: String(i),
|
|
41
|
-
description: u,
|
|
42
|
-
path: t,
|
|
43
|
-
source: o,
|
|
44
|
-
license: r.license,
|
|
45
|
-
compatibility: r.compatibility,
|
|
46
|
-
metadata: r.metadata,
|
|
47
|
-
allowed_tools: r["allowed-tools"]
|
|
48
|
-
};
|
|
49
|
-
} catch (n) {
|
|
50
|
-
return console.warn(`Error reading ${t}: ${n.message}`), null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function y(t, o) {
|
|
54
|
-
if (!S(t))
|
|
55
|
-
return [];
|
|
56
|
-
let n;
|
|
57
|
-
try {
|
|
58
|
-
n = m(t);
|
|
59
|
-
} catch {
|
|
60
|
-
return [];
|
|
61
|
-
}
|
|
62
|
-
const s = [];
|
|
63
|
-
let e;
|
|
64
|
-
try {
|
|
65
|
-
e = _(t);
|
|
66
|
-
} catch {
|
|
67
|
-
return [];
|
|
68
|
-
}
|
|
69
|
-
for (const c of e) {
|
|
70
|
-
const a = d(t, c);
|
|
71
|
-
if (!g(a, n))
|
|
72
|
-
continue;
|
|
73
|
-
let r;
|
|
74
|
-
try {
|
|
75
|
-
r = L(a);
|
|
76
|
-
} catch {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (!r.isDirectory())
|
|
80
|
-
continue;
|
|
81
|
-
const i = d(a, "SKILL.md");
|
|
82
|
-
if (!S(i) || !g(i, n))
|
|
83
|
-
continue;
|
|
84
|
-
const l = x(i, o);
|
|
85
|
-
l && s.push(l);
|
|
86
|
-
}
|
|
87
|
-
return s;
|
|
88
|
-
}
|
|
89
|
-
function k(t, o) {
|
|
90
|
-
const n = /* @__PURE__ */ new Map();
|
|
91
|
-
if (t) {
|
|
92
|
-
const s = y(t, "user");
|
|
93
|
-
for (const e of s)
|
|
94
|
-
n.set(e.name, e);
|
|
95
|
-
}
|
|
96
|
-
if (o) {
|
|
97
|
-
const s = y(o, "project");
|
|
98
|
-
for (const e of s)
|
|
99
|
-
n.set(e.name, e);
|
|
100
|
-
}
|
|
101
|
-
return Array.from(n.values());
|
|
102
|
-
}
|
|
103
|
-
export {
|
|
104
|
-
k as l
|
|
105
|
-
};
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { tool as g, HumanMessage as h, SystemMessage as p } from "langchain";
|
|
2
|
-
import { Command as m, Annotation as f } from "@langchain/langgraph";
|
|
3
|
-
import { z as n } from "zod";
|
|
4
|
-
import { m as b, n as y, o as w } from "./graphBuilder-mpLrx9tk.mjs";
|
|
5
|
-
import "@langchain/openai";
|
|
6
|
-
n.object({
|
|
7
|
-
task_store: n.record(n.string(), n.any()).default({})
|
|
8
|
-
});
|
|
9
|
-
b().build({
|
|
10
|
-
task_store: f({
|
|
11
|
-
reducer: (r, t) => ({ ...r, ...t }),
|
|
12
|
-
default: () => ({})
|
|
13
|
-
})
|
|
14
|
-
});
|
|
15
|
-
const k = n.object({
|
|
16
|
-
task_id: n.string().optional().describe("The task id to ask the subagent, if not provided, will use the tool call id"),
|
|
17
|
-
subagent_id: n.string().describe(
|
|
18
|
-
'REQUIRED. The specific ID of the subagent to invoke (e.g., "agents/default", "agents/manager"). Must match exactly one of the available subagents listed in the system prompt.'
|
|
19
|
-
),
|
|
20
|
-
subagent_type: n.string().describe(
|
|
21
|
-
'REQUIRED. The type/category of subagent (e.g., "general-purpose", "statusline-setup"). Must be one of the available agent types listed in the tool description.'
|
|
22
|
-
),
|
|
23
|
-
task_description: n.string().describe("Describe the user state and what you want the subagent to do."),
|
|
24
|
-
data_transfer: n.any().optional().describe("Data to transfer to the subagent.")
|
|
25
|
-
}), _ = (r, t) => g(
|
|
26
|
-
async (e, s) => {
|
|
27
|
-
const a = s.state, o = e.task_id || s.toolCall.id;
|
|
28
|
-
let i = {
|
|
29
|
-
messages: []
|
|
30
|
-
};
|
|
31
|
-
o && a?.task_store?.[o] ? i = a?.task_store[o] : (i = JSON.parse(JSON.stringify(a)), i.messages = [], i.task_store = {});
|
|
32
|
-
const l = await r(o, e, a);
|
|
33
|
-
i.messages.push(new h({ content: e.task_description })), e.data_transfer && i.messages.push(
|
|
34
|
-
new h({
|
|
35
|
-
content: `Here is the data to help you complete the task: ${JSON.stringify(
|
|
36
|
-
e.data_transfer,
|
|
37
|
-
null,
|
|
38
|
-
2
|
|
39
|
-
)}`
|
|
40
|
-
})
|
|
41
|
-
);
|
|
42
|
-
const u = await l.invoke(i), c = u.messages.at(-1), d = {
|
|
43
|
-
task_store: {
|
|
44
|
-
...a?.task_store || {},
|
|
45
|
-
[o]: u
|
|
46
|
-
},
|
|
47
|
-
messages: [
|
|
48
|
-
{
|
|
49
|
-
role: "tool",
|
|
50
|
-
content: `task_id: ${o}
|
|
51
|
-
---
|
|
52
|
-
` + (c?.text || ""),
|
|
53
|
-
tool_call_id: s.toolCall.id
|
|
54
|
-
}
|
|
55
|
-
]
|
|
56
|
-
};
|
|
57
|
-
return new m({
|
|
58
|
-
update: d
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "task",
|
|
63
|
-
description: `Launch a new agent to handle complex, multi-step tasks autonomously.
|
|
64
|
-
|
|
65
|
-
Available agent types and the tools they have access to:
|
|
66
|
-
- 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: *)
|
|
67
|
-
- statusline-setup: Use this agent to configure the user's Claude Code status line setting. (Tools: Read, Edit)
|
|
68
|
-
- output-style-setup: Use this agent to create a Claude Code output style. (Tools: Read, Write, Edit, Glob, LS, Grep)
|
|
69
|
-
|
|
70
|
-
**IMPORTANT: Both subagent_id AND subagent_type are REQUIRED parameters. You must provide BOTH.**
|
|
71
|
-
|
|
72
|
-
- subagent_id: The specific ID of the subagent (e.g., "agents/default", "agents/manager")
|
|
73
|
-
- subagent_type: The type category of the subagent (e.g., "general-purpose", "statusline-setup")
|
|
74
|
-
|
|
75
|
-
When NOT to use the Agent tool:
|
|
76
|
-
- 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
|
|
77
|
-
- If you are searching for a specific class definition like "class Foo", use the Glob tool instead, to find the match more quickly
|
|
78
|
-
- 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
|
|
79
|
-
- Other tasks that are not related to the agent descriptions above
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
Usage notes:
|
|
83
|
-
1. Launch multiple agents concurrently whenever possible, to maximize performance; to do that, use a single message with multiple tool uses
|
|
84
|
-
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.
|
|
85
|
-
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.
|
|
86
|
-
4. The agent's outputs should generally be trusted
|
|
87
|
-
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
|
|
88
|
-
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.
|
|
89
|
-
|
|
90
|
-
Example usage:
|
|
91
|
-
|
|
92
|
-
<example_agent_descriptions>
|
|
93
|
-
"code-reviewer": use this agent after you are done writing a significant piece of code
|
|
94
|
-
"greeting-responder": use this agent when to respond to user greetings with a friendly joke
|
|
95
|
-
</example_agent_description>
|
|
96
|
-
|
|
97
|
-
<example>
|
|
98
|
-
user: "Please write a function that checks if a number is prime"
|
|
99
|
-
assistant: Sure let me write a function that checks if a number is prime
|
|
100
|
-
assistant: First let me use the Write tool to write a function that checks if a number is prime
|
|
101
|
-
assistant: I'm going to use the Write tool to write the following code:
|
|
102
|
-
<code>
|
|
103
|
-
function isPrime(n) {
|
|
104
|
-
if (n <= 1) return false
|
|
105
|
-
for (let i = 2; i * i <= n; i++) {
|
|
106
|
-
if (n % i === 0) return false
|
|
107
|
-
}
|
|
108
|
-
return true
|
|
109
|
-
}
|
|
110
|
-
</code>
|
|
111
|
-
<commentary>
|
|
112
|
-
Since a signficant piece of code was written and the task was completed, now use the code-reviewer agent to review the code
|
|
113
|
-
</commentary>
|
|
114
|
-
assistant: Now let me use the code-reviewer agent to review the code
|
|
115
|
-
assistant: Uses the Task tool to launch the with the code-reviewer agent
|
|
116
|
-
</example>
|
|
117
|
-
|
|
118
|
-
<example>
|
|
119
|
-
user: "Hello"
|
|
120
|
-
<commentary>
|
|
121
|
-
Since the user is greeting, use the greeting-responder agent to respond with a friendly joke
|
|
122
|
-
</commentary>
|
|
123
|
-
assistant: "I'm going to use the Task tool to launch the with the greeting-responder agent"
|
|
124
|
-
</example>
|
|
125
|
-
`,
|
|
126
|
-
schema: k
|
|
127
|
-
}
|
|
128
|
-
), v = `
|
|
129
|
-
|
|
130
|
-
## SubAgents System
|
|
131
|
-
|
|
132
|
-
You have access to a subagent system that can delegate specialized tasks to other agents.
|
|
133
|
-
|
|
134
|
-
**Available SubAgents:**
|
|
135
|
-
|
|
136
|
-
{subagents_list}
|
|
137
|
-
|
|
138
|
-
**How to Use SubAgents (Progressive Disclosure):**
|
|
139
|
-
|
|
140
|
-
SubAgents follow a **progressive disclosure** pattern - you know they exist (name + description above), but you only delegate tasks when needed:
|
|
141
|
-
|
|
142
|
-
1. **Recognize when to delegate**: Check if the user's task matches a subagent's specialization
|
|
143
|
-
2. **Use the task tool**: Call the tool with the subagent's ID and a clear task description
|
|
144
|
-
3. **Provide context**: Use the \`data_transfer\` parameter to pass relevant information
|
|
145
|
-
4. **Get results**: The subagent will process the task and return results
|
|
146
|
-
|
|
147
|
-
**When to Use SubAgents:**
|
|
148
|
-
- When the user's request requires specialized knowledge or workflows
|
|
149
|
-
- When a task is complex and can be broken down into subtasks
|
|
150
|
-
- When you need parallel processing or different expertise areas
|
|
151
|
-
- When a subagent provides proven patterns for specific domains
|
|
152
|
-
|
|
153
|
-
**SubAgent Tool Usage:**
|
|
154
|
-
|
|
155
|
-
The \`task\` tool is available for delegation:
|
|
156
|
-
|
|
157
|
-
- **subagent_id**: The ID of the subagent to delegate to
|
|
158
|
-
- **task_description**: Clear description of what needs to be done
|
|
159
|
-
- **task_id** (optional): Identifier for tracking, it will automatically be generated after you run a subagent.
|
|
160
|
-
- **data_transfer** (optional): Context/data to pass to the subagent
|
|
161
|
-
|
|
162
|
-
**Example Workflow:**
|
|
163
|
-
|
|
164
|
-
User: "Can you have the research agent look into quantum computing developments?"
|
|
165
|
-
|
|
166
|
-
1. Check available subagents above → See "research" subagent with ID
|
|
167
|
-
2. Use task tool with appropriate parameters
|
|
168
|
-
3. Provide clear task description and any necessary context
|
|
169
|
-
4. Process the results from the subagent
|
|
170
|
-
|
|
171
|
-
Remember: SubAgents are tools to distribute work and leverage specialized capabilities. When in doubt, check if a subagent exists for the task!
|
|
172
|
-
`;
|
|
173
|
-
class U {
|
|
174
|
-
name = "SubAgentsMiddleware";
|
|
175
|
-
stateSchema = y;
|
|
176
|
-
// contextSchema = undefined;
|
|
177
|
-
tools = [];
|
|
178
|
-
agentList = Promise.resolve("");
|
|
179
|
-
constructor(t) {
|
|
180
|
-
this.agentList = this.formatSubAgentsList(t), this.tools.push(
|
|
181
|
-
_(async (e, s, a) => await w(s.subagent_id, t, a, {}, { parent_id: e }))
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Format subagents metadata for display in system prompt.
|
|
186
|
-
*/
|
|
187
|
-
async formatSubAgentsList(t) {
|
|
188
|
-
const e = [];
|
|
189
|
-
for (const s of await t.listAgents())
|
|
190
|
-
e.push(`- **${s.id}**: ${s.description}`), e.push(` → Use task with subagent_id: "${s.id}"`);
|
|
191
|
-
return e.join(`
|
|
192
|
-
`);
|
|
193
|
-
}
|
|
194
|
-
async wrapModelCall(t, e) {
|
|
195
|
-
const s = await this.agentList, a = v.replace("{subagents_list}", s);
|
|
196
|
-
let o;
|
|
197
|
-
t.systemPrompt ? o = t.systemPrompt + `
|
|
198
|
-
|
|
199
|
-
` + a : o = a;
|
|
200
|
-
const i = new p(o), l = {
|
|
201
|
-
...t,
|
|
202
|
-
systemMessage: i
|
|
203
|
-
};
|
|
204
|
-
return await e(l);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
export {
|
|
208
|
-
U as SubAgentsMiddleware
|
|
209
|
-
};
|