Adding a harness adapter
Audience: Developers — Contributors implementing or reviewing harness adapters.
An adapter translates one agent runtime into hpilot's common launch, streaming, cancellation, and post-run evaluation interfaces. Pipeline orchestration, retries, routing, contract validation, and verifier policy stay in shared modules.
Required surface
Implement an AgentAdapter and register its descriptor in hpilot.adapters.registry. The adapter must provide:
- command or SDK launch through
start(request) - cancellation and wait semantics through its execution handle
- canonical stream events for replies, reasoning, tools, and session metadata
evaluate_reply(context, reply_text, session_id=None)when its descriptor declaressupports_post_run_evaluation=True- a health check and any adapter-specific authentication discovery
HarnessCapabilities advertises behavior. Do not add harness-name conditionals to pipeline code; keep transport-specific behavior inside the adapter.
supports_model_effort is structural: it declares that the adapter can carry HarnessLaunchRequest.effort to its harness. It never declares an effort vocabulary. Do not add adapter or provider effort allowlists to hpilot; forward normalized values and let the harness or provider decide validity.
Raise HarnessConfigurationError only for deterministic configuration rejection that another identical attempt cannot repair. Preserve the canonical harness name and native diagnosis. Transient transport, timeout, rate-limit, server, authentication, contract, artifact, and hook failures must remain ordinary retryable failures. If an adapter uses a worker thread, carry the typed exception back to the pipeline thread before broad exception fallback.
Post-run evaluation
HarnessLaunchRequest.evaluation_context contains an immutable StageEvaluationContext:
@dataclass(frozen=True)
class StageEvaluationContext:
harness: str
workspace_root: Path
stage_name: str
stage_prompt: str
contract: StageContractConfig | None
attempt: int
max_retries: int
event_log_path: PathUse the context passed by the pipeline. Do not reconstruct stage state from a runtime file and do not edit an agent's persistent settings. A normal adapter implementation is a thin call to the shared evaluator:
from hpilot.evaluation.reply import evaluate_stage_reply
def evaluate_reply(
self,
context: StageEvaluationContext,
*,
reply_text: str,
session_id: str | None = None,
) -> AgentDecision:
return evaluate_stage_reply(
context=context,
display_name=self.descriptor.display_name,
reply_text=reply_text,
session_id=session_id,
)The shared evaluator validates the active contract first and then asks the configured verifier for a structured approve or block decision. Malformed responses use structured-output recovery; unavailable verification fails safely. Evaluation events append directly to .hpilot/logs/evaluation-events.jsonl.
Verifier endpoint, model, and API-key configuration belongs in ~/.hpilot/config.yaml; never persist verifier secrets in a workspace. The evaluation context and event records contain only non-secret stage metadata.
Adapters that support conversational continuation translate a blocking AgentDecision with continuation_message_for_decision() and resume their existing session. Final-attempt behavior is available as context.is_final_attempt.
Read-only paths
Read-only enforcement is separate from reply evaluation:
- Claude, Codex, Cursor, and Antigravity use the shared Git-backed guard.
- OpenCode emits ordered native V2 root/agent/session permissions, preserving denies after ask normalization. Known MCP file-write requests use actual-path native admission; arbitrary shell access is not a security boundary. See the adapter lifecycle and verification gates.
Enforcement must never mutate persistent user settings. Preserve adapter-local permission configuration in the launched process only.
Streaming and cancellation
Normalize tool calls without changing their arguments. Visible assistant text maps to reply:, internal model output maps to thinking:, and tool activity maps to tool call:. Preserve provider session identifiers when available.
Cancellation must stop the active SDK task or process group, perform bounded cleanup, and return code 130. A handle's wait() must be idempotent.
Registration and validation
Add the adapter descriptor to the registry and verify:
- the declared adapter name is unique
- required launch, health, and stream methods exist
evaluate_replyexists when post-run evaluation is advertised- credential failures are actionable and contain no secret values
Tests
Add:
- descriptor and registry-validation tests
- launch request and stream translation tests
- cancellation and process cleanup tests
- context propagation tests covering prompt, contract, and attempt
- approve, block, malformed response, and verifier-unavailable tests
- proof that no agent settings file is created or changed
- positive and adjacent-negative classification tests for deterministic configuration rejection
Run:
uv run ruff check src/
uv run mypy --strict src/
uv run pytestNative session declaration
Every registered adapter must set AdapterDescriptor.native_session_behavior to a frozen NativeSessionBehavior with explicit values for records_runtime, supports_direct_resume, supports_native_discovery, and discovery_requires_non_interactive_flag. The four values are independent descriptive statements and must never be derived from one another.
This metadata is not a capability gate and never proves visibility. Add a native-surface integration test that captures the exact returned identifier, finds it in the harness-owned store, exercises the supported list, picker, export, or direct-resume surface, and skips cleanly when the CLI or credential is unavailable. Keep transcript content and credentials out of output. A production adapter without the declaration fails registry validation.