@push.rocks/smartagent 1.8.0 → 3.0.1

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 (87) hide show
  1. package/dist_ts/00_commitinfo_data.js +3 -3
  2. package/dist_ts/index.d.ts +8 -14
  3. package/dist_ts/index.js +8 -24
  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 +7 -70
  9. package/dist_ts/smartagent.classes.toolregistry.js +11 -155
  10. package/dist_ts/smartagent.interfaces.d.ts +47 -283
  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 +38 -84
  35. package/readme.md +254 -682
  36. package/ts/00_commitinfo_data.ts +2 -2
  37. package/ts/index.ts +10 -37
  38. package/ts/plugins.ts +22 -21
  39. package/ts/smartagent.classes.agent.ts +198 -0
  40. package/ts/smartagent.classes.toolregistry.ts +11 -179
  41. package/ts/smartagent.interfaces.ts +51 -363
  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 -93
  55. package/dist_ts/smartagent.classes.dualagent.js +0 -614
  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.expert.d.ts +0 -27
  65. package/dist_ts/smartagent.tools.expert.js +0 -126
  66. package/dist_ts/smartagent.tools.filesystem.d.ts +0 -40
  67. package/dist_ts/smartagent.tools.filesystem.js +0 -801
  68. package/dist_ts/smartagent.tools.http.d.ts +0 -16
  69. package/dist_ts/smartagent.tools.http.js +0 -264
  70. package/dist_ts/smartagent.tools.json.d.ts +0 -24
  71. package/dist_ts/smartagent.tools.json.js +0 -202
  72. package/dist_ts/smartagent.tools.search.d.ts +0 -29
  73. package/dist_ts/smartagent.tools.search.js +0 -215
  74. package/dist_ts/smartagent.tools.shell.d.ts +0 -17
  75. package/dist_ts/smartagent.tools.shell.js +0 -202
  76. package/ts/smartagent.classes.driveragent.ts +0 -775
  77. package/ts/smartagent.classes.dualagent.ts +0 -692
  78. package/ts/smartagent.classes.guardianagent.ts +0 -241
  79. package/ts/smartagent.tools.base.ts +0 -83
  80. package/ts/smartagent.tools.browser.ts +0 -253
  81. package/ts/smartagent.tools.deno.ts +0 -230
  82. package/ts/smartagent.tools.expert.ts +0 -144
  83. package/ts/smartagent.tools.filesystem.ts +0 -885
  84. package/ts/smartagent.tools.http.ts +0 -283
  85. package/ts/smartagent.tools.json.ts +0 -224
  86. package/ts/smartagent.tools.search.ts +0 -237
  87. package/ts/smartagent.tools.shell.ts +0 -230
