hookCompatibility.ts ×7

Frontier kind: Code frontier

unlabeled · c_6d10b8cb21ac

317 tests · 14744 LOC · 59 files · introduces 0 tests · 181 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
14 ranges181 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1136 ranges14744 lines · 59 files · Browse complete extent
All tests (intent)
317 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

3 files ranked by introduced lines: 181 introduced LOC across 14 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/contrib/chat/common/promptSyntax/hookCompatibility.ts 89 introduced LOC · 7 ranges

Open complete file

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);
53 return HookSourceFormat.Copilot;
54 }
56 > /**
57 > * Checks if a file is read-only based on its source format.
58 > * Claude settings files should be read-only from our perspective since they have a different format.
59 > */
60 > export function isReadOnlyHookSource(format: HookSourceFormat): boolean {
61 return format === HookSourceFormat.Claude;
62 }
64 > /**
65 > * Parses hooks from a Copilot hooks .json file (our native format).
66 > */
67 > export function parseCopilotHooks(
68 json: unknown,
69 workspaceRootUri: URI | undefined,
111 return result;
112 }
114 > /**
115 > * Result of parsing hooks from a file.
116 > */
117 > export interface IParseHooksFromFileResult {
118 > readonly format: HookSourceFormat;
119 > readonly hooks: Map<HookType, { hooks: IHookCommand[]; originalId: string }>;
120 > /**
121 > * Whether all hooks from this file were disabled via `disableAllHooks: true`.
122 > */
123 > readonly disabledAllHooks: boolean;
124 > }
125 >
126 > /**
127 > * Parses hooks from any supported format, auto-detecting the format from the file URI.
128 > */
129 > export function parseHooksFromFile(
130 fileUri: URI,
131 json: unknown,
153 return { format, hooks, disabledAllHooks };
154 }
156 > /**
157 > * Parses hooks from a file, ignoring the `disableAllHooks` flag.
158 > * Used by diagnostics to show which hooks are hidden when `disableAllHooks: true` is set.
159 > */
160 > export function parseHooksIgnoringDisableAll(
161 fileUri: URI,
162 json: unknown,
188 return { format, hooks, disabledAllHooks: true };
189 }
191 > /**
192 > * Gets a human-readable label for a hook source format.
193 > */
194 > export function getHookSourceFormatLabel(format: HookSourceFormat): string {
195 switch (format) {
196 case HookSourceFormat.Claude:
200 }
201 }
203 > /**
204 > * Builds a new hook entry object in the appropriate format for the given source format.
205 > * - Copilot format: `{ type: 'command', command: '' }`
206 > * - Claude format: `{ matcher: '', hooks: [{ type: 'command', command: '' }] }`
207 > */
208 > export function buildNewHookEntry(format: HookSourceFormat): Record<string, unknown> {
209 const commandEntry = { type: 'command', command: '' };
210 if (format === HookSourceFormat.Claude) {
src/vs/workbench/contrib/chat/common/promptSyntax/hookClaudeCompat.ts 65 introduced LOC · 4 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- hookClaudeCompat.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 { toHookType, IHookCommand, extractHookCommandsFromItem } from './hookSchema.js';
8 > import { HOOKS_BY_TARGET, HookType } from './hookTypes.js';
9 > import { Target } from './promptTypes.js';
10 >
11 > export { extractHookCommandsFromItem };
12 >
13 > /**
14 > * Cached inverse mapping from HookType to Claude hook type name.
15 > * Lazily computed on first access.
16 > */
17 > let _hookTypeToClaudeName: Map<HookType, string> | undefined;
18 >
19 function getHookTypeToClaudeNameMap(): Map<HookType, string> {
20 if (!_hookTypeToClaudeName) {
26 return _hookTypeToClaudeName;
27 }
29 > /**
30 > * Resolves a Claude hook type name to our abstract HookType.
31 > */
32 > export function resolveClaudeHookType(name: string): HookType | undefined {
33 return HOOKS_BY_TARGET[Target.Claude][name];
34 }
36 > /**
37 > * Gets the Claude hook type name for a given abstract HookType.
38 > * Returns undefined if the hook type is not supported in Claude.
39 > */
40 > export function getClaudeHookTypeName(hookType: HookType): string | undefined {
41 return getHookTypeToClaudeNameMap().get(hookType);
42 }
44 > /**
45 > * Result of parsing Claude hooks file.
46 > */
47 > export interface IParseClaudeHooksResult {
48 > /**
49 > * The parsed hooks by type.
50 > */
51 > readonly hooks: Map<HookType, { hooks: IHookCommand[]; originalId: string }>;
52 > /**
53 > * Whether all hooks from this file were disabled via `disableAllHooks: true`.
54 > */
55 > readonly disabledAllHooks: boolean;
56 > }
57 >
58 > /**
59 > * Parses hooks from a Claude settings.json file.
60 > * Claude format:
61 > * {
62 > * "hooks": {
63 > * "PreToolUse": [
64 > * { "matcher": "Bash", "hooks": [{ "type": "command", "command": "..." }] }
65 > * ]
66 > * }
67 > * }
68 > *
69 > * Or simpler format:
70 > * {
71 > * "hooks": {
72 > * "PreToolUse": [{ "type": "command", "command": "..." }]
73 > * }
74 > * }
75 > *
76 > * If the file has `disableAllHooks: true` at the top level, all hooks are filtered out.
77 > */
78 > export function parseClaudeHooks(
79 json: unknown,
80 workspaceRootUri: URI | undefined,
src/vs/workbench/contrib/chat/common/promptSyntax/hookCopilotCliCompat.ts 27 introduced LOC · 3 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- hookCopilotCliCompat.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 { HOOKS_BY_TARGET, HookType } from './hookTypes.js';
7 > import { Target } from './promptTypes.js';
8 >
9 > const COPILOT_CLI_HOOK_TYPE_MAP: Record<string, HookType> = HOOKS_BY_TARGET[Target.GitHubCopilot];
10 >
11 > /**
12 > * Cached inverse mapping from HookType to Copilot CLI hook type name.
13 > * Lazily computed on first access.
14 > */
15 > let _hookTypeToCopilotCliName: Map<HookType, string> | undefined;
16 >
17 function getHookTypeToCopilotCliNameMap(): Map<HookType, string> {
18 if (!_hookTypeToCopilotCliName) {
24 return _hookTypeToCopilotCliName;
25 }
27 > /**
28 > * Resolves a Copilot CLI hook type name to our abstract HookType.
29 > */
30 > export function resolveCopilotCliHookType(name: string): HookType | undefined {
31 return (COPILOT_CLI_HOOK_TYPE_MAP as Record<string, HookType>)[name];
32 }
34 > /**
35 > * Gets the Copilot CLI hook type name for a given abstract HookType.
36 > * Returns undefined if the hook type is not supported in Copilot CLI.
37 > */
38 > export function getCopilotCliHookTypeName(hookType: HookType): string | undefined {
39 return getHookTypeToCopilotCliNameMap().get(hookType);
40 }