Repository navigation
Conversation
🦋 Changeset detectedLatest commit: b0a0f89 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
haiyu614
force-pushed
the
fix/session-start-hook-output
branch
from
October 6, 2026 16:59
57916c6 to
b0a0f89
Compare
haiyu614
marked this pull request as ready for review
October 6, 2026 17:11
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Fixes #2873
Problem
SessionStarthook commands execute, but the session-scope external hooks service discards the returnedHookResult[]—triggerSessionStart()never publishes ahook.resultevent and never appends the hook stdout to the conversation context. Users see nothing despite the documented hook contract ("stdout content (if any) may be appended to context"), and the model never receives SessionStart output either.Verified on 2.1.1 (Windows): a
SessionStarthook withecho hello-from-sessionstart-hookwrites its side effects but the main agent'swire.jsonlcontains nohook.resultevent and no context entry for the stdout.Fix
After the session-scope trigger completes,
SessionExternalHooksServicenow surfaces successful hook results through the main agent:action !== 'block'(reusing the same extraction rules asUserPromptSubmit: skip timed out / errored / non-zero exits, prefermessage, fall back tostdout),origin: { kind: 'hook_result', event: 'SessionStart' }and the same<hook_result hook_event="...">wrapper used by other hook results, so the model sees the output and session replay renders it as a transcript entry,hook.resultagent event per message, so attached clients (TUI / print / SDK) render it exactly likeUserPromptSubmithook results.If the main agent does not exist yet (session created without a main agent binding), the results are dropped as before — no behavior change in that edge case.
SessionEnd/ heartbeat / subagent triggers remain fire-and-forget.hookResultMessage()(previously the privateuserPromptHookMessage) is exported frominternal/userPrompt.tsso both scopes share the same extraction rules.Tests
surfaces SessionStart hook stdout on the main agent as a hook result and context entry— fires theSessionStartlifecycle event with a real runner, asserts the context append (role/origin/wrapped text) and the dispatchedhook.resultevent, and assertsSessionEndoutput is still not surfaced.IAgentLifecycleServicestub (the service now injects it).pnpm --filter @moonshot-ai/agent-core-v2 test: no new failures vs. clean baseline on Windows (the pre-existing failures are identical before/after; new test passes).kimi -pwith aSessionStarthook now records the<hook_result hook_event="SessionStart">context message in the main agent'swire.jsonl.