P0-P8: Full V1.0.0 Alpha implementation + audit reports
Implements 123 tasks across 9 phases (T-001..T-809) totaling 146 source files. Monorepo (P0): - 7-package Bun + Turborepo + TypeScript monorepo - dependency-cruiser enforcing 7 forbidden edges + 5 deep-import rules Contracts (P0): - 16 type files (ids/error/event/runtime/ipc/task/worker-result/tool/artifact/evidence/project/provider/permission/ui/capability/platform) Storage & Events (P1): - DatabaseManager + MigrationRunner (19 tables, 22 indexes, 5 schema_meta seeds) - 16 repositories (Repository<T,I,U> pattern, INV-1 status columns via EventStore.project only) - EventSchemaRegistry (54 durable + 7 ephemeral), EventStore, EventBus, EventIngestor - Project/Session/Artifact/Evidence stores + 8-step Recovery Tools & Permission (P2): - PathClassifier (8 categories), CommandRiskAnalyzer (10 categories), SecretRedactor - PermissionEngine 6-layer evaluation (capability→profile→task_scope→risk→credential→user_prompt) - ToolRegistry with 20+ tools across fs/shell/git/project/artifact/context/permission/doctor - CapabilityManifestValidator + CapabilityRegistry LLM & Context (P3): - ModelConfigLoader, CapabilityMatrix, AnthropicCanonicalConverter - AnthropicAdapter + OpenAICompatibleAdapter - ProviderManager facade - PromptLayerLoader (L0/L1/L3/L5), CompactionPolicy, ContextAssembler Worker IPC & Scheduler (P4): - WorkerProtocol (NDJSON), WorkerProcess (exit codes 0-5), WorkerManager (spawn/handshake) - WorkerRuntime (INV-3: IPC only, no direct fs/shell/SQLite) - 5 worker roles (Executor/Reviewer/Debugger/Compactor/ExperienceMiner) - TaskGraph, WavePlanner, RetryPlanner, AgentMonitor, WorkspaceManager - Scheduler (state machine), 8-step Recovery C++ Toolchain (P5): - DiagnosticParser, CppProjectDetector, CMakeConfigurator, CppBuilder - CppTestRunner, CppcheckRunner, ClangdClient - CppToolRegistrar + capability manifest Projection & TUI (P6): - ProjectionStore (hydrate/apply/snapshot/subscribe) - TuiApp + 8 components (Session/Task/Agent/Tool/Diff/Evidence/Permission/Blocker/Hud) - ProjectionClient in-process ref Agents & Knowledge (P7): - MainAgent, ArchitectureDesigner - DebugKnowledgeStore + LearnedMemoryStore (single-writer, outbox model) - Role integration wiring CLI & Doctor & Release (P8): - Logger + DeveloperLogEncryptor (AES-256-GCM) - DoctorService (self_bootstrap first) - RuntimeApp + ServiceRegistry - 11 CLI commands: run/init/doctor/provider/resume/compact/history/session/restore/e2e/release - CliEntrypoint + air<TODO> Audit (in AirPlan/docs/): - Deepseek开发阶段审计.md (97 findings) - Opus开发阶段审计.md (140+ findings, 18 P0 blockers) - MiniMaxM3开发阶段审计.md (18 P0 blockers, focuses on executability) - AirPlan/TODO.md (technical debt + 42 TODOs by phase) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
170
packages/runtime/src/storage/repositories/MessageDraftRepository.ts
Executable file
170
packages/runtime/src/storage/repositories/MessageDraftRepository.ts
Executable file
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* MessageDraftRepository - CRUD + upsert, delete_for_message for message_drafts table (§5)
|
||||
*
|
||||
* Implements Repository<MessageDraftRecord, MessageDraftInsert, MessageDraftUpdate>
|
||||
* per contracts §6.
|
||||
*
|
||||
* @module packages/runtime/src/storage/repositories/MessageDraftRepository
|
||||
*/
|
||||
|
||||
import type {
|
||||
Repository,
|
||||
TransactionHandle,
|
||||
SessionID,
|
||||
MessageID,
|
||||
ISOTimeString,
|
||||
} from '@aircoding/contracts'
|
||||
|
||||
import { DatabaseHandle } from '../MigrationRunner.js'
|
||||
import { assertEnumValues } from '../assertEnum.js'
|
||||
|
||||
// =============================================================================
|
||||
// Types - per db-schema §5
|
||||
// =============================================================================
|
||||
|
||||
export interface MessageDraftRecord {
|
||||
message_id: MessageID
|
||||
session_id: SessionID
|
||||
role: 'user' | 'assistant' | 'system' | 'tool'
|
||||
canonical_format: 'anthropic'
|
||||
partial_content_json: string
|
||||
status: 'streaming' | 'interrupted' | 'error'
|
||||
created_at: ISOTimeString
|
||||
updated_at: ISOTimeString
|
||||
metadata_json?: string
|
||||
}
|
||||
|
||||
export type MessageDraftInsert = Omit<MessageDraftRecord, 'message_id'> & {
|
||||
message_id?: MessageID
|
||||
}
|
||||
|
||||
export type MessageDraftUpdate = Partial<Omit<MessageDraftRecord, 'message_id' | 'session_id' | 'created_at'>>
|
||||
|
||||
// =============================================================================
|
||||
// MessageDraftRepository
|
||||
// =============================================================================
|
||||
|
||||
export class MessageDraftRepository implements Repository<MessageDraftRecord, MessageDraftInsert, MessageDraftUpdate> {
|
||||
private db: DatabaseHandle
|
||||
|
||||
constructor(db: DatabaseHandle) {
|
||||
this.db = db
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a draft by message ID.
|
||||
*/
|
||||
async get(message_id: MessageID, _tx?: TransactionHandle): Promise<MessageDraftRecord | undefined> {
|
||||
const stmt = this.db.prepare('SELECT * FROM message_drafts WHERE message_id = ?')
|
||||
const row = stmt.get(message_id) as MessageDraftRecord | undefined
|
||||
return row
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a new draft.
|
||||
*/
|
||||
async insert(record: MessageDraftInsert, _tx?: TransactionHandle): Promise<void> {
|
||||
// Validate enum columns (only status is a closed enum for message_drafts)
|
||||
assertEnumValues('message_drafts', {
|
||||
status: record.status,
|
||||
})
|
||||
|
||||
const stmt = this.db.prepare(`
|
||||
INSERT INTO message_drafts (
|
||||
message_id, session_id, role, canonical_format,
|
||||
partial_content_json, status, created_at, updated_at, metadata_json
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`)
|
||||
|
||||
stmt.run(
|
||||
record.message_id,
|
||||
record.session_id,
|
||||
record.role,
|
||||
record.canonical_format,
|
||||
record.partial_content_json,
|
||||
record.status,
|
||||
record.created_at,
|
||||
record.updated_at,
|
||||
record.metadata_json ?? null,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing draft.
|
||||
*/
|
||||
async update(message_id: MessageID, patch: MessageDraftUpdate, _tx?: TransactionHandle): Promise<void> {
|
||||
// Validate enum columns if present (only status is a closed enum for message_drafts)
|
||||
if (patch.status !== undefined) {
|
||||
assertEnumValues('message_drafts', { status: patch.status })
|
||||
}
|
||||
|
||||
const fields: string[] = []
|
||||
const values: unknown[] = []
|
||||
|
||||
if (patch.partial_content_json !== undefined) {
|
||||
fields.push('partial_content_json = ?')
|
||||
values.push(patch.partial_content_json)
|
||||
}
|
||||
if (patch.status !== undefined) {
|
||||
fields.push('status = ?')
|
||||
values.push(patch.status)
|
||||
}
|
||||
if (patch.updated_at !== undefined) {
|
||||
fields.push('updated_at = ?')
|
||||
values.push(patch.updated_at)
|
||||
}
|
||||
if (patch.metadata_json !== undefined) {
|
||||
fields.push('metadata_json = ?')
|
||||
values.push(patch.metadata_json)
|
||||
}
|
||||
|
||||
if (fields.length === 0) {
|
||||
return // Nothing to update
|
||||
}
|
||||
|
||||
values.push(message_id)
|
||||
const stmt = this.db.prepare(`UPDATE message_drafts SET ${fields.join(', ')} WHERE message_id = ?`)
|
||||
stmt.run(...values)
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Extra methods
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Upsert a draft - insert or replace existing.
|
||||
*/
|
||||
async upsert(record: MessageDraftRecord, _tx?: TransactionHandle): Promise<void> {
|
||||
// Validate enum columns (only status is a closed enum for message_drafts)
|
||||
assertEnumValues('message_drafts', {
|
||||
status: record.status,
|
||||
})
|
||||
|
||||
const stmt = this.db.prepare(`
|
||||
INSERT OR REPLACE INTO message_drafts (
|
||||
message_id, session_id, role, canonical_format,
|
||||
partial_content_json, status, created_at, updated_at, metadata_json
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`)
|
||||
|
||||
stmt.run(
|
||||
record.message_id,
|
||||
record.session_id,
|
||||
record.role,
|
||||
record.canonical_format,
|
||||
record.partial_content_json,
|
||||
record.status,
|
||||
record.created_at,
|
||||
record.updated_at,
|
||||
record.metadata_json ?? null,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete draft for a specific message.
|
||||
*/
|
||||
async delete_for_message(message_id: MessageID, _tx?: TransactionHandle): Promise<void> {
|
||||
const stmt = this.db.prepare('DELETE FROM message_drafts WHERE message_id = ?')
|
||||
stmt.run(message_id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user