@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,59 @@
1
+ {
2
+ "status": 200,
3
+ "response": {
4
+ "id": "080ab233-e37e-bd72-4d2e-e0fb478e05e8",
5
+ "object": "chat.completion",
6
+ "created": 1752061910,
7
+ "model": "grok-3",
8
+ "choices": [
9
+ {
10
+ "index": 0,
11
+ "message": {
12
+ "role": "assistant",
13
+ "content": "\n",
14
+ "tool_calls": [
15
+ {
16
+ "id": "call_95425891",
17
+ "function": {
18
+ "name": "get_date_time",
19
+ "arguments": "{}"
20
+ },
21
+ "type": "function"
22
+ },
23
+ {
24
+ "id": "call_27865503",
25
+ "function": {
26
+ "name": "get_current_weather",
27
+ "arguments": "{\"location\":\"Amsterdam, The Netherlands\"}"
28
+ },
29
+ "type": "function"
30
+ }
31
+ ],
32
+ "refusal": null
33
+ },
34
+ "finish_reason": "stop"
35
+ }
36
+ ],
37
+ "usage": {
38
+ "prompt_tokens": 305,
39
+ "completion_tokens": 52,
40
+ "total_tokens": 357,
41
+ "prompt_tokens_details": {
42
+ "text_tokens": 305,
43
+ "audio_tokens": 0,
44
+ "image_tokens": 0,
45
+ "cached_tokens": 2
46
+ },
47
+ "completion_tokens_details": {
48
+ "reasoning_tokens": 0,
49
+ "audio_tokens": 0,
50
+ "accepted_prediction_tokens": 0,
51
+ "rejected_prediction_tokens": 0
52
+ },
53
+ "num_sources_used": 0
54
+ },
55
+ "system_fingerprint": "fp_9ad1a16f77"
56
+ },
57
+ "headers": {},
58
+ "responseType": "js"
59
+ }
@@ -0,0 +1,10 @@
1
+ 1. Parse reponse 1 {
2
+ "status": 422,
3
+ "response": "Failed to deserialize the JSON body into the target type: messages[2]: missing field `name` at line 1 column 527",
4
+ "headers": {},
5
+ "responseType": "text"
6
+ }
7
+ (duration: 394 ms)
8
+ --------------------------------------------------
9
+ Total: 2 tests, executed: 1 in 394 ms - errors: 0
10
+ ** Not all tests have been executed **
@@ -0,0 +1,59 @@
1
+ {
2
+ "status": 200,
3
+ "responseType": "js",
4
+ "response": {
5
+ "id": "cb870601-b91e-c00f-bb28-bb3211c9ba0a",
6
+ "object": "chat.completion",
7
+ "created": 1751294195,
8
+ "model": "grok-3-mini-fast",
9
+ "choices": [
10
+ {
11
+ "index": 0,
12
+ "message": {
13
+ "role": "assistant",
14
+ "content": "\n",
15
+ "reasoning_content": "First, the user is asking two things: 1) What day is today? 2) What is the weather forecast in Amsterdam, The Netherlands.\n\nAvailable tools:\n\n- get_current_weather: This requires a location, like a city and country. The user specified \"Amsterdam, The Netherlands\", which matches perfectly.\n\n- get_date_time: This gets the current date and time. It doesn't require any parameters, so I can call it directly.\n\nI need to address both parts of the query. For the date and time, I can use get_date_time. For the weather, I can use get_current_weather with the location provided.\n\nThe description for get_current_weather says \"Get the current weather\", not \"forecast\". The user said \"weather forecast\", but the tool is for current weather. I should use it as is, since it's the closest match.\n\nIn a multi-turn conversation, I should call functions to advance the request. So, I need to call both functions.\n\nResponse guidelines: Respond precisely and concisely. Only use <function_call> tags when deciding to call a function.\n\nSince both parts can be handled by available functions, I should call them.\n\nFirst, call get_date_time for the current date and time.\n\nSecond, call get_current_weather for Amsterdam, The Netherlands.\n\nI can use multiple <function_call> tags in my response.\n\nAfter calling these functions, the system will presumably execute them and provide results, then I can respond based on that.\n\nMy response should only contain the function calls if that's the next step.\n\nStructure: If I'm calling functions, my response should just be the <function_call> tags, without additional text, to keep it concise.\n\nThe instructions say: \"You are only permitted to use the <function_call> tag in your response only if you have made the decision to call a function.\"\n\nSo, for this query, my response should consist of the function calls.\n\nOrder: Maybe call get_date_time first, then get_current_weather.\n\nFinally, once I have the results, in a subsequent turn, I can compile the answer.\n\nBut for now, in this response, I just need to output the function calls.",
16
+ "tool_calls": [
17
+ {
18
+ "id": "call_73832078",
19
+ "function": {
20
+ "name": "get_date_time",
21
+ "arguments": "{}"
22
+ },
23
+ "type": "function"
24
+ },
25
+ {
26
+ "id": "call_35308569",
27
+ "function": {
28
+ "name": "get_current_weather",
29
+ "arguments": "{\"location\":\"Amsterdam, The Netherlands\"}"
30
+ },
31
+ "type": "function"
32
+ }
33
+ ],
34
+ "refusal": null
35
+ },
36
+ "finish_reason": "stop"
37
+ }
38
+ ],
39
+ "usage": {
40
+ "prompt_tokens": 341,
41
+ "completion_tokens": 52,
42
+ "total_tokens": 827,
43
+ "prompt_tokens_details": {
44
+ "text_tokens": 341,
45
+ "audio_tokens": 0,
46
+ "image_tokens": 0,
47
+ "cached_tokens": 5
48
+ },
49
+ "completion_tokens_details": {
50
+ "reasoning_tokens": 434,
51
+ "audio_tokens": 0,
52
+ "accepted_prediction_tokens": 0,
53
+ "rejected_prediction_tokens": 0
54
+ },
55
+ "num_sources_used": 0
56
+ },
57
+ "system_fingerprint": "fp_768091f8b2"
58
+ }
59
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "status": 200,
3
+ "responseType": "js",
4
+ "response": {
5
+ "id": "f964eed9-95b6-5d95-2383-d25be743d8e6",
6
+ "object": "chat.completion",
7
+ "created": 1751456496,
8
+ "model": "grok-3-mini",
9
+ "choices": [
10
+ {
11
+ "index": 0,
12
+ "message": {
13
+ "role": "assistant",
14
+ "content": "To install a Language Server Protocol (LSP) for JavaScript on the Helix editor, follow these steps based on Helix documentation and community guides:\n\n### 1. **Install a JavaScript Language Server**\n - The most common LSP for JavaScript is the TypeScript Language Server (tsserver), which also supports JavaScript.\n - Install it via npm (Node.js package manager):\n ```\n npm install -g typescript\n ```\n - Ensure Node.js and npm are installed first (download from the official Node.js website if needed).\n - Alternatively, other LSPs like ESLint or Volar can be used for specific features; install them via npm or their respective methods.\n\n### 2. **Configure Helix Editor**\n - Helix uses a `languages.toml` file for language server settings.\n - Locate or create a `languages.toml` file in one of these locations (as per Helix docs):\n - User config: `~/.config/helix/languages.toml`\n - Project-specific: In your project directory.\n - Add or update the JavaScript section. For example, add this to your `languages.toml`:\n ```\n [language.javascript]\n language-server = { command = \"typescript-language-server\", args = [\"--stdio\"] }\n ```\n - This assumes `typescript-language-server` is installed (it comes with the TypeScript global install).\n - Save the file and restart Helix.\n\n### 3. **Verify and Test**\n - Run `hx --health` in your terminal to check language server support.\n - Open a JavaScript file in Helix (e.g., `.js` or `.ts`) and test features like autocompletion or diagnostics.\n\nFor more details, refer to the Helix documentation on language support (e.g., docs.helix-editor.com/lang-support.html) or a guide on installing Helix language servers. If you encounter issues, ensure your Helix version is up to date. If this doesn't work, posts on platforms like X suggest checking npm installations for compatibility.",
15
+ "reasoning_content": "First, the user is asking: \"How to install an LSP for JavaScript on the Helix editor.\" This matches the search query I have context for: \"Install Language Server Protocol for JavaScript on Helix editor.\"\n\nI need to respond precisely and concisely, as per my system prompt. I'm an assistant for searches on the internet, so I should base my answer on the provided web results, news results, and X posts, but only if relevant.\n\nKey relevant information from the web results:\n\n- From โ€ฝweb:0 (docs.helix-editor.com/lang-support.html): Helix supports languages and Language Servers. You need to configure the appropriate Language Server.\n\n- From โ€ฝweb:1 (docs.helix-editor.com/languages.html): Language-specific settings are in languages.toml files.\n\n- From โ€ฝweb:2 (ar.al/2022/11/14/...): There's a script for installing Language Servers for web development in Helix.\n\n- From โ€ฝweb:3 (batsov.com/articles/2025/02/21/...): A basic Helix setup for JavaScript, which likely includes LSP setup.\n\n- From โ€ฝweb:4 (github.com/helix-editor/helix): The languages.toml file, which is key for configuration.\n\nFrom news results:\n\n- โ€ฝweb:3 (volarjs.dev/guides/first-server/): This is about Volar, which is a Language Server for Vue.js but might be adaptable for JavaScript.\n\n- โ€ฝweb:4 (guillermoap.medium.com/...): Turning Helix into an IDE, which could involve LSP setup.\n\nFrom X posts:\n\n- There's a post about IntelliJ supporting LSP, but that's not directly related.\n\n- Astro post mentions building on LSP and using it for JS.\n\n- A post by Alisher mentions installing with npm, which could be relevant for JavaScript LSP.\n\nThe most directly relevant is the script from Aral Balkan's blog (โ€ฝweb:2) and the Helix documentation.\n\nSteps to install LSP for JavaScript in Helix:\n\n1. Identify the Language Server for JavaScript. Common ones are like TypeScript Language Server (tsserver) since JavaScript is handled by TypeScript tools.\n\n2. Configure it in Helix via languages.toml.\n\nFrom the results, users need to install the Language Server first, then configure it in Helix.\n\nA concise answer should include:\n\n- Install a JavaScript Language Server, e.g., via npm (like typescript, which includes tsserver).\n\n- Configure it in Helix's languages.toml file.\n\nMention sources briefly if it makes sense, like referring to Helix documentation.\n\nFinally, structure the response: Be precise, use bullet points or numbered steps for clarity, and keep it concise.",
16
+ "refusal": null
17
+ },
18
+ "finish_reason": "stop"
19
+ }
20
+ ],
21
+ "usage": {
22
+ "prompt_tokens": 2434,
23
+ "completion_tokens": 411,
24
+ "total_tokens": 3393,
25
+ "prompt_tokens_details": {
26
+ "text_tokens": 2434,
27
+ "audio_tokens": 0,
28
+ "image_tokens": 0,
29
+ "cached_tokens": 6
30
+ },
31
+ "completion_tokens_details": {
32
+ "reasoning_tokens": 548,
33
+ "audio_tokens": 0,
34
+ "accepted_prediction_tokens": 0,
35
+ "rejected_prediction_tokens": 0
36
+ },
37
+ "num_sources_used": 3
38
+ },
39
+ "system_fingerprint": "fp_2e0c052777",
40
+ "citations": [
41
+ "https://docs.helix-editor.com/lang-support.html",
42
+ "https://docs.helix-editor.com/languages.html",
43
+ "https://ar.al/2022/11/14/installing-helix-editor-language-servers/",
44
+ "https://batsov.com/articles/2025/02/21/a-basic-helix-setup-for-javascript/",
45
+ "https://github.com/helix-editor/helix/blob/master/languages.toml",
46
+ "https://herecomesthemoon.net/2025/06/i-like-helix/",
47
+ "https://freecodecamp.org/news/how-to-build-a-custom-mcp-server-with-typescript-a-handbook-for-developers",
48
+ "https://infoworld.com/article/3849654/typescript-gets-go-faster-stripes.html",
49
+ "https://volarjs.dev/guides/first-server/",
50
+ "https://guillermoap.medium.com/turning-helix-into-an-ide-with-the-help-of-zellij-03c4e52524da",
51
+ "https://x.com/JBPlatform/status/1677320230534561793",
52
+ "https://x.com/sawaba/status/1061673555652472833",
53
+ "https://x.com/0xMert_/status/1748394502073520405",
54
+ "https://x.com/astrodotbuild/status/1760709773589188811",
55
+ "https://x.com/JavaScriptDaily/status/1264628987592093697"
56
+ ]
57
+ }
58
+ }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { Test , assert} from '@j-o-r/sh';
3
+ import {env} from '../lib/fafs.js';
4
+ const test = new Test();
5
+ test.add('Test enviroment caching', async () => {
6
+ const user = await env();
7
+ console.log(user);
8
+ assert.strictEqual(typeof user, 'object');
9
+ });
10
+ await test.run();
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import assert from 'node:assert/strict';
3
+ /**
4
+ * Create a async callstack
5
+ * @param {function} callback - async function
6
+ */
7
+ const test = (callback) => {
8
+ (async () => {
9
+ return await callback()
10
+ })()
11
+ }
12
+ test(async () => {
13
+ assert.equal(true, true);
14
+ });
15
+
16
+
17
+
@@ -0,0 +1,182 @@
1
+ #!/usr/bin/env node
2
+ import { Test, assert, jsType } from '@j-o-r/sh';
3
+ import tools from '../lib/genericToolset.js'; // Import the ToolSet instance to test
4
+
5
+ const t = new Test();
6
+
7
+ // Test 1: get_user_env - Should return a string with environment details
8
+ t.add('get_user_env returns environment info', async () => {
9
+ const result = await tools.call('get_user_env', {});
10
+ assert.ok(typeof result === 'string' && result.includes('Name:') && result.includes('System:'));
11
+ console.log('Environment snippet:', result.slice(0, 100));
12
+ });
13
+
14
+ // Test 2: javascript_interpreter - Execute a simple JS script
15
+ t.add('javascript_interpreter executes basic math', async () => {
16
+ const script = "console.log(2 + 2);";
17
+ const result = await tools.call('javascript_interpreter', { script });
18
+ assert.ok(result.includes('4'));
19
+ });
20
+
21
+ // Test 3: execute_bash_script - Run pwd (flexible path check)
22
+ t.add('execute_bash_script runs pwd', async () => {
23
+ const bash_script = 'pwd';
24
+ const result = await tools.call('execute_bash_script', { bash_script });
25
+ assert.ok(result && result.includes('hello-dave'));
26
+ console.log('Current dir:', result.trim());
27
+ });
28
+
29
+ // Test 4: history_search - Empty query lists sessions (no error)
30
+ t.add('history_search empty query lists sessions', async () => {
31
+ const result = await tools.call('history_search', { query: '' });
32
+ assert.ok(typeof result === 'string' && result.length > 10); // Expect non-trivial output from list_sessions.sh
33
+ console.log('History search snippet:', result.slice(0, 200));
34
+ });
35
+
36
+ // Test 5: ToolSet basics - Verify key tools exist (flexible, subset + min count)
37
+ t.add('ToolSet has expected tools', () => {
38
+ const toolList = tools.list();
39
+ const expectedTools = [
40
+ 'execute_bash_script', 'execute_remote_script', 'get_user_env', 'history_search',
41
+ 'javascript_interpreter', 'memory_recall', 'memory_write', 'open_link',
42
+ 'read_file', 'send_email', 'syntax_check', 'write_file'
43
+ ];
44
+ const actualNames = toolList.map(t => t.name).sort();
45
+ assert.ok(toolList.length >= 12, `Expected at least 12 tools, got ${toolList.length}`);
46
+ assert.ok(expectedTools.every(name => actualNames.includes(name)),
47
+ `Missing tools. Expected: ${expectedTools.join(', ')}. Got: ${actualNames.join(', ')}`);
48
+ console.log(`Tool count: ${toolList.length}, names: ${actualNames.slice(0,5).join(', ')}...`);
49
+ });
50
+
51
+ // Test 6: javascript_interpreter - Complex JS with backticks (template literal)
52
+ t.add('javascript_interpreter handles backticks/templates', async () => {
53
+ const script = `
54
+ const name = 'Dave';
55
+ const greeting = \`Hello \${name}!\`;
56
+ console.log(greeting);
57
+ console.log(\`2 + 2 = \${2 + 2}\`);
58
+ `.trim();
59
+ const result = await tools.call('javascript_interpreter', { script });
60
+ assert.ok(result.includes('Hello Dave!') && result.includes('2 + 2 = 4'));
61
+ });
62
+
63
+ // Test 7: javascript_interpreter - Arrow functions & async/await
64
+ t.add('javascript_interpreter handles ESNext features', async () => {
65
+ const script = `
66
+ const add = async (a, b) => a + b;
67
+ console.log(await add(3, 4));
68
+ `.trim();
69
+ const result = await tools.call('javascript_interpreter', { script });
70
+ assert.ok(result.includes('7'));
71
+ });
72
+
73
+ // Test 8: javascript_interpreter - Error handling
74
+ t.add('javascript_interpreter reports JS errors', async () => {
75
+ const script = 'console.log("ok"); invalidSyntaxHere();';
76
+ const result = await tools.call('javascript_interpreter', { script });
77
+ assert.ok(result.includes('invalidSyntaxHere') || result.includes('ReferenceError'));
78
+ });
79
+
80
+ // Test 9: read_file - Read package.json
81
+ t.add('read_file reads package.json', async () => {
82
+ const result = await tools.call('read_file', { file: 'package.json' });
83
+ assert.ok(result.includes('@j-o-r/hello-dave') && result.includes('"tests":'));
84
+ });
85
+
86
+ // Test 10: write_file + read_file roundtrip (temp file, cleanup)
87
+ t.add('write_file + read_file roundtrip', async () => {
88
+ const tempFile = 'scenarios/temp.test.txt';
89
+ const testContent = 'Test content: ' + Date.now();
90
+
91
+ // Write
92
+ const writeRes = await tools.call('write_file', {
93
+ file: tempFile,
94
+ content: testContent
95
+ });
96
+ assert.ok(writeRes.includes('Successfully wrote'));
97
+
98
+ // Read back
99
+ const readRes = await tools.call('read_file', { file: tempFile });
100
+ assert.strictEqual(readRes.trim(), testContent);
101
+
102
+ // Cleanup
103
+ await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` });
104
+ console.log('Temp file roundtrip OK');
105
+ });
106
+
107
+ // Test 11: memory_write + memory_recall
108
+ t.add('memory_write and recall', async () => {
109
+ const cat = 'tasks';
110
+ const content = 'Test task from genericToolset.test.js';
111
+
112
+ // Write
113
+ await tools.call('memory_write', { category: cat, content });
114
+
115
+ // Recall
116
+ const recall = await tools.call('memory_recall', { query: cat });
117
+ assert.ok(recall.includes(cat) && recall.includes('Test task'));
118
+
119
+ console.log('Memory test OK');
120
+ });
121
+
122
+ // Test 12: write_file rejects invalid JS syntax (unclosed string)
123
+ t.add('write_file rejects invalid JS syntax', async () => {
124
+ const ts = Date.now().toString();
125
+ const tempFile = `scenarios/temp_invalid_${ts}.js`;
126
+ const invalidJS = `console.log("unclosed quote`;
127
+ await assert.rejects(
128
+ () => tools.call('write_file', { file: tempFile, content: invalidJS }),
129
+ (err) => {
130
+ assert.strictEqual(jsType(err), 'Error');
131
+ assert.ok(err.message.includes('โŒ SYNTAX ERROR'));
132
+ assert.ok(err.message.includes('syntax error') || err.message.includes('SyntaxError'));
133
+ return true;
134
+ }
135
+ );
136
+ // Cleanup if exists (write happens before check)
137
+ await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` }).catch(() => {});
138
+ console.log('Invalid JS rejection OK');
139
+ });
140
+
141
+ // Test 13: write_file rejects invalid Python syntax (unclosed string)
142
+ t.add('write_file rejects invalid Python syntax', async () => {
143
+ const ts = Date.now().toString();
144
+ const tempFile = `scenarios/temp_invalid_${ts}.py`;
145
+ const invalidPy = `print("unclosed quote`;
146
+ await assert.rejects(
147
+ () => tools.call('write_file', { file: tempFile, content: invalidPy }),
148
+ (err) => {
149
+ assert.strictEqual(jsType(err), 'Error');
150
+ assert.ok(err.message.includes('โŒ SYNTAX ERROR'));
151
+ assert.ok(err.message.includes('syntax error') || err.message.includes('SyntaxError'));
152
+ return true;
153
+ }
154
+ );
155
+ // Cleanup
156
+ await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` }).catch(() => {});
157
+ console.log('Invalid Python rejection OK');
158
+ });
159
+
160
+ // Test 14: write_file rejects invalid Bash syntax (unclosed string)
161
+ t.add('write_file rejects invalid Bash syntax', async () => {
162
+ const ts = Date.now().toString();
163
+ const tempFile = `scenarios/temp_invalid_${ts}.sh`;
164
+ const invalidBash = `echo "unclosed quote`;
165
+ await assert.rejects(
166
+ () => tools.call('write_file', { file: tempFile, content: invalidBash }),
167
+ (err) => {
168
+ assert.strictEqual(jsType(err), 'Error');
169
+ assert.ok(err.message.includes('โŒ SYNTAX ERROR'));
170
+ assert.ok(err.message.includes('syntax error') || err.message.includes('SyntaxError') || err.message.includes('unexpected EOF'));
171
+ return true;
172
+ }
173
+ );
174
+ // Cleanup
175
+ await tools.call('execute_bash_script', { bash_script: `rm -f ${tempFile}` }).catch(() => {});
176
+ console.log('Invalid Bash rejection OK');
177
+ });
178
+
179
+ // Run tests
180
+ const report = await t.run();
181
+ console.log('\n=== Final Report ===', report);
182
+ process.exit(report.errors > 0 ? 1 : 0);
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+ import { Test, assert, SH } from '@j-o-r/sh'
3
+ import { generateRequest, parseResponse, request } from '../lib/API/x.ai/text.js';
4
+ import { request as doRequest } from '@j-o-r/apiserver';
5
+
6
+ import Prompt from '../lib/Prompt.js';
7
+ import tools from './testToolset.js';
8
+
9
+ function LOG (me) {
10
+ console.log(JSON.stringify(me, null, ' '));
11
+ }
12
+
13
+ const test = new Test();
14
+ // test.add('0: parse response, create request FAKE ', async () => {
15
+ // // Load a fake reponse
16
+ // const resLocal = JSON.parse((await SH`cat scenarios/data/tool_xai.json`.run()));
17
+ // const prompt = new Prompt();
18
+ // prompt.add('system', 'You are an assistant for an administrative office. Respond precise and concise', true);
19
+ // prompt.add('user', 'What is your task?');
20
+ // prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
21
+ // prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
22
+ // // // const { url, headers, body } = generateRequest(prompt, tools);
23
+ // // await parseResponse(1100, prompt, resLocal, tools);
24
+ // // let lastMessage = prompt.getLastMessage();
25
+ // // assert.strictEqual(lastMessage.role, 'tool', 'Last message has role tool');
26
+ // // assert.strictEqual(lastMessage.content.length, 2, '2 toolcalls')
27
+ // // const { url, headers, body } = generateRequest(prompt, tools);
28
+ // // assert.equal(body.messages.length, 6);
29
+ //
30
+ // const res2 = JSON.parse((await SH`cat scenarios/data/tool_xai2.json`.run()));
31
+ // // const res2 = await doRequest(url, 'POST', headers, body);
32
+ // await parseResponse(1000, prompt, res2, tools);
33
+ // // console.log(JSON.stringify(res2, null, ' '));
34
+ // console.log(JSON.stringify(prompt.messages, null, ' '));
35
+ // // console.log({retrigger, lastMessage})
36
+ // });
37
+ //
38
+ // // @TODO add tools
39
+ // test.add('1: Full tool call with reasoning', async () => {
40
+ // const prompt = new Prompt();
41
+ // prompt.add('system', 'You are an assistant that can answer questions and help with tasks. Respond precise and concise.', true);
42
+ // prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
43
+ // // Create simple toolset
44
+ // /**
45
+ // * @type {import('../lib/API/x.ai/text.js').XOptions}
46
+ // */
47
+ // const options = {
48
+ // model: 'grok-3-mini-fast-latest',
49
+ // reasoning_effort: 'low'
50
+ // }
51
+ // const { url, headers, body } = generateRequest(prompt, tools, options);
52
+ // const res = await doRequest(url, 'POST', headers, body);
53
+ // // console.log(JSON.stringify(res, null, ' '));
54
+ //
55
+ // await parseResponse(1000, prompt, res, tools);
56
+ // const lastMessage = prompt.getLastMessage();
57
+ // console.log(lastMessage);
58
+ // })
59
+ //
60
+ // test.add('2: Add a complete toolcall, a real request', async () => {
61
+ // const prompt = new Prompt();
62
+ // prompt.add('system', 'Respond precise and concise', true);
63
+ // prompt.add('user', 'What is your task?');
64
+ // prompt.add('assistant', 'My task is to assist with administrative duties, such as answering questions, scheduling, providing information, and supporting office operations efficiently.')
65
+ // prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
66
+ // const message = await request(prompt, tools);
67
+ // console.log(message);
68
+ // })
69
+ //
70
+ // test.add('3: Add a search XAI tool', async () => {
71
+ // const res2 = JSON.parse((await SH`cat scenarios/data/xai_search_response.json`.run()));
72
+ // /**
73
+ // * @type {import('../lib//API/x.ai/text.js').XOptions}
74
+ // */
75
+ // const options = {
76
+ // model: 'grok-3-mini',
77
+ // reasoning_effort: 'low',
78
+ // search_parameters: {
79
+ // mode: 'on'
80
+ // }
81
+ // }
82
+ // const prompt = new Prompt();
83
+ // prompt.add('system', 'You are an assistant for an searches on the internet. Respond precise and concise', true);
84
+ // prompt.add('user', 'How to install an LSP for javascript on the helix editor');
85
+ // parseResponse(1000, prompt, res2)
86
+ // // const message = await request(prompt, null, options);
87
+ // // console.log(message);
88
+ // console.log(JSON.stringify(prompt.messages, null, ' '));
89
+ // });
90
+
91
+
92
+ test.add('4 REFACTOR TOOLCALLS and message history', async () => {
93
+ const prompt = new Prompt();
94
+ prompt.add('system', 'Respond precise and concise', true);
95
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
96
+ const req1 = generateRequest(prompt, tools)
97
+ const { url, headers, body } = generateRequest(prompt, tools);
98
+ const res = await doRequest(url, 'POST', headers, body);
99
+ LOG(res);
100
+ })
101
+
102
+ test.add('Parse reponse 1', async () => {
103
+ const prompt = new Prompt();
104
+ prompt.add('system', 'Respond precise and concise', true);
105
+ prompt.add('user', 'What day is today and what is the weather forcast in Amsterdam, The Netherlands');
106
+ const res1 = JSON.parse((await SH`cat scenarios/data/xai-response-1.json`.run()));
107
+ await parseResponse(1000, prompt, res1, tools);
108
+ const { url, headers, body } = generateRequest(prompt, tools);
109
+ const res = await doRequest(url, 'POST', headers, body);
110
+ LOG(body);
111
+
112
+ });
113
+ await test.run([1]);
@@ -0,0 +1,51 @@
1
+ import tools from '../lib/genericToolset.js';
2
+ import { promises as fs } from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ const memoryPath = path.join(process.cwd(), '.cache', 'memory.ndjson');
6
+
7
+ // Cleanup previous test data
8
+ try {
9
+ await fs.unlink(memoryPath);
10
+ console.log('๐Ÿงน Cleared previous memory.ndjson');
11
+ } catch (e) {
12
+ // No previous file, fine
13
+ }
14
+
15
+ console.log('๐Ÿง  Testing memory_write & memory_recall from lib/genericToolset.js...\n');
16
+
17
+ const testWrites = [
18
+ { category: 'tasks', content: 'Test task 1: Optimize runWithMemory loop using memory tools.' },
19
+ { category: 'errors', content: 'Test error: Infinite loop detected in prior agent run; suggest human handoff.' },
20
+ { category: 'prefs', content: 'User preference: Use temperature=0.2 for decision-making tasks.' },
21
+ { category: 'tasks', content: 'Test task 2: Update system prompts in spawndave.js to include memory instructions.' }
22
+ ];
23
+
24
+ // Write memories
25
+ for (const data of testWrites) {
26
+ const result = await tools.call('memory_write', data);
27
+ console.log(result);
28
+ }
29
+
30
+ console.log('\n๐Ÿ“– Test Recalls:\n');
31
+
32
+ console.log('1. Recent memories (empty query):');
33
+ console.log(await tools.call('memory_recall', {}));
34
+
35
+ console.log('\n2. Filter by "tasks":');
36
+ console.log(await tools.call('memory_recall', { query: 'tasks' }));
37
+
38
+ console.log('\n3. Filter by "errors":');
39
+ console.log(await tools.call('memory_recall', { query: 'errors' }));
40
+
41
+ console.log('\n4. Filter by "prefs":');
42
+ console.log(await tools.call('memory_recall', { query: 'prefs' }));
43
+
44
+ console.log('\n5. No matches (nonexistent):');
45
+ console.log(await tools.call('memory_recall', { query: 'foobar' }));
46
+
47
+ // Verify file exists and has content
48
+ const content = await fs.readFile(memoryPath, 'utf8');
49
+ console.log(`\n๐Ÿ“ Raw .cache/memory.ndjson (${content.split('\\n').length - 1} entries):\n${content}`);
50
+
51
+ console.log('\nโœ… All tests passed! Tools work as expected.');