1
>
/*---------------------------------------------------------------------------------------------
hookCompatibility.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 { URI } from '../../../../../base/common/uri.js';
7
>
import { basename, dirname } from '../../../../../base/common/path.js';
8
>
import { IHookCommand, toHookType } from './hookSchema.js';
9
>
import { parseClaudeHooks, extractHookCommandsFromItem } from './hookClaudeCompat.js';
10
>
import { resolveCopilotCliHookType } from './hookCopilotCliCompat.js';
11
>
import { HookType } from './hookTypes.js';
12
>
13
>
/**
14
>
* Represents a hook source with its original and normalized properties.
15
>
* Used to display hooks from different formats in a unified view.
16
>
*/
17
>
export interface IResolvedHookEntry {
18
>
/** The normalized hook type (our canonical HookType enum) */
19
>
readonly hookType: HookType;
20
>
/** The original hook type ID as it appears in the source file */
21
>
readonly originalHookTypeId: string;
22
>
/** The source format this hook came from */
23
>
readonly sourceFormat: HookSourceFormat;
24
>
/** The resolved hook command */
25
>
readonly command: IHookCommand;
26
>
/** The index of this hook in its array (for editing) */
27
>
readonly index: number;
28
>
}
29
>
30
>
/**
31
>
* Supported hook file formats.
32
>
*/
33
>
export enum HookSourceFormat {
34
>
/** GitHub Copilot hooks .json format */
35
>
Copilot = 'copilot',
36
>
/** Claude settings.json / settings.local.json format */
37
>
Claude = 'claude',
38
>
}
39
>
40
>
/**
41
>
* Determines the hook source format based on the file URI.
42
>
*/
43
>
export function getHookSourceFormat(fileUri: URI): HookSourceFormat {
44
const filename = basename(fileUri.path).toLowerCase();
45
const dir = dirname(fileUri.path);