feat(agent): L3 记忆注入——子任务带父任务拆解意图 + 兄弟状态

- types.TaskContext + Task.context(daemon 装配、不持久化)
- store.taskContextOf(taskId):父 plan + 同层兄弟概览(标题/状态/复杂度,排除自身)
- orchestrator.claimOne:executor 子任务填充 context 下发(planner 跑在父任务上不需要)
- runner.buildPrompt 注入「## 拆解背景」段(顺序:规范→背景→任务内容)
- 仅 DB 读,不做 git/RAG 检索(成本控制)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-24 22:32:21 +08:00
parent fe7923a618
commit 74be3ecec1
5 changed files with 79 additions and 1 deletions
+22
View File
@@ -39,6 +39,27 @@ export function rulesHeaderLines(project?: Project, globalRules?: string | null)
return out;
}
/**
* L3 拆解背景注入:若任务带 context(父任务拆解意图 + 兄弟任务状态),生成背景段;否则空数组。
* 由 daemon 在 claimOne 时把 store.taskContextOf 填进 task.context 下发(仅 executor 子任务)。
*/
function contextLines(task: Task): string[] {
const ctx = task.context;
if (!ctx) return [];
const out: string[] = [];
const plan = ctx.parentPlan?.trim();
const sibs = ctx.siblings ?? [];
if (!plan && sibs.length === 0) return [];
out.push('## 拆解背景(你是某个大任务拆出的子任务)');
if (plan) out.push('父任务的拆解意图:', plan, '');
if (sibs.length) {
out.push('同批兄弟子任务(注意衔接,不要重复或冲突):');
for (const s of sibs) out.push(`- 「${s.title}」(${s.complexity},状态:${s.status}`);
out.push('');
}
return out;
}
/**
* L1 记忆注入:若任务带「上次失败原因」(重试任务),生成一段提醒;否则空数组。
* 由 daemon 在 claimOne 时把 store.lastRunErrorOf 填进 task.lastRunError 下发(见 orchestrator)。
@@ -64,6 +85,7 @@ export function buildPrompt(task: Task, project?: Project, globalRules?: string
`任务 ID${task.id}`,
'',
...rulesHeaderLines(project, globalRules),
...contextLines(task),
'## 任务内容',
body || '(无详细说明,按标题完成)',
'',