@cuylabs/agent-code 0.6.0 → 0.8.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.
@@ -756,6 +756,58 @@ IMPORTANT:
756
756
  }
757
757
  });
758
758
 
759
+ // src/tools/plan.ts
760
+ import { z as z7 } from "zod";
761
+ import { Tool as Tool7 } from "@cuylabs/agent-core";
762
+ var planEntrySchema = z7.object({
763
+ id: z7.number().describe("Unique sequential identifier (1, 2, 3\u2026)"),
764
+ title: z7.string().max(120).describe("Concise action-oriented description of the task"),
765
+ status: z7.enum(["pending", "in-progress", "done"]).describe("Current status of this task")
766
+ });
767
+ var planParameters = z7.object({
768
+ entries: z7.array(planEntrySchema).min(1).describe("The complete plan \u2014 all tasks with current statuses")
769
+ });
770
+ var planTool = Tool7.define("plan", {
771
+ description: `Create or update a structured task plan for tracking multi-step work.
772
+
773
+ When to use:
774
+ - Before starting complex tasks that involve multiple files or steps
775
+ - After completing a step, to mark it done and show progress
776
+ - When the approach changes and tasks need to be revised
777
+
778
+ Rules:
779
+ - Send the COMPLETE plan every time (all entries, not just changes)
780
+ - Keep titles short and action-oriented (max 120 chars)
781
+ - Only ONE entry should be "in-progress" at a time
782
+ - Use sequential IDs starting from 1
783
+ - Mark tasks "done" as you complete them`,
784
+ parameters: planParameters,
785
+ replayPolicy: {
786
+ sideEffectLevel: "none",
787
+ reason: "Plan updates are informational \u2014 no file or network effects."
788
+ },
789
+ async execute(params) {
790
+ const { entries } = params;
791
+ const pending = entries.filter((e) => e.status === "pending").length;
792
+ const active = entries.filter((e) => e.status === "in-progress").length;
793
+ const done = entries.filter((e) => e.status === "done").length;
794
+ const lines = [];
795
+ for (const entry of entries) {
796
+ const marker = entry.status === "done" ? "\u2713" : entry.status === "in-progress" ? "\u2192" : "\u25CB";
797
+ lines.push(`${marker} ${entry.id}. ${entry.title}`);
798
+ }
799
+ return {
800
+ title: `Plan: ${done}/${entries.length} done`,
801
+ output: [
802
+ lines.join("\n"),
803
+ "",
804
+ `${done} done \xB7 ${active} active \xB7 ${pending} pending`
805
+ ].join("\n"),
806
+ metadata: { entries, done, active, pending, total: entries.length }
807
+ };
808
+ }
809
+ });
810
+
759
811
  // src/tools/defaults.ts
