feat(integration): prepaid billing, engine UI, credits console, direct tasks, v2 final

- Prepaid credit system: org wallet, debit on usage, chat gate, admin credit console
- Engine UI: /manager, /tasks, /tasks/[id], /workforce, /dashboard, /traces pages
- Direct task creation (HTTP POST /tasks, MCP tasks_create) at pending_manager_review
- Pause/resume/cancel/answer actions in engine API and UI
- Employee cap (7 per org default), review pipeline guard (active reviewer required)
- Scheduler: wide window prevents org starvation; archived employees excluded from cap
- Tenant isolation: project-id cross-org 404, engine never uses another tenant's sandbox
- Order route fix: manager built with pipeline states + employee profiles
- Contract extension: ModelGrantPort.get_org_policy with DefaultOrgPolicy
- Engine event types in @agy/contracts (task.step, task.gate, run.log, run.tool, team.changed)
- api-engine.ts typed client; api-credit.ts client
- Alembic migration c4d5e6f7a8b9: prepaid credit + engine UI tables
- 859 tests passed, 1 skipped; ruff/mypy/tsc/eslint/vitest all green

Refs: PLAN-v2.md §9 (T1–T43), todo-v2-final.md
This commit is contained in:
mjalmoudy94
2026-10-14 23:19:05 +03:30
parent fef5a9deab
commit d532929189
117 changed files with 13119 additions and 640 deletions
@@ -0,0 +1,82 @@
"""prepaid credit ledger, task diff/merged sha, default employee cap 7
Revision ID: c4d5e6f7a8b9
Revises: b9c0d1e2f3a4
Create Date: 2026-10-14 12:00:00.000000
Owned by the v2 prepaid-credit workstream (todo-v2-final.md T1, decisions D-A and
D-B). ``credit_transactions`` is the wallet history; ``usage_event_id`` is unique,
so one usage row debits the wallet at most once. ``last_diff`` and ``merged_sha``
back the task page. The default employee cap moves from 5 to 7.
"""
from __future__ import annotations
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "c4d5e6f7a8b9"
down_revision: str | None = "b9c0d1e2f3a4"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
def upgrade() -> None:
op.create_table(
"credit_transactions",
sa.Column("id", sa.String(length=32), primary_key=True),
sa.Column(
"organization_id",
sa.String(length=32),
sa.ForeignKey("organizations.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("kind", sa.String(length=16), nullable=False),
sa.Column("amount", sa.Float(), nullable=False),
sa.Column("balance_after", sa.Float(), nullable=False),
sa.Column("reason", sa.String(length=500), nullable=False, server_default=""),
sa.Column("actor_user_id", sa.String(length=32), nullable=True),
sa.Column("usage_event_id", sa.String(length=32), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
sa.UniqueConstraint("usage_event_id", name="uq_credit_transactions_usage_event_id"),
)
op.create_index(
"ix_credit_transactions_organization_id", "credit_transactions", ["organization_id"]
)
op.create_index(
"ix_credit_tx_org_created", "credit_transactions", ["organization_id", "created_at"]
)
with op.batch_alter_table("task_pipeline_state") as batch:
batch.add_column(sa.Column("last_diff", sa.Text(), nullable=False, server_default=""))
batch.add_column(
sa.Column("merged_sha", sa.String(length=64), nullable=False, server_default="")
)
with op.batch_alter_table("org_policies") as batch:
batch.alter_column(
"max_employees",
existing_type=sa.Integer(),
existing_nullable=False,
server_default="7",
)
def downgrade() -> None:
with op.batch_alter_table("org_policies") as batch:
batch.alter_column(
"max_employees",
existing_type=sa.Integer(),
existing_nullable=False,
server_default="5",
)
with op.batch_alter_table("task_pipeline_state") as batch:
batch.drop_column("merged_sha")
batch.drop_column("last_diff")
op.drop_index("ix_credit_tx_org_created", table_name="credit_transactions")
op.drop_index("ix_credit_transactions_organization_id", table_name="credit_transactions")
op.drop_table("credit_transactions")