goatchain 0.0.2 → 0.0.4

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.
Files changed (86) hide show
  1. package/README.md +173 -236
  2. package/README.zh.md +430 -0
  3. package/dist/acp-adapter/ACPAgent.d.ts +63 -0
  4. package/dist/acp-adapter/ProtocolConverter.d.ts +48 -0
  5. package/dist/acp-adapter/SessionRouter.d.ts +50 -0
  6. package/dist/acp-adapter/index.d.ts +12 -0
  7. package/dist/acp-adapter/types.d.ts +95 -0
  8. package/dist/acp-server.d.ts +21 -0
  9. package/dist/agent/agent.d.ts +196 -0
  10. package/dist/agent/errors.d.ts +29 -0
  11. package/dist/agent/hooks/index.d.ts +2 -0
  12. package/dist/agent/hooks/manager.d.ts +8 -0
  13. package/dist/agent/hooks/types.d.ts +19 -0
  14. package/dist/agent/index.d.ts +14 -0
  15. package/dist/agent/middleware.d.ts +162 -0
  16. package/dist/agent/tokenCounter.d.ts +55 -0
  17. package/dist/agent/types.d.ts +247 -0
  18. package/dist/index.d.ts +21 -3328
  19. package/dist/index.js +424 -140
  20. package/dist/middleware/checkpointMiddleware.d.ts +29 -0
  21. package/dist/middleware/commitModeMiddleware.d.ts +93 -0
  22. package/dist/middleware/contextCompressionMiddleware.d.ts +131 -0
  23. package/dist/middleware/gitUtils.d.ts +119 -0
  24. package/dist/middleware/parallelSubagentMiddleware.d.ts +83 -0
  25. package/dist/middleware/planModeMiddleware.d.ts +80 -0
  26. package/dist/middleware/utils.d.ts +58 -0
  27. package/dist/model/adapter.d.ts +14 -0
  28. package/dist/model/createModel.d.ts +168 -0
  29. package/dist/model/errors.d.ts +14 -0
  30. package/dist/model/health.d.ts +35 -0
  31. package/dist/model/index.d.ts +7 -0
  32. package/dist/model/openai/createOpenAIAdapter.d.ts +23 -0
  33. package/dist/model/router.d.ts +17 -0
  34. package/dist/model/types.d.ts +190 -0
  35. package/dist/model/utils/http.d.ts +15 -0
  36. package/dist/model/utils/id.d.ts +1 -0
  37. package/dist/model/utils/retry.d.ts +142 -0
  38. package/dist/session/base.d.ts +1 -0
  39. package/dist/session/executors/ParallelTaskExecutor.d.ts +16 -0
  40. package/dist/session/executors/ToolExecutor.d.ts +37 -0
  41. package/dist/session/handlers/ApprovalHandler.d.ts +6 -0
  42. package/dist/session/handlers/CheckpointManager.d.ts +10 -0
  43. package/dist/session/index.d.ts +4 -0
  44. package/dist/session/manager.d.ts +35 -0
  45. package/dist/session/session.d.ts +159 -0
  46. package/dist/session/stateStoreSessionManager.d.ts +36 -0
  47. package/dist/session/utils/AsyncQueue.d.ts +7 -0
  48. package/dist/session/utils/AutoSaveManager.d.ts +6 -0
  49. package/dist/state/FileStateStore.d.ts +72 -0
  50. package/dist/state/InMemoryStateStore.d.ts +46 -0
  51. package/dist/state/index.d.ts +6 -0
  52. package/dist/state/stateStore.d.ts +181 -0
  53. package/dist/state/types.d.ts +85 -0
  54. package/dist/subagent/file-search-specialist.d.ts +16 -0
  55. package/dist/subagent/index.d.ts +7 -0
  56. package/dist/tool/FilteredToolRegistry.d.ts +82 -0
  57. package/dist/tool/base.d.ts +57 -0
  58. package/dist/tool/builtin/askUser.d.ts +90 -0
  59. package/dist/tool/builtin/astGrepCli.d.ts +37 -0
  60. package/dist/tool/builtin/astGrepFormat.d.ts +4 -0
  61. package/dist/tool/builtin/astGrepReplace.d.ts +71 -0
  62. package/dist/tool/builtin/astGrepSearch.d.ts +101 -0
  63. package/dist/tool/builtin/bash.d.ts +96 -0
  64. package/dist/tool/builtin/edit.d.ts +82 -0
  65. package/dist/tool/builtin/enterPlanMode.d.ts +58 -0
  66. package/dist/tool/builtin/exitPlanMode.d.ts +48 -0
  67. package/dist/tool/builtin/glob.d.ts +70 -0
  68. package/dist/tool/builtin/grep.d.ts +122 -0
  69. package/dist/tool/builtin/index.d.ts +30 -0
  70. package/dist/tool/builtin/read.d.ts +127 -0
  71. package/dist/tool/builtin/skill.d.ts +111 -0
  72. package/dist/tool/builtin/task.d.ts +132 -0
  73. package/dist/tool/builtin/todoPlan.d.ts +52 -0
  74. package/dist/tool/builtin/todoWrite.d.ts +94 -0
  75. package/dist/tool/builtin/webFetch.d.ts +62 -0
  76. package/dist/tool/builtin/webSearch.d.ts +89 -0
  77. package/dist/tool/builtin/write.d.ts +103 -0
  78. package/dist/tool/index.d.ts +6 -0
  79. package/dist/tool/registry.d.ts +55 -0
  80. package/dist/tool/types.d.ts +107 -0
  81. package/dist/types/common.d.ts +53 -0
  82. package/dist/types/event.d.ts +217 -0
  83. package/dist/types/index.d.ts +4 -0
  84. package/dist/types/message.d.ts +44 -0
  85. package/dist/types/snapshot.d.ts +329 -0
  86. package/package.json +35 -28
