You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a comprehensive and well-structured Bash script that enables a conversational interface with models running on Ollama, using CLI tool execution as plugins ("toolshed"). Here's a detailed code review broken down into strengths, issues, and recommendations.
✅ Strengths
🔧 Modularity
Each function has a clear single responsibility, e.g., getSystemPrompt*(), addMessage(), sendRequestToAPI(), etc.
Configurations are centralized using the configs array and handled cleanly.
📦 Tool Integration
Good support for modular "tools" via a JSON definition and a shell script. This design makes it easy to add new capabilities.
💬 Prompt Management
Tracks conversation history using a JSON array of messages.
Allows multi-line input via /multi and raw shell commands using !cmd.
🧪 Debugging Support
Simple but effective debug() and debugJson() functions toggle via /config verbose on.
🧠 Structured Thinking
Incorporates "thinking" steps in assistant responses via showThinking().
If $toolFile contains spaces (e.g., in argument strings), it may fail.
✅ Safer:
toolResult="$(bash -c "$toolFile")"
Race Conditions on toolResult
If tool output is large or error-prone, you should handle:
Exit status of tool execution
Stderr/stdout separation
✅ Example:
toolResult="$(bash -c "$toolFile" 2>&1)"
if [ $? -ne 0 ]; then
echo "Tool execution failed: $toolResult"
return
fi
Hard-Coded Tool Paths
Assumes all tools are in ./tools/toolName/run.sh.
✅ Suggest using:
local toolPath="${TOOLS_DIRECTORY}/${function_name}/run.sh"
if [ ! -x "$toolPath" ]; then
echo "Tool script not found or not executable: $toolPath"
return 1
fi
Missing JSON Escaping in Shell Tool Arguments
Tool arguments passed like this:
run.sh {json}
This will break if json contains quotes or special chars.
✅ Safer:
Write JSON to a temp file and pass the file path
Or use proper JSON escaping with printf '%q'.
💡 Suggestions for Improvement
A. Use ShellCheck
Run your script through ShellCheck. It’ll flag subtle quoting, logic, and portability issues.
B. Add Logging Levels (INFO, WARN, ERROR)
Currently only debug is supported. A logging helper like:
Create a tests/ folder with sample tools and model mocks to validate CLI behavior.
E. Graceful Ctrl+C
Consider catching SIGINT for cleanup:
trap 'echo; echo "🛑 Exiting..."; exit 0' SIGINT
✅ Overall Assessment
Category Score / Notes
Functionality ✅ Excellent. Core features work well.
Code Organization ✅ Clean modular functions
Error Handling ⚠️ Needs improvement in some areas
Shell Scripting Best Practices ⚠️ A few issues with continue, quoting
User Experience ✅ Thoughtful prompt, tools, and help UX
Extensibility ✅ High – easy to add tools or models
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
This is a comprehensive and well-structured Bash script that enables a conversational interface with models running on Ollama, using CLI tool execution as plugins ("toolshed"). Here's a detailed code review broken down into strengths, issues, and recommendations.
✅ Strengths
🔧 Modularity
Each function has a clear single responsibility, e.g., getSystemPrompt*(), addMessage(), sendRequestToAPI(), etc.
Configurations are centralized using the configs array and handled cleanly.
📦 Tool Integration
Good support for modular "tools" via a JSON definition and a shell script. This design makes it easy to add new capabilities.
💬 Prompt Management
Tracks conversation history using a JSON array of messages.
Allows multi-line input via /multi and raw shell commands using !cmd.
🧪 Debugging Support
Simple but effective debug() and debugJson() functions toggle via /config verbose on.
🧠 Structured Thinking
Incorporates "thinking" steps in assistant responses via showThinking().
continue should only be used inside loops.
continue
You likely meant return here. For example:
/config name value - set a config to new value
Change this:
setConfig "${commandArray[1]}" "${commandArray[2]}"
continue
To:
setConfig "${commandArray[1]}" "${commandArray[2]}"
return 0
Applies to other places in processUserCommand.
In:
toolResult="$($toolFile)"
If $toolFile contains spaces (e.g., in argument strings), it may fail.
✅ Safer:
toolResult="$(bash -c "$toolFile")"
If tool output is large or error-prone, you should handle:
Exit status of tool execution
Stderr/stdout separation
✅ Example:
toolResult="$(bash -c "$toolFile" 2>&1)"
if [ $? -ne 0 ]; then
echo "Tool execution failed: $toolResult"
return
fi
Assumes all tools are in ./tools/toolName/run.sh.
✅ Suggest using:
local toolPath="${TOOLS_DIRECTORY}/${function_name}/run.sh"
if [ ! -x "$toolPath" ]; then
echo "Tool script not found or not executable: $toolPath"
return 1
fi
Tool arguments passed like this:
run.sh {json}
This will break if json contains quotes or special chars.
✅ Safer:
Write JSON to a temp file and pass the file path
Or use proper JSON escaping with printf '%q'.
💡 Suggestions for Improvement
A. Use ShellCheck
Run your script through ShellCheck. It’ll flag subtle quoting, logic, and portability issues.
B. Add Logging Levels (INFO, WARN, ERROR)
Currently only debug is supported. A logging helper like:
log() { echo -e "[INFO] $"; }
warn() { echo -e "[WARN] $" >&2; }
error() { echo -e "[ERROR] $*" >&2; }
Would improve readability and structure.
C. JSON Validation
Use jq empty to validate tool JSON definitions before loading:
cat "$definitionFile" | jq empty 2>/dev/null || {
echo "Invalid JSON in $definitionFile"
continue
}
D. Add Unit Tests (optional)
Create a tests/ folder with sample tools and model mocks to validate CLI behavior.
E. Graceful Ctrl+C
Consider catching SIGINT for cleanup:
trap 'echo; echo "🛑 Exiting..."; exit 0' SIGINT
✅ Overall Assessment
Category Score / Notes
Functionality ✅ Excellent. Core features work well.⚠️ Needs improvement in some areas⚠️ A few issues with continue, quoting
Code Organization ✅ Clean modular functions
Error Handling
Shell Scripting Best Practices
User Experience ✅ Thoughtful prompt, tools, and help UX
Extensibility ✅ High – easy to add tools or models
Would you like me to:
Refactor the script for safer tool execution?
Generate unit tests or a ShellCheck report?
Create a CLI help summary as Markdown?
Let me know how deep you'd like to go.
Beta Was this translation helpful? Give feedback.
All reactions