Skip to content

Map more Claude hooks to completed#16

Merged
trydis merged 1 commit intomainfrom
extend-claude-hooks-handling
Mar 10, 2026
Merged

Map more Claude hooks to completed#16
trydis merged 1 commit intomainfrom
extend-claude-hooks-handling

Conversation

@trydis
Copy link
Owner

@trydis trydis commented Mar 10, 2026

Summary by CodeRabbit

  • New Features

    • Runtime agent now supports notification hooks for handling permission requests and system notification events, enhancing surface interaction management.
  • Tests

    • Expanded test coverage to verify notification hook mappings and event handling.

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

📝 Walkthrough

Walkthrough

AgentRuntimeBridge.swift's Claude wrapper settings payload is expanded to inject managed activity hooks for surface interactions. Three new sections are added: PermissionRequest with a universal matcher, and Notification with two matchers (permission_prompt and elicitation_dialog), each triggering hooks to mark completion. Tests are updated to verify these new hook sections.

Changes

Cohort / File(s) Summary
Claude Wrapper Hook Configuration
Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift
Expanded Claude wrapper settings payload with three new hook sections: PermissionRequest (with universal matcher) and Notification (with permission_prompt and elicitation_dialog matchers), replacing previous top-level start/stop hooks with managed activity hooks.
Runtime Bridge Tests
Tests/ShellraiserTests/AgentRuntimeBridgeTests.swift
Renamed test method from testPrepareRuntimeSupportWritesClaudeWrapperWithoutSubagentStopHook to testPrepareRuntimeSupportWritesClaudeWrapperWithMappedNotificationHooks and added assertions to verify PermissionRequest, Notification, and matcher entries in wrapper content.

Possibly related PRs

  • Fix Claude completion notifications #9: Modifies Claude wrapper hooks in AgentRuntimeBridge.swift; this PR builds upon those changes by replacing top-level start/stop hooks with managed activity hooks and adding PermissionRequest/Notification hook sections.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Map more Claude hooks to completed' accurately describes the main change: extending Claude wrapper settings to include new notification and permission request hooks that call the completion helper.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch extend-claude-hooks-handling

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift (1)

256-285: Factor the repeated completed hook payload into one builder.

The same command stanza is now duplicated across Stop, PermissionRequest, and both Notification entries. Centralizing that payload would make future hook changes one-shot instead of editing multiple embedded JSON fragments.

As per coding guidelines, "Prefer small, composable methods and keep methods focused and readable".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift` around
lines 256 - 285, The JSON hook command payload for the completed hook is
duplicated across "Stop", "PermissionRequest", and both "Notification" entries;
create a small helper (e.g., buildCompletedHook() or makeCompletedHookPayload())
in AgentRuntimeBridge that returns the consolidated hook structure (the command
string using "$SHELLRAISER_HELPER_PATH" and "$SHELLRAISER_SURFACE_ID"), then
replace the duplicated embedded JSON fragments in the Stop, PermissionRequest,
and Notification builders with a call to that helper so future changes are made
in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Tests/ShellraiserTests/AgentRuntimeBridgeTests.swift`:
- Around line 20-24: The test currently only checks wrapperContents contains
entries for "PermissionRequest", "Notification", and matchers but not that those
hooks map to the completed lifecycle; update the assertions in
AgentRuntimeBridgeTests (e.g., the expectations referencing wrapperContents) to
also assert the specific mapping value is "\"state\": \"completed\"" (or the
exact completed mapping used by the product) for the new hooks—ensure you check
that the PermissionRequest, Notification, and matcher entries include the
completed state rather than started or another command so a regression will fail
if they do not map to completed.

---

Nitpick comments:
In `@Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift`:
- Around line 256-285: The JSON hook command payload for the completed hook is
duplicated across "Stop", "PermissionRequest", and both "Notification" entries;
create a small helper (e.g., buildCompletedHook() or makeCompletedHookPayload())
in AgentRuntimeBridge that returns the consolidated hook structure (the command
string using "$SHELLRAISER_HELPER_PATH" and "$SHELLRAISER_SURFACE_ID"), then
replace the duplicated embedded JSON fragments in the Stop, PermissionRequest,
and Notification builders with a call to that helper so future changes are made
in one place.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1307b620-b340-4c3d-9180-dae6de318952

📥 Commits

Reviewing files that changed from the base of the PR and between f6bb939 and 552fdc6.

📒 Files selected for processing (2)
  • Sources/Shellraiser/Infrastructure/Agents/AgentRuntimeBridge.swift
  • Tests/ShellraiserTests/AgentRuntimeBridgeTests.swift

Comment on lines +20 to +24
XCTAssertTrue(wrapperContents.contains("\"PermissionRequest\""))
XCTAssertTrue(wrapperContents.contains("\"matcher\": \"*\""))
XCTAssertTrue(wrapperContents.contains("\"Notification\""))
XCTAssertTrue(wrapperContents.contains("\"matcher\": \"permission_prompt\""))
XCTAssertTrue(wrapperContents.contains("\"matcher\": \"elicitation_dialog\""))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Assert the new hooks still map to completed.

These checks only prove the sections and matchers exist. A regression where one of the new hooks emitted started or pointed at a different command would still pass, which misses the PR’s actual behavior change.

🔍 Tighten the assertion
         XCTAssertTrue(wrapperContents.contains("\"Notification\""))
         XCTAssertTrue(wrapperContents.contains("\"matcher\": \"permission_prompt\""))
         XCTAssertTrue(wrapperContents.contains("\"matcher\": \"elicitation_dialog\""))
+        XCTAssertEqual(
+            wrapperContents.components(
+                separatedBy: #"claudeCode \"$SHELLRAISER_SURFACE_ID\" completed"#
+            ).count - 1,
+            4
+        )
         XCTAssertFalse(wrapperContents.contains("\"SubagentStop\""))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Tests/ShellraiserTests/AgentRuntimeBridgeTests.swift` around lines 20 - 24,
The test currently only checks wrapperContents contains entries for
"PermissionRequest", "Notification", and matchers but not that those hooks map
to the completed lifecycle; update the assertions in AgentRuntimeBridgeTests
(e.g., the expectations referencing wrapperContents) to also assert the specific
mapping value is "\"state\": \"completed\"" (or the exact completed mapping used
by the product) for the new hooks—ensure you check that the PermissionRequest,
Notification, and matcher entries include the completed state rather than
started or another command so a regression will fail if they do not map to
completed.

@trydis trydis merged commit 8536419 into main Mar 10, 2026
2 checks passed
@trydis trydis deleted the extend-claude-hooks-handling branch March 10, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant