@j-o-r/hello-dave 0.0.2 → 0.0.4

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 (161) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +445 -160
  3. package/README.md.backup +269 -0
  4. package/README.md.bak +481 -0
  5. package/README.md.bak.1774780058 +338 -0
  6. package/README.md.bak2 +455 -0
  7. package/bin/dave.js +165 -0
  8. package/docs.bak.1774780058/agent-manager.md +167 -0
  9. package/docs.bak.1774780058/agent-manager.md.bak +137 -0
  10. package/docs.bak.1774780058/agent-manager.md.bak2 +157 -0
  11. package/docs.bak.1774780058/codeserver-pattern.md +191 -0
  12. package/docs.bak.1774780058/path-resolution-best-practices.md +104 -0
  13. package/docs.bak.1774780058/project-overview.md +67 -0
  14. package/docs.bak.1774780058/project-overview.md.bak +67 -0
  15. package/docs.bak.1774780058/prompt-class.md +141 -0
  16. package/docs.bak.1774780058/prompt-class.md.bak +142 -0
  17. package/docs.bak.1774780058/tools-syntax-validation.md +121 -0
  18. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +125 -0
  19. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +125 -0
  20. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +106 -0
  21. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +106 -0
  22. package/docs.bak.1774780058/toolset.md +164 -0
  23. package/docs.bak.1774780058/toolset.md.bak +94 -0
  24. package/docs.bak.1774780058/toolset.md.bak3 +161 -0
  25. package/docs.bak.1774780058/toolset.md.bak4 +161 -0
  26. package/docs.bak.1774780058/toolset.md.bak5 +161 -0
  27. package/docs.bak.1774780058/toolset.md.bak6 +163 -0
  28. package/docs.bak.1774780058/toolset.md.bak_path +163 -0
  29. package/docs.bak.1774780058/toolset.md.bak_syntax +161 -0
  30. package/docs.bak.1774780058/xai-responses.md +111 -0
  31. package/docs.bak.1774780058/xai-responses.md.bak +107 -0
  32. package/docs.bak.1774780058/xai-responses.md.bak2 +107 -0
  33. package/docs.bak.1774780058/xai_collections.md +106 -0
  34. package/examples/ask_agent.js +137 -0
  35. package/examples/code_agent.js +149 -0
  36. package/examples/coderev_agent.js +136 -0
  37. package/examples/codeserver.sh +47 -0
  38. package/examples/daisy_agent.js +170 -0
  39. package/examples/docs_agent.js +148 -0
  40. package/examples/gpt_agent.js +125 -0
  41. package/examples/grok_agent.js +132 -0
  42. package/examples/grok_agent.js.bak +98 -0
  43. package/examples/grok_agent.js.bak.2 +99 -0
  44. package/examples/grok_agent.js.bak.3 +1 -0
  45. package/examples/grok_agent.js.bak.4 +124 -0
  46. package/examples/grok_agent.js.bak.5 +1 -0
  47. package/examples/grok_agent.js.bak.6 +1 -0
  48. package/examples/memory_agent.js +152 -0
  49. package/examples/npm_agent.js +202 -0
  50. package/examples/npm_agent.js.bak.3 +2 -0
  51. package/examples/npm_agent.js.bak.4 +205 -0
  52. package/examples/npm_agent.js.bak.5 +1 -0
  53. package/examples/npm_agent.js.bak.6 +1 -0
  54. package/examples/prompt_agent.js +133 -0
  55. package/examples/readme_agent.js +148 -0
  56. package/examples/spawn_agent.js +293 -0
  57. package/examples/test_agent.js +187 -0
  58. package/examples/todo_agent.js +175 -0
  59. package/examples.bak.1774780058/ask_agent.js +114 -0
  60. package/examples.bak.1774780058/code_agent.js +149 -0
  61. package/examples.bak.1774780058/coderev_agent.js +72 -0
  62. package/examples.bak.1774780058/codeserver.sh +47 -0
  63. package/examples.bak.1774780058/daisy_agent.js +177 -0
  64. package/examples.bak.1774780058/docs_agent.js +119 -0
  65. package/{bin/hdAsk.js → examples.bak.1774780058/gpt_agent.js} +46 -40
  66. package/examples.bak.1774780058/grok_agent.js +98 -0
  67. package/examples.bak.1774780058/memory_agent.js +112 -0
  68. package/examples.bak.1774780058/npm_agent.js +175 -0
  69. package/examples.bak.1774780058/prompt_agent.js +112 -0
  70. package/examples.bak.1774780058/readme_agent.js +144 -0
  71. package/examples.bak.1774780058/spawn_agent.js +263 -0
  72. package/examples.bak.1774780058/test_agent.js +162 -0
  73. package/examples.bak.1774780058/todo_agent.js +138 -0
  74. package/lib/API/openai.com/reponses/text.js +12 -18
  75. package/lib/API/x.ai/collections.js +354 -0
  76. package/lib/API/x.ai/files.js +218 -0
  77. package/lib/API/x.ai/responses.js +492 -0
  78. package/lib/API/x.ai/text.js +1 -1
  79. package/lib/AgentClient.js +13 -6
  80. package/lib/AgentManager.js +80 -10
  81. package/lib/AgentServer.js +50 -22
  82. package/lib/Cli.js +7 -1
  83. package/lib/Prompt.js +4 -2
  84. package/lib/ToolSet.js +2 -1
  85. package/lib/genericToolset.js +258 -88
  86. package/lib/genericToolset.js.bak_syntax +402 -0
  87. package/lib/index.js +4 -2
  88. package/lib/wsCli.js +256 -0
  89. package/lib/wsIO.js +96 -0
  90. package/package.json +26 -21
  91. package/scenarios.bak.1774780058/data/eval_node_message.json +9 -0
  92. package/scenarios.bak.1774780058/data/hist_oa.json +66 -0
  93. package/scenarios.bak.1774780058/data/o3_response1.json +96 -0
  94. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +112 -0
  95. package/scenarios.bak.1774780058/data/tool_oa.json +96 -0
  96. package/scenarios.bak.1774780058/data/tool_xai.json +59 -0
  97. package/scenarios.bak.1774780058/data/tool_xai2.json +40 -0
  98. package/scenarios.bak.1774780058/data/xai-response-1.json +59 -0
  99. package/scenarios.bak.1774780058/data/xai-response-2.json +10 -0
  100. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +59 -0
  101. package/scenarios.bak.1774780058/data/xai_search_response.json +58 -0
  102. package/scenarios.bak.1774780058/environment.js +10 -0
  103. package/scenarios.bak.1774780058/example.js +17 -0
  104. package/scenarios.bak.1774780058/genericToolset.test.js +182 -0
  105. package/scenarios.bak.1774780058/grok.js +113 -0
  106. package/scenarios.bak.1774780058/memory-tools.js +51 -0
  107. package/scenarios.bak.1774780058/openai-o3.js +137 -0
  108. package/scenarios.bak.1774780058/openai-prompt.js +155 -0
  109. package/scenarios.bak.1774780058/openai-session.js +148 -0
  110. package/scenarios.bak.1774780058/openai.js +102 -0
  111. package/scenarios.bak.1774780058/prompt.js +118 -0
  112. package/scenarios.bak.1774780058/promptFishbowl.js +76 -0
  113. package/scenarios.bak.1774780058/search.brave.com.js +25 -0
  114. package/scenarios.bak.1774780058/sh.js +15 -0
  115. package/scenarios.bak.1774780058/test-wsio.js +26 -0
  116. package/scenarios.bak.1774780058/testToolset.js +42 -0
  117. package/scenarios.bak.1774780058/toolset.js +16 -0
  118. package/scenarios.bak.1774780058/toolset.test.js +141 -0
  119. package/scenarios.bak.1774780058/write_file_syntax.test.js +145 -0
  120. package/scenarios.bak.1774780058/write_file_validation/README.md +30 -0
  121. package/scenarios.bak.1774780058/write_file_validation/bad.js +3 -0
  122. package/scenarios.bak.1774780058/write_file_validation/good.js +4 -0
  123. package/scenarios.bak.1774780058/write_file_validation/test.sh +43 -0
  124. package/scenarios.bak.1774780058/wsClient.js +69 -0
  125. package/scenarios.bak.1774780058/xai_responses.integration.test.js +57 -0
  126. package/scenarios.bak.1774780058/xai_responses.test.js +154 -0
  127. package/scenarios.bak.1774780058/xaicoll.js +50 -0
  128. package/scenarios.bak.1774780058/xaifiles.js +48 -0
  129. package/types/API/openai.com/reponses/text.d.ts +17 -3
  130. package/types/API/x.ai/collections.d.ts +167 -0
  131. package/types/API/x.ai/files.d.ts +84 -0
  132. package/types/API/x.ai/responses.d.ts +379 -0
  133. package/types/AgentClient.d.ts +5 -0
  134. package/types/AgentManager.d.ts +25 -31
  135. package/types/AgentServer.d.ts +5 -1
  136. package/types/Prompt.d.ts +4 -2
  137. package/types/ToolSet.d.ts +1 -0
  138. package/types/index.d.ts +4 -3
  139. package/types/wsCli.d.ts +3 -0
  140. package/types/wsIO.d.ts +26 -0
  141. package/utils/bars.js +40 -0
  142. package/utils/clear_sessions.sh +54 -0
  143. package/{bin/hdInspect.js → utils/format_log.js} +5 -0
  144. package/utils/list_sessions.sh +46 -0
  145. package/utils/search_sessions.sh +73 -0
  146. package/utils/syntax_check.sh +61 -0
  147. package/utils/test.sh +46 -0
  148. package/bin/hdClear.js +0 -13
  149. package/bin/hdCode.js +0 -115
  150. package/bin/hdConnect.js +0 -230
  151. package/bin/hdNpm.js +0 -114
  152. package/bin/hdPrompt.js +0 -108
  153. package/examples/claude-test.js +0 -89
  154. package/examples/claude.js +0 -143
  155. package/examples/gpt.js +0 -127
  156. package/examples/gpt_code.js +0 -125
  157. package/examples/gpt_note_keeping.js +0 -117
  158. package/examples/grok.js +0 -119
  159. package/examples/grok_code.js +0 -114
  160. package/examples/grok_note_keeping.js +0 -111
  161. package/module.md +0 -189
@@ -0,0 +1,94 @@
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` (9 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
+ Pre-built `ToolSet('auto')` with 9 tools. Copied via `AgentManager.addGenericToolcall(name)`.
39
+
40
+ | Tool Name | Description |
41
+ |--------------------------|-------------|
42
+ | `javascript_interpreter` | Execute ESM ES6 JavaScript on `node`. `console.log` captures output. cwd: `~/devpri/js/hello-dave`. |
43
+ | `get_user_env` | Get user environment (name, system, city/region/country/timezone, external IP). |
44
+ | `execute_bash_script` | Execute raw Bash script/command (no escaping; verbatim `$ | < > & " ' \\ \` newlines $(( )) [[ ]]`. Heredoc-safe). Ubuntu 25.10. |
45
+ | `send_email` | Send email via `msmtp` (to, subject, body). |
46
+ | `open_link` | Open URL/file with `xdg-open`. |
47
+ | `execute_remote_script` | Execute raw Bash on remote via SSH (`ssh://user@host[:port]`). |
48
+ | `history_search` | Search chat sessions: `"(todo\|task)"` or `"package.json"`. Regex in `.cache/[app]/[prompt]/sessions/*.ndjson`. |
49
+ | `read_file` | Read raw file in CWD (relative path, no `/ .. \\\\`). |
50
+ | `write_file` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
51
+
52
+ ## Integration with AgentManager
53
+ In `setup()`:
54
+ ```javascript
55
+ agent.setup({
56
+ toolsetMode: 'auto', // Loads genericToolset.js equivalents
57
+ // or 'required': Empty ToolSet (add manually)
58
+ });
59
+ agent.addGenericToolcall('read_file'); // Copy from toolsPool post-setup
60
+ ```
61
+
62
+ **Custom Tools**:
63
+ ```javascript
64
+ import { AgentManager } from '@j-o-r/hello-dave';
65
+
66
+ agent.setup({ toolsetMode: 'required' });
67
+ const ts = agent.getToolset();
68
+ ts.add('math', 'Add numbers', {
69
+ type: 'object',
70
+ properties: {a: {type: 'number'}, b: {type: 'number'}},
71
+ required: ['a', 'b']
72
+ }, async ({a, b}) => a + b);
73
+ ```
74
+
75
+ **Workflow** (in `Prompt.call()` / API adapters):
76
+ 1. LLM → `function_request`s (assistant message).
77
+ 2. `ToolSet.execute(prompt)` → parallel `call()` → `function_response`s (tool message).
78
+ 3. Recurse until text response.
79
+
80
+ ## Examples
81
+ ### Standalone ToolSet
82
+ ```javascript
83
+ import { ToolSet } from '@j-o-r/hello-dave';
84
+
85
+ const ts = new ToolSet('required');
86
+ ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
87
+ async ({name}) => `Hello, ${name}!`);
88
+ console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
89
+ ```
90
+
91
+ ### With Prompt/AgentManager
92
+ See [agent-manager.md](../agent-manager.md#custom-tools--generics), [prompt-class.md](../prompt-class.md).
93
+
94
+ **Updated:** March 24, 2026 (9 generics from `lib/genericToolset.js`).
@@ -0,0 +1,161 @@
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
+ Pre-built \`ToolSet('auto')\` with **11 tools**. Copied via \`AgentManager.addGenericToolcall(name)\` or \`toolsetMode: 'auto'\`.
39
+
40
+ | Tool Name | Description |
41
+ |----------------------------|-------------|
42
+ | \`javascript_interpreter\` | Execute ESM ES6 JavaScript on \`node\`. \`console.log\` captures output. cwd: \`~/devpri/js/hello-dave\`. |
43
+ | \`get_user_env\` | Get user environment (name, system, city/region/country/timezone, external IP). |
44
+ | \`execute_bash_script\` | Execute raw Bash script/command (no escaping; verbatim \`$\| < > & " ' \\\\` newlines \`$(())\` \`[[ ]]\`. Heredoc-safe). Ubuntu 25.10. |
45
+ | \`send_email\` | Send email via \`msmtp\` (to, subject, body). |
46
+ | \`open_link\` | Open URL/file with \`xdg-open\`. |
47
+ | \`execute_remote_script\` | Execute raw Bash on remote via SSH (\`ssh://user@host[:port]\`). |
48
+ | \`history_search\` | Search chat sessions: \`"(todo\\|task)"\` or \`"package.json"\`. Regex in \`.cache/[app]/[prompt]/sessions/*.ndjson\`. |
49
+ | \`read_file\` | Read raw file in CWD (relative path, no \`/\` \`..\` \`\\\\\`). |
50
+ | \`write_file\` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
51
+ | \`memory_recall\` | Recall persistent memory entries from agent-specific storage (\`.cache/[agent]/memory.ndjson\`). |
52
+ | \`memory_write\` | Write/update persistent memory entries for long-term state (\`.cache/[agent]/memory.ndjson\`). |
53
+
54
+ ## Memory Tools (New)
55
+ 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.
56
+
57
+ ### \`memory_recall\`
58
+ **Description**: Retrieve the latest values for specified keys from memory file. Returns JSON: \`{key: value, ...}\` or \`{}\` if missing.
59
+
60
+ **Parameters**:
61
+ \`\`\`json
62
+ {
63
+ "type": "object",
64
+ "properties": {
65
+ "keys": {
66
+ "type": "array",
67
+ "items": { "type": "string" },
68
+ "description": "List of memory keys to recall, e.g., ['current_task', 'last_decision']"
69
+ }
70
+ },
71
+ "required": ["keys"]
72
+ }
73
+ \`\`\`
74
+
75
+ **Example Usage in Agent Prompt**:
76
+ \`\`\`
77
+ Before proceeding, recall your current task and previous decision:
78
+ - Call memory_recall with keys: ["current_task", "last_decision"]
79
+ Then, use the recalled info to avoid repetition.
80
+ \`\`\`
81
+
82
+ **Token Efficiency**: Stores tasks/decisions externally. Recall only needed state (e.g., 100 tokens) vs. full history (10k+ tokens), preventing loops/re-reasoning.
83
+
84
+ ### \`memory_write\`
85
+ **Description**: Append/update key-value pairs to memory (overwrites prior same-key entries). Returns confirmation with stored entries.
86
+
87
+ **Parameters**:
88
+ \`\`\`json
89
+ {
90
+ "type": "object",
91
+ "properties": {
92
+ "entries": {
93
+ "type": "array",
94
+ "items": {
95
+ "type": "object",
96
+ "properties": {
97
+ "key": { "type": "string", "description": "Unique key (e.g., 'current_task')" },
98
+ "value": { "type": "string", "description": "JSON-stringifiable value" }
99
+ },
100
+ "required": ["key", "value"]
101
+ },
102
+ "description": "List of {key, value} pairs to store"
103
+ }
104
+ },
105
+ "required": ["entries"]
106
+ }
107
+ \`\`\`
108
+
109
+ **Example Usage in Agent Prompt**:
110
+ \`\`\`
111
+ After analyzing, store the plan:
112
+ - Call memory_write with entries: [{"key": "current_task", "value": "Implement login feature"}, {"key": "step", "value": "1/5"}]
113
+ \`\`\`
114
+
115
+ **Token Efficiency**: Persist intermediate results across calls/sessions. Avoids context explosion/loops by recalling compact state instead of regenerating.
116
+
117
+ ## Integration with AgentManager
118
+ In \`setup()\`:
119
+ \`\`\`javascript
120
+ agent.setup({
121
+ toolsetMode: 'auto', // Loads all 11 generic tools
122
+ // or 'required': Empty ToolSet (add manually)
123
+ });
124
+ agent.addGenericToolcall('memory_recall'); // Selective copy post-setup
125
+ \`\`\`
126
+
127
+ **Custom Tools**:
128
+ \`\`\`javascript
129
+ import { AgentManager } from '@j-o-r/hello-dave';
130
+
131
+ agent.setup({ toolsetMode: 'required' });
132
+ const ts = agent.getToolset();
133
+ ts.add('math', 'Add numbers', {
134
+ type: 'object',
135
+ properties: {a: {type: 'number'}, b: {type: 'number'}},
136
+ required: ['a', 'b']
137
+ }, async ({a, b}) => a + b);
138
+ \`\`\`
139
+
140
+ **Workflow** (in \`Prompt.call()\` / API adapters):
141
+ 1. LLM → \`function_request\`s (assistant message).
142
+ 2. \`ToolSet.execute(prompt)\` → parallel \`call()\` → \`function_response\`s (tool message).
143
+ 3. Recurse until text response.
144
+
145
+ ## Examples
146
+ ### Standalone ToolSet
147
+ \`\`\`javascript
148
+ import { ToolSet } from '@j-o-r/hello-dave';
149
+
150
+ const ts = new ToolSet('required');
151
+ ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
152
+ async ({name}) => \`Hello, \${name}!\`);
153
+ console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
154
+ \`\`\`
155
+
156
+ ### With Prompt/AgentManager
157
+ See [AgentManager](./agent-manager.md#custom-tools--generics), [Prompt](./prompt-class.md).
158
+
159
+ **Updated:** March 26, 2026 (11 generics from \`lib/genericToolset.js\`).
160
+
161
+ See also: [GenericToolset Source](./generic-toolset.md).
@@ -0,0 +1,161 @@
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
+ Pre-built \`ToolSet('auto')\` with **11 tools**. Copied via \`AgentManager.addGenericToolcall(name)\` or \`toolsetMode: 'auto'\`.
39
+
40
+ | Tool Name | Description |
41
+ |----------------------------|-------------|
42
+ | \`javascript_interpreter\` | Execute ESM ES6 JavaScript on \`node\`. \`console.log\` captures output. cwd: \`~/devpri/js/hello-dave\`. |
43
+ | \`get_user_env\` | Get user environment (name, system, city/region/country/timezone, external IP). |
44
+ | \`execute_bash_script\` | Execute raw Bash script/command (no escaping; verbatim \`$\| < > & " ' \\\\` newlines \`$(())\` \`[[ ]]\`. Heredoc-safe). Ubuntu 25.10. |
45
+ | \`send_email\` | Send email via \`msmtp\` (to, subject, body). |
46
+ | \`open_link\` | Open URL/file with \`xdg-open\`. |
47
+ | \`execute_remote_script\` | Execute raw Bash on remote via SSH (\`ssh://user@host[:port]\`). |
48
+ | \`history_search\` | Search chat sessions: \`"(todo\\|task)"\` or \`"package.json"\`. Regex in \`.cache/[app]/[prompt]/sessions/*.ndjson\`. |
49
+ | \`read_file\` | Read raw file in CWD (relative path, no \`/\` \`..\` \`\\\\\`). |
50
+ | \`write_file\` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
51
+ | \`memory_recall\` | Recall persistent memory entries from agent-specific storage (\`.cache/[agent]/memory.ndjson\`). |
52
+ | \`memory_write\` | Write/update persistent memory entries for long-term state (\`.cache/[agent]/memory.ndjson\`). |
53
+
54
+ ## Memory Tools (New)
55
+ 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.
56
+
57
+ ### \`memory_recall\`
58
+ **Description**: Retrieve the latest values for specified keys from memory file. Returns JSON: \`{key: value, ...}\` or \`{}\` if missing.
59
+
60
+ **Parameters**:
61
+ \`\`\`json
62
+ {
63
+ "type": "object",
64
+ "properties": {
65
+ "keys": {
66
+ "type": "array",
67
+ "items": { "type": "string" },
68
+ "description": "List of memory keys to recall, e.g., ['current_task', 'last_decision']"
69
+ }
70
+ },
71
+ "required": ["keys"]
72
+ }
73
+ \`\`\`
74
+
75
+ **Example Usage in Agent Prompt**:
76
+ \`\`\`
77
+ Before proceeding, recall your current task and previous decision:
78
+ - Call memory_recall with keys: ["current_task", "last_decision"]
79
+ Then, use the recalled info to avoid repetition.
80
+ \`\`\`
81
+
82
+ **Token Efficiency**: Stores tasks/decisions externally. Recall only needed state (e.g., 100 tokens) vs. full history (10k+ tokens), preventing loops/re-reasoning.
83
+
84
+ ### \`memory_write\`
85
+ **Description**: Append/update key-value pairs to memory (overwrites prior same-key entries). Returns confirmation with stored entries.
86
+
87
+ **Parameters**:
88
+ \`\`\`json
89
+ {
90
+ "type": "object",
91
+ "properties": {
92
+ "entries": {
93
+ "type": "array",
94
+ "items": {
95
+ "type": "object",
96
+ "properties": {
97
+ "key": { "type": "string", "description": "Unique key (e.g., 'current_task')" },
98
+ "value": { "type": "string", "description": "JSON-stringifiable value" }
99
+ },
100
+ "required": ["key", "value"]
101
+ },
102
+ "description": "List of {key, value} pairs to store"
103
+ }
104
+ },
105
+ "required": ["entries"]
106
+ }
107
+ \`\`\`
108
+
109
+ **Example Usage in Agent Prompt**:
110
+ \`\`\`
111
+ After analyzing, store the plan:
112
+ - Call memory_write with entries: [{"key": "current_task", "value": "Implement login feature"}, {"key": "step", "value": "1/5"}]
113
+ \`\`\`
114
+
115
+ **Token Efficiency**: Persist intermediate results across calls/sessions. Avoids context explosion/loops by recalling compact state instead of regenerating.
116
+
117
+ ## Integration with AgentManager
118
+ In \`setup()\`:
119
+ \`\`\`javascript
120
+ agent.setup({
121
+ toolsetMode: 'auto', // Loads all 11 generic tools
122
+ // or 'required': Empty ToolSet (add manually)
123
+ });
124
+ agent.addGenericToolcall('memory_recall'); // Selective copy post-setup
125
+ \`\`\`
126
+
127
+ **Custom Tools**:
128
+ \`\`\`javascript
129
+ import { AgentManager } from '@j-o-r/hello-dave';
130
+
131
+ agent.setup({ toolsetMode: 'required' });
132
+ const ts = agent.getToolset();
133
+ ts.add('math', 'Add numbers', {
134
+ type: 'object',
135
+ properties: {a: {type: 'number'}, b: {type: 'number'}},
136
+ required: ['a', 'b']
137
+ }, async ({a, b}) => a + b);
138
+ \`\`\`
139
+
140
+ **Workflow** (in \`Prompt.call()\` / API adapters):
141
+ 1. LLM → \`function_request\`s (assistant message).
142
+ 2. \`ToolSet.execute(prompt)\` → parallel \`call()\` → \`function_response\`s (tool message).
143
+ 3. Recurse until text response.
144
+
145
+ ## Examples
146
+ ### Standalone ToolSet
147
+ \`\`\`javascript
148
+ import { ToolSet } from '@j-o-r/hello-dave';
149
+
150
+ const ts = new ToolSet('required');
151
+ ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
152
+ async ({name}) => \`Hello, \${name}!\`);
153
+ console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
154
+ \`\`\`
155
+
156
+ ### With Prompt/AgentManager
157
+ See [AgentManager](./agent-manager.md#custom-tools--generics), [Prompt](./prompt-class.md).
158
+
159
+ **Updated:** March 26, 2026 (11 generics from \`lib/genericToolset.js\`).
160
+
161
+ See also: [GenericToolset Source](./generic-toolset.md).
@@ -0,0 +1,161 @@
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
+ Pre-built \`ToolSet('auto')\` with **11 tools**. Copied via \`AgentManager.addGenericToolcall(name)\` or \`toolsetMode: 'auto'\`.
39
+
40
+ | Tool Name | Description |
41
+ |----------------------------|-------------|
42
+ | \`javascript_interpreter\` | Execute ESM ES6 JavaScript on \`node\`. \`console.log\` captures output. cwd: \`~/devpri/js/hello-dave\`. |
43
+ | \`get_user_env\` | Get user environment (name, system, city/region/country/timezone, external IP). |
44
+ | \`execute_bash_script\` | Execute raw Bash script/command (no escaping; verbatim \`$\| < > & " ' \\\\` newlines \`$(())\` \`[[ ]]\`. Heredoc-safe). Ubuntu 25.10. |
45
+ | \`send_email\` | Send email via \`msmtp\` (to, subject, body). |
46
+ | \`open_link\` | Open URL/file with \`xdg-open\`. |
47
+ | \`execute_remote_script\` | Execute raw Bash on remote via SSH (\`ssh://user@host[:port]\`). |
48
+ | \`history_search\` | Search chat sessions: \`"(todo\\|task)"\` or \`"package.json"\`. Regex in \`.cache/[app]/[prompt]/sessions/*.ndjson\`. |
49
+ | \`read_file\` | Read raw file in CWD (relative path, no \`/\` \`..\` \`\\\\\`). |
50
+ | \`write_file\` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
51
+ | \`memory_recall\` | Recall persistent memory entries from agent-specific storage (\`.cache/[agent]/memory.ndjson\`). |
52
+ | \`memory_write\` | Write/update persistent memory entries for long-term state (\`.cache/[agent]/memory.ndjson\`). |
53
+
54
+ ## Memory Tools (New)
55
+ 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.
56
+
57
+ ### \`memory_recall\`
58
+ **Description**: Retrieve the latest values for specified keys from memory file. Returns JSON: \`{key: value, ...}\` or \`{}\` if missing.
59
+
60
+ **Parameters**:
61
+ \`\`\`json
62
+ {
63
+ "type": "object",
64
+ "properties": {
65
+ "keys": {
66
+ "type": "array",
67
+ "items": { "type": "string" },
68
+ "description": "List of memory keys to recall, e.g., ['current_task', 'last_decision']"
69
+ }
70
+ },
71
+ "required": ["keys"]
72
+ }
73
+ \`\`\`
74
+
75
+ **Example Usage in Agent Prompt**:
76
+ \`\`\`
77
+ Before proceeding, recall your current task and previous decision:
78
+ - Call memory_recall with keys: ["current_task", "last_decision"]
79
+ Then, use the recalled info to avoid repetition.
80
+ \`\`\`
81
+
82
+ **Token Efficiency**: Stores tasks/decisions externally. Recall only needed state (e.g., 100 tokens) vs. full history (10k+ tokens), preventing loops/re-reasoning.
83
+
84
+ ### \`memory_write\`
85
+ **Description**: Append/update key-value pairs to memory (overwrites prior same-key entries). Returns confirmation with stored entries.
86
+
87
+ **Parameters**:
88
+ \`\`\`json
89
+ {
90
+ "type": "object",
91
+ "properties": {
92
+ "entries": {
93
+ "type": "array",
94
+ "items": {
95
+ "type": "object",
96
+ "properties": {
97
+ "key": { "type": "string", "description": "Unique key (e.g., 'current_task')" },
98
+ "value": { "type": "string", "description": "JSON-stringifiable value" }
99
+ },
100
+ "required": ["key", "value"]
101
+ },
102
+ "description": "List of {key, value} pairs to store"
103
+ }
104
+ },
105
+ "required": ["entries"]
106
+ }
107
+ \`\`\`
108
+
109
+ **Example Usage in Agent Prompt**:
110
+ \`\`\`
111
+ After analyzing, store the plan:
112
+ - Call memory_write with entries: [{"key": "current_task", "value": "Implement login feature"}, {"key": "step", "value": "1/5"}]
113
+ \`\`\`
114
+
115
+ **Token Efficiency**: Persist intermediate results across calls/sessions. Avoids context explosion/loops by recalling compact state instead of regenerating.
116
+
117
+ ## Integration with AgentManager
118
+ In \`setup()\`:
119
+ \`\`\`javascript
120
+ agent.setup({
121
+ toolsetMode: 'auto', // Loads all 11 generic tools
122
+ // or 'required': Empty ToolSet (add manually)
123
+ });
124
+ agent.addGenericToolcall('memory_recall'); // Selective copy post-setup
125
+ \`\`\`
126
+
127
+ **Custom Tools**:
128
+ \`\`\`javascript
129
+ import { AgentManager } from '@j-o-r/hello-dave';
130
+
131
+ agent.setup({ toolsetMode: 'required' });
132
+ const ts = agent.getToolset();
133
+ ts.add('math', 'Add numbers', {
134
+ type: 'object',
135
+ properties: {a: {type: 'number'}, b: {type: 'number'}},
136
+ required: ['a', 'b']
137
+ }, async ({a, b}) => a + b);
138
+ \`\`\`
139
+
140
+ **Workflow** (in \`Prompt.call()\` / API adapters):
141
+ 1. LLM → \`function_request\`s (assistant message).
142
+ 2. \`ToolSet.execute(prompt)\` → parallel \`call()\` → \`function_response\`s (tool message).
143
+ 3. Recurse until text response.
144
+
145
+ ## Examples
146
+ ### Standalone ToolSet
147
+ \`\`\`javascript
148
+ import { ToolSet } from '@j-o-r/hello-dave';
149
+
150
+ const ts = new ToolSet('required');
151
+ ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
152
+ async ({name}) => \`Hello, \${name}!\`);
153
+ console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
154
+ \`\`\`
155
+
156
+ ### With Prompt/AgentManager
157
+ See [AgentManager](./agent-manager.md#custom-tools--generics), [Prompt](./prompt-class.md).
158
+
159
+ **Updated:** March 26, 2026 (11 generics from \`lib/genericToolset.js\`).
160
+
161
+ See also: [GenericToolset Source](./generic-toolset.md).