@push.rocks/smartagent 1.7.0 → 3.0.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.
Files changed (81) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/index.d.ts +9 -12
  3. package/dist_ts/index.js +9 -20
  4. package/dist_ts/plugins.d.ts +8 -9
  5. package/dist_ts/plugins.js +10 -12
  6. package/dist_ts/smartagent.classes.agent.d.ts +2 -0
  7. package/dist_ts/smartagent.classes.agent.js +173 -0
  8. package/dist_ts/smartagent.classes.toolregistry.d.ts +12 -0
  9. package/dist_ts/smartagent.classes.toolregistry.js +17 -0
  10. package/dist_ts/smartagent.interfaces.d.ts +47 -231
  11. package/dist_ts/smartagent.interfaces.js +6 -7
  12. package/dist_ts/smartagent.utils.truncation.d.ts +10 -0
  13. package/dist_ts/smartagent.utils.truncation.js +26 -0
  14. package/dist_ts_compaction/index.d.ts +1 -0
  15. package/dist_ts_compaction/index.js +2 -0
  16. package/dist_ts_compaction/plugins.d.ts +4 -0
  17. package/dist_ts_compaction/plugins.js +3 -0
  18. package/dist_ts_compaction/smartagent.compaction.d.ts +10 -0
  19. package/dist_ts_compaction/smartagent.compaction.js +46 -0
  20. package/dist_ts_tools/index.d.ts +8 -0
  21. package/dist_ts_tools/index.js +6 -0
  22. package/dist_ts_tools/plugins.d.ts +15 -0
  23. package/dist_ts_tools/plugins.js +19 -0
  24. package/dist_ts_tools/tool.filesystem.d.ts +6 -0
  25. package/dist_ts_tools/tool.filesystem.js +102 -0
  26. package/dist_ts_tools/tool.http.d.ts +2 -0
  27. package/dist_ts_tools/tool.http.js +65 -0
  28. package/dist_ts_tools/tool.json.d.ts +2 -0
  29. package/dist_ts_tools/tool.json.js +47 -0
  30. package/dist_ts_tools/tool.shell.d.ts +8 -0
  31. package/dist_ts_tools/tool.shell.js +40 -0
  32. package/npmextra.json +1 -1
  33. package/package.json +30 -18
  34. package/readme.hints.md +43 -42
  35. package/readme.md +257 -526
  36. package/ts/00_commitinfo_data.ts +2 -2
  37. package/ts/index.ts +11 -31
  38. package/ts/plugins.ts +22 -21
  39. package/ts/smartagent.classes.agent.ts +198 -0
  40. package/ts/smartagent.classes.toolregistry.ts +20 -0
  41. package/ts/smartagent.interfaces.ts +51 -303
  42. package/ts/smartagent.utils.truncation.ts +39 -0
  43. package/ts_compaction/index.ts +1 -0
  44. package/ts_compaction/plugins.ts +6 -0
  45. package/ts_compaction/smartagent.compaction.ts +51 -0
  46. package/ts_tools/index.ts +8 -0
  47. package/ts_tools/plugins.ts +30 -0
  48. package/ts_tools/tool.filesystem.ts +131 -0
  49. package/ts_tools/tool.http.ts +78 -0
  50. package/ts_tools/tool.json.ts +53 -0
  51. package/ts_tools/tool.shell.ts +62 -0
  52. package/dist_ts/smartagent.classes.driveragent.d.ts +0 -134
  53. package/dist_ts/smartagent.classes.driveragent.js +0 -671
  54. package/dist_ts/smartagent.classes.dualagent.d.ts +0 -79
  55. package/dist_ts/smartagent.classes.dualagent.js +0 -583
  56. package/dist_ts/smartagent.classes.guardianagent.d.ts +0 -46
  57. package/dist_ts/smartagent.classes.guardianagent.js +0 -201
  58. package/dist_ts/smartagent.tools.base.d.ts +0 -52
  59. package/dist_ts/smartagent.tools.base.js +0 -42
  60. package/dist_ts/smartagent.tools.browser.d.ts +0 -17
  61. package/dist_ts/smartagent.tools.browser.js +0 -229
  62. package/dist_ts/smartagent.tools.deno.d.ts +0 -21
  63. package/dist_ts/smartagent.tools.deno.js +0 -191
  64. package/dist_ts/smartagent.tools.filesystem.d.ts +0 -40
  65. package/dist_ts/smartagent.tools.filesystem.js +0 -801
  66. package/dist_ts/smartagent.tools.http.d.ts +0 -16
  67. package/dist_ts/smartagent.tools.http.js +0 -264
  68. package/dist_ts/smartagent.tools.json.d.ts +0 -24
  69. package/dist_ts/smartagent.tools.json.js +0 -202
  70. package/dist_ts/smartagent.tools.shell.d.ts +0 -17
  71. package/dist_ts/smartagent.tools.shell.js +0 -202
  72. package/ts/smartagent.classes.driveragent.ts +0 -775
  73. package/ts/smartagent.classes.dualagent.ts +0 -657
  74. package/ts/smartagent.classes.guardianagent.ts +0 -241
  75. package/ts/smartagent.tools.base.ts +0 -83
  76. package/ts/smartagent.tools.browser.ts +0 -253
  77. package/ts/smartagent.tools.deno.ts +0 -230
  78. package/ts/smartagent.tools.filesystem.ts +0 -885
  79. package/ts/smartagent.tools.http.ts +0 -283
  80. package/ts/smartagent.tools.json.ts +0 -224
  81. package/ts/smartagent.tools.shell.ts +0 -230
