Repository navigation
Description
Outcome
uf_delegate_command — the tool /uf.unleash and /uf.run-pipeline-plan use to delegate work to content agents (default cobalt-crush-dev) — must run each delegated task on the model best suited to it, selected from a configured, capability-driven matrix, instead of always replaying the parent session's model.
Done means:
- Spec/plan/tasks authoring work ("meta-prompting") can run on a different model than code implementation, per configuration.
- Selection is deterministic, auditable, and overridable per call.
- A gitignored per-developer override file carries model identities; tracked config carries structure only (mirrors the review-matrix pattern).
- Zero-config is unchanged: with no matrix present, delegation behaves exactly as today (host model).
- The capability taxonomy ties back to UF convention packs (
.opencode/uf/packs/): a newmeta-promptpack maps to spec-authoring; language packs (go,typescript,python) map to code-writing. Example stakeholder configuration: meta-prompt → glm, go → deepseek (per developer, via the override file).
Motivation (stakeholder intent): there is a large capability gap between models good at meta-prompt engineering (spec/plan/tasks/command authoring) and models good at writing code; other capability categories likely exist and must be expressible without code changes.
Background
Where selection hooks in today
uf_delegate_commandis defined in.opencode/plugins/uf-workflow/index.ts(factorycreateDelegateCommandTool, ~line 1964). Current params:agent(any non-divisor-name, 1–128 chars),command_path,prompt,feature_dir,expected_artifact,checkpoint_step,phase,timeout(default 600,000 ms),task_classification(deterministic|judgment; required for prompt-only delegation),skill/skill_absent_reason(deterministic-only, mutually exclusive).- The child model today ALWAYS comes from
resolveHostModel()(.opencode/lib/agent-executor.ts~line 259) — parent-session introspection of the current assistant message. If that fails, delegation aborts withHOST_MODEL_UNAVAILABLE. executeAgentSession(.opencode/lib/agent-executor.ts~line 318) already accepts anyModelIdentity {providerID, modelID, combined}plus optionalvariant— review agents already run on non-host models viainvoke_agent. Running content agents on a chosen model is mechanically supported today; only the selection layer is missing.- Prompt composition (deterministic order): command text →
Feature directory: <dir>→ skill directive (renderSkillDirective, only when a skill reference resolved) → extra prompt. - Signals available in-tool at selection time:
command_path,checkpoint_step,phase,task_classification,agent,feature_dir,skill. - Delegation call sites:
.opencode/commands/uf.unleash.mdand.opencode/commands/uf.run-pipeline-plan.mdonly. - No pre-existing "model-matrix" references exist in
.opencode/,.uf/, orinternal/— the namespace is clean.
Pattern to mirror: the review matrix
This feature deliberately mirrors the existing review-dispatch matrix trio:
.uf/review-matrix.yaml(v3):profiles(weight tiers with optionalmodel+variant, 1–32 profiles),defaultsper mode,alwaysper-agent pins,runs,limits..uf/review-matrix.override.yaml: gitignored; whitelisted keys ONLYprofiles.<name>.modelandprofiles.<name>.variant; any other key fails validation, fail-closed. Implementation precedent:validateOverride()/mergeOverride()in.opencode/plugins/review-dispatch/index.ts(~lines 1669 / 1729).- Schemas:
.uf/schemas/review-matrix/(README.md, samples/, vN.schema.json; closed input,additionalProperties: false). - Docs:
docs/configuration.md(~line 274) documents the tracked/override pair. - Plugin code is mirrored into
internal/scaffold/assets/opencode/plugins/with drift tests enforcing byte-identity (internal/scaffold/scaffold_test.go,TestEmbeddedAssets_MatchSource). - Precedent OpenSpec changes to study:
openspec/changes/review-council-multi-model-fanout/(original matrix),openspec/changes/optional-profile-models/(optional profile model → host fallback; override whitelist),openspec/changes/derive-per-run-timeout/.
Decisions already made with the stakeholder
These define the contract; do not re-litigate without cause.
| Question | Decision |
|---|---|
| Selection mechanism | Hybrid: deterministic precedence chain by default; explicit params override |
| Agent scope | All content agents (any non-divisor- agent) |
| Fallback | Host model; missing matrix file = valid no-op |
| Config file | .uf/model-matrix.yaml + gitignored .uf/model-matrix.override.yaml |
| Matrix shape | Capability-named profiles + packs: mapping (pack → capability) |
pack param |
Double duty: selects model AND renders a pack directive in the child prompt |
| Auto-derivation | Classifier cascade (agent engine → LLM engine → static fallback) |
| Workflow tier | OpenSpec tactical change, repo-first slice; hero-repo deployment deferred to slice 2 |
Selection precedence (contract semantics)
- explicit
model(+variant) param - explicit
profile(capability) param - explicit
packparam (validated: pack file exists in.opencode/uf/packs/AND has a matrix entry) agents:pin- static
defaults:by task kind (checkpoint_stepplan/tasks→ spec-authoring) - classifier cascade for
implementand unknown kinds: agent engine → LLM engine → static default - host model (resolved profile lacks a model, or no matrix)
Side effect to preserve: when any matrix profile model resolves, host introspection is skipped entirely — delegation no longer fails on HOST_MODEL_UNAVAILABLE.
Classifier (auto-derivation)
Modeled on the auto-question plugin pattern (investigate-then-decide subagent with a JSON-only response contract, plus an LLM-engine fallback):
- Agent engine: new hidden subagent (e.g.
.opencode/agents/model-matrix-classifier.md; modesubagent, hidden, description "Internal to the model-matrix plugin"). It investigates the feature dir's spec/plan/tasks plus existing code/diff with tools, then responds with ONLY a JSON object —{"pack": "<name>", "confidence": <0.0-1.0>, "reasoning": "<optional>"}— no markdown fences, no prose, never asks questions. The child session inherits the model hierarchy (no endpoint config needed). - LLM engine: chat-completions POST,
temperature: 0,response_format: {type: "json_object"}with a 400-retry without it (some endpoints reject the field), request timeout via AbortSignal,{env:VAR}environment interpolation for apiKey (established secrets pattern — never a literal key). Endpoint/model config lives only in the gitignored override file. - First valid, above-confidence-threshold, matrix-valid pack wins. Below threshold or any failure → static default. Classifier failure never blocks delegation. Cache classifier results (keyed by sha256 of feature_dir + prompt + agent, capped).
- A classifier-selected pack also renders the pack directive (double duty).
Audit trail
The delegation success envelope and checkpoint data record selection_source (one of: explicit-model, explicit-profile, explicit-pack, agent-pin, default-kind, classifier-agent, classifier-llm, host), the selected pack/capability/model, and classifier confidence when applicable.
Recommended approach (starting point — adapt if circumstances demand)
Tracked matrix v1 shape:
version: 1
profiles: # capability-named model slots; model optional → host fallback
spec-authoring: {} # filled per-developer by the override file
code-writing: {}
content-writing: {}
mechanical: {}
packs: # pack name → capability (validated against .opencode/uf/packs/)
meta-prompt: spec-authoring
go: code-writing
typescript: code-writing
python: code-writing
content: content-writing
defaults: # closed key set: task kind → capability
plan: spec-authoring
tasks: spec-authoring
implement: code-writing
agents: {} # per-agent capability pins
classifier: # structure only — no model strings in tracked config
enabled: true
agent: model-matrix-classifier
agent_timeout_ms: 45000
llm: {}
confidence_threshold: 0.6Override whitelist (fail-closed): profiles.*.model, profiles.*.variant, classifier.llm.*. Anything else — including structural keys — fails validation with an error naming the whitelist.
Starter capability set (adjustable at spec review): spec-authoring, code-writing, content-writing, mechanical. Cross-cutting packs (severity, determinism, review-voice, default) get no matrix entries — they are never the primary capability of a task.
File map:
New: .uf/model-matrix.yaml · .uf/schemas/model-matrix/ (v1.schema.json + README + samples) · .opencode/agents/model-matrix-classifier.md · .opencode/lib/model-matrix.ts (loader, schema validation, override merge, precedence resolution, classifier engines; injectable dependencies.readText for tests, following loadPolicies) · .opencode/test/model-matrix*.test.ts · the OpenSpec change directory.
Modified: .opencode/plugins/uf-workflow/index.ts (new params, selection integration, pack directive) · internal/scaffold/assets/opencode/plugins/uf-workflow/index.ts (byte-identical mirror — drift test forces sync) · internal/scaffold/assets/opencode/lib/model-matrix.ts (mirror of the new lib module — REQUIRED: the mirrored plugin imports it; a missing mirror breaks plugin load in scaffolded hero repos) · internal/scaffold/scaffold.go (tool-owned asset enum += lib file name; gitignoreBlock += .uf/model-matrix.override.yaml) · .gitignore (+= .uf/model-matrix.override.yaml) · docs/configuration.md · CHANGELOG.md · .opencode/commands/uf.unleash.md (recommended: instruct passing pack on implement delegation when the task clearly names one; the classifier covers the rest).
Pack directive (prompt composition gains one tool-rendered section after the skill directive; golden-shape tested, never agent-reconstructed, mirroring renderSkillDirective): a short instruction to load .opencode/uf/packs/<pack>.md before writing — not the pack content inlined.
Acceptance criteria (the contract)
- A delegated task runs on a non-host model configured via
.uf/model-matrix.yaml+ override, proven by an integration test with a mocked child session. plan/tasksdelegations resolve to the spec-authoring capability;implement/unknown kinds go through the classifier cascade with static fallback.- Explicit
model/profile/packparams override all automatic selection, in the documented precedence order. - Missing
.uf/model-matrix.yaml→ behavior identical to today (host model, no errors). - The override file accepts only whitelisted keys; anything else fails closed with a clear error naming the whitelist.
- The
packparam renders a tool-generated pack directive in the child prompt (golden-shape test). - Classifier failure, timeout, or low confidence never blocks delegation; falls back statically; the audit trail records it.
- Every selection records
selection_sourceand the resolved model in the delegation envelope / checkpoint data. make checkandmake plugin-testpass (mirrors synced; 94% statement coverage floor held for the.opencode/suite).docs/configuration.mddocuments the new config pair; a CHANGELOG entry exists.
Constraints (non-negotiable)
- This issue is the originating issue for the OpenSpec change (
originating_issue: <this issue number>in.openspec.yaml); spec artifacts are committed before implementation. Route via/uf.unleash #<N>or/opsx-propose— the OpenSpec change becomes the working contract once written. - Gatekeeping: no weakening of coverage floors, review limits, CI flags, or pinned dependency versions.
- Phase boundaries: spec → implement → review; review-phase changes are fixes only.
- CI parity: replicate CI checks locally (
make check) before marking tasks complete. - Documentation gate: file a documentation issue for this user-facing change before PR merge.
- Explicit staging only; never
git add -A/git add .. - When implementation must deviate from the recommended approach above, preserve the contract semantics: precedence order, fail-closed override whitelist, host fallback, missing-matrix no-op, classifier-never-blocks, and the audit trail.
Dependencies and split work
- UF convention pack: meta-prompt authoring rules for spec/plan/tasks/command work (model-matrix-delegation) #888 — the
meta-promptconvention pack. Required for the starterpacks:mapping to validate (pack existence check); may be authored inside this change as a distinct task if the implementer prefers. - Slice 2: deploy model-matrix config and meta-prompt pack to hero repos via uf init (model-matrix) #889 — hero-repo deployment via
uf init(slice 2). Out of scope here.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
docs(model-matrix): file documentation issue, record Closes bookkeepi…
docs(openspec): add model-matrix-delegation change artifacts
docs(model-matrix): file documentation issue, record Closes bookkeepi…
docs(openspec): add model-matrix-delegation change artifacts
docs(model-matrix): file documentation issue, record Closes bookkeepi…