# dsh-rigorquant bundle patch — the skill layer and model router of this
# distribution.
#
# `dsh plugin --profile <p> add dsh-rigorquant` (or the github: spec) makes
# the `rigorquant` skill and the role-model router available to every session
# of that profile, and declares the `rigorquant` preset through
# ./agent-presets/rigorquant.patch.yml. ./install.sh adds Agent Teams and
# carries saved routes over.
#
# The skill directory is resolved through the PACKAGE, not through `baseUrl`.
# A patch file's `!!js` runs against the boot root context, whose `baseUrl` is
# the PROFILE directory (`dsh-app-boot`: `ctx.baseUrl = dirname(absoluteConfigPath)`),
# not this file's package root — per-file base anchors are an `Include`
# behaviour that only composition files get. `createRequire` therefore walks
# the profile's `node_modules` to the installed package, wherever pnpm put it.
#
# `includeDefaultRoots: false` keeps THIS provider off the default roots; it
# does not stop the default provider from serving them. A machine that also ran
# ./install.sh therefore has rigorquant, arxiv, and academic-paper-search in
# both places. That resolves deterministically rather than ambiguously: a
# custom root ranks 300 and $DSH_HOME/skills ranks 400, and the lower rank wins
# a duplicate name, so the copy shipped with this package is always the one
# that serves. The $DSH_HOME/skills copies are shadowed, not consulted —
# running ./install.sh --skill-only alongside the plugin is redundant, not
# harmful.
- insert:
    - id: skill-filesystem-rigorquant
      name: '@deepseek-ai/dsh-skill-filesystem'
      config:
        providerName: rigorquant
        includeDefaultRoots: false
        customSkillDirs:
          - !!js "process.getBuiltinModule('node:path').join(process.getBuiltinModule('node:path').dirname(process.getBuiltinModule('node:module').createRequire(baseUrl + 'package.json').resolve('dsh-rigorquant/package.json')), 'agent-presets', 'rigorquant', 'skills')"

    # Role-routed models (see docs/architecture.md, Decisions 16 and 25). Each
    # role's primary and fallback are `.volatile()` fields of THIS row's
    # config (`<role>Primary`, `<role>Fallback`), so the profile owns them
    # and a saved route applies on the next request; the browser half edits
    # them on this bundle's page under Plugins. The router overlays those
    # choices plus a fallback on terminal route failure. It carries the
    # shipped tier matrix itself (DoubleChecker and adversary on pro; every
    # other role inherits the session model, root following the chatbox
    # picker), moves that matrix to `deepseek-account` when only the account
    # route is routable, and resolves the role from the Team membership name
    # (Decision 24). Agents with no membership, or outside this preset, are
    # never touched.
    - id: rq-model-router
      name: 'dsh-rigorquant'

    # Compute-lane sync (docs/architecture.md, Decisions 22 and 25). The
    # preset is declared in ./agent-presets/rigorquant.patch.yml; what a
    # declaration cannot serve is the uv lane, since node_modules cannot host
    # it. This host half therefore lands env/, mcp/ and docs/ into
    # $DSH_HOME/share/rigorquant/ at boot (idempotent byte-compare; derived
    # state such as .venv never copied or pruned) and removes the directory
    # preset an older release landed, only when its .rq-sync.json names this
    # package. Removal of the lane stays
    # explicit via ./install.sh --uninstall.
    - id: rq-lane-sync
      name: 'dsh-rigorquant/sync'

    # Team composition: role personas, tool-tier budgets, and the "RigorQuant
    # team guard: armed" runtime context line (docs/architecture.md,
    # Decision 24; docs/adr/0001-rigorquant-on-agent-teams.md). Declares the
    # `agentTeams` service OPTIONAL and reaches it duck-typed by service name,
    # never importing the experimental Agent Teams packages. It also
    # registers the per-call guards (send_message target, roster-blindness,
    # own-task-only board access, bash network denial, spawn_teammate
    # refusal). The preset carries no classic delegation row, so this row is
    # the only source of a teammate's composition.
    - id: rq-team
      name: 'dsh-rigorquant/team'

# Decision 24 cap consistency pin (docs/adr/0001-rigorquant-on-agent-teams.md):
# the same `maxMembers` override ./install.sh writes into the profile's user
# patch, restated here so a profile that enables Agent Teams through this
# package's own bundle patch (rather than through ./install.sh) still gets
# the raised lifetime cap. A non-insert, id-targeted patch replaces the row's
# `config` wholesale (`@deepseek-ai/cordis-plugin-include`'s `applyEntryPatches`),
# so this is a no-op — not an error — everywhere the Team layer is absent,
# and effective only when it precedes this bundle in the profile's `bundles`
# order; the loader's own "entry not found" warning fires otherwise.
- id: agent-team
  config:
    maxMembers: 64
    maxTasks: 256
    maxPendingMessagesPerMember: 64
    maxMessageBytes: 65536
    disposalTimeoutMs: 5000
