Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion omnigent/claude_native_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,18 @@ def _trusted_parent_for_bridge_dir(target: Path) -> Path:
# bridge-owned directories below it.
return _absolute_syntactic_path(kiro_root.parent.parent)

# Headless ACP harnesses (acp / goose / qwen) put their Omnigent-MCP relay
# bridge below ``$TMPDIR/omnigent-<uid>/acp-mcp`` (same uid-scoped shape as
# cursor/qwen/hermes-native), so trust the uid-scoped temp dir's parent.
acp_root = _absolute_syntactic_path(acp_mcp_bridge_root())
if target.is_relative_to(acp_root):
return _absolute_syntactic_path(acp_root.parent.parent)

raise RuntimeError(
f"bridge dir {target!s} is not under an allowed bridge root "
f"({claude_root!s}, {codex_root!s}, {cursor_root!s}, "
f"{antigravity_root!s}, {qwen_root!s}, {hermes_root!s}, {opencode_root!s}, "
f"{kiro_root!s})"
f"{kiro_root!s}, {acp_root!s})"
)


Expand Down Expand Up @@ -704,6 +711,38 @@ def _ensure_secure_dir(target: Path) -> None:
os.chmod(ancestor, 0o700)


def acp_mcp_bridge_root() -> Path:
"""Bridge root for the headless ACP harnesses' Omnigent-MCP relay.

Shares the uid-scoped temp parent with claude-native
(``$TMPDIR/omnigent-<uid>/acp-mcp``). Used by the acp / goose / qwen
executors' ``OmnigentAcpMcp`` relay so ``serve-mcp``'s bridge dir passes the
:func:`_trusted_parent_for_bridge_dir` secure-root check.

:returns: The ACP-MCP bridge root directory (not created here).
"""
return _BRIDGE_ROOT_PARENT / "acp-mcp"


def prepare_acp_mcp_bridge_dir() -> Path:
"""Create a fresh, secure per-relay bridge dir for an ACP harness.

Returns a unique owner-only directory under :func:`acp_mcp_bridge_root` with
a minimal token-only ``bridge.json`` — so the shared ``serve-mcp`` serves
ONLY the relay tools (no raw ``sys_os_*`` filesystem tools; the ACP agent
owns those). The caller's relay writes ``tool_relay.json`` here and points
``serve-mcp`` at the directory.

:returns: The prepared bridge directory path.
"""
bridge_dir = acp_mcp_bridge_root() / secrets.token_hex(8)
_ensure_secure_dir(bridge_dir)
config_path = bridge_dir / _CONFIG_FILE
if not config_path.exists():
_write_json_file(config_path, {"token": secrets.token_urlsafe(32)})
return bridge_dir


def bridge_dir_for_bridge_id(bridge_id: str) -> Path:
"""
Return the deterministic bridge directory for a Claude-native bridge.
Expand Down
133 changes: 133 additions & 0 deletions omnigent/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10134,6 +10134,113 @@ def _manage_goose_harness() -> None:
status = None


def _print_acp_examples() -> None:
"""Print example ACP-agent commands (Omnigent stores no credential)."""
from omnigent.onboarding.interactive import console

console.print(
"\n [bold]Custom ACP agents[/bold] — connect any agent that speaks the "
"Agent Client Protocol ([underline]agentclientprotocol.com[/underline]).\n"
" Omnigent stores no credential — log into each agent via its own CLI first.\n\n"
" Example commands to paste:\n"
" • Gemini CLI [bold]gemini --experimental-acp[/bold]\n"
" • Qwen Code [bold]qwen --acp[/bold]\n"
" • Goose [bold]goose acp[/bold]\n"
" • Claude Code [bold]npx -y @zed-industries/claude-code-acp[/bold]\n"
)


def _add_acp_agent() -> str | None:
"""Prompt for a new ACP agent and append it to the ``acp:`` config block.

