- 两阶段分离:设计阶段人工确认,执行阶段全自动化 - 子代理驱动:Implementer → Spec Reviewer → Quality Reviewer - 原生 Task 系统:使用 Claude Code Task 替代自定义状态管理 - 跨 Compact 恢复:PreCompact + SessionStart Hook(内联命令实现) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
97 lines
2.7 KiB
JavaScript
97 lines
2.7 KiB
JavaScript
/**
|
||
* VibeEngineering V2 - 上下文提取脚本
|
||
* 从 transcript.jsonl 提取最后一次 TaskUpdate completed 之后的内容
|
||
*/
|
||
|
||
const fs = require('fs');
|
||
|
||
function extractSinceLastTaskComplete(transcriptPath) {
|
||
const content = fs.readFileSync(transcriptPath, 'utf-8');
|
||
const lines = content.split('\n').filter(Boolean);
|
||
|
||
// 倒序找最后一次 TaskUpdate status=completed
|
||
let cutoffIndex = 0;
|
||
for (let i = lines.length - 1; i >= 0; i--) {
|
||
try {
|
||
const entry = JSON.parse(lines[i]);
|
||
if (entry.tool_name === 'TaskUpdate' &&
|
||
entry.tool_input?.status === 'completed') {
|
||
cutoffIndex = i + 1;
|
||
break;
|
||
}
|
||
} catch (e) {
|
||
continue;
|
||
}
|
||
}
|
||
|
||
const relevantLines = lines.slice(cutoffIndex);
|
||
const simplified = simplifyEntries(relevantLines);
|
||
return simplified.map(e => JSON.stringify(e)).join('\n');
|
||
}
|
||
|
||
function simplifyEntries(lines) {
|
||
return lines.map(line => {
|
||
try {
|
||
const entry = JSON.parse(line);
|
||
|
||
// Claude 输出:全部保留
|
||
if (entry.role === 'assistant') {
|
||
return { type: 'assistant', content: entry.content };
|
||
}
|
||
|
||
// 用户输入:全部保留
|
||
if (entry.role === 'user') {
|
||
return { type: 'user', content: entry.content };
|
||
}
|
||
|
||
// Task tool 返回(子代理结果):全部保留
|
||
if (entry.type === 'tool_result' && entry.agentId) {
|
||
return {
|
||
type: 'task_result',
|
||
agentId: entry.agentId,
|
||
content: entry.content
|
||
};
|
||
}
|
||
|
||
// 工具调用
|
||
if (entry.tool_name) {
|
||
const input = entry.tool_input || {};
|
||
|
||
// Task tool(派发子代理):prompt 全部保留
|
||
if (entry.tool_name === 'Task') {
|
||
return {
|
||
type: 'tool',
|
||
name: 'Task',
|
||
subagent_type: input.subagent_type,
|
||
description: input.description,
|
||
prompt: input.prompt
|
||
};
|
||
}
|
||
|
||
// 其他工具:只保留关键参数
|
||
const simplified = { type: 'tool', name: entry.tool_name };
|
||
if (input.file_path) simplified.file = input.file_path;
|
||
if (input.command) simplified.command = input.command;
|
||
if (input.pattern) simplified.pattern = input.pattern;
|
||
if (input.path) simplified.path = input.path;
|
||
if (input.taskId) simplified.taskId = input.taskId;
|
||
if (input.status) simplified.status = input.status;
|
||
|
||
if (entry.tool_result?.exit_code !== undefined) {
|
||
simplified.exit_code = entry.tool_result.exit_code;
|
||
}
|
||
return simplified;
|
||
}
|
||
|
||
return null;
|
||
} catch (e) {
|
||
return null;
|
||
}
|
||
}).filter(Boolean);
|
||
}
|
||
|
||
const transcriptPath = process.argv[2];
|
||
if (transcriptPath) {
|
||
console.log(extractSinceLastTaskComplete(transcriptPath));
|
||
}
|