Skip to content

feat: generalize host routing and add OpenCode as a routable execution host #76

Description

@pacphi

Summary

Generalize agentic-kit's current Claude+Codex dual execution substrate into capability-driven multi-host routing, then add OpenCode as the first third routable execution host.

This is the immediate follow-on to:

Do not implement this work by merely changing OpenCode's canRouteActivities flag. That flag is a safety gate. It may become true only after a real execution adapter and generalized orchestrator can launch, supervise, interpret, cancel, and verify OpenCode workers.

Problem

The routing policy is increasingly capability-driven, but execution is still coupled to @claude-flow/codex and the vocabulary/assumptions of exactly two worker platforms:

  • ak dual run delegates to claude-flow-codex;
  • workers execute through claude -p or codex exec;
  • templates and escalation ladders assume Claude/Codex platform identifiers;
  • configuration and documentation define dual as the Claude+Codex collaboration substrate;
  • there is no OpenCode worker launcher, structured-result interpreter, cancellation contract, or readiness probe.

OpenCode now exposes credible automation surfaces:

  • opencode run for non-interactive execution;
  • --model, --agent, --format json, --dir, and --auto;
  • attachment to a persistent opencode serve process;
  • a headless HTTP/OpenAPI server; and
  • ACP over stdin/stdout.

The remaining limitation is therefore agentic-kit's orchestration integration, not a categorical inability of OpenCode to execute headlessly.

Goals

  1. Define one host-worker execution contract independent of Claude, Codex, and OpenCode.
  2. Adapt existing Claude and Codex execution without regressing ak dual.
  3. Implement and prove an OpenCode worker adapter.
  4. Allow per-activity routes and ordered escalation ladders to target any capability-qualified routable host.
  5. Preserve host/provider/provenance separation introduced by ADR-0016.
  6. Generalize user-facing vocabulary and configuration without silently changing existing dual behavior.
  7. Keep automatic route seeding cost-safe.
  8. Produce sufficient independent evidence for qe-court to render a cross-vendor verdict.

Non-goals

  • Do not fold this into feat: OpenCode as a managed non-routable host adapter (ADR-0017) #67.
  • Do not treat OpenCode as an AQE inference-provider type.
  • Do not infer an execution provider solely from the OpenCode host.
  • Do not add a dashboard control plane.
  • Do not promise OpenCode subscription, quota, or cost semantics that cannot be observed.
  • Do not remove the existing ak dual compatibility surface without a documented migration and deprecation decision.
  • Do not make canRouteActivities: true precede a verified execution adapter.

Proposed architecture

1. Host-worker adapter contract

Introduce a contract conceptually covering:

detect/readiness
  → prepare
  → launch
  → stream/observe
  → interpret result
  → cancel/timeout
  → cleanup

The exact names may follow existing lifecycle vocabulary, but execution and configuration lifecycle must remain distinct concerns.

Each adapter must define:

  • executable/readiness detection;
  • command/API construction;
  • working-directory and environment handling;
  • model and agent normalization;
  • structured event/output parsing;
  • success/failure/cancellation interpretation;
  • timeout and signal behavior;
  • permission/sandbox policy;
  • authentication/provider readiness facts;
  • transcript/evidence correlation;
  • cleanup and orphan prevention.

Initial adapters:

Host Execution surface
Claude Code claude -p
Codex CLI codex exec
OpenCode initially evaluate opencode run --format json --auto; compare against ACP/server attachment before fixing the contract

The OpenCode transport choice must be recorded in an ADR with observed tradeoffs. Prefer the smallest reliable surface that supports deterministic completion, cancellation, structured evidence, and repo mutation.

2. Generalized orchestrator

Separate pipeline orchestration from claude-flow-codex platform assumptions:

  • materialize workers from the canonical per-activity policy;
  • resolve a host-worker adapter by registry capability;
  • honor dependency ordering and bounded concurrency;
  • share only explicitly supported coordination state;
  • propagate cancellation and timeout;
  • collect normalized worker results;
  • apply ordered escalation consistently across hosts;
  • prevent unsupported hosts from entering a runnable plan.

