Commit Graph

123 Commits

Author SHA1 Message Date
jcfs 0b071782c0 feat: worktrees at agent session level with random suffix
- Branch name format: kandev/{task_id}_{random8chars}
- Worktree path: ~/.kandev/worktrees/{task_id}_{random}/
- Multiple worktrees per task allowed (one per agent session)
- WorktreeID stored in agent instance metadata for session resumption
- Pass WorktreeID in CreateRequest to reuse existing worktree
- OnTaskDeleted removes ALL worktrees for the task
- Added GetByID, GetAllByTaskID, RemoveByID methods
2026-01-12 16:12:34 +00:00
jcfs 3961afc29e feat: cleanup worktree and branch on task deletion
- Add WorktreeCleanup interface to task service
- Call OnTaskDeleted when a task is deleted to remove worktree dir and branch
- Wire worktree manager to task service in main.go

This ensures that when tasks are deleted, their associated worktrees
and git branches (kandev/{task_id}) are properly cleaned up.
2026-01-12 15:56:09 +00:00
jcfs 76e4221312 fix: configure git safe.directory in agent containers
Container runs as root but mounted files are owned by host user.
Git 2.35.2+ rejects this as 'dubious ownership'. Configure git via
environment variables to trust all directories in the container.
2026-01-12 15:48:41 +00:00
jcfs 3c460a694b fix: mount entire .git directory for worktree support in containers
Git worktree metadata in .git/worktrees/{name} has a 'commondir' file
that references back to the parent .git directory (typically '../..').

Mounting just the worktrees subdirectory wasn't sufficient - we need
to mount the entire .git directory so that:
1. The worktree's .git file can resolve to .git/worktrees/{name}
2. The commondir reference can resolve back to the main .git
3. Git objects, refs, and other shared data are accessible
2026-01-12 15:43:42 +00:00
jcfs c5769e9b6a fix: mount git worktree metadata directory into container
Git worktrees store their metadata in the parent repository's
.git/worktrees/{name} directory. The worktree's .git file contains
an absolute path to this directory.

When mounting a worktree into a container, git commands fail because
the .git file references a host path that doesn't exist in the container.

This fix mounts the git worktree metadata directory into the container
at the same path it exists on the host, so git commands work correctly.
2026-01-12 15:34:06 +00:00
jcfs b8eade8c26 fix: wire worktree manager to lifecycle manager for agent isolation
The worktree manager was created but never connected to the lifecycle
manager, so worktrees were never being created when agents launched.
2026-01-12 15:23:19 +00:00
jcfs 19ea7ddc4e feat: expose worktree path and branch in task API and UI
- Add WorktreePath and WorktreeBranch fields to TaskDTO
- Add WorktreeLookup interface to TaskController for enriching task responses
- Add GetWorktreeInfo method to worktree.Manager implementing WorktreeLookup
- Wire worktree manager to task controller in main.go
- Add worktree_path and worktree_branch to frontend Task type
- Display worktree path with copy button in TaskTopBar when worktree exists
- Show worktree branch in tooltip for easy reference
2026-01-12 15:19:11 +00:00
jcfs 20c456dc07 feat: implement Git worktrees for concurrent agent execution
- Add worktree package with Manager, Store, Config, and error types
- Integrate worktree creation/reuse into lifecycle manager
- Update executor to pass worktree configuration
- Add WorktreeConfig to common config package
- Enable worktrees by default for agent isolation
- Add unit tests for worktree manager

This allows multiple agents to work on the same repository simultaneously
by creating isolated worktrees for each task. Worktrees persist between
agent runs for task resumption and are only cleaned up when tasks are
explicitly deleted.
2026-01-12 15:04:16 +00:00
jcfs 8e01191c68 feat: enhance tool call display with payload details and typing indicator
- Add typing indicator in TaskChatPanel that shows when agent is working
- Enhanced ToolCallCard component with expandable details section
- Backend now passes tool call args (kind, path, locations, raw_input) to comments
- Add generateUUID fallback for non-secure contexts (HTTP non-localhost)
- Configure Next.js allowedDevOrigins for cross-origin dev access
- Bind dev server to 0.0.0.0 for network access

Backend changes:
- Extract Kind, Locations, RawInput from ACP ToolCall updates
- Add Args field to ToolCallData in watcher
- Pass args through CommentCreator interface to comment metadata

