Add LinaAI terminal command
This commit is contained in:
Executable
+175
@@ -0,0 +1,175 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
DEFAULT_REPO="${LINAAI_REPO:-$HOME/repos/AgrarianGame}"
|
||||
REPO="$DEFAULT_REPO"
|
||||
DRY_RUN=0
|
||||
FORCE_ESCALATE=0
|
||||
|
||||
usage() {
|
||||
cat >&2 <<'EOF'
|
||||
Usage:
|
||||
linaai [--repo PATH] [--dry-run] [--force-escalate] [task text...]
|
||||
|
||||
Without task text, opens an interactive LinaAI terminal prompt. Each instruction
|
||||
is routed through Scripts/linaai_task.sh from the selected repo.
|
||||
|
||||
Examples:
|
||||
linaai
|
||||
linaai --dry-run "Confirm repo access and list LinaAI docs."
|
||||
linaai "Update docs for the current deployment workflow."
|
||||
|
||||
Interactive commands:
|
||||
/help Show commands.
|
||||
/repo PATH Change repo path.
|
||||
/status Show git status for current repo.
|
||||
/refresh Refresh LinaAI knowledge cache.
|
||||
/dry on|off Toggle dry-run mode.
|
||||
/codex on|off Toggle forced Codex escalation.
|
||||
/exit Quit.
|
||||
EOF
|
||||
}
|
||||
|
||||
run_status() {
|
||||
cd "$REPO"
|
||||
printf 'Repo: %s\n' "$REPO"
|
||||
git branch --show-current 2>/dev/null || true
|
||||
git status --short
|
||||
}
|
||||
|
||||
refresh_context() {
|
||||
cd "$REPO"
|
||||
if [[ -x Scripts/linaai_refresh_knowledge.sh ]]; then
|
||||
Scripts/linaai_refresh_knowledge.sh
|
||||
fi
|
||||
if [[ -x Scripts/linaai_bootstrap_context.sh ]]; then
|
||||
Scripts/linaai_bootstrap_context.sh
|
||||
fi
|
||||
}
|
||||
|
||||
run_task() {
|
||||
local task="$1"
|
||||
cd "$REPO"
|
||||
if [[ ! -x Scripts/linaai_task.sh ]]; then
|
||||
echo "Missing Scripts/linaai_task.sh in ${REPO}" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
local args=()
|
||||
if [[ "$DRY_RUN" -eq 1 ]]; then
|
||||
args+=(--dry-run)
|
||||
fi
|
||||
if [[ "$FORCE_ESCALATE" -eq 1 ]]; then
|
||||
args+=(--force-escalate)
|
||||
fi
|
||||
|
||||
Scripts/linaai_task.sh "${args[@]}" "$task"
|
||||
}
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--repo)
|
||||
REPO="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
--dry-run)
|
||||
DRY_RUN=1
|
||||
shift
|
||||
;;
|
||||
--force-escalate)
|
||||
FORCE_ESCALATE=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
echo "Unknown option: $1" >&2
|
||||
usage
|
||||
exit 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ ! -d "$REPO" ]]; then
|
||||
echo "Repo does not exist: ${REPO}" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ $# -gt 0 ]]; then
|
||||
run_task "$*"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
LinaAI terminal
|
||||
Repo: ${REPO}
|
||||
Dry run: $([[ "$DRY_RUN" -eq 1 ]] && echo on || echo off)
|
||||
Forced Codex: $([[ "$FORCE_ESCALATE" -eq 1 ]] && echo on || echo off)
|
||||
Type /help for commands or /exit to quit.
|
||||
EOF
|
||||
|
||||
while true; do
|
||||
printf '\nlinaai> '
|
||||
if ! IFS= read -r line; then
|
||||
printf '\n'
|
||||
break
|
||||
fi
|
||||
|
||||
[[ -z "${line// }" ]] && continue
|
||||
|
||||
case "$line" in
|
||||
/exit|/quit)
|
||||
break
|
||||
;;
|
||||
/help)
|
||||
usage
|
||||
;;
|
||||
/status)
|
||||
run_status
|
||||
;;
|
||||
/refresh)
|
||||
refresh_context
|
||||
;;
|
||||
/dry\ on)
|
||||
DRY_RUN=1
|
||||
echo "Dry run on."
|
||||
;;
|
||||
/dry\ off)
|
||||
DRY_RUN=0
|
||||
echo "Dry run off."
|
||||
;;
|
||||
/codex\ on)
|
||||
FORCE_ESCALATE=1
|
||||
echo "Forced Codex escalation on."
|
||||
;;
|
||||
/codex\ off)
|
||||
FORCE_ESCALATE=0
|
||||
echo "Forced Codex escalation off."
|
||||
;;
|
||||
/repo\ *)
|
||||
next_repo="${line#/repo }"
|
||||
if [[ -d "$next_repo" ]]; then
|
||||
REPO="$next_repo"
|
||||
echo "Repo set to ${REPO}"
|
||||
else
|
||||
echo "Repo does not exist: ${next_repo}" >&2
|
||||
fi
|
||||
;;
|
||||
/*)
|
||||
echo "Unknown command: ${line}" >&2
|
||||
;;
|
||||
*)
|
||||
run_task "$line"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user