# ChatCode CLI TUI interactive front door over the agent-spine bundle.
# Run with: chatcode-cli --config cordis.yml (or use the normal profile launcher)
# Uses ChatCode/user-managed model providers; a terminal TTY is mandatory.

# The user-interaction service: hosts `ctx.userQuestions`, the seam behind
# the model-facing ask_user_question tool. dsh-tui uses the legacy provider
# API when present, otherwise the scoped user-questions/request waterfall;
# the service must live at the root so the agent loop's tool execution can
# reach it.
- id: user-questions
  name: '@deepseek-ai/dsh-user-questions'

# The approval service (issue #49): the harness's sandbox escalation seam
# (`sandbox_permissions: danger-full-access`) asks ApprovalService.request(),
# which dispatches an `approval/request` waterfall; dsh-tui registers itself
# as the interactive answerer (ApprovalStore + approval panel). Without this
# row the waterfall has no service and fail-closes to 'unavailable'. Policy
# expression mirrors the profile cordis.patch.yml row exactly (verified by
# scripts/verify-cordis-approval.mjs): ask everywhere except
# danger-full-access (nothing needs asking) and Windows (no sandbox — the
# user's terminal trust model, matching every other terminal coding agent).
- id: approval
  name: '@deepseek-ai/dsh-user-approval'
  config:
    policy: !!js "process.platform === 'win32' ? 'never' : (((process.env.CHATCODE_CLI_PERMISSION_MODE ?? process.env.DSH_PERMISSION_MODE) ?? 'workspace-write') === 'danger-full-access' ? 'never' : 'ask')"

- id: dsh-tui-workspaces
  name: '@chatcode/cco-tui/workspaces'

- id: dsh-tui-command-trees
  name: '@chatcode/cco-tui/command-trees'

# Optional plugins declare editable settings sections here (issue #165);
# storage, validation and writes remain owned by the dsh settings service.
- id: dsh-tui-settings-sections
  name: '@chatcode/cco-tui/settings-sections'

- id: dsh-tui-scenes
  name: '@chatcode/cco-tui/scenes'

# Plugin-interop anchor (v0.15): unified grant store, runtime generation
# id, Host Descriptor; later contract surfaces mount off this row's apply.
- id: dsh-tui-plugin-host
  name: '@chatcode/cco-tui/plugin-host'

# Plugin-facing UI seams: managed dialogs, status-line contributions,
# keyboard shortcuts, custom session-entry renderers, and runtime themes
# (decision events are fired by the channel and need no row).
- id: dsh-tui-extensions
  name: '@chatcode/cco-tui/extensions'

- id: dsh-tui
  name: '@chatcode/cco-tui'
  # Entry-level only: orders/rebinds optional extension services on reload;
  # dsh-tui does not hard-inject them at code level, so stale profiles degrade
  # to static themes and inert extension surfaces instead of deadlocking boot.
  inject: [agents, tuiWorkspaces, tuiScenes, tuiDialogs, tuiStatus, tuiShortcuts, tuiRenderers, tuiThemes]
  config:
    # Alt-screen fullscreen (CC 同款): 应用内鼠标选区（选择即复制, OSC 52 +
    # wl-copy/xclip/xsel 兜底）、滚轮滚动、双击选词/三击选行。false 则退回
    # inline 渲染, 鼠标交给终端模拟器原生选择。
    fullscreen: true
    # Shift+Tab 会话模式循环（数组顺序即循环顺序；缺省为下面三档）。
    # 每档可声明 plan（计划模式开/关）、sandbox（read-only/
    # workspace-write/danger-full-access）、approval（ask/never）三个
    # 原子的任意子集；未声明的原子不动。首档（index 0）为无标记基态。
    # modes:
    #   - id: default
    #     plan: false
    #     sandbox: workspace-write
    #     approval: ask
    #   - id: plan
    #     plan: true
    #     sandbox: read-only
    #     approval: ask
    #   - id: full
    #     plan: false
    #     sandbox: danger-full-access
    #     approval: never
    #  feeds the chosen session id through the canonical env var; legacy
    #  DSH_TUI_ and DSH_CC_ spellings remain compatibility inputs.
    sessionId: !!js process.env.CHATCODE_CLI_TUI_RESUME_SESSION ?? process.env.DSH_TUI_RESUME_SESSION ?? process.env.DSH_CC_RESUME_SESSION ?? undefined
    workspace: !!js process.env.CHATCODE_CLI_TUI_WORKSPACE_TARGET ?? process.env.DSH_TUI_WORKSPACE_TARGET ?? undefined

# Keep the adapter and settings namespace available without advertising its
# four native built-in models. Explicit user configuration can add models.
- id: llm-deepseek
  name: '@deepseek-ai/dsh-llm-deepseek'
  config:
    models: []

# Managed child-process groups for the bash executor.
- id: subprocess
  name: '@deepseek-ai/dsh-subprocess-local'

- id: bash
  name: '@deepseek-ai/dsh-bash-local'
  config:
    cwd: !!js process.cwd()
    timeoutMs: 60000

# Filesystem service: `@` completion lists the session cwd through it, and
# the model-facing fs tools resolve relative paths from the process cwd.
- id: fs
  name: '@deepseek-ai/dsh-fs-local'
  config:
    cwd: !!js process.cwd()

# Read/write/edit policy loads before the model-facing filesystem tools so
# writes and edits require an observed file (DSH's own fs policy gate).
- id: fs-policy
  name: '@deepseek-ai/dsh-fs-observation-policy'

- id: tool-fs
  name: '@deepseek-ai/dsh-tool-fs'

