Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 59 additions & 35 deletions .claude/skills/hugagent-backend-dev/references/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

```
Browser → Nginx (:3000 /api/ proxy) → FastAPI (api/app.py)
→ api/middleware/ (CORS → Logging → Error Handler)
→ api/routes/v1/*.py (路由层;注册表见 api/routes/v1/__init__.py)
→ api/middleware/ (CORS → Logging → Error Handler → license_gate)
→ api/routes/v1/*.py (路由层;CE 注册表 api/routes/v1/__init__.py,EE 注册表 edition_ee/routes/registry.py)
→ core/services/*.py (服务层 — 业务逻辑)
→ core/db/repository/ (仓库层 — 数据访问,按领域分文件)
→ core/db/models/ (ORM 包 → PostgreSQL/SQLite)
Expand All @@ -27,16 +27,16 @@ Browser → Nginx (:3000 /api/ proxy) → FastAPI (api/app.py)
│ - 幂等操作 (ensure_xxx) │
│ - 抛 AppException │
├─────────────────────────────────────────┤
│ Repository (core/db/repository/) │ ← 数据访问抽象(包,按领域分文件
│ Repository (core/db/repository/) │ ← 数据访问抽象(包,10 个领域文件
│ - CRUD 操作 │
│ - 分页查询 │
│ - 软删除过滤 │
│ - 不含业务逻辑 │
├─────────────────────────────────────────┤
│ Models (core/db/models/) │ ← ORM 定义(包,11 个领域文件)
│ Models (core/db/models/) │ ← ORM 定义(包,17 个领域文件)
│ - SQLAlchemy declarative │
│ - 索引、约束、关系 │
│ - EE 专属表登记 edition_tables.py
│ - EE 专属表登记 edition_ee/db/edition_tables.py │
│ - Alembic 迁移 │
└─────────────────────────────────────────┘
```
Expand All @@ -48,58 +48,82 @@ POST /v1/chats/stream
→ api/routes/v1/chats.py
→ orchestration/chat_run_executor.py # ChatRun + Redis Stream(后台 run,SSE 跟随,断线续播)
→ orchestration/workflow.py # 流式编排主入口
→ core/services/chat_mode_service.py # 解析对话模式 ChatModeSpec(standard/turbo/市场模式;装配契约)
→ orchestration/memory_integration.py # 检索分层记忆并注入(user-role 冻结块,600ms 预算)
→ orchestration/strategy.py # 路由策略(ROUTER_STRATEGY,默认 main_only)
→ core/llm/agent_factory.py # 构建 AgentScope 2.0 ReActAgent
→ core/llm/agent_factory.py # 构建 AgentScope 2.0 ReActAgent(按 ChatModeSpec 收窄工具面)
→ core/llm/mcp_manager.py # MCP 客户端池(streamable-http → mcp 容器)
→ core/config/mcp_config.py # MCP server 定义
→ core/llm/middlewares.py # AS2 中间件(动态模型、文件上下文等
→ core/config/mcp_config.py # MCP server 定义(端口真源 mcp_servers/_ports.py)
→ core/llm/middlewares.py # AS2 中间件(动态模型、文件上下文、CitationAnchorMiddleware、OntologyGateMiddleware
→ prompts/prompt_runtime.py # 装配系统提示词(DB 版本池优先,prompt_text/ 兜底)
→ orchestration/citations.py # 提取 [ref:tool-N] 引用标记
→ orchestration/streaming.py # StreamingAgent:把 AS2 事件流映射为内部块事件
→ orchestration/citation_anchor.py # 引用锚点唯一发号(AnchorAllocator,e1/e2/…,经中间件回注工具结果)
→ core/memory/service.py # 流结束后后台保存记忆(L1/L2/L3)
→ orchestration/followups.py # 流结束后后台生成追问建议(写入消息 extra_data)
```

SSE 事件:`run_started`(首帧,携带续播 run_id)、`content`(delta 增量)、`thinking`、
`tool_call`、`tool_result`、`tool_pending`、`batch_confirm`、`file_confirm`、`meta`、`error`;
流以 `data: [DONE]` 终止,心跳为 SSE 注释行(15s)。**没有 `text` / `done` 事件。**
断线续播:`GET /v1/chats/stream/{run_id}`。
> `orchestration/strategy.py` 仍在但已退化为占位符(两个分支都返回 MainOnlyStrategy),不再是主链路环节。

**平级编排入口**(不走普通 chat run 的独立驱动):

| 入口 | 文件 | 说明 |
|------|------|------|
| 自主循环 | `orchestration/autonomous_loop.py` + `loop_planner.py` / `loop_evaluator.py` + `subagents/loop_reviewer.py` | driver 持有需求台账 feature_list.json,逐条注入 + 只读 reviewer 验收;路由 `v1/loops.py` |
| 批量执行 | `orchestration/batch_orchestrator.py` | batch_confirm 确认后逐行执行 |
| 计划模式 | `orchestration/subagents/plan_mode.py` | plan_generate / plan_execute run |
| 渠道入站 | `core/channels/`(protocol/registry/manager/inbound/outbound) | IM 消息归一为 InboundMsg 后复用聊天编排,回复经 markdown.py 降级回发 |
| 定时任务 | `orchestration/schedulers/`(automation / distillation_cron / evolution / memory_ttl) | croniter 调度 |

SSE 事件(前端解析真源 `src/frontend/src/hooks/chatStream.ts`):

- 生命周期:`run_started`(首帧,携带续播 run_id)、`meta`、`error`、`end` / `data: [DONE]`(终止)、心跳为 SSE 注释行
- 正文/思考:`content`(delta 增量;别名 ai_message/text/delta)、`content_replace`、`thinking`、`compaction_notice`、`steer_applied`
- 工具:`tool_call_start`、`tool_call_delta`(参数流式)、`tool_call`、`tool_result`、`tool_pending`、`model_progress`(活性信号)
- 交互确认:`batch_confirm`、`file_confirm`、`design_pick`
- 计划/子智能体:`plan_update`、`subagent_event`
- 本体治理:`ontology_activation` / `ontology_gate` / `ontology_review` / `ontology_repair` / `ontology_revision` / `ontology_revision_thinking`

断线续播:`GET /v1/chats/stream/{run_id}`。追问建议(follow_up_questions)流结束后后台生成,也可能以 `follow_up` 事件流内直送。

## 模块索引

| 模块 | 路径 | 职责 |
|------|------|------|
| App 入口 | `api/app.py` | FastAPI 实例、中间件;路由按注册表自动注册 |
| 路由注册表 | `api/routes/v1/__init__.py` | **CE_ROUTERS / EE_ROUTERS 单一真源**(EE 项带 license 能力位) |
| 依赖注入 | `api/deps.py` | require_admin(ADMIN_TOKEN)、require_admin_or_config、require_super_admin、team 权限 |
| 用户认证 | `core/auth/backend.py` | get_current_user / UserContext(AUTH_MODE: mock/session/remote) |
| CE 路由注册表 | `api/routes/v1/__init__.py` | **CE_ROUTERS 单一真源**(二元组);re-export EE_ROUTERS |
| EE 路由注册表 | `edition_ee/routes/registry.py` | **EE_ROUTERS 单一真源**(三元组,带 license 能力位) |
| 依赖注入 | `api/deps.py` | require_admin(ADMIN_TOKEN)、require_config(CONFIG_TOKEN)、require_admin_or_config、require_system_settings、require_super_admin |
| 用户认证 | `core/auth/backend.py` | get_current_user / UserContext(桌面桥接 → session → API-Key → mock/remote) |
| 健康检查 | `api/health.py` | /health, /ready, /live |
| Schema | `api/schemas.py` | 请求/响应 Pydantic 模型 |
| 中间件 | `api/middleware/` | CORS, logging, error_handler |
| 路由 | `api/routes/v1/` | 50+ 路由文件 |
| 路由 | `api/routes/v1/` | 66 个路由文件 |
| 技能引擎 | `core/agent_skills/` | SKILL.md 解析、多源加载、{dir} 沙箱路径注入 |
| 生成物 | `core/artifacts/` | 注册与下载(store.py,local/oss 双模) |
| 认证 | `core/auth/` | backend.py, session.py, sso.py, permissions_iface.py(CE/EE 接缝) |
| 渠道 | `core/channels/` | 入站机器人框架:钉钉/飞书/企微/微信 adapter;加渠道 = 写 adapter + registry.py 注册 |
| 聊天 | `core/chat/` | context.py, tool_log.py |
| 配置 | `core/config/` | settings.py + catalog 五件套(catalog.json/catalog.py/loader/resolver/migration)+ mcp_config.py |
| 内容 | `core/content/` | 内容块、file_parser.py |
| 数据库 | `core/db/` | engine.py, models/(包), repository/(包), edition_tables.py |
| 基础设施 | `core/infra/` | exceptions, responses, logging, metrics, 限流, Redis |
| 知识库 | `core/kb/` | 分块、向量化、混合检索 |
| 数据库 | `core/db/` | engine.py, models/(17 领域文件), repository/(10 领域文件), model_extensions.py, edition_tables.py(垫片) |
| 进化 | `core/evolution/` | GCE 共享契约(Episode/候选/结算);控制面在 edition_ee/evolution |
| 基础设施 | `core/infra/` | exceptions, responses, logging, metrics, 限流, Redis, crypto |
| 知识库 | `core/kb/` | 分块、向量化、混合检索 + wiki/(LLM-Wiki 管线)+ wiki_router.py + external_provider.py(外接接缝) |
| License | `core/licensing/` | features.py(能力位+402)、manager.py(状态机) |
| LLM | `core/llm/` | agent_factory, chat_models, middlewares, mcp_manager/mcp_pool, offloader, tools/ |
| 记忆 | `core/memory/` | service.py(mem0)、pipeline.py、profile.py(L1)、sanitizer.py |
| 沙箱 | `core/sandbox/` | protocol.py + provider 实现 |
| 服务 | `core/services/` | 30+ 业务服务(user/chat/catalog/kb/artifact/plan/automation/prompt_version/marketplace…) |
| LLM | `core/llm/` | agent_factory(含 turbo 参数), chat_models, middlewares, mcp_manager/mcp_pool, offloader, subagent_tool, tools/ |
| 记忆 | `core/memory/` | service.py(mem0)、pipeline.py、profile.py(L1)、sanitizer.py、audit.py |
| 本体 | `core/ontology/` | Domain Pack 校验、运行时选取、工具闸(schemas/validator/revision/toolkit) |
| 沙箱 | `core/sandbox/` | protocol.py + script_runner / opensandbox / cube 三实现 |
| 服务 | `core/services/` | 70+ 业务服务(user/chat/chat_mode/channel/loop/kb/plugin/prompt_version/marketplace…) |
| 存储 | `core/storage/` | protocol, local, s3, oss |
| 编排 | `orchestration/` | workflow, chat_run_executor, strategy, citations, memory_integration, schedulers/, subagents/ |
| 提示词 | `prompts/` | prompt_runtime + provider + prompt_text/{default,code_exec,distillation,plan_mode}/ |
| MCP 服务器 | `mcp_servers/` | 8 个内置 server,streamable-http 常驻 mcp 容器(端口 9100–9107,真源 _ports.py) |
| 技能资产 | `skill_bundles/` | default/(内置)+ marketplace/(可安装) |
| 编排 | `orchestration/` | workflow, chat_run_executor, streaming, citation_anchor, autonomous_loop, followups, batch_orchestrator, schedulers/, subagents/ |
| 提示词 | `prompts/` | prompt_runtime + provider + prompt_text/{default,code_exec,distillation,plan_mode,subagents,turbo}/ |
| MCP 服务器 | `mcp_servers/` | 12 个 server 目录、11 个在役(端口 9100–9114,真源 _ports.py;9105/9109-9111 为退役保留位) |
| 技能资产 | `skill_bundles/` | default/(5 内置)+ marketplace/(40+ 可安装) |
| EE 树 | `edition_ee/` | EE 专属路由/模型/KB provider(dify/fastgpt/weknora)/evolution 控制面;CE 派生树物理删除 |

## 新路由注册步骤

1. 创建 `api/routes/v1/my_feature.py`,文件内定义 `router = APIRouter(prefix="/v1/xxx", tags=["Xxx"])`
2. 在 `api/routes/v1/__init__.py` 的注册表中加一项
- 通用功能 → `CE_ROUTERS` 加 `("my_feature", "router")`
- 企业版功能 → `EE_ROUTERS` 加 `("my_feature", "router", "<license能力位>")`(能力位 `None` 表示显式豁免 feature 守卫)
3. **不要**在 `api/app.py` 手工 `include_router()` —— app 启动时按表自动注册,模块缺失(CE 派生树物理删除了 EE 文件)会被静默跳过
1. 创建 `api/routes/v1/my_feature.py`(EE 专属则放 `edition_ee/routes/`),文件内定义 `router = APIRouter(prefix="/v1/xxx", tags=["Xxx"])`
2. 注册进对应注册表
- 通用功能 → `api/routes/v1/__init__.py` 的 `CE_ROUTERS` 加 `("my_feature", "router")`
- 企业版功能 → `edition_ee/routes/registry.py` 的 `EE_ROUTERS` 加 `("edition_ee.routes.my_feature", "router", "<license能力位>")`(能力位 `None` 表示显式豁免 feature 守卫)
3. **不要**在 `api/app.py` 手工 `include_router()` —— app 启动时经 `iter_edition_routers()` 按表自动注册,模块缺失(CE 派生树物理删除了 EE 文件)会被静默跳过
45 changes: 28 additions & 17 deletions .claude/skills/hugagent-frontend-dev/references/css-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
--color-bg-gray: #F5F6F7;

/* 文字 */
--color-text: #262626;
--color-text-secondary: #4D4D4D;
--color-text-tertiary: #808080;
--color-text-placeholder: #B3B3B3;
--color-text: #101828;
--color-text-secondary: #475467;
--color-text-tertiary: #667085;
--color-text-placeholder: #98A2B3;
--color-text-white: #FFFFFF;

/* 语义色 */
Expand All @@ -37,10 +37,10 @@
--color-error: #FC5D5D;

/* 圆角 */
--radius-xs: 4px; /* 标签等小面积 */
--radius-sm: 8px; /* 按钮、输入框、下拉框 */
--radius-md: 12px; /* 卡片视图、背景卡片 */
--radius-lg: 20px; /* 弹窗、大输入框 */
--radius-xs: 6px; /* 标签等小面积 */
--radius-sm: 10px; /* 按钮、输入框、下拉框 */
--radius-md: 16px; /* 卡片视图、背景卡片 */
--radius-lg: 24px; /* 弹窗、大输入框 */

/* 间距 (4px 基准) */
--space-xs: 4px;
Expand All @@ -49,12 +49,23 @@
--space-lg: 20px;
--space-xl: 40px;

/* 字体 */
--font-family: "PingFang SC", "Microsoft YaHei", "微软雅黑", sans-serif;
/* 字体(后一条定义生效:系统栈优先,中文回退 PingFang/雅黑) */
--font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
--font-family-number: "DingTalk Sans", "PingFang SC", "Microsoft YaHei", sans-serif;

/* Motion 令牌(TS 侧镜像在 utils/motionTokens.ts) */
--motion-duration-instant: 100ms;
--motion-duration-fast: 160ms;
--motion-duration-normal: 240ms;
--motion-duration-slow: 320ms;
/* easing: --motion-ease-brand-out cubic-bezier(.16,1,.3,1) / --motion-ease-standard cubic-bezier(.4,0,.2,1) */
}
```

