Commit graph

10 commits

Author SHA1 Message Date
dan 48ec6cde83 fix(worker): address code review findings
- Fix rollback to handle partial branch creation (skills-yylq)
  - Pre-compute branch/worktree names before createWorktree
  - Use gitBranchExists() and dirExists() for robust cleanup
- Add step context to error messages (skills-ux6h)
  - Track currentStep through spawn process
  - Error now shows which step failed
- Deduplicate success output block (skills-qjln)
  - Consolidated to single block with conditional review line
- Simplify use-skills.sh auth symlink (skills-475o)
  - One-liner with || instead of nested if
- Fix inconsistent default branch in git.nim (skills-fext)
  - Changed default from "origin/integration" to "main"

Closes skills-yylq, skills-ux6h, skills-qjln, skills-475o, skills-fext

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 09:37:37 -08:00
dan 461c5ac148 fix(worker): improve spawn reliability and add noFetch flag
- Change default base branch from origin/integration to main
- Add --noFetch flag to skip git fetch (for offline/sandbox use)
- Add try/except with rollback on spawn failure
- Improve error message for missing review-gate
- Add Codex auth.json symlink to use-skills.sh
- Include worker orchestration AAR from 2026-01-13

Addresses pain points from worker-orchestration-aar-2026-01-13.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 09:29:36 -08:00
dan b0719d2c59 cleanup: P4 worker code quality fixes
- Extract renderStatusTable() from nested proc in status()
- Add column width constants (ColTask, ColState, etc.)
- Use parseEnum for heartbeat status instead of case statement
- Return bool from startGlobalHeartbeat() to indicate if started
- Remove unused getBranchStatus() function (dead code)

Closes: skills-y76g, skills-f8yd, skills-audh, skills-hx1n, skills-827e

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 15:46:34 -08:00
dan de84648563 fix: proper exit codes for state transition errors
- Add try/except blocks in worker commands to catch WorkerNotFound,
  InvalidTransition, and StaleState exceptions
- Return ExitInvalidTransition (3) for state transition errors
- Return ExitNotFound (7) for missing workers
- Fix double ROLLBACK bug in state.nim by removing inline ROLLBACKs
  and letting the except block handle transaction cleanup

Closes: skills-lxb9

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 14:28:21 -08:00
dan 7660693717 feat(worker): add test suite and fix worktree DB path
Test infrastructure:
- Add comprehensive test-worker.sh with 59 tests
- Cover spawn, start, done, approve, reject, cancel, fail, heartbeat
- Test status filtering, context files, review-gate integration
- Test invalid state transitions and error cases

Bug fixes:
- Fix agent commands failing when run from worktrees (skills-y3f2)
  - Add getMainRepoBusDbPath() to find DB in main repo
  - Update start, done, fail, heartbeat to use correct path
- Fix review.nim crash when review-gate not installed (OSError)
  - Gracefully return exitCode=-1 instead of crashing

Closes skills-y3f2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 00:26:02 -08:00
dan caff76f618 feat(worker): integrate review-gate with worker CLI
- Add review.nim module for review-gate integration
- spawn: enables review-gate automatically
- status: shows review state column (pending/approved/REJECTED)
- show: displays review status in detailed view
- approve: calls review-gate approve before state transition
- request-changes: calls review-gate reject with comment
- cancel/merge: clean up review state files

Closes skills-byq

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 23:24:33 -08:00
dan 3afd621bb4 fix: P2 bugs - heartbeat timing, symlink check, conflict detection
worker.nim:
- Start heartbeat before state transition in start command
  (prevents WORKING state without heartbeat if startup fails)

context.nim:
- Reject symlinks when reading context file (security)
  (prevents reading arbitrary files via symlinked .worker-ctx.json)

git.nim:
- Use case-insensitive conflict detection in rebase/merge
  (toLowerAscii instead of checking "CONFLICT" and "conflict" separately)

Closes: skills-qekj, skills-16zf, skills-n3qp

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 20:55:15 -08:00
dan 32fc21b089 chore: remove dead code and unused parameters
types.nim:
- Remove unused constants: BusJsonlPath, BlobsDir, WorkersDir

worker.nim:
- Remove unused 'by' and 'comment' parameters from approve()

Note: skills-5ax (unused imports in db.nim) no longer applies -
strutils is used for toHex in genOid fallback path.

Closes: skills-t9ub, skills-5ax, skills-fdu, skills-ghlb

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 20:41:22 -08:00
dan d3d22a91e5 refactor: extract common utilities to utils.nim
- Add branchName() and worktreePath() helpers for consistent path generation
- Add msToTime() for epoch ms to Time conversion (8 occurrences consolidated)
- Add validateTaskId() for CLI input validation (prevents path traversal)
- Add optString/optInt64 helpers for nullable DB values
- Add withTransaction template for automatic rollback on error

Closes: skills-lzh2, skills-3d9o, skills-5x2o, skills-qiq0, skills-73yu, skills-vuj2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 20:32:47 -08:00
dan 1c66d019bd feat: add worker CLI scaffold in Nim
Multi-agent coordination CLI with SQLite message bus:
- State machine: ASSIGNED -> WORKING -> IN_REVIEW -> APPROVED -> COMPLETED
- Commands: spawn, start, done, approve, merge, cancel, fail, heartbeat
- SQLite WAL mode, dedicated heartbeat thread, channel-based IPC
- cligen for CLI, tiny_sqlite for DB, ORC memory management

Design docs for branch-per-worker, state machine, message passing,
and human observability patterns.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 18:47:47 -08:00