import type { ToolSpec, ToolResult } from './tools/types.js'; import type { FacadeSpec, DetailTier, McpToolDefinition } from './facades/types.js'; import { type CircuitSnapshot } from './runtime/circuitBreaker.js'; /** * Optional context threaded through every dispatch call. * This is plumbing, not policy — the kernel passes it to handlers * but doesn't enforce it. decibel-agent passes agentId, runId, and * scope so coordinator logs, vector events, and provenance know * WHO did WHAT. */ export interface DispatchContext { /** Who is calling (e.g. "cymoril-code", "claude-code", "anonymous") */ agentId?: string; /** Vector run ID for tracing */ runId?: string; /** If this call was delegated from another agent's call */ parentCallId?: string; /** Project ID or "portfolio" */ scope?: string; /** Restrict dispatch to these facades only (undefined = all allowed) */ allowedFacades?: string[]; /** License tier — when set, pro facades are rejected for 'core' tier */ tier?: 'core' | 'pro' | 'apps'; /** * Which transport carried this call. Set by the adapter, never by the caller. * 'http' rejects facades marked localOnly — see FacadeSpec.localOnly. * * Unset means stdio: a context arriving without a transport came from an * in-process caller, and defaulting the ABSENT case to 'http' would break * every existing direct kernel consumer. The HTTP adapters set it explicitly. */ transport?: 'stdio' | 'http'; /** Engagement mode: 'suggest' | 'curate' | 'compose' */ engagementMode?: string; /** Identity of the calling user (Supabase access token / JWT, via X-User-Key) */ userKey?: string; /** Tenant org id (hq.orgs.id) for the multi-tenant store, via X-Org-Key */ orgId?: string; /** Request correlation ID (crypto.randomUUID) — set by client, threaded through events */ requestId?: string; } /** * What the last createKernel() call loaded, and what it refused. Surfaced on * /health so a rejected extension is visible without reading the daemon log. */ export declare function getExtensionDiagnostics(): { loaded: Array<{ name: string; version: string; tier: string; facades: string[]; }>; rejected: Array<{ entry: string; reason: string; }>; }; export interface DispatchEvent { type: 'dispatch' | 'result' | 'error'; facade?: string; action?: string; tool?: string; agentId: string; runId?: string; requestId?: string; timestamp: string; duration_ms?: number; success?: boolean; error?: string; } /** Single call in a batch request */ export interface BatchCall { facade: string; action: string; params?: Record; } /** Result of a single call within a batch */ export interface BatchResult { facade: string; action: string; result?: ToolResult; error?: string; /** * Machine-readable failure kind. Present only for STRUCTURAL failures — the * call never ran because nothing by that name is registered. A call that ran * and failed carries its failure in `result.isError` instead, which is a * different thing and must stay distinguishable: "this facade does not exist * here" and "this action returned an error" need different reactions from a * caller, and only the first is a configuration problem. */ code?: 'UNKNOWN_FACADE'; duration_ms: number; } export interface ToolKernel { /** All internal tool definitions (full registry, ~170 tools) */ tools: ToolSpec[]; /** Fast lookup by internal tool name */ toolMap: Map; /** Active facade definitions (filtered by pro tier) */ facades: FacadeSpec[]; /** Fast lookup by facade name */ facadeMap: Map; /** * Dispatch a tool call. Handles both: * - Facade calls: name="sentinel", args={ action: "create_issue", title: "...", ... } * - Direct calls: name="sentinel_create_issue", args={...} (backward compat) * - Legacy nested: name="sentinel", args={ action: "create_issue", params: {...} } */ dispatch(name: string, args: Record, context?: DispatchContext): Promise; /** * Dispatch multiple independent calls in parallel. Returns results in same order. * Errors are per-call — one failure doesn't abort others. */ batch(calls: BatchCall[], context?: DispatchContext): Promise; /** * Get MCP tool definitions for the tools/list response. * Returns facade definitions filtered by detail tier. */ getMcpToolDefinitions(tier?: DetailTier, opts?: { transport?: 'stdio' | 'http'; }): McpToolDefinition[]; /** Subscribe to dispatch events (dispatch, result, error) */ on(event: string, listener: (evt: DispatchEvent) => void): void; /** Unsubscribe from dispatch events (for SSE cleanup) */ off(event: string, listener: (evt: DispatchEvent) => void): void; /** * Circuits that are open or accumulating faults, keyed by facade. * Empty object means every facade is healthy. Surfaced on /health so a * degraded dependency is visible without reading the dispatch log. */ circuitSnapshot(): Record; /** Force a circuit closed (operator escape hatch, and test hygiene). */ resetCircuit(key?: string): void; /** Total internal tool count */ toolCount: number; /** Total facade count */ facadeCount: number; } /** * Coerce params that arrived as JSON strings but whose target tool's schema * declares them as object or array. Facade MCP definitions expose only * `{action}` with additionalProperties, so callers get no type info for * nested params and often serialize them (ISS-0112, ISS-0116). A parse * failure or type mismatch leaves the value untouched — the tool's own * validation stays the source of truth for errors. */ export declare function coerceStringifiedParams(params: Record, schema: ToolSpec['definition']['inputSchema']): Record; /** * Create the tool kernel. Call once at startup — both transports share it. */ export declare function createKernel(): Promise; //# sourceMappingURL=kernel.d.ts.map