diff options
| author | Coder Wayne <1418551940@qq.com> | 2026-05-27 22:42:26 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-27 17:42:26 +0300 |
| commit | bfb9e756a01a8ddf4e20d2451c8316ab33454bb4 (patch) | |
| tree | 2cf90e050e5a6e4d32bbda2f13321aecb4615345 /src/integration/assets/qodercli | |
| parent | 858c36974bad616e9e6c1897882b8c9a97396bec (diff) | |
feat: add Qoder CLI integration (#309)
* feat: add qodercli agent integration
Recognize qodercli as an agent in herdr panes, with basic Idle/Working/
Blocked screen-state detection mirroring the existing claude / codex
patterns. Adds an IntegrationTarget::Qodercli variant, install_target
wiring for shell hooks under src/integration/assets/qodercli/, the
herdr integration install qodercli CLI surface, and sound-override
coverage so qodercli notifications follow the same routing rules as
other agents.
refs #308
* fix: detect qodercli permission required as blocked
refs #308
* fix: detect qodercli ask-user prompt as blocked
refs #308
* refactor: extract has_qodercli_blocked_prompt helper aligning detect_claude
refs #308
* fix: tighten qodercli working state detection
Combine spinner-row strictness and explicit cancel-hint matching, and
stop matching the bare word 'working'. This avoids false positives when
narrative output (logs, commit messages, Markdown) contains the word
'working' or when a stale braille glyph is sitting in the scrollback
from a previous frame.
- has_qodercli_spinner_row: require row-start braille glyph + space +
alphabetic char so only an active spinner row triggers Working.
- has_qodercli_working_hint: match '(esc to cancel,' as a positive
signal that survives spinner masking (e.g. when a hook icon replaces
the spinner glyph).
refs #308
* fix: short-circuit qodercli press-again banners to idle
refs #308
* fix: detect qodercli AskUser dialog by its 'Asking User' title
refs #308
* feat: recognize qodercli, qoderclicn, qoder, qodercn process names
Map qodercli, qoderclicn, qoder, and qodercn process names all to the
Qodercli agent. Covers both international (qodercli/qoder) and CN
(qoderclicn/qodercn) Qoder CLI binary names.
refs #308
* feat: register qodercli hook in qoder settings.json with stdin payload
Address the integration-layer feedback on #308:
- `herdr integration install qodercli` now writes the bundled hook into
~/.qoder/hooks/herdr-agent-state.sh AND registers it in
~/.qoder/settings.json under the schema documented at
https://docs.qoder.com/zh/cli/hooks (and confirmed against the
packages/core/src/hooks/types.ts type definitions in qodercli's own
source tree). The hooks object is keyed by event name —
SessionStart / UserPromptSubmit / PreToolUse / PermissionRequest /
Stop / SessionEnd — with each entry holding a matcher and a list of
`{ type: "command", command, timeout }` invocations, mirroring how
install_claude already wires claude code's settings.json.
- The bundled assets/qodercli/herdr-agent-state.sh now reads the hook
payload from stdin (per HookInput in qodercli's types.ts:
session_id, transcript_path, cwd, hook_event_name, agent_id, ...).
No environment variable is consulted to identify the event;
SubagentStop and subagent release events return early so a recap or
away-summary frame cannot revive an idle pane, mirroring
assets/claude/herdr-agent-state.sh.
- uninstall_qodercli reverses the same set of entries while preserving
any foreign hook entries the user may have configured by hand.
- Tests cover write / idempotency / uninstall-preserves-others and
lock the stdin contract via a bundled-asset assertion.
refs #308
---------
Co-authored-by: coderwayne <jlu1318079810@163.com>
Co-authored-by: Can Celik <ogulcancelik@gmail.com>
Diffstat (limited to 'src/integration/assets/qodercli')
| -rw-r--r-- | src/integration/assets/qodercli/herdr-agent-state.sh | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/integration/assets/qodercli/herdr-agent-state.sh b/src/integration/assets/qodercli/herdr-agent-state.sh new file mode 100644 index 00000000..8903c45c --- /dev/null +++ b/src/integration/assets/qodercli/herdr-agent-state.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# installed by herdr +# managed by herdr; reinstalling or updating the integration overwrites this file. +# add custom hooks beside this file instead of editing it. +# HERDR_INTEGRATION_ID=qodercli +# HERDR_INTEGRATION_VERSION=1 +# +# Reports qodercli agent state changes to herdr. Registered as a Command hook +# in ~/.qoder/settings.json by `herdr integration install qodercli` and +# invoked by qodercli's hook system on lifecycle events. +# +# qodercli (per https://docs.qoder.com/zh/cli/hooks) sends a JSON payload on +# stdin describing the hook event. The event name is read from the stdin +# payload's `hook_event_name` field, the same way +# `assets/claude/herdr-agent-state.sh` already consumes claude code's stdin +# payload. No environment variable is consulted for the event identity. + +set -eu + +action="${1:-}" +hook_input_file="$(mktemp "${TMPDIR:-/tmp}/herdr-qodercli-hook.XXXXXX")" || exit 0 +trap 'rm -f "$hook_input_file"' EXIT HUP INT TERM +cat >"$hook_input_file" 2>/dev/null || true + +case "$action" in + working|idle|blocked|release) ;; + *) exit 0 ;; +esac + +[ "${HERDR_ENV:-}" = "1" ] || exit 0 +[ -n "${HERDR_SOCKET_PATH:-}" ] || exit 0 +[ -n "${HERDR_PANE_ID:-}" ] || exit 0 +command -v python3 >/dev/null 2>&1 || exit 0 + +HERDR_ACTION="$action" HERDR_HOOK_INPUT_FILE="$hook_input_file" python3 - <<'PY' +import json +import os +import random +import socket +import time + +source = "herdr:qodercli" +action = os.environ.get("HERDR_ACTION", "") +pane_id = os.environ.get("HERDR_PANE_ID") +socket_path = os.environ.get("HERDR_SOCKET_PATH") +hook_input_file = os.environ.get("HERDR_HOOK_INPUT_FILE") + +if not pane_id or not socket_path: + raise SystemExit(0) + +hook_input = {} +if hook_input_file: + try: + with open(hook_input_file, encoding="utf-8") as handle: + content = handle.read() + if content.strip(): + hook_input = json.loads(content) + except Exception: + hook_input = {} + +# Per docs.qoder.com/zh/cli/hooks the payload always carries `hook_event_name`. +hook_event_name = str(hook_input.get("hook_event_name") or "") +is_subagent = bool(hook_input.get("agent_id")) +if hook_event_name == "SubagentStop": + # SubagentStop is a completion event; never let it revive an idle pane the + # way the parallel claude integration does. + raise SystemExit(0) +if is_subagent and action in ("idle", "release"): + # Subagent completion must not make the parent pane look done early. + raise SystemExit(0) + +request_id = f"{source}:{int(time.time() * 1000)}:{random.randrange(1_000_000):06d}" +report_seq = time.time_ns() +session_id = hook_input.get("session_id") +agent_session_id = session_id if isinstance(session_id, str) and session_id else None +if action == "release": + request = { + "id": request_id, + "method": "pane.release_agent", + "params": { + "pane_id": pane_id, + "source": source, + "agent": "qodercli", + "seq": report_seq, + }, + } +else: + request = { + "id": request_id, + "method": "pane.report_agent", + "params": { + "pane_id": pane_id, + "source": source, + "agent": "qodercli", + "state": action, + "seq": report_seq, + }, + } + if agent_session_id: + request["params"]["agent_session_id"] = agent_session_id + +try: + client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + client.settimeout(0.5) + client.connect(socket_path) + client.sendall((json.dumps(request) + "\n").encode()) + try: + client.recv(4096) + except Exception: + pass + client.close() +except Exception: + pass +PY |
