docs: add Claude AI assistant rules and configuration
Add comprehensive rule documentation for AI-assisted development covering authentication surfaces, outbound-call safety invariants, and other project conventions to guide Claude's understanding of critical system behaviors.
This commit is contained in:
@@ -14,6 +14,7 @@ from sqlalchemy import (
|
||||
Column,
|
||||
DateTime,
|
||||
Float,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
@@ -153,6 +154,48 @@ class RecordingRecord(Base):
|
||||
return f"<Recording {self.id} call={self.call_id} {self.path}>"
|
||||
|
||||
|
||||
class User(Base):
|
||||
"""An SSO-provisioned identity. The gateway is owner-only: the single
|
||||
owner is the user whose `name` matches settings.owner_name; everyone else
|
||||
is created on first login but reaches nothing (403 on every surface)."""
|
||||
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(String, primary_key=True) # uuid4().hex, set in Python
|
||||
name = Column(String, nullable=False) # Casdoor username — owner-match key
|
||||
display_name = Column(String, nullable=True) # Casdoor display name (UI only)
|
||||
email = Column(String, nullable=True, unique=True)
|
||||
casdoor_sub = Column(String, nullable=True, unique=True) # OIDC subject claim
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<User {self.id} {self.name}>"
|
||||
|
||||
|
||||
class PersonalAccessToken(Base):
|
||||
"""Long-lived bearer token for API/MCP clients (Claude Desktop, Cline)
|
||||
that can't refresh a JWT. Plaintext is shown once at creation; only the
|
||||
SHA-256 hash is persisted. Soft-revoked by setting revoked_at."""
|
||||
|
||||
__tablename__ = "personal_access_tokens"
|
||||
|
||||
id = Column(String, primary_key=True) # uuid4().hex
|
||||
user_id = Column(
|
||||
String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
name = Column(String, nullable=False)
|
||||
token_hash = Column(String, nullable=False, unique=True, index=True)
|
||||
token_prefix = Column(String, nullable=False) # for display, not a secret
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
last_used_at = Column(DateTime, nullable=True)
|
||||
expires_at = Column(DateTime, nullable=True)
|
||||
revoked_at = Column(DateTime, nullable=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<PersonalAccessToken {self.id} user={self.user_id}>"
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Engine & Session
|
||||
# ============================================================
|
||||
|
||||
55
db/migrations/versions/a1b2c3d4e5f6_users_and_pats.py
Normal file
55
db/migrations/versions/a1b2c3d4e5f6_users_and_pats.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""users and personal access tokens
|
||||
|
||||
Revision ID: a1b2c3d4e5f6
|
||||
Revises: 5187577efc23
|
||||
Create Date: 2026-07-22 00: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, None] = '5187577efc23'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.String(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('display_name', sa.String(), nullable=True),
|
||||
sa.Column('email', sa.String(), nullable=True),
|
||||
sa.Column('casdoor_sub', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('email'),
|
||||
sa.UniqueConstraint('casdoor_sub')
|
||||
)
|
||||
op.create_table('personal_access_tokens',
|
||||
sa.Column('id', sa.String(), nullable=False),
|
||||
sa.Column('user_id', sa.String(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=False),
|
||||
sa.Column('token_hash', sa.String(), nullable=False),
|
||||
sa.Column('token_prefix', sa.String(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('last_used_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('expires_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('revoked_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('token_hash')
|
||||
)
|
||||
op.create_index(op.f('ix_personal_access_tokens_token_hash'), 'personal_access_tokens', ['token_hash'], unique=True)
|
||||
op.create_index(op.f('ix_personal_access_tokens_user_id'), 'personal_access_tokens', ['user_id'], unique=False)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index(op.f('ix_personal_access_tokens_user_id'), table_name='personal_access_tokens')
|
||||
op.drop_index(op.f('ix_personal_access_tokens_token_hash'), table_name='personal_access_tokens')
|
||||
op.drop_table('personal_access_tokens')
|
||||
op.drop_table('users')
|
||||
Reference in New Issue
Block a user