# yaml-language-server: $schema=none
# The deepseek-tui bundle patch: terminal-surface mode directly over dsh-base.
# It mounts no Host, HTTP server, Web runtime, or browser plugin. An ordinary
# provider plugin parses --resume/--cwd and the task positional, then the
# terminal driver creates an Agent through the core registry and prints its
# durable result. Unlike the web surface, the agent plane stays process-wide:
# dsh-base keeps tool-bash/tool-fs/tool-todo and friends because the TUI is
# single-session and composes its agent process-wide.

- id: system-prompt
  config:
    persona: >-
      You are a coding agent powered by the {{model}} model.
      Your working directory is {{cwd}}.
      You are interacting with the user through the deepseek-tui
      terminal interface.

# The shared module-reload HMR row stays off; the launcher's watch-only
# fallback still keeps the user patch layers live until the run exits.
- id: hmr
  disabled: true

- id: tools
  config:
    # Keep the same temporary process-wide Code Mode opt-in as the Web surface.
    # pi-lens-ignore: YAML:0
    mode: !!js process.env.DSH_TOOLS_MODE

- id: approval
  # pi-lens-ignore: YAML:0
  config:
    policy: !!js >-
      (process.env.DSH_PERMISSION_MODE ?? 'workspace-write')
      === 'danger-full-access'
      ? 'never' : 'ask'

# Full-text session search stays disabled until the first Ctrl+K search (the
# base row's `openAt: never`). The TUI has no browser-latency concern, so the
# node:sqlite import and in-memory handle open lazily on first search.
- id: session-query-sqlite
  config:
    path: ':memory:'
    openAt: first-search

- id: llm-deepseek
  config:
    models:
      - id: deepseek-v4-flash
        name: DeepSeek-V4-Flash
        description: >-
          Fast, efficient, and economical; suited to focused, routine,
          or parallel tasks.
        contextWindow: 1000000
      - id: deepseek-v4-pro
        name: DeepSeek-V4-Pro
        description: >-
          Stronger agentic coding, knowledge, and difficult reasoning;
          suited to complex or quality-critical tasks at higher cost.
        contextWindow: 1000000
      - id: deepseek-v4-flash-vision-exp
        name: DeepSeek-V4-Flash-Vision-Exp
        contextWindow: 1000000
        inputModalities: [text, image]
      - id: deepseek-v4.1-flash-expires-on-0910
        name: DeepSeek-V4.1-Flash
        description: >-
          DeepSeek V4.1 Flash intermediate beta with native multimodal
          support, higher capability, faster speed, and lower cost.
        contextWindow: 1000000
        inputModalities: [text, image]

- id: agent-default-model
  config:
    # pi-lens-ignore: YAML:0
    provider: deepseek-official
    # pi-lens-ignore: YAML:0
    model: !!js "process.env.DSH_MODEL ?? 'deepseek-v4-flash'"

# pi-lens-ignore: YAML:0
- id: session-title-llm
  name: "@deepseek-ai/dsh-session-title-all-prompts-llm"
  config:
    targetWords: 5
    targetCjkCharacters: 10
    maxInputBytes: 16384
    maxOutputTokens: 64
    timeoutMs: 60000

- insert:
    # Code Mode is a core execution capability, not a Web component.
    - id: code-runtime
      name: "@deepseek-ai/dsh-code-runtime-worker-thread"

    # Per-round token/duration stats for the terminal status line.
    - id: session-stats
      name: "@deepseek-ai/dsh-session-stats"

    # Base owns the shared storage/domain/projection-cache stack. This layer
    # contributes only the TUI-facing feedback consumer over that stack.
    - id: message-feedback
      name: "@deepseek-ai/dsh-message-feedback"
      config:
        maxNoteBytes: 8192

    - id: tool-ask-user
      name: "@deepseek-ai/dsh-tool-ask-user"

    - id: tui-startup
      name: "@deepseek-ai/dsh-tui/startup"

    # Zero-config official OpenAI/Anthropic routes. They register
    # openai-official / anthropic-official so they do not collide with the
    # dormant llm-pi-ai catalog keys openai / anthropic that the Web Models
    # page already owns.
    - id: llm-openai
      name: "@deepseek-ai/dsh-llm-openai"

    - id: llm-anthropic
      name: "@deepseek-ai/dsh-llm-anthropic"

    # In-process OpenCode Zen header proxy (vendored from
    # zhangyang-crazy-one/dsh-zen-proxy, MIT). Listens on localhost
    # only; point an opencode provider baseURL at
    # http://127.0.0.1:4097/v1 to reach the Zen free tier.
    # Remove this row to disable the listener.
    - id: zen-proxy
      name: "./zen-proxy/index.js"
      config:
        host: 127.0.0.1
        port: 4097

    # Reads its task from the ordinary tuiStartup provider.
    - id: tui-runtime
      # pi-lens-ignore: YAML:0
      name: "@deepseek-ai/dsh-tui"
      inject: [tuiStartup]
      # pi-lens-ignore: YAML:0
      config:
        # pi-lens-ignore: YAML:0
        task: !!js ctx.tuiStartup.task
        resume: !!js ctx.tuiStartup.resume
        # pi-lens-ignore: YAML:0
        cwd: !!js ctx.tuiStartup.cwd
        model: !!js ctx.tuiStartup.model
        frameStats: !!js ctx.tuiStartup.frameStats
        # Render policy (overscan, stream pacing, scroll pacing, cache).
        # Loaded by the runtime Config schema; the values below mirror the
        # schema defaults so the deployment layer owns the tunables. Override
        # here to retune without touching the plugin.
        renderPolicy:
          transcriptOverscan: 16
          stream:
            frameIntervalMs: 16
            entryDepth: 64
            exitDepth: 32
            entryOldestAgeMs: 500
            exitOldestAgeMs: 250
            entryDrainBackpressureMs: 100
            exitDrainBackpressureMs: 50
            catchUpRowsPerFrame: 16
          scroll:
            frameIntervalMs: 16
            stepPerFrame: 1
            wheelRows: 3
            catchUpThreshold: 10
            maxCatchUpStep: 8
          cache:
            maxRows: 4096
            maxBytes: 4194304
