Commit graph

176 commits

Author SHA1 Message Date
dan daec0f3b85 docs: ADR-006 Nim language choice for worker CLI
Documents rationale for using Nim with ORC for the worker coordination
CLI: fast startup, single binary, Python-like syntax, excellent SQLite
support via tiny_sqlite, CLI generation via cligen.

Closes skills-q40

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 23:27:32 -08:00
dan b9866b7930 chore: ignore .worker-state runtime directory
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 23:24:53 -08:00
dan 7f264facd9 bd sync: 2026-01-10 23:24:37 2026-01-10 23:24:37 -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 f9ac03a8a8 bd sync: 2026-01-10 23:07:31 2026-01-10 23:07:31 -08:00
dan 405e6b9aee fix: varargs binding bug in git.nim runGit/runGitCheck
Nim's varargs doesn't consume the last positional argument when there's
a trailing parameter with a default value. This caused calls like
`runGit("fetch", "origin")` to be parsed as:
  - args = ["fetch"]
  - workDir = "origin"

Instead of the intended:
  - args = ["fetch", "origin"]
  - workDir = ""

Fixed by changing from varargs to openArray, which requires explicit
array syntax at call sites: `runGit(["fetch", "origin"])`.

Also includes P2 bug fixes:
- Start heartbeat before state transition (skills-qekj)
- Reject symlinks when reading context file (skills-16zf)
- Case-insensitive conflict detection (skills-n3qp)

Smoke tested: spawn, status, start, show, cancel all work.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 21:24:41 -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 c44f2106ee bd sync: 2026-01-10 20:55:02 2026-01-10 20:55:02 -08:00
dan 7e368a2cde bd sync: 2026-01-10 20:41:42 2026-01-10 20:41:42 -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 2f0aad5a25 bd sync: 2026-01-10 20:41:13 2026-01-10 20:41:13 -08:00
dan 09b76605c2 refactor: implement consistent error handling strategy
Error handling helpers in utils.nim:
- logError/logWarn: consistent stderr format
- wrapError template: catch and re-raise with context

db.nim:
- openBusDb: wrap with DbError and path context
- poll: handle malformed JSON gracefully with warning
- tryClaim: log failures instead of silently swallowing

git.nim:
- createWorktree/rebaseOnIntegration: warn on fetch failure
- removeWorktree/removeBranch: log cleanup failures
- getBranchStatus: log parseInt failures

context.nim:
- readContext/findContext: add path context to parse errors
- writeContext: wrap IOError with path

types.nim:
- Extract ContextDateFormat constant
- Add context to date parse errors

Closes: skills-05ah, skills-xcl, skills-266, skills-8xv, skills-8vdo,
        skills-tdfm, skills-koes, skills-8bi, skills-2wjp, skills-3uv9, skills-xgh0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 20:37:47 -08:00
dan 5121bbb008 bd sync: 2026-01-10 20:37:34 2026-01-10 20:37:34 -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 5550421ae9 bd sync: 2026-01-10 20:32:36 2026-01-10 20:32:36 -08:00
dan 200c040d3a fix: P1 security bugs - cryptographic IDs and GC-managed heartbeat
- genOid: use std/sysrand for cryptographic randomness instead of rand()
- HeartbeatThread: change from ptr with manual alloc/dealloc to ref object
- Add error handling for DB open in heartbeat thread
- Remove unused globalChannel and times import

