@codeany/open-agent-sdk 0.2.1 → 0.2.3

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 (57) hide show
  1. package/dist/engine.d.ts.map +1 -1
  2. package/dist/engine.js +2 -0
  3. package/dist/engine.js.map +1 -1
  4. package/package.json +5 -6
  5. package/src/agent.ts +0 -516
  6. package/src/engine.ts +0 -630
  7. package/src/hooks.ts +0 -261
  8. package/src/index.ts +0 -426
  9. package/src/mcp/client.ts +0 -150
  10. package/src/providers/anthropic.ts +0 -60
  11. package/src/providers/index.ts +0 -34
  12. package/src/providers/openai.ts +0 -315
  13. package/src/providers/types.ts +0 -85
  14. package/src/sdk-mcp-server.ts +0 -78
  15. package/src/session.ts +0 -227
  16. package/src/skills/bundled/commit.ts +0 -38
  17. package/src/skills/bundled/debug.ts +0 -48
  18. package/src/skills/bundled/index.ts +0 -28
  19. package/src/skills/bundled/review.ts +0 -41
  20. package/src/skills/bundled/simplify.ts +0 -51
  21. package/src/skills/bundled/test.ts +0 -43
  22. package/src/skills/index.ts +0 -25
  23. package/src/skills/registry.ts +0 -133
  24. package/src/skills/types.ts +0 -99
  25. package/src/tool-helper.ts +0 -127
  26. package/src/tools/agent-tool.ts +0 -164
  27. package/src/tools/ask-user.ts +0 -79
  28. package/src/tools/bash.ts +0 -75
  29. package/src/tools/config-tool.ts +0 -89
  30. package/src/tools/cron-tools.ts +0 -153
  31. package/src/tools/edit.ts +0 -74
  32. package/src/tools/glob.ts +0 -77
  33. package/src/tools/grep.ts +0 -168
  34. package/src/tools/index.ts +0 -240
  35. package/src/tools/lsp-tool.ts +0 -163
  36. package/src/tools/mcp-resource-tools.ts +0 -125
  37. package/src/tools/notebook-edit.ts +0 -93
  38. package/src/tools/plan-tools.ts +0 -88
  39. package/src/tools/read.ts +0 -73
  40. package/src/tools/send-message.ts +0 -96
  41. package/src/tools/skill-tool.ts +0 -133
  42. package/src/tools/task-tools.ts +0 -290
  43. package/src/tools/team-tools.ts +0 -128
  44. package/src/tools/todo-tool.ts +0 -112
  45. package/src/tools/tool-search.ts +0 -87
  46. package/src/tools/types.ts +0 -66
  47. package/src/tools/web-fetch.ts +0 -66
  48. package/src/tools/web-search.ts +0 -86
  49. package/src/tools/worktree-tools.ts +0 -140
  50. package/src/tools/write.ts +0 -42
  51. package/src/types.ts +0 -486
  52. package/src/utils/compact.ts +0 -207
  53. package/src/utils/context.ts +0 -191
  54. package/src/utils/fileCache.ts +0 -148
  55. package/src/utils/messages.ts +0 -195
  56. package/src/utils/retry.ts +0 -140
  57. package/src/utils/tokens.ts +0 -145
