-
Notifications
You must be signed in to change notification settings - Fork 517
fix: stale agent hook declarations #2657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
janburzinski
wants to merge
5
commits into
main
Choose a base branch
from
emdash/hooks-update-npvlz
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+231
−46
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b9e30f0
feat(hooks): add error hook support
janburzinski 8e5cba8
feat(hooks): expand provider event coverage
janburzinski 2e59164
fix(plugins): tighten lifecycle hook handling
janburzinski 2a0545a
refactor(agents): drop legacy hook markers
janburzinski e7d3bd8
fix(hooks): handle tool-use events
janburzinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| export const HOOK_EVENTS = [ | ||
| 'notification', | ||
| 'stop', | ||
| 'error', | ||
| 'session', | ||
| 'start', | ||
| 'tool-use', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/core/src/agents/plugins/helpers/parse-hook-event.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { defaultHookEventParser } from './parse-hook-event'; | ||
|
|
||
| describe('defaultHookEventParser', () => { | ||
| it('maps tool-use events to working status events', () => { | ||
| expect(defaultHookEventParser('tool-use', { message: 'ran shell' })).toEqual({ | ||
| kind: 'status', | ||
| type: 'start', | ||
| lastAssistantMessage: undefined, | ||
| title: undefined, | ||
| message: 'ran shell', | ||
| }); | ||
| }); | ||
|
|
||
| it('maps tool-use-failure events to error status events', () => { | ||
| expect(defaultHookEventParser('tool-use-failure', { title: 'Tool failed' })).toEqual({ | ||
| kind: 'status', | ||
| type: 'error', | ||
| lastAssistantMessage: undefined, | ||
| title: 'Tool failed', | ||
| message: undefined, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { buildClaudeHookConfig } from './hooks'; | ||
|
|
||
| describe('buildClaudeHookConfig', () => { | ||
| it('uses explicit notification_type before message heuristics', () => { | ||
| const hooks = buildClaudeHookConfig(); | ||
|
|
||
| expect( | ||
| hooks.parseHookEvent('notification', { notification_type: 'permission_prompt' }) | ||
| ).toEqual({ | ||
| kind: 'status', | ||
| type: 'notification', | ||
| notificationType: 'permission_prompt', | ||
| lastAssistantMessage: undefined, | ||
| title: undefined, | ||
| message: undefined, | ||
| }); | ||
| }); | ||
|
|
||
| it('classifies Claude notification messages when no notification_type is present', () => { | ||
| const hooks = buildClaudeHookConfig(); | ||
|
|
||
| expect(hooks.parseHookEvent('notification', { message: 'Claude needs approval' })).toEqual({ | ||
| kind: 'status', | ||
| type: 'notification', | ||
| notificationType: 'permission_prompt', | ||
| message: 'Claude needs approval', | ||
| title: undefined, | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type { PluginFs } from '@emdash/core/agents/plugins'; | ||
| import { EMDASH_MARKER } from '@emdash/core/agents/plugins/helpers'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { COPILOT_HOOKS_PATH, buildCopilotHookConfig } from './hooks'; | ||
|
|
||
| function createMemoryFs(initial: Record<string, string> = {}): PluginFs { | ||
| const files = new Map(Object.entries(initial)); | ||
|
|
||
| return { | ||
| async read(path) { | ||
| return files.get(path) ?? null; | ||
| }, | ||
| async write(path, content) { | ||
| files.set(path, content); | ||
| }, | ||
| async delete(path) { | ||
| files.delete(path); | ||
| }, | ||
| async exists(path) { | ||
| return files.has(path); | ||
| }, | ||
| async list(path) { | ||
| return [...files.keys()].filter((file) => file.startsWith(path)); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| function copilotConfigWithHooks(hookKeys: string[]): string { | ||
| return JSON.stringify({ | ||
| hooks: Object.fromEntries( | ||
| hookKeys.map((hookKey) => [ | ||
| hookKey, | ||
| [ | ||
| { | ||
| type: 'command', | ||
| command: 'curl http://127.0.0.1:$EMDASH_HOOK_PORT/hook', | ||
| }, | ||
| ], | ||
| ]) | ||
| ), | ||
| }); | ||
| } | ||
|
|
||
| describe('buildCopilotHookConfig', () => { | ||
| it('does not treat partial managed hook installs as installed', async () => { | ||
| const fs = createMemoryFs({ | ||
| [COPILOT_HOOKS_PATH]: copilotConfigWithHooks([ | ||
| 'agentStop', | ||
| 'sessionStart', | ||
| 'permissionRequest', | ||
| ]), | ||
| }); | ||
| const hooks = buildCopilotHookConfig(); | ||
|
|
||
| await expect(hooks.getHooksInstalled(fs)).resolves.toBe(false); | ||
| await expect(hooks.readHooks(fs)).resolves.toEqual([]); | ||
| }); | ||
|
|
||
| it('treats a complete managed hook install as installed', async () => { | ||
| const fs = createMemoryFs({ | ||
| [COPILOT_HOOKS_PATH]: copilotConfigWithHooks([ | ||
| 'agentStop', | ||
| 'sessionEnd', | ||
| 'sessionStart', | ||
| 'userPromptSubmitted', | ||
| 'errorOccurred', | ||
| 'notification', | ||
| 'permissionRequest', | ||
| ]), | ||
| }); | ||
| const hooks = buildCopilotHookConfig(); | ||
|
|
||
| await expect(hooks.getHooksInstalled(fs)).resolves.toBe(true); | ||
| await expect(hooks.readHooks(fs)).resolves.toEqual([ | ||
| { event: 'emdash', command: EMDASH_MARKER }, | ||
| ]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to get rid of this after the plugin refactor now, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid!! was just a little unsure. removed it :D