Skip to content

feat(cosh): surface UserPromptSubmit and PostToolUse hook reason in UI#545

Open
kongche-jbw wants to merge 1 commit into
alibaba:mainfrom
kongche-jbw:feat/cosh/surface-hook-reason
Open

feat(cosh): surface UserPromptSubmit and PostToolUse hook reason in UI#545
kongche-jbw wants to merge 1 commit into
alibaba:mainfrom
kongche-jbw:feat/cosh/surface-hook-reason

Conversation

@kongche-jbw
Copy link
Copy Markdown
Collaborator

Description

Follow-up to #421. UserPromptSubmit and PostToolUse hooks could return
a reason (or systemMessage) on non-blocking decisions, but the
terminal UI never showed it — leaving informational warnings invisible.

This PR mirrors the #421 PreToolUse path:

  • firePostToolUseEvent() now carries aggregator notifications[] on
    the returned output, and coreToolScheduler emits each one via
    outputUpdateHandler(callId, {hookName, hookMessage, decision, mergedDecision})
    before applying the merged block / ask / allow outcome.
  • UserPromptSubmit non-blocking allow / approve now yields a
    HookSystemMessage event using systemMessage ?? reason. Block
    (Error event) and ask (UserPromptConfirmation) paths are unchanged
    because they already render the message.
  • additionalContext LLM injection is unchanged — the new path is
    UI-only.

Related Issue

closes #535

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional change)
  • Performance improvement
  • CI/CD or build changes

Scope

  • cosh (copilot-shell)
  • sec-core (agent-sec-core)
  • skill (os-skills)
  • sight (agentsight)
  • tokenless (tokenless)
  • Multiple / Project-wide

Checklist

  • I have read the Contributing Guide
  • My code follows the project's code style
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the documentation accordingly
  • For cosh: Lint passes, type check passes, and tests pass
  • For sec-core (Rust): cargo clippy -- -D warnings and cargo fmt --check pass
  • For sec-core (Python): Ruff format and pytest pass
  • For skill: Skill directory structure is valid and shell scripts pass syntax check
  • For sight: cargo clippy -- -D warnings and cargo fmt --check pass
  • For tokenless: cargo clippy -- -D warnings and cargo fmt --check pass
  • Lock files are up to date (`package-lock.json` / `Cargo.lock`)

Testing

```
npx vitest run packages/core/src/core/client.test.ts
packages/core/src/core/coreToolScheduler.test.ts
packages/core/src/hooks/hookSystem.test.ts
→ 3 files passed, 122/122 tests passed
```

Type check on the three changed test files is clean (pre-existing
third-party `@types` errors for `simple-git` / `google-auth-library` /
`@opentelemetry/exporter-metrics-otlp-http` are unrelated to this PR).

Manual verification scenarios:

  • `UserPromptSubmit` returning `{decision: "allow", reason: "..."}` —
    reason now renders in the terminal as a `HookSystemMessage`.
  • `PostToolUse` returning `{decision: "allow", reason: "..."}` —
    reason renders as a per-hook notification on the existing tool
    message UI; tool still completes successfully.
  • `PostToolUse` returning `{decision: "block", reason: "..."}` —
    notification renders with `mergedDecision: "block"` and the
    response sent to the LLM is replaced with the reason.

Additional Notes

The non-interactive JSON output adapter
(`BaseJsonOutputAdapter.processEvent` handling of `HookSystemMessage`)
is intentionally deferred; #535 scopes to the terminal UI.

    - carry PostToolUse notifications through firePostToolUseEvent output
    - emit per-hook notifications via outputUpdateHandler in scheduler
    - yield HookSystemMessage on UserPromptSubmit non-blocking allow
    - add tests for hookSystem, coreToolScheduler and client
@kongche-jbw kongche-jbw requested a review from samchu-zsl as a code owner May 15, 2026 10:30
@kongche-jbw kongche-jbw self-assigned this May 15, 2026
@github-actions github-actions Bot added the component:cosh src/copilot-shell/ label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component:cosh src/copilot-shell/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cosh] enhancement: surface reason for UserPromptSubmit and PostToolUse hooks

1 participant