Claude-skill-registry add-nodebridge-handler
Use this skill when adding a new NodeBridge handler to src/nodeBridge.ts, including updating types in src/nodeBridge.types.ts and optionally testing with scripts/test-nodebridge.ts
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/add-nodebridge-handler" ~/.claude/skills/majiayu000-claude-skill-registry-add-nodebridge-handler && rm -rf "$T"
manifest:
skills/data/add-nodebridge-handler/SKILL.mdsource content
Add NodeBridge Handler
Overview
This skill guides the process of adding a new message handler to the NodeBridge system, which enables communication between the UI layer and the Node.js backend.
Steps
1. Add Handler Implementation in src/nodeBridge.ts
src/nodeBridge.tsLocate the
registerHandlers() method in the NodeHandlerRegistry class and add your handler:
this.messageBus.registerHandler('category.handlerName', async (data) => { const { cwd, ...otherParams } = data; const context = await this.getContext(cwd); // Implementation logic here return { success: true, data: { // Return data }, }; });
Handler Naming Convention:
- Use dot notation:
(e.g.,category.action
,git.status
,session.send
)utils.getPaths - Categories:
,config
,git
,mcp
,models
,outputStyles
,project
,projects
,providers
,session
,sessions
,slashCommand
,statusutils
Common Patterns:
- Always get context via
await this.getContext(cwd) - Return
for success{ success: true, data: {...} } - Return
for errors{ success: false, error: 'message' } - Wrap in try/catch for error handling
2. Add Type Definitions in src/nodeBridge.types.ts
src/nodeBridge.types.tsAdd input and output types near the relevant section:
// ============================================================================ // Category Handlers // ============================================================================ type CategoryHandlerNameInput = { cwd: string; // other required params optionalParam?: string; }; type CategoryHandlerNameOutput = { success: boolean; error?: string; data?: { // return data shape }; };
Then add to the
HandlerMap type:
export type HandlerMap = { // ... existing handlers // Category handlers 'category.handlerName': { input: CategoryHandlerNameInput; output: CategoryHandlerNameOutput; }; };
3. (Optional) Add to Test Script
Update
scripts/test-nodebridge.ts HANDLERS object if the handler should be easily testable:
const HANDLERS: Record<string, string> = { // ... existing handlers 'category.handlerName': 'Description of what this handler does', };
4. Test the Handler
Run the test script:
bun scripts/test-nodebridge.ts category.handlerName --cwd=/path/to/dir --param=value
Or with JSON data:
bun scripts/test-nodebridge.ts category.handlerName --data='{"cwd":"/path","param":"value"}'
Example: Complete Handler Addition
nodeBridge.ts
this.messageBus.registerHandler('utils.example', async (data) => { const { cwd, name } = data; try { const context = await this.getContext(cwd); // Do something with context and params const result = await someOperation(name); return { success: true, data: { result, }, }; } catch (error: any) { return { success: false, error: error.message || 'Failed to execute example', }; } });
nodeBridge.types.ts
type UtilsExampleInput = { cwd: string; name: string; }; type UtilsExampleOutput = { success: boolean; error?: string; data?: { result: string; }; }; // In HandlerMap: 'utils.example': { input: UtilsExampleInput; output: UtilsExampleOutput; };
Notes
- Handlers are async functions that receive
parameterdata - Use
to get the Context instance (cached per cwd)this.getContext(cwd) - Context provides access to:
,config
,paths
,mcpManager
,productName
, etc.version - For long-running operations, consider using abort controllers (see
pattern)git.clone - For operations that emit progress, use
(seethis.messageBus.emitEvent()
pattern)git.commit.output