Commit Graph

72 Commits

Author SHA1 Message Date
Levi Neely bb29ec6de7 Extract Assist to anvillm-acme, move logging to pkg/ 2026-03-20 15:29:06 +01:00
Levi Neely ed43407383 Move sandbox to pkg/ for external import 2026-03-20 15:18:50 +01:00
Levi Neely 2a1d620a31 rename 9P endpoint from 'agent' to 'anvillm'
- Update socket path, MountService calls, path prefixes
- Update mcptools, scripts, docs, diagrams, services
- Fix idleSince initialization at session creation
2026-03-12 12:13:40 +01:00
Levi Neely 46da046fb3 tmux: remove FIFO plumbing, fix per-window metadata
- Remove dead streaming code: reader(), waitForReady(), StartupHandler, pipe-pane
- Switch recovery metadata from session-scoped set-environment to window-scoped set-option -w @key
- Sessions now start in idle state immediately (no startup wait)
2026-03-12 11:47:37 +01:00
Levi Neely 10d25a371a session: reset initialPromptSent when context is set
If context is written after the first mail nudge has already fired,
initialPromptSent was already true and the context would never be
injected. Resetting it on SetContext ensures the context is always
prepended to the next prompt regardless of timing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-07 12:30:21 +01:00
Levi Neely ebc162ac4f crash recovery: reset initialPromptSent and send inbox message
On crash restart:
- Reset initialPromptSent flag so context gets re-injected
- Send 'Continue working.' inbox message from user to session
- Add OnCrashRestart callback to Session struct
2026-03-06 17:27:50 +01:00
Levi Neely b51bbf7e72 working on a different approach for roles 2026-03-06 08:54:44 +01:00
Levi Neely ec880544df fix skill prompt commands 2026-03-05 22:31:21 +01:00
Levi Neely 6475b9f216 Add maildir messaging support for agent communication 2026-03-05 14:33:47 +01:00
Levi Neely c0d09125ca Add backend-specific handlers for clear, compact, resume commands
- Add ClearHandler, CompactHandler, ResumeHandler callbacks to tmux.Config
- kiro-cli: clear/resume need 250ms delay + confirmation key
- claude: clear/compact are simple /command[ENTER], resume not implemented
- Add Resume tag and handler to Assist prompt window
- Update server.go to use new Session methods
2026-03-05 09:41:05 +01:00
Levi Neely e3a63dedd8 tmux backend and p9 server improvements 2026-03-05 09:32:07 +01:00
Levi Neely d0e3ff2cd8 Rename role to sandbox in layered sandbox config
- cfg/roles/ → cfg/sandbox/
- DefaultRole → DefaultSandbox, LoadRole → LoadSandbox
- SessionOptions.Role → Sandbox, Session.Role() → Sandbox()
- p9 file: role → sandbox
- Remove tasks from layered sandbox config
- Update create_session.sh and SKILL.md docs
2026-03-04 13:10:10 +01:00
Levi Neely 2c32295094 fix: inject session context into first prompt only
Context was prepended to every Send() call. Now it is consumed
on the first Send() and cleared, acting as a one-shot spawn
initialization rather than a per-prompt overhead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-01 16:49:22 +01:00
Levi Neely ba5fd04025 fix: make beads mount work with lazy initialization
- Changed NewServer to accept *BeadsFS instead of bd.Storage
- BeadsFS is always created but with no initial mounts
- Each mount opens its own store on-demand
- Added nil check in supervisor to handle missing beads gracefully
2026-03-01 00:47:13 +01:00
Levi Neely cbace3407c Update changes 2026-02-27 12:12:08 +01:00
Levi Neely 2111f19e9f Add zap logging to ~/.config/anvillm/logs with panic recovery
- Created internal/logging package with zap logger
- Added panic recovery to anvilsrv main loop, monitor goroutine, and mail processing
- Replaced log.Printf/Fatal with zap in debug, p9, tmux packages
- Fixed beads race condition: clear assignee before closing issue
- All errors and crashes now logged to ~/.config/anvillm/logs
2026-02-27 11:46:49 +01:00
Levi Neely addcf0a978 Fix crash bugs: remove impossible nil checks, add bounds check for strings.Fields
- mailManager guaranteed non-nil by constructor, removed defensive checks
- Added bounds check for strings.Fields()[0] in slash command validation
- Removed impossible nil check in processMailboxes()
2026-02-26 22:28:16 +01:00
Levi Neely 5bcaa38ad7 cost / usage optimization, phase 1 2026-02-25 19:17:50 +01:00
Levi Neely 572ac91d86 Set CLAUDE_CONFIG_DIR at startup and propagate to tmux/shell/sandbox
- anvilsrv sets CLAUDE_CONFIG_DIR to ~/.config/anvillm/claude on start
  if not already set in the environment
