From 3dae8211263ba3a3f4e97a5a04c6b6d27ac223e8 Mon Sep 17 00:00:00 2001 From: EDMND-SRC Date: Mon, 30 Nov 2026 14:43:18 +0200 Subject: [PATCH 1/2] docs: add verified Cline hook bridge example --- CHANGELOG.md | 1 + docs/README.md | 1 + docs/cline-hook-bridge.md | 19 +++++++++ examples/cline-hook-bridge/README.md | 41 +++++++++++++++++++ examples/cline-hook-bridge/cline.toml | 20 +++++++++ .../hooks/SessionShutdown.sh | 7 ++++ .../cline-hook-bridge/hooks/TaskComplete.sh | 7 ++++ examples/cline-hook-bridge/hooks/TaskError.sh | 7 ++++ examples/cline-hook-bridge/hooks/TaskStart.sh | 8 ++++ 9 files changed, 111 insertions(+) create mode 100644 docs/cline-hook-bridge.md create mode 100644 examples/cline-hook-bridge/README.md create mode 100644 examples/cline-hook-bridge/cline.toml create mode 100755 examples/cline-hook-bridge/hooks/SessionShutdown.sh create mode 100755 examples/cline-hook-bridge/hooks/TaskComplete.sh create mode 100755 examples/cline-hook-bridge/hooks/TaskError.sh create mode 100755 examples/cline-hook-bridge/hooks/TaskStart.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 6eb59b78c..d2858557e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ breaking changes may land in a minor release. ### Added +- Add a verified Cline CLI hook bridge example: an experimental profile, executable hook scripts that relay `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError`, and a setup guide. See `docs/cline-hook-bridge.md`. - Add the experimental `tickets` work source for BMAD v7 initiative ticket trees (`[stories] source = "tickets"`): dispatch `bmad-build-auto ticket ` in initiative build order, verify each plan at `built`, and mark it `done` through `tickets.py mark` diff --git a/docs/README.md b/docs/README.md index b7ca53c75..a5e9486dc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -22,6 +22,7 @@ guides below go deeper, roughly in the order you'll need them. ## Extending bmad-loop - **[Authoring CLI adapters & profiles](adapter-authoring-guide.md)** — using `bmad-loop probe-adapter` to collect + sanitize the hook payload shape, transcript location, and token schema a new CLI profile needs, plus the `CodingCLIAdapter` ABC and how an adapter class (and the profile selecting it) ships out-of-tree. +- **[Cline hook bridge](cline-hook-bridge.md)** — experimental profile and executable hook scripts for driving Cline before a first-class hook dialect exists. - **[Writing a bmad-loop plugin](plugin-authoring-guide.md)** — the plugin system: `plugin.toml` manifest, hooks, lifecycle stages, settings, the trust model, and workflow injection, with a worked walkthrough. - **[Writing a Game Engine plugin](game-engine-plugin-guide.md)** — the game-engine layer (built on the plugin system): driving a live engine Editor, the `editor_mode` ↔ `[scm] isolation` coupling, a minimal Godot example. - **[Writing a plugin for a specific Editor MCP](game-engine-mcp-guide.md)** — Editor-MCP specifics for the bundled Unity plugin: IvanMurzak vs CoplayDev, readiness probes, `per_worktree` isolation, and the full `BMAD_LOOP_*` env-var reference. diff --git a/docs/cline-hook-bridge.md b/docs/cline-hook-bridge.md new file mode 100644 index 000000000..07f81a84a --- /dev/null +++ b/docs/cline-hook-bridge.md @@ -0,0 +1,19 @@ +# Cline hook bridge + +A verified recipe for driving bmad-loop with the Cline CLI before a first-class Cline hook dialect exists. + +Cline discovers hooks as executable files in `.cline/hooks/`. bmad-loop checks relay registration in a JSON hook config. The recipe in [examples/cline-hook-bridge](../examples/cline-hook-bridge/README.md) supplies both halves: an experimental profile and four executable hook scripts. + +## When to use it + +Use it when Cline is the chosen adapter for a stage and the project has a multiplexer backend available. The Herdr backend works without tmux. OpenCode over HTTP/SSE needs no multiplexer and stays the default adapter for other stages. + +## Setup + +Install the profile into `.bmad-loop/profiles/`, copy the scripts into `.cline/hooks/`, make them executable, then run `bmad-loop init --project . --cli cline` and `bmad-loop validate --project .`. + +The profile uses the `claude-settings-json` registration shape. The JSON file is not read by Cline; the executable scripts are the live path. + +## Limits + +Token usage is not parsed because the Cline hook payload carries no transcript path. Cline hooks are disabled in yolo mode, so the profile uses `--auto-approve false` instead of `--yolo`. Only `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError` are mapped. diff --git a/examples/cline-hook-bridge/README.md b/examples/cline-hook-bridge/README.md new file mode 100644 index 000000000..3fcc0f7b4 --- /dev/null +++ b/examples/cline-hook-bridge/README.md @@ -0,0 +1,41 @@ +# Cline hook bridge (experimental) + +Cline can drive bmad-loop today, but it needs a small hook bridge because bmad-loop has no Cline hook dialect yet. Cline finds hooks as executable files in `.cline/hooks/`. bmad-loop validates relay registration in a JSON hook config. This example supplies both halves. + +The profile declares `claude-settings-json` only as the registration shape bmad-loop checks. Cline does not read that JSON file. The executable files in `hooks/` are what Cline actually runs, and they pipe each payload into `bmad-loop relay` with the canonical event name. + +## Requirements + +- Cline CLI 3.0 or newer, authenticated with `cline auth` in the project. +- `jq` on PATH. +- `bmad-loop` on PATH, installed next to the project. +- A multiplexer backend available for the launches. The `herdr` backend works without tmux; `opencode-http` needs no multiplexer and can remain the default adapter. + +## Install in a project + +```bash +mkdir -p .bmad-loop/profiles .cline/hooks +cp cline.toml .bmad-loop/profiles/cline.toml +cp hooks/*.sh .cline/hooks/ +chmod +x .cline/hooks/*.sh +bmad-loop init --project . --cli cline +bmad-loop validate --project . +``` + +`init` writes `.cline/hooks.json`. That file is only for bmad-loop's registration check; the `.cline/hooks/*.sh` scripts are the live path. + +## Point a stage at Cline + +`--cli` registers hooks. `[adapter] name` in `.bmad-loop/policy.toml` selects the CLI that runs each stage. Use `[adapter.dev]`, `[adapter.review]`, or `[adapter.triage]` to mix CLIs per stage. Any CLI named there must also be registered with `--cli`. + +Cline disables hooks in yolo mode, so the profile uses `--auto-approve false` instead of `--yolo`. + +## What was verified + +On Cline 3.0.74 and bmad-loop 0.13.2, a live Cline turn fired `agent_start` and `agent_end`. The hooks wrote `SessionStart` and `Stop` event files with the same `sessionId` and the correct `cwd`. `bmad-loop validate` passed with `adapter dev=cline` and the Herdr backend, and `bmad-loop run --dry-run` accepted the ticket-tree plan. + +## Limits + +- This is a bridge, not a first-class Cline dialect. A future dialect could write Cline's file hooks directly and make the JSON shim unnecessary. +- Token usage is not parsed. The profile sets `usage_parser = "none"` because the hook payload carries no transcript path. +- Map events are `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError`. Other Cline hooks are ignored. diff --git a/examples/cline-hook-bridge/cline.toml b/examples/cline-hook-bridge/cline.toml new file mode 100644 index 000000000..b91333862 --- /dev/null +++ b/examples/cline-hook-bridge/cline.toml @@ -0,0 +1,20 @@ +# Experimental Cline CLI profile for bmad-loop. +# +# Cline discovers hooks as executable files in .cline/hooks/, not as a JSON +# settings file. This profile uses the claude-settings-json dialect only as the +# registration shape bmad-loop validates; the files in hooks/ are what Cline +# actually runs. See README.md in this folder before using it. +name = "cline" +binary = "cline" +prompt_template = "{prompt}" +# Cline disables hooks in yolo mode, so keep act mode for unattended runs. +bypass_args = ["--auto-approve", "false"] +model_flag = "--model" +usage_parser = "none" +skill_tree = ".agents/skills" +first_run_note = "run `cline auth` once in this project and choose a provider and model" + +[hooks] +dialect = "claude-settings-json" +config_path = ".cline/hooks.json" +events = { TaskStart = "SessionStart", TaskComplete = "Stop", SessionShutdown = "SessionEnd", TaskError = "StopFailure" } diff --git a/examples/cline-hook-bridge/hooks/SessionShutdown.sh b/examples/cline-hook-bridge/hooks/SessionShutdown.sh new file mode 100755 index 000000000..d3fac0380 --- /dev/null +++ b/examples/cline-hook-bridge/hooks/SessionShutdown.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Relay Cline's session_shutdown to bmad-loop as SessionEnd. +set -euo pipefail +payload=$(cat) +printf '%s' "$payload" \ + | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ + | bmad-loop relay SessionEnd diff --git a/examples/cline-hook-bridge/hooks/TaskComplete.sh b/examples/cline-hook-bridge/hooks/TaskComplete.sh new file mode 100755 index 000000000..c3670f965 --- /dev/null +++ b/examples/cline-hook-bridge/hooks/TaskComplete.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Relay Cline's agent_end to bmad-loop as Stop. +set -euo pipefail +payload=$(cat) +printf '%s' "$payload" \ + | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ + | bmad-loop relay Stop diff --git a/examples/cline-hook-bridge/hooks/TaskError.sh b/examples/cline-hook-bridge/hooks/TaskError.sh new file mode 100755 index 000000000..0493cf523 --- /dev/null +++ b/examples/cline-hook-bridge/hooks/TaskError.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Relay Cline's agent_error to bmad-loop as StopFailure. +set -euo pipefail +payload=$(cat) +printf '%s' "$payload" \ + | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ + | bmad-loop relay StopFailure diff --git a/examples/cline-hook-bridge/hooks/TaskStart.sh b/examples/cline-hook-bridge/hooks/TaskStart.sh new file mode 100755 index 000000000..74d43b7a8 --- /dev/null +++ b/examples/cline-hook-bridge/hooks/TaskStart.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Relay Cline's agent_start to bmad-loop as SessionStart. +# Cline sends taskId, not session_id; jq maps it for session attribution. +set -euo pipefail +payload=$(cat) +printf '%s' "$payload" \ + | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ + | bmad-loop relay SessionStart From b93a6287ea7fbd2967de8ee9563f04472e46e5b9 Mon Sep 17 00:00:00 2001 From: EDMND-SRC Date: Mon, 30 Nov 2026 15:31:54 +0200 Subject: [PATCH 2/2] feat: add Cline CLI adapter with file hooks --- CHANGELOG.md | 2 +- docs/README.md | 2 +- docs/cline-hook-bridge.md | 18 +++----- examples/cline-hook-bridge/README.md | 41 ------------------- examples/cline-hook-bridge/cline.toml | 20 --------- .../hooks/SessionShutdown.sh | 7 ---- .../cline-hook-bridge/hooks/TaskComplete.sh | 7 ---- examples/cline-hook-bridge/hooks/TaskError.sh | 7 ---- examples/cline-hook-bridge/hooks/TaskStart.sh | 8 ---- src/bmad_loop/adapters/profile.py | 3 ++ src/bmad_loop/data/profiles/cline.toml | 27 ++++++++++++ src/bmad_loop/install.py | 37 +++++++++++++++++ tests/test_install.py | 24 +++++++++++ tests/test_profile.py | 14 ++++++- 14 files changed, 111 insertions(+), 106 deletions(-) delete mode 100644 examples/cline-hook-bridge/README.md delete mode 100644 examples/cline-hook-bridge/cline.toml delete mode 100755 examples/cline-hook-bridge/hooks/SessionShutdown.sh delete mode 100755 examples/cline-hook-bridge/hooks/TaskComplete.sh delete mode 100755 examples/cline-hook-bridge/hooks/TaskError.sh delete mode 100755 examples/cline-hook-bridge/hooks/TaskStart.sh create mode 100644 src/bmad_loop/data/profiles/cline.toml diff --git a/CHANGELOG.md b/CHANGELOG.md index d2858557e..3f21b0a9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ breaking changes may land in a minor release. ### Added -- Add a verified Cline CLI hook bridge example: an experimental profile, executable hook scripts that relay `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError`, and a setup guide. See `docs/cline-hook-bridge.md`. +- Add a first-class Cline CLI adapter profile with a `cline-file-hooks` dialect. `init` writes executable Cline hook scripts that relay task start, completion, shutdown, and error, map `taskId` to `sessionId`, preserve failure text, and seed the scripts into worktrees. - Add the experimental `tickets` work source for BMAD v7 initiative ticket trees (`[stories] source = "tickets"`): dispatch `bmad-build-auto ticket ` in initiative build order, verify each plan at `built`, and mark it `done` through `tickets.py mark` diff --git a/docs/README.md b/docs/README.md index a5e9486dc..8c1d00c93 100644 --- a/docs/README.md +++ b/docs/README.md @@ -22,7 +22,7 @@ guides below go deeper, roughly in the order you'll need them. ## Extending bmad-loop - **[Authoring CLI adapters & profiles](adapter-authoring-guide.md)** — using `bmad-loop probe-adapter` to collect + sanitize the hook payload shape, transcript location, and token schema a new CLI profile needs, plus the `CodingCLIAdapter` ABC and how an adapter class (and the profile selecting it) ships out-of-tree. -- **[Cline hook bridge](cline-hook-bridge.md)** — experimental profile and executable hook scripts for driving Cline before a first-class hook dialect exists. +- **[Cline CLI](cline-hook-bridge.md)** — built-in profile: file hooks, the JSON registration shim, worktree seeding, and unattended launch flags. - **[Writing a bmad-loop plugin](plugin-authoring-guide.md)** — the plugin system: `plugin.toml` manifest, hooks, lifecycle stages, settings, the trust model, and workflow injection, with a worked walkthrough. - **[Writing a Game Engine plugin](game-engine-plugin-guide.md)** — the game-engine layer (built on the plugin system): driving a live engine Editor, the `editor_mode` ↔ `[scm] isolation` coupling, a minimal Godot example. - **[Writing a plugin for a specific Editor MCP](game-engine-mcp-guide.md)** — Editor-MCP specifics for the bundled Unity plugin: IvanMurzak vs CoplayDev, readiness probes, `per_worktree` isolation, and the full `BMAD_LOOP_*` env-var reference. diff --git a/docs/cline-hook-bridge.md b/docs/cline-hook-bridge.md index 07f81a84a..d16ebb350 100644 --- a/docs/cline-hook-bridge.md +++ b/docs/cline-hook-bridge.md @@ -1,19 +1,11 @@ -# Cline hook bridge +# Cline CLI -A verified recipe for driving bmad-loop with the Cline CLI before a first-class Cline hook dialect exists. +Cline is a built-in adapter profile. `bmad-loop init --cli cline` writes a JSON registration shim and four executable hook scripts in `.cline/hooks/`, then Cline relays `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError` into bmad-loop. -Cline discovers hooks as executable files in `.cline/hooks/`. bmad-loop checks relay registration in a JSON hook config. The recipe in [examples/cline-hook-bridge](../examples/cline-hook-bridge/README.md) supplies both halves: an experimental profile and four executable hook scripts. - -## When to use it - -Use it when Cline is the chosen adapter for a stage and the project has a multiplexer backend available. The Herdr backend works without tmux. OpenCode over HTTP/SSE needs no multiplexer and stays the default adapter for other stages. +Cline discovers hooks as files, not as a JSON settings file. The shim exists so `validate` can check registration; the scripts are the live hook path. `init` writes them with the relay command for this installation. ## Setup -Install the profile into `.bmad-loop/profiles/`, copy the scripts into `.cline/hooks/`, make them executable, then run `bmad-loop init --project . --cli cline` and `bmad-loop validate --project .`. - -The profile uses the `claude-settings-json` registration shape. The JSON file is not read by Cline; the executable scripts are the live path. - -## Limits +Run `cline auth` once in the project, then `bmad-loop init --project . --cli cline` and `bmad-loop validate --project .`. The profile reads skills from `.agents/skills` and seeds the four hook scripts into worktrees. -Token usage is not parsed because the Cline hook payload carries no transcript path. Cline hooks are disabled in yolo mode, so the profile uses `--auto-approve false` instead of `--yolo`. Only `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError` are mapped. +Unattended stages use `--auto-approve true` rather than `--yolo`, because yolo mode disables Cline's hook forwarding. Token usage is not parsed; the profile sets `usage_parser = "none"`. diff --git a/examples/cline-hook-bridge/README.md b/examples/cline-hook-bridge/README.md deleted file mode 100644 index 3fcc0f7b4..000000000 --- a/examples/cline-hook-bridge/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Cline hook bridge (experimental) - -Cline can drive bmad-loop today, but it needs a small hook bridge because bmad-loop has no Cline hook dialect yet. Cline finds hooks as executable files in `.cline/hooks/`. bmad-loop validates relay registration in a JSON hook config. This example supplies both halves. - -The profile declares `claude-settings-json` only as the registration shape bmad-loop checks. Cline does not read that JSON file. The executable files in `hooks/` are what Cline actually runs, and they pipe each payload into `bmad-loop relay` with the canonical event name. - -## Requirements - -- Cline CLI 3.0 or newer, authenticated with `cline auth` in the project. -- `jq` on PATH. -- `bmad-loop` on PATH, installed next to the project. -- A multiplexer backend available for the launches. The `herdr` backend works without tmux; `opencode-http` needs no multiplexer and can remain the default adapter. - -## Install in a project - -```bash -mkdir -p .bmad-loop/profiles .cline/hooks -cp cline.toml .bmad-loop/profiles/cline.toml -cp hooks/*.sh .cline/hooks/ -chmod +x .cline/hooks/*.sh -bmad-loop init --project . --cli cline -bmad-loop validate --project . -``` - -`init` writes `.cline/hooks.json`. That file is only for bmad-loop's registration check; the `.cline/hooks/*.sh` scripts are the live path. - -## Point a stage at Cline - -`--cli` registers hooks. `[adapter] name` in `.bmad-loop/policy.toml` selects the CLI that runs each stage. Use `[adapter.dev]`, `[adapter.review]`, or `[adapter.triage]` to mix CLIs per stage. Any CLI named there must also be registered with `--cli`. - -Cline disables hooks in yolo mode, so the profile uses `--auto-approve false` instead of `--yolo`. - -## What was verified - -On Cline 3.0.74 and bmad-loop 0.13.2, a live Cline turn fired `agent_start` and `agent_end`. The hooks wrote `SessionStart` and `Stop` event files with the same `sessionId` and the correct `cwd`. `bmad-loop validate` passed with `adapter dev=cline` and the Herdr backend, and `bmad-loop run --dry-run` accepted the ticket-tree plan. - -## Limits - -- This is a bridge, not a first-class Cline dialect. A future dialect could write Cline's file hooks directly and make the JSON shim unnecessary. -- Token usage is not parsed. The profile sets `usage_parser = "none"` because the hook payload carries no transcript path. -- Map events are `TaskStart`, `TaskComplete`, `SessionShutdown`, and `TaskError`. Other Cline hooks are ignored. diff --git a/examples/cline-hook-bridge/cline.toml b/examples/cline-hook-bridge/cline.toml deleted file mode 100644 index b91333862..000000000 --- a/examples/cline-hook-bridge/cline.toml +++ /dev/null @@ -1,20 +0,0 @@ -# Experimental Cline CLI profile for bmad-loop. -# -# Cline discovers hooks as executable files in .cline/hooks/, not as a JSON -# settings file. This profile uses the claude-settings-json dialect only as the -# registration shape bmad-loop validates; the files in hooks/ are what Cline -# actually runs. See README.md in this folder before using it. -name = "cline" -binary = "cline" -prompt_template = "{prompt}" -# Cline disables hooks in yolo mode, so keep act mode for unattended runs. -bypass_args = ["--auto-approve", "false"] -model_flag = "--model" -usage_parser = "none" -skill_tree = ".agents/skills" -first_run_note = "run `cline auth` once in this project and choose a provider and model" - -[hooks] -dialect = "claude-settings-json" -config_path = ".cline/hooks.json" -events = { TaskStart = "SessionStart", TaskComplete = "Stop", SessionShutdown = "SessionEnd", TaskError = "StopFailure" } diff --git a/examples/cline-hook-bridge/hooks/SessionShutdown.sh b/examples/cline-hook-bridge/hooks/SessionShutdown.sh deleted file mode 100755 index d3fac0380..000000000 --- a/examples/cline-hook-bridge/hooks/SessionShutdown.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -# Relay Cline's session_shutdown to bmad-loop as SessionEnd. -set -euo pipefail -payload=$(cat) -printf '%s' "$payload" \ - | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ - | bmad-loop relay SessionEnd diff --git a/examples/cline-hook-bridge/hooks/TaskComplete.sh b/examples/cline-hook-bridge/hooks/TaskComplete.sh deleted file mode 100755 index c3670f965..000000000 --- a/examples/cline-hook-bridge/hooks/TaskComplete.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -# Relay Cline's agent_end to bmad-loop as Stop. -set -euo pipefail -payload=$(cat) -printf '%s' "$payload" \ - | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ - | bmad-loop relay Stop diff --git a/examples/cline-hook-bridge/hooks/TaskError.sh b/examples/cline-hook-bridge/hooks/TaskError.sh deleted file mode 100755 index 0493cf523..000000000 --- a/examples/cline-hook-bridge/hooks/TaskError.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash -# Relay Cline's agent_error to bmad-loop as StopFailure. -set -euo pipefail -payload=$(cat) -printf '%s' "$payload" \ - | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ - | bmad-loop relay StopFailure diff --git a/examples/cline-hook-bridge/hooks/TaskStart.sh b/examples/cline-hook-bridge/hooks/TaskStart.sh deleted file mode 100755 index 74d43b7a8..000000000 --- a/examples/cline-hook-bridge/hooks/TaskStart.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -# Relay Cline's agent_start to bmad-loop as SessionStart. -# Cline sends taskId, not session_id; jq maps it for session attribution. -set -euo pipefail -payload=$(cat) -printf '%s' "$payload" \ - | jq '. + {sessionId: (.sessionId // .taskId // ""), cwd: (.cwd // .workspaceRoots[0] // "")}' \ - | bmad-loop relay SessionStart diff --git a/src/bmad_loop/adapters/profile.py b/src/bmad_loop/adapters/profile.py index e5af4b93d..70c0b36c0 100644 --- a/src/bmad_loop/adapters/profile.py +++ b/src/bmad_loop/adapters/profile.py @@ -76,6 +76,9 @@ "gemini-settings-json", "copilot-settings-json", "antigravity-hooks-json", + # Cline discovers hooks as executable files in .cline/hooks/. init still + # writes a JSON registration shim for validate, then writes the scripts. + "cline-file-hooks", # hookless: the adapter observes completion itself (HTTP/SSE transport) — # no hook config is ever written, so config_path/events must stay empty. "none", diff --git a/src/bmad_loop/data/profiles/cline.toml b/src/bmad_loop/data/profiles/cline.toml new file mode 100644 index 000000000..269c504bb --- /dev/null +++ b/src/bmad_loop/data/profiles/cline.toml @@ -0,0 +1,27 @@ +# Cline CLI, using file-based hooks in .cline/hooks/. +# init writes the JSON registration shim at config_path and executable scripts +# for each mapped native event. --yolo would disable Cline's hook forwarding, +# so unattended runs use --auto-approve true instead. +name = "cline" +binary = "cline" +prompt_template = "{prompt}" +bypass_args = ["--auto-approve", "true"] +model_flag = "--model" +usage_parser = "none" +skill_tree = ".agents/skills" +seed_files = [ + ".cline/hooks/TaskStart.sh", + ".cline/hooks/TaskComplete.sh", + ".cline/hooks/SessionShutdown.sh", + ".cline/hooks/TaskError.sh", +] +first_run_note = "run `cline auth` once in this project and choose a provider and model" + +[hooks] +dialect = "cline-file-hooks" +config_path = ".cline/hooks.json" +events = { TaskStart = "SessionStart", TaskComplete = "Stop", SessionShutdown = "SessionEnd", TaskError = "StopFailure" } + +[user_skills] +precedence = "unordered" +roots = ["~/.cline/skills", "~/.agents/skills"] diff --git a/src/bmad_loop/install.py b/src/bmad_loop/install.py index 97297c05b..47d8d83e1 100644 --- a/src/bmad_loop/install.py +++ b/src/bmad_loop/install.py @@ -68,6 +68,7 @@ # agy's .agents/hooks.json keys by hook NAME at the top level (not a "hooks" # wrapper); bmad-loop registers all its handlers under this single group. ANTIGRAVITY_HOOK_GROUP = "bmad-loop" +CLINE_FILE_HOOKS = "cline-file-hooks" # The bmad-loop-* skills bundled in the wheel (bmad_loop/data/skills/, mapped from # the repo-root `skills/` at build time; see :func:`skills_root`) that @@ -2672,6 +2673,26 @@ def _hook_command(project: Path, profile: CLIProfile, canonical_event: str) -> s return f"{get_process_host().shell_quote(str(_relay_executable()))} relay {canonical_event}" +def _cline_hook_script(native: str, command: str) -> str: + """Executable Cline file hook that relays one native event. + + Cline sends `taskId` and a workspace-root list, not bmad-loop's `session_id` + and `cwd`; jq maps both. Cline's `agent_error` carries a message object, so + it is copied to `error_details`, the field the relay forwards on StopFailure. + """ + del native # the filename carries the native event; the command carries the canonical one + return ( + "#!/usr/bin/env bash\n" + "set -euo pipefail\n" + "payload=$(cat)\n" + "printf '%s' \"$payload\" | jq " + "'. + {sessionId: (.sessionId // .taskId // \"\"), " + "cwd: (.cwd // .workspaceRoots[0] // \"\"), " + "error_details: ((.error.message? // .error? // \"\") | tostring)}' " + f"| {command}\n" + ) + + def _warn_unsafe_relay_path() -> None: """DW-346: print one advisory line when the relay executable ``init`` just registered carries shell metacharacters this host's hook quoting leaves @@ -3549,6 +3570,22 @@ def _register_hooks(project: Path, profile: CLIProfile) -> int: atomic_write_text( config_path, json.dumps(config, indent=2) + "\n", require_writable_target=True ) + if profile.hooks.dialect == CLINE_FILE_HOOKS: + hooks_dir = project / ".cline" / "hooks" + hooks_dir.mkdir(parents=True, exist_ok=True) + for native_event, command in registrations.items(): + if not native_event.isalnum(): + raise ProfileError( + f"unsafe Cline hook event name {native_event!r}; expected alphanumeric" + ) + script = hooks_dir / f"{native_event}.sh" + atomic_write_text( + script, + _cline_hook_script(native_event, command), + require_writable_target=True, + ) + script.chmod(0o755) + print(f" Cline hook scripts written: {hooks_dir}") print(f" hooks registered ({profile.name}): {config_path}") else: print(f" hooks already registered ({profile.name})") diff --git a/tests/test_install.py b/tests/test_install.py index b18797033..edfa1caab 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -1690,6 +1690,30 @@ def test_provision_worktree_lays_down_skills_and_hook(tmp_path): assert json.loads(next((wt / "events").glob("*.json")).read_text())["event"] == "Stop" +def test_cline_registration_writes_executable_hook_scripts(tmp_path): + """Cline discovers hooks as files, so init must lay them down with the relay. + + The scripts map taskId to sessionId and workspace root to cwd, and carry the + agent_error message in error_details so StopFailure keeps its reason. + """ + cline = get_profile("cline") + assert _register_hooks(tmp_path, cline) == 0 + hooks = tmp_path / ".cline" / "hooks" + scripts = sorted(hooks.glob("*.sh")) + assert [p.name for p in scripts] == [ + "SessionShutdown.sh", + "TaskComplete.sh", + "TaskError.sh", + "TaskStart.sh", + ] + start = (hooks / "TaskStart.sh").read_text() + assert "relay SessionStart" in start + assert "sessionId" in start and "cwd" in start + error = (hooks / "TaskError.sh").read_text() + assert "relay StopFailure" in error and "error_details" in error + assert all(path.stat().st_mode & 0o111 for path in scripts) + + def test_provision_worktree_rewrites_seeded_relative_hook_to_absolute(tmp_path): """The main repo's .claude/settings.json carries a $CLAUDE_PROJECT_DIR-relative relay command. Seeded into a worktree, that variable resolves to the worktree, diff --git a/tests/test_profile.py b/tests/test_profile.py index dd7f55a8a..af5074fe8 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -72,6 +72,11 @@ def test_builtin_profiles_load(): assert profiles["copilot"].usage_parser == "copilot-events" # agy 1.4.9 writes per-step counts into its transcript assert profiles["antigravity"].usage_parser == "antigravity-transcript" + # Cline uses file hooks; init writes executable scripts beside the JSON shim + assert "cline" in profiles + assert profiles["cline"].hooks.dialect == "cline-file-hooks" + assert profiles["cline"].bypass_args == ("--auto-approve", "true") + assert ".cline/hooks/TaskStart.sh" in profiles["cline"].seed_files # copilot confirms tool calls, file paths and URL fetches separately; an # unattended session needs all three bypassed, or a URL fetch parks it assert profiles["copilot"].bypass_args == ( @@ -289,7 +294,10 @@ def test_claude_maps_its_stop_failure_types(): for name, prof in load_profiles().items(): if name != "claude": assert prof.hooks.stop_failure_types == {}, name - assert "StopFailure" not in prof.hooks.events.values(), name + # Cline maps agent_error to StopFailure and forwards its message in + # error_details; other adapters have no StopFailure carrier. + if name != "cline": + assert "StopFailure" not in prof.hooks.events.values(), name assert prof.hooks.event_min_versions == {}, name @@ -2263,6 +2271,10 @@ def test_default_profile_declares_no_extra_trees_and_no_user_skills(tmp_path): UserSkillRoot("~/.agents/skills", ("COPILOT_HOME",)), ), ), + "cline": UserSkillsSpec( + "unordered", + (UserSkillRoot("~/.cline/skills"), UserSkillRoot("~/.agents/skills")), + ), "opencode-http": UserSkillsSpec( "project", (