Initial commit: VibeEngineering V2
- 两阶段分离:设计阶段人工确认,执行阶段全自动化 - 子代理驱动:Implementer → Spec Reviewer → Quality Reviewer - 原生 Task 系统:使用 Claude Code Task 替代自定义状态管理 - 跨 Compact 恢复:PreCompact + SessionStart Hook(内联命令实现) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
96
.claude/hooks/extract-last-context.js
Normal file
96
.claude/hooks/extract-last-context.js
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* 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));
|
||||
}
|
||||
24
.claude/hooks/pre-compact.sh
Normal file
24
.claude/hooks/pre-compact.sh
Normal file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
# .claude/hooks/pre-compact.sh
|
||||
# VibeEngineering V2 - PreCompact Hook
|
||||
# 当上下文即将满时,从 transcript.jsonl 提取当前任务上下文
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# 使用 CLAUDE_PROJECT_DIR 环境变量确保路径正确
|
||||
PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
|
||||
cd "$PROJECT_DIR"
|
||||
|
||||
INPUT=$(cat)
|
||||
TRANSCRIPT_PATH=$(echo "$INPUT" | jq -r '.transcript_path')
|
||||
|
||||
# 等待 transcript.jsonl 完全写入
|
||||
sleep 1
|
||||
|
||||
# 确保 .vibe 目录存在
|
||||
mkdir -p .vibe
|
||||
|
||||
# 调用 Node.js 脚本提取上下文
|
||||
node "$PROJECT_DIR/.claude/hooks/extract-last-context.js" "$TRANSCRIPT_PATH" > .vibe/last_task_context.jsonl
|
||||
|
||||
exit 0
|
||||
79
.claude/hooks/session-start.sh
Normal file
79
.claude/hooks/session-start.sh
Normal file
@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env bash
|
||||
# .claude/hooks/session-start.sh
|
||||
# VibeEngineering V2 - SessionStart Hook
|
||||
# 只有存在 last_task_context.jsonl 才触发恢复提示
|
||||
|
||||
# 不使用严格模式,避免 Windows 环境兼容问题
|
||||
|
||||
# 检查是否存在恢复上下文文件(当前目录已由调用者设置)
|
||||
if [[ ! -f ".vibe/last_task_context.jsonl" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -f ".vibe/session.yml" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 读取 task_list_id(使用 grep + sed 替代 yq,兼容性更好)
|
||||
TASK_LIST_ID=$(grep 'task_list_id:' .vibe/session.yml | sed 's/task_list_id: *//' | tr -d '"' | tr -d "'")
|
||||
TASK_DIR="$HOME/.claude/tasks/$TASK_LIST_ID"
|
||||
|
||||
cat << 'PROMPT'
|
||||
## 【系统提示:检测到跨 Compact 恢复 - VibeEngineering V2 执行阶段】
|
||||
|
||||
你正在从 Compact 后恢复执行上下文。请严格按以下顺序读取信息:
|
||||
|
||||
### Step 1: 读取执行流程定义
|
||||
```
|
||||
Read .claude/commands/vibe-execute.md
|
||||
```
|
||||
了解 Phase 2 执行循环的完整流程。
|
||||
|
||||
### Step 2: 读取 subagent-driven-development skill
|
||||
```
|
||||
Read .claude/skills/subagent-driven-development/SKILL.md
|
||||
```
|
||||
了解子代理派发模板(Implementer、Spec Reviewer、Code Quality Reviewer)。
|
||||
|
||||
### Step 3: 读取设计文档
|
||||
```
|
||||
Read .vibe/session.yml
|
||||
```
|
||||
获取 design_doc 路径,然后读取设计文档了解需求。
|
||||
|
||||
### Step 4: 读取所有 Task JSON
|
||||
PROMPT
|
||||
|
||||
echo '```'
|
||||
echo "Glob pattern='*.json' path='$TASK_DIR'"
|
||||
echo "然后 Read 每个返回的 JSON 文件"
|
||||
echo '```'
|
||||
|
||||
cat << 'PROMPT'
|
||||
从 Task JSON 了解:
|
||||
- 所有任务列表(subject)和详细信息(description)
|
||||
- 任务状态(status: pending / in_progress / completed)
|
||||
- **已完成任务的 metadata**:files_modified, errors_encountered, git_commit, test_results
|
||||
|
||||
### Step 5: 读取上一窗口执行上下文
|
||||
```
|
||||
Read .vibe/last_task_context.jsonl
|
||||
```
|
||||
从 last_task_context.jsonl 了解:
|
||||
- 当前任务执行到哪一步
|
||||
- Claude 的思考过程和决策
|
||||
- 用户的纠正指令(如有)
|
||||
- 子代理派发的任务和返回结果
|
||||
|
||||
### 恢复后行为
|
||||
|
||||
1. 找到第一个 status 为 pending 或 in_progress 的 Task
|
||||
2. 如果有 in_progress 的 Task,结合 last_task_context.jsonl 从中断点继续
|
||||
3. 如果上一个 Task 已 completed,从下一个 pending Task 开始
|
||||
4. **按照 vibe-execute.md Phase 2 和 subagent-driven-development skill 执行**:
|
||||
- 业务 Task:派发 Implementer → Spec Reviewer → Code Quality Reviewer → 标记完成
|
||||
- 校验 Task:执行 Step 0-5 固定流程
|
||||
5. 所有 Task 完成后,校验 Task 保存快照并标记完成
|
||||
PROMPT
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user