concevent-ai-agent-sdk 2.2.0 → 2.3.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.
- package/README.md +279 -0
- package/dist/core/orchestrator.d.ts.map +1 -1
- package/dist/core/orchestrator.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/bash-output.d.ts +19 -0
- package/dist/tools/bash-output.d.ts.map +1 -0
- package/dist/tools/bash-output.js +47 -0
- package/dist/tools/bash-output.js.map +1 -0
- package/dist/tools/bash.d.ts +25 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +79 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit.d.ts +28 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +97 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +25 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +88 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +31 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +195 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +85 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +141 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/kill-bash.d.ts +19 -0
- package/dist/tools/kill-bash.d.ts.map +1 -0
- package/dist/tools/kill-bash.js +49 -0
- package/dist/tools/kill-bash.js.map +1 -0
- package/dist/tools/read.d.ts +25 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +103 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/task.d.ts +25 -0
- package/dist/tools/task.d.ts.map +1 -0
- package/dist/tools/task.js +71 -0
- package/dist/tools/task.js.map +1 -0
- package/dist/tools/todo-write.d.ts +46 -0
- package/dist/tools/todo-write.d.ts.map +1 -0
- package/dist/tools/todo-write.js +151 -0
- package/dist/tools/todo-write.js.map +1 -0
- package/dist/tools/types.d.ts +147 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +16 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/utils/index.d.ts +3 -0
- package/dist/tools/utils/index.d.ts.map +1 -0
- package/dist/tools/utils/index.js +3 -0
- package/dist/tools/utils/index.js.map +1 -0
- package/dist/tools/utils/path.d.ts +40 -0
- package/dist/tools/utils/path.d.ts.map +1 -0
- package/dist/tools/utils/path.js +146 -0
- package/dist/tools/utils/path.js.map +1 -0
- package/dist/tools/utils/shell.d.ts +49 -0
- package/dist/tools/utils/shell.d.ts.map +1 -0
- package/dist/tools/utils/shell.js +232 -0
- package/dist/tools/utils/shell.js.map +1 -0
- package/dist/tools/write.d.ts +22 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +70 -0
- package/dist/tools/write.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
3
|
+
/**
|
|
4
|
+
* Schema for a single todo item
|
|
5
|
+
*/
|
|
6
|
+
const todoItemSchema = z.object({
|
|
7
|
+
id: z.string().describe('Unique identifier for the todo item.'),
|
|
8
|
+
content: z.string().max(200).describe('Description of the todo item. Maximum 200 characters.'),
|
|
9
|
+
status: z
|
|
10
|
+
.enum(['pending', 'in_progress', 'completed', 'cancelled'])
|
|
11
|
+
.describe('Current status of the todo item.'),
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Schema for the TodoWrite tool parameters
|
|
15
|
+
*/
|
|
16
|
+
export const todoWriteSchema = z.object({
|
|
17
|
+
todos: z
|
|
18
|
+
.array(todoItemSchema)
|
|
19
|
+
.min(1)
|
|
20
|
+
.describe('Array of todo items to write. Each item must have id, content, and status.'),
|
|
21
|
+
merge: z
|
|
22
|
+
.boolean()
|
|
23
|
+
.optional()
|
|
24
|
+
.default(false)
|
|
25
|
+
.describe('If true, merge with existing todos (update by ID). If false, replace all todos.'),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* In-memory todo storage implementation
|
|
29
|
+
*/
|
|
30
|
+
class InMemoryTodoStorage {
|
|
31
|
+
todos = new Map();
|
|
32
|
+
async getAll() {
|
|
33
|
+
return Array.from(this.todos.values());
|
|
34
|
+
}
|
|
35
|
+
async save(todos, merge) {
|
|
36
|
+
if (!merge) {
|
|
37
|
+
this.todos.clear();
|
|
38
|
+
}
|
|
39
|
+
for (const todo of todos) {
|
|
40
|
+
this.todos.set(todo.id, todo);
|
|
41
|
+
}
|
|
42
|
+
return this.getAll();
|
|
43
|
+
}
|
|
44
|
+
async clear() {
|
|
45
|
+
this.todos.clear();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Singleton storage instance for when no custom storage is provided
|
|
49
|
+
let defaultStorage = null;
|
|
50
|
+
function getDefaultStorage() {
|
|
51
|
+
if (!defaultStorage) {
|
|
52
|
+
defaultStorage = new InMemoryTodoStorage();
|
|
53
|
+
}
|
|
54
|
+
return defaultStorage;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates the TodoWrite tool for managing todo items
|
|
58
|
+
*/
|
|
59
|
+
export function createTodoWriteTool(config = {}) {
|
|
60
|
+
const storage = config.todoStorage ?? getDefaultStorage();
|
|
61
|
+
return {
|
|
62
|
+
declaration: {
|
|
63
|
+
name: 'TodoWrite',
|
|
64
|
+
description: `Manages a structured todo list for tracking tasks.
|
|
65
|
+
|
|
66
|
+
Use this tool to:
|
|
67
|
+
- Create new todo items for complex multi-step tasks
|
|
68
|
+
- Update task status as you progress (pending → in_progress → completed)
|
|
69
|
+
- Track multiple parallel workstreams
|
|
70
|
+
- Document what has been accomplished
|
|
71
|
+
|
|
72
|
+
Status values:
|
|
73
|
+
- pending: Task not yet started
|
|
74
|
+
- in_progress: Currently working on this task
|
|
75
|
+
- completed: Task finished successfully
|
|
76
|
+
- cancelled: Task no longer needed
|
|
77
|
+
|
|
78
|
+
Best practices:
|
|
79
|
+
- Only one task should be in_progress at a time
|
|
80
|
+
- Mark tasks complete immediately after finishing
|
|
81
|
+
- Use clear, actionable descriptions`,
|
|
82
|
+
parametersJsonSchema: zodToJsonSchema(todoWriteSchema),
|
|
83
|
+
},
|
|
84
|
+
executor: async (args) => {
|
|
85
|
+
const params = todoWriteSchema.parse(args);
|
|
86
|
+
// Validate todos
|
|
87
|
+
const validatedTodos = params.todos.map((todo) => ({
|
|
88
|
+
id: todo.id,
|
|
89
|
+
content: todo.content,
|
|
90
|
+
status: todo.status,
|
|
91
|
+
}));
|
|
92
|
+
// Save todos
|
|
93
|
+
const updatedTodos = await storage.save(validatedTodos, params.merge);
|
|
94
|
+
// Generate summary
|
|
95
|
+
const summary = {
|
|
96
|
+
pending: 0,
|
|
97
|
+
in_progress: 0,
|
|
98
|
+
completed: 0,
|
|
99
|
+
cancelled: 0,
|
|
100
|
+
};
|
|
101
|
+
for (const todo of updatedTodos) {
|
|
102
|
+
summary[todo.status]++;
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
success: true,
|
|
106
|
+
todos: updatedTodos,
|
|
107
|
+
summary,
|
|
108
|
+
total: updatedTodos.length,
|
|
109
|
+
message: params.merge
|
|
110
|
+
? `Updated ${params.todos.length} todo item${params.todos.length > 1 ? 's' : ''}`
|
|
111
|
+
: `Set ${params.todos.length} todo item${params.todos.length > 1 ? 's' : ''} (replaced existing)`,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
parallel: false, // Todo writes should be sequential to avoid race conditions
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates a TodoRead tool for reading current todos (bonus utility)
|
|
119
|
+
*/
|
|
120
|
+
export function createTodoReadTool(config = {}) {
|
|
121
|
+
const storage = config.todoStorage ?? getDefaultStorage();
|
|
122
|
+
return {
|
|
123
|
+
declaration: {
|
|
124
|
+
name: 'TodoRead',
|
|
125
|
+
description: 'Reads the current todo list. Returns all todo items with their status.',
|
|
126
|
+
parametersJsonSchema: zodToJsonSchema(z.object({})),
|
|
127
|
+
},
|
|
128
|
+
executor: async () => {
|
|
129
|
+
const todos = await storage.getAll();
|
|
130
|
+
const summary = {
|
|
131
|
+
pending: 0,
|
|
132
|
+
in_progress: 0,
|
|
133
|
+
completed: 0,
|
|
134
|
+
cancelled: 0,
|
|
135
|
+
};
|
|
136
|
+
for (const todo of todos) {
|
|
137
|
+
summary[todo.status]++;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
todos,
|
|
141
|
+
summary,
|
|
142
|
+
total: todos.length,
|
|
143
|
+
message: todos.length > 0
|
|
144
|
+
? `Found ${todos.length} todo item${todos.length > 1 ? 's' : ''}`
|
|
145
|
+
: 'No todos found',
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
parallel: true, // Reading is safe to do in parallel
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=todo-write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo-write.js","sourceRoot":"","sources":["../../src/tools/todo-write.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sCAAsC,CAAC;IAC/D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,uDAAuD,CAAC;IAC9F,MAAM,EAAE,CAAC;SACN,IAAI,CAAC,CAAC,SAAS,EAAE,aAA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AC,CAAC,gBAAgB;aACvB,CAAC;QACJ,CAAC;QACD,QAAQ,EAAE,IAAI,EAAE,oCAAoC;KACrD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Status of a todo item
|
|
4
|
+
*/
|
|
5
|
+
export type TodoStatus = 'pending' | 'in_progress' | 'completed' | 'cancelled';
|
|
6
|
+
/**
|
|
7
|
+
* A single todo item
|
|
8
|
+
*/
|
|
9
|
+
export interface TodoItem {
|
|
10
|
+
id: string;
|
|
11
|
+
content: string;
|
|
12
|
+
status: TodoStatus;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Interface for custom todo storage implementations
|
|
16
|
+
*/
|
|
17
|
+
export interface TodoStorage {
|
|
18
|
+
/** Get all todos */
|
|
19
|
+
getAll(): Promise<TodoItem[]>;
|
|
20
|
+
/** Save todos (replaces all or merges based on implementation) */
|
|
21
|
+
save(todos: TodoItem[], merge: boolean): Promise<TodoItem[]>;
|
|
22
|
+
/** Clear all todos */
|
|
23
|
+
clear(): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for creating a sub-agent via the Task tool
|
|
27
|
+
*/
|
|
28
|
+
export interface TaskAgentConfig {
|
|
29
|
+
description: string;
|
|
30
|
+
prompt: string;
|
|
31
|
+
allowedTools?: string[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Factory function type for creating sub-agents
|
|
35
|
+
*/
|
|
36
|
+
export type AgentFactory = (config: TaskAgentConfig) => Promise<{
|
|
37
|
+
message: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Information about a running background process
|
|
41
|
+
*/
|
|
42
|
+
export interface ProcessInfo {
|
|
43
|
+
id: string;
|
|
44
|
+
command: string;
|
|
45
|
+
startTime: Date;
|
|
46
|
+
stdout: string;
|
|
47
|
+
stderr: string;
|
|
48
|
+
exitCode: number | null;
|
|
49
|
+
running: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Manager for background shell processes
|
|
53
|
+
*/
|
|
54
|
+
export interface ProcessManager {
|
|
55
|
+
/** Get a process by ID */
|
|
56
|
+
get(id: string): ProcessInfo | undefined;
|
|
57
|
+
/** Get all processes */
|
|
58
|
+
getAll(): ProcessInfo[];
|
|
59
|
+
/** Kill a process by ID */
|
|
60
|
+
kill(id: string): Promise<boolean>;
|
|
61
|
+
/** Clean up all processes */
|
|
62
|
+
cleanup(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Base configuration options for built-in tools (used by individual tool creators)
|
|
66
|
+
*/
|
|
67
|
+
export interface ToolConfig {
|
|
68
|
+
/** Working directory for file operations (defaults to process.cwd()) */
|
|
69
|
+
workingDirectory?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Allowed file paths for sandboxing.
|
|
72
|
+
* If specified, file operations are restricted to these paths.
|
|
73
|
+
* Supports directory paths - files under these directories are allowed.
|
|
74
|
+
*/
|
|
75
|
+
allowedPaths?: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Blocked shell command patterns.
|
|
78
|
+
* Commands matching these patterns will be rejected.
|
|
79
|
+
* Defaults to common dangerous patterns like 'rm -rf /', etc.
|
|
80
|
+
*/
|
|
81
|
+
blockedCommands?: RegExp[];
|
|
82
|
+
/** Default timeout for shell commands in milliseconds (defaults to 30000) */
|
|
83
|
+
defaultTimeout?: number;
|
|
84
|
+
/**
|
|
85
|
+
* Agent factory for the Task tool.
|
|
86
|
+
* If not provided, the Task tool will not be available.
|
|
87
|
+
*/
|
|
88
|
+
agentFactory?: AgentFactory;
|
|
89
|
+
/**
|
|
90
|
+
* Custom todo storage for the TodoWrite tool.
|
|
91
|
+
* If not provided, uses in-memory storage.
|
|
92
|
+
*/
|
|
93
|
+
todoStorage?: TodoStorage;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Configuration for creating multiple built-in tools.
|
|
97
|
+
* Extends ToolConfig and requires specifying which tools to include.
|
|
98
|
+
*/
|
|
99
|
+
export interface BuiltInToolsConfig extends ToolConfig {
|
|
100
|
+
/**
|
|
101
|
+
* Which tools to include. You must explicitly specify which tools you need.
|
|
102
|
+
* Tool names are strongly typed with autocomplete support.
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* import { createBuiltInTools } from 'concevent-ai-agent-sdk';
|
|
106
|
+
*
|
|
107
|
+
* const { tools } = createBuiltInTools({
|
|
108
|
+
* workingDirectory: '/project',
|
|
109
|
+
* tools: ['Read', 'Write', 'Glob'],
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
tools: ToolName[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Result of a shell command execution
|
|
117
|
+
*/
|
|
118
|
+
export interface ShellResult {
|
|
119
|
+
stdout: string;
|
|
120
|
+
stderr: string;
|
|
121
|
+
exitCode: number;
|
|
122
|
+
timedOut?: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Tool names constant for type-safe tool selection
|
|
126
|
+
*/
|
|
127
|
+
export declare const TOOL_NAMES: {
|
|
128
|
+
readonly READ: "Read";
|
|
129
|
+
readonly WRITE: "Write";
|
|
130
|
+
readonly EDIT: "Edit";
|
|
131
|
+
readonly GLOB: "Glob";
|
|
132
|
+
readonly GREP: "Grep";
|
|
133
|
+
readonly BASH: "Bash";
|
|
134
|
+
readonly BASH_OUTPUT: "BashOutput";
|
|
135
|
+
readonly KILL_BASH: "KillBash";
|
|
136
|
+
readonly TASK: "Task";
|
|
137
|
+
readonly TODO_WRITE: "TodoWrite";
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Union type of all valid tool name values
|
|
141
|
+
*/
|
|
142
|
+
export type ToolName = (typeof TOOL_NAMES)[keyof typeof TOOL_NAMES];
|
|
143
|
+
/**
|
|
144
|
+
* Type for tool creator functions
|
|
145
|
+
*/
|
|
146
|
+
export type ToolCreator = (config: ToolConfig, processManager?: ProcessManager) => ToolDefinition;
|
|
147
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,GAAG,WAAW,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB;IACpB,MAAM,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9B,kEAAkE;IAClE,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,sBAAsB;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAErF;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAA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AAM,OAAO,UAAU,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,cAAc,KAAK,cAAc,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool names constant for type-safe tool selection
|
|
3
|
+
*/
|
|
4
|
+
export const TOOL_NAMES = {
|
|
5
|
+
READ: 'Read',
|
|
6
|
+
WRITE: 'Write',
|
|
7
|
+
EDIT: 'Edit',
|
|
8
|
+
GLOB: 'Glob',
|
|
9
|
+
GREP: 'Grep',
|
|
10
|
+
BASH: 'Bash',
|
|
11
|
+
BASH_OUTPUT: 'BashOutput',
|
|
12
|
+
KILL_BASH: 'KillBash',
|
|
13
|
+
TASK: 'Task',
|
|
14
|
+
TODO_WRITE: 'TodoWrite',
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAyIA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,YAAY;IACzB,SAAS,EAAE,UAAU;IACrB,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,WAAW;CACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a file path and resolves it relative to the working directory.
|
|
3
|
+
* Handles cross-platform path differences.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolvePath(filePath: string, workingDirectory: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if a path is within the allowed paths (for sandboxing).
|
|
8
|
+
* Returns true if no allowedPaths are specified (no sandboxing).
|
|
9
|
+
*/
|
|
10
|
+
export declare function isPathAllowed(targetPath: string, allowedPaths?: string[]): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks for path traversal attempts.
|
|
13
|
+
* Returns true if the path is safe (no traversal detected).
|
|
14
|
+
*/
|
|
15
|
+
export declare function isPathSafe(filePath: string, workingDirectory: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Ensures a directory exists, creating it if necessary.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureDirectory(dirPath: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the relative path from the working directory.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getRelativePath(absolutePath: string, workingDirectory: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Normalizes line endings to the current platform's standard.
|
|
26
|
+
*/
|
|
27
|
+
export declare function normalizeLineEndings(content: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Simple glob pattern matching.
|
|
30
|
+
* Supports *, **, and ? wildcards.
|
|
31
|
+
*/
|
|
32
|
+
export declare function matchGlobPattern(pattern: string, filePath: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Recursively walks a directory and returns all file paths.
|
|
35
|
+
*/
|
|
36
|
+
export declare function walkDirectory(dir: string, options?: {
|
|
37
|
+
ignore?: string[];
|
|
38
|
+
maxDepth?: number;
|
|
39
|
+
}): Promise<string[]>;
|
|
40
|
+
//# sourceMappingURL=path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../src/tools/utils/path.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAO9E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAelF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAa9E;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUpE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAEtF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CA2B3E;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACd,GACL,OAAO,CAAC,MAAM,EAAE,CAAC,CA0CnB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a file path and resolves it relative to the working directory.
|
|
5
|
+
* Handles cross-platform path differences.
|
|
6
|
+
*/
|
|
7
|
+
export function resolvePath(filePath, workingDirectory) {
|
|
8
|
+
// If it's already an absolute path, normalize it
|
|
9
|
+
if (path.isAbsolute(filePath)) {
|
|
10
|
+
return path.normalize(filePath);
|
|
11
|
+
}
|
|
12
|
+
// Otherwise resolve relative to working directory
|
|
13
|
+
return path.resolve(workingDirectory, filePath);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a path is within the allowed paths (for sandboxing).
|
|
17
|
+
* Returns true if no allowedPaths are specified (no sandboxing).
|
|
18
|
+
*/
|
|
19
|
+
export function isPathAllowed(targetPath, allowedPaths) {
|
|
20
|
+
if (!allowedPaths || allowedPaths.length === 0) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const normalizedTarget = path.normalize(path.resolve(targetPath));
|
|
24
|
+
return allowedPaths.some((allowedPath) => {
|
|
25
|
+
const normalizedAllowed = path.normalize(path.resolve(allowedPath));
|
|
26
|
+
// Check if target is the allowed path or is under it
|
|
27
|
+
return (normalizedTarget === normalizedAllowed ||
|
|
28
|
+
normalizedTarget.startsWith(normalizedAllowed + path.sep));
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Checks for path traversal attempts.
|
|
33
|
+
* Returns true if the path is safe (no traversal detected).
|
|
34
|
+
*/
|
|
35
|
+
export function isPathSafe(filePath, workingDirectory) {
|
|
36
|
+
const resolved = resolvePath(filePath, workingDirectory);
|
|
37
|
+
const normalizedWorking = path.normalize(path.resolve(workingDirectory));
|
|
38
|
+
// The resolved path should be within or equal to the working directory
|
|
39
|
+
// or be an absolute path that was explicitly provided
|
|
40
|
+
if (path.isAbsolute(filePath)) {
|
|
41
|
+
// Absolute paths are allowed but still need normalization
|
|
42
|
+
return !filePath.includes('..');
|
|
43
|
+
}
|
|
44
|
+
// For relative paths, ensure they don't escape the working directory
|
|
45
|
+
return resolved.startsWith(normalizedWorking) || resolved === normalizedWorking;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Ensures a directory exists, creating it if necessary.
|
|
49
|
+
*/
|
|
50
|
+
export async function ensureDirectory(dirPath) {
|
|
51
|
+
try {
|
|
52
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
// Directory might already exist
|
|
56
|
+
const stat = await fs.stat(dirPath).catch(() => null);
|
|
57
|
+
if (!stat?.isDirectory()) {
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the relative path from the working directory.
|
|
64
|
+
*/
|
|
65
|
+
export function getRelativePath(absolutePath, workingDirectory) {
|
|
66
|
+
return path.relative(workingDirectory, absolutePath);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Normalizes line endings to the current platform's standard.
|
|
70
|
+
*/
|
|
71
|
+
export function normalizeLineEndings(content) {
|
|
72
|
+
// Always use LF internally, let consumers handle platform-specific needs
|
|
73
|
+
return content.replace(/\r\n/g, '\n');
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Simple glob pattern matching.
|
|
77
|
+
* Supports *, **, and ? wildcards.
|
|
78
|
+
*/
|
|
79
|
+
export function matchGlobPattern(pattern, filePath) {
|
|
80
|
+
// Normalize path separators
|
|
81
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
82
|
+
const normalizedPattern = pattern.replace(/\\/g, '/');
|
|
83
|
+
// Convert glob pattern to regex
|
|
84
|
+
let regexPattern = normalizedPattern
|
|
85
|
+
// Escape special regex characters (except our wildcards)
|
|
86
|
+
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
|
87
|
+
// Convert ** to a placeholder
|
|
88
|
+
.replace(/\*\*/g, '{{GLOBSTAR}}')
|
|
89
|
+
// Convert * to match anything except /
|
|
90
|
+
.replace(/\*/g, '[^/]*')
|
|
91
|
+
// Convert ? to match any single character except /
|
|
92
|
+
.replace(/\?/g, '[^/]')
|
|
93
|
+
// Convert ** placeholder back to match any path
|
|
94
|
+
.replace(/\{\{GLOBSTAR\}\}/g, '.*');
|
|
95
|
+
// Anchor the pattern
|
|
96
|
+
regexPattern = `^${regexPattern}$`;
|
|
97
|
+
try {
|
|
98
|
+
const regex = new RegExp(regexPattern);
|
|
99
|
+
return regex.test(normalizedPath);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Recursively walks a directory and returns all file paths.
|
|
107
|
+
*/
|
|
108
|
+
export async function walkDirectory(dir, options = {}) {
|
|
109
|
+
const { ignore = [], maxDepth = 100 } = options;
|
|
110
|
+
const results = [];
|
|
111
|
+
async function walk(currentDir, depth) {
|
|
112
|
+
if (depth > maxDepth) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const entries = await fs.readdir(currentDir, { withFileTypes: true });
|
|
117
|
+
for (const entry of entries) {
|
|
118
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
119
|
+
const relativePath = path.relative(dir, fullPath);
|
|
120
|
+
// Check if path should be ignored
|
|
121
|
+
const shouldIgnore = ignore.some((pattern) => {
|
|
122
|
+
// Simple check for common ignore patterns
|
|
123
|
+
if (pattern.startsWith('**/')) {
|
|
124
|
+
return matchGlobPattern(pattern, relativePath) || entry.name === pattern.slice(3);
|
|
125
|
+
}
|
|
126
|
+
return matchGlobPattern(pattern, relativePath) || matchGlobPattern(pattern, entry.name);
|
|
127
|
+
});
|
|
128
|
+
if (shouldIgnore) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (entry.isDirectory()) {
|
|
132
|
+
await walk(fullPath, depth + 1);
|
|
133
|
+
}
|
|
134
|
+
else if (entry.isFile()) {
|
|
135
|
+
results.push(fullPath);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
// Directory might not be readable, skip it
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
await walk(dir, 0);
|
|
144
|
+
return results;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../../src/tools/utils/path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,gBAAwB;IACpE,iDAAiD;IACjD,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IACD,kDAAkD;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,UAAkB,EAAE,YAAuB;IACvE,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IAElE,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE;QACvC,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;QACpE,qDAAqD;QACrD,OAAO,CACL,gBAAgB,KAAK,iBAAiB;YACtC,gBAAgB,CAAC,UAAU,CAAC,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,CAC1D,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,QAAgB,EAA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'child_process';
|
|
2
|
+
import type { ShellResult, ProcessInfo, ProcessManager } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Default dangerous command patterns that should be blocked
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_BLOCKED_COMMANDS: RegExp[];
|
|
7
|
+
/**
|
|
8
|
+
* Gets the appropriate shell command for the current platform
|
|
9
|
+
*/
|
|
10
|
+
export declare function getShellCommand(): {
|
|
11
|
+
shell: string;
|
|
12
|
+
args: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a command matches any blocked patterns
|
|
16
|
+
*/
|
|
17
|
+
export declare function isCommandBlocked(command: string, blockedPatterns?: RegExp[]): string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Executes a shell command and returns the result
|
|
20
|
+
*/
|
|
21
|
+
export declare function executeCommand(command: string, options?: {
|
|
22
|
+
cwd?: string;
|
|
23
|
+
timeout?: number;
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
abortSignal?: AbortSignal;
|
|
26
|
+
}): Promise<ShellResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a ProcessManager for managing background processes
|
|
29
|
+
*/
|
|
30
|
+
export declare function createProcessManager(): ProcessManager;
|
|
31
|
+
/**
|
|
32
|
+
* Spawns a background process and registers it with the ProcessManager
|
|
33
|
+
*/
|
|
34
|
+
export declare function spawnBackgroundProcess(command: string, processManager: ProcessManager & {
|
|
35
|
+
_register?: (id: string, process: ChildProcess, info: ProcessInfo) => void;
|
|
36
|
+
}, options?: {
|
|
37
|
+
cwd?: string;
|
|
38
|
+
env?: Record<string, string>;
|
|
39
|
+
}): ProcessInfo;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a ProcessManager with internal registration capability
|
|
42
|
+
*/
|
|
43
|
+
export declare function createProcessManagerWithInternal(): ProcessManager & {
|
|
44
|
+
_processes: Map<string, {
|
|
45
|
+
process: ChildProcess;
|
|
46
|
+
info: ProcessInfo;
|
|
47
|
+
}>;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