@@ -1,230 +0,0 @@
1
- import * as plugins from './plugins.js';
2
- import * as interfaces from './smartagent.interfaces.js';
3
- import { BaseToolWrapper } from './smartagent.tools.base.js';
4
-
5
- /**
6
- * Shell tool for executing commands securely
7
- * Wraps @push.rocks/smartshell with execSpawn for safety (no shell injection)
8
- */
9
- export class ShellTool extends BaseToolWrapper {
10
- public name = 'shell';
11
- public description =
12
- 'Execute shell commands securely. Uses execSpawn (shell:false) to prevent command injection.';
13
-
14
- public actions: interfaces.IToolAction[] = [
15
- {
16
- name: 'execute',
17
- description:
18
- 'Execute a command with arguments (secure, no shell injection possible). Command and args are passed separately.',
19
- parameters: {
20
- type: 'object',
21
- properties: {
22
- command: {
23
- type: 'string',
24
- description: 'The command to execute (e.g., "ls", "cat", "grep", "node")',
25
- },
26
- args: {
27
- type: 'array',
28
- items: { type: 'string' },
29
- description: 'Array of arguments (each argument is properly escaped)',
30
- },
31
- cwd: { type: 'string', description: 'Working directory for the command' },
32
- timeout: { type: 'number', description: 'Timeout in milliseconds' },
33
- env: {
34
- type: 'object',
35
- description: 'Additional environment variables (key-value pairs)',
36
- },
37
- },
38
- required: ['command'],
39
- },
40
- },
41
- {
42
- name: 'which',
43
- description: 'Check if a command exists and get its path',
44
- parameters: {
45
- type: 'object',
46
- properties: {
47
- command: { type: 'string', description: 'Command name to look up (e.g., "node", "git")' },
48
- },
49
- required: ['command'],
50
- },
51
- },
52
- ];
53
-
54
- private smartshell!: plugins.smartshell.Smartshell;
55
-
56
- public async initialize(): Promise<void> {
57
- this.smartshell = new plugins.smartshell.Smartshell({
58
- executor: 'bash',
59
- });
60
- this.isInitialized = true;
61
- }
62
-
63
- public async cleanup(): Promise<void> {
64
- this.isInitialized = false;
65
- }
66
-
67
- public async execute(
68
- action: string,
69
- params: Record<string, unknown>
70
- ): Promise<interfaces.IToolExecutionResult> {
71
- this.validateAction(action);
72
- this.ensureInitialized();
73
-
74
- try {
75
- switch (action) {
76
- case 'execute': {
77
- const command = params.command as string;
78
- const args = (params.args as string[]) || [];
79
-
80
- // Build options
81
- const options: {
82
- timeout?: number;
83
- env?: NodeJS.ProcessEnv;
84
- cwd?: string;
85
- } = {};
86
-
87
- if (params.timeout) {
88
- options.timeout = params.timeout as number;
89
- }
90
-
91
- if (params.env) {
92
- options.env = {
93
- ...process.env,
94
- ...(params.env as NodeJS.ProcessEnv),
95
- };
96
- }
97
-
98
- // Use execSpawn for security - no shell injection possible
99
- const result = await this.smartshell.execSpawn(command, args, options);
100
-
101
- return {
102
- success: result.exitCode === 0,
103
- result: {
104
- command,
105
- args,
106
- exitCode: result.exitCode,
107
- stdout: result.stdout,
108
- stderr: result.stderr,
109
- signal: result.signal,
110
- },
111
- };
112
- }
113
-
114
- case 'which': {
115
- try {
116
- const commandPath = await plugins.smartshell.which(params.command as string);
117
- return {
118
- success: true,
119
- result: {
120
- command: params.command,
121
- path: commandPath,
122
- exists: true,
123
- },
124
- };
125
- } catch {
126
- return {
127
- success: true,
128
- result: {
129
- command: params.command,
130
- path: null,
131
- exists: false,
132
- },
133
- };
134
- }
135
- }
136
-
137
- default:
138
- return {
139
- success: false,
140
- error: `Unknown action: ${action}`,
141
- };
142
- }
143
- } catch (error) {
144
- return {
145
- success: false,
146
- error: error instanceof Error ? error.message : String(error),
147
- };
148
- }
149
- }
150
-
151
- public getToolExplanation(): string {
152
- return `## Tool: shell
153
- Execute shell commands securely. Uses execSpawn (shell:false) to prevent command injection.
154
-
155
- ### Actions:
156
-
157
- **execute** - Execute a command with arguments (secure, no shell injection possible)
158
- Parameters:
159
- - command (required): The command to execute (e.g., "ls", "cat", "grep", "node")
160
- - args (optional): Array of arguments (each argument is properly escaped)
161
- - cwd (optional): Working directory for the command
162
- - timeout (optional): Timeout in milliseconds
163
- - env (optional): Additional environment variables (key-value object)
164
-
165
- Example - List files:
166
- <tool_call>
167
- <tool>shell</tool>
168
- <action>execute</action>
169
- <params>{"command": "ls", "args": ["-la", "/path/to/dir"]}</params>
170
- </tool_call>
171
-
172
- Example - Run Node script:
173
- <tool_call>
174
- <tool>shell</tool>
175
- <action>execute</action>
176
- <params>{"command": "node", "args": ["script.js"], "cwd": "/path/to/project"}</params>
177
- </tool_call>
178
-
179
- Example - Search in files:
180
- <tool_call>
181
- <tool>shell</tool>
182
- <action>execute</action>
183
- <params>{"command": "grep", "args": ["-r", "pattern", "src/"]}</params>
184
- </tool_call>
185
-
186
- **which** - Check if a command exists and get its path
187
- Parameters:
188
- - command (required): Command name to look up (e.g., "node", "git")
189
-
190
- Example:
191
- <tool_call>
192
- <tool>shell</tool>
193
- <action>which</action>
194
- <params>{"command": "node"}</params>
195
- </tool_call>
196
- `;
197
- }
198
-
199
- public getCallSummary(action: string, params: Record<string, unknown>): string {
200
- switch (action) {
201
- case 'execute': {
202
- const command = params.command as string;
203
- const args = (params.args as string[]) || [];
204
- const fullCommand = [command, ...args].join(' ');
205
- let summary = `Execute: ${fullCommand}`;
206
-
207
- if (params.cwd) {
208
- summary += ` (in ${params.cwd})`;
209
- }
210
-
211
- if (params.timeout) {
212
- summary += ` [timeout: ${params.timeout}ms]`;
213
- }
214
-
215
- if (params.env && Object.keys(params.env as object).length > 0) {
216
- const envKeys = Object.keys(params.env as object).join(', ');
217
- summary += ` [env: ${envKeys}]`;
218
- }
219
-
220
- return summary;
221
- }
222
-
223
- case 'which':
224
- return `Check if command "${params.command}" exists and get its path`;
225
-
226
- default:
227
- return `Unknown action: ${action}`;
228
- }
229
- }
230
- }