fix: enrich session_end lifecycle hooks (#59715)

Merged via squash.

Prepared head SHA: b3ef62b973
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Josh Lehman
2026-04-03 00:16:14 -07:00
committed by GitHub
parent 52d8dc5b56
commit 2b28e75822
19 changed files with 801 additions and 20 deletions

View File

@@ -2482,11 +2482,25 @@ export type PluginHookSessionStartEvent = {
};
// session_end hook
export type PluginHookSessionEndReason =
| "new"
| "reset"
| "idle"
| "daily"
| "compaction"
| "deleted"
| "unknown";
export type PluginHookSessionEndEvent = {
sessionId: string;
sessionKey?: string;
messageCount: number;
durationMs?: number;
reason?: PluginHookSessionEndReason;
sessionFile?: string;
transcriptArchived?: boolean;
nextSessionId?: string;
nextSessionKey?: string;
};
// Subagent context

View File

@@ -40,7 +40,15 @@ describe("session hook runner methods", () => {
{
name: "runSessionEnd invokes registered session_end hooks",
hookName: "session_end" as const,
event: { sessionId: "abc-123", sessionKey: "agent:main:abc", messageCount: 42 },
event: {
sessionId: "abc-123",
sessionKey: "agent:main:abc",
messageCount: 42,
reason: "daily" as const,
sessionFile: "/tmp/abc-123.jsonl.reset.2026-04-02T10-00-00.000Z",
transcriptArchived: true,
nextSessionId: "def-456",
},
},
] as const)("$name", async ({ hookName, event }) => {
await expectSessionHookCall({ hookName, event, sessionCtx });