- Claude backend includes CLAUDE_CONFIG_DIR in its Environment map so
  it is set in the tmux session and exported to the shell
- tmux backend now exports all b.cfg.Environment vars to the shell
  (via sendKeys) in addition to setting them in the tmux environment,
  both on CreateSession and Restart
- cfg/backends/claude.yaml adds CLAUDE_CONFIG_DIR to the sandbox env
  whitelist so landrun passes it through to the Claude process

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 11:49:02 +01:00
Levi Neely 060dbef65a Make bot prompt send_message instruction dynamic and compact
Replace hardcoded PROMPT_RESPONSE/subject/to values with dynamic
placeholders so bots derive the correct response type, recipient,
and subject from message context. Also restructure prompt assembly
order so the task instruction appears before the send_message
instruction (context → prompt → outInstruction).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 09:12:13 +01:00
Levi Neely 4b80a279f8 minor fix 2026-02-21 21:05:18 +01:00
Levi Neely 536b358006 Sort session list by creation time (newest first)
Backend changes:
- Add CreatedAt() to Session interface
- Implement CreatedAt() in tmux.Session (field already existed)
- Sort Manager.List() by creation time descending

Benefits:
- Deterministic ordering (no more random map iteration)
- Newest sessions appear first (most useful)
- All clients benefit immediately
- head -1 now reliably gets most recent session

README:
- Update example to use head -1 for newest session
- Document that list is sorted newest first
2026-02-19 23:51:10 +01:00
Levi Neely e1fc56f213 Improve event system: add initial state event and rename exited to killed
- Emit initial state change event (stopped -> starting) when session is created
- Rename 'exited' state to 'killed' for clarity
- Remove duplicate killed event emission (Close() already emits via transitionToLocked)
- Set OnStateChange callback in NewManager to emit state change events
- All state changes now properly emit events via callbacks
2026-02-19 20:29:43 +01:00
Levi Neely 65be761262 Fix event system: wire state changes to OnStateChange and fix /events 9p read
- Wire all state changes in tmux session to use transitionToLocked (triggers OnStateChange)
  - Close() exited state
  - Refresh() stopped states (intentional stop, restart spam prevention, auto-restart failure, PID=0)
- Add event callbacks to mailbox manager for send/receive events
  - Callbacks fire when message removed from outbox (send) and delivered to inbox (receive)
  - Consistent with state change callback pattern
- Fix /events 9p read handler to respect offset/count
  - Prevents infinite read loop by properly signaling EOF
  - Uses readFile() pattern like /list for consistency
2026-02-19 20:18:55 +01:00
Levi Neely 4c79fc796c Add 9P event queue infrastructure
- internal/events: new package with Queue supporting Push/Read/Ack and 2-min TTL
- internal/p9: expose /events file (read returns JSON lines, write accepts ack)
- internal/backend/tmux: add OnStateChange callback to Session
- internal/session: add OnStateChange callback to Manager

No events are emitted yet - infrastructure only.
2026-02-19 18:56:24 +01:00
Levi Neely 97a0a66722 Reload sandbox config on Restart for hot-reload of YAML changes 2026-02-19 16:24:57 +01:00
Levi Neely 3515f51151 Replace all 9p command references with MCP tools
- Updated anvillm-communication skill to use MCP tools
- Changed session.go to instruct agents to use send_message
- Updated manager.go to tell agents to use read_inbox
- Updated Claude hook to mention read_inbox tool
- Cleaner, more consistent interface across all documentation
2026-02-18 21:49:35 +01:00
Levi Neely 75bfd529ca fix build errors 2026-02-18 20:20:58 +01:00
Levi Neely 5399d709c4 Replace PID-based temp files with AGENT_ID env var
- Simplified Claude hooks to use AGENT_ID instead of PID lookup
- Updated 9p-read-inbox to use AGENT_ID env var
- Removed temporary file creation in tmux.go
- Much cleaner and more reliable approach
2026-02-18 20:09:12 +01:00
Levi Neely af206f4304 Add agent system configuration and AGENT_ID support
- Add HOME/prj and HOME/src filesystem mounts to global config
- Add AGENT_ID environment variable support
- Add agent skills and mcpt configuration paths
- Add JENKINS_MCP_AUTH environment variable
- Implement AGENT_ID setup in tmux backend sessions
2026-02-18 16:23:30 +01:00
Levi Neely 937ad83e97 Remove deprecated endpoints and fix mailbox auto-completion
- Fix PROMPT_RESPONSE messages not auto-completing
- Remove deprecated message types (LogInfo, LogError, StatusUpdate)
- Remove entire chat log system (replaced by audit log)
- Migrate user prompts to mailbox system in main.go
- Remove {id}/in and {id}/out 9P endpoints
- Only mail processor uses sess.Send() directly
- Fix file index constants after removing in/out files
- Remove unused SendCtl function
2026-02-17 23:06:07 +01:00
Levi Neely ff2bd372c1 improve send message api 2026-02-17 18:20:01 +01:00
Levi Neely b66e9822a2 Fix attach for new tmux session naming and clean up emacs prompts
Front-ends were constructing anvillm-{backend} but backend now uses
anvillm-{namespace}. Updated Assist and emacs to read tmux target from
the tmux file instead of constructing it from backend name.