@@ -1,237 +0,0 @@
1
- import * as interfaces from './smartagent.interfaces.js';
2
- import { BaseToolWrapper } from './smartagent.tools.base.js';
3
- import { ToolRegistry } from './smartagent.classes.toolregistry.js';
4
-
5
- /**
6
- * ToolSearchTool - AI-facing interface for discovering and activating tools
7
- *
8
- * This tool enables the Driver to:
9
- * - Search for tools by capability
10
- * - List all available tools
11
- * - Activate on-demand tools
12
- * - Get detailed information about specific tools
13
- */
14
- export class ToolSearchTool extends BaseToolWrapper {
15
- public name = 'tools';
16
- public description =
17
- 'Search for and activate available tools and experts. Use this to discover specialized capabilities.';
18
-
19
- public actions: interfaces.IToolAction[] = [
20
- {
21
- name: 'search',
22
- description: 'Search for tools by name, description, tags, or capabilities',
23
- parameters: {
24
- type: 'object',
25
- properties: {
26
- query: { type: 'string', description: 'Search query' },
27
- },
28
- required: ['query'],
29
- },
30
- },
31
- {
32
- name: 'list',
33
- description: 'List all available tools grouped by visibility',
34
- parameters: { type: 'object', properties: {} },
35
- },
36
- {
37
- name: 'activate',
38
- description: 'Activate an on-demand tool to make it available for use',
39
- parameters: {
40
- type: 'object',
41
- properties: {
42
- name: { type: 'string', description: 'Name of the tool to activate' },
43
- },
44
- required: ['name'],
45
- },
46
- },
47
- {
48
- name: 'details',
49
- description: 'Get detailed information about a specific tool',
50
- parameters: {
51
- type: 'object',
52
- properties: {
53
- name: { type: 'string', description: 'Name of the tool' },
54
- },
55
- required: ['name'],
56
- },
57
- },
58
- ];
59
-
60
- private registry: ToolRegistry;
61
- private onToolActivated?: (tool: BaseToolWrapper) => void;
62
-
63
- constructor(registry: ToolRegistry, onToolActivated?: (tool: BaseToolWrapper) => void) {
64
- super();
65
- this.registry = registry;
66
- this.onToolActivated = onToolActivated;
67
- }
68
-
69
- async initialize(): Promise<void> {
70
- this.isInitialized = true;
71
- }
72
-
73
- async cleanup(): Promise<void> {
74
- this.isInitialized = false;
75
- }
76
-
77
- async execute(
78
- action: string,
79
- params: Record<string, unknown>
80
- ): Promise<interfaces.IToolExecutionResult> {
81
- this.validateAction(action);
82
-
83
- switch (action) {
84
- case 'search':
85
- return this.handleSearch(params.query as string);
86
- case 'list':
87
- return this.handleList();
88
- case 'activate':
89
- return this.handleActivate(params.name as string);
90
- case 'details':
91
- return this.handleDetails(params.name as string);
92
- default:
93
- return { success: false, error: `Unknown action: ${action}` };
94
- }
95
- }
96
-
97
- private handleSearch(query: string): interfaces.IToolExecutionResult {
98
- const results = this.registry.search(query);
99
- return {
100
- success: true,
101
- result: results.map((m) => ({
102
- name: m.name,
103
- description: m.description,
104
- visibility: m.visibility,
105
- isActivated: m.isActivated,
106
- category: m.category,
107
- tags: m.tags,
108
- actionCount: m.actions.length,
109
- })),
110
- summary: `Found ${results.length} tools matching "${query}"`,
111
- };
112
- }
113
-
114
- private handleList(): interfaces.IToolExecutionResult {
115
- const all = this.registry.getAllMetadata();
116
- const initial = all.filter((m) => m.visibility === 'initial');
117
- const onDemand = all.filter((m) => m.visibility === 'on-demand');
118
-
119
- return {
120
- success: true,
121
- result: {
122
- initial: initial.map((m) => ({
123
- name: m.name,
124
- description: m.description,
125
- category: m.category,
126
- })),
127
- onDemand: onDemand.map((m) => ({
128
- name: m.name,
129
- description: m.description,
130
- category: m.category,
131
- isActivated: m.isActivated,
132
- })),
133
- summary: `${initial.length} initial, ${onDemand.length} on-demand`,
134
- },
135
- };
136
- }
137
-
138
- private async handleActivate(name: string): Promise<interfaces.IToolExecutionResult> {
139
- const result = await this.registry.activate(name);
140
-
141
- if (result.success && this.onToolActivated) {
142
- const tool = this.registry.getTool(name);
143
- if (tool) {
144
- this.onToolActivated(tool);
145
- }
146
- }
147
-
148
- return {
149
- success: result.success,
150
- result: result.success ? { name, message: `Tool "${name}" is now available` } : undefined,
151
- error: result.error,
152
- summary: result.success ? `Activated: ${name}` : result.error,
153
- };
154
- }
155
-
156
- private handleDetails(name: string): interfaces.IToolExecutionResult {
157
- const tool = this.registry.getTool(name);
158
- const meta = this.registry.getMetadata(name);
159
-
160
- if (!tool || !meta) {
161
- return { success: false, error: `Tool "${name}" not found` };
162
- }
163
-
164
- return {
165
- success: true,
166
- result: {
167
- name: meta.name,
168
- description: meta.description,
169
- visibility: meta.visibility,
170
- isActivated: meta.isActivated,
171
- category: meta.category,
172
- tags: meta.tags,
173
- actions: meta.actions,
174
- fullExplanation: tool.getToolExplanation(),
175
- },
176
- };
177
- }
178
-
179
- getCallSummary(action: string, params: Record<string, unknown>): string {
180
- switch (action) {
181
- case 'search':
182
- return `Search tools: "${params.query}"`;
183
- case 'list':
184
- return 'List all tools';
185
- case 'activate':
186
- return `Activate tool: ${params.name}`;
187
- case 'details':
188
- return `Get details: ${params.name}`;
189
- default:
190
- return `tools.${action}`;
191
- }
192
- }
193
-
194
- getToolExplanation(): string {
195
- return `## Tool: tools
196
- Search for and manage available tools and experts.
197
-
198
- ### Actions:
199
-
200
- **search** - Find tools by capability
201
- \`\`\`
202
- <tool_call>
203
- <tool>tools</tool>
204
- <action>search</action>
205
- <params>{"query": "database"}</params>
206
- </tool_call>
207
- \`\`\`
208
-
209
- **list** - List all tools grouped by visibility
210
- \`\`\`
211
- <tool_call>
212
- <tool>tools</tool>
213
- <action>list</action>
214
- <params>{}</params>
215
- </tool_call>
216
- \`\`\`
217
-
218
- **activate** - Activate an on-demand tool
219
- \`\`\`
220
- <tool_call>
221
- <tool>tools</tool>
222
- <action>activate</action>
223
- <params>{"name": "database_expert"}</params>
224
- </tool_call>
225
- \`\`\`
226
-
227
- **details** - Get full information about a tool
228
- \`\`\`
229
- <tool_call>
230
- <tool>tools</tool>
231
- <action>details</action>
232
- <params>{"name": "filesystem"}</params>
233
- </tool_call>
234
- \`\`\`
235
- `;
236
- }
237
- }
@@ -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
- }