f1da9644f4
* feat: add MCP mode pipeline for config vs task tool registration
Thread McpMode field through the entire instance creation chain:
CreateInstanceRequest → InstanceOverrides → InstanceConfig → MCP Server.
This allows config-mode MCP sessions to register a different set of
tools than the default task-mode sessions.
* feat: add config-mode MCP tools and agentctl handlers
Register config-mode tools (workflow steps, agents, MCP config, tasks)
when MCP server mode is "config". Add 16 new WS action constants and
agentctl-side handlers that forward tool calls to the backend via the
existing BackendClient channel.
* feat: add backend MCP handlers for config-mode operations
Add backend WebSocket handlers for workflow step CRUD, agent CRUD,
MCP config get/update, and task move/delete/archive/state operations.
Wire config dependencies via SetConfigDeps pattern to avoid breaking
the existing NewHandlers constructor.
* feat: add config-mode system prompt and unit tests
Add ConfigContext system prompt listing all config-mode MCP tools.
Add unit tests for mode-based tool registration, agentctl config
handler forwarding, backend handler validation, and system prompt
content.
* test: add exhaustive E2E tests for config-mode MCP handlers
38 end-to-end tests covering the full handler → service → DB pipeline
for all 16 config-mode operations: workflow step CRUD, agent CRUD,
agent profiles, MCP config, and task management (move, delete, archive,
update state). Includes handler registration verification and two
full pipeline integration tests.
* fix: remove E2E test that depends on agent CLIs installed in CI
TestE2E_Agent_CreateMultipleAndList tried to create claude-code and
codex agents, which aren't available in CI. Agents are unique by type
ID so creating duplicates also fails. Removed the test since
CreateAndList already validates the create+list flow.
* test: remove Go E2E tests for config-mode handlers
Replacing with Playwright E2E tests.
* test: add Playwright E2E tests for config-mode features
13 tests covering workflow steps, task operations, agent/profile
settings pages, MCP config, and workflow settings round-trips.
* feat: add dynamic MCP mode reconfiguration for agentctl instances
Add SetMode() to the MCP server that clears and re-registers tools for
the new mode. Expose it via PUT /api/v1/mcp/mode on per-instance servers,
a SetMcpMode client method, and a lifecycle Manager.SetMcpMode wrapper.
This enables switching from task to config MCP tools on workspaces that
were prepared before plan_mode was set on the session.
* feat: wire McpMode through executor launch and resume pipelines
Add McpMode to LaunchOptions so callers can set it at launch time.
StartTask and StartTaskWithSession now pass McpMode="config" when
plan mode is active. startAgentOnExistingWorkspace reconfigures the
MCP server via SetMcpMode before starting the agent subprocess.
The AgentManagerClient interface gains SetMcpMode; the lifecycle
adapter, executor, and all mock implementations are updated.
* fix: pass plan_mode from workflow step when auto-starting moved tasks
handleTaskMovedNoSession was hardcoding planMode=false when calling
StartTask. Now it loads the target step and checks for enable_plan_mode
in on_enter actions, passing the correct value so config-mode MCP tools
are registered for the agent.
* test: fix config-mode E2E tests and add SetMcpMode mock stubs
- Add SetMcpMode stubs to all AgentManager mock implementations
- Fix strict mode violations with { exact: true } on tool name assertions
- Expand collapsed tool call groups before asserting individual names
- Remove temporary diagnostic code
* fix: address CodeRabbit review comments
- Add servers parameter to update_mcp_config tool schema
- Add mutex protection to SetMode for thread safety
- Create session before building prompt so config context has session ID
- Fix inconsistent ask_user_question tool name reference (use _kandev suffix)
* refactor: use canonical ws.ActionMCP constants and handle marshal errors
- Import ActionMCP* constants from pkg/websocket instead of duplicating
them locally in config_handlers.go and handlers.go
- Handle json.MarshalIndent error in forwardToBackend instead of ignoring it
* fix: extract McpModeConfig constant and fix Prettier formatting
- Add McpModeConfig constant to avoid repeated "config" string (goconst)
- Fix Prettier formatting in config-management E2E spec
* fix: validate task state before update and strengthen sysprompt tests
- Add TaskState validation in handleUpdateTaskState to return proper
validation error instead of internal error for invalid states
- Strengthen format-contract assertions (exact %s counts, no %! markers)
- Extract repeated test data into constants per project guidelines
* refactor: decouple config MCP mode from plan_mode, use session metadata
Replace plan_mode-based config MCP activation with config_mode in
session metadata. Add isConfigModeSession() helper used across
executor_execute, executor_interaction, and executor_resume.
Propagate task.Metadata to session.Metadata in PrepareSession so
config_mode flows from task creation through to the agent launch.
* refactor: remove task tools from config MCP mode and update sysprompt
Remove task management tools (list_tasks, move_task, delete_task,
archive_task) from ModeConfig registration — they remain available in
ModeTask. Update ConfigContext system prompt to remove task tool docs
and add example requests section. Update MCP server tests for new tool
count (18→14) and remove deleted task handler tests.
* feat: add config-chat endpoint and workspace config agent profile
Add default_config_agent_profile_id column to workspaces with SQLite
migration. Add POST /workspaces/:id/config-chat endpoint that creates
an ephemeral task with config_mode metadata and starts a session with
config MCP tools. Extract resolveConfigChatDefaults helper to stay
within lint complexity limits.
* feat: add config chat UI with workspace settings integration
Add config chat modal component and hook for starting config sessions.
Add configChat state slice with open/close actions. Add workspace API
client for config-chat endpoint. Add configuration agent profile
selector to workspace settings form. Add config chat button to
settings layout sidebar.
* test: rewrite config-mode E2E tests to use metadata and session_id
Rewrite config-management E2E tests to use createTaskWithAgent with
config_mode metadata instead of a custom fetch helper. Fix navigation
to use task.session_id instead of task.id. Add metadata parameter
support to ApiClient.createTaskWithAgent.
* fix: use floating FAB for config chat and pass default agent profile
Move config chat button from header to a floating action button in the
bottom-right corner with a sparkles icon. Pass the workspace's default
agent profile ID when opening the config chat to avoid "no agent
profile configured" error. Add default_config_agent_profile_id to
workspace slice type.
* feat: async agent launch for config-chat and extract helpers
The config-chat endpoint now launches the agent asynchronously when a
prompt is provided, matching the start_agent flow used by task creation.
Extract deleteTaskOnError and launchConfigChatAgent helpers. Remove
LaunchWorkspace from prepare step to avoid blocking.
* feat: first-interaction agent profile selection for config chat
Open the config chat modal immediately on FAB click. If no default
config agent profile is set, the empty state now shows a profile
selector before starting. The selected profile is saved as the
workspace default_config_agent_profile_id for future sessions.
* test: fix config E2E tests — remove duplicate method, use real tools
Remove duplicate startConfigChat method in ApiClient that overrode the
correct 3-param signature. Replace invalid create_agent test (requires
registered agent type) with update_agent test. Remove fragile tool calls
group UI assertion from multi-tool test.
* fix: resolve 'no active session' error in config chat
Add openConfigChatModal action that only sets isOpen and workspaceId
without touching sessionId. Previously, open() called openConfigChat
with empty sessionId which was truthy, causing QuickChatContent to
render with an invalid session.
* feat: add minimal toolbar mode for config chat input
Thread minimalToolbar prop through ChatInputArea → ChatInputContainer →
ChatInputBody → ChatInputToolbar → QuickChatContent. When enabled,
renders only the submit/cancel button, hiding plan toggle, MCP
indicator, context popover, model selector, and other controls.
* feat: replace config chat dialog with floating popover panel
Replace Dialog with Popover from @kandev/ui so the config chat floats
up from the FAB button. Reduce FAB size to h-12/w-12 with larger h-7/w-7
icon. Rename tooltip to "Configuration Chat". Remove standalone
ConfigChatFAB component from settings layout.
* feat: filter config chat tasks from quick chat listing
Add exclude_config query parameter to ListTasksByWorkspace that filters
out tasks with metadata.config_mode=true. Apply it in the quick chat
sessions API call to prevent config chat tasks from appearing as tabs.
* refactor: move config agent profile setting to agents page
Remove the Configuration Agent Profile selector from workspace settings
and add a dedicated ConfigChatAgentSection to the agents settings page
with auto-save on change.
* feat: redesign config chat empty state with inline text input
Replace clickable template buttons with subtle suggestion hints that
fill the textarea on click and disappear once the user starts typing.
Add a persistent Textarea + send button at the bottom so users can
type directly without clicking templates. This prevents the "no active
session" error since QuickChatContent only renders after startSession
succeeds.
* fix: config chat UX polish — non-clickable suggestions, profile persistence
- Make suggestion prompts purely visual (non-interactive text hints)
- Update workspace store after saving config agent profile so the
profile selector doesn't reappear on subsequent opens
- Use useAppStoreApi for store access in callbacks
* fix: add inline error display and prevent accidental popover dismiss
- Show API errors inline below the input instead of via toast (which
can be hidden behind the popover)
- Prevent popover from closing on outside click via onInteractOutside,
so the user doesn't lose their typed input or active session
- Surface error state from useConfigChat hook to the empty state UI
* fix: use config-specific placeholder in config chat input
Add placeholderOverride prop through ChatInputArea and QuickChatContent
so the config chat shows "Ask anything about your configuration..."
instead of the default "Continue working on the task..." placeholder.
* feat: add default_config_agent_profile_id to workspace DTO and API
Wire the field through WorkspaceDTO, FromWorkspace(), HTTP/WS request
structs, service layer, and public API types so the config chat default
profile persists across page reloads and SSR hydration.
* feat: add config chat store actions and prompt delivery via WS
Add configChat slice actions (open, close, rename, tab management),
pendingPrompt state in useConfigChat hook, and initialPrompt support
in QuickChatContent so prompts are delivered via WS after subscription
is established rather than via HTTP (avoiding race condition).
* fix: resolve dual store issue and message fetch race condition
Replace StateProvider with StateHydrator in settings layout to prevent
a shadow Zustand store that intercepted WS events. Fix message fetch
race condition by merging WS-delivered messages with fetch results
instead of replacing them.
* feat: make config chat global with command panel integration
Add ConfigChatProvider at root layout so the popover is available on all
pages. FAB button only visible on settings pages; hidden anchor on other
pages for popover positioning. Add "Configuration Chat" command to the
command panel (Cmd+K). Add close button and header bar to the popover.
* test: add E2E tests for config chat popover and command panel
Add tests for opening config chat via FAB on settings page (with full
agent response flow) and opening via command panel on kanban page.
Fix api-client endpoint and add workspace update fields for E2E setup.
* fix: compress props destructuring to satisfy max-lines-per-function lint
Rebase merged both sides' additions into ChatInputEditorArea and
ChatInputToolbar, pushing them over the 100-line function limit.
Use object parameter with compact destructuring to reduce line count.
* fix: register config task tools and add exhaustive E2E coverage
Config-mode MCP task tools (list_tasks, move_task, delete_task,
archive_task) were defined but never registered — registerConfigTaskTools()
was never called in registerTools(). Fixed the registration and expanded
E2E tests from 5 to 15, covering all testable config-mode MCP tools
(workflow, agent, MCP config, and task management) with API-side
verification of side effects.
* feat: replace create/delete agent with create/delete agent profile in config mode
Agent creation/deletion via MCP isn't practical since agents map to
registered types. Replace with create_agent_profile and
delete_agent_profile tools that manage the per-agent configuration
presets users actually need to work with. Wires full chain: agentctl
MCP tools → WS actions → backend handlers → controller layer.
* chore: fix Prettier formatting
* fix: compress props destructuring to satisfy max-lines-per-function lint
* test: update MCP tests for agent profile tools and correct config tool count
* fix: address CodeRabbit review — normalize MCP mode, set default, consolidate tests
* fix: address CodeRabbit review — error leaks, search filter bug, stale prompt, sysprompt tools
* feat: expose all workflow step fields in config-mode MCP tools
* feat: add workflow CRUD to config-mode MCP tools
* fix: split workflow CRUD E2E test into separate tests
* fix: prevent cascade deletion of config session in delete workflow E2E test
The config-chat endpoint picks the newest workflow (ORDER BY created_at
DESC) for the ephemeral task. When the test created a deletable workflow
right before starting the config session, the session's own task landed
under that workflow. Deleting the workflow then cascaded and wiped the
running session's task, causing the MCP tool call to hang.
Add a "Config Anchor" bumper workflow so the config session uses it
instead of the deletable one.
* feat: add executor management to config-mode MCP tools
Add 8 new MCP tools for executor and executor profile CRUD in config
mode: list/create/update/delete for both executors and profiles.
Wired through the full stack (WS actions, backend handlers, agentctl
tools, sysprompt) with unit tests and E2E coverage.
* fix: auto-focus config chat input and rename popover title
* fix: remove executor CRUD MCP tools, keep executor profile management
Executors are pre-defined system entities (local, worktree, docker,
sprites). Only executor profiles should be managed via config chat.
Removes create_executor, update_executor, delete_executor MCP tools
while keeping list_executors and all executor profile tools.
* fix: add realtime UI sync for workflow steps and agent profiles via MCP
Workflow step and agent profile changes made through the config chat
MCP tools were not broadcasting events to the frontend. Executor
profile events worked because they went through the task service which
has event bus integration.
- Add WorkflowStep and AgentProfile event types to the event bus
- Add WS notification action constants for workflow step events
- Publish events from MCP handlers after step/profile CRUD operations
- Register gateway subscriptions for the new event types
- Add frontend WS handlers for workflow.step.created/updated/deleted
* fix: reuse existing config chat session when opened from command panel
The command panel always called openConfigChatModal() which reset the
session state, causing the profile picker to show again. Now it checks
for an existing active session first, matching the FAB behavior.
* fix: suppress FAB tooltip while config chat popover is open
When closing the popover via the X button, the mouse ends up over the
FAB area and the tooltip re-appears. Force the tooltip closed while
the popover is open so it cannot re-trigger on close.
* fix: thread default_config_agent_profile_id through all workspace data paths
The field was defined on the workspace type but never populated in:
- SSR mapper (page.tsx) — missing from initial hydration
- WS workspace handlers — wiped on workspace.created/updated events
- Backend publishWorkspaceEvent — not included in event data
This caused the config chat to always show the profile picker when
opened from the command panel, since the saved default was lost.
* fix: address PR review comments — workspace sync, type fixes, missing tool doc
- Sync configChat.workspaceId when promoting next tab in closeConfigChatSession
- Add update_task_state_kandev to ConfigContext system prompt
- Fix workflow step WS event types (workflow.step.* instead of step.*)
- Fix const reassignment in E2E tests (const → let)
* refactor: clean up dead code and register missing MCP tools
- Register update_task_state, delete_workflow_step, and
reorder_workflow_steps as MCP tools in agentctl config mode
- Remove dead handleCreateAgent/handleDeleteAgent WS handlers
and their ActionMCP constants (only profiles are managed)
- Rename openConfigChatModal to startNewConfigChat across frontend
- Update sysprompt, tests, and tool counts
* fix: remove extra next.config.ts machine
* fix: address CI failures — prettier formatting and funlen split
* fix: address coderabbit review comments across config-mode stack
- Include prompt field in workflow step broadcast payloads
- Align sysprompt task-state values with actual backend enum
- Return error instead of continuing when MCP mode switch fails
- Validate mode values in agentctl set-mcp-mode endpoint
- Use errors.Is() for sentinel error comparison
- Fix nullish coalescing to allow clearing config agent profile
- Expand StepPayload type with missing config-step fields
- Derive config agent Select value from store instead of local state
* fix: reuse persisted config chat session and reduce toolbar complexity
- Look up configChat.sessions for workspace before creating new session
- Extract MinimalToolbar and move defaults to module-level object to
reduce ChatInputToolbar cyclomatic complexity from 16 to 7
* fix: E2E executor test strict mode violation and invalid cleanup
- Use exact match for list_executors text to avoid matching 2 elements
- Remove cleanup that tried to delete pre-existing system executor
- Reuse persisted config chat session for workspace in global commands
- Reduce ChatInputToolbar cyclomatic complexity with module-level defaults
683 lines
26 KiB
Go
683 lines
26 KiB
Go
package dto
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/kandev/kandev/internal/task/models"
|
|
"github.com/kandev/kandev/internal/task/service"
|
|
v1 "github.com/kandev/kandev/pkg/api/v1"
|
|
)
|
|
|
|
type WorkflowDTO struct {
|
|
ID string `json:"id"`
|
|
WorkspaceID string `json:"workspace_id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type WorkspaceDTO struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Description *string `json:"description,omitempty"`
|
|
OwnerID string `json:"owner_id"`
|
|
DefaultExecutorID *string `json:"default_executor_id,omitempty"`
|
|
DefaultEnvironmentID *string `json:"default_environment_id,omitempty"`
|
|
DefaultAgentProfileID *string `json:"default_agent_profile_id,omitempty"`
|
|
DefaultConfigAgentProfileID *string `json:"default_config_agent_profile_id,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type RepositoryDTO struct {
|
|
ID string `json:"id"`
|
|
WorkspaceID string `json:"workspace_id"`
|
|
Name string `json:"name"`
|
|
SourceType string `json:"source_type"`
|
|
LocalPath string `json:"local_path"`
|
|
Provider string `json:"provider"`
|
|
ProviderRepoID string `json:"provider_repo_id"`
|
|
ProviderOwner string `json:"provider_owner"`
|
|
ProviderName string `json:"provider_name"`
|
|
DefaultBranch string `json:"default_branch"`
|
|
WorktreeBranchPrefix string `json:"worktree_branch_prefix"`
|
|
PullBeforeWorktree bool `json:"pull_before_worktree"`
|
|
SetupScript string `json:"setup_script"`
|
|
CleanupScript string `json:"cleanup_script"`
|
|
DevScript string `json:"dev_script"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Scripts []RepositoryScriptDTO `json:"scripts,omitempty"`
|
|
}
|
|
|
|
type RepositoryScriptDTO struct {
|
|
ID string `json:"id"`
|
|
RepositoryID string `json:"repository_id"`
|
|
Name string `json:"name"`
|
|
Command string `json:"command"`
|
|
Position int `json:"position"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ExecutorDTO struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Type models.ExecutorType `json:"type"`
|
|
Status models.ExecutorStatus `json:"status"`
|
|
IsSystem bool `json:"is_system"`
|
|
Resumable bool `json:"resumable"`
|
|
Config map[string]string `json:"config,omitempty"`
|
|
Profiles []ExecutorProfileDTO `json:"profiles,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ExecutorProfileDTO struct {
|
|
ID string `json:"id"`
|
|
ExecutorID string `json:"executor_id"`
|
|
ExecutorType string `json:"executor_type,omitempty"`
|
|
ExecutorName string `json:"executor_name,omitempty"`
|
|
Name string `json:"name"`
|
|
McpPolicy string `json:"mcp_policy,omitempty"`
|
|
Config map[string]string `json:"config,omitempty"`
|
|
PrepareScript string `json:"prepare_script"`
|
|
CleanupScript string `json:"cleanup_script"`
|
|
EnvVars []models.ProfileEnvVar `json:"env_vars,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type ListExecutorProfilesResponse struct {
|
|
Profiles []ExecutorProfileDTO `json:"profiles"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type EnvironmentDTO struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
Kind models.EnvironmentKind `json:"kind"`
|
|
IsSystem bool `json:"is_system"`
|
|
WorktreeRoot string `json:"worktree_root,omitempty"`
|
|
ImageTag string `json:"image_tag,omitempty"`
|
|
Dockerfile string `json:"dockerfile,omitempty"`
|
|
BuildConfig map[string]string `json:"build_config,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type TaskDTO struct {
|
|
ID string `json:"id"`
|
|
WorkspaceID string `json:"workspace_id"`
|
|
WorkflowID string `json:"workflow_id"`
|
|
WorkflowStepID string `json:"workflow_step_id"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
State v1.TaskState `json:"state"`
|
|
Priority int `json:"priority"`
|
|
Repositories []TaskRepositoryDTO `json:"repositories,omitempty"`
|
|
Position int `json:"position"`
|
|
PrimarySessionID *string `json:"primary_session_id,omitempty"`
|
|
SessionCount *int `json:"session_count,omitempty"`
|
|
ReviewStatus *string `json:"review_status,omitempty"`
|
|
PrimaryExecutorID *string `json:"primary_executor_id,omitempty"`
|
|
PrimaryExecutorType *string `json:"primary_executor_type,omitempty"`
|
|
PrimaryExecutorName *string `json:"primary_executor_name,omitempty"`
|
|
PrimaryAgentName *string `json:"primary_agent_name,omitempty"`
|
|
PrimaryWorkingDirectory *string `json:"primary_working_directory,omitempty"`
|
|
PrimarySessionState *string `json:"primary_session_state,omitempty"`
|
|
IsRemoteExecutor bool `json:"is_remote_executor,omitempty"`
|
|
ArchivedAt *time.Time `json:"archived_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
}
|
|
|
|
type TaskRepositoryDTO struct {
|
|
ID string `json:"id"`
|
|
TaskID string `json:"task_id"`
|
|
RepositoryID string `json:"repository_id"`
|
|
BaseBranch string `json:"base_branch"`
|
|
Position int `json:"position"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type TaskSessionDTO struct {
|
|
ID string `json:"id"`
|
|
TaskID string `json:"task_id"`
|
|
AgentExecutionID string `json:"agent_execution_id,omitempty"`
|
|
ContainerID string `json:"container_id,omitempty"`
|
|
AgentProfileID string `json:"agent_profile_id,omitempty"`
|
|
ExecutorID string `json:"executor_id,omitempty"`
|
|
EnvironmentID string `json:"environment_id,omitempty"`
|
|
RepositoryID string `json:"repository_id,omitempty"`
|
|
BaseBranch string `json:"base_branch,omitempty"`
|
|
BaseCommitSHA string `json:"base_commit_sha,omitempty"`
|
|
WorktreeID string `json:"worktree_id,omitempty"`
|
|
WorktreePath string `json:"worktree_path,omitempty"`
|
|
WorktreeBranch string `json:"worktree_branch,omitempty"`
|
|
State models.TaskSessionState `json:"state"`
|
|
ErrorMessage string `json:"error_message,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
AgentProfileSnapshot map[string]interface{} `json:"agent_profile_snapshot,omitempty"`
|
|
ExecutorSnapshot map[string]interface{} `json:"executor_snapshot,omitempty"`
|
|
EnvironmentSnapshot map[string]interface{} `json:"environment_snapshot,omitempty"`
|
|
RepositorySnapshot map[string]interface{} `json:"repository_snapshot,omitempty"`
|
|
StartedAt time.Time `json:"started_at"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
// Workflow fields
|
|
IsPrimary bool `json:"is_primary"`
|
|
IsPassthrough bool `json:"is_passthrough"`
|
|
WorkflowStepID *string `json:"workflow_step_id,omitempty"`
|
|
ReviewStatus *string `json:"review_status,omitempty"`
|
|
}
|
|
|
|
// TaskSessionSummaryDTO is a lightweight version of TaskSessionDTO without snapshot fields.
|
|
// Used for list endpoints where snapshots are not needed, reducing response size by ~40-60%.
|
|
type TaskSessionSummaryDTO struct {
|
|
ID string `json:"id"`
|
|
TaskID string `json:"task_id"`
|
|
AgentExecutionID string `json:"agent_execution_id,omitempty"`
|
|
ContainerID string `json:"container_id,omitempty"`
|
|
AgentProfileID string `json:"agent_profile_id,omitempty"`
|
|
ExecutorID string `json:"executor_id,omitempty"`
|
|
EnvironmentID string `json:"environment_id,omitempty"`
|
|
RepositoryID string `json:"repository_id,omitempty"`
|
|
BaseBranch string `json:"base_branch,omitempty"`
|
|
BaseCommitSHA string `json:"base_commit_sha,omitempty"`
|
|
WorktreeID string `json:"worktree_id,omitempty"`
|
|
WorktreePath string `json:"worktree_path,omitempty"`
|
|
WorktreeBranch string `json:"worktree_branch,omitempty"`
|
|
State models.TaskSessionState `json:"state"`
|
|
ErrorMessage string `json:"error_message,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
StartedAt time.Time `json:"started_at"`
|
|
CompletedAt *time.Time `json:"completed_at,omitempty"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
IsPrimary bool `json:"is_primary"`
|
|
IsPassthrough bool `json:"is_passthrough"`
|
|
WorkflowStepID *string `json:"workflow_step_id,omitempty"`
|
|
ReviewStatus *string `json:"review_status,omitempty"`
|
|
}
|
|
|
|
// ListTaskSessionSummariesResponse is the list response using summary DTOs.
|
|
type ListTaskSessionSummariesResponse struct {
|
|
Sessions []TaskSessionSummaryDTO `json:"sessions"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type GetTaskSessionResponse struct {
|
|
Session TaskSessionDTO `json:"session"`
|
|
}
|
|
|
|
type ListTaskSessionsResponse struct {
|
|
Sessions []TaskSessionDTO `json:"sessions"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type WorkflowSnapshotDTO struct {
|
|
Workflow WorkflowDTO `json:"workflow"`
|
|
Steps []WorkflowStepDTO `json:"steps"`
|
|
Tasks []TaskDTO `json:"tasks"`
|
|
}
|
|
|
|
type ListMessagesResponse struct {
|
|
Messages []*v1.Message `json:"messages"`
|
|
Total int `json:"total"`
|
|
HasMore bool `json:"has_more"`
|
|
Cursor string `json:"cursor"`
|
|
}
|
|
|
|
type TurnDTO struct {
|
|
ID string `json:"id"`
|
|
SessionID string `json:"session_id"`
|
|
TaskID string `json:"task_id"`
|
|
StartedAt string `json:"started_at"`
|
|
CompletedAt *string `json:"completed_at,omitempty"`
|
|
Metadata map[string]interface{} `json:"metadata,omitempty"`
|
|
CreatedAt string `json:"created_at"`
|
|
UpdatedAt string `json:"updated_at"`
|
|
}
|
|
|
|
type ListTurnsResponse struct {
|
|
Turns []TurnDTO `json:"turns"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type ListWorkflowsResponse struct {
|
|
Workflows []WorkflowDTO `json:"workflows"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type ListWorkspacesResponse struct {
|
|
Workspaces []WorkspaceDTO `json:"workspaces"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type ListRepositoriesResponse struct {
|
|
Repositories []RepositoryDTO `json:"repositories"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type ListRepositoryScriptsResponse struct {
|
|
Scripts []RepositoryScriptDTO `json:"scripts"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type ListExecutorsResponse struct {
|
|
Executors []ExecutorDTO `json:"executors"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type ListEnvironmentsResponse struct {
|
|
Environments []EnvironmentDTO `json:"environments"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type BranchDTO struct {
|
|
Name string `json:"name"`
|
|
Type string `json:"type"` // "local" or "remote"
|
|
Remote string `json:"remote"` // remote name (e.g., "origin") for remote branches
|
|
}
|
|
|
|
type RepositoryBranchesResponse struct {
|
|
Branches []BranchDTO `json:"branches"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type LocalRepositoryDTO struct {
|
|
Path string `json:"path"`
|
|
Name string `json:"name"`
|
|
DefaultBranch string `json:"default_branch,omitempty"`
|
|
}
|
|
|
|
type RepositoryDiscoveryResponse struct {
|
|
Roots []string `json:"roots"`
|
|
Repositories []LocalRepositoryDTO `json:"repositories"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type RepositoryPathValidationResponse struct {
|
|
Path string `json:"path"`
|
|
Exists bool `json:"exists"`
|
|
IsGitRepo bool `json:"is_git"`
|
|
Allowed bool `json:"allowed"`
|
|
DefaultBranch string `json:"default_branch,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
}
|
|
|
|
type ListTasksResponse struct {
|
|
Tasks []TaskDTO `json:"tasks"`
|
|
Total int `json:"total"`
|
|
}
|
|
|
|
type SuccessResponse struct {
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func FromWorkflow(workflow *models.Workflow) WorkflowDTO {
|
|
var description *string
|
|
if workflow.Description != "" {
|
|
description = &workflow.Description
|
|
}
|
|
|
|
return WorkflowDTO{
|
|
ID: workflow.ID,
|
|
WorkspaceID: workflow.WorkspaceID,
|
|
Name: workflow.Name,
|
|
Description: description,
|
|
CreatedAt: workflow.CreatedAt,
|
|
UpdatedAt: workflow.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func FromWorkspace(workspace *models.Workspace) WorkspaceDTO {
|
|
var description *string
|
|
if workspace.Description != "" {
|
|
description = &workspace.Description
|
|
}
|
|
|
|
return WorkspaceDTO{
|
|
ID: workspace.ID,
|
|
Name: workspace.Name,
|
|
Description: description,
|
|
OwnerID: workspace.OwnerID,
|
|
DefaultExecutorID: workspace.DefaultExecutorID,
|
|
DefaultEnvironmentID: workspace.DefaultEnvironmentID,
|
|
DefaultAgentProfileID: workspace.DefaultAgentProfileID,
|
|
DefaultConfigAgentProfileID: workspace.DefaultConfigAgentProfileID,
|
|
CreatedAt: workspace.CreatedAt,
|
|
UpdatedAt: workspace.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func FromRepository(repository *models.Repository) RepositoryDTO {
|
|
return RepositoryDTO{
|
|
ID: repository.ID,
|
|
WorkspaceID: repository.WorkspaceID,
|
|
Name: repository.Name,
|
|
SourceType: repository.SourceType,
|
|
LocalPath: repository.LocalPath,
|
|
Provider: repository.Provider,
|
|
ProviderRepoID: repository.ProviderRepoID,
|
|
ProviderOwner: repository.ProviderOwner,
|
|
ProviderName: repository.ProviderName,
|
|
DefaultBranch: repository.DefaultBranch,
|
|
WorktreeBranchPrefix: repository.WorktreeBranchPrefix,
|
|
PullBeforeWorktree: repository.PullBeforeWorktree,
|
|
SetupScript: repository.SetupScript,
|
|
CleanupScript: repository.CleanupScript,
|
|
DevScript: repository.DevScript,
|
|
CreatedAt: repository.CreatedAt,
|
|
UpdatedAt: repository.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func FromRepositoryScript(script *models.RepositoryScript) RepositoryScriptDTO {
|
|
return RepositoryScriptDTO{
|
|
ID: script.ID,
|
|
RepositoryID: script.RepositoryID,
|
|
Name: script.Name,
|
|
Command: script.Command,
|
|
Position: script.Position,
|
|
CreatedAt: script.CreatedAt,
|
|
UpdatedAt: script.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func FromExecutor(executor *models.Executor) ExecutorDTO {
|
|
return ExecutorDTO{
|
|
ID: executor.ID,
|
|
Name: executor.Name,
|
|
Type: executor.Type,
|
|
Status: executor.Status,
|
|
IsSystem: executor.IsSystem,
|
|
Resumable: executor.Resumable,
|
|
Config: executor.Config,
|
|
CreatedAt: executor.CreatedAt,
|
|
UpdatedAt: executor.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func FromExecutorProfile(profile *models.ExecutorProfile) ExecutorProfileDTO {
|
|
return ExecutorProfileDTO{
|
|
ID: profile.ID,
|
|
ExecutorID: profile.ExecutorID,
|
|
Name: profile.Name,
|
|
McpPolicy: profile.McpPolicy,
|
|
Config: profile.Config,
|
|
PrepareScript: profile.PrepareScript,
|
|
CleanupScript: profile.CleanupScript,
|
|
EnvVars: profile.EnvVars,
|
|
CreatedAt: profile.CreatedAt,
|
|
UpdatedAt: profile.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// FromExecutorProfileWithExecutor converts an ExecutorProfile model to a DTO
|
|
// with executor type and name populated.
|
|
func FromExecutorProfileWithExecutor(profile *models.ExecutorProfile, executor *models.Executor) ExecutorProfileDTO {
|
|
d := FromExecutorProfile(profile)
|
|
if executor != nil {
|
|
d.ExecutorType = string(executor.Type)
|
|
d.ExecutorName = executor.Name
|
|
}
|
|
return d
|
|
}
|
|
|
|
func FromEnvironment(environment *models.Environment) EnvironmentDTO {
|
|
return EnvironmentDTO{
|
|
ID: environment.ID,
|
|
Name: environment.Name,
|
|
Kind: environment.Kind,
|
|
IsSystem: environment.IsSystem,
|
|
WorktreeRoot: environment.WorktreeRoot,
|
|
ImageTag: environment.ImageTag,
|
|
Dockerfile: environment.Dockerfile,
|
|
BuildConfig: environment.BuildConfig,
|
|
CreatedAt: environment.CreatedAt,
|
|
UpdatedAt: environment.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
func FromLocalRepository(repo service.LocalRepository) LocalRepositoryDTO {
|
|
return LocalRepositoryDTO{
|
|
Path: repo.Path,
|
|
Name: repo.Name,
|
|
DefaultBranch: repo.DefaultBranch,
|
|
}
|
|
}
|
|
|
|
func FromTask(task *models.Task) TaskDTO {
|
|
return FromTaskWithPrimarySession(task, nil)
|
|
}
|
|
|
|
// FromTaskWithPrimarySession converts a task model to a TaskDTO, including the primary session ID.
|
|
func FromTaskWithPrimarySession(task *models.Task, primarySessionID *string) TaskDTO {
|
|
return FromTaskWithSessionInfo(task, primarySessionID, nil, nil, nil, nil, nil, nil, nil, nil)
|
|
}
|
|
|
|
// FromTaskWithSessionInfo converts a task model to a TaskDTO, including session information.
|
|
func FromTaskWithSessionInfo(
|
|
task *models.Task,
|
|
primarySessionID *string,
|
|
sessionCount *int,
|
|
reviewStatus *string,
|
|
primaryExecutorID *string,
|
|
primaryExecutorType *string,
|
|
primaryExecutorName *string,
|
|
primaryAgentName *string,
|
|
primaryWorkingDirectory *string,
|
|
primarySessionState *string,
|
|
) TaskDTO {
|
|
// Convert repositories
|
|
var repositories []TaskRepositoryDTO
|
|
for _, repo := range task.Repositories {
|
|
repositories = append(repositories, TaskRepositoryDTO{
|
|
ID: repo.ID,
|
|
TaskID: repo.TaskID,
|
|
RepositoryID: repo.RepositoryID,
|
|
BaseBranch: repo.BaseBranch,
|
|
Position: repo.Position,
|
|
Metadata: repo.Metadata,
|
|
CreatedAt: repo.CreatedAt,
|
|
UpdatedAt: repo.UpdatedAt,
|
|
})
|
|
}
|
|
|
|
return TaskDTO{
|
|
ID: task.ID,
|
|
WorkspaceID: task.WorkspaceID,
|
|
WorkflowID: task.WorkflowID,
|
|
WorkflowStepID: task.WorkflowStepID,
|
|
Title: task.Title,
|
|
Description: task.Description,
|
|
State: task.State,
|
|
Priority: task.Priority,
|
|
Repositories: repositories,
|
|
Position: task.Position,
|
|
PrimarySessionID: primarySessionID,
|
|
SessionCount: sessionCount,
|
|
ReviewStatus: reviewStatus,
|
|
PrimaryExecutorID: primaryExecutorID,
|
|
PrimaryExecutorType: primaryExecutorType,
|
|
PrimaryExecutorName: primaryExecutorName,
|
|
PrimaryAgentName: primaryAgentName,
|
|
PrimaryWorkingDirectory: primaryWorkingDirectory,
|
|
PrimarySessionState: primarySessionState,
|
|
IsRemoteExecutor: primaryExecutorType != nil && models.IsRemoteExecutorType(models.ExecutorType(*primaryExecutorType)),
|
|
ArchivedAt: task.ArchivedAt,
|
|
CreatedAt: task.CreatedAt,
|
|
UpdatedAt: task.UpdatedAt,
|
|
Metadata: task.Metadata,
|
|
}
|
|
}
|
|
|
|
// FromTaskSessionSummary converts a session model to a summary DTO (no snapshot fields).
|
|
func FromTaskSessionSummary(session *models.TaskSession) TaskSessionSummaryDTO {
|
|
result := TaskSessionSummaryDTO{
|
|
ID: session.ID,
|
|
TaskID: session.TaskID,
|
|
AgentExecutionID: session.AgentExecutionID,
|
|
ContainerID: session.ContainerID,
|
|
AgentProfileID: session.AgentProfileID,
|
|
ExecutorID: session.ExecutorID,
|
|
EnvironmentID: session.EnvironmentID,
|
|
RepositoryID: session.RepositoryID,
|
|
BaseBranch: session.BaseBranch,
|
|
BaseCommitSHA: session.BaseCommitSHA,
|
|
State: session.State,
|
|
ErrorMessage: session.ErrorMessage,
|
|
Metadata: session.Metadata,
|
|
StartedAt: session.StartedAt,
|
|
CompletedAt: session.CompletedAt,
|
|
UpdatedAt: session.UpdatedAt,
|
|
IsPrimary: session.IsPrimary,
|
|
IsPassthrough: session.IsPassthrough,
|
|
WorkflowStepID: session.WorkflowStepID,
|
|
ReviewStatus: session.ReviewStatus,
|
|
}
|
|
if len(session.Worktrees) > 0 {
|
|
result.WorktreeID = session.Worktrees[0].WorktreeID
|
|
result.WorktreePath = session.Worktrees[0].WorktreePath
|
|
result.WorktreeBranch = session.Worktrees[0].WorktreeBranch
|
|
}
|
|
return result
|
|
}
|
|
|
|
func FromTaskSession(session *models.TaskSession) TaskSessionDTO {
|
|
result := TaskSessionDTO{
|
|
ID: session.ID,
|
|
TaskID: session.TaskID,
|
|
AgentExecutionID: session.AgentExecutionID,
|
|
ContainerID: session.ContainerID,
|
|
AgentProfileID: session.AgentProfileID,
|
|
ExecutorID: session.ExecutorID,
|
|
EnvironmentID: session.EnvironmentID,
|
|
RepositoryID: session.RepositoryID,
|
|
BaseBranch: session.BaseBranch,
|
|
BaseCommitSHA: session.BaseCommitSHA,
|
|
State: session.State,
|
|
ErrorMessage: session.ErrorMessage,
|
|
Metadata: session.Metadata,
|
|
AgentProfileSnapshot: session.AgentProfileSnapshot,
|
|
ExecutorSnapshot: session.ExecutorSnapshot,
|
|
EnvironmentSnapshot: session.EnvironmentSnapshot,
|
|
RepositorySnapshot: session.RepositorySnapshot,
|
|
StartedAt: session.StartedAt,
|
|
CompletedAt: session.CompletedAt,
|
|
UpdatedAt: session.UpdatedAt,
|
|
// Workflow fields
|
|
IsPrimary: session.IsPrimary,
|
|
IsPassthrough: session.IsPassthrough,
|
|
WorkflowStepID: session.WorkflowStepID,
|
|
ReviewStatus: session.ReviewStatus,
|
|
}
|
|
if len(session.Worktrees) > 0 {
|
|
result.WorktreeID = session.Worktrees[0].WorktreeID
|
|
result.WorktreePath = session.Worktrees[0].WorktreePath
|
|
result.WorktreeBranch = session.Worktrees[0].WorktreeBranch
|
|
}
|
|
return result
|
|
}
|
|
|
|
// WorkflowStepDTO represents a workflow step for API responses
|
|
type WorkflowStepDTO struct {
|
|
ID string `json:"id"`
|
|
WorkflowID string `json:"workflow_id"`
|
|
Name string `json:"name"`
|
|
Position int `json:"position"`
|
|
Color string `json:"color"`
|
|
Prompt string `json:"prompt,omitempty"`
|
|
Events *StepEventsDTO `json:"events,omitempty"`
|
|
AllowManualMove bool `json:"allow_manual_move"`
|
|
IsStartStep bool `json:"is_start_step"`
|
|
ShowInCommandPanel bool `json:"show_in_command_panel"`
|
|
AutoArchiveAfterHours int `json:"auto_archive_after_hours,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// StepEventsDTO represents step events for API responses
|
|
type StepEventsDTO struct {
|
|
OnEnter []StepActionDTO `json:"on_enter,omitempty"`
|
|
OnTurnComplete []StepActionDTO `json:"on_turn_complete,omitempty"`
|
|
}
|
|
|
|
// StepActionDTO represents a step action for API responses
|
|
type StepActionDTO struct {
|
|
Type string `json:"type"`
|
|
Config map[string]interface{} `json:"config,omitempty"`
|
|
}
|
|
|
|
// MoveTaskResponse includes the task and the target workflow step info
|
|
type MoveTaskResponse struct {
|
|
Task TaskDTO `json:"task"`
|
|
WorkflowStep WorkflowStepDTO `json:"workflow_step"`
|
|
}
|
|
|
|
// Session Workflow Review DTOs
|
|
|
|
// ApproveSessionRequest is the request to approve a session's current step
|
|
type ApproveSessionRequest struct {
|
|
SessionID string `json:"-"` // From URL path
|
|
}
|
|
|
|
// ApproveSessionResponse is the response after approving a session
|
|
type ApproveSessionResponse struct {
|
|
Success bool `json:"success"`
|
|
Session TaskSessionDTO `json:"session"`
|
|
WorkflowStep WorkflowStepDTO `json:"workflow_step,omitempty"` // New step after approval
|
|
}
|
|
|
|
// TaskPlanDTO represents a task plan for API responses
|
|
type TaskPlanDTO struct {
|
|
ID string `json:"id"`
|
|
TaskID string `json:"task_id"`
|
|
Title string `json:"title"`
|
|
Content string `json:"content"`
|
|
CreatedBy string `json:"created_by"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// TaskPlanFromModel converts a TaskPlan model to a TaskPlanDTO.
|
|
func TaskPlanFromModel(plan *models.TaskPlan) *TaskPlanDTO {
|
|
if plan == nil {
|
|
return nil
|
|
}
|
|
return &TaskPlanDTO{
|
|
ID: plan.ID,
|
|
TaskID: plan.TaskID,
|
|
Title: plan.Title,
|
|
Content: plan.Content,
|
|
CreatedBy: plan.CreatedBy,
|
|
CreatedAt: plan.CreatedAt,
|
|
UpdatedAt: plan.UpdatedAt,
|
|
}
|
|
}
|
|
|
|
// FromTurn converts a Turn model to a TurnDTO.
|
|
func FromTurn(turn *models.Turn) TurnDTO {
|
|
var completedAt *string
|
|
if turn.CompletedAt != nil {
|
|
formatted := turn.CompletedAt.UTC().Format(time.RFC3339)
|
|
completedAt = &formatted
|
|
}
|
|
|
|
return TurnDTO{
|
|
ID: turn.ID,
|
|
SessionID: turn.TaskSessionID,
|
|
TaskID: turn.TaskID,
|
|
StartedAt: turn.StartedAt.UTC().Format(time.RFC3339),
|
|
CompletedAt: completedAt,
|
|
Metadata: turn.Metadata,
|
|
CreatedAt: turn.CreatedAt.UTC().Format(time.RFC3339),
|
|
UpdatedAt: turn.UpdatedAt.UTC().Format(time.RFC3339),
|
|
}
|
|
}
|