Also removed broken direct prompt functionality from emacs (P and M-P
keybindings that used /in file directly).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-17 15:32:48 +01:00
Levi Neely 35b3ff338e Fix 9p-read-inbox to strip .json extension when marking messages complete 2026-02-17 14:37:46 +01:00
Levi Neely 72ffd90bf3 Add Claude hooks integration for AnviLLM
- Created install-claude-hooks.sh to merge hooks into existing settings.json
- Updated mkfile to use merge script instead of overwriting settings.json
- Made agent name configurable via CLAUDE_AGENT_NAME env var
- Added Claude agent configuration and hook scripts
- Removed unused NewClaudeWithContinue/NewClaudeWithResume functions
2026-02-17 10:27:59 +01:00
Levi Neely 50f8cde2ee Remove reserved flag and fix state transitions
- Remove reserved flag and all reservation logic (unnecessary for kiro-cli)
- Fix session ID file creation: detect kiro-cli runs directly in pane
- Add retry loop for FindBackendPID with kiro-cli detection
- Update hooks to use PPID's parent (kiro-cli PID) instead of 15569
- Remove 5-second delay from running->idle transition
- Clean up workflow scripts: remove explicit skill references and communication protocol sections
- Update researcher roles to use knowledge base, web, and codebase
2026-02-16 23:07:35 +01:00
Levi Neely 7dc3e6f4b5 Add state machine verification and error recovery transitions
- Created STATE_MACHINE_VERIFICATION.md documenting all states and transitions
- Added error→idle transition for manual recovery from error state
- Added error→starting transition for restart from error state
- Verified all 21 transition call sites across codebase
2026-02-16 20:46:30 +01:00
Levi Neely 825ce1e415 Implement state machine improvements with reservation system and condition variables 2026-02-16 20:26:50 +01:00
Levi Neely 9ff6262d62 Rename peer-bot skill to anvillm-communication
- Rename skill to reflect broader scope (agent-to-agent, agent-to-user)
- Add AnviLLM references to all workflow agent contexts
- Update README example to use mailbox pattern
- Fix heredoc delimiter conflict (EOF -> MSGEOF) in injected prompt
2026-02-16 15:35:46 +01:00
Levi Neely e95c9ad8cd Simplify idle transition via mailbox
Message to user now triggers idle state automatically.
Removed separate idle signal instruction from prompts.
Single action (send to user) replaces two-step process.
2026-02-16 15:11:39 +01:00
Levi Neely e6766999dc fix: overly aggressive error state detection 2026-02-16 09:33:21 +01:00
Levi Neely 51679e5661 Implement mailbox system for bot-to-bot communication
- Add mailbox manager with inbox/outbox/completed structure
- Expose mailboxes via 9P filesystem (agent/{id}/inbox, outbox, completed)
- Mail processor runs every 5s to deliver messages from outbox to inbox
- Messages delivered when recipient is idle, formatted and sent via in file
- Retry logic: 3 attempts max, then discard with notification to sender
- Race condition fixes: messages moved to completed before sending
- Auto-generate message ID and timestamp if missing from bot's JSON
- Update peer-bot skill to use mailbox system with JSON format
- Update all workflows (DevReview, DevReviewQA, Planning) with:
  - Explicit shell command examples for sending messages
  - plan9 task for all agents
  - Mailbox instructions without markdown code blocks
