-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathharbor_adapter.py
More file actions
95 lines (81 loc) · 3.62 KB
/
harbor_adapter.py
File metadata and controls
95 lines (81 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from __future__ import annotations
import os
import shlex
from harbor.agents.installed.base import BaseInstalledAgent, CliFlag, EnvVar, with_prompt_template
from harbor.environments.base import BaseEnvironment
from harbor.models.agent.context import AgentContext
class ClawCodeInstalledAgent(BaseInstalledAgent):
"""
Harbor installed-agent adapter for claw-code-agent.
This installs the published GitHub repo inside the Harbor environment and
runs the CLI in one-shot mode against the task working directory.
"""
CLI_FLAGS = [
CliFlag("max_turns", cli="--max-turns", type="int"),
CliFlag("append_system_prompt", cli="--append-system-prompt", type="str"),
CliFlag("system_prompt", cli="--system-prompt", type="str"),
CliFlag("stream", cli="--stream", type="bool"),
CliFlag("allow_write", cli="--allow-write", type="bool", default=True),
CliFlag("allow_shell", cli="--allow-shell", type="bool", default=True),
]
ENV_VARS = [
EnvVar("openai_api_key", env="OPENAI_API_KEY", type="str", env_fallback="OPENAI_API_KEY"),
EnvVar("openai_base_url", env="OPENAI_BASE_URL", type="str", env_fallback="OPENAI_BASE_URL"),
EnvVar("openai_model", env="OPENAI_MODEL", type="str", env_fallback="OPENAI_MODEL"),
]
@staticmethod
def name() -> str:
return "claw-code-agent"
def get_version_command(self) -> str | None:
return "claw-code-agent --help >/dev/null 2>&1 && echo installed"
async def install(self, environment: BaseEnvironment) -> None:
await self.exec_as_root(
environment,
command=(
"if command -v apk >/dev/null 2>&1; then "
"apk add --no-cache python3 py3-pip bash curl git; "
"elif command -v apt-get >/dev/null 2>&1; then "
"apt-get update && apt-get install -y python3 python3-pip bash curl git; "
"elif command -v yum >/dev/null 2>&1; then "
"yum install -y python3 python3-pip bash curl git; "
"fi"
),
env={"DEBIAN_FRONTEND": "noninteractive"},
)
version_spec = f"@{self._version}" if self._version else ""
repo_spec = (
f"git+https://github.com/HarnessLab/claw-code-agent.git{version_spec}"
if version_spec
else "git+https://github.com/HarnessLab/claw-code-agent.git"
)
await self.exec_as_agent(
environment,
command=(
"set -euo pipefail; "
f"python3 -m pip install --upgrade pip && python3 -m pip install {shlex.quote(repo_spec)} && "
"claw-code-agent --help >/dev/null"
),
)
def populate_context_post_run(self, context: AgentContext) -> None:
del context
@with_prompt_template
async def run(
self,
instruction: str,
environment: BaseEnvironment,
context: AgentContext,
) -> None:
del context
env = self.resolve_env_vars()
if self.model_name and "OPENAI_MODEL" not in env:
env["OPENAI_MODEL"] = self.model_name
cli_flags = self.build_cli_flags()
extra_flags = (cli_flags + " ") if cli_flags else ""
escaped_instruction = shlex.quote(instruction)
# Harbor executes in the task working directory; keep cwd anchored there.
command = (
f"claw-code-agent agent {escaped_instruction} "
f"--cwd $(pwd) {extra_flags}"
"2>&1 | stdbuf -oL tee /logs/agent/claw-code-agent.txt"
)
await self.exec_as_agent(environment, command=command, env=env)