# DSH remote-aware web-startup + auth bundle.
#
# This patch is meant to be applied AFTER the web-app bundle layer, so it can:
#   1. disable the stock web-startup (which hard-rejects --host 0.0.0.0)
#   2. insert a remote-capable startup that provides the same webStartup service
#   3. insert an auth plugin with front-end login/register
#   4. point the `connection` row's trustedHosts at the remote startup's
#      complete authority list, and inject `webAuth` so the row waits for the
#      auth plugin to wrap the webserver's route registration.
#
# Usage:
#   dsh --profile web --patch ./cordis.patch.yml --host 0.0.0.0

- id: web-startup
  disabled: true

- id: connection
  # webServer must stay in this list: HostConnectionService.register runs
  # `owner.webServer.register(route)` against the connection row's inject
  # scope, so third-party consumers of `ctx.connection.rpc.handle` /
  # `connection.fetch.register` (e.g. dsh-ntr) fail with `cannot get property
  # "webServer" without inject` when it is dropped (E2E 2026-10-12, the 0.2.1
  # preview stock row [webStartup] has the same gap). webStartup carries the
  # fence authority list the expression below reads: cordis gates
  # ctx.<service> access on inject declarations (ungated access throws at
  # interpolation). webAuth is the ordering red line — this row must not
  # activate before the auth plugin wrapped the webserver's route
  # registration, or the /api routes mount unprotected
  # (docs/agent/auth-mechanics.md「路由保护顺序」). Row inject merges into the
  # connection module's own `inject`; it never replaces it.
  inject: [webServer, webStartup, webAuth]
  config:
    # One expression, both harness eras: on the 0.2.1 line this is verbatim the
    # stock row (upstream deleted resolveLanTrust and reads invocation
    # authorities from webStartup), on the 0.2.0 line it replaces the stock
    # `ctx.webRuntime.trustedHosts` consumption. Either way the list is the
    # remote startup's: --trusted-host values plus the bind-derived LAN/IPv6
    # authorities the stock derivations cannot produce for wildcard binds
    # (issue #35; docs/agent/ipv6-bind.md).
    trustedHosts: !!js ctx.webStartup.trustedHosts

- insert:
    - id: dsh-web-startup-auth
      name: dsh-web-startup-auth

    - id: remote-web-startup
      name: dsh-web-startup-auth/startup

    - id: web-auth
      name: dsh-web-startup-auth/auth
