forked from Rockachopa/Timmy-time-dashboard
Implement two foundational infrastructure pieces for the Morrowind integration: 1. Perception/Command Protocol (Issue #859): - Formal spec document with JSON schemas, API contracts, versioning strategy - Engine-agnostic design following the Falsework Rule - Pydantic v2 models (PerceptionOutput, CommandInput) for runtime validation 2. SQLite Command Log + Training Pipeline (Issue #855): - SQLAlchemy model for command_log table with full indexing - CommandLogger class with log_command(), query(), export_training_data() - TrainingExporter with chat-completion, episode, and instruction formats - Storage management (rotation/archival) utilities - Alembic migration for the new table Includes 39 passing tests covering schema validation, logging, querying, and export. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
"""Create command_log table
|
|
|
|
Revision ID: a1b2c3d4e5f6
|
|
Revises: 0093c15b4bbf
|
|
Create Date: 2026-03-21 12:00:00.000000
|
|
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
import sqlalchemy as sa
|
|
from alembic import op
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = "a1b2c3d4e5f6"
|
|
down_revision: Union[str, Sequence[str], None] = "0093c15b4bbf"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
op.create_table(
|
|
"command_log",
|
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
|
sa.Column("timestamp", sa.DateTime(), nullable=False),
|
|
sa.Column("command", sa.String(length=64), nullable=False),
|
|
sa.Column("params", sa.Text(), nullable=False, server_default="{}"),
|
|
sa.Column("reasoning", sa.Text(), nullable=False, server_default=""),
|
|
sa.Column(
|
|
"perception_snapshot", sa.Text(), nullable=False, server_default="{}"
|
|
),
|
|
sa.Column("outcome", sa.Text(), nullable=True),
|
|
sa.Column(
|
|
"agent_id",
|
|
sa.String(length=64),
|
|
nullable=False,
|
|
server_default="timmy",
|
|
),
|
|
sa.Column("episode_id", sa.String(length=128), nullable=True),
|
|
sa.Column("cell", sa.String(length=255), nullable=True),
|
|
sa.Column(
|
|
"protocol_version",
|
|
sa.String(length=16),
|
|
nullable=False,
|
|
server_default="1.0.0",
|
|
),
|
|
sa.Column("created_at", sa.DateTime(), nullable=False),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(
|
|
op.f("ix_command_log_timestamp"), "command_log", ["timestamp"], unique=False
|
|
)
|
|
op.create_index(
|
|
op.f("ix_command_log_command"), "command_log", ["command"], unique=False
|
|
)
|
|
op.create_index(
|
|
op.f("ix_command_log_agent_id"), "command_log", ["agent_id"], unique=False
|
|
)
|
|
op.create_index(
|
|
op.f("ix_command_log_episode_id"),
|
|
"command_log",
|
|
["episode_id"],
|
|
unique=False,
|
|
)
|
|
op.create_index(
|
|
op.f("ix_command_log_cell"), "command_log", ["cell"], unique=False
|
|
)
|
|
op.create_index(
|
|
"ix_command_log_cmd_cell", "command_log", ["command", "cell"], unique=False
|
|
)
|
|
op.create_index(
|
|
"ix_command_log_episode",
|
|
"command_log",
|
|
["episode_id", "timestamp"],
|
|
unique=False,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
op.drop_index("ix_command_log_episode", table_name="command_log")
|
|
op.drop_index("ix_command_log_cmd_cell", table_name="command_log")
|
|
op.drop_index(op.f("ix_command_log_cell"), table_name="command_log")
|
|
op.drop_index(op.f("ix_command_log_episode_id"), table_name="command_log")
|
|
op.drop_index(op.f("ix_command_log_agent_id"), table_name="command_log")
|
|
op.drop_index(op.f("ix_command_log_command"), table_name="command_log")
|
|
op.drop_index(op.f("ix_command_log_timestamp"), table_name="command_log")
|
|
op.drop_table("command_log")
|