hooks.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import type { SettingsDirectoryLocation } from "./settings-source.js";
  2. import type { WorkspaceHookReviewTrustState } from "./zcode-protocol-v4/workspace-hook-review.js";
  3. export type HookEvent =
  4. | "SessionStart"
  5. | "UserPromptSubmit"
  6. | "PreToolUse"
  7. | "PermissionRequest"
  8. | "PostToolUse"
  9. | "PostToolUseFailure"
  10. | "Stop";
  11. export type HookType = "command" | "process";
  12. export interface HookConfiguredState {
  13. sourceRootEnabled: boolean;
  14. declarationEnabled: boolean;
  15. runtimeHooksEnabled: boolean;
  16. configuredEnabled: boolean;
  17. sourcePath: string;
  18. }
  19. export interface WorkspaceHookDiscoveryState extends HookConfiguredState {
  20. reviewItemId: string;
  21. workspaceIdentity: string;
  22. bundleDigest: string;
  23. hookDeclarationDigest: string;
  24. sourceFileIndex: number;
  25. /** Read-only Settings evaluation; a live Runtime review projection overrides this value. */
  26. trustState?: WorkspaceHookReviewTrustState;
  27. }
  28. export interface Hook {
  29. id: string;
  30. event: HookEvent;
  31. matcher?: string;
  32. type: HookType;
  33. command: string;
  34. args?: string[];
  35. async?: boolean;
  36. shell?: true | string;
  37. statusMessage?: string;
  38. timeout?: number;
  39. enabled: boolean;
  40. editable?: boolean;
  41. configuredState?: HookConfiguredState;
  42. workspaceHook?: WorkspaceHookDiscoveryState;
  43. custom?: Record<string, unknown>;
  44. location?: SettingsDirectoryLocation;
  45. }
  46. export interface HookConfig {
  47. event: HookEvent;
  48. matcher?: string;
  49. type: HookType;
  50. command: string;
  51. args?: string[];
  52. async?: boolean;
  53. shell?: true | string;
  54. statusMessage?: string;
  55. timeout?: number;
  56. enabled?: boolean;
  57. custom?: Record<string, unknown>;
  58. storageLevel?: "user" | "project";
  59. }
  60. /**
  61. * Metadata for hook identification in tool calls.
  62. * Used in both chat-panel.types.ts and conversationStore.ts.
  63. */
  64. export interface ToolCallHookMeta {
  65. isHook?: boolean;
  66. hookEvent?: string;
  67. hookCommand?: string;
  68. hookMatcher?: string;
  69. hookToolName?: string;
  70. hookExitCode?: number | null;
  71. hookError?: string;
  72. hookStdout?: string;
  73. hookName?: string;
  74. hookFeedback?: string;
  75. hookStderr?: string;
  76. /** Skill-related metadata */
  77. "zcode/isSkill"?: boolean;
  78. "zcode/skillName"?: string;
  79. [key: string]: unknown;
  80. }