mcpField
C
cross-agent-delegation

cross-agent-delegation

github.com/alinaqiAgent 工作流711114 次安装2 周前更新
代码仓库

关于 cross-agent-delegation

cross-agent-delegation 是供 Claude Code 使用的技能,可将编码任务路由给 Kimi 和 Codex。它依据任务复杂度与风险决定是否委派,并在测试通过后自动运行 Codex 审查。

主要功能

  1. 01按复杂度和风险路由任务
  2. 02通过 Claude Code 委派给 Kimi
  3. 03测试通过后自动进行 Codex 审查
  4. 04代码修改前后的 iCPG 检查
  5. 05用 Mnemos 检查点传递上下文

适用场景

  1. 01将范围明确的编码任务委派给 Kimi
  2. 02用 Codex 审查已完成的修改
  3. 03在编码 Agent 之间传递任务上下文

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/alinaqi/maggy --skill cross-agent-delegation

安装后在 Claude Code 中输入/cross-agent-delegation确认已加载。

详细介绍

跨 Agent 委派

Claude Code 将任务路由给 Kimi 和 Codex。用户只与 Claude 交互——委派在后台进行。


工具检测

在会话开始时,检测可用工具:

command -v kimi &>/dev/null && HAS_KIMI=true || HAS_KIMI=false
command -v codex &>/dev/null && HAS_CODEX=true || HAS_CODEX=false

Codex 自动审查(停止钩子 — 自动)

安装 Codex 后,停止钩子会在测试通过后审查代码:

  1. TDD 循环检查运行测试
  2. codex-auto-review.sh 使用 Codex 审查差异
  3. 严重/高危问题反馈给 Claude(exit 2)
  4. 审查通过时继续执行(exit 0)

完全自动。 无需用户或 Claude 执行任何操作。


Kimi 委派(Claude 负责协调)

安装 Kimi 且任务复杂度有界时,Claude 会直接委派——用户无需运行任何操作。

步骤 1:评估复杂度,而非文件数

文件数并不是衡量委派风险的可靠指标。对 authz 路径进行 1 个文件的修改,比重命名 12 个文件更棘手。从五个维度对任务评分,每项 0-2 分,依据 iCPG 信号和 Claude 的语义推理:

维度0(低)1(中)2(高)来源
圈复杂度 / 表面深度<10 LOC,无分支10-50 LOC,≤3 个分支50+ LOC 或嵌套控制流对函数体执行 iCPG query_graph
扇出(消费者影响范围)0-2 个调用方3-10 个调用方11+ 个调用方iCPG trace_path(<symbol>, mode=callers)
跨越安全边界(SEC-006、auth、PII、RLS、org-scope、billing、payments)无间接涉及直接读写iCPG SEC-* / R-063 标签 + 搜索 org_id、user_id、auth、pii
并发 / 事务性纯函数 / 同步仅异步锁、事务、原子认领、FOR UPDATE、asyncio.Lock、session.beginiCPG 并发标记 + 搜索
所需领域不变量无 / 内联文档完善有些隐式内容(需要阅读 1-2 个文件)大量隐式内容(跨文档、受 ADR 约束、受 RFC 约束)Claude 推理 + iCPG ADR 关联
# Auto-collect signals
icpg query blast <scope> --format json    # fan-out, async flags, sec tags
grep -rE "org_id|user_id|auth|pii"  <file>  # cheap sec heuristic if iCPG flags absent
grep -rE "asyncio.Lock|FOR UPDATE|session.begin" <file>  # concurrency heuristic
步骤 2:求和 → 路由
总分路由理由
0-3Kimi 单独处理范围有界,没有安全、并发或跨文档方面的顾虑
4-6Kimi → Codex 自动审查(不提示用户)存在实际风险,但尚未高到需要完整的 Claude 上下文——Codex 可以发现 Kimi 可能遗漏的问题
7-10由 Claude 直接处理涉及多个方面 / 安全关键 / 并发密集——需要完整上下文
步骤 3:设定下限——琐碎任务快捷处理

为真正琐碎的工作跳过 iCPG 查询开销:

# If <2 files changed AND no SEC/auth/PII/concurrency keyword in diff,
# → auto-Kimi without scoring.
FILES=$(git diff --name-only | wc -l)
HAS_RISK_KEYWORDS=$(git diff | grep -ciE "org_id|auth|pii|asyncio|FOR UPDATE|transaction|session\.begin" || true)
if [ "$FILES" -lt 2 ] && [ "$HAS_RISK_KEYWORDS" -eq 0 ]; then
  AUTO_KIMI=true
fi

这样可以处理琐碎的重命名 / 拼写修复,无需承担 iCPG 往返开销。

不应委派的情况(优先于评分)
  • 用户明确要求 Claude 处理
  • 跨服务修改(API + 前端 + 数据库)——无论评分如何都需要完整上下文
  • 发布分支上的生产热修复——跨工具审查延迟过高
  • 任一维度得分达到 7+(任何一个关键维度都足以让 Claude 参与处理)
步骤 4:通过 Bash 委派

Claude 写入 mnemos 检查点,然后以无头模式运行 Kimi:

# 1. Save current context to disk
mnemos checkpoint --force

# 2. Get context summary for Kimi
CONTEXT=$(mnemos resume 2>/dev/null)

# 3. Get constraints for target files
CONSTRAINTS=$(icpg query constraints <target-file> 2>/dev/null)

# 4. Run Kimi headless with full context
kimi --print -y -w . -p "
## Context (from mnemos checkpoint)
$CONTEXT

## Constraints (from iCPG)
$CONSTRAINTS

## Task
<specific task description>

## Rules
- Run tests after changes
- Record changes: icpg record --base main
- Write checkpoint when done: mnemos checkpoint --force
"
步骤 4:读取结果

Kimi 完成后,Claude 会:

# Read what Kimi did
mnemos resume          # Kimi's checkpoint
icpg status            # Kimi's recorded symbols
git diff               # Kimi's file changes
不应委派的情况
  • 安全敏感代码(auth、加密、支付)
  • 跨服务修改(API + 前端 + 数据库)
  • 涉及共享接口的重构
  • 用户明确要求 Claude 处理

iCPG — 所有 Agent 的强制要求

进行任何代码修改前,Claude 都会运行以下操作(委派时也会附上结果):

任务前查询
# 1. Duplicate check — already done?
icpg query prior "<goal>"

# 2. Constraints — what invariants apply?
icpg query constraints <file-path>

# 3. Risk — is this symbol fragile?
icpg query risk <symbol-name>
代码修改后
icpg record --reason <id> --base main
icpg drift check

Mnemos — 所有 Agent 的强制要求

任务开始时
mnemos add goal "<task description>"
子目标边界处
mnemos checkpoint
任务结束时(由停止钩子自动处理)
mnemos checkpoint --force
工具间上下文传递

检查点是桥梁。Claude 写入检查点,Kimi 读取检查点:

# Claude saves state
mnemos checkpoint --force

# Kimi (or Codex) reads state
mnemos resume

检查点包含:目标、约束、近期文件、Git 状态、疲劳程度。


完整协调流程

TASK ARRIVES (user tells Claude)
    |
    v
[1] Claude: icpg query prior "<goal>"     ← Already done?
[2] Claude: trivial-case shortcut         ← <2 files & no risk keywords?
    |
    +-- YES + Kimi installed -----> AUTO-KIMI (no scoring)
    |
    +-- NO ↓
    v
[3] Claude: score complexity (5 dims × 0-2, iCPG + reasoning)
    |
    +-- score 0-3   ----> KIMI SOLO PATH
    |   [a] mnemos checkpoint --force
    |   [b] kimi --print -y -p "..."
    |   [c] mnemos resume + git diff
    |   [d] Continue in Claude
    |
    +-- score 4-6   ----> KIMI + CODEX REVIEW PATH
    |   [a] mnemos checkpoint --force
    |   [b] kimi --print -y -p "..."
    |   [c] codex review --uncommitted    ← Auto-review the diff
    |   [d] If P0/P1 findings: re-prompt Kimi with findings
    |   [e] Once clean: continue in Claude
    |
    +-- score 7-10  ----> CLAUDE DIRECT PATH (full context)
    |
    v
[4] icpg query constraints <files>         ← Invariants
[5] icpg query risk <symbols>              ← Fragility
[6] mnemos add goal "<task>"               ← Track in memory
    |
    v
[7] IMPLEMENT (TDD: RED -> GREEN)
    |
    v
[8]  Stop: tdd-loop-check.sh               ← Tests pass?
[9]  Stop: codex-auto-review.sh            ← Codex reviews diff
[10] Stop: icpg-stop-record.sh             ← Record symbols
[11] Stop: mnemos-checkpoint.sh            ← Save memory

评论

支持 Markdown