/** * PluginAdapter — OpenClaw hook registration & event dispatch (arc42 §5.7). * * Registers three hooks: before_prompt_build, before_tool_call, subagent_ended. * Implements SEVO tag protocol, bridge.js concept (HostAdapter interface), * and degradation strategy (CLI-only mode when no host is available). * * AC-19.10: subagent_ended hook handler programmatically calls host API to * dispatch next-stage tasks (instead of injecting prompt text). * AC-19.11: Parallel stages are triggered in one batch. * AC-19.12: Endgame delivery chain is configurable. * AC-19.1: Review pass triggers endgame delivery chain. * AC-19.13: Single-agent users get role knowledge injection. * * Connects ComplianceRouter (before_tool_call) and RoleKnowledgeInjector * (before_prompt_build) to the hook lifecycle. */ import type { StageId, ArtifactRef } from '../types/index.js'; import type { ComplianceRouter, ComplianceTaskContext, ComplianceResult } from '../compliance/index.js'; import type { SevoHostAdapter } from '../adapter/host-adapter.js'; import type { EndgameDeliveryConfig } from '../config.js'; import { RoleKnowledgeInjector } from '../knowledge/role-knowledge-injector.js'; import type { PipelineState } from '../types/index.js'; /** Format: sevo::: */ export interface SevoTag { pipelineId: string; stageId: StageId; attempt: number; } /** Parse a SEVO tag string. Returns null if format is invalid. */ export declare function parseSevoTag(label: string): SevoTag | null; /** Create a SEVO tag string from components. */ export declare function createSevoTag(pipelineId: string, stageId: StageId, attempt: number): string; /** * Minimal interface that any host environment must implement * to integrate with SEVO's PluginAdapter. * This decouples SEVO from any specific runtime (OpenClaw, standalone, etc.) */ export interface HostBridge { /** Register a hook handler. Returns a dispose function. */ registerHook(hookName: HookName, handler: HookHandler): () => void; /** Get active pipeline IDs from the host's perspective. */ getActivePipelines(): string[]; /** Signal stage completion to the pipeline engine. */ handleStageComplete(pipelineId: string, stageId: StageId, result: StageCompletePayload): void; /** Get the current stage for a pipeline. */ getCurrentStage(pipelineId: string): StageId | null; /** Get input artifacts for the current stage. */ getStageInputArtifacts(pipelineId: string, stageId: StageId): ArtifactRef[]; } export type HookName = 'before_prompt_build' | 'before_tool_call' | 'subagent_ended'; export type HookHandler = (context: HookContext) => HookResult | Promise; export interface HookContext { hookName: HookName; /** For before_tool_call: the tool being called */ toolName?: string; /** For before_tool_call: tool call arguments */ toolArgs?: Record; /** For subagent_ended: the label of the completed subagent */ label?: string; /** For subagent_ended: the output/result */ output?: string; /** For before_prompt_build: current prompt context */ promptContext?: Record; } export interface HookResult { /** Prompt text to inject (before_prompt_build) */ promptInjection?: string; /** Modified tool args (before_tool_call) */ modifiedArgs?: Record; /** Whether to proceed with the original action */ proceed: boolean; /** Advisory message for the host */ advisory?: string; } export interface StageCompletePayload { outcome: 'passed' | 'failed'; artifacts: ArtifactRef[]; failureReason?: string; } export interface PluginAdapterOptions { bridge?: HostBridge; complianceRouter?: ComplianceRouter; knowledgeInjector?: RoleKnowledgeInjector; /** If true, operate in CLI-only mode (no hook registration). */ cliOnly?: boolean; /** Host adapter for programmatic task spawning (AC-19.10). */ hostAdapter?: SevoHostAdapter; /** Endgame delivery chain configuration (AC-19.12). */ endgameDelivery?: Partial; /** Whether this is a single-agent environment (AC-19.13). */ singleAgent?: boolean; /** Callback to retrieve pipeline state for parallel branch detection. */ getPipelineState?: (pipelineId: string) => PipelineState | null; } /** * PluginAdapter orchestrates SEVO's integration with a host environment. * * In hosted mode (bridge provided): registers hooks, injects prompts, handles events. * In CLI-only mode (no bridge): provides direct method access without hooks. * * AC-19.10: When hostAdapter.supportsSpawn() is true, subagent_ended triggers * programmatic dispatch via hostAdapter.spawnTask/spawnParallelTasks. * When supportsSpawn() is false, falls back to prompt injection (backward compat). */ export declare class PluginAdapter { private readonly bridge; private readonly complianceRouter; private readonly knowledgeInjector; private readonly cliOnly; private readonly hostAdapter; private readonly endgameConfig; private readonly singleAgent; private readonly getPipelineState; private readonly disposers; private registered; constructor(options?: PluginAdapterOptions); /** * Register all three hooks with the host bridge. * No-op in CLI-only mode. */ register(): void; /** Unregister all hooks. */ dispose(): void; /** Whether hooks are currently registered. */ isRegistered(): boolean; /** Whether operating in CLI-only (degraded) mode. */ isCliOnly(): boolean; /** * before_prompt_build: Inject SEVO Auto-Advance directive + stage principles. * Connects RoleKnowledgeInjector to inject role knowledge. */ handleBeforePromptBuild(context: HookContext): HookResult; /** * before_tool_call: Inject SEVO tag into sessions_spawn label; * run ComplianceRouter check for unmanaged tasks. */ handleBeforeToolCall(context: HookContext): Promise; /** * subagent_ended: Parse SEVO tag from label, signal stage completion * to PipelineEngine via bridge, then programmatically dispatch next stage (AC-19.10). * * Dispatch strategy: * 1. If hostAdapter.supportsSpawn() → programmatic dispatch via API * 2. Otherwise → prompt injection fallback (backward compatible) * * AC-19.1: If completed stage is 'review' with outcome 'passed', * triggers the endgame delivery chain. * AC-19.11: If next stages are parallel, dispatches all at once. */ handleSubagentEnded(context: HookContext): HookResult; /** * Dispatch next activatable stages after a stage completes. * If multiple stages are activatable (parallel fork), dispatches all at once (AC-19.11). */ private dispatchNextStages; /** * Endgame Delivery Chain (AC-19.1, AC-19.12). * Triggered when review passes. Dispatches: README → bump → publish → gap scan. * Each step is configurable via endgameDelivery config. */ private triggerEndgameChain; /** Build spawn options for a stage dispatch, including role knowledge for single-agent (AC-19.13). */ private buildSpawnOptions; /** Build a task prompt for dispatching a stage. */ private buildStageTaskPrompt; /** Get appropriate timeout for a stage. */ private getStageTimeout; /** * Directly inject principles for a stage (bypasses hook system). * Useful in CLI-only mode. */ injectPrinciples(stageId: StageId): string; /** * Directly evaluate compliance for a task context. * Useful in CLI-only mode. */ evaluateCompliance(taskContext: ComplianceTaskContext): Promise; /** * Create a SEVO tag for a given pipeline stage. */ createTag(pipelineId: string, stageId: StageId, attempt?: number): string; /** * Parse a SEVO tag from a label string. */ parseTag(label: string): SevoTag | null; } //# sourceMappingURL=plugin-adapter.d.ts.map