@@ -0,0 +1,58 @@
1
+ import type { CallToolResult, ToolInputSchema } from '../../types';
2
+ import type { RiskLevel } from '../types';
3
+ import { BaseTool } from '../base';
4
+ /**
5
+ * Result of entering plan mode
6
+ */
7
+ export interface EnterPlanModeResult {
8
+ /** Whether the operation was successful */
9
+ success: boolean;
10
+ /** Message indicating plan mode has been entered */
11
+ message: string;
12
+ /** Whether user approved entering plan mode */
13
+ approved?: boolean;
14
+ }
15
+ /**
16
+ * Arguments for the EnterPlanMode tool
17
+ */
18
+ export interface EnterPlanModeArgs {
19
+ /** User approval collected by the permission component */
20
+ approved?: boolean;
21
+ }
22
+ /**
23
+ * Tool for entering plan mode before starting non-trivial implementation tasks.
24
+ *
25
+ * This tool allows the agent to transition into plan mode where it can:
26
+ * - Thoroughly explore the codebase using various tools
27
+ * - Understand existing patterns and architecture
28
+ * - Design an implementation approach
29
+ * - Present the plan to the user for approval
30
+ * - Use AskUserQuestion to clarify approaches if needed
31
+ *
32
+ * Getting user sign-off on the approach before writing code prevents wasted
33
+ * effort and ensures alignment.
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const enterPlanModeTool = new EnterPlanModeTool()
38
+ * const result = await enterPlanModeTool.execute({})
39
+ * // Agent is now in plan mode and can explore before implementing
40
+ * ```
41
+ */
42
+ export declare class EnterPlanModeTool extends BaseTool {
43
+ readonly name = "EnterPlanMode";
44
+ readonly riskLevel: RiskLevel;
45
+ readonly description = "Use this tool proactively when you're about to start a non-trivial implementation task. Getting user sign-off on your approach before writing code prevents wasted effort and ensures alignment. This tool transitions you into plan mode where you can explore the codebase and design an implementation approach for user approval.\n\n## When to Use This Tool\n\n**Prefer using EnterPlanMode** for implementation tasks unless they're simple. Use it when ANY of these conditions apply:\n\n1. **New Feature Implementation**: Adding meaningful new functionality\n - Example: \"Add a logout button\" - where should it go? What should happen on click?\n - Example: \"Add form validation\" - what rules? What error messages?\n\n2. **Multiple Valid Approaches**: The task can be solved in several different ways\n - Example: \"Add caching to the API\" - could use Redis, in-memory, file-based, etc.\n - Example: \"Improve performance\" - many optimization strategies possible\n\n3. **Code Modifications**: Changes that affect existing behavior or structure\n - Example: \"Update the login flow\" - what exactly should change?\n - Example: \"Refactor this component\" - what's the target architecture?\n\n4. **Architectural Decisions**: The task requires choosing between patterns or technologies\n - Example: \"Add real-time updates\" - WebSockets vs SSE vs polling\n - Example: \"Implement state management\" - Redux vs Context vs custom solution\n\n5. **Multi-File Changes**: The task will likely touch more than 2-3 files\n - Example: \"Refactor the authentication system\"\n - Example: \"Add a new API endpoint with tests\"\n\n6. **Unclear Requirements**: You need to explore before understanding the full scope\n - Example: \"Make the app faster\" - need to profile and identify bottlenecks\n - Example: \"Fix the bug in checkout\" - need to investigate root cause\n\n7. **User Preferences Matter**: The implementation could reasonably go multiple ways\n - If you would use AskUserQuestion to clarify the approach, use EnterPlanMode instead\n - Plan mode lets you explore first, then present options with context\n\n## When NOT to Use This Tool\n\nOnly skip EnterPlanMode for simple tasks:\n- Single-line or few-line fixes (typos, obvious bugs, small tweaks)\n- Adding a single function with clear requirements\n- Tasks where the user has given very specific, detailed instructions\n- Pure research/exploration tasks (use the Task tool with explore agent instead)\n\n## What Happens in Plan Mode\n\nIn plan mode, you'll:\n1. Thoroughly explore the codebase using Glob, Grep, and Read tools\n2. Understand existing patterns and architecture\n3. Design an implementation approach\n4. Present your plan to the user for approval\n5. Use AskUserQuestion if you need to clarify approaches\n6. Exit plan mode with ExitPlanMode when ready to implement\n\n## Examples\n\n### GOOD - Use EnterPlanMode:\nUser: \"Add user authentication to the app\"\n- Requires architectural decisions (session vs JWT, where to store tokens, middleware structure)\n\nUser: \"Optimize the database queries\"\n- Multiple approaches possible, need to profile first, significant impact\n\nUser: \"Implement dark mode\"\n- Architectural decision on theme system, affects many components\n\nUser: \"Add a delete button to the user profile\"\n- Seems simple but involves: where to place it, confirmation dialog, API call, error handling, state updates\n\nUser: \"Update the error handling in the API\"\n- Affects multiple files, user should approve the approach\n\n### BAD - Don't use EnterPlanMode:\nUser: \"Fix the typo in the README\"\n- Straightforward, no planning needed\n\nUser: \"Add a console.log to debug this function\"\n- Simple, obvious implementation\n\nUser: \"What files handle routing?\"\n- Research task, not implementation planning\n\n## Important Notes\n\n- This tool REQUIRES user approval - they must consent to entering plan mode\n- If unsure whether to use it, err on the side of planning - it's better to get alignment upfront than to redo work\n- Users appreciate being consulted before significant changes are made to their codebase";
46
+ readonly parameters: ToolInputSchema;
47
+ /**
48
+ * Execute enter plan mode
49
+ *
50
+ * @param args - EnterPlanMode arguments
51
+ * @returns MCP-compliant CallToolResult indicating plan mode has been entered
52
+ */
53
+ execute(args: Record<string, unknown>): Promise<CallToolResult>;
54
+ /**
55
+ * Validate and parse arguments
56
+ */
57
+ private validateArgs;
58
+ }
@@ -0,0 +1,48 @@
1
+ import type { CallToolResult, ToolInputSchema } from '../../types';
2
+ import type { RiskLevel } from '../types';
3
+ import { BaseTool } from '../base';
4
+ /**
5
+ * Result of exiting plan mode
6
+ */
7
+ export interface ExitPlanModeResult {
8
+ /** Whether the operation was successful */
9
+ success: boolean;
10
+ /** Message indicating plan mode has been exited */
11
+ message: string;
12
+ }
13
+ /**
14
+ * Arguments for the ExitPlanMode tool
15
+ */
16
+ export interface ExitPlanModeArgs {
17
+ }
18
+ /**
19
+ * Tool for exiting plan mode after completing the implementation plan.
20
+ *
21
+ * This tool is used when:
22
+ * - You have finished writing your plan to the plan file
23
+ * - The plan is clear and unambiguous
24
+ * - You are ready for user approval of the plan
25
+ *
26
+ * The tool signals completion of the planning phase and transitions
27
+ * to waiting for user review and approval.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const exitPlanModeTool = new ExitPlanModeTool()
32
+ * const result = await exitPlanModeTool.execute({})
33
+ * // Plan is now ready for user review
34
+ * ```
35
+ */
36
+ export declare class ExitPlanModeTool extends BaseTool {
37
+ readonly name = "ExitPlanMode";
38
+ readonly riskLevel: RiskLevel;
39
+ readonly description = "Use this tool when you are in plan mode and have finished writing your plan to the plan file and are ready for user approval.\n\n## How This Tool Works\n- You should have already written your plan to the plan file specified in the plan mode system message\n- This tool does NOT take the plan content as a parameter - it will read the plan from the file you wrote\n- This tool simply signals that you're done planning and ready for the user to review and approve\n- The user will see the contents of your plan file when they review it\n\n## When to Use This Tool\nIMPORTANT: Only use this tool when the task requires planning the implementation steps of a task that requires writing code. For research tasks where you're gathering information, searching files, reading files or in general trying to understand the codebase - do NOT use this tool.\n\n## Handling Ambiguity in Plans\nBefore using this tool, ensure your plan is clear and unambiguous. If there are multiple valid approaches or unclear requirements:\n1. Use the AskUserQuestion tool to clarify with the user\n2. Ask about specific implementation choices (e.g., architectural patterns, which library to use)\n3. Clarify any assumptions that could affect the implementation\n4. Edit your plan file to incorporate user feedback\n5. Only proceed with ExitPlanMode after resolving ambiguities and updating the plan file\n\n## Examples\n\n1. Initial task: \"Search for and understand the implementation of vim mode in the codebase\" - Do not use the exit plan mode tool because you are not planning the implementation steps of a task.\n2. Initial task: \"Help me implement yank mode for vim\" - Use the exit plan mode tool after you have finished planning the implementation steps of the task.\n3. Initial task: \"Add a new feature to handle user authentication\" - If unsure about auth method (OAuth, JWT, etc.), use AskUserQuestion first, then use exit plan mode tool after clarifying the approach.\n";
40
+ readonly parameters: ToolInputSchema;
41
+ /**
42
+ * Execute exit plan mode
43
+ *
44
+ * @param _args - ExitPlanMode arguments (empty)
45
+ * @returns MCP-compliant CallToolResult indicating plan mode has been exited
46
+ */
47
+ execute(_args: Record<string, unknown>): Promise<CallToolResult>;
48
+ }
@@ -0,0 +1,70 @@
1
+ import type { CallToolResult, ToolInputSchema } from '../../types';
2
+ import { BaseTool } from '../base';
3
+ /**
4
+ * Result of a glob operation
5
+ */
6
+ export interface GlobResult {
7
+ /** List of matched file paths (sorted by modification time, newest first) */
8
+ files: string[];
9
+ /** Total number of matches found */
10
+ totalMatches: number;
11
+ /** Whether results were truncated */
12
+ truncated: boolean;
13
+ }
14
+ /**
15
+ * Arguments for the Glob tool
16
+ */
17
+ export interface GlobArgs {
18
+ /** The glob pattern to match files against */
19
+ pattern: string;
20
+ /** The directory to search in (defaults to cwd) */
21
+ path?: string;
22
+ }
23
+ /**
24
+ * Tool for finding files matching glob patterns.
25
+ *
26
+ * This tool provides fast file pattern matching that works with any codebase size,
27
+ * returning matching file paths sorted by modification time.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const globTool = new GlobTool()
32
+ * const result = await globTool.execute({
33
+ * pattern: '**\/*.ts',
34
+ * path: './src'
35
+ * })
36
+ * ```
37
+ */
38
+ export declare class GlobTool extends BaseTool {
39
+ readonly name = "Glob";
40
+ readonly description = "Fast file pattern matching tool that works with any codebase size.\n\nUsage notes:\n- Supports glob patterns like \"**/*.js\" or \"src/**/*.ts\"\n- Returns matching file paths sorted by modification time (newest first)\n- Use this tool when you need to find files by name patterns\n- You can call multiple tools in a single response for parallel searches\n\nSupported patterns:\n- `*` matches any sequence of characters except path separator\n- `**` matches any sequence of characters including path separator\n- `?` matches any single character\n- `{a,b}` matches either a or b\n- `[abc]` matches any character in brackets";
41
+ readonly parameters: ToolInputSchema;
42
+ /** Current working directory for search */
43
+ private cwd;
44
+ constructor(options?: {
45
+ cwd?: string;
46
+ });
47
+ /**
48
+ * Set the current working directory
49
+ */
50
+ setCwd(cwd: string): void;
51
+ /**
52
+ * Get the current working directory
53
+ */
54
+ getCwd(): string;
55
+ /**
56
+ * Execute glob pattern matching
57
+ *
58
+ * @param args - Glob arguments
59
+ * @returns MCP-compliant CallToolResult with matching files
60
+ */
61
+ execute(args: Record<string, unknown>): Promise<CallToolResult>;
62
+ /**
63
+ * Validate and parse arguments
64
+ */
65
+ private validateArgs;
66
+ /**
67
+ * Recursively walk directory and collect matching files
68
+ */
69
+ private walkDirectory;
70
+ }
@@ -0,0 +1,122 @@
1
+ import type { CallToolResult, ToolInputSchema } from '../../types';
2
+ import { BaseTool } from '../base';
3
+ export declare function downloadRipgrep(version?: string): Promise<string | null>;
4
+ export declare function ensureRipgrepBinary(version?: string): Promise<string | null>;
5
+ export declare function getRipgrepPath(): Promise<string | null>;
6
+ /**
7
+ * Output modes for grep results
8
+ */
9
+ export type GrepOutputMode = 'content' | 'files_with_matches' | 'count';
10
+ /**
11
+ * Result of a grep operation
12
+ */
13
+ export interface GrepResult {
14
+ /** Command exit code */
15
+ exitCode: number | null;
16
+ /** Backend used for the search */
17
+ engine?: 'rg' | 'grep' | 'js';
18
+ /** Search output */
19
+ output: string;
20
+ /** Whether output was truncated */
21
+ truncated: boolean;
22
+ /** Whether search timed out */
23
+ timedOut: boolean;
24
+ /** Number of matches found (when available) */
25
+ matchCount?: number;
26
+ }
27
+ /**
28
+ * Arguments for the Grep tool
29
+ */
30
+ export interface GrepArgs {
31
+ /** The regular expression pattern to search for */
32
+ 'pattern': string;
33
+ /** File or directory to search in */
34
+ 'path'?: string;
35
+ /** Glob pattern to filter files */
36
+ 'glob'?: string;
37
+ /** Output mode */
38
+ 'output_mode'?: GrepOutputMode;
39
+ /** Lines before match */
40
+ '-B'?: number;
41
+ /** Lines after match */
42
+ '-A'?: number;
43
+ /** Lines before and after match */
44
+ '-C'?: number;
45
+ /** Show line numbers */
46
+ '-n'?: boolean;
47
+ /** Case insensitive search */
48
+ '-i'?: boolean;
49
+ /** File type to search */
50
+ 'type'?: string;
51
+ /** Limit output to first N lines/entries */
52
+ 'head_limit'?: number;
53
+ /** Skip first N lines/entries */
54
+ 'offset'?: number;
55
+ /** Enable multiline mode */
56
+ 'multiline'?: boolean;
57
+ }
58
+ /**
59
+ * Tool for searching files using ripgrep.
60
+ *
61
+ * A powerful search tool built on ripgrep that supports regex patterns,
62
+ * multiple output modes, and various filtering options.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const grepTool = new GrepTool()
67
+ * const result = await grepTool.execute({
68
+ * pattern: 'function\\s+\\w+',
69
+ * path: './src',
70
+ * type: 'ts'
71
+ * })
72
+ * ```
73
+ */
74
+ export declare class GrepTool extends BaseTool {
75
+ readonly name = "Grep";
76
+ readonly description = "A powerful search tool built on ripgrep.\n\nUsage notes:\n- Supports full regex syntax (e.g., \"log.*Error\", \"function\\s+\\w+\")\n- Filter files with glob parameter (e.g., \"*.js\", \"**/*.tsx\") or type parameter (e.g., \"js\", \"py\", \"rust\")\n- Output modes: \"content\" shows matching lines, \"files_with_matches\" shows only file paths (default), \"count\" shows match counts\n- Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use `interface\\{\\}` to find `interface{}` in Go code)\n- Multiline matching: By default patterns match within single lines only. For cross-line patterns, use multiline: true\n- If ripgrep is not available, this tool falls back to a JS-based search (slower). You can opt into downloading a ripgrep binary via the GrepTool constructor option `allowDownload: true`.";
77
+ readonly parameters: ToolInputSchema;
78
+ /** Current working directory for search */
79
+ private cwd;
80
+ /** Path to ripgrep binary */
81
+ private rgPath;
82
+ /**
83
+ * If true, the tool may download a ripgrep binary when none is available.
84
+ *
85
+ * Default: false (falls back to a JS-based search instead).
86
+ */
87
+ private allowDownload;
88
+ constructor(options?: {
89
+ cwd?: string;
90
+ rgPath?: string;
91
+ allowDownload?: boolean;
92
+ });
93
+ /**
94
+ * Set the current working directory
95
+ */
96
+ setCwd(cwd: string): void;
97
+ /**
98
+ * Get the current working directory
99
+ */
100
+ getCwd(): string;
101
+ /**
102
+ * Execute grep search
103
+ *
104
+ * @param args - Grep arguments
105
+ * @returns MCP-compliant CallToolResult with search results
106
+ */
107
+ execute(args: Record<string, unknown>): Promise<CallToolResult>;
108
+ /**
109
+ * Validate and parse arguments
110
+ */
111
+ private validateArgs;
112
+ /**
113
+ * Build ripgrep command arguments
114
+ */
115
+ private buildRgArgs;
116
+ /**
117
+ * Run ripgrep command
118
+ */
119
+ private runRipgrep;
120
+ private runJsSearch;
121
+ private runSystemGrep;
122
+ }
@@ -0,0 +1,30 @@
1
+ export { AskUserTool } from './askUser';
2
+ export type { AskUserArgs, AskUserResult, Question, QuestionOption } from './askUser';
3
+ export { AstGrepReplaceTool } from './astGrepReplace';
4
+ export type { AstGrepReplaceArgs, AstGrepReplaceResult } from './astGrepReplace';
5
+ export { AstGrepSearchTool } from './astGrepSearch';
6
+ export type { AstGrepMatch, AstGrepSearchArgs, AstGrepSearchResult } from './astGrepSearch';
7
+ export { BashTool } from './bash';
8
+ export type { BashArgs, BashResult } from './bash';
9
+ export { EditTool } from './edit';
10
+ export type { EditArgs, EditResult } from './edit';
11
+ export { EnterPlanModeTool } from './enterPlanMode';
12
+ export type { EnterPlanModeArgs, EnterPlanModeResult } from './enterPlanMode';
13
+ export { ExitPlanModeTool } from './exitPlanMode';
14
+ export type { ExitPlanModeArgs, ExitPlanModeResult } from './exitPlanMode';
15
+ export { GlobTool } from './glob';
16
+ export type { GlobArgs, GlobResult } from './glob';
17
+ export { GrepTool } from './grep';
18
+ export type { GrepArgs, GrepOutputMode, GrepResult } from './grep';
19
+ export { ReadTool } from './read';
20
+ export type { ReadArgs, ReadResult } from './read';
21
+ export { TaskTool } from './task';
22
+ export type { SubagentDefinition, TaskArgs, TaskExecutor, TaskResult } from './task';
23
+ export { TodoPlanTool } from './todoPlan';
24
+ export type { TodoPlanArgs, TodoPlanResult } from './todoPlan';
25
+ export { TodoWriteTool } from './todoWrite';
26
+ export type { TodoItem, TodoStatus, TodoWriteArgs, TodoWriteResult } from './todoWrite';
27
+ export { WebSearchTool } from './webSearch';
28
+ export type { SearchResultItem, WebSearchArgs, WebSearchResult } from './webSearch';
29
+ export { WriteTool } from './write';
30
+ export type { WriteArgs, WriteResult } from './write';
@@ -0,0 +1,127 @@
1
+ import type { CallToolResult, ToolInputSchema } from '../../types';
2
+ import { BaseTool } from '../base';
3
+ /**
4
+ * Result of a file read operation
5
+ */
6
+ export interface ReadResult {
7
+ /** File content with line numbers */
8
+ content: string;
9
+ /** Total number of lines in file */
10
+ totalLines: number;
11
+ /** Number of lines returned */
12
+ linesReturned: number;
13
+ /** Starting line number (1-based) */
14
+ startLine: number;
15
+ /** Whether any lines were truncated */
16
+ truncated: boolean;
17
+ /** File size in bytes */
18
+ fileSize: number;
19
+ /** Whether this is a binary/image file */
20
+ isBinary: boolean;
21
+ /** MIME type if detected */
22
+ mimeType?: string;
23
+ }
24
+ /**
25
+ * Arguments for the Read tool
26
+ */
27
+ export interface ReadArgs {
28
+ /** The absolute path to the file to read */
29
+ file_path: string;
30
+ /** The line number to start reading from (1-based) */
31
+ offset?: number;
32
+ /** The number of lines to read */
33
+ limit?: number;
34
+ }
35
+ /**
36
+ * Tool for reading files from the filesystem.
37
+ *
38
+ * This tool reads files with line number formatting, supporting
39
+ * offset/limit for large files and detecting binary content.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const readTool = new ReadTool()
44
+ * const result = await readTool.execute({
45
+ * file_path: '/path/to/file.ts',
46
+ * offset: 100,
47
+ * limit: 50
48
+ * })
49
+ * ```
50
+ *
51
+ * @example Restrict reads to a specific directory
52
+ * ```typescript
53
+ * const readTool = new ReadTool({
54
+ * cwd: '/app/output',
55
+ * restrictToDirectory: true
56
+ * })
57
+ * // All paths will be resolved relative to /app/output
58
+ * // Absolute paths and path traversal (../) will be blocked
59
+ * ```
60
+ */
61
+ export declare class ReadTool extends BaseTool {
62
+ readonly name = "Read";
63
+ /** Current working directory for resolving relative paths */
64
+ private _cwd;
65
+ /** Allowed directory for file operations (if set, restricts reads to this directory) */
66
+ private _allowedDirectory?;
67
+ constructor(options?: {
68
+ cwd?: string;
69
+ /** If set, restricts all file reads to this directory. Paths outside will be rejected. */
70
+ allowedDirectory?: string;
71
+ });
72
+ /**
73
+ * Dynamic description that includes allowed directory info if configured
74
+ */
75
+ get description(): string;
76
+ /**
77
+ * Dynamic parameters that include allowed directory info if configured
78
+ */
79
+ get parameters(): ToolInputSchema;
80
+ /**
81
+ * Set the current working directory
82
+ */
83
+ setCwd(cwd: string): void;
84
+ /**
85
+ * Get the current working directory
86
+ */
87
+ getCwd(): string;
88
+ /**
89
+ * Set the allowed directory for file operations
90
+ */
91
+ setAllowedDirectory(dir: string | undefined): void;
92
+ /**
93
+ * Get the allowed directory for file operations
94
+ */
95
+ getAllowedDirectory(): string | undefined;
96
+ /**
97
+ * Execute file read
98
+ *
99
+ * @param args - Read arguments
100
+ * @returns MCP-compliant CallToolResult with file content
101
+ */
102
+ execute(args: Record<string, unknown>): Promise<CallToolResult>;
103
+ /**
104
+ * Validate and parse arguments
105
+ */
106
+ private validateArgs;
107
+ /**
108
+ * Handle binary file (images, PDFs, etc.)
109
+ */
110
+ private handleBinaryFile;
111
+ /**
112
+ * Handle Jupyter notebook file
113
+ */
114
+ private handleJupyterNotebook;
115
+ /**
116
+ * Handle text file
117
+ */
118
+ private handleTextFile;
119
+ /**
120
+ * Format output with line numbers and apply offset/limit
121
+ */
122
+ private formatOutput;
123
+ /**
124
+ * Format file size for display
125
+ */
126
+ private formatSize;
127
+ }
@@ -0,0 +1,111 @@
1
+ import type { CallToolResult, ToolInputSchema } from '../../types';
2
+ import { BaseTool } from '../base';
3
+ /**
4
+ * Definition of an available skill
5
+ */
6
+ export interface SkillDefinition {
7
+ /** Unique name of the skill */
8
+ name: string;
9
+ /** Description of what the skill does */
10
+ description: string;
11
+ /** Additional metadata (extensible for future use) */
12
+ [key: string]: unknown;
13
+ }
14
+ /**
15
+ * Result of a skill execution
16
+ */
17
+ export interface SkillResult {
18
+ /** Whether the skill execution was successful */
19
+ success: boolean;
20
+ /** The skill that was invoked */
21
+ skill: string;
22
+ /** Arguments passed to the skill */
23
+ args?: string;
24
+ /** Result data from the skill execution */
25
+ data?: unknown;
26
+ /** Error message if execution failed */
27
+ error?: string;
28
+ }
29
+ /**
30
+ * Arguments for the Skill tool
31
+ */
32
+ export interface SkillArgs {
33
+ /** The skill name to invoke */
34
+ skill: string;
35
+ /** Optional arguments for the skill */
36
+ args?: string;
37
+ }
38
+ /**
39
+ * Skill executor function type
40
+ */
41
+ export type SkillExecutor = (skill: string, args?: string) => Promise<unknown>;
42
+ /**
43
+ * @experimental
44
+ * Tool for executing skills within a conversation.
45
+ *
46
+ * This tool allows the agent to invoke specialized skills that provide
47
+ * domain-specific capabilities. The available skills are configured
48
+ * at construction time.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const skillTool = new SkillTool({
53
+ * skills: [
54
+ * { name: 'pdf', description: 'PDF manipulation toolkit' },
55
+ * { name: 'commit', description: 'Git commit helper' }
56
+ * ],
57
+ * executor: async (skill, args) => {
58
+ * // Handle skill execution
59
+ * }
60
+ * })
61
+ * ```
62
+ */
63
+ export declare class SkillTool extends BaseTool {
64
+ readonly name = "Skill";
65
+ /** Dynamic description built from available skills */
66
+ readonly description: string;
67
+ readonly parameters: ToolInputSchema;
68
+ /** Available skills */
69
+ private skills;
70
+ /** Skill executor function */
71
+ private executor?;
72
+ constructor(options?: {
73
+ skills?: SkillDefinition[];
74
+ executor?: SkillExecutor;
75
+ });
76
+ /**
77
+ * Register a new skill
78
+ */
79
+ registerSkill(skill: SkillDefinition): void;
80
+ /**
81
+ * Unregister a skill
82
+ */
83
+ unregisterSkill(name: string): boolean;
84
+ /**
85
+ * Get all available skills
86
+ */
87
+ getSkills(): SkillDefinition[];
88
+ /**
89
+ * Check if a skill is available
90
+ */
91
+ hasSkill(name: string): boolean;
92
+ /**
93
+ * Set the skill executor
94
+ */
95
+ setExecutor(executor: SkillExecutor): void;
96
+ /**
97
+ * Execute a skill
98
+ *
99
+ * @param args - Skill arguments
100
+ * @returns MCP-compliant CallToolResult with skill execution result
101
+ */
102
+ execute(args: Record<string, unknown>): Promise<CallToolResult>;
103
+ /**
104
+ * Validate and parse arguments
105
+ */
106
+ private validateArgs;
107
+ /**
108
+ * Build description from available skills
109
+ */
110
+ private buildDescription;
111
+ }