A mod is now a plugin built with defineMod() around its register(on,
options); the bridge is the ClaudeCodeMods service (ctx.claudeCodeMods)
that keeps the loaded mods and raises their events. The plugin.json /
hooks.json loader, pluginDirs, and dynamic imports are gone.
prompt.submit context becomes text blocks appended to the human's own
prompt message and $.prompt.submit queues a user-sourced message, so the
bridge adds no message source kind: the persistence record and the
regenerated schema are removed and the artifacts match master again.
Engine correctness from the review round: next() is memoized and every
started run beneath is awaited before a hook's answer settles; a rewritten
tool argument skips the hook with a report pointing at the pre-tool input
rewrite proposal; timers belong to the session whose event started them;
$.tool.call injects a tool's deferred contexts; $.clock.sleep honors the
event signal; a built-in tool answered with { result } is validated against
its output schema before it becomes an error-shaped result; hooks on events
this host never raises are reported at load.
Examples: the three mods from the Claude Code blog post under examples/,
Token Weather and its test unchanged, Blast Radius and Replay Theater
completed from the published fragments, run by their own tests through a
claude-code/testing alias over the new test kit ($.ui.mount/find/press).
59 lines
2.9 KiB
TypeScript
59 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { describeMatcher, eventMatches, isEventPattern, KNOWN_EVENTS, matcherMatches } from '../src/matcher.ts'
|
|
import { createToolNameAliases, DEFAULT_TOOL_ALIASES } from '../src/tool-names.ts'
|
|
|
|
describe('event patterns and matchers', () => {
|
|
it('knows Claude Code\'s event names and globs', () => {
|
|
expect(KNOWN_EVENTS.has('tool.call')).toBe(true)
|
|
expect(isEventPattern('tool.call')).toBe(true)
|
|
expect(isEventPattern('tool.calls')).toBe(false)
|
|
expect(isEventPattern('*')).toBe(true)
|
|
expect(isEventPattern('classic.*')).toBe(false)
|
|
expect(isEventPattern('telemetry.*')).toBe(true)
|
|
expect(isEventPattern('.*')).toBe(false)
|
|
})
|
|
|
|
it('matches exact names, namespace globs, and the star without telemetry', () => {
|
|
expect(eventMatches('tool.call', 'tool.call')).toBe(true)
|
|
expect(eventMatches('tool.call', 'tool.check')).toBe(false)
|
|
expect(eventMatches('tool.*', 'tool.check')).toBe(true)
|
|
expect(eventMatches('tool.*', 'turn.start')).toBe(false)
|
|
expect(eventMatches('*', 'turn.start')).toBe(true)
|
|
expect(eventMatches('*', 'telemetry.log')).toBe(false)
|
|
expect(eventMatches('telemetry.*', 'telemetry.log')).toBe(true)
|
|
})
|
|
|
|
it('compares scalars by equality, arrays by membership, and regular expressions by test', () => {
|
|
const input = { tool: 'mcp__github__issues', count: 3, flag: true }
|
|
expect(matcherMatches({ tool: 'mcp__github__issues' }, input)).toBe(true)
|
|
expect(matcherMatches({ tool: 'Bash' }, input)).toBe(false)
|
|
expect(matcherMatches({ tool: ['Edit', 'mcp__github__issues'] }, input)).toBe(true)
|
|
expect(matcherMatches({ tool: /^mcp__github__/ }, input)).toBe(true)
|
|
expect(matcherMatches({ count: /^3$/ }, input)).toBe(true)
|
|
expect(matcherMatches({ flag: /true/ }, input)).toBe(false)
|
|
expect(matcherMatches({ tool: 'x', count: 3 }, input)).toBe(false)
|
|
expect(matcherMatches({ tool: 'x' }, 'not an object')).toBe(false)
|
|
expect(matcherMatches({}, input)).toBe(true)
|
|
})
|
|
|
|
it('describes matchers the way claude plugin validate prints them', () => {
|
|
expect(describeMatcher(undefined)).toBe('')
|
|
expect(describeMatcher({ component: 'Spinner' })).toBe('{component=Spinner}')
|
|
expect(describeMatcher({ tool: ['Edit', 'Write'], id: /^T-/ })).toBe('{tool=Edit|Write,id=/^T-/}')
|
|
})
|
|
})
|
|
|
|
describe('tool-name aliases', () => {
|
|
it('translates both ways, falling back to the name itself, and takes overrides', () => {
|
|
const aliases = createToolNameAliases({ Bash: 'pwsh', Custom: 'my_tool' })
|
|
expect(DEFAULT_TOOL_ALIASES.Bash).toBe('bash')
|
|
expect(aliases.toHarness('Bash')).toBe('pwsh')
|
|
expect(aliases.toMod('pwsh')).toBe('Bash')
|
|
expect(aliases.toMod('bash')).toBe('bash')
|
|
expect(aliases.toHarness('Custom')).toBe('my_tool')
|
|
expect(aliases.toHarness('Read')).toBe('read')
|
|
expect(aliases.toMod('read')).toBe('Read')
|
|
expect(aliases.toMod('unknown_tool')).toBe('unknown_tool')
|
|
})
|
|
})
|