feat(agent): L1 记忆注入——重试任务带上次失败原因喂回 prompt

- store.lastRunErrorOf(taskId):取最近一次失败 run 的 error(任意 kind)
- orchestrator.claimOne:写 job.json 时填充 task.lastRunError 下发 worker
- runner 三处 prompt(executor/planner/conflict)注入「## 上次失败原因」段(截断 2000 字符)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-24 22:09:06 +08:00
parent 7a6c826610
commit ecea1ae9b6
4 changed files with 97 additions and 2 deletions
+11
View File
@@ -866,6 +866,17 @@ export class Store {
return rows.map(rowToApproval);
}
/**
* 取某任务最近一次失败 run 的错误信息(任意 kindexecutor/planner)。供 L1 记忆注入:
* 重试任务时把"上次为何失败"喂回 agent prompt,避免重蹈覆辙。无失败 run 返回 null。
*/
lastRunErrorOf(taskId: string): string | null {
const row = this.db.prepare(
`SELECT error FROM runs WHERE task_id = ? AND status = 'failed' AND error IS NOT NULL ORDER BY ended_at DESC LIMIT 1`,
).get(taskId) as { error?: string | null } | undefined;
return row?.error ?? null;
}
/** 列出所有处于审批闸状态(plan_review/spec_review/exec_review)的任务。 */
pendingApprovals(projectId?: string): Task[] {
// 包含 needs_attention:让审核区展示失败任务供人工确认/重排