feat(agent-queue): add requeue and clean commands

- requeue <job>: move a failed job back to inbox/ and drop stale meta/body so
  it re-runs cleanly
- clean [--keep N]: archive finished jobs' logs+meta beyond the newest N
  (default 50) into queue/.archive/<ts>/; running jobs + .md records untouched
- document both in usage + bytelyst-cli subcommand list
This commit is contained in:
saravanakumardb1 2026-05-28 22:31:56 -07:00
parent 76104bda84
commit 1f15520c4f
2 changed files with 57 additions and 1 deletions

View File

@ -489,6 +489,58 @@ cmd_logs() {
if [[ -n "$follow" ]]; then tail -f "$lf"; else cat "$lf"; fi
}
# requeue <job> — move a failed job back to inbox/ for a fresh run.
cmd_requeue() {
ensure_dirs
local job="${1:-}"
[[ -n "$job" ]] || die "usage: requeue <job>"
local f="$FAILED/$job.md"
[[ -f "$f" ]] || f=$(ls -1t "$FAILED"/*"$job"*.md 2>/dev/null | head -1)
[[ -f "$f" ]] || die "no failed job matching '$job'"
local base name; base=$(basename "$f"); name=${base%.md}
mv "$f" "$INBOX/$base"
# drop stale state so it re-runs cleanly
rm -f "$STATE/$name.meta" "$STATE/$name.body.md" "$STATE/$name.timedout"
log "requeued $C_BOLD$base$C_RESET (failed → inbox)"
}
# clean [--keep N] — archive finished jobs' logs+meta beyond the newest N
# (default 50) into queue/.archive/<ts>/. Running jobs and the done/failed .md
# kanban records are left untouched.
cmd_clean() {
ensure_dirs
local keep=50
while [[ $# -gt 0 ]]; do
case "$1" in
--keep) keep=$2; shift 2;;
*) die "clean: unknown arg '$1'";;
esac
done
[[ "$keep" =~ ^[0-9]+$ ]] || die "clean: --keep must be a number"
local arch="$QUEUE_ROOT/.archive/$(date +%Y%m%d-%H%M%S)"
# finished metas (have ended=), newest-first by mtime
local metas; metas=$(grep -l '^ended=' "$STATE"/*.meta 2>/dev/null \
| while IFS= read -r m; do printf '%s %s\n' "$(_mtime "$m")" "$m"; done \
| sort -rn | awk '{print $2}')
local i=0 moved=0 m name
while IFS= read -r m; do
[[ -n "$m" ]] || continue
i=$((i+1))
[[ "$i" -le "$keep" ]] && continue
name=$(basename "$m"); name=${name%.meta}
mkdir -p "$arch"
mv "$m" "$arch/" 2>/dev/null
[[ -f "$LOGS/$name.log" ]] && mv "$LOGS/$name.log" "$arch/" 2>/dev/null
[[ -f "$STATE/$name.body.md" ]] && mv "$STATE/$name.body.md" "$arch/" 2>/dev/null
moved=$((moved+1))
done <<< "$metas"
if [[ "$moved" -gt 0 ]]; then
log "archived $moved finished job(s) to $C_BOLD$arch$C_RESET (kept newest $keep)"
else
log "nothing to clean (≤$keep finished jobs)"
fi
}
usage() {
cat <<EOF
${C_BOLD}agent-queue${C_RESET} — folder kanban runner for devin | claude | codex
@ -507,6 +559,8 @@ ${C_BOLD}COMMANDS${C_RESET}
dash [--interval N] richer live Node dashboard (recent done/failed too)
stop kill running workers + the run loop
logs <job> [-f] print (or follow) a job's log
requeue <job> move a failed job back to inbox/
clean [--keep N] archive finished logs+meta beyond newest N (default 50)
help this message
${C_BOLD}KANBAN${C_RESET} inbox → doing → done / failed (logs/ + .state/ alongside)
@ -537,6 +591,8 @@ main() {
dash|dashboard) cmd_dash "$@";;
stop) cmd_stop "$@";;
logs) cmd_logs "$@";;
requeue) cmd_requeue "$@";;
clean) cmd_clean "$@";;
help|-h|--help) usage;;
*) err "unknown command: $cmd"; echo; usage; exit 1;;
esac

View File

@ -88,7 +88,7 @@ usage() {
echo " check-collaborators --input <input.json>"
echo " export --type <repos|users> --output <file.json>"
echo " remove-user-from-all-repos --user <username> [--input <file.json>]"
echo " agent-queue (aq) <init|add|run|status|watch|stop|logs> — agent prompt queue runner"
echo " agent-queue (aq) <init|add|run|status|watch|dash|stop|logs|requeue|clean> — agent prompt queue runner"
echo " help Show this help message"
echo ""
echo "If no command is given, an interactive menu will be shown."