Commit graph

37 commits

Author SHA1 Message Date
jedarden
114dc5bf35 feat(tmux-detector): implement automatic poller with @tb- prefix opt-in
Implements the tmux detector poller module based on the design in
docs/notes/tmux-detector-design.md.

Features:
- Auto-discovers opted-in panes via @tb- prefix in window title
- Polls every 2s (configurable via TRAILBOSS_POLL_INTERVAL_MS)
- Detects stuck sessions: quiet for 30s with prompt-like last line
- Detects unstuck: any output change after being stuck
- Emits normalized events to /event/normalized endpoint
- Synthetic session IDs: tmux-%446-{timestamp}
- Graceful shutdown with SIGINT/SIGTERM handling

Configuration:
- TRAILBOSS_POLL_INTERVAL_MS (default: 2000)
- TRAILBOSS_QUIET_THRESHOLD_MS (default: 30000)
- TRAILBOSS_OPT_IN_PREFIX (default: @tb-)
- TRAILBOSS_DAEMON_URL (default: http://127.0.0.1:4000/event/normalized)

Usage: bun run daemon/tmux-detector.ts

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 09:47:31 -04:00
jedarden
fd53105f6d docs(tmux-detector): add comprehensive detector poller design
Specifies the complete architecture for the harness-agnostic tmux
detector poller, answering all key questions:
- Opt-in mechanism: @tb- pane title prefix pattern
- Quiet detection: capture-pane hash comparison
- Prompt detection: configurable regex patterns
- Quiet threshold: 30 seconds (configurable)
- Unstuck detection: any output change
- Session ID generation: synthetic tmux-{paneId}-{timestamp}

Includes state machine, poll loop pseudocode, error handling,
daemon integration, testing strategy, and future enhancements.

Addresses bead tb-1ke: tmux detector poller architecture design.
2026-07-02 09:41:48 -04:00
jedarden
4ff41bc74b docs(normalized-event-contract): add comprehensive harness-agnostic adapter contract specification
Document the POST /event/normalized endpoint contract with:
- Complete endpoint specification (URL, method, request/response)
- All 4 event types with field descriptions and examples
- Derivation guide for sessionId, paneId, cwd, transcriptPath from harness context
- Implementation example for adapter authors
- Error handling and versioning guidance

This enables future adapter authors to integrate any coding harness
without reading the daemon source code.
2026-07-02 09:38:57 -04:00
jedarden
9afd810ef5 Merge branch 'main' of https://git.ardenone.com/jedarden/trail-boss 2026-07-02 09:04:06 -04:00
jedarden
116464fe30 feat(security): tighten ingest trust boundary and add invariant tests
- Remove CORS headers and OPTIONS preflight from daemon
- CORS was enabling cross-origin browser POSTs to loopback endpoint
- No legitimate consumer is a browser (emitter uses curl, TUI uses Go http)

Add invariant test script test-invariants.sh:
- Daemon listens on 127.0.0.1 only (loopback-only binding)
- No synthesized input: verify no tmux send-keys in daemon sources
- OPTIONS preflight is no longer honored (returns 404)

Validates trust boundary specified in docs/plan/plan.md section
'Failure modes & invariants'.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 09:03:55 -04:00
jedarden
cab4e37537 docs: update plan.md and README to match shipped Phase 8/9 state
- plan.md: mark Phase 8 as complete, remove (planned) marker
- plan.md: update PermissionRequest status from unverified to confirmed
  (probe 2026-05-25 confirmed firing + payload with tool_name/tool_input)
- plan.md: mark Open question 2 (PermissionRequest specifics) as resolved
- plan.md: correct Phase 8 keyboard map (l/Tab focuses detail pane, not queue head)
- plan.md: mark Open question 5 (popup vs persistent window) as resolved
  (both retained: popup for quick triage, TUI for sustained work)
- README: add SessionStart and SessionEnd to hook wiring snippet
  (daemon also consumes these for registry and retirement)
- README: add trailboss-bootstrap and trailboss-watch to repository layout
  (trailboss-watch noted as deprecated/superseded by TUI)
- CLAUDE.md: update Go version from 1.22+ to 1.24+ to match tui/go.mod

Co-Authored-By: Claude <noreply@anthropic.com>
Bead-Id: tb-1jl
2026-07-02 08:59:53 -04:00
jedarden
eecfacc55a docs: update plan.md and README to match shipped Phase 8/9 state
- plan.md: mark Phase 8 as complete, remove (planned) marker
- plan.md: update PermissionRequest status from unverified to confirmed
  (probe 2026-05-25 confirmed firing + payload with tool_name/tool_input)
- plan.md: mark Open question 2 (PermissionRequest specifics) as resolved
- plan.md: correct Phase 8 keyboard map (l/Tab focuses detail pane, not queue head)
- plan.md: mark Open question 5 (popup vs persistent window) as resolved
  (both retained: popup for quick triage, TUI for sustained work)
- README: add SessionStart and SessionEnd to hook wiring snippet
  (daemon also consumes these for registry and retirement)
- README: add trailboss-bootstrap and trailboss-watch to repository layout
  (trailboss-watch noted as deprecated/superseded by TUI)
- CLAUDE.md: update Go version from 1.22+ to 1.24+ to match tui/go.mod

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 08:58:05 -04:00
jedarden
59096c49d6 feat(reconcile): implement stuck-direction reconcile for dropped Stop events
- Add reconcileStuckDirection() to scan transcripts and recover sessions that became stuck while daemon was down
- Add paneExists() to verify tmux pane still exists before enqueuing
- Add detectStuckFromTranscriptTail() to detect stuck state from transcript tail
- Add getSessionsNotInQueue() to DB layer for finding non-queued sessions
- Call reconcileStuckDirection() on daemon startup to recover dropped events
- Remove duplicate AS-4 test code

Acceptance criteria:
- Extended test-walking-skeleton.sh AS-4 to full plan scenario (daemon restart with transcript tail scan)
- All AS-1..AS-7 tests pass
- Session appears in /queue within one sweep after daemon restart

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 08:45:26 -04:00
jedarden
1d0aafcf45 docs: update README to reflect TUI build process
- Change 'pre-built binary' language to 'build from tui/ with Go'
- Add explicit build step in installation instructions
- Note that trailboss-start auto-builds if binary is missing
- Update predispatch SHA

Bead-Id: tb-25j
Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 08:25:44 -04:00
jedarden
31829c48e4 feat(tui): commit Phase 8/9 source files
- Add tui/main.go, tui/go.mod, tui/go.sum (Go + Bubble Tea TUI)
- Add CLAUDE.md with project instructions
- Add bin/trailboss-preview script
- Update bin/trailboss, bin/trailboss-start, bin/trailboss-watch
- Update PROGRESS.md and docs/plan/plan.md to reflect completion
- Add .gitignore entries for build artifacts (tui/tui, bin/trailboss-tui)
- Remove stray root main.go placeholder and ~ directory

Bead-Id: tb-25j
Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-02 07:57:11 -04:00
jedarden
ac3c332cbd fix(reconcile): parse real Claude Code transcript format
- Parse ISO-8601 timestamps via Date.parse(), handle both strings and numbers
- Recognize real entry shape: type='user'|'assistant' with nested message.role
- Ignore non-message lines (attachments, queue-operations, etc.)
- Remove duplicate TranscriptEntry interface (import was not exported)
- Add AS-8 test validating real-format JSONL behavior
- Update fixtures to use real Claude Code format

Fixes tb-67q
2026-07-02 07:48:11 -04:00
jedarden
3e4f77289f feat(tui): add HTTP client + daemon data models
- Add Go types matching daemon /queue response (QueueItem, QueueResponse)
- Add Go types for /status response (StatusResponse)
- Add HTTP client with configurable base URL (default http://127.0.0.1:4000)
- Add 1s timeout
- Add FetchQueue() ([]QueueItem, error)
- Add PostSkip() error
- Add PostNext() (string, error)
- Add GetPaneSessionMap() to parse pane_id→session_name map via tmux list-panes -a

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 00:56:04 -04:00
jedarden
dd0ebbd6ce feat(tui): add Dracula lipgloss theme with auto-detection
- Define Theme struct with all Dracula palette colors
- Auto-detect terminal color support (truecolor, 256-color, no-color)
- Implement graceful fallback for dumb terminals
- Fix model theme field type to use pointer
- Colors: stopped badge (#F1FA8C), permission badge (#FF5555), selected row (#BD93F9),
  panel border (#6272A4), header bar (#282A36), status bar (#44475A),
  metadata text (#AAAAAA), accent cyan (#8BE9FD), accent green (#50FA7B)

Closes tb-6cj
2026-06-25 00:50:59 -04:00
jedarden
1f0e7d4f95 Merge branch 'main' of https://git.ardenone.com/jedarden/trail-boss 2026-06-24 07:09:41 -04:00
jedarden
7e32f72aed docs: improve README for clarity and discoverability
Rewrite README to reflect actual implementation (phases 1–9 complete,
all 7 acceptance scenarios passing). Previous README said "No
implementation yet" — replaced with accurate architecture overview,
setup instructions, TUI key reference, component table, and design
principles.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 07:09:16 -04:00
jedarden
d74984a7c1 docs(trail-boss): update PROGRESS.md - phase 6 complete
Bead-Id: tb-4mq
2026-05-30 12:58:43 -04:00
jedarden
2c9d0436be docs(trail-boss): update PROGRESS.md - phase 6 complete 2026-05-30 12:58:36 -04:00
jedarden
95b8bb833a docs(trail-boss): phase 6 complete - all 7 acceptance scenarios passing
- Ran test-walking-skeleton.sh successfully
- All AS-1 through AS-7 pass end-to-end
- No code changes required - implementation was already complete
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 12:57:08 -04:00
jedarden
4e593de16d feat(trail-boss): phase 6 complete - all 7 acceptance scenarios passing
Walking skeleton test suite passes end-to-end:
- AS-1: Permission block enqueue/dequeue
- AS-2: FIFO ordering
- AS-3: Answered-in-pane reconcile
- AS-4: Dropped-event recovery
- AS-5: Skip + cooldown
- AS-6: No forced focus-steal
- AS-7: Pane reuse regression

Phase 6 exit criterion met (AS-1 through AS-6 pass).
Phase 6 complete (AS-7 also passes).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-30 12:55:37 -04:00
jedarden
986582e643 docs(marathon): update Current state — phases 1–5 complete, phase 6 next
The "no implementation code exists" line was stale and would have misdirected
a fresh marathon session to re-implement from phase 1.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 22:57:57 -04:00
jedarden
fbaf1d86ab feat(trail-boss): commit phase 3 daemon code (previously untracked)
daemon/ (index.ts, types.ts, claude-adapter.ts, db.ts, reconcile.ts, schema.sql),
package.json, and test scripts were implemented but never staged. Phase 3 exit
criteria verified per PROGRESS.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 22:57:51 -04:00
jedarden
694225aee0 feat(trail-boss): phase 5 - Presentation layer
Complete the presentation layer with popup queue picker, keybindings,
and status-line segment.

Changes:
- bin/trailboss-popup: Rewritten with python3 JSON parsing, box drawing UI,
  and index-based selection that navigates directly to chosen pane
- bin/trailboss-status: Status-line segment showing "⚠ N" when stuck
- tmux.conf: Keybindings for Next (prefix+Tab), Skip (prefix+s), Popup (prefix+g)
- test-presentation.sh: Phase 5 exit criterion tests (all passing)

Verified: CLI commands work, popup lists queue with selection, status shows
stuck count, keybindings configured.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 22:26:17 -04:00
jedarden
b0b2cec511 docs(trail-boss): update PROGRESS.md for phase 4
Phase 4 complete. Navigation command implemented and verified.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 22:18:25 -04:00
jedarden
24abe52a26 feat(trail-boss): phase 4 - Navigation command
Implemented trailboss CLI with jump-next and skip commands that
navigate to panes returned by the daemon's /next endpoint.

- bin/trailboss: main CLI with jump-next, skip, popup stubs
- jump-next: queries /next, navigates via switch-client/select-window/select-pane
- skip: POSTs /skip, then jumps to new head
- test-navigation.sh: synthetic event test verifying exit criterion

Exit criterion passed: jump-next lands operator on pane returned by /next.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 22:18:01 -04:00
jedarden
21383771c6 docs(trail-boss): update PROGRESS.md for phase 3
Phase 1 and 2 complete. Moving to Phase 3: Daemon implementation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 22:04:30 -04:00
jedarden
c89b315aa7 feat(trail-boss): phase 1-2 - PermissionRequest probe and emitter
Phase 1: Probed PermissionRequest hook, confirmed firing + payload shape.
Documented in docs/research/claude-code-mechanics.md.

Phase 2: Built trailboss-emit.sh that forwards hook payloads to collector
and injects $TMUX_PANE. Wired all hooks in .claude/settings.json.

Verified: stub collector logs POSTs with session_id, cwd, and pane_id.
Demonstrated bare curl drops $TMUX_PANE, proving wrapper required.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-25 22:04:03 -04:00
jedarden
5dcb63d17b fix(marathon): source .marathon/env inside the loop shell
The launcher sourced env into its own process, but the loop runs in a separate
tmux shell that didn't inherit ANTHROPIC_BASE_URL/AUTH_TOKEN — so claude ran
unauthenticated ("Not logged in"). Source the env file inside the loop command
so the proxy/model config is present in the shell that launches claude.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 21:55:26 -04:00
jedarden
18bf11577a docs(plan): add Testing & validation — exit criteria, acceptance scenarios, harness
The plan defined deliverables but no definition of done. Add a "Testing &
validation" section: a per-phase exit-criteria table, seven acceptance
scenarios (AS-1..AS-7, incl. reconcile self-correction, dropped-event
recovery, skip/cooldown, no-forced-focus-steal, pane reuse), a test harness
(synthetic event injection, throwaway-tmux isolation, transcript fixtures,
mock hook emitter, navigation assertion, invariant checks), and a quality
gate. Point the marathon instruction at these as the definition of done.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 21:47:52 -04:00
jedarden
bc5075a016 chore(marathon): add plan-driven marathon coding infrastructure
Model the setup on existing marathon instances (FORGE/AIVC/NEEDLE):
- .marathon/instruction.md — per-iteration autonomous prompt, plan-driven off
  docs/plan/plan.md with the 7-phase order, settled invariants, and commit/push
  loop protocol
- .marathon/launch-marathon.sh — self-contained `while true` loop piping the
  instruction to `claude --print`, sourcing model/proxy config from an
  untracked .marathon/env (keeps internal endpoints out of this public repo)
- .marathon/env.example — config template
- .gitignore — ignore .marathon/env, logs/, *-config/, and .beads/*.db

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 21:42:55 -04:00
jedarden
0276706340 docs(plan): specify the switching & keybindings surface
Add a "Switching & keybindings" section: global prefix bindings that call the
daemon via run-shell — Next (jump to head-of-queue pane), Popup (display-popup
picker), Skip (tail+cooldown then advance) — plus a status-line segment.
Documents the prefix-not-bare-key constraint and why the jump is the keypress,
never automatic. Resolves open questions 3 and 4 down to polish.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 15:37:38 -04:00
jedarden
f6f31ceaea docs: gap-review round 3 — reason enum, skip-cooldown ordering, label fixes
- MEDIUM: reason enum stated as exactly {permission, stopped} (drop stray
  "stopped/needs-next" third label)
- MEDIUM: specify oldest-READY-stuck-first — a cooldowned skipped item is not
  eligible to be the head; advance to next ready item, else present empty
- MEDIUM: SubagentStop downgraded from "Confirmed" to "exists; not probed"
  (probe only saw SessionStart/Stop)
- LOW: agent-inbox reuse reworded (Trail Boss actions are navigate-and-reply /
  skip, not accept/edit/ignore); note permission_mode is display-only

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 15:28:35 -04:00
jedarden
4e1b8a9cf2 docs: gap-review round 2 — fix hook-wiring self-contradiction
- HIGH: settings.json example wired PermissionRequest to a bare curl that drops
  the env-only $TMUX_PANE; route all hooks through trailboss-emit.sh (which
  injects $TMUX_PANE) and note SessionStart is not special
- MEDIUM: remove the stray trailboss-register.sh (contradicted "registry
  self-heals on every emit"); single emitter script
- LOW: add struck-through SubagentStop row to plan detection table; clarify
  disler's store is append-only (not "read-only")

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 15:21:23 -04:00
jedarden
675c1e531d docs: gap-review round 1 — reconcile supporting docs + close spec gaps
Fix 10 gaps found by fresh-eyes review:
- CRITICAL: mechanics doc still documented send-keys-relay/Agent-SDK delivery
  and the Notification hook; rewrote DELIVER to the navigator model, dropped
  Notification throughout
- HIGH: decisions.md + related-work.md still referenced priority "ranking",
  /reply dispatch, send-keys/SDK delivery, and the dead plan/question/idle
  reason taxonomy; aligned to FIFO + navigation + permission/stopped
- collector and daemon stated as one process; pull-not-broadcast presentation
- added trust boundary (loopback-only ingest, single-host trust assumption)
- resolved auto-advance focus-steal hazard (operator-initiated jump) and
  specified skip re-ordering (move to tail + cooldown) to avoid livelock
- downgraded SessionEnd to "not yet probed" (probe only saw SessionStart/Stop)
- dropped forked collector's WebSocket layer; most-stuck → oldest-stuck (FIFO)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 15:18:56 -04:00
jedarden
ca08cbbead docs: simplify to flat FIFO dead-letter queue + harness adapter seam
Resolve open questions from the design session:
- Stuck is stuck: no permission-vs-stopped priority; reason is display-only;
  queue is a flat FIFO dead-letter queue (Stop AND PermissionRequest still
  both required — permission blocks emit no Stop)
- Drop Notification entirely
- Auto-advance depletion loop: next stuck session loads on resolve/skip;
  saturation is a non-issue by construction
- New primary open question: harness-coupled detection vs harness-agnostic
  core, via a normalized stuck/unstuck adapter contract (switching is already
  tmux-level/harness-agnostic)
- Reboot: operator re-invokes manually (no auto-resurrection in v1)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 10:20:58 -04:00
jedarden
4784c61e4c docs: rework plan around navigator model + confirmed hook mechanics
Major design update from the design session:
- Human-on-the-loop framing; "stopped = needs attention" axiom
- Navigator-not-relay delivery via tmux (switch/link), resume + remote-control
  ruled out; live-panes (Model A) chosen over transcript-sessions (Model B)
- Daemon + presentation split; tmux-native durability across disconnect, with
  backlog accumulation while detached
- Transcript-as-ground-truth reconcile loop; non-goals; failure modes/invariants
- Probe-confirmed mechanics (2026-05-25): $TMUX_PANE + identity in hook env,
  Stop carries last_assistant_message, both interactive and -p fire hooks

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-25 10:01:17 -04:00
jedarden
7650735f18 docs(readme): frame Trail Boss as human-on-the-loop / dead-letter queue
Emphasize that agents run autonomously and the human is engaged only by
exception — the failure-mode handler / dead-letter-queue processor for a fleet
of agents, not a gate on every step.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 22:56:59 -04:00
jedarden
f5e66b831c Initial commit: Trail Boss design docs
Single-pane attention router for interactive AI coding agents: stuck sessions
surface in one prioritized queue (most-stuck first) via Claude Code hooks, and
your reply is delivered back into the exact session.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-24 22:37:56 -04:00