Frontend changes:
- ToolCallCard shows file path, status icons, expandable args
- getToolIcon matches ACP ToolKind values (read, edit, search, execute)
- Typing indicator with animated dots when awaiting agent response
- Replace crypto.randomUUID with fallback utility across all files
2026-01-12 14:21:26 +00:00
jcfs e012e070a9 fix: recover agent state from Docker on backend restart
- Add Docker reconciliation on lifecycle manager startup to find running containers
- Add container_id field to agent_sessions table for cleanup tracking
- Add GetRecoveredInstances to AgentManagerClient interface
- Sync executor cache with recovered Docker instances on startup
- Add task.execution WebSocket endpoint to check agent running state
- Fix Stop Agent button showing Start Agent after page refresh
- Ensure containers are not leaked when backend restarts
2026-01-12 03:42:54 +00:00
jcfs 3b1c6f14bf fix(backend): filter out internal ACP messages from WebSocket broadcast
Only broadcast message types that the frontend handles (progress, log, result,
error, status, heartbeat, input_required). Skip internal types like session/update.
2026-01-12 02:58:42 +00:00
jcfs ad2a0bd9d0 fix(web): fix real-time comments not appearing on first agent start
- Initialize comments.items array in setCommentsTaskId and addComment
- Fixes race condition where WebSocket notifications arrived before API call completed
2026-01-12 02:57:09 +00:00
jcfs 0ad5082a09 feat(backend): make repository_url optional when launching agents
- Remove validation requiring repository_url in lifecycleAdapter.LaunchAgent
- Skip workspace mounts in lifecycle manager when no workspace path is provided
- Agents can now run without a pre-existing workspace directory
2026-01-12 02:25:49 +00:00
jcfs 14e57bd8e3 Merge remote-tracking branch 'origin/main' into feat/frontend-improvements 2026-01-12 02:20:12 +00:00
João Salavisa 7ac25bfb66 Merge pull request #6 from kdlbs/feat/agent-session-persistence
feat(backend): Persistent Agent Session Tracking
2026-01-12 02:10:45 +00:00
jcfs 5381094bba feat(web): enhance WebSocket handling and chat panel improvements
- Add react-markdown with remark-breaks and remark-gfm for markdown rendering
- Improve WebSocket client with better reconnection handling
- Enhanced task chat panel with markdown support for comments
- Add comment type and metadata support for tool call rendering
- Improve connection status indicator
- Update task page with improved agent controls
- Add WebSocket router for better message handling
- Update state store with enhanced type safety
2026-01-12 02:05:30 +00:00
jcfs 7b3e94d6dc feat(backend): add persistent agent session tracking
- Add AgentSession database entity with SQLite persistence
- Implement AgentSession CRUD operations in repository layer
- Update executor to use hybrid cache + database approach
- Add session restoration on startup (LoadActiveSessionsFromDB)
- Link comments to agent sessions via agent_session_id
- Fix SQLite NULL handling for nullable task fields
- Add dev database setup with seed data (make dev, make dev-db-reset)
- Update Makefile with dev targets for development mode

This enables agent sessions to persist across backend restarts,
solving the 'execution not found' error for resumed conversations.
2026-01-12 02:02:47 +00:00
João Salavisa 00c0a0c529 Merge pull request #5 from kdlbs/feat/unify-ws-pattern-a
refactor: unify WebSocket patterns to Pattern A (handlers + controller + dto)
2026-01-11 22:53:09 +00:00
jcfs 0b8cd401c2 refactor: unify WebSocket patterns to Pattern A (handlers + controller + dto)
- Add missing repository action constants to pkg/websocket/actions.go
- Update repository_handlers.go to use action constants instead of string literals
- Refactor orchestrator module: create dto/, controller/, handlers/ packages
- Refactor agent module: create dto/, controller/, handlers/ packages
- Update main.go and integration tests to use new Pattern A wiring
- Remove old wshandlers/ directories from both modules

All modules now follow the same architecture:
  handlers/    → Parse WS messages, validate, call controller
  controller/  → Business logic coordination, convert to/from DTOs
  dto/         → Centralized request/response Data Transfer Objects
  service/     → Core business logic (unchanged)
