diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-09 15:59:34 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-09 15:59:34 +0300 |
| commit | df7880c54b8b5d337421cb4b1dd8daea27008801 (patch) | |
| tree | 4d0cc6290ad71c413bac71cfaab4ef41ea017ecb /src/integration/assets/qodercli | |
| parent | eeacb45b4b6ab4446c5bea1331f743fee5e5b9f8 (diff) | |
feat: update agent lifecycle integrations
Diffstat (limited to 'src/integration/assets/qodercli')
| -rw-r--r-- | src/integration/assets/qodercli/herdr-agent-state.ps1 | 17 | ||||
| -rw-r--r-- | src/integration/assets/qodercli/herdr-agent-state.sh | 64 |
2 files changed, 23 insertions, 58 deletions
diff --git a/src/integration/assets/qodercli/herdr-agent-state.ps1 b/src/integration/assets/qodercli/herdr-agent-state.ps1 index f7102817..df527f6d 100644 --- a/src/integration/assets/qodercli/herdr-agent-state.ps1 +++ b/src/integration/assets/qodercli/herdr-agent-state.ps1 @@ -2,11 +2,11 @@ # 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 +# HERDR_INTEGRATION_VERSION=2 param([string]$Action = "") -if ($Action -notin @("working", "idle", "blocked", "release")) { exit 0 } +if ($Action -ne "session") { exit 0 } if ($env:HERDR_ENV -ne "1") { exit 0 } if ([string]::IsNullOrWhiteSpace($env:HERDR_PANE_ID)) { exit 0 } @@ -17,19 +17,10 @@ try { $payload = $null } -if ($payload.hook_event_name -eq "SubagentStop") { exit 0 } -if ($payload.agent_id -and $Action -in @("idle", "release")) { exit 0 } +if ($null -eq $payload -or [string]::IsNullOrWhiteSpace($payload.session_id)) { exit 0 } $seq = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() try { - if ($Action -eq "release") { - & herdr pane release-agent $env:HERDR_PANE_ID --source herdr:qodercli --agent qodercli --seq $seq 2>$null | Out-Null - } else { - $args = @("pane", "report-agent", $env:HERDR_PANE_ID, "--source", "herdr:qodercli", "--agent", "qodercli", "--state", $Action, "--seq", "$seq") - if (-not [string]::IsNullOrWhiteSpace($payload.session_id)) { - $args += @("--agent-session-id", $payload.session_id) - } - & herdr @args 2>$null | Out-Null - } + & herdr pane report-agent-session $env:HERDR_PANE_ID --source herdr:qodercli --agent qodercli --agent-session-id $payload.session_id --seq $seq 2>$null | Out-Null } catch { } diff --git a/src/integration/assets/qodercli/herdr-agent-state.sh b/src/integration/assets/qodercli/herdr-agent-state.sh index 8903c45c..b55d8194 100644 --- a/src/integration/assets/qodercli/herdr-agent-state.sh +++ b/src/integration/assets/qodercli/herdr-agent-state.sh @@ -3,17 +3,15 @@ # 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 +# HERDR_INTEGRATION_VERSION=2 # -# Reports qodercli agent state changes to herdr. Registered as a Command hook +# Reports qodercli session identity 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. +# invoked by qodercli's hook system on session start. # # 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. +# stdin describing the hook event. This hook reads the session id from that +# payload. set -eu @@ -23,7 +21,7 @@ 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) ;; + session) ;; *) exit 0 ;; esac @@ -40,7 +38,6 @@ 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") @@ -58,46 +55,23 @@ if hook_input_file: 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. +session_id = hook_input.get("session_id") +if not isinstance(session_id, str) or not session_id: 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 +request = { + "id": request_id, + "method": "pane.report_agent_session", + "params": { + "pane_id": pane_id, + "source": source, + "agent": "qodercli", + "agent_session_id": session_id, + "seq": report_seq, + }, +} try: client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
