@tyvm/knowhow 0.0.25 → 0.0.27
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/CONFIG.md +38 -0
- package/PROCESSING.md +429 -0
- package/WORKER.md +425 -0
- package/package.json +1 -1
- package/src/agents/tools/executeScript/definition.ts +1 -1
- package/src/chat.ts +5 -5
- package/src/embeddings.ts +24 -9
- package/src/services/script-execution/SandboxContext.ts +5 -1
- package/src/services/script-execution/ScriptExecutor.ts +1 -0
- package/src/services/script-execution/ScriptPolicy.ts +1 -4
- package/ts_build/src/agents/tools/executeScript/definition.js +1 -1
- package/ts_build/src/chat.js +1 -1
- package/ts_build/src/chat.js.map +1 -1
- package/ts_build/src/cli.js +0 -0
- package/ts_build/src/embeddings.js +12 -8
- package/ts_build/src/embeddings.js.map +1 -1
- package/ts_build/src/services/script-execution/SandboxContext.js +4 -1
- package/ts_build/src/services/script-execution/SandboxContext.js.map +1 -1
- package/ts_build/src/services/script-execution/ScriptExecutor.js +1 -0
- package/ts_build/src/services/script-execution/ScriptExecutor.js.map +1 -1
- package/ts_build/src/services/script-execution/ScriptPolicy.js +0 -3
- package/ts_build/src/services/script-execution/ScriptPolicy.js.map +1 -1
package/WORKER.md
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
# Knowhow Workers Guide
|
|
2
|
+
|
|
3
|
+
Knowhow workers allow you to expose your local tools and development environment to the Knowhow platform, enabling remote agents to execute commands, access files, and leverage your local setup through a secure WebSocket connection.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
### 1. Initial Setup
|
|
10
|
+
|
|
11
|
+
First, authenticate with the Knowhow platform:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
knowhow login
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
This will open your browser and guide you through the authentication process.
|
|
18
|
+
|
|
19
|
+
### 2. Generate Worker Configuration
|
|
20
|
+
|
|
21
|
+
Run the worker command to generate the initial configuration:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
knowhow worker
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This will:
|
|
28
|
+
- Generate a `worker` configuration block in your `knowhow.json`
|
|
29
|
+
- Display available tools that can be exposed
|
|
30
|
+
- Create a secure connection to the Knowhow platform
|
|
31
|
+
|
|
32
|
+
### 3. Configure Allowed Tools
|
|
33
|
+
|
|
34
|
+
Edit your `knowhow.json` to specify which tools you want to expose:
|
|
35
|
+
|
|
36
|
+
```json
|
|
37
|
+
{
|
|
38
|
+
"worker": {
|
|
39
|
+
"allowedTools": [
|
|
40
|
+
"readFile",
|
|
41
|
+
"writeFileChunk",
|
|
42
|
+
"patchFile",
|
|
43
|
+
"execCommand",
|
|
44
|
+
"textSearch",
|
|
45
|
+
"fileSearch",
|
|
46
|
+
"embeddingSearch"
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 4. Start the Worker
|
|
53
|
+
|
|
54
|
+
Run the worker again to start the connection:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
knowhow worker
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Your local tools are now available to Knowhow behaviors and agents!
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Worker Architecture
|
|
65
|
+
|
|
66
|
+
### WebSocket Connection
|
|
67
|
+
|
|
68
|
+
Workers establish a secure WebSocket connection to the Knowhow platform:
|
|
69
|
+
|
|
70
|
+
- **Authentication**: Uses your login credentials for secure access
|
|
71
|
+
- **Real-time Communication**: Enables instant tool execution requests
|
|
72
|
+
- **Automatic Reconnection**: Handles network interruptions gracefully
|
|
73
|
+
- **Tool Allowlisting**: Only exposed tools can be executed remotely
|
|
74
|
+
|
|
75
|
+
### MCP Integration
|
|
76
|
+
|
|
77
|
+
Workers leverage the Model Context Protocol (MCP) to expose tools:
|
|
78
|
+
|
|
79
|
+
- **Tool Registration**: Local tools are registered as MCP resources
|
|
80
|
+
- **Parameter Validation**: Ensures proper argument types and requirements
|
|
81
|
+
- **Error Handling**: Provides detailed error messages for debugging
|
|
82
|
+
- **Response Formatting**: Standardizes tool outputs for agent consumption
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Configuration
|
|
87
|
+
|
|
88
|
+
### Basic Worker Configuration
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"worker": {
|
|
93
|
+
"allowedTools": [
|
|
94
|
+
"readFile",
|
|
95
|
+
"writeFileChunk",
|
|
96
|
+
"patchFile",
|
|
97
|
+
"lintFile",
|
|
98
|
+
"execCommand",
|
|
99
|
+
"textSearch",
|
|
100
|
+
"fileSearch",
|
|
101
|
+
"embeddingSearch"
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Advanced Configuration
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"worker": {
|
|
112
|
+
"allowedTools": [
|
|
113
|
+
"readFile",
|
|
114
|
+
"writeFileChunk",
|
|
115
|
+
"patchFile",
|
|
116
|
+
"lintFile",
|
|
117
|
+
"execCommand",
|
|
118
|
+
"textSearch",
|
|
119
|
+
"fileSearch",
|
|
120
|
+
"embeddingSearch",
|
|
121
|
+
"createAiCompletion",
|
|
122
|
+
"listAllModels",
|
|
123
|
+
"callPlugin"
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Available Tools
|
|
132
|
+
|
|
133
|
+
### File Operations
|
|
134
|
+
|
|
135
|
+
#### Core File Tools
|
|
136
|
+
- **`readFile`** - Read complete file contents
|
|
137
|
+
- **`writeFileChunk`** - Write content to files (supports chunking for large files)
|
|
138
|
+
- **`patchFile`** - Apply unified diff patches to files
|
|
139
|
+
- **`readBlocks`** - Read specific blocks from files
|
|
140
|
+
|
|
141
|
+
#### Search Tools
|
|
142
|
+
- **`textSearch`** - Search for exact text matches across files
|
|
143
|
+
- **`fileSearch`** - Search for files by path patterns
|
|
144
|
+
- **`embeddingSearch`** - Semantic search using embeddings
|
|
145
|
+
|
|
146
|
+
### Development Tools
|
|
147
|
+
|
|
148
|
+
#### Code Quality
|
|
149
|
+
- **`lintFile`** - Run linters on files based on extension
|
|
150
|
+
- **`execCommand`** - Execute shell commands with timeout support
|
|
151
|
+
|
|
152
|
+
#### AI Integration
|
|
153
|
+
- **`createAiCompletion`** - Create AI completions using configured models
|
|
154
|
+
- **`listAllModels`** - List available AI models
|
|
155
|
+
- **`listAllProviders`** - List available AI providers
|
|
156
|
+
|
|
157
|
+
### Plugin System
|
|
158
|
+
- **`callPlugin`** - Execute plugin functions
|
|
159
|
+
- **`addLanguageTerm`** - Add language terms for context loading
|
|
160
|
+
- **`getAllLanguageTerms`** - Retrieve all configured language terms
|
|
161
|
+
- **`lookupLanguageTerm`** - Look up specific language terms
|
|
162
|
+
|
|
163
|
+
### Integration Tools
|
|
164
|
+
|
|
165
|
+
#### Version Control
|
|
166
|
+
- **`getPullRequest`** - Fetch GitHub pull request information
|
|
167
|
+
- **`getPullRequestBuildStatuses`** - Get build status for PRs
|
|
168
|
+
- **`getRunLogs`** - Retrieve GitHub Actions run logs
|
|
169
|
+
- **`getPullRequestBuildFailureLogs`** - Get failure logs from PR builds
|
|
170
|
+
|
|
171
|
+
### MCP Server Tools
|
|
172
|
+
|
|
173
|
+
When MCP servers are configured, their tools become available with prefixed names:
|
|
174
|
+
|
|
175
|
+
```json
|
|
176
|
+
{
|
|
177
|
+
"mcps": [
|
|
178
|
+
{
|
|
179
|
+
"name": "browser",
|
|
180
|
+
"command": "npx",
|
|
181
|
+
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"worker": {
|
|
185
|
+
"allowedTools": [
|
|
186
|
+
"mcp_0_browser_navigate",
|
|
187
|
+
"mcp_0_browser_screenshot",
|
|
188
|
+
"mcp_0_browser_click",
|
|
189
|
+
"mcp_0_browser_fill",
|
|
190
|
+
"mcp_0_browser_select"
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Security Considerations
|
|
199
|
+
|
|
200
|
+
### Tool Allowlisting
|
|
201
|
+
|
|
202
|
+
Only tools explicitly listed in `allowedTools` can be executed remotely:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"worker": {
|
|
207
|
+
"allowedTools": [
|
|
208
|
+
"readFile", // ✅ Allowed
|
|
209
|
+
"writeFileChunk", // ✅ Allowed
|
|
210
|
+
// "execCommand" // ❌ Not allowed - commented out
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### File System Access
|
|
217
|
+
|
|
218
|
+
Workers respect the project directory boundaries:
|
|
219
|
+
- **Limited Scope**: Only files within the project directory are accessible
|
|
220
|
+
- **Path Validation**: Prevents directory traversal attacks
|
|
221
|
+
- **Permission Checks**: Respects file system permissions
|
|
222
|
+
|
|
223
|
+
### Command Execution
|
|
224
|
+
|
|
225
|
+
When `execCommand` is enabled:
|
|
226
|
+
- **Timeout Protection**: Commands have configurable timeouts
|
|
227
|
+
- **Process Isolation**: Commands run in separate processes
|
|
228
|
+
- **Error Handling**: Captures both stdout and stderr
|
|
229
|
+
- **Security Warning**: Be cautious with command execution in untrusted environments
|
|
230
|
+
|
|
231
|
+
### Network Security
|
|
232
|
+
|
|
233
|
+
- **Encrypted Connection**: All communication uses WebSocket Secure (WSS)
|
|
234
|
+
- **Authentication Required**: Valid Knowhow credentials required
|
|
235
|
+
- **Session Management**: Automatic session expiration and renewal
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Integration with Knowhow Behaviors
|
|
240
|
+
|
|
241
|
+
### Creating Worker-Enabled Behaviors
|
|
242
|
+
|
|
243
|
+
Behaviors can leverage worker tools through the Knowhow platform:
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"name": "Code Reviewer",
|
|
248
|
+
"description": "Reviews code changes and provides feedback",
|
|
249
|
+
"instructions": "Use readFile to examine code, textSearch to find patterns, and writeFileChunk to create review comments",
|
|
250
|
+
"tools": ["worker_0_readFile", "worker_0_textSearch", "worker_0_writeFileChunk"],
|
|
251
|
+
"workers": ["worker_connection_id"]
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Tool Usage in Agents
|
|
256
|
+
|
|
257
|
+
Agents can call worker tools directly:
|
|
258
|
+
|
|
259
|
+
```javascript
|
|
260
|
+
// Agent can read local files
|
|
261
|
+
const fileContent = await callTool('readFile', {
|
|
262
|
+
filePath: './src/components/Header.tsx'
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Search for patterns in codebase
|
|
266
|
+
const searchResults = await callTool('textSearch', {
|
|
267
|
+
searchTerm: 'useState'
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
// Apply code changes
|
|
271
|
+
await callTool('patchFile', {
|
|
272
|
+
filePath: './src/utils/helpers.ts',
|
|
273
|
+
patch: `--- a/src/utils/helpers.ts
|
|
274
|
+
+++ b/src/utils/helpers.ts
|
|
275
|
+
@@ -10,6 +10,7 @@
|
|
276
|
+
export function formatDate(date: Date): string {
|
|
277
|
+
+ if (!date) return '';
|
|
278
|
+
return date.toISOString().split('T')[0];
|
|
279
|
+
}`
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Command Line Usage
|
|
286
|
+
|
|
287
|
+
### Basic Commands
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# Authenticate with Knowhow
|
|
291
|
+
knowhow login
|
|
292
|
+
|
|
293
|
+
# Generate worker configuration
|
|
294
|
+
knowhow worker
|
|
295
|
+
|
|
296
|
+
# Start worker with default config
|
|
297
|
+
knowhow worker
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### Environment Variables
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## Troubleshooting
|
|
305
|
+
|
|
306
|
+
### Common Issues
|
|
307
|
+
|
|
308
|
+
#### Connection Problems
|
|
309
|
+
|
|
310
|
+
**Issue**: Worker fails to connect
|
|
311
|
+
```
|
|
312
|
+
Error: WebSocket connection failed
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Solutions**:
|
|
316
|
+
1. Check internet connection
|
|
317
|
+
2. Verify authentication: `knowhow login`
|
|
318
|
+
3. Check firewall settings for WebSocket connections
|
|
319
|
+
|
|
320
|
+
#### Authentication Errors
|
|
321
|
+
|
|
322
|
+
**Issue**: Authentication failed
|
|
323
|
+
```
|
|
324
|
+
Error: Invalid credentials
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Solutions**:
|
|
328
|
+
1. Re-authenticate: `knowhow login`
|
|
329
|
+
2. Check token expiration
|
|
330
|
+
3. Verify organization permissions
|
|
331
|
+
|
|
332
|
+
#### Tool Execution Failures
|
|
333
|
+
|
|
334
|
+
**Issue**: Tool not found or not allowed
|
|
335
|
+
```
|
|
336
|
+
Error: Function readFile not enabled
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Solutions**:
|
|
340
|
+
1. Add tool to `allowedTools` in `knowhow.json`
|
|
341
|
+
2. Restart worker after configuration changes
|
|
342
|
+
3. Verify tool name spelling
|
|
343
|
+
|
|
344
|
+
## Best Practices
|
|
345
|
+
|
|
346
|
+
### Security
|
|
347
|
+
|
|
348
|
+
1. **Principle of Least Privilege**: Only expose necessary tools
|
|
349
|
+
2. **Regular Audits**: Review `allowedTools` periodically
|
|
350
|
+
3. **Environment Separation**: Use different configurations for dev/prod
|
|
351
|
+
4. **Command Restrictions**: Be cautious with `execCommand` permissions
|
|
352
|
+
|
|
353
|
+
### Development Workflow
|
|
354
|
+
|
|
355
|
+
1. **Version Control**: Include `knowhow.json` in version control
|
|
356
|
+
2. **Team Coordination**: Document tool requirements for team members
|
|
357
|
+
3. **Testing**: Test worker configuration before deploying behaviors
|
|
358
|
+
4. **Documentation**: Document custom tools and their usage
|
|
359
|
+
|
|
360
|
+
### Maintenance
|
|
361
|
+
1. **Regular Updates**: Keep Knowhow CLI updated
|
|
362
|
+
2. **Log Monitoring**: Review worker logs for issues
|
|
363
|
+
3. **Configuration Backup**: Backup working configurations
|
|
364
|
+
4. **Health Checks**: Implement monitoring for worker connectivity
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## Examples
|
|
369
|
+
|
|
370
|
+
### Development Environment Setup
|
|
371
|
+
|
|
372
|
+
```json
|
|
373
|
+
{
|
|
374
|
+
"worker": {
|
|
375
|
+
"allowedTools": [
|
|
376
|
+
"readFile",
|
|
377
|
+
"writeFileChunk",
|
|
378
|
+
"patchFile",
|
|
379
|
+
"textSearch",
|
|
380
|
+
"fileSearch",
|
|
381
|
+
"embeddingSearch",
|
|
382
|
+
"execCommand",
|
|
383
|
+
"lintFile"
|
|
384
|
+
]
|
|
385
|
+
},
|
|
386
|
+
"mcps": [
|
|
387
|
+
{
|
|
388
|
+
"name": "browser",
|
|
389
|
+
"command": "npx",
|
|
390
|
+
"args": ["-y", "@modelcontextprotocol/server-puppeteer"]
|
|
391
|
+
}
|
|
392
|
+
]
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Production Environment (Restricted)
|
|
397
|
+
|
|
398
|
+
```json
|
|
399
|
+
{
|
|
400
|
+
"worker": {
|
|
401
|
+
"allowedTools": [
|
|
402
|
+
"readFile",
|
|
403
|
+
"textSearch",
|
|
404
|
+
"fileSearch",
|
|
405
|
+
"embeddingSearch"
|
|
406
|
+
]
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### Code Review Workflow
|
|
412
|
+
|
|
413
|
+
```json
|
|
414
|
+
{
|
|
415
|
+
"worker": {
|
|
416
|
+
"allowedTools": [
|
|
417
|
+
"readFile",
|
|
418
|
+
"textSearch",
|
|
419
|
+
"getPullRequest",
|
|
420
|
+
"getPullRequestBuildStatuses",
|
|
421
|
+
"lintFile"
|
|
422
|
+
]
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
```
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ export const executeScriptDefinition: Tool = {
|
|
|
15
15
|
- createArtifact(name, content, type): Create downloadable artifacts
|
|
16
16
|
- console: Standard console logging
|
|
17
17
|
- getQuotaUsage(): Check resource usage
|
|
18
|
-
- sleep(ms): Pause execution for a specified time
|
|
18
|
+
- sleep(ms): Pause execution for a specified time, max 2000ms
|
|
19
19
|
|
|
20
20
|
Example:
|
|
21
21
|
\`\`\`typescript
|
package/src/chat.ts
CHANGED
|
@@ -293,11 +293,6 @@ export async function chatLoop<E extends GptQuestionEmbedding>(
|
|
|
293
293
|
default:
|
|
294
294
|
console.log("Thinking...");
|
|
295
295
|
console.log(input);
|
|
296
|
-
const formattedPrompt = await formatChatInput(
|
|
297
|
-
input,
|
|
298
|
-
plugins,
|
|
299
|
-
chatHistory
|
|
300
|
-
);
|
|
301
296
|
const interaction = {
|
|
302
297
|
input,
|
|
303
298
|
output: "",
|
|
@@ -311,6 +306,11 @@ export async function chatLoop<E extends GptQuestionEmbedding>(
|
|
|
311
306
|
interaction,
|
|
312
307
|
});
|
|
313
308
|
} else {
|
|
309
|
+
const formattedPrompt = await formatChatInput(
|
|
310
|
+
input,
|
|
311
|
+
plugins,
|
|
312
|
+
chatHistory
|
|
313
|
+
);
|
|
314
314
|
results = await askAI(formattedPrompt, provider, model);
|
|
315
315
|
interaction.output = results;
|
|
316
316
|
console.log(Marked.parse(results || "No response from the AI"));
|
package/src/embeddings.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import glob from "glob";
|
|
2
2
|
import * as path from "path";
|
|
3
3
|
import { getConfig, loadPrompt } from "./config";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Config,
|
|
6
|
+
Hashes,
|
|
7
|
+
Embeddable,
|
|
8
|
+
EmbeddingBase,
|
|
9
|
+
Models,
|
|
10
|
+
EmbeddingModels,
|
|
11
|
+
} from "./types";
|
|
5
12
|
import {
|
|
6
13
|
readFile,
|
|
7
14
|
writeFile,
|
|
@@ -75,25 +82,33 @@ export async function embedSource(
|
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
console.log("Embedding", source.input, "to", source.output);
|
|
78
|
-
let
|
|
85
|
+
let inputs = [];
|
|
86
|
+
|
|
87
|
+
const kind = source.kind || "file";
|
|
79
88
|
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
// Don't glob a paragraph or some other kind of input
|
|
90
|
+
if (kind !== "file") {
|
|
91
|
+
inputs = await glob.sync(source.input, { ignore: ignorePattern });
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
|
|
85
|
-
if (
|
|
94
|
+
// It wasn't a file glob, so we need to loop through input
|
|
95
|
+
if (source.kind && inputs.length === 0) {
|
|
96
|
+
inputs = [source.input];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
console.log(`Found ${inputs.length} files`);
|
|
100
|
+
if (inputs.length > 100) {
|
|
86
101
|
console.error(
|
|
87
102
|
"woah there, that's a lot of files. I'm not going to embed that many"
|
|
88
103
|
);
|
|
89
104
|
}
|
|
90
|
-
console.log(
|
|
105
|
+
console.log(inputs);
|
|
91
106
|
const embeddings: Embeddable[] = await loadEmbedding(source.output);
|
|
92
107
|
let batch = [];
|
|
93
108
|
let index = 0;
|
|
94
|
-
for (const file of
|
|
109
|
+
for (const file of inputs) {
|
|
95
110
|
index++;
|
|
96
|
-
const shouldSave = batch.length > 20 || index ===
|
|
111
|
+
const shouldSave = batch.length > 20 || index === inputs.length;
|
|
97
112
|
if (shouldSave) {
|
|
98
113
|
await Promise.all(batch);
|
|
99
114
|
batch = [];
|
|
@@ -73,6 +73,10 @@ export class SandboxContext {
|
|
|
73
73
|
throw new Error(`Tool call '${toolName}' blocked by policy`);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
if (toolName === "executeScript") {
|
|
77
|
+
throw new Error("Nested script execution is not allowed in sandbox");
|
|
78
|
+
}
|
|
79
|
+
|
|
76
80
|
this.tracer.emitEvent("tool_call_start", {
|
|
77
81
|
toolName,
|
|
78
82
|
parameters: this.sanitizeForLogging(parameters),
|
|
@@ -206,7 +210,7 @@ export class SandboxContext {
|
|
|
206
210
|
|
|
207
211
|
async sleep(ms: number): Promise<void> {
|
|
208
212
|
if (typeof ms !== "number" || ms < 0 || ms > 2000) {
|
|
209
|
-
throw new Error("Invalid sleep duration");
|
|
213
|
+
throw new Error("Invalid sleep duration, sleep must be >0 and <2000");
|
|
210
214
|
}
|
|
211
215
|
await new Promise((res) => setTimeout(res, ms));
|
|
212
216
|
this.tracer.emitEvent("sleep", { durationMs: ms });
|
|
@@ -27,6 +27,7 @@ export class ScriptExecutor {
|
|
|
27
27
|
private defaultPolicy: SecurityPolicy = {
|
|
28
28
|
allowlistedTools: [], // Empty means all tools allowed
|
|
29
29
|
denylistedTools: [
|
|
30
|
+
"executeScript", // Circular script execution
|
|
30
31
|
"execCommand", // Dangerous system commands
|
|
31
32
|
"writeFileChunk", // File system write access
|
|
32
33
|
"patchFile", // File system modification
|
|
@@ -178,9 +178,6 @@ export class ScriptPolicyEnforcer {
|
|
|
178
178
|
/fetch\s*\(/gi, // Direct fetch calls
|
|
179
179
|
/XMLHttpRequest/gi, // XHR
|
|
180
180
|
/WebSocket/gi, // WebSocket
|
|
181
|
-
/location\./gi, // Location object
|
|
182
|
-
/document\./gi, // Document object
|
|
183
|
-
/window\./gi, // Window object
|
|
184
181
|
];
|
|
185
182
|
|
|
186
183
|
for (const pattern of dangerousPatterns) {
|
|
@@ -233,4 +230,4 @@ export class ScriptPolicyEnforcer {
|
|
|
233
230
|
|
|
234
231
|
this.violations.push(violation);
|
|
235
232
|
}
|
|
236
|
-
}
|
|
233
|
+
}
|
|
@@ -13,7 +13,7 @@ exports.executeScriptDefinition = {
|
|
|
13
13
|
- createArtifact(name, content, type): Create downloadable artifacts
|
|
14
14
|
- console: Standard console logging
|
|
15
15
|
- getQuotaUsage(): Check resource usage
|
|
16
|
-
- sleep(ms): Pause execution for a specified time
|
|
16
|
+
- sleep(ms): Pause execution for a specified time, max 2000ms
|
|
17
17
|
|
|
18
18
|
Example:
|
|
19
19
|
\`\`\`typescript
|
package/ts_build/src/chat.js
CHANGED
|
@@ -229,7 +229,6 @@ async function chatLoop(aiName, embeddings, plugins = []) {
|
|
|
229
229
|
default:
|
|
230
230
|
console.log("Thinking...");
|
|
231
231
|
console.log(input);
|
|
232
|
-
const formattedPrompt = await formatChatInput(input, plugins, chatHistory);
|
|
233
232
|
const interaction = {
|
|
234
233
|
input,
|
|
235
234
|
output: "",
|
|
@@ -244,6 +243,7 @@ async function chatLoop(aiName, embeddings, plugins = []) {
|
|
|
244
243
|
});
|
|
245
244
|
}
|
|
246
245
|
else {
|
|
246
|
+
const formattedPrompt = await formatChatInput(input, plugins, chatHistory);
|
|
247
247
|
results = await askAI(formattedPrompt, provider, model);
|
|
248
248
|
interaction.output = results;
|
|
249
249
|
console.log(utils_1.Marked.parse(results || "No response from the AI"));
|
package/ts_build/src/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/chat.ts"],"names":[],"mappings":";;;;;;AAEA,8DAAsC;AAStC,mCAAiC;AACjC,mCAA8B;AAC9B,+CAA4C;AAC5C,6CAAyE;AACzE,0CAAuC;AACvC,4CAAgD;AAGhD,6CAAwD;AACxD,6BAA8B;AAE9B,qCAAqC;AACrC,k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ACR,KAAK,QAAQ;gBACX,OAAO,qBAAqB,CAAC;gBAC7B,MAAM;YACR;gBACE,WAAW,CAAC,qBAAqB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;SACvE;QAED,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC;YACzB,QAAQ,CACN,gCAAgC,WAAW,CAAC,IAAI,IAAI,EACpD,QAAQ,EACR,OAAO,CACR;YACD,WAAW;SACZ,CAAC,CAAC;KACJ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlGD,gCAkGC"}
|
package/ts_build/src/cli.js
CHANGED
|
File without changes
|
|
@@ -84,21 +84,25 @@ async function embedSource(model, source, ignorePattern) {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
console.log("Embedding", source.input, "to", source.output);
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
let inputs = [];
|
|
88
|
+
const kind = source.kind || "file";
|
|
89
|
+
if (kind !== "file") {
|
|
90
|
+
inputs = await glob_1.default.sync(source.input, { ignore: ignorePattern });
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
if (source.kind && inputs.length === 0) {
|
|
93
|
+
inputs = [source.input];
|
|
94
|
+
}
|
|
95
|
+
console.log(`Found ${inputs.length} files`);
|
|
96
|
+
if (inputs.length > 100) {
|
|
93
97
|
console.error("woah there, that's a lot of files. I'm not going to embed that many");
|
|
94
98
|
}
|
|
95
|
-
console.log(
|
|
99
|
+
console.log(inputs);
|
|
96
100
|
const embeddings = await loadEmbedding(source.output);
|
|
97
101
|
let batch = [];
|
|
98
102
|
let index = 0;
|
|
99
|
-
for (const file of
|
|
103
|
+
for (const file of inputs) {
|
|
100
104
|
index++;
|
|
101
|
-
const shouldSave = batch.length > 20 || index ===
|
|
105
|
+
const shouldSave = batch.length > 20 || index === inputs.length;
|
|
102
106
|
if (shouldSave) {
|
|
103
107
|
await Promise.all(batch);
|
|
104
108
|
batch = [];
|