diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-22 19:36:40 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-07-22 19:36:40 +0300 |
| commit | d3b4d5b0e1a0859969e709b9d47fb2d1d4a1524c (patch) | |
| tree | 508e45e11ad2e2a10437bbd02a626381d680db67 /src | |
| parent | 1d238bc9a365d9dd1297b4e11fe775cd656aebd0 (diff) | |
refactor: simplify qoder session reporting
replaces contributions from wayneleelwc
Diffstat (limited to 'src')
| -rw-r--r-- | src/integration/assets/qodercli/herdr-agent-state.sh | 95 | ||||
| -rw-r--r-- | src/integration/tests.rs | 12 |
2 files changed, 29 insertions, 78 deletions
diff --git a/src/integration/assets/qodercli/herdr-agent-state.sh b/src/integration/assets/qodercli/herdr-agent-state.sh index b55d8194..871549e6 100644 --- a/src/integration/assets/qodercli/herdr-agent-state.sh +++ b/src/integration/assets/qodercli/herdr-agent-state.sh @@ -1,88 +1,39 @@ #!/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. +# managed by herdr; reinstalling the integration replaces this file. # HERDR_INTEGRATION_ID=qodercli # HERDR_INTEGRATION_VERSION=2 -# -# 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 session start. -# -# qodercli (per https://docs.qoder.com/zh/cli/hooks) sends a JSON payload on -# stdin describing the hook event. This hook reads the session id from that -# payload. - -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 - session) ;; - *) exit 0 ;; -esac +[ "${1:-}" = "session" ] || exit 0 [ "${HERDR_ENV:-}" = "1" ] || exit 0 [ -n "${HERDR_SOCKET_PATH:-}" ] || exit 0 [ -n "${HERDR_PANE_ID:-}" ] || exit 0 +command -v herdr >/dev/null 2>&1 || exit 0 command -v python3 >/dev/null 2>&1 || exit 0 -HERDR_ACTION="$action" HERDR_HOOK_INPUT_FILE="$hook_input_file" python3 - <<'PY' +python3 -c ' import json import os -import random -import socket +import subprocess +import sys import time -source = "herdr:qodercli" -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 = {} - -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() -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) - client.settimeout(0.5) - client.connect(socket_path) - client.sendall((json.dumps(request) + "\n").encode()) - try: - client.recv(4096) - except Exception: - pass - client.close() + payload = json.load(sys.stdin) + session_id = payload.get("session_id") + if not isinstance(session_id, str) or not session_id: + raise ValueError + subprocess.run( + [ + "herdr", "pane", "report-agent-session", os.environ["HERDR_PANE_ID"], + "--source", "herdr:qodercli", "--agent", "qodercli", + "--agent-session-id", session_id, "--seq", str(time.time_ns()), + ], + stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + timeout=1, + check=False, + ) except Exception: pass -PY +' 2>/dev/null || true diff --git a/src/integration/tests.rs b/src/integration/tests.rs index e2cde978..d3e8d6c2 100644 --- a/src/integration/tests.rs +++ b/src/integration/tests.rs @@ -2724,12 +2724,12 @@ fn bundled_integration_assets_report_session_refs() { assert!(HERMES_PLUGIN_INIT_ASSET.contains("on_session_end")); assert!(!HERMES_PLUGIN_INIT_ASSET.contains("on_session_finalize")); assert!(!HERMES_PLUGIN_INIT_ASSET.contains("pane.release_agent")); - assert!(QODERCLI_HOOK_ASSET.contains("HERDR_HOOK_INPUT_FILE")); - assert!(QODERCLI_HOOK_ASSET.contains("agent_session_id")); - assert!(QODERCLI_HOOK_ASSET.contains("pane.report_agent_session")); - assert!(!QODERCLI_HOOK_ASSET.contains("\"state\": action")); - assert!(!QODERCLI_HOOK_ASSET.contains("pane.release_agent")); - assert!(!QODERCLI_HOOK_ASSET.contains("QODER_HOOK_EVENT")); + assert!(QODERCLI_HOOK_ASSET.contains("HERDR_PANE_ID")); + assert!(QODERCLI_HOOK_ASSET.contains("session_id")); + assert!(QODERCLI_HOOK_ASSET.contains("report-agent-session")); + assert!(QODERCLI_HOOK_ASSET.contains("--agent-session-id")); + assert!(!QODERCLI_HOOK_ASSET.contains("report-agent\"")); + assert!(!QODERCLI_HOOK_ASSET.contains("release-agent")); assert!(CURSOR_HOOK_ASSET.contains("HERDR_INTEGRATION_ID=cursor")); assert!(CURSOR_HOOK_ASSET.contains("conversation_id")); assert!(CURSOR_HOOK_ASSET.contains("conversationId")); |