Determine whether to:

  1. extend/replace the upstream adapter;
  2. add an agentic-kit-owned thin generalized adapter; or
  3. introduce a versioned adapter interface with claude-flow-codex retained as the Claude/Codex implementation.

The decision must be grounded in upstream capabilities and recorded before implementation is locked in.

3. Vocabulary and CLI compatibility

dual currently means Claude+Codex. Adding a third routable peer must not silently redefine it.

Design and document one of:

  • a new generalized command such as ak run / ak swarm run while retaining ak dual as a compatibility projection; or
  • a versioned generalization with an explicit migration/deprecation path.

Requirements:

  • existing Claude/Codex route configuration remains readable;
  • existing ak dual invocations retain behavior during the compatibility window;
  • templates become host-neutral activity pipelines;
  • ak host pick --route validates against canRouteActivities;
  • primary-host semantics are explicitly revisited rather than automatically extended;
  • help, README, provider/host docs, upgrading docs, dashboard labels, and ADR vocabulary agree.

4. Routing and model normalization

OpenCode model identifiers use provider/model. The canonical policy must keep these axes distinct:

activity → execution host + optional host model selector
host execution → observed/configured inference provider + exact model + provenance

Define:

  • accepted OpenCode model selector syntax;
  • whether the policy stores an opaque host-native selector or normalized fields;
  • validation without turning curated catalogs into hard allowlists;
  • migration of existing Claude/Codex route entries;
  • behavior when a configured OpenCode provider/model is unavailable.

5. Permission and unattended-execution safety

Ground and test OpenCode's non-interactive permission semantics:

  • explicit policy for --auto;
  • behavior for operations explicitly denied by configuration;
  • protection against an unattended permission prompt/hang;
  • external-directory and secret-file behavior;
  • timeout if structured progress stops;
  • no implicit weakening of user-owned OpenCode permission rules.

Document which policy is owned by agentic-kit and which remains user-owned.

6. Cost safety and provider provenance

OpenCode can route inference through multiple providers. Therefore:

  • enabling OpenCode routing must not silently introduce a metered path;
  • automatic seed defaults may target OpenCode only when billing/provenance is sufficiently grounded and allowed by the existing cost-safety rules;
  • an unknown OpenCode inference provider remains unknown, not inferred from model naming or host identity;
  • escalation must disclose when it can cross billing classes;
  • qe-court vendor diversity must use established inference-vendor evidence, not merely three different host CLIs.

7. Observability and normalized results

Define a normalized worker result that can represent:

  • host;
  • activity/role;
  • configured model selector;
  • observed provider/model and provenance;
  • session/correlation ID;
  • timestamps/duration;
  • status and exit category;
  • structured failure reason;
  • transcript/event references where supported;
  • cost/usage only when grounded.

OpenCode JSON/ACP/server events must be tested against recorded fixtures with secrets removed.

Implementation slices

  1. Specification/ADR
    • choose orchestration ownership and command vocabulary;
    • define execution-adapter and normalized-result contracts;
    • define migration/compatibility and cost-safety decisions.
  2. Contract and Claude/Codex parity
    • implement adapters around current execution;
    • prove no behavioral regression in existing templates, escalation, timeout, and dry-run.
  3. OpenCode proof harness
    • capture sanitized structured fixtures;
    • prove readiness, repo mutation, result parsing, timeout, cancellation, denied operations, and cleanup.
  4. OpenCode adapter
    • implement against the selected transport;
    • retain canRouteActivities: false until adapter conformance and integration tests pass.
  5. Generalized routing/CLI
    • enable OpenCode route selection;
    • migrate/project existing policy;
    • preserve ak dual compatibility.
  6. Observability/dashboard/docs
    • expose honest normalized facts;
    • update canonical docs and upgrading guidance.
  7. Verification
    • full repository gates;
    • live smoke tests for all three hosts where credentials are available;
    • ruflo swarm review;
    • qe-court cross-vendor verdict.

Required tests

Adapter conformance

  • every routable host implements the complete execution contract;
  • non-routable hosts cannot materialize runnable workers;
  • readiness failure occurs before partial orchestration starts;
  • timeout/cancellation always terminates or reports any surviving child;
  • cleanup is idempotent.

