You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@magpie.apache.org by po...@apache.org on 2026/07/08 13:14:30 UTC

(magpie) branch main updated: feat(agent-isolation): expose harness-agnostic agent-iso entry point (#764)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/magpie.git


The following commit(s) were added to refs/heads/main by this push:
     new 18026ce9 feat(agent-isolation): expose harness-agnostic agent-iso entry point (#764)
18026ce9 is described below

commit 18026ce9a44f6cdae45ca79514911bc73b6d90f3
Author: Justin Mclean <ju...@classsoftware.com>
AuthorDate: Wed Jul 8 23:14:25 2026 +1000

    feat(agent-isolation): expose harness-agnostic agent-iso entry point (#764)
    
    * feat(agent-isolation): expose harness-agnostic agent-iso entry point
    
    The env-isolation core of agent-iso.sh already worked for any CLI;
    this makes that capability explicit and documented:
    
    - Add `agent-iso()` shell function (sourced) and a sub-command mode
      `bash agent-iso.sh agent-iso <cli> [args]` (direct exec) so any
      harness CLI can be launched with the same credential-strip posture
      that claude-iso and opencode-iso provide.  A symlink named `agent-iso`
      (no .sh extension) also works — first positional arg is the CLI name.
    - The Claude-specific --settings sandbox allowRead injection continues
      to be skipped for all non-claude agents (guard was already in place).
    - Change `**Harness:** Claude Code, OpenCode` → `**Harness:** agnostic`
      in tools/agent-isolation/README.md; the env-isolation layer is now
      available for Codex, Cursor, Gemini CLI, Aider, and any future CLI.
    - Update docs/vendor-neutrality.md harness table and harness index to
      reflect agent-isolation moving from portable to agnostic; the hook
      regenerates the score section automatically.
    - Update docs/adapters/add-a-harness.md Step 2 and Step 4 to document
      `agent-iso <cli>` as the ready-made layer-0 wrapper for runtimes
      without a built-in hook API.
    - Add tests/test_generic_iso.py covering both the direct-exec and
      sourced entry points: credential strip, no --settings injection,
      banner, missing-CLI exit-127, no-CLI-arg usage message, and multiple
      harness names (codex/cursor/gemini).
    
    All 72 agent-isolation tests pass; vendor-neutrality-score and
    skill-and-tool-validate both pass.
    
    Generated-by: Claude (claude-sonnet-4-6)
    
    * minor fix
    
    * address review: skip dead git resolution for non-Claude -w; surface no-push-gate caveat for generic harnesses
    
    ---------
    
    Co-authored-by: Tester <t...@example.com>
    Co-authored-by: Jarek Potiuk <ja...@potiuk.com>
---
 docs/adapters/add-a-harness.md                  |  26 +-
 docs/vendor-neutrality.md                       |   8 +-
 tools/agent-isolation/README.md                 |  50 +++-
 tools/agent-isolation/agent-iso.sh              |  78 +++++-
 tools/agent-isolation/tests/test_generic_iso.py | 327 ++++++++++++++++++++++++
 5 files changed, 466 insertions(+), 23 deletions(-)

diff --git a/docs/adapters/add-a-harness.md b/docs/adapters/add-a-harness.md
index da111165..507e0472 100644
--- a/docs/adapters/add-a-harness.md
+++ b/docs/adapters/add-a-harness.md
@@ -117,9 +117,20 @@ uv run --project tools/agent-guard --group dev pytest
 in the row's notes in `skills/setup/agents.md`. An OS-level wrapper
 (e.g. `bubblewrap` on Linux, `sandbox-exec` on macOS, or a custom
 `PATH`-shadowing script that intercepts `git push` and `gh pr create`)
-can enforce the rules at the process level without a harness hook. See
-`tools/agent-isolation/agent-iso.sh` for the credential-stripping
-pattern; extend it or write a sibling wrapper for the new runtime.
+can enforce the rules at the process level without a harness hook. The
+credential-strip layer is already available for any runtime:
+
+```bash
+# Source agent-iso.sh and use the generic entry point:
+source /path/to/magpie/tools/agent-isolation/agent-iso.sh
+agent-iso <your-runtime-cli> [cli-args]
+```
+
+See [`tools/agent-isolation/README.md`](../../tools/agent-isolation/README.md)
+for the full generic-harness usage. The `agent-iso` entry point works
+for any CLI; the Claude-specific `--settings` sandbox grant is skipped
+automatically. For deeper enforcement (action guard, confirmation
+prompts), a harness-specific adapter is still needed.
 
 Whatever the enforcement mechanism, update the affected substrate tool
 READMEs (step 4) to declare the new harness in their `**Harness:**` line
@@ -181,13 +192,16 @@ README. When your new runtime uses one of these tools, update its line:
 | Tool | Current harness declaration |
 |---|---|
 | `tools/agent-guard` | `**Harness:** Claude Code, OpenCode` |
-| `tools/agent-isolation` | `**Harness:** Claude Code, OpenCode` |
+| `tools/agent-isolation` | `**Harness:** agnostic` |
 | `tools/permission-audit` | `**Harness:** Claude Code, OpenCode` |
 | `tools/sandbox-lint` | `**Harness:** Claude Code, OpenCode` |
 | `tools/spec-loop` | `**Harness:** Claude Code, Codex, Cursor, Gemini CLI, OpenCode` |
 
-Add your runtime to every tool it integrates with. Tools that declare
-`**Harness:** agnostic` need no change — they work under any runtime
+`tools/agent-isolation` already exposes a harness-agnostic `agent-iso <cli>` entry
+point — no update needed for new runtimes (see
+[`tools/agent-isolation/README.md`](../../tools/agent-isolation/README.md)).
+Add your runtime to every other tool it integrates with. Tools that declare
+`**Harness:** any` or `agnostic` need no change — they work under any runtime
 unchanged. After updating, refresh the vendor-neutrality score:
 
 ```bash
diff --git a/docs/vendor-neutrality.md b/docs/vendor-neutrality.md
index d09da8eb..bc0dfaca 100644
--- a/docs/vendor-neutrality.md
+++ b/docs/vendor-neutrality.md
@@ -584,7 +584,7 @@ Organization scope (declared, orthogonal to vendor): ASF = 14, agnostic = 55.
 | Substrate tool | Substrate | Harness support | Verdict |
 |---|---|---|---|
 | `agent-guard` | action-guard | Claude Code, OpenCode | ✅ portable |
-| `agent-isolation` | sandbox | Claude Code, OpenCode | ✅ portable |
+| `agent-isolation` | sandbox | any | ✅ agnostic |
 | `dashboard-generator` | analytics | any | ✅ agnostic |
 | `dev` | framework-dev | any | ✅ agnostic |
 | `egress-gateway` | sandbox | any | ✅ agnostic |
@@ -608,12 +608,12 @@ Organization scope (declared, orthogonal to vendor): ASF = 14, agnostic = 55.
 
 Harness → substrate tools it supports:
 
-- **Claude Code** (5): `agent-guard`, `agent-isolation`, `permission-audit`, `sandbox-lint`, `spec-loop`
+- **Claude Code** (4): `agent-guard`, `permission-audit`, `sandbox-lint`, `spec-loop`
 - **Codex** (1): `spec-loop`
 - **Cursor** (1): `spec-loop`
 - **Gemini CLI** (1): `spec-loop`
-- **OpenCode** (5): `agent-guard`, `agent-isolation`, `permission-audit`, `sandbox-lint`, `spec-loop`
-- **any harness** (17): `dashboard-generator`, `dev`, `egress-gateway`, `pilot-report-validator`, `pr-management-stats`, `preflight-audit`, `privacy-llm`, `probe-templates`, `security-tracker-stats-dashboard`, `skill-and-tool-validator`, `skill-evals`, `skill-reconciler-diff`, `spec-inventory`, `spec-status-index`, `spec-validator`, `symlink-lint`, `vendor-neutrality-score`
+- **OpenCode** (4): `agent-guard`, `permission-audit`, `sandbox-lint`, `spec-loop`
+- **any harness** (18): `agent-isolation`, `dashboard-generator`, `dev`, `egress-gateway`, `pilot-report-validator`, `pr-management-stats`, `preflight-audit`, `privacy-llm`, `probe-templates`, `security-tracker-stats-dashboard`, `skill-and-tool-validator`, `skill-evals`, `skill-reconciler-diff`, `spec-inventory`, `spec-status-index`, `spec-validator`, `symlink-lint`, `vendor-neutrality-score`
 
 **Model endpoint: neutral by construction — 4 default-approved endpoint classes across independent trust domains, plus adopter opt-in.** From the [`privacy-llm` registry](../tools/privacy-llm/models.md): the framework keys approval on *endpoint identity*, not on who hosts the model, so no single LLM vendor is privileged.
 
diff --git a/tools/agent-isolation/README.md b/tools/agent-isolation/README.md
index 09e8cbc2..ff7ac565 100644
--- a/tools/agent-isolation/README.md
+++ b/tools/agent-isolation/README.md
@@ -20,7 +20,7 @@
 
 **Capability:** substrate:sandbox
 
-**Harness:** Claude Code, OpenCode
+**Harness:** agnostic
 
 This directory ships the moving pieces the framework's
 [`docs/setup/secure-agent-setup.md`](../../docs/setup/secure-agent-setup.md) document
@@ -29,15 +29,38 @@ under `tools/cve-tool-vulnogram/` and `tools/gmail/oauth-draft/`) — these are
 plain shell scripts plus a TOML manifest of pinned upstream
 versions.
 
-The clean-environment launcher [`agent-iso.sh`](agent-iso.sh) is
-agent-agnostic at its core: it exposes a `claude-iso` entry point (the
-default) and an `opencode-iso` entry point that launch **Claude Code** and
-**OpenCode** respectively under the same `env -i` credential strip. Only the
-Claude path adds the in-process `--settings` sandbox grant; OpenCode takes its
-filesystem isolation from the OS-level sandbox of the secure setup. Isolate
-OpenCode by sourcing the script and calling `opencode-iso`, or when running it
-directly, `AGENT_ISO_AGENT=opencode bash agent-iso.sh …` (or a symlink named
-`opencode-iso`).
+The clean-environment launcher [`agent-iso.sh`](agent-iso.sh) provides
+harness-agnostic env isolation. It exposes three entry points, all sharing
+the same `env -i` credential-strip core:
+
+- **`claude-iso`** — launches Claude Code; additionally injects a one-shot
+  `--settings` sandbox `allowRead` grant for the current repo (Claude-specific).
+- **`opencode-iso`** — launches OpenCode with the same clean env; no settings
+  grant (OpenCode takes its filesystem isolation from the OS-level sandbox).
+- **`agent-iso <cli>`** — launches *any* agentic CLI (`codex`, `cursor`,
+  `gemini`, `aider`, …) with the same credential strip. The `--settings`
+  injection is skipped for non-Claude CLIs, which take their filesystem
+  isolation from the OS-level sandbox. The `-w` / `--worktree` flag is a
+  Claude-only control flag and is stripped from the argv of non-Claude CLIs
+  (it has no meaning for them). The Layer 0 env passthrough (including
+  `SSH_AUTH_SOCK`) is identical for every harness per
+  [RFC-AI-0002 § Layer 0](https://magpie.apache.org/docs/rfcs/rfc-ai-0002/#layer-0--clean-env-wrapper);
+  gating git push is a separate Layer 3 concern wired per-harness (see
+  [`docs/adapters/add-a-harness.md`](../../docs/adapters/add-a-harness.md)).
+
+All three paths enforce layer 0 of the secure-agent posture regardless of
+which harness drives the session. Harness-specific layers (the in-process
+action guard, the `permissions.ask` confirmation list) are wired separately
+per runtime — see [`docs/adapters/add-a-harness.md`](../../docs/adapters/add-a-harness.md).
+
+> ⚠️ **Generic harnesses (`agent-iso <cli>`) get Layer 0 only — no push gate.**
+> Claude and OpenCode ship a Layer 3 push gate (agent-guard / `permissions.ask`),
+> so a `git push` from those harnesses is gated. An arbitrary CLI launched via
+> `agent-iso` (`codex`, `aider`, …) receives the live `SSH_AUTH_SOCK` with
+> **nothing gating `git push`**. The credential-strip posture is identical across
+> harnesses, but the *net* protection is weaker: a runtime with no Layer 3 adapter
+> is responsible for providing its own push gate before it is trusted with the
+> agent socket.
 
 ## Prerequisites
 
@@ -79,6 +102,13 @@ alias claude='claude-iso'
 cd ~/code/<tracker>
 claude-iso
 
+# For any other harness — same credential strip, no Claude-specific settings:
+agent-iso codex [codex-args]
+agent-iso cursor [cursor-args]
+agent-iso gemini [gemini-cli-args]
+# Or directly without sourcing:
+bash /path/to/magpie/tools/agent-isolation/agent-iso.sh agent-iso codex [codex-args]
+
 # Periodically (or via /schedule weekly), check for upgrade candidates:
 bash /path/to/magpie/tools/agent-isolation/check-tool-updates.sh
 ```
diff --git a/tools/agent-isolation/agent-iso.sh b/tools/agent-isolation/agent-iso.sh
index cf341615..c6aea685 100755
--- a/tools/agent-isolation/agent-iso.sh
+++ b/tools/agent-isolation/agent-iso.sh
@@ -119,7 +119,12 @@ agent_iso_run() {
     XDG_DATA_HOME
     DISPLAY              # for OAuth flows that pop a browser
     WAYLAND_DISPLAY
-    SSH_AUTH_SOCK        # for git push (the agent gates push behind ASK; the socket alone is harmless)
+    # SSH_AUTH_SOCK is a fixed member of the Layer 0 passthrough (RFC-AI-0002
+    # § "Layer 0 — Clean-env wrapper"): git push/pull needs the ssh-agent socket.
+    # Layer 0 stays harness-agnostic. Gating the push itself is a *separate* layer
+    # (Layer 3 — permissions.ask / agent-guard), wired per-harness; a runtime with
+    # no Layer 3 adapter is responsible for providing its own push gate.
+    SSH_AUTH_SOCK
   )
 
   # Build an `env -i ... NAME=value ...` argv from the passthrough list.
@@ -198,6 +203,26 @@ agent_iso_run() {
     esac
   done
 
+  # `-w` / `--worktree` is an agent-iso control flag understood only by the
+  # Claude sandbox-grant path below (it widens the allowRead set to the main
+  # repo). For any other harness it is meaningless, and forwarding it into the
+  # launched CLI's argv risks it being misparsed as a native flag. Strip it for
+  # non-Claude agents so the generic entry point stays transparent.
+  if [[ "$agent" != "claude" && "$has_worktree" -eq 1 ]]; then
+    local -a _passargs=()
+    for arg in "$@"; do
+      case "$arg" in
+        -w|--worktree|-w=*|--worktree=*) ;;   # drop the control flag
+        *) _passargs+=("$arg") ;;
+      esac
+    done
+    set -- "${_passargs[@]}"
+    # The main-repo git resolution below is Claude-only (settings injection is
+    # gated on `$agent == claude`), so once `-w` is stripped for a non-Claude
+    # agent there is nothing left to resolve — skip the git calls.
+    has_worktree=0
+  fi
+
   local main_repo=""
   if [[ "$has_worktree" -eq 1 ]]; then
     local common_dir
@@ -273,12 +298,59 @@ claude_iso_main() { agent_iso_run "${AGENT_ISO_AGENT:-claude}" "$@"; }
 # executed directly, pick the agent from the invoked name (a symlink such as
 # `opencode-iso` selects OpenCode) or from AGENT_ISO_AGENT, defaulting to
 # `claude` so existing `bash agent-iso.sh …` invocations are unchanged.
+#
+# Generic entry point:
+#   agent-iso() / `bash agent-iso.sh agent-iso <cli> [args]` takes the
+#   harness CLI name as its first positional argument and works for ANY
+#   agentic runtime — Codex, Cursor, Gemini CLI, Aider, or any future CLI.
+#   The credential-strip and clean-env launch are harness-agnostic; only the
+#   `--settings` sandbox allowRead injection is skipped (it is Claude-specific
+#   and already guarded by `if [[ "$agent" == "claude" ]]`).
 if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
   claude-iso()   { agent_iso_run claude "$@"; }
   opencode-iso() { agent_iso_run opencode "$@"; }
+  # Harness-agnostic entry point: agent-iso <cli> [cli-args]
+  # Guard the no-CLI case so it matches the direct-exec path (usage + exit 1)
+  # instead of falling through to agent_iso_run with an empty agent name.
+  agent-iso() {
+    if [[ $# -lt 1 ]]; then
+      printf 'Usage: agent-iso <cli> [cli-args]\n  e.g.: agent-iso codex "my prompt"\n' >&2
+      return 1
+    fi
+    agent_iso_run "$@"
+  }
 else
-  case "$(basename "${0}")" in
+  _aig_basename="$(basename "${0}")"
+  case "$_aig_basename" in
     opencode-iso*) agent_iso_run opencode "$@" ;;
-    *)             agent_iso_run "${AGENT_ISO_AGENT:-claude}" "$@" ;;
+    # Symlink named exactly `agent-iso` (no .sh extension) → first positional
+    # arg is the harness CLI name.
+    agent-iso)
+      if [[ $# -ge 1 ]]; then
+        _aig_cli="$1"; shift; agent_iso_run "$_aig_cli" "$@"
+      else
+        printf 'Usage: %s <cli> [cli-args]\n  e.g.: agent-iso codex "my prompt"\n' \
+          "$_aig_basename" >&2
+        exit 1
+      fi
+      ;;
+    *)
+      # Default direct-exec path (e.g. `bash agent-iso.sh`).
+      # If the first positional arg is the literal word "agent-iso", treat
+      # the next arg as the harness CLI name — generic sub-command:
+      #   bash agent-iso.sh agent-iso codex [codex-args]
+      if [[ "${1-}" == "agent-iso" ]]; then
+        shift
+        if [[ $# -ge 1 ]]; then
+          _aig_cli="$1"; shift; agent_iso_run "$_aig_cli" "$@"
+        else
+          printf 'Usage: %s agent-iso <cli> [cli-args]\n  e.g.: bash %s agent-iso codex "my prompt"\n' \
+            "$_aig_basename" "$_aig_basename" >&2
+          exit 1
+        fi
+      else
+        agent_iso_run "${AGENT_ISO_AGENT:-claude}" "$@"
+      fi
+      ;;
   esac
 fi
diff --git a/tools/agent-isolation/tests/test_generic_iso.py b/tools/agent-isolation/tests/test_generic_iso.py
new file mode 100644
index 00000000..d9603277
--- /dev/null
+++ b/tools/agent-isolation/tests/test_generic_iso.py
@@ -0,0 +1,327 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Tests for the generic `agent-iso` entry point of agent-iso.sh.
+
+The generic entry point accepts any harness CLI as its first positional
+argument:
+  - Sourced: ``agent-iso <cli> [cli-args]``
+  - Direct exec: ``bash agent-iso.sh agent-iso <cli> [cli-args]``
+
+Strategy: put a fake arbitrary CLI (named ``my-harness``) on $PATH that
+prints ARG: lines for its argv then its env.  Invoke via both paths.
+Verify:
+  - credential-shaped env vars are stripped (same posture as claude-iso /
+    opencode-iso);
+  - the Claude-only ``--settings`` sandbox grant is NOT injected;
+  - the banner identifies the harness name correctly;
+  - missing CLI exits 127 with a helpful message;
+  - empty first-arg (no CLI given) exits 1 with a usage hint.
+"""
+
+from __future__ import annotations
+
+import os
+import shutil
+import stat
+import subprocess
+from pathlib import Path
+
+SCRIPT = Path(__file__).parent.parent / "agent-iso.sh"
+BASH = shutil.which("bash") or "/bin/bash"
+
+_FAKE_CLI = "my-harness"
+
+
+def _make_fake_cli(tmp_path: Path, name: str = _FAKE_CLI) -> Path:
+    """A fake CLI that prints ARG: lines for its argv, then its env."""
+    fake = tmp_path / name
+    fake.write_text('#!/bin/sh\nfor a in "$@"; do echo "ARG:$a"; done\nprintenv\n')
+    fake.chmod(fake.stat().st_mode | stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH)
+    return tmp_path
+
+
+def _run_direct(
+    tmp_path: Path,
+    cli_name: str = _FAKE_CLI,
+    extra_env: dict | None = None,
+    extra_cli_args: list | None = None,
+) -> subprocess.CompletedProcess:
+    """Invoke via direct exec: bash agent-iso.sh agent-iso <cli> [args]."""
+    _make_fake_cli(tmp_path, cli_name)
+    env: dict[str, str] = {
+        "PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}",
+        "HOME": "/tmp/testhome",
+        "USER": "testuser",
+        "SHELL": "/bin/sh",
+        "TERM": "xterm",
+        "LANG": "en_US.UTF-8",
+    }
+    if extra_env:
+        env.update(extra_env)
+    # The generic direct-exec path: first arg selects "agent-iso" mode, second
+    # is the harness CLI name, rest are CLI args.
+    cmd = [BASH, str(SCRIPT), "agent-iso", cli_name] + (extra_cli_args or [])
+    return subprocess.run(cmd, env=env, cwd=str(tmp_path), capture_output=True, text=True)
+
+
+def _parse_env(stdout: str) -> dict[str, str]:
+    result: dict[str, str] = {}
+    for line in stdout.splitlines():
+        if line.startswith("ARG:"):
+            continue
+        if "=" in line:
+            key, _, val = line.partition("=")
+            result[key] = val
+    return result
+
+
+def _argv(stdout: str) -> list[str]:
+    return [line[len("ARG:"):] for line in stdout.splitlines() if line.startswith("ARG:")]
+
+
+class TestGenericIsoDirectExec:
+    def test_launches_generic_cli(self, tmp_path: Path) -> None:
+        res = _run_direct(tmp_path)
+        assert res.returncode == 0, res.stderr
+        assert f"[{_FAKE_CLI}-iso] running in isolated env" in res.stderr
+
+    def test_credentials_stripped(self, tmp_path: Path) -> None:
+        res = _run_direct(
+            tmp_path,
+            extra_env={"GH_TOKEN": "ghp_secret", "ANTHROPIC_API_KEY": "sk-ant-secret"},
+        )
+        assert res.returncode == 0, res.stderr
+        env = _parse_env(res.stdout)
+        assert "GH_TOKEN" not in env
+        assert "ANTHROPIC_API_KEY" not in env
+
+    def test_passthrough_preserved(self, tmp_path: Path) -> None:
+        res = _run_direct(tmp_path, extra_env={"HOME": "/home/testuser"})
+        assert res.returncode == 0, res.stderr
+        assert _parse_env(res.stdout).get("HOME") == "/home/testuser"
+
+    def test_no_settings_injection(self, tmp_path: Path) -> None:
+        # The Claude-only --settings sandbox grant must NOT appear for generic CLIs.
+        res = _run_direct(tmp_path, extra_cli_args=["run", "hello"])
+        assert res.returncode == 0, res.stderr
+        argv = _argv(res.stdout)
+        assert "--settings" not in argv
+        assert argv == ["run", "hello"]
+
+    def test_cli_args_forwarded(self, tmp_path: Path) -> None:
+        res = _run_direct(tmp_path, extra_cli_args=["--flag", "value", "positional"])
+        assert res.returncode == 0, res.stderr
+        assert _argv(res.stdout) == ["--flag", "value", "positional"]
+
+    def test_worktree_flag_stripped_for_generic_cli(self, tmp_path: Path) -> None:
+        # -w / --worktree is a Claude-only control flag; it must not leak into a
+        # generic CLI's argv where it could be misparsed as a native flag.
+        res = _run_direct(tmp_path, extra_cli_args=["-w", "run"])
+        assert res.returncode == 0, res.stderr
+        argv = _argv(res.stdout)
+        assert "-w" not in argv
+        assert "--worktree" not in argv
+        assert argv == ["run"]
+
+    def test_ssh_auth_sock_passed_through_for_generic_cli(self, tmp_path: Path) -> None:
+        # SSH_AUTH_SOCK is a fixed member of the Layer 0 passthrough (RFC-AI-0002
+        # § Layer 0) and must reach every harness identically, generic ones
+        # included. Gating git push is a separate Layer 3 concern.
+        res = _run_direct(tmp_path, extra_env={"SSH_AUTH_SOCK": "/tmp/agent.sock"})
+        assert res.returncode == 0, res.stderr
+        assert _parse_env(res.stdout).get("SSH_AUTH_SOCK") == "/tmp/agent.sock"
+
+    def test_missing_cli_exits_127(self, tmp_path: Path) -> None:
+        # No fake binary in tmp_path — should exit 127.
+        env = {
+            "PATH": str(tmp_path),
+            "HOME": "/tmp",
+            "USER": "testuser",
+            "SHELL": "/bin/sh",
+        }
+        res = subprocess.run(
+            [BASH, str(SCRIPT), "agent-iso", "nonexistent-cli"],
+            env=env,
+            cwd=str(tmp_path),
+            capture_output=True,
+            text=True,
+        )
+        assert res.returncode == 127
+        assert "not found" in res.stderr
+
+    def test_no_cli_arg_exits_nonzero(self, tmp_path: Path) -> None:
+        # Invoke as: bash agent-iso.sh agent-iso   (no CLI name given)
+        env = {
+            "PATH": str(tmp_path),
+            "HOME": "/tmp",
+            "USER": "testuser",
+            "SHELL": "/bin/sh",
+        }
+        res = subprocess.run(
+            [BASH, str(SCRIPT), "agent-iso"],
+            env=env,
+            cwd=str(tmp_path),
+            capture_output=True,
+            text=True,
+        )
+        assert res.returncode != 0
+        assert "Usage" in res.stderr
+
+
+class TestGenericIsoSourced:
+    """Test the ``agent-iso()`` shell function exposed when the script is sourced."""
+
+    def _run_sourced(
+        self,
+        tmp_path: Path,
+        cli_name: str = _FAKE_CLI,
+        extra_env: dict | None = None,
+        extra_cli_args: list | None = None,
+    ) -> subprocess.CompletedProcess:
+        _make_fake_cli(tmp_path, cli_name)
+        env: dict[str, str] = {
+            "PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}",
+            "HOME": "/tmp/testhome",
+            "USER": "testuser",
+            "SHELL": "/bin/sh",
+            "TERM": "xterm",
+            "LANG": "en_US.UTF-8",
+        }
+        if extra_env:
+            env.update(extra_env)
+        cli_args_str = " ".join(f'"{a}"' for a in (extra_cli_args or []))
+        script_body = (
+            f'source "{SCRIPT}"\n'
+            f"agent-iso {cli_name} {cli_args_str}\n"
+        )
+        return subprocess.run(
+            [BASH, "-c", script_body],
+            env=env,
+            cwd=str(tmp_path),
+            capture_output=True,
+            text=True,
+        )
+
+    def test_sourced_launches_generic_cli(self, tmp_path: Path) -> None:
+        res = self._run_sourced(tmp_path)
+        assert res.returncode == 0, res.stderr
+        assert f"[{_FAKE_CLI}-iso] running in isolated env" in res.stderr
+
+    def test_sourced_credentials_stripped(self, tmp_path: Path) -> None:
+        res = self._run_sourced(
+            tmp_path,
+            extra_env={"GH_TOKEN": "ghp_secret", "ANTHROPIC_API_KEY": "sk-ant-secret"},
+        )
+        assert res.returncode == 0, res.stderr
+        env = _parse_env(res.stdout)
+        assert "GH_TOKEN" not in env
+        assert "ANTHROPIC_API_KEY" not in env
+
+    def test_sourced_no_settings_injection(self, tmp_path: Path) -> None:
+        res = self._run_sourced(tmp_path, extra_cli_args=["run", "hello"])
+        assert res.returncode == 0, res.stderr
+        argv = _argv(res.stdout)
+        assert "--settings" not in argv
+        assert argv == ["run", "hello"]
+
+    def test_sourced_different_cli_names(self, tmp_path: Path) -> None:
+        for cli in ("codex", "cursor", "gemini"):
+            _make_fake_cli(tmp_path, cli)
+            env: dict[str, str] = {
+                "PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}",
+                "HOME": "/tmp/testhome",
+                "USER": "testuser",
+                "SHELL": "/bin/sh",
+                "TERM": "xterm",
+                "LANG": "en_US.UTF-8",
+            }
+            script_body = f'source "{SCRIPT}"\nagent-iso {cli}\n'
+            res = subprocess.run(
+                [BASH, "-c", script_body],
+                env=env,
+                cwd=str(tmp_path),
+                capture_output=True,
+                text=True,
+            )
+            assert res.returncode == 0, f"CLI {cli!r} failed: {res.stderr}"
+            assert f"[{cli}-iso] running in isolated env" in res.stderr
+
+    def test_sourced_no_cli_arg_exits_nonzero(self, tmp_path: Path) -> None:
+        # Sourced `agent-iso` with no CLI must match the direct-exec path: a
+        # usage hint and a non-zero exit, not a confusing "'' not found".
+        env = {
+            "PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}",
+            "HOME": "/tmp/testhome",
+            "USER": "testuser",
+            "SHELL": "/bin/sh",
+        }
+        res = subprocess.run(
+            [BASH, "-c", f'source "{SCRIPT}"\nagent-iso\n'],
+            env=env,
+            cwd=str(tmp_path),
+            capture_output=True,
+            text=True,
+        )
+        assert res.returncode != 0
+        assert "Usage" in res.stderr
+
+
+class TestGenericIsoSymlink:
+    """The direct-exec ``case "agent-iso")`` branch: a symlink named exactly
+    ``agent-iso`` takes its first positional arg as the harness CLI name."""
+
+    @staticmethod
+    def _env(tmp_path: Path) -> dict:
+        return {
+            "PATH": f"{tmp_path}:{os.environ.get('PATH', '/usr/bin:/bin')}",
+            "HOME": "/tmp/testhome",
+            "USER": "testuser",
+            "SHELL": "/bin/sh",
+            "TERM": "xterm",
+            "LANG": "en_US.UTF-8",
+        }
+
+    def test_symlink_named_agent_iso_launches_cli(self, tmp_path: Path) -> None:
+        _make_fake_cli(tmp_path)
+        link = tmp_path / "agent-iso"
+        link.symlink_to(SCRIPT)
+        res = subprocess.run(
+            [BASH, str(link), _FAKE_CLI, "run", "hello"],
+            env=self._env(tmp_path),
+            cwd=str(tmp_path),
+            capture_output=True,
+            text=True,
+        )
+        assert res.returncode == 0, res.stderr
+        assert f"[{_FAKE_CLI}-iso] running in isolated env" in res.stderr
+        assert _argv(res.stdout) == ["run", "hello"]
+
+    def test_symlink_named_agent_iso_no_cli_arg_exits_nonzero(
+        self, tmp_path: Path
+    ) -> None:
+        link = tmp_path / "agent-iso"
+        link.symlink_to(SCRIPT)
+        res = subprocess.run(
+            [BASH, str(link)],
+            env=self._env(tmp_path),
+            cwd=str(tmp_path),
+            capture_output=True,
+            text=True,
+        )
+        assert res.returncode != 0
+        assert "Usage" in res.stderr