@j-o-r/hello-dave 0.0.5 → 0.0.6
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/CHANGELOG.md +8 -1
- package/bin/dave.js +114 -94
- package/examples/memory_agent.js +134 -23
- package/examples/test_agent.js +0 -2
- package/lib/genericToolset.js +4 -88
- package/lib/wsIO.js +1 -11
- package/package.json +2 -2
- package/README.md +0 -601
- package/README.md.backup +0 -269
- package/README.md.bak +0 -523
- package/README.md.bak.1774780058 +0 -338
- package/README.md.bak2 +0 -531
- package/docs.bak.1774780058/agent-manager.md +0 -167
- package/docs.bak.1774780058/agent-manager.md.bak +0 -137
- package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
- package/docs.bak.1774780058/codeserver-pattern.md +0 -191
- package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
- package/docs.bak.1774780058/project-overview.md +0 -67
- package/docs.bak.1774780058/project-overview.md.bak +0 -67
- package/docs.bak.1774780058/prompt-class.md +0 -141
- package/docs.bak.1774780058/prompt-class.md.bak +0 -142
- package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
- package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
- package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
- package/docs.bak.1774780058/toolset.md +0 -164
- package/docs.bak.1774780058/toolset.md.bak +0 -94
- package/docs.bak.1774780058/toolset.md.bak3 +0 -161
- package/docs.bak.1774780058/toolset.md.bak4 +0 -161
- package/docs.bak.1774780058/toolset.md.bak5 +0 -161
- package/docs.bak.1774780058/toolset.md.bak6 +0 -163
- package/docs.bak.1774780058/toolset.md.bak_path +0 -163
- package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
- package/docs.bak.1774780058/xai-responses.md +0 -111
- package/docs.bak.1774780058/xai-responses.md.bak +0 -107
- package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
- package/docs.bak.1774780058/xai_collections.md +0 -106
- package/examples.bak.1774780058/ask_agent.js +0 -114
- package/examples.bak.1774780058/code_agent.js +0 -149
- package/examples.bak.1774780058/coderev_agent.js +0 -72
- package/examples.bak.1774780058/codeserver.sh +0 -47
- package/examples.bak.1774780058/daisy_agent.js +0 -177
- package/examples.bak.1774780058/docs_agent.js +0 -119
- package/examples.bak.1774780058/gpt_agent.js +0 -109
- package/examples.bak.1774780058/grok_agent.js +0 -98
- package/examples.bak.1774780058/memory_agent.js +0 -112
- package/examples.bak.1774780058/npm_agent.js +0 -175
- package/examples.bak.1774780058/prompt_agent.js +0 -112
- package/examples.bak.1774780058/readme_agent.js +0 -144
- package/examples.bak.1774780058/spawn_agent.js +0 -263
- package/examples.bak.1774780058/test_agent.js +0 -162
- package/examples.bak.1774780058/todo_agent.js +0 -138
- package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
- package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
- package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
- package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
- package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
- package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
- package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
- package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
- package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
- package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
- package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
- package/scenarios.bak.1774780058/environment.js +0 -10
- package/scenarios.bak.1774780058/example.js +0 -17
- package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
- package/scenarios.bak.1774780058/grok.js +0 -113
- package/scenarios.bak.1774780058/memory-tools.js +0 -51
- package/scenarios.bak.1774780058/openai-o3.js +0 -137
- package/scenarios.bak.1774780058/openai-prompt.js +0 -155
- package/scenarios.bak.1774780058/openai-session.js +0 -148
- package/scenarios.bak.1774780058/openai.js +0 -102
- package/scenarios.bak.1774780058/prompt.js +0 -118
- package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
- package/scenarios.bak.1774780058/search.brave.com.js +0 -25
- package/scenarios.bak.1774780058/sh.js +0 -15
- package/scenarios.bak.1774780058/test-wsio.js +0 -26
- package/scenarios.bak.1774780058/testToolset.js +0 -42
- package/scenarios.bak.1774780058/toolset.js +0 -16
- package/scenarios.bak.1774780058/toolset.test.js +0 -141
- package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
- package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
- package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
- package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
- package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
- package/scenarios.bak.1774780058/wsClient.js +0 -69
- package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
- package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
- package/scenarios.bak.1774780058/xaicoll.js +0 -50
- package/scenarios.bak.1774780058/xaifiles.js +0 -48
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
# Syntax Validation in Generic Tools
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
Recent enhancements to `lib/genericToolset.js` introduce **automatic syntax validation** for files written via the `write_file` tool. This prevents invalid code deployment, resolves common **escaping issues** in JavaScript, and supports shebang executables. Validation occurs **post-write**, throwing descriptive errors to prompt LLM retries/fixes.
|
|
5
|
-
|
|
6
|
-
**Key Benefits**:
|
|
7
|
-
- **JS Safety**: `node --check` catches syntax errors (e.g., unescaped backticks in template literals).
|
|
8
|
-
- **Executable Prep**: Auto `chmod +x` for shebangs.
|
|
9
|
-
- **Retry-Friendly**: Errors include code preview + fix hints, enabling agent self-correction.
|
|
10
|
-
- **No Overhead**: Only for JS/shebang files; fast native checks.
|
|
11
|
-
|
|
12
|
-
**Commit History** (relevant):
|
|
13
|
-
- `3c8e1ae`: Added `read_file`, `write_file` with initial path security.
|
|
14
|
-
- Recent refinements: Syntax check + escaping guidance.
|
|
15
|
-
|
|
16
|
-
## write_file Tool Updates (`lib/genericToolset.js`)
|
|
17
|
-
|
|
18
|
-
### Updated Description
|
|
19
|
-
```
|
|
20
|
-
Write raw content to a file strictly within the current working directory (CWD). Paths must be relative (no leading /, no ..). Content written as-is (no escaping). **AUTO-VALIDATES JS FILES** with `node --check`; chmod +x shebangs. Retries syntax errors force LLM fix.
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Validation Logic
|
|
24
|
-
```javascript
|
|
25
|
-
// After fs.writeFile(resolvedPath, content, 'utf8');
|
|
26
|
-
const ext = path.extname(file).toLowerCase();
|
|
27
|
-
const isJS = ext === '.js' || content.startsWith('#!/usr/bin/env node');
|
|
28
|
-
const hasShebang = content.startsWith('#!');
|
|
29
|
-
|
|
30
|
-
if (isJS) {
|
|
31
|
-
try {
|
|
32
|
-
await SH`node --check ${[resolvedPath]}`.run();
|
|
33
|
-
validationMsg = ' ✓ JS syntax OK';
|
|
34
|
-
} catch (e) {
|
|
35
|
-
const errPreview = content.slice(0, 1000).split('\\n').slice(0, 20).join('\\n');
|
|
36
|
-
throw new Error(`❌ JS SYNTAX ERROR in '${file}' (node --check failed):
|
|
37
|
-
${e.message}
|
|
38
|
-
|
|
39
|
-
PREVIEW:
|
|
40
|
-
${errPreview}
|
|
41
|
-
|
|
42
|
-
... Fix escaping/backticks in template literals (use \\\\` for \` in JS strings) and retry.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (hasShebang) {
|
|
46
|
-
await SH`chmod +x ${[resolvedPath]}`.run();
|
|
47
|
-
validationMsg += ' ✓ chmod +x';
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Escaping Issues Resolved
|
|
52
|
-
- **Backticks in JS Strings**: Common LLM error—generates `` `hi` `` inside strings without escaping. Hint: `use \\\\` for \` in JS strings`.
|
|
53
|
-
- **Template Literals**: Ensures `` \` ${var} \` `` is valid; catches mismatched quotes.
|
|
54
|
-
- **Raw Content**: Verbatim write (newlines, `$|<> & " '\\`` preserved), but syntax-enforced.
|
|
55
|
-
- **No False Positives**: Only triggers on `.js` ext or Node shebang; preview limits noise.
|
|
56
|
-
|
|
57
|
-
**Example Error (LLM Sees)**:
|
|
58
|
-
```
|
|
59
|
-
❌ JS SYNTAX ERROR in 'test.js' (node --check failed):
|
|
60
|
-
SyntaxError: Unexpected token `
|
|
61
|
-
|
|
62
|
-
PREVIEW:
|
|
63
|
-
const msg = `Hello ${name}
|
|
64
|
-
...
|
|
65
|
-
|
|
66
|
-
... Fix escaping/backticks in template literals (use \\\\` for \` in JS strings) and retry.
|
|
67
|
-
```
|
|
68
|
-
- **LLM Fix**: Rewrites with `"Hello \${name}"` or proper `` \` `` nesting.
|
|
69
|
-
|
|
70
|
-
### Usage in Agents
|
|
71
|
-
```javascript
|
|
72
|
-
agent.addGenericToolcall('write_file'); // Auto-includes validation
|
|
73
|
-
await agent.directCall("Write test.js: const x = `hi`; console.log(x);"); // Passes
|
|
74
|
-
// Fails + retries: "Write test.js: const x = `hi; console.log(x);" → SyntaxError → Fix
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Multi-Language Syntax Validation (utils/syntax_check.sh)
|
|
78
|
-
|
|
79
|
-
**New Utility**: `./utils/syntax_check.sh` – Standalone script for **JS, Python, Bash, JSON**. Detects lang via ext/shebang, runs native checkers. Exit 0=OK, 1=error. Integrates as future `write_file` extension or new tool.
|
|
80
|
-
|
|
81
|
-
### Features
|
|
82
|
-
| Lang | Checker | Optional | Notes |
|
|
83
|
-
|------|---------|----------|-------|
|
|
84
|
-
| **JS** | `node --check` | - | Syntax only (no runtime). |
|
|
85
|
-
| **Python** | `python3 -m py_compile` | - | Bytecode compile. |
|
|
86
|
-
| **Bash/Sh** | `bash -n` + `shellcheck` | Shellcheck | Static + linter. |
|
|
87
|
-
| **JSON** | `node -e JSON.parse(...)` | - | Parse validation. |
|
|
88
|
-
| **Unknown** | Skip | - | Non-fatal. |
|
|
89
|
-
|
|
90
|
-
### Usage
|
|
91
|
-
```bash
|
|
92
|
-
./utils/syntax_check.sh path/to/file.js # 🔍 JS OK / ❌ error
|
|
93
|
-
./utils/syntax_check.sh script.py --verbose # Extra output
|
|
94
|
-
# Future: --fix (auto-retry via agent?)
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Script Source (utils/syntax_check.sh)
|
|
98
|
-
```bash
|
|
99
|
-
#!/bin/bash
|
|
100
|
-
set -euo pipefail
|
|
101
|
-
# Full script: Detects lang, validates, echoes status.
|
|
102
|
-
# Created: March 27, 2026
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Integration Proposal: New Tool `syntax_check`
|
|
106
|
-
Add to `ToolSet` / `genericToolset.js`:
|
|
107
|
-
```javascript
|
|
108
|
-
tools.add('syntax_check', 'Validate file syntax (JS/Py/Bash/JSON).', {
|
|
109
|
-
type: 'object',
|
|
110
|
-
properties: { file: {type: 'string'} },
|
|
111
|
-
required: ['file']
|
|
112
|
-
}, async ({file}) => {
|
|
113
|
-
const script = path.resolve(__dirname, '..', 'utils', 'syntax_check.sh');
|
|
114
|
-
return await SH`${script} "${file}"`.run();
|
|
115
|
-
});
|
|
116
|
-
```
|
|
117
|
-
- **Post-write Call**: `write_file` → `syntax_check` → LLM fix loop.
|
|
118
|
-
- **Extend write_file**: Run `./syntax_check.sh "$file"` after JS check.
|
|
119
|
-
|
|
120
|
-
**Cross-Links**:
|
|
121
|
-
- [ToolSet](../toolset.md#generic-tools)
|
|
122
|
-
- [AgentManager](../agent-manager.md#custom-tools--generics)
|
|
123
|
-
- Source: [lib/genericToolset.js](../lib/genericToolset.js)
|
|
124
|
-
|
|
125
|
-
**Updated**: March 27, 2026
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
# Syntax Validation in Generic Tools
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
Recent enhancements to `lib/genericToolset.js` introduce **automatic syntax validation** for files written via the `write_file` tool. This prevents invalid code deployment, resolves common **escaping issues** in JavaScript, and supports shebang executables. Validation occurs **post-write**, throwing descriptive errors to prompt LLM retries/fixes.
|
|
5
|
-
|
|
6
|
-
**Key Benefits**:
|
|
7
|
-
- **JS Safety**: `node --check` catches syntax errors (e.g., unescaped backticks in template literals).
|
|
8
|
-
- **Executable Prep**: Auto `chmod +x` for shebangs.
|
|
9
|
-
- **Retry-Friendly**: Errors include code preview + fix hints, enabling agent self-correction.
|
|
10
|
-
- **No Overhead**: Only for JS/shebang files; fast native checks.
|
|
11
|
-
|
|
12
|
-
**Commit History** (relevant):
|
|
13
|
-
- `3c8e1ae`: Added `read_file`, `write_file` with initial path security.
|
|
14
|
-
- Recent refinements: Syntax check + escaping guidance.
|
|
15
|
-
|
|
16
|
-
## write_file Tool Updates (`lib/genericToolset.js`)
|
|
17
|
-
|
|
18
|
-
### Updated Description
|
|
19
|
-
```
|
|
20
|
-
Write raw content to a file strictly within the current working directory (CWD). Paths must be relative (no leading /, no ..). Content written as-is (no escaping). **AUTO-VALIDATES JS FILES** with `node --check`; chmod +x shebangs. Retries syntax errors force LLM fix.
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Validation Logic
|
|
24
|
-
```javascript
|
|
25
|
-
// After fs.writeFile(resolvedPath, content, 'utf8');
|
|
26
|
-
const ext = path.extname(file).toLowerCase();
|
|
27
|
-
const isJS = ext === '.js' || content.startsWith('#!/usr/bin/env node');
|
|
28
|
-
const hasShebang = content.startsWith('#!');
|
|
29
|
-
|
|
30
|
-
if (isJS) {
|
|
31
|
-
try {
|
|
32
|
-
await SH`node --check ${[resolvedPath]}`.run();
|
|
33
|
-
validationMsg = ' ✓ JS syntax OK';
|
|
34
|
-
} catch (e) {
|
|
35
|
-
const errPreview = content.slice(0, 1000).split('\\n').slice(0, 20).join('\\n');
|
|
36
|
-
throw new Error(`❌ JS SYNTAX ERROR in '${file}' (node --check failed):
|
|
37
|
-
${e.message}
|
|
38
|
-
|
|
39
|
-
PREVIEW:
|
|
40
|
-
${errPreview}
|
|
41
|
-
|
|
42
|
-
... Fix escaping/backticks in template literals (use \\\\` for \` in JS strings) and retry.`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (hasShebang) {
|
|
46
|
-
await SH`chmod +x ${[resolvedPath]}`.run();
|
|
47
|
-
validationMsg += ' ✓ chmod +x';
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Escaping Issues Resolved
|
|
52
|
-
- **Backticks in JS Strings**: Common LLM error—generates `` `hi` `` inside strings without escaping. Hint: `use \\\\` for \` in JS strings`.
|
|
53
|
-
- **Template Literals**: Ensures `` \` ${var} \` `` is valid; catches mismatched quotes.
|
|
54
|
-
- **Raw Content**: Verbatim write (newlines, `$|<> & " '\\`` preserved), but syntax-enforced.
|
|
55
|
-
- **No False Positives**: Only triggers on `.js` ext or Node shebang; preview limits noise.
|
|
56
|
-
|
|
57
|
-
**Example Error (LLM Sees)**:
|
|
58
|
-
```
|
|
59
|
-
❌ JS SYNTAX ERROR in 'test.js' (node --check failed):
|
|
60
|
-
SyntaxError: Unexpected token `
|
|
61
|
-
|
|
62
|
-
PREVIEW:
|
|
63
|
-
const msg = `Hello ${name}
|
|
64
|
-
...
|
|
65
|
-
|
|
66
|
-
... Fix escaping/backticks in template literals (use \\\\` for \` in JS strings) and retry.
|
|
67
|
-
```
|
|
68
|
-
- **LLM Fix**: Rewrites with `"Hello \${name}"` or proper `` \` `` nesting.
|
|
69
|
-
|
|
70
|
-
### Usage in Agents
|
|
71
|
-
```javascript
|
|
72
|
-
agent.addGenericToolcall('write_file'); // Auto-includes validation
|
|
73
|
-
await agent.directCall("Write test.js: const x = `hi`; console.log(x);"); // Passes
|
|
74
|
-
// Fails + retries: "Write test.js: const x = `hi; console.log(x);" → SyntaxError → Fix
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## Multi-Language Syntax Validation (utils/syntax_check.sh)
|
|
78
|
-
|
|
79
|
-
**New Utility**: `./utils/syntax_check.sh` – Standalone script for **JS, Python, Bash, JSON**. Detects lang via ext/shebang, runs native checkers. Exit 0=OK, 1=error. Integrates as future `write_file` extension or new tool.
|
|
80
|
-
|
|
81
|
-
### Features
|
|
82
|
-
| Lang | Checker | Optional | Notes |
|
|
83
|
-
|------|---------|----------|-------|
|
|
84
|
-
| **JS** | `node --check` | - | Syntax only (no runtime). |
|
|
85
|
-
| **Python** | `python3 -m py_compile` | - | Bytecode compile. |
|
|
86
|
-
| **Bash/Sh** | `bash -n` + `shellcheck` | Shellcheck | Static + linter. |
|
|
87
|
-
| **JSON** | `node -e JSON.parse(...)` | - | Parse validation. |
|
|
88
|
-
| **Unknown** | Skip | - | Non-fatal. |
|
|
89
|
-
|
|
90
|
-
### Usage
|
|
91
|
-
```bash
|
|
92
|
-
./utils/syntax_check.sh path/to/file.js # 🔍 JS OK / ❌ error
|
|
93
|
-
./utils/syntax_check.sh script.py --verbose # Extra output
|
|
94
|
-
# Future: --fix (auto-retry via agent?)
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
### Script Source (utils/syntax_check.sh)
|
|
98
|
-
```bash
|
|
99
|
-
#!/bin/bash
|
|
100
|
-
set -euo pipefail
|
|
101
|
-
# Full script: Detects lang, validates, echoes status.
|
|
102
|
-
# Created: March 27, 2026
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Integration Proposal: New Tool `syntax_check`
|
|
106
|
-
Add to `ToolSet` / `genericToolset.js`:
|
|
107
|
-
```javascript
|
|
108
|
-
tools.add('syntax_check', 'Validate file syntax (JS/Py/Bash/JSON).', {
|
|
109
|
-
type: 'object',
|
|
110
|
-
properties: { file: {type: 'string'} },
|
|
111
|
-
required: ['file']
|
|
112
|
-
}, async ({file}) => {
|
|
113
|
-
const script = path.resolve(__dirname, '..', 'utils', 'syntax_check.sh');
|
|
114
|
-
return await SH`${script} "${file}"`.run();
|
|
115
|
-
});
|
|
116
|
-
```
|
|
117
|
-
- **Post-write Call**: `write_file` → `syntax_check` → LLM fix loop.
|
|
118
|
-
- **Extend write_file**: Run `./syntax_check.sh "$file"` after JS check.
|
|
119
|
-
|
|
120
|
-
**Cross-Links**:
|
|
121
|
-
- [ToolSet](../toolset.md#generic-tools)
|
|
122
|
-
- [AgentManager](../agent-manager.md#custom-tools--generics)
|
|
123
|
-
- Source: [lib/genericToolset.js](../lib/genericToolset.js)
|
|
124
|
-
|
|
125
|
-
**Updated**: March 27, 2026
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# Syntax Validation in Generic Tools
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
**Integration Complete**: `lib/genericToolset.js` now includes **automatic JS syntax validation** in `write_file` **and a new `syntax_check` tool** using `./utils/syntax_check.sh` for multi-language support (JS/Python/Bash/JSON). Prevents invalid code, resolves escaping issues, auto `chmod +x` shebangs. Post-write errors prompt LLM retries.
|
|
5
|
-
|
|
6
|
-
**Key Benefits**:
|
|
7
|
-
- **JS Safety**: `node --check` (in `write_file`); full multi-lang in `syntax_check`.
|
|
8
|
-
- **Executable Prep**: Auto `chmod +x`.
|
|
9
|
-
- **Retry-Friendly**: Descriptive errors + previews.
|
|
10
|
-
- **Generic Access**: `toolsetMode: 'auto'` loads both.
|
|
11
|
-
|
|
12
|
-
**Commit History** (relevant):
|
|
13
|
-
- `3c8e1ae`: Initial `read_file`/`write_file`.
|
|
14
|
-
- Recent: JS validation + `syntax_check` tool.
|
|
15
|
-
|
|
16
|
-
## write_file Tool Updates
|
|
17
|
-
|
|
18
|
-
### Description (Updated)
|
|
19
|
-
```
|
|
20
|
-
Write raw content to a file strictly within the current working directory (CWD). Paths must be relative (no leading /, no ..). Content written as-is (no escaping). **AUTO-VALIDATES JS FILES** with `node --check`; chmod +x shebangs. Retries syntax errors force LLM fix.
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Examples
|
|
24
|
-
**Success** (CLI/Agent):
|
|
25
|
-
```bash
|
|
26
|
-
echo 'const x = \`hi\`; console.log(x);' | agent.directCall("Use write_file on test.js with this content")
|
|
27
|
-
# Returns: "Successfully wrote to 'test.js' (42 bytes). ✓ JS syntax OK"
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Failure + Retry**:
|
|
31
|
-
```javascript
|
|
32
|
-
// LLM generates invalid:
|
|
33
|
-
const msg = `Hello ${name`; // Missing `
|
|
34
|
-
```
|
|
35
|
-
**Error**:
|
|
36
|
-
```
|
|
37
|
-
❌ JS SYNTAX ERROR in 'test.js' (node --check failed):
|
|
38
|
-
SyntaxError: Unexpected token '}'
|
|
39
|
-
|
|
40
|
-
PREVIEW:
|
|
41
|
-
const msg = `Hello ${name
|
|
42
|
-
...
|
|
43
|
-
|
|
44
|
-
... Fix escaping/backticks in template literals (use \\\\` for \` in JS strings) and retry.
|
|
45
|
-
```
|
|
46
|
-
**LLM Sees → Fixes**: Uses `"Hello \${name}"` or proper `` \` ``.
|
|
47
|
-
|
|
48
|
-
**Shebang**:
|
|
49
|
-
```javascript
|
|
50
|
-
content: '#!/usr/bin/env node\nconst hello = () => console.log("Hi");'
|
|
51
|
-
# Returns: "... ✓ JS syntax OK ✓ chmod +x"
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## New: syntax_check Tool
|
|
55
|
-
|
|
56
|
-
**Description**:
|
|
57
|
-
```
|
|
58
|
-
Validate syntax of a file (JS, Python, Bash/Sh, JSON). Detects language from extension/shebang. Uses native checkers... Exit 1 on fail.
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Parameters
|
|
62
|
-
```json
|
|
63
|
-
{
|
|
64
|
-
"type": "object",
|
|
65
|
-
"properties": { "file": { "type": "string" } },
|
|
66
|
-
"required": ["file"]
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Examples
|
|
71
|
-
**Agent Call**:
|
|
72
|
-
```
|
|
73
|
-
agent.directCall("Use syntax_check on test.js") → "🔍 Validating test.js (lang: js)\n✅ JS OK\n✅ Syntax validation passed for test.js"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**Multi-Lang**:
|
|
77
|
-
- **Python**: `syntax_check script.py` → `✅ Python OK`
|
|
78
|
-
- **Bash**: `syntax_check script.sh` → `✅ Bash OK` ( + Shellcheck if avail.)
|
|
79
|
-
- **JSON**: `syntax_check config.json` → `✅ JSON OK`
|
|
80
|
-
- **Fail**: Invalid JSON → `❌ JSON invalid`
|
|
81
|
-
|
|
82
|
-
**Integration**: Post-`write_file`, agent can call `syntax_check(file)` for non-JS.
|
|
83
|
-
|
|
84
|
-
## utils/syntax_check.sh (Underlying Script)
|
|
85
|
-
[Full source in prior doc]. Detects lang, runs checkers. Standalone/executable.
|
|
86
|
-
|
|
87
|
-
### Usage (Direct)
|
|
88
|
-
```bash
|
|
89
|
-
./utils/syntax_check.sh test.js # ✅ JS OK
|
|
90
|
-
./utils/syntax_check.sh bad.py # ❌ Python syntax error
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Agent Workflow Example
|
|
94
|
-
```
|
|
95
|
-
User: "Create & validate test.js: const add = (a,b) => a+b; export {add};"
|
|
96
|
-
Agent:
|
|
97
|
-
1. write_file(test.js, content) → ✓ JS OK
|
|
98
|
-
2. syntax_check(test.js) → ✅ (redundant but confirms)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Cross-Links
|
|
102
|
-
- [ToolSet](../toolset.md#generic-tools) ← [Linked below](#update-to-toolsetmd)
|
|
103
|
-
- [AgentManager](../agent-manager.md)
|
|
104
|
-
- Source: [lib/genericToolset.js](../lib/genericToolset.js), [utils/syntax_check.sh](../utils/syntax_check.sh)
|
|
105
|
-
|
|
106
|
-
**Updated**: March 27, 2026 (syntax_check integrated).
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
# Syntax Validation in Generic Tools
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
**Integration Complete**: `lib/genericToolset.js` now includes **automatic JS syntax validation** in `write_file` **and a new `syntax_check` tool** using `./utils/syntax_check.sh` for multi-language support (JS/Python/Bash/JSON). Prevents invalid code, resolves escaping issues, auto `chmod +x` shebangs. Post-write errors prompt LLM retries.
|
|
5
|
-
|
|
6
|
-
**Key Benefits**:
|
|
7
|
-
- **JS Safety**: `node --check` (in `write_file`); full multi-lang in `syntax_check`.
|
|
8
|
-
- **Executable Prep**: Auto `chmod +x`.
|
|
9
|
-
- **Retry-Friendly**: Descriptive errors + previews.
|
|
10
|
-
- **Generic Access**: `toolsetMode: 'auto'` loads both.
|
|
11
|
-
|
|
12
|
-
**Commit History** (relevant):
|
|
13
|
-
- `3c8e1ae`: Initial `read_file`/`write_file`.
|
|
14
|
-
- Recent: JS validation + `syntax_check` tool.
|
|
15
|
-
|
|
16
|
-
## write_file Tool Updates
|
|
17
|
-
|
|
18
|
-
### Description (Updated)
|
|
19
|
-
```
|
|
20
|
-
Write raw content to a file strictly within the current working directory (CWD). Paths must be relative (no leading /, no ..). Content written as-is (no escaping). **AUTO-VALIDATES JS FILES** with `node --check`; chmod +x shebangs. Retries syntax errors force LLM fix.
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
### Examples
|
|
24
|
-
**Success** (CLI/Agent):
|
|
25
|
-
```bash
|
|
26
|
-
echo 'const x = \`hi\`; console.log(x);' | agent.directCall("Use write_file on test.js with this content")
|
|
27
|
-
# Returns: "Successfully wrote to 'test.js' (42 bytes). ✓ JS syntax OK"
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
**Failure + Retry**:
|
|
31
|
-
```javascript
|
|
32
|
-
// LLM generates invalid:
|
|
33
|
-
const msg = `Hello ${name`; // Missing `
|
|
34
|
-
```
|
|
35
|
-
**Error**:
|
|
36
|
-
```
|
|
37
|
-
❌ JS SYNTAX ERROR in 'test.js' (node --check failed):
|
|
38
|
-
SyntaxError: Unexpected token '}'
|
|
39
|
-
|
|
40
|
-
PREVIEW:
|
|
41
|
-
const msg = `Hello ${name
|
|
42
|
-
...
|
|
43
|
-
|
|
44
|
-
... Fix escaping/backticks in template literals (use \\\\` for \` in JS strings) and retry.
|
|
45
|
-
```
|
|
46
|
-
**LLM Sees → Fixes**: Uses `"Hello \${name}"` or proper `` \` ``.
|
|
47
|
-
|
|
48
|
-
**Shebang**:
|
|
49
|
-
```javascript
|
|
50
|
-
content: '#!/usr/bin/env node\nconst hello = () => console.log("Hi");'
|
|
51
|
-
# Returns: "... ✓ JS syntax OK ✓ chmod +x"
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## New: syntax_check Tool
|
|
55
|
-
|
|
56
|
-
**Description**:
|
|
57
|
-
```
|
|
58
|
-
Validate syntax of a file (JS, Python, Bash/Sh, JSON). Detects language from extension/shebang. Uses native checkers... Exit 1 on fail.
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Parameters
|
|
62
|
-
```json
|
|
63
|
-
{
|
|
64
|
-
"type": "object",
|
|
65
|
-
"properties": { "file": { "type": "string" } },
|
|
66
|
-
"required": ["file"]
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Examples
|
|
71
|
-
**Agent Call**:
|
|
72
|
-
```
|
|
73
|
-
agent.directCall("Use syntax_check on test.js") → "🔍 Validating test.js (lang: js)\n✅ JS OK\n✅ Syntax validation passed for test.js"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**Multi-Lang**:
|
|
77
|
-
- **Python**: `syntax_check script.py` → `✅ Python OK`
|
|
78
|
-
- **Bash**: `syntax_check script.sh` → `✅ Bash OK` ( + Shellcheck if avail.)
|
|
79
|
-
- **JSON**: `syntax_check config.json` → `✅ JSON OK`
|
|
80
|
-
- **Fail**: Invalid JSON → `❌ JSON invalid`
|
|
81
|
-
|
|
82
|
-
**Integration**: Post-`write_file`, agent can call `syntax_check(file)` for non-JS.
|
|
83
|
-
|
|
84
|
-
## utils/syntax_check.sh (Underlying Script)
|
|
85
|
-
[Full source in prior doc]. Detects lang, runs checkers. Standalone/executable.
|
|
86
|
-
|
|
87
|
-
### Usage (Direct)
|
|
88
|
-
```bash
|
|
89
|
-
./utils/syntax_check.sh test.js # ✅ JS OK
|
|
90
|
-
./utils/syntax_check.sh bad.py # ❌ Python syntax error
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
## Agent Workflow Example
|
|
94
|
-
```
|
|
95
|
-
User: "Create & validate test.js: const add = (a,b) => a+b; export {add};"
|
|
96
|
-
Agent:
|
|
97
|
-
1. write_file(test.js, content) → ✓ JS OK
|
|
98
|
-
2. syntax_check(test.js) → ✅ (redundant but confirms)
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
## Cross-Links
|
|
102
|
-
- [ToolSet](../toolset.md#generic-tools) ← [Linked below](#update-to-toolsetmd)
|
|
103
|
-
- [AgentManager](../agent-manager.md)
|
|
104
|
-
- Source: [lib/genericToolset.js](../lib/genericToolset.js), [utils/syntax_check.sh](../utils/syntax_check.sh)
|
|
105
|
-
|
|
106
|
-
**Updated**: March 27, 2026 (syntax_check integrated).
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
# ToolSet (\`lib/ToolSet.js\`)
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
**ToolSet** manages LLM function calls (tools): registration, execution, listing. Integrates with \`Prompt.js\` (via \`execute(prompt)\`) and \`AgentManager.js\` (pre-configured modes, generics). Supports JSON Schema params, async methods. Exports from \`lib/genericToolset.js\`: \`toolsPool\` (11 pre-built tools).
|
|
5
|
-
|
|
6
|
-
**Uses named exports from \`lib/index.js\` - NO default export.**
|
|
7
|
-
|
|
8
|
-
Key Features:
|
|
9
|
-
- **Modes**: \`toolChoice: 'auto'|'none'|'required'\` (default \`'auto'\`).
|
|
10
|
-
- **Validation**: Name regex \`/^\[#![a-z_0-9]{2,}$/\`.
|
|
11
|
-
- **Events** (via \`Prompt\`): \`tool_request\`, \`tool_error\`, \`tool_response\`.
|
|
12
|
-
- **Execution**: \`execute(prompt)\` processes \`function_request\`s from last message → calls → adds \`function_response\`s.
|
|
13
|
-
|
|
14
|
-
## Constructor
|
|
15
|
-
\`\`\`javascript
|
|
16
|
-
import { ToolSet } from '@j-o-r/hello-dave';
|
|
17
|
-
|
|
18
|
-
new ToolSet(choice = 'auto'); // 'auto'|'none'|'required'
|
|
19
|
-
\`\`\`
|
|
20
|
-
|
|
21
|
-
## Methods
|
|
22
|
-
| Method | Args | Returns | Description |
|
|
23
|
-
|--------|------|---------|-------------|
|
|
24
|
-
| \`add(name, desc, params, method)\` | \`string\`, \`string\`, \`TSSchema\`, \`async (params) => *\` | \`void\` | Register tool. Overwrites if exists. |
|
|
25
|
-
| \`get(name)\` | \`string\` | \`TSTool\` | Get tool details. |
|
|
26
|
-
| \`delete(name)\` | \`string\` | \`void\` | Remove tool. |
|
|
27
|
-
| \`has(name)\` | \`string\` | \`boolean\` | Exists? |
|
|
28
|
-
| \`list()\` | - | \`TSToolListItem[]\` (sorted) | All tools (name/desc/params). |
|
|
29
|
-
| \`call(name, params)\` | \`string\`, \`object\` | \`Promise<*\>\` | Execute tool. |
|
|
30
|
-
| \`execute(prompt)\` | \`Prompt\` | \`Promise<void>\` | Process last message \`function_request\`s → execute → add \`function_response\`s to \`tool\` role. |
|
|
31
|
-
| \`length\` | - | \`number\` | Tool count. |
|
|
32
|
-
| \`toolChoice\` | - | \`string\` | Getter for mode. |
|
|
33
|
-
|
|
34
|
-
**TSTool**: \`{description: string, parameters: TSSchema, method: async (params) => *}\`
|
|
35
|
-
**TSSchema**: OpenAI-style JSON Schema (\`{type: 'object', properties: {...}, required: [...]}\`).
|
|
36
|
-
|
|
37
|
-
## Generic Tools (\`lib/genericToolset.js\` → \`toolsPool\`)
|
|
38
|
-
| `syntax_check` | Validate syntax (JS/Py/Bash/JSON) via utils/syntax_check.sh. |\n|-----|-----|
|
|
39
|
-
Pre-built \`ToolSet('auto')\` with **11 tools**. Copied via \`AgentManager.addGenericToolcall(name)\` or \`toolsetMode: 'auto'\`.
|
|
40
|
-
|
|
41
|
-
| Tool Name | Description |
|
|
42
|
-
|----------------------------|-------------|
|
|
43
|
-
| \`javascript_interpreter\` | Execute ESM ES6 JavaScript on \`node\`. \`console.log\` captures output. cwd: \`~/devpri/js/hello-dave\`. |
|
|
44
|
-
| \`get_user_env\` | Get user environment (name, system, city/region/country/timezone, external IP). |
|
|
45
|
-
| \`execute_bash_script\` | Execute raw Bash script/command (no escaping; verbatim \`$\| < > & " ' \\\\` newlines \`$(())\` \`[[ ]]\`. Heredoc-safe). Ubuntu 25.10. |
|
|
46
|
-
| \`send_email\` | Send email via \`msmtp\` (to, subject, body). |
|
|
47
|
-
| \`open_link\` | Open URL/file with \`xdg-open\`. |
|
|
48
|
-
| \`execute_remote_script\` | Execute raw Bash on remote via SSH (\`ssh://user@host[:port]\`). |
|
|
49
|
-
| \`history_search\` | Search chat sessions: \`"(todo\\|task)"\` or \`"package.json"\`. Regex in \`.cache/[app]/[prompt]/sessions/*.ndjson\`. |
|
|
50
|
-
| \`read_file\` | Read raw file in CWD (relative path, no \`/\` \`..\` \`\\\\\`). |
|
|
51
|
-
| \`write_file\` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
|
|
52
|
-
| \`memory_recall\` | Recall persistent memory entries from agent-specific storage (\`.cache/[agent]/memory.ndjson\`). |
|
|
53
|
-
| \`memory_write\` | Write/update persistent memory entries for long-term state (\`.cache/[agent]/memory.ndjson\`). |
|
|
54
|
-
|
|
55
|
-
## Memory Tools (New)
|
|
56
|
-
These tools provide persistent, agent-specific memory storage in NDJSON format (\`.cache/[agent-name]/memory.ndjson\`). Append-only; latest value per key. Ideal for token efficiency by offloading state/decisions from context.
|
|
57
|
-
|
|
58
|
-
### \`memory_recall\`
|
|
59
|
-
**Description**: Retrieve the latest values for specified keys from memory file. Returns JSON: \`{key: value, ...}\` or \`{}\` if missing.
|
|
60
|
-
|
|
61
|
-
**Parameters**:
|
|
62
|
-
\`\`\`json
|
|
63
|
-
{
|
|
64
|
-
"type": "object",
|
|
65
|
-
"properties": {
|
|
66
|
-
"keys": {
|
|
67
|
-
"type": "array",
|
|
68
|
-
"items": { "type": "string" },
|
|
69
|
-
"description": "List of memory keys to recall, e.g., ['current_task', 'last_decision']"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
"required": ["keys"]
|
|
73
|
-
}
|
|
74
|
-
\`\`\`
|
|
75
|
-
|
|
76
|
-
**Example Usage in Agent Prompt**:
|
|
77
|
-
\`\`\`
|
|
78
|
-
Before proceeding, recall your current task and previous decision:
|
|
79
|
-
- Call memory_recall with keys: ["current_task", "last_decision"]
|
|
80
|
-
Then, use the recalled info to avoid repetition.
|
|
81
|
-
\`\`\`
|
|
82
|
-
|
|
83
|
-
**Token Efficiency**: Stores tasks/decisions externally. Recall only needed state (e.g., 100 tokens) vs. full history (10k+ tokens), preventing loops/re-reasoning.
|
|
84
|
-
|
|
85
|
-
### \`memory_write\`
|
|
86
|
-
**Description**: Append/update key-value pairs to memory (overwrites prior same-key entries). Returns confirmation with stored entries.
|
|
87
|
-
|
|
88
|
-
**Parameters**:
|
|
89
|
-
\`\`\`json
|
|
90
|
-
{
|
|
91
|
-
"type": "object",
|
|
92
|
-
"properties": {
|
|
93
|
-
"entries": {
|
|
94
|
-
"type": "array",
|
|
95
|
-
"items": {
|
|
96
|
-
"type": "object",
|
|
97
|
-
"properties": {
|
|
98
|
-
"key": { "type": "string", "description": "Unique key (e.g., 'current_task')" },
|
|
99
|
-
"value": { "type": "string", "description": "JSON-stringifiable value" }
|
|
100
|
-
},
|
|
101
|
-
"required": ["key", "value"]
|
|
102
|
-
},
|
|
103
|
-
"description": "List of {key, value} pairs to store"
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"required": ["entries"]
|
|
107
|
-
}
|
|
108
|
-
\`\`\`
|
|
109
|
-
|
|
110
|
-
**Example Usage in Agent Prompt**:
|
|
111
|
-
\`\`\`
|
|
112
|
-
After analyzing, store the plan:
|
|
113
|
-
- Call memory_write with entries: [{"key": "current_task", "value": "Implement login feature"}, {"key": "step", "value": "1/5"}]
|
|
114
|
-
\`\`\`
|
|
115
|
-
|
|
116
|
-
**Token Efficiency**: Persist intermediate results across calls/sessions. Avoids context explosion/loops by recalling compact state instead of regenerating.
|
|
117
|
-
|
|
118
|
-
## Integration with AgentManager
|
|
119
|
-
In \`setup()\`:
|
|
120
|
-
\`\`\`javascript
|
|
121
|
-
agent.setup({
|
|
122
|
-
toolsetMode: 'auto', // Loads all 11 generic tools
|
|
123
|
-
// or 'required': Empty ToolSet (add manually)
|
|
124
|
-
});
|
|
125
|
-
agent.addGenericToolcall('memory_recall'); // Selective copy post-setup
|
|
126
|
-
\`\`\`
|
|
127
|
-
|
|
128
|
-
**Custom Tools**:
|
|
129
|
-
\`\`\`javascript
|
|
130
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
131
|
-
|
|
132
|
-
agent.setup({ toolsetMode: 'required' });
|
|
133
|
-
const ts = agent.getToolset();
|
|
134
|
-
ts.add('math', 'Add numbers', {
|
|
135
|
-
type: 'object',
|
|
136
|
-
properties: {a: {type: 'number'}, b: {type: 'number'}},
|
|
137
|
-
required: ['a', 'b']
|
|
138
|
-
}, async ({a, b}) => a + b);
|
|
139
|
-
\`\`\`
|
|
140
|
-
|
|
141
|
-
**Workflow** (in \`Prompt.call()\` / API adapters):
|
|
142
|
-
1. LLM → \`function_request\`s (assistant message).
|
|
143
|
-
2. \`ToolSet.execute(prompt)\` → parallel \`call()\` → \`function_response\`s (tool message).
|
|
144
|
-
3. Recurse until text response.
|
|
145
|
-
|
|
146
|
-
## Examples
|
|
147
|
-
### Standalone ToolSet
|
|
148
|
-
\`\`\`javascript
|
|
149
|
-
import { ToolSet } from '@j-o-r/hello-dave';
|
|
150
|
-
|
|
151
|
-
const ts = new ToolSet('required');
|
|
152
|
-
ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
|
|
153
|
-
async ({name}) => \`Hello, \${name}!\`);
|
|
154
|
-
console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
|
|
155
|
-
\`\`\`
|
|
156
|
-
|
|
157
|
-
### With Prompt/AgentManager
|
|
158
|
-
See [AgentManager](./agent-manager.md#custom-tools--generics), [Prompt](./prompt-class.md).
|
|
159
|
-
|
|
160
|
-
**Updated:** March 26, 2026 (11 generics from \`lib/genericToolset.js\`).
|
|
161
|
-
|
|
162
|
-
See also: [GenericToolset Source](./generic-toolset.md).
|
|
163
|
-
\n## Syntax Validation\nSee [tools-syntax-validation.md](tools-syntax-validation.md) for `write_file` JS checks + `syntax_check` tool.
|
|
164
|
-
\n## Path Resolution\nSee [path-resolution-best-practices.md](path-resolution-best-practices.md) for __dirname vs cwd() in tools (e.g., syntax_check.sh).\\n
|