760
812
  var defaultCodingTools = [
761
813
  bashTool,
@@ -763,18 +815,19 @@ var defaultCodingTools = [
763
815
  editTool,
764
816
  writeTool,
765
817
  grepTool,
766
- globTool
818
+ globTool,
819
+ planTool
767
820
  ];
768
821
 
769
822
  // src/tools/toolset.ts
770
823
  import { defaultRegistry } from "@cuylabs/agent-core";
771
824
  function setupToolRegistry() {
772
- for (const tool of [bashTool, readTool, editTool, writeTool, grepTool, globTool]) {
825
+ for (const tool of [bashTool, readTool, editTool, writeTool, grepTool, globTool, planTool]) {
773
826
  defaultRegistry.set(tool);
774
827
  }
775
- defaultRegistry.registerGroup("all", ["bash", "read", "edit", "write", "grep", "glob"]);
828
+ defaultRegistry.registerGroup("all", ["bash", "read", "edit", "write", "grep", "glob", "plan"]);
776
829
  defaultRegistry.registerGroup("read-only", ["read", "grep", "glob"]);
777
- defaultRegistry.registerGroup("safe", ["read", "edit", "write", "grep", "glob"]);
830
+ defaultRegistry.registerGroup("safe", ["read", "edit", "write", "grep", "glob", "plan"]);
778
831
  defaultRegistry.registerGroup("minimal", ["read", "write"]);
779
832
  }
780
833
  var ToolsetBuilder = class {
@@ -858,9 +911,11 @@ export {
858
911
  grepTool,
859
912
  globParameters,
860
913
  globTool,
861
- defaultCodingTools,
914
+ planParameters,
915
+ planTool,
862
916
  setupToolRegistry,
863
917
  ToolsetBuilder,
864
918
  toolset,
865
- resolveTools
919
+ resolveTools,
920
+ defaultCodingTools
866
921
  };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,100 @@
1
+ import { AgentConfig, ToolSpec, ApprovalMiddlewareConfig, PromptCacheConfig, SkillConfig, SkillRegistry, SubAgentToolConfig, AgentProfile, SessionManager, FileStorageOptions, Agent } from '@cuylabs/agent-core';
1
2
  export * from '@cuylabs/agent-core';
2
- export { BashParams, EditParams, GlobParams, GrepParams, ReadParams, ToolsetBuilder, WriteParams, bashParameters, bashTool, defaultCodingTools, editParameters, editTool, executeBash, executeGrep, globParameters, globTool, grepParameters, grepTool, readParameters, readTool, resolveTools, setupToolRegistry, toolset, writeParameters, writeTool } from './tools/index.js';
3
- import 'zod';
3
+ export { z } from 'zod';
4
+ export { B as BashParams, E as EditParams, G as GlobParams, a as GrepParams, R as ReadParams, T as ToolsetBuilder, W as WriteParams, b as bashParameters, c as bashTool, d as defaultCodingTools, e as editParameters, f as editTool, g as executeBash, h as executeGrep, i as globParameters, j as globTool, k as grepParameters, l as grepTool, r as readParameters, m as readTool, n as resolveTools, s as setupToolRegistry, t as toolset, w as writeParameters, o as writeTool } from './toolset-DdlrWOqv.js';
5
+
6
+ interface CodingSessionStorageOptions extends Partial<Omit<FileStorageOptions, "directory">> {
7
+ /**
8
+ * Explicit directory for project sessions.
9
+ *
10
+ * When omitted, `getProjectSessionsDir(cwd, appName)` is used.
11
+ */
12
+ directory?: string;
13
+ /**
14
+ * App namespace used by `getProjectSessionsDir()`.
15
+ *
16
+ * @default "cuylabs"
17
+ */
18
+ appName?: string;
19
+ }
20
+ interface CodingSubAgentOptions extends Omit<SubAgentToolConfig, "profiles"> {
21
+ /**
22
+ * Specialist profiles exposed through `invoke_agent`.
23
+ *
24
+ * Defaults to `defaultCodingProfiles`.
25
+ */
26
+ profiles?: AgentProfile[];
27
+ }
28
+ interface CodingAgentOptions extends AgentConfig {
29
+ /**
30
+ * Coding tools to expose. Defaults to the full coding toolset.
31
+ *
32
+ * Accepts the same `ToolSpec` formats as `resolveTools()`.
33
+ */
34
+ tools?: ToolSpec;
35
+ /**
36
+ * Optional approval middleware configuration.
37
+ *
38
+ * Pass `false` to disable approval wiring entirely.
39
+ */
40
+ approval?: false | ApprovalMiddlewareConfig;
41
+ /**
42
+ * Enable the prompt cache middleware.
43
+ *
44
+ * `true` uses provider defaults.
45
+ */
46
+ promptCache?: boolean | PromptCacheConfig;
47
+ /**
48
+ * Skill discovery configuration or a pre-built registry.
49
+ *
50
+ * Defaults to `true`, which scans the current project and user skill roots.
51
+ */
52
+ skills?: boolean | SkillConfig | SkillRegistry;
53
+ /**
54
+ * Sub-agent delegation configuration.
55
+ *
56
+ * Defaults to `true`, which enables `invoke_agent` with the default
57
+ * coding specialist profiles.
58
+ */
59
+ subAgents?: boolean | CodingSubAgentOptions;
60
+ /**
61
+ * Explicit session manager. Overrides `sessionStorage` when provided.
62
+ */
63
+ sessionManager?: SessionManager;
64
+ /**
65
+ * Configure project-scoped file-backed sessions.
66
+ *
67
+ * Defaults to `true`, which stores sessions under the project storage dir.
68
+ * Pass `false` to keep the agent on the default in-memory session manager.
69
+ */
70
+ sessionStorage?: boolean | CodingSessionStorageOptions;
71
+ }
72
+ interface CodingAgentSetupResult {
73
+ agent: Agent;
74
+ skillRegistry: SkillRegistry | null;
75
+ }
76
+ /**
77
+ * Assemble a batteries-included coding agent from `agent-core` primitives.
78
+ *
79
+ * This wires the coding toolset, optional approval middleware, skill tools,
80
+ * persistent sessions, and sub-agent delegation into a reusable package-level
81
+ * surface. UI-specific concerns stay outside this helper.
82
+ */
83
+ declare function setupCodingAgent(options: CodingAgentOptions): Promise<CodingAgentSetupResult>;
84
+ /**
85
+ * Create a fully-wired coding agent.
86
+ *
87
+ * Returns just the agent instance for the common embeddable case. Use
88
+ * `setupCodingAgent()` when you also need the resolved skill registry.
89
+ */
90
+ declare function createCodingAgent(options: CodingAgentOptions): Promise<Agent>;
91
+
92
+ /**
93
+ * Default specialist profiles for coding-focused agents.
94
+ *
95
+ * These are the profiles enabled by `setupCodingAgent()` when
96
+ * `subAgents: true` is used.
97
+ */
98
+ declare const defaultCodingProfiles: AgentProfile[];
99
+
100
+ export { type CodingAgentOptions, type CodingAgentSetupResult, type CodingSessionStorageOptions, type CodingSubAgentOptions, createCodingAgent, defaultCodingProfiles, setupCodingAgent };
package/dist/index.js CHANGED
@@ -18,14 +18,185 @@ import {
18
18
  toolset,
19
19
  writeParameters,
20
20
  writeTool
21
- } from "./chunk-U6W6NJNW.js";
21
+ } from "./chunk-DXHZSPO6.js";
22
22
 
23
23
  // src/index.ts
24
24
  export * from "@cuylabs/agent-core";
25
+ import { z } from "zod";
26
+
27
+ // src/create.ts
28
+ import process from "process";
29
+ import {
30
+ PRIORITY_SKILLS,
31
+ FileStorage,
32
+ SessionManager,
33
+ SkillRegistry,
34
+ approvalMiddleware,
35
+ createAgent,
36
+ createSkillRegistry,
37
+ createSkillTools,
38
+ createSubAgentTools,
39
+ getProjectSessionsDir,
40
+ promptCacheMiddleware
41
+ } from "@cuylabs/agent-core";
42
+
43
+ // src/profiles.ts
44
+ import { Presets } from "@cuylabs/agent-core";
45
+ var defaultCodingProfiles = [
46
+ {
47
+ name: "explorer",
48
+ description: 'Fast read-only codebase search and exploration. Use for finding files by pattern, searching code for keywords, reading file contents, answering questions about the codebase, and mapping project structure. Starts with glob/grep to discover paths. Specify thoroughness: "quick" for basic lookups, "thorough" for deep analysis across multiple locations.',
49
+ preset: Presets.explore,
50
+ maxSteps: 20
51
+ },
52
+ {
53
+ name: "coder",
54
+ description: "Full-power implementation agent for writing, editing, and modifying code. Use for implementing features, fixing bugs, refactoring, writing tests, and any task that requires file modifications. Reads context first, follows existing conventions, verifies changes. Iterates until done.",
55
+ preset: Presets.code,
56
+ maxSteps: 40
57
+ },
58
+ {
59
+ name: "planner",
60
+ description: "Read-only analysis and planning agent. Use when you need a detailed implementation plan before starting work. Breaks down complex tasks into numbered, actionable steps. Does not make changes.",
61
+ preset: Presets.plan,
62
+ maxSteps: 15
63
+ },
64
+ {
65
+ name: "runner",
66
+ description: "Process execution and monitoring agent. Use for running test suites, builds, lint, or any command that takes time. Executes the command, waits for output, and reports a clear pass/fail summary. Does not modify files.",
67
+ preset: Presets.watch,
68
+ maxSteps: 10
69
+ }
70
+ ];
71
+
72
+ // src/create.ts
73
+ function resolveSessionManager(cwd, sessionManager, sessionStorage) {
74
+ if (sessionManager) {
75
+ return sessionManager;
76
+ }
77
+ if (sessionStorage === false) {
78
+ return void 0;
79
+ }
80
+ const storageOptions = sessionStorage && sessionStorage !== true ? sessionStorage : void 0;
81
+ const directory = storageOptions?.directory ?? getProjectSessionsDir(cwd, storageOptions?.appName);
82
+ return new SessionManager(
83
+ new FileStorage({
84
+ directory,
85
+ extension: storageOptions?.extension,
86
+ cache: storageOptions?.cache
87
+ })
88
+ );
89
+ }
90
+ async function resolveSkillRegistry(cwd, skills) {
91
+ if (skills === false) {
92
+ return null;
93
+ }
94
+ if (skills instanceof SkillRegistry) {
95
+ return skills;
96
+ }
97
+ const config = skills === true || skills === void 0 ? void 0 : skills;
98
+ return await createSkillRegistry(cwd, config);
99
+ }
100
+ function resolveSubAgentOptions(subAgents) {
101
+ if (subAgents === false) {
102
+ return null;
103
+ }
104
+ const config = subAgents && subAgents !== true ? subAgents : void 0;
105
+ const profiles = config?.profiles ?? defaultCodingProfiles;
106
+ if (profiles.length === 0) {
107
+ return null;
108
+ }
109
+ return {
110
+ profiles,
111
+ maxConcurrent: config?.maxConcurrent,
112
+ maxDepth: config?.maxDepth,
113
+ currentDepth: config?.currentDepth,
114
+ async: config?.async,
115
+ sessionTitlePrefix: config?.sessionTitlePrefix
116
+ };
117
+ }
118
+ function mergePromptConfig(options) {
119
+ const { prompt, systemPrompt, skillRegistry } = options;
120
+ const skillSummary = skillRegistry?.formatSummary() ?? "";
121
+ if (skillSummary.length === 0) {
122
+ return prompt;
123
+ }
124
+ if (prompt === void 0 && systemPrompt !== void 0) {
125
+ return void 0;
126
+ }
127
+ if (prompt?.skills !== void 0) {
128
+ return prompt;
129
+ }
130
+ const sections = [...prompt?.sections ?? []];
131
+ sections.push({
132
+ id: "coding-skills",
133
+ label: "Available Skills",
134
+ content: skillSummary,
135
+ priority: PRIORITY_SKILLS
136
+ });
137
+ return {
138
+ ...prompt,
139
+ sections
140
+ };
141
+ }
142
+ async function setupCodingAgent(options) {
143
+ const {
144
+ tools: toolSpec = true,
145
+ approval = false,
146
+ promptCache = false,
147
+ skills = true,
148
+ subAgents = true,
149
+ sessionManager,
150
+ sessionStorage = true,
151
+ middleware,
152
+ prompt,
153
+ cwd = process.cwd(),
154
+ ...agentOptions
155
+ } = options;
156
+ const tools = resolveTools(toolSpec);
157
+ const skillRegistry = await resolveSkillRegistry(cwd, skills);
158
+ if (skillRegistry && skillRegistry.size > 0) {
159
+ tools.push(...createSkillTools(skillRegistry));
160
+ }
161
+ const resolvedMiddleware = [...middleware ?? []];
162
+ if (approval) {
163
+ resolvedMiddleware.push(approvalMiddleware(approval));
164
+ }
165
+ if (promptCache) {
166
+ resolvedMiddleware.push(
167
+ promptCacheMiddleware(promptCache === true ? void 0 : promptCache)
168
+ );
169
+ }
170
+ const agent = createAgent({
171
+ ...agentOptions,
172
+ cwd,
173
+ prompt: mergePromptConfig({
174
+ prompt,
175
+ systemPrompt: agentOptions.systemPrompt,
176
+ skillRegistry
177
+ }),
178
+ sessionManager: resolveSessionManager(cwd, sessionManager, sessionStorage),
179
+ ...resolvedMiddleware.length > 0 ? { middleware: resolvedMiddleware } : {},
180
+ ...tools.length > 0 ? { tools } : {}
181
+ });
182
+ const subAgentConfig = resolveSubAgentOptions(subAgents);
183
+ if (subAgentConfig && tools.length > 0) {
184
+ for (const tool of createSubAgentTools(agent, subAgentConfig)) {
185
+ agent.addTool(tool);
186
+ }
187
+ }
188
+ return { agent, skillRegistry };
189
+ }
190
+ async function createCodingAgent(options) {
191
+ const { agent } = await setupCodingAgent(options);
192
+ return agent;
193
+ }
25
194
  export {
26
195
  ToolsetBuilder,
27
196
  bashParameters,
28
197
  bashTool,
198
+ createCodingAgent,
199
+ defaultCodingProfiles,
29
200
  defaultCodingTools,
30
201
  editParameters,
31
202
  editTool,
@@ -38,8 +209,10 @@ export {
38
209
  readParameters,
39
210
  readTool,
40
211
  resolveTools,
212
+ setupCodingAgent,
41
213
  setupToolRegistry,
42
214
  toolset,
43
215
  writeParameters,
44
- writeTool
216
+ writeTool,
217
+ z
45
218
  };
@@ -1,354 +1,93 @@
1
- import { Tool, ToolHost, ExecResult, ToolSpec } from '@cuylabs/agent-core';
1
+ export { B as BashParams, E as EditParams, G as GlobParams, a as GrepParams, R as ReadParams, T as ToolsetBuilder, W as WriteParams, b as bashParameters, c as bashTool, d as defaultCodingTools, e as editParameters, f as editTool, g as executeBash, h as executeGrep, i as globParameters, j as globTool, k as grepParameters, l as grepTool, r as readParameters, m as readTool, n as resolveTools, s as setupToolRegistry, t as toolset, w as writeParameters, o as writeTool } from '../toolset-DdlrWOqv.js';
2
2
  import { z } from 'zod';
3
+ import { Tool } from '@cuylabs/agent-core';
3
4
 
4
5
  /**
5
- * Bash tool - Execute shell commands
6
- */
7
-
8
- declare const bashParameters: z.ZodObject<{
9
- command: z.ZodString;
10
- timeout: z.ZodOptional<z.ZodNumber>;
11
- workdir: z.ZodOptional<z.ZodString>;
12
- description: z.ZodString;
13
- }, "strip", z.ZodTypeAny, {
14
- description: string;
15
- command: string;
16
- timeout?: number | undefined;
17
- workdir?: string | undefined;
18
- }, {
19
- description: string;
20
- command: string;
21
- timeout?: number | undefined;
22
- workdir?: string | undefined;
23
- }>;
24
- type BashParams = z.infer<typeof bashParameters>;
25
- /**
26
- * Execute a bash command via a ToolHost.
27
- */
28
- declare function executeBash(params: BashParams, host: ToolHost, cwd: string, abort?: AbortSignal): Promise<ExecResult>;
29
- /**
30
- * Bash tool definition
31
- */
32
- declare const bashTool: Tool.Info<z.ZodObject<{
33
- command: z.ZodString;
34
- timeout: z.ZodOptional<z.ZodNumber>;
35
- workdir: z.ZodOptional<z.ZodString>;
36
- description: z.ZodString;
37
- }, "strip", z.ZodTypeAny, {
38
- description: string;
39
- command: string;
40
- timeout?: number | undefined;
41
- workdir?: string | undefined;
42
- }, {
43
- description: string;
44
- command: string;
45
- timeout?: number | undefined;
46
- workdir?: string | undefined;
47
- }>, {
48
- exitCode: number | null;
49
- timedOut: boolean;
50
- truncated: boolean;
51
- outputPath: string | undefined;
52
- }>;
53
-
54
- /**
55
- * Read tool - Read file contents
56
- */
57
-
58
- declare const readParameters: z.ZodObject<{
59
- filePath: z.ZodString;
60
- offset: z.ZodOptional<z.ZodNumber>;
61
- limit: z.ZodOptional<z.ZodNumber>;
62
- }, "strip", z.ZodTypeAny, {
63
- filePath: string;
64
- limit?: number | undefined;
65
- offset?: number | undefined;
66
- }, {
67
- filePath: string;
68
- limit?: number | undefined;
69
- offset?: number | undefined;
70
- }>;
71
- type ReadParams = z.infer<typeof readParameters>;
72
- /**
73
- * Read tool definition
74
- */
75
- declare const readTool: Tool.Info<z.ZodObject<{
76
- filePath: z.ZodString;
77
- offset: z.ZodOptional<z.ZodNumber>;
78
- limit: z.ZodOptional<z.ZodNumber>;
79
- }, "strip", z.ZodTypeAny, {
80
- filePath: string;
81
- limit?: number | undefined;
82
- offset?: number | undefined;
83
- }, {
84
- filePath: string;
85
- limit?: number | undefined;
86
- offset?: number | undefined;
87
- }>, {
88
- totalLines: number;
89
- linesRead: number;
90
- offset: number;
91
- truncated: boolean;
92
- preview: string;
93
- }>;
94
-
95
- /**
96
- * Edit tool - Edit files by replacing text
97
- */
98
-
99
- declare const editParameters: z.ZodObject<{
100
- filePath: z.ZodString;
101
- oldString: z.ZodString;
102
- newString: z.ZodString;
103
- replaceAll: z.ZodOptional<z.ZodBoolean>;
104
- }, "strip", z.ZodTypeAny, {
105
- filePath: string;
106
- oldString: string;
107
- newString: string;
108
- replaceAll?: boolean | undefined;
109
- }, {
110
- filePath: string;
111
- oldString: string;
112
- newString: string;
113
- replaceAll?: boolean | undefined;
114
- }>;
115
- type EditParams = z.infer<typeof editParameters>;
116
- /**
117
- * Edit tool definition
118
- */
119
- declare const editTool: Tool.Info<z.ZodObject<{
120
- filePath: z.ZodString;
121
- oldString: z.ZodString;
122
- newString: z.ZodString;
123
- replaceAll: z.ZodOptional<z.ZodBoolean>;
124
- }, "strip", z.ZodTypeAny, {
125
- filePath: string;
126
- oldString: string;
127
- newString: string;
128
- replaceAll?: boolean | undefined;
129
- }, {
130
- filePath: string;
131
- oldString: string;
132
- newString: string;
133
- replaceAll?: boolean | undefined;
134
- }>, {
135
- filepath: string;
136
- created: boolean;
137
- additions: number;
138
- deletions: number;
139
- diff: string;
140
- }>;
141
-
142
- /**
143
- * Write tool - Create or overwrite files
144
- */
145
-
146
- declare const writeParameters: z.ZodObject<{
147
- filePath: z.ZodString;
148
- content: z.ZodString;
149
- }, "strip", z.ZodTypeAny, {
150
- content: string;
151
- filePath: string;
152
- }, {
153
- content: string;
154
- filePath: string;
155
- }>;
156
- type WriteParams = z.infer<typeof writeParameters>;
157
- /**
158
- * Write tool definition
159
- */
160
- declare const writeTool: Tool.Info<z.ZodObject<{
161
- filePath: z.ZodString;
162
- content: z.ZodString;
163
- }, "strip", z.ZodTypeAny, {
164
- content: string;
165
- filePath: string;
166
- }, {
167
- content: string;
168
- filePath: string;
169
- }>, {
170
- filepath: string;
171
- created: boolean;
172
- updated: boolean;
173
- lines: number;
174
- }>;
175
-
176
- /**
177
- * Grep tool - Search file contents
6
+ * Plan tool structured task planning for multi-step work.
7
+ *
8
+ * Allows the agent to create, track, and update a structured plan
9
+ * that is visible to the user. Each invocation replaces the full plan,
10
+ * so the agent always sends the complete current state.
178
11
  */
179
12
 
180
- declare const grepParameters: z.ZodObject<{
181
- pattern: z.ZodString;
182
- path: z.ZodOptional<z.ZodString>;
183
- include: z.ZodOptional<z.ZodString>;
13
+ declare const planEntrySchema: z.ZodObject<{
14
+ id: z.ZodNumber;
15
+ title: z.ZodString;
16
+ status: z.ZodEnum<["pending", "in-progress", "done"]>;
184
17
  }, "strip", z.ZodTypeAny, {
185
- pattern: string;
186
- path?: string | undefined;
187
- include?: string | undefined;
18
+ id: number;
19
+ status: "done" | "pending" | "in-progress";
20
+ title: string;
188
21
  }, {
189
- pattern: string;
190
- path?: string | undefined;
191
- include?: string | undefined;
192
- }>;
193
- type GrepParams = z.infer<typeof grepParameters>;
194
- /**
195
- * Execute grep search
196
- */
197
- declare function executeGrep(params: GrepParams, host: ToolHost, cwd: string, abort?: AbortSignal): Promise<{
198
- matches: Array<{
199
- file: string;
200
- line: number;
201
- text: string;
202
- }>;
203
- truncated: boolean;
22
+ id: number;
23
+ status: "done" | "pending" | "in-progress";
24
+ title: string;
204
25
  }>;
205
- /**
206
- * Grep tool definition
207
- */
208
- declare const grepTool: Tool.Info<z.ZodObject<{
209
- pattern: z.ZodString;
210
- path: z.ZodOptional<z.ZodString>;
211
- include: z.ZodOptional<z.ZodString>;
26
+ declare const planParameters: z.ZodObject<{
27
+ entries: z.ZodArray<z.ZodObject<{
28
+ id: z.ZodNumber;
29
+ title: z.ZodString;
30
+ status: z.ZodEnum<["pending", "in-progress", "done"]>;
31
+ }, "strip", z.ZodTypeAny, {
32
+ id: number;
33
+ status: "done" | "pending" | "in-progress";
34
+ title: string;
35
+ }, {
36
+ id: number;
37
+ status: "done" | "pending" | "in-progress";
38
+ title: string;
39
+ }>, "many">;
212
40
  }, "strip", z.ZodTypeAny, {
213
- pattern: string;
214
- path?: string | undefined;
215
- include?: string | undefined;
41
+ entries: {
42
+ id: number;
43
+ status: "done" | "pending" | "in-progress";
44
+ title: string;
45
+ }[];
216
46
  }, {
217
- pattern: string;
218
- path?: string | undefined;
219
- include?: string | undefined;
220
- }>, {
221
- matches: number;
222
- truncated: boolean;
47
+ entries: {
48
+ id: number;
49
+ status: "done" | "pending" | "in-progress";
50
+ title: string;
51
+ }[];
223
52
  }>;
224
-
225
- /**
226
- * Glob tool - Find files by pattern
227
- */
228
-
229
- declare const globParameters: z.ZodObject<{
230
- pattern: z.ZodString;
231
- path: z.ZodOptional<z.ZodString>;
232
- }, "strip", z.ZodTypeAny, {
233
- pattern: string;
234
- path?: string | undefined;
235
- }, {
236
- pattern: string;
237
- path?: string | undefined;
238
- }>;
239
- type GlobParams = z.infer<typeof globParameters>;
240
- /**
241
- * Glob tool definition
242
- */
243
- declare const globTool: Tool.Info<z.ZodObject<{
244
- pattern: z.ZodString;
245
- path: z.ZodOptional<z.ZodString>;
53
+ type PlanParams = z.infer<typeof planParameters>;
54
+ type PlanEntry = z.infer<typeof planEntrySchema>;
55
+ declare const planTool: Tool.Info<z.ZodObject<{
56
+ entries: z.ZodArray<z.ZodObject<{
57
+ id: z.ZodNumber;
58
+ title: z.ZodString;
59
+ status: z.ZodEnum<["pending", "in-progress", "done"]>;
60
+ }, "strip", z.ZodTypeAny, {
61
+ id: number;
62
+ status: "done" | "pending" | "in-progress";
63
+ title: string;
64
+ }, {
65
+ id: number;
66
+ status: "done" | "pending" | "in-progress";
67
+ title: string;
68
+ }>, "many">;
246
69
  }, "strip", z.ZodTypeAny, {
247
- pattern: string;
248
- path?: string | undefined;
70
+ entries: {
71
+ id: number;
72
+ status: "done" | "pending" | "in-progress";
73
+ title: string;
74
+ }[];
249
75
  }, {
250
- pattern: string;
251
- path?: string | undefined;
76
+ entries: {
77
+ id: number;
78
+ status: "done" | "pending" | "in-progress";
79
+ title: string;
80
+ }[];
252
81
  }>, {
253
- count: number;
254
- truncated: boolean;
82
+ entries: {
83
+ id: number;
84
+ status: "done" | "pending" | "in-progress";
85
+ title: string;
86
+ }[];
87
+ done: number;
88
+ active: number;
89
+ pending: number;
90
+ total: number;
255
91
  }>;
256
92
 
257
- /**
258
- * Default tool collections
259
- */
260
-
261
- /**
262
- * Default tools for a coding agent
263
- */
264
- declare const defaultCodingTools: Tool.AnyInfo[];
265
-
266
- /**
267
- * Tool composition and registry setup for @cuylabs/agent-code.
268
- *
269
- * Registers all coding tools into the default registry, defines standard
270
- * groups, and provides a fluent `toolset()` builder for easy composition.
271
- *
272
- * @example
273
- * ```typescript
274
- * import { toolset, resolveTools } from "@cuylabs/agent-code";
275
- *
276
- * // Fluent builder
277
- * const tools = toolset("read-only").add(myCustomTool).build();
278
- *
279
- * // Spec-based resolution
280
- * const tools = resolveTools("all,-bash");
281
- * const tools = resolveTools("read,grep,glob");
282
- * const tools = resolveTools("safe");
283
- * ```
284
- */
285
-
286
- /**
287
- * Register all coding tools and standard groups into the default registry.
288
- * Uses `set()` (upsert) so it's safe to call multiple times, even after
289
- * `clear()`.
290
- */
291
- declare function setupToolRegistry(): void;
292
- /**
293
- * Fluent tool composition builder.
294
- *
295
- * @example
296
- * ```typescript
297
- * // Start from a group and customize
298
- * const tools = toolset("read-only").add(myTool).build();
299
- *
300
- * // Start from all and exclude
301
- * const tools = toolset("all").remove("bash").build();
302
- *
303
- * // Start empty and pick
304
- * const tools = toolset().add("read").add("grep").build();
305
- * ```
306
- */
307
- declare class ToolsetBuilder {
308
- private tools;
309
- constructor(base?: ToolSpec);
310
- /** Add a tool by ID (from registry) or by instance. */
311
- add(tool: string | Tool.AnyInfo): this;
312
- /** Remove a tool by ID. */
313
- remove(id: string): this;
314
- /** Keep only the specified tool IDs (intersection). */
315
- only(...ids: string[]): this;
316
- /** Return the final tool array. */
317
- build(): Tool.AnyInfo[];
318
- }
319
- /**
320
- * Create a toolset builder with an optional base spec.
321
- *
322
- * @param base Starting point — group name, tool IDs, boolean, or array.
323
- * Defaults to empty (call `.add()` to populate).
324
- *
325
- * @example
326
- * ```typescript
327
- * // All tools except bash
328
- * const tools = toolset("all").remove("bash").build();
329
- *
330
- * // Read-only with a custom tool
331
- * const tools = toolset("read-only").add(mySearchTool).build();
332
- * ```
333
- */
334
- declare function toolset(base?: ToolSpec): ToolsetBuilder;
335
- /**
336
- * Resolve a tool spec to an array of tools.
337
- *
338
- * Ensures the coding tool registry is initialized, then delegates to
339
- * `defaultRegistry.resolve()`.
340
- *
341
- * @param spec Group name, comma-separated IDs, boolean, or array.
342
- *
343
- * @example
344
- * ```typescript
345
- * resolveTools("read-only"); // → [readTool, grepTool, globTool]
346
- * resolveTools("all,-bash"); // → all except bash
347
- * resolveTools("read,grep"); // → [readTool, grepTool]
348
- * resolveTools(true); // → all coding tools
349
- * resolveTools(false); // → []
350
- * ```
351
- */
352
- declare function resolveTools(spec: ToolSpec): Tool.AnyInfo[];
353
-
354
- export { type BashParams, type EditParams, type GlobParams, type GrepParams, type ReadParams, ToolsetBuilder, type WriteParams, bashParameters, bashTool, defaultCodingTools, editParameters, editTool, executeBash, executeGrep, globParameters, globTool, grepParameters, grepTool, readParameters, readTool, resolveTools, setupToolRegistry, toolset, writeParameters, writeTool };
93
+ export { type PlanEntry, type PlanParams, planParameters, planTool };
@@ -11,6 +11,8 @@ import {
11
11
  globTool,
12
12
  grepParameters,
13
13
  grepTool,
14
+ planParameters,
15
+ planTool,
14
16
  readParameters,
15
17
  readTool,
16
18
  resolveTools,
@@ -18,7 +20,7 @@ import {
18
20
  toolset,
19
21
  writeParameters,
20
22
  writeTool
21
- } from "../chunk-U6W6NJNW.js";
23
+ } from "../chunk-DXHZSPO6.js";
22
24
  export {
23
25
  ToolsetBuilder,
24
26
  bashParameters,
@@ -32,6 +34,8 @@ export {
32
34
  globTool,
33
35
  grepParameters,
34
36
  grepTool,
37
+ planParameters,
38
+ planTool,
35
39
  readParameters,
36
40
  readTool,
37
41
  resolveTools,
@@ -0,0 +1,354 @@
1
+ import { z } from 'zod';
2
+ import { Tool, ToolHost, ExecResult, ToolSpec } from '@cuylabs/agent-core';
3
+
4
+ /**
5
+ * Bash tool - Execute shell commands
6
+ */
7
+
8
+ declare const bashParameters: z.ZodObject<{
9
+ command: z.ZodString;
10
+ timeout: z.ZodOptional<z.ZodNumber>;
11
+ workdir: z.ZodOptional<z.ZodString>;
12
+ description: z.ZodString;
13
+ }, "strip", z.ZodTypeAny, {
14
+ description: string;
15
+ command: string;
16
+ timeout?: number | undefined;
17
+ workdir?: string | undefined;
18
+ }, {
19
+ description: string;
20
+ command: string;
21
+ timeout?: number | undefined;
22
+ workdir?: string | undefined;
23
+ }>;
24
+ type BashParams = z.infer<typeof bashParameters>;
25
+ /**
26
+ * Execute a bash command via a ToolHost.
27
+ */
28
+ declare function executeBash(params: BashParams, host: ToolHost, cwd: string, abort?: AbortSignal): Promise<ExecResult>;
29
+ /**
30
+ * Bash tool definition
31
+ */
32
+ declare const bashTool: Tool.Info<z.ZodObject<{
33
+ command: z.ZodString;
34
+ timeout: z.ZodOptional<z.ZodNumber>;
35
+ workdir: z.ZodOptional<z.ZodString>;
36
+ description: z.ZodString;
37
+ }, "strip", z.ZodTypeAny, {
38
+ description: string;
39
+ command: string;
40
+ timeout?: number | undefined;
41
+ workdir?: string | undefined;
42
+ }, {
43
+ description: string;
44
+ command: string;
45
+ timeout?: number | undefined;
46
+ workdir?: string | undefined;
47
+ }>, {
48
+ exitCode: number | null;
49
+ timedOut: boolean;
50
+ truncated: boolean;
51
+ outputPath: string | undefined;
52
+ }>;
53
+
54
+ /**
55
+ * Read tool - Read file contents
56
+ */
57
+
58
+ declare const readParameters: z.ZodObject<{
59
+ filePath: z.ZodString;
60
+ offset: z.ZodOptional<z.ZodNumber>;
61
+ limit: z.ZodOptional<z.ZodNumber>;
62
+ }, "strip", z.ZodTypeAny, {
63
+ filePath: string;
64
+ limit?: number | undefined;
65
+ offset?: number | undefined;
66
+ }, {
67
+ filePath: string;
68
+ limit?: number | undefined;
69
+ offset?: number | undefined;
70
+ }>;
71
+ type ReadParams = z.infer<typeof readParameters>;
72
+ /**
73
+ * Read tool definition
74
+ */
75
+ declare const readTool: Tool.Info<z.ZodObject<{
76
+ filePath: z.ZodString;
77
+ offset: z.ZodOptional<z.ZodNumber>;
78
+ limit: z.ZodOptional<z.ZodNumber>;
79
+ }, "strip", z.ZodTypeAny, {
80
+ filePath: string;
81
+ limit?: number | undefined;
82
+ offset?: number | undefined;
83
+ }, {
84
+ filePath: string;
85
+ limit?: number | undefined;
86
+ offset?: number | undefined;
87
+ }>, {
88
+ totalLines: number;
89
+ linesRead: number;
90
+ offset: number;
91
+ truncated: boolean;
92
+ preview: string;
93
+ }>;
94
+
95
+ /**
96
+ * Edit tool - Edit files by replacing text
97
+ */
98
+
99
+ declare const editParameters: z.ZodObject<{
100
+ filePath: z.ZodString;
101
+ oldString: z.ZodString;
102
+ newString: z.ZodString;
103
+ replaceAll: z.ZodOptional<z.ZodBoolean>;
104
+ }, "strip", z.ZodTypeAny, {
105
+ filePath: string;
106
+ oldString: string;
107
+ newString: string;
108
+ replaceAll?: boolean | undefined;
109
+ }, {
110
+ filePath: string;
111
+ oldString: string;
112
+ newString: string;
113
+ replaceAll?: boolean | undefined;
114
+ }>;
115
+ type EditParams = z.infer<typeof editParameters>;
116
+ /**
117
+ * Edit tool definition
118
+ */
119
+ declare const editTool: Tool.Info<z.ZodObject<{
120
+ filePath: z.ZodString;
121
+ oldString: z.ZodString;
122
+ newString: z.ZodString;
123
+ replaceAll: z.ZodOptional<z.ZodBoolean>;
124
+ }, "strip", z.ZodTypeAny, {
125
+ filePath: string;
126
+ oldString: string;
127
+ newString: string;
128
+ replaceAll?: boolean | undefined;
129
+ }, {
130
+ filePath: string;
131
+ oldString: string;
132
+ newString: string;
133
+ replaceAll?: boolean | undefined;
134
+ }>, {
135
+ filepath: string;
136
+ created: boolean;
137
+ additions: number;
138
+ deletions: number;
139
+ diff: string;
140
+ }>;
141
+
142
+ /**
143
+ * Write tool - Create or overwrite files
144
+ */
145
+
146
+ declare const writeParameters: z.ZodObject<{
147
+ filePath: z.ZodString;
148
+ content: z.ZodString;
149
+ }, "strip", z.ZodTypeAny, {
150
+ content: string;
151
+ filePath: string;
152
+ }, {
153
+ content: string;
154
+ filePath: string;
155
+ }>;
156
+ type WriteParams = z.infer<typeof writeParameters>;
157
+ /**
158
+ * Write tool definition
159
+ */
160
+ declare const writeTool: Tool.Info<z.ZodObject<{
161
+ filePath: z.ZodString;
162
+ content: z.ZodString;
163
+ }, "strip", z.ZodTypeAny, {
164
+ content: string;
165
+ filePath: string;
166
+ }, {
167
+ content: string;
168
+ filePath: string;
169
+ }>, {
170
+ filepath: string;
171
+ created: boolean;
172
+ updated: boolean;
173
+ lines: number;
174
+ }>;
175
+
176
+ /**
177
+ * Grep tool - Search file contents
178
+ */
179
+
180
+ declare const grepParameters: z.ZodObject<{
181
+ pattern: z.ZodString;
182
+ path: z.ZodOptional<z.ZodString>;
183
+ include: z.ZodOptional<z.ZodString>;
184
+ }, "strip", z.ZodTypeAny, {
185
+ pattern: string;
186
+ path?: string | undefined;
187
+ include?: string | undefined;
188
+ }, {
189
+ pattern: string;
190
+ path?: string | undefined;
191
+ include?: string | undefined;
192
+ }>;
193
+ type GrepParams = z.infer<typeof grepParameters>;
194
+ /**
195
+ * Execute grep search
196
+ */
197
+ declare function executeGrep(params: GrepParams, host: ToolHost, cwd: string, abort?: AbortSignal): Promise<{
198
+ matches: Array<{
199
+ file: string;
200
+ line: number;
201
+ text: string;
202
+ }>;
203
+ truncated: boolean;
204
+ }>;
205
+ /**
206
+ * Grep tool definition
207
+ */
208
+ declare const grepTool: Tool.Info<z.ZodObject<{
209
+ pattern: z.ZodString;
210
+ path: z.ZodOptional<z.ZodString>;
211
+ include: z.ZodOptional<z.ZodString>;
212
+ }, "strip", z.ZodTypeAny, {
213
+ pattern: string;
214
+ path?: string | undefined;
215
+ include?: string | undefined;
216
+ }, {
217
+ pattern: string;
218
+ path?: string | undefined;
219
+ include?: string | undefined;
220
+ }>, {
221
+ matches: number;
222
+ truncated: boolean;
223
+ }>;
224
+
225
+ /**
226
+ * Glob tool - Find files by pattern
227
+ */
228
+
229
+ declare const globParameters: z.ZodObject<{
230
+ pattern: z.ZodString;
231
+ path: z.ZodOptional<z.ZodString>;
232
+ }, "strip", z.ZodTypeAny, {
233
+ pattern: string;
234
+ path?: string | undefined;
235
+ }, {
236
+ pattern: string;
237
+ path?: string | undefined;
238
+ }>;
239
+ type GlobParams = z.infer<typeof globParameters>;
240
+ /**
241
+ * Glob tool definition
242
+ */
243
+ declare const globTool: Tool.Info<z.ZodObject<{
244
+ pattern: z.ZodString;
245
+ path: z.ZodOptional<z.ZodString>;
246
+ }, "strip", z.ZodTypeAny, {
247
+ pattern: string;
248
+ path?: string | undefined;
249
+ }, {
250
+ pattern: string;
251
+ path?: string | undefined;
252
+ }>, {
253
+ count: number;
254
+ truncated: boolean;
255
+ }>;
256
+
257
+ /**
258
+ * Default tool collections
259
+ */
260
+
261
+ /**
262
+ * Default tools for a coding agent
263
+ */
264
+ declare const defaultCodingTools: Tool.AnyInfo[];
265
+
266
+ /**
267
+ * Tool composition and registry setup for @cuylabs/agent-code.
268
+ *
269
+ * Registers all coding tools into the default registry, defines standard
270
+ * groups, and provides a fluent `toolset()` builder for easy composition.
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * import { toolset, resolveTools } from "@cuylabs/agent-code";
275
+ *
276
+ * // Fluent builder
277
+ * const tools = toolset("read-only").add(myCustomTool).build();
278
+ *
279
+ * // Spec-based resolution
280
+ * const tools = resolveTools("all,-bash");
281
+ * const tools = resolveTools("read,grep,glob");
282
+ * const tools = resolveTools("safe");
283
+ * ```
284
+ */
285
+
286
+ /**
287
+ * Register all coding tools and standard groups into the default registry.
288
+ * Uses `set()` (upsert) so it's safe to call multiple times, even after
289
+ * `clear()`.
290
+ */
291
+ declare function setupToolRegistry(): void;
292
+ /**
293
+ * Fluent tool composition builder.
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * // Start from a group and customize
298
+ * const tools = toolset("read-only").add(myTool).build();
299
+ *
300
+ * // Start from all and exclude
301
+ * const tools = toolset("all").remove("bash").build();
302
+ *
303
+ * // Start empty and pick
304
+ * const tools = toolset().add("read").add("grep").build();
305
+ * ```
306
+ */
307
+ declare class ToolsetBuilder {
308
+ private tools;
309
+ constructor(base?: ToolSpec);
310
+ /** Add a tool by ID (from registry) or by instance. */
311
+ add(tool: string | Tool.AnyInfo): this;
312
+ /** Remove a tool by ID. */
313
+ remove(id: string): this;
314
+ /** Keep only the specified tool IDs (intersection). */
315
+ only(...ids: string[]): this;
316
+ /** Return the final tool array. */
317
+ build(): Tool.AnyInfo[];
318
+ }
319
+ /**
320
+ * Create a toolset builder with an optional base spec.
321
+ *
322
+ * @param base Starting point — group name, tool IDs, boolean, or array.
323
+ * Defaults to empty (call `.add()` to populate).
324
+ *
325
+ * @example
326
+ * ```typescript
327
+ * // All tools except bash
328
+ * const tools = toolset("all").remove("bash").build();
329
+ *
330
+ * // Read-only with a custom tool
331
+ * const tools = toolset("read-only").add(mySearchTool).build();
332
+ * ```
333
+ */
334
+ declare function toolset(base?: ToolSpec): ToolsetBuilder;
335
+ /**
336
+ * Resolve a tool spec to an array of tools.
337
+ *
338
+ * Ensures the coding tool registry is initialized, then delegates to
339
+ * `defaultRegistry.resolve()`.
340
+ *
341
+ * @param spec Group name, comma-separated IDs, boolean, or array.
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * resolveTools("read-only"); // → [readTool, grepTool, globTool]
346
+ * resolveTools("all,-bash"); // → all except bash
347
+ * resolveTools("read,grep"); // → [readTool, grepTool]
348
+ * resolveTools(true); // → all coding tools
349
+ * resolveTools(false); // → []
350
+ * ```
351
+ */
352
+ declare function resolveTools(spec: ToolSpec): Tool.AnyInfo[];
353
+
354
+ export { type BashParams as B, type EditParams as E, type GlobParams as G, type ReadParams as R, ToolsetBuilder as T, type WriteParams as W, type GrepParams as a, bashParameters as b, bashTool as c, defaultCodingTools as d, editParameters as e, editTool as f, executeBash as g, executeGrep as h, globParameters as i, globTool as j, grepParameters as k, grepTool as l, readTool as m, resolveTools as n, writeTool as o, readParameters as r, setupToolRegistry as s, toolset as t, writeParameters as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuylabs/agent-code",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Embeddable AI coding agent built on @cuylabs/agent-core",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "ai": "^6.0.67",
26
26
  "zod": "^3.24.0",
27
- "@cuylabs/agent-core": "^0.6.0"
27
+ "@cuylabs/agent-core": "^0.8.0"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@ai-sdk/anthropic": "^3.0.0",