Playbook Agent: runner, service, and barrel exports (7/8)

Draft
RA
5mo ago
+2970-0

Summary

Wires all components into the orchestrator and Coop integration layer. This is where it all comes together.

Part 7 of 8 — depends on #577 (JSON extractor).

playbookRunner.ts — core orchestrator

Pipeline:

  1. Load playbook from registry
  2. Execute baseline queries in parallel via IEvidenceStore
  3. Evaluate hard rules (deterministic, before LLM)
  4. Call LLM via ILLMAdapter (even when hard rule fires — for rationale)
  5. Extract structured verdict with JsonExtractor
  6. Override verdict if hard rule fired
  7. Compute grounded confidence via ConfidenceEngine
  8. Store immutable artifacts via IArtifactStore

Falls back to default label with low confidence on extraction failure.

playbookAgentService.ts — Coop integration

  • PlaybookAgentService wraps PlaybookRunner for MRT queue integration
  • Maps queue IDs to playbook IDs (per-queue config)
  • runForJob(): returns PlaybookResult | undefined
  • try/catch guard: playbook failure never blocks the MRT enqueue path
  • makePlaybookAgentService(): BottleJS-compatible factory

index.ts — barrel re-exports

All public types, functions, and classes exported from a single entry point.

playbookAgentService.test.ts — 3 integration tests

  • Returns undefined for unmapped queue
  • Full pipeline: hard rule overrides LLM, artifacts stored, evidence flattened
  • Returns undefined (not throw) when LLM adapter crashes

Test plan

  • npm test -- --testPathPattern=playbookAgentService passes (all 51 tests across 7 suites)

Depends on #577 JSON extractor. Merge #572, #573, #574, #575, #576, #577 first.

Summary by CodeRabbit

  • New Features
    • Investigation playbooks framework for automated evidence collection, structured verdicts, and artifact persistence
    • Deterministic hard-rule evaluation to override or short-circuit LLM decisions
    • Grounded confidence scoring with detailed factor breakdown and bucketed outputs
    • Query cataloging and playbook parsing/validation utilities; runtime interfaces for LLM/evidence/artifact adapters
  • Tests
    • Comprehensive unit tests covering confidence, hard rules, JSON verdict extraction, query catalog, loader, runner, and service behavior

Review Change Stack

Part of #659