Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ echo "Fix this code: print('hello world)" | ask
cat script.py | ask "Review this code"
```

### Interactive execution mode

```bash
# Show the AI response, then prompt:
# Execute this command? (y/n):
ask -x "list all files in current directory"
```

## Options

| Option | Description |
Expand All @@ -99,6 +107,7 @@ cat script.py | ask "Review this code"
| `-r` | Disable system prompt |
| `--stream` | Enable streaming output |
| `--system` | Set custom system prompt |
| `-x` | Enable Interactive execution |
| `--provider` | Set provider order (comma-separated) |
| `-h, --help` | Show help message |

Expand Down
43 changes: 40 additions & 3 deletions ask
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PROMPT=""
STREAMING=false
NO_SYSTEM=false
PROVIDER_ORDER=""
EXECUTE=false

# Default system prompt (direct answers)
DEFAULT_PROMPT="You are a direct answer engine. Output ONLY the requested information.
Expand Down Expand Up @@ -60,6 +61,7 @@ Options:
-q Use qwen/qwen3-235b-a22b-2507
-m MODEL Use custom model
-r Disable system prompt (raw model behavior)
-x Enable interactive execution (prompt y/n to execute)
--stream Enable streaming output
--system Set system prompt for the conversation
--provider Comma-separated list of providers for routing
Expand All @@ -69,6 +71,7 @@ Examples:
ask "Write a hello world in Python"
ask -g "Explain quantum computing"
ask -m openai/gpt-4o "What is 2+2?"
ask -x "Create a backup of my home directory"
echo "Fix this code" | ask
ask --system "You are a pirate" "Tell me about sailing"

Expand All @@ -89,6 +92,9 @@ while [ $# -gt 0 ]; do
-r)
NO_SYSTEM=true
shift ;;
-x)
EXECUTE=true
shift ;;
--stream)
STREAMING=true
shift ;;
Expand Down Expand Up @@ -148,7 +154,8 @@ echo

# Make API request
if [ "$STREAMING" = true ]; then
# Streaming mode
# Streaming mode - use temp file to capture content for execution
temp_file=$(mktemp)
curl -sS "$API_URL" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
Expand All @@ -165,10 +172,17 @@ if [ "$STREAMING" = true ]; then
[ "$json" = "" ] || [ "$json" = "[DONE]" ] && continue

content=$(echo "$json" | jq -r '.choices[0].delta.content // ""' 2>/dev/null)
[ -n "$content" ] && printf '%s' "$content"
if [ -n "$content" ]; then
printf '%s' "$content"
printf '%s' "$content" >> "$temp_file"
fi
fi
done
echo

# Read captured content for potential execution
response_content=$(cat "$temp_file")
rm -f "$temp_file"

# Show metadata
ELAPSED=$(printf "%.2f" $(echo "$(date +%s.%N) - $START_TIME" | bc))
Expand All @@ -188,7 +202,8 @@ else
fi

# Extract and print content
echo "$response" | jq -r '.choices[0].message.content // "No response received"'
response_content=$(echo "$response" | jq -r '.choices[0].message.content // "No response received"')
echo "$response_content"

# Show metadata
ELAPSED=$(printf "%.2f" $(echo "$(date +%s.%N) - $START_TIME" | bc))
Expand All @@ -199,3 +214,25 @@ else
echo
echo "[$MODEL via $PROVIDER - ${ELAPSED}s - ${TPS} tok/s]" >&2
fi

# Interactive execution if enabled
if [ "$EXECUTE" = true ]; then
echo >&2
echo -n "Execute this command? (y/n): " >&2
read -r answer
case "$answer" in
[Yy]|[Yy][Ee][Ss])
echo "Executing..." >&2
echo
# Execute the command using captured response content
if [ -n "$response_content" ]; then
eval "$response_content"
else
echo "Error: No command to execute" >&2
fi
;;
*)
echo "Command not executed." >&2
;;
esac
fi