@@ -1,89 +0,0 @@
1
- /**
2
- * ConfigTool - Dynamic configuration management
3
- *
4
- * Get/set global configuration and session settings.
5
- */
6
-
7
- import type { ToolDefinition, ToolResult } from '../types.js'
8
-
9
- // In-memory config store
10
- const configStore = new Map<string, unknown>()
11
-
12
- /**
13
- * Get a config value.
14
- */
15
- export function getConfig(key: string): unknown {
16
- return configStore.get(key)
17
- }
18
-
19
- /**
20
- * Set a config value.
21
- */
22
- export function setConfig(key: string, value: unknown): void {
23
- configStore.set(key, value)
24
- }
25
-
26
- /**
27
- * Clear all config.
28
- */
29
- export function clearConfig(): void {
30
- configStore.clear()
31
- }
32
-
33
- export const ConfigTool: ToolDefinition = {
34
- name: 'Config',
35
- description: 'Get or set configuration values. Supports session-scoped settings.',
36
- inputSchema: {
37
- type: 'object',
38
- properties: {
39
- action: {
40
- type: 'string',
41
- enum: ['get', 'set', 'list'],
42
- description: 'Operation to perform',
43
- },
44
- key: { type: 'string', description: 'Config key' },
45
- value: { description: 'Config value (for set)' },
46
- },
47
- required: ['action'],
48
- },
49
- isReadOnly: () => false,
50
- isConcurrencySafe: () => true,
51
- isEnabled: () => true,
52
- async prompt() { return 'Manage configuration settings.' },
53
- async call(input: any): Promise<ToolResult> {
54
- switch (input.action) {
55
- case 'get': {
56
- if (!input.key) {
57
- return { type: 'tool_result', tool_use_id: '', content: 'key required for get', is_error: true }
58
- }
59
- const value = configStore.get(input.key)
60
- return {
61
- type: 'tool_result',
62
- tool_use_id: '',
63
- content: value !== undefined ? JSON.stringify(value) : `Config key "${input.key}" not found`,
64
- }
65
- }
66
- case 'set': {
67
- if (!input.key) {
68
- return { type: 'tool_result', tool_use_id: '', content: 'key required for set', is_error: true }
69
- }
70
- configStore.set(input.key, input.value)
71
- return {
72
- type: 'tool_result',
73
- tool_use_id: '',
74
- content: `Config set: ${input.key} = ${JSON.stringify(input.value)}`,
75
- }
76
- }
77
- case 'list': {
78
- const entries = Array.from(configStore.entries())
79
- if (entries.length === 0) {
80
- return { type: 'tool_result', tool_use_id: '', content: 'No config values set.' }
81
- }
82
- const lines = entries.map(([k, v]) => `${k} = ${JSON.stringify(v)}`)
83
- return { type: 'tool_result', tool_use_id: '', content: lines.join('\n') }
84
- }
85
- default:
86
- return { type: 'tool_result', tool_use_id: '', content: `Unknown action: ${input.action}`, is_error: true }
87
- }
88
- },
89
- }
@@ -1,153 +0,0 @@
1
- /**
2
- * Cron/Scheduling Tools
3
- *
4
- * CronCreate, CronDelete, CronList - Schedule recurring tasks.
5
- * RemoteTrigger - Manage remote scheduled agent triggers.
6
- */
7
-
8
- import type { ToolDefinition, ToolResult } from '../types.js'
9
-
10
- /**
11
- * Cron job definition.
12
- */
13
- export interface CronJob {
14
- id: string
15
- name: string
16
- schedule: string // cron expression
17
- command: string
18
- enabled: boolean
19
- createdAt: string
20
- lastRunAt?: string
21
- nextRunAt?: string
22
- }
23
-
24
- // In-memory cron store
25
- const cronStore = new Map<string, CronJob>()
26
- let cronCounter = 0
27
-
28
- /**
29
- * Get all cron jobs.
30
- */
31
- export function getAllCronJobs(): CronJob[] {
32
- return Array.from(cronStore.values())
33
- }
34
-
35
- /**
36
- * Clear all cron jobs.
37
- */
38
- export function clearCronJobs(): void {
39
- cronStore.clear()
40
- cronCounter = 0
41
- }
42
-
43
- export const CronCreateTool: ToolDefinition = {
44
- name: 'CronCreate',
45
- description: 'Create a scheduled recurring task (cron job). Supports cron expressions for scheduling.',
46
- inputSchema: {
47
- type: 'object',
48
- properties: {
49
- name: { type: 'string', description: 'Job name' },
50
- schedule: { type: 'string', description: 'Cron expression (e.g., "*/5 * * * *" for every 5 minutes)' },
51
- command: { type: 'string', description: 'Command or prompt to execute' },
52
- },
53
- required: ['name', 'schedule', 'command'],
54
- },
55
- isReadOnly: () => false,
56
- isConcurrencySafe: () => true,
57
- isEnabled: () => true,
58
- async prompt() { return 'Create a scheduled cron job.' },
59
- async call(input: any): Promise<ToolResult> {
60
- const id = `cron_${++cronCounter}`
61
- const job: CronJob = {
62
- id,
63
- name: input.name,
64
- schedule: input.schedule,
65
- command: input.command,
66
- enabled: true,
67
- createdAt: new Date().toISOString(),
68
- }
69
- cronStore.set(id, job)
70
-
71
- return {
72
- type: 'tool_result',
73
- tool_use_id: '',
74
- content: `Cron job created: ${id} "${job.name}" schedule="${job.schedule}"`,
75
- }
76
- },
77
- }
78
-
79
- export const CronDeleteTool: ToolDefinition = {
80
- name: 'CronDelete',
81
- description: 'Delete a scheduled cron job.',
82
- inputSchema: {
83
- type: 'object',
84
- properties: {
85
- id: { type: 'string', description: 'Cron job ID to delete' },
86
- },
87
- required: ['id'],
88
- },
89
- isReadOnly: () => false,
90
- isConcurrencySafe: () => true,
91
- isEnabled: () => true,
92
- async prompt() { return 'Delete a cron job.' },
93
- async call(input: any): Promise<ToolResult> {
94
- if (!cronStore.has(input.id)) {
95
- return { type: 'tool_result', tool_use_id: '', content: `Cron job not found: ${input.id}`, is_error: true }
96
- }
97
- cronStore.delete(input.id)
98
- return { type: 'tool_result', tool_use_id: '', content: `Cron job deleted: ${input.id}` }
99
- },
100
- }
101
-
102
- export const CronListTool: ToolDefinition = {
103
- name: 'CronList',
104
- description: 'List all scheduled cron jobs.',
105
- inputSchema: { type: 'object', properties: {} },
106
- isReadOnly: () => true,
107
- isConcurrencySafe: () => true,
108
- isEnabled: () => true,
109
- async prompt() { return 'List cron jobs.' },
110
- async call(): Promise<ToolResult> {
111
- const jobs = getAllCronJobs()
112
- if (jobs.length === 0) {
113
- return { type: 'tool_result', tool_use_id: '', content: 'No cron jobs scheduled.' }
114
- }
115
- const lines = jobs.map(j =>
116
- `[${j.id}] ${j.enabled ? '✓' : '✗'} "${j.name}" schedule="${j.schedule}" command="${j.command.slice(0, 50)}"`
117
- )
118
- return { type: 'tool_result', tool_use_id: '', content: lines.join('\n') }
119
- },
120
- }
121
-
122
- export const RemoteTriggerTool: ToolDefinition = {
123
- name: 'RemoteTrigger',
124
- description: 'Manage remote scheduled agent triggers. Supports list, get, create, update, and run operations.',
125
- inputSchema: {
126
- type: 'object',
127
- properties: {
128
- action: {
129
- type: 'string',
130
- enum: ['list', 'get', 'create', 'update', 'run'],
131
- description: 'Operation to perform',
132
- },
133
- id: { type: 'string', description: 'Trigger ID (for get/update/run)' },
134
- name: { type: 'string', description: 'Trigger name (for create)' },
135
- schedule: { type: 'string', description: 'Cron schedule (for create/update)' },
136
- prompt: { type: 'string', description: 'Agent prompt (for create/update)' },
137
- },
138
- required: ['action'],
139
- },
140
- isReadOnly: () => false,
141
- isConcurrencySafe: () => true,
142
- isEnabled: () => true,
143
- async prompt() { return 'Manage remote agent triggers.' },
144
- async call(input: any): Promise<ToolResult> {
145
- // RemoteTrigger operations are typically handled by the remote backend
146
- // In standalone SDK mode, we provide a stub implementation
147
- return {
148
- type: 'tool_result',
149
- tool_use_id: '',
150
- content: `RemoteTrigger ${input.action}: This feature requires a connected remote backend. In standalone SDK mode, use CronCreate/CronList/CronDelete for local scheduling.`,
151
- }
152
- },
153
- }
package/src/tools/edit.ts DELETED
@@ -1,74 +0,0 @@
1
- /**
2
- * FileEditTool - Precise string replacement in files
3
- */
4
-
5
- import { readFile, writeFile } from 'fs/promises'
6
- import { resolve } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const FileEditTool = defineTool({
10
- name: 'Edit',
11
- description: 'Perform exact string replacements in files. The old_string must match exactly (including whitespace and indentation). Use replace_all to change every occurrence.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- file_path: {
16
- type: 'string',
17
- description: 'The absolute path to the file to modify',
18
- },
19
- old_string: {
20
- type: 'string',
21
- description: 'The exact text to find and replace',
22
- },
23
- new_string: {
24
- type: 'string',
25
- description: 'The replacement text',
26
- },
27
- replace_all: {
28
- type: 'boolean',
29
- description: 'Replace all occurrences (default false)',
30
- },
31
- },
32
- required: ['file_path', 'old_string', 'new_string'],
33
- },
34
- isReadOnly: false,
35
- isConcurrencySafe: false,
36
- async call(input, context) {
37
- const filePath = resolve(context.cwd, input.file_path)
38
- const { old_string, new_string, replace_all } = input
39
-
40
- if (old_string === new_string) {
41
- return { data: 'Error: old_string and new_string are identical', is_error: true }
42
- }
43
-
44
- try {
45
- let content = await readFile(filePath, 'utf-8')
46
-
47
- if (!content.includes(old_string)) {
48
- return { data: `Error: old_string not found in ${filePath}. Make sure it matches exactly including whitespace.`, is_error: true }
49
- }
50
-
51
- if (!replace_all) {
52
- // Check uniqueness
53
- const count = content.split(old_string).length - 1
54
- if (count > 1) {
55
- return {
56
- data: `Error: old_string appears ${count} times in the file. Provide more context to make it unique, or set replace_all: true.`,
57
- is_error: true,
58
- }
59
- }
60
- content = content.replace(old_string, new_string)
61
- } else {
62
- content = content.split(old_string).join(new_string)
63
- }
64
-
65
- await writeFile(filePath, content, 'utf-8')
66
- return `File edited: ${filePath}`
67
- } catch (err: any) {
68
- if (err.code === 'ENOENT') {
69
- return { data: `Error: File not found: ${filePath}`, is_error: true }
70
- }
71
- return { data: `Error editing file: ${err.message}`, is_error: true }
72
- }
73
- },
74
- })
package/src/tools/glob.ts DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * GlobTool - File pattern matching
3
- */
4
-
5
- import { resolve } from 'path'
6
- import { defineTool } from './types.js'
7
-
8
- export const GlobTool = defineTool({
9
- name: 'Glob',
10
- description: 'Find files matching a glob pattern. Returns matching file paths sorted by modification time. Supports patterns like "**/*.ts", "src/**/*.js".',
11
- inputSchema: {
12
- type: 'object',
13
- properties: {
14
- pattern: {
15
- type: 'string',
16
- description: 'The glob pattern to match files against',
17
- },
18
- path: {
19
- type: 'string',
20
- description: 'The directory to search in (defaults to cwd)',
21
- },
22
- },
23
- required: ['pattern'],
24
- },
25
- isReadOnly: true,
26
- isConcurrencySafe: true,
27
- async call(input, context) {
28
- const searchDir = input.path ? resolve(context.cwd, input.path) : context.cwd
29
- const { pattern } = input
30
-
31
- try {
32
- // Use Node.js glob (available in Node 22+) or fall back to bash find
33
- const { glob } = await import('fs/promises')
34
-
35
- // @ts-ignore - glob is available in Node 22+
36
- if (typeof glob === 'function') {
37
- const matches: string[] = []
38
- // @ts-ignore
39
- for await (const entry of glob(pattern, { cwd: searchDir })) {
40
- matches.push(entry)
41
- if (matches.length >= 500) break
42
- }
43
- if (matches.length === 0) {
44
- return `No files matching pattern "${pattern}" in ${searchDir}`
45
- }
46
- return matches.join('\n')
47
- }
48
- } catch {
49
- // Fall through to bash-based approach
50
- }
51
-
52
- // Fallback: use bash find/glob
53
- const { spawn } = await import('child_process')
54
- return new Promise<string>((resolvePromise) => {
55
- // Use bash glob expansion or find
56
- const cmd = `shopt -s globstar nullglob 2>/dev/null; cd ${JSON.stringify(searchDir)} && ls -1d ${pattern} 2>/dev/null | head -500`
57
- const proc = spawn('bash', ['-c', cmd], {
58
- cwd: searchDir,
59
- timeout: 30000,
60
- })
61
-
62
- const chunks: Buffer[] = []
63
- proc.stdout?.on('data', (d: Buffer) => chunks.push(d))
64
- proc.on('close', () => {
65
- const result = Buffer.concat(chunks).toString('utf-8').trim()
66
- if (!result) {
67
- resolvePromise(`No files matching pattern "${pattern}" in ${searchDir}`)
68
- } else {
69
- resolvePromise(result)
70
- }
71
- })
72
- proc.on('error', () => {
73
- resolvePromise(`Error searching for files with pattern "${pattern}"`)
74
- })
75
- })
76
- },
77
- })
package/src/tools/grep.ts DELETED
@@ -1,168 +0,0 @@
1
- /**
2
- * GrepTool - Search file contents using regex
3
- */
4
-
5
- import { spawn } from 'child_process'
6
- import { resolve } from 'path'
7
- import { defineTool } from './types.js'
8
-
9
- export const GrepTool = defineTool({
10
- name: 'Grep',
11
- description: 'Search file contents using regex patterns. Uses ripgrep (rg) if available, falls back to grep. Supports file type filtering and context lines.',
12
- inputSchema: {
13
- type: 'object',
14
- properties: {
15
- pattern: {
16
- type: 'string',
17
- description: 'The regex pattern to search for',
18
- },
19
- path: {
20
- type: 'string',
21
- description: 'File or directory to search in (defaults to cwd)',
22
- },
23
- glob: {
24
- type: 'string',
25
- description: 'Glob pattern to filter files (e.g., "*.ts", "*.{js,jsx}")',
26
- },
27
- type: {
28
- type: 'string',
29
- description: 'File type filter (e.g., "ts", "py", "js")',
30
- },
31
- output_mode: {
32
- type: 'string',
33
- enum: ['content', 'files_with_matches', 'count'],
34
- description: 'Output mode (default: files_with_matches)',
35
- },
36
- '-i': {
37
- type: 'boolean',
38
- description: 'Case insensitive search',
39
- },
40
- '-n': {
41
- type: 'boolean',
42
- description: 'Show line numbers (default: true)',
43
- },
44
- '-A': { type: 'number', description: 'Lines after match' },
45
- '-B': { type: 'number', description: 'Lines before match' },
46
- '-C': { type: 'number', description: 'Context lines' },
47
- context: { type: 'number', description: 'Context lines (alias for -C)' },
48
- head_limit: { type: 'number', description: 'Limit output entries (default: 250)' },
49
- },
50
- required: ['pattern'],
51
- },
52
- isReadOnly: true,
53
- isConcurrencySafe: true,
54
- async call(input, context) {
55
- const searchPath = input.path ? resolve(context.cwd, input.path) : context.cwd
56
- const outputMode = input.output_mode || 'files_with_matches'
57
- const headLimit = input.head_limit ?? 250
58
-
59
- // Build rg command (fall back to grep if rg unavailable)
60
- const args: string[] = []
61
-
62
- // Try ripgrep first
63
- let cmd = 'rg'
64
-
65
- if (outputMode === 'files_with_matches') {
66
- args.push('--files-with-matches')
67
- } else if (outputMode === 'count') {
68
- args.push('--count')
69
- } else {
70
- // content mode
71
- if (input['-n'] !== false) args.push('--line-number')
72
- }
73
-
74
- if (input['-i']) args.push('--ignore-case')
75
- if (input['-A']) args.push('-A', String(input['-A']))
76
- if (input['-B']) args.push('-B', String(input['-B']))
77
- const ctx = input['-C'] ?? input.context
78
- if (ctx) args.push('-C', String(ctx))
79
- if (input.glob) args.push('--glob', input.glob)
80
- if (input.type) args.push('--type', input.type)
81
-
82
- args.push('--', input.pattern, searchPath)
83
-
84
- return new Promise<string>((resolvePromise) => {
85
- const proc = spawn(cmd, args, {
86
- cwd: context.cwd,
87
- timeout: 30000,
88
- })
89
-
90
- const chunks: Buffer[] = []
91
- const errChunks: Buffer[] = []
92
- proc.stdout?.on('data', (d: Buffer) => chunks.push(d))
93
- proc.stderr?.on('data', (d: Buffer) => errChunks.push(d))
94
-
95
- proc.on('close', (code) => {
96
- let result = Buffer.concat(chunks).toString('utf-8').trim()
97
-
98
- if (!result && code !== 0) {
99
- // Try fallback to grep
100
- const grepArgs = ['-r']
101
- if (input['-i']) grepArgs.push('-i')
102
- if (outputMode === 'files_with_matches') grepArgs.push('-l')
103
- if (outputMode === 'count') grepArgs.push('-c')
104
- if (outputMode === 'content' && input['-n'] !== false) grepArgs.push('-n')
105
- if (input.glob) grepArgs.push('--include', input.glob)
106
- grepArgs.push('--', input.pattern, searchPath)
107
-
108
- const grepProc = spawn('grep', grepArgs, {
109
- cwd: context.cwd,
110
- timeout: 30000,
111
- })
112
-
113
- const grepChunks: Buffer[] = []
114
- grepProc.stdout?.on('data', (d: Buffer) => grepChunks.push(d))
115
- grepProc.on('close', () => {
116
- const grepResult = Buffer.concat(grepChunks).toString('utf-8').trim()
117
- if (!grepResult) {
118
- resolvePromise(`No matches found for pattern "${input.pattern}"`)
119
- } else {
120
- // Apply head limit
121
- const lines = grepResult.split('\n')
122
- if (headLimit > 0 && lines.length > headLimit) {
123
- resolvePromise(lines.slice(0, headLimit).join('\n') + `\n... (${lines.length - headLimit} more)`)
124
- } else {
125
- resolvePromise(grepResult)
126
- }
127
- }
128
- })
129
- grepProc.on('error', () => {
130
- resolvePromise(`No matches found for pattern "${input.pattern}"`)
131
- })
132
- return
133
- }
134
-
135
- if (!result) {
136
- resolvePromise(`No matches found for pattern "${input.pattern}"`)
137
- return
138
- }
139
-
140
- // Apply head limit
141
- const lines = result.split('\n')
142
- if (headLimit > 0 && lines.length > headLimit) {
143
- result = lines.slice(0, headLimit).join('\n') + `\n... (${lines.length - headLimit} more)`
144
- }
145
-
146
- resolvePromise(result)
147
- })
148
-
149
- proc.on('error', () => {
150
- // rg not found, try grep directly
151
- const grepArgs = ['-r', '-n', '--', input.pattern, searchPath]
152
- const grepProc = spawn('grep', grepArgs, {
153
- cwd: context.cwd,
154
- timeout: 30000,
155
- })
156
- const grepChunks: Buffer[] = []
157
- grepProc.stdout?.on('data', (d: Buffer) => grepChunks.push(d))
158
- grepProc.on('close', () => {
159
- const grepResult = Buffer.concat(grepChunks).toString('utf-8').trim()
160
- resolvePromise(grepResult || `No matches found for pattern "${input.pattern}"`)
161
- })
162
- grepProc.on('error', () => {
163
- resolvePromise(`Error: neither rg nor grep available`)
164
- })
165
- })
166
- })
167
- },
168
- })