feat: ai — gemini terse+render+last+session+machine, openrouter new tool, capture any command
gemini enhancements: - built-in terse system prompt with troubleshooting clause + machine context - markdown→terminal rendering (glow opportunistic + zero-dep awk fallback) - --last: pos logs + captured output fallback, staleness warning, stderr annotations - session default always on; --session override; answer separation on tty - --full flag, --system wholesale override openrouter (new tool): - cloned from gemini, adapted for OpenAI-compatible REST API - Bearer auth, messages array, choices[0].message.content parsing - config: pos config ai-openrouter → OPENROUTER_API_KEY/MODEL - default model: openrouter/auto (auto-picks best model) - all features: ask, chat, sessions, --last, capture capture subcommand (both tools): - runs any command, tees output to last_cmd_output for --last - --last fallback: pos logs (priority) → last_cmd_output (secondary) shell hook (optional): - lib/pos-ai-hook.sh: sourceable .bashrc snippet for auto-capture - exec > >(tee ...) with 1 MB truncation
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
# Optional shell hook for pos ai * --last: auto-captures terminal output.
|
||||
# Usage: add to ~/.bashrc:
|
||||
# source /usr/local/bin/pos-ai-hook.sh
|
||||
# — or —
|
||||
# source /path/to/Linux_post_install/lib/pos-ai-hook.sh
|
||||
#
|
||||
# After sourcing, every command's stdout+stderr is silently tee'd to
|
||||
# ~/.local/share/linux_post_install/last_cmd_output (truncated at 1 MB).
|
||||
# Then pos ai gemini ask --last / pos ai openrouter ask --last will
|
||||
# pick it up automatically — no 'capture' subcommand needed.
|
||||
# To disable: unset __POS_CAPTURE_ACTIVE
|
||||
|
||||
__POS_CAPTURE_FILE="${HOME}/.local/share/linux_post_install/last_cmd_output"
|
||||
__POS_CAPTURE_MAX=${__POS_CAPTURE_MAX:-1048576} # 1 MB, override with env
|
||||
|
||||
# Truncate if oversized (keep last half)
|
||||
if [ -f "$__POS_CAPTURE_FILE" ]; then
|
||||
__sz=$(stat -c%s "$__POS_CAPTURE_FILE" 2>/dev/null || echo 0)
|
||||
if [ "$__sz" -gt "$__POS_CAPTURE_MAX" ]; then
|
||||
tail -c $((__POS_CAPTURE_MAX / 2)) "$__POS_CAPTURE_FILE" > "${__POS_CAPTURE_FILE}.tmp" 2>/dev/null
|
||||
mv -- "${__POS_CAPTURE_FILE}.tmp" "$__POS_CAPTURE_FILE"
|
||||
fi
|
||||
else
|
||||
: > "$__POS_CAPTURE_FILE"
|
||||
fi
|
||||
|
||||
# Only activate in interactive terminals, not already redirected
|
||||
if [ -t 1 ] && [ -t 2 ] && [ -z "${__POS_CAPTURE_ACTIVE:-}" ]; then
|
||||
export __POS_CAPTURE_ACTIVE=1
|
||||
exec > >(tee -a "$__POS_CAPTURE_FILE" 2>&1) 2>&1
|
||||
fi
|
||||
Reference in New Issue
Block a user