@librechat/agents 3.1.67-dev.4 → 3.1.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/cjs/agents/AgentContext.cjs +3 -23
  2. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  3. package/dist/cjs/common/enum.cjs +0 -16
  4. package/dist/cjs/common/enum.cjs.map +1 -1
  5. package/dist/cjs/graphs/Graph.cjs +0 -91
  6. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  7. package/dist/cjs/graphs/MultiAgentGraph.cjs +36 -0
  8. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  9. package/dist/cjs/main.cjs +1 -53
  10. package/dist/cjs/main.cjs.map +1 -1
  11. package/dist/cjs/messages/format.cjs +12 -74
  12. package/dist/cjs/messages/format.cjs.map +1 -1
  13. package/dist/cjs/run.cjs +0 -111
  14. package/dist/cjs/run.cjs.map +1 -1
  15. package/dist/cjs/summarization/index.cjs +41 -0
  16. package/dist/cjs/summarization/index.cjs.map +1 -1
  17. package/dist/cjs/summarization/node.cjs +121 -63
  18. package/dist/cjs/summarization/node.cjs.map +1 -1
  19. package/dist/cjs/tools/ToolNode.cjs +140 -304
  20. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  21. package/dist/esm/agents/AgentContext.mjs +3 -23
  22. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  23. package/dist/esm/common/enum.mjs +1 -15
  24. package/dist/esm/common/enum.mjs.map +1 -1
  25. package/dist/esm/graphs/Graph.mjs +0 -91
  26. package/dist/esm/graphs/Graph.mjs.map +1 -1
  27. package/dist/esm/graphs/MultiAgentGraph.mjs +36 -0
  28. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  29. package/dist/esm/main.mjs +2 -13
  30. package/dist/esm/main.mjs.map +1 -1
  31. package/dist/esm/messages/format.mjs +4 -66
  32. package/dist/esm/messages/format.mjs.map +1 -1
  33. package/dist/esm/run.mjs +0 -111
  34. package/dist/esm/run.mjs.map +1 -1
  35. package/dist/esm/summarization/index.mjs +41 -1
  36. package/dist/esm/summarization/index.mjs.map +1 -1
  37. package/dist/esm/summarization/node.mjs +121 -63
  38. package/dist/esm/summarization/node.mjs.map +1 -1
  39. package/dist/esm/tools/ToolNode.mjs +142 -306
  40. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  41. package/dist/types/agents/AgentContext.d.ts +0 -6
  42. package/dist/types/common/enum.d.ts +1 -10
  43. package/dist/types/graphs/Graph.d.ts +0 -2
  44. package/dist/types/graphs/MultiAgentGraph.d.ts +12 -0
  45. package/dist/types/index.d.ts +0 -8
  46. package/dist/types/messages/format.d.ts +1 -2
  47. package/dist/types/run.d.ts +0 -1
  48. package/dist/types/summarization/index.d.ts +2 -0
  49. package/dist/types/summarization/node.d.ts +0 -2
  50. package/dist/types/tools/ToolNode.d.ts +2 -24
  51. package/dist/types/types/graph.d.ts +2 -61
  52. package/dist/types/types/index.d.ts +0 -1
  53. package/dist/types/types/run.d.ts +0 -20
  54. package/dist/types/types/tools.d.ts +1 -38
  55. package/package.json +1 -5
  56. package/src/agents/AgentContext.ts +2 -26
  57. package/src/common/enum.ts +0 -15
  58. package/src/graphs/Graph.ts +0 -113
  59. package/src/graphs/MultiAgentGraph.ts +39 -0
  60. package/src/graphs/__tests__/MultiAgentGraph.test.ts +91 -0
  61. package/src/index.ts +0 -10
  62. package/src/messages/format.ts +4 -74
  63. package/src/run.ts +0 -126
  64. package/src/summarization/__tests__/node.test.ts +42 -0
  65. package/src/summarization/__tests__/trigger.test.ts +100 -1
  66. package/src/summarization/index.ts +47 -0
  67. package/src/summarization/node.ts +149 -77
  68. package/src/tools/ToolNode.ts +169 -391
  69. package/src/tools/__tests__/ToolNode.session.test.ts +12 -12
  70. package/src/types/graph.ts +1 -80
  71. package/src/types/index.ts +0 -1
  72. package/src/types/run.ts +0 -20
  73. package/src/types/tools.ts +1 -41
  74. package/dist/cjs/hooks/HookRegistry.cjs +0 -162
  75. package/dist/cjs/hooks/HookRegistry.cjs.map +0 -1
  76. package/dist/cjs/hooks/executeHooks.cjs +0 -276
  77. package/dist/cjs/hooks/executeHooks.cjs.map +0 -1
  78. package/dist/cjs/hooks/matchers.cjs +0 -256
  79. package/dist/cjs/hooks/matchers.cjs.map +0 -1
  80. package/dist/cjs/hooks/types.cjs +0 -27
  81. package/dist/cjs/hooks/types.cjs.map +0 -1
  82. package/dist/cjs/tools/BashExecutor.cjs +0 -175
  83. package/dist/cjs/tools/BashExecutor.cjs.map +0 -1
  84. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +0 -296
  85. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +0 -1
  86. package/dist/cjs/tools/ReadFile.cjs +0 -43
  87. package/dist/cjs/tools/ReadFile.cjs.map +0 -1
  88. package/dist/cjs/tools/SkillTool.cjs +0 -50
  89. package/dist/cjs/tools/SkillTool.cjs.map +0 -1
  90. package/dist/cjs/tools/SubagentTool.cjs +0 -92
  91. package/dist/cjs/tools/SubagentTool.cjs.map +0 -1
  92. package/dist/cjs/tools/skillCatalog.cjs +0 -84
  93. package/dist/cjs/tools/skillCatalog.cjs.map +0 -1
  94. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +0 -511
  95. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +0 -1
  96. package/dist/esm/hooks/HookRegistry.mjs +0 -160
  97. package/dist/esm/hooks/HookRegistry.mjs.map +0 -1
  98. package/dist/esm/hooks/executeHooks.mjs +0 -273
  99. package/dist/esm/hooks/executeHooks.mjs.map +0 -1
  100. package/dist/esm/hooks/matchers.mjs +0 -251
  101. package/dist/esm/hooks/matchers.mjs.map +0 -1
  102. package/dist/esm/hooks/types.mjs +0 -25
  103. package/dist/esm/hooks/types.mjs.map +0 -1
  104. package/dist/esm/tools/BashExecutor.mjs +0 -169
  105. package/dist/esm/tools/BashExecutor.mjs.map +0 -1
  106. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +0 -287
  107. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +0 -1
  108. package/dist/esm/tools/ReadFile.mjs +0 -38
  109. package/dist/esm/tools/ReadFile.mjs.map +0 -1
  110. package/dist/esm/tools/SkillTool.mjs +0 -45
  111. package/dist/esm/tools/SkillTool.mjs.map +0 -1
  112. package/dist/esm/tools/SubagentTool.mjs +0 -85
  113. package/dist/esm/tools/SubagentTool.mjs.map +0 -1
  114. package/dist/esm/tools/skillCatalog.mjs +0 -82
  115. package/dist/esm/tools/skillCatalog.mjs.map +0 -1
  116. package/dist/esm/tools/subagent/SubagentExecutor.mjs +0 -505
  117. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +0 -1
  118. package/dist/types/hooks/HookRegistry.d.ts +0 -56
  119. package/dist/types/hooks/executeHooks.d.ts +0 -79
  120. package/dist/types/hooks/index.d.ts +0 -6
  121. package/dist/types/hooks/matchers.d.ts +0 -95
  122. package/dist/types/hooks/types.d.ts +0 -320
  123. package/dist/types/tools/BashExecutor.d.ts +0 -45
  124. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +0 -72
  125. package/dist/types/tools/ReadFile.d.ts +0 -28
  126. package/dist/types/tools/SkillTool.d.ts +0 -40
  127. package/dist/types/tools/SubagentTool.d.ts +0 -36
  128. package/dist/types/tools/skillCatalog.d.ts +0 -19
  129. package/dist/types/tools/subagent/SubagentExecutor.d.ts +0 -137
  130. package/dist/types/tools/subagent/index.d.ts +0 -2
  131. package/dist/types/types/skill.d.ts +0 -9
  132. package/src/hooks/HookRegistry.ts +0 -208
  133. package/src/hooks/__tests__/HookRegistry.test.ts +0 -190
  134. package/src/hooks/__tests__/compactHooks.test.ts +0 -214
  135. package/src/hooks/__tests__/executeHooks.test.ts +0 -1013
  136. package/src/hooks/__tests__/integration.test.ts +0 -337
  137. package/src/hooks/__tests__/matchers.test.ts +0 -238
  138. package/src/hooks/__tests__/toolHooks.test.ts +0 -669
  139. package/src/hooks/executeHooks.ts +0 -375
  140. package/src/hooks/index.ts +0 -57
  141. package/src/hooks/matchers.ts +0 -280
  142. package/src/hooks/types.ts +0 -404
  143. package/src/messages/formatAgentMessages.skills.test.ts +0 -334
  144. package/src/scripts/multi-agent-subagent.ts +0 -246
  145. package/src/scripts/subagent-event-driven-debug.ts +0 -190
  146. package/src/scripts/subagent-tools-debug.ts +0 -160
  147. package/src/specs/subagent.test.ts +0 -305
  148. package/src/tools/BashExecutor.ts +0 -205
  149. package/src/tools/BashProgrammaticToolCalling.ts +0 -397
  150. package/src/tools/ReadFile.ts +0 -39
  151. package/src/tools/SkillTool.ts +0 -46
  152. package/src/tools/SubagentTool.ts +0 -100
  153. package/src/tools/__tests__/ReadFile.test.ts +0 -44
  154. package/src/tools/__tests__/SkillTool.test.ts +0 -442
  155. package/src/tools/__tests__/SubagentExecutor.test.ts +0 -1148
  156. package/src/tools/__tests__/SubagentTool.test.ts +0 -149
  157. package/src/tools/__tests__/skillCatalog.test.ts +0 -161
  158. package/src/tools/__tests__/subagentHooks.test.ts +0 -215
  159. package/src/tools/skillCatalog.ts +0 -126
  160. package/src/tools/subagent/SubagentExecutor.ts +0 -676
  161. package/src/tools/subagent/index.ts +0 -13
  162. package/src/types/skill.ts +0 -11
