M5:百工与司命——能力注册表、授契行契请命、禁域裁决与观察标证
- 百工域 domains/baigong:capabilities(统一能力契约:执行类型 builtin/qiankun/mcp/http + 四维风险标注 + 来源版本)、mandates(授契 grant / 行契 charter 预算时间窗,撤销立即生效)、tool_calls(净化摘要 + 观察标证);请命复用 pending_confirmations 加 expires_at/brief_json(超时=拒绝执行 HJ-1302,六要素说明) - 司命裁决器 siming.py:四维取最高档(能力/数据/后果/情境);禁域为代码常量不可配置(递归删根/格式化/写裸设备/fork 炸弹、file:// 协议、密钥材料外发)——专项测试断言恶意标注与篡改对象仍拒 HJ-1301 - 执行链:禁域→裁决(HJ-1303 未授契拒且双留痕)→请命→执行(乾坤经 SandboxClient HMAC;MCP 经 call_tool;内置无副作用)→净化标证(观察非事实,敏感遮蔽+体量截断)→行动账 - MCP 登记/启停/刷新自动派生与撤下 capabilities(博闻登记接入点);内置能力种子(echo/datetime/qiankun.shell/web.fetch) - 端点:/capabilities /mandates /petitions /tool-calls + /tools 兼容投影;前端百工页四区(能力目录四维标注/授契行契/请命批准拒绝/行动账观察标证) - 退役:modules/safety|skills|tool_runtime|agent、application/tool_runtime、services/skills|safety、tool_policies/skills/model_endpoint_overrides 表(迁移 006)、前端 SkillManager/ToolsConsole/旧 tools 页 - 验收(test_baigong_siming 四用例):未授契被拒留痕、请命超时不执行、禁域不可关闭、结果为观察不入忆;后端 454、前端 220、BFF 4、神识 5 包全绿(2 个预存环境失败不变)
This commit is contained in:
1 parent
144415247e
commit
684261f4b4
97 files changed
+3075
-5554
No files matched your search
@@ -0,0 +1,153 @@
|
||||
"""百工域_能力注册表_授契行契_调用记录_请命超时改造_退役旧策略与端点覆盖表
|
||||
|
||||
Revision ID: 006
|
||||
Revises: 005
|
||||
Create Date: 2026-08-27 18:52:47.720303
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '006'
|
||||
down_revision: Union[str, Sequence[str], None] = '005'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('capabilities',
|
||||
sa.Column('id', sa.String(length=80), nullable=False),
|
||||
sa.Column('name', sa.String(length=120), nullable=False),
|
||||
sa.Column('owner_scope', sa.String(length=80), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=False),
|
||||
sa.Column('executor_type', sa.String(length=20), nullable=False),
|
||||
sa.Column('executor_ref', sa.String(length=200), nullable=False),
|
||||
sa.Column('params_schema_json', sa.Text(), nullable=False),
|
||||
sa.Column('risk_dims_json', sa.Text(), nullable=False),
|
||||
sa.Column('data_scope', sa.Text(), nullable=False),
|
||||
sa.Column('destinations', sa.Text(), nullable=False),
|
||||
sa.Column('source', sa.String(length=20), nullable=False),
|
||||
sa.Column('version', sa.String(length=40), nullable=False),
|
||||
sa.Column('consent_mode', sa.String(length=10), nullable=False),
|
||||
sa.Column('enabled', sa.Boolean(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_capabilities_owner_scope'), 'capabilities', ['owner_scope'], unique=False)
|
||||
op.create_index('uq_capabilities_owner_name', 'capabilities', ['owner_scope', 'name'], unique=True)
|
||||
op.create_table('mandates',
|
||||
sa.Column('id', sa.String(length=80), nullable=False),
|
||||
sa.Column('owner_scope', sa.String(length=80), nullable=False),
|
||||
sa.Column('character_id', sa.String(length=80), nullable=True),
|
||||
sa.Column('capability_id', sa.String(length=80), nullable=False),
|
||||
sa.Column('kind', sa.String(length=10), nullable=False),
|
||||
sa.Column('scope_json', sa.JSON(), nullable=False),
|
||||
sa.Column('expires_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('budget_total', sa.Integer(), nullable=False),
|
||||
sa.Column('budget_used', sa.Integer(), nullable=False),
|
||||
sa.Column('status', sa.String(length=20), nullable=False),
|
||||
sa.Column('granted_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('revoked_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['capability_id'], ['capabilities.id'], ),
|
||||
sa.ForeignKeyConstraint(['character_id'], ['characters.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_mandates_capability_id'), 'mandates', ['capability_id'], unique=False)
|
||||
op.create_index(op.f('ix_mandates_character_id'), 'mandates', ['character_id'], unique=False)
|
||||
op.create_index(op.f('ix_mandates_owner_scope'), 'mandates', ['owner_scope'], unique=False)
|
||||
op.create_index(op.f('ix_mandates_status'), 'mandates', ['status'], unique=False)
|
||||
op.create_table('tool_calls',
|
||||
sa.Column('id', sa.String(length=80), nullable=False),
|
||||
sa.Column('run_id', sa.String(length=80), nullable=True),
|
||||
sa.Column('character_id', sa.String(length=80), nullable=True),
|
||||
sa.Column('capability_id', sa.String(length=80), nullable=False),
|
||||
sa.Column('trace_id', sa.String(length=80), nullable=True),
|
||||
sa.Column('decision', sa.String(length=40), nullable=False),
|
||||
sa.Column('mandate_id', sa.String(length=80), nullable=True),
|
||||
sa.Column('status', sa.String(length=20), nullable=False),
|
||||
sa.Column('error_code', sa.String(length=40), nullable=True),
|
||||
sa.Column('input_digest', sa.Text(), nullable=False),
|
||||
sa.Column('output_digest', sa.Text(), nullable=False),
|
||||
sa.Column('evidence_json', sa.JSON(), nullable=False),
|
||||
sa.Column('duration_ms', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(['character_id'], ['characters.id'], ),
|
||||
sa.ForeignKeyConstraint(['run_id'], ['runs.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_tool_calls_capability_id'), 'tool_calls', ['capability_id'], unique=False)
|
||||
op.create_index(op.f('ix_tool_calls_character_id'), 'tool_calls', ['character_id'], unique=False)
|
||||
op.create_index(op.f('ix_tool_calls_created_at'), 'tool_calls', ['created_at'], unique=False)
|
||||
op.create_index(op.f('ix_tool_calls_run_id'), 'tool_calls', ['run_id'], unique=False)
|
||||
op.create_index(op.f('ix_tool_calls_trace_id'), 'tool_calls', ['trace_id'], unique=False)
|
||||
op.drop_index(op.f('ix_skills_status'), table_name='skills')
|
||||
op.drop_table('skills')
|
||||
op.drop_table('tool_policies')
|
||||
op.drop_table('model_endpoint_overrides')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('model_endpoint_overrides',
|
||||
sa.Column('logical_model_name', sa.VARCHAR(length=120), nullable=False),
|
||||
sa.Column('endpoint_name', sa.VARCHAR(length=120), nullable=False),
|
||||
sa.Column('base_url', sa.VARCHAR(length=500), nullable=True),
|
||||
sa.Column('api_key', sa.VARCHAR(length=500), nullable=True),
|
||||
sa.Column('status', sa.VARCHAR(length=40), nullable=True),
|
||||
sa.Column('weight', sa.INTEGER(), nullable=True),
|
||||
sa.Column('priority', sa.INTEGER(), nullable=True),
|
||||
sa.Column('created_at', sa.DATETIME(), nullable=False),
|
||||
sa.Column('updated_at', sa.DATETIME(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('logical_model_name', 'endpoint_name')
|
||||
)
|
||||
op.create_table('tool_policies',
|
||||
sa.Column('name', sa.VARCHAR(length=80), nullable=False),
|
||||
sa.Column('description', sa.TEXT(), nullable=False),
|
||||
sa.Column('risk_level', sa.VARCHAR(length=20), nullable=False),
|
||||
sa.Column('permission_policy', sa.VARCHAR(length=20), nullable=False),
|
||||
sa.Column('side_effect', sa.BOOLEAN(), nullable=False),
|
||||
sa.Column('audit_required', sa.BOOLEAN(), nullable=False),
|
||||
sa.Column('source', sa.VARCHAR(length=20), nullable=False),
|
||||
sa.Column('enabled', sa.BOOLEAN(), nullable=False),
|
||||
sa.Column('created_at', sa.DATETIME(), nullable=False),
|
||||
sa.Column('updated_at', sa.DATETIME(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('name')
|
||||
)
|
||||
op.create_table('skills',
|
||||
sa.Column('id', sa.VARCHAR(length=80), nullable=False),
|
||||
sa.Column('name', sa.VARCHAR(length=120), nullable=False),
|
||||
sa.Column('description', sa.TEXT(), nullable=False),
|
||||
sa.Column('trigger', sa.TEXT(), nullable=False),
|
||||
sa.Column('prompt_fragment', sa.TEXT(), nullable=False),
|
||||
sa.Column('tool_bindings_json', sa.TEXT(), nullable=False),
|
||||
sa.Column('risk_level', sa.VARCHAR(length=8), nullable=False),
|
||||
sa.Column('status', sa.VARCHAR(length=40), nullable=False),
|
||||
sa.Column('created_at', sa.DATETIME(), nullable=False),
|
||||
sa.Column('updated_at', sa.DATETIME(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_index(op.f('ix_skills_status'), 'skills', ['status'], unique=False)
|
||||
op.drop_index(op.f('ix_tool_calls_trace_id'), table_name='tool_calls')
|
||||
op.drop_index(op.f('ix_tool_calls_run_id'), table_name='tool_calls')
|
||||
op.drop_index(op.f('ix_tool_calls_created_at'), table_name='tool_calls')
|
||||
op.drop_index(op.f('ix_tool_calls_character_id'), table_name='tool_calls')
|
||||
op.drop_index(op.f('ix_tool_calls_capability_id'), table_name='tool_calls')
|
||||
op.drop_table('tool_calls')
|
||||
op.drop_index(op.f('ix_mandates_status'), table_name='mandates')
|
||||
op.drop_index(op.f('ix_mandates_owner_scope'), table_name='mandates')
|
||||
op.drop_index(op.f('ix_mandates_character_id'), table_name='mandates')
|
||||
op.drop_index(op.f('ix_mandates_capability_id'), table_name='mandates')
|
||||
op.drop_table('mandates')
|
||||
op.drop_index('uq_capabilities_owner_name', table_name='capabilities')
|
||||
op.drop_index(op.f('ix_capabilities_owner_scope'), table_name='capabilities')
|
||||
op.drop_table('capabilities')
|
||||
# ### end Alembic commands ###
|
||||
Reference in new issue
Block a user