Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/chat/common/hookExecutor.ts
13401 views
1
/*---------------------------------------------------------------------------------------------
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 type { CancellationToken, ChatHookCommand } from 'vscode';
7
import { createServiceIdentifier } from '../../../util/common/services';
8
9
export const IHookExecutor = createServiceIdentifier<IHookExecutor>('IHookExecutor');
10
11
export const enum HookCommandResultKind {
12
Success = 1,
13
/** Blocking error - shown to model (exit code 2) */
14
Error = 2,
15
/** Non-blocking error - shown to user only (other non-zero exit codes) */
16
NonBlockingError = 3
17
}
18
19
export interface IHookCommandResult {
20
readonly kind: HookCommandResultKind;
21
/**
22
* For success: stdout parsed as JSON if valid, otherwise as string.
23
* For errors: stderr content.
24
*/
25
readonly result: string | object;
26
/**
27
* The normalized exit code for the command.
28
* 0 = success, 2 = blocking error, other non-zero = non-blocking error.
29
* Terminations without a numeric exit code (e.g., by signal) are normalized to 1.
30
*/
31
readonly exitCode?: number;
32
}
33
34
export interface IHookExecutor {
35
readonly _serviceBrand: undefined;
36
37
/**
38
* Execute a single hook command, writing JSON input to stdin
39
* and capturing stdout/stderr.
40
*
41
* Exit code semantics:
42
* - 0: Success (stdout parsed as JSON if valid)
43
* - non-zero: Error (stderr returned)
44
*/
45
executeCommand(
46
hookCommand: ChatHookCommand,
47
input: unknown,
48
token: CancellationToken
49
): Promise<IHookCommandResult>;
50
}
51
52