feat(agent): L2/L4 记忆注入——项目规范 + 全局规范文件喂进 4 处 prompt

- L2 projects.agent_rules 列(schema+迁移+类型+mapper+patchProject+API 透传)
- L4 protocol.readGlobalAgentRules():worker 直接读 <data>/agent-global.md(非DB,
  不读用户 ~/.claude/CLAUDE.md,避免个人习惯与受控执行冲突)
- runner.rulesHeaderLines 注入 executor/planner/conflict;reviewer 同注入
- 顺序:全局规范(L4)→项目规范(L2)→任务内容→上次失败(L1)→执行约束

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-06-24 22:29:29 +08:00
parent ff2d7c22e7
commit fe7923a618
10 changed files with 81 additions and 13 deletions
+1
View File
@@ -37,6 +37,7 @@ export function openDb(file: string): Database.Database {
ensureColumn(db, 'projects', 'budget_usd', 'budget_usd REAL'); // 项目当期预算上限 USD(null=不限)
ensureColumn(db, 'projects', 'budget_period', "budget_period TEXT NOT NULL DEFAULT 'month'"); // 预算周期 day|month
ensureColumn(db, 'tasks', 'attachments', 'attachments TEXT'); // 附件 JSON [{name,type,path}](图片/文件随任务提交)
ensureColumn(db, 'projects', 'agent_rules', 'agent_rules TEXT'); // L2 项目级 agent 执行规范(注入 worker prompt
const schema = readFileSync(join(HERE, 'schema.sql'), 'utf8');
db.exec(schema);
return db;
+2
View File
@@ -12,6 +12,7 @@ export interface ProjectRow {
last_sync_at: string | null; logo: string | null; sort_order: number;
checks: string | null; auto_approve_plan: number; auto_approve_exec: number;
budget_usd: number | null; budget_period: string | null;
agent_rules: string | null;
}
export interface TaskRow {
id: string; project_id: string; parent_id: string | null; depth: number;
@@ -51,6 +52,7 @@ export function rowToProject(r: ProjectRow): Project {
autoApproveExec: Boolean(r.auto_approve_exec),
budgetUsd: r.budget_usd ?? null,
budgetPeriod: (r.budget_period === 'day' ? 'day' : 'month'),
agentRules: r.agent_rules ?? null,
};
}
+2 -1
View File
@@ -22,7 +22,8 @@ CREATE TABLE IF NOT EXISTS projects (
auto_approve_plan INTEGER NOT NULL DEFAULT 0, -- 全 easy 子任务时跳过 plan_review0=关)
auto_approve_exec INTEGER NOT NULL DEFAULT 0, -- 双复审 approve 后跳过 exec_review0=关)
budget_usd REAL, -- 项目当期预算上限 USD(null=不限)
budget_period TEXT NOT NULL DEFAULT 'month' -- 预算周期 day | month
budget_period TEXT NOT NULL DEFAULT 'month', -- 预算周期 day | month
agent_rules TEXT -- L2 项目级 agent 执行规范(注入 worker prompt
);
CREATE TABLE IF NOT EXISTS tasks (
+3 -1
View File
@@ -46,6 +46,7 @@ export interface PatchProjectInput {
maxRetries?: number; timeoutMs?: number;
budgetUsd?: number | null; budgetPeriod?: 'day' | 'month';
autoApprovePlan?: boolean; autoApproveExec?: boolean; checks?: string | null;
agentRules?: string | null;
}
export interface PatchTaskInput {
title?: string; priority?: number; complexity?: Complexity; deps?: string[];
@@ -131,7 +132,7 @@ export class Store {
status: 'active', created_at: now(),
last_sync_at: null, logo: null, sort_order: maxOrder + 1,
checks: null, auto_approve_plan: 0, auto_approve_exec: 0,
budget_usd: null, budget_period: 'month',
budget_usd: null, budget_period: 'month', agent_rules: null,
};
this.db.prepare(
`INSERT INTO projects (id,name,repo_path,default_branch,verify_cmd,autonomy,model,concurrency,max_retries,timeout_ms,status,created_at,last_sync_at,logo,sort_order,checks,auto_approve_plan,auto_approve_exec)
@@ -238,6 +239,7 @@ export class Store {
sets.push('auto_approve_exec = @auto_approve_exec'); args.auto_approve_exec = patch.autoApproveExec ? 1 : 0;
}
if (patch.checks !== undefined) { sets.push('checks = @checks'); args.checks = patch.checks; }
if (patch.agentRules !== undefined) { sets.push('agent_rules = @agent_rules'); args.agent_rules = patch.agentRules; }
if (sets.length > 0) {
this.db.prepare(`UPDATE projects SET ${sets.join(', ')} WHERE id = @id`).run(args);