{"modulePath":"github.com/masterkeysrd/tasksmith","version":"v0.0.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package command\n\nPackage command implements the REPL slash command system for the TaskSmith CLI. It defines a command registry, the built-in slash commands, and the interactive browser views that render inside the store's slot area, bridging the interactive CLI store and the daemon API client.\n\n### Command Registry {#hdr-Command_Registry}\n\nA [Registry](#Registry) maintains the collection of [Command](#Command) values, each pairing a name (and optional aliases) with a [Handler](#Handler) that runs when the command is invoked. [NewRegistry](#NewRegistry) returns a registry pre-populated with every built-in command. [Registry.Register](#Registry.Register) adds or replaces a command and indexes its name and aliases (normalized to lowercase with any leading \"/\" stripped), while [Registry.Lookup](#Registry.Lookup) resolves a command by its primary name or alias. [Registry.Execute](#Registry.Execute) parses a raw slash command line, resolves it through [Registry.Lookup](#Registry.Lookup), and invokes the matching handler with the remaining arguments; an unknown command or a command with no handler returns an error. [Registry.List](#Registry.List) returns all registered commands in registration order.\n\n### Built-in Commands {#hdr-Built_in_Commands}\n\n[NewRegistry](#NewRegistry) registers the built-in commands, grouped by purpose:\n\n  - System: /help, /mode, /model, /agent, /effort, /budget, /thinking, /theme, and /exit.\n  - Session: /new, /clear, and /sessions.\n  - Changes: /changes and /revert.\n  - Permissions: /permissions.\n  - Tasks: /tasks.\n  - Context: /compact and /context.\n  - Usage: /usage.\n  - Skills: /skills.\n  - Rules: /rules.\n  - Tools: /tools.\n\nEach command either mutates the store directly (for example /mode and /model) or enqueues an interactive browser into the store's slot area.\n\n### Interactive Browsers {#hdr-Interactive_Browsers}\n\nSeveral commands render interactive, slot-scoped views built as trail functional components: [ChangesBrowser](#ChangesBrowser), [PermissionBrowser](#PermissionBrowser), [SessionBrowser](#SessionBrowser), [SkillsBrowser](#SkillsBrowser), [RulesBrowser](#RulesBrowser), [ToolsBrowser](#ToolsBrowser), [TasksBrowser](#TasksBrowser), [ModelPicker](#ModelPicker), and [AgentPicker](#AgentPicker). Each view is enqueued into the store, reads live data from the daemon client, and closes itself through the store when the user cancels.\n\n### Workspace Commands and Skills {#hdr-Workspace_Commands_and_Skills}\n\n[Registry.RegisterWorkspace](#Registry.RegisterWorkspace) adapts workspace Command and Skill manifests (via [Registry.RegisterCommandResource](#Registry.RegisterCommandResource) and [Registry.RegisterSkillResource](#Registry.RegisterSkillResource)) into interactive slash commands. Executing one validates its declared arguments client-side and then forwards the reconstructed line to the store, so workspace commands and skills run through the same pipeline as user input. [SkillScope](#SkillScope) and [EstimateSkillTokens](#EstimateSkillTokens) provide the canonical scope label and token estimate used to present skills.\n\n### Autocomplete {#hdr-Autocomplete}\n\n[Registry.Sources](#Registry.Sources) snapshots the registered commands as headless autocomplete sources for the REPL, including per-command argument completers. [CompletionViews](#CompletionViews) returns command-specific completion views for the active permission mode.\n\n## Constants\n\n```go\nconst (\n\t// MCPRefPrefix is the slash trigger for invoking an MCP prompt. It is\n\t// exported so the composer can tell an MCP prompt reference apart from a\n\t// slash command.\n\tMCPRefPrefix = \"/mcp:\"\n)\n```\nmcpPromptRefPrefix and mcpResourceRefPrefix are the composer triggers for invoking an MCP prompt and attaching an MCP resource. The trigger character (\"/\" or \"@\") is consumed by the autocomplete engine, so candidate insert text starts at the body; parseMCPRef accepts both the full reference and the body.\n\n## Variables\n\n```go\nvar AgentPicker = trail.FC(\"AgentPicker\", func(slotID string) trail.Node {\n\tc := store.Client()\n\n\tresult := wind.Use(\"agents\", promise.WrapWithProps(func(ctx context.Context, _ string) ([]api.Agent, error) {\n\t\tif c == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn c.ListAgents(ctx)\n\t}), wind.Options{Enabled: c != nil})\n\n\tkitex.UseEffect(func() {\n\t\tif c == nil {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"Client unavailable.\")\n\t\t\treturn\n\t\t}\n\t\tif result.IsLoading {\n\t\t\treturn\n\t\t}\n\t\tif result.IsError {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendError(\"Error\", result.Error.Error())\n\t\t} else if len(result.Data) == 0 {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"No agents available.\")\n\t\t}\n\t}, []any{c == nil, result.IsLoading, result.IsError, result.Error, len(result.Data)})\n\n\tif c == nil {\n\t\treturn nil\n\t}\n\tif result.IsLoading {\n\t\treturn loadingHint(\"Loading agents...\")\n\t}\n\tif result.IsError || len(result.Data) == 0 {\n\t\treturn nil\n\t}\n\n\tcurrentAgent := store.GetSession().Config.Agent\n\tif store.GetSession().Session != nil {\n\t\tcurrentAgent = store.GetSession().Session.Config.Agent\n\t}\n\n\topts := make([]uicomponents.Option, len(result.Data))\n\tfor i, a := range result.Data {\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue:       a.Name,\n\t\t\tLabel:       a.Name,\n\t\t\tDescription: agentDescription(a),\n\t\t\tCurrent:     a.Name == currentAgent,\n\t\t}\n\t}\n\n\tpicker := components.NewPicker(\"Select agent:\", opts, func(opt uicomponents.Option) {\n\t\tstore.RemoveSlot(slotID)\n\t\tfor _, a := range result.Data {\n\t\t\tif a.Name == opt.Value {\n\t\t\t\tif !a.CanHumanTrigger() {\n\t\t\t\t\tstore.AppendError(\"Error\", fmt.Sprintf(\"Agent %q cannot be triggered by human (triggers: %s)\", a.Name, strings.Join(a.Triggers, \", \")))\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tstore.SetAgent(opt.Value)\n\t})\n\tpicker.Filterable = true\n\tpicker.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/agent\", \"Exited /agent command\")\n\t}\n\n\treturn components.Picker(picker)\n})\n```\nAgentPicker renders an interactive agent picker querying daemon agents via wind.\n\n```go\nvar ChangesBrowser = trail.FC(\"ChangesBrowser\", func(slotID string) trail.Node {\n\tsess := store.GetSession().Session\n\tc := store.Client()\n\n\tselectedChange, setSelectedChange := kitex.UseState[*api.FileChange](nil)\n\tchangesState, setChangesState := kitex.UseState[[]api.FileChange](nil)\n\tisLoading, setIsLoading := kitex.UseState(true)\n\terrorState, setErrorState := kitex.UseState[error](nil)\n\tfetchCount, setFetchCount := kitex.UseState(0)\n\n\tsessID := \"\"\n\tif sess != nil {\n\t\tsessID = sess.ID\n\t}\n\n\trefetch := func() {\n\t\tsetFetchCount(fetchCount() + 1)\n\t}\n\n\tkitex.UseEffectCleanup(func() func() {\n\t\tif sess == nil || sess.ID == \"\" || c == nil {\n\t\t\tsetIsLoading(false)\n\t\t\treturn nil\n\t\t}\n\t\tctx, cancel := context.WithCancel(context.Background())\n\t\tsetIsLoading(true)\n\t\tgo func() {\n\t\t\tdata, err := c.Changes(ctx, sess.ID)\n\t\t\tif ctx.Err() != nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif err != nil {\n\t\t\t\tsetErrorState(err)\n\t\t\t} else {\n\t\t\t\tsetChangesState(data)\n\t\t\t\tsetErrorState(nil)\n\t\t\t}\n\t\t\tsetIsLoading(false)\n\t\t}()\n\t\treturn cancel\n\t}, []any{sessID, fetchCount()})\n\n\tif sess == nil || sess.ID == \"\" {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/changes\", \"No active session.\")\n\t\treturn nil\n\t}\n\tif c == nil {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendNotice(\"Client unavailable.\")\n\t\treturn nil\n\t}\n\n\tif sel := selectedChange(); sel != nil {\n\t\treturn changeDiffViewer(changeDiffProps{\n\t\t\tsessionID: sess.ID,\n\t\t\tchange:    sel,\n\t\t\tonClose: func() {\n\t\t\t\tsetSelectedChange(nil)\n\t\t\t},\n\t\t})\n\t}\n\n\tif isLoading() {\n\t\treturn loadingHint(\"Loading changes...\")\n\t}\n\tif err := errorState(); err != nil {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendError(\"Error\", err.Error())\n\t\treturn nil\n\t}\n\n\taggregated := aggregateFileChanges(changesState())\n\tif len(aggregated) == 0 {\n\t\treturn emptyChangesView(emptyChangesViewProps{slotID: slotID})\n\t}\n\n\tscheme := theme.UseTheme()\n\topts := make([]uicomponents.Option, len(aggregated))\n\tfor i, ch := range aggregated {\n\t\tstats := fmt.Sprintf(\"+%d/-%d\", ch.Additions, ch.Deletions)\n\t\tstatsNode := trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().WhiteSpace(style.WhiteSpacePre),\n\t\t},\n\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\tStyle: style.S().Foreground(scheme.Color.Diff.AddedText),\n\t\t\t}, trail.Text(fmt.Sprintf(\"+%d\", ch.Additions))),\n\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\tStyle: style.S().Foreground(scheme.Color.Text.Secondary),\n\t\t\t}, trail.Text(\"/\")),\n\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\tStyle: style.S().Foreground(scheme.Color.Diff.RemovedText),\n\t\t\t}, trail.Text(fmt.Sprintf(\"-%d\", ch.Deletions))),\n\t\t)\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue:     ch.Path,\n\t\t\tLabel:     ch.Path,\n\t\t\tCells:     []string{ch.Path, string(ch.Kind), stats},\n\t\t\tCellNodes: []trail.Node{nil, nil, statsNode},\n\t\t}\n\t}\n\n\tpickerProps := components.NewPicker(\"Tracked Changes\", opts, func(opt uicomponents.Option) {\n\t\tfor i := range aggregated {\n\t\t\tif aggregated[i].Path == opt.Value {\n\t\t\t\tch := aggregated[i]\n\t\t\t\tsetSelectedChange(\u0026ch)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t})\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: 0},\n\t\t{Width: 16, Align: style.TextAlignLeft},\n\t\t{Width: 16, Align: style.TextAlignRight},\n\t}\n\tpickerProps.Filterable = true\n\tpickerProps.Bindings = []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"View diff\"},\n\t\t{Key: \"r\", Label: \"Revert\"},\n\t\t{Key: \"esc\", Label: \"Close\"},\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t}\n\tpickerProps.ConfirmActions = map[string]components.ConfirmAction{\n\t\t\"r\": {\n\t\t\tPrompt: func(opt uicomponents.Option) string {\n\t\t\t\treturn fmt.Sprintf(\"Revert changes to %s?\", opt.Label)\n\t\t\t},\n\t\t\tOnConfirm: func(opt uicomponents.Option) {\n\t\t\t\tgo func() {\n\t\t\t\t\terr := c.Revert(context.Background(), sess.ID, api.RevertRequest{\n\t\t\t\t\t\tPath: opt.Value,\n\t\t\t\t\t})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tstore.AppendError(\"Revert Error\", err.Error())\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t\trefetch()\n\t\t\t\t}()\n\t\t\t},\n\t\t},\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nChangesBrowser renders an interactive changes list and inline diff viewer inside \\\u003cSlot /\u003e.\n\n```go\nvar DaemonBrowser = trail.FC(\"DaemonBrowser\", func(slotID string) trail.Node {\n\tstatus := store.UseDaemonStatus()\n\thealth, setHealth := kitex.UseState[*api.HealthResponse](nil)\n\tinProgress, setInProgress := kitex.UseState(false)\n\n\trefreshHealth := func() {\n\t\tc := store.Client()\n\t\tif c == nil {\n\t\t\tsetHealth(nil)\n\t\t\treturn\n\t\t}\n\t\tgo func() {\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)\n\t\t\tdefer cancel()\n\t\t\th, err := c.Health(ctx)\n\t\t\tif err == nil {\n\t\t\t\tsetHealth(h)\n\t\t\t} else {\n\t\t\t\tsetHealth(nil)\n\t\t\t}\n\t\t}()\n\t}\n\n\tkitex.UseEffect(func() {\n\t\tc := store.Client()\n\t\tif c == nil {\n\t\t\tsetHealth(nil)\n\t\t\treturn\n\t\t}\n\t\tctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)\n\t\tdefer cancel()\n\t\th, err := c.Health(ctx)\n\t\tif err == nil {\n\t\t\tsetHealth(h)\n\t\t} else {\n\t\t\tsetHealth(nil)\n\t\t}\n\t}, []any{status})\n\n\tdoStart := func() {\n\t\tif inProgress() {\n\t\t\treturn\n\t\t}\n\t\tsetInProgress(true)\n\t\tgo func() {\n\t\t\tdefer setInProgress(false)\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\t\t\tdefer cancel()\n\t\t\th, err := store.StartDaemon(ctx)\n\t\t\tif err == nil \u0026\u0026 h != nil {\n\t\t\t\tsetHealth(h)\n\t\t\t} else {\n\t\t\t\tsetHealth(nil)\n\t\t\t}\n\t\t}()\n\t}\n\n\tdoRestart := func() {\n\t\tif inProgress() {\n\t\t\treturn\n\t\t}\n\t\tsetInProgress(true)\n\t\tgo func() {\n\t\t\tdefer setInProgress(false)\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)\n\t\t\tdefer cancel()\n\t\t\th, err := store.RestartDaemon(ctx)\n\t\t\tif err == nil \u0026\u0026 h != nil {\n\t\t\t\tsetHealth(h)\n\t\t\t} else {\n\t\t\t\tsetHealth(nil)\n\t\t\t}\n\t\t}()\n\t}\n\n\tdoStop := func() {\n\t\tif inProgress() {\n\t\t\treturn\n\t\t}\n\t\tsetInProgress(true)\n\t\tgo func() {\n\t\t\tdefer setInProgress(false)\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\t\t\tdefer cancel()\n\t\t\t_ = store.StopDaemon(ctx)\n\t\t\tsetHealth(nil)\n\t\t}()\n\t}\n\n\ttrail.UseInput(func(_ string, k event.KeyEvent) {\n\t\tswitch {\n\t\tcase k.MatchString(\"esc\", \"escape\", \"q\"):\n\t\t\tstore.RemoveSlot(slotID)\n\t\tcase k.MatchString(\"g\"):\n\t\t\trefreshHealth()\n\t\tcase k.MatchString(\"r\"):\n\t\t\tif status == store.DaemonDisconnected || health() == nil {\n\t\t\t\tdoStart()\n\t\t\t} else {\n\t\t\t\tdoRestart()\n\t\t\t}\n\t\tcase k.MatchString(\"s\"):\n\t\t\tif status == store.DaemonDisconnected || health() == nil {\n\t\t\t\tdoStart()\n\t\t\t}\n\t\tcase k.MatchString(\"x\"):\n\t\t\tif status == store.DaemonConnected \u0026\u0026 health() != nil {\n\t\t\t\tdoStop()\n\t\t\t}\n\t\t}\n\t})\n\n\tscheme := theme.UseTheme()\n\tborder := style.SingleBorder().Top(true).Bottom(false).Left(false).Right(false).Color(scheme.Color.Border.Default)\n\tboxStyle := style.S().\n\t\tBorder(border).\n\t\tWidth(style.Percent(100)).\n\t\tFlexDirection(style.FlexColumn)\n\n\ttitleStyle := style.S().Bold(true).Margin(0, 0, 1, 0).Foreground(scheme.Color.Text.Primary)\n\n\tsockPath := store.SocketPath()\n\tif sockPath == \"\" {\n\t\tif c := store.Client(); c != nil {\n\t\t\tsockPath = c.SocketPath()\n\t\t}\n\t}\n\n\tkvRow := func(label, value string, valColor color.Color) trail.Node {\n\t\treturn trail.Box(trail.BoxProps{\n\t\t\tStyle: style.S().FlexDirection(style.FlexRow).Width(style.Percent(100)),\n\t\t},\n\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\tStyle: style.S().WhiteSpace(style.WhiteSpacePre).Foreground(scheme.Color.Text.Secondary),\n\t\t\t}, trail.Text(label)),\n\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\tStyle: style.S().WhiteSpace(style.WhiteSpacePre).Foreground(valColor),\n\t\t\t}, trail.Text(value)),\n\t\t)\n\t}\n\n\tmsgRow := func(msg string) trail.Node {\n\t\treturn trail.Box(trail.BoxProps{\n\t\t\tStyle: style.S().FlexDirection(style.FlexRow).Width(style.Percent(100)).Margin(0, 0, 1, 0),\n\t\t},\n\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\tStyle: style.S().WhiteSpace(style.WhiteSpacePre).Foreground(scheme.Color.Text.Secondary),\n\t\t\t}, trail.Text(msg)),\n\t\t)\n\t}\n\n\tvar children []trail.Node\n\tchildren = append(children, trail.Span(trail.SpanProps{Style: titleStyle}, trail.Text(\"Brain Daemon\")))\n\n\th := health()\n\tisRestarting := status == store.DaemonRestarting || inProgress()\n\n\tif isRestarting {\n\t\tchildren = append(children,\n\t\t\tkvRow(\"  Status:      \", \"↻ Restarting...\", scheme.Color.Text.Warning),\n\t\t\tkvRow(\"  Socket:      \", sockPath, scheme.Color.Text.Primary),\n\t\t\tmsgRow(\"  Stopping existing daemon and spawning a new background process...\"),\n\t\t\tuicomponents.KeyboardHint(uicomponents.KeyboardHintProps{\n\t\t\t\tBindings: []uicomponents.KeyBinding{\n\t\t\t\t\t{Key: \"esc\", Label: \"Close\"},\n\t\t\t\t},\n\t\t\t}),\n\t\t)\n\t} else if status == store.DaemonConnected \u0026\u0026 h != nil {\n\t\tdurationStr := format.Duration(time.Since(h.StartedAt))\n\t\ttimeStr := h.StartedAt.Format(\"2006-01-02 15:04:05\")\n\n\t\trunningChildren := []trail.Node{\n\t\t\tkvRow(\"  Status:      \", \"● Running\", scheme.Color.Text.Success),\n\t\t\tkvRow(\"  Version:     \", daemonDisplayVersion(h), scheme.Color.Text.Primary),\n\t\t\tkvRow(\"  PID:         \", fmt.Sprintf(\"%d\", h.PID), scheme.Color.Text.Primary),\n\t\t\tkvRow(\"  Uptime:      \", fmt.Sprintf(\"%s (started %s)\", durationStr, timeStr), scheme.Color.Text.Primary),\n\t\t\tkvRow(\"  Socket:      \", sockPath, scheme.Color.Text.Primary),\n\t\t\tkvRow(\"  Workspaces:  \", fmt.Sprintf(\"%d active\", len(h.Workspaces)), scheme.Color.Text.Primary),\n\t\t}\n\n\t\tfor _, ws := range h.Workspaces {\n\t\t\trunningChildren = append(runningChildren, trail.Box(trail.BoxProps{\n\t\t\t\tStyle: style.S().FlexDirection(style.FlexRow).Width(style.Percent(100)),\n\t\t\t},\n\t\t\t\ttrail.Span(trail.SpanProps{\n\t\t\t\t\tStyle: style.S().WhiteSpace(style.WhiteSpacePre).Foreground(scheme.Color.Text.Secondary),\n\t\t\t\t}, trail.Text(fmt.Sprintf(\"               • %s\", ws))),\n\t\t\t))\n\t\t}\n\n\t\trunningChildren = append(runningChildren, uicomponents.KeyboardHint(uicomponents.KeyboardHintProps{\n\t\t\tBindings: []uicomponents.KeyBinding{\n\t\t\t\t{Key: \"r\", Label: \"Restart\"},\n\t\t\t\t{Key: \"x\", Label: \"Stop\"},\n\t\t\t\t{Key: \"g\", Label: \"Refresh\"},\n\t\t\t\t{Key: \"esc\", Label: \"Close\"},\n\t\t\t},\n\t\t}))\n\n\t\tchildren = append(children, runningChildren...)\n\t} else {\n\n\t\tchildren = append(children,\n\t\t\tkvRow(\"  Status:      \", \"○ Offline\", scheme.Color.Text.Error),\n\t\t\tkvRow(\"  Socket:      \", sockPath, scheme.Color.Text.Primary),\n\t\t\tmsgRow(\"  The background daemon is not running. Press s or r to start it.\"),\n\t\t\tuicomponents.KeyboardHint(uicomponents.KeyboardHintProps{\n\t\t\t\tBindings: []uicomponents.KeyBinding{\n\t\t\t\t\t{Key: \"s/r\", Label: \"Start\"},\n\t\t\t\t\t{Key: \"g\", Label: \"Refresh\"},\n\t\t\t\t\t{Key: \"esc\", Label: \"Close\"},\n\t\t\t\t},\n\t\t\t}),\n\t\t)\n\t}\n\n\treturn trail.Box(trail.BoxProps{Style: boxStyle}, children...)\n})\n```\nDaemonBrowser renders an interactive view of daemon health and controls in \\\u003cSlot /\u003e.\n\n```go\nvar ErrUnknownCommand = errors.New(\"unknown command\")\n```\nErrUnknownCommand reports a slash command no local handler owns. Callers forward such a line to the daemon, which resolves workspace commands, skills, and MCP prompts, so the TUI, exec, and ACP share one workflow surface.\n\n```go\nvar ModelPicker = trail.FC(\"ModelPicker\", func(slotID string) trail.Node {\n\tc := store.Client()\n\twinSize := trail.UseWindowSize()\n\n\tcurrentModel := store.UseSession(store.SessionState.ActiveModelID)\n\n\tresult := wind.Use(\"models\", promise.WrapWithProps(func(ctx context.Context, _ string) ([]api.Model, error) {\n\t\tif c == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn c.ListModels(ctx)\n\t}), wind.Options{Enabled: c != nil})\n\twindClient := wind.UseClient()\n\n\taliasState, setAliasState := kitex.UseState[[]api.AliasAssignment](nil)\n\tshowEditor, setShowEditor := kitex.UseState(false)\n\teditorTarget := kitex.UseRef[api.Model](api.Model{})\n\tkitex.UseEffect(func() {\n\t\tif c == nil {\n\t\t\treturn\n\t\t}\n\t\tgo func() {\n\t\t\tlist, err := c.ListAliasAssignments(context.Background())\n\t\t\tif err == nil {\n\t\t\t\tsetAliasState(list)\n\t\t\t}\n\t\t}()\n\t}, []any{c != nil})\n\n\topts := modelPickerOptions(result.Data, currentModel)\n\n\tkitex.UseEffect(func() {\n\t\tif c == nil {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"Client unavailable.\")\n\t\t\treturn\n\t\t}\n\t\tif result.IsLoading {\n\t\t\treturn\n\t\t}\n\t\tswitch {\n\t\tcase result.IsError:\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendError(\"Error\", result.Error.Error())\n\t\tcase len(result.Data) == 0:\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"No models available.\")\n\t\tcase len(opts) == 0:\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"No chat-capable models available.\")\n\t\t}\n\t}, []any{c == nil, result.IsLoading, result.IsError, result.Error, len(result.Data), len(opts)})\n\n\tif c == nil {\n\t\treturn nil\n\t}\n\tif result.IsLoading {\n\t\treturn loadingHint(\"Loading models...\")\n\t}\n\tif result.IsError || len(result.Data) == 0 || len(opts) == 0 {\n\t\treturn nil\n\t}\n\n\tif showEditor() \u0026\u0026 editorTarget.Current.Provider != \"\" {\n\t\treturn modelAliasEditorSlot(modelAliasEditorSlotProps{\n\t\t\tProviderName: editorTarget.Current.Provider,\n\t\t\tModelID:      modelIDPart(editorTarget.Current.ID),\n\t\t\tModelName:    firstNonEmpty(editorTarget.Current.Label, editorTarget.Current.Name),\n\t\t\tonDone: func(message string, err error) {\n\t\t\t\tsetShowEditor(false)\n\t\t\t\tif err != nil {\n\t\t\t\t\tstore.AppendError(\"Alias editor\", err.Error())\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tstore.AppendCommandOutput(\"/model\", message)\n\t\t\t\trefreshPickerAliases(c, setAliasState)\n\n\t\t\t\tif windClient != nil {\n\t\t\t\t\twindClient.InvalidateQueries(\"models\")\n\t\t\t\t}\n\t\t\t\trefreshProviderWorkspaceContext(context.Background())\n\t\t\t},\n\t\t\tonCancel: func() { setShowEditor(false) },\n\t\t})\n\t}\n\n\tpicker := components.NewPicker(\"Select model:\", opts, func(opt uicomponents.Option) {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.SetModel(opt.Value)\n\t})\n\tpicker.Filterable = true\n\tpicker.Subtitle = modelAliasStatusLine(aliasState(), winSize.Width)\n\tpicker.Columns = modelPickerColumns(opts, winSize.Width)\n\tpicker.GroupLabel = modelPickerGroupLabel(result.Data)\n\tpicker.Footer = modelPickerFooter(result.Data)\n\tpicker.Bindings = append(slices.Clone(components.DefaultPickerBindings),\n\t\tuicomponents.KeyBinding{Key: \"f2\", Label: \"Edit aliases\"},\n\t)\n\tpicker.Keys = map[string]func(uicomponents.Option){\n\n\t\t\"f2\": func(opt uicomponents.Option) {\n\t\t\teditorTarget.Current = api.Model{}\n\t\t\tfor _, m := range result.Data {\n\t\t\t\tif m.ID == opt.Value {\n\t\t\t\t\teditorTarget.Current = m\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t\tif editorTarget.Current.Provider != \"\" {\n\t\t\t\tsetShowEditor(true)\n\t\t\t}\n\t\t},\n\t}\n\tpicker.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/model\", \"Exited /model command\")\n\t}\n\n\treturn components.Picker(picker)\n})\n```\nModelPicker renders an interactive model picker querying daemon models via wind.\n\n```go\nvar PermissionBrowser = trail.FC(\"PermissionBrowser\", func(slotID string) trail.Node {\n\tc := store.Client()\n\terrMsg, setErrMsg := kitex.UseState(\"\")\n\n\tpermsQuery := wind.Use(\"permissions\", promise.WrapWithProps(func(ctx context.Context, _ string) (api.PermissionsResponse, error) {\n\t\tif c == nil {\n\t\t\treturn api.PermissionsResponse{}, errors.New(\"client unavailable\")\n\t\t}\n\t\tresp, err := c.Permissions(ctx)\n\t\tif err != nil {\n\t\t\treturn api.PermissionsResponse{}, err\n\t\t}\n\t\tif resp == nil {\n\t\t\treturn api.PermissionsResponse{}, nil\n\t\t}\n\t\treturn *resp, nil\n\t}), wind.Options{Enabled: c != nil})\n\n\taddMutation := wind.UseMutation(func(ctx context.Context, req api.PermissionRuleRequest) *promise.Promise[any] {\n\t\treturn promise.Wrap(func(ctx context.Context) (any, error) {\n\t\t\tif c == nil {\n\t\t\t\treturn nil, errors.New(\"client unavailable\")\n\t\t\t}\n\t\t\t_, err := c.AddPermissionRule(ctx, req)\n\t\t\treturn nil, err\n\t\t})(ctx)\n\t}, wind.MutationOptions[api.PermissionRuleRequest, any]{\n\t\tOnSuccess: func(_ any, _ api.PermissionRuleRequest, _ wind.MutationContext) {\n\t\t\tpermsQuery.Refetch()\n\t\t\tsetErrMsg(\"\")\n\t\t},\n\t\tOnError: func(err error, _ api.PermissionRuleRequest, _ wind.MutationContext) {\n\t\t\tsetErrMsg(err.Error())\n\t\t},\n\t})\n\n\tremoveMutation := wind.UseMutation(func(ctx context.Context, req api.PermissionRuleRequest) *promise.Promise[any] {\n\t\treturn promise.Wrap(func(ctx context.Context) (any, error) {\n\t\t\tif c == nil {\n\t\t\t\treturn nil, errors.New(\"client unavailable\")\n\t\t\t}\n\t\t\t_, err := c.RemovePermissionRule(ctx, req)\n\t\t\treturn nil, err\n\t\t})(ctx)\n\t}, wind.MutationOptions[api.PermissionRuleRequest, any]{\n\t\tOnSuccess: func(_ any, _ api.PermissionRuleRequest, _ wind.MutationContext) {\n\t\t\tpermsQuery.Refetch()\n\t\t\tsetErrMsg(\"\")\n\t\t},\n\t\tOnError: func(err error, _ api.PermissionRuleRequest, _ wind.MutationContext) {\n\t\t\tsetErrMsg(err.Error())\n\t\t},\n\t})\n\n\teditMutation := wind.UseMutation(func(ctx context.Context, p editRuleParams) *promise.Promise[any] {\n\t\treturn promise.Wrap(func(ctx context.Context) (any, error) {\n\t\t\tif c == nil {\n\t\t\t\treturn nil, errors.New(\"client unavailable\")\n\t\t\t}\n\t\t\taddReq := api.PermissionRuleRequest{\n\t\t\t\tScope:  p.scope,\n\t\t\t\tEffect: p.effect,\n\t\t\t\tRule:   p.newRule,\n\t\t\t}\n\t\t\tif _, err := c.AddPermissionRule(ctx, addReq); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tremoveOldReq := api.PermissionRuleRequest{\n\t\t\t\tScope:  p.scope,\n\t\t\t\tEffect: p.effect,\n\t\t\t\tRule:   p.oldRule,\n\t\t\t}\n\t\t\tif _, err := c.RemovePermissionRule(ctx, removeOldReq); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn nil, nil\n\t\t})(ctx)\n\t}, wind.MutationOptions[editRuleParams, any]{\n\t\tOnSuccess: func(_ any, _ editRuleParams, _ wind.MutationContext) {\n\t\t\tpermsQuery.Refetch()\n\t\t\tsetErrMsg(\"\")\n\t\t},\n\t\tOnError: func(err error, _ editRuleParams, _ wind.MutationContext) {\n\t\t\tsetErrMsg(err.Error())\n\t\t},\n\t})\n\n\tkitex.UseEffect(func() {\n\t\tif c == nil {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"Client unavailable.\")\n\t\t\treturn\n\t\t}\n\t\tif permsQuery.IsLoading {\n\t\t\treturn\n\t\t}\n\t\tif permsQuery.IsError {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendError(\"Error\", permsQuery.Error.Error())\n\t\t}\n\t}, []any{c == nil, permsQuery.IsLoading, permsQuery.IsError, permsQuery.Error})\n\n\tif c == nil {\n\t\treturn nil\n\t}\n\n\tif permsQuery.IsLoading {\n\t\treturn loadingHint(\"Loading permissions...\")\n\t}\n\tif permsQuery.IsError {\n\t\treturn nil\n\t}\n\n\treturn components.PermissionConfigEditor(components.PermissionConfigEditorProps{\n\t\tPermissions:  permsQuery.Data,\n\t\tErrorMessage: errMsg(),\n\t\tOnAddRule: func(scope api.PermissionScope, effect api.PermissionEffect, rule string) {\n\t\t\taddMutation.Mutate(api.PermissionRuleRequest{\n\t\t\t\tScope:  scope,\n\t\t\t\tEffect: effect,\n\t\t\t\tRule:   rule,\n\t\t\t})\n\t\t},\n\t\tOnEditRule: func(scope api.PermissionScope, effect api.PermissionEffect, oldRule, newRule string) {\n\t\t\teditMutation.Mutate(editRuleParams{\n\t\t\t\tscope:   scope,\n\t\t\t\teffect:  effect,\n\t\t\t\toldRule: oldRule,\n\t\t\t\tnewRule: newRule,\n\t\t\t})\n\t\t},\n\t\tOnRemoveRule: func(scope api.PermissionScope, effect api.PermissionEffect, rule string) {\n\t\t\tremoveMutation.Mutate(api.PermissionRuleRequest{\n\t\t\t\tScope:  scope,\n\t\t\t\tEffect: effect,\n\t\t\t\tRule:   rule,\n\t\t\t})\n\t\t},\n\t\tOnClearError: func() {\n\t\t\tsetErrMsg(\"\")\n\t\t},\n\t\tOnClose: func() {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendCommandOutput(\"/permissions\", \"Exited /permissions command\")\n\t\t},\n\t})\n})\n```\nPermissionBrowser renders an interactive permission configuration editor inside \\\u003cSlot /\u003e.\n\n```go\nvar RulesBrowser = trail.FC(\"RulesBrowser\", func(slotID string) trail.Node {\n\trulesPtr := store.UseApp(func(s store.AppState) *[]api.Rule { return s.Rules })\n\ttranscriptItems := store.UseTranscript(func(s store.TranscriptState) *[]store.TranscriptItem { return s.Items })\n\tstreamMessages := store.UseStream(func(s store.StreamState) *[]store.Message { return s.Messages })\n\tselectedRule, setSelectedRule := kitex.UseState[*api.Rule](nil)\n\tnotice, setNotice := kitex.UseState(\"\")\n\tisReloading, setIsReloading := kitex.UseState(false)\n\n\tvar rules []api.Rule\n\tif rulesPtr != nil {\n\t\trules = *rulesPtr\n\t}\n\n\tc := store.Client()\n\tkitex.UseEffect(func() {\n\t\tif rulesPtr == nil \u0026\u0026 c != nil {\n\t\t\tgo func() {\n\t\t\t\tif rls, err := c.ListRules(context.Background()); err == nil {\n\t\t\t\t\tstore.SetWorkspaceRules(rls)\n\t\t\t\t}\n\t\t\t}()\n\t\t}\n\t}, []any{rulesPtr == nil, c == nil})\n\n\tdoReload := func() {\n\t\tif isReloading() {\n\t\t\treturn\n\t\t}\n\t\tsetIsReloading(true)\n\t\tsetNotice(\"Reloading workspace rules via registry.Reload...\")\n\t\tgo func() {\n\t\t\tdefer setIsReloading(false)\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\t\t\tdefer cancel()\n\t\t\terr := store.ReloadWorkspace(ctx)\n\t\t\tif err != nil {\n\t\t\t\tsetNotice(\"Failed to reload workspace: \" + err.Error())\n\t\t\t} else {\n\t\t\t\tcount := 0\n\t\t\t\tif s := store.GetApp().Rules; s != nil {\n\t\t\t\t\tcount = len(*s)\n\t\t\t\t}\n\t\t\t\tsetNotice(fmt.Sprintf(\"Workspace reloaded via registry.Reload (%d rules available).\", count))\n\t\t\t}\n\t\t}()\n\t}\n\n\tif sel := selectedRule(); sel != nil {\n\t\treturn ruleMarkdownViewer(ruleMarkdownProps{\n\t\t\tslotID:  slotID,\n\t\t\trule:    *sel,\n\t\t\tonClose: func() { setSelectedRule(nil) },\n\t\t})\n\t}\n\n\tif len(rules) == 0 {\n\t\treturn emptyRulesView(emptyRulesViewProps{\n\t\t\tslotID:   slotID,\n\t\t\tnotice:   notice(),\n\t\t\tonReload: doReload,\n\t\t})\n\t}\n\n\ttitle := fmt.Sprintf(\"Rules (%d available)\", len(rules))\n\tif n := notice(); n != \"\" {\n\t\ttitle = fmt.Sprintf(\"Rules (%d available) — %s\", len(rules), n)\n\t}\n\n\tscheme := theme.UseTheme()\n\n\twinSize := trail.UseWindowSize()\n\tavailDescWidth := 0\n\tif winSize.Width \u003e 0 {\n\t\tavailDescWidth = max(20, winSize.Width-30-12-10-8-4)\n\t}\n\n\tloaded := loadedRuleNamesFromSession(transcriptItems, streamMessages)\n\n\topts := make([]uicomponents.Option, len(rules))\n\tfor i, rl := range rules {\n\t\tscope := RuleScope(rl)\n\t\testTokens := rl.Tokens\n\t\tif estTokens == 0 \u0026\u0026 rl.Instructions != \"\" {\n\t\t\testTokens = EstimateRuleTokens(rl.Instructions)\n\t\t}\n\t\ttokStr := format.Tokens(estTokens)\n\n\t\tstatusCol := ruleStatusBadge(rl, loaded)\n\t\tscopeCol := fmt.Sprintf(\"[%s]\", scope)\n\t\tdesc := format.CompactSingleLine(rl.Description, availDescWidth)\n\n\t\tdescNode := trail.Box(trail.BoxProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlexDirection(style.FlexRow).\n\t\t\t\tWidth(style.Percent(100)).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden),\n\t\t}, trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlex(0, 1).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden).\n\t\t\t\tWhiteSpace(style.WhiteSpacePre).\n\t\t\t\tForeground(scheme.Color.Text.Muted),\n\t\t}, trail.Text(desc)))\n\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue:       rl.Name,\n\t\t\tLabel:       rl.Name,\n\t\t\tDescription: desc,\n\t\t\tCells:       []string{rl.Name, statusCol, scopeCol, tokStr, desc},\n\t\t\tCellNodes:   []trail.Node{nil, nil, nil, nil, descNode},\n\t\t}\n\t}\n\n\tpickerProps := components.NewPicker(title, opts, func(opt uicomponents.Option) {\n\t\tfor i := range rules {\n\t\t\tif rules[i].Name == opt.Value {\n\t\t\t\tsetSelectedRule(\u0026rules[i])\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t})\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: 30, Align: style.TextAlignLeft},\n\t\t{Width: 12, Align: style.TextAlignLeft},\n\t\t{Width: 10, Align: style.TextAlignLeft},\n\t\t{Width: 8, Align: style.TextAlignRight},\n\t\t{Width: 0, Align: style.TextAlignLeft},\n\t}\n\tpickerProps.Filterable = false\n\tpickerProps.Bindings = []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"Inspect rule\"},\n\t\t{Key: \"r\", Label: \"Reload workspace\"},\n\t\t{Key: \"esc\", Label: \"Close\"},\n\t}\n\tpickerProps.Keys = map[string]func(uicomponents.Option){\n\t\t\"r\": func(_ uicomponents.Option) {\n\t\t\tdoReload()\n\t\t},\n\t\t\"i\": func(opt uicomponents.Option) {\n\t\t\tfor i := range rules {\n\t\t\t\tif rules[i].Name == opt.Value {\n\t\t\t\t\tsetSelectedRule(\u0026rules[i])\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/rules\", \"Exited /rules command\")\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nRulesBrowser renders an interactive rules list and markdown inspector inside \\\u003cSlot /\u003e.\n\n```go\nvar SandboxBrowser = trail.FC(\"SandboxBrowser\", func(slotID string) trail.Node {\n\tc := store.Client()\n\terrMsg, setErrMsg := kitex.UseState(\"\")\n\tsaving, setSaving := kitex.UseState(false)\n\n\tsandboxQuery := wind.Use(\"sandbox\", promise.WrapWithProps(func(ctx context.Context, _ string) (api.SandboxResponse, error) {\n\t\tif c == nil {\n\t\t\treturn api.SandboxResponse{}, errors.New(\"client unavailable\")\n\t\t}\n\t\tresp, err := c.GetSandbox(ctx)\n\t\tif err != nil {\n\t\t\treturn api.SandboxResponse{}, err\n\t\t}\n\t\tif resp == nil {\n\t\t\treturn api.SandboxResponse{}, nil\n\t\t}\n\t\treturn *resp, nil\n\t}), wind.Options{Enabled: c != nil})\n\n\tupdateMutation := wind.UseMutation(func(ctx context.Context, p sandboxUpdateParams) *promise.Promise[any] {\n\t\treturn promise.Wrap(func(ctx context.Context) (any, error) {\n\t\t\tif c == nil {\n\t\t\t\treturn nil, errors.New(\"client unavailable\")\n\t\t\t}\n\t\t\t_, err := c.UpdateSandbox(ctx, api.UpdateSandboxRequest{Scope: p.scope, Settings: p.settings})\n\t\t\treturn nil, err\n\t\t})(ctx)\n\t}, wind.MutationOptions[sandboxUpdateParams, any]{\n\t\tOnSuccess: func(_ any, _ sandboxUpdateParams, _ wind.MutationContext) {\n\t\t\tsetSaving(false)\n\t\t\tsandboxQuery.Refetch()\n\t\t\tsetErrMsg(\"\")\n\t\t},\n\t\tOnError: func(err error, _ sandboxUpdateParams, _ wind.MutationContext) {\n\t\t\tsetSaving(false)\n\t\t\tsetErrMsg(err.Error())\n\t\t},\n\t})\n\n\tkitex.UseEffect(func() {\n\t\tif c == nil {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"Client unavailable.\")\n\t\t\treturn\n\t\t}\n\t\tif sandboxQuery.IsLoading {\n\t\t\treturn\n\t\t}\n\t\tif sandboxQuery.IsError {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendError(\"Error\", sandboxQuery.Error.Error())\n\t\t}\n\t}, []any{c == nil, sandboxQuery.IsLoading, sandboxQuery.IsError, sandboxQuery.Error})\n\n\tsessionMode := store.UseSession(func(s store.SessionState) api.SandboxMode { return s.SandboxMode })\n\n\tif c == nil {\n\t\treturn nil\n\t}\n\n\tif sandboxQuery.IsLoading {\n\t\treturn loadingHint(\"Loading sandbox settings...\")\n\t}\n\tif sandboxQuery.IsError {\n\t\treturn nil\n\t}\n\n\tresp := sandboxQuery.Data\n\n\tscopeSettings := func(scope api.PermissionScope) api.SandboxSettings {\n\t\tif scope == api.ScopeGlobal {\n\t\t\treturn resp.Global.Clone()\n\t\t}\n\t\treturn resp.Project.Clone()\n\t}\n\n\treturn components.SandboxConfigEditor(components.SandboxConfigEditorProps{\n\t\tResponse:     resp,\n\t\tSessionMode:  sessionMode,\n\t\tLockedKnobs:  sandboxLockedKnobs(resp),\n\t\tSaving:       saving(),\n\t\tErrorMessage: errMsg(),\n\t\tOnSetMode: func(scope api.PermissionScope, mode api.SandboxMode) {\n\t\t\tsettings := scopeSettings(scope)\n\t\t\tsettings.Mode = mode\n\t\t\tsetSaving(true)\n\t\t\tupdateMutation.Mutate(sandboxUpdateParams{scope: scope, settings: settings})\n\t\t},\n\t\tOnToggleKnob: func(scope api.PermissionScope, knob components.SandboxPolicyKnob, value *bool) {\n\t\t\tsettings := scopeSettings(scope)\n\t\t\tswitch knob {\n\t\t\tcase components.KnobFailIfUnavailable:\n\t\t\t\tsettings.FailIfUnavailable = value\n\t\t\tcase components.KnobAllowUnsandboxed:\n\t\t\t\tsettings.AllowUnsandboxed = value\n\t\t\tcase components.KnobAutoAllowBash:\n\t\t\t\tsettings.AutoAllowBash = value\n\t\t\tdefault:\n\t\t\t\tsetSaving(false)\n\t\t\t\tsetErrMsg(fmt.Sprintf(\"unknown sandbox setting %q\", knob))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsetSaving(true)\n\t\t\tupdateMutation.Mutate(sandboxUpdateParams{scope: scope, settings: settings})\n\t\t},\n\t\tOnAddExcluded: func(scope api.PermissionScope, pattern string) {\n\t\t\tsettings := scopeSettings(scope)\n\t\t\tsettings.ExcludedCommands = append(settings.ExcludedCommands, pattern)\n\t\t\tsetSaving(true)\n\t\t\tupdateMutation.Mutate(sandboxUpdateParams{scope: scope, settings: settings})\n\t\t},\n\t\tOnEditExcluded: func(scope api.PermissionScope, oldPattern, newPattern string) {\n\t\t\tsettings := scopeSettings(scope)\n\t\t\tedited := make([]string, 0, len(settings.ExcludedCommands))\n\t\t\treplaced := false\n\t\t\tfor _, p := range settings.ExcludedCommands {\n\t\t\t\tif p == oldPattern \u0026\u0026 !replaced {\n\t\t\t\t\tedited = append(edited, newPattern)\n\t\t\t\t\treplaced = true\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif p == newPattern {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tedited = append(edited, p)\n\t\t\t}\n\t\t\tsettings.ExcludedCommands = edited\n\t\t\tsetSaving(true)\n\t\t\tupdateMutation.Mutate(sandboxUpdateParams{scope: scope, settings: settings})\n\t\t},\n\t\tOnRemoveExcluded: func(scope api.PermissionScope, pattern string) {\n\t\t\tsettings := scopeSettings(scope)\n\t\t\tkept := make([]string, 0, len(settings.ExcludedCommands))\n\t\t\tfor _, p := range settings.ExcludedCommands {\n\t\t\t\tif p != pattern {\n\t\t\t\t\tkept = append(kept, p)\n\t\t\t\t}\n\t\t\t}\n\t\t\tsettings.ExcludedCommands = kept\n\t\t\tsetSaving(true)\n\t\t\tupdateMutation.Mutate(sandboxUpdateParams{scope: scope, settings: settings})\n\t\t},\n\t\tOnClearError: func() {\n\t\t\tsetErrMsg(\"\")\n\t\t},\n\t\tOnClose: func() {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendCommandOutput(\"/sandbox\", \"Exited /sandbox command\")\n\t\t},\n\t})\n})\n```\nSandboxBrowser renders an interactive sandbox configuration editor inside \\\u003cSlot /\u003e.\n\n```go\nvar SessionBrowser = trail.FC(\"SessionBrowser\", func(slotID string) trail.Node {\n\tc := store.Client()\n\n\tresult := wind.Use(\"sessions\", promise.WrapWithProps(func(ctx context.Context, _ string) ([]api.Session, error) {\n\t\tif c == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn c.ListSessions(ctx)\n\t}), wind.Options{Enabled: c != nil})\n\n\ttype renamePayload struct {\n\t\tid    string\n\t\ttitle string\n\t}\n\trenameMutation := wind.UseMutation(func(ctx context.Context, p renamePayload) *promise.Promise[*api.Session] {\n\t\treturn promise.Wrap(func(ctx context.Context) (*api.Session, error) {\n\t\t\tif c == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"client unavailable\")\n\t\t\t}\n\t\t\treturn c.UpdateSession(ctx, p.id, api.UpdateSessionRequest{Title: p.title})\n\t\t})(ctx)\n\t}, wind.MutationOptions[renamePayload, *api.Session]{\n\t\tOnSuccess: func(s *api.Session, v renamePayload, mc wind.MutationContext) {\n\t\t\tresult.Refetch()\n\t\t\tif store.GetSession().Session != nil \u0026\u0026 store.GetSession().Session.ID == v.id {\n\t\t\t\tstore.SetSession(s)\n\t\t\t}\n\t\t},\n\t\tOnError: func(err error, _ renamePayload, _ wind.MutationContext) {\n\t\t\tstore.AppendError(\"Error renaming session\", err.Error())\n\t\t},\n\t})\n\n\tdeleteMutation := wind.UseMutation(func(ctx context.Context, id string) *promise.Promise[any] {\n\t\treturn promise.Wrap(func(ctx context.Context) (any, error) {\n\t\t\tif c == nil {\n\t\t\t\treturn nil, fmt.Errorf(\"client unavailable\")\n\t\t\t}\n\t\t\terr := c.DeleteSession(ctx, id)\n\t\t\treturn nil, err\n\t\t})(ctx)\n\t}, wind.MutationOptions[string, any]{\n\t\tOnSuccess: func(_ any, id string, mc wind.MutationContext) {\n\t\t\tresult.Refetch()\n\t\t\tif store.GetSession().Session != nil \u0026\u0026 store.GetSession().Session.ID == id {\n\t\t\t\tstore.NewDraftSession(\"\")\n\t\t\t}\n\t\t},\n\t\tOnError: func(err error, _ string, _ wind.MutationContext) {\n\t\t\tstore.AppendError(\"Error deleting session\", err.Error())\n\t\t},\n\t})\n\n\tkitex.UseEffect(func() {\n\t\tif c == nil {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendNotice(\"Client unavailable.\")\n\t\t\treturn\n\t\t}\n\t\tif result.IsLoading {\n\t\t\treturn\n\t\t}\n\t\tif result.IsError {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendError(\"Error\", result.Error.Error())\n\t\t} else if len(result.Data) == 0 {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendCommandOutput(\"/sessions\", \"No sessions found.\")\n\t\t}\n\t}, []any{c == nil, result.IsLoading, result.IsError, result.Error, len(result.Data)})\n\n\tif c == nil {\n\t\treturn nil\n\t}\n\tif result.IsLoading {\n\t\treturn loadingHint(\"Loading sessions...\")\n\t}\n\tif result.IsError || len(result.Data) == 0 {\n\t\treturn nil\n\t}\n\n\tactiveID := \"\"\n\tif store.GetSession().Session != nil {\n\t\tactiveID = store.GetSession().Session.ID\n\t}\n\n\topts := make([]uicomponents.Option, len(result.Data))\n\tfor i, s := range result.Data {\n\t\ttitle := strings.TrimSpace(s.Title)\n\t\tif title == \"\" {\n\t\t\ttitle = \"Untitled\"\n\t\t}\n\t\tmodel := strings.TrimSpace(s.Config.Model)\n\t\tif model == \"\" {\n\t\t\tmodel = \"-\"\n\t\t}\n\t\trelTime := humanize.Time(s.UpdatedAt)\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue:   s.ID,\n\t\t\tLabel:   title,\n\t\t\tCells:   []string{title, model, relTime},\n\t\t\tCurrent: activeID != \"\" \u0026\u0026 s.ID == activeID,\n\t\t}\n\t}\n\n\tpickerProps := components.NewPicker(\"Sessions\", opts, func(opt uicomponents.Option) {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.SwitchSession(opt.Value)\n\t})\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: 0},\n\t\t{Width: 24, Align: style.TextAlignLeft},\n\t\t{Width: 26, Align: style.TextAlignRight},\n\t}\n\tpickerProps.Filterable = true\n\tpickerProps.Bindings = []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"Switch\"},\n\t\t{Key: \"f2\", Label: \"Rename\"},\n\t\t{Key: \"f3\", Label: \"Fork\"},\n\t\t{Key: \"f4\", Label: \"Delete\"},\n\t\t{Key: \"esc\", Label: \"Cancel\"},\n\t}\n\tpickerProps.Keys = map[string]func(uicomponents.Option){\n\t\t\"f3\": func(opt uicomponents.Option) {\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.ForkSession(opt.Value, \"\")\n\t\t},\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/sessions\", \"Exited /sessions command\")\n\t}\n\tpickerProps.InputActions = map[string]components.InputAction{\n\t\t\"f2\": {\n\t\t\tPrompt: \"Rename session:\",\n\t\t\tInitialValue: func(opt uicomponents.Option) string {\n\t\t\t\treturn opt.Label\n\t\t\t},\n\t\t\tOnSubmit: func(opt uicomponents.Option, val string) {\n\t\t\t\trenameMutation.Mutate(renamePayload{id: opt.Value, title: val})\n\t\t\t},\n\t\t},\n\t}\n\tpickerProps.ConfirmActions = map[string]components.ConfirmAction{\n\t\t\"f4\": {\n\t\t\tPrompt: func(opt uicomponents.Option) string {\n\t\t\t\treturn fmt.Sprintf(\"Delete session %q?\", opt.Label)\n\t\t\t},\n\t\t\tOnConfirm: func(opt uicomponents.Option) {\n\t\t\t\tdeleteMutation.Mutate(opt.Value)\n\t\t\t},\n\t\t},\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nSessionBrowser renders an interactive session browser with rename (f2), fork (f3), and delete (f4).\n\n```go\nvar SkillsBrowser = trail.FC(\"SkillsBrowser\", func(slotID string) trail.Node {\n\tskillsPtr := store.UseApp(func(s store.AppState) *[]api.Skill { return s.Skills })\n\tselectedSkill, setSelectedSkill := kitex.UseState[*api.Skill](nil)\n\tnotice, setNotice := kitex.UseState(\"\")\n\tisReloading, setIsReloading := kitex.UseState(false)\n\n\tvar skills []api.Skill\n\tif skillsPtr != nil {\n\t\tskills = *skillsPtr\n\t}\n\n\tc := store.Client()\n\tkitex.UseEffect(func() {\n\t\tif skillsPtr == nil \u0026\u0026 c != nil {\n\t\t\tgo func() {\n\t\t\t\tif sks, err := c.ListSkills(context.Background()); err == nil {\n\t\t\t\t\tstore.SetWorkspaceSkills(sks)\n\t\t\t\t}\n\t\t\t}()\n\t\t}\n\t}, []any{skillsPtr == nil, c == nil})\n\n\tdoReload := func() {\n\t\tif isReloading() {\n\t\t\treturn\n\t\t}\n\t\tsetIsReloading(true)\n\t\tsetNotice(\"Reloading workspace skills via registry.Reload...\")\n\t\tgo func() {\n\t\t\tdefer setIsReloading(false)\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\t\t\tdefer cancel()\n\t\t\terr := store.ReloadWorkspace(ctx)\n\t\t\tif err != nil {\n\t\t\t\tsetNotice(\"Failed to reload workspace: \" + err.Error())\n\t\t\t} else {\n\t\t\t\tcount := 0\n\t\t\t\tif s := store.GetApp().Skills; s != nil {\n\t\t\t\t\tcount = len(*s)\n\t\t\t\t}\n\t\t\t\tsetNotice(fmt.Sprintf(\"Workspace reloaded via registry.Reload (%d skills available).\", count))\n\t\t\t}\n\t\t}()\n\t}\n\n\tif sel := selectedSkill(); sel != nil {\n\t\treturn skillMarkdownViewer(skillMarkdownProps{\n\t\t\tslotID:  slotID,\n\t\t\tskill:   *sel,\n\t\t\tonClose: func() { setSelectedSkill(nil) },\n\t\t})\n\t}\n\n\tif len(skills) == 0 {\n\t\treturn emptySkillsView(emptySkillsViewProps{\n\t\t\tslotID:   slotID,\n\t\t\tnotice:   notice(),\n\t\t\tonReload: doReload,\n\t\t})\n\t}\n\n\ttitle := fmt.Sprintf(\"Skills (%d available)\", len(skills))\n\tif n := notice(); n != \"\" {\n\t\ttitle = fmt.Sprintf(\"Skills (%d available) — %s\", len(skills), n)\n\t}\n\n\tscheme := theme.UseTheme()\n\n\twinSize := trail.UseWindowSize()\n\tavailDescWidth := 0\n\tif winSize.Width \u003e 0 {\n\t\tavailDescWidth = max(20, winSize.Width-30-10-8-4)\n\t}\n\n\topts := make([]uicomponents.Option, len(skills))\n\tfor i, sk := range skills {\n\t\tscope := SkillScope(sk)\n\t\testTokens := sk.Tokens\n\t\tif estTokens == 0 \u0026\u0026 sk.Instructions != \"\" {\n\t\t\testTokens = EstimateSkillTokens(sk.Instructions)\n\t\t}\n\t\ttokStr := format.Tokens(estTokens)\n\n\t\tscopeCol := fmt.Sprintf(\"[%s]\", scope)\n\t\tdesc := format.CompactSingleLine(sk.Description, availDescWidth)\n\n\t\tdescNode := trail.Box(trail.BoxProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlexDirection(style.FlexRow).\n\t\t\t\tWidth(style.Percent(100)).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden),\n\t\t}, trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlex(0, 1).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden).\n\t\t\t\tWhiteSpace(style.WhiteSpacePre).\n\t\t\t\tForeground(scheme.Color.Text.Muted),\n\t\t}, trail.Text(desc)))\n\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue:       sk.Name,\n\t\t\tLabel:       sk.Name,\n\t\t\tDescription: desc,\n\t\t\tCells:       []string{sk.Name, scopeCol, tokStr, desc},\n\t\t\tCellNodes:   []trail.Node{nil, nil, nil, descNode},\n\t\t}\n\t}\n\n\tpickerProps := components.NewPicker(title, opts, func(opt uicomponents.Option) {\n\t\tfor i := range skills {\n\t\t\tif skills[i].Name == opt.Value {\n\t\t\t\tsetSelectedSkill(\u0026skills[i])\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t})\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: 30, Align: style.TextAlignLeft},\n\t\t{Width: 10, Align: style.TextAlignLeft},\n\t\t{Width: 8, Align: style.TextAlignRight},\n\t\t{Width: 0, Align: style.TextAlignLeft},\n\t}\n\tpickerProps.Filterable = false\n\tpickerProps.Bindings = []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"Inspect runbook\"},\n\t\t{Key: \"r\", Label: \"Reload workspace\"},\n\t\t{Key: \"esc\", Label: \"Close\"},\n\t}\n\tpickerProps.Keys = map[string]func(uicomponents.Option){\n\t\t\"r\": func(_ uicomponents.Option) {\n\t\t\tdoReload()\n\t\t},\n\t\t\"i\": func(opt uicomponents.Option) {\n\t\t\tfor i := range skills {\n\t\t\t\tif skills[i].Name == opt.Value {\n\t\t\t\t\tsetSelectedSkill(\u0026skills[i])\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/skills\", \"Exited /skills command\")\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nSkillsBrowser renders an interactive skills list and markdown inspector inside \\\u003cSlot /\u003e.\n\n```go\nvar StatusLineEditor = trail.FC(\"StatusLineEditor\", func(slotID string) trail.Node {\n\tscheme := theme.UseTheme()\n\n\toriginal := kitex.UseRef(store.GetStatusLine())\n\tissues := kitex.UseRef(store.GetStatusLineDropped())\n\tdraft, setDraft := kitex.UseState(original.Current)\n\tall := statusLineEditorSegments(draft().Rows)\n\tcursor := uicomponents.UseCursor(len(all), 0)\n\n\ttrail.UseInput(func(_ string, k event.KeyEvent) {\n\t\tif cursor.HandleKey(k) {\n\t\t\treturn\n\t\t}\n\t\tid := all[cursor.Index]\n\t\tcfg := draft()\n\t\tcfg.Rows = slices.Clone(cfg.Rows)\n\t\trow, index := statusLineSegmentPosition(cfg.Rows, id)\n\t\tswitch {\n\t\tcase k.MatchString(\"esc\", \"escape\"):\n\t\t\tif _, err := store.ApplyStatusLine(original.Current); err != nil {\n\t\t\t\tstore.AppendError(\"/statusline\", \"Failed to restore status line: \"+err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendCommandOutput(\"/statusline\", \"Exited /statusline without saving.\")\n\t\t\treturn\n\t\tcase k.MatchString(\"space\", \"enter\", \"t\"):\n\t\t\tif row \u003c 0 {\n\t\t\t\tdefaultRow, _ := statusLineSegmentPosition(store.DefaultStatusLineRows, id)\n\t\t\t\tcfg.Rows[defaultRow] = append(slices.Clone(cfg.Rows[defaultRow]), id)\n\t\t\t} else {\n\t\t\t\tif len(cfg.Rows[0])+len(cfg.Rows[1]) == 1 {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tcfg.Rows[row] = slices.Delete(slices.Clone(cfg.Rows[row]), index, index+1)\n\t\t\t}\n\t\tcase k.MatchString(\"left\", \"h\", \"right\", \"l\"):\n\t\t\tif row \u003c 0 {\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttarget := index + 1\n\t\t\tif k.MatchString(\"left\", \"h\") {\n\t\t\t\ttarget = index - 1\n\t\t\t}\n\t\t\tif target \u003c 0 || target \u003e= len(cfg.Rows[row]) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tsegments := slices.Clone(cfg.Rows[row])\n\t\t\tsegments[index], segments[target] = segments[target], segments[index]\n\t\t\tcfg.Rows[row] = segments\n\t\tcase k.MatchString(\"r\"):\n\t\t\tif row \u003c 0 {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tother := 1 - row\n\t\t\tcfg.Rows[row] = slices.Delete(slices.Clone(cfg.Rows[row]), index, index+1)\n\t\t\tcfg.Rows[other] = append(slices.Clone(cfg.Rows[other]), id)\n\t\tcase k.MatchString(\"c\"):\n\t\t\tcfg.Compact = !cfg.Compact\n\t\tcase k.MatchString(\"s\"):\n\t\t\tdropped, err := store.SaveStatusLine(cfg)\n\t\t\tif err != nil {\n\t\t\t\tstore.AppendError(\"/statusline\", \"Failed to save statusline.json: \"+err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tmsg := \"Status line saved to statusline.json.\"\n\t\t\tif len(dropped) \u003e 0 {\n\t\t\t\tmsg += \" Ignored entries: \" + strings.Join(dropped, \", \") + \".\"\n\t\t\t}\n\t\t\tstore.RemoveSlot(slotID)\n\t\t\tstore.AppendCommandOutput(\"/statusline\", msg)\n\t\t\treturn\n\t\tdefault:\n\t\t\treturn\n\t\t}\n\t\tif _, err := store.ApplyStatusLine(cfg); err != nil {\n\t\t\tstore.AppendError(\"/statusline\", \"Failed to preview status line: \"+err.Error())\n\t\t\treturn\n\t\t}\n\t\tsetDraft(cfg)\n\t\tcursor.Set(slices.Index(statusLineEditorSegments(cfg.Rows), id))\n\t})\n\n\toptions := make([]uicomponents.Option, 0, len(all))\n\tfor _, id := range all {\n\t\ti := slices.IndexFunc(statusLineSegmentLabels, func(segment statusLineSegmentLabel) bool {\n\t\t\treturn segment.id == id\n\t\t})\n\t\toptions = append(options, uicomponents.Option{\n\t\t\tValue: string(id),\n\t\t\tCells: []string{string(id), statusLineSegmentLabels[i].description},\n\t\t})\n\t}\n\n\ttitleStyle := style.S().Bold(true).Foreground(scheme.Color.Text.Primary)\n\tcompactStyle := style.S().Foreground(scheme.Color.Mode.Plan)\n\tvar diagnostics trail.Node\n\tif len(issues.Current) \u003e 0 {\n\t\tdiagnostics = trail.Box(trail.BoxProps{}, trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().Foreground(scheme.Color.Text.Warning).OverflowWrap(style.OverflowWrapAnywhere),\n\t\t}, trail.Text(\"Ignored entries: \"+strings.Join(issues.Current, \", \"))))\n\t}\n\treturn trail.Box(trail.BoxProps{\n\t\tStyle: style.S().FlexDirection(style.FlexColumn).Width(style.Percent(100)),\n\t},\n\t\ttrail.Box(trail.BoxProps{Style: titleStyle}, trail.Text(\"Status line configuration\")),\n\t\tdiagnostics,\n\t\tuicomponents.OptionList(uicomponents.OptionListProps{\n\t\t\tOptions:  options,\n\t\t\tSelected: cursor.Index,\n\t\t\tColumns:  []uicomponents.Column{{Width: 12}, {}},\n\t\t\tGroupLabel: func(opt uicomponents.Option) string {\n\t\t\t\trow, _ := statusLineSegmentPosition(draft().Rows, store.StatusLineSegmentID(opt.Value))\n\t\t\t\tif row \u003c 0 {\n\t\t\t\t\treturn \"Disabled\"\n\t\t\t\t}\n\t\t\t\treturn fmt.Sprintf(\"Row %d\", row+1)\n\t\t\t},\n\t\t}),\n\t\ttrail.Box(trail.BoxProps{Style: compactStyle}, trail.Text(fmt.Sprintf(\"compact: %s (c to toggle)\", onOff(draft().Compact)))),\n\t\tuicomponents.KeyboardHint(uicomponents.KeyboardHintProps{\n\t\t\tBindings: []uicomponents.KeyBinding{\n\t\t\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t\t\t{Key: \"Space\", Label: \"Toggle segment\"},\n\t\t\t\t{Key: \"←/→\", Label: \"Reorder in row\"},\n\t\t\t\t{Key: \"r\", Label: \"Move to other row\"},\n\t\t\t\t{Key: \"C\", Label: \"Compact\"},\n\t\t\t\t{Key: \"S\", Label: \"Save\"},\n\t\t\t\t{Key: \"Esc\", Label: \"Discard \u0026 exit\"},\n\t\t\t},\n\t\t}),\n\t)\n})\n```\nStatusLineEditor renders an interactive status line configuration view inside \\\u003cSlot /\u003e. Edits apply live (the rendered status line below previews them); s saves to statusline.json, esc discards and restores.\n\n```go\nvar SubagentViewer = trail.FC(\"SubagentViewer\", func(props SubagentViewerProps) trail.Node {\n\tscheme := theme.UseTheme()\n\tallSubs := store.UseSubagents()\n\tvar sub *api.Session\n\tfor i := range allSubs {\n\t\tif allSubs[i].ID == props.SubagentID {\n\t\t\tsub = \u0026allSubs[i]\n\t\t\tbreak\n\t\t}\n\t}\n\n\tsubSession, setSubSession := kitex.UseState[*api.Session](nil)\n\tif sub == nil \u0026\u0026 subSession() != nil {\n\t\tsub = subSession()\n\t}\n\n\tconv := kitex.UseMemo(func() *store.SubagentConversation {\n\t\treturn store.NewSubagentConversation(props.SubagentID)\n\t}, []any{props.SubagentID})\n\n\trev, setRev := kitex.UseState(0)\n\tscroll := uicomponents.UseScroll(uicomponents.ScrollOptions{\n\t\tFollowTail: true,\n\t\tExtraDeps:  []any{rev()},\n\t})\n\n\tkitex.UseEffectCleanup(func() func() {\n\t\tctx, cancel := context.WithCancel(context.Background())\n\t\tc := store.Client()\n\t\tif c == nil {\n\t\t\treturn cancel\n\t\t}\n\t\tgo func() {\n\t\t\tlocalRev := 0\n\t\t\tif loaded, err := c.GetSession(ctx, props.SubagentID); err == nil \u0026\u0026 loaded != nil {\n\t\t\t\tsetSubSession(loaded)\n\t\t\t\tif tl, err := c.Timeline(ctx, props.SubagentID); err == nil {\n\t\t\t\t\tconv.LoadTimelineSnapshot(loaded, tl, loaded.PendingQuestions)\n\t\t\t\t}\n\t\t\t\tif len(loaded.PendingPermissions) \u003e 0 {\n\t\t\t\t\tconv.SeedPermissions(loaded.PendingPermissions)\n\t\t\t\t}\n\t\t\t\tconv.ReconcileStreamStatus(loaded)\n\t\t\t\tlocalRev++\n\t\t\t\tsetRev(localRev)\n\t\t\t}\n\t\t\tfor ev, err := range c.Watch(ctx, \"\", api.SessionStreamTopic(props.SubagentID)) {\n\t\t\t\tif err != nil {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tconv.ApplyEvent(ev)\n\t\t\t\tlocalRev++\n\t\t\t\tsetRev(localRev)\n\t\t\t}\n\t\t}()\n\t\treturn cancel\n\t}, []any{props.SubagentID})\n\n\tvar perms []api.PermissionRequest\n\tvar questions []api.QuestionRequest\n\tif sub != nil {\n\t\tperms = sub.PendingPermissions\n\t\tquestions = sub.PendingQuestions\n\t}\n\tif len(perms) == 0 {\n\t\tperms = conv.PendingPermissions()\n\t}\n\tif len(questions) == 0 {\n\t\tquestions = conv.PendingQuestions()\n\t}\n\thasPrompt := len(perms) \u003e 0 || len(questions) \u003e 0\n\n\ttrail.UseInput(func(input string, k event.KeyEvent) {\n\t\tif k.MatchString(\"esc\", \"escape\") {\n\t\t\tif props.OnClose != nil {\n\t\t\t\tprops.OnClose()\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tif !hasPrompt {\n\t\t\tif scroll.HandleKey(input, k) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif k.MatchString(\"x\") \u0026\u0026 sub != nil \u0026\u0026 sub.Status != api.StatusIdle {\n\t\t\t\t_ = store.KillSubagent(props.SubagentID)\n\t\t\t}\n\t\t\treturn\n\t\t}\n\n\t\tif k.MatchString(\"pgup\", \"ctrl+u\", \"b\", \"ctrl+b\", \"pgdown\", \"ctrl+d\", \"f\", \"ctrl+f\") {\n\t\t\tscroll.HandleKey(input, k)\n\t\t}\n\t})\n\n\tborder := style.\n\t\tSingleBorder().\n\t\tTop(true).\n\t\tBottom(false).\n\t\tLeft(false).\n\t\tRight(false).\n\t\tColor(scheme.Color.Border.Default)\n\n\tagentName := \"subagent\"\n\ttitle := props.SubagentID\n\tstatus := api.StatusExecuting\n\tisWorktree := false\n\n\tif sub != nil {\n\t\tif sub.Config.Agent != \"\" {\n\t\t\tagentName = sub.Config.Agent\n\t\t}\n\t\tif strings.TrimSpace(sub.Title) != \"\" {\n\t\t\ttitle = strings.TrimSpace(strings.ReplaceAll(sub.Title, \"\\n\", \" \"))\n\t\t}\n\t\tif sub.Status != \"\" {\n\t\t\tstatus = sub.Status\n\t\t}\n\t\tif sub.WorkDir != \"\" {\n\t\t\tmainSess := store.GetSession().Session\n\t\t\tif mainSess != nil \u0026\u0026 mainSess.WorkDir != \"\" \u0026\u0026 sub.WorkDir != mainSess.WorkDir {\n\t\t\t\tisWorktree = true\n\t\t\t}\n\t\t}\n\t}\n\tagentColor := components.SubagentColor(scheme, agentName)\n\n\theaderChildren := []trail.Node{\n\t\ttrail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().Bold(true).Foreground(agentColor),\n\t\t}, trail.Text(\"@\"+agentName)),\n\t}\n\tif sub != nil {\n\t\theaderChildren = append(headerChildren, components.SubagentModelBadge(scheme, *sub))\n\t}\n\theaderChildren = append(headerChildren, trail.Span(trail.SpanProps{\n\t\tStyle: style.S().Bold(true).Foreground(scheme.Color.Text.Primary),\n\t}, trail.Text(\" · \"+title+\" (\"+formatSubagentStatus(status)+\")\")))\n\tif isWorktree {\n\t\theaderChildren = append(headerChildren, trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().Foreground(scheme.Color.Text.Secondary),\n\t\t}, trail.Text(\" · worktree\")))\n\t}\n\tif !scroll.AutoScroll \u0026\u0026 scroll.Pos \u003e 0 {\n\t\theaderChildren = append(headerChildren, trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().Foreground(scheme.Color.Text.Secondary),\n\t\t}, trail.Text(\" [scrolled up]\")))\n\t}\n\n\theaderNode := trail.Box(trail.BoxProps{\n\t\tStyle: style.S().\n\t\t\tDisplay(style.DisplayFlex).\n\t\t\tFlexDirection(style.FlexRow).\n\t\t\tWidth(style.Percent(100)).\n\t\t\tMargin(0, 0, 1, 0),\n\t}, headerChildren...)\n\n\tchatChildren := make([]trail.Node, 0)\n\tfor _, msg := range conv.Messages() {\n\t\tchatChildren = append(chatChildren, components.Message(components.MessageProps{Message: msg}))\n\t}\n\n\tif conv.IsStreaming() \u0026\u0026 status != api.StatusIdle \u0026\u0026 status != api.StatusWaitingPermission \u0026\u0026 status != api.StatusWaitingQuestion \u0026\u0026 status != api.StatusWaitingPlanReview {\n\t\tstartedAt, input, output := conv.TurnStats()\n\t\ttodos := conv.Todos()\n\t\tactiveText := \"\"\n\t\tfor _, it := range todos {\n\t\t\tif it.Status == \"in_progress\" {\n\t\t\t\tactiveText = it.Content\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tspinnerProps := components.SpinnerProps{\n\t\t\tStatus:     conv.SessionStatus(),\n\t\t\tActiveText: activeText,\n\t\t\tStartedAt:  startedAt,\n\t\t\tInput:      input,\n\t\t\tOutput:     output,\n\t\t}\n\t\tchatChildren = append(chatChildren, components.Spinner(spinnerProps))\n\t}\n\n\tchatBox := trail.Box(trail.BoxProps{\n\t\tRef: scroll.Ref,\n\t\tStyle: style.S().\n\t\t\tMaxHeight(style.Cells(18)).\n\t\t\tOverflowY(style.OverflowAuto).\n\t\t\tScrollbarY(true).\n\t\t\tWidth(style.Percent(100)).\n\t\t\tFlexDirection(style.FlexColumn).\n\t\t\tMargin(0, 0, 1, 0),\n\t}, chatChildren...)\n\n\tvar promptNode trail.Node\n\tif len(perms) \u003e 0 {\n\t\tpromptNode = components.PermissionPrompt(components.PermissionPromptProps{\n\t\t\tRequest: perms[0],\n\t\t\tOnDecision: func(req api.PermissionRequest, dec api.PermissionDecision) {\n\t\t\t\tconv.RemovePermission(req.ID)\n\t\t\t\tstore.DecideSubagentPermission(props.SubagentID, req, dec)\n\t\t\t},\n\t\t})\n\t} else if len(questions) \u003e 0 {\n\t\tpromptNode = components.QuestionPrompt(components.QuestionPromptProps{\n\t\t\tRequest: questions[0],\n\t\t\tOnSubmit: func(req api.QuestionRequest, resp api.QuestionResponse, done func(error)) {\n\t\t\t\tconv.RemoveQuestion(req.ID)\n\t\t\t\tstore.SubmitSubagentQuestion(props.SubagentID, req, resp, done)\n\t\t\t},\n\t\t})\n\t}\n\n\tvar bindings []uicomponents.KeyBinding\n\tif !hasPrompt {\n\t\tbindings = append(bindings,\n\t\t\tuicomponents.KeyBinding{Key: \"↑/↓ or j/k\", Label: \"Scroll\"},\n\t\t\tuicomponents.KeyBinding{Key: \"pgup/pgdn\", Label: \"Page\"},\n\t\t\tuicomponents.KeyBinding{Key: \"g/G\", Label: \"Top/Bottom\"},\n\t\t)\n\t} else {\n\t\tbindings = append(bindings,\n\t\t\tuicomponents.KeyBinding{Key: \"pgup/pgdn\", Label: \"Scroll chat\"},\n\t\t)\n\t}\n\tif sub != nil \u0026\u0026 sub.Status != api.StatusIdle {\n\t\tbindings = append(bindings, uicomponents.KeyBinding{Key: \"x\", Label: \"Kill subagent\"})\n\t}\n\tbindings = append(bindings, uicomponents.KeyBinding{Key: \"esc\", Label: \"Return\"})\n\n\thintBar := uicomponents.KeyboardHint(uicomponents.KeyboardHintProps{\n\t\tBindings: bindings,\n\t})\n\n\tmainChildren := []trail.Node{headerNode, chatBox}\n\tif promptNode != nil {\n\t\tmainChildren = append(mainChildren, promptNode)\n\t}\n\tmainChildren = append(mainChildren, hintBar)\n\n\treturn trail.Box(trail.BoxProps{\n\t\tStyle: style.S().\n\t\t\tBorder(border).\n\t\t\tWidth(style.Percent(100)).\n\t\t\tFlexDirection(style.FlexColumn),\n\t}, mainChildren...)\n})\n```\nSubagentViewer renders a live, non-static, navigable chat view of a subagent session.\n\n```go\nvar SubagentsBrowser = trail.FC(\"SubagentsBrowser\", func(slotID string) trail.Node {\n\tscheme := theme.UseTheme()\n\tshowAll, setShowAll := kitex.UseState(false)\n\tallSubs := store.UseSubagents()\n\n\tselectedSubagentID, setSelectedSubagentID := kitex.UseState(\"\")\n\n\tvar visibleSubs []api.Session\n\tif showAll() {\n\t\tvisibleSubs = allSubs\n\t} else {\n\t\tfor _, s := range allSubs {\n\t\t\tif s.Status != \"\" \u0026\u0026 s.Status != api.StatusIdle {\n\t\t\t\tvisibleSubs = append(visibleSubs, s)\n\t\t\t}\n\t\t}\n\t}\n\n\ttoggleLabel := \"Show all\"\n\tif showAll() {\n\t\ttoggleLabel = \"Hide idle\"\n\t}\n\n\ttitle := \"Subagents\"\n\tif showAll() {\n\t\ttitle = \"Subagents (all)\"\n\t}\n\n\tif selID := selectedSubagentID(); selID != \"\" {\n\t\treturn SubagentViewer(SubagentViewerProps{\n\t\t\tSubagentID: selID,\n\t\t\tOnClose: func() {\n\t\t\t\tsetSelectedSubagentID(\"\")\n\t\t\t},\n\t\t})\n\t}\n\n\tif len(visibleSubs) == 0 {\n\t\temptyMsg := \"  No subagents.\"\n\t\tif !showAll() \u0026\u0026 len(allSubs) \u003e 0 {\n\t\t\temptyMsg = \"  No running subagents.\"\n\t\t}\n\t\treturn emptySubagentsView(emptySubagentsViewProps{\n\t\t\tslotID:          slotID,\n\t\t\ttitle:           title,\n\t\t\temptyMsg:        emptyMsg,\n\t\t\ttoggleLabel:     toggleLabel,\n\t\t\thasAllSubagents: len(allSubs) \u003e 0 || showAll(),\n\t\t\tonToggle: func() {\n\t\t\t\tif len(allSubs) \u003e 0 || showAll() {\n\t\t\t\t\tsetShowAll(!showAll())\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t}\n\n\tmainSess := store.GetSession().Session\n\topts := make([]uicomponents.Option, len(visibleSubs))\n\tfor i, s := range visibleSubs {\n\t\ttimeStr := \"--:--:--\"\n\t\tif !s.CreatedAt.IsZero() {\n\t\t\ttimeStr = s.CreatedAt.Local().Format(\"15:04:05\")\n\t\t}\n\n\t\tagentName := cmp.Or(s.Config.Agent, \"subagent\")\n\t\ttaskTitle := strings.TrimSpace(strings.ReplaceAll(s.Title, \"\\n\", \" \"))\n\t\tif taskTitle == \"\" {\n\t\t\ttaskTitle = s.ID\n\t\t}\n\n\t\tlabel := fmt.Sprintf(\"[%s] @%s · %s\", timeStr, agentName, taskTitle)\n\t\tif s.WorkDir != \"\" \u0026\u0026 mainSess != nil \u0026\u0026 mainSess.WorkDir != \"\" \u0026\u0026 s.WorkDir != mainSess.WorkDir {\n\t\t\tlabel += \" (worktree)\"\n\t\t}\n\n\t\tvar durStr string\n\t\tif s.CreatedAt.IsZero() {\n\t\t\tdurStr = \"-\"\n\t\t} else if s.Status != api.StatusIdle {\n\t\t\tdurStr = formatSubagentDuration(time.Since(s.CreatedAt))\n\t\t} else if !s.UpdatedAt.IsZero() {\n\t\t\tdurStr = formatSubagentDuration(s.UpdatedAt.Sub(s.CreatedAt))\n\t\t} else {\n\t\t\tdurStr = \"-\"\n\t\t}\n\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue: s.ID,\n\t\t\tLabel: label,\n\t\t\tCells: []string{label, formatSubagentStatus(s.Status), durStr},\n\t\t\tIcon:  components.SubagentModelBadge(scheme, s),\n\t\t}\n\t}\n\n\tvar hasKillable bool\n\tfor _, s := range visibleSubs {\n\t\tif s.Status != api.StatusIdle {\n\t\t\thasKillable = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tbindings := []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"Inspect\"},\n\t}\n\tif hasKillable {\n\t\tbindings = append(bindings, uicomponents.KeyBinding{Key: \"x\", Label: \"Kill\"})\n\t}\n\tbindings = append(bindings,\n\t\tuicomponents.KeyBinding{Key: \"a\", Label: toggleLabel},\n\t\tuicomponents.KeyBinding{Key: \"esc\", Label: \"Close\"},\n\t)\n\n\tpickerProps := components.NewPicker(title, opts, func(opt uicomponents.Option) {\n\t\tsetSelectedSubagentID(opt.Value)\n\t})\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: 0},\n\t\t{Width: 20, Align: style.TextAlignLeft},\n\t\t{Width: 14, Align: style.TextAlignRight},\n\t}\n\tpickerProps.Filterable = false\n\tpickerProps.Bindings = bindings\n\tpickerProps.Keys = map[string]func(uicomponents.Option){\n\t\t\"a\": func(_ uicomponents.Option) {\n\t\t\tsetShowAll(!showAll())\n\t\t},\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/subagents\", \"Exited /subagents command\")\n\t}\n\tpickerProps.ConfirmActions = map[string]components.ConfirmAction{\n\t\t\"x\": {\n\t\t\tDisabledReason: func(opt uicomponents.Option) string {\n\t\t\t\tfor _, s := range visibleSubs {\n\t\t\t\t\tif s.ID == opt.Value {\n\t\t\t\t\t\tif s.Status == api.StatusIdle {\n\t\t\t\t\t\t\treturn \"Subagent is already idle.\"\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn \"\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn \"\"\n\t\t\t},\n\t\t\tPrompt: func(opt uicomponents.Option) string {\n\t\t\t\tfor _, s := range visibleSubs {\n\t\t\t\t\tif s.ID == opt.Value {\n\t\t\t\t\t\tif s.Status == api.StatusIdle {\n\t\t\t\t\t\t\treturn \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn fmt.Sprintf(\"Kill subagent %s?\", opt.Label)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn \"\"\n\t\t\t},\n\t\t\tOnConfirm: func(opt uicomponents.Option) {\n\t\t\t\t_ = store.KillSubagent(opt.Value)\n\t\t\t},\n\t\t},\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nSubagentsBrowser renders an interactive subagents list and inline live viewer inside \\\u003cSlot /\u003e.\n\n```go\nvar TasksBrowser = trail.FC(\"TasksBrowser\", func(slotID string) trail.Node {\n\tshowAll, setShowAll := kitex.UseState(false)\n\tallTasks := store.UseTasks()\n\n\tselectedTaskID, setSelectedTaskID := kitex.UseState(\"\")\n\n\tvar visibleTasks []api.Task\n\tif showAll() {\n\t\tvisibleTasks = allTasks\n\t} else {\n\t\tfor _, t := range allTasks {\n\t\t\tif t.Status == api.TaskStatusRunning || t.Status == api.TaskStatusPending {\n\t\t\t\tvisibleTasks = append(visibleTasks, t)\n\t\t\t}\n\t\t}\n\t}\n\n\ttoggleLabel := \"Show all\"\n\tif showAll() {\n\t\ttoggleLabel = \"Hide completed\"\n\t}\n\n\ttitle := \"Background Tasks\"\n\tif showAll() {\n\t\ttitle = \"Background Tasks (all)\"\n\t}\n\n\tif selID := selectedTaskID(); selID != \"\" {\n\t\tvar sel *api.Task\n\t\tfor i := range allTasks {\n\t\t\tif allTasks[i].ID == selID {\n\t\t\t\tsel = \u0026allTasks[i]\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif sel != nil {\n\t\t\treturn taskOutputViewer(taskOutputProps{\n\t\t\t\ttask: *sel,\n\t\t\t\tonClose: func() {\n\t\t\t\t\tsetSelectedTaskID(\"\")\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\n\tif len(visibleTasks) == 0 {\n\t\temptyMsg := \"  No background tasks.\"\n\t\tif !showAll() \u0026\u0026 len(allTasks) \u003e 0 {\n\t\t\temptyMsg = \"  No running background tasks.\"\n\t\t}\n\t\treturn emptyTasksView(emptyTasksViewProps{\n\t\t\tslotID:      slotID,\n\t\t\ttitle:       title,\n\t\t\temptyMsg:    emptyMsg,\n\t\t\ttoggleLabel: toggleLabel,\n\t\t\thasAllTasks: len(allTasks) \u003e 0 || showAll(),\n\t\t\tonToggle: func() {\n\t\t\t\tif len(allTasks) \u003e 0 || showAll() {\n\t\t\t\t\tsetShowAll(!showAll())\n\t\t\t\t}\n\t\t\t},\n\t\t})\n\t}\n\n\topts := make([]uicomponents.Option, len(visibleTasks))\n\tfor i, t := range visibleTasks {\n\t\ttimeStr := \"--:--:--\"\n\t\tif !t.StartedAt.IsZero() {\n\t\t\ttimeStr = t.StartedAt.Local().Format(\"15:04:05\")\n\t\t}\n\n\t\ttitleStr := strings.TrimSpace(strings.ReplaceAll(t.Title, \"\\n\", \" \"))\n\t\tcmdStr := strings.TrimSpace(strings.ReplaceAll(t.Command, \"\\n\", \" \"))\n\n\t\tvar label string\n\t\tif titleStr != \"\" \u0026\u0026 cmdStr != \"\" \u0026\u0026 titleStr != cmdStr {\n\t\t\tlabel = fmt.Sprintf(\"[%s] %s (%s)\", timeStr, titleStr, cmdStr)\n\t\t} else {\n\t\t\tlabel = fmt.Sprintf(\"[%s] %s\", timeStr, cmp.Or(titleStr, cmdStr, t.ID))\n\t\t}\n\n\t\tdur := fmt.Sprintf(\"%dms\", t.DurationMs)\n\t\tif t.DurationMs \u003e= 1000 {\n\t\t\tdur = fmt.Sprintf(\"%.1fs\", float64(t.DurationMs)/1000.0)\n\t\t}\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue: t.ID,\n\t\t\tLabel: label,\n\t\t\tCells: []string{label, string(t.Status), dur},\n\t\t}\n\t}\n\n\tvar hasKillable bool\n\tfor _, t := range visibleTasks {\n\t\tif t.Status == api.TaskStatusRunning || t.Status == api.TaskStatusPending {\n\t\t\thasKillable = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tbindings := []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"View output\"},\n\t}\n\tif hasKillable {\n\t\tbindings = append(bindings, uicomponents.KeyBinding{Key: \"x\", Label: \"Kill\"})\n\t}\n\tbindings = append(bindings,\n\t\tuicomponents.KeyBinding{Key: \"a\", Label: toggleLabel},\n\t\tuicomponents.KeyBinding{Key: \"esc\", Label: \"Close\"},\n\t)\n\n\tpickerProps := components.NewPicker(title, opts, func(opt uicomponents.Option) {\n\t\tsetSelectedTaskID(opt.Value)\n\t})\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: 0},\n\t\t{Width: 14, Align: style.TextAlignLeft},\n\t\t{Width: 14, Align: style.TextAlignRight},\n\t}\n\tpickerProps.Filterable = false\n\tpickerProps.Bindings = bindings\n\tpickerProps.Keys = map[string]func(uicomponents.Option){\n\t\t\"a\": func(_ uicomponents.Option) {\n\t\t\tsetShowAll(!showAll())\n\t\t},\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/tasks\", \"Exited /tasks command\")\n\t}\n\tpickerProps.ConfirmActions = map[string]components.ConfirmAction{\n\t\t\"x\": {\n\t\t\tDisabledReason: func(opt uicomponents.Option) string {\n\t\t\t\tfor _, t := range visibleTasks {\n\t\t\t\t\tif t.ID == opt.Value {\n\t\t\t\t\t\tif t.Status != api.TaskStatusRunning \u0026\u0026 t.Status != api.TaskStatusPending {\n\t\t\t\t\t\t\treturn fmt.Sprintf(\"Task is already %s.\", t.Status)\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn \"\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn \"\"\n\t\t\t},\n\t\t\tPrompt: func(opt uicomponents.Option) string {\n\t\t\t\tfor _, t := range visibleTasks {\n\t\t\t\t\tif t.ID == opt.Value {\n\t\t\t\t\t\tif t.Status != api.TaskStatusRunning \u0026\u0026 t.Status != api.TaskStatusPending {\n\t\t\t\t\t\t\treturn \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn fmt.Sprintf(\"Kill background task %s?\", opt.Label)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn \"\"\n\t\t\t},\n\t\t\tOnConfirm: func(opt uicomponents.Option) {\n\t\t\t\tfor _, t := range visibleTasks {\n\t\t\t\t\tif t.ID == opt.Value {\n\t\t\t\t\t\tif t.Status == api.TaskStatusRunning || t.Status == api.TaskStatusPending {\n\t\t\t\t\t\t\t_ = store.KillTask(opt.Value)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t},\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nTasksBrowser renders an interactive tasks list and inline output viewer inside \\\u003cSlot /\u003e.\n\n```go\nvar ToolsBrowser = trail.FC(\"ToolsBrowser\", func(slotID string) trail.Node {\n\ttoolsPtr := store.UseApp(func(s store.AppState) *[]api.Tool { return s.Tools })\n\tcachedAgent := store.UseApp(func(s store.AppState) string { return s.ToolsAgent })\n\ttoolsFetched := store.UseApp(func(s store.AppState) bool { return s.ToolsFetched })\n\tdefaultAgent := store.UseApp(func(s store.AppState) string { return s.DefaultAgent })\n\tsessionAgent := store.UseSession(func(s store.SessionState) string { return s.Config.Agent })\n\tselectedTool, setSelectedTool := kitex.UseState[*api.Tool](nil)\n\tnotice, setNotice := kitex.UseState(\"\")\n\tisReloading, setIsReloading := kitex.UseState(false)\n\ttoggling, setToggling := kitex.UseState(\"\")\n\n\tvar tools []api.Tool\n\tif toolsPtr != nil {\n\t\ttools = *toolsPtr\n\t}\n\n\tagent := strings.TrimSpace(sessionAgent)\n\tif agent == \"\" {\n\t\tagent = strings.TrimSpace(defaultAgent)\n\t}\n\n\tkitex.UseEffect(func() {\n\t\tif toolsFetched \u0026\u0026 cachedAgent == agent {\n\t\t\treturn\n\t\t}\n\t\tif store.Client() == nil {\n\t\t\treturn\n\t\t}\n\t\tgo func() {\n\t\t\tif _, err := store.RefreshWorkspaceTools(context.Background(), agent); err != nil {\n\t\t\t\tstore.AppendCommandOutput(\"/tools\", \"Failed to load workspace tools: \"+err.Error())\n\t\t\t}\n\t\t}()\n\t}, []any{agent, cachedAgent, toolsFetched})\n\n\tdoReload := func() {\n\t\tif isReloading() {\n\t\t\treturn\n\t\t}\n\t\tsetIsReloading(true)\n\t\tsetNotice(\"Reloading workspace tools via registry.Reload...\")\n\t\tgo func() {\n\t\t\tdefer setIsReloading(false)\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\t\t\tdefer cancel()\n\t\t\tif err := store.ReloadWorkspace(ctx); err != nil {\n\t\t\t\tsetNotice(\"Failed to reload workspace: \" + err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcount := 0\n\t\t\tif s := store.GetApp().Tools; s != nil {\n\t\t\t\tfor _, t := range *s {\n\t\t\t\t\tif t.Enabled {\n\t\t\t\t\t\tcount++\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tsetNotice(fmt.Sprintf(\"Workspace reloaded via registry.Reload (%d tools available).\", count))\n\t\t}()\n\t}\n\n\ttoggleEnabled := func(opt uicomponents.Option) {\n\t\tc := store.Client()\n\t\tif c == nil || toggling() != \"\" {\n\t\t\treturn\n\t\t}\n\t\ttarget := false\n\t\tfor i := range tools {\n\t\t\tif tools[i].Name == opt.Value {\n\t\t\t\ttarget = tools[i].Enabled\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tsetToggling(opt.Value)\n\t\tgoMCPBackground(func() {\n\t\t\tdefer setToggling(\"\")\n\t\t\tctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)\n\t\t\tdefer cancel()\n\t\t\tif _, err := c.SetToolEnabled(ctx, opt.Value, !target); err != nil {\n\t\t\t\tsetNotice(\"Failed to update \" + opt.Value + \": \" + err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif _, err := store.ForceRefreshWorkspaceTools(ctx); err != nil {\n\t\t\t\tsetNotice(\"Updated \" + opt.Value + \", but refreshing the tool listing failed: \" + err.Error())\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif target {\n\t\t\t\tsetNotice(\"Disabled \" + opt.Value + \".\")\n\t\t\t} else {\n\t\t\t\tsetNotice(\"Enabled \" + opt.Value + \".\")\n\t\t\t}\n\t\t})\n\t}\n\n\tif sel := selectedTool(); sel != nil {\n\t\treturn toolInspector(toolInspectorProps{\n\t\t\tslotID:  slotID,\n\t\t\ttool:    *sel,\n\t\t\tonClose: func() { setSelectedTool(nil) },\n\t\t})\n\t}\n\n\tif len(tools) == 0 {\n\t\treturn emptyToolsView(emptyToolsViewProps{\n\t\t\tslotID:   slotID,\n\t\t\tnotice:   notice(),\n\t\t\tonReload: doReload,\n\t\t})\n\t}\n\n\tenabledCount := 0\n\tfor i := range tools {\n\t\tif tools[i].Enabled {\n\t\t\tenabledCount++\n\t\t}\n\t}\n\ttitle := fmt.Sprintf(\"Tools (%d available)\", enabledCount)\n\tif enabledCount \u003c len(tools) {\n\t\ttitle = fmt.Sprintf(\"Tools (%d of %d available)\", enabledCount, len(tools))\n\t}\n\tif n := notice(); n != \"\" {\n\t\ttitle = fmt.Sprintf(\"%s — %s\", title, n)\n\t}\n\n\tscheme := theme.UseTheme()\n\n\twinSize := trail.UseWindowSize()\n\tnameCol, statusCol, scopeCol, annotationCol, availDescWidth := toolColumnWidths(tools, winSize.Width)\n\n\topts := make([]uicomponents.Option, len(tools))\n\tfor i, tl := range tools {\n\t\tstatusBadge := toolStatusBadge(tl)\n\t\tscopeBadge := fmt.Sprintf(\"[%s]\", ToolScope(tl))\n\t\tannotations := toolAnnotationBadges(tl)\n\t\tdesc := format.CompactSingleLine(tl.Description, availDescWidth)\n\n\t\tstatusNode := trail.Box(trail.BoxProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlexDirection(style.FlexRow).\n\t\t\t\tWidth(style.Percent(100)).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden),\n\t\t}, trail.Span(trail.SpanProps{\n\t\t\tStyle: toolStatusColor(scheme, tl.Status).\n\t\t\t\tWhiteSpace(style.WhiteSpacePre).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden),\n\t\t}, trail.Text(statusBadge)))\n\n\t\tdescNode := trail.Box(trail.BoxProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlexDirection(style.FlexRow).\n\t\t\t\tWidth(style.Percent(100)).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden),\n\t\t}, trail.Span(trail.SpanProps{\n\t\t\tStyle: style.S().\n\t\t\t\tFlex(0, 1).\n\t\t\t\tMinWidth(style.Cells(0)).\n\t\t\t\tOverflow(style.OverflowHidden).\n\t\t\t\tWhiteSpace(style.WhiteSpacePre).\n\t\t\t\tForeground(scheme.Color.Text.Muted),\n\t\t}, trail.Text(desc)))\n\n\t\topts[i] = uicomponents.Option{\n\t\t\tValue:       tl.Name,\n\t\t\tLabel:       tl.Name,\n\t\t\tDescription: desc,\n\t\t\tCells:       []string{tl.Name, statusBadge, scopeBadge, annotations, desc},\n\t\t\tCellNodes:   []trail.Node{nil, statusNode, nil, nil, descNode},\n\t\t}\n\t}\n\n\tinspect := func(opt uicomponents.Option) {\n\t\tfor i := range tools {\n\t\t\tif tools[i].Name == opt.Value {\n\t\t\t\tsetSelectedTool(\u0026tools[i])\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\tpickerProps := components.NewPicker(title, opts, inspect)\n\tpickerProps.Columns = []uicomponents.Column{\n\t\t{Width: nameCol, Align: style.TextAlignLeft},\n\t\t{Width: statusCol, Align: style.TextAlignLeft},\n\t\t{Width: scopeCol, Align: style.TextAlignLeft},\n\t\t{Width: annotationCol, Align: style.TextAlignLeft},\n\t\t{Width: 0, Align: style.TextAlignLeft},\n\t}\n\tpickerProps.Filterable = false\n\tpickerProps.Bindings = []uicomponents.KeyBinding{\n\t\t{Key: \"↑/↓\", Label: \"Select\"},\n\t\t{Key: \"enter\", Label: \"Inspect tool\"},\n\t\t{Key: \"space\", Label: \"Enable/disable\"},\n\t\t{Key: \"r\", Label: \"Reload workspace\"},\n\t\t{Key: \"esc\", Label: \"Close\"},\n\t}\n\tpickerProps.Keys = map[string]func(uicomponents.Option){\n\t\t\"space\": toggleEnabled,\n\t\t\"r\": func(_ uicomponents.Option) {\n\t\t\tdoReload()\n\t\t},\n\t\t\"i\": inspect,\n\t}\n\tpickerProps.OnCancel = func() {\n\t\tstore.RemoveSlot(slotID)\n\t\tstore.AppendCommandOutput(\"/tools\", \"Exited /tools command\")\n\t}\n\n\treturn components.Picker(pickerProps)\n})\n```\nToolsBrowser renders an interactive tool table and schema inspector inside \\\u003cSlot /\u003e.\n\n## Functions\n\n```go\nfunc CompletionViews(activeMode api.PermissionMode) map[string]uicomponents.AutocompleteView\n```\nCompletionViews returns command-specific completion views for the active mode.\n\n```go\nfunc EnqueueProviderAuth(provider string)\n```\nEnqueueProviderAuth opens the sign-in screen for one provider. An empty name lets the daemon resolve the sole OAuth preset.\n\n```go\nfunc EstimateRuleTokens(instructions string) int\n```\nEstimateRuleTokens calculates approximate tokens for rule instructions using the code-calibrated tokenizer density (⌈bytes / 3⌉).\n\n```go\nfunc EstimateSkillTokens(instructions string) int\n```\nEstimateSkillTokens calculates approximate tokens for skill instructions using the code-calibrated tokenizer density (⌈bytes / 3⌉).\n\n```go\nfunc RuleScope(r api.Rule) string\n```\nRuleScope returns the canonical scope string for a rule: \\[Workspace], \\[Project], \\[User], or \\[Builtin] (System and Builtin are treated as Builtin).\n\n```go\nfunc SkillScope(sk api.Skill) string\n```\nSkillScope returns the canonical scope string for a skill: \\[Workspace], \\[Project], \\[User], or \\[Builtin] (System and Builtin are treated as Builtin).\n\n```go\nfunc SubmitMCPReference(text string, attachments ...api.Attachment) bool\n```\nSubmitMCPReference routes a submitted composer line containing an MCP reference. Allowed items run immediately; prohibited ones present the Option B confirmation. It reports whether the line was handled, so the caller only forwards an ordinary message when this returns false.\n\n```go\nfunc ToolScope(t api.Tool) string\n```\nToolScope returns the canonical scope string for a tool: \\[Builtin], \\[Workspace], \\[Project], or \\[User].\n\n## Types\n\n```go\ntype Command struct {\n\tName        string\n\tAliases     []string\n\tUsage       string\n\tDescription string\n\tHandler     Handler\n\tComplete    autocomplete.Completer\n\t// contains filtered or unexported fields\n}\n```\nCommand defines a REPL slash command and its metadata.\n\n```go\ntype Handler func(args []string) error\n```\nHandler executes a slash command with supplied arguments.\n\n```go\ntype Registry struct {\n\t// contains filtered or unexported fields\n}\n```\nRegistry maintains the collection of REPL slash commands.\n\n```go\nfunc NewRegistry() *Registry\n```\nNewRegistry constructs a Registry pre-populated with all built-in REPL commands.\n\n```go\nfunc (r *Registry) Execute(line string) error\n```\nExecute parses a raw slash command line and invokes the matching Handler.\n\n```go\nfunc (r *Registry) List() []Command\n```\nList returns all registered commands in registration order.\n\n```go\nfunc (r *Registry) Lookup(name string) (Command, bool)\n```\nLookup resolves a command by its primary name or alias, ignoring any leading \"/\".\n\n```go\nfunc (r *Registry) Register(cmd Command)\n```\nRegister adds or replaces a Command in the registry and indexes its name and aliases.\n\n```go\nfunc (r *Registry) RegisterCommandResource(cmd api.Command)\n```\nRegisterCommandResource registers a workspace Command manifest as a REPL slash command.\n\n```go\nfunc (r *Registry) RegisterSkillResource(sk api.Skill)\n```\nRegisterSkillResource registers a workspace Skill manifest as a REPL slash command.\n\n```go\nfunc (r *Registry) RegisterWorkspace(commands []api.Command, skills []api.Skill)\n```\nRegisterWorkspace registers workspace commands and skills as interactive slash commands.\n\n```go\nfunc (r *Registry) Sources() []autocomplete.Source\n```\nSources snapshots the registered commands as headless autocomplete sources.\n\n```go\ntype SubagentViewerProps struct {\n\tSubagentID string\n\tOnClose    func()\n}\n```\nSubagentViewerProps defines the properties for the live SubagentViewer component.\n\n","path":"github.com/masterkeysrd/tasksmith/internal/cli/command","name":"command","synopsis":"Package command implements the REPL slash command system for the TaskSmith CLI.","isRedistributable":true}
