@push.rocks/smartagent 1.0.2

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 (42) hide show
  1. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  2. package/dist_ts/00_commitinfo_data.js +9 -0
  3. package/dist_ts/index.d.ts +10 -0
  4. package/dist_ts/index.js +18 -0
  5. package/dist_ts/plugins.d.ts +6 -0
  6. package/dist_ts/plugins.js +8 -0
  7. package/dist_ts/smartagent.classes.driveragent.d.ts +70 -0
  8. package/dist_ts/smartagent.classes.driveragent.js +274 -0
  9. package/dist_ts/smartagent.classes.dualagent.d.ts +62 -0
  10. package/dist_ts/smartagent.classes.dualagent.js +298 -0
  11. package/dist_ts/smartagent.classes.guardianagent.d.ts +46 -0
  12. package/dist_ts/smartagent.classes.guardianagent.js +201 -0
  13. package/dist_ts/smartagent.classes.smartagent.d.ts +123 -0
  14. package/dist_ts/smartagent.classes.smartagent.js +274 -0
  15. package/dist_ts/smartagent.interfaces.d.ts +165 -0
  16. package/dist_ts/smartagent.interfaces.js +8 -0
  17. package/dist_ts/smartagent.tools.base.d.ts +46 -0
  18. package/dist_ts/smartagent.tools.base.js +45 -0
  19. package/dist_ts/smartagent.tools.browser.d.ts +16 -0
  20. package/dist_ts/smartagent.tools.browser.js +177 -0
  21. package/dist_ts/smartagent.tools.filesystem.d.ts +16 -0
  22. package/dist_ts/smartagent.tools.filesystem.js +352 -0
  23. package/dist_ts/smartagent.tools.http.d.ts +15 -0
  24. package/dist_ts/smartagent.tools.http.js +187 -0
  25. package/dist_ts/smartagent.tools.shell.d.ts +16 -0
  26. package/dist_ts/smartagent.tools.shell.js +155 -0
  27. package/npmextra.json +18 -0
  28. package/package.json +50 -0
  29. package/readme.hints.md +16 -0
  30. package/readme.md +299 -0
  31. package/ts/00_commitinfo_data.ts +8 -0
  32. package/ts/index.ts +29 -0
  33. package/ts/plugins.ts +14 -0
  34. package/ts/smartagent.classes.driveragent.ts +321 -0
  35. package/ts/smartagent.classes.dualagent.ts +350 -0
  36. package/ts/smartagent.classes.guardianagent.ts +241 -0
  37. package/ts/smartagent.interfaces.ts +210 -0
  38. package/ts/smartagent.tools.base.ts +80 -0
  39. package/ts/smartagent.tools.browser.ts +200 -0
  40. package/ts/smartagent.tools.filesystem.ts +379 -0
  41. package/ts/smartagent.tools.http.ts +205 -0
  42. package/ts/smartagent.tools.shell.ts +182 -0
@@ -0,0 +1,182 @@
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 getCallSummary(action: string, params: Record<string, unknown>): string {
152
+ switch (action) {
153
+ case 'execute': {
154
+ const command = params.command as string;
155
+ const args = (params.args as string[]) || [];
156
+ const fullCommand = [command, ...args].join(' ');
157
+ let summary = `Execute: ${fullCommand}`;
158
+
159
+ if (params.cwd) {
160
+ summary += ` (in ${params.cwd})`;
161
+ }
162
+
163
+ if (params.timeout) {
164
+ summary += ` [timeout: ${params.timeout}ms]`;
165
+ }
166
+
167
+ if (params.env && Object.keys(params.env as object).length > 0) {
168
+ const envKeys = Object.keys(params.env as object).join(', ');
169
+ summary += ` [env: ${envKeys}]`;
170
+ }
171
+
172
+ return summary;
173
+ }
174
+
175
+ case 'which':
176
+ return `Check if command "${params.command}" exists and get its path`;
177
+
178
+ default:
179
+ return `Unknown action: ${action}`;
180
+ }
181
+ }
182
+ }