@@ -44,7 +44,7 @@ $agent = AgentBuilder::new()
4444 })
4545
4646 ->build();
47- // @doctest id="f7c2 "
47+ // @doctest id="b455 "
4848```
4949
5050## Lifecycle Events
@@ -104,7 +104,7 @@ HookOutcome::block('Dangerous command detected');
104104
105105// Stop the entire agent execution
106106HookOutcome::stop('Budget exceeded');
107- // @doctest id="d629 "
107+ // @doctest id="5c54 "
108108```
109109
110110### Semantic Differences
@@ -146,7 +146,7 @@ function afterTool(ToolHookContext $ctx): HookOutcome {
146146
147147 return HookOutcome::proceed();
148148}
149- // @doctest id="2c95 "
149+ // @doctest id="495b "
150150```
151151
152152### StepHookContext
@@ -167,7 +167,7 @@ function onStep(StepHookContext $ctx): HookOutcome {
167167
168168 return HookOutcome::proceed();
169169}
170- // @doctest id="e6d9 "
170+ // @doctest id="379e "
171171```
172172
173173### StopHookContext
@@ -187,7 +187,7 @@ function onStop(StopHookContext $ctx): HookOutcome {
187187
188188 return HookOutcome::proceed(); // Allow stop
189189}
190- // @doctest id="1add "
190+ // @doctest id="8133 "
191191```
192192
193193### ExecutionHookContext
@@ -206,7 +206,7 @@ function onExecution(ExecutionHookContext $ctx): HookOutcome {
206206
207207 return HookOutcome::proceed();
208208}
209- // @doctest id="7830 "
209+ // @doctest id="2e65 "
210210```
211211
212212### FailureHookContext
@@ -223,7 +223,7 @@ function onFailure(FailureHookContext $ctx): HookOutcome {
223223
224224 return HookOutcome::proceed();
225225}
226- // @doctest id="96aa "
226+ // @doctest id="5619 "
227227```
228228
229229## Matchers
@@ -247,7 +247,7 @@ new ToolNameMatcher('*'); // Match all
247247
248248// Regex patterns
249249new ToolNameMatcher('/^(read|write)_.+$/');
250- // @doctest id="3fd1 "
250+ // @doctest id="4702 "
251251```
252252
253253### EventTypeMatcher
@@ -263,7 +263,7 @@ new EventTypeMatcher(HookEvent::PreToolUse);
263263
264264// Multiple events
265265new EventTypeMatcher(HookEvent::BeforeStep, HookEvent::AfterStep);
266- // @doctest id="da63 "
266+ // @doctest id="c451 "
267267```
268268
269269### CompositeMatcher
@@ -294,7 +294,7 @@ $matcher = CompositeMatcher::and(
294294 ),
295295 new CallableMatcher(fn($ctx) => $ctx->state()->metadata()->get('safe_mode')),
296296);
297- // @doctest id="4d34 "
297+ // @doctest id="c3c6 "
298298```
299299
300300### CallableMatcher
@@ -307,7 +307,7 @@ use Cognesy\Addons\Agent\Hooks\Matchers\CallableMatcher;
307307$matcher = new CallableMatcher(function (HookContext $ctx): bool {
308308 return $ctx->state()->metadata()->get('priority') === 'high';
309309});
310- // @doctest id="ff80 "
310+ // @doctest id="9846 "
311311```
312312
313313## Priority
@@ -324,7 +324,7 @@ $builder
324324
325325 // Logging hooks run last (low priority)
326326 ->onAfterToolUse($logger, priority: -100);
327- // @doctest id="ec88 "
327+ // @doctest id="21f3 "
328328```
329329
330330** Priority Guidelines:**
@@ -352,7 +352,7 @@ $builder->onAfterToolUse(
352352 priority: int = 0,
353353 matcher: string|HookMatcher|null = null,
354354);
355- // @doctest id="32c4 "
355+ // @doctest id="bff9 "
356356```
357357
358358### Step Hooks
@@ -367,7 +367,7 @@ $builder->onBeforeStep(
367367$builder->onAfterStep(
368368 callback: callable, // (AgentState) -> AgentState
369369);
370- // @doctest id="7c77 "
370+ // @doctest id="c6b5 "
371371```
372372
373373### Execution Hooks
@@ -384,7 +384,7 @@ $builder->onExecutionEnd(
384384 callback: callable, // (ExecutionHookContext) -> HookOutcome|void
385385 priority: int = 0,
386386);
387- // @doctest id="6412 "
387+ // @doctest id="9170 "
388388```
389389
390390### Continuation Hooks
@@ -401,7 +401,7 @@ $builder->onSubagentStop(
401401 callback: callable, // (StopHookContext) -> HookOutcome|void
402402 priority: int = 0,
403403);
404- // @doctest id="3a0c "
404+ // @doctest id="7450 "
405405```
406406
407407### Error Hooks
@@ -412,7 +412,7 @@ $builder->onAgentFailed(
412412 callback: callable, // (FailureHookContext) -> HookOutcome|void
413413 priority: int = 0,
414414);
415- // @doctest id="700a "
415+ // @doctest id="534d "
416416```
417417
418418### Unified Registration
@@ -428,7 +428,7 @@ $builder->addHook(
428428 hook: new CallableHook($callback, $matcher),
429429 priority: 100,
430430);
431- // @doctest id="f22b "
431+ // @doctest id="5607 "
432432```
433433
434434## Creating Custom Hooks
@@ -457,7 +457,7 @@ class RateLimitHook implements Hook
457457 return $next($context);
458458 }
459459}
460- // @doctest id="7cb4 "
460+ // @doctest id="bfa4 "
461461```
462462
463463## Using HookStack Directly
@@ -482,7 +482,7 @@ if ($outcome->isBlocked()) {
482482} elseif ($outcome->isStopped()) {
483483 // Handle stopped
484484}
485- // @doctest id="1d82 "
485+ // @doctest id="e097 "
486486```
487487
488488## Backward Compatibility
@@ -498,7 +498,7 @@ use Cognesy\Addons\Agent\Hooks\Adapters\StateProcessorAdapter;
498498
499499$processor = new YourStateProcessor();
500500$hook = new StateProcessorAdapter($processor, position: 'after');
501- // @doctest id="7351 "
501+ // @doctest id="7d0e "
502502```
503503
504504### ContinuationCriteriaAdapter
@@ -508,7 +508,7 @@ use Cognesy\Addons\Agent\Hooks\Adapters\ContinuationCriteriaAdapter;
508508
509509$criterion = new YourContinuationCriterion();
510510$hook = new ContinuationCriteriaAdapter($criterion);
511- // @doctest id="7a88 "
511+ // @doctest id="0471 "
512512```
513513
514514## Common Patterns
@@ -533,7 +533,7 @@ $builder->onBeforeToolUse(
533533 priority: 100, // Run first
534534 matcher: 'bash',
535535);
536- // @doctest id="4e5e "
536+ // @doctest id="f1e5 "
537537```
538538
539539### Execution Timing
@@ -550,7 +550,7 @@ $builder
550550 $duration = microtime(true) - $started;
551551 $this->metrics->record('execution_duration', $duration);
552552 });
553- // @doctest id="06f6 "
553+ // @doctest id="8517 "
554554```
555555
556556### Conditional Continuation
@@ -573,7 +573,7 @@ $builder->onStop(function (StopHookContext $ctx): HookOutcome {
573573
574574 return HookOutcome::proceed();
575575});
576- // @doctest id="aab6 "
576+ // @doctest id="d6c6 "
577577```
578578
579579### Error Recovery Logging
@@ -599,7 +599,7 @@ $builder->onAgentFailed(function (FailureHookContext $ctx): void {
599599 $this->alerting->sendCritical($exception);
600600 }
601601});
602- // @doctest id="68fb "
602+ // @doctest id="2742 "
603603```
604604
605605## Architecture
@@ -631,7 +631,7 @@ $builder->onAgentFailed(function (FailureHookContext $ctx): void {
631631│ │ execution│ │ action │ │ entirely │ │
632632│ └──────────┘ └──────────┘ └──────────┘ │
633633└─────────────────────────────────────────────────────────────┘
634- // @doctest id="2fab "
634+ // @doctest id="6482 "
635635```
636636
637637## File Structure
@@ -672,5 +672,5 @@ packages/addons/src/Agent/Hooks/
672672└── Adapters/
673673 ├── StateProcessorAdapter.php
674674 └── ContinuationCriteriaAdapter.php
675- // @doctest id="b442 "
675+ // @doctest id="85c1 "
676676```
0 commit comments