# The todo_write tool replaces the logged whole list (DSH's todo tool).
# allowParallelInProgress is REQUIRED (no schema default) — a bare mount
# fails validation. True matches the official dsh-base bundle value.
- id: tool-todo
  name: '@deepseek-ai/dsh-tool-todo'
  config:
    allowParallelInProgress: true

# Subagents: the registry service, then the spawn/fork backends and the
# delegation tools (max depth 1 keeps the TUI's tool cards shallow). The
# core `dsh-subagent` service MUST be mounted before any provider.
- id: subagent
  name: '@deepseek-ai/dsh-subagent'

- id: subagent-spawn
  name: '@deepseek-ai/dsh-subagent-spawn-in-process'
  config:
    providerName: spawn

- id: subagent-fork
  name: '@deepseek-ai/dsh-subagent-fork-in-process'
  config:
    providerName: fork

- id: tool-subagent
  name: '@deepseek-ai/dsh-tool-subagent'
  config:
    provider: spawn
    toolName: subagent
    backgroundMode: continuable
    maxDepth: 1

- id: tool-subagent-fork
  name: '@deepseek-ai/dsh-tool-subagent'
  config:
    provider: fork
    toolName: subagent_fork
    backgroundMode: continuable
    maxDepth: 1

- id: agent-spine
  name: '@deepseek-ai/dsh-agent-spine-demo'
  config:
    persona: !!js process.env.CHATCODE_CLI_TUI_PERSONA ?? process.env.DSH_TUI_PERSONA ?? 'You are ChatCode CLI, an AI coding agent.'
    # Workspace context (AGENTS.md injection) at the standard 64KB cap;
    # task tools stay at their DSH defaults (on).
    workspaceContext:
      maxBytes: 65536
    # Skills on: the spine mounts the local skill provider (discovers
    # SKILL.md catalogs under ~/.dsh, ~/.agents and project roots) plus the
    # model-facing skill catalog/load tools.
    skills:
      enabled: true
    # Persisted goal stack: mounts the goal domain service + the model-facing
    # goal tool; /goal (command-goal below) needs the service present.
    goals: {}

# Human-command registry: plan-mode's /plan and command-goal's /goal register
# here; the TUI merges them into its slash menu and dispatches through the
# registry (logs command/run + command/done). Must mount before the commands.
- id: commands
  name: '@deepseek-ai/dsh-commands'

# Plan mode: the plan:policy prompt section, the /plan command and the
# model-facing plan/exit tools (DSH's plan seam). `section` is REQUIRED and
# non-empty — a bare mount fails validation and rolls the whole tree back.
- id: plan-mode
  name: '@deepseek-ai/dsh-plan-mode'
  config:
    section: |
      You are in plan mode. Explore and design before presenting the
      complete plan through exit_plan_mode.

# /goal — set or view the goal for a long-running task (needs the goal
# domain service mounted by agent-spine's `goals` config above).
- id: command-goal
  name: '@deepseek-ai/dsh-command-goal'

# Live working line narration support. dsh-tui computes the visible status
# in-process from base session events; activity/status is never persisted.
# Mounted through @chatcode/cco-tui's `./working-activity`
# re-export (not the bare `dsh-working-activity` name) so the row resolves
# from install layouts that never link transitive dependencies into the
# boot anchor's node_modules — pnpm's isolated profile layout, issue #60.
- id: working-activity
  name: '@chatcode/cco-tui/working-activity'
  config:
    publish: false
    publishIntervalMs: 500

# Durable session log (DSH's own persistence seam): /resume and rewind both
# rely on this backend writing every session/event. Root defaults under the
# user home so sessions survive across terminals (Windows: USERPROFILE).
- id: sessions
  name: '@deepseek-ai/dsh-session-persistence-jsonl'
  config:
    root: !!js process.env.CHATCODE_CLI_TUI_SESSION_ROOT ?? process.env.DSH_TUI_SESSION_ROOT ?? (process.env.CHATCODE_CLI_HOME ?? process.env.DSH_HOME ?? (process.env.USERPROFILE ?? process.env.HOME) + '/.chatcode-cli') + '/sessions'

# Whole-log projections back `/stats session`. The TUI reads this official
# service and never reconstructs timing/token totals from rendered messages.
- id: session-projection
  name: '@deepseek-ai/dsh-session-projection'

- id: session-stats
  name: '@deepseek-ai/dsh-session-stats'

# Read-only session lineage — the subagent service's /agents listing reads it.
- id: session-query
  name: '@deepseek-ai/dsh-session-query'

- id: session-checkpoints
  name: '@deepseek-ai/dsh-session-checkpoint-policy'

# Token accounting + manual session compaction (/compact).
- id: token-meter
  name: '@deepseek-ai/dsh-token-meter'

- id: compact
  name: '@deepseek-ai/dsh-compaction-basic'
  config:
    # DeepSeek advertises a 1M context window, so the 80% default threshold
    # would never make manual /compact useful. Default 20% (200k tokens)
    # with a 5% retained tail; both are overridable for tests and must keep
    # retainRatio < thresholdRatio (BasicCompactConfig validates this).
    thresholdRatio: !!js parseFloat(process.env.CHATCODE_CLI_TUI_COMPACT_RATIO ?? process.env.DSH_TUI_COMPACT_RATIO ?? '0.2')
    retainRatio: !!js parseFloat(process.env.CHATCODE_CLI_TUI_COMPACT_RETAIN ?? process.env.DSH_TUI_COMPACT_RETAIN ?? '0.05')
