# The dsh-pi-tui bundle patch: the TUI surface over the dsh-base layer.
# Applied after dsh-base's insert; rows here override base rows by id, with
# the profile's own cordis.patch.yml and any --patch overlays still to come.
#
# The tui-startup plugin injects `cmdlineArgs` and provides `tuiStartup` as
# an ordinary Cordis service. The runner row injects that service, so Loader
# resolves its expressions only after the command line has been parsed.
# `dsh --profile pi-tui --help` provides nothing, so the TUI never mounts.

- insert:
    - id: tui-startup
      name: '@xmoon76/dsh-pi-tui/startup'

    # M6-2A: the daemon Coordinator. Mounts ONLY when the startup row published
    # `tuiDaemonStartup` (the daemon backend); it spawns the ONE foreground Client
    # and owns its exit. It owns no Host, Session or Writer.
    - id: pi-tui-daemon-launcher
      name: '@xmoon76/dsh-pi-tui/daemon-launcher'
      inject: [tuiDaemonStartup]

    # The extension platform (M3/E): the host provides the piTuiExtensions
    # service (third-party plugins inject it), the builtins row registers
    # the first-party chrome contributions through the SAME public API, and
    # the runner row attaches the surface host over the service's ledger.
    # All three gate on tuiStartup, so `--help` mounts none of them.
    - id: pi-tui-extension-host
      name: '@xmoon76/dsh-pi-tui/extensions'
      inject: [tuiStartup]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    - id: pi-tui-builtins
      name: '@xmoon76/dsh-pi-tui/builtins'
      inject: [tuiStartup, piTuiExtensions]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The bundle's OWN Host performance projection (plan PR-1): the single
    # authority for the R5 / All model-request output rate and the recent TTFB.
    # It registers the `piTuiPerformance` unit on the official
    # `sessionProjections` seam — the same seam the official `sessionStats` row
    # uses — and then publishes the `piTuiPerformanceReady` gate. Gating on
    # `tuiStartup` keeps `--help` from mounting it; the `sessionProjections`
    # inject makes the row wait for the Host registry instead of registering
    # into a missing seam.
    - id: pi-tui-performance-host
      name: '@xmoon76/dsh-pi-tui/performance-host'
      inject: [tuiStartup, sessionProjections]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # Workspace file service (the OFFICIAL `@deepseek-ai/dsh-api-workspace-files`):
    # the ONE Host owner of the `workspaceFiles` Remote namespace the delivered-
    # files preview reads through — bounded `stat`/`read` under the Session's
    # header-derived workspace scope, with the composed filesystem's own read
    # access. Mounted here because dsh-base does not ship it; the row is
    # registered EXACTLY ONCE per Host graph and reused by the in-process Remote
    # Host (never remounted by a Client). Gated on `tuiStartup`, so
    # `dsh --profile pi-tui --help` still mounts no Host file surface.
    - id: workspace-files
      name: '@deepseek-ai/dsh-api-workspace-files'
      inject: [tuiStartup]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # Visual tools: three Host tool definitions — the two generators
    # (`dsh_pi_tui_chart`, `dsh_pi_tui_svg`) and the publication tool
    # (`present_visual`) — on the official `ctx.tools` registry. The row owns the
    # profile-wide `enabled` volatile Config (default On) and keeps the GROUP
    # registered only while it is on: `/settings → Tools → Visual tools` writes
    # that value, and the Loader commits it live (no restart / row remount).
    # The row itself is deliberately NOT gated on `tuiStartup`, a renderer, a
    # Tern hello, a client capability or a session: the same Host profile (and
    # the in-process Remote Host built on it) serves every Client. `tools` is
    # the registry the row owns; `agents` supplies the executing Agent/Session
    # identity, `sessionQuery` reads the committed log through one caller-owned
    # observation lease, and `sessionProjections` supplies the authoritative
    # `turnBoundary` fold the publisher fences on (the same seam the official
    # `present` and `agent-instructions` rows read). The result contract carries
    # no `presentationMeta` — the final durable content is the drawing's
    # admission source.
    # M6-2A: a Host business row that does NOT gate on `tuiStartup`. In the
    # daemon supervisor PID it must not register tools or own Host state; the
    # real Host (detached local-host.mjs) owns them. Disabled only for the
    # daemon supervisor, live in Direct / Host-only.
    - id: pi-tui-visual-tools
      name: '@xmoon76/dsh-pi-tui/visual-tools'
      inject: [tools, agents, sessionQuery, sessionProjections]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The ONE Host MCP manager: the official `@deepseek-ai/dsh-mcp-manager`
    # service (`ctx.mcpManager`) that owns the profile's `mcp-manager.servers`
    # fleet plus every plugin `register()`ed server, and exposes `list`/`watch`/
    # `probe`/`restart` to the Host and the authenticated Remote. It is declared
    # ONCE here as a SHARED Host row — deliberately NOT a Web row — so Direct
    # owns it with the Web frontend off and a Split Host keeps the SAME instance
    # across `/web` on/off. No `config.servers` is declared: the user's profile
    # configuration is inherited through the same row id, and the loader commits
    # live `servers` updates without remounting the row.
    #
    # `credentials` is the official provider the manager resolves
    # `${credential:…}` entry templates through; the class's own static
    # `inject: ['tools']` still supplies the tool registry. The daemon
    # supervisor PID owns no Host business state, so the row is absent there
    # exactly like the other Host-owned rows below.
    - id: mcp-manager
      name: '@deepseek-ai/dsh-mcp-manager'
      inject: [credentials]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The profile-owned Web startup preference (M5-W PR-C): ONE durable boolean,
    # `autoStart`, that a NEW Split Host reads BEFORE it becomes Ready. The row
    # performs no work; it exists so the official Settings service projects the
    # section and the Loader persists the user patch. It is deliberately NOT
    # gated on `tuiStartup`: a Direct process also loads the profile and must be
    # able to edit the preference for the Split Host it may start later.
    - id: pi-tui-web-preferences
      name: '@xmoon76/dsh-pi-tui/web-preferences'

    # The profile-owned ACP startup preference (PO-1B): ONE durable boolean,
    # `autoStart`, that a NEW Split Host reads BEFORE it becomes Ready to decide
    # whether to bind the local ACP v1 Unix socket listener. The row performs no
    # work; it exists so the official Settings service projects the section and
    # the Loader persists the user patch. It is deliberately NOT gated on
    # `tuiStartup`: a Direct process also loads the profile and must be able to
    # edit the preference for the Split Host it may start later.
    - id: pi-tui-acp-preferences
      name: '@xmoon76/dsh-pi-tui/acp-preferences'

    # The OFFICIAL Host browser-callback listener for DeepSeek Account sign-in.
    # The account provider registers `/oauth/callback` on this instance while an
    # attempt is waiting for the browser; it is mounted here because the dsh-base
    # layer ships the account provider but not the webserver. `host: 127.0.0.1`
    # plus `port: 0` keeps the listener on a private loopback interface with an
    # OS-assigned port (the stable `webserver` id lets a profile patch override
    # the configuration without introducing a second service). `tuiStartup`
    # gates the row on the same command-line admission as the TUI runner, so
    # `dsh --profile pi-tui --help` never opens a socket.
    - id: webserver
      name: '@deepseek-ai/dsh-host-webserver'
      inject: [tuiStartup]
      # M6-2A: `webserver` is an app-boot REQUIRED entry. Under the daemon
      # backend the CLI/supervisor PID publishes `tuiDaemonStartup` and must not
      # serve (the real Host does); leaving the row enabled-but-pending on
      # `tuiStartup` would fail startup with "1 required plugin did not
      # activate". A conditional `disabled` makes the row legitimately absent in
      # the daemon supervisor and live in Direct / Host-only graphs.
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"
      config:
        host: 127.0.0.1
        port: 0

    # The canonical profile-owned TUI preferences (M6 PR-A): the ONE hidden,
    # profile-persisted Config carrier every backend reads — Direct, the Split
    # Host and, through the Host settings wire, every Remote Client. It is a
    # CONFIG-ONLY row: no TUI, Agent, Session, Gateway, timer or watcher. It is
    # NOT gated on `tuiStartup` (a profile that runs `--help` still needs the
    # canonical authority settled), and it is disabled only in the daemon
    # supervisor, which owns no Host state. Its auto-generated settings page is
    # hidden by the row itself; the TUI's own /settings drives it.
    - id: pi-tui-preferences
      name: '@xmoon76/dsh-pi-tui/preferences'
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    - id: tui-app
      name: '@xmoon76/dsh-pi-tui'
      # `workspaceRegistry` is injected, not merely looked up: D2.4 Direct fork
      # must observe the official workspace membership, and Cordis must have
      # finished the registry's one-time history bootstrap before the surface
      # can fork. The row below is this bundle's own, so the dependency is
      # self-contained and a profile that disables it fails loud instead of
      # silently forking without workspace inheritance.
      # `pluginManager` is injected for the P1-A Plugin Manager surface: the
      # dsh-base layer already mounts it (disabled only without a profile),
      # so this is an explicit lifecycle ordering dependency, never a second
      # package-manager row.
      # `piTuiPerformanceReady` is the bundle's own Host projection gate: the
      # surface must not mount without its performance authority, so a profile
      # that disables the `pi-tui-performance-host` row fails loudly here
      # instead of silently falling back to a Client-side estimate.
      # `deepseekAccount` and `webServer` are the DeepSeek Account authority and
      # its browser callback listener: the surface must not mount before both
      # are published, otherwise the Account page could start a sign-in the
      # Host cannot complete.
      inject: [tuiStartup, piTuiExtensions, authorization, workspaceRegistry, pluginManager, jobController, piTuiPerformanceReady, deepseekAccount, webServer]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"
      config:
        sessionId: ''

    # The Split Host's ONE built-in Host Runtime row (the private contribution
    # plus its business services). It is DECLARED here, disabled by default, so
    # its config belongs to this bundle patch and the USER profile can own every
    # saved preference; the Host-only overlay only flips `disabled: false`.
    # Declaring it in that overlay instead would make the official ConfigEditor
    # refuse every save ("overridden by a home patch or command-line overlay"),
    # because this row is the Split Host's ONE live TUI settings authority.
    # Direct keeps the `tui-app` row and the daemon supervisor mounts neither.
    - id: split-host-pi-tui-runtime
      name: '@xmoon76/dsh-pi-tui/host-runtime'
      inject: [typert, agents, fileReferences, workingDirectory, sessions, subprocess, workspaceRegistry, skills, agentPresets]
      disabled: true
      config:
        sessionId: ''

    # One background Job's observation stream (P1-B): the official Host
    # controller wraps `jobs.events` + `jobs.readAt()` into a
    # NON-CONSUMING follow stream (never `jobs.read()`), so the selected Job
    # detail can render a live retained-output tail without touching the
    # model's `job_output` cursor or completion notices. The rc.1 web bundle
    # mounts this same row; the dsh-base layer does not, so the TUI inserts
    # it. This is NOT M3: same process, same Host Context, no Client Context,
    # no Connection, no transport.
    - id: job-controller
      name: '@deepseek-ai/dsh-api-job-controller'
      # M6-2A: not gated on `tuiStartup`; must not mount in the daemon supervisor.
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # Host-owned workspace membership (`ctx.workspaceRegistry`): D2.4 Direct
    # fork mirrors the official Host rule (use the source's directly owning
    # workspace, else the nearest ancestor workspace of a subagent source) and
    # attaches the child after publication. That association only exists while
    # this service is mounted, so the TUI inserts the same official row the web
    # bundle does (the DSH installation already ships the package). Activating
    # it also performs the official one-time history bootstrap that groups
    # stored Session headers by canonical cwd into durable workspace records —
    # an upstream migration, not a TUI invention, and the reason the row is
    # documented in docs/architecture/host-client.md.
    - id: workspace
      name: '@deepseek-ai/dsh-workspace'
      # M6-2A: mounting this row performs the official one-time history bootstrap
      # that WRITES workspace records. The daemon supervisor must not write Host
      # state, so it is disabled only under the daemon backend.
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The ONE Host Workspace commands/follow owner over the registry above
    # (`ctx.workspaceController`, Typert namespace `workspace`): the same
    # official row ID the web bundle mounts, so a Direct Host and a Host-only
    # Split Host expose one Workspace Remote authority instead of two. Gating on
    # `tuiStartup` is Direct's command-line admission only (`--help` starts no
    # Host mutation); the Host-only overlay removes exactly that dependency in
    # place, and the class's own `static inject` still supplies
    # `remoteAccess`/`typert`/`workspaceRegistry`. Mounting it registers the
    # generated `workspace` Remote namespace; it creates no Workspace and no
    # directory by itself.
    - id: workspace-controller
      name: '@deepseek-ai/dsh-api-workspace-controller'
      inject: [tuiStartup]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The ONE official Host directory-browsing backend (`ctx.directoryPicker`,
    # browse capability): the existing Workspace Controller mounts its
    # `DirectoryPickerController` child over this seam, and that child is what
    # serves the generated `directoryPicker/list` Remote verb. The browse
    # backend is chosen deliberately instead of the `auto` package, which may
    # pick the host-display `native` chooser and leave remote clients without
    # listing primitives. Mounting it creates no Workspace and no directory.
    # `tuiStartup` is Direct's command-line admission; the Host-only overlay
    # removes exactly that dependency in place, and no overlay inserts a second
    # picker row.
    - id: directory-picker
      name: '@deepseek-ai/dsh-host-directory-picker-browse'
      inject: [tuiStartup]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # ── Host Schedule management (S5-PR4) ──────────────────────────────────
    # ONE Host Schedule domain shared by Direct and the Host-only Split
    # overlay: the official durable task store, the single timer, the session
    # FIFO and the delivery receipts all belong to this row. The Host-only
    # overlay removes only the `tuiStartup` gate IN PLACE (`inject:
    # [sessionController]`) and never inserts a second copy.
    #
    # `sessionController` is injected as a readiness barrier, not as a second
    # owner: the Schedule runtime creates a `new`/`new_once` target Session
    # through the one official Host Session controller, so the row must not
    # arm its timer before that provider exists. The class's own inject still
    # supplies agents/sessions/storageDomain/sessionPersistence, and
    # `--help` (no tuiStartup) mounts neither this row nor the three Direct
    # prerequisites below.
    - id: pi-tui-schedule
      name: '@deepseek-ai/dsh-schedule'
      inject: [tuiStartup, sessionController]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The three OFFICIAL Direct activation prerequisites of a Schedule target
    # that creates Sessions, declared exactly once for the Direct graph:
    # `SessionController` injects `fileUploads`, and `FileUploads` injects the
    # Host `connection`. They are the same packages the web bundle and the
    # Split Host-only overlay mount; the Split overlay disables exactly these
    # three Direct rows so one Host PID never holds two Connections, two
    # FileUploads or two Session controllers. `trustedHosts: []` keeps the
    # loopback listener and the listener's own bind IP as the only accepted
    # authorities, and `nativeOpen: false` keeps the controller from opening a
    # host-side native surface for a Remote client.
    - id: pi-tui-direct-connection
      name: '@deepseek-ai/dsh-client-connection'
      inject: [tuiStartup, credentials, webServer]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"
      config:
        trustedHosts: []

    - id: pi-tui-direct-file-upload
      name: '@deepseek-ai/dsh-client-file-upload'
      inject: [tuiStartup, agents, attachments, commands, connection]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    - id: pi-tui-direct-session-controller
      name: '@deepseek-ai/dsh-api-session-controller'
      inject: [tuiStartup, agentDefaultModel, agents, attachments, fileUploads, fs, llm, remoteAccess, sessions, sessionProjections, sessionQuery, typert, typertGateway, workspaceRegistry]
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"
      config:
        nativeOpen: false

    # The OFFICIAL Host `@`-file reference authority (M3-3A): this row is
    # the same one the official web bundle mounts. It provides
    # `ctx.fileReferences` (the discovery service the Session Controller's
    # `fileReferences/list` Remote already forwards to) AND installs the
    # official per-agent `context:file-reference` system prompt — the model
    # guidance that relative `@` paths resolve from the workspace root.
    # Mounting it aligns the TUI's `@`-mention semantics with the official
    # client contract: the selected mention text goes to the prompt
    # LITERALLY (`@src/foo.ts`), and the Host/model resolves it; the TUI's
    # historical send-time absolute-path rewrite is retired with it.
    - id: file-reference-local
      name: '@deepseek-ai/dsh-file-reference-local'
      # M6-2A: not gated on `tuiStartup`; must not mount in the daemon supervisor.
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # Shared Host prompt guidance for delivered file links and present results.
    # Independent of Web serving; inherited unchanged by Direct and Split Host.
    - id: deliverable-file-references
      name: '@deepseek-ai/dsh-deliverable-file-references'
      # M6-2A: not gated on `tuiStartup`; must not mount in the daemon supervisor.
      disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

    # The 0.1.7 declarative preset registry: preset identity, revisions and
    # default/selection policy are registry-owned (deployment `default` here;
    # the user's `selectedDefault` rides the profile form). The four shipped
    # preset declarations follow as separate patch files under
    # generated/dsh-presets/, listed after this file in package.json
    # `dsh.bundle.patch` — a generated, parity-gated byte-exact mirror of
    # @deepseek-ai/dsh-web-app's exported preset assets (0.1.7
    # dsh.bundle.patch cannot reference another package's files).
    - id: agent-preset-registry
      name: '@deepseek-ai/dsh-agent-preset-registry'
      config:
        default: standard

    # The official standard preset composes its `subagent` tool with
    # `modelSelection: true` + `modelDiscovery: true`, which injects this
    # Host-owned setting service — the row is required for the standard
    # composition to mount.
    # Mounting the service ALONE enables nothing: it only owns the
    # `subagent-model-selection` settings section (default enabled=false,
    # empty allowlist). Each NEW session samples that section at
    # composition; the TUI exposes the toggle + allowlist in /settings.
    - id: subagent-model-selection-settings
      name: '@deepseek-ai/dsh-tool-subagent/model-selection-settings'

    # Host-plane cordis runner: the `cordis` preset's `tool-cordis` row waits
    # for `dynamicCordisRunner`/`cordisInspect` and fails the preset at mount
    # without them (same host row the web bundle inserts).
    - id: cordis-host-runner
      name: '@deepseek-ai/dsh-cordis-host-runner'

# ── the agent plane moves behind agent presets ─────────────────────────────
#
# Every row below composes what ONE agent contributes to the host registries:
# its tools, its prompt sections, its delegation backends. The base keeps them
# for single-session surfaces that compose their agent process-wide; the TUI
# now composes one preset per session, so these rows are disabled here and the
# official `agent-preset-registry` row above, plus the declarations it resolves,
# lets each session mount a preset instead.
#
# Disabling rather than deleting is deliberate: the base is shared, and a row
# absent from a surface overlay would silently reappear the day someone
# reorders the composition. The disabled set is the web bundle's, unchanged.
#
# Rows that STAY on the host plane (not listed): `tools` (registry), `shell-env`
# (publishes the DSH env the model's shell sees), `subagent` + its spawn/fork
# backends (process singletons), `subagent-model-selection-settings`, the
# goal/jobs/compaction services and
# their host infrastructure, `permission`, `approval`, `sandbox*`,
# `fs-observation-policy`, `spill*`, `timeout-policy`, `repeat-tool-reminder`,
# `session-*`, `token-meter`. The base's official `ptc-runtime` row also stays:
# it provides `ptcRuntime`, which the `ptc` preset's `tool-executor-ptc` row
# injects, and this overlay owns no second PTC runtime.
# `command-goal` is disabled below and reintroduced
# only by presets that own that command in their scoped composition.

- id: tool-bash
  disabled: true

- id: tool-pwsh
  disabled: true

- id: tool-jobs
  disabled: true

- id: tool-fs
  disabled: true

- id: tool-fs-search
  disabled: true

- id: skill-filesystem
  disabled: true

- id: tool-skill
  disabled: true

- id: command-goal
  disabled: true

- id: tool-goal
  disabled: true

- id: plan-mode
  disabled: true

- id: compaction-basic
  disabled: true

- id: command-compact
  disabled: true

- id: tool-result-pruner
  disabled: true

- id: tool-subagent-control
  disabled: true

- id: tool-subagent
  disabled: true

- id: tool-subagent-fork
  disabled: true

- id: workflow-ptc
  disabled: true

- id: tool-workflow
  disabled: true

- id: agent-instructions
  disabled: true

- id: tool-todo
  disabled: true

- id: tool-web
  disabled: true

# ── M6-2A daemon-supervisor Host-business isolation ────────────────────────
# Under the daemon backend the `dsh --profile pi-tui` CLI is a short-lived
# supervisor; the real Host is the detached local-host.mjs. These are the
# official dsh-base rows that would be a SECOND Host Session/Storage/Jobs/
# Gateway/Account authority if they mounted in the supervisor, so they are
# disabled for the daemon backend only (condition evaluated per entry; Direct
# and Host-only never publish tuiDaemonStartup and keep every row unchanged).

- id: session
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-log-deepseek
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-persistence-jsonl
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-query-sqlite
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: storage
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: storage-json
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: storage-domain
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-projection
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-projection-cache
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-title
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-title-llm
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: jobs
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: typert-gateway
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: remote-access
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: plugin-manager
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: plugin-package-inventory-deepseek
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: credentials
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: deepseek-account
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: authorization
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: otel
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: session-telemetry-otel
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

- id: attachment-local
  disabled: !!js "ctx.get('tuiDaemonStartup') !== undefined"

