amduat-api/scripts/v2_app.sh

134 lines
2.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# shellcheck source=/dev/null
source "${ROOT_DIR}/src/app_v2.sh"
usage() {
cat <<USAGE
usage: $0 COMMAND [args]
commands:
startup-check
ai-vertical-slice [--skip-evals] [--auto-start-daemon]
ai-agent [--json] [--require-evidence] [--max-steps N] [--state-file PATH] [--auto-start-daemon] ROOTS_CSV QUESTION [GOAL_PREDICATES_CSV]
ai-check
ai-generate [--json] PROMPT
ai-answer [--json] [--require-evidence] ROOTS_CSV QUESTION [GOAL_PREDICATES_CSV]
ingest PAYLOAD_JSON
sync-once
consume-changes [--once]
sync-loop (deprecated alias for consume-changes)
retrieve ROOTS_CSV [GOAL_PREDICATES_CSV]
tombstone EDGE_REF
USAGE
}
if [[ $# -lt 1 ]]; then
usage >&2
exit 2
fi
app_init
cmd="$1"
shift
case "${cmd}" in
startup-check)
app_startup_checks
;;
ai-vertical-slice)
"${ROOT_DIR}/scripts/ai_vertical_slice.sh" "$@"
;;
ai-agent)
"${ROOT_DIR}/scripts/ai_agent_loop.sh" "$@"
;;
ai-check)
app_ai_check
;;
ai-generate)
output_mode="text"
if [[ $# -gt 0 && "$1" == "--json" ]]; then
output_mode="json"
shift
fi
if [[ $# -lt 1 ]]; then
echo "usage: $0 ai-generate [--json] PROMPT" >&2
exit 2
fi
if [[ "${output_mode}" == "json" ]]; then
app_ai_generate_json "$*"
else
app_ai_generate_text "$*"
fi
;;
ai-answer)
output_mode="text"
require_evidence=0
while [[ $# -gt 0 ]]; do
case "$1" in
--json)
output_mode="json"
shift
;;
--require-evidence)
require_evidence=1
shift
;;
*)
break
;;
esac
done
if [[ $# -lt 2 || $# -gt 3 ]]; then
echo "usage: $0 ai-answer [--json] [--require-evidence] ROOTS_CSV QUESTION [GOAL_PREDICATES_CSV]" >&2
exit 2
fi
roots_csv="$1"
question="$2"
goals_csv="${3:-}"
if [[ "${output_mode}" == "json" ]]; then
app_ai_answer_json "${roots_csv}" "${question}" "${goals_csv}" "${require_evidence}"
else
app_ai_answer_text "${roots_csv}" "${question}" "${goals_csv}" "${require_evidence}"
fi
;;
ingest)
if [[ $# -ne 1 ]]; then
echo "usage: $0 ingest PAYLOAD_JSON" >&2
exit 2
fi
app_ingest_batch "$1"
;;
sync-once)
app_sync_once
;;
consume-changes)
"${ROOT_DIR}/scripts/changes_consumer.sh" "$@"
;;
sync-loop)
echo "sync-loop is deprecated; use consume-changes" >&2
"${ROOT_DIR}/scripts/changes_consumer.sh" "$@"
;;
retrieve)
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "usage: $0 retrieve ROOTS_CSV [GOAL_PREDICATES_CSV]" >&2
exit 2
fi
app_retrieve_with_fallback "$1" "${2:-}"
;;
tombstone)
if [[ $# -ne 1 ]]; then
echo "usage: $0 tombstone EDGE_REF" >&2
exit 2
fi
app_tombstone_edge "$1"
;;
*)
usage >&2
exit 2
;;
esac