2026-01-11 22:51:43 +00:00
Carlos Florêncio 4282d67910 fix: go tests 2026-01-11 22:44:10 +00:00
Carlos Florêncio 58ecd85885 fix: task page 2026-01-11 22:42:31 +00:00
Carlos Florêncio a9047cf823 feat: tasks crud 2026-01-11 22:32:04 +00:00
João Salavisa 4706e3be40 Merge pull request #4 from kdlbs/feat/acp-permission-requests
feat: implement ACP permission request flow
2026-01-11 22:26:10 +00:00
jcfs c1c9dfa2c1 docs: update WEBSOCKET_API.md with complete API reference
- Add Workspace Actions section (workspace.list, create, get, update, delete)
- Add Repository Actions section (repository.*, repository.script.*)
- Add Comment Actions section (comment.add, comment.list)
- Add Permission Actions section (permission.requested, permission.respond)
- Add comment.added notification documentation
- Update Quick Reference table with all actions organized by category
- Document all notification actions (ACP, task, workspace, board, column events)
2026-01-11 22:22:15 +00:00
jcfs fd98328058 chore: remove unused legacy agent.sh
- Remove agent.sh (was never actually used, entrypoint.sh handles both modes)
- Update Dockerfile to remove the copy of agent.sh
2026-01-11 22:15:11 +00:00
jcfs 15cf60edb9 merge: resolve conflicts with main
- Keep both RegisterRepositoryRoutes and RegisterCommentRoutes
- Merge permission actions with repository actions in websocket/actions.go
2026-01-11 22:12:16 +00:00
jcfs 195be5e575 feat: enhance comment system and e2e testing
- Add comment handlers for WebSocket API (comment.add, comment.list)
- Update e2e-test.sh to focus on comment system testing
- Test multi-turn conversation flow (3 turns)
- Display comment content and metadata in test output
- Reduce test timeouts for faster execution
- Fix various orchestrator and lifecycle manager issues
- Add CODE_REVIEW_ISSUES.md documenting known issues
2026-01-11 22:08:00 +00:00
jcfs 6dd0d7ffa4 feat: implement ACP permission request flow
- Add permission stream support to backend agentctl client
  - StreamPermissions() connects to permission WebSocket
  - RespondToPermission() sends responses via HTTP POST
  - PermissionNotification type for permission request data

- Connect lifecycle manager to permission stream
  - handlePermissionStream() receives permission requests
  - publishPermissionRequest() forwards to event bus
  - RespondToPermission() and RespondToPermissionByTaskID() methods

- Add WebSocket handler for permission.respond action
  - Validates task_id, pending_id, option_id
  - Routes response through orchestrator → executor → lifecycle manager

- Add permission WebSocket actions
  - ActionPermissionRequested for notifications
  - ActionPermissionRespond for user responses

- Update executor interface with RespondToPermissionByTaskID()
- Update mock implementations in tests
- Add permission response test to e2e-test.sh
- Fix e2e-test.sh ID extraction (strip newlines)

The full permission flow is now wired up:
agent → agentctl → backend → frontend → user → backend → agentctl → agent

Auto-approve mode is still enabled by default until frontend is ready.
2026-01-11 20:56:50 +00:00
Carlos Florêncio 473b336b13 feat: added repositories support 2026-01-11 19:59:28 +00:00
João Salavisa 00c65268bc Merge pull request #3 from kdlbs/feat/comments-input-request-flow
feat: add bidirectional comment system and agent input request flow
2026-01-11 19:38:54 +00:00
jcfs 0fdf18c37b feat: add bidirectional comment system and agent input request flow
- Add Comment model and CRUD operations (repository, service layers)
- Add WAITING_FOR_INPUT task state for agent input requests
- Add WebSocket actions for comment.add, comment.get, comment.list
- Add ActionCommentAdded and ActionInputRequested notifications
- Update PromptAgent to return PromptResult with stop reason
- Add e2e test for agent input request flow
- Add PR template for the repository

This enables agents to request input from users by returning
stopReason 'needs_input' which transitions the task to
WAITING_FOR_INPUT state and creates an agent comment.
2026-01-11 18:41:52 +00:00
Carlos Florêncio 47a26fcc0e feat: web app support for boards and columns 2026-01-11 18:30:02 +00:00
Carlos Florêncio af6e482c4c feat: web app support for workspaces 2026-01-11 16:28:25 +00:00
Carlos Florêncio 602ce61bc5 feat: clean db command 2026-01-11 15:41:06 +00:00
Carlos Florêncio 609fd4e16d fix: workspace migration 2026-01-11 14:51:01 +00:00
Carlos Florêncio 8579e8ec91 feat: added workspaces 2026-01-11 14:46:01 +00:00
Carlos Florêncio de8c3abb41 feat: ws state 2026-01-11 12:55:50 +00:00
Carlos Florêncio f7c089d8ba feat: ws and zustand init 2026-01-11 12:35:30 +00:00
Carlos Florêncio 6753bfa397 feat: add http handlers to backend 2026-01-11 12:33:10 +00:00
Carlos Florêncio a7f8c767d7 chore: refactored task components 2026-01-11 11:19:34 +00:00
jcfs 6a46eb5a54 feat: implement persistent agent execution logs storage and retrieval
- Add task_agent_execution_logs table schema in SQLite with indexes
- Create SQLiteMessageStore implementing MessageStore interface for persistent ACP message storage
- Add task.logs WebSocket action for retrieving historical logs
- Implement historical log replay on task.subscribe
- Add HistoricalLogsProvider callback to WebSocket Hub