@@ -1,404 +0,0 @@
1
- // src/hooks/types.ts
2
- import type { BaseMessage } from '@langchain/core/messages';
3
-
4
- /**
5
- * Closed set of hook lifecycle events supported by the hooks system.
6
- *
7
- * These mirror the subset of Claude Code's event surface that makes sense
8
- * for a library context (no filesystem/CLI-specific events). See
9
- * `docs/hooks-design-report.md` §3.2 for the mapping to existing
10
- * `@librechat/agents` emission points.
11
- */
12
- export const HOOK_EVENTS = [
13
- 'RunStart',
14
- 'UserPromptSubmit',
15
- 'PreToolUse',
16
- 'PostToolUse',
17
- 'PostToolUseFailure',
18
- 'PermissionDenied',
19
- 'SubagentStart',
20
- 'SubagentStop',
21
- 'Stop',
22
- 'StopFailure',
23
- 'PreCompact',
24
- 'PostCompact',
25
- ] as const;
26
-
27
- export type HookEvent = (typeof HOOK_EVENTS)[number];
28
-
29
- /** Tool-gating decision; executeHooks folds with `deny > ask > allow` precedence. */
30
- export type ToolDecision = 'allow' | 'deny' | 'ask';
31
-
32
- /** Stop-loop decision; `block` means "do not stop, run another turn". Any `block` wins. */
33
- export type StopDecision = 'continue' | 'block';
34
-
35
- /**
36
- * Fields shared by every `HookInput`. Discriminated by `hook_event_name`.
37
- *
38
- * - `runId` identifies the current agent run and is always present.
39
- * - `threadId` identifies the conversation thread when the host has one.
40
- * - `agentId` is only set when the hook fires inside a subagent scope.
41
- */
42
- export interface BaseHookInput {
43
- runId: string;
44
- threadId?: string;
45
- agentId?: string;
46
- }
47
-
48
- export interface RunStartHookInput extends BaseHookInput {
49
- hook_event_name: 'RunStart';
50
- messages: BaseMessage[];
51
- }
52
-
53
- export interface UserPromptSubmitHookInput extends BaseHookInput {
54
- hook_event_name: 'UserPromptSubmit';
55
- prompt: string;
56
- attachments?: BaseMessage[];
57
- }
58
-
59
- /**
60
- * Fires before a tool is invoked. Hook may return `deny`/`ask`/`allow` and/or
61
- * an `updatedInput` that replaces the tool arguments before invocation.
62
- *
63
- * `toolInput` is intentionally typed as `Record<string, unknown>` because the
64
- * SDK is tool-agnostic — concrete tool argument shapes are only known at the
65
- * call site and are narrowed by the host. This is the one escape hatch in
66
- * the hook type system.
67
- */
68
- export interface PreToolUseHookInput extends BaseHookInput {
69
- hook_event_name: 'PreToolUse';
70
- toolName: string;
71
- toolInput: Record<string, unknown>;
72
- toolUseId: string;
73
- stepId?: string;
74
- /**
75
- * Number of times this tool has been invoked in prior batches within the
76
- * current run. Within a single batch of parallel calls, all calls to the
77
- * same tool share the same turn value — per-call discrimination within a
78
- * batch is not supported in v1.
79
- */
80
- turn?: number;
81
- }
82
-
83
- export interface PostToolUseHookInput extends BaseHookInput {
84
- hook_event_name: 'PostToolUse';
85
- toolName: string;
86
- toolInput: Record<string, unknown>;
87
- toolOutput: unknown;
88
- toolUseId: string;
89
- stepId?: string;
90
- turn?: number;
91
- }
92
-
93
- export interface PostToolUseFailureHookInput extends BaseHookInput {
94
- hook_event_name: 'PostToolUseFailure';
95
- toolName: string;
96
- toolInput: Record<string, unknown>;
97
- toolUseId: string;
98
- error: string;
99
- stepId?: string;
100
- turn?: number;
101
- }
102
-
103
- export interface PermissionDeniedHookInput extends BaseHookInput {
104
- hook_event_name: 'PermissionDenied';
105
- toolName: string;
106
- toolInput: Record<string, unknown>;
107
- toolUseId: string;
108
- reason: string;
109
- }
110
-
111
- export interface SubagentStartHookInput extends BaseHookInput {
112
- hook_event_name: 'SubagentStart';
113
- parentAgentId?: string;
114
- agentId: string;
115
- agentType: string;
116
- inputs: BaseMessage[];
117
- }
118
-
119
- export interface SubagentStopHookInput extends BaseHookInput {
120
- hook_event_name: 'SubagentStop';
121
- agentId: string;
122
- agentType: string;
123
- messages: BaseMessage[];
124
- }
125
-
126
- export interface StopHookInput extends BaseHookInput {
127
- hook_event_name: 'Stop';
128
- messages: BaseMessage[];
129
- stopReason?: string;
130
- stopHookActive: boolean;
131
- }
132
-
133
- export interface StopFailureHookInput extends BaseHookInput {
134
- hook_event_name: 'StopFailure';
135
- error: string;
136
- lastAssistantMessage?: BaseMessage;
137
- }
138
-
139
- export interface PreCompactHookInput extends BaseHookInput {
140
- hook_event_name: 'PreCompact';
141
- messagesBeforeCount: number;
142
- /**
143
- * What triggered compaction. Matches `SummarizationTrigger.type` from the
144
- * agent's summarization config. `'default'` means no trigger was
145
- * configured and compaction fired because messages were pruned.
146
- */
147
- trigger:
148
- | 'token_ratio'
149
- | 'remaining_tokens'
150
- | 'messages_to_refine'
151
- | 'default'
152
- | (string & {});
153
- }
154
-
155
- export interface PostCompactHookInput extends BaseHookInput {
156
- hook_event_name: 'PostCompact';
157
- summary: string;
158
- /**
159
- * Number of messages remaining after compaction. The summarize node
160
- * returns a `removeAll` signal that clears all messages from state;
161
- * the summary itself is injected into the system prompt, not as a
162
- * message. This is `0` at the point of hook dispatch.
163
- */
164
- messagesAfterCount: number;
165
- }
166
-
167
- /** Discriminated union of every hook input shape. */
168
- export type HookInput =
169
- | RunStartHookInput
170
- | UserPromptSubmitHookInput
171
- | PreToolUseHookInput
172
- | PostToolUseHookInput
173
- | PostToolUseFailureHookInput
174
- | PermissionDeniedHookInput
175
- | SubagentStartHookInput
176
- | SubagentStopHookInput
177
- | StopHookInput
178
- | StopFailureHookInput
179
- | PreCompactHookInput
180
- | PostCompactHookInput;
181
-
182
- /** Compile-time map from event name to its input shape. */
183
- export type HookInputByEvent = {
184
- RunStart: RunStartHookInput;
185
- UserPromptSubmit: UserPromptSubmitHookInput;
186
- PreToolUse: PreToolUseHookInput;
187
- PostToolUse: PostToolUseHookInput;
188
- PostToolUseFailure: PostToolUseFailureHookInput;
189
- PermissionDenied: PermissionDeniedHookInput;
190
- SubagentStart: SubagentStartHookInput;
191
- SubagentStop: SubagentStopHookInput;
192
- Stop: StopHookInput;
193
- StopFailure: StopFailureHookInput;
194
- PreCompact: PreCompactHookInput;
195
- PostCompact: PostCompactHookInput;
196
- };
197
-
198
- /**
199
- * Fields common to every hook output. Hooks that have nothing to say simply
200
- * return `{}` (or omit the fields below).
201
- */
202
- export interface BaseHookOutput {
203
- /** Context string to inject into the conversation. Accumulated across hooks. */
204
- additionalContext?: string;
205
- /** True to prevent the next model turn. Any hook can set this. */
206
- preventContinuation?: boolean;
207
- /** Reason reported alongside `preventContinuation`. */
208
- stopReason?: string;
209
- }
210
-
211
- export type RunStartHookOutput = BaseHookOutput;
212
-
213
- export interface UserPromptSubmitHookOutput extends BaseHookOutput {
214
- decision?: ToolDecision;
215
- reason?: string;
216
- }
217
-
218
- export interface PreToolUseHookOutput extends BaseHookOutput {
219
- decision?: ToolDecision;
220
- reason?: string;
221
- /**
222
- * Replacement tool input. Merged into the pending tool call by the host.
223
- *
224
- * When multiple hooks set `updatedInput` within a single `executeHooks`
225
- * call, the last writer in registration order wins (outer loop: matcher
226
- * registration order; inner loop: hook position within the matcher). The
227
- * winner is deterministic — `Promise.all` preserves input-array order.
228
- * Consumers that need a single authoritative rewrite should still scope
229
- * `updatedInput` to one hook per matcher to avoid confusing precedence.
230
- */
231
- updatedInput?: Record<string, unknown>;
232
- }
233
-
234
- export interface PostToolUseHookOutput extends BaseHookOutput {
235
- /**
236
- * Replacement tool output. Flows through the aggregated result so the
237
- * host can substitute it before appending the tool result message.
238
- * Ordering semantics match `PreToolUseHookOutput.updatedInput`:
239
- * last-writer-wins in registration order.
240
- */
241
- updatedOutput?: unknown;
242
- }
243
-
244
- export type PostToolUseFailureHookOutput = BaseHookOutput;
245
-
246
- export type PermissionDeniedHookOutput = BaseHookOutput;
247
-
248
- export interface SubagentStartHookOutput extends BaseHookOutput {
249
- decision?: ToolDecision;
250
- reason?: string;
251
- }
252
-
253
- export type SubagentStopHookOutput = BaseHookOutput;
254
-
255
- export interface StopHookOutput extends BaseHookOutput {
256
- decision?: StopDecision;
257
- reason?: string;
258
- }
259
-
260
- export type StopFailureHookOutput = BaseHookOutput;
261
-
262
- export type PreCompactHookOutput = BaseHookOutput;
263
-
264
- export type PostCompactHookOutput = BaseHookOutput;
265
-
266
- /** Compile-time map from event name to its output shape. */
267
- export type HookOutputByEvent = {
268
- RunStart: RunStartHookOutput;
269
- UserPromptSubmit: UserPromptSubmitHookOutput;
270
- PreToolUse: PreToolUseHookOutput;
271
- PostToolUse: PostToolUseHookOutput;
272
- PostToolUseFailure: PostToolUseFailureHookOutput;
273
- PermissionDenied: PermissionDeniedHookOutput;
274
- SubagentStart: SubagentStartHookOutput;
275
- SubagentStop: SubagentStopHookOutput;
276
- Stop: StopHookOutput;
277
- StopFailure: StopFailureHookOutput;
278
- PreCompact: PreCompactHookOutput;
279
- PostCompact: PostCompactHookOutput;
280
- };
281
-
282
- /** Superset output shape used by the executor's fold loop. */
283
- export type HookOutput =
284
- | RunStartHookOutput
285
- | UserPromptSubmitHookOutput
286
- | PreToolUseHookOutput
287
- | PostToolUseHookOutput
288
- | PostToolUseFailureHookOutput
289
- | PermissionDeniedHookOutput
290
- | SubagentStartHookOutput
291
- | SubagentStopHookOutput
292
- | StopHookOutput
293
- | StopFailureHookOutput
294
- | PreCompactHookOutput
295
- | PostCompactHookOutput;
296
-
297
- /**
298
- * A hook callback is a plain async function registered against a specific
299
- * event. The `signal` is always supplied by `executeHooks` and combines the
300
- * batch's parent signal with the per-hook timeout — callbacks that perform
301
- * long-running work should observe it.
302
- */
303
- export type HookCallback<E extends HookEvent = HookEvent> = (
304
- input: HookInputByEvent[E],
305
- signal: AbortSignal
306
- ) => HookOutputByEvent[E] | Promise<HookOutputByEvent[E]>;
307
-
308
- /**
309
- * A matcher groups one or more callbacks under a shared regex filter and
310
- * shared timeout/once/internal flags. The generic `E` ties the callback
311
- * types to the event the matcher is registered against.
312
- */
313
- export interface HookMatcher<E extends HookEvent = HookEvent> {
314
- /**
315
- * Regex pattern matched against the event's primary query string (e.g.
316
- * the tool name for `PreToolUse`, the agent type for `SubagentStart`).
317
- *
318
- * Omitted or empty means "always match". For events that do not supply a
319
- * query string (`RunStart`, `Stop`, etc.), only wildcard matchers fire —
320
- * a non-empty pattern on such events will never match.
321
- *
322
- * Patterns are treated as trusted input: `executeHooks` compiles them
323
- * with `new RegExp(pattern)` without any sandbox, and a pathological
324
- * pattern can block the event loop. Host registration code is expected
325
- * to validate or length-bound patterns that originate from user input.
326
- */
327
- pattern?: string;
328
- /** Callbacks that fire when the matcher hits. Executed in parallel. */
329
- hooks: HookCallback<E>[];
330
- /** Per-matcher timeout in ms. Defaults to the executor's batch timeout. */
331
- timeout?: number;
332
- /**
333
- * Atomically remove the matcher before its first dispatch.
334
- *
335
- * `executeHooks` claims `once: true` matchers synchronously — between
336
- * `getMatchers` and its first `await` — so two concurrent calls cannot
337
- * both dispatch the same matcher. Whichever call runs its sync prefix
338
- * first wins the matcher; the other sees an empty bucket.
339
- *
340
- * Semantics are "at most one dispatch, ever" — if every hook in the
341
- * matcher throws, the matcher is still gone. Use `once` for
342
- * fire-and-forget bootstrapping (registration, telemetry, setup). Hosts
343
- * that need retry semantics should register a normal matcher and
344
- * self-unregister via the callback returned from `registry.register`.
345
- */
346
- once?: boolean;
347
- /** Internal hooks are excluded from telemetry and non-fatal error logging. */
348
- internal?: boolean;
349
- }
350
-
351
- /**
352
- * Storage shape for matchers keyed by event. Each event's matcher list is
353
- * a generic array parameterized by that event type, so lookup via
354
- * `HooksByEvent[E]` preserves type-safe callback signatures.
355
- */
356
- export type HooksByEvent = {
357
- [E in HookEvent]?: HookMatcher<E>[];
358
- };
359
-
360
- /**
361
- * Aggregated result of a single `executeHooks` call. Fields are populated
362
- * according to the fold rules in `executeHooks.ts`.
363
- */
364
- export interface AggregatedHookResult {
365
- /** Folded tool-gating decision; `deny > ask > allow`. */
366
- decision?: ToolDecision;
367
- /** Folded stop decision; any `block` wins. */
368
- stopDecision?: StopDecision;
369
- /** Reason from the hook that set the winning decision. */
370
- reason?: string;
371
- /**
372
- * Replacement tool input from a `PreToolUse` hook.
373
- *
374
- * Last-writer-wins in **registration order**: `executeHooks` uses
375
- * `Promise.all`, which preserves input-array order, so the fold iterates
376
- * outcomes in the same order they were pushed — outer loop over matchers
377
- * as they sit in the registry, inner loop over each matcher's `hooks`
378
- * array. The winner is therefore deterministic but may not match the
379
- * order in which hooks actually completed. Consumers that want a single
380
- * authoritative rewrite should still register one `updatedInput`-setting
381
- * hook per matcher to avoid subtle precedence bugs.
382
- */
383
- updatedInput?: Record<string, unknown>;
384
- /**
385
- * Replacement tool output from a `PostToolUse` hook.
386
- *
387
- * Same last-writer-wins-in-registration-order semantics as
388
- * `updatedInput`. Present only when at least one hook set it; `undefined`
389
- * means "use the original tool output".
390
- */
391
- updatedOutput?: unknown;
392
- /** Accumulated `additionalContext` strings from every hook, in order. */
393
- additionalContexts: string[];
394
- /** True if any hook returned `preventContinuation`. */
395
- preventContinuation?: boolean;
396
- /**
397
- * Reason recorded alongside `preventContinuation`. First winner wins:
398
- * once a hook sets both flags, later hooks that also set
399
- * `preventContinuation` do not overwrite the reason.
400
- */
401
- stopReason?: string;
402
- /** Error messages from hooks that threw; always present (possibly empty). */
403
- errors: string[];
404
- }