Files
bvandeusen 8fe571e175
CI & Build / Python lint (push) Successful in 3s
CI & Build / TypeScript typecheck (push) Successful in 33s
CI & Build / Python tests (push) Successful in 51s
CI & Build / Build & push image (push) Successful in 1m0s
feat(plugin): resolve session project from git remote, not a pinned project_id
The SessionStart hook asked for a project_id via plugin userConfig, which pins
one install to a single project — wrong for an operator working across many
repos/projects. Resolve the active project server-side from the working repo's
git remote instead (a stable identifier, not a dir-name guess).

- repo_bindings table (migration 0064) + RepoBinding model: (user, repo_key) ->
  project, FKs CASCADE.
- services/repo_bindings: normalize_repo_key collapses ssh/https/scp/creds/port/
  .git to host/owner/repo; resolve/set/list/delete.
- GET /api/plugin/context takes ?repo=<remote>; unbound repo -> a "bind this
  repo" hint with a ready bind_repo() call. project_id kept as manual override.
- MCP tools: bind_repo / list_repo_bindings / unbind_repo.
- Hook sends ?repo=$(git remote get-url origin) URL-encoded; all project_id
  handling removed. plugin.json drops the project_id userConfig (0.1.2 -> 0.1.3).
- Tests: normalize equivalence classes + unbound-hint rendering.

Refs task 755 (Scribe-as-plugin push channel).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 01:33:58 -04:00

59 lines
1.7 KiB
Python

"""repo -> project bindings
Revision ID: 0064
Revises: 0063
Create Date: 2026-06-10
Maps a git repository (by its normalized remote, `repo_key`) to the Scribe
project it represents, so the SessionStart hook can resolve the active project
from the working repo instead of a project id pinned in plugin config. FKs
CASCADE so deleting a user or project removes the stale binding automatically.
"""
from alembic import op
import sqlalchemy as sa
revision = "0064"
down_revision = "0063"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"repo_bindings",
sa.Column("id", sa.BigInteger(), primary_key=True, autoincrement=True),
sa.Column(
"user_id",
sa.BigInteger(),
sa.ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column(
"project_id",
sa.BigInteger(),
sa.ForeignKey("projects.id", ondelete="CASCADE"),
nullable=False,
),
sa.Column("repo_key", sa.Text(), nullable=False),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.DateTime(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.UniqueConstraint("user_id", "repo_key", name="uq_repo_bindings_user_repo"),
)
op.create_index("ix_repo_bindings_user_id", "repo_bindings", ["user_id"])
def downgrade() -> None:
op.drop_index("ix_repo_bindings_user_id", table_name="repo_bindings")
op.drop_table("repo_bindings")