Tests:
- Add comprehensive unit tests for SQLiteMessageStore (29 tests)
- Add integration tests for task.logs and historical replay (3 test suites)
- Enhance e2e-test.sh with historical logs test scenarios (Steps 14-16)

Files:
- apps/backend/internal/orchestrator/acp/sqlite_store.go (new)
- apps/backend/internal/orchestrator/acp/sqlite_store_test.go (new)
- apps/backend/internal/task/repository/sqlite.go (schema)
- apps/backend/internal/gateway/websocket/hub.go (provider)
- apps/backend/internal/gateway/websocket/client.go (replay)
- apps/backend/internal/orchestrator/wshandlers/handlers.go (task.logs)
- apps/backend/cmd/kandev/main.go (wiring)
- scripts/e2e-test.sh (test scenarios)
2026-01-11 01:24:54 +00:00
jcfs 0f0c8edfd2 chore: Run go mod tidy to fix CI 2026-01-11 00:34:26 +00:00
jcfs f91199fa66 test: Add session ID verification to e2e test script
- Add Step 13: Verify Session ID in Task Metadata
- Check that auggie_session_id is present in task metadata after completion
- Update test summary to include session ID verification
2026-01-11 00:31:00 +00:00
jcfs 3b17f2af8d test: Add integration test to verify session_id is stored in task metadata
- Wire session_info ACP handler in test server (mirrors main.go)
- Update TestOrchestratorSessionInfo to verify auggie_session_id is stored
- Test confirms session ID flows from agent → event bus → task metadata
2026-01-11 00:29:54 +00:00
jcfs 35cf080717 fix: Structure session_info event correctly for protocol.Message parsing
The session_id must be in the 'data' field, not at the top level,
so the watcher can parse it into protocol.Message and the handler
can find it at msg.Data["session_id"].
2026-01-11 00:27:01 +00:00
jcfs 1a56148ea7 fix: Publish session_info event so session ID is stored in task metadata
The lifecycle manager now publishes a session_info event after creating
an ACP session. This event is handled in main.go to store the session ID
in the task metadata, enabling session resumption for follow-up tasks.
2026-01-11 00:23:23 +00:00
jcfs 0120b7b6d7 docs: Update AGENTS.md for WebSocket-only architecture
- Replace REST endpoint references with WebSocket actions
- Update message flow diagram to show client → backend → agentctl
- Change agent.* actions to orchestrator.* actions
- Add ACP notification examples
- Update session resumption example with correct endpoint
- Add orchestrator action reference table
2026-01-11 00:10:50 +00:00
jcfs 7dc481e7a7 ci: Add GitHub Actions workflow for backend tests 2026-01-11 00:01:40 +00:00
jcfs 4d0efdc3ed chore: Clean up unused code and placeholder directories
Remove obsolete REST API code and empty placeholder directories:

Removed REST API code:
- apps/backend/internal/agent/api/ (REST handlers)
- apps/backend/internal/orchestrator/api/ (REST handlers)
- apps/backend/internal/orchestrator/streaming/ (REST streaming)
- apps/backend/internal/task/api/ (REST handlers)

Removed obsolete cmd binaries:
- apps/backend/cmd/agent-manager/
- apps/backend/cmd/orchestrator/
- apps/backend/cmd/api-gateway/
- apps/backend/cmd/task-service/
- apps/backend/cmd/agentctl/

Removed empty placeholder directories:
- apps/backend/internal/agent/models/
- apps/backend/internal/agent/monitor/
- apps/backend/internal/common/acp/
- apps/backend/internal/common/auth/
- apps/backend/internal/events/publisher/
- apps/backend/internal/events/subscriber/
- apps/backend/internal/gateway/handlers/
- apps/backend/internal/gateway/middleware/
- apps/backend/internal/gateway/router/
- apps/backend/internal/gateway/streaming/
- apps/backend/pkg/acp/client/
- apps/backend/pkg/acp/server/
- deployments/docker/agents/
- deployments/docker/compose/
- migrations/postgres/
- apps/agentctl/

Fixed:
- Added missing PromptAgent method to mock in scheduler_test.go

All tests pass, build succeeds.
2026-01-10 23:33:38 +00:00
Carlos Florêncio ec0b97ebfb fix: build 2026-01-10 23:17:27 +00:00