- Fix idle signaling: bots must write summary to out BEFORE signaling idle
- All messages archived in completed/ with proper metadata
2026-02-15 21:16:00 +01:00
Levi Neely 873f839278 Implement layered sandbox configuration system
- Add global.yaml base config (renamed from sandbox.yaml)
- Add backend-specific configs (claude.yaml, kiro-cli.yaml)
- Add role configs (developer, reviewer, tester, architect, etc.)
- Add task configs (git, docker, go, rust, python, nodejs, etc.)
- Implement config merging: global + backend + role + tasks
- Update workflows to use roles and tasks
- Create tester role with read-only source, execute-only bins
- Fix reviewer role to use rox for bin directories
- Auto-create RW directories that don't exist
- Make backend configs required (fail if missing)
- Update mkfile to install cfg files to ~/.config/anvillm
- Remove Role-Based Sessions from IDEAS.md (now implemented)
2026-02-15 18:57:55 +01:00
Levi Neely 2c0196fbe9 Add idle state signaling and output summary support 2026-02-15 10:57:18 +01:00
Levi Neely a10a70bebd Fix deadlock in agent chat log and improve response tracking
- Add chat log support with new 'log' file (read) and 'out' file (write)
- Fix deadlock: create appendToChatLogLocked for callers holding mutex
- Improve prompts to request comprehensive summaries with actual response text
- Enforce 2MB chat log size limit with smart truncation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 10:20:32 +01:00
Levi Neely bef457a3aa Qualify tmux sessions per-namespace
- Extract namespace suffix (e.g., '0' from '/tmp/ns.user.:0/')
- Append suffix to tmux session names (e.g., 'anvillm-kiro-cli-0')
- Allows multiple namespace instances to coexist without conflicts
- Updated backend constructors to accept namespace suffix parameter
2026-02-14 18:35:35 +01:00
Levi Neely 452fc41ea5 basic self-healing 2026-02-14 17:51:28 +01:00
Levi Neely 4a79985bcf explicit signaling for process states 2026-02-14 14:33:57 +01:00
Levi Neely b7a823f120 feat: split monolith into anvilsrv daemon and Assist client
Major architectural refactoring to separate server and UI concerns:

Architecture Changes:
- Split into anvilsrv (server daemon) and Assist (Acme client)
- Removed UI coupling from server (OnAliasChange, WinID tracking)
- Server runs as background daemon, client reconnects as needed
- Client auto-starts server if not running

Server (anvilsrv):
- Add daemon management: start/stop/status commands
- Daemonize by default (fgstart for foreground/debug mode)
- Proper PID file handling in $NAMESPACE (not /tmp)
- Graceful shutdown with SIGTERM handling
- Duplicate start prevention with stale PID detection

Client (Assist):
- Auto-start anvilsrv if not running
- Fixed plan9 package imports (OWRITE/OREAD constants)
- Removed unused context import

Security Fixes:
- Move PID file from /tmp to $NAMESPACE (prevent symlink attacks)
- Add path validation in session creation:
  - Clean path traversal (/../../../etc → /etc)
  - Verify directory exists before creating session
  - Ensure absolute paths
  - Reject non-directory paths
- Add SECURITY.md documenting 9P socket risks

Service Integration:
- Add systemd service files (system, user, template)
- Add runit service files (run, finish)
- Add service documentation and installation instructions

Build & Testing:
- Both binaries build successfully
- All daemon operations verified (start/stop/status/daemonize)
- Path validation tested and working
- Auto-start functionality verified
- Add DevReviewQA workflow script

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-14 11:30:57 +01:00
Levi Neely c445b21206 fix: Stop now preserves tmux window by tracking backend PID
The Stop() method was destroying the tmux window because it killed the
bash shell (pane PID) instead of just the backend process. This commit
fixes the issue by:

1. Added FindBackendPID() to find the actual backend process (child of bash)
2. Modified session creation to store the backend PID, not the shell PID
3. Updated stopInternal() to kill only the backend process:
   - Send Ctrl+C (handles SIGINT)
   - Send second Ctrl+C if still alive (some CLIs need 2x)
   - Use SIGTERM/SIGKILL on backend PID if unresponsive
   - Never kill the bash shell, preserving the tmux window
4. Fixed Restart() to properly clean up and recreate FIFO

Tested successfully:
- Stop kills backend but preserves window ✓
- Session state transitions to "stopped" ✓
- Restart reuses same window and works ✓
- Can send prompts after restart ✓

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-14 10:28:06 +01:00