aboutsummaryrefslogtreecommitdiff
path: root/src/integration/assets/codex
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-21 02:38:14 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-21 02:42:39 +0300
commit92a10fc044d42b216317696a4e8e6f70d7cc7a7d (patch)
treea45fb881c85e66ff8641fa84bb2a1bf0ead584ed /src/integration/assets/codex
parent73b137a4ae75cb1465e8d4ddfc293ff7366d8133 (diff)
fix: protect root agent restore sessions
refs #712
Diffstat (limited to 'src/integration/assets/codex')
-rw-r--r--src/integration/assets/codex/herdr-agent-state.ps122
-rw-r--r--src/integration/assets/codex/herdr-agent-state.sh26
2 files changed, 38 insertions, 10 deletions
diff --git a/src/integration/assets/codex/herdr-agent-state.ps1 b/src/integration/assets/codex/herdr-agent-state.ps1
index e56948f5..d837b78a 100644
--- a/src/integration/assets/codex/herdr-agent-state.ps1
+++ b/src/integration/assets/codex/herdr-agent-state.ps1
@@ -2,7 +2,7 @@
# managed by herdr; reinstalling or updating the integration overwrites this file.
# add custom hooks beside this file instead of editing it.
# HERDR_INTEGRATION_ID=codex
-# HERDR_INTEGRATION_VERSION=5
+# HERDR_INTEGRATION_VERSION=6
param([string]$Action = "")
@@ -17,11 +17,29 @@ try {
exit 0
}
+if ($payload.hook_event_name -and $payload.hook_event_name -ne "SessionStart") { exit 0 }
+
$sessionId = $payload.session_id
if ([string]::IsNullOrWhiteSpace($sessionId)) { exit 0 }
$seq = [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()
try {
- & herdr pane report-agent-session $env:HERDR_PANE_ID --source herdr:codex --agent codex --seq $seq --agent-session-id $sessionId 2>$null | Out-Null
+ $args = @(
+ "pane",
+ "report-agent-session",
+ $env:HERDR_PANE_ID,
+ "--source",
+ "herdr:codex",
+ "--agent",
+ "codex",
+ "--seq",
+ "$seq",
+ "--agent-session-id",
+ "$sessionId"
+ )
+ if ($payload.hook_event_name -eq "SessionStart" -and $payload.source -is [string] -and -not [string]::IsNullOrWhiteSpace($payload.source)) {
+ $args += @("--session-start-source", "$($payload.source)")
+ }
+ & herdr @args 2>$null | Out-Null
} catch {
}
diff --git a/src/integration/assets/codex/herdr-agent-state.sh b/src/integration/assets/codex/herdr-agent-state.sh
index 385c9a98..b3b08a78 100644
--- a/src/integration/assets/codex/herdr-agent-state.sh
+++ b/src/integration/assets/codex/herdr-agent-state.sh
@@ -3,7 +3,7 @@
# managed by herdr; reinstalling or updating the integration overwrites this file.
# add custom hooks beside this file instead of editing it.
# HERDR_INTEGRATION_ID=codex
-# HERDR_INTEGRATION_VERSION=5
+# HERDR_INTEGRATION_VERSION=6
set -eu
@@ -48,21 +48,31 @@ if hook_input_file:
except Exception:
hook_input = {}
+hook_event_name = str(hook_input.get("hook_event_name") or "")
+if hook_event_name and hook_event_name != "SessionStart":
+ 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
+session_start_source = hook_input.get("source") if hook_event_name == "SessionStart" else None
+if not isinstance(session_start_source, str) or not session_start_source:
+ session_start_source = None
if agent_session_id:
+ params = {
+ "pane_id": pane_id,
+ "source": source,
+ "agent": "codex",
+ "seq": report_seq,
+ "agent_session_id": agent_session_id,
+ }
+ if session_start_source:
+ params["session_start_source"] = session_start_source
request = {
"id": request_id,
"method": "pane.report_agent_session",
- "params": {
- "pane_id": pane_id,
- "source": source,
- "agent": "codex",
- "seq": report_seq,
- "agent_session_id": agent_session_id,
- },
+ "params": params,
}
else:
raise SystemExit(0)