Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
"""Agentic Claude Code adapter.
|
|
|
|
|
|
|
|
|
|
llm-connect's ClaudeCodeAdapter is a text-generation adapter (`claude
|
|
|
|
|
--print`, no working directory, no tool grants). An executor run needs an
|
|
|
|
|
*agentic* session: file edits and git commits inside the target repo, under
|
|
|
|
|
a hard tool allow-list. This adapter subclasses it, keeping the llm-connect
|
|
|
|
|
LLMAdapter interface so a hosted adapter can be swapped in later, and adds:
|
|
|
|
|
|
|
|
|
|
- cwd pinned to the target repo
|
|
|
|
|
- --permission-mode acceptEdits
|
2026-07-17 23:49:03 +02:00
|
|
|
- allow-list from a named tool profile (default: green-commit-only)
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from llm_connect.claude_code import ClaudeCodeAdapter
|
|
|
|
|
from llm_connect.exceptions import LLMSubprocessError, LLMTimeoutError
|
|
|
|
|
from llm_connect.models import LLMResponse, RunConfig
|
|
|
|
|
|
Rename package, CLI, and deploy artifacts to rein-aharness (HARNESS-WP-0002-T02)
agent_harness -> rein_aharness (package + all imports), CLI command
agent-harness -> rein-aharness, Docker image tag, k8s namespace/labels/
names, Makefile targets, deploy script env var/paths. In-repo identity
strings (hub event source, metrics harness field, default assignee,
argparse prog name, commit author identity) updated to match.
Historical documents left untouched on purpose: docs/adr/ADR-001-agent-harness-architecture.md,
docs/architecture.md (dated v0.1 snapshot), workplans/HARNESS-WP-0001
(completed under the old name), and the SSH host alias
"forgejo-agent-harness" (external ~/.ssh/config entry, not owned here).
Verified: 47/47 tests pass, CLI runs correctly from a fresh venv,
`make image` builds and the resulting container runs correctly.
deploy/README.md gained an explicit rename cutover checklist for what
this session cannot safely do unattended -- moving the host-side
secrets dir and checkout on railiance01, and not deleting the old k8s
namespace until the new one is confirmed working. The actual live
cutover (running that checklist against the real Railiance deployment)
is not attempted here -- real production surgery on binky-control's
live automation, needs the operator present.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-26 14:22:18 +02:00
|
|
|
from rein_aharness.profiles import ToolProfile, get_profile
|
2026-07-17 23:49:03 +02:00
|
|
|
|
|
|
|
|
# Backward-compatible alias for the seed profile allow-list string.
|
|
|
|
|
ALLOWED_TOOLS = get_profile("green-commit-only").allowed_tools
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class AgenticClaudeCodeAdapter(ClaudeCodeAdapter):
|
2026-07-17 23:49:03 +02:00
|
|
|
def __init__(
|
|
|
|
|
self,
|
|
|
|
|
workdir: Path,
|
|
|
|
|
*,
|
|
|
|
|
tool_profile: str | ToolProfile = "green-commit-only",
|
|
|
|
|
**kwargs,
|
|
|
|
|
):
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
self._workdir = workdir
|
2026-07-17 23:49:03 +02:00
|
|
|
if isinstance(tool_profile, ToolProfile):
|
|
|
|
|
self._profile = tool_profile
|
|
|
|
|
else:
|
|
|
|
|
self._profile = get_profile(tool_profile)
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def tool_profile(self) -> ToolProfile:
|
|
|
|
|
return self._profile
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
|
|
|
|
|
def _build_command(self, config: RunConfig) -> list[str]:
|
|
|
|
|
cmd = [
|
|
|
|
|
self._cli_path,
|
|
|
|
|
"--print",
|
|
|
|
|
"--permission-mode",
|
|
|
|
|
"acceptEdits",
|
|
|
|
|
"--allowedTools",
|
2026-07-17 23:49:03 +02:00
|
|
|
self._profile.allowed_tools,
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
]
|
|
|
|
|
if self._model:
|
|
|
|
|
cmd.extend(["--model", self._model])
|
|
|
|
|
return cmd
|
|
|
|
|
|
|
|
|
|
def execute_prompt(self, prompt: str, config: RunConfig) -> LLMResponse:
|
|
|
|
|
self._preflight_budget(config)
|
|
|
|
|
cmd = self._build_command(config)
|
|
|
|
|
timeout = config.timeout_seconds or self._config.timeout_seconds
|
|
|
|
|
try:
|
|
|
|
|
result = subprocess.run(
|
|
|
|
|
cmd,
|
|
|
|
|
input=prompt,
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
timeout=timeout,
|
|
|
|
|
cwd=self._workdir,
|
|
|
|
|
)
|
|
|
|
|
except subprocess.TimeoutExpired as exc:
|
|
|
|
|
raise LLMTimeoutError(
|
|
|
|
|
f"claude CLI timed out after {timeout}s", cause=exc
|
|
|
|
|
) from exc
|
|
|
|
|
if result.returncode != 0:
|
|
|
|
|
raise LLMSubprocessError(
|
|
|
|
|
f"claude CLI exited with code {result.returncode}",
|
|
|
|
|
return_code=result.returncode,
|
|
|
|
|
stderr=result.stderr,
|
|
|
|
|
)
|
2026-07-17 23:49:03 +02:00
|
|
|
response = LLMResponse(
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
content=result.stdout,
|
|
|
|
|
model=self._model or "claude-code-cli",
|
|
|
|
|
usage={},
|
|
|
|
|
finish_reason="stop",
|
|
|
|
|
metadata={
|
|
|
|
|
"provider": "claude-code-agentic",
|
|
|
|
|
"cli_path": self._cli_path,
|
|
|
|
|
"workdir": str(self._workdir),
|
2026-07-17 23:49:03 +02:00
|
|
|
"tool_profile": self._profile.name,
|
Harness foundation: INTENT, ADR-001, architecture, prototype adoption
- INTENT.md: three-layer model (blueprint/instance/harness), single
shared runtime, never-become boundaries
- ADR-001 (accepted): DEC-2026-002 resolution — one harness repo for
all projects; instances are declarative state in consuming repos
- docs/architecture.md: components, contracts (manifest, tool
profiles, completion events, credential lanes), deployment shape
- agent_harness/: executor-worker prototype adopted and renamed
(6/6 tests green); HARNESS-WP-0001 initial workplan (7 tasks)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-17 23:35:27 +02:00
|
|
|
},
|
|
|
|
|
)
|
2026-07-17 23:49:03 +02:00
|
|
|
self._consume_budget(config, response)
|
|
|
|
|
return response
|