Repository navigation
feat: add Cline CLI adapter with file hooks #1068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Cline CLI | ||
|
|
||
| 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 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 | ||
|
|
||
| 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. | ||
|
|
||
| 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"`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconcile live scripts even when the JSON shim is unchanged. If a script write fails after Move script reconciliation outside
|
||
| 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, | ||
|
Comment on lines
+3582
to
+3585
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confine each live-script destination before writing. If Check the hooks directory and every script destination with
|
||
| ) | ||
| 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})") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the
jqprerequisite before completing installation.If
jqis absent, every generated hook fails underpipefail. The transformed payload never reaches the relay. Neither installation nor validation checks this dependency, and the setup guide does not list it.Require
jqbefore reporting successful installation and document the prerequisite, or remove the external dependency.