1
>
/*---------------------------------------------------------------------------------------------
hookTypes.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as nls from '../../../../../nls.js';
7
>
import { Target } from './promptTypes.js';
8
>
9
>
/**
10
>
* Enum of hook types across all targets. For the set of supported hooks per target, see HOOKS_BY_TARGET.
11
>
*/
12
>
export enum HookType {
13
>
SessionStart = 'SessionStart',
14
>
SessionEnd = 'SessionEnd',
15
>
UserPromptSubmit = 'UserPromptSubmit',
16
>
PreToolUse = 'PreToolUse',
17
>
PostToolUse = 'PostToolUse',
18
>
PreCompact = 'PreCompact',
19
>
SubagentStart = 'SubagentStart',
20
>
SubagentStop = 'SubagentStop',
21
>
Stop = 'Stop',
22
>
ErrorOccurred = 'ErrorOccurred',
23
>
}
24
>
25
>
/**
26
>
* String literal type derived from HookType enum values.
27
>
*/
28
>
export type HookTypeValue = `${HookType}`;
29
>
30
>
export const HOOKS_BY_TARGET: Record<Target, Record<string, HookType>> = {
31
>
// see https://code.visualstudio.com/docs/copilot/customization/hooks#_hook-lifecycle-events
32
>
[Target.VSCode]: {
33
>
'SessionStart': HookType.SessionStart,
34
>
'UserPromptSubmit': HookType.UserPromptSubmit,
35
>
'PreToolUse': HookType.PreToolUse,
36
>
'PostToolUse': HookType.PostToolUse,
37
>
'PreCompact': HookType.PreCompact,
38
>
'SubagentStart': HookType.SubagentStart,
39
>
'SubagentStop': HookType.SubagentStop,
40
>
'Stop': HookType.Stop,
41
>
},
42
>
// see https://docs.github.com/en/copilot/concepts/agents/coding-agent/about-hooks#types-of-hooks
43
>
[Target.GitHubCopilot]: {
44
>
'sessionStart': HookType.SessionStart,
45
>
'sessionEnd': HookType.SessionEnd,
46
>
'userPromptSubmitted': HookType.UserPromptSubmit,
47
>
'preToolUse': HookType.PreToolUse,
48
>
'postToolUse': HookType.PostToolUse,
49
>
'agentStop': HookType.Stop,
50
>
'subagentStop': HookType.SubagentStop,
51
>
'errorOccurred': HookType.ErrorOccurred
52
>
},
53
>
// see https://docs.anthropic.com/en/docs/claude-code/hooks
54
>
[Target.Claude]: {
55
>
'SessionStart': HookType.SessionStart,
56
>
'UserPromptSubmit': HookType.UserPromptSubmit,
57
>
'PreToolUse': HookType.PreToolUse,
58
>
'PostToolUse': HookType.PostToolUse,
59
>
'PreCompact': HookType.PreCompact,
60
>
'SubagentStart': HookType.SubagentStart,
61
>
'SubagentStop': HookType.SubagentStop,
62
>
'Stop': HookType.Stop,
63
>
},
64
>
// if no target, just list all known hook types.
65
>
[Target.Undefined]: Object.fromEntries(
66
>
Object.values(HookType).map(h => [h, h])
67
>
) as Record<string, HookType>
68
>
};
69
>
70
>
/**
71
>
* Metadata for a hook type including localized label and description.
72
>
*/
73
>
export interface IHookTypeMeta {
74
>
readonly label: string;
75
>
readonly description: string;
76
>
}
77
>
78
>
/**
79
>
* Metadata for hook types including localized labels and descriptions
80
>
*/
81
>
export const HOOK_METADATA: { [key in HookType]: IHookTypeMeta } = {
82
>
[HookType.SessionStart]: {
83
>
label: nls.localize('hookType.sessionStart.label', "Session Start"),
84
>
description: nls.localize('hookType.sessionStart.description', "Executed when a new agent session begins.")
85
>
},
86
>
[HookType.UserPromptSubmit]: {
87
>
label: nls.localize('hookType.userPromptSubmit.label', "User Prompt Submit"),
88
>
description: nls.localize('hookType.userPromptSubmit.description', "Executed when the user submits a prompt to the agent.")
89
>
},
90
>
[HookType.PreToolUse]: {
91
>
label: nls.localize('hookType.preToolUse.label', "Pre-Tool Use"),
92
>
description: nls.localize('hookType.preToolUse.description', "Executed before the agent uses any tool.")
93
>
},
94
>
[HookType.PostToolUse]: {
95
>
label: nls.localize('hookType.postToolUse.label', "Post-Tool Use"),
96
>
description: nls.localize('hookType.postToolUse.description', "Executed after a tool completes execution successfully.")
97
>
},
98
>
[HookType.PreCompact]: {
99
>
label: nls.localize('hookType.preCompact.label', "Pre-Compact"),
100
>
description: nls.localize('hookType.preCompact.description', "Executed before the agent compacts the conversation context.")
101
>
},
102
>
[HookType.SubagentStart]: {
103
>
label: nls.localize('hookType.subagentStart.label', "Subagent Start"),
104
>
description: nls.localize('hookType.subagentStart.description', "Executed when a subagent is started.")
105
>
},
106
>
[HookType.SubagentStop]: {
107
>
label: nls.localize('hookType.subagentStop.label', "Subagent Stop"),
108
>
description: nls.localize('hookType.subagentStop.description', "Executed when a subagent stops.")
109
>
},
110
>
[HookType.Stop]: {
111
>
label: nls.localize('hookType.stop.label', "Stop"),
112
>
description: nls.localize('hookType.stop.description', "Executed when the agent stops.")
113
>
},
114
>
[HookType.SessionEnd]: {
115
>
label: nls.localize('hookType.sessionEnd.label', "Session End"),
116
>
description: nls.localize('hookType.sessionEnd.description', "Executed when an agent session ends.")
117
>
},
118
>
[HookType.ErrorOccurred]: {
119
>
label: nls.localize('hookType.errorOccurred.label', "Error Occurred"),
120
>
description: nls.localize('hookType.errorOccurred.description', "Executed when an error occurs during the agent session.")
121
>
}
122
>
};