Claude/Codex regression

  • current templates materialize the same effective host assignments;
  • sequential/parallel behavior remains bounded;
  • escalation produces the same next rung;
  • dry-run remains side-effect free;
  • auth/model errors remain distinguishable from routing errors.

OpenCode integration

  • non-interactive edit succeeds in a sandbox repository;
  • structured output produces a normalized successful result;
  • configured model/agent/directory reach the invocation correctly;
  • an explicit permission denial fails deterministically;
  • no permission prompt can hang CI indefinitely;
  • timeout and cancellation stop the worker;
  • malformed/truncated structured events fail honestly;
  • absent CLI, missing auth, unavailable model, and non-zero exit are distinct;
  • user-owned OpenCode configuration is not weakened or overwritten;
  • concurrent workers use isolated sessions/workspaces as designed.

Routing/migration

Evidence and qe-court

  • host diversity is not mistaken for inference-vendor diversity;
  • unknown provider/model remains unknown;
  • correlated OpenCode events establish host/session provenance;
  • qe-court receives at least two independently evidenced vendors for a diversity-backed verdict.

Acceptance criteria

  • feat: OpenCode as a managed non-routable host adapter (ADR-0017) #67 is merged first as the managed, observable, non-routable OpenCode baseline.
  • An accepted ADR defines generalized orchestration, CLI vocabulary, migration, and OpenCode transport.
  • Claude, Codex, and OpenCode satisfy one tested host-worker execution contract.
  • Existing ak dual workflows remain compatible or have an explicit, tested migration path.
  • OpenCode becomes canRouteActivities: true only in the same change that makes its runnable contract real.
  • An explicit activity can route to OpenCode and complete a sandboxed repository mutation.
  • Timeout, cancellation, permissions, authentication, and malformed-output behavior are deterministic.
  • Ordered cross-host escalation is tested.
  • Automatic routing cannot silently introduce an unknown metered provider.
  • Host/provider/model provenance remains normalized and evidence-backed.
  • pnpm run check passes.
  • pnpm run test:surface passes.
  • Relevant live smoke tests pass on the exact final head.
  • A ruflo swarm reviews architecture, implementation, testing, security, docs, and migration.
  • qe-court convenes on the exact final head and returns a passing cross-vendor verdict, or all blocking findings are remediated and the court is reconvened.

Dependencies and ordering

  1. Merge feat: OpenCode as a managed non-routable host adapter (ADR-0017) #67 after it is rebased onto the feat: add capability-driven integration adapters #74 architecture and passes its own qe-court review.
  2. Reconcile or incorporate x provider pick: excluding a routing host (codex) leaves seeded routes, agentOverrides, and MCP bridges live — one disable semantics for all hosts #73's disable semantics so generalized routing cannot leave stale routes/bridges.
  3. Start this issue from the clean post-feat: OpenCode as a managed non-routable host adapter (ADR-0017) #67 main.

This issue should be the source of truth for the immediate follow-on activity. Keep #67 focused on complete managed-host integration and honest non-routability.

Managed OpenCode CLI parity

OpenCode must retain the same managed-CLI lifecycle as Claude and Codex while routing is generalized:

  • an enabled but absent OpenCode CLI is installed as opencode-ai by ak host pick, setup, or sync;
  • npm-managed versions participate in the shared version-drift/update path;
  • external/brew/mise/native installs are detected but never shadowed or overwritten;
  • ak host, setup, sync, status, and teardown converge or remove only agentic-kit-owned OpenCode integration artifacts;
  • installation success alone is not execution readiness: wiring follows post-install detection, and routing remains disabled until the worker adapter contract is proven.

Required parity coverage: enabled-absent install, declined/failed install, npm version drift, external-install preservation, post-install wiring, status visibility, and marker-precise teardown.

Live baseline recorded 2026-07-29: opencode-ai 1.18.9 was installed through npm, enabled with ak host pick --host claude,codex,opencode --yes, and status reports the CLI, managed MCP wiring, converted agents, and npm ownership as healthy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions