Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a89a70a983 | |||
| 1c939bfa27 | |||
| 080d1d0b23 | |||
| d1ef64b5cc | |||
| e83ad1de73 | |||
| a27ea8ed89 | |||
| 146816303f | |||
| 11349b5225 | |||
| a037497053 |
@@ -0,0 +1,34 @@
|
||||
name: Bug 报告
|
||||
about: 报告一个 Bug
|
||||
title: "[moz] bug: "
|
||||
labels:
|
||||
- type/bug
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Bug 描述
|
||||
description: 清晰描述什么行为是错误的
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: reproduce
|
||||
attributes:
|
||||
label: 复现步骤
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: expected
|
||||
attributes:
|
||||
label: 预期行为
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: priority
|
||||
attributes:
|
||||
label: 优先级
|
||||
options:
|
||||
- P0 紧急
|
||||
- P1 高
|
||||
- P2 中
|
||||
- P3 低
|
||||
@@ -0,0 +1,27 @@
|
||||
name: 功能需求
|
||||
about: 提出一个新功能需求
|
||||
title: "[moz] feat: "
|
||||
labels:
|
||||
- type/feat
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: 需求描述
|
||||
description: 你希望实现什么功能?为什么需要?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: 建议方案
|
||||
description: 如果有初步想法可以写 here
|
||||
- type: dropdown
|
||||
id: priority
|
||||
attributes:
|
||||
label: 优先级
|
||||
options:
|
||||
- P0 紧急
|
||||
- P1 高
|
||||
- P2 中
|
||||
- P3 低
|
||||
@@ -0,0 +1,20 @@
|
||||
name: 测试任务
|
||||
about: 创建一个测试任务(E2E、集成测试等)
|
||||
title: "[moz] test: "
|
||||
labels:
|
||||
- type/test
|
||||
body:
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: 测试目标
|
||||
description: 要验证什么场景?
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: steps
|
||||
attributes:
|
||||
label: 测试步骤
|
||||
description: 关键步骤或验收标准
|
||||
validations:
|
||||
required: true
|
||||
@@ -0,0 +1,26 @@
|
||||
## 改动概述
|
||||
|
||||
<!-- 一句话说明这个 PR 做了什么 -->
|
||||
|
||||
## 关联 Issue
|
||||
|
||||
<!-- #issue_number,如果没有关联可删掉 -->
|
||||
|
||||
## 改动类型
|
||||
|
||||
- [ ] feat: 新功能
|
||||
- [ ] impl: 实现
|
||||
- [ ] fix: 修复
|
||||
- [ ] docs: 文档
|
||||
- [ ] test: 测试
|
||||
- [ ] refactor: 重构
|
||||
- [ ] ci: CI/CD
|
||||
- [ ] chore: 杂项
|
||||
|
||||
## 检查清单
|
||||
|
||||
- [ ] 标题格式正确:`[代号] type(scope): 简述`
|
||||
- [ ] 改动在开发目录(`~/.openclaw/sanguo_projects/`)完成
|
||||
- [ ] 已同步到安装目录(`~/.sanguo_projects/`)
|
||||
- [ ] 已运行测试(如适用)
|
||||
- [ ] 已更新相关设计文档(如适用)
|
||||
@@ -245,11 +245,14 @@ pm2 show sanguo-act-runner # 详情
|
||||
|------|------|
|
||||
| `feat` | 新功能 |
|
||||
| `fix` | Bug 修复 |
|
||||
| `impl` | 按设计文档实现 |
|
||||
| `refactor` | 重构(不改行为) |
|
||||
| `test` | 测试相关 |
|
||||
| `docs` | 文档 |
|
||||
| `chore` | 构建/工具/配置 |
|
||||
|
||||
sanguo 组织所有仓库统一使用此 commit 规范。
|
||||
|
||||
---
|
||||
|
||||
## §4. 问题管理
|
||||
@@ -266,15 +269,19 @@ pm2 show sanguo-act-runner # 详情
|
||||
|
||||
### 4.2 Issue 标签体系
|
||||
|
||||
| 标签 | 颜色 | 说明 |
|
||||
|------|------|------|
|
||||
| `bug` | 红 | 功能异常 |
|
||||
| `feature` | 蓝 | 新功能需求 |
|
||||
| `improvement` | 绿 | 改进优化 |
|
||||
| `security` | 橙 | 安全相关 |
|
||||
| `risk:high/standard/low` | 分级色 | 风险级别(见 §6.1 判定规则) |
|
||||
| `priority:high/medium/low` | 黄/灰 | 优先级 |
|
||||
| `blocked` | 紫 | 阻塞中 |
|
||||
| 标签 | 颜色 | 色值 | 说明 |
|
||||
|------|------|------|------|
|
||||
| `type/bug` | 红 | #ee0701 | Bug 修复 |
|
||||
| `type/feat` | 蓝 | #84b6eb | 新功能 |
|
||||
| `type/impl` | 浅蓝 | #c5def5 | 按设计实现 |
|
||||
| `type/docs` | 黄 | #fbca04 | 文档 |
|
||||
| `type/test` | 绿 | #0e8a16 | 测试 |
|
||||
| `type/ci` | 紫 | #d4c5f9 | CI/CD |
|
||||
| `type/refactor` | 橙 | #ff6f00 | 重构 |
|
||||
| `priority/P0` | 深红 | #b60205 | 紧急 |
|
||||
| `priority/P1` | 红 | #d93f0b | 高 |
|
||||
| `priority/P2` | 黄 | #fbca04 | 中 |
|
||||
| `priority/P3` | 浅蓝 | #c5def5 | 低 |
|
||||
|
||||
### 4.3 需求/问题 Review 前置
|
||||
|
||||
@@ -296,6 +303,29 @@ Open → In Progress → Review → Closed
|
||||
└──── Reopened ←───────────────────┘
|
||||
```
|
||||
|
||||
### 4.5 标题规范
|
||||
|
||||
所有 Issue 和 PR 标题**必须**包含项目代号前缀,让人类一眼识别项目+类型:
|
||||
|
||||
**Issue**: `[代号] type: 简述`
|
||||
**PR**: `[代号] type(scope): 简述`
|
||||
|
||||
项目代号:
|
||||
|
||||
| 仓库 | 代号 |
|
||||
|------|------|
|
||||
| sanguo_moziplus_v2 | moz |
|
||||
| sanguo_quant_live | quant |
|
||||
| sanguo_vnpy | vnpy |
|
||||
|
||||
示例:
|
||||
- `[moz] bug: Mail API 500 when comment_type invalid`
|
||||
- `[moz] impl(daemon): 知识注入 L2 引擎层 — WikiGuideSection`
|
||||
- `[quant] feat: 趋势跟踪策略骨架`
|
||||
|
||||
此规范通过 L2 引擎层 `GiteaConventionSection`(priority=55)自动注入所有 Agent prompt。
|
||||
完整规范文档:L3 Skill `gitea-conventions`。
|
||||
|
||||
---
|
||||
|
||||
## §5. CI/CD 管道设计
|
||||
@@ -3297,3 +3327,48 @@ async def _handle_issue_comment(payload):
|
||||
|------|------|------|
|
||||
| 2026-06-09 | v1.0 | 初版:E2E 真实场景暴露问题 → 四层改造方案 + @mention 通知 + Mail type 改造 |
|
||||
|
||||
---
|
||||
|
||||
## §26. Gitea 协作规范落地
|
||||
|
||||
> **状态**: ✅ 已完成
|
||||
> **日期**: 2026-06-14
|
||||
> **PR**: 本次改动随 PR 提交
|
||||
|
||||
### 26.1 动机
|
||||
|
||||
团队三个仓库(moziplus_v2 / quant_live / vnpy)缺少统一的 Issue/PR 模板、Label 体系和标题规范。人类从标题无法一眼分辨是哪个项目什么类型的问题。
|
||||
|
||||
### 26.2 落地内容
|
||||
|
||||
| 层级 | 内容 | 说明 |
|
||||
|------|------|------|
|
||||
| L3 | `gitea-conventions` Skill | 完整规范文档(标题/分支/commit/label) |
|
||||
| L2 | `GiteaConventionSection`(priority=55) | 注入所有 handler(task/toolchain/mail),自动提醒 Agent 遵循标题格式 |
|
||||
| L1 | TOOLS.md 追加代号表 | Agent 静态可见的速查 |
|
||||
| Gitea 模板 | 3 仓库 × 4 文件 | bug.yml / feature.yml / test.yml / PULL_REQUEST_TEMPLATE.md |
|
||||
| Gitea Labels | 3 仓库 × 11 个 | type × 7 + priority × 4 |
|
||||
|
||||
### 26.3 四层注入路径
|
||||
|
||||
```
|
||||
L1 TOOLS.md(静态,Agent workspace)
|
||||
→ 代号表 + 格式速查
|
||||
|
||||
L2 GiteaConventionSection(动态,每次 spawn 注入)
|
||||
→ "创建 Issue/PR 时标题必须带 [代号] 前缀"
|
||||
|
||||
L3 gitea-conventions Skill(被动,extraDirs 自动发现)
|
||||
→ 完整规范:标题/分支/commit/label/模板
|
||||
```
|
||||
|
||||
### 26.4 代码改动
|
||||
|
||||
| 文件 | 改动 |
|
||||
|------|------|
|
||||
| `prompt_composer.py` | 新增 `GiteaConventionSection`(priority=55) |
|
||||
| `task_handler.py` | `get_sections()` 注册 `GiteaConventionSection()` |
|
||||
| `toolchain_handler.py` | `get_sections()` 注册 `GiteaConventionSection()` |
|
||||
| `mail_handler.py` | `get_sections()` 注册 `GiteaConventionSection()` |
|
||||
| `db.py` | `COMMENT_TYPES` 补 `action_report`(修 API 500 bug) |
|
||||
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
# #16 知识注入设计
|
||||
|
||||
> 状态:v2 设计中
|
||||
> 作者:庞统
|
||||
> 日期:2026-06-13(v1),2026-06-14(v2 对齐 #11 四层架构)
|
||||
> 评审:待司马懿评审
|
||||
|
||||
## 一、问题
|
||||
|
||||
### 1.1 现状
|
||||
|
||||
Agent(庞统、司马懿、张飞等)在执行任务时,不主动查询已有知识库(wiki-vault)。导致:
|
||||
|
||||
1. **重复调研**:赵云查过的数据清洗经验,张飞又从头调研一遍
|
||||
2. **重复踩坑**:wiki-vault 里已有"vnpy load_bar 需要显式指定 end=None"的实践,张飞还是踩了
|
||||
3. **方案质量低**:做方案时纯靠推理,不查已有的优秀实践
|
||||
4. **知识 gap 无人管**:查不到相关知识时没记录,下次还是查不到
|
||||
|
||||
### 1.2 根因
|
||||
|
||||
不是没有知识库(wiki-vault 有 50+ practices 页面),也不是没有检索能力(wiki-query Skill 已存在)。
|
||||
|
||||
**根因是注入时机**:Agent 不知道什么时候该查、没有强制机制让 Agent 在关键决策点查。
|
||||
|
||||
### 1.3 目标
|
||||
|
||||
1. Agent 在关键决策点**主动查询** wiki-vault
|
||||
2. 查不到相关知识时**自动记录** knowledge gap
|
||||
3. 定时任务处理 gap + 总结经验,**持续丰富** wiki-vault
|
||||
4. 不增加 prompt token 负担(不自动注入知识全文,只引导查询)
|
||||
|
||||
## 二、调研
|
||||
|
||||
### 2.1 Superpowers:强制 Skill 检查(最有效)
|
||||
|
||||
**核心设计**:session-start hook 注入铁律级指令——
|
||||
|
||||
> "If you think there is even a **1% chance** a skill might apply, you **ABSOLUTELY MUST** invoke the skill. This is not negotiable."
|
||||
|
||||
配合 **Red Flags 表**防止 Agent 自合理化跳过:
|
||||
|
||||
| Agent 的想法 | Red Flag 驳回 |
|
||||
|---|---|
|
||||
| "这个问题很简单" | 简单问题也需要查实践 |
|
||||
| "我需要更多上下文" | Skill 检查在澄清问题之前 |
|
||||
| "先看看代码" | Skill 告诉你怎么看代码 |
|
||||
| "我记住了这个 Skill" | Skill 会更新,重新读 |
|
||||
|
||||
**为什么有效**:不靠 Agent "想起来",靠铁律强制。Skill 触发在任何响应之前。
|
||||
|
||||
### 2.2 Hermes:经验闭环 + Session Search
|
||||
|
||||
**经验闭环**:完成复杂任务(5+ tool calls)→ 自动创建 Skill → 下次自然触发。
|
||||
|
||||
**Session Search**:系统提示注入——"当用户提及过去内容时,主动搜索而非要求用户重复"。
|
||||
|
||||
**为什么有效**:不是"知识查询"而是"行为内化"——经验变成 Skill,Skill 有 description 触发词。
|
||||
|
||||
### 2.3 结论
|
||||
|
||||
综合两个项目的优势:
|
||||
|
||||
| 设计点 | 来源 | 我们的做法 |
|
||||
|--------|------|-----------|
|
||||
| 铁律级强制 | Superpowers | L0 Hook 注入 + L1 SOUL.md 行为引导 |
|
||||
| Red Flags 反合理化 | Superpowers | 知识查询 Red Flags 表(L1 SOUL.md) |
|
||||
| 经验内化 | Hermes | 经验→wiki-vault→下次查询 |
|
||||
| 渐进式披露 | Hermes | 先查 summary,按需读全文 |
|
||||
|
||||
## 三、设计决策(对齐 #11 四层架构)
|
||||
|
||||
> **层级体系严格对齐 [#11](./11-context-layers-redesign.md)**,不自创命名。
|
||||
|
||||
### 总览
|
||||
|
||||
| #11 层级 | 知识注入角色 | 本设计覆盖 | 注入方式 |
|
||||
|----------|------------|-----------|---------|
|
||||
| **L0 铁律层** | "做方案前先查 wiki-vault" | ✅ D16-1 | Hook 每轮强制注入 |
|
||||
| **L1 角色层** | TOOLS.md 知识库速查表 + SOUL.md Red Flags | ✅ D16-2 | Workspace 文件自动注入 |
|
||||
| **L2 引擎注入层** | 三种 handler 各注入 WikiGuideSection | ✅ D16-3 | PromptComposer 拼装 |
|
||||
| **L3 被动参考层** | wiki-query Skill 按需触发 | ✅ D16-4 | extraDirs Description 匹配 |
|
||||
| 运维层 | gap 闭环 cron job | ✅ D16-5 | 不属于上下文分层 |
|
||||
|
||||
### D16-1:L0 铁律层 — 新增一条 wiki 查询铁律
|
||||
|
||||
L0 只放跨系统通用的、不可绕过的行为底线。wiki 查询铁律和 GATE 门控同级。
|
||||
|
||||
**新增铁律**:
|
||||
|
||||
```
|
||||
<wiki-rule>
|
||||
做方案前先查 wiki-vault,有 1% 相关就要查。查不到记 knowledge-gaps.md。
|
||||
</wiki-rule>
|
||||
```
|
||||
|
||||
**注入方式**:和 `<gate-rules>` / `<delegation-rule>` 并列,Hook 每轮强制注入。
|
||||
|
||||
**覆盖范围**:所有 Agent、所有场景(不限于 moziplus spawn 的子任务)。
|
||||
|
||||
### D16-2:L1 角色层 — TOOLS.md + SOUL.md
|
||||
|
||||
#### TOOLS.md(✅ 已完成)
|
||||
|
||||
各 Agent workspace 的 TOOLS.md 中已有「LLM Wiki 知识库」段,包含:
|
||||
|
||||
- 速查表(场景 → 怎么做 → 什么时候用)
|
||||
- 检索原则(index.md → summary → grep → 整页读取,从便宜到昂贵)
|
||||
- 目录结构(wiki-vault / practices / concepts / skills / ...)
|
||||
- 铁律(做方案前先查、查不到记 gap)
|
||||
|
||||
#### SOUL.md Red Flags
|
||||
|
||||
在各 Agent 的 SOUL.md 中加入知识查询 Red Flags 表(和 Superpowers 一致):
|
||||
|
||||
| Agent 的想法 | 反驳 |
|
||||
|---|---|
|
||||
| "这个我以前做过" | 知识库可能已更新,查一下确认 |
|
||||
| "先做再说" | 做方案前查实践比做错了返工便宜 |
|
||||
| "这个领域我熟悉" | 熟悉≠知道最新实践,wiki-vault 持续更新 |
|
||||
| "查知识库浪费时间" | 重复踩坑浪费的时间远大于查询时间 |
|
||||
|
||||
### D16-3:L2 引擎注入层 — 三种 handler 各注入 WikiGuideSection
|
||||
|
||||
L2 是 BootstrapBuilder/PromptComposer 动态拼装的 prompt 段。当前有三种 handler,各有自己的 PromptSection 实现:
|
||||
|
||||
#### 当前 handler 结构
|
||||
|
||||
| Handler | Sections(priority) | 有 wiki 引导? |
|
||||
|---------|---------------------|--------------|
|
||||
| **TaskHandler** | Context(10) → Prior(20) → RoleSkill(30) → API(40) → Constraints(50) | ❌ |
|
||||
| **MailHandler** | Context(10) → API(40) → Constraints(50) | ❌ |
|
||||
| **ToolchainHandler** | Context(10) → API(40) → Constraints(50) | ❌ |
|
||||
|
||||
#### 新增 WikiGuideSection(priority=60,PRIORITY_EXTENSION)
|
||||
|
||||
创建一个**通用 PromptSection**,三种 handler 的 `get_sections()` 都注入:
|
||||
|
||||
```python
|
||||
# 可放在 prompt_composer.py 或独立文件,三种 handler 共用
|
||||
|
||||
class WikiGuideSection:
|
||||
"""知识查询引导段 — 引导 Agent 在关键决策点查 wiki-vault。"""
|
||||
|
||||
name: str = "wiki_guide"
|
||||
priority: int = 60 # PRIORITY_EXTENSION
|
||||
|
||||
WIKI_GUIDE = (
|
||||
"## 知识查询引导\n"
|
||||
"涉及方案设计、编码实现、故障排查时,先查 wiki-vault 相关实践:\n"
|
||||
"- 路径:/Volumes/KnowledgeBase/wiki-vault/\n"
|
||||
"- 速查:index.md → grep 关键词 → summary 字段 → 按需读全文\n"
|
||||
"- 查不到:在 _meta/knowledge-gaps.md 记录"
|
||||
)
|
||||
|
||||
def render(self, context: PromptContext) -> str:
|
||||
return self.WIKI_GUIDE
|
||||
|
||||
def should_include(self, context: PromptContext) -> bool:
|
||||
return True
|
||||
```
|
||||
|
||||
#### 三种 handler 改动
|
||||
|
||||
每种 handler 的 `get_sections()` 末尾加 `WikiGuideSection()`:
|
||||
|
||||
```python
|
||||
# TaskHandler
|
||||
def get_sections(self) -> list:
|
||||
return [
|
||||
TaskContextSection(),
|
||||
PriorOutputsSection(),
|
||||
RoleSkillSection(),
|
||||
TaskApiSection(),
|
||||
TaskConstraintsSection(),
|
||||
WikiGuideSection(), # ← 新增
|
||||
]
|
||||
|
||||
# MailHandler
|
||||
def get_sections(self) -> list:
|
||||
return [
|
||||
MailContextSection(),
|
||||
MailApiSection(),
|
||||
MailConstraintsSection(),
|
||||
WikiGuideSection(), # ← 新增
|
||||
]
|
||||
|
||||
# ToolchainHandler
|
||||
def get_sections(self) -> list:
|
||||
return [
|
||||
ToolchainContextSection(),
|
||||
ToolchainApiSection(),
|
||||
ToolchainConstraintsSection(),
|
||||
WikiGuideSection(), # ← 新增
|
||||
]
|
||||
```
|
||||
|
||||
#### 为什么三种 handler 都需要
|
||||
|
||||
- **TaskHandler**:executor 做方案/编码,最需要查实践
|
||||
- **ToolchainHandler**:CI 失败排查、部署问题,有相关运维实践可参考
|
||||
- **MailHandler**:request 类型回复杂问题时也可能需要查已有经验
|
||||
|
||||
#### token 开销
|
||||
|
||||
WikiGuideSection 固定 ~60 字(~30 tokens),对 L2 预算影响可忽略。
|
||||
|
||||
### D16-4:L3 被动参考层 — wiki-query Skill
|
||||
|
||||
#### 现状
|
||||
|
||||
`wiki-query` Skill 已部署在 `~/.sanguo_projects/sanguo_mozi/skills/wiki/wiki-query/SKILL.md`,description 包含中文触发词:
|
||||
|
||||
> 调查、研究、分析、优秀实践、最佳实践、经验、怎么做X、有没有X的经验、以前怎么处理的
|
||||
|
||||
#### 触发机制
|
||||
|
||||
Agent 通过 extraDirs 加载 Skill header(name + description),按 Description 匹配自主 `read` 全文。这是标准 L3 行为,和 #11 设计一致。
|
||||
|
||||
#### 待确认:extraDirs 子目录递归
|
||||
|
||||
wiki-query 在 `skills/wiki/wiki-query/` 子目录下。需确认 moziplus spawn 子 agent 时 extraDirs 是否递归扫描子目录。如果不递归,需要:
|
||||
- 方案 A:把 wiki-query 移到 `skills/` 顶层
|
||||
- 方案 B:配置 extraDirs 包含 `skills/wiki/` 子目录
|
||||
|
||||
### D16-5:知识 gap 记录 + 定时任务(运维层)
|
||||
|
||||
> 不属于上下文分层体系,是独立的运维流程。
|
||||
|
||||
#### gap 记录机制(已有基础设施)
|
||||
|
||||
- **位置**:`/Volumes/KnowledgeBase/wiki-vault/_meta/knowledge-gaps.md`
|
||||
- **格式**:`- [日期] Agent名查"主题" → 待处理`
|
||||
- **已有 20+ 条历史记录**,处理后标注 `→ 已建立 ✅`
|
||||
|
||||
wiki-query Skill 的 Step 5 已内置 gap 记录逻辑。
|
||||
|
||||
#### 定时任务(已有 cron 基础)
|
||||
|
||||
| 任务 | 时间 | 内容 | 状态 |
|
||||
|------|------|------|------|
|
||||
| wiki-daily-update | 每天 04:00 | 处理 knowledge gaps + 当天经验总结 → 写入 wiki-vault | ✅ 已有 cron,需完善 |
|
||||
| pangtong-vault-sync | 每天 05:00 | 同步 wiki-vault 到 agent workspace | ✅ 已有 |
|
||||
|
||||
**wiki-daily-update 完善内容**:
|
||||
1. 读取 knowledge-gaps.md 中"待处理"条目
|
||||
2. 对每个 gap:搜索 knowledge_base 是否有相关源码/文档 → 有则提炼写入 wiki-vault
|
||||
3. 搜索最近一天的 jsonl 日志,提取有价值的经验
|
||||
4. 新建或更新 wiki-vault 页面
|
||||
5. 更新 knowledge-gaps.md(标记为"已建立 ✅"或"无KB内容,跳过")
|
||||
|
||||
### D16-6:和 #11 各层关系总结
|
||||
|
||||
| #11 层级 | #11 原始定义 | 知识注入贡献 | 本设计 |
|
||||
|---------|------------|------------|--------|
|
||||
| L0 铁律 | GATE 门控 + Delegation + 安全底线 | wiki 查询铁律 | ✅ D16-1 |
|
||||
| L1 角色 | SOUL.md + AGENTS.md + TOOLS.md + MEMORY.md | TOOLS.md 速查表 + SOUL.md Red Flags | ✅ D16-2 |
|
||||
| L2 引擎 | 任务上下文 + 角色操作规范 + 硬约束 | WikiGuideSection 通用段 | ✅ D16-3 |
|
||||
| L3 参考 | A/B/C/D 类 Skill,靠 Description 触发 | wiki-query Skill | ✅ D16-4 |
|
||||
| 运维 | — | gap 闭环 cron job | ✅ D16-5 |
|
||||
|
||||
### D16-7:为什么不做 PromptComposer 自动注入知识全文
|
||||
|
||||
1. **token 浪费**:每次任务都注入可能不相关的知识
|
||||
2. **覆盖范围有限**:只影响 moziplus 子任务 Agent
|
||||
3. **Agent 主动查询更精准**:知道自己缺什么知识,按需查询
|
||||
|
||||
## 四、改动清单
|
||||
|
||||
### 4.1 已完成 ✅
|
||||
|
||||
| 改动 | 文件 | 层级 | 说明 |
|
||||
|------|------|------|------|
|
||||
| TOOLS.md 知识库段 | 各 Agent workspace TOOLS.md | L1 | 速查表 + 检索原则 + 目录结构 + 铁律 |
|
||||
| wiki-query Skill 部署 | `skills/wiki/wiki-query/SKILL.md` | L3 | 中文触发词 + 渐进式检索协议 |
|
||||
| knowledge-gaps.md | `_meta/knowledge-gaps.md` | 运维 | 已有 20+ 条记录 |
|
||||
| wiki-daily-update cron | cron job | 运维 | 每天 04:00,需完善处理逻辑 |
|
||||
| pangtong-vault-sync cron | cron job | 运维 | 每天 05:00 |
|
||||
|
||||
### 4.2 待实现
|
||||
|
||||
| 改动 | 文件 | 层级 | 说明 |
|
||||
|------|------|------|------|
|
||||
| L0 wiki 铁律 | Hook 注入配置(`prependContext`) | L0 | 新增 `<wiki-rule>` 段 |
|
||||
| SOUL.md Red Flags | 各 Agent workspace SOUL.md | L1 | 知识查询 Red Flags 表 |
|
||||
| WikiGuideSection | `prompt_composer.py` 或独立文件 | L2 | 通用 PromptSection,三种 handler 共用 |
|
||||
| TaskHandler 注入 | `task_handler.py` `get_sections()` | L2 | 末尾加 `WikiGuideSection()` |
|
||||
| MailHandler 注入 | `mail_handler.py` `get_sections()` | L2 | 末尾加 `WikiGuideSection()` |
|
||||
| ToolchainHandler 注入 | `toolchain_handler.py` `get_sections()` | L2 | 末尾加 `WikiGuideSection()` |
|
||||
| extraDirs 递归确认 | moziplus spawn 配置 | L3 | 确认 wiki-query 子目录可被发现 |
|
||||
| wiki-daily-update 完善 | cron job 脚本 | 运维 | gap 处理 + jsonl 经验提取 |
|
||||
|
||||
### 4.3 不做
|
||||
|
||||
| 项目 | 原因 |
|
||||
|------|------|
|
||||
| PromptComposer 知识全文注入 | token 浪费,Agent 主动查询更精准 |
|
||||
| experiences 表 | wiki-vault 已覆盖,不重复建设 |
|
||||
| 新 Skill(除 wiki-query 外) | wiki-query 已有,不需要新的 |
|
||||
|
||||
## 五、风险
|
||||
|
||||
| 风险 | 概率 | 缓解 |
|
||||
|------|------|------|
|
||||
| Agent 不主动查 wiki | 中 | L0 铁律强制 + L2 引导 + L3 Description 触发,三层保障 |
|
||||
| wiki-query 在子目录不被 extraDirs 发现 | 中 | 确认后决定移顶层或配置子目录 |
|
||||
| wiki-daily-update gap 处理质量不够 | 低 | 人工审核 + 逐步完善 |
|
||||
| WikiGuideSection 增加 token | 低 | 固定 ~30 tokens,影响可忽略 |
|
||||
@@ -209,6 +209,7 @@ VALID_TRANSITIONS = {
|
||||
COMMENT_TYPES = frozenset({
|
||||
"general", "handoff", "observation", "review", "rebuttal",
|
||||
"rebuttal_response", "debate_argument", "debate_rebuttal", "debate_judgment",
|
||||
"action_report",
|
||||
})
|
||||
|
||||
SEVERITY_LEVELS = frozenset({"blocking", "warning", "info", "audit"})
|
||||
|
||||
@@ -9,7 +9,7 @@ import logging
|
||||
from pathlib import Path
|
||||
|
||||
from src.daemon.base_task_handler import BaseTaskHandler, VerifyResult
|
||||
from src.daemon.prompt_composer import PromptComposer, PromptContext
|
||||
from src.daemon.prompt_composer import PromptComposer, PromptContext, GiteaConventionSection, WikiGuideSection
|
||||
from src.blackboard.db import get_connection
|
||||
|
||||
logger = logging.getLogger("moziplus-v2.handler.mail")
|
||||
@@ -36,7 +36,7 @@ class MailHandler(BaseTaskHandler):
|
||||
return composer.compose(context)
|
||||
|
||||
def get_sections(self) -> list:
|
||||
return [MailContextSection(), MailApiSection(), MailConstraintsSection()]
|
||||
return [MailContextSection(), MailApiSection(), MailConstraintsSection(), GiteaConventionSection(), WikiGuideSection()]
|
||||
|
||||
def verify_completion(self, task_id: str, db_path: Path) -> VerifyResult:
|
||||
"""Mail 完成验证:区分 inform/request。
|
||||
|
||||
@@ -127,3 +127,50 @@ class PromptComposer:
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
class GiteaConventionSection:
|
||||
"""Gitea 标题规范引导段 — 提醒 Agent 创建 Issue/PR 时遵循标题格式。"""
|
||||
|
||||
name: str = "gitea_convention"
|
||||
priority: int = 55 # CONSTRAINTS(50) 和 EXTENSION(60) 之间
|
||||
|
||||
CONVENTION_TEXT = (
|
||||
"## Gitea 标题规范\n"
|
||||
"创建 Issue/PR 时,标题**必须**包含项目代号前缀:\n"
|
||||
"- Issue: `[代号] type: 简述`,如 `[moz] bug: Mail API 500`\n"
|
||||
"- PR: `[代号] type(scope): 简述`,如 `[moz] impl(daemon): WikiGuideSection 注入`\n"
|
||||
"代号:moz=moziplus_v2, quant=quant_live, vnpy=vnpy\n"
|
||||
"type: bug/feat/impl/fix/docs/test/ci/refactor/chore"
|
||||
)
|
||||
|
||||
def render(self, context: "PromptContext") -> str:
|
||||
return self.CONVENTION_TEXT
|
||||
|
||||
def should_include(self, context: "PromptContext") -> bool:
|
||||
return True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# WikiGuideSection — 知识查询引导段
|
||||
# ---------------------------------------------------------------------------
|
||||
class WikiGuideSection:
|
||||
"""知识查询引导段 — 引导 Agent 在关键决策点查 wiki-vault。"""
|
||||
|
||||
name: str = "wiki_guide"
|
||||
priority: int = 60 # PRIORITY_EXTENSION
|
||||
|
||||
WIKI_GUIDE = (
|
||||
"## 知识查询引导\n"
|
||||
"涉及方案设计、编码实现、故障排查时,先查 wiki-vault 相关实践:\n"
|
||||
"- 路径:/Volumes/KnowledgeBase/wiki-vault/\n"
|
||||
"- 速查:index.md → grep 关键词 → summary 字段 → 按需读全文\n"
|
||||
"- 查不到:在 _meta/knowledge-gaps.md 记录"
|
||||
)
|
||||
|
||||
def render(self, context: "PromptContext") -> str:
|
||||
return self.WIKI_GUIDE
|
||||
|
||||
def should_include(self, context: "PromptContext") -> bool:
|
||||
return True
|
||||
|
||||
@@ -10,7 +10,7 @@ from pathlib import Path
|
||||
from typing import Dict, Optional
|
||||
|
||||
from src.daemon.base_task_handler import BaseTaskHandler, VerifyResult
|
||||
from src.daemon.prompt_composer import PromptComposer, PromptContext
|
||||
from src.daemon.prompt_composer import PromptComposer, PromptContext, GiteaConventionSection, WikiGuideSection
|
||||
from src.blackboard.db import get_connection
|
||||
|
||||
logger = logging.getLogger("moziplus-v2.handler")
|
||||
@@ -306,13 +306,15 @@ class TaskHandler(BaseTaskHandler):
|
||||
return True
|
||||
|
||||
def get_sections(self) -> list:
|
||||
"""返回 5 个 PromptSection 实例。"""
|
||||
"""返回 PromptSection 实例。"""
|
||||
return [
|
||||
TaskContextSection(),
|
||||
PriorOutputsSection(),
|
||||
RoleSkillSection(),
|
||||
TaskApiSection(),
|
||||
TaskConstraintsSection(),
|
||||
GiteaConventionSection(),
|
||||
WikiGuideSection(),
|
||||
]
|
||||
|
||||
def build_prompt(self, context: PromptContext) -> str:
|
||||
|
||||
@@ -13,7 +13,7 @@ from pathlib import Path
|
||||
from typing import Dict, List
|
||||
|
||||
from src.daemon.base_task_handler import BaseTaskHandler, VerifyResult
|
||||
from src.daemon.prompt_composer import PromptComposer, PromptContext
|
||||
from src.daemon.prompt_composer import PromptComposer, PromptContext, GiteaConventionSection, WikiGuideSection
|
||||
from src.daemon.toolchain_templates import render_template, _TEMPLATE_MAP
|
||||
from src.blackboard.db import get_connection
|
||||
|
||||
@@ -221,11 +221,13 @@ class ToolchainHandler(BaseTaskHandler):
|
||||
return self._auto_mark_working(task_id, db_path)
|
||||
|
||||
def get_sections(self) -> list:
|
||||
"""返回 3 个 Toolchain PromptSection 实例"""
|
||||
"""返回 Toolchain PromptSection 实例"""
|
||||
return [
|
||||
ToolchainContextSection(),
|
||||
ToolchainApiSection(),
|
||||
ToolchainConstraintsSection(),
|
||||
GiteaConventionSection(),
|
||||
WikiGuideSection(),
|
||||
]
|
||||
|
||||
def build_prompt(self, context: PromptContext) -> str:
|
||||
|
||||
Reference in New Issue
Block a user