Closes: skills-0wk, skills-bk7x, skills-69sz, skills-ib9u, skills-kvdl, skills-n6zf

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 20:26:38 -08:00
dan 02b7054709 bd sync: 2026-01-10 20:26:28 2026-01-10 20:26:28 -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
dan 555dbb8ccd bd sync: 2026-01-10 18:04:40 2026-01-10 18:04:40 -08:00
dan 6dfd373637 bd sync: 2026-01-10 16:08:27 2026-01-10 16:08:27 -08:00
dan 91f324949c bd sync: 2026-01-10 15:56:52 2026-01-10 15:56:53 -08:00
dan f2a5199337 bd sync: 2026-01-10 15:44:21 2026-01-10 15:44:21 -08:00
dan 713a627185 bd sync: 2026-01-10 15:41:05 2026-01-10 15:41:05 -08:00
dan 0fcfbe0624 bd sync: 2026-01-10 15:34:24 2026-01-10 15:34:24 -08:00
dan 1888db7ec0 bd sync: 2026-01-10 15:27:39 2026-01-10 15:27:39 -08:00
dan bc4f2e85cf bd sync: 2026-01-10 15:08:58 2026-01-10 15:08:58 -08:00
dan 83b126719d bd sync: 2026-01-10 15:00:45 2026-01-10 15:00:45 -08:00
dan ed12600df1 bd sync: 2026-01-10 14:37:59 2026-01-10 14:37:59 -08:00
dan 7c6ff10be7 bd sync: 2026-01-10 14:01:28 2026-01-10 14:01:28 -08:00
dan a34da926c2 bd sync: 2026-01-10 13:55:44 2026-01-10 13:55:44 -08:00
dan d6c47c26f5 docs: worklog for multi-agent Lego architecture design session
Covers: review-gate Stop hook fixes, circuit breaker, research on
OpenHands/Gastown/JWZ patterns, epic creation, phased approach

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 13:35:58 -08:00
dan cc2a727644 bd sync: 2026-01-10 13:34:04 2026-01-10 13:34:04 -08:00
dan 71d8445be4 bd sync: 2026-01-10 13:24:42 2026-01-10 13:24:43 -08:00
dan 7426c1f303 bd sync: 2026-01-10 12:24:11 2026-01-10 12:24:11 -08:00
dan c474b81f51 bd sync: 2026-01-10 12:15:46 2026-01-10 12:15:46 -08:00
dan 0356ed237c feat: add circuit breaker to prevent Stop hook infinite loop
- Track block attempts per session in .attempts file
- After 3 attempts (configurable via REVIEW_MAX_ATTEMPTS), trip breaker
- Circuit breaker allows exit with warning instead of crashing
- Clear attempts on approve or when breaker trips
- Add 3 new tests for circuit breaker behavior (46 total)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 10:33:24 -08:00
dan 9df3aedc2f fix: prevent Stop hook infinite loop via stop_hook_active check
When Claude continues after a Stop hook block, the next Stop hook
invocation has stop_hook_active: true. Detect this and allow exit
to break the loop and prevent stack overflow crash.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 09:34:15 -08:00
dan 020458c9b8 fix: review-gate Stop hook output format and test harness
- Change exit code to 2 (Claude Code blocking signal)
- Output JSON to stderr with decision: block and reason fields
- Add integration test harness for live Claude testing
- Update unit tests for new JSON output format
- Add hooks.json example for Stop hook

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 08:23:46 -08:00
dan 4130dd4614 test: add review-gate unit tests (43 tests)
Tests cover:
- All CLI commands (check, enable, approve, reject, status, list, clean)
- Exit codes (0 for allow, 1 for block)
- State file creation and JSON structure
- Session ID auto-detection from env vars
- Multiple issues in reject
- Workflow reset (re-enable after approve)
- Error handling

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 23:09:33 -08:00
dan 061556e003 bd sync: 2026-01-09 20:39:37 2026-01-09 20:39:37 -08:00
dan 91b6c842a2 feat: add review-gate skill for cross-agent quality enforcement
- CLI tool with check/enable/approve/reject/status commands
- Stop hook integration for Claude Code blocking
- Adversarial reviewer prompt template
- Dual-publish structure (SKILL.md + .claude-plugin)
- Session ID auto-detection from env vars or git state

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 20:39:34 -08:00
dan 4d298c1e22 bd sync: 2026-01-09 19:59:51 2026-01-09 19:59:51 -08:00
dan beace9046d bd sync: 2026-01-09 19:51:10 2026-01-09 19:51:10 -08:00
dan 75c5edb86c docs: cross-agent enforcement architecture design
Comprehensive design covering:
- Abstract layers (message passing, memory, enforcement)
- Four enforcement strategies:
  - Hook-based (Claude/Gemini)
  - Orchestrator-enforced (OpenCode/Codex)
  - Validator sidecar (universal)
  - Proxy-based (API interception)
- Circuit breakers (semantic drift, three-strike, budget)
- Adversarial reviewer pattern
- State flow diagram
- Implementation phases

Based on web research via orch (gemini --websearch).

Addresses: skills-8sj

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:51:09 -08:00
dan 8c033eedd1 docs: add Gemini path fix (includeDirectories setting)
Gemini CLI can access ~/.claude/skills/ via:
  settings.json: { "context": { "includeDirectories": ["~/.claude/skills"] } }
  or CLI: gemini --include-directories ~/.claude/skills

Closes: skills-8nl, skills-bo8

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 19:35:28 -08:00
dan f7483edcf3 bd sync: 2026-01-09 19:33:03 2026-01-09 19:33:03 -08:00
dan 52fe241734 bd sync: 2026-01-09 19:01:55 2026-01-09 19:01:55 -08:00
dan c14075ae7e docs: web research on cross-agent patterns (via orch)
Key findings from gemini --websearch:
- Manager-Worker orchestration (Maestro pattern)
- alice/idle adversarial review gates (emes)
- Git-as-state for agent coordination
- tissue for machine-first issue tracking
- Circuit breakers: semantic drift, three-strike, budget limits
- Sandboxing: Wasm and Docker playgrounds

Validates our direction: beads, orch, file-based coordination.
Gaps: orchestrator-enforced gates, agent messaging, sandboxing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 17:50:37 -08:00
dan e367be6cb6 bd sync: 2026-01-09 17:32:23 2026-01-09 17:32:23 -08:00
dan ec2d856c05 docs: add agent capability matrix for cross-agent design
Comprehensive comparison of Claude Code, Gemini CLI, OpenCode, and Codex:
- Hooks/lifecycle events (Claude/Gemini best, OpenCode most comprehensive)
- Subagent spawning (MCP is universal bridge)
- File access (Gemini has path restrictions - skills-bo8)
- Sandboxing (Codex has OS-level, others approval-based)
- State persistence (need external store for cross-agent)

Key finding: Orchestrator pattern works across all agents.
Stop hooks only in Claude/Gemini - others need protocol-based gates.

Closes: skills-fqu

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-09 17:32:17 -08:00