49 lines
1.7 KiB
Bash
Executable file
49 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# kilocode-loop launcher — run from anywhere inside a git repo.
|
|
#
|
|
# kilo-loop --goal .kilocode-loop/goal.json -n 5
|
|
# kilo-loop # uses <repo>/.kilocode-loop/goal.json
|
|
# kilo-loop --dry-run -n 3 # offline rehearsal
|
|
#
|
|
# Installs node_modules on first use, then runs the loop with the repo root as
|
|
# --project. Every argument is forwarded to bin/kilocode-loop.mjs.
|
|
set -euo pipefail
|
|
|
|
APP_DIR="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
|
|
|
|
# Project = git root of the current directory (submodules resolve to themselves).
|
|
ROOT="$(git -C "$PWD" rev-parse --show-toplevel 2>/dev/null || printf '%s' "$PWD")"
|
|
|
|
if [ ! -d "$APP_DIR/node_modules" ]; then
|
|
echo "[kilo-loop] installing dependencies in $APP_DIR ..." >&2
|
|
(cd "$APP_DIR" && npm install --no-audit --no-fund >&2)
|
|
fi
|
|
|
|
# Use the repo's default goal when the caller did not pass one.
|
|
has_goal=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--goal | --goal=* | --goal-text | --goal-text=* | --help | -h) has_goal=1 ;;
|
|
esac
|
|
done
|
|
|
|
# Prefer <root>/.kilocode-loop/goal.json; fall back to the superproject's goal
|
|
# so the command also works from inside a submodule (e.g. w4c-workflows-api).
|
|
goal_file=""
|
|
if [ -f "$ROOT/.kilocode-loop/goal.json" ]; then
|
|
goal_file="$ROOT/.kilocode-loop/goal.json"
|
|
else
|
|
super="$(git -C "$ROOT" rev-parse --show-superproject-working-tree 2>/dev/null || true)"
|
|
if [ -n "${super:-}" ] && [ -f "$super/.kilocode-loop/goal.json" ]; then
|
|
goal_file="$super/.kilocode-loop/goal.json"
|
|
fi
|
|
fi
|
|
|
|
default_goal=()
|
|
if [ "$has_goal" -eq 0 ] && [ -n "$goal_file" ]; then
|
|
default_goal=(--goal "$goal_file")
|
|
fi
|
|
|
|
exec node "$APP_DIR/bin/kilocode-loop.mjs" --project "$ROOT" \
|
|
${default_goal[@]+"${default_goal[@]}"} "$@"
|