78cae96bb1
* feat(plugins): add capability-gated Host reader for conversation content Plugins can now read historical user/agent message content over the Host data API, gated by a new `api_read:messages` capability (ADR 0047). This unblocks "summarize yesterday"-style plugins that the live `message.added` bus event alone cannot serve. - proto: `ListMessages` RPC + `Message`/`MessageFilter` on `service Host`. - SDK: `Host.Messages() MessageReader`, Go-native `Message`/`MessageFilter`. - host: `api_read:messages` accessor + denied reader; content sanitized via `sysprompt.StripSystemContent` (no raw system prompts); RFC3339 `since`/ `until` → `InvalidArgument` on bad input. - data: new `ListMessagesForPlugin` filtered query (session/task ids, type, created_at range) through the task service, never the DB file. - tests: in-process + wire capability gating, content stripping, filter/time passthrough, pagination, and the SQLite query. - docs: ADR 0047, spec, plugins-manifest, plugins-authoring. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(plugins): add Host.InvokeUtilityAgent for settings-selectable utility agent Plugins can now delegate a one-shot LLM step to an operator-configured agent, gated by a new `agent_invoke` capability (ADR 0048), so a plugin needs no provider API key of its own. - setting: new `utility_agent_profile_id` user setting (Settings > System > Utility Agent), a profile dropdown cloned from the existing utility-agent path; selectable in the UI. - capability: boolean `agent_invoke`, enforced like `state`/`secrets`. - proto/SDK: `InvokeUtilityAgent(prompt) -> text` RPC and `Host.InvokeUtilityAgent(ctx, prompt)`. - backend: reuses the sessionless host-utility inference tier (ADR 0002) via a thin adapter — no agent loop, no task/session/workspace; resolves the configured profile to (agent type, model). Unconfigured / deleted profile -> gRPC FailedPrecondition. - tests: capability gating, completion path (asserts the configured profile is used and text returned), no-utility-agent and stale-profile error paths, SDK/wire round-trips, and the settings apply/trim behavior. - docs: ADR 0048, spec, plugins-manifest, plugins-authoring. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(plugins): resolve utility-agent deps live and bound message filter size Address CI + review feedback on the host plugin capabilities: - docs: register the new /settings/system/utility-agent route in docs/public/coverage.json (fixes the "Validate public docs" CI failure). - utility agent (ADR 0048): hostUtilityMgr is wired late in boot — after StartActivePlugins has already spawned boot-active plugins — so snapshotting the utility deps in hostForPlugin stranded those hosts with nil deps and made InvokeUtilityAgent return Unimplemented for their lifetime. Read the deps live from the Service (mutex-guarded) at call time instead; add a regression test for late wiring reaching an already-spawned host. - messages (ADR 0047): cap the combined session/task/type filter values at 400 so an oversized filter fails fast with InvalidArgument instead of hitting SQLite's host-parameter limit at query execution; add a test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
117 lines
4.2 KiB
Go
117 lines
4.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
|
|
"github.com/kandev/kandev/internal/user/dto"
|
|
"github.com/kandev/kandev/internal/user/service"
|
|
)
|
|
|
|
type Controller struct {
|
|
svc *service.Service
|
|
}
|
|
|
|
func NewController(svc *service.Service) *Controller {
|
|
return &Controller{svc: svc}
|
|
}
|
|
|
|
func (c *Controller) GetCurrentUser(ctx context.Context) (dto.UserResponse, error) {
|
|
user, err := c.svc.GetCurrentUser(ctx)
|
|
if err != nil {
|
|
return dto.UserResponse{}, err
|
|
}
|
|
settings, err := c.svc.GetUserSettings(ctx)
|
|
if err != nil {
|
|
return dto.UserResponse{}, err
|
|
}
|
|
return dto.UserResponse{
|
|
User: dto.FromUser(user),
|
|
Settings: dto.FromUserSettings(settings),
|
|
}, nil
|
|
}
|
|
|
|
func (c *Controller) GetUserSettings(ctx context.Context) (dto.UserSettingsResponse, error) {
|
|
settings, err := c.svc.GetUserSettings(ctx)
|
|
if err != nil {
|
|
return dto.UserSettingsResponse{}, err
|
|
}
|
|
return dto.UserSettingsResponse{
|
|
Settings: dto.FromUserSettings(settings),
|
|
ShellOptions: shellOptionsForOS(),
|
|
}, nil
|
|
}
|
|
|
|
func (c *Controller) UpdateUserSettings(ctx context.Context, req dto.UpdateUserSettingsRequest) (dto.UserSettingsResponse, error) {
|
|
settings, err := c.svc.UpdateUserSettings(ctx, &service.UpdateUserSettingsRequest{
|
|
WorkspaceID: req.WorkspaceID,
|
|
KanbanViewMode: req.KanbanViewMode,
|
|
WorkflowFilterID: req.WorkflowFilterID,
|
|
RepositoryIDs: req.RepositoryIDs,
|
|
TasksListSort: req.TasksListSort,
|
|
TasksListGroup: req.TasksListGroup,
|
|
InitialSetupComplete: req.InitialSetupComplete,
|
|
PreferredShell: req.PreferredShell,
|
|
DefaultEditorID: req.DefaultEditorID,
|
|
EnablePreviewOnClick: req.EnablePreviewOnClick,
|
|
ChatSubmitKey: req.ChatSubmitKey,
|
|
ReviewAutoMarkOnScroll: req.ReviewAutoMarkOnScroll,
|
|
ConfirmTaskArchive: req.ConfirmTaskArchive,
|
|
MCPTaskAgentProfileDefault: req.MCPTaskAgentProfileDefault,
|
|
ShowReleaseNotification: req.ShowReleaseNotification,
|
|
ReleaseNotesLastSeenVersion: req.ReleaseNotesLastSeenVersion,
|
|
LspAutoStartLanguages: req.LspAutoStartLanguages,
|
|
LspAutoInstallLanguages: req.LspAutoInstallLanguages,
|
|
LspServerConfigs: req.LspServerConfigs,
|
|
SavedLayouts: req.SavedLayouts,
|
|
SidebarViews: req.SidebarViews,
|
|
SidebarActiveViewID: req.SidebarActiveViewID,
|
|
SidebarDraft: req.SidebarDraft.ServiceValue(),
|
|
SidebarTaskPrefs: req.SidebarTaskPrefs,
|
|
TaskCreateLastUsed: req.TaskCreateLastUsed,
|
|
JiraSavedViews: req.JiraSavedViews.ServiceValue(),
|
|
JiraTaskPresets: req.JiraTaskPresets.ServiceValue(),
|
|
GitHubSavedPresets: req.GitHubSavedPresets.ServiceValue(),
|
|
GitHubDefaultQueryPresets: req.GitHubDefaultQueryPresets.ServiceValue(),
|
|
GitLabSavedPresets: req.GitLabSavedPresets.ServiceValue(),
|
|
DefaultUtilityAgentID: req.DefaultUtilityAgentID,
|
|
DefaultUtilityModel: req.DefaultUtilityModel,
|
|
UtilityAgentProfileID: req.UtilityAgentProfileID,
|
|
KeyboardShortcuts: req.KeyboardShortcuts,
|
|
TerminalLinkBehavior: req.TerminalLinkBehavior,
|
|
TerminalFontFamily: req.TerminalFontFamily,
|
|
TerminalFontSize: req.TerminalFontSize,
|
|
ChangesPanelLayout: req.ChangesPanelLayout,
|
|
SystemMetricsDisplay: req.SystemMetricsDisplay,
|
|
VoiceMode: req.VoiceMode,
|
|
})
|
|
if err != nil {
|
|
return dto.UserSettingsResponse{}, err
|
|
}
|
|
return dto.UserSettingsResponse{
|
|
Settings: dto.FromUserSettings(settings),
|
|
ShellOptions: shellOptionsForOS(),
|
|
}, nil
|
|
}
|
|
|
|
func shellOptionsForOS() []dto.ShellOption {
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
return []dto.ShellOption{
|
|
{Value: "auto", Label: "System default"},
|
|
{Value: "pwsh.exe", Label: "PowerShell (pwsh)"},
|
|
{Value: "powershell.exe", Label: "Windows PowerShell"},
|
|
{Value: "cmd.exe", Label: "Command Prompt"},
|
|
{Value: "custom", Label: "Custom"},
|
|
}
|
|
default:
|
|
return []dto.ShellOption{
|
|
{Value: "auto", Label: "System default"},
|
|
{Value: "/bin/zsh", Label: "zsh"},
|
|
{Value: "/bin/bash", Label: "bash"},
|
|
{Value: "/bin/sh", Label: "sh"},
|
|
{Value: "custom", Label: "Custom"},
|
|
}
|
|
}
|
|
}
|