> 阴影令牌:`--shadow-card` / `--shadow-card-hover` / `--shadow-dropdown`(双层 ambient + key-light)。
> 底部还有 legacy 别名(`--primary` / `--bg` / `--text` / `--muted` / `--border` 等),新代码不要使用。

## CSS 类名前缀

所有自定义类使用 `.jx-` 前缀,避免与 Ant Design 冲突。
Expand All @@ -77,10 +88,10 @@
| 消息最大宽度 | 840px |
| 面板内边距 | 20px (桌面) / 16px (移动) |
| 卡片间距 | 8px - 16px |
| 卡片圆角 | 12px (`--radius-md`) |
| 输入框圆角 | 8px (`--radius-sm`) |
| 按钮圆角 | 8px (`--radius-sm`) |
| 弹窗圆角 | 20px (`--radius-lg`) |
| 卡片圆角 | 16px (`--radius-md`) |
| 输入框圆角 | 10px (`--radius-sm`) |
| 按钮圆角 | 10px (`--radius-sm`) |
| 弹窗圆角 | 24px (`--radius-lg`) |
| 按钮最小高度 | 36px |

## 常用样式模式
Expand All @@ -90,7 +101,7 @@
```css
.jx-card {
padding: var(--space-md) var(--space-lg); /* 16px 20px */
border-radius: var(--radius-md); /* 12px */
border-radius: var(--radius-md); /* 16px */
border: 1px solid var(--color-border);
background: #fff;
transition: box-shadow 0.2s, border-color 0.2s;
Expand All @@ -109,7 +120,7 @@
align-items: center;
gap: 6px;
padding: 8px 18px;
border-radius: var(--radius-sm); /* 8px */
border-radius: var(--radius-sm); /* 10px */
font-size: 14px;
cursor: pointer;
transition: all 0.2s;
Expand All @@ -124,7 +135,7 @@
width: 100%;
max-width: 840px;
margin: 0 auto;
border-radius: var(--radius-lg); /* 20px */
border-radius: var(--radius-lg); /* 24px */
border: 1.5px solid var(--color-border);
background: #fff;
}
Expand Down
Loading
Loading