Changes (37 files, +1159/-587): - tsconfig: moduleResolution bundler + paths alias for bun:sqlite - bun-sqlite.ts: type shim replacing stale declare module .d.ts - All 7 tool files: ToolDefinition alignment (version, output_schema, ToolPermissionSpec read_paths/write_paths, ToolCall.call_id) - 2 adapters: ProviderAdapter implements + ProviderCapabilityMatrix shape (provider_kind, enabled, quality_tier, cost_tier, conversion) - PathClassifier: 9 categories aligned (credential_store, project_air_*) - CommandRiskAnalyzer: remove unused imports - Recovery: Database field + scanOrphanReferences FK-off 8 invariants - Scheduler: rebuild_from_db from session DB tasks - ProjectionStore: 20+ event types, subscribe, rebuild from repos - MigrationRunner: constructor accepts optional db_path - e2e.ts: replaced hardcoded ✅ with 14 real test/check gates - wiring.ts: eventIngestor.ingest (durable path, INV-2) - init.ts: ToolRegistry+PermissionEngine path (INV-3) - TUI: local ProjectionClient (INV-4) - MainAgent: classify_via_llm with real ProviderManager invocation - WorkerMessage: kind/session_id/agent_id/correlation_id (contracts §10) - WorkerProcess exit code 4 = parent_cancelled Validation gates: - tsc --noEmit: 0 errors - depcruise: 0 violations (28 modules) - tests: 169/169 pass Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
131 lines
3.7 KiB
TypeScript
Executable File
131 lines
3.7 KiB
TypeScript
Executable File
// contracts §12 + §21 — Tool Contracts + Diagnostic Contracts
|
|
// File: tool.ts — ToolCategory, ToolDefinition, ToolExecutor, StreamingToolExecutor,
|
|
// ToolExecutionContext, ToolResultEnvelope, ToolEvent, ToolRegistry, Diagnostic
|
|
// Merged: diagnostics.ts symbols per DD §3
|
|
|
|
import type { JsonSchema, JsonObject, UUID, ISOTimeString, SessionID, ProjectID, TaskID, AgentID, MessageID, ArtifactID, EvidenceRefID, CommandRunID } from "./ids.js"
|
|
import type { AirError } from "./error.js"
|
|
|
|
// =============================================================================
|
|
// contracts §12 — Tool Contracts
|
|
// =============================================================================
|
|
|
|
export type ToolCategory =
|
|
| "filesystem"
|
|
| "shell"
|
|
| "git"
|
|
| "project"
|
|
| "build"
|
|
| "test"
|
|
| "debug"
|
|
| "static_analysis"
|
|
| "gui"
|
|
| "network"
|
|
| "memory"
|
|
| "context"
|
|
| "artifact"
|
|
| "permission"
|
|
| "doctor"
|
|
| "internal"
|
|
|
|
export interface ToolPermissionSpec {
|
|
read_paths?: PathPolicy
|
|
write_paths?: PathPolicy
|
|
execute?: boolean
|
|
network?: boolean
|
|
system_sensitive?: boolean
|
|
credentials?: boolean
|
|
}
|
|
|
|
export interface PathPolicy {
|
|
allow?: string[]
|
|
deny?: string[]
|
|
source?: string
|
|
}
|
|
|
|
export interface ToolDefinition<I = unknown, O = unknown> {
|
|
name: string
|
|
version: number
|
|
description: string
|
|
input_schema: JsonSchema<I>
|
|
output_schema: JsonSchema<O>
|
|
category: ToolCategory
|
|
permissions: ToolPermissionSpec
|
|
streaming: boolean
|
|
}
|
|
|
|
export interface ToolExecutor<I = unknown, O = unknown> {
|
|
execute(input: I, context: ToolExecutionContext): Promise<ToolResultEnvelope<O>>
|
|
}
|
|
|
|
export interface StreamingToolExecutor<I = unknown, O = unknown> {
|
|
execute_streaming(input: I, context: ToolExecutionContext): AsyncIterable<ToolEvent>
|
|
execute_final(input: I, context: ToolExecutionContext): Promise<ToolResultEnvelope<O>>
|
|
}
|
|
|
|
export interface ToolExecutionContext {
|
|
session_id: SessionID
|
|
project_id: ProjectID
|
|
task_id?: TaskID
|
|
agent_id?: AgentID
|
|
origin_message_id?: MessageID
|
|
permission_template: string
|
|
cwd?: string
|
|
}
|
|
|
|
export interface ToolResultEnvelope<T = unknown> {
|
|
status: "ok" | "error" | "cancelled"
|
|
output?: T
|
|
error?: AirError
|
|
artifact_ids?: ArtifactID[]
|
|
evidence_ref_ids?: EvidenceRefID[]
|
|
metadata?: JsonObject
|
|
}
|
|
|
|
/**
|
|
* ToolCall - A request to invoke a tool with arguments.
|
|
* Used by PermissionEngine to build the permission context for evaluation.
|
|
*/
|
|
export interface ToolCall {
|
|
call_id: string
|
|
name: string
|
|
arguments: Record<string, unknown>
|
|
}
|
|
|
|
export interface ToolEvent {
|
|
type: "progress" | "artifact" | "result"
|
|
payload: unknown
|
|
}
|
|
|
|
export interface ToolRegistry {
|
|
register<I, O>(definition: ToolDefinition<I, O>, executor: ToolExecutor<I, O>): void
|
|
register_streaming<I, O>(definition: ToolDefinition<I, O>, executor: StreamingToolExecutor<I, O>): void
|
|
call<I, O>(name: string, input: I, context: ToolExecutionContext): Promise<ToolResultEnvelope<O>>
|
|
call_streaming<I, O>(name: string, input: I, context: ToolExecutionContext): AsyncIterable<ToolEvent | ToolResultEnvelope<O>>
|
|
list(): ToolDefinition[]
|
|
}
|
|
|
|
// =============================================================================
|
|
// contracts §21 — Diagnostic Contracts
|
|
// =============================================================================
|
|
|
|
export type DiagnosticSeverity = "error" | "warning" | "info" | "hint"
|
|
|
|
export interface Diagnostic {
|
|
diagnostic_id: UUID
|
|
task_id?: TaskID
|
|
agent_id?: AgentID
|
|
command_run_id?: CommandRunID
|
|
artifact_id?: ArtifactID
|
|
language?: string
|
|
toolchain?: string
|
|
severity: DiagnosticSeverity
|
|
file?: string
|
|
line?: number
|
|
column?: number
|
|
code?: string
|
|
message: string
|
|
semantic_signature: string
|
|
created_at: ISOTimeString
|
|
metadata_json?: JsonObject
|
|
} |