:returns: A status line for the menu, or ``None`` when nothing was added.
"""
from omnigent.onboarding.acp_auth import (
AcpAgentEntry,
acp_agents,
acp_agents_settings,
slugify,
)
from omnigent.onboarding.interactive import prompt_text

name = prompt_text("Agent name (e.g. Gemini CLI)").strip()
if not name:
return "No name entered"
command = prompt_text("Command to launch (e.g. gemini --experimental-acp)").strip()
if not command:
return "No command entered"
model = (prompt_text("Model (optional — Enter to skip)", default="") or "").strip() or None

entries = list(acp_agents())
entries.append(
AcpAgentEntry(slug=slugify(name), name=name, command=command, model=model)
)
_save_global_config(acp_agents_settings(entries))
return f"✓ Added {name}"


def _remove_acp_agent() -> str | None:
"""Pick a configured ACP agent to drop from the ``acp:`` config block.

:returns: A status line for the menu, or ``None`` when cancelled.
"""
from omnigent.onboarding.acp_auth import acp_agents, acp_agents_settings
from omnigent.onboarding.interactive import select

entries = list(acp_agents())
if not entries:
return "No agents to remove"
labels = [f"{e.name} ({e.command})" for e in entries] + ["← Cancel"]
idx = select("Remove which ACP agent?", labels, clear_on_exit=True)
if idx < 0 or idx >= len(entries):
return None
removed = entries.pop(idx)
_save_global_config(acp_agents_settings(entries))
return f"✓ Removed {removed.name}"


def _manage_acp_harness() -> None:
"""Run the level-2 loop for the generic ACP harness: manage named agents.

The ``acp`` harness drives any user-configured ACP-agent command. Each named
agent lives in the ``acp:`` block of ``~/.omnigent/config.yaml`` and surfaces
as its own row (``acp:<slug>``) in the agent-harness picker. Omnigent stores
no credential — the user logs into each agent via its own CLI — so this
drill-in just adds / lists / removes commands.

:returns: None. Side effects: reads/writes the ``acp:`` config block.
"""
from omnigent.onboarding.acp_auth import acp_agents
from omnigent.onboarding.interactive import select

status: str | None = None
while True:
agents = acp_agents()
if agents:
names = ", ".join(a.name for a in agents)
header = f"Custom ACP agents — {len(agents)} configured: {names}"
else:
header = "Custom ACP agents — none configured yet"
rows: list[_HarnessMenuRow] = [_HarnessMenuRow("Add an ACP agent", action="add")]
if agents:
rows.append(_HarnessMenuRow("Remove an agent", action="remove"))
rows.append(_HarnessMenuRow("Show examples", action="help"))
rows.append(_HarnessMenuRow("← Back", action="back"))
idx = select(header, [r.label for r in rows], clear_on_exit=True, status=status)
if idx < 0: # Esc / q
return
action = rows[idx].action
if action == "back":
return
if action == "add":
status = _add_acp_agent()
elif action == "remove":
status = _remove_acp_agent()
elif action == "help":
_print_acp_examples()
status = None


def _manage_hermes_harness() -> None:
"""Run the level-2 loop for Hermes: ensure the CLI is installed.

Expand Down Expand Up @@ -11151,6 +11258,10 @@ def _run_configure_harnesses_interactive() -> None:
# / ``kimi provider add`` → ~/.kimi/config.toml), so it dispatches to its
# own drill-in rather than ``_manage_harness_providers``.
_KIMI = "\x00kimi"
# Sentinel marking the Custom ACP agent row — the generic ACP harness that
# drives any user-configured agent command. Not a provider family (each agent
# owns its own auth), so it dispatches to its own add/list/remove drill-in.
_ACP = "\x00acp"
families = [ANTHROPIC_FAMILY, OPENAI_FAMILY, PI_SURFACE]

# Status glyph + Rich color per readiness kind: "ready" is a configured,
Expand Down Expand Up @@ -11366,6 +11477,26 @@ def build_harness_rows() -> list[tuple[str, str, str, str, str]]:
(_GOOSE, "Goose", "Not configured", "warn", "Open to run `goose configure`."),
)

# Custom ACP agents — any user-configured ACP-agent command. Not gated on
# a binary (each agent owns its own install); "configured" = ≥1 registered.
from omnigent.onboarding.acp_auth import acp_config_summary

acp_summary = acp_config_summary()
if acp_summary.configured:
rows.append(
(_ACP, "Custom ACP agent", f"{acp_summary.count} configured", "ready", "")
)
else:
rows.append(
(
_ACP,
"Custom ACP agent",
"None configured",
"warn",
"Add any ACP agent (gemini, qwen, goose, …).",
)
)

# Copilot — GitHub token (github-copilot-sdk extra is soft).
if copilot_github_token_configured(config) or any(
os.environ.get(v) for v in COPILOT_TOKEN_ENV_VARS
Expand Down Expand Up @@ -11477,6 +11608,8 @@ def build_harness_rows() -> list[tuple[str, str, str, str, str]]:
_manage_opencode_harness()
elif target == _GOOSE:
_manage_goose_harness()
elif target == _ACP:
_manage_acp_harness()
elif target == _HERMES:
_manage_hermes_harness()
elif target == _KIRO:
Expand Down
6 changes: 6 additions & 0 deletions omnigent/harness_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def canonicalize_harness(harness: str | None) -> str | None:
"""
if harness is None:
return None
# Namespaced generic-ACP ids (``acp:<slug>``) canonicalize to the base
# ``acp`` harness for identity / validity / module resolution / model-family
# checks. The ``<slug>`` selecting the concrete agent is carried separately in
# the spec's ``executor.config`` and read by ``_build_acp_spawn_env``.
if harness.startswith("acp:"):
return "acp"
return HARNESS_ALIASES.get(harness, harness)


Expand Down
36 changes: 36 additions & 0 deletions omnigent/harness_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,20 @@ class HarnessPluginState:
interrupt=True,
streaming=True,
),
# Generic ACP harness — drives any user-configured ACP agent command. Same
# profile as goose/qwen (own-auth, cold resume, SSE permission), but its
# interrupt IS implemented (ACP ``session/cancel``), not just declared.
"acp": _C(
_IM.ACP_SUBPROCESS,
_EL.SSE_PERMISSION,
_RS.COLD_ONLY,
_EF.NONE,
_MF.MULTI,
_AU.OWN_AUTH,
subagents=False,
interrupt=True,
streaming=True,
),
"goose": _C(
_IM.ACP_SUBPROCESS,
_EL.SSE_PERMISSION,
Expand Down Expand Up @@ -495,6 +509,7 @@ class HarnessPluginState:
name="omnigent",
valid_harnesses=frozenset(
{
"acp",
"antigravity",
"antigravity-native",
"claude-native",
Expand All @@ -521,6 +536,7 @@ class HarnessPluginState:
}
),
harness_modules={
"acp": "omnigent.inner.acp_harness",
"antigravity": "omnigent.inner.antigravity_harness",
"antigravity-native": "omnigent.inner.antigravity_native_harness",
"claude-native": "omnigent.inner.claude_native_harness",
Expand Down Expand Up @@ -602,6 +618,7 @@ class HarnessPluginState:
HERMES_NATIVE_CODING_AGENT,
),
model_env_keys={
"acp": "HARNESS_ACP_MODEL",
"antigravity": "HARNESS_ANTIGRAVITY_MODEL",
"claude-sdk": "HARNESS_CLAUDE_SDK_MODEL",
"codex": "HARNESS_CODEX_MODEL",
Expand Down Expand Up @@ -898,6 +915,25 @@ def harness_catalog() -> list[dict[str, Any]]:
if capability is not None:
row["capabilities"] = capability.as_dict()
rows.append(row)

# Dynamic rows: one per user-configured generic-ACP agent, id ``acp:<slug>``.
# The base ``acp`` harness deliberately has no ``harness_labels`` entry, so it
# is not a standalone picker row — only the configured agents surface. Read
# lazily so importing this registry never pulls in the onboarding/config
# stack, and never let a malformed ``acp:`` block break the whole catalog.
acp_capability = capabilities.get("acp")
try:
from omnigent.onboarding.acp_auth import acp_agents

for agent in acp_agents():
acp_row: dict[str, Any] = {"id": f"acp:{agent.slug}", "label": agent.name}
if acp_capability is not None:
acp_row["capabilities"] = acp_capability.as_dict()
rows.append(acp_row)
except Exception: # noqa: BLE001 — a malformed acp: block must never break the catalog
import logging
Comment thread
github-code-quality[bot] marked this conversation as resolved.
Fixed

logging.getLogger(__name__).debug("acp catalog rows skipped", exc_info=True)
return rows


Expand Down
Loading
Loading