mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-11 02:33:51 +08:00
feat: Enhance memory compact output format for better session recovery
- Add Session ID and Project Root fields for workflow tracking - Split Active Files into Working Files (modified) and Reference Files (read-only) - Use absolute paths for all file references - Support multiple plan sources: workflow/todo/user-stated/inferred - Preserve complete execution plan verbatim without summarization - Add path resolution rules and reference file categories - Update quality checklist with new validation criteria 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -29,17 +29,57 @@ The `memory:compact` command **compresses current session working memory** into
|
|||||||
## 3. Structured Output Format
|
## 3. Structured Output Format
|
||||||
|
|
||||||
```markdown
|
```markdown
|
||||||
|
## Session ID
|
||||||
|
[WFS-ID if workflow session active, otherwise (none)]
|
||||||
|
|
||||||
|
## Project Root
|
||||||
|
[Absolute path to project root, e.g., D:\Claude_dms3]
|
||||||
|
|
||||||
## Objective
|
## Objective
|
||||||
[High-level goal - the "North Star" of this session]
|
[High-level goal - the "North Star" of this session]
|
||||||
|
|
||||||
## Plan
|
## Execution Plan
|
||||||
- [x] [Completed step]
|
[CRITICAL: Embed the LATEST plan in its COMPLETE and DETAILED form]
|
||||||
- [x] [Completed step]
|
|
||||||
- [ ] [Pending step]
|
|
||||||
|
|
||||||
## Active Files
|
### Source: [workflow | todo | user-stated | inferred]
|
||||||
- path/to/file1.ts (role: main implementation)
|
|
||||||
- path/to/file2.ts (role: tests)
|
<details>
|
||||||
|
<summary>Full Execution Plan (Click to expand)</summary>
|
||||||
|
|
||||||
|
[PRESERVE COMPLETE PLAN VERBATIM - DO NOT SUMMARIZE]
|
||||||
|
- ALL phases, tasks, subtasks
|
||||||
|
- ALL file paths (absolute)
|
||||||
|
- ALL dependencies and prerequisites
|
||||||
|
- ALL acceptance criteria
|
||||||
|
- ALL status markers ([x] done, [ ] pending)
|
||||||
|
- ALL notes and context
|
||||||
|
|
||||||
|
Example:
|
||||||
|
## Phase 1: Setup
|
||||||
|
- [x] Initialize project structure
|
||||||
|
- Created D:\Claude_dms3\src\core\index.ts
|
||||||
|
- Added dependencies: lodash, zod
|
||||||
|
- [ ] Configure TypeScript
|
||||||
|
- Update tsconfig.json for strict mode
|
||||||
|
|
||||||
|
## Phase 2: Implementation
|
||||||
|
- [ ] Implement core API
|
||||||
|
- Target: D:\Claude_dms3\src\api\handler.ts
|
||||||
|
- Dependencies: Phase 1 complete
|
||||||
|
- Acceptance: All tests pass
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
## Working Files (Modified)
|
||||||
|
[Absolute paths to actively modified files]
|
||||||
|
- D:\Claude_dms3\src\file1.ts (role: main implementation)
|
||||||
|
- D:\Claude_dms3\tests\file1.test.ts (role: unit tests)
|
||||||
|
|
||||||
|
## Reference Files (Read-Only)
|
||||||
|
[Absolute paths to context files - NOT modified but essential for understanding]
|
||||||
|
- D:\Claude_dms3\.claude\CLAUDE.md (role: project instructions)
|
||||||
|
- D:\Claude_dms3\src\types\index.ts (role: type definitions)
|
||||||
|
- D:\Claude_dms3\package.json (role: dependencies)
|
||||||
|
|
||||||
## Last Action
|
## Last Action
|
||||||
[Last significant action and its result/status]
|
[Last significant action and its result/status]
|
||||||
@@ -71,9 +111,12 @@ The `memory:compact` command **compresses current session working memory** into
|
|||||||
|
|
||||||
| Field | Purpose | Recovery Value |
|
| Field | Purpose | Recovery Value |
|
||||||
|-------|---------|----------------|
|
|-------|---------|----------------|
|
||||||
|
| **Session ID** | Workflow session identifier (WFS-*) | Links memory to specific stateful task execution |
|
||||||
|
| **Project Root** | Absolute path to project directory | Enables correct path resolution in new sessions |
|
||||||
| **Objective** | Ultimate goal of the session | Prevents losing track of broader feature |
|
| **Objective** | Ultimate goal of the session | Prevents losing track of broader feature |
|
||||||
| **Plan** | Steps with status markers | Avoids re-planning or repeating steps |
|
| **Execution Plan** | Complete plan from any source (verbatim) | Preserves full planning context, avoids re-planning |
|
||||||
| **Active Files** | Working set of files | Eliminates re-exploration of codebase |
|
| **Working Files** | Actively modified files (absolute paths) | Immediately identifies where work was happening |
|
||||||
|
| **Reference Files** | Read-only context files (absolute paths) | Eliminates re-exploration for critical context |
|
||||||
| **Last Action** | Final tool output/status | Immediate state awareness (success/failure) |
|
| **Last Action** | Final tool output/status | Immediate state awareness (success/failure) |
|
||||||
| **Decisions** | Architectural choices + reasoning | Prevents re-litigating settled decisions |
|
| **Decisions** | Architectural choices + reasoning | Prevents re-litigating settled decisions |
|
||||||
| **Constraints** | User-imposed limitations | Maintains personalized coding style |
|
| **Constraints** | User-imposed limitations | Maintains personalized coding style |
|
||||||
@@ -91,9 +134,15 @@ Extract the following from conversation history:
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const sessionAnalysis = {
|
const sessionAnalysis = {
|
||||||
|
sessionId: "", // WFS-* if workflow session active, null otherwise
|
||||||
|
projectRoot: "", // Absolute path: D:\Claude_dms3
|
||||||
objective: "", // High-level goal (1-2 sentences)
|
objective: "", // High-level goal (1-2 sentences)
|
||||||
plan: [], // Steps with status: {step, status: 'done'|'pending'}
|
executionPlan: {
|
||||||
activeFiles: [], // {path, role} - working set
|
source: "workflow" | "todo" | "user-stated" | "inferred",
|
||||||
|
content: "" // Full plan content - ALWAYS preserve COMPLETE and DETAILED form
|
||||||
|
},
|
||||||
|
workingFiles: [], // {absolutePath, role} - modified files
|
||||||
|
referenceFiles: [], // {absolutePath, role} - read-only context files
|
||||||
lastAction: "", // Last significant action + result
|
lastAction: "", // Last significant action + result
|
||||||
decisions: [], // {decision, reasoning}
|
decisions: [], // {decision, reasoning}
|
||||||
constraints: [], // User-specified limitations
|
constraints: [], // User-specified limitations
|
||||||
@@ -108,16 +157,43 @@ const sessionAnalysis = {
|
|||||||
### Step 2: Generate Structured Text
|
### Step 2: Generate Structured Text
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const structuredText = `## Objective
|
// Helper: Generate execution plan section
|
||||||
|
const generateExecutionPlan = (plan) => {
|
||||||
|
const sourceLabels = {
|
||||||
|
'workflow': 'workflow (IMPL_PLAN.md)',
|
||||||
|
'todo': 'todo (TodoWrite)',
|
||||||
|
'user-stated': 'user-stated',
|
||||||
|
'inferred': 'inferred'
|
||||||
|
};
|
||||||
|
|
||||||
|
// CRITICAL: Preserve complete plan content verbatim - DO NOT summarize
|
||||||
|
return `### Source: ${sourceLabels[plan.source] || plan.source}
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Full Execution Plan (Click to expand)</summary>
|
||||||
|
|
||||||
|
${plan.content}
|
||||||
|
|
||||||
|
</details>`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const structuredText = `## Session ID
|
||||||
|
${sessionAnalysis.sessionId || '(none)'}
|
||||||
|
|
||||||
|
## Project Root
|
||||||
|
${sessionAnalysis.projectRoot}
|
||||||
|
|
||||||
|
## Objective
|
||||||
${sessionAnalysis.objective}
|
${sessionAnalysis.objective}
|
||||||
|
|
||||||
## Plan
|
## Execution Plan
|
||||||
${sessionAnalysis.plan.map(p =>
|
${generateExecutionPlan(sessionAnalysis.executionPlan)}
|
||||||
`- [${p.status === 'done' ? 'x' : ' '}] ${p.step}`
|
|
||||||
).join('\n')}
|
|
||||||
|
|
||||||
## Active Files
|
## Working Files (Modified)
|
||||||
${sessionAnalysis.activeFiles.map(f => `- ${f.path} (${f.role})`).join('\n')}
|
${sessionAnalysis.workingFiles.map(f => `- ${f.absolutePath} (role: ${f.role})`).join('\n') || '(none)'}
|
||||||
|
|
||||||
|
## Reference Files (Read-Only)
|
||||||
|
${sessionAnalysis.referenceFiles.map(f => `- ${f.absolutePath} (role: ${f.role})`).join('\n') || '(none)'}
|
||||||
|
|
||||||
## Last Action
|
## Last Action
|
||||||
${sessionAnalysis.lastAction}
|
${sessionAnalysis.lastAction}
|
||||||
@@ -135,7 +211,7 @@ ${sessionAnalysis.dependencies.map(d => `- ${d}`).join('\n') || '(none)'}
|
|||||||
${sessionAnalysis.knownIssues.map(i => `- ${i}`).join('\n') || '(none)'}
|
${sessionAnalysis.knownIssues.map(i => `- ${i}`).join('\n') || '(none)'}
|
||||||
|
|
||||||
## Changes Made
|
## Changes Made
|
||||||
${sessionAnalysis.changesMade.map(c => `- ${c}`).join('\n')}
|
${sessionAnalysis.changesMade.map(c => `- ${c}`).join('\n') || '(none)'}
|
||||||
|
|
||||||
## Pending
|
## Pending
|
||||||
${sessionAnalysis.pending.length > 0
|
${sessionAnalysis.pending.length > 0
|
||||||
@@ -208,17 +284,114 @@ ccw core-memory summary --id CMEM-20251218-150322
|
|||||||
## 8. Quality Checklist
|
## 8. Quality Checklist
|
||||||
|
|
||||||
Before generating:
|
Before generating:
|
||||||
|
- [ ] Session ID captured if workflow session active (WFS-*)
|
||||||
|
- [ ] Project Root is absolute path (e.g., D:\Claude_dms3)
|
||||||
- [ ] Objective clearly states the "North Star" goal
|
- [ ] Objective clearly states the "North Star" goal
|
||||||
- [ ] Plan shows completion status with [x] / [ ] markers
|
- [ ] Execution Plan: COMPLETE plan preserved VERBATIM (no summarization)
|
||||||
- [ ] Active Files includes 3-8 core files with roles
|
- [ ] Plan Source: Clearly identified (workflow | todo | user-stated | inferred)
|
||||||
|
- [ ] Plan Details: ALL phases, tasks, file paths, dependencies, status markers included
|
||||||
|
- [ ] All file paths are ABSOLUTE (not relative)
|
||||||
|
- [ ] Working Files: 3-8 modified files with roles
|
||||||
|
- [ ] Reference Files: Key context files (CLAUDE.md, types, configs)
|
||||||
- [ ] Last Action captures final state (success/failure)
|
- [ ] Last Action captures final state (success/failure)
|
||||||
- [ ] Decisions include reasoning, not just choices
|
- [ ] Decisions include reasoning, not just choices
|
||||||
- [ ] Known Issues separates deferred from forgotten bugs
|
- [ ] Known Issues separates deferred from forgotten bugs
|
||||||
- [ ] Notes preserve debugging hypotheses if any
|
- [ ] Notes preserve debugging hypotheses if any
|
||||||
|
|
||||||
## 9. Notes
|
## 9. Path Resolution Rules
|
||||||
|
|
||||||
|
### Project Root Detection
|
||||||
|
1. Check current working directory from environment
|
||||||
|
2. Look for project markers: `.git/`, `package.json`, `.claude/`
|
||||||
|
3. Use the topmost directory containing these markers
|
||||||
|
|
||||||
|
### Absolute Path Conversion
|
||||||
|
```javascript
|
||||||
|
// Convert relative to absolute
|
||||||
|
const toAbsolutePath = (relativePath, projectRoot) => {
|
||||||
|
if (path.isAbsolute(relativePath)) return relativePath;
|
||||||
|
return path.join(projectRoot, relativePath);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Example: "src/api/auth.ts" → "D:\Claude_dms3\src\api\auth.ts"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reference File Categories
|
||||||
|
| Category | Examples | Priority |
|
||||||
|
|----------|----------|----------|
|
||||||
|
| Project Config | `.claude/CLAUDE.md`, `package.json`, `tsconfig.json` | High |
|
||||||
|
| Type Definitions | `src/types/*.ts`, `*.d.ts` | High |
|
||||||
|
| Related Modules | Parent/sibling modules with shared interfaces | Medium |
|
||||||
|
| Test Files | Corresponding test files for modified code | Medium |
|
||||||
|
| Documentation | `README.md`, `ARCHITECTURE.md` | Low |
|
||||||
|
|
||||||
|
## 10. Plan Detection (Priority Order)
|
||||||
|
|
||||||
|
### Priority 1: Workflow Session (IMPL_PLAN.md)
|
||||||
|
```javascript
|
||||||
|
// Check for active workflow session
|
||||||
|
const manifest = await mcp__ccw-tools__session_manager({
|
||||||
|
operation: "list",
|
||||||
|
location: "active"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (manifest.sessions?.length > 0) {
|
||||||
|
const session = manifest.sessions[0];
|
||||||
|
const plan = await mcp__ccw-tools__session_manager({
|
||||||
|
operation: "read",
|
||||||
|
session_id: session.id,
|
||||||
|
content_type: "plan"
|
||||||
|
});
|
||||||
|
sessionAnalysis.sessionId = session.id;
|
||||||
|
sessionAnalysis.executionPlan.source = "workflow";
|
||||||
|
sessionAnalysis.executionPlan.content = plan.content;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Priority 2: TodoWrite (Current Session Todos)
|
||||||
|
```javascript
|
||||||
|
// Extract from conversation - look for TodoWrite tool calls
|
||||||
|
// Preserve COMPLETE todo list with all details
|
||||||
|
const todos = extractTodosFromConversation();
|
||||||
|
if (todos.length > 0) {
|
||||||
|
sessionAnalysis.executionPlan.source = "todo";
|
||||||
|
// Format todos with full context - preserve status markers
|
||||||
|
sessionAnalysis.executionPlan.content = todos.map(t =>
|
||||||
|
`- [${t.status === 'completed' ? 'x' : t.status === 'in_progress' ? '>' : ' '}] ${t.content}`
|
||||||
|
).join('\n');
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Priority 3: User-Stated Plan
|
||||||
|
```javascript
|
||||||
|
// Look for explicit plan statements in user messages:
|
||||||
|
// - "Here's my plan: 1. ... 2. ... 3. ..."
|
||||||
|
// - "I want to: first..., then..., finally..."
|
||||||
|
// - Numbered or bulleted lists describing steps
|
||||||
|
const userPlan = extractUserStatedPlan();
|
||||||
|
if (userPlan) {
|
||||||
|
sessionAnalysis.executionPlan.source = "user-stated";
|
||||||
|
sessionAnalysis.executionPlan.content = userPlan;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Priority 4: Inferred Plan
|
||||||
|
```javascript
|
||||||
|
// If no explicit plan, infer from:
|
||||||
|
// - Task description and breakdown discussion
|
||||||
|
// - Sequence of actions taken
|
||||||
|
// - Outstanding work mentioned
|
||||||
|
const inferredPlan = inferPlanFromDiscussion();
|
||||||
|
if (inferredPlan) {
|
||||||
|
sessionAnalysis.executionPlan.source = "inferred";
|
||||||
|
sessionAnalysis.executionPlan.content = inferredPlan;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 11. Notes
|
||||||
|
|
||||||
- **Timing**: Execute at task completion or before context switch
|
- **Timing**: Execute at task completion or before context switch
|
||||||
- **Frequency**: Once per independent task or milestone
|
- **Frequency**: Once per independent task or milestone
|
||||||
- **Recovery**: New session can immediately continue with full context
|
- **Recovery**: New session can immediately continue with full context
|
||||||
- **Knowledge Graph**: Entity relationships auto-extracted for visualization
|
- **Knowledge Graph**: Entity relationships auto-extracted for visualization
|
||||||
|
- **Absolute Paths**: Critical for cross-session recovery on different machines
|
||||||
|
|||||||
Reference in New Issue
Block a user