Skip to content
This repository was archived by the owner on Feb 21, 2026. It is now read-only.

refactor: extract shared cloud IPC message handler, fix Discord TS error - #143

Merged
Peyton-Spencer merged 1 commit into
mainfrom
simplify/nanoclaw-20260219
Feb 19, 2026
Merged

refactor: extract shared cloud IPC message handler, fix Discord TS error#143
Peyton-Spencer merged 1 commit into
mainfrom
simplify/nanoclaw-20260219

Conversation

@Peyton-Spencer

@Peyton-Spencer Peyton-Spencer commented Feb 19, 2026

Copy link
Copy Markdown

Summary

Two code quality improvements found during routine simplification analysis (2026-02-19):

1. Extract makeCloudMessageHandler (ipc.ts)

The processMessage callback passed to both startSpritesIpcPoller and startDaytonaIpcPoller was copy-pasted verbatim — 16 lines each, differing only in the log label string.

Before: Two identical 16-line blocks in startIpcWatcher(), one for each backend poller.

After: Single makeCloudMessageHandler(deps) factory function that returns the shared handler closure. Each poller passes its own label: processMessage: (s, d) => cloudMessageHandler(s, d, 'Sprites')

Benefit: Any future routing logic change only needs a single update. Also shared cloudTaskHandler constant removes the identical 1-line processTask blocks.

2. Fix mentionsOtherUsersOnly type error (discord.ts)

botId is typed as string | undefined, but Map.has() requires string. Added botId \!= null guard at the start of the expression so TypeScript can narrow the type correctly.

No behavior change — the outer if (\!isDM && botId && ...) already prevented execution when botId was falsy. This eliminates the pre-existing TS2345 compiler error.

Test plan

  • bun run typecheck passes (no new errors in modified files)
  • Sprites-backed groups still route IPC messages correctly
  • Daytona-backed groups still route IPC messages correctly
  • Discord bot correctly ignores messages mentioning other users (not the bot)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Reorganized internal communication logic to improve code maintainability and reduce duplication.
  • Style

    • Applied consistent formatting and documentation improvements throughout the codebase.
    • Enhanced type-safety with additional null checks.

@coderabbitai

coderabbitai Bot commented Feb 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

These changes consist of formatting refinements and architectural refactoring across the Discord channel implementation and IPC message handling system. The Discord module receives style updates with a minor type-safety guard addition, while the IPC module introduces centralized cloud message handlers to replace existing inline handler implementations.

Changes

Cohort / File(s) Summary
Discord Channel Formatting
src/channels/discord.ts
Formatting adjustments including line breaks, reflowed parameters, trailing commas, and multiline object/array styling. Adds an explicit botId != null type-safety guard for mentions-for-visibility computation. No functional or API signature changes.
IPC Handler Centralization
src/ipc.ts
Introduces shared makeCloudMessageHandler and wrapper functions (cloudMessageHandler, cloudTaskHandler) to centralize cloud-backed group communication logic. Replaces inline handlers passed to Sprites and Daytona pollers with the new centralized handlers. Import grouping refactored with minor formatting adjustments.
Manifest Updates
package.json
Configuration updates related to Discord and IPC module changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • omarzanji

Poem

🐰 A hop through the code, with formatting care,
Mentions and handlers now cleaner to wear,
Cloud logic consolidated, no behavior changed,
Just tidier lines and a refactor well-arranged!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: extracting a shared cloud IPC message handler and fixing a Discord TypeScript error.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch simplify/nanoclaw-20260219

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

… error

Two improvements in this PR:

1. **Extract `makeCloudMessageHandler` in `ipc.ts`** — the `processMessage`
   callback passed to both `startSpritesIpcPoller` and `startDaytonaIpcPoller`
   was copy-pasted verbatim (16 lines each), differing only in the log label.
   Extracted into a shared factory `makeCloudMessageHandler(deps)` that accepts
   a `backendLabel` string for the logger. Also extracts the `processTask`
   handler into a shared `cloudTaskHandler` constant.
   Net change: removes ~12 lines of duplication, single place to update routing
   logic when adding future cloud backends.

2. **Fix `mentionsOtherUsersOnly` type error in `discord.ts`** — `botId` is
   `string | undefined`, but `Map.has()` requires `string`. Added `botId != null`
   guard at the start of the expression so TypeScript can narrow the type.
   No behavior change (outer `if (!isDM && botId && ...)` already guarded it),
   but eliminates the pre-existing TS2345 error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Peyton-Spencer
Peyton-Spencer force-pushed the simplify/nanoclaw-20260219 branch from 3a36b10 to 2e6df7f Compare February 19, 2026 15:14
@Peyton-Spencer

Copy link
Copy Markdown
Author

Rebased onto main to resolve conflict with the security fix in PR #142 (requestId path traversal sanitization in ipc.ts). The security fix in HEAD was preserved — the PR #143 reformatting of that block was dropped in favor of maintaining the sanitization logic. All other changes are identical.

@Peyton-Spencer
Peyton-Spencer merged commit e8110e3 into main Feb 19, 2026
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant