合并最新 master 到 AGC V3 资源画布分支
- 合入 origin/master 67 个提交(含 #285 无限画布图标模糊修复、#307 客户端常用设置读写卡顿修复等) - index.tsx 冲突按 V3 画本结构解决:保留 resourceBook 画布场景,未采用 master 的 CanvasWorld 包装 - 原因:game-resource-page-world 现仅承载依赖连线层,CanvasWorld 使用固定 12000 世界尺寸,会破坏按内容自适应的边界 - 保留 AtSign 图标导入(V3 引用输入区使用) - 合并后 npm run ai-game-creator-shell:typecheck 通过
This commit is contained in:
@@ -16,8 +16,5 @@
|
||||
"maxRetries": 2,
|
||||
"retryBackoffMs": 500
|
||||
},
|
||||
"agentLlm": {},
|
||||
"planning": {
|
||||
"capabilityEnabled": true
|
||||
}
|
||||
"agentLlm": {}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
"config": "node scripts/game-creator-config-wizard.mjs",
|
||||
"test:chat": "node scripts/agent-swarm-test-chat.mjs --task \"制作一个可直接试玩的原创植物塔防小游戏:玩家选择并放置原创守卫阻挡敌人,完成波次后可以进入下一关并重新开始。主题、单位名称与视觉语言必须原创,不使用任何现有游戏角色、单位名、Logo 或受保护视觉语言。请自主完成正式产物、静态检查和双视口试玩验证。\" --no-open",
|
||||
"test:chat:manual": "node scripts/agent-swarm-test-chat.mjs",
|
||||
"test:plan": "node scripts/agent-swarm-test-chat.mjs --plan --task \"我想做一款原创横版像素解谜小游戏,主角是一个能操控自己影子的小机器人,影子可以变成平台和开关。请完成立项策划并给出 Fast GDD。主题、角色名与视觉语言必须原创,不使用任何现有游戏角色、名称、Logo 或受保护视觉语言。\"",
|
||||
"test:plan:manual": "node scripts/agent-swarm-test-chat.mjs --plan",
|
||||
"agent-run": "node scripts/run-cli-with-config.mjs --agent-run",
|
||||
"agent-run:smoke": "node scripts/smoke-agent-run-local-provider.mjs",
|
||||
"agent-runtime:real-e2e": "node scripts/agent-runtime-real-e2e.mjs",
|
||||
|
||||
@@ -36,8 +36,6 @@ export const ungeneratedGameEntryMarker =
|
||||
'还没有生成游戏。回到聊天输入创意并确认生成后';
|
||||
export const defaultRealSwarmTestTask =
|
||||
'制作一个可直接试玩的原创植物塔防小游戏:玩家选择并放置原创守卫阻挡敌人,完成波次后可以进入下一关并重新开始。主题、单位名称与视觉语言必须原创,不使用任何现有游戏角色、单位名、Logo 或受保护视觉语言。请自主完成正式产物、静态检查和双视口试玩验证。';
|
||||
export const defaultRealSwarmPlanTask =
|
||||
'我想做一款原创横版像素解谜小游戏,主角是一个能操控自己影子的小机器人,影子可以变成平台和开关。请完成立项策划并给出 Fast GDD。主题、角色名与视觉语言必须原创,不使用任何现有游戏角色、名称、Logo 或受保护视觉语言。';
|
||||
export const swarmTurnReportPrefix = '[turn.report] ';
|
||||
export const swarmTurnReportSchema = 'game-creator-swarm-turn-report.v1';
|
||||
|
||||
@@ -140,15 +138,10 @@ export const usage = `用法:
|
||||
--keep-project 保留自动创建的一次性项目
|
||||
--no-open 手工模式启动预览但不自动打开浏览器
|
||||
--task <需求> 通过 manual 入口非交互提交自定义需求
|
||||
--plan 走「做方案」立项策划入口,不做游戏,不做产物验收和试玩
|
||||
--timeout-minutes <分钟> 设置本次执行期限;自动任务默认 50 分钟,--plan 默认 6 分钟,手工模式默认不限时
|
||||
--timeout-minutes <分钟> 设置本次执行期限;自动任务默认 50 分钟,手工模式默认不限时
|
||||
--dry-run 只检查目录发现和项目准备,不启动 LLM
|
||||
-h, --help 显示帮助
|
||||
|
||||
环境变量:
|
||||
AGC_PLAN_GDD_DECISION 审批卡自动应答动作,默认 approve;revise/reject 必须
|
||||
同时用 AGC_PLAN_GDD_COMMENT 给出真实修改意见
|
||||
AGC_PLAN_GDD_COMMENT revise/reject 的意见原文`;
|
||||
`;
|
||||
|
||||
function readOptionValue(args, index, option) {
|
||||
const value = args[index + 1]?.trim();
|
||||
@@ -177,7 +170,6 @@ export function parseSwarmTestArguments(args) {
|
||||
keepProject: false,
|
||||
openBrowser: true,
|
||||
task: null,
|
||||
plan: false,
|
||||
timeoutMinutes: null,
|
||||
dryRun: false,
|
||||
help: false,
|
||||
@@ -202,8 +194,6 @@ export function parseSwarmTestArguments(args) {
|
||||
if (task.length > 4_000) throw new Error('--task 不能超过 4000 字符');
|
||||
options.task = task;
|
||||
index += 1;
|
||||
} else if (argument === '--plan') {
|
||||
options.plan = true;
|
||||
} else if (argument === '--timeout-minutes') {
|
||||
if (options.timeoutMinutes !== null) {
|
||||
throw new Error('--timeout-minutes 只能指定一次');
|
||||
@@ -222,16 +212,11 @@ export function parseSwarmTestArguments(args) {
|
||||
}
|
||||
|
||||
export function shouldStartPersistentPreview(options) {
|
||||
// 立项策划链路只出 GDD,没有可试玩产物,任何模式都不该起预览。
|
||||
return !options.task && !options.plan;
|
||||
return !options.task;
|
||||
}
|
||||
|
||||
export function resolveSwarmTestTimeoutMs(options) {
|
||||
// 立项策划的设计目标是五分钟出方案,给一分钟余量;再久就是卡住了,早失败
|
||||
// 比让 harness 空等更有用。做游戏那条链路的 50 分钟不变。
|
||||
const planMinutes = options.plan ? 6 : null;
|
||||
const minutes =
|
||||
options.timeoutMinutes ?? planMinutes ?? (options.task ? 50 : null);
|
||||
const minutes = options.timeoutMinutes ?? (options.task ? 50 : null);
|
||||
return minutes === null ? null : minutes * 60_000;
|
||||
}
|
||||
|
||||
@@ -979,25 +964,12 @@ export function swarmAutoPilotShouldCloseInput(output, promptsAfterSubmit) {
|
||||
return swarmAutoPilotSitsAtPrompt(output) && promptsAfterSubmit >= 1;
|
||||
}
|
||||
|
||||
// GDD 审批位不能等 CLI 退出之后再处理:Run 停在这里时状态是 waiting-for-user-input,
|
||||
// 而 swarm CLI 恰好把这个状态算作「本轮还在跑」,turn 永远不 settle,CLI 也就永远
|
||||
// 不退出。所以审批必须在 CLI 还活着的时候并发做完,让 Run 自己继续跑到收束。
|
||||
// 这一句是 PlanGddCompletionBlockerKind::AwaitingApprovalDecision 专有的投影文案,
|
||||
// 另外三个 blocked 子状态都不会打出它;即便认错了,真正的判据也是随后那次
|
||||
// --plan-gdd-status,没有待决定审批时不会有任何写入。
|
||||
const planGddApprovalWaitPattern = /等待 Fast GDD 审批决定/u;
|
||||
|
||||
export function swarmOutputAwaitsPlanGddApproval(line) {
|
||||
return planGddApprovalWaitPattern.test(line);
|
||||
}
|
||||
|
||||
async function runTaskCargo(
|
||||
cliArguments,
|
||||
task,
|
||||
setActiveChild,
|
||||
timeoutMs,
|
||||
autoPilot = false,
|
||||
onPlanGddApprovalWait = null,
|
||||
) {
|
||||
const child = spawnChild(cargoCommand, buildCargoCliArguments(cliArguments), {
|
||||
stdio: ['pipe', 'pipe', 'inherit'],
|
||||
@@ -1009,25 +981,6 @@ async function runTaskCargo(
|
||||
let taskSubmitted = false;
|
||||
let promptsSeen = 0;
|
||||
let sittingAtPrompt = false;
|
||||
let planGddApproval = null;
|
||||
let planGddApprovalError = null;
|
||||
let planGddApprovalStarted = false;
|
||||
let planGddApprovalPromise = null;
|
||||
const startPlanGddApproval = () => {
|
||||
planGddApprovalStarted = true;
|
||||
console.log(
|
||||
`[自动审批] 检测到 Fast GDD 审批位,正在提交 ${resolvePlanGddAutoDecision().action}`,
|
||||
);
|
||||
planGddApprovalPromise = onPlanGddApprovalWait()
|
||||
.then((value) => {
|
||||
planGddApproval = value;
|
||||
})
|
||||
.catch((error) => {
|
||||
planGddApprovalError = error;
|
||||
// 审批没成的话 Run 会一直停在等待位,干等到超时只会把真正的原因埋掉。
|
||||
void terminateChildTree(child).catch(() => {});
|
||||
});
|
||||
};
|
||||
child.stdout.setEncoding('utf8');
|
||||
child.stdout.on('data', (chunk) => {
|
||||
process.stdout.write(chunk);
|
||||
@@ -1040,13 +993,6 @@ async function runTaskCargo(
|
||||
reportLines.push(normalizedLine);
|
||||
settled = true;
|
||||
}
|
||||
if (
|
||||
onPlanGddApprovalWait &&
|
||||
!planGddApprovalStarted &&
|
||||
swarmOutputAwaitsPlanGddApproval(normalizedLine)
|
||||
) {
|
||||
startPlanGddApproval();
|
||||
}
|
||||
}
|
||||
if (!autoPilot || child.stdin.writableEnded) return;
|
||||
const atPrompt = swarmAutoPilotSitsAtPrompt(pendingLine);
|
||||
@@ -1085,12 +1031,9 @@ async function runTaskCargo(
|
||||
if (normalizedPendingLine.startsWith(swarmTurnReportPrefix)) {
|
||||
reportLines.push(normalizedPendingLine);
|
||||
}
|
||||
await planGddApprovalPromise;
|
||||
if (planGddApprovalError) throw planGddApprovalError;
|
||||
return {
|
||||
...result,
|
||||
turnReportOutput: reportLines.join('\n'),
|
||||
planGddApproval,
|
||||
};
|
||||
} finally {
|
||||
setActiveChild(null);
|
||||
@@ -1780,196 +1723,6 @@ export async function validateSwarmProjectArtifacts(projectPath, options) {
|
||||
return inspection;
|
||||
}
|
||||
|
||||
// 这四条路径的权威定义都在 Rust 侧 `planning_storage.rs`(`PLAN_SESSION_PATH`、
|
||||
// `PLAN_GDD_INDEX_PATH`、`PLAN_STORAGE_ROOT`、`PLAN_FAST_GDD_PATH`)。跨语言没有共享
|
||||
// 常量的通道,改路径时要连同 `GddApprovalCard.tsx` 一起动。
|
||||
export const planningOutputPaths = [
|
||||
'.agent/planning/session.json',
|
||||
'.agent/planning/index.json',
|
||||
'.agent/planning/pending.json',
|
||||
'game/fast_gdd.md',
|
||||
];
|
||||
|
||||
export async function inspectPlanningOutputs(projectPath) {
|
||||
const outputs = [];
|
||||
for (const relativePath of planningOutputPaths) {
|
||||
const absolutePath = path.join(projectPath, ...relativePath.split('/'));
|
||||
const metadata = await lstat(absolutePath).catch((error) => {
|
||||
if (error?.code === 'ENOENT') return null;
|
||||
throw error;
|
||||
});
|
||||
outputs.push({
|
||||
path: relativePath,
|
||||
exists: Boolean(metadata?.isFile()),
|
||||
bytes: metadata?.isFile() ? metadata.size : 0,
|
||||
});
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
||||
async function reportPlanningOutputs(projectPath) {
|
||||
const outputs = await inspectPlanningOutputs(projectPath);
|
||||
console.log('\n立项策划产物:');
|
||||
for (const output of outputs) {
|
||||
console.log(
|
||||
output.exists
|
||||
? ` [有] ${output.path}(${output.bytes} 字节)`
|
||||
: ` [无] ${output.path}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const planGddApprovalTimeoutMs = 60_000;
|
||||
export const planGddStatusOutputPrefix = 'planGddStateJson=';
|
||||
export const planGddDecisionOutputPrefix = 'planGddDecisionJson=';
|
||||
|
||||
function parsePrefixedJsonLine(output, prefix, label) {
|
||||
const line = output
|
||||
.split('\n')
|
||||
.map((value) => (value.endsWith('\r') ? value.slice(0, -1) : value))
|
||||
.find((value) => value.startsWith(prefix));
|
||||
if (!line) throw new Error(`${label}缺少 ${prefix} 输出`);
|
||||
try {
|
||||
return JSON.parse(line.slice(prefix.length));
|
||||
} catch (error) {
|
||||
throw new Error(`解析${label}失败:${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function parsePlanGddStatusOutput(output) {
|
||||
return parsePrefixedJsonLine(
|
||||
output,
|
||||
planGddStatusOutputPrefix,
|
||||
'Fast GDD 审批状态',
|
||||
);
|
||||
}
|
||||
|
||||
export function parsePlanGddDecisionOutput(output) {
|
||||
return parsePrefixedJsonLine(
|
||||
output,
|
||||
planGddDecisionOutputPrefix,
|
||||
'Fast GDD 审批回执',
|
||||
);
|
||||
}
|
||||
|
||||
// 审批卡是这条链路唯一的人类判据,所以自动应答默认只投 approve,且只在投影确实有
|
||||
// 一张待决定审批时出手。revise/reject 需要一段真实的修改意见,让机器编一段等于把
|
||||
// 判据换成噪声——所以那两条分支只在跑的人自己用 AGC_PLAN_GDD_COMMENT 给出意见时
|
||||
// 才走。手工调 --plan-gdd-decide 也能达到同样效果,但那要求 plan 根 run 仍然活着,
|
||||
// 而它恰好是本进程持有的 CLI 子进程。
|
||||
export function planGddAutoApprovalIsPending(state) {
|
||||
return Boolean(state?.pendingApproval);
|
||||
}
|
||||
|
||||
export function resolvePlanGddAutoDecision(env = process.env) {
|
||||
const action = (env.AGC_PLAN_GDD_DECISION ?? 'approve').trim();
|
||||
if (!['approve', 'revise', 'reject'].includes(action)) {
|
||||
throw new Error('AGC_PLAN_GDD_DECISION 只能是 approve / revise / reject');
|
||||
}
|
||||
const comment = (env.AGC_PLAN_GDD_COMMENT ?? '').trim();
|
||||
if (action === 'approve') return { action, comment: null };
|
||||
if (!comment) {
|
||||
throw new Error(
|
||||
`${action} 必须同时设 AGC_PLAN_GDD_COMMENT 提供真实修改意见`,
|
||||
);
|
||||
}
|
||||
return { action, comment };
|
||||
}
|
||||
|
||||
async function settlePlanGddApproval(
|
||||
projectPath,
|
||||
runtimeConfigPath,
|
||||
setActiveChild,
|
||||
) {
|
||||
const readStatus = async () => {
|
||||
const result = await runCapturedCargo(
|
||||
['--config-dir', runtimeConfigPath, '--plan-gdd-status', projectPath],
|
||||
setActiveChild,
|
||||
{
|
||||
timeoutMs: planGddApprovalTimeoutMs,
|
||||
label: 'Fast GDD 审批状态查询',
|
||||
},
|
||||
);
|
||||
if (result.code !== 0 || result.signal) {
|
||||
throw new Error(
|
||||
`读取 Fast GDD 审批状态失败:${result.stderr.trim() || result.stdout.trim()}`,
|
||||
);
|
||||
}
|
||||
return parsePlanGddStatusOutput(result.stdout);
|
||||
};
|
||||
|
||||
const before = await readStatus();
|
||||
if (!planGddAutoApprovalIsPending(before)) {
|
||||
return { decided: false, state: before };
|
||||
}
|
||||
const { action, comment } = resolvePlanGddAutoDecision();
|
||||
const decision = await runCapturedCargo(
|
||||
[
|
||||
'--config-dir',
|
||||
runtimeConfigPath,
|
||||
'--plan-gdd-decide',
|
||||
projectPath,
|
||||
action,
|
||||
...(comment === null ? [] : ['--stdin']),
|
||||
],
|
||||
setActiveChild,
|
||||
{
|
||||
timeoutMs: planGddApprovalTimeoutMs,
|
||||
label: 'Fast GDD 审批决定',
|
||||
stdin: comment,
|
||||
},
|
||||
);
|
||||
if (decision.code !== 0 || decision.signal) {
|
||||
throw new Error(
|
||||
`提交 Fast GDD 审批决定失败:${decision.stderr.trim() || decision.stdout.trim()}`,
|
||||
);
|
||||
}
|
||||
const receipt = parsePlanGddDecisionOutput(decision.stdout);
|
||||
// 回执落盘和唤醒后台任务是两件事:decide 命令把唤醒失败降级成 recoveryPending,
|
||||
// 于是审批已经生效、Run 却仍停在 waiting-for-user-input。实测就是这样——只有
|
||||
// 补一次 --agent-resume 才会重新起 turn。这是仓库自己给这个状态定义的恢复动作。
|
||||
let recovered = false;
|
||||
if (receipt.recoveryPending) {
|
||||
const resume = await runCapturedCargo(
|
||||
['--config-dir', runtimeConfigPath, '--agent-resume', projectPath],
|
||||
setActiveChild,
|
||||
{
|
||||
timeoutMs: planGddApprovalTimeoutMs,
|
||||
label: 'Fast GDD 审批后恢复后台任务',
|
||||
},
|
||||
);
|
||||
if (resume.code !== 0 || resume.signal) {
|
||||
throw new Error(
|
||||
`审批已提交但恢复后台任务失败:${resume.stderr.trim() || resume.stdout.trim()}`,
|
||||
);
|
||||
}
|
||||
recovered = true;
|
||||
}
|
||||
return { decided: true, receipt, recovered, state: await readStatus() };
|
||||
}
|
||||
|
||||
async function reportPlanGddApproval(approval) {
|
||||
const { state } = approval;
|
||||
console.log('\nFast GDD 审批:');
|
||||
if (!approval.decided) {
|
||||
console.log(` [无待决定审批] 当前投影状态=${state.state}`);
|
||||
return;
|
||||
}
|
||||
console.log(
|
||||
` [已决定 ${approval.receipt.decisionRef.action}] outcome=${approval.receipt.outcome} v${approval.receipt.decisionRef.version} 投影状态=${state.state}`,
|
||||
);
|
||||
if (approval.recovered) {
|
||||
console.log(
|
||||
' [已恢复] 审批回执的 recoveryPending 由一次 --agent-resume 收口',
|
||||
);
|
||||
}
|
||||
if (state.session) {
|
||||
console.log(
|
||||
` 澄清轮次=${state.session.clarificationRound} 返工深度=${state.session.repairDepth} phase=${state.session.phase}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function hasConfiguredEditorApiKey(configDir) {
|
||||
let configured = false;
|
||||
for (const fileName of [configFileName, localConfigFileName]) {
|
||||
@@ -2122,13 +1875,7 @@ export async function runSwarmTestChat(options) {
|
||||
const setActiveChild = (child) => {
|
||||
activeChild = child;
|
||||
};
|
||||
// GDD 审批要和 swarm CLI 并发跑,两者不能共用 activeChild 这一个槽位:审批子进程
|
||||
// 结束时的 setActiveChild(null) 会把 CLI 从槽里抹掉,Ctrl-C 就杀不到它了。
|
||||
const concurrentChildren = new Set();
|
||||
const setConcurrentChild = (child) => {
|
||||
if (child) concurrentChildren.add(child);
|
||||
else concurrentChildren.clear();
|
||||
};
|
||||
const stopRequested = () => receivedSignal !== null;
|
||||
const handleSignal = (signal) => {
|
||||
const repeatedSignal = receivedSignal !== null;
|
||||
@@ -2206,11 +1953,10 @@ export async function runSwarmTestChat(options) {
|
||||
);
|
||||
}
|
||||
console.log('LLM 配置已就绪。');
|
||||
const requirementNoun = options.plan ? '立项策划需求' : '游戏需求';
|
||||
console.log(
|
||||
options.task
|
||||
? `已提交一条非交互${requirementNoun},正在等待 Swarm 自主完成。\n`
|
||||
: `输入一条${requirementNoun}并回车;提交后按 Ctrl+D,让 Swarm 自主完成。\n`,
|
||||
? '已提交一条非交互游戏需求,正在等待 Swarm 自主完成。\n'
|
||||
: '输入一条游戏需求并回车;提交后按 Ctrl+D,让 Swarm 自主完成。\n',
|
||||
);
|
||||
|
||||
phase = 'chat';
|
||||
@@ -2220,8 +1966,7 @@ export async function runSwarmTestChat(options) {
|
||||
runtimeConfig.path,
|
||||
'--swarm-chat',
|
||||
'--init',
|
||||
// 做方案链路只能跑 standard 档,后端对 plan + autonomous 是硬否决。
|
||||
options.plan ? '--plan' : '--autonomous-game-build',
|
||||
'--autonomous-game-build',
|
||||
project.path,
|
||||
];
|
||||
let chat;
|
||||
@@ -2234,15 +1979,6 @@ export async function runSwarmTestChat(options) {
|
||||
timeoutDeadline === null
|
||||
? null
|
||||
: Math.max(1, timeoutDeadline - Date.now()),
|
||||
options.plan,
|
||||
options.plan
|
||||
? () =>
|
||||
settlePlanGddApproval(
|
||||
project.path,
|
||||
runtimeConfig.path,
|
||||
setConcurrentChild,
|
||||
)
|
||||
: null,
|
||||
)
|
||||
: await runInteractiveCargo(chatArguments, setActiveChild);
|
||||
} catch (error) {
|
||||
@@ -2258,32 +1994,6 @@ export async function runSwarmTestChat(options) {
|
||||
if (options.task) {
|
||||
turnReport = parseSettledSwarmTurnReport(chat.turnReportOutput);
|
||||
}
|
||||
if (options.plan) {
|
||||
// 立项策划不出游戏产物,正式验收在 GDD 审批卡上;这里只报告落盘情况,
|
||||
// 是否收束已经由 CLI 的退出码判过了。
|
||||
// 自动任务档的审批已经在 CLI 运行期间并发做完了;手工档(人自己敲 Ctrl+D
|
||||
// 退出)没有那次触发,退出后补一次,没有待决定审批时它是只读的。
|
||||
phase = 'plan-approval';
|
||||
const approval =
|
||||
chat.planGddApproval ??
|
||||
(await settlePlanGddApproval(
|
||||
project.path,
|
||||
runtimeConfig.path,
|
||||
setConcurrentChild,
|
||||
));
|
||||
if (receivedSignal) break session;
|
||||
phase = 'plan-report';
|
||||
await reportPlanGddApproval(approval);
|
||||
await reportPlanningOutputs(project.path);
|
||||
phase = 'complete';
|
||||
console.log(
|
||||
approval.decided
|
||||
? '\n立项策划链路已收束:Fast GDD 已批准,策划产物见上方清单。'
|
||||
: '\n立项策划链路已收束:Run 正常结束但没有待决定审批,策划产物见上方清单。',
|
||||
);
|
||||
break session;
|
||||
}
|
||||
phase = 'artifact-validation';
|
||||
const requireEditorImages = await hasConfiguredEditorApiKey(
|
||||
runtimeConfig.path,
|
||||
);
|
||||
|
||||
@@ -43,7 +43,6 @@ struct PromptCompositions {
|
||||
/// 而是一份独立的完整清单:plan 根的工具面只有 7 个原生工具,专业组、
|
||||
/// isolated child、任务图与视觉产物合同在这条链路上全部不可执行,逐段
|
||||
/// 减法会把「plan 根到底看到什么」摊在两个函数的四个否定分支里。
|
||||
supervisor_plan: Vec<String>,
|
||||
supervisor_chat: SupervisorChatComposition,
|
||||
}
|
||||
|
||||
@@ -99,10 +98,6 @@ struct ProviderFragments {
|
||||
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
||||
struct AgentCatalog {
|
||||
supervisor: AgentGroup,
|
||||
/// 立项策划子 Agent。与 `supervisor` 平级、**不进 `groups`**:`specialist_nodes`
|
||||
/// 只从 `groups[].roles[]` 派生,因此它不参与 `build.rs` 与种子 DAG 的一致性
|
||||
/// 校验,「做游戏」的 16 任务 DAG 一行不动。详见技术方案第 3.1 节。
|
||||
planning: AgentGroup,
|
||||
groups: Vec<AgentGroup>,
|
||||
}
|
||||
|
||||
@@ -231,12 +226,6 @@ pub fn compile_manifest(manifest_path: &Path) -> Result<CompiledPromptBundle, St
|
||||
§ions,
|
||||
&["$base", "$visualContract"],
|
||||
)?;
|
||||
validate_composition(
|
||||
"supervisorPlan",
|
||||
&manifest.compositions.supervisor_plan,
|
||||
§ions,
|
||||
&["$header"],
|
||||
)?;
|
||||
validate_section_reference(
|
||||
&manifest.compositions.supervisor_chat.identity,
|
||||
§ions,
|
||||
@@ -299,7 +288,6 @@ pub fn compile_manifest(manifest_path: &Path) -> Result<CompiledPromptBundle, St
|
||||
.supervisor
|
||||
.roles
|
||||
.iter()
|
||||
.chain(manifest.agent_catalog.planning.roles.iter())
|
||||
.chain(
|
||||
manifest
|
||||
.agent_catalog
|
||||
@@ -348,7 +336,6 @@ pub fn compile_manifest(manifest_path: &Path) -> Result<CompiledPromptBundle, St
|
||||
.runtime
|
||||
.iter()
|
||||
.chain(manifest.compositions.supervisor.iter())
|
||||
.chain(manifest.compositions.supervisor_plan.iter())
|
||||
.filter(|item| !item.starts_with('$'))
|
||||
.cloned()
|
||||
.collect::<BTreeSet<_>>();
|
||||
@@ -421,14 +408,6 @@ fn validate_section_ownership(manifest: &PromptBundleManifest) -> Result<(), Str
|
||||
{
|
||||
register("composition supervisor", section);
|
||||
}
|
||||
for section in manifest
|
||||
.compositions
|
||||
.supervisor_plan
|
||||
.iter()
|
||||
.filter(|section| !section.starts_with('$'))
|
||||
{
|
||||
register("composition supervisorPlan", section);
|
||||
}
|
||||
register("composition supervisorChat.identity", identity);
|
||||
register(
|
||||
"composition supervisorChat.finalReply",
|
||||
@@ -457,19 +436,9 @@ fn validate_section_ownership(manifest: &PromptBundleManifest) -> Result<(), Str
|
||||
"composition supervisor",
|
||||
"composition supervisorChat.identity",
|
||||
]);
|
||||
// plan 根 composition 是 Supervisor system prompt 的第二条 lane,不是另一种
|
||||
// 语义面。它按设计复用 runtime lane 的 `isolatedAgentContract`(`agent.delegate`
|
||||
// 的 expectedArtifacts/writeScopes 合同)和 supervisor lane 的 `supervisorRepair`
|
||||
// (返工必须逐字继承原合同)。除这两个方向外,跨所有者复用仍然是错误。
|
||||
let allowed_plan_runtime_owners =
|
||||
BTreeSet::from(["composition runtime", "composition supervisorPlan"]);
|
||||
let allowed_plan_supervisor_owners =
|
||||
BTreeSet::from(["composition supervisor", "composition supervisorPlan"]);
|
||||
for (section, section_owners) in owners {
|
||||
if section_owners.len() > 1
|
||||
&& !(section == identity && section_owners == allowed_identity_owners)
|
||||
&& section_owners != allowed_plan_runtime_owners
|
||||
&& section_owners != allowed_plan_supervisor_owners
|
||||
{
|
||||
return Err(format!(
|
||||
"Prompt section 跨语义所有者复用:{section} -> {section_owners:?}"
|
||||
@@ -706,17 +675,11 @@ fn validate_agent_catalog(catalog: &AgentCatalog) -> Result<(), String> {
|
||||
if catalog.supervisor.roles.len() != 1 {
|
||||
return Err("agentCatalog.supervisor 必须且只能包含一个 role".to_string());
|
||||
}
|
||||
if catalog.planning.roles.len() != 1 {
|
||||
return Err("agentCatalog.planning 必须且只能包含一个 role".to_string());
|
||||
}
|
||||
if catalog.groups.is_empty() {
|
||||
return Err("agentCatalog.groups 不能为空".to_string());
|
||||
}
|
||||
let mut group_brief_names = BTreeSet::new();
|
||||
for group in std::iter::once(&catalog.supervisor)
|
||||
.chain(std::iter::once(&catalog.planning))
|
||||
.chain(catalog.groups.iter())
|
||||
{
|
||||
for group in std::iter::once(&catalog.supervisor).chain(catalog.groups.iter()) {
|
||||
if !group_brief_names.insert(group.brief_path_name.as_str()) {
|
||||
return Err(format!(
|
||||
"agent group briefPathName 重复:{}",
|
||||
@@ -724,10 +687,7 @@ fn validate_agent_catalog(catalog: &AgentCatalog) -> Result<(), String> {
|
||||
));
|
||||
}
|
||||
}
|
||||
let mut generated_names = BTreeSet::from([
|
||||
"PROJECT_SUPERVISOR".to_string(),
|
||||
"PROJECT_PLANNING".to_string(),
|
||||
]);
|
||||
let mut generated_names = BTreeSet::from(["PROJECT_SUPERVISOR".to_string()]);
|
||||
for group in &catalog.groups {
|
||||
let generated = rust_identifier(&group.id);
|
||||
if !generated
|
||||
@@ -753,12 +713,6 @@ fn validate_agent_catalog(catalog: &AgentCatalog) -> Result<(), String> {
|
||||
&mut task_ids,
|
||||
&mut tool_ids,
|
||||
)?;
|
||||
validate_agent_group(
|
||||
&catalog.planning,
|
||||
&mut group_ids,
|
||||
&mut task_ids,
|
||||
&mut tool_ids,
|
||||
)?;
|
||||
for group in &catalog.groups {
|
||||
validate_agent_group(group, &mut group_ids, &mut task_ids, &mut tool_ids)?;
|
||||
}
|
||||
@@ -920,10 +874,6 @@ fn render_rust(manifest: &PromptBundleManifest, sections: &BTreeMap<String, Stri
|
||||
"RUNTIME_PROMPT_SUPERVISOR_COMPOSITION",
|
||||
&manifest.compositions.supervisor,
|
||||
));
|
||||
output.push_str(&render_string_slice_const(
|
||||
"RUNTIME_PROMPT_SUPERVISOR_PLAN_COMPOSITION",
|
||||
&manifest.compositions.supervisor_plan,
|
||||
));
|
||||
output.push_str(&format!(
|
||||
"pub(crate) const RUNTIME_PROMPT_SUPERVISOR_CHAT_COMPOSITION: &[&str] = &[{}, {}];\n",
|
||||
rust_literal(&manifest.compositions.supervisor_chat.identity),
|
||||
@@ -1012,26 +962,6 @@ fn render_agent_catalog(catalog: &AgentCatalog) -> String {
|
||||
"static PROJECT_SUPERVISOR_AGENT_DEFINITION: AgentGroupDefinition = {};\n",
|
||||
render_group_value(&catalog.supervisor, "&PROJECT_SUPERVISOR_AGENT_ROLES")
|
||||
));
|
||||
let planning_role = &catalog.planning.roles[0];
|
||||
output.push_str(&format!(
|
||||
"pub(crate) const GAME_CREATOR_PROJECT_PLANNING_AGENT_ID: &str = {};\n",
|
||||
rust_literal(&planning_role.task_id)
|
||||
));
|
||||
output.push_str(&format!(
|
||||
"pub(crate) const GAME_CREATOR_PROJECT_PLANNING_MEMORY_PATH: &str = {};\n",
|
||||
rust_literal(&format!(
|
||||
"memory/agents/{}",
|
||||
catalog.planning.brief_path_name
|
||||
))
|
||||
));
|
||||
output.push_str(&render_role_array(
|
||||
"PROJECT_PLANNING_AGENT_ROLES",
|
||||
&catalog.planning.roles,
|
||||
));
|
||||
output.push_str(&format!(
|
||||
"static PROJECT_PLANNING_AGENT_DEFINITION: AgentGroupDefinition = {};\n",
|
||||
render_group_value(&catalog.planning, "&PROJECT_PLANNING_AGENT_ROLES")
|
||||
));
|
||||
for group in &catalog.groups {
|
||||
let roles_name = format!("{}_AGENT_ROLES", rust_identifier(&group.id));
|
||||
output.push_str(&render_role_array(&roles_name, &group.roles));
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
"supervisorVisualWithEditor": "supervisor/visual-contract-with-editor.md",
|
||||
"supervisorPlaybook": "supervisor/playbook.md",
|
||||
"supervisorClaimGate": "supervisor/claim-gate.md",
|
||||
"supervisorRepair": "supervisor/repair.md",
|
||||
"projectPlanningRoleBrief": "roles/project-planning.md",
|
||||
"planCommon": "plan/common.md",
|
||||
"planSupervisorIdentity": "plan/supervisor-identity.md",
|
||||
"planSupervisorPlaybook": "plan/supervisor-playbook.md"
|
||||
"supervisorRepair": "supervisor/repair.md"
|
||||
},
|
||||
"compositions": {
|
||||
"runtime": [
|
||||
@@ -47,14 +43,6 @@
|
||||
"supervisorClaimGate",
|
||||
"supervisorRepair"
|
||||
],
|
||||
"supervisorPlan": [
|
||||
"$header",
|
||||
"planCommon",
|
||||
"isolatedAgentContract",
|
||||
"planSupervisorIdentity",
|
||||
"planSupervisorPlaybook",
|
||||
"supervisorRepair"
|
||||
],
|
||||
"supervisorChat": {
|
||||
"identity": "supervisorIdentityContract",
|
||||
"finalReply": "supervisorFinalReplyContract"
|
||||
@@ -70,12 +58,7 @@
|
||||
"editorUnavailable": "supervisorVisualWithoutEditor"
|
||||
}
|
||||
},
|
||||
"roleOverlays": [
|
||||
{
|
||||
"agentId": "project-planning",
|
||||
"sections": ["projectPlanningRoleBrief"]
|
||||
}
|
||||
],
|
||||
"roleOverlays": [],
|
||||
"providerFragments": {
|
||||
"isolatedToolContract": "providerIsolatedToolContract",
|
||||
"autonomousRunProfile": "providerAutonomousRunProfile",
|
||||
@@ -102,21 +85,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"planning": {
|
||||
"id": "planning",
|
||||
"label": "立项策划",
|
||||
"role": "Project Planning",
|
||||
"briefPathName": "project-planning.md",
|
||||
"roles": [
|
||||
{
|
||||
"id": "project-planning",
|
||||
"role": "Project Planning",
|
||||
"taskId": "project-planning",
|
||||
"toolId": "agent.runtime.project-planning",
|
||||
"briefPathName": "project-planning.md"
|
||||
}
|
||||
]
|
||||
},
|
||||
"groups": [
|
||||
{
|
||||
"id": "design",
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
用户只描述玩法类型、机制或相似体验时,不代表授权复刻现有游戏。所有专业 Agent 必须创建原创标题、阵营、资源、单位名称、角色造型、界面术语和视觉语言;禁止沿用、翻译或近似改写现有游戏的专有角色、单位名、Logo、贴图、标志性布局与受保护视觉语言。除非用户明确提供有权使用的项目内素材,否则不得把 Sunflower、Peashooter、向日葵、豌豆射手、僵尸等知名塔防元素写入策划、记忆、代码、图片提示或正式产物。
|
||||
|
||||
静态委派协议:新 agent.delegate 必须提交 1-8 条 acceptanceCriteria、0-16 个精确项目内非私有 expectedArtifacts,以及 nullable repairOfDelegationId/runId/continuationOfDelegationId/questionsSha256/answersSha256,普通委派后三项传 null。专业 Agent 收到的 task 会携带完整合同。Supervisor 认领回执后必须区分 evidence-ready、needs-user-input 与 needs-repair;前者仍需语义验收,needs-repair 不能作为成功。专业 Agent 若缺少会实质改变结果的用户事实,不能调用 user.input_request,必须以最终回复首行 `AGC_NEEDS_USER_INPUT_V1`,下一行短 JSON `{"questions":[...]}` 返回 1-3 个结构化问题;Runtime 会把它作为内部回执交给 Supervisor。Supervisor 对每个原 delivery 逐一用现有 user.input_request 提问,收齐对应答案后最多创建一次 continuation 委派,并同时提交 continuationOfDelegationId、questionsSha256、answersSha256;Runtime 会自动派生稳定 continuation identity,不得把多个 delivery 的问题或答案混入同一 continuation。
|
||||
|
||||
每 6 轮只是一次进度 checkpoint 与停滞检测,不是上下文压缩或 run 的终止上限;只要 observation 出现新的独立进展,就在同一 run 继续下一窗口,只有窗口没有新进展时才按停滞处理。真正的上下文压缩仅由 token 阈值或显式 compact 触发。
|
||||
|
||||
必须直接调用与当前请求广告的工具一一对应的动作函数,或在本阶段确实无事可做时调用 respond_to_user。本 run 不维护结构化计划,也没有 update_agent_plan 可调;工具结果会由 Runtime 作为 observation 返回,不要假装工具已执行,不要把动作或回复放进普通文本,不要 markdown,不要泄露密钥。
|
||||
@@ -1,7 +0,0 @@
|
||||
你是 Genarrative AI 游戏创作桌面 App 的 Project Supervisor。当前 run 是立项策划根 run(`source=project-supervisor-plan`),你是用户在本条链路里唯一的对话对象。
|
||||
|
||||
你不生产策划内容。本链路的全部策划工作——提问、取舍、撰写 GDD——都由 `project-planning` 子 Agent 完成。你只有四件事:冻结目标合同;发起与续跑对 `project-planning` 的委派;代子 Agent 向用户提问并把答案原样转达回去;在子 Agent 提交 GDD 后完成取证,把审批交给用户。
|
||||
|
||||
你不做的事:不自己提策划问题(`user.input_request` 只能用于转达子 Agent 的问题信封);不自己撰写、补写或改写 GDD 正文、决定台账与原型验证项;不替用户做产品决定;不写文件、不跑命令、不做预览、不生成素材、不查询任务图、不调度 ready 任务;不委派 `project-planning` 以外的任何 Agent,也不创建 isolated child 或启动构建。
|
||||
|
||||
`project-planning` 的消息和回执只是原目标的证据,不能替换原目标。contractStatus=evidence-ready 只代表客观证据齐全,你仍须按 acceptanceCriteria 逐条完成语义验收;needs-repair 不得忽略,同一原委派最多发起一轮显式返工。GDD 最终是否通过由用户在审批卡上决定,不由你代答。
|
||||
@@ -1,22 +0,0 @@
|
||||
【固定动作顺序,不得跳步】
|
||||
|
||||
1. 本 run 第一轮只调用一次 `agent.goal_contract` 冻结目标合同:outcome 概括用户原话意图,`preferences` 必须传空数组,`acceptanceNodes` 提交 Runtime 指定的固定单节点。这一轮不做任何其它调用。
|
||||
2. 冻结后立即用一次 `agent.delegate` 把任务委派给 `project-planning`,`expectedArtifacts` 写 `game/fast_gdd.md`,`repairOfDelegationId`、`runId`、`continuationOfDelegationId`、`questionsSha256`、`answersSha256` 全传 null。已有委派尚未收束时不要重复委派。
|
||||
3. 等待子 Agent 期间不得调用 `respond_to_user`。Runtime 会通过 delegate 完成屏障保持同一父 run,回执到达后再继续。
|
||||
4. 子 Agent 以问询信封退出时,决策卡由 Runtime 直接按信封原文呈现给用户,**不需要你调用任何工具**——你根本不会在那一刻被恢复。用户答完之后你才会拿到答案,届时为该原 delivery 创建且仅创建一次 continuation 委派,`continuationOfDelegationId` 与 `repairOfDelegationId` 都指向该原 delivery。`questionsSha256`、`answersSha256`、`acceptanceCriteria`、`expectedArtifacts` 四个全传 null——Runtime 会从该原 delivery 补齐权威指纹和原委派合同,你不要自己抄。子 Agent 在 continuation 里**再次**以信封退出时,对那条新 delivery 重复同一动作:「仅创建一次」约束的是单条 delivery,不是整条链,澄清预算未用尽时这个循环继续。Runtime 会在委派 task 末尾写明已用轮次与上限,不需要你自己数,也不要替它宣布预算已尽。
|
||||
5. 回执 contractStatus=evidence-ready 且 GDD 已提交时,用 `file.read` 从第 1 行读到 `game/fast_gdd.md` 末尾取证,每次都传 `maxLines: 240`(上限),尽量一页读完;确实需要第二页时从上一页的下一行开始,不要重复读同一段。每次 `file.read` 的 observation 末尾都带着 `sourceAgentId` / `sourceRunId` / `sourceActionId` 三个字段,把它们原样抄成 evidence 的 `{agentId, runId, actionId}`,用一次 `agent.acceptance_update` 一并提交即可——evidence 是按这三个字段整体查回执的,回忆错任何一个都会被判成"缺少持久动作回执"。不要为了取这些字段再去查动作历史。取证完成前审批卡不会出现。
|
||||
6. 用户在审批卡上选择修改或退回时,直接创建返工委派:`repairOfDelegationId` 指向原 delegationId,`runId`、`acceptanceCriteria`、`expectedArtifacts` 都传 null——Runtime 会从原 delivery 继承权威合同,不需要先 `agent.run_status` 去取再手抄。把用户原话完整附在 task 里。「同一原委派只能返工一次」约束的是单条 delivery,不是整条链:用户看过新稿再点一次修改,就对那条新 delivery 重复同一动作,这个循环没有次数上限——`repair_depth` 防的是 runaway agent,而每一轮修订都由用户亲手触发,人本身就是循环边界。不要替 Runtime 宣布「这是最后一次修改机会」,也不要因此把多条意见攒到一轮里改完。用户通过后只做一句简短收尾。
|
||||
|
||||
【转达的规则】
|
||||
|
||||
- 把用户答案回灌给 `project-planning` 时,逐条列出全部已确认决定,每条格式为 `[已确认] 第N轮问的是:{question 原文} | 候选项:{option1.label} / {option2.label} / {option3.label} → 用户答:{原文}`。**问题原文和三个选项标签必须带上**:`{header}` 只写到「第N轮·当前要决定:{主题}」这一层,答案落在选项上;子 Agent 每轮都是全新 run,除了这段正文什么都看不到,只给它主题和答案,「类似B」「B · 沙盒里程碑成长」这类答案就无从解读,它只能把同一件事再问一遍。用户答案原文一字不改、不归纳、不拆分、不搬轮次;任务长度接近上限时压缩你自己的说明文字和选项描述,绝不压缩用户答案、问题原文和选项标签。
|
||||
- 策划链路的澄清信封**恰好一题**,不是通用静态委派协议里的 1-3 题:`project-planning` 每轮只提一个主要决定,Runtime 也只接受一题,多于一题会在出卡时被拒。委派 task 里不要写“1-3 个结构化问题”。
|
||||
- 上一条格式里的三个选项标签就是决策卡上的 A、B 和“需要原型验证”,必须原样转述、一个都不能省;B 是用户确认的 `confirmed/user_option`,不能转成默认建议。用户后续自由填写推翻了更早的决定时,你只负责把两轮答案的原文都原样带到,并说明后者更晚;怎么记进决定台账由 `project-planning` 判断,不要替它裁定哪条作废。
|
||||
|
||||
【委派合同的边界】
|
||||
|
||||
委派 `project-planning` 时,acceptanceCriteria 只写产物形状、覆盖范围与红线(例如必须交付 `game/fast_gdd.md`、必须原创、必须只定义一个 MVP 闭环),**不得替用户预先裁定产品取舍**。用户没有指定的玩法规则、数值、关卡量级、美术方向和目标人群,一律留给策划子 Agent 按其 3 轮问询预算决定是提问还是按默认建议填写;不要写“未指定的标注为立项假设”“自行假设后继续”这类指令,那会把问询预算作废。平台事实(自包含 Web、desktop/mobile 双视口、keyboard/touch 双输入、本地 HTTP 预览)由 Runtime 固定注入,属于已定事实,不得要求标为待定、建议或开放项。
|
||||
|
||||
**本轮指令三选一。** 委派任务正文里,除了用户原始意图和已确认答案原文,你只能再写一句“本轮该做什么”,且必须是下面三个之一:**继续澄清**(默认,不附加任何前置条件)、**直接出稿**(仅当用户明确要求跳过问询)、**按意见修订**(仅审批返回修改或退回时)。不要自己描述“什么情况下才该提问”“若缺少会实质改变结果的事实则……”“否则直接提交完整 GDD”——那不在这三项里。提问预算怎么花,由 `project-planning` 按 Runtime 注入的判据决定。
|
||||
|
||||
不要向用户暴露内部 task/event、工具计划、动态 child ID 或调试状态。
|
||||
@@ -1,33 +0,0 @@
|
||||
你是“立项策划 Agent”(`agentId=project-planning`),由 Project Supervisor 通过静态 `agent.delegate` 委派。你的工作是把一句用户需求收敛成可审批的 MVP Fast GDD;你只负责玩法澄清、原型验证建议和最小 GDD,不负责完整游戏构建。
|
||||
|
||||
## 身份与边界
|
||||
|
||||
- 当前 run 固定为 `source=agent-delegate`、`profile=standard`,父 Agent 是 `project-supervisor`。不得伪造、改写或猜测这些 Runtime 身份。
|
||||
- 你不能委派或调度其他 Agent,不能创建 isolated child,不能调用 MCP、命令、进程、预览、画布、素材生成、写入/补丁/删除工具,也不能改变项目版本或审批事实。
|
||||
- 你的原生工具目录只应包含 `file.read`、`file.list` 以及 Runtime 协议控制函数 `update_agent_plan`、`respond_to_user`;`user.input_request` 不属于你的工具目录。若需要用户决定,必须以终态信封首行 `AGC_NEEDS_USER_INPUT_V1` 退出本轮,下一行给出严格 JSON 信封 `{"questions":[{ ... }]}`,交由 Supervisor 转发。`questions` 恰好一个元素;元素字段只能是 `id`、`header`、`question`、`options` 四个,多写任何字段(例如 `answerFormat`)或省掉 `questions` 外壳都会被 Runtime 拒收,整条委派随即作废。`id` 是唯一 snake_case(小写字母开头,只含小写字母、数字、下划线);`header` 是决策卡标题,写成 `第N轮·当前要决定:<主题>`,单行且不超过 60 字符;`question` 是决策卡正文,单行且不超过 400 字符;`options` 恰好 3 个 `{"label": ..., "description": ...}`,依次是 A、B、逐字“需要原型验证”(详见下文决策卡一段),label 单行不超过 60 字符、description 单行不超过 240 字符。不要另起一行写答题说明或把选项复述进 `question`,作答方式由 Runtime 自己呈现。
|
||||
- 只有 Runtime 广告并允许 `plan.submit_gdd` 时才可提交 GDD;不要假设未广告的工具存在,也不要把 GDD、审批或下游构建写进普通文本。
|
||||
|
||||
## 目标与轮次
|
||||
|
||||
- 最多进行 3 轮关键澄清;每轮是新 run、同一 session。你看得到自己的历史,但用户答案以 Supervisor 委派任务中的转述为准,缺失信息不能臆造。
|
||||
- **默认先澄清。** 出稿只有四个触发器,除此之外每轮都先做下面的字段差距检测再决定问不问:①任务正文出现“直接出稿”这四个字;②已完成第 3 轮澄清(任务正文写明的已用轮次已达上限);③剩余空白都能由默认建议覆盖,且不影响首个可玩闭环;④收到 Runtime 的活跃预算或超时提示。任务正文能改变流程的只有第 ① 条——它写的其它说明属于内容,不是出稿触发器。既定事实(用户答案、已确认决定)仍以任务正文为准。
|
||||
- 每轮提问前逐项对照 `plan-submit-gdd-input.v1` 的 `game` 字段做差距检测:用户明确提供的 = `confirmed`;有依据可推断的 = 按下面的默认建议填写并标 `default_pending`;无从判断的 = 空白。提问名额只花在**空白或存疑、且影响首个可玩闭环**的决定上;有默认建议兜底的字段优先用默认建议而不是提问——「有默认」不等于「不能问」,那条默认明显可能是错的、且选错就做不出首个可玩闭环时,它就是一个该问的存疑项。`title`、`oneLiner`、`mvpSystems`、`creatorTips` 由你生成并标 `default_pending`,不作为提问对象;`platformFacts` 禁问。
|
||||
- **默认建议**(一律 `answerSource=default`、`round=0`;只用于缩短对话,不覆盖用户明确输入):`targetUsers.sessionLength` 缺 → 10~20 分钟一局;`artStyle` 缺 → `visualType` 风格化、轮廓清楚,`keywords` 取自已确认的核心行为,`mvpArtBoundary` 写明 MVP 用占位资产、资产可复用;缺成长时 → 1 条成长线和 2~3 个选择;缺探索时 → 1 条主路线加 1 个有意义的岔路;缺构建时 → 高风险输出和稳健防御两种方向。清单之外的字段没有默认值兜底——`genre.fusion`、`targetUsers.coreUsers` / `preferences` / `referenceGames`、`outOfScope` 缺失时都算空白,该不该花一轮问它们由上面的判据决定,不要自己拍一个值填掉就当它已经定了。**`pillars` 与 `coreLoop` 没有默认建议**:它们就是首个可玩闭环本身,空白时属于该问的空白,不得用默认值填掉。
|
||||
- 优先顺序:核心行为与本局目标 → 重玩动力 → 制作边界与 MVP。每轮最多问一个主要决定。**已确认决定关掉的那条轴不得重问。** 任务正文里每条 `[已确认]` 都带着当轮的问题原文和三个选项标签,先照它判断哪些轴已经关闭,本轮的问题必须落在另一条还没关闭的轴上。把已确认答案换个说法再问一遍——例如用户已经选定“自由经营、靠成就和攒钱升级推进”,你又拿“短周期经营目标 vs 沙盒里程碑成长”去问——是白烧一轮预算。所有轴都已关闭时按出稿触发器③直接出稿。
|
||||
- 决策卡的 header 写成“第N轮·当前要决定:<主题>”,最多 60 字符。N 是 Runtime 从委派谱系派生的当前轮号,写错会被 Runtime 拒收:首轮恒为 1;之后每次续跑的任务正文都会写明已用轮次与上限,本轮该用的 N 就是“已用轮次 + 1”。`<主题>` 是这一轮真正要定的那件事本身(例如“塔的构筑方式”“每局变化来源”),一句话说完、不带状态标记——它会原样落进决定台账的 `topic`,也是你下一轮辨认哪些轴已经关掉的唯一线索,写成“关键决定”这类空话等于把它作废。正文只问尚未由平台事实或 MVP 规则排除的真实产品取舍,并说明为什么现在问;每张卡固定提供三个选项:A 是你的推荐方案(label 以 `A ·`、`A:`、`A:` 或 `A-` 开头并写明推荐、好处和代价),B 是形状不同且真实可行的平行备选(label 以 `B ·`、`B:`、`B:` 或 `B-` 开头并写明后果和代价),第三项逐字为“需要原型验证”,description 必须给出 30~90 分钟微型原型、试玩对象、观察信号和通过标准。自由输入按用户原话处理。
|
||||
|
||||
## 低幻觉与 GDD 约束
|
||||
|
||||
- 用户描述玩法类型、机制或“像某款游戏”时,不代表授权复刻该游戏。游戏名称、世界观、角色与单位名、阵营、资源、界面术语和视觉语言必须原创;不得沿用、翻译或近似改写现有游戏的专有名称、Logo、标志性布局与受保护视觉语言,也不得把它们写进 GDD 正文、决定台账或原型验证项。用户提到的相似作品只能作为抽象品类参考,`targetUsers.referenceGames` 同样不得填入受保护名称。你的工具面窄,但内容红线不因此放宽——GDD 是整条产线的上游。
|
||||
- 决定台账记录当前 GDD 的决定快照。澄清阶段的 A、B 或自由填写得到的用户决定标 `confirmed`,选择“需要原型验证”标 `prototype_pending`;未提问、由你按默认建议填写的字段标 `default_pending`、`answerSource=default`、`round=0`。审批阶段的用户修改意见是本轮最高优先级:由该意见新增或改写的决定使用 `answerSource=user_revision`、`round=0`,并按当前意见重新填写 `topic`、`state` 和 `answerSummary`。
|
||||
- 以当前 GDD 为基线,仅修改用户审批意见明确涉及的内容,以及为保持内部一致性所必需同步调整的派生内容。未被意见涉及的内容保持不变;如果意见与过去决定冲突,以最新意见为准。不要把用户未要求的其它方向自行扩展进本轮修订。提交时仍须提供完整 GDD 快照,但完整快照不代表可以任意重写未涉及内容。
|
||||
- `prototypeValidationItems` 是必填字段(没有就传空数组),与 `prototype_pending` 决定**一一对应**:每条 `prototype_pending` 决定必须有一个同 id 的验证项,每个验证项也必须对应一条 `prototype_pending` 决定,最多 3 项。除了用户亲选“需要原型验证”之外,你自己也可以主动标:手感、节奏、可读性、难度曲线这类你没问过、但选错就做不出首个可玩闭环的判断,标 `prototype_pending`(`answerSource=default`、`round=0`)比标 `default_pending` 诚实——那不是一个默认值,是一个没人验证过的假设。每项写清 30~90 分钟微型原型做什么、让谁试玩、观察什么信号、什么算通过。
|
||||
- 不得编造具体游戏的机制、数值、销量、人群规模、团队规模或来源。写 `targetUsers` 时按已确认的类型与核心行为描述典型玩家即可。
|
||||
- 只定义一个完整可玩闭环。MVP 不含多人、商城、服务器、开放世界、赛季、复杂社交、完整剧情或全量内容,除非用户明确改变范围。
|
||||
- GDD 至少覆盖:游戏名称与类型、一句话描述、2~4 条游戏支柱、核心循环、目标用户、美术方向、3~6 个最小 MVP 系统、先做/暂缓/验证/扩展条件、决定状态和审批请求。不要把 Runtime 注入的身份、时间、指纹、审批 receipt 或平台事实当作 Provider 输入字段。
|
||||
- 平台事实由 Runtime 固定注入为自包含 Web、desktop/mobile 双视口、keyboard/touch 双输入、本地 HTTP 预览;不得修改、删减或向用户询问。
|
||||
|
||||
## 输出纪律
|
||||
|
||||
- 澄清模式只返回 `AGC_NEEDS_USER_INPUT_V1` 终态信封,不再调用其他函数;成稿模式只在 `plan.submit_gdd` 被广告时调用它并等待 Runtime 校验;收到 revise/reject observation 后按同一 GDD 谱系修订,收到 approve 后只做简短收尾。
|
||||
- 必须直接调用当前请求广告的原生函数;不要输出 JSON、代码围栏或内部思考过程,不要假装已经写入文件、完成审批或启动构建。
|
||||
@@ -3777,8 +3777,6 @@ pub(crate) async fn direct_game_creator_codex_chat_at_with_optional_observer(
|
||||
request_slot: "direct-chat".to_string(),
|
||||
web_search_enabled: config.llm.web_search_enabled,
|
||||
allow_idle_context_compaction: false,
|
||||
// direct-codex 不是立项策划链路,没有 planning session 可绑定。
|
||||
planning_session_binding: None,
|
||||
};
|
||||
let api_kind =
|
||||
parse_game_creator_llm_api_kind(&config.llm.api_kind).map_err(|error| error.to_string())?;
|
||||
@@ -3845,8 +3843,6 @@ pub(crate) async fn direct_game_creator_home_codex_chat(
|
||||
request_slot: "direct-home-chat".to_string(),
|
||||
web_search_enabled: config.llm.web_search_enabled,
|
||||
allow_idle_context_compaction: false,
|
||||
// 直连 Codex 的首页对话不属于任何立项策划 session。
|
||||
planning_session_binding: None,
|
||||
};
|
||||
let api_kind =
|
||||
parse_game_creator_llm_api_kind(&config.llm.api_kind).map_err(|error| error.to_string())?;
|
||||
@@ -4180,7 +4176,6 @@ mod tests {
|
||||
request_slot: "slot-1".to_string(),
|
||||
web_search_enabled: false,
|
||||
allow_idle_context_compaction: false,
|
||||
planning_session_binding: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -337,9 +337,6 @@ pub(crate) fn agent_role_memory_relative_path_for_task(task_id: &str) -> Result<
|
||||
if task_id == GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID {
|
||||
return Ok(GAME_CREATOR_PROJECT_SUPERVISOR_MEMORY_PATH.to_string());
|
||||
}
|
||||
if task_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
return Ok(GAME_CREATOR_PROJECT_PLANNING_MEMORY_PATH.to_string());
|
||||
}
|
||||
for group in GAME_CREATOR_AGENT_GROUP_DEFINITIONS {
|
||||
for role in group.roles {
|
||||
if role.task_id == task_id {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -44,7 +44,6 @@ pub(in crate::agent) use run_status_observation::*;
|
||||
pub(in crate::agent) use structured_plan::*;
|
||||
pub(in crate::agent) use tool_plan_protocol::*;
|
||||
|
||||
pub(crate) use crate::agent::runtime_protocol::plan_gdd_completion_blocker_at_locked;
|
||||
#[cfg(test)]
|
||||
pub(crate) use action_audit::agent_runtime_action_receipt_public_safe_detail_for_test;
|
||||
#[cfg(test)]
|
||||
@@ -74,7 +73,6 @@ pub(crate) use context_compaction::compact_game_creator_agent_runtime_session_at
|
||||
pub(crate) use parallel_ledger::{
|
||||
agent_runtime_confirmation_path_component, agent_runtime_parallel_read_batch_len,
|
||||
agent_runtime_tool_allowed_for_agent, agent_runtime_tool_is_parallel_safe_read,
|
||||
agent_runtime_tool_rejected_by_agent_identity,
|
||||
game_creator_agent_runtime_parallel_read_batch_path,
|
||||
game_creator_agent_runtime_pending_tool_action_path,
|
||||
game_creator_agent_runtime_provider_action_batch_path,
|
||||
@@ -106,6 +104,7 @@ pub(crate) use project_gates::{
|
||||
prepare_agent_runtime_project_mutation_locked, process_session_completion_blocker_at,
|
||||
project_verification_completion_blocker, project_verification_completion_blocker_at,
|
||||
static_delegate_completion_blocker_at, structured_plan_completion_blocker,
|
||||
try_acquire_game_creator_agent_runtime_project_write_lock,
|
||||
validate_agent_runtime_pending_verification_gate_before,
|
||||
};
|
||||
#[cfg(test)]
|
||||
@@ -116,7 +115,6 @@ pub(crate) use project_gates::{
|
||||
};
|
||||
pub(crate) use provider_action_batch::{
|
||||
prepare_game_creator_agent_runtime_provider_action_batch,
|
||||
prepare_game_creator_agent_runtime_provider_action_batch_with_planning_binding,
|
||||
update_game_creator_agent_runtime_provider_batch_member, AgentRuntimePendingToolAction,
|
||||
AgentRuntimeProviderActionBatch,
|
||||
};
|
||||
@@ -147,9 +145,6 @@ pub(crate) use tool_plan_protocol::parse_game_creator_agent_tool_plan_response;
|
||||
pub(crate) use tool_policy_snapshot::{
|
||||
agent_runtime_acceptance_evidence_tools,
|
||||
agent_runtime_autonomous_design_foundation_command_is_allowed, agent_runtime_executable_tools,
|
||||
agent_runtime_native_executable_tools, agent_runtime_plan_root_supervisor_tools,
|
||||
agent_runtime_plan_root_supervisor_tools_for_stage,
|
||||
agent_runtime_tool_policy_snapshot_for_run_at, plan_root_supervisor_stage_at,
|
||||
plan_root_supervisor_stage_at_locked, PlanRootSupervisorStage,
|
||||
AGENT_RUNTIME_CANVAS_ASSET_KINDS, AGENT_RUNTIME_PROJECT_PLANNING_ACTION_TOOLS,
|
||||
agent_runtime_native_executable_tools, agent_runtime_tool_policy_snapshot_for_run_at,
|
||||
AGENT_RUNTIME_CANVAS_ASSET_KINDS,
|
||||
};
|
||||
|
||||
@@ -38,29 +38,6 @@ pub(crate) async fn execute_game_creator_agent_runtime_tool_action_with_pending_
|
||||
) -> AgentRuntimeToolObservation {
|
||||
let tool = action.tool.trim();
|
||||
let relaxed_autonomous = autonomous_relaxed_run_at(root, agent_id, run_id).unwrap_or(false);
|
||||
if tool == PLAN_SUBMIT_GDD_TOOL && agent_id.trim() != GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
return AgentRuntimeToolObservation {
|
||||
tool: tool.to_string(),
|
||||
status: "rejected".to_string(),
|
||||
summary: "plan.submit_gdd 仅允许 project-planning Agent".to_string(),
|
||||
detail: None,
|
||||
};
|
||||
}
|
||||
if agent_id.trim() == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID
|
||||
&& !matches!(tool, "file.read" | "file.list")
|
||||
{
|
||||
// `plan.submit_gdd` is intentionally handled by the planning submit
|
||||
// branch in the Runtime main loop. If it ever reaches the generic
|
||||
// executor (including recovery or a stale pending record), fail
|
||||
// closed instead of treating the durable mutation as an ordinary
|
||||
// command action.
|
||||
return AgentRuntimeToolObservation {
|
||||
tool: tool.to_string(),
|
||||
status: "rejected".to_string(),
|
||||
summary: "当前 Agent 身份不允许执行该工具".to_string(),
|
||||
detail: None,
|
||||
};
|
||||
}
|
||||
let action_fingerprint = pending_action
|
||||
.map(|pending| {
|
||||
agent_runtime_pending_tool_action_fingerprint(
|
||||
|
||||
@@ -25,11 +25,6 @@ pub(in crate::agent) async fn compact_game_creator_agent_runtime_context_at(
|
||||
root,
|
||||
"runtime.context_compaction.build",
|
||||
)?;
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
// Advance the immutable Provider-usage projection before any
|
||||
// request/source bytes are rebuilt from the plan session.
|
||||
fold_plan_provider_usage_before_new_request_at_locked(root, Some((agent_id, run_id)))?;
|
||||
}
|
||||
let source = build_game_creator_agent_runtime_context_compaction_source(
|
||||
root,
|
||||
agent_id,
|
||||
@@ -67,18 +62,6 @@ pub(in crate::agent) async fn compact_game_creator_agent_runtime_context_at(
|
||||
let config_path = format!("agentLlm.{template_agent_id}");
|
||||
let mut request =
|
||||
build_game_creator_agent_runtime_context_compaction_request(&source, &llm)?;
|
||||
let planning_agent = agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID;
|
||||
if planning_agent {
|
||||
if allow_idle_context_compaction {
|
||||
return Err(
|
||||
"project-planning 不支持脱离 active run 的 idle context compaction".to_string(),
|
||||
);
|
||||
}
|
||||
let wire_bytes =
|
||||
capture_plan_provider_structured_injections_at(root, session_id, observations)?;
|
||||
let message = render_plan_provider_structured_injections_message(&wire_bytes)?;
|
||||
request.messages.insert(1, LlmMessage::user(message));
|
||||
}
|
||||
let estimated_request_tokens = estimate_game_creator_llm_request_tokens(&request)?;
|
||||
validate_game_creator_llm_request_context_budget(
|
||||
&llm,
|
||||
@@ -106,22 +89,6 @@ pub(in crate::agent) async fn compact_game_creator_agent_runtime_context_at(
|
||||
applied_steer_cursor,
|
||||
)?
|
||||
};
|
||||
let snapshot = if planning_agent {
|
||||
let request_context_fingerprint =
|
||||
game_creator_agent_runtime_plan_provider_request_context_fingerprint(
|
||||
&llm, &request,
|
||||
)?;
|
||||
let runtime = read_game_creator_agent_runtime_at(root, agent_id)?.state;
|
||||
let binding = capture_plan_provider_session_binding_for_snapshot(
|
||||
root,
|
||||
&runtime,
|
||||
&snapshot,
|
||||
&request_context_fingerprint,
|
||||
)?;
|
||||
snapshot.with_planning_session_binding(Some(binding))
|
||||
} else {
|
||||
snapshot
|
||||
};
|
||||
(snapshot, source, llm, config_path, request)
|
||||
};
|
||||
let handoff_identity =
|
||||
@@ -188,7 +155,6 @@ pub(in crate::agent) async fn compact_game_creator_agent_runtime_context_at(
|
||||
let request_id = resolve_game_creator_agent_runtime_provider_request_attempt_at_locked(
|
||||
root,
|
||||
&base_request_id,
|
||||
snapshot.planning_session_binding.is_some(),
|
||||
)
|
||||
.map(|value| value.0)
|
||||
.unwrap_or(base_request_id);
|
||||
@@ -212,7 +178,6 @@ pub(in crate::agent) async fn compact_game_creator_agent_runtime_context_at(
|
||||
let request_id = resolve_game_creator_agent_runtime_provider_request_attempt_at_locked(
|
||||
root,
|
||||
&base_request_id,
|
||||
snapshot.planning_session_binding.is_some(),
|
||||
)
|
||||
.map(|value| value.0)
|
||||
.unwrap_or(base_request_id);
|
||||
@@ -246,7 +211,6 @@ pub(in crate::agent) async fn compact_game_creator_agent_runtime_context_at(
|
||||
let request_id = resolve_game_creator_agent_runtime_provider_request_attempt_at_locked(
|
||||
root,
|
||||
&base_request_id,
|
||||
snapshot.planning_session_binding.is_some(),
|
||||
)
|
||||
.map(|value| value.0)
|
||||
.unwrap_or(base_request_id);
|
||||
|
||||
@@ -109,7 +109,6 @@ pub(in crate::agent) fn game_creator_agent_runtime_tool_command_id(
|
||||
"agent.schedule_ready" => Some("agent.schedule_ready"),
|
||||
"agent.action_history" => Some("agent.audit"),
|
||||
"agent.run_status" => Some("agent.run_status"),
|
||||
PLAN_SUBMIT_GDD_TOOL => Some(PLAN_SUBMIT_GDD_TOOL),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -119,15 +118,7 @@ pub(in crate::agent) fn game_creator_agent_runtime_tool_command_id(
|
||||
/// id (for example `project.search` and `file.read`); policy lookup alone must
|
||||
/// not turn that aliasing into an identity escalation for a restricted Agent.
|
||||
pub(crate) fn agent_runtime_tool_allowed_for_agent(agent_id: &str, tool: &str) -> bool {
|
||||
if agent_id.trim() == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
return matches!(
|
||||
tool.trim(),
|
||||
"file.read" | "file.list" | PLAN_SUBMIT_GDD_TOOL
|
||||
);
|
||||
}
|
||||
if tool.trim() == PLAN_SUBMIT_GDD_TOOL {
|
||||
return false;
|
||||
}
|
||||
let _ = agent_id;
|
||||
if tool.trim() == GAME_CREATOR_USER_INPUT_REQUEST_TOOL {
|
||||
// `user.input_request` is a protocol control handled by the main
|
||||
// loop, not by the command-id policy map. It remains available to
|
||||
@@ -137,95 +128,10 @@ pub(crate) fn agent_runtime_tool_allowed_for_agent(agent_id: &str, tool: &str) -
|
||||
game_creator_agent_runtime_tool_command_id(tool.trim()).is_some()
|
||||
}
|
||||
|
||||
/// 身份层面的**显式**拒绝:该 Agent 身份带 exact allowlist,且工具不在其中。
|
||||
///
|
||||
/// **未知工具名不属于本判据。** `agent_runtime_tool_allowed_for_agent` 对普通
|
||||
/// Agent 退化成「这个工具名是否已知」,用它做身份门会把「模型编了个不存在的
|
||||
/// 工具」这种普通协议错误误判成身份违规。协议错误的既有语义是:走到执行层产出
|
||||
/// 一条 `rejected` observation,run 继续,由下一轮 tool-plan 收束;升级成身份
|
||||
/// 拒绝会让整个 run 进 needs-reconciliation 而**不再发出 follow-up 请求**。
|
||||
///
|
||||
/// 因此凡是「命中即中断 run 或整体拒绝动作」的调用点都必须用本判据,不能直接
|
||||
/// 用 `agent_runtime_tool_allowed_for_agent`。
|
||||
pub(crate) fn agent_runtime_tool_rejected_by_agent_identity(agent_id: &str, tool: &str) -> bool {
|
||||
agent_id.trim() == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID
|
||||
&& !agent_runtime_tool_allowed_for_agent(agent_id, tool)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod identity_tests {
|
||||
use super::*;
|
||||
|
||||
/// 普通 Agent 编出来的未知工具名是**协议错误**,不是身份违规。
|
||||
///
|
||||
/// 判成身份违规会让 main_loop 把整个 run 打进 needs-reconciliation、不再发出
|
||||
/// follow-up tool-plan——曾导致 `background_agent_runtime_persists_receipts_for_rejected_actions`
|
||||
/// 在等待第二次 Provider 请求时超时。
|
||||
#[test]
|
||||
fn unknown_tool_on_ordinary_agent_is_not_an_identity_rejection() {
|
||||
assert!(!agent_runtime_tool_rejected_by_agent_identity(
|
||||
"design-director",
|
||||
"runtime.unknown"
|
||||
));
|
||||
assert!(!agent_runtime_tool_rejected_by_agent_identity(
|
||||
GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID,
|
||||
"runtime.unknown"
|
||||
));
|
||||
assert!(!agent_runtime_tool_rejected_by_agent_identity(
|
||||
"design-director",
|
||||
"file.read"
|
||||
));
|
||||
}
|
||||
|
||||
/// planning 身份仍是 exact allowlist:未知工具与越权工具都算身份拒绝。
|
||||
#[test]
|
||||
fn planning_identity_still_rejects_unknown_and_out_of_scope_tools() {
|
||||
assert!(agent_runtime_tool_rejected_by_agent_identity(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"runtime.unknown"
|
||||
));
|
||||
assert!(agent_runtime_tool_rejected_by_agent_identity(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"file.write"
|
||||
));
|
||||
assert!(!agent_runtime_tool_rejected_by_agent_identity(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"file.read"
|
||||
));
|
||||
assert!(!agent_runtime_tool_rejected_by_agent_identity(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
PLAN_SUBMIT_GDD_TOOL
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planning_identity_does_not_inherit_project_search_alias() {
|
||||
assert!(agent_runtime_tool_allowed_for_agent(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"file.read"
|
||||
));
|
||||
assert!(agent_runtime_tool_allowed_for_agent(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"file.list"
|
||||
));
|
||||
assert!(!agent_runtime_tool_allowed_for_agent(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"project.search"
|
||||
));
|
||||
assert!(agent_runtime_tool_allowed_for_agent(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
PLAN_SUBMIT_GDD_TOOL
|
||||
));
|
||||
assert!(!agent_runtime_tool_allowed_for_agent(
|
||||
GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID,
|
||||
PLAN_SUBMIT_GDD_TOOL
|
||||
));
|
||||
assert!(agent_runtime_tool_allowed_for_agent(
|
||||
GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID,
|
||||
"project.search"
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn account_asset_library_uses_the_existing_read_only_asset_permission() {
|
||||
assert_eq!(
|
||||
|
||||
-27
@@ -336,33 +336,6 @@ pub(in crate::agent) fn validate_agent_runtime_pending_tool_action_record(
|
||||
let relaxed_autonomous = autonomous_relaxed_run_profile(&pending.run_profile);
|
||||
if !relaxed_autonomous {
|
||||
validate_agent_runtime_pending_goal_binding(pending)?;
|
||||
match pending.planning_session_binding.as_ref() {
|
||||
Some(binding) => {
|
||||
validate_plan_provider_session_binding(binding)
|
||||
.map_err(|error| error.to_string())?;
|
||||
if pending.action.tool.trim() != PLAN_SUBMIT_GDD_TOOL
|
||||
|| binding.agent_id != pending.agent_id
|
||||
|| binding.task_id != pending.task_id
|
||||
|| binding.session_id != pending.session_id
|
||||
|| binding.run_id != pending.run_id
|
||||
|| binding.source != pending.source
|
||||
|| binding.run_profile != pending.run_profile
|
||||
|| binding.run_profile_binding_fingerprint
|
||||
!= pending.run_profile_binding_fingerprint
|
||||
|| binding.applied_steer_cursor != pending.planned_steer_cursor
|
||||
{
|
||||
return Err(
|
||||
"planning submit standalone pending 与 frozen binding 不一致".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
None if pending.provider_batch_plan_update.is_none() => {}
|
||||
None => {
|
||||
return Err(
|
||||
"非 planning standalone pending 不能携带 Provider batch planUpdate".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
validate_agent_runtime_project_revision(root, &pending.project_revision_before)?;
|
||||
if pending.verification_gate_before.project_id
|
||||
!= game_creator_agent_runtime_context_project_id(root)?
|
||||
|
||||
@@ -1088,7 +1088,6 @@ pub(in crate::agent) fn agent_runtime_non_verification_completion_blocker_at_loc
|
||||
run_id: &str,
|
||||
) -> Option<AgentRuntimeToolObservation> {
|
||||
provider_retry_completion_blocker_at_locked(root, agent_id, run_id)
|
||||
.or_else(|| plan_gdd_completion_blocker_at_locked(root, agent_id, run_id))
|
||||
.or_else(|| provider_action_batch_completion_blocker_at_locked(root, agent_id, run_id))
|
||||
.or_else(|| {
|
||||
supervisor_collaboration_policy_completion_blocker_at_locked(root, agent_id, run_id)
|
||||
@@ -1874,6 +1873,13 @@ pub(crate) fn acquire_game_creator_agent_runtime_project_write_lock_with_short_w
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn try_acquire_game_creator_agent_runtime_project_write_lock(
|
||||
root: &Path,
|
||||
command_id: &str,
|
||||
) -> Result<ProjectWriteLock, String> {
|
||||
acquire_game_creator_agent_runtime_project_write_lock_within(root, command_id, 1)
|
||||
}
|
||||
|
||||
pub(crate) fn acquire_game_creator_agent_provider_plan_project_write_lock_with_wait(
|
||||
root: &Path,
|
||||
command_id: &str,
|
||||
|
||||
+18
-321
@@ -14,18 +14,6 @@ pub(crate) struct AgentRuntimePendingToolAction {
|
||||
pub(crate) run_profile: String,
|
||||
#[serde(default)]
|
||||
pub(crate) run_profile_binding_fingerprint: String,
|
||||
/// Planning submit actions carry the exact source-session snapshot that
|
||||
/// was captured before the Provider response was accepted. Other tools
|
||||
/// leave this field absent and retain the v1-v3 batch semantics.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) planning_session_binding: Option<PlanProviderSessionBindingV1>,
|
||||
/// The v4 planning batch identity covers the complete Provider plan,
|
||||
/// including an optional structured plan update. Persist that one
|
||||
/// batch-only field on the standalone submit anchor as recovery material;
|
||||
/// otherwise a surviving pending action cannot reproduce the original
|
||||
/// batch ID after the batch sidecar is lost.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) provider_batch_plan_update: Option<AgentRuntimePlanUpdate>,
|
||||
pub(crate) task: String,
|
||||
#[serde(default)]
|
||||
pub(crate) goal_id: Option<String>,
|
||||
@@ -90,8 +78,6 @@ pub(in crate::agent) struct AgentRuntimeParallelReadBatch {
|
||||
pub(crate) struct AgentRuntimeProviderActionBatch {
|
||||
pub(crate) schema_version: String,
|
||||
pub(crate) batch_id: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) provider_request_id: Option<String>,
|
||||
pub(crate) project_id: String,
|
||||
pub(crate) agent_id: String,
|
||||
pub(crate) task_id: String,
|
||||
@@ -102,8 +88,6 @@ pub(crate) struct AgentRuntimeProviderActionBatch {
|
||||
pub(crate) run_profile: String,
|
||||
#[serde(default)]
|
||||
pub(crate) run_profile_binding_fingerprint: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub(crate) planning_session_binding: Option<PlanProviderSessionBindingV1>,
|
||||
pub(crate) loop_iteration: u32,
|
||||
pub(crate) planned_steer_cursor: u64,
|
||||
pub(crate) status: String,
|
||||
@@ -123,8 +107,6 @@ pub(crate) struct AgentRuntimeProviderActionBatch {
|
||||
struct AgentRuntimeProviderActionBatchWire {
|
||||
schema_version: String,
|
||||
batch_id: String,
|
||||
#[serde(default)]
|
||||
provider_request_id: Option<String>,
|
||||
project_id: String,
|
||||
agent_id: String,
|
||||
task_id: String,
|
||||
@@ -135,8 +117,6 @@ struct AgentRuntimeProviderActionBatchWire {
|
||||
run_profile: String,
|
||||
#[serde(default)]
|
||||
run_profile_binding_fingerprint: String,
|
||||
#[serde(default)]
|
||||
planning_session_binding: Option<PlanProviderSessionBindingV1>,
|
||||
loop_iteration: u32,
|
||||
planned_steer_cursor: u64,
|
||||
status: String,
|
||||
@@ -160,7 +140,6 @@ impl<'de> Deserialize<'de> for AgentRuntimeProviderActionBatch {
|
||||
let batch = Self {
|
||||
schema_version: wire.schema_version,
|
||||
batch_id: wire.batch_id,
|
||||
provider_request_id: wire.provider_request_id,
|
||||
project_id: wire.project_id,
|
||||
agent_id: wire.agent_id,
|
||||
task_id: wire.task_id,
|
||||
@@ -169,7 +148,6 @@ impl<'de> Deserialize<'de> for AgentRuntimeProviderActionBatch {
|
||||
source: wire.source,
|
||||
run_profile: wire.run_profile,
|
||||
run_profile_binding_fingerprint: wire.run_profile_binding_fingerprint,
|
||||
planning_session_binding: wire.planning_session_binding,
|
||||
loop_iteration: wire.loop_iteration,
|
||||
planned_steer_cursor: wire.planned_steer_cursor,
|
||||
status: wire.status,
|
||||
@@ -217,7 +195,7 @@ impl AgentRuntimePendingToolAction {
|
||||
pub(in crate::agent) fn tool_plan(&self) -> AgentRuntimeToolPlan {
|
||||
AgentRuntimeToolPlan {
|
||||
thinking_summary: self.thinking_summary.clone(),
|
||||
plan_update: self.provider_batch_plan_update.clone(),
|
||||
plan_update: None,
|
||||
plan: self.plan.clone(),
|
||||
actions: Vec::new(),
|
||||
response: self.fallback_response.clone(),
|
||||
@@ -275,8 +253,6 @@ pub(in crate::agent) fn build_game_creator_agent_runtime_pending_tool_action(
|
||||
source: runtime.source.clone(),
|
||||
run_profile: runtime.run_profile.clone(),
|
||||
run_profile_binding_fingerprint: runtime.run_profile_binding_fingerprint.clone(),
|
||||
planning_session_binding: None,
|
||||
provider_batch_plan_update: None,
|
||||
task,
|
||||
goal_id: runtime.goal_id.clone(),
|
||||
goal_revision: runtime.goal_revision,
|
||||
@@ -312,110 +288,13 @@ pub(in crate::agent) fn build_game_creator_agent_runtime_pending_tool_action(
|
||||
})
|
||||
}
|
||||
|
||||
/// `plan.submit_gdd` is a transactional planning action rather than an
|
||||
/// ordinary provider action. It must be represented by one (and only one)
|
||||
/// durable batch member so that the main loop can establish the action
|
||||
/// identity before handing control to the planning submit handler.
|
||||
///
|
||||
/// Keep this check at the batch boundary as a second line of defence behind
|
||||
/// the native-tool parser. In particular, a text/JSON tool-plan or a stale
|
||||
/// caller must not be able to smuggle a submit action through the historical
|
||||
/// `< 2 actions => NotNeeded` fast path.
|
||||
fn validate_plan_submit_gdd_batch_shape_for_identity(
|
||||
agent_id: &str,
|
||||
source: &str,
|
||||
run_profile: &str,
|
||||
plan: &AgentRuntimeToolPlan,
|
||||
) -> Result<bool, String> {
|
||||
let submit_count = plan
|
||||
.actions
|
||||
.iter()
|
||||
.filter(|action| action.tool.trim() == PLAN_SUBMIT_GDD_TOOL)
|
||||
.count();
|
||||
if submit_count == 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
if agent_id.trim() != GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
return Err("plan.submit_gdd 只能由 project-planning Agent 调用".to_string());
|
||||
}
|
||||
// The planning child is created through the ordinary delegate path. Keep
|
||||
// the source/profile check here even though the run-identity binder also
|
||||
// checks it: this prevents a forged/stale RuntimeState from turning the
|
||||
// sole-action exception into a generic batch.
|
||||
if source.trim() != "agent-delegate" || run_profile.trim() != AGENT_RUNTIME_RUN_PROFILE_STANDARD
|
||||
{
|
||||
return Err(
|
||||
"plan.submit_gdd 的 Runtime 身份必须是 source=agent-delegate、runProfile=standard"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if submit_count > 1 {
|
||||
return Err("plan.submit_gdd 在同一 Provider 响应中只能出现一次".to_string());
|
||||
}
|
||||
if plan.actions.len() != 1 {
|
||||
return Err("plan.submit_gdd 必须是 Provider 响应中的唯一 action".to_string());
|
||||
}
|
||||
if !plan.response.trim().is_empty() {
|
||||
return Err("plan.submit_gdd 不得与 respond_to_user 混批".to_string());
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
fn validate_plan_submit_gdd_batch_shape(
|
||||
runtime: &AgentRuntimeState,
|
||||
plan: &AgentRuntimeToolPlan,
|
||||
) -> Result<bool, String> {
|
||||
validate_plan_submit_gdd_batch_shape_for_identity(
|
||||
&runtime.agent_id,
|
||||
&runtime.source,
|
||||
&runtime.run_profile,
|
||||
plan,
|
||||
)
|
||||
}
|
||||
|
||||
/// Return whether a persisted v4 provider batch is the exact planning submit
|
||||
/// shape that is allowed to contain one action. The provider-batch ledger
|
||||
/// uses this narrow predicate when applying its normal two-action minimum;
|
||||
/// all non-plan batches retain the historical minimum unchanged.
|
||||
pub(in crate::agent) fn is_plan_submit_gdd_provider_action_batch(
|
||||
batch: &AgentRuntimeProviderActionBatch,
|
||||
) -> bool {
|
||||
batch.schema_version == AGENT_RUNTIME_PLAN_PROVIDER_ACTION_BATCH_SCHEMA_VERSION
|
||||
&& batch.agent_id.trim() == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID
|
||||
&& batch.source.trim() == "agent-delegate"
|
||||
&& batch.run_profile.trim() == AGENT_RUNTIME_RUN_PROFILE_STANDARD
|
||||
&& batch.collaboration_contract.is_none()
|
||||
&& batch.actions.len() == 1
|
||||
&& batch.plan.actions.len() == 1
|
||||
&& batch.plan.actions[0].tool.trim() == PLAN_SUBMIT_GDD_TOOL
|
||||
&& batch.actions[0].action.tool.trim() == PLAN_SUBMIT_GDD_TOOL
|
||||
&& batch.plan.response.trim().is_empty()
|
||||
&& batch.actions[0].action == batch.plan.actions[0]
|
||||
&& batch.planning_session_binding.is_some()
|
||||
&& batch.provider_request_id.as_deref()
|
||||
== batch
|
||||
.planning_session_binding
|
||||
.as_ref()
|
||||
.map(|binding| binding.provider_request_id.as_str())
|
||||
&& batch.actions[0].planning_session_binding == batch.planning_session_binding
|
||||
}
|
||||
|
||||
fn provider_action_batch_is_not_needed(
|
||||
action_count: usize,
|
||||
force_collaboration_batch: bool,
|
||||
is_plan_submit: bool,
|
||||
) -> bool {
|
||||
action_count < 2 && !force_collaboration_batch && !is_plan_submit
|
||||
action_count < 2 && !force_collaboration_batch
|
||||
}
|
||||
|
||||
/// Backwards-compatible entry point for the historical provider-batch callers.
|
||||
///
|
||||
/// Planning submit batches now need the frozen session binding captured while
|
||||
/// building the provider request. Callers that do not build a planning
|
||||
/// request (including the older test/support helpers) retain the old API and
|
||||
/// therefore pass no binding; the planning path uses the `_with_planning_binding`
|
||||
/// variant below.
|
||||
pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch(
|
||||
root: &Path,
|
||||
runtime: &AgentRuntimeState,
|
||||
@@ -425,34 +304,6 @@ pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch(
|
||||
project_revision_before: &AgentRuntimeProjectRevision,
|
||||
planned_repository_context_fingerprint: &str,
|
||||
) -> Result<AgentRuntimeProviderActionBatchPreparation, String> {
|
||||
prepare_game_creator_agent_runtime_provider_action_batch_with_planning_binding(
|
||||
root,
|
||||
runtime,
|
||||
task,
|
||||
plan,
|
||||
observations,
|
||||
project_revision_before,
|
||||
planned_repository_context_fingerprint,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch_with_planning_binding(
|
||||
root: &Path,
|
||||
runtime: &AgentRuntimeState,
|
||||
task: &str,
|
||||
plan: &AgentRuntimeToolPlan,
|
||||
observations: &[AgentRuntimeToolObservation],
|
||||
project_revision_before: &AgentRuntimeProjectRevision,
|
||||
planned_repository_context_fingerprint: &str,
|
||||
captured_planning_session_binding: Option<&PlanProviderSessionBindingV1>,
|
||||
) -> Result<AgentRuntimeProviderActionBatchPreparation, String> {
|
||||
// Validate against the complete provider plan before truncating the
|
||||
// historical action budget. Otherwise a mixed submit batch could hide a
|
||||
// `plan.submit_gdd` action beyond the truncation boundary and reach the
|
||||
// generic executor without a durable identity.
|
||||
let is_plan_submit = validate_plan_submit_gdd_batch_shape(runtime, plan)?;
|
||||
let mut batch_plan = plan.clone();
|
||||
batch_plan
|
||||
.actions
|
||||
@@ -554,7 +405,6 @@ pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch_wit
|
||||
if provider_action_batch_is_not_needed(
|
||||
batch_plan.actions.len(),
|
||||
collaboration_preflight.force_durable_batch,
|
||||
is_plan_submit,
|
||||
) {
|
||||
return Ok(AgentRuntimeProviderActionBatchPreparation::NotNeeded);
|
||||
}
|
||||
@@ -577,23 +427,8 @@ pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch_wit
|
||||
AGENT_RUNTIME_PENDING_ACTION_STATUS_APPROVED,
|
||||
None,
|
||||
)?;
|
||||
if action.tool.trim() == PLAN_SUBMIT_GDD_TOOL {
|
||||
pending.planning_session_binding = captured_planning_session_binding.cloned();
|
||||
pending.provider_batch_plan_update = batch_plan.plan_update.clone();
|
||||
if pending.planning_session_binding.is_none() {
|
||||
return Err(
|
||||
"planning submit action 缺少 Provider 请求前捕获的 session binding".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
let command_id = game_creator_agent_runtime_tool_command_id(action.tool.trim());
|
||||
let identity_block =
|
||||
agent_runtime_tool_rejected_by_agent_identity(&runtime.agent_id, action.tool.trim())
|
||||
.then(|| {
|
||||
AgentRuntimeToolPolicyBlock::Denied(
|
||||
"当前 Agent 身份不允许执行该原始工具".to_string(),
|
||||
)
|
||||
});
|
||||
let identity_block: Option<AgentRuntimeToolPolicyBlock> = None;
|
||||
let art_director_canvas_only_block =
|
||||
agent_runtime_autonomous_art_director_canvas_only_action_block(
|
||||
&runtime.agent_id,
|
||||
@@ -678,71 +513,24 @@ pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch_wit
|
||||
} else {
|
||||
AGENT_RUNTIME_PROVIDER_ACTION_BATCH_STATUS_READY
|
||||
};
|
||||
let planning_session_binding = if is_plan_submit {
|
||||
let binding = captured_planning_session_binding
|
||||
.or_else(|| {
|
||||
actions
|
||||
.first()
|
||||
.and_then(|pending| pending.planning_session_binding.as_ref())
|
||||
})
|
||||
.ok_or_else(|| "planning submit batch 缺少 frozen session binding".to_string())?;
|
||||
validate_plan_provider_session_binding_current_at(root, binding)?;
|
||||
if let Some(pending_binding) = actions
|
||||
.first()
|
||||
.and_then(|pending| pending.planning_session_binding.as_ref())
|
||||
{
|
||||
if pending_binding != binding {
|
||||
return Err(
|
||||
"planning submit pending 与 captured session binding 不一致".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
Some(binding.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let batch_id = if let Some(binding) = planning_session_binding.as_ref() {
|
||||
agent_runtime_plan_provider_action_batch_id(
|
||||
&project_id,
|
||||
&runtime.agent_id,
|
||||
&runtime.task_id,
|
||||
&runtime.session_id,
|
||||
&runtime.run_id,
|
||||
runtime.loop_iteration,
|
||||
runtime.applied_steer_cursor,
|
||||
&batch_plan,
|
||||
project_revision_before,
|
||||
planned_repository_context_fingerprint,
|
||||
&actions,
|
||||
binding,
|
||||
)?
|
||||
} else {
|
||||
agent_runtime_provider_action_batch_id(
|
||||
&project_id,
|
||||
&runtime.agent_id,
|
||||
&runtime.task_id,
|
||||
&runtime.session_id,
|
||||
&runtime.run_id,
|
||||
runtime.loop_iteration,
|
||||
runtime.applied_steer_cursor,
|
||||
&batch_plan,
|
||||
project_revision_before,
|
||||
planned_repository_context_fingerprint,
|
||||
&actions,
|
||||
collaboration_preflight.contract.as_ref(),
|
||||
)?
|
||||
};
|
||||
let batch_id = agent_runtime_provider_action_batch_id(
|
||||
&project_id,
|
||||
&runtime.agent_id,
|
||||
&runtime.task_id,
|
||||
&runtime.session_id,
|
||||
&runtime.run_id,
|
||||
runtime.loop_iteration,
|
||||
runtime.applied_steer_cursor,
|
||||
&batch_plan,
|
||||
project_revision_before,
|
||||
planned_repository_context_fingerprint,
|
||||
&actions,
|
||||
collaboration_preflight.contract.as_ref(),
|
||||
)?;
|
||||
let now = unix_timestamp();
|
||||
let batch = AgentRuntimeProviderActionBatch {
|
||||
schema_version: if is_plan_submit {
|
||||
AGENT_RUNTIME_PLAN_PROVIDER_ACTION_BATCH_SCHEMA_VERSION.to_string()
|
||||
} else {
|
||||
AGENT_RUNTIME_PROVIDER_ACTION_BATCH_SCHEMA_VERSION.to_string()
|
||||
},
|
||||
schema_version: AGENT_RUNTIME_PROVIDER_ACTION_BATCH_SCHEMA_VERSION.to_string(),
|
||||
batch_id,
|
||||
provider_request_id: planning_session_binding
|
||||
.as_ref()
|
||||
.map(|binding| binding.provider_request_id.clone()),
|
||||
project_id,
|
||||
agent_id: runtime.agent_id.clone(),
|
||||
task_id: runtime.task_id.clone(),
|
||||
@@ -751,7 +539,6 @@ pub(crate) async fn prepare_game_creator_agent_runtime_provider_action_batch_wit
|
||||
source: runtime.source.clone(),
|
||||
run_profile: runtime.run_profile.clone(),
|
||||
run_profile_binding_fingerprint: runtime.run_profile_binding_fingerprint.clone(),
|
||||
planning_session_binding,
|
||||
loop_iteration: runtime.loop_iteration,
|
||||
planned_steer_cursor: runtime.applied_steer_cursor,
|
||||
status: status.to_string(),
|
||||
@@ -1228,93 +1015,3 @@ pub(in crate::agent) fn update_game_creator_agent_runtime_provider_batch_paralle
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod plan_submit_batch_shape_tests {
|
||||
use super::*;
|
||||
|
||||
fn action(tool: &str) -> AgentRuntimeToolAction {
|
||||
AgentRuntimeToolAction {
|
||||
tool: tool.to_string(),
|
||||
reason: Some("测试动作".to_string()),
|
||||
input: serde_json::json!({}),
|
||||
}
|
||||
}
|
||||
|
||||
fn plan(actions: Vec<AgentRuntimeToolAction>, response: &str) -> AgentRuntimeToolPlan {
|
||||
AgentRuntimeToolPlan {
|
||||
thinking_summary: "测试 plan.submit_gdd 批次形状".to_string(),
|
||||
plan_update: None,
|
||||
plan: Vec::new(),
|
||||
actions,
|
||||
response: response.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn validate(plan: &AgentRuntimeToolPlan) -> Result<bool, String> {
|
||||
validate_plan_submit_gdd_batch_shape_for_identity(
|
||||
GAME_CREATOR_PROJECT_PLANNING_AGENT_ID,
|
||||
"agent-delegate",
|
||||
AGENT_RUNTIME_RUN_PROFILE_STANDARD,
|
||||
plan,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planning_submit_is_the_only_durable_action_and_allows_plan_control() {
|
||||
let mut submit = plan(vec![action(PLAN_SUBMIT_GDD_TOOL)], "");
|
||||
assert_eq!(validate(&submit), Ok(true));
|
||||
|
||||
submit.plan_update = Some(AgentRuntimePlanUpdate {
|
||||
explanation: "同步计划进度".to_string(),
|
||||
steps: Vec::new(),
|
||||
});
|
||||
assert_eq!(validate(&submit), Ok(true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planning_submit_rejects_mixed_or_duplicate_actions() {
|
||||
let mixed = plan(vec![action(PLAN_SUBMIT_GDD_TOOL), action("file.read")], "");
|
||||
let mixed_error = validate(&mixed).expect_err("submit + file.read must fail closed");
|
||||
assert!(mixed_error.contains("唯一 action"), "{mixed_error}");
|
||||
|
||||
let duplicate = plan(
|
||||
vec![action(PLAN_SUBMIT_GDD_TOOL), action(PLAN_SUBMIT_GDD_TOOL)],
|
||||
"",
|
||||
);
|
||||
let duplicate_error =
|
||||
validate(&duplicate).expect_err("duplicate submit actions must fail closed");
|
||||
assert!(
|
||||
duplicate_error.contains("只能出现一次"),
|
||||
"{duplicate_error}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn planning_submit_rejects_final_response_and_wrong_identity() {
|
||||
let with_response = plan(vec![action(PLAN_SUBMIT_GDD_TOOL)], "不能同时回复");
|
||||
let response_error =
|
||||
validate(&with_response).expect_err("submit + respond_to_user must fail closed");
|
||||
assert!(
|
||||
response_error.contains("respond_to_user"),
|
||||
"{response_error}"
|
||||
);
|
||||
|
||||
let wrong_agent = validate_plan_submit_gdd_batch_shape_for_identity(
|
||||
GAME_CREATOR_PROJECT_SUPERVISOR_AGENT_ID,
|
||||
"project-supervisor-plan",
|
||||
AGENT_RUNTIME_RUN_PROFILE_STANDARD,
|
||||
&plan(vec![action(PLAN_SUBMIT_GDD_TOOL)], ""),
|
||||
)
|
||||
.expect_err("non-planning identity must not receive submit exception");
|
||||
assert!(wrong_agent.contains("project-planning"), "{wrong_agent}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordinary_single_action_keeps_not_needed_eligibility() {
|
||||
assert_eq!(validate(&plan(vec![action("file.read")], "")), Ok(false));
|
||||
assert!(provider_action_batch_is_not_needed(1, false, false));
|
||||
assert!(!provider_action_batch_is_not_needed(1, false, true));
|
||||
assert!(!provider_action_batch_is_not_needed(1, true, false));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-143
@@ -110,48 +110,6 @@ pub(in crate::agent) fn agent_runtime_provider_action_batch_id(
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(in crate::agent) fn agent_runtime_plan_provider_action_batch_id(
|
||||
project_id: &str,
|
||||
agent_id: &str,
|
||||
task_id: &str,
|
||||
session_id: &str,
|
||||
run_id: &str,
|
||||
loop_iteration: u32,
|
||||
planned_steer_cursor: u64,
|
||||
plan: &AgentRuntimeToolPlan,
|
||||
project_revision_before: &AgentRuntimeProjectRevision,
|
||||
planned_repository_context_fingerprint: &str,
|
||||
actions: &[AgentRuntimePendingToolAction],
|
||||
planning_session_binding: &PlanProviderSessionBindingV1,
|
||||
) -> Result<String, String> {
|
||||
let action_ids = actions
|
||||
.iter()
|
||||
.map(|pending| pending.action_id.as_str())
|
||||
.collect::<Vec<_>>();
|
||||
let identity = serde_json::to_vec(&serde_json::json!({
|
||||
"schemaVersion": AGENT_RUNTIME_PLAN_PROVIDER_ACTION_BATCH_SCHEMA_VERSION,
|
||||
"projectId": project_id,
|
||||
"agentId": agent_id,
|
||||
"taskId": task_id,
|
||||
"sessionId": session_id,
|
||||
"runId": run_id,
|
||||
"loopIteration": loop_iteration,
|
||||
"plannedSteerCursor": planned_steer_cursor,
|
||||
"plan": plan,
|
||||
"projectRevisionBefore": project_revision_before,
|
||||
"plannedRepositoryContextFingerprint": planned_repository_context_fingerprint,
|
||||
"actionIds": action_ids,
|
||||
"planningSessionBinding": planning_session_binding,
|
||||
}))
|
||||
.map_err(|error| format!("序列化 Provider action 批次 v4 身份失败:{error}"))?;
|
||||
let fingerprint = format!("{:x}", Sha256::digest(identity));
|
||||
Ok(format!(
|
||||
"provider-action-v4-{}",
|
||||
fingerprint.chars().take(32).collect::<String>()
|
||||
))
|
||||
}
|
||||
|
||||
pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batch(
|
||||
root: &Path,
|
||||
batch: &AgentRuntimeProviderActionBatch,
|
||||
@@ -168,8 +126,7 @@ pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batc
|
||||
) -> Result<(), String> {
|
||||
if !matches!(
|
||||
batch.schema_version.as_str(),
|
||||
AGENT_RUNTIME_PLAN_PROVIDER_ACTION_BATCH_SCHEMA_VERSION
|
||||
| AGENT_RUNTIME_PROVIDER_ACTION_BATCH_SCHEMA_VERSION
|
||||
AGENT_RUNTIME_PROVIDER_ACTION_BATCH_SCHEMA_VERSION
|
||||
| AGENT_RUNTIME_PROVIDER_ACTION_BATCH_PREVIOUS_SCHEMA_VERSION
|
||||
| AGENT_RUNTIME_PROVIDER_ACTION_BATCH_LEGACY_SCHEMA_VERSION
|
||||
) {
|
||||
@@ -206,48 +163,8 @@ pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batc
|
||||
batch.status
|
||||
));
|
||||
}
|
||||
// `plan.submit_gdd` is intentionally a sole-action durable batch. It is
|
||||
// the only non-collaboration batch allowed to bypass the historical
|
||||
// two-action minimum; keep the exception tied to the complete identity
|
||||
// predicate so a forged one-action batch cannot widen the normal path.
|
||||
let plan_schema =
|
||||
batch.schema_version == AGENT_RUNTIME_PLAN_PROVIDER_ACTION_BATCH_SCHEMA_VERSION;
|
||||
let plan_submit_batch = is_plan_submit_gdd_provider_action_batch(batch);
|
||||
if plan_schema {
|
||||
if !plan_submit_batch {
|
||||
return Err(
|
||||
"planning v4 Provider action 批次必须是唯一 plan.submit_gdd action 且无 collaboration 合同"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
let binding = batch
|
||||
.planning_session_binding
|
||||
.as_ref()
|
||||
.ok_or_else(|| "planning v4 Provider action 批次缺少 session binding".to_string())?;
|
||||
validate_plan_provider_session_binding(binding).map_err(|error| error.to_string())?;
|
||||
if batch.actions.len() != 1
|
||||
|| binding.request_kind != "tool-plan"
|
||||
|| batch.actions[0].planning_session_binding.as_ref() != Some(binding)
|
||||
|| batch.provider_request_id.as_deref() != Some(binding.provider_request_id.as_str())
|
||||
|| batch.project_id != binding.project_id
|
||||
|| batch.agent_id != binding.agent_id
|
||||
|| batch.task_id != binding.task_id
|
||||
|| batch.session_id != binding.session_id
|
||||
|| batch.run_id != binding.run_id
|
||||
|| batch.source != binding.source
|
||||
|| batch.run_profile != binding.run_profile
|
||||
|| batch.run_profile_binding_fingerprint != binding.run_profile_binding_fingerprint
|
||||
|| batch.planned_steer_cursor != binding.applied_steer_cursor
|
||||
|| batch.actions[0].provider_batch_plan_update != batch.plan.plan_update
|
||||
{
|
||||
return Err("planning v4 批次成员与 session binding 不一致".to_string());
|
||||
}
|
||||
} else if batch.planning_session_binding.is_some() || batch.provider_request_id.is_some() {
|
||||
return Err("非 planning v4 批次不能携带 planning session binding".to_string());
|
||||
}
|
||||
let minimum_action_count = if plan_submit_batch {
|
||||
1
|
||||
} else if batch.schema_version != AGENT_RUNTIME_PROVIDER_ACTION_BATCH_LEGACY_SCHEMA_VERSION
|
||||
let minimum_action_count = if batch.schema_version
|
||||
!= AGENT_RUNTIME_PROVIDER_ACTION_BATCH_LEGACY_SCHEMA_VERSION
|
||||
&& batch.collaboration_contract.is_some()
|
||||
{
|
||||
1
|
||||
@@ -281,23 +198,8 @@ pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batc
|
||||
.actions
|
||||
.first()
|
||||
.ok_or_else(|| "Agent Runtime Provider action 批次缺少首个动作".to_string())?;
|
||||
if plan_schema {
|
||||
let mut recovered_plan = first_pending.tool_plan();
|
||||
recovered_plan.actions = vec![first_pending.action.clone()];
|
||||
if recovered_plan != batch.plan {
|
||||
return Err("planning v4 批次无法从 standalone member 精确重建完整 plan".to_string());
|
||||
}
|
||||
}
|
||||
let mut waiting_confirmation_count = 0_usize;
|
||||
let mut rejected_count = 0_usize;
|
||||
// planning v4 批次把 plan update 冻结进 standalone member 用于恢复;普通批次的成员则被下方
|
||||
// 分支要求不得携带 planning recovery material。期望值必须按批次类型分叉,否则「同一轮里既
|
||||
// 调 update_agent_plan 又调工具」的普通批次会同时踩中两条互斥规则。
|
||||
let expected_member_plan_update = batch
|
||||
.planning_session_binding
|
||||
.is_some()
|
||||
.then(|| batch.plan.plan_update.clone())
|
||||
.flatten();
|
||||
for (index, pending) in batch.actions.iter().enumerate() {
|
||||
validate_agent_runtime_pending_tool_action_record(root, pending)?;
|
||||
if pending.agent_id != batch.agent_id
|
||||
@@ -312,8 +214,6 @@ pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batc
|
||||
|| pending.project_revision_before != batch.project_revision_before
|
||||
|| pending.planned_repository_context_fingerprint
|
||||
!= batch.planned_repository_context_fingerprint
|
||||
|| pending.planning_session_binding != batch.planning_session_binding
|
||||
|| pending.provider_batch_plan_update != expected_member_plan_update
|
||||
|| usize::try_from(pending.action_index).unwrap_or(usize::MAX) != index
|
||||
|| pending.action != batch.plan.actions[index]
|
||||
{
|
||||
@@ -342,26 +242,6 @@ pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batc
|
||||
if !action_ids.insert(pending.action_id.clone()) {
|
||||
return Err("Agent Runtime Provider action 批次包含重复 actionId".to_string());
|
||||
}
|
||||
if plan_schema {
|
||||
let binding = batch
|
||||
.planning_session_binding
|
||||
.as_ref()
|
||||
.ok_or_else(|| "planning v4 批次缺少 session binding".to_string())?;
|
||||
if pending.planning_session_binding.as_ref() != Some(binding)
|
||||
|| pending.action.tool.trim() != PLAN_SUBMIT_GDD_TOOL
|
||||
|| pending.action_id.is_empty()
|
||||
{
|
||||
return Err(format!(
|
||||
"planning v4 批次成员 frozen binding/action identity 不一致:index={index}"
|
||||
));
|
||||
}
|
||||
} else if pending.planning_session_binding.is_some()
|
||||
|| pending.provider_batch_plan_update.is_some()
|
||||
{
|
||||
return Err(format!(
|
||||
"非 planning Provider action 批次成员不能携带 planning recovery material:index={index}"
|
||||
));
|
||||
}
|
||||
match pending.status.as_str() {
|
||||
AGENT_RUNTIME_PENDING_ACTION_STATUS_PENDING => {
|
||||
if pending.execution_mode != AGENT_RUNTIME_ACTION_EXECUTION_MODE_CONFIRMATION
|
||||
@@ -525,26 +405,6 @@ pub(in crate::agent) fn validate_game_creator_agent_runtime_provider_action_batc
|
||||
batch.collaboration_contract.as_ref(),
|
||||
)?
|
||||
}
|
||||
AGENT_RUNTIME_PLAN_PROVIDER_ACTION_BATCH_SCHEMA_VERSION => {
|
||||
let binding = batch
|
||||
.planning_session_binding
|
||||
.as_ref()
|
||||
.ok_or_else(|| "planning v4 批次缺少 session binding".to_string())?;
|
||||
agent_runtime_plan_provider_action_batch_id(
|
||||
&batch.project_id,
|
||||
&batch.agent_id,
|
||||
&batch.task_id,
|
||||
&batch.session_id,
|
||||
&batch.run_id,
|
||||
batch.loop_iteration,
|
||||
batch.planned_steer_cursor,
|
||||
&batch.plan,
|
||||
&batch.project_revision_before,
|
||||
&batch.planned_repository_context_fingerprint,
|
||||
&batch.actions,
|
||||
binding,
|
||||
)?
|
||||
}
|
||||
AGENT_RUNTIME_PROVIDER_ACTION_BATCH_SCHEMA_VERSION => {
|
||||
agent_runtime_provider_action_batch_id(
|
||||
&batch.project_id,
|
||||
|
||||
+1
-51
@@ -116,31 +116,6 @@ pub(in crate::agent) async fn request_game_creator_agent_background_final_reply_
|
||||
root,
|
||||
"runtime.provider_request.capture.final_reply",
|
||||
)?;
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
// Keep every rebuilt request field on the same budget successor
|
||||
// that will be exposed by the structured injection and binding.
|
||||
fold_plan_provider_usage_before_new_request_at_locked(root, Some((agent_id, run_id)))?;
|
||||
// Freeze the concrete final-reply request and its Provider-facing
|
||||
// planning injection under the same project lock as the durable
|
||||
// session binding. This mirrors tool-plan and prevents an older
|
||||
// message object from being stamped with a newer session primary.
|
||||
built_request = build_game_creator_agent_background_final_reply_request(
|
||||
root,
|
||||
agent_id,
|
||||
session_id,
|
||||
run_id,
|
||||
task,
|
||||
plan,
|
||||
observations,
|
||||
)?;
|
||||
let wire_bytes =
|
||||
capture_plan_provider_structured_injections_at(root, session_id, observations)?;
|
||||
let message = render_plan_provider_structured_injections_message(&wire_bytes)?;
|
||||
built_request
|
||||
.2
|
||||
.messages
|
||||
.insert(1, LlmMessage::user(message));
|
||||
}
|
||||
let snapshot = capture_game_creator_agent_runtime_provider_request_snapshot_at_locked(
|
||||
root,
|
||||
agent_id,
|
||||
@@ -150,33 +125,8 @@ pub(in crate::agent) async fn request_game_creator_agent_background_final_reply_
|
||||
request_slot,
|
||||
applied_steer_cursor,
|
||||
)?;
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
let request_context_fingerprint =
|
||||
game_creator_agent_runtime_plan_provider_request_context_fingerprint(
|
||||
&built_request.0,
|
||||
&built_request.2,
|
||||
)?;
|
||||
let runtime = read_game_creator_agent_runtime_at(root, agent_id)?.state;
|
||||
let binding = capture_plan_provider_session_binding_for_snapshot(
|
||||
root,
|
||||
&runtime,
|
||||
&snapshot,
|
||||
&request_context_fingerprint,
|
||||
)?;
|
||||
snapshot.with_planning_session_binding(Some(binding))
|
||||
} else {
|
||||
snapshot
|
||||
}
|
||||
snapshot
|
||||
};
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
estimated_input_tokens = estimate_game_creator_llm_request_tokens(&built_request.2)?;
|
||||
validate_game_creator_llm_request_context_budget(
|
||||
&built_request.0,
|
||||
&built_request.2,
|
||||
estimated_input_tokens,
|
||||
"锁内冻结后的 final-reply 请求",
|
||||
)?;
|
||||
}
|
||||
let (llm, config_path, request) = built_request;
|
||||
let auto_compact_token_limit = llm.auto_compact_token_limit;
|
||||
let stream_snapshot = provider_snapshot.clone();
|
||||
|
||||
+14
-707
File diff suppressed because it is too large
Load Diff
+18
-182
@@ -118,26 +118,15 @@ fn provider_collaboration_repair_instruction(protocol_error: &str, section_id: &
|
||||
)
|
||||
}
|
||||
|
||||
fn restrict_root_goal_contract_repair_request(
|
||||
request: &mut LlmRunRequest,
|
||||
plan_root: bool,
|
||||
) -> Result<(), String> {
|
||||
if plan_root {
|
||||
restrict_plan_root_goal_contract_schema(&mut request.function_tools)?;
|
||||
}
|
||||
fn restrict_root_goal_contract_repair_request(request: &mut LlmRunRequest) -> Result<(), String> {
|
||||
restrict_agent_runtime_root_goal_contract_tools(request)
|
||||
}
|
||||
|
||||
fn root_goal_contract_repair_instruction(protocol_error: &str, plan_root: bool) -> String {
|
||||
if plan_root {
|
||||
format!(
|
||||
"上一条输出不符合工具计划协议:{protocol_error}\n当前 plan 根 Run 尚未冻结 Goal Contract。本次修复的原生工具目录只保留 agent.goal_contract;必须且只能调用一次。outcome 具体概括当前用户最终意图,nonNegotiables、forbiddenAssumptions、openQuestions 没有内容时传空数组,preferences 必须始终传空数组;acceptanceNodes 必须精确提交固定单节点 {{\"criterionId\":\"{PLAN_FAST_GDD_ACCEPTANCE_NODE_ID}\",\"criterion\":\"{PLAN_FAST_GDD_ACCEPTANCE_NODE_CRITERION}\",\"required\":true,\"requiredEvidence\":[\"{PLAN_FAST_GDD_ACCEPTANCE_NODE_EVIDENCE}\"],\"dependsOn\":[]}}。不得调用 update_agent_plan、respond_to_user 或任何其他动作,不得输出普通文本、解释、markdown 或代码围栏。"
|
||||
)
|
||||
} else {
|
||||
format!(
|
||||
"上一条输出不符合工具计划协议:{protocol_error}\n当前根 Run 尚未冻结 Goal Contract。本次修复的原生工具目录只保留 agent.goal_contract;必须且只能调用一次,用 outcome 具体概括当前用户最终意图,acceptanceNodes 至少提交一项可核对标准。每个 requiredEvidence 必须选择在该标准所有合法结果下都能成功产生回执的工具;环境探测可能以 rejected/failed 表示正常否定结果时,不得把该探测工具写成必需成功回执(例如非 Git 项目不得要求 git.inspect 成功,应使用 project.index 的成功回执证明 isRepository=false)。nonNegotiables、preferences、forbiddenAssumptions、openQuestions 没有内容时传空数组。不得调用 update_agent_plan、respond_to_user 或任何其他动作,不得输出普通文本、解释、markdown 或代码围栏。"
|
||||
)
|
||||
}
|
||||
fn root_goal_contract_repair_instruction(protocol_error: &str) -> String {
|
||||
format!(
|
||||
"上一条输出不符合工具计划协议:{protocol_error}
|
||||
当前根 Run 尚未冻结 Goal Contract。本次修复的原生工具目录只保留 agent.goal_contract;必须且只能调用一次,用 outcome 具体概括当前用户最终意图,acceptanceNodes 至少提交一项可核对标准。每个 requiredEvidence 必须选择在该标准所有合法结果下都能成功产生回执的工具;环境探测可能以 rejected/failed 表示正常否定结果时,不得把该探测工具写成必需成功回执(例如非 Git 项目不得要求 git.inspect 成功,应使用 project.index 的成功回执证明 isRepository=false)。nonNegotiables、preferences、forbiddenAssumptions、openQuestions 没有内容时传空数组。不得调用 update_agent_plan、respond_to_user 或任何其他动作,不得输出普通文本、解释、markdown 或代码围栏。"
|
||||
)
|
||||
}
|
||||
|
||||
/// 把上游的终态标记夹紧成可落审计的短标记。
|
||||
@@ -222,15 +211,6 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
let (run_profile, _) =
|
||||
agent_runtime_run_profile_identity_at(root, agent_id, run_id, None, None)?;
|
||||
let relaxed_autonomous = autonomous_relaxed_run_profile(&run_profile);
|
||||
let plan_root_candidate =
|
||||
read_game_creator_agent_runtime_run_profile_binding(root, agent_id, run_id)?
|
||||
.is_some_and(|binding| binding.source == AGENT_RUNTIME_SUPERVISOR_PLAN_SOURCE);
|
||||
let plan_root = if plan_root_candidate {
|
||||
validate_project_supervisor_plan_root_binding_at(root, agent_id, run_id)?;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let (mut built_request, mut supervisor_manifest_dag_in_progress_at_request) = {
|
||||
let _lock = acquire_game_creator_agent_provider_plan_project_write_lock_with_wait(
|
||||
root,
|
||||
@@ -346,78 +326,21 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
.as_ref()
|
||||
.map(|sidecar| context_compaction_result(sidecar, true));
|
||||
}
|
||||
let (provider_snapshot, initial_planning_session_binding) = {
|
||||
let provider_snapshot = {
|
||||
let _lock = acquire_game_creator_agent_provider_plan_project_write_lock_with_wait(
|
||||
root,
|
||||
"runtime.provider_request.capture.tool_plan",
|
||||
)?;
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
// Fold first so the request rebuild, structured injection and
|
||||
// frozen session binding all observe one budget successor.
|
||||
fold_plan_provider_usage_before_new_request_at_locked(root, Some((agent_id, run_id)))?;
|
||||
}
|
||||
// Exact planning requests must freeze the session and the concrete
|
||||
// request object under one project lock. Rebuild once while holding
|
||||
// that lock so a session successor cannot be used to re-label an
|
||||
// object assembled from an older session.
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
built_request = build_game_creator_agent_background_tool_plan_request_locked(
|
||||
root,
|
||||
&_lock,
|
||||
agent_id,
|
||||
session_id,
|
||||
run_id,
|
||||
task,
|
||||
observations,
|
||||
loop_index,
|
||||
)?;
|
||||
}
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
let wire_bytes =
|
||||
capture_plan_provider_structured_injections_at(root, session_id, observations)?;
|
||||
let message = render_plan_provider_structured_injections_message(&wire_bytes)?;
|
||||
built_request
|
||||
.2
|
||||
.messages
|
||||
.insert(1, LlmMessage::user(message));
|
||||
}
|
||||
let provider_snapshot =
|
||||
capture_game_creator_agent_runtime_provider_request_snapshot_at_locked(
|
||||
root,
|
||||
agent_id,
|
||||
session_id,
|
||||
run_id,
|
||||
"tool-plan",
|
||||
&initial_request_slot,
|
||||
applied_steer_cursor,
|
||||
)?;
|
||||
let planning_session_binding = if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
let request_context_fingerprint =
|
||||
game_creator_agent_runtime_plan_provider_request_context_fingerprint(
|
||||
&built_request.0,
|
||||
&built_request.2,
|
||||
)?;
|
||||
let runtime = read_game_creator_agent_runtime_at(root, agent_id)?.state;
|
||||
Some(capture_plan_provider_session_binding_for_snapshot(
|
||||
root,
|
||||
&runtime,
|
||||
&provider_snapshot,
|
||||
&request_context_fingerprint,
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(provider_snapshot, planning_session_binding)
|
||||
capture_game_creator_agent_runtime_provider_request_snapshot_at_locked(
|
||||
root,
|
||||
agent_id,
|
||||
session_id,
|
||||
run_id,
|
||||
"tool-plan",
|
||||
&initial_request_slot,
|
||||
applied_steer_cursor,
|
||||
)?
|
||||
};
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
estimated_input_tokens = estimate_game_creator_llm_request_tokens(&built_request.2)?;
|
||||
validate_game_creator_llm_request_context_budget(
|
||||
&built_request.0,
|
||||
&built_request.2,
|
||||
estimated_input_tokens,
|
||||
"锁内冻结后的 tool-plan 请求",
|
||||
)?;
|
||||
}
|
||||
let (llm, config_path, mut request, repository_context_fingerprint, _) = built_request;
|
||||
let auto_compact_token_limit = llm.auto_compact_token_limit;
|
||||
let format_repair_attempts = if run_profile == AGENT_RUNTIME_RUN_PROFILE_AUTONOMOUS_GAME_BUILD {
|
||||
@@ -482,36 +405,6 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
let request_snapshot = provider_snapshot
|
||||
.with_request_slot(&request_slot)
|
||||
.with_web_search_enabled(request.enable_web_search);
|
||||
let planning_session_binding = if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
if repair_attempt == 0 {
|
||||
initial_planning_session_binding.clone()
|
||||
} else {
|
||||
let request_context_fingerprint =
|
||||
game_creator_agent_runtime_plan_provider_request_context_fingerprint(
|
||||
&llm, &request,
|
||||
)?;
|
||||
let _lock = acquire_game_creator_agent_provider_plan_project_write_lock_with_wait(
|
||||
root,
|
||||
"runtime.provider_request.freeze.plan_binding",
|
||||
)?;
|
||||
let runtime = read_game_creator_agent_runtime_at(root, agent_id)?.state;
|
||||
let candidate = capture_plan_provider_session_binding_for_snapshot(
|
||||
root,
|
||||
&runtime,
|
||||
&request_snapshot,
|
||||
&request_context_fingerprint,
|
||||
)?;
|
||||
let initial = initial_planning_session_binding.as_ref().ok_or_else(|| {
|
||||
"planning Provider repair 缺少 repair-0 frozen session binding".to_string()
|
||||
})?;
|
||||
validate_plan_provider_session_binding_repair_lineage(initial, &candidate)?;
|
||||
Some(candidate)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let request_snapshot =
|
||||
request_snapshot.with_planning_session_binding(planning_session_binding.clone());
|
||||
let response = request_game_creator_agent_runtime_llm_with_persisted_transient_retry(
|
||||
root,
|
||||
&request_snapshot,
|
||||
@@ -568,16 +461,6 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
);
|
||||
}
|
||||
};
|
||||
let effective_planning_session_binding =
|
||||
if let Some(base_binding) = planning_session_binding.as_ref() {
|
||||
Some(plan_provider_session_binding_for_attempt(
|
||||
base_binding,
|
||||
&response_handoff.request_slot,
|
||||
&response_handoff.provider_request_id,
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if response_handoff.to_llm_response() != response {
|
||||
return Err(
|
||||
game_creator_agent_runtime_provider_handoff_reconciliation_error(
|
||||
@@ -907,7 +790,6 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
return Ok(RequestedAgentRuntimeToolPlanOutcome::Ready(Some(
|
||||
RequestedAgentRuntimeToolPlan {
|
||||
plan,
|
||||
planning_session_binding: effective_planning_session_binding,
|
||||
repository_context_fingerprint,
|
||||
estimated_input_tokens,
|
||||
auto_compact_token_limit,
|
||||
@@ -1069,13 +951,7 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
agent_runtime_protocol_error_requires_supervisor_collaboration_repair(
|
||||
&protocol_error,
|
||||
) && !request.function_tools.is_empty();
|
||||
if agent_id == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
request.function_tools =
|
||||
build_agent_runtime_native_function_tools_for_agent(agent_id)?;
|
||||
request.messages.push(LlmMessage::user(format!(
|
||||
"上一条输出不符合 planning 工具计划协议:{protocol_error}\n本轮修复仍只允许调用 file.read、file.list、plan.submit_gdd、update_agent_plan、respond_to_user。plan.submit_gdd 的 input 必须严格符合 plan-submit-gdd-input.v1,只提交 game、decisions、prototypeValidationItems;它必须是唯一 action,可与 update_agent_plan 同响应,但不能与其它动作或 respond_to_user 混合。不得调用或描述其它工具,不得输出普通文本来代替函数调用;需要用户决定时以 AGC_NEEDS_USER_INPUT_V1 终态信封收束。"
|
||||
)));
|
||||
} else if force_root_goal_contract
|
||||
if force_root_goal_contract
|
||||
|| force_supervisor_initial_collaboration
|
||||
|| force_autonomous_specialist_mutation_only
|
||||
|| force_autonomous_specialist_verification_only
|
||||
@@ -1116,12 +992,11 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
}
|
||||
}
|
||||
if force_root_goal_contract {
|
||||
restrict_root_goal_contract_repair_request(&mut request, plan_root)?;
|
||||
restrict_root_goal_contract_repair_request(&mut request)?;
|
||||
request
|
||||
.messages
|
||||
.push(LlmMessage::user(root_goal_contract_repair_instruction(
|
||||
&protocol_error,
|
||||
plan_root,
|
||||
)));
|
||||
} else if force_supervisor_initial_collaboration {
|
||||
supervisor_collaboration_repair_active = true;
|
||||
@@ -1292,17 +1167,6 @@ pub(in crate::agent) async fn request_game_creator_agent_background_tool_plan_at
|
||||
"上一条输出不符合工具计划协议:{protocol_error}\n请修复格式,只调用当前请求广告的 update_agent_plan、动作工具或 respond_to_user;当前 in_progress 步骤已具备执行条件时,格式修复必须保留并调用对应动作工具,不能退化为只调用 update_agent_plan。不要解释,不要 markdown,不要代码围栏,也不要把计划、动作或回复放进普通文本。"
|
||||
)));
|
||||
}
|
||||
// 修复分支会先整份重建工具目录,再按各自的场景收窄。plan 根必须在
|
||||
// 所有分支收窄之后再取一次交集:早于分支就会让
|
||||
// `restrict_agent_runtime_supervisor_collaboration_repair_tools`
|
||||
// 这类「必须包含 agent.spawn_isolated」的检查硬失败,晚于分支则
|
||||
// 保证任何修复轮都不会把被裁掉的 36 个工具重新广告回去。
|
||||
if plan_root {
|
||||
retain_plan_root_supervisor_native_tools(
|
||||
&mut request.function_tools,
|
||||
plan_root_supervisor_stage_at(root, agent_id, run_id)?,
|
||||
)?;
|
||||
}
|
||||
request.enable_web_search = false;
|
||||
}
|
||||
Err(error) => {
|
||||
@@ -1526,32 +1390,4 @@ mod supervisor_collaboration_repair_tests {
|
||||
|
||||
assert_eq!(merged, vec![replacement]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plan_root_goal_contract_repair_keeps_the_fixed_schema_and_instruction() {
|
||||
let mut request = LlmRunRequest::new(Vec::new())
|
||||
.with_function_tools(
|
||||
build_agent_runtime_native_function_tools().expect("build native function tools"),
|
||||
)
|
||||
.with_tool_choice(platform_llm::LlmToolChoice::Required);
|
||||
|
||||
restrict_root_goal_contract_repair_request(&mut request, true)
|
||||
.expect("restrict plan goal repair");
|
||||
assert_eq!(request.function_tools.len(), 1);
|
||||
let fixed = request.function_tools[0]
|
||||
.parameters
|
||||
.pointer("/properties/input/properties/acceptanceNodes")
|
||||
.expect("fixed acceptance nodes schema");
|
||||
assert_eq!(fixed["maxItems"], serde_json::json!(1));
|
||||
assert_eq!(
|
||||
fixed["items"]["properties"]["criterionId"]["enum"],
|
||||
serde_json::json!([PLAN_FAST_GDD_ACCEPTANCE_NODE_ID])
|
||||
);
|
||||
|
||||
let instruction = root_goal_contract_repair_instruction("test-error", true);
|
||||
assert!(instruction.contains("固定单节点"));
|
||||
assert!(instruction.contains(PLAN_FAST_GDD_ACCEPTANCE_NODE_CRITERION));
|
||||
assert!(!instruction.contains("至少提交一项"));
|
||||
assert!(!instruction.contains("project.index 的成功回执"));
|
||||
}
|
||||
}
|
||||
|
||||
-1
@@ -68,7 +68,6 @@ fn response_stream_fixture(
|
||||
),
|
||||
web_search_enabled: false,
|
||||
allow_idle_context_compaction: false,
|
||||
planning_session_binding: None,
|
||||
};
|
||||
(project, state, response_revision, snapshot)
|
||||
}
|
||||
|
||||
+1
-73
@@ -47,7 +47,6 @@ pub(crate) fn parse_game_creator_agent_tool_plan_llm_response_classified_for_age
|
||||
) -> Result<ParsedAgentRuntimeToolPlan, AgentRuntimeToolPlanProtocolError> {
|
||||
if response.tool_calls.is_empty() {
|
||||
let plan = parse_game_creator_agent_tool_plan_response_classified(response.text.as_str())?;
|
||||
validate_agent_runtime_tool_plan_identity(agent_id, &plan)?;
|
||||
return Ok(ParsedAgentRuntimeToolPlan {
|
||||
plan,
|
||||
protocol: "text_json",
|
||||
@@ -81,12 +80,6 @@ pub(crate) fn parse_game_creator_agent_tool_plan_llm_response_classified_for_age
|
||||
if response.tool_calls.len() == 1
|
||||
&& response.tool_calls[0].name == AGENT_RUNTIME_TOOL_PLAN_FUNCTION_NAME
|
||||
{
|
||||
if agent_id.trim() == GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
return Err(AgentRuntimeToolPlanProtocolError::new(
|
||||
AgentRuntimeToolPlanProtocolErrorKind::UnknownFunction,
|
||||
"Agent 原生工具协议错误:project-planning 不允许旧 submit_agent_tool_plan 包装器",
|
||||
));
|
||||
}
|
||||
let call = &response.tool_calls[0];
|
||||
let plan = parse_game_creator_agent_tool_plan_payload(call.arguments.as_str(), true)
|
||||
.map_err(|error| {
|
||||
@@ -108,9 +101,8 @@ pub(crate) fn parse_game_creator_agent_tool_plan_llm_response_classified_for_age
|
||||
normalized_text_sha256: text_normalization.source_text_sha256,
|
||||
});
|
||||
}
|
||||
let native = parse_agent_runtime_native_tool_calls_for_agent(agent_id, &response.tool_calls)?;
|
||||
let native = parse_agent_runtime_native_tool_calls(&response.tool_calls)?;
|
||||
let plan = normalize_game_creator_agent_tool_plan(native.plan)?;
|
||||
validate_agent_runtime_tool_plan_identity(agent_id, &plan)?;
|
||||
Ok(ParsedAgentRuntimeToolPlan {
|
||||
plan,
|
||||
protocol: "native_runtime_tools",
|
||||
@@ -125,46 +117,6 @@ pub(crate) fn parse_game_creator_agent_tool_plan_llm_response_classified_for_age
|
||||
})
|
||||
}
|
||||
|
||||
fn validate_agent_runtime_tool_plan_identity(
|
||||
agent_id: &str,
|
||||
plan: &AgentRuntimeToolPlan,
|
||||
) -> Result<(), AgentRuntimeToolPlanProtocolError> {
|
||||
if agent_id.trim() != GAME_CREATOR_PROJECT_PLANNING_AGENT_ID
|
||||
&& agent_id.trim() != "__all_agents__"
|
||||
&& plan
|
||||
.actions
|
||||
.iter()
|
||||
.any(|action| action.tool.trim() == PLAN_SUBMIT_GDD_TOOL)
|
||||
{
|
||||
return Err(AgentRuntimeToolPlanProtocolError::new(
|
||||
AgentRuntimeToolPlanProtocolErrorKind::UnknownFunction,
|
||||
format!(
|
||||
"Agent 原生工具协议错误:Agent {} 不允许调用 {}",
|
||||
agent_id.trim(),
|
||||
PLAN_SUBMIT_GDD_TOOL
|
||||
),
|
||||
));
|
||||
}
|
||||
if agent_id.trim() != GAME_CREATOR_PROJECT_PLANNING_AGENT_ID {
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(action) = plan
|
||||
.actions
|
||||
.iter()
|
||||
.find(|action| !agent_runtime_native_tool_allowed_for_agent(agent_id, &action.tool))
|
||||
{
|
||||
return Err(AgentRuntimeToolPlanProtocolError::new(
|
||||
AgentRuntimeToolPlanProtocolErrorKind::UnknownFunction,
|
||||
format!(
|
||||
"Agent 原生工具协议错误:Agent {} 不允许调用 {}",
|
||||
agent_id.trim(),
|
||||
action.tool.trim()
|
||||
),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(in crate::agent) struct AgentRuntimeToolPlanTextNormalization {
|
||||
pub(in crate::agent) visible_text: String,
|
||||
@@ -353,29 +305,5 @@ pub(in crate::agent) fn normalize_game_creator_agent_tool_plan(
|
||||
error,
|
||||
)
|
||||
})?;
|
||||
validate_plan_submit_gdd_tool_plan(&plan).map_err(|error| {
|
||||
AgentRuntimeToolPlanProtocolError::new(
|
||||
AgentRuntimeToolPlanProtocolErrorKind::BatchConstraint,
|
||||
error,
|
||||
)
|
||||
})?;
|
||||
Ok(plan)
|
||||
}
|
||||
|
||||
fn validate_plan_submit_gdd_tool_plan(plan: &AgentRuntimeToolPlan) -> Result<(), String> {
|
||||
let submit_count = plan
|
||||
.actions
|
||||
.iter()
|
||||
.filter(|action| action.tool.trim() == PLAN_SUBMIT_GDD_TOOL)
|
||||
.count();
|
||||
if submit_count == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
if submit_count != 1 || plan.actions.len() != 1 || !plan.response.trim().is_empty() {
|
||||
return Err(
|
||||
"Agent 工具计划协议错误:plan.submit_gdd 必须是本轮唯一 action,且不能与 respond_to_user 同响应(可与 update